systemd/SOURCES/0780-test-Skip-test-recurse-dir-on-overlayfs.patch

71 lines
2.9 KiB
Diff

From d4290244c49c6cc341225151cf0dfd5329dde943 Mon Sep 17 00:00:00 2001
From: Richard Maw <richard.maw@codethink.co.uk>
Date: Wed, 25 Oct 2023 18:12:58 +0100
Subject: [PATCH] test: Skip test-recurse-dir on overlayfs
(cherry picked from commit 31cfcf50088b69c973b9335a2383fa6502d90419)
Related: RHEL-27512
---
src/test/test-recurse-dir.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/test/test-recurse-dir.c b/src/test/test-recurse-dir.c
index c194896a1b..3e42526679 100644
--- a/src/test/test-recurse-dir.c
+++ b/src/test/test-recurse-dir.c
@@ -2,7 +2,9 @@
#include <ftw.h>
+#include "fd-util.h"
#include "log.h"
+#include "missing_magic.h"
#include "recurse-dir.h"
#include "strv.h"
#include "tests.h"
@@ -119,7 +121,7 @@ int main(int argc, char *argv[]) {
_cleanup_strv_free_ char **list_recurse_dir = NULL;
const char *p;
usec_t t1, t2, t3, t4;
- int r;
+ _cleanup_close_ int fd = -EBADF;
log_show_color(true);
test_setup_logging(LOG_INFO);
@@ -129,18 +131,28 @@ int main(int argc, char *argv[]) {
else
p = "/usr/share/man"; /* something hopefully reasonably stable while we run (and limited in size) */
+ fd = open(p, O_DIRECTORY|O_CLOEXEC);
+ if (fd < 0 && errno == ENOENT) {
+ log_warning_errno(errno, "Couldn't open directory %s, ignoring: %m", p);
+ return EXIT_TEST_SKIP;
+ }
+ assert_se(fd >= 0);
+
+ /* If the test directory is on an overlayfs then files and their direcory may return different st_dev
+ * in stat results, which confuses nftw into thinking they're on different filesystems
+ * and won't return the result when the FTW_MOUNT flag is set. */
+ if (fd_is_fs_type(fd, OVERLAYFS_SUPER_MAGIC)) {
+ log_tests_skipped("nftw mountpoint detection produces false-positives on overlayfs");
+ return EXIT_TEST_SKIP;
+ }
+
/* Enumerate the specified dirs in full, once via nftw(), and once via recurse_dir(), and ensure the
* results are identical. nftw() sometimes skips symlinks (see
* https://github.com/systemd/systemd/issues/29603), so ignore them to avoid bogus errors. */
t1 = now(CLOCK_MONOTONIC);
- r = recurse_dir_at(AT_FDCWD, p, 0, UINT_MAX, RECURSE_DIR_SORT|RECURSE_DIR_ENSURE_TYPE|RECURSE_DIR_SAME_MOUNT, recurse_dir_callback, &list_recurse_dir);
+ assert_se(recurse_dir(fd, p, 0, UINT_MAX, RECURSE_DIR_SORT|RECURSE_DIR_ENSURE_TYPE|RECURSE_DIR_SAME_MOUNT, recurse_dir_callback, &list_recurse_dir) >= 0);
t2 = now(CLOCK_MONOTONIC);
- if (r == -ENOENT) {
- log_warning_errno(r, "Couldn't open directory %s, ignoring: %m", p);
- return EXIT_TEST_SKIP;
- }
- assert_se(r >= 0);
t3 = now(CLOCK_MONOTONIC);
assert_se(nftw(p, nftw_cb, 64, FTW_PHYS|FTW_MOUNT) >= 0);