From 23835bdf840841319dd30b427bbb9f113e06956b Mon Sep 17 00:00:00 2001 From: Jim906 Date: Thu, 17 Jul 2025 10:58:56 -0400 Subject: [PATCH] nfs4: Fix _LoadSnapshot comparison logic * If a ".." entry is present in fNameCache, don't look for a matching entry in the DirectoryCacheSnapshot. * Fixes an assert failure reported incidentally in the #19656 ticket, but is not related to the original reported bug. This is a correction to 258fce50e0f84b6a980f750f7540802e821bebda. The comparison added in that patch is between 2 different types of directory entry caches that exist in the DirectoryCache class. One of them caches "..", and the other one doesn't. Change-Id: I56335271436be18e363f6b164e1fc2de24193bfb Reviewed-on: https://review.haiku-os.org/c/haiku/+/9498 Reviewed-by: waddlesplash --- .../file_systems/nfs4/DirectoryCache.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp b/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp index 016d71ed11..70dc8b1e74 100644 --- a/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp @@ -224,21 +224,24 @@ DirectoryCache::_LoadSnapshot(bool trash) // obtained snapshot that might indicate stale nodes. while (!fNameCache.IsEmpty()) { NameCacheEntry* current = fNameCache.RemoveHead(); - bool nodeFound = false; - for (SinglyLinkedList::ConstIterator it - = newSnapshot->fEntries.GetIterator(); - NameCacheEntry* snapshotEntry = it.Next();) { - if (current->fNode == snapshotEntry->fNode - && strcmp(current->fName, snapshotEntry->fName) == 0) { - nodeFound = true; - break; + if (strcmp(current->fName, "..") != 0) { + bool nodeFound = false; + for (SinglyLinkedList::ConstIterator it + = newSnapshot->fEntries.GetIterator(); + NameCacheEntry* snapshotEntry = it.Next();) { + if (current->fNode == snapshotEntry->fNode + && strcmp(current->fName, snapshotEntry->fName) == 0) { + nodeFound = true; + break; + } + } + if (!nodeFound) { + // The inode-name association that was cached in 'current' is no longer valid. + result = fInode->GetFileSystem()->TrashStaleNode(current->fNode); + if (result != B_OK) + INFORM("_LoadSnapshot: Couldn't free stale node %" B_PRIdINO "\n", + current->fNode); } - } - if (!nodeFound) { - // The inode-name association that was cached in 'current' is no longer valid. - result = fInode->GetFileSystem()->TrashStaleNode(current->fNode); - if (result != B_OK) - INFORM("_LoadSnapshot: Couldn't free stale node.\n"); } delete current; }