All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] mount_setattr02.c: Check mount_setattr attr.propagation
Date: Tue, 18 Feb 2025 16:18:58 +0100	[thread overview]
Message-ID: <20250218151858.GA2492575@pevik> (raw)
In-Reply-To: <20250217020423.31602-1-wegao@suse.com>

Hi Wei,

nit: I guess you want to replace dot with space in subject.

> +++ b/testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2025 SUSE LLC Wei Gao <wegao@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Basic mount_setattr() test.
> + * Test basic propagation mount attributes are set correctly.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <sys/statvfs.h>
> +#include "tst_test.h"
> +#include "lapi/fsmount.h"
> +#include "tst_safe_stdio.h"
> +
> +#define DIRA "/DIRA_PROPAGATION_CHECK"

Is it necessary to to use directory under root?

...
> +static void cleanup(void)
> +{

I guess this is due result of:
SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
There should be either a proper detection whether this works or 

../../../../include/lapi/fsmount.h:113: TCONF: syscall(442) __NR_mount_setattr not supported on your arch
mount_setattr02.c:52: TWARN: rmdir(/DIRA_PROPAGATION_CHECK) failed: EBUSY (16)


> +	SAFE_RMDIR(DIRA);

When running on old kernel (e.g. SLES based 4.12) it fails due TCONF:

../../../../include/lapi/fsmount.h:197: TCONF: Test not supported on kernel version < v5.2
mount_setattr02.c:52: TWARN: rmdir(/DIRA_PROPAGATION_CHECK) failed: ENOENT (2)

There should be a flag to remove dir only when it was created.

> +
nit: please remove this new line (I have to keep asking this :( ).
> +}
> +
> +static void setup(void)
> +{
> +	fsopen_supported_by_kernel();
I wonder if this needed for detecting new mount API support. Because second
SAFE_MOUNT also runs code which detects code unsupported:

../../../../include/lapi/fsmount.h:113: TCONF: syscall(442) __NR_mount_setattr not supported on your arch
mount_setattr02.c:52: TWARN: rmdir(/DIRA_PROPAGATION_CHECK) failed: EBUSY (16)

But I have no idea what would be needed to be done to cleanup result of the
first SAFE_MOUNT().

> +
> +	SAFE_MKDIR(DIRA, 0777);
> +}
> +
> +static void run(void)
> +{
> +
and here new line.
> +	SAFE_UNSHARE(CLONE_NEWNS);
> +	SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
> +	SAFE_MOUNT("testing", DIRA, "tmpfs", MS_NOATIME | MS_NODEV, "");
Do these 2 needs to be in the run()? How about move them to setup()?

static int dir_created, mounted;

static void setup(void)
{
	fsopen_supported_by_kernel();

	SAFE_MKDIR(DIRA, 0777);
	dir_created = 1;
	SAFE_UNSHARE(CLONE_NEWNS);
	SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
	SAFE_MOUNT("testing", DIRA, "tmpfs", MS_NOATIME | MS_NODEV, "");
	mounted = 1;
}

static void cleanup(void)
{
	if (mounted)
		SAFE_UMOUNT(DIRA);

	if (dir_created)
		SAFE_RMDIR(DIRA);
}

+ I later create generic helper from is_shared_mount().

Kind regards,
Petr

> +
> +	struct mount_attr attr = {
> +		.attr_set       = MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOEXEC | MOUNT_ATTR_RELATIME,
> +		.attr_clr       = MOUNT_ATTR__ATIME,
> +	};
> +
> +	TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
> +	TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
> +
> +	attr.propagation = -1;
> +	TST_EXP_FAIL_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)), EINVAL);
> +	TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
> +
> +	attr.propagation = MS_SHARED;
> +	TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
> +	TST_EXP_EQ_LI(is_shared_mount(DIRA), 1);
> +
> +	attr.propagation = MS_PRIVATE;
> +	TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
> +	TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
> +
> +	attr.propagation = MS_SLAVE;
> +	TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
> +	TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
> +
> +	SAFE_UMOUNT(DIRA);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +};

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2025-02-18 15:19 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 [this message]
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
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=20250218151858.GA2492575@pevik \
    --to=pvorel@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.