diff options
| author | Amir Goldstein <[email protected]> | 2025-05-09 13:32:38 +0000 |
|---|---|---|
| committer | Christian Brauner <[email protected]> | 2025-05-12 09:40:12 +0000 |
| commit | e897b9b1334bab7427f062e4ec1f4297676c60da (patch) | |
| tree | 76853a7be279852a55894efaa9a8a2a95b0f57be /tools/testing/selftests/filesystems/utils.c | |
| parent | selftests/fs/mount-notify: build with tools include dir (diff) | |
| download | kernel-e897b9b1334bab7427f062e4ec1f4297676c60da.tar.gz kernel-e897b9b1334bab7427f062e4ec1f4297676c60da.zip | |
selftests/filesystems: create get_unique_mnt_id() helper
Add helper to utils.c and use it in mount-notify and statmount tests.
Linking with utils.c drags in a dependecy with libcap, so add it to the
Makefile of the tests.
Reviewed-by: John Hubbard <[email protected]>
Signed-off-by: Amir Goldstein <[email protected]>
Link: https://lore.kernel.org/[email protected]
Reviewed-by: Christian Brauner <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
Diffstat (limited to 'tools/testing/selftests/filesystems/utils.c')
| -rw-r--r-- | tools/testing/selftests/filesystems/utils.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/testing/selftests/filesystems/utils.c b/tools/testing/selftests/filesystems/utils.c index e553c89c5b19..5a114af822af 100644 --- a/tools/testing/selftests/filesystems/utils.c +++ b/tools/testing/selftests/filesystems/utils.c @@ -19,6 +19,8 @@ #include <sys/wait.h> #include <sys/xattr.h> +#include "../kselftest.h" +#include "wrappers.h" #include "utils.h" #define MAX_USERNS_LEVEL 32 @@ -499,3 +501,23 @@ out: cap_free(caps); return fret; } + +uint64_t get_unique_mnt_id(const char *path) +{ + struct statx sx; + int ret; + + ret = statx(AT_FDCWD, path, 0, STATX_MNT_ID_UNIQUE, &sx); + if (ret == -1) { + ksft_print_msg("retrieving unique mount ID for %s: %s\n", path, + strerror(errno)); + return 0; + } + + if (!(sx.stx_mask & STATX_MNT_ID_UNIQUE)) { + ksft_print_msg("no unique mount ID available for %s\n", path); + return 0; + } + + return sx.stx_mnt_id; +} |
