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/statmount/statmount_test_ns.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/statmount/statmount_test_ns.c')
| -rw-r--r-- | tools/testing/selftests/filesystems/statmount/statmount_test_ns.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c b/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c index 70cb0c8b21cf..375a52101d08 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c +++ b/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c @@ -14,6 +14,7 @@ #include <linux/stat.h> #include "statmount.h" +#include "../utils.h" #include "../../kselftest.h" #define NSID_PASS 0 @@ -78,27 +79,6 @@ static int get_mnt_ns_id(const char *mnt_ns, uint64_t *mnt_ns_id) return NSID_PASS; } -static int get_mnt_id(const char *path, uint64_t *mnt_id) -{ - 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 NSID_ERROR; - } - - if (!(sx.stx_mask & STATX_MNT_ID_UNIQUE)) { - ksft_print_msg("no unique mount ID available for %s\n", path); - return NSID_ERROR; - } - - *mnt_id = sx.stx_mnt_id; - return NSID_PASS; -} - static int write_file(const char *path, const char *val) { int fd = open(path, O_WRONLY); @@ -174,9 +154,9 @@ static int _test_statmount_mnt_ns_id(void) if (ret != NSID_PASS) return ret; - ret = get_mnt_id("/", &root_id); - if (ret != NSID_PASS) - return ret; + root_id = get_unique_mnt_id("/"); + if (!root_id) + return NSID_ERROR; ret = statmount(root_id, 0, STATMOUNT_MNT_NS_ID, &sm, sizeof(sm), 0); if (ret == -1) { |
