Search in sources :

Example 1 with LOOKUP3Response

use of org.apache.hadoop.nfs.nfs3.response.LOOKUP3Response in project hadoop by apache.

the class RpcProgramNfs3 method lookup.

@VisibleForTesting
LOOKUP3Response lookup(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    LOOKUP3Response response = new LOOKUP3Response(Nfs3Status.NFS3_OK);
    if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_ONLY)) {
        response.setStatus(Nfs3Status.NFS3ERR_ACCES);
        return response;
    }
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    LOOKUP3Request request;
    try {
        request = LOOKUP3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid LOOKUP request");
        return new LOOKUP3Response(Nfs3Status.NFS3ERR_INVAL);
    }
    FileHandle dirHandle = request.getHandle();
    String fileName = request.getName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS LOOKUP dir fileId: " + dirHandle.getFileId() + " name: " + fileName + " client: " + remoteAddress);
    }
    try {
        String dirFileIdPath = Nfs3Utils.getFileIdPath(dirHandle);
        Nfs3FileAttributes postOpObjAttr = writeManager.getFileAttr(dfsClient, dirHandle, fileName);
        if (postOpObjAttr == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("NFS LOOKUP fileId: " + dirHandle.getFileId() + " name: " + fileName + " does not exist");
            }
            Nfs3FileAttributes postOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
            return new LOOKUP3Response(Nfs3Status.NFS3ERR_NOENT, null, null, postOpDirAttr);
        }
        Nfs3FileAttributes postOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
        if (postOpDirAttr == null) {
            LOG.info("Can't get path for dir fileId: " + dirHandle.getFileId());
            return new LOOKUP3Response(Nfs3Status.NFS3ERR_STALE);
        }
        FileHandle fileHandle = new FileHandle(postOpObjAttr.getFileId());
        return new LOOKUP3Response(Nfs3Status.NFS3_OK, fileHandle, postOpObjAttr, postOpDirAttr);
    } catch (IOException e) {
        LOG.warn("Exception ", e);
        int status = mapErrorStatus(e);
        return new LOOKUP3Response(status);
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) LOOKUP3Request(org.apache.hadoop.nfs.nfs3.request.LOOKUP3Request) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) IOException(java.io.IOException) LOOKUP3Response(org.apache.hadoop.nfs.nfs3.response.LOOKUP3Response) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with LOOKUP3Response

use of org.apache.hadoop.nfs.nfs3.response.LOOKUP3Response in project hadoop by apache.

the class TestRpcProgramNfs3 method testLookup.

@Test(timeout = 60000)
public void testLookup() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    FileHandle handle = new FileHandle(dirId);
    LOOKUP3Request lookupReq = new LOOKUP3Request(handle, "bar");
    XDR xdr_req = new XDR();
    lookupReq.serialize(xdr_req);
    // Attempt by an unpriviledged user should fail.
    LOOKUP3Response response1 = nfsd.lookup(xdr_req.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a priviledged user should pass.
    LOOKUP3Response response2 = nfsd.lookup(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) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) LOOKUP3Request(org.apache.hadoop.nfs.nfs3.request.LOOKUP3Request) XDR(org.apache.hadoop.oncrpc.XDR) LOOKUP3Response(org.apache.hadoop.nfs.nfs3.response.LOOKUP3Response) Test(org.junit.Test)

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)2 LOOKUP3Request (org.apache.hadoop.nfs.nfs3.request.LOOKUP3Request)2 LOOKUP3Response (org.apache.hadoop.nfs.nfs3.response.LOOKUP3Response)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 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)1 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)1 XDR (org.apache.hadoop.oncrpc.XDR)1 Test (org.junit.Test)1