[LTP] fanotify13: fix test failure when running iterations

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Wed Jun 3 06:15:22 CEST 2026


Hi AnonymeMeow,

Thank you for the patch. The overall approach is correct — the two problems
identified (missing state restoration after FAN_DELETE_SELF and the overlayfs
mount-timing issue in setup) are real, and the split between
clean_upper_dir() for the lower-only case and create_objects() for the rest
is sound. However there is one correctness gap that needs fixing before this
can be applied.

---

[BUG] restore_objects() does not re-add the nofid_fd mark

In do_setup(), a mark without FAN_REPORT_FID is placed on FILE_PATH_ONE
specifically to exercise the "uninitialized connector->fsid cache" path
(regression test for c285a2f01d69):

    nofid_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
    ...
    SAFE_FANOTIFY_MARK(nofid_fd, FAN_MARK_ADD, FAN_CLOSE_WRITE, AT_FDCWD,
                      FILE_PATH_ONE);

The new restore_objects() correctly rebuilds files and refreshes fids, but it
calls create_objects() for variants 0 and 4 (TST_VARIANT_OVL_LOWER == 0).
Those calls allocate new inodes at the same paths. The nofid_fd mark remains
bound to the *old*, now-orphaned inode; the new FILE_PATH_ONE inode has no
nofid mark at all. On the second iteration, setup_marks() attaches fanotify_fd
(FAN_REPORT_FID) to a fresh inode that has never had a non-FID mark, so the
very scenario that c285a2f01d69 fixes is no longer exercised.

For variant 3 (TST_VARIANT_OVL_LOWER == 1), clean_upper_dir() only removes
overlayfs whiteouts from OVL_UPPER and remounts the overlay; the original
OVL_LOWER inodes are never freed, so the nofid_fd mark is preserved. But
variants 0 and 4 both go through create_objects(), where the inodes are
replaced.

+static void restore_objects(void)
+{
+if (TST_VARIANT_OVL_LOWER)
+clean_upper_dir();
+else
+create_objects();
+
+/* Get the re-created object ids */
+get_object_stats();
+}

Fix: re-add the nofid_fd mark after re-creating the objects so that the
connector state matches do_setup():

 static void restore_objects(void)
 {
 if (TST_VARIANT_OVL_LOWER)
 clean_upper_dir();
 else
 create_objects();
 
+/* Re-add the nofid mark; create_objects() creates new inodes */
+SAFE_FANOTIFY_MARK(nofid_fd, FAN_MARK_ADD, FAN_CLOSE_WRITE,
+   AT_FDCWD, FILE_PATH_ONE);
+
 /* Get the re-created object ids */
 get_object_stats();
 }

For variant 3 this is a harmless no-op (FAN_MARK_ADD on an already-marked
inode succeeds and leaves the mark unchanged). For variants 0 and 4 it
restores full coverage of c285a2f01d69.

---

[NIT] Commit message: "crash" is imprecise

> The FAN_DELETE_SELF test case removes test files, causing later
> iterations to crash.

SAFE_OPEN() failing due to ENOENT causes tst_brk(TBROK, ...), which
terminates the iteration — not a crash. "fail" or "abort" would be more
accurate LTP terminology.

---

[NIT] Trailing whitespace in do_setup()

The blank line inserted after create_objects(); in do_setup() carries a
trailing TAB/space. checkpatch.pl will flag it. Please remove.

 /* Create file and directory objects for testing on base fs */
 create_objects();
-<trailing whitespace here>
+
 if (tst_variant) {

---

Everything else looks good:

- The macro definitions for TST_VARIANT_OVL_LOWER / TST_VARIANT_OVL_WATCH are
  correct for all 5 variants and replace the two open-coded expressions neatly.
- clean_upper_dir() correctly handles directory whiteouts: since all objects
  (including DIR_ONE) were created in OVL_LOWER and OVL_UPPER starts empty,
  overlayfs creates char-device (c 0 0) whiteouts in OVL_UPPER for all three
  deleted objects, so SAFE_UNLINK() works uniformly.
- Moving TST_MOUNT_OVERLAY() to after create_objects() correctly avoids
  creating files directly in the lower/upper directory while the overlay is
  already mounted.
- The mount/umount sequence in clean_upper_dir() interacts correctly with
  do_cleanup(): the OVL_LOWER bind mount (bind_mounted) remains on the bottom
  of the MOUNT_PATH stack and is unmounted last in cleanup.
- Kernel commits c285a2f01d69, bc2473c90fca, and c45beebfde34a are all present
  in kernel 7.1 (current stable); no staging concerns.
- runtest entry confirmed: syscalls/fanotify13 fanotify13.

Verdict: Needs revision

LTP AI Reviewer


More information about the ltp mailing list