Search in sources :

Example 1 with RMDIR3Request

use of org.apache.hadoop.nfs.nfs3.request.RMDIR3Request in project hadoop by apache.

the class RMDIR3Request method deserialize.

public static RMDIR3Request deserialize(XDR xdr) throws IOException {
    FileHandle handle = readHandle(xdr);
    String name = xdr.readString();
    return new RMDIR3Request(handle, name);
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle)

Example 2 with RMDIR3Request

use of org.apache.hadoop.nfs.nfs3.request.RMDIR3Request in project hadoop by apache.

the class RpcProgramNfs3 method rmdir.

@VisibleForTesting
RMDIR3Response rmdir(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    RMDIR3Response response = new RMDIR3Response(Nfs3Status.NFS3_OK);
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    RMDIR3Request request;
    try {
        request = RMDIR3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid RMDIR request");
        return new RMDIR3Response(Nfs3Status.NFS3ERR_INVAL);
    }
    FileHandle dirHandle = request.getHandle();
    String fileName = request.getName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS RMDIR dir fileId: " + dirHandle.getFileId() + " fileName: " + fileName + " client: " + remoteAddress);
    }
    String dirFileIdPath = Nfs3Utils.getFileIdPath(dirHandle);
    Nfs3FileAttributes preOpDirAttr = null;
    Nfs3FileAttributes postOpDirAttr = null;
    try {
        preOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
        if (preOpDirAttr == null) {
            LOG.info("Can't get path for dir fileId: " + dirHandle.getFileId());
            return new RMDIR3Response(Nfs3Status.NFS3ERR_STALE);
        }
        WccData errWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr), preOpDirAttr);
        if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
            return new RMDIR3Response(Nfs3Status.NFS3ERR_ACCES, errWcc);
        }
        String fileIdPath = dirFileIdPath + "/" + fileName;
        HdfsFileStatus fstat = Nfs3Utils.getFileStatus(dfsClient, fileIdPath);
        if (fstat == null) {
            return new RMDIR3Response(Nfs3Status.NFS3ERR_NOENT, errWcc);
        }
        if (!fstat.isDir()) {
            return new RMDIR3Response(Nfs3Status.NFS3ERR_NOTDIR, errWcc);
        }
        if (fstat.getChildrenNum() > 0) {
            return new RMDIR3Response(Nfs3Status.NFS3ERR_NOTEMPTY, errWcc);
        }
        boolean result = dfsClient.delete(fileIdPath, false);
        WccData dirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(preOpDirAttr), dfsClient, dirFileIdPath, iug);
        if (!result) {
            return new RMDIR3Response(Nfs3Status.NFS3ERR_ACCES, dirWcc);
        }
        return new RMDIR3Response(Nfs3Status.NFS3_OK, dirWcc);
    } catch (IOException e) {
        LOG.warn("Exception ", e);
        // Try to return correct WccData
        if (postOpDirAttr == null) {
            try {
                postOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
            } catch (IOException e1) {
                LOG.info("Can't get postOpDirAttr for " + dirFileIdPath, e1);
            }
        }
        WccData dirWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr), postOpDirAttr);
        int status = mapErrorStatus(e);
        return new RMDIR3Response(status, dirWcc);
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) WccData(org.apache.hadoop.nfs.nfs3.response.WccData) RMDIR3Response(org.apache.hadoop.nfs.nfs3.response.RMDIR3Response) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) RMDIR3Request(org.apache.hadoop.nfs.nfs3.request.RMDIR3Request) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with RMDIR3Request

use of org.apache.hadoop.nfs.nfs3.request.RMDIR3Request in project hadoop by apache.

the class TestRpcProgramNfs3 method testRmdir.

@Test(timeout = 60000)
public void testRmdir() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    RMDIR3Request req = new RMDIR3Request(handle, "foo");
    req.serialize(xdr_req);
    // Attempt by an unprivileged user should fail.
    RMDIR3Response response1 = nfsd.rmdir(xdr_req.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a privileged user should pass.
    RMDIR3Response response2 = nfsd.rmdir(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response2.getStatus());
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) RMDIR3Response(org.apache.hadoop.nfs.nfs3.response.RMDIR3Response) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) RMDIR3Request(org.apache.hadoop.nfs.nfs3.request.RMDIR3Request) Test(org.junit.Test)

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)3 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)2 RMDIR3Request (org.apache.hadoop.nfs.nfs3.request.RMDIR3Request)2 RMDIR3Response (org.apache.hadoop.nfs.nfs3.response.RMDIR3Response)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 DFSClient (org.apache.hadoop.hdfs.DFSClient)1 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)1 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)1 XDR (org.apache.hadoop.oncrpc.XDR)1 Test (org.junit.Test)1