Search in sources :

Example 16 with VerifierNone

use of org.apache.hadoop.oncrpc.security.VerifierNone in project hadoop by apache.

the class RpcProgramNfs3 method handleInternal.

@Override
public void handleInternal(ChannelHandlerContext ctx, RpcInfo info) {
    RpcCall rpcCall = (RpcCall) info.header();
    final NFSPROC3 nfsproc3 = NFSPROC3.fromValue(rpcCall.getProcedure());
    int xid = rpcCall.getXid();
    byte[] data = new byte[info.data().readableBytes()];
    info.data().readBytes(data);
    XDR xdr = new XDR(data);
    XDR out = new XDR();
    InetAddress client = ((InetSocketAddress) info.remoteAddress()).getAddress();
    Credentials credentials = rpcCall.getCredential();
    // Ignore auth only for NFSPROC3_NULL, especially for Linux clients.
    if (nfsproc3 != NFSPROC3.NULL) {
        if (credentials.getFlavor() != AuthFlavor.AUTH_SYS && credentials.getFlavor() != AuthFlavor.RPCSEC_GSS) {
            LOG.info("Wrong RPC AUTH flavor, " + credentials.getFlavor() + " is not AUTH_SYS or RPCSEC_GSS.");
            XDR reply = new XDR();
            RpcDeniedReply rdr = new RpcDeniedReply(xid, RpcReply.ReplyState.MSG_ACCEPTED, RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
            rdr.write(reply);
            ChannelBuffer buf = ChannelBuffers.wrappedBuffer(reply.asReadOnlyWrap().buffer());
            RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
            RpcUtil.sendRpcResponse(ctx, rsp);
            return;
        }
    }
    if (!isIdempotent(rpcCall)) {
        RpcCallCache.CacheEntry entry = rpcCallCache.checkOrAddToCache(client, xid);
        if (entry != null) {
            // in cache
            if (entry.isCompleted()) {
                LOG.info("Sending the cached reply to retransmitted request " + xid);
                RpcUtil.sendRpcResponse(ctx, entry.getResponse());
                return;
            } else {
                // else request is in progress
                LOG.info("Retransmitted request, transaction still in progress " + xid);
                // Ignore the request and do nothing
                return;
            }
        }
    }
    // Since write and commit could be async, they use their own startTime and
    // only record success requests.
    final long startTime = System.nanoTime();
    NFS3Response response = null;
    if (nfsproc3 == NFSPROC3.NULL) {
        response = nullProcedure();
    } else if (nfsproc3 == NFSPROC3.GETATTR) {
        response = getattr(xdr, info);
        metrics.addGetattr(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.SETATTR) {
        response = setattr(xdr, info);
        metrics.addSetattr(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.LOOKUP) {
        response = lookup(xdr, info);
        metrics.addLookup(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.ACCESS) {
        response = access(xdr, info);
        metrics.addAccess(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.READLINK) {
        response = readlink(xdr, info);
        metrics.addReadlink(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.READ) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(Nfs3Utils.READ_RPC_START + xid);
        }
        response = read(xdr, info);
        if (LOG.isDebugEnabled() && (nfsproc3 == NFSPROC3.READ)) {
            LOG.debug(Nfs3Utils.READ_RPC_END + xid);
        }
        metrics.addRead(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.WRITE) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(Nfs3Utils.WRITE_RPC_START + xid);
        }
        response = write(xdr, info);
    // Write end debug trace is in Nfs3Utils.writeChannel
    } else if (nfsproc3 == NFSPROC3.CREATE) {
        response = create(xdr, info);
        metrics.addCreate(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.MKDIR) {
        response = mkdir(xdr, info);
        metrics.addMkdir(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.SYMLINK) {
        response = symlink(xdr, info);
        metrics.addSymlink(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.MKNOD) {
        response = mknod(xdr, info);
        metrics.addMknod(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.REMOVE) {
        response = remove(xdr, info);
        metrics.addRemove(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.RMDIR) {
        response = rmdir(xdr, info);
        metrics.addRmdir(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.RENAME) {
        response = rename(xdr, info);
        metrics.addRename(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.LINK) {
        response = link(xdr, info);
        metrics.addLink(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.READDIR) {
        response = readdir(xdr, info);
        metrics.addReaddir(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.READDIRPLUS) {
        response = readdirplus(xdr, info);
        metrics.addReaddirplus(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.FSSTAT) {
        response = fsstat(xdr, info);
        metrics.addFsstat(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.FSINFO) {
        response = fsinfo(xdr, info);
        metrics.addFsinfo(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.PATHCONF) {
        response = pathconf(xdr, info);
        metrics.addPathconf(Nfs3Utils.getElapsedTime(startTime));
    } else if (nfsproc3 == NFSPROC3.COMMIT) {
        response = commit(xdr, info);
    } else {
        // Invalid procedure
        RpcAcceptedReply.getInstance(xid, RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(out);
    }
    if (response == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No sync response, expect an async response for request XID=" + rpcCall.getXid());
        }
        return;
    }
    // TODO: currently we just return VerifierNone
    out = response.serialize(out, xid, new VerifierNone());
    ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap().buffer());
    RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
    if (!isIdempotent(rpcCall)) {
        rpcCallCache.callCompleted(client, xid, rsp);
    }
    RpcUtil.sendRpcResponse(ctx, rsp);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) XDR(org.apache.hadoop.oncrpc.XDR) RpcResponse(org.apache.hadoop.oncrpc.RpcResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) RpcCall(org.apache.hadoop.oncrpc.RpcCall) RpcDeniedReply(org.apache.hadoop.oncrpc.RpcDeniedReply) NFS3Response(org.apache.hadoop.nfs.nfs3.response.NFS3Response) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) NFSPROC3(org.apache.hadoop.nfs.nfs3.Nfs3Constant.NFSPROC3) InetAddress(java.net.InetAddress) Credentials(org.apache.hadoop.oncrpc.security.Credentials) RpcCallCache(org.apache.hadoop.oncrpc.RpcCallCache)

Example 17 with VerifierNone

use of org.apache.hadoop.oncrpc.security.VerifierNone 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 18 with VerifierNone

use of org.apache.hadoop.oncrpc.security.VerifierNone 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)

Example 19 with VerifierNone

use of org.apache.hadoop.oncrpc.security.VerifierNone in project hadoop by apache.

the class OpenFileCtx method processCommits.

private void processCommits(long offset) {
    Preconditions.checkState(offset > 0);
    long flushedOffset = getFlushedOffset();
    Entry<Long, CommitCtx> entry = pendingCommits.firstEntry();
    if (entry == null || entry.getValue().offset > flushedOffset) {
        return;
    }
    // Now do sync for the ready commits
    int status = Nfs3Status.NFS3ERR_IO;
    try {
        // Sync file data and length
        fos.hsync(EnumSet.of(SyncFlag.UPDATE_LENGTH));
        status = Nfs3Status.NFS3_OK;
    } catch (ClosedChannelException cce) {
        if (!pendingWrites.isEmpty()) {
            LOG.error("Can't sync for fileId: " + latestAttr.getFileId() + ". Channel closed with writes pending.", cce);
        }
        status = Nfs3Status.NFS3ERR_IO;
    } catch (IOException e) {
        LOG.error("Got stream error during data sync: ", e);
        // Do nothing. Stream will be closed eventually by StreamMonitor.
        status = Nfs3Status.NFS3ERR_IO;
    }
    // Update latestAttr
    try {
        latestAttr = Nfs3Utils.getFileAttr(client, Nfs3Utils.getFileIdPath(latestAttr.getFileId()), iug);
    } catch (IOException e) {
        LOG.error("Can't get new file attr, fileId: " + latestAttr.getFileId(), e);
        status = Nfs3Status.NFS3ERR_IO;
    }
    if (latestAttr.getSize() != offset) {
        LOG.error("After sync, the expect file size: " + offset + ", however actual file size is: " + latestAttr.getSize());
        status = Nfs3Status.NFS3ERR_IO;
    }
    WccData wccData = new WccData(Nfs3Utils.getWccAttr(latestAttr), latestAttr);
    // Send response for the ready commits
    while (entry != null && entry.getValue().offset <= flushedOffset) {
        pendingCommits.remove(entry.getKey());
        CommitCtx commit = entry.getValue();
        COMMIT3Response response = new COMMIT3Response(status, wccData, Nfs3Constant.WRITE_COMMIT_VERF);
        RpcProgramNfs3.metrics.addCommit(Nfs3Utils.getElapsedTime(commit.startTime));
        Nfs3Utils.writeChannelCommit(commit.getChannel(), response.serialize(new XDR(), commit.getXid(), new VerifierNone()), commit.getXid());
        if (LOG.isDebugEnabled()) {
            LOG.debug("FileId: " + latestAttr.getFileId() + " Service time: " + Nfs3Utils.getElapsedTime(commit.startTime) + "ns. Sent response for commit: " + commit);
        }
        entry = pendingCommits.firstEntry();
    }
}
Also used : WccData(org.apache.hadoop.nfs.nfs3.response.WccData) ClosedChannelException(java.nio.channels.ClosedChannelException) COMMIT3Response(org.apache.hadoop.nfs.nfs3.response.COMMIT3Response) XDR(org.apache.hadoop.oncrpc.XDR) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException)

Example 20 with VerifierNone

use of org.apache.hadoop.oncrpc.security.VerifierNone in project hadoop by apache.

the class TestOutOfOrderWrite method create.

static XDR create() {
    XDR request = new XDR();
    RpcCall.getInstance(0x8000004c, Nfs3Constant.PROGRAM, Nfs3Constant.VERSION, Nfs3Constant.NFSPROC3.CREATE.getValue(), new CredentialsNone(), new VerifierNone()).write(request);
    SetAttr3 objAttr = new SetAttr3();
    CREATE3Request createReq = new CREATE3Request(new FileHandle("/"), "out-of-order-write" + System.currentTimeMillis(), 0, objAttr, 0);
    createReq.serialize(request);
    return request;
}
Also used : SetAttr3(org.apache.hadoop.nfs.nfs3.request.SetAttr3) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) XDR(org.apache.hadoop.oncrpc.XDR) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) CredentialsNone(org.apache.hadoop.oncrpc.security.CredentialsNone) CREATE3Request(org.apache.hadoop.nfs.nfs3.request.CREATE3Request)

Aggregations

VerifierNone (org.apache.hadoop.oncrpc.security.VerifierNone)21 XDR (org.apache.hadoop.oncrpc.XDR)15 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)8 WRITE3Response (org.apache.hadoop.nfs.nfs3.response.WRITE3Response)6 IOException (java.io.IOException)5 CredentialsNone (org.apache.hadoop.oncrpc.security.CredentialsNone)5 Test (org.junit.Test)5 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)4 RpcCall (org.apache.hadoop.oncrpc.RpcCall)4 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4 WriteStableHow (org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow)3 WccAttr (org.apache.hadoop.nfs.nfs3.response.WccAttr)3 RpcResponse (org.apache.hadoop.oncrpc.RpcResponse)3 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)2 COMMIT3Response (org.apache.hadoop.nfs.nfs3.response.COMMIT3Response)2 Credentials (org.apache.hadoop.oncrpc.security.Credentials)2 Verifier (org.apache.hadoop.oncrpc.security.Verifier)2 File (java.io.File)1