Search in sources :

Example 6 with SetAttr3

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

the class TestRpcProgramNfs3 method testCreate.

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

Example 7 with SetAttr3

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

the class TestRpcProgramNfs3 method testReadlink.

@Test(timeout = 60000)
public void testReadlink() throws Exception {
    // Create a symlink first.
    HdfsFileStatus status = nn.getRpcServer().getFileInfo(testdir);
    long dirId = status.getFileId();
    XDR xdr_req = new XDR();
    FileHandle handle = new FileHandle(dirId);
    SYMLINK3Request req = new SYMLINK3Request(handle, "fubar", new SetAttr3(), "bar");
    req.serialize(xdr_req);
    SYMLINK3Response response = nfsd.symlink(xdr_req.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response.getStatus());
    // Now perform readlink operations.
    FileHandle handle2 = response.getObjFileHandle();
    XDR xdr_req2 = new XDR();
    READLINK3Request req2 = new READLINK3Request(handle2);
    req2.serialize(xdr_req2);
    // Attempt by an unpriviledged user should fail.
    READLINK3Response response1 = nfsd.readlink(xdr_req2.asReadOnlyWrap(), securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a priviledged user should pass.
    READLINK3Response response2 = nfsd.readlink(xdr_req2.asReadOnlyWrap(), securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3_OK, response2.getStatus());
}
Also used : SYMLINK3Request(org.apache.hadoop.nfs.nfs3.request.SYMLINK3Request) SetAttr3(org.apache.hadoop.nfs.nfs3.request.SetAttr3) READLINK3Request(org.apache.hadoop.nfs.nfs3.request.READLINK3Request) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) READLINK3Response(org.apache.hadoop.nfs.nfs3.response.READLINK3Response) SYMLINK3Response(org.apache.hadoop.nfs.nfs3.response.SYMLINK3Response) Test(org.junit.Test)

Example 8 with SetAttr3

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

the class MKNOD3Request method deserialize.

