@samitouri / QOSamiQemu / commits / 7430c34b25

test-util-filemonitor: Adapt to FreeBSD 15's native inotify semantics

FreeBSD 15 introduces a native inotify implementation rather than requiring use of the kqueue-based libinotify package. This native implementation does not generate the extra deleted events, so don't expect them. However, the original implementation did have a bug that caused IN_IGNORED to never be generated if you did not also watch for IN_DELETE_SELF, which affects 15.0 and 15.1, but has been fixed and will no longer apply in 15.2 / 16.0. Note that the deleted event check is for the userspace version, since that governs whether libinotify is being used or not, whereas the ignored event check is both for the userspace version (to check if we're using the native syscall) and the kernel version (to check if the kernel has the bug or not). All __FreeBSD_version values used here correspond to the value in-tree at the time of the relevant commits. Since neither commit bumped the value there will be a window of development snapshots between each commit and the previous bump that will be incorrectly identified here, but this is the best we can do, and something users of snapshots should be prepared to deal with. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Jessica Clarke committed Jul 9, 2026 at 19:42 UTC 7430c34b25a8d6f08281c64cc01438e0ec3c91ab
1 file changed +28 -1
tests/unit/test-util-filemonitor.c
+28 -1
@@ -27,6 +27,10 @@
27
28 #include <utime.h>
29
30 +#ifdef __FreeBSD__
31 +#include <osreldate.h>
32 +#endif
33 +
34 enum {
35 QFILE_MONITOR_TEST_OP_ADD_WATCH,
36 QFILE_MONITOR_TEST_OP_DEL_WATCH,
@@ -221,6 +225,24 @@ qemu_file_monitor_test_expect(QFileMonitorTestData *data,
225 }
226
227
228 +static bool
229 +expect_broken_ignored(void)
230 +{
231 +#if defined(__FreeBSD__) && __FreeBSD_version >= 1500051
232 + int osreldate;
233 +
234 + osreldate = getosreldate();
235 + if (osreldate == -1) {
236 + g_printerr("Unable to call getosreldate: %s\n", strerror(errno));
237 + abort();
238 + }
239 + return osreldate < 1501501 || (osreldate >= 1600000 && osreldate < 1600019);
240 +#else
241 + return false;
242 +#endif
243 +}
244 +
245 +
246 static void
247 test_file_monitor_events(void)
248 {
@@ -360,7 +382,7 @@ test_file_monitor_events(void)
382 { .type = QFILE_MONITOR_TEST_OP_EVENT,
383 .filesrc = "one.txt", .watchid = &watch4,
384 .eventid = QFILE_MONITOR_EVENT_DELETED },
363 -#ifdef __FreeBSD__
385 +#if defined(__FreeBSD__) && __FreeBSD_version < 1500051
386 { .type = QFILE_MONITOR_TEST_OP_EVENT,
387 .filesrc = "two.txt", .watchid = &watch0,
388 .eventid = QFILE_MONITOR_EVENT_DELETED },
@@ -539,6 +561,11 @@ test_file_monitor_events(void)
561 g_printerr("Event id=%" PRIx64 " event=%d file=%s\n",
562 *op->watchid, op->eventid, op->filesrc);
563 }
564 + if (op->eventid == QFILE_MONITOR_EVENT_IGNORED &&
565 + expect_broken_ignored()) {
566 + g_printerr("Expect ignored event to be broken, skipping\n");
567 + break;
568 + }
569 if (!qemu_file_monitor_test_expect(&data, *op->watchid,
570 op->eventid, op->filesrc,
571 op->swapnext))