Search in sources :

Example 1 with GETATTR3Request

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

the class RpcProgramNfs3 method getattr.

@VisibleForTesting
GETATTR3Response getattr(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    GETATTR3Response response = new GETATTR3Response(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;
    }
    GETATTR3Request request;
    try {
        request = GETATTR3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid GETATTR request");
        response.setStatus(Nfs3Status.NFS3ERR_INVAL);
        return response;
    }
    FileHandle handle = request.getHandle();
    if (LOG.isDebugEnabled()) {
        LOG.debug("GETATTR for fileId: " + handle.getFileId() + " client: " + remoteAddress);
    }
    Nfs3FileAttributes attrs = null;
    try {
        attrs = writeManager.getFileAttr(dfsClient, handle, iug);
    } catch (RemoteException r) {
        LOG.warn("Exception ", r);
        IOException io = r.unwrapRemoteException();
        /**
       * AuthorizationException can be thrown if the user can't be proxy'ed.
       */
        if (io instanceof AuthorizationException) {
            return new GETATTR3Response(Nfs3Status.NFS3ERR_ACCES);
        } else {
            return new GETATTR3Response(Nfs3Status.NFS3ERR_IO);
        }
    } catch (IOException e) {
        LOG.info("Can't get file attribute, fileId=" + handle.getFileId(), e);
        int status = mapErrorStatus(e);
        response.setStatus(status);
        return response;
    }
    if (attrs == null) {
        LOG.error("Can't get path for fileId: " + handle.getFileId());
        response.setStatus(Nfs3Status.NFS3ERR_STALE);
        return response;
    }
    response.setPostOpAttr(attrs);
    return response;
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) IOException(java.io.IOException) GETATTR3Response(org.apache.hadoop.nfs.nfs3.response.GETATTR3Response) RemoteException(org.apache.hadoop.ipc.RemoteException) GETATTR3Request(org.apache.hadoop.nfs.nfs3.request.GETATTR3Request) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with GETATTR3Request

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

the class TestRpcProgramNfs3 method testGetattr.

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

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)2 GETATTR3Request (org.apache.hadoop.nfs.nfs3.request.GETATTR3Request)2 GETATTR3Response (org.apache.hadoop.nfs.nfs3.response.GETATTR3Response)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 RemoteException (org.apache.hadoop.ipc.RemoteException)1 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)1 XDR (org.apache.hadoop.oncrpc.XDR)1 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)1 Test (org.junit.Test)1