From: Bernd Schubert <bernd@bsbernd.com>
To: linux-fsdevel@vger.kernel.org
Cc: Miklos Szeredi <miklos@szeredi.hu>,
Joanne Koong <joannelkoong@gmail.com>,
"Darrick J. Wong" <djwong@kernel.org>,
Bernd Schubert <bernd@bsbernd.com>,
Bernd Schubert <bschubert@ddn.com>
Subject: [PATCH 06/19] mount.c: Split fuse_mount_sys to prepare privileged sync FUSE_INIT
Date: Mon, 23 Mar 2026 18:45:01 +0100 [thread overview]
Message-ID: <20260323-fuse-init-before-mount-v1-6-a52d3040af69@bsbernd.com> (raw)
In-Reply-To: <20260323-fuse-init-before-mount-v1-0-a52d3040af69@bsbernd.com>
From: Bernd Schubert <bschubert@ddn.com>
Synchronous FUSE_INIT needs to spawn a worker thread to handle
FUSE_INIT before starting the mount. For that it needs to have
the device file descriptor - this is preparation work and
fuse_mount_sys() is split into fuse_kern_mount_prepare()
and fuse_kern_do_mount().
Signed-off-by: Bernd Schubert <bschubert@ddn.com>
---
lib/mount.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 69 insertions(+), 19 deletions(-)
diff --git a/lib/mount.c b/lib/mount.c
index 398bf9e7a86743ac3c99f0cc2975e8db92346013..6e404451cc9edc8e35434cc31f25612cfc4edca1 100644
--- a/lib/mount.c
+++ b/lib/mount.c
@@ -506,13 +506,11 @@ static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo,
#define O_CLOEXEC 0
#endif
-static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
- const char *mnt_opts)
+static int fuse_kern_mount_prepare(const char *mnt,
+ struct mount_opts *mo)
{
char tmp[128];
const char *devname = getenv(FUSE_KERN_DEVICE_ENV) ?: "/dev/fuse";
- char *source = NULL;
- char *type = NULL;
struct stat stbuf;
int fd;
int res;
@@ -524,32 +522,58 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
res = stat(mnt, &stbuf);
if (res == -1) {
- fuse_log(FUSE_LOG_ERR, "fuse: failed to access mountpoint %s: %s\n",
- mnt, strerror(errno));
+ fuse_log(FUSE_LOG_ERR,
+ "fuse: failed to access mountpoint %s: %s\n", mnt,
+ strerror(errno));
return -1;
}
fd = open(devname, O_RDWR | O_CLOEXEC);
if (fd == -1) {
if (errno == ENODEV || errno == ENOENT)
- fuse_log(FUSE_LOG_ERR,
+ fuse_log(
+ FUSE_LOG_ERR,
"fuse: device %s not found. Kernel module not loaded?\n",
devname);
else
fuse_log(FUSE_LOG_ERR, "fuse: failed to open %s: %s\n",
- devname, strerror(errno));
+ devname, strerror(errno));
return -1;
}
if (!O_CLOEXEC)
fcntl(fd, F_SETFD, FD_CLOEXEC);
- snprintf(tmp, sizeof(tmp), "fd=%i,rootmode=%o,user_id=%u,group_id=%u",
+ snprintf(tmp, sizeof(tmp), "fd=%i,rootmode=%o,user_id=%u,group_id=%u",
fd, stbuf.st_mode & S_IFMT, getuid(), getgid());
res = fuse_opt_add_opt(&mo->kernel_opts, tmp);
if (res == -1)
goto out_close;
+ return fd;
+
+out_close:
+ close(fd);
+ return -1;
+}
+
+/**
+ * Complete the mount operation with an already-opened fd
+ * @mnt: mountpoint
+ * @mo: mount options
+ * @mnt_opts: mount options to pass to the kernel
+ *
+ * Returns: 0 on success, -1 on failure, -2 if fusermount should be used
+ */
+static int fuse_kern_do_mount(const char *mnt, struct mount_opts *mo,
+ const char *mnt_opts)
+{
+ const char *devname = getenv(FUSE_KERN_DEVICE_ENV) ?: "/dev/fuse";
+ char *source = NULL;
+ char *type = NULL;
+ int res;
+
+ res = -ENOMEM;
source = malloc((mo->fsname ? strlen(mo->fsname) : 0) +
(mo->subtype ? strlen(mo->subtype) : 0) +
strlen(devname) + 32);
@@ -593,10 +617,11 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
if (mo->blkdev && errno == ENODEV &&
!fuse_mnt_check_fuseblk())
fuse_log(FUSE_LOG_ERR,
- "fuse: 'fuseblk' support missing\n");
+ "fuse: 'fuseblk' support missing\n");
else
- fuse_log(FUSE_LOG_ERR, "fuse: mount failed: %s\n",
- strerror(errno_save));
+ fuse_log(FUSE_LOG_ERR,
+ "fuse: mount failed: %s\n",
+ strerror(errno_save));
}
goto out_close;
@@ -619,17 +644,35 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
free(type);
free(source);
- return fd;
+ return 0;
out_umount:
umount2(mnt, 2); /* lazy umount */
out_close:
free(type);
free(source);
- close(fd);
return res;
}
+static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
+ const char *mnt_opts)
+{
+ int fd;
+ int res;
+
+ fd = fuse_kern_mount_prepare(mnt, mo);
+ if (fd == -1)
+ return -1;
+
+ res = fuse_kern_do_mount(mnt, mo, mnt_opts);
+ if (res) {
+ close(fd);
+ return res;
+ }
+
+ return fd;
+}
+
static int get_mnt_flag_opts(char **mnt_optsp, int flags)
{
int i;
@@ -678,6 +721,17 @@ void destroy_mount_opts(struct mount_opts *mo)
free(mo);
}
+static int fuse_kern_mount_get_base_mnt_opts(struct mount_opts *mo,
+ char **mnt_optsp)
+{
+ if (get_mnt_flag_opts(mnt_optsp, mo->flags) == -1)
+ return -1;
+ if (mo->kernel_opts && fuse_opt_add_opt(mnt_optsp, mo->kernel_opts) == -1)
+ return -1;
+ if (mo->mtab_opts && fuse_opt_add_opt(mnt_optsp, mo->mtab_opts) == -1)
+ return -1;
+ return 0;
+}
int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo)
{
@@ -685,11 +739,7 @@ int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo)
char *mnt_opts = NULL;
res = -1;
- if (get_mnt_flag_opts(&mnt_opts, mo->flags) == -1)
- goto out;
- if (mo->kernel_opts && fuse_opt_add_opt(&mnt_opts, mo->kernel_opts) == -1)
- goto out;
- if (mo->mtab_opts && fuse_opt_add_opt(&mnt_opts, mo->mtab_opts) == -1)
+ if (fuse_kern_mount_get_base_mnt_opts(mo, &mnt_opts) == -1)
goto out;
res = fuse_mount_sys(mountpoint, mo, mnt_opts);
--
2.43.0
next prev parent reply other threads:[~2026-03-23 17:45 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 17:44 [PATCH 00/19] libfuse: Add support for synchronous init Bernd Schubert
2026-03-23 17:44 ` [PATCH 01/19] ci-build: Add environment logging Bernd Schubert
2026-03-23 17:44 ` [PATCH 02/19] Add 'STRCPY' to the checkpatch ignore option Bernd Schubert
2026-03-23 21:03 ` Darrick J. Wong
2026-03-23 17:44 ` [PATCH 03/19] checkpatch.pl: Add _Atomic to $Attribute patttern Bernd Schubert
2026-03-23 21:09 ` Darrick J. Wong
2026-03-23 17:44 ` [PATCH 04/19] Add a new daemonize API Bernd Schubert
2026-03-23 22:28 ` Darrick J. Wong
2026-03-24 17:36 ` Bernd Schubert
2026-03-24 22:20 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 05/19] Sync fuse_kernel.h with linux-6.18 Bernd Schubert
2026-03-23 21:16 ` Darrick J. Wong
2026-03-23 17:45 ` Bernd Schubert [this message]
2026-03-23 22:34 ` [PATCH 06/19] mount.c: Split fuse_mount_sys to prepare privileged sync FUSE_INIT Darrick J. Wong
2026-03-23 17:45 ` [PATCH 07/19] Add FUSE_MOUNT_FALLBACK_NEEDED define for -2 mount errors Bernd Schubert
2026-03-23 22:36 ` Darrick J. Wong
2026-03-24 18:03 ` Bernd Schubert
2026-03-23 17:45 ` [PATCH 08/19] Refactor mount code / move common functions to mount_util.c Bernd Schubert
2026-03-23 22:40 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 09/19] Move mount flags to mount_i.h Bernd Schubert
2026-03-23 22:45 ` Darrick J. Wong
2026-03-24 18:40 ` Bernd Schubert
2026-03-23 17:45 ` [PATCH 10/19] conftest.py: Add more valgrind filter patterns Bernd Schubert
2026-03-23 17:45 ` [PATCH 11/19] Add support for the new linux mount API Bernd Schubert
2026-03-23 23:42 ` Darrick J. Wong
2026-03-24 20:16 ` Bernd Schubert
2026-03-24 22:46 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 12/19] fuse mount: Support synchronous FUSE_INIT (privileged daemon) Bernd Schubert
2026-03-24 0:03 ` Darrick J. Wong
2026-03-24 20:42 ` Bernd Schubert
2026-03-24 22:50 ` Darrick J. Wong
2026-03-25 7:52 ` Bernd Schubert
2026-03-25 16:42 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 13/19] Add fuse_session_set_debug() to enable debug output without foreground Bernd Schubert
2026-03-24 0:04 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 14/19] Move more generic mount code to mount_util.{c,h} Bernd Schubert
2026-03-24 0:06 ` Darrick J. Wong
2026-03-24 20:57 ` Bernd Schubert
2026-03-23 17:45 ` [PATCH 15/19] Split the fusermount do_mount function Bernd Schubert
2026-03-24 0:14 ` Darrick J. Wong
2026-03-24 21:05 ` Bernd Schubert
2026-03-24 22:53 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 16/19] fusermount: Refactor extract_x_options Bernd Schubert
2026-03-24 0:18 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 17/19] Make fusermount work bidirectional for sync init Bernd Schubert
2026-03-24 19:35 ` Darrick J. Wong
2026-03-24 21:24 ` Bernd Schubert
2026-03-24 22:59 ` Darrick J. Wong
2026-03-25 19:48 ` Bernd Schubert
2026-03-25 22:03 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 18/19] New mount API: Filter out "user=" Bernd Schubert
2026-03-24 19:51 ` Darrick J. Wong
2026-03-24 20:01 ` Bernd Schubert
2026-03-24 23:02 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 19/19] Add support for sync-init of unprivileged daemons Bernd Schubert
2026-03-24 20:21 ` Darrick J. Wong
2026-03-24 21:53 ` Bernd Schubert
2026-03-24 23:13 ` Darrick J. Wong
2026-03-24 0:19 ` [PATCH 00/19] libfuse: Add support for synchronous init 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=20260323-fuse-init-before-mount-v1-6-a52d3040af69@bsbernd.com \
--to=bernd@bsbernd.com \
--cc=bschubert@ddn.com \
--cc=djwong@kernel.org \
--cc=joannelkoong@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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