Search in sources :

Example 16 with WccData

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

the class RpcProgramNfs3 method setattr.

@VisibleForTesting
SETATTR3Response setattr(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    SETATTR3Response response = new SETATTR3Response(Nfs3Status.NFS3_OK);
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    SETATTR3Request request;
    try {
        request = SETATTR3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid SETATTR request");
        response.setStatus(Nfs3Status.NFS3ERR_INVAL);
        return response;
    }
    FileHandle handle = request.getHandle();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS SETATTR fileId: " + handle.getFileId() + " client: " + remoteAddress);
    }
    if (request.getAttr().getUpdateFields().contains(SetAttrField.SIZE)) {
        LOG.error("Setting file size is not supported when setattr, fileId: " + handle.getFileId());
        response.setStatus(Nfs3Status.NFS3ERR_INVAL);
        return response;
    }
    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());
            response.setStatus(Nfs3Status.NFS3ERR_STALE);
            return response;
        }
        WccAttr preOpWcc = Nfs3Utils.getWccAttr(preOpAttr);
        if (request.isCheck()) {
            if (!preOpAttr.getCtime().equals(request.getCtime())) {
                WccData wccData = new WccData(preOpWcc, preOpAttr);
                return new SETATTR3Response(Nfs3Status.NFS3ERR_NOT_SYNC, wccData);
            }
        }
        // check the write access privilege
        if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
            return new SETATTR3Response(Nfs3Status.NFS3ERR_ACCES, new WccData(preOpWcc, preOpAttr));
        }
        setattrInternal(dfsClient, fileIdPath, request.getAttr(), true);
        Nfs3FileAttributes postOpAttr = Nfs3Utils.getFileAttr(dfsClient, fileIdPath, iug);
        WccData wccData = new WccData(preOpWcc, postOpAttr);
        return new SETATTR3Response(Nfs3Status.NFS3_OK, wccData);
    } catch (IOException e) {
        LOG.warn("Exception ", e);
        WccData wccData = null;
        try {
            wccData = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(preOpAttr), dfsClient, fileIdPath, iug);
        } catch (IOException e1) {
            LOG.info("Can't get postOpAttr for fileIdPath: " + fileIdPath, e1);
        }
        int status = mapErrorStatus(e);
        return new SETATTR3Response(status, wccData);
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) WccData(org.apache.hadoop.nfs.nfs3.response.WccData) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) WccAttr(org.apache.hadoop.nfs.nfs3.response.WccAttr) SETATTR3Response(org.apache.hadoop.nfs.nfs3.response.SETATTR3Response) SETATTR3Request(org.apache.hadoop.nfs.nfs3.request.SETATTR3Request) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 17 with WccData

use of org.apache.hadoop.nfs.nfs3.response.WccData 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 18 with WccData

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

the class RpcProgramNfs3 method remove.

@VisibleForTesting
REMOVE3Response remove(XDR xdr, SecurityHandler securityHandler, SocketAddress remoteAddress) {
    REMOVE3Response response = new REMOVE3Response(Nfs3Status.NFS3_OK);
    DFSClient dfsClient = clientCache.getDfsClient(securityHandler.getUser());
    if (dfsClient == null) {
        response.setStatus(Nfs3Status.NFS3ERR_SERVERFAULT);
        return response;
    }
    REMOVE3Request request;
    try {
        request = REMOVE3Request.deserialize(xdr);
    } catch (IOException e) {
        LOG.error("Invalid REMOVE request");
        return new REMOVE3Response(Nfs3Status.NFS3ERR_INVAL);
    }
    FileHandle dirHandle = request.getHandle();
    String fileName = request.getName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("NFS REMOVE dir fileId: " + dirHandle.getFileId() + " fileName: " + fileName + " client: " + remoteAddress);
    }
    String dirFileIdPath = Nfs3Utils.getFileIdPath(dirHandle);
    Nfs3FileAttributes preOpDirAttr = null;
    Nfs3FileAttributes postOpDirAttr = null;
    try {
        preOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
        if (preOpDirAttr == null) {
            LOG.info("Can't get path for dir fileId: " + dirHandle.getFileId());
            return new REMOVE3Response(Nfs3Status.NFS3ERR_STALE);
        }
        WccData errWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr), preOpDirAttr);
        if (!checkAccessPrivilege(remoteAddress, AccessPrivilege.READ_WRITE)) {
            return new REMOVE3Response(Nfs3Status.NFS3ERR_ACCES, errWcc);
        }
        String fileIdPath = dirFileIdPath + "/" + fileName;
        HdfsFileStatus fstat = Nfs3Utils.getFileStatus(dfsClient, fileIdPath);
        if (fstat == null) {
            return new REMOVE3Response(Nfs3Status.NFS3ERR_NOENT, errWcc);
        }
        if (fstat.isDir()) {
            return new REMOVE3Response(Nfs3Status.NFS3ERR_ISDIR, errWcc);
        }
        boolean result = dfsClient.delete(fileIdPath, false);
        WccData dirWcc = Nfs3Utils.createWccData(Nfs3Utils.getWccAttr(preOpDirAttr), dfsClient, dirFileIdPath, iug);
        if (!result) {
            return new REMOVE3Response(Nfs3Status.NFS3ERR_ACCES, dirWcc);
        }
        return new REMOVE3Response(Nfs3Status.NFS3_OK, dirWcc);
    } catch (IOException e) {
        LOG.warn("Exception ", e);
        // Try to return correct WccData
        if (postOpDirAttr == null) {
            try {
                postOpDirAttr = Nfs3Utils.getFileAttr(dfsClient, dirFileIdPath, iug);
            } catch (IOException e1) {
                LOG.info("Can't get postOpDirAttr for " + dirFileIdPath, e1);
            }
        }
        WccData dirWcc = new WccData(Nfs3Utils.getWccAttr(preOpDirAttr), postOpDirAttr);
        int status = mapErrorStatus(e);
        return new REMOVE3Response(status, dirWcc);
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) WccData(org.apache.hadoop.nfs.nfs3.response.WccData) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) IOException(java.io.IOException) REMOVE3Response(org.apache.hadoop.nfs.nfs3.response.REMOVE3Response) REMOVE3Request(org.apache.hadoop.nfs.nfs3.request.REMOVE3Request) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 19 with WccData

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

