Re: [PATCH] nilfs2: keep the current mount options on remount

From: Ryusuke Konishi

Date: Sat Dec 05 2026 - 11:55:26 EST


On Sat, Dec 5, 2026 at 12:28 PM Yifan Feng wrote:
>
> nilfs_init_fs_context() fills every new context with the default
> options, and nilfs_reconfigure() installs them as they are. So a
> remount that does not repeat nobarrier, errors=, order=strict and
> discard resets them:
>
> # mount -t nilfs2 -o nobarrier,discard /dev/vda /mnt
> # findmnt -no OPTIONS /mnt
> rw,relatime,nobarrier,discard
> # mount -o remount,noatime /dev/vda /mnt
> # findmnt -no OPTIONS /mnt
> rw,noatime
>
> mount(8) hides this when it is given the mount point only, because it
> then passes the current options again. Before the conversion to the
> mount API a remount changed only the options that it named.
>
> For a remount, start from the options in use.
>
> Fixes: 36defdd9d7c6 ("nilfs2: convert to use the new mount API")
> Signed-off-by: Yifan Feng <evanfengff@xxxxxxxxx>
> ---
> On the for-next branch of nilfs2.git. Tested in QEMU with mount(2), mount(8) and fspick()/fsconfig(); with nobarrier the flush requests were counted before and after each remount.
> Found and written with the help of an AI coding assistant.
>
> fs/nilfs2/super.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
> index ddad1e4f55ce..a4e17d6ee8d7 100644
> --- a/fs/nilfs2/super.c
> +++ b/fs/nilfs2/super.c
> @@ -1286,12 +1286,18 @@ static const struct fs_context_operations nilfs_context_ops = {
> static int nilfs_init_fs_context(struct fs_context *fc)
> {
> struct nilfs_fs_context *ctx;
> + struct the_nilfs *nilfs;
>
> ctx = kzalloc_obj(*ctx);
> if (!ctx)
> return -ENOMEM;
>
> - ctx->ns_mount_opt = NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER;
> + if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
> + nilfs = fc->root->d_sb->s_fs_info;
> + ctx->ns_mount_opt = nilfs->ns_mount_opt;
> + } else {
> + ctx->ns_mount_opt = NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER;
> + }
> fc->fs_private = ctx;
> fc->ops = &nilfs_context_ops;
>
>
> base-commit: 499a46e4a0f0ff642d5fe2a53bb04a0de64cfe74
> --
> 2.39.3 (Apple Git-146)
>

Hi Yifan,

Thank you for catching this regression and sending the fix! It was a
bit surprising to realize that this behavior had been broken since the
mount API conversion.

I also ran tests across several kernel versions to see what was
happening, and confirmed both the regression after the mount API
conversion and that this patch restores the original mount option
behavior on remount.

Acked-by: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx>

Viacheslav, could you please apply this patch directly to your tree
with Cc: stable@xxxxxxxxxxxxxxx added?

Thanks,
Ryusuke Konishi