Search in sources :

Example 1 with COMMIT3Request

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

the class COMMIT3Request method deserialize.

public static COMMIT3Request deserialize(XDR xdr) throws IOException {
    FileHandle handle = readHandle(xdr);
    long offset = xdr.readHyper();
    int count = xdr.readInt();
    return new COMMIT3Request(handle, offset, count);
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle)

Example 2 with COMMIT3Request

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

the class RpcProgramNfs3 method commit.

@VisibleForTesting
COMMIT3Response commit(XDR xdr, Channel channel, int xid, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    COMMIT3Response response = new COMMIT3Response(Nfs3Status.NFS3_OK);
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    COMMIT3Request request;
    try {
        request = COMMIT3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid COMMIT request");
        response.setStatus(Nfs3Status.NFS3ERR_INVAL);
        return response;
    }
    FileHandle handle = request.getHandle();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS COMMIT fileId: " + handle.getFileId() + " offset=" + request.getOffset() + " count=" + request.getCount() + " client: " + remoteAddress);
    }
    String fileIdPath = Nfs3Utils.getFileIdPath(handle);
    Nfs3FileAttributes preOpAttr = null;
    try {
        preOpAttr = Nfs3Utils.getFileAttr(dfsClient, fileIdPath, iug);
        if (preOpAttr == null) {
            LOG.info("Can't get path for fileId: " + handle.getFileId());
            return new COMMIT3Response(Nfs3Status.NFS3ERR_STALE);
        }
        if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
            return new COMMIT3Response(Nfs3Status.NFS3ERR_ACCES, new WccData(Nfs3Utils.getWccAttr(preOpAttr), preOpAttr), Nfs3Constant.WRITE_COMMIT_VERF);
        }
        long commitOffset = (request.getCount() == 0) ? 0 : (request.getOffset() + request.getCount());
        // Insert commit as an async request
        writeManager.handleCommit(dfsClient, handle, commitOffset, channel, xid, preOpAttr);
        return null;
    } catch (IOException e) {
        LOG.warn("Exception ", e);
        Nfs3FileAttributes postOpAttr = null;
        try {
            postOpAttr = writeManager.getFileAttr(dfsClient, handle, iug);
        } catch (IOException e1) {
            LOG.info("Can't get postOpAttr for fileId: " + handle.getFileId(), e1);
        }
        WccData fileWcc = new WccData(Nfs3Utils.getWccAttr(preOpAttr), postOpAttr);
        int status = mapErrorStatus(e);
        return new COMMIT3Response(status, fileWcc, Nfs3Constant.WRITE_COMMIT_VERF);
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) WccData(org.apache.hadoop.nfs.nfs3.response.WccData) COMMIT3Response(org.apache.hadoop.nfs.nfs3.response.COMMIT3Response) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) IOException(java.io.IOException) COMMIT3Request(org.apache.hadoop.nfs.nfs3.request.COMMIT3Request) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with COMMIT3Request

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

the class TestRpcProgramNfs3 method testCommit.

@Test(timeout = 60000)
public void testCommit() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
    long dirId = status.getFileId();
    FileHandle handle = new FileHandle(dirId);
    XDR xdr_req = new XDR();
    COMMIT3Request req = new COMMIT3Request(handle, 0, 5);
    req.serialize(xdr_req);
    Channel ch = Mockito.mock(Channel.class);
    // Attempt by an unpriviledged user should fail.
    COMMIT3Response response1 = nfsd.commit(xdr_req.asReadOnlyWrap(), ch, 1, securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a priviledged user should pass.
    COMMIT3Response response2 = nfsd.commit(xdr_req.asReadOnlyWrap(), ch, 1, securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect COMMIT3Response:", null, response2);
}
Also used : COMMIT3Response(org.apache.hadoop.nfs.nfs3.response.COMMIT3Response) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) Channel(org.jboss.netty.channel.Channel) COMMIT3Request(org.apache.hadoop.nfs.nfs3.request.COMMIT3Request) Test(org.junit.Test)

Example 4 with COMMIT3Request

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

the class TestRpcProgramNfs3 method commit.

private void commit(String fileName, int len) throws Exception {
    final HdfsFileStatus status = nn.getRpcServer().getFileInfo(fileName);
    final long dirId = status.getFileId();
    final FileHandle handle = new FileHandle(dirId);
    final XDR xdr_req = new XDR();
    final COMMIT3Request req = new COMMIT3Request(handle, 0, len);
    req.serialize(xdr_req);
    Channel ch = Mockito.mock(Channel.class);
    COMMIT3Response response2 = nfsd.commit(xdr_req.asReadOnlyWrap(), ch, 1, securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect COMMIT3Response:", null, response2);
}
Also used : COMMIT3Response(org.apache.hadoop.nfs.nfs3.response.COMMIT3Response) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) Channel(org.jboss.netty.channel.Channel) COMMIT3Request(org.apache.hadoop.nfs.nfs3.request.COMMIT3Request)

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)4 COMMIT3Request (org.apache.hadoop.nfs.nfs3.request.COMMIT3Request)3 COMMIT3Response (org.apache.hadoop.nfs.nfs3.response.COMMIT3Response)3 InetSocketAddress (java.net.InetSocketAddress)2 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)2 XDR (org.apache.hadoop.oncrpc.XDR)2 Channel (org.jboss.netty.channel.Channel)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)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 Test (org.junit.Test)1