nfs4: Acquire fFileCacheLock in Inode::Read()

* Prevent file_cache_read() from being called in the middle of
  Inode::RevalidateFileCache().
* Correct an apparent typo in RevalidateFileCache.
* Fixes #16395.

If file_cache_read is called in one thread while RevalidateFileCache
is in progress in another thread, the file_cache_ref could be deleted
while file_cache_read is in progress.

Currently, RevalidateFileCache does not update fChange after it
obtains a new change value from the server.  As a result, for a file
that has been changed at least once since its node was constructed,
RevalidateFileCache will delete and recreate the file cache each time
it is called, instead of returning early as it would if fChange had
been updated the last time it ran.

Change-Id: Ifbf5a892c3003e41b2c73d9c3c806d8fbd79dff7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9147
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Jim906
2025-03-28 19:23:51 +00:00
committed by waddlesplash
parent d67db61955
commit 5650b97673
2 changed files with 3 additions and 1 deletions
@@ -182,7 +182,7 @@ Inode::RevalidateFileCache()
fMaxFileSize = st.st_size;
fFileCache = file_cache_create(fFileSystem->DevId(), ID(), fMaxFileSize);
change = fChange;
fChange = change;
return B_OK;
}
@@ -353,6 +353,8 @@ Inode::Read(OpenFileCookie* cookie, off_t pos, void* buffer, size_t* _length)
bool eof = false;
if ((cookie->fMode & O_NOCACHE) != 0)
return ReadDirect(cookie, pos, buffer, _length, &eof);
MutexLocker _(fFileCacheLock);
return file_cache_read(fFileCache, cookie, pos, buffer, _length);
}