nfs4: Fix OPEN and CLOSE sequence numbers

This commit is contained in:
Pawel Dziepak
2012-06-29 02:14:52 +02:00
parent 941416ff8b
commit 5a451a5405
6 changed files with 30 additions and 42 deletions
+10 -9
View File
@@ -15,6 +15,9 @@
#include "Request.h"
vint64 OpenFileCookie::fLastOwnerId = 0;
Inode::Inode()
{
}
@@ -395,6 +398,7 @@ Inode::Open(int mode, OpenFileCookie* cookie)
cookie->fHandle = fHandle;
cookie->fMode = mode;
cookie->fSequence = 0;
do {
cookie->fClientId = fFilesystem->NFSServer()->ClientId();
@@ -402,13 +406,11 @@ Inode::Open(int mode, OpenFileCookie* cookie)
Request request(fFilesystem->Server());
RequestBuilder& req = request.Builder();
cookie->fOwnerTime = time(NULL);
cookie->fOwnerTID = find_thread(NULL);
cookie->fOwnerId = atomic_add64(&cookie->fLastOwnerId, 1);
req.PutFH(fParentFH);
req.Open(CLAIM_NULL, fFilesystem->NFSServer()->SequenceId(),
OPEN4_SHARE_ACCESS_READ, cookie->fClientId, OPEN4_NOCREATE,
cookie->fOwnerTime, cookie->fOwnerTID, fName);
req.Open(CLAIM_NULL, cookie->fSequence++, OPEN4_SHARE_ACCESS_READ,
cookie->fClientId, OPEN4_NOCREATE, cookie->fOwnerId, fName);
result = request.Send();
if (result != B_OK)
@@ -434,7 +436,6 @@ Inode::Open(int mode, OpenFileCookie* cookie)
if (result != B_OK)
return result;
result = reply.Open(cookie->fStateId, &cookie->fStateSeq, &confirm);
if (result != B_OK)
return result;
@@ -450,8 +451,8 @@ Inode::Open(int mode, OpenFileCookie* cookie)
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.OpenConfirm(fFilesystem->NFSServer()->SequenceId(),
cookie->fStateId, cookie->fStateSeq);
req.OpenConfirm(cookie->fSequence++, cookie->fStateId,
cookie->fStateSeq);
result = request.Send();
if (result != B_OK) {
@@ -488,7 +489,7 @@ Inode::Close(OpenFileCookie* cookie)
RequestBuilder& req = request.Builder();
req.PutFH(fHandle);
req.Close(fFilesystem->NFSServer()->SequenceId(), cookie->fStateId,
req.Close(cookie->fSequence++, cookie->fStateId,
cookie->fStateSeq);
status_t result = request.Send();
+11 -9
View File
@@ -19,19 +19,21 @@
struct OpenFileCookie {
uint64 fClientId;
uint64 fClientId;
uint32 fMode;
uint32 fMode;
Filehandle fHandle;
uint32 fStateId[3];
uint32 fStateSeq;
Filehandle fHandle;
uint32 fStateId[3];
uint32 fStateSeq;
uint32 fOwnerTime;
uint32 fOwnerTID;
uint32 fSequence;
OpenFileCookie* fNext;
OpenFileCookie* fPrev;
uint64 fOwnerId;
static vint64 fLastOwnerId;
OpenFileCookie* fNext;
OpenFileCookie* fPrev;
};
class Inode {
@@ -17,7 +17,6 @@ NFS4Server::NFS4Server(RPC::Server* serv)
fThreadCancel(true),
fLeaseTime(0),
fCIDUseCount(0),
fSequenceId(0),
fOpenFiles(NULL),
fServer(serv)
{
@@ -72,11 +71,10 @@ NFS4Server::_ReclaimOpen(OpenFileCookie* cookie)
RequestBuilder& req = request.Builder();
req.PutFH(cookie->fHandle);
req.Open(CLAIM_PREVIOUS, SequenceId(), OPEN4_SHARE_ACCESS_READ,
cookie->fClientId, OPEN4_NOCREATE, cookie->fOwnerTime,
cookie->fOwnerTID, NULL);
req.Open(CLAIM_PREVIOUS, cookie->fSequence++, OPEN4_SHARE_ACCESS_READ,
cookie->fClientId, OPEN4_NOCREATE, cookie->fOwnerId, NULL);
status_t result = request.Send();
status_t result = request.Send();;
if (result != B_OK)
return result;
@@ -95,7 +93,8 @@ NFS4Server::_ReclaimOpen(OpenFileCookie* cookie)
request.Reset();
req.PutFH(cookie->fHandle);
req.OpenConfirm(SequenceId(), cookie->fStateId, cookie->fStateSeq);
req.OpenConfirm(cookie->fSequence++, cookie->fStateId,
cookie->fStateSeq);
result = request.Send();
if (result != B_OK)
@@ -28,8 +28,6 @@ public:
uint64 ClientId(uint64 prevId = 0, bool forceNew = false);
void ReleaseCID(uint64 cid);
inline uint32 SequenceId();
inline uint32 LeaseTime();
private:
status_t _ReclaimOpen(OpenFileCookie* cookie);
@@ -48,20 +46,12 @@ private:
uint32 fCIDUseCount;
mutex fLock;
vint32 fSequenceId;
OpenFileCookie* fOpenFiles;
mutex fOpenLock;
RPC::Server* fServer;
};
inline uint32
NFS4Server::SequenceId()
{
return static_cast<uint32>(atomic_add(&fSequenceId, 1));
}
inline uint32
NFS4Server::LeaseTime()
@@ -153,7 +153,7 @@ RequestBuilder::LookUpUp()
status_t
RequestBuilder::Open(OpenClaim claim, uint32 seq, uint32 access, uint64 id,
OpenCreate oc, uint32 ownerTime, uint32 ownerTID, const char* name)
OpenCreate oc, uint64 ownerId, const char* name)
{
if (fProcedure != ProcCompound)
return B_BAD_VALUE;
@@ -168,11 +168,8 @@ RequestBuilder::Open(OpenClaim claim, uint32 seq, uint32 access, uint64 id,
char owner[128];
int pos = 0;
*(uint32*)(owner + pos) = ownerTime;
pos += sizeof(uint32);
*(uint32*)(owner + pos) = ownerTID;
pos += sizeof(uint32);
*(uint64*)(owner + pos) = ownerId;
pos += sizeof(uint64);
fRequest->Stream().AddOpaque(owner, pos);
@@ -33,8 +33,7 @@ public:
status_t LookUpUp();
status_t Open(OpenClaim claim, uint32 seq,
uint32 access, uint64 id, OpenCreate oc,
uint32 ownerTime, uint32 ownerTID,
const char* name);
uint64 ownerId, const char* name);
status_t OpenConfirm(uint32 seq, const uint32* id,
uint32 stateSeq);
status_t PutFH(const Filehandle& fh);