nfs4: Use DoublyLinkedList instead of custom FileSystem list implementation

This commit is contained in:
Pawel Dziepak
2013-01-04 16:03:36 +01:00
parent d72bdcc88a
commit 332621d196
4 changed files with 15 additions and 29 deletions
@@ -24,8 +24,6 @@ extern RPC::ProgramData* CreateNFS4Server(RPC::Server* serv);
FileSystem::FileSystem(const MountConfiguration& configuration) FileSystem::FileSystem(const MountConfiguration& configuration)
: :
fNext(NULL),
fPrev(NULL),
fOpenCount(0), fOpenCount(0),
fOpenOwnerSequence(0), fOpenOwnerSequence(0),
fNamedAttrs(true), fNamedAttrs(true),
@@ -27,7 +27,7 @@ struct MountConfiguration {
bool fCacheMetadata; bool fCacheMetadata;
}; };
class FileSystem { class FileSystem : public DoublyLinkedListLinkImpl<FileSystem> {
public: public:
static status_t Mount(FileSystem** pfs, RPC::Server* serv, static status_t Mount(FileSystem** pfs, RPC::Server* serv,
const char* path, dev_t id, const char* path, dev_t id,
@@ -76,8 +76,6 @@ public:
inline const MountConfiguration& GetConfiguration(); inline const MountConfiguration& GetConfiguration();
FileSystem* fNext;
FileSystem* fPrev;
private: private:
FileSystem(const MountConfiguration& config); FileSystem(const MountConfiguration& config);
@@ -21,7 +21,6 @@ NFS4Server::NFS4Server(RPC::Server* serv)
fLeaseTime(0), fLeaseTime(0),
fClientIdLastUse(0), fClientIdLastUse(0),
fUseCount(0), fUseCount(0),
fFileSystems(NULL),
fServer(serv) fServer(serv)
{ {
ASSERT(serv != NULL); ASSERT(serv != NULL);
@@ -58,7 +57,7 @@ NFS4Server::ServerRebooted(uint64 clientId)
// reclaim all opened files and held locks from all filesystems // reclaim all opened files and held locks from all filesystems
MutexLocker _(fFSLock); MutexLocker _(fFSLock);
FileSystem* fs = fFileSystems; FileSystem* fs = fFileSystems.Head();
while (fs != NULL) { while (fs != NULL) {
DoublyLinkedList<OpenState>::Iterator iterator DoublyLinkedList<OpenState>::Iterator iterator
= fs->OpenFilesLock().GetIterator(); = fs->OpenFilesLock().GetIterator();
@@ -70,7 +69,7 @@ NFS4Server::ServerRebooted(uint64 clientId)
} }
fs->OpenFilesUnlock(); fs->OpenFilesUnlock();
fs = fs->fNext; fs = fFileSystems.GetNext(fs);
} }
return fClientId; return fClientId;
@@ -83,11 +82,8 @@ NFS4Server::AddFileSystem(FileSystem* fs)
ASSERT(fs != NULL); ASSERT(fs != NULL);
MutexLocker _(fFSLock); MutexLocker _(fFSLock);
fs->fPrev = NULL; fFileSystems.Add(fs);
fs->fNext = fFileSystems;
if (fFileSystems != NULL)
fFileSystems->fPrev = fs;
fFileSystems = fs;
fUseCount += fs->OpenFilesCount(); fUseCount += fs->OpenFilesCount();
if (fs->OpenFilesCount() > 0) if (fs->OpenFilesCount() > 0)
_StartRenewing(); _StartRenewing();
@@ -100,13 +96,7 @@ NFS4Server::RemoveFileSystem(FileSystem* fs)
ASSERT(fs != NULL); ASSERT(fs != NULL);
MutexLocker _(fFSLock); MutexLocker _(fFSLock);
if (fs == fFileSystems) fFileSystems.Remove(fs);
fFileSystems = fs->fNext;
if (fs->fNext)
fs->fNext->fPrev = fs->fPrev;
if (fs->fPrev)
fs->fPrev->fNext = fs->fNext;
fUseCount -= fs->OpenFilesCount(); fUseCount -= fs->OpenFilesCount();
} }
@@ -152,10 +142,10 @@ NFS4Server::FileSystemMigrated()
{ {
// reclaim all opened files and held locks from all filesystems // reclaim all opened files and held locks from all filesystems
MutexLocker _(fFSLock); MutexLocker _(fFSLock);
FileSystem* fs = fFileSystems; FileSystem* fs = fFileSystems.Head();
while (fs != NULL) { while (fs != NULL) {
fs->Migrate(fServer); fs->Migrate(fServer);
fs = fs->fNext; fs = fFileSystems.GetNext(fs);
} }
return B_OK; return B_OK;
@@ -336,13 +326,13 @@ NFS4Server::CallbackRecall(RequestInterpreter* request, ReplyBuilder* reply)
MutexLocker locker(fFSLock); MutexLocker locker(fFSLock);
Delegation* delegation = NULL; Delegation* delegation = NULL;
FileSystem* current = fFileSystems; FileSystem* current = fFileSystems.Head();
while (current != NULL) { while (current != NULL) {
delegation = current->GetDelegation(handle); delegation = current->GetDelegation(handle);
if (delegation != NULL) if (delegation != NULL)
break; break;
current = current->fNext; current = fFileSystems.GetNext(current);
} }
locker.Unlock(); locker.Unlock();
@@ -379,13 +369,13 @@ NFS4Server::CallbackGetAttr(RequestInterpreter* request, ReplyBuilder* reply)
MutexLocker locker(fFSLock); MutexLocker locker(fFSLock);
Delegation* delegation = NULL; Delegation* delegation = NULL;
FileSystem* current = fFileSystems; FileSystem* current = fFileSystems.Head();
while (current != NULL) { while (current != NULL) {
delegation = current->GetDelegation(handle); delegation = current->GetDelegation(handle);
if (delegation != NULL) if (delegation != NULL)
break; break;
current = current->fNext; current = fFileSystems.GetNext(current);
} }
locker.Unlock(); locker.Unlock();
@@ -411,7 +401,7 @@ status_t
NFS4Server::RecallAll() NFS4Server::RecallAll()
{ {
MutexLocker _(fFSLock); MutexLocker _(fFSLock);
FileSystem* fs = fFileSystems; FileSystem* fs = fFileSystems.Head();
while (fs != NULL) { while (fs != NULL) {
DoublyLinkedList<Delegation>& list = fs->DelegationsLock(); DoublyLinkedList<Delegation>& list = fs->DelegationsLock();
DoublyLinkedList<Delegation>::Iterator iterator = list.GetIterator(); DoublyLinkedList<Delegation>::Iterator iterator = list.GetIterator();
@@ -427,7 +417,7 @@ NFS4Server::RecallAll()
} }
fs->DelegationsUnlock(); fs->DelegationsUnlock();
fs = fs->fNext; fs = fFileSystems.GetNext(fs);
} }
return B_OK; return B_OK;
@@ -66,7 +66,7 @@ private:
mutex fClientIdLock; mutex fClientIdLock;
uint32 fUseCount; uint32 fUseCount;
FileSystem* fFileSystems; DoublyLinkedList<FileSystem> fFileSystems;
mutex fFSLock; mutex fFSLock;
RPC::Server* fServer; RPC::Server* fServer;