From: Cyril Hrubis <chrubis@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3] mount_setattr02.c: Check mount_setattr attr propagation
Date: Fri, 11 Jul 2025 11:21:47 +0200 [thread overview]
Message-ID: <aHDXqyMUZ_KdNV1U@yuki.lan> (raw)
In-Reply-To: <20250319114144.24349-1-wegao@suse.com>
Hi!
> move_mount01 move_mount01
> move_mount02 move_mount02
> diff --git a/testcases/kernel/syscalls/mount_setattr/.gitignore b/testcases/kernel/syscalls/mount_setattr/.gitignore
> index 52a77b9ca..1654f27de 100644
> --- a/testcases/kernel/syscalls/mount_setattr/.gitignore
> +++ b/testcases/kernel/syscalls/mount_setattr/.gitignore
> @@ -1 +1,2 @@
> /mount_setattr01
> +/mount_setattr02
> diff --git a/testcases/kernel/syscalls/mount_setattr/mount_setattr02.c b/testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
> new file mode 100644
> index 000000000..fcc088e3b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
> @@ -0,0 +1,99 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2025 SUSE LLC Wei Gao <wegao@suse.com>
> + */
> +
> +/*\
> + * Basic mount_setattr() test.
> + *
> + * Test basic propagation mount attributes are set correctly.
This is too sparse. We should at least write here which parameters we
are testing, obviously the test is checking if the propagation field of
the structure is handled properly.
And then we should list what we are trying to test
- When propagation is set to 0 it's not changed
- EINVAL with propagation set to -1
- MS_SHARED turns propagation on
- MS_PRIVATE turns propagation off
...
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <sys/statvfs.h>
> +#include "tst_test.h"
> +#include "lapi/fsmount.h"
> +#include "tst_safe_stdio.h"
> +
> +static char *tmpdir;
> +
> +static int mounted;
> +
> +static bool is_shared_mount(const char *path)
> +{
> + FILE *file = SAFE_FOPEN("/proc/self/mountinfo", "r");
> +
> + char line[PATH_MAX];
> + bool found = false;
> +
> + while (fgets(line, sizeof(line), file)) {
> + char mntpoint[PATH_MAX];
> + char opts[256];
> +
> + if (sscanf(line, "%*d %*d %*d:%*d %*s %255s %*s %255s",
> + mntpoint, opts) != 2)
> + continue;
> +
> + if (strcmp(mntpoint, path) != 0)
> + continue;
> +
> + if (strstr(opts, "shared:") != NULL) {
> + found = true;
> + break;
> + }
> + }
> +
> + fclose(file);
> + return found;
> +}
> +
> +static void cleanup(void)
> +{
> + if (mounted)
> + SAFE_UMOUNT(tmpdir);
> +}
> +
> +static void setup(void)
> +{
> + tmpdir = tst_tmpdir_path();
> + SAFE_UNSHARE(CLONE_NEWNS);
> + SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
> + SAFE_MOUNT("testing", tmpdir, "tmpfs", MS_NOATIME | MS_NODEV, "");
^
We tend to include ltp in names that are visible on
the system so that's clear where they came from.
It would be a bit better if the name of the mount
was "ltp-mount_setattr" or something that makes it clear
which test was mounting it.
> + mounted = 1;
> +}
> +
> +static void run(void)
> +{
> + struct mount_attr attr = {
> + .attr_set = MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOEXEC | MOUNT_ATTR_RELATIME,
> + .attr_clr = MOUNT_ATTR__ATIME,
I suppose that we can as well set these to zero as we are trying to test
only the propagation part. Or is there a reason why we are specifying
any attributes here?
> + };
> +
> + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
> + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
> +
> + attr.propagation = -1;
> + TST_EXP_FAIL_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)), EINVAL);
> + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
> +
> + attr.propagation = MS_SHARED;
> + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
> + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 1);
Here we should once more check with propagation = 0 and expect that the
mount is shared after that call.
> + attr.propagation = MS_PRIVATE;
> + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
> + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
> +
> + attr.propagation = MS_SLAVE;
> + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
> + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
Can we figure out slave mount from the mountinfo? I suppose there will
be slave in in the opts.
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .setup = setup,
> + .cleanup = cleanup,
> + .needs_root = 1,
> + .needs_tmpdir = 1,
> +};
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-07-11 9:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 2:04 [LTP] [PATCH v1] mount_setattr02.c: Check mount_setattr attr.propagation Wei Gao via ltp
2025-02-18 15:18 ` Petr Vorel
2025-02-19 8:47 ` Wei Gao via ltp
2025-02-19 9:05 ` Petr Vorel
2025-02-19 9:51 ` Wei Gao via ltp
2025-02-19 11:24 ` Petr Vorel
2025-02-19 8:29 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-02-21 12:54 ` Petr Vorel
2025-02-24 1:44 ` Wei Gao via ltp
2025-03-19 11:41 ` [LTP] [PATCH v3] mount_setattr02.c: Check mount_setattr attr propagation Wei Gao via ltp
2025-07-11 9:21 ` Cyril Hrubis [this message]
2025-07-24 13:40 ` [LTP] [PATCH v4] " Wei Gao via ltp
2025-07-28 15:37 ` 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=aHDXqyMUZ_KdNV1U@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=wegao@suse.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.