From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 08/13] Add statmount03 test
Date: Thu, 3 Oct 2024 15:27:33 +0200 [thread overview]
Message-ID: <Zv6bxSyf-NMxc_3C@yuki.lan> (raw)
In-Reply-To: <20240909-listmount_statmount-v4-8-39558204ddf0@suse.com>
Hi!
> This test verifies that statmount() is correctly reading mount
> information (mount id, parent mount id, mount attributes etc.)
> using STATMOUNT_MNT_BASIC.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> runtest/syscalls | 1 +
> testcases/kernel/syscalls/statmount/.gitignore | 1 +
> testcases/kernel/syscalls/statmount/statmount.h | 24 ++++
> testcases/kernel/syscalls/statmount/statmount03.c | 137 ++++++++++++++++++++++
> 4 files changed, 163 insertions(+)
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index e028baf19..ec11a3a21 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1570,6 +1570,7 @@ stat04_64 stat04_64
>
> statmount01 statmount01
> statmount02 statmount02
> +statmount03 statmount03
>
> statfs01 statfs01
> statfs01_64 statfs01_64
> diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
> index a30b9565f..2a02bf721 100644
> --- a/testcases/kernel/syscalls/statmount/.gitignore
> +++ b/testcases/kernel/syscalls/statmount/.gitignore
> @@ -1,2 +1,3 @@
> statmount01
> statmount02
> +statmount03
> diff --git a/testcases/kernel/syscalls/statmount/statmount.h b/testcases/kernel/syscalls/statmount/statmount.h
> index e807c8288..5cd54242c 100644
> --- a/testcases/kernel/syscalls/statmount/statmount.h
> +++ b/testcases/kernel/syscalls/statmount/statmount.h
> @@ -10,6 +10,7 @@
> #include "tst_test.h"
> #include "lapi/mount.h"
> #include "lapi/syscalls.h"
> +#include "tst_safe_stdio.h"
>
> static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *buf,
> size_t bufsize, unsigned int flags)
> @@ -23,4 +24,27 @@ static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *bu
> return tst_syscall(__NR_statmount, &req, buf, bufsize, flags);
> }
>
> +static inline int read_peer_group(const char *path)
> +{
> + FILE *file;
> + char line[PATH_MAX];
> + char mroot[PATH_MAX];
> + int group = -1;
> +
> + file = SAFE_FOPEN("/proc/self/mountinfo", "r");
> +
> + while (fgets(line, sizeof(line), file)) {
> + if (sscanf(line, "%*d %*d %*d:%*d %s %*s %*s shared:%d", mroot, &group) != 2)
> + continue;
> +
> + if (strcmp(mroot, path) == 0)
> + break;
> + }
> +
> + if (group == -1)
> + tst_brk(TBROK, "Can't reed peer group ID for %s", path);
> +
> + return group;
> +}
> +
> #endif
> diff --git a/testcases/kernel/syscalls/statmount/statmount03.c b/testcases/kernel/syscalls/statmount/statmount03.c
> new file mode 100644
> index 000000000..634c4b447
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statmount/statmount03.c
> @@ -0,0 +1,137 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that statmount() is correctly reading mount information
> + * (mount id, parent mount id, mount attributes etc.) using STATMOUNT_MNT_BASIC.
> + *
> + * [Algorithm]
> + *
> + * - create a mount point
> + * - create a new parent folder inside the mount point and obtain its mount info
> + * - create the new "/" mount folder and obtain its mount info
> + * - run statmount() on the mount point using STATMOUNT_MNT_BASIC
> + * - read results and check if mount info are correct
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "statmount.h"
> +#include "lapi/stat.h"
> +#include "lapi/sched.h"
> +
> +#define DIR_A "LTP_DIR_A"
> +#define DIR_B "LTP_DIR_B"
> +
> +static uint64_t mnt_id;
> +static uint64_t mnt_id_old;
> +static uint64_t parent_id;
> +static uint64_t parent_id_old;
> +static uint64_t mnt_peer_group;
> +static uint64_t mnt_master;
> +static struct statmount *st_mount;
> +
> +static void read_mnt_id(
> + const char *path,
> + uint64_t *mnt_id,
> + uint64_t *mnt_id_unique)
> +{
> + struct ltp_statx sx;
> +
> + if (mnt_id) {
> + SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID, &sx);
> + *mnt_id = sx.data.stx_mnt_id;
> + }
> +
> + if (mnt_id_unique) {
> + SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID_UNIQUE, &sx);
> + *mnt_id_unique = sx.data.stx_mnt_id;
> + }
Technically the stx_mnt_id is only valid if the sx.data.stx_mask has the
STATX_MNT_ID or STATX_MNT_ID_UNIQUE set when statx() returns.
We have min_kver set to 6.8 so this should always work, but it wouldn't
hurt to double check.
> +}
> +
> +static struct tcase {
> + uint64_t prop_type;
> + char *msg;
> +} tcases[] = {
> + { MS_PRIVATE, TST_TO_STR_(MS_PRIVATE) },
> + { MS_SHARED, TST_TO_STR_(MS_SHARED) },
> + { MS_SLAVE, TST_TO_STR_(MS_SLAVE) },
> + { MS_UNBINDABLE, TST_TO_STR_(MS_UNBINDABLE) },
> +};
> +
> +static void run(unsigned int i)
> +{
> + struct tcase *tc = &tcases[i];
> +
> + tst_res(TINFO, "Testing statmount() on %s", tc->msg);
> +
> + SAFE_MOUNT(DIR_B, DIR_A, "none", MS_BIND, NULL);
> + SAFE_MOUNT("none", DIR_A, "none", tc->prop_type, NULL);
> + read_mnt_id(DIR_A, &mnt_id_old, &mnt_id);
> +
> + memset(st_mount, 0, sizeof(struct statmount));
> +
> + TST_EXP_PASS(statmount(mnt_id, STATMOUNT_MNT_BASIC, st_mount,
> + sizeof(struct statmount), 0));
> +
> + SAFE_UMOUNT(DIR_A);
> +
> + if (TST_RET == -1)
> + return;
Here as well if (!TST_PASS)
> + /* s->sm.mnt_peer_group = IS_MNT_SHARED(m) ? m->mnt_group_id : 0;
> + * s->sm.mnt_master = IS_MNT_SLAVE(m) ? m->mnt_master->mnt_group_id : 0;
> + */
This comment looks like a leftover.
> + mnt_peer_group = tc->prop_type == MS_SHARED ? read_peer_group(DIR_A) : 0;
> + mnt_master = tc->prop_type == MS_SLAVE ? read_peer_group(DIR_A) : 0;
> +
> + TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_BASIC);
> + TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
> + TST_EXP_EQ_LI(st_mount->mnt_id, mnt_id);
> + TST_EXP_EQ_LI(st_mount->mnt_id_old, mnt_id_old);
> + TST_EXP_EQ_LI(st_mount->mnt_parent_id, parent_id);
> + TST_EXP_EQ_LI(st_mount->mnt_parent_id_old, parent_id_old);
> + TST_EXP_EQ_LU(st_mount->mnt_propagation & tc->prop_type, tc->prop_type);
> + TST_EXP_EQ_LI(st_mount->mnt_master, mnt_master);
> + TST_EXP_EQ_LI(st_mount->mnt_peer_group, mnt_peer_group);
> +}
Otherwise it looks good:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-10-03 13:29 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
2024-09-09 16:21 ` Andrea Cervesato via ltp
2024-10-02 12:27 ` Cyril Hrubis
2024-10-02 13:00 ` Andrea Cervesato via ltp
2024-09-09 10:00 ` [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls Andrea Cervesato
2024-10-02 12:30 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations Andrea Cervesato
2024-10-02 14:12 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 04/13] Add listmount01 test Andrea Cervesato
2024-10-02 14:05 ` Cyril Hrubis
2024-10-02 14:14 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 05/13] Add listmount02 test Andrea Cervesato
2024-10-02 14:37 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 06/13] Add statmount01 test Andrea Cervesato
2024-10-02 14:45 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 07/13] Add statmount02 test Andrea Cervesato
2024-10-02 15:15 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 08/13] Add statmount03 test Andrea Cervesato
2024-10-03 13:27 ` Cyril Hrubis [this message]
2024-09-09 10:00 ` [LTP] [PATCH v4 09/13] Add statmount04 test Andrea Cervesato
2024-10-03 13:51 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 10/13] Add statmount05 test Andrea Cervesato
2024-10-03 14:09 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro Andrea Cervesato
2024-10-03 14:13 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 12/13] Add statmount06 test Andrea Cervesato
2024-10-03 14:20 ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 13/13] Add statmount07 test Andrea Cervesato
2024-10-03 14:34 ` Cyril Hrubis
2024-10-04 8:19 ` Andrea Cervesato via ltp
2024-10-04 9:17 ` Cyril Hrubis
2024-10-04 11:03 ` Andrea Cervesato via ltp
2024-10-04 12:02 ` Jan Kara
2024-10-03 14:42 ` [LTP] [PATCH v4 00/13] statmount/listmount testing suites Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zv6bxSyf-NMxc_3C@yuki.lan \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox