[haiku-commits] BRANCH pdziepak-github.nfs4 - src/add-ons/kernel/file_systems/nfs4

  • From: pdziepak-github.nfs4 <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 17 Aug 2012 01:49:13 +0200 (CEST)

added 2 changesets to branch 'refs/remotes/pdziepak-github/nfs4'
old head: e8c12d9410d16c9a504198755b85c385e7ab667a
new head: 8568341ae61b9ecdd5f96b6167c5eb5589a20ed1

----------------------------------------------------------------------------

da950cb: nfs4: Fix several problems with emulated attributes

8568341: nfs4: Fix bugs when metadata cache is disabled

                                    [ Pawel Dziepak <pdziepak@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

7 files changed, 51 insertions(+), 19 deletions(-)
src/add-ons/kernel/file_systems/nfs4/Inode.cpp     |   24 +++++++++++++++-
src/add-ons/kernel/file_systems/nfs4/Inode.h       |    2 ++
src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp  |    4 +--
.../kernel/file_systems/nfs4/InodeRegular.cpp      |   19 ++++++------
.../kernel/file_systems/nfs4/MetadataCache.cpp     |    7 ++---
.../kernel/file_systems/nfs4/MetadataCache.h       |    6 ++--
src/add-ons/kernel/file_systems/nfs4/RootInode.cpp |    8 +++++-

############################################################################

Commit:      da950cb2ef76ecc309a833bcf9cc748b16f78bc1

Author:      Pawel Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Thu Aug 16 23:14:30 2012 UTC

nfs4: Fix several problems with emulated attributes

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp 
b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp
index a98ca4c..4b179c5 100644
--- a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp
@@ -12,6 +12,7 @@
 #include <ctype.h>
 #include <string.h>
 
+#include <AutoDeleter.h>
 #include <fs_cache.h>
 #include <NodeMonitor.h>
 
@@ -267,10 +268,16 @@ Inode::Link(Inode* dir, const char* name)
 status_t
 Inode::Remove(const char* name, FileType type)
 {
+       MemoryDeleter nameDeleter;
        if (type == NF4NAMEDATTR) {
                status_t result = LoadAttrDirHandle();
                if (result != B_OK)
                        return result;
+
+               name = AttrToFileName(name);
+               if (name == NULL)
+                       return B_NO_MEMORY;
+               nameDeleter.SetTo(const_cast<char*>(name));
        }
 
        ChangeInfo changeInfo;
@@ -311,6 +318,8 @@ Inode::Rename(Inode* from, Inode* to, const char* fromName, 
const char* toName,
        if (from->fFileSystem != to->fFileSystem)
                return B_DONT_DO_THAT;
 
+       MemoryDeleter fromNameDeleter;
+       MemoryDeleter toNameDeleter;
        if (attribute) {
                status_t result = from->LoadAttrDirHandle();
                if (result != B_OK)
@@ -319,6 +328,14 @@ Inode::Rename(Inode* from, Inode* to, const char* 
fromName, const char* toName,
                result = to->LoadAttrDirHandle();
                if (result != B_OK)
                        return result;
+
+               fromName = from->AttrToFileName(fromName);
+               toName = to->AttrToFileName(toName);
+
+               fromNameDeleter.SetTo(const_cast<char*>(fromName));
+               toNameDeleter.SetTo(const_cast<char*>(toName));
+               if (fromName == NULL || toName == NULL)
+                       return B_NO_MEMORY;
        }
 
        ChangeInfo fromChange, toChange;
diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.h 
b/src/add-ons/kernel/file_systems/nfs4/Inode.h
index 7497fa5..3815e97 100644
--- a/src/add-ons/kernel/file_systems/nfs4/Inode.h
+++ b/src/add-ons/kernel/file_systems/nfs4/Inode.h
@@ -132,6 +132,8 @@ protected:
                                        status_t        GetStat(struct stat* st,
                                                                        
OpenAttrCookie* attr = NULL);
 
+                                       char*           AttrToFileName(const 
char* path);
+
        static inline   status_t        CheckLockType(short ltype, uint32 mode);
 
 private:
diff --git a/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp 
b/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp
index 65f735a..5633fba 100644
--- a/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp
@@ -85,11 +85,11 @@ Inode::LoadAttrDirHandle()
                return B_UNSUPPORTED;
 
        char* attrDir
-               = reinterpret_cast<char*>(malloc(strlen(fInfo.fName) + 32));
+               = reinterpret_cast<char*>(malloc(strlen(Name()) + 32));
        if (attrDir == NULL)
                return B_NO_MEMORY;
        strcpy(attrDir, ".");
-       strcat(attrDir, fInfo.fName);
+       strcat(attrDir, Name());
        strcat(attrDir, "-haiku-attrs");
 
        result = NFS4Inode::LookUp(attrDir, NULL, NULL, &handle, true);
diff --git a/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp 
b/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp
index 4d1b943..b677477 100644
--- a/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp
@@ -40,12 +40,15 @@ Inode::CreateState(const char* name, int mode, int perms, 
OpenState* state,
        fi.fParent = fInfo.fHandle;
        fi.fName = strdup(name);
 
-       char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2 +
-               strlen(fInfo.fPath)));
-       strcpy(path, fInfo.fPath);
-       strcat(path, "/");
-       strcat(path, name);
-       fi.fPath = path;
+       if (fInfo.fPath != NULL) {
+               char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2 +
+                       strlen(fInfo.fPath)));
+               strcpy(path, fInfo.fPath);
+               strcat(path, "/");
+               strcat(path, name);
+               fi.fPath = path;
+       } else
+               fi.fPath = strdup(name);
 
        fFileSystem->InoIdMap()->AddEntry(fi, FileIdToInoT(fileID));
 
@@ -193,8 +196,8 @@ Inode::Close(OpenFileCookie* cookie)
 }
 
 