public static MKNOD3Request deserialize(XDR xdr) throws IOException {
    FileHandle handle = readHandle(xdr);
    String name = xdr.readString();
    int type = xdr.readInt();
    SetAttr3 objAttr = new SetAttr3();
    Specdata3 spec = null;
    if (type == NfsFileType.NFSCHR.toValue() || type == NfsFileType.NFSBLK.toValue()) {
        objAttr.deserialize(xdr);
        spec = new Specdata3(xdr.readInt(), xdr.readInt());
    } else if (type == NfsFileType.NFSSOCK.toValue() || type == NfsFileType.NFSFIFO.toValue()) {
        objAttr.deserialize(xdr);
    }
    return new MKNOD3Request(handle, name, type, objAttr, spec);
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Specdata3(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes.Specdata3)

Example 9 with SetAttr3

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

the class SYMLINK3Request method deserialize.

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

Example 10 with SetAttr3

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

the class RpcProgramNfs3 method create.

@VisibleForTesting
CREATE3Response create(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    CREATE3Response response = new CREATE3Response(Nfs3Status.NFS3_OK);
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    CREATE3Request request;
    try {
        request = CREATE3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid CREATE request");
        return new CREATE3Response(Nfs3Status.NFS3ERR_INVAL);
    }
    FileHandle dirHandle = request.getHandle();
    String fileName = request.getName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS CREATE dir fileId: " + dirHandle.getFileId() + " filename: " + fileName + " client: " + remoteAddress);
    }
    int createMode = request.getMode();
    if ((createMode != Nfs3Constant.CREATE_EXCLUSIVE) && request.getObjAttr().getUpdateFields().contains(SetAttrField.SIZE) && request.getObjAttr().getSize() != 0) {
        LOG.error("Setting file size is not supported when creating file: " + fileName + " dir fileId: " + dirHandle.getFileId());
        return new CREATE3Response(Nfs3Status.NFS3ERR_INVAL);
    }
    HdfsDataOutputStream fos = null;
    String dirFileIdPath = Nfs3Utils.getFileIdPath(dirHandle);
    Nfs3FileAttributes preOpDirAttr = null;
    Nfs3FileAttributes postOpObjAttr = null;
    FileHandle fileHandle = null;
    WccData dirWcc = null;
    try {
        preOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
        if (preOpDirAttr == null) {
            LOG.error("Can't get path for dirHandle: " + dirHandle);
            return new CREATE3Response(Nfs3Status.NFS3ERR_STALE);
        }
        if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
            return new CREATE3Response(Nfs3Status.NFS3ERR_ACCES, null, preOpDirAttr, new WccData(Nfs3Utils.getWccAttr(preOpDirAttr), preOpDirAttr));
        }
        String fileIdPath = Nfs3Utils.getFileIdPath(dirHandle) + "/" + fileName;
        SetAttr3 setAttr3 = request.getObjAttr();
        assert (setAttr3 != null);
        FsPermission permission = setAttr3.getUpdateFields().contains(SetAttrField.MODE) ? new FsPermission((short) setAttr3.getMode()) : FsPermission.getDefault().applyUMask(umask);
        EnumSet<CreateFlag> flag = (createMode != Nfs3Constant.CREATE_EXCLUSIVE) ? EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE) : EnumSet.of(CreateFlag.CREATE);
        fos = dfsClient.createWrappedOutputStream(dfsClient.create(fileIdPath, permission, flag, false, replication, blockSize, null, bufferSize, null), null);
        if ((createMode == Nfs3Constant.CREATE_UNCHECKED) || (createMode == Nfs3Constant.CREATE_GUARDED)) {
            // Set group if it's not specified in the request.
            if (!setAttr3.getUpdateFields().contains(SetAttrField.GID)) {
                setAttr3.getUpdateFields().add(SetAttrField.GID);
                setAttr3.setGid(securityHandler.getGid());
            }
            setattrInternal(dfsClient, fileIdPath, setAttr3, false);
        }
        postOpObjAttr = Nfs3Utils.getFileAttr(dfsClient, fileIdPath, iug);
        dirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(preOpDirAttr), dfsClient, dirFileIdPath, iug);
        // Add open stream
        OpenFileCtx openFileCtx = new OpenFileCtx(fos, postOpObjAttr, writeDumpDir + "/" + postOpObjAttr.getFileId(), dfsClient, iug, aixCompatMode, config);
        fileHandle = new FileHandle(postOpObjAttr.getFileId());
        if (!writeManager.addOpenFileStream(fileHandle, openFileCtx)) {
            LOG.warn("Can't add more stream, close it." + " Future write will become append");
            fos.close();
            fos = null;
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Opened stream for file: " + fileName + ", fileId: " + fileHandle.getFileId());
            }
        }
    } catch (IOException e) {
        LOG.error("Exception", e);
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e1) {
                LOG.error("Can't close stream for dirFileId: " + dirHandle.getFileId() + " filename: " + fileName, e1);
            }
        }
        if (dirWcc == null) {
            try {
                dirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(preOpDirAttr), dfsClient, dirFileIdPath, iug);
            } catch (IOException e1) {
                LOG.error("Can't get postOpDirAttr for dirFileId: " + dirHandle.getFileId(), e1);
            }
        }
        int status = mapErrorStatus(e);
        return new CREATE3Response(status, fileHandle, postOpObjAttr, dirWcc);
    }
    return new CREATE3Response(Nfs3Status.NFS3_OK, fileHandle, postOpObjAttr, dirWcc);
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) WccData(org.apache.hadoop.nfs.nfs3.response.WccData) CreateFlag(org.apache.hadoop.fs.CreateFlag) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) IOException(java.io.IOException) SetAttr3(org.apache.hadoop.nfs.nfs3.request.SetAttr3) CREATE3Response(org.apache.hadoop.nfs.nfs3.response.CREATE3Response) HdfsDataOutputStream(org.apache.hadoop.hdfs.client.HdfsDataOutputStream) FsPermission(org.apache.hadoop.fs.permission.FsPermission) CREATE3Request(org.apache.hadoop.nfs.nfs3.request.CREATE3Request) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)16 SetAttr3 (org.apache.hadoop.nfs.nfs3.request.SetAttr3)11 XDR (org.apache.hadoop.oncrpc.XDR)9 InetSocketAddress (java.net.InetSocketAddress)8 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)8 Test (org.junit.Test)8 CREATE3Request (org.apache.hadoop.nfs.nfs3.request.CREATE3Request)6 DFSClient (org.apache.hadoop.hdfs.DFSClient)5 CREATE3Response (org.apache.hadoop.nfs.nfs3.response.CREATE3Response)5 IOException (java.io.IOException)3 FsPermission (org.apache.hadoop.fs.permission.FsPermission)3 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)3 NfsConfiguration (org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration)3 READ3Request (org.apache.hadoop.nfs.nfs3.request.READ3Request)3 WRITE3Request (org.apache.hadoop.nfs.nfs3.request.WRITE3Request)3 READ3Response (org.apache.hadoop.nfs.nfs3.response.READ3Response)3 SecurityHandler (org.apache.hadoop.oncrpc.security.SecurityHandler)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)2 MKDIR3Request (org.apache.hadoop.nfs.nfs3.request.MKDIR3Request)2