nfs4: Don't flush cache when closing read only share reservation

NFS4 specification requires that modified data has to be flushed before
sending CLOSE request. Our original implementation was stricter than that
by flushing all modified data at each file close. That caused problems
with e.g. Tracker, which likes to periodically open files for read only,
in a situation when there were still asynchronous writes pending
(e.g. large file copied).
This commit is contained in:
Pawel Dziepak 2014-02-21 04:08:49 +01:00
parent b637b72e15
commit d072da2344
2 changed files with 16 additions and 11 deletions

View File

@ -170,17 +170,16 @@ Inode::RevalidateFileCache()
MutexLocker _(fFileCacheLock);
if (change == fChange)
return B_OK;
SyncAndCommit(true);
file_cache_delete(fFileCache);
struct stat st;
fMetaCache.InvalidateStat();
result = Stat(&st);
if (result != B_OK)
return result;
fFileCache = file_cache_create(fFileSystem->DevId(), ID(), st.st_size);
if (result == B_OK)
fMaxFileSize = st.st_size;
fFileCache = file_cache_create(fFileSystem->DevId(), ID(), fMaxFileSize);
change = fChange;
return B_OK;
@ -833,7 +832,8 @@ Inode::ReleaseAllLocks(OpenFileCookie* cookie)
{
ASSERT(cookie != NULL);
SyncAndCommit();
if (cookie->fLocks)
SyncAndCommit();
OpenState* state = cookie->fOpenState;
MutexLocker _(state->fLocksLock);

View File

@ -106,8 +106,6 @@ Inode::Open(int mode, OpenFileCookie* cookie)
OpenDelegationData data;
data.fType = OPEN_DELEGATE_NONE;
if (fOpenState == NULL) {
RevalidateFileCache();
OpenState* state = new(std::nothrow) OpenState;
if (state == NULL)
return B_NO_MEMORY;
@ -125,6 +123,8 @@ Inode::Open(int mode, OpenFileCookie* cookie)
fOpenState = state;
cookie->fOpenState = state;
locker.Unlock();
RevalidateFileCache();
} else {
fOpenState->AcquireReference();
cookie->fOpenState = fOpenState;
@ -143,6 +143,9 @@ Inode::Open(int mode, OpenFileCookie* cookie)
return result;
}
fOpenState->fMode = O_RDWR;
if (oldMode == O_RDONLY)
RevalidateFileCache();
} else {
int newMode = mode & O_RWMASK;
uint32 allowed = 0;
@ -190,7 +193,9 @@ Inode::Close(OpenFileCookie* cookie)
ASSERT(cookie != NULL);
ASSERT(fOpenState == cookie->fOpenState);
SyncAndCommit();
int mode = cookie->fMode & O_RWMASK;
if (mode == O_RDWR || mode == O_WRONLY)
SyncAndCommit();
MutexLocker _(fStateLock);
ReleaseOpenState();
@ -437,10 +442,10 @@ Inode::Write(OpenFileCookie* cookie, off_t pos, const void* _buffer,
status_t
Inode::Commit()
{
WriteLocker _(fWriteLock);
if (!fWriteDirty)
return B_OK;
WriteLocker _(fWriteLock);
status_t result = CommitWrites();
if (result != B_OK)
return result;