]> git.hungrycats.org Git - bees/commitdiff
fs: set the correct nr_items to 0 in the ENOENT search case
authorZygo Blaxell <bees@furryterror.org>
Fri, 13 Dec 2024 03:48:15 +0000 (22:48 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 13 Dec 2024 03:48:15 +0000 (22:48 -0500)
Commit 72c3bf8438830b65cae7bdaff126053e562280e5 ("fs: handle ENOENT
within lib") was meant to prevent exceptions when a subvol is deleted.

If the search ioctl fails, the kernel won't set nr_items in the
ioctl output, which means `nr_items` still has the input value.  When
ENOENT is detected, `this->nr_items` is set to 0, then later `*this =
ioctl_ptr->key` overwrites `this->nr_items` with the original requested
number of items.

This replaced the ENOENT exception with an exception triggered by
interpreting garbage in the memory buffer.  The number of exceptions
was reduced because the memory buffers are frequently reused, but upper
layers would then reject the data or ignore it because it didn't match
the key range.

Fix by setting `ioctl_ptr->key.nr_items`, which then overwrites
`this->nr_items`, so the loop that extracts items from the ioctl data
gets the right number of items (i.e. zero).

Fixes: 72c3bf8438830b65cae7bdaff126053e562280e5 ("fs: handle ENOENT within lib")
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
lib/fs.cc

index dc9a2eb1355e5ba1627e40237f119827d20f8f95..3366d14b201767772470695c4c61ea9d75f49aa3 100644 (file)
--- a/lib/fs.cc
+++ b/lib/fs.cc
@@ -781,7 +781,7 @@ namespace crucible {
                        ++s_calls;
                        if (rv != 0 && errno == ENOENT) {
                                // If we are searching a tree that is deleted or no longer exists, just return an empty list
-                               nr_items = 0;
+                               ioctl_ptr->key.nr_items = 0;
                                break;
                        }
                        if (rv != 0 && errno != EOVERFLOW) {