the class OpenFileCtx method receivedNewWriteInternal.

private void receivedNewWriteInternal(DFSClient dfsClient, WRITE3Request request, Channel channel, int xid, AsyncDataService asyncDataService, IdMappingServiceProvider iug) {
    WriteStableHow stableHow = request.getStableHow();
    WccAttr preOpAttr = latestAttr.getWccAttr();
    int count = request.getCount();
    WriteCtx writeCtx = addWritesToCache(request, channel, xid);
    if (writeCtx == null) {
        // offset < nextOffset
        processOverWrite(dfsClient, request, channel, xid, iug);
    } else {
        // The write is added to pendingWrites.
        // Check and start writing back if necessary
        boolean startWriting = checkAndStartWrite(asyncDataService, writeCtx);
        if (!startWriting) {
            // offset > nextOffset. check if we need to dump data
            waitForDump();
            // for unstable non-sequential write
            if (stableHow != WriteStableHow.UNSTABLE) {
                LOG.info("Have to change stable write to unstable write: " + request.getStableHow());
                stableHow = WriteStableHow.UNSTABLE;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("UNSTABLE write request, send response for offset: " + writeCtx.getOffset());
            }
            WccData fileWcc = new WccData(preOpAttr, latestAttr);
            WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK, fileWcc, count, stableHow, Nfs3Constant.WRITE_COMMIT_VERF);
            RpcProgramNfs3.metrics.addWrite(Nfs3Utils.getElapsedTime(writeCtx.startTime));
            Nfs3Utils.writeChannel(channel, response.serialize(new XDR(), xid, new VerifierNone()), xid);
            writeCtx.setReplied(true);
        }
    }
}
Also used : WccData(org.apache.hadoop.nfs.nfs3.response.WccData) WriteStableHow(org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow) XDR(org.apache.hadoop.oncrpc.XDR) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) WccAttr(org.apache.hadoop.nfs.nfs3.response.WccAttr) WRITE3Response(org.apache.hadoop.nfs.nfs3.response.WRITE3Response)

Example 20 with WccData

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

the class OpenFileCtx method receivedNewWrite.

public void receivedNewWrite(DFSClient dfsClient, WRITE3Request request, Channel channel, int xid, AsyncDataService asyncDataService, IdMappingServiceProvider iug) {
    if (!activeState) {
        LOG.info("OpenFileCtx is inactive, fileId: " + request.getHandle().getFileId());
        WccData fileWcc = new WccData(latestAttr.getWccAttr(), latestAttr);
        WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO, fileWcc, 0, request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF);
        Nfs3Utils.writeChannel(channel, response.serialize(new XDR(), xid, new VerifierNone()), xid);
    } else {
        // Update the write time first
        updateLastAccessTime();
        // Handle repeated write requests (same xid or not).
        // If already replied, send reply again. If not replied, drop the
        // repeated request.
        WriteCtx existantWriteCtx = checkRepeatedWriteRequest(request, channel, xid);
        if (existantWriteCtx != null) {
            if (!existantWriteCtx.getReplied()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Repeated write request which hasn't been served: xid=" + xid + ", drop it.");
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Repeated write request which is already served: xid=" + xid + ", resend response.");
                }
                WccData fileWcc = new WccData(latestAttr.getWccAttr(), latestAttr);
                WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK, fileWcc, request.getCount(), request.getStableHow(), Nfs3Constant.WRITE_COMMIT_VERF);
                Nfs3Utils.writeChannel(channel, response.serialize(new XDR(), xid, new VerifierNone()), xid);
            }
        } else {
            // not a repeated write request
            receivedNewWriteInternal(dfsClient, request, channel, xid, asyncDataService, iug);
        }
    }
}
Also used : WccData(org.apache.hadoop.nfs.nfs3.response.WccData) XDR(org.apache.hadoop.oncrpc.XDR) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) WRITE3Response(org.apache.hadoop.nfs.nfs3.response.WRITE3Response)

Aggregations

Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)17 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)17 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)16 IOException (java.io.IOException)15 VisibleForTesting (com.google.common.annotations.VisibleForTesting)9 DFSClient (org.apache.hadoop.hdfs.DFSClient)9 WRITE3Response (org.apache.hadoop.nfs.nfs3.response.WRITE3Response)8 XDR (org.apache.hadoop.oncrpc.XDR)8 VerifierNone (org.apache.hadoop.oncrpc.security.VerifierNone)8 WccAttr (org.apache.hadoop.nfs.nfs3.response.WccAttr)6 WriteStableHow (org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow)5 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)3 COMMIT3Response (org.apache.hadoop.nfs.nfs3.response.COMMIT3Response)3 ClosedChannelException (java.nio.channels.ClosedChannelException)2 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 HdfsDataOutputStream (org.apache.hadoop.hdfs.client.HdfsDataOutputStream)2 SetAttr3 (org.apache.hadoop.nfs.nfs3.request.SetAttr3)2 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1