nfs4: Use unstable writes and commit before close

This commit is contained in:
Pawel Dziepak
2012-07-27 03:08:46 +02:00
parent be4499d19e
commit 36577ed54b
8 changed files with 64 additions and 1 deletions
@@ -34,6 +34,8 @@ public:
status_t GetChangeInfo(uint64* change);
status_t Commit();
status_t LookUp(const char* name, ino_t* id);
status_t CreateLink(const char* name, const char* path,
@@ -456,3 +456,29 @@ Inode::Write(OpenFileCookie* cookie, off_t pos, const void* _buffer,
return B_OK;
}
status_t
Inode::Commit()
{
do {
RPC::Server* serv = fFileSystem->Server();
Request request(serv);
RequestBuilder& req = request.Builder();
req.PutFH(fInfo.fHandle);
req.Commit(0, 0);
status_t result = request.Send();
if (result != B_OK)
return result;
ReplyInterpreter& reply = request.Reply();
if (_HandleErrors(reply.NFS4Error(), serv))
continue;
reply.PutFH();
return reply.Commit();
} while (true);
}
@@ -23,6 +23,7 @@ enum Procedure {
enum Opcode {
OpAccess = 3,
OpClose = 4,
OpCommit = 5,
OpCreate = 6,
OpGetAttr = 9,
OpGetFH = 10,
@@ -125,6 +125,19 @@ ReplyInterpreter::Close()
}
status_t
ReplyInterpreter::Commit()
{
status_t res = _OperationError(OpCommit);
if (res != B_OK)
return res;
fReply->Stream().GetOpaque(NULL);
return fReply->Stream().IsEOF() ? B_BAD_VALUE : B_OK;
}
status_t
ReplyInterpreter::Create(uint64* before, uint64* after, bool& atomic)
{
@@ -69,6 +69,7 @@ public:
status_t Access(uint32* supported, uint32* allowed);
status_t Close();
status_t Commit();
status_t Create(uint64* before, uint64* after, bool& atomic);
status_t GetAttr(AttrValue** attrs, uint32* count);
status_t GetFH(FileHandle* fh);
@@ -89,6 +89,24 @@ RequestBuilder::Close(uint32 seq, const uint32* id, uint32 stateSeq)
}
status_t
RequestBuilder::Commit(uint64 offset, uint32 count)
{
if (fProcedure != ProcCompound)
return B_BAD_VALUE;
if (fRequest == NULL)
return B_NO_MEMORY;
fRequest->Stream().AddUInt(OpCommit);
fRequest->Stream().AddUHyper(offset);
fRequest->Stream().AddUInt(count);
fOpCount++;
return B_OK;
}
status_t
RequestBuilder::Create(FileType type, const char* name, AttrValue* attr,
uint32 count, const char* path)
@@ -729,7 +747,7 @@ RequestBuilder::Write(const uint32* id, uint32 stateSeq, const void* buffer,
fRequest->Stream().AddUInt(id[1]);
fRequest->Stream().AddUInt(id[2]);
fRequest->Stream().AddUHyper(pos);
fRequest->Stream().AddInt(FILE_SYNC4);
fRequest->Stream().AddInt(UNSTABLE4);
fRequest->Stream().AddOpaque(buffer, len);
fOpCount++;
@@ -33,6 +33,7 @@ public:
status_t Access();
status_t Close(uint32 seq, const uint32* id,
uint32 stateSeq);
status_t Commit(uint64 offset, uint32 count);
status_t Create(FileType type, const char* name,
AttrValue* attr, uint32 count,
const char* path = NULL);
@@ -472,6 +472,7 @@ nfs4_free_cookie(fs_volume* volume, fs_vnode* vnode, void* _cookie)
OpenFileCookie* cookie = reinterpret_cast<OpenFileCookie*>(_cookie);
file_cache_sync(inode->FileCache());
inode->Commit();
inode->Close(cookie);
delete cookie;