-static char*
-AttrToFileName(const char* path)
+char*
+Inode::AttrToFileName(const char* path)
 {
        char* name = strdup(path);
        if (name == NULL)
diff --git a/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp 
b/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp
index 4ca51e2..65fbd73 100644
--- a/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp
@@ -126,7 +126,13 @@ RootInode::_UpdateInfo(bool force)
                break;
        } while (true);
 
-       fInfoCache.flags = 0;
+       fInfoCache.flags =      B_FS_IS_PERSISTENT | B_FS_IS_SHARED
+               | B_FS_SUPPORTS_NODE_MONITORING;
+
+       if (fFileSystem->NamedAttrs()
+               || fFileSystem->GetConfiguration().fEmulateNamedAttrs)
+               fInfoCache.flags |= B_FS_HAS_MIME | B_FS_HAS_ATTR;
+
        strncpy(fInfoCache.volume_name, fName, B_FILE_NAME_LENGTH);
 
        fInfoCacheExpire = time(NULL) + MetadataCache::kExpirationTime;

############################################################################

Commit:      8568341ae61b9ecdd5f96b6167c5eb5589a20ed1

Author:      Pawel Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Thu Aug 16 23:28:48 2012 UTC

nfs4: Fix bugs when metadata cache is disabled

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp 
b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp
index 4b179c5..29f9cb7 100644
--- a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp
@@ -430,8 +430,9 @@ Inode::Access(int mode)
        int acc = 0;
 
        uint32 allowed;
+       bool cache = fFileSystem->GetConfiguration().fCacheMetadata;
        status_t result = fMetaCache.GetAccess(geteuid(), &allowed);
-       if (result != B_OK) {
+       if (result != B_OK || !cache) {
                result = NFS4Inode::Access(&allowed);
                if (result != B_OK)
                        return result;
@@ -463,6 +464,10 @@ Inode::Stat(struct stat* st, OpenAttrCookie* attr)
        if (attr != NULL)
                return GetStat(st, attr);
 
+       bool cache = fFileSystem->GetConfiguration().fCacheMetadata;
+       if (!cache)
+               return GetStat(st, NULL);
+
        status_t result = fMetaCache.GetStat(st);
        if (result != B_OK) {
                struct stat temp;
diff --git a/src/add-ons/kernel/file_systems/nfs4/MetadataCache.cpp 
b/src/add-ons/kernel/file_systems/nfs4/MetadataCache.cpp
index bc345a9..38795b4 100644
--- a/src/add-ons/kernel/file_systems/nfs4/MetadataCache.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/MetadataCache.cpp
@@ -35,8 +35,7 @@ status_t
 MetadataCache::GetStat(struct stat* st)
 {
        MutexLocker _(fLock);
-       bool cache = fInode->GetFileSystem()->GetConfiguration().fCacheMetadata;
-       if (fForceValid || (cache && fExpire > time(NULL))) {
+       if (fForceValid || fExpire > time(NULL)) {
                // Do not touch other members of struct stat
                st->st_size = fStatCache.st_size;
                st->st_mode = fStatCache.st_mode;
@@ -112,9 +111,7 @@ MetadataCache::SetAccess(uid_t uid, uint32 allowed)
        entry.fExpire = time(NULL) + kExpirationTime;
        entry.fForceValid = fForceValid;
 
-       bool cache = fInode->GetFileSystem()->GetConfiguration().fCacheMetadata;
-       if (fForceValid || cache)
-               fAccessCache.Insert(uid, entry);
+       fAccessCache.Insert(uid, entry);
 }
 
 
diff --git a/src/add-ons/kernel/file_systems/nfs4/MetadataCache.h 
b/src/add-ons/kernel/file_systems/nfs4/MetadataCache.h
index 07a13a3..82e44c6 100644
--- a/src/add-ons/kernel/file_systems/nfs4/MetadataCache.h
+++ b/src/add-ons/kernel/file_systems/nfs4/MetadataCache.h
@@ -69,7 +69,8 @@ inline void
 MetadataCache::InvalidateStat()
 {
        MutexLocker _(fLock);
-       fExpire = 0;
+       if (!fForceValid)
+               fExpire = 0;
 }
 
 
@@ -77,7 +78,8 @@ inline void
 MetadataCache::InvalidateAccess()
 {
        MutexLocker _(fLock);
-       fAccessCache.MakeEmpty();
+       if (!fForceValid)
+               fAccessCache.MakeEmpty();
 }
 
 


Other related posts: