All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: bernd@bsbernd.com
Cc: neal@gompa.dev, fuse-devel@lists.linux.dev
Subject: Re: [PATCH 1/4] mount_fsmount: split superblock creation and move_mount into a helper
Date: Wed, 30 Sep 2026 08:13:50 -0700	[thread overview]
Message-ID: <20260930151350.GN6253@frogsfrogsfrogs> (raw)
In-Reply-To: <20260930-mount-service-use-mount-fsmount-v1-1-d585598896ee@bsbernd.com>

On Wed, Sep 30, 2026 at 03:44:33PM +0200, Bernd Schubert via B4 Relay wrote:
> From: Bernd Schubert <bernd@bsbernd.com>
> 
> This is a preparation patch. fuse_kern_fsmount() ran fsconfig
> CREATE, fsmount() and move_mount() inline. A later commit will make
> mount_service.c call the same three calls after it has run FSOPEN,
> SOURCE and MNTOPTS itself, so this moves them into
> fuse_fsmount_create_and_move(). The fsopen fd stays owned by the
> caller, because mount_service.c will close mo->fsopenfd itself
> later.
> 
> fuse_kern_fsmount() now converts MS_* flags before calling the
> helper, so unsupported flags are caught before the superblock is
> created, not after.
> 
> Signed-off-by: Bernd Schubert <bernd@bsbernd.com>

