⛏️ index : haiku.git

author Jim906 <jim_l@fastmail.com> 2025-06-18 10:44:28.0 -04:00:00
committer Adrien Destugues <pulkomandy@pulkomandy.tk> 2025-06-20 9:06:43.0 +00:00:00
commit
45037be1107c94f2dc2ef8b612a1081bc979656d [patch]
tree
b9436d2ef4654e794dad349e394780f1a272bfca
parent
08478942771b4ae49520ae2a598d1ce8d5142252
download
45037be1107c94f2dc2ef8b612a1081bc979656d.tar.gz

nfs4: zero out possible garbage values

* When a file hole is created, zero the start of the page where the
  hole ends.

In my test setup at least, the server takes care of zeroing any full
pages in the hole created when a write begins at a position after the
existing EOF. Since the file cache page where the write starts will be
written back to the server, we just need to partially zero that page.

This change allows the driver to pass the 'holey file' test in the
nfs connectathon test suite.

Change-Id: I5a0d52af5cce4fb9e2d9f928f45fd0adcfa23627
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9381
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>

Diff

 src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp b/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp
index a792fc0..2560243 100644
--- a/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp
+++ b/src/add-ons/kernel/file_systems/nfs4/InodeRegular.cpp
@@ -430,6 +430,14 @@
		status_t result = file_cache_set_size(fFileCache, fileSize);
		if (result != B_OK)
			return result;
		if (static_cast<uint64>(pos) > ROUNDUP(fMaxFileSize, B_PAGE_SIZE)
			&& (cookie->fMode & O_NOCACHE) == 0) {
			// Zero out the start of the file cache page where the write begins.
			// We will let the server zero out the rest of the hole.
			fMaxFileSize = pos;
			size_t pageOffset = pos % B_PAGE_SIZE;
			file_cache_write(fFileCache, cookie, pos - pageOffset, NULL, &pageOffset);
		}
		fMaxFileSize = fileSize;
		fMetaCache.GrowFile(fMaxFileSize);
	}