Search in sources :

Example 1 with RENAME3Request

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

the class RENAME3Request method deserialize.

public static RENAME3Request deserialize(XDR xdr) throws IOException {
    FileHandle fromDirHandle = readHandle(xdr);
    String fromName = xdr.readString();
    FileHandle toDirHandle = readHandle(xdr);
    String toName = xdr.readString();
    return new RENAME3Request(fromDirHandle, fromName, toDirHandle, toName);
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle)

Example 2 with RENAME3Request

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

the class RpcProgramNfs3 method rename.

@VisibleForTesting
RENAME3Response rename(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    RENAME3Response response = new RENAME3Response(Nfs3Status.NFS3_OK);
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    RENAME3Request request = null;
    try {
        request = RENAME3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid RENAME request");
        return new RENAME3Response(Nfs3Status.NFS3ERR_INVAL);
    }
    FileHandle fromHandle = request.getFromDirHandle();
    String fromName = request.getFromName();
    FileHandle toHandle = request.getToDirHandle();
    String toName = request.getToName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS RENAME from: " + fromHandle.getFileId() + "/" + fromName + " to: " + toHandle.getFileId() + "/" + toName + " client: " + remoteAddress);
    }
    String fromDirFileIdPath = Nfs3Utils.getFileIdPath(fromHandle);
    String toDirFileIdPath = Nfs3Utils.getFileIdPath(toHandle);
    Nfs3FileAttributes fromPreOpAttr = null;
    Nfs3FileAttributes toPreOpAttr = null;
    WccData fromDirWcc = null;
    WccData toDirWcc = null;
    try {
        fromPreOpAttr = Nfs3Utils.getFileAttr(dfsClient, fromDirFileIdPath, iug);
        if (fromPreOpAttr == null) {
            LOG.info("Can't get path for fromHandle fileId: " + fromHandle.getFileId());
            return new RENAME3Response(Nfs3Status.NFS3ERR_STALE);
        }
        toPreOpAttr = Nfs3Utils.getFileAttr(dfsClient, toDirFileIdPath, iug);
        if (toPreOpAttr == null) {
            LOG.info("Can't get path for toHandle fileId: " + toHandle.getFileId());
            return new RENAME3Response(Nfs3Status.NFS3ERR_STALE);
        }
        if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
            WccData fromWcc = new WccData(Nfs3Utils.getWccAttr(fromPreOpAttr), fromPreOpAttr);
            WccData toWcc = new WccData(Nfs3Utils.getWccAttr(toPreOpAttr), toPreOpAttr);
            return new RENAME3Response(Nfs3Status.NFS3ERR_ACCES, fromWcc, toWcc);
        }
        String src = fromDirFileIdPath + "/" + fromName;
        String dst = toDirFileIdPath + "/" + toName;
        dfsClient.rename(src, dst, Options.Rename.NONE);
        // Assemble the reply
        fromDirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(fromPreOpAttr), dfsClient, fromDirFileIdPath, iug);
        toDirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(toPreOpAttr), dfsClient, toDirFileIdPath, iug);
        return new RENAME3Response(Nfs3Status.NFS3_OK, fromDirWcc, toDirWcc);
    } catch (IOException e) {
        LOG.warn("Exception ", e);
        // Try to return correct WccData
        try {
            fromDirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(fromPreOpAttr), dfsClient, fromDirFileIdPath, iug);
            toDirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(toPreOpAttr), dfsClient, toDirFileIdPath, iug);
        } catch (IOException e1) {
            LOG.info("Can't get postOpDirAttr for " + fromDirFileIdPath + " or" + toDirFileIdPath, e1);
        }
        int status = mapErrorStatus(e);
        return new RENAME3Response(status, fromDirWcc, toDirWcc);
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) WccData(org.apache.hadoop.nfs.nfs3.response.WccData) RENAME3Request(org.apache.hadoop.nfs.nfs3.request.RENAME3Request) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) RENAME3Response(org.apache.hadoop.nfs.nfs3.response.RENAME3Response) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with RENAME3Request

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

the class TestRpcProgramNfs3 method testRename.

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

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)3 RENAME3Request (org.apache.hadoop.nfs.nfs3.request.RENAME3Request)2 RENAME3Response (org.apache.hadoop.nfs.nfs3.response.RENAME3Response)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 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)1 XDR (org.apache.hadoop.oncrpc.XDR)1 Test (org.junit.Test)1