/// <exception cref="System.IO.IOException"/> internal virtual Nfs3FileAttributes GetFileAttr(DFSClient client, FileHandle dirHandle , string fileName) { string fileIdPath = Nfs3Utils.GetFileIdPath(dirHandle) + "/" + fileName; Nfs3FileAttributes attr = Nfs3Utils.GetFileAttr(client, fileIdPath, iug); if ((attr != null) && (attr.GetType() == NfsFileType.Nfsreg.ToValue())) { OpenFileCtx openFileCtx = fileContextCache.Get(new FileHandle(attr.GetFileId())); if (openFileCtx != null) { attr.SetSize(openFileCtx.GetNextOffset()); attr.SetUsed(openFileCtx.GetNextOffset()); } } return(attr); }
internal virtual void HandleCommit(DFSClient dfsClient, FileHandle fileHandle, long commitOffset, Org.Jboss.Netty.Channel.Channel channel, int xid, Nfs3FileAttributes preOpAttr) { long startTime = Runtime.NanoTime(); int status; OpenFileCtx openFileCtx = fileContextCache.Get(fileHandle); if (openFileCtx == null) { Log.Info("No opened stream for fileId: " + fileHandle.GetFileId() + " commitOffset=" + commitOffset + ". Return success in this case."); status = Nfs3Status.Nfs3Ok; } else { OpenFileCtx.COMMIT_STATUS ret = openFileCtx.CheckCommit(dfsClient, commitOffset, channel, xid, preOpAttr, false); switch (ret) { case OpenFileCtx.COMMIT_STATUS.CommitFinished: case OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx: { status = Nfs3Status.Nfs3Ok; break; } case OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite: case OpenFileCtx.COMMIT_STATUS.CommitError: { status = Nfs3Status.Nfs3errIo; break; } case OpenFileCtx.COMMIT_STATUS.CommitWait: { // Do nothing. Commit is async now. return; } case OpenFileCtx.COMMIT_STATUS.CommitSpecialWait: { status = Nfs3Status.Nfs3errJukebox; break; } case OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess: { status = Nfs3Status.Nfs3Ok; break; } default: { Log.Error("Should not get commit return code: " + ret.ToString()); throw new RuntimeException("Should not get commit return code: " + ret.ToString() ); } } } // Send out the response Nfs3FileAttributes postOpAttr = null; try { postOpAttr = GetFileAttr(dfsClient, new FileHandle(preOpAttr.GetFileId()), iug); } catch (IOException e1) { Log.Info("Can't get postOpAttr for fileId: " + preOpAttr.GetFileId(), e1); } WccData fileWcc = new WccData(Nfs3Utils.GetWccAttr(preOpAttr), postOpAttr); COMMIT3Response response = new COMMIT3Response(status, fileWcc, Nfs3Constant.WriteCommitVerf ); RpcProgramNfs3.metrics.AddCommit(Nfs3Utils.GetElapsedTime(startTime)); Nfs3Utils.WriteChannelCommit(channel, response.Serialize(new XDR(), xid, new VerifierNone ()), xid); }