mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-23 14:02:06 -04:00
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 <jhubbard@nvidia.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://lore.kernel.org/20250509133240.529330-7-amir73il@gmail.com Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
committed by
Christian Brauner
parent
c6d9775c20
commit
e897b9b133
@@ -1,7 +1,10 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
|
||||
LDLIBS += -lcap
|
||||
|
||||
TEST_GEN_PROGS := statmount_test statmount_test_ns listmount_test
|
||||
|
||||
include ../../lib.mk
|
||||
|
||||
$(OUTPUT)/statmount_test_ns: ../utils.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) {
|
||||
|
||||
Reference in New Issue
Block a user