This is a simple hoist, so
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  lib/mount_fsmount.c | 86 +++++++++++++++++++++++++++++++----------------------
>  lib/mount_i_linux.h | 18 +++++++++++
>  2 files changed, 69 insertions(+), 35 deletions(-)
> 
> diff --git a/lib/mount_fsmount.c b/lib/mount_fsmount.c
> index b2d0453e5c93..0b1fd4300d2d 100644
> --- a/lib/mount_fsmount.c
> +++ b/lib/mount_fsmount.c
> @@ -489,6 +489,53 @@ void fuse_kern_umount_mountfd(int mountfd)
>  	}
>  }
>  
> +int fuse_fsmount_create_and_move(int fsfd, unsigned int mount_attrs,
> +				 int dest_mnt_fd, const char *dest_path,
> +				 int *mountfd_out)
> +{
> +	int mountfd;
> +	int res;
> +
> +	res = fuse_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
> +	if (res == -1) {
> +		int save_errno = errno;
> +
> +		log_fsconfig_kmsg(fsfd);
> +		fuse_log(FUSE_LOG_ERR, "fuse: fsconfig CREATE failed: %s\n",
> +			 strerror(save_errno));
> +		return -save_errno;
> +	}
> +
> +	mountfd = fuse_fsmount(fsfd, FSMOUNT_CLOEXEC, mount_attrs);
> +	if (mountfd == -1) {
> +		int save_errno = errno;
> +
> +		log_fsconfig_kmsg(fsfd);
> +		fuse_log(FUSE_LOG_ERR, "fuse: fsmount failed: %s\n",
> +			 strerror(save_errno));
> +		return -save_errno;
> +	}
> +
> +	if (dest_mnt_fd >= 0)
> +		res = fuse_move_mount(mountfd, "", dest_mnt_fd, "",
> +				      MOVE_MOUNT_F_EMPTY_PATH |
> +					      MOVE_MOUNT_T_EMPTY_PATH);
> +	else
> +		res = fuse_move_mount(mountfd, "", AT_FDCWD, dest_path,
> +				      MOVE_MOUNT_F_EMPTY_PATH);
> +	if (res == -1) {
> +		int save_errno = errno;
> +
> +		fuse_log(FUSE_LOG_ERR, "fuse: move_mount failed: %s\n",
> +			 strerror(save_errno));
> +		close(mountfd);
> +		return -save_errno;
> +	}
> +
> +	*mountfd_out = mountfd;
> +	return 0;
> +}
> +
>  int fuse_kern_fsmount(const char *mnt, int dest_mnt_fd, unsigned long flags,
>  		      int blkdev, const char *fsname, const char *subtype,
>  		      const char *source_dev, const char *kernel_opts,
> @@ -584,16 +631,6 @@ int fuse_kern_fsmount(const char *mnt, int dest_mnt_fd, unsigned long flags,
>  		goto out_free;
>  	}
>  
> -	/* Create the filesystem instance */
> -	res = fuse_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
> -	if (res == -1) {
> -		err = -errno;
> -		log_fsconfig_kmsg(fsfd);
> -		fuse_log(FUSE_LOG_ERR, "fuse: fsconfig CREATE failed: %s\n",
> -			 strerror(errno));
> -		goto out_free;
> -	}
> -
>  	/* Convert MS_* flags to MOUNT_ATTR_* for fsmount() */
>  	flags = ms_flags_to_mount_attrs(flags, &mount_attrs);
>  	if (flags != 0) {
> @@ -602,33 +639,14 @@ int fuse_kern_fsmount(const char *mnt, int dest_mnt_fd, unsigned long flags,
>  		goto out_free;
>  	}
>  
> -	/* Create mount object with mount attributes */
> -	mountfd = fuse_fsmount(fsfd, FSMOUNT_CLOEXEC, mount_attrs);
> -	if (mountfd == -1) {
> -		err = -errno;
> -		log_fsconfig_kmsg(fsfd);
> -		fuse_log(FUSE_LOG_ERR, "fuse: fsmount failed: %s\n",
> -			 strerror(errno));
> +	err = fuse_fsmount_create_and_move(fsfd, mount_attrs, dest_mnt_fd, mnt,
> +					   &mountfd);
> +	if (err)
>  		goto out_free;
> -	}
>  
>  	close(fsfd);
>  	fsfd = -1;
>  
> -	if (dest_mnt_fd >= 0)
> -		res = fuse_move_mount(mountfd, "", dest_mnt_fd, "",
> -				 MOVE_MOUNT_F_EMPTY_PATH |
> -					 MOVE_MOUNT_T_EMPTY_PATH);
> -	else
> -		res = fuse_move_mount(mountfd, "", AT_FDCWD, mnt,
> -				 MOVE_MOUNT_F_EMPTY_PATH);
> -	if (res == -1) {
> -		err = -errno;
> -		fuse_log(FUSE_LOG_ERR, "fuse: move_mount failed: %s\n",
> -			 strerror(errno));
> -		goto out_close_mntfd;
> -	}
> -
>  	res = fuse_mnt_add_mount_helper(mnt, source, type, mtab_opts);
>  	if (res == -1) {
>  		err = -EIO;
> @@ -645,9 +663,7 @@ int fuse_kern_fsmount(const char *mnt, int dest_mnt_fd, unsigned long flags,
>  
>  out_umount:
>  	fuse_kern_umount_mountfd(mountfd);
> -out_close_mntfd:
> -	if (mountfd != -1)
> -		close(mountfd);
> +	close(mountfd);
>  out_free:
>  	free(source);
>  	free(type);
> diff --git a/lib/mount_i_linux.h b/lib/mount_i_linux.h
> index 8cf7ff4532c6..35bb54c82236 100644
> --- a/lib/mount_i_linux.h
> +++ b/lib/mount_i_linux.h
> @@ -86,6 +86,24 @@ int fuse_kern_fsmount(const char *mnt, int mnt_fd, unsigned long flags,
>  int fuse_kern_fsmount_mo(const char *mnt, const struct mount_opts *mo,
>  			 const char *mtab_opts, int *mountfd_out);
>  
> +/**
> + * Create the superblock and attach the resulting mount to a destination.
> + *
> + * The fsopen fd stays owned by the caller - a caller that keeps it in
> + * long-lived state must not be left with a descriptor closed behind its back.
> + *
> + * @fsfd fsopen fd, fully configured
> + * @mount_attrs MOUNT_ATTR_* flags, from ms_flags_to_mount_attrs()
> + * @dest_mnt_fd pre-resolved destination fd, or -1 to use @dest_path
> + * @dest_path destination path, used only when @dest_mnt_fd is -1
> + * @mountfd_out on success receives the fsmount() fd, to be closed by the
> + *              caller and usable for fuse_kern_umount_mountfd()
> + * @return 0 on success, negative error code on failure
> + */
> +int fuse_fsmount_create_and_move(int fsfd, unsigned int mount_attrs,
> +				 int dest_mnt_fd, const char *dest_path,
> +				 int *mountfd_out);
> +
>  /**
>   * Unmount (lazily) the mount @mountfd was created for, without a path lookup.
>   *
> 
> -- 
> 2.53.0
> 
> 
> 

  reply	other threads:[~2026-09-30 15:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 13:44 [PATCH 0/4] libfuse: Avoid mount API code dup between mount-service and libfuse Bernd Schubert
2026-09-30 13:44 ` Bernd Schubert via B4 Relay
2026-09-30 13:44 ` [PATCH 1/4] mount_fsmount: split superblock creation and move_mount into a helper Bernd Schubert
2026-09-30 13:44   ` Bernd Schubert via B4 Relay
2026-09-30 15:13   ` Darrick J. Wong [this message]
2026-09-30 13:44 ` [PATCH 2/4] mount_service: mount via the shared fsmount helper Bernd Schubert
2026-09-30 13:44   ` Bernd Schubert via B4 Relay
2026-09-30 15:16   ` Darrick J. Wong
2026-09-30 13:44 ` [PATCH 3/4] mount_util: share the mtab flag-option builder Bernd Schubert
2026-09-30 13:44   ` Bernd Schubert via B4 Relay
2026-09-30 15:20   ` Darrick J. Wong
2026-09-30 13:44 ` [PATCH 4/4] mount/fuse_service: share the service socket helpers Bernd Schubert
2026-09-30 13:44   ` Bernd Schubert via B4 Relay
2026-09-30 15:23   ` Darrick J. Wong

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=20260930151350.GN6253@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=bernd@bsbernd.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=neal@gompa.dev \
    /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.