Skip to contentSkip to conversation

libfuse: various fixes for new mount code

PATCHBOMB In review Darrick J. Wong 2 participants 31 messages May 5 – May 6

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi Bernd,

The two patchsets under this message try to fix various bugs in both yours and my new fuse filesystem mounting code.

The first patchset branches off the "fuse-service-container" branch on your private github account and fixes a couple of problems I noticed in the new SYNC_INIT + fsmount code. I think they should be applied to libfuse master sooner than later since all that stuff is in master now.

https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-mount-api-fixes_2026-05-04

The second patchset contains some latent bugfixes that I put into my branch after you pulled my series *and* what I hope are sufficient corrections to resolve all the new cppcheck complaints that you sent me. I have now managed to (I think) replicate your setup exactly enough that I can run it here independently.

https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git/log/?h=fuse-service-container-fixes_2026-05-04

--D

#1 lore raw

PATCH 1/2 libfuse: new mount API and SYNC_INIT fixes

Hi all,

Here's a collection of bug fixes and cppcheck cleanups for the new mount API code and the new SYNC_INIT code that landed in main recently.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D
---
Commits in this patchset:
* libfuse: don't use SYNC_INIT unless asked for
* libfuse: always send the subtype to the kernel when using fsconfig()

---
 lib/fuse_lowlevel.c  |    6 +++---
 lib/mount_fsmount.c  |   13 +++++++++++++
 util/mount_service.c |    3 ++-
 3 files changed, 18 insertions(+), 4 deletions(-)
#16 lore raw

PATCH 2/2 libfuse: new mount service container fixes

In reply to Darrick J. Wong

Hi all,

This is a collection of bug fixes and cppcheck cleanups for the new fuse service container code.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D
---
Commits in this patchset:
* util/mount.fuse.c: loop in waitpid
* fuse_service: handle weird behavior during SCM_RIGHTS fd transfers
* examples: improve documentation of the new systemd service fuse servers
* example/single_file: sync backing fd when statx wants us to fsync
* example/single_file: fix ctime handling
* libfuse: fix cppcheck complaints about constifying pointers
* libfuse: fix cppcheck complaints about constifying pointers in user-visible ABI
* util: fix cppcheck complaints about constifying pointers
* fuser_conf: fix cppcheck complaints
* example: fix cppcheck complaints about constifying pointers

---
 example/single_file.h   |    6 +++-
 include/fuse_service.h  |   18 ++++++-----
 example/service_hl.c    |   20 +++++++++++-
 example/service_ll.c    |   20 +++++++++++-
 example/single_file.c   |   31 ++++++++++++++++---
 lib/fuse_service.c      |   76 ++++++++++++++++++++++++++++++++---------------
 lib/fuse_service_stub.c |   17 ++++++-----
 util/fuser_conf.c       |    9 +++---
 util/fuservicemount.c   |    2 +
 util/mount.fuse.c       |    4 ++
 util/mount_service.c    |   68 ++++++++++++++++++++++--------------------
 11 files changed, 183 insertions(+), 88 deletions(-)
#2 lore raw

PATCH 1/2 libfuse: don't use SYNC_INIT unless asked for

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")
---
 lib/fuse_lowlevel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +3 -3
index 0e16845d2f14ff..0a801132590079 100644
@@ -4475,9 +4475,9 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/* SYNC_INIT is required for io_uring(?) */
+		if ((se->uring.enable && !fuse_daemonize_is_used()) || se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");
 		return 0;
#12 lore raw

PATCH 2/2 libfuse: always send the subtype to the kernel when using fsconfig()

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Although it's possible to supply a filesystem subtype when calling fsopen(), it does not pass the stuff after the dot to the mount option parsing mechanism like the legacy mount() call does. Therefore, it's necessary to pass the subtype explicitly via fsconfig() or else the subtype will be missing from the /proc/mounts output.

For example, fuse4fs with the old mount API produces this:

/dev/sda /mnt fuse.ext4 rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0

But with the new mount API, we only get:

/dev/sda /mnt fuse rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0

...which breaks fstests, which requires the fsname to match the string that it passes to mount -t. Update the comment in mount_service.c to match this requirement.

Fixes 14cb7b93bb9688 ("Add support for the new linux mount API")
---
 lib/mount_fsmount.c  |   13 +++++++++++++
 util/mount_service.c |    3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)
lib/mount_fsmount.c +13 -0
index 615271b09758c3..5e13b34ccfc610 100644
@@ -359,6 +359,19 @@ int fuse_kern_fsmount(const char *mnt, unsigned long flags, int blkdev,
 		goto out_free;
 	}
 
+	/* Configure subtype */
+	if (subtype) {
+		res = fsconfig(fsfd, FSCONFIG_SET_STRING, "subtype",
+			       subtype, 0);
+		if (res) {
+			err = -errno;
+			log_fsconfig_kmsg(fsfd);
+			fprintf(stderr, "fuse: fsconfig subtype failed: %s\n",
+				strerror(-err));
+			goto out_free;
+		}
+	}
+
 	/* Configure source */
 	res = fsconfig(fsfd, FSCONFIG_SET_STRING, "source", source, 0);
 	if (res == -1) {
util/mount_service.c +2 -1
index bc5940bc900dad..3fbabfdd69300d 100644
@@ -821,7 +821,8 @@ static void try_fsopen(struct mount_service *mo)
 	/*
 	 * As of Linux 7.0 you can pass subtypes to fsopen, but the manpage for
 	 * fsopen only says that you can pass any value of the second column of
-	 * /proc/filesystems into fsopen.
+	 * /proc/filesystems into fsopen.  You must still call fsconfig() for
+	 * the subtype separately, however.
 	 */
 	mo->fsopenfd = fsopen(fsname(mo), FSOPEN_CLOEXEC);
 }
#17 lore raw

PATCH 1/10 util/mount.fuse.c: loop in waitpid

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

waitpid can return EINTR if interrupted by a signal; don't abort when this happens.

---
 util/mount.fuse.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
util/mount.fuse.c +3 -1
index 085c88835e6c9a..802d7f99fe7815 100644
@@ -267,7 +267,9 @@ static int mount_service_child(char **argv)
 		return MOUNT_SERVICE_FALLBACK_NEEDED;
 	}
 
-	ret = waitpid(child_pid, &child_status, 0);
+	do {
+		ret = waitpid(child_pid, &child_status, 0);
+	} while (ret < 0 && errno == EINTR);
 	if (ret < 0) {
 		fprintf(stderr, "%s: could not wait for %s helper: %s\n",
 			argv[0], FUSERVICEMOUNT_PROG, strerror(errno));
#18 lore raw

PATCH 2/10 fuse_service: handle weird behavior during SCM_RIGHTS fd transfers

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix a few problems in the code that tries to receive an fd from the mount service helper: MSG_CTRUNC must be handled if an LSM denies us the fd transfer; and protect ourselves against the kernel never actually writing to the fd array.

---
 lib/fuse_service.c |   33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
lib/fuse_service.c +27 -6
index e9a8ddc0912362..240b1107296849 100644
@@ -64,17 +64,28 @@ static int __recv_fd(struct fuse_service *sf,
 	union {
 		struct cmsghdr cmsghdr;
 		char control[CMSG_SPACE(sizeof(int))];
-	} cmsgu;
+	} cmsgu = { };
 	struct msghdr msg = {
 		.msg_iov = &iov,
 		.msg_iovlen = 1,
 		.msg_control = cmsgu.control,
-		.msg_controllen = sizeof(cmsgu.control),
+
+		/*
+		 * Do not include padding at the end of the control buffer,
+		 * because we don't want to receive fds that we weren't
+		 * expecting.
+		 */
+		.msg_controllen = CMSG_LEN(sizeof(int)),
 	};
 	struct cmsghdr *cmsg;
 	ssize_t size;
 
-	memset(&cmsgu, 0, sizeof(cmsgu));
+	/*
+	 * Set the initial fd value to -1 to signal an invalid fd in case the
+	 * kernel doesn't write to the cmsg buffer and doesn't return an error.
+	 * It shouldn't do that, but we absolutely don't want a zero here.
+	 */
+	memset(cmsgu.control, -1, sizeof(cmsgu.control));
 
 	size = recvmsg(sf->sockfd, &msg, MSG_TRUNC | MSG_CMSG_CLOEXEC);
 	if (size < 0) {
@@ -91,6 +102,13 @@ static int __recv_fd(struct fuse_service *sf,
 		return -EBADMSG;
 	}
 
+	if (msg.msg_flags & MSG_CTRUNC) {
+		/* SMACK does this */
+		fuse_log(FUSE_LOG_ERR,
+"fuse: service file reply control data truncated; did an LSM deny SCM_RIGHTS?\n");
+		return -EBADMSG;
+	}
+
 	cmsg = CMSG_FIRSTHDR(&msg);
 	if (!cmsg) {
 		/* no control message means mount.service sent us an error */
@@ -147,7 +165,7 @@ int fuse_service_receive_file(struct fuse_service *sf, const char *path,
 {
 	struct fuse_service_requested_file *req;
 	const size_t req_sz = sizeof_fuse_service_requested_file(strlen(path));
-	int fd = -ENOENT;
+	int fd = -1;
 	int ret;
 
 	*fdp = -ENOENT;
@@ -182,9 +200,12 @@ int fuse_service_receive_file(struct fuse_service *sf, const char *path,
 		goto out_close;
 	}
 
-	if (fd == -ENOENT)
-		fuse_log(FUSE_LOG_ERR, "fuse: did not receive `%s' but no error?\n",
+	if (fd < 0) {
+		fuse_log(FUSE_LOG_ERR,
+			 "fuse: did not receive valid fd for `%s' but no error?\n",
 			 path);
+		goto out_req;
+	}
 
 	*fdp = fd;
 	goto out_req;
#19 lore raw

PATCH 3/10 examples: improve documentation of the new systemd service fuse servers

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Say a bit more about what the sample files are actually trying to do.

---
 example/single_file.h |    4 ++++
 example/service_hl.c  |   20 ++++++++++++++++++--
 example/service_ll.c  |   20 ++++++++++++++++++--
 example/single_file.c |    4 ++++
 4 files changed, 44 insertions(+), 4 deletions(-)
example/single_file.h +4 -0
index 86edb51afb3384..290dd6051ed6f5 100644
@@ -4,6 +4,10 @@
  *
  * This program can be distributed under the terms of the GNU GPLv2.
  * See the file GPL2.txt.
+ *
+ * This file is shared library code for example fuse servers that want to
+ * expose a single regular file that wraps another file in a manner that goes
+ * beyond simple passthrough.  It is not itself a fuse server.
  */
 #ifndef FUSE_SINGLE_FILE_H_
 #define FUSE_SINGLE_FILE_H_
example/service_hl.c +18 -2
index 9c4f3ae7a6cf3c..ea041f670f2ec5 100644
@@ -8,7 +8,15 @@
 
 /** @file
  *
- * minimal example filesystem using high-level API and systemd service api
+ * Minimal example filesystem using high-level API and systemd service API.
+ *
+ * - Shows how to build a high level FUSE filesystem server that can be managed
+ *   by systemd
+ * - Enables on-demand filesystem mounting via socket activation
+ * - Demonstrates requesting resources from the mount-caller's environment
+ * - Allows running FUSE servers with minimal privileges; isolated mount,
+ *   network, and pid namespaces; and a separate uid/gid (unlike traditional
+ *   FUSE which needs mount permissions and runs in the caller's environment)
  *
  * Compile with:
  *
@@ -25,7 +33,15 @@
  * to point to the actual path of the service_hl binary.
  *
  * Finally, install the [email protected] and service_hl.socket files to the
- * systemd service directory, usually /run/systemd/system.
+ * systemd service directory, usually /run/systemd/system.  Run these commands
+ * to activate:
+ *
+ *     systemctl daemon-reload
+ *     systemctl start service_hl.socket
+ *
+ * Then mount with:
+ *
+ *     mount -t fuse.service_hl /dev/sda /mnt
  *
  * ## Source code ##
  * \include service_hl.c
example/service_ll.c +18 -2
index 8958a221e09a66..33a8bd48bc1215 100644
@@ -8,7 +8,15 @@
 
 /** @file
  *
- * minimal example filesystem using low-level API and systemd service api
+ * Minimal example filesystem using low-level API and systemd service API.
+ *
+ * - Shows how to build a low level FUSE filesystem server that can be managed
+ *   by systemd
+ * - Enables on-demand filesystem mounting via socket activation
+ * - Demonstrates requesting resources from the mount-caller's environment
+ * - Allows running FUSE servers with minimal privileges; isolated mount,
+ *   network, and pid namespaces; and a separate uid/gid (unlike traditional
+ *   FUSE which needs mount permissions and runs in the caller's environment)
  *
  * Compile with:
  *
@@ -25,7 +33,15 @@
  * to point to the actual path of the service_ll binary.
  *
  * Finally, install the [email protected] and service_ll.socket files to the
- * systemd service directory, usually /run/systemd/system.
+ * systemd service directory, usually /run/systemd/system.  Run these commands
+ * to activate:
+ *
+ *     systemctl daemon-reload
+ *     systemctl start service_ll.socket
+ *
+ * Then mount with:
+ *
+ *     mount -t fuse.service_ll /dev/sda /mnt
  *
  * ## Source code ##
  * \include service_ll.c
example/single_file.c +4 -0
index 6932eac3a2f276..aeceac83c517c1 100644
@@ -4,6 +4,10 @@
  *
  * This program can be distributed under the terms of the GNU GPLv2.
  * See the file GPL2.txt.
+ *
+ * This file is shared library code for example fuse servers that want to
+ * expose a single regular file that wraps another file in a manner that goes
+ * beyond simple passthrough.  It is not itself a fuse server.
  */
 #define _GNU_SOURCE
 #include <pthread.h>
#20 lore raw

PATCH 4/10 example/single_file: sync backing fd when statx wants us to fsync

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

statx callers can tell the filesystem to fsync the file, so let's pass that through to the backing fd.

---
 example/single_file.c |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
example/single_file.c +18 -2
index aeceac83c517c1..e7da1f2933fc81 100644
@@ -286,9 +286,18 @@ void single_file_ll_statx(fuse_req_t req, fuse_ino_t ino, int flags, int mask,
 	struct statx stx = { };
 	bool filled;
 
-	(void)flags;
 	(void)fi;
 
+	if ((flags & AT_STATX_FORCE_SYNC) && is_single_file_ino(ino) &&
+	    single_file.backing_fd >= 0) {
+		int ret = fsync(single_file.backing_fd);
+
+		if (ret) {
+			fuse_reply_err(req, errno);
+			return;
+		}
+	}
+
 	pthread_mutex_lock(&single_file.lock);
 	filled = sf_statx(ino, mask, &stx);
 	pthread_mutex_unlock(&single_file.lock);
@@ -301,13 +310,20 @@ void single_file_ll_statx(fuse_req_t req, fuse_ino_t ino, int flags, int mask,
 int single_file_hl_statx(const char *path, int statx_flags, int statx_mask,
 			 struct statx *stx, struct fuse_file_info *fi)
 {
-	(void)statx_flags;
 	fuse_ino_t ino = single_open_file_path_to_ino(fi, path);
 	bool filled;
 
 	if (!ino)
 		return -ENOENT;
 
+	if ((statx_flags & AT_STATX_FORCE_SYNC) && is_single_file_ino(ino) &&
+	    single_file.backing_fd >= 0) {
+		int ret = fsync(single_file.backing_fd);
+
+		if (ret)
+			return -errno;
+	}
+
 	pthread_mutex_lock(&single_file.lock);
 	filled = sf_statx(ino, statx_mask, stx);
 	pthread_mutex_unlock(&single_file.lock);
#21 lore raw

PATCH 5/10 example/single_file: fix ctime handling

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix the ctime initialization and updates so that it behaves like ctime is supposed to.

---
 example/single_file.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
example/single_file.c +3 -2
index e7da1f2933fc81..a962232d576e17 100644
@@ -466,8 +466,6 @@ void single_file_ll_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
 			single_file.mtime = attr->st_mtim;
 	}
 	if (to_set & FUSE_SET_ATTR_CTIME)
-		single_file.ctime = attr->st_mtim;
-	else
 		single_file.ctime = now;
 	pthread_mutex_unlock(&single_file.lock);
 
@@ -491,6 +489,7 @@ int single_file_hl_chmod(const char *path, mode_t mode,
 
 	pthread_mutex_lock(&single_file.lock);
 	single_file.mode = (single_file.mode & S_IFMT) | (mode & ~S_IFMT);
+	get_now(&single_file.ctime);
 	pthread_mutex_unlock(&single_file.lock);
 
 	return 0;
@@ -844,6 +843,7 @@ ssize_t single_file_pwrite(const char *buf, size_t count, off_t pos)
 		get_now(&now);
 
 		pthread_mutex_lock(&single_file.lock);
+		single_file.mtime = now;
 		single_file.ctime = now;
 		pthread_mutex_unlock(&single_file.lock);
 
@@ -973,6 +973,7 @@ int single_file_configure_simple(const char *filename)
 	get_now(&startup_time);
 	single_file.atime = startup_time;
 	single_file.mtime = startup_time;
+	single_file.ctime = startup_time;
 
 	if (!single_file.ro)
 		single_file.mode |= 0220;
#22 lore raw

PATCH 6/10 libfuse: fix cppcheck complaints about constifying pointers

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix various cppcheck complaints about pointers that could be const pointers instead.

---
 include/fuse_service.h  |    7 ++++---
 lib/fuse_service.c      |   30 +++++++++++++++++-------------
 lib/fuse_service_stub.c |    6 ++++--
 3 files changed, 25 insertions(+), 18 deletions(-)
include/fuse_service.h +4 -3
index 7e4c204e7a70bf..399830fcf142fe 100644
@@ -48,7 +48,7 @@ int fuse_service_accept(struct fuse_service **sfp);
  * @param sf service context
  * @return true if it has, false if not
  */
-static inline bool fuse_service_accepted(struct fuse_service *sf)
+static inline bool fuse_service_accepted(const struct fuse_service *sf)
 {
 	return sf != NULL;
 }
@@ -59,7 +59,7 @@ static inline bool fuse_service_accepted(struct fuse_service *sf)
  * @param sf service context
  * @return true if it has, false if not
  */
-bool fuse_service_can_allow_other(struct fuse_service *sf);
+bool fuse_service_can_allow_other(const struct fuse_service *sf);
 
 /**
  * Release all resources associated with the service context.
@@ -97,7 +97,8 @@ int fuse_service_append_args(struct fuse_service *sf, struct fuse_args *args);
  * @param args fuse args structure
  * @return effective command line string, or NULL
  */
-char *fuse_service_cmdline(int argc, char *argv[], struct fuse_args *args);
+char *fuse_service_cmdline(int argc, const char * const *argv,
+			   struct fuse_args *args);
 
 struct fuse_cmdline_opts;
 
lib/fuse_service.c +17 -13
index 240b1107296849..5831e2131e9cbf 100644
@@ -53,7 +53,7 @@ struct fuse_service {
 	bool allow_other;
 };
 
-static int __recv_fd(struct fuse_service *sf,
+static int __recv_fd(const struct fuse_service *sf,
 		     struct fuse_service_requested_file *buf,
 		     ssize_t bufsize, int *fdp)
 {
@@ -132,7 +132,8 @@ static int __recv_fd(struct fuse_service *sf,
 	return 0;
 }
 
-static ssize_t __send_packet(struct fuse_service *sf, void *ptr, size_t len)
+static ssize_t __send_packet(const struct fuse_service *sf, void *ptr,
+			     size_t len)
 {
 	struct iovec iov = {
 		.iov_base = ptr,
@@ -146,7 +147,8 @@ static ssize_t __send_packet(struct fuse_service *sf, void *ptr, size_t len)
 	return sendmsg(sf->sockfd, &msg, MSG_EOR | MSG_NOSIGNAL);
 }
 
-static ssize_t __recv_packet(struct fuse_service *sf, void *ptr, size_t len)
+static ssize_t __recv_packet(const struct fuse_service *sf, void *ptr,
+			     size_t len)
 {
 	struct iovec iov = {
 		.iov_base = ptr,
@@ -219,7 +221,8 @@ int fuse_service_receive_file(struct fuse_service *sf, const char *path,
 
 #define FUSE_SERVICE_REQUEST_FILE_FLAGS	(FUSE_SERVICE_REQUEST_FILE_QUIET)
 
-static int fuse_service_request_path(struct fuse_service *sf, const char *path,
+static int fuse_service_request_path(const struct fuse_service *sf,
+				     const char *path,
 				     mode_t expected_fmt, int open_flags,
 				     mode_t create_mode,
 				     unsigned int request_flags,
@@ -322,8 +325,8 @@ int fuse_service_send_goodbye(struct fuse_service *sf, int exitcode)
 
 static int count_listen_fds(void)
 {
-	char *listen_fds;
-	char *listen_pid;
+	const char *listen_fds;
+	const char *listen_pid;
 	char *p;
 	long l;
 
@@ -589,7 +592,7 @@ int fuse_service_accept(struct fuse_service **sfp)
 	return ret;
 }
 
-bool fuse_service_can_allow_other(struct fuse_service *sf)
+bool fuse_service_can_allow_other(const struct fuse_service *sf)
 {
 	return sf->allow_other;
 }
@@ -781,7 +784,7 @@ int fuse_service_finish_file_requests(struct fuse_service *sf)
 }
 #endif
 
-static int send_fsopen(struct fuse_service *sf, const char *fstype,
+static int send_fsopen(const struct fuse_service *sf, const char *fstype,
 		       int *errorp)
 {
 	struct fuse_service_simple_reply reply = { };
@@ -825,7 +828,7 @@ static int send_fsopen(struct fuse_service *sf, const char *fstype,
 	return 0;
 }
 
-static int send_string(struct fuse_service *sf, uint32_t command,
+static int send_string(const struct fuse_service *sf, uint32_t command,
 		       const char *value, int *errorp)
 {
 	struct fuse_service_simple_reply reply = { };
@@ -877,7 +880,7 @@ static int send_string(struct fuse_service *sf, uint32_t command,
 	return 0;
 }
 
-static int send_mountpoint(struct fuse_service *sf, mode_t expected_fmt,
+static int send_mountpoint(const struct fuse_service *sf, mode_t expected_fmt,
 			   const char *value, int *errorp)
 {
 	struct fuse_service_simple_reply reply = { };
@@ -932,7 +935,7 @@ static int send_mountpoint(struct fuse_service *sf, mode_t expected_fmt,
 	return 0;
 }
 
-static int send_mount(struct fuse_service *sf, unsigned int ms_flags,
+static int send_mount(const struct fuse_service *sf, unsigned int ms_flags,
 		      int *errorp)
 {
 	struct fuse_service_simple_reply reply = { };
@@ -1175,12 +1178,13 @@ void fuse_service_destroy(struct fuse_service **sfp)
 	*sfp = NULL;
 }
 
-char *fuse_service_cmdline(int argc, char *argv[], struct fuse_args *args)
+char *fuse_service_cmdline(int argc, const char * const *argv,
+			   struct fuse_args *args)
 {
 	char *p, *dst;
 	size_t len = 1;
 	ssize_t ret;
-	char *argv0;
+	const char *argv0;
 	unsigned int i;
 
 	/* Try to preserve argv[0] */
lib/fuse_service_stub.c +4 -2
index 231b98423df628..83f749bc15c0cc 100644
@@ -23,6 +23,7 @@
 int fuse_service_receive_file(struct fuse_service *sf, const char *path,
 			      int *fdp)
 {
+	*fdp = -1;
 	return -EOPNOTSUPP;
 }
 
@@ -52,7 +53,7 @@ int fuse_service_accept(struct fuse_service **sfp)
 	return 0;
 }
 
-bool fuse_service_can_allow_other(struct fuse_service *sf)
+bool fuse_service_can_allow_other(const struct fuse_service *sf)
 {
 	return false;
 }
@@ -63,7 +64,8 @@ int fuse_service_append_args(struct fuse_service *sf,
 	return -EOPNOTSUPP;
 }
 
-char *fuse_service_cmdline(int argc, char *argv[], struct fuse_args *args)
+char *fuse_service_cmdline(int argc, const char * const *argv,
+			   struct fuse_args *args)
 {
 	return NULL;
 }
#23 lore raw

PATCH 7/10 libfuse: fix cppcheck complaints about constifying pointers in user-visible ABI

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix various cppcheck complaints about pointers that could be const pointers instead.

I am not sure you ought to take this patch, because this affects the client program ABI by limiting what the library can do in the future with the passed in struct fuse_service object.

---
 include/fuse_service.h  |   11 ++++++-----
 lib/fuse_service.c      |   13 +++++++------
 lib/fuse_service_stub.c |   11 ++++++-----
 3 files changed, 19 insertions(+), 16 deletions(-)
include/fuse_service.h +6 -5
index 399830fcf142fe..bd89189cfe5d5b 100644
@@ -139,7 +139,7 @@ int fuse_service_parse_cmdline_opts(struct fuse_args *args,
  * @param request_flags set of FUSE_SERVICE_REQUEST_* flags
  * @return 0 on success, or negative errno on failure
  */
-int fuse_service_request_file(struct fuse_service *sf, const char *path,
+int fuse_service_request_file(const struct fuse_service *sf, const char *path,
 			      int open_flags, mode_t create_mode,
 			      unsigned int request_flags);
 
@@ -155,7 +155,8 @@ int fuse_service_request_file(struct fuse_service *sf, const char *path,
  * @param block_size set the block device block size to this value
  * @return 0 on success, or negative errno on failure
  */
-int fuse_service_request_blockdev(struct fuse_service *sf, const char *path,
+int fuse_service_request_blockdev(const struct fuse_service *sf,
+				  const char *path,
 				  int open_flags, mode_t create_mode,
 				  unsigned int request_flags,
 				  unsigned int block_size);
@@ -169,7 +170,7 @@ int fuse_service_request_blockdev(struct fuse_service *sf, const char *path,
  *      descriptor value on success, or negative errno on failure
  * @return 0 on success, or negative errno on socket communication failure
  */
-int fuse_service_receive_file(struct fuse_service *sf,
+int fuse_service_receive_file(const struct fuse_service *sf,
 			      const char *path, int *fdp);
 
 /**
@@ -178,7 +179,7 @@ int fuse_service_receive_file(struct fuse_service *sf,
  * @param sf service context
  * @return 0 on success, or negative errno on failure
  */
-int fuse_service_finish_file_requests(struct fuse_service *sf);
+int fuse_service_finish_file_requests(const struct fuse_service *sf);
 
 /**
  * Require that the filesystem mount point have the expected file format
@@ -215,7 +216,7 @@ int fuse_service_session_mount(struct fuse_service *sf, struct fuse_session *se,
  * @param sf service context
  * @return 0 on success, or negative errno on failure
  */
-int fuse_service_session_unmount(struct fuse_service *sf);
+int fuse_service_session_unmount(const struct fuse_service *sf);
 
 /**
  * Bid farewell to the mount.service helper.  It is still necessary to call
lib/fuse_service.c +7 -6
index 5831e2131e9cbf..d14aced29e8268 100644
@@ -162,7 +162,7 @@ static ssize_t __recv_packet(const struct fuse_service *sf, void *ptr,
 	return recvmsg(sf->sockfd, &msg, MSG_TRUNC);
 }
 
-int fuse_service_receive_file(struct fuse_service *sf, const char *path,
+int fuse_service_receive_file(const struct fuse_service *sf, const char *path,
 			      int *fdp)
 {
 	struct fuse_service_requested_file *req;
@@ -278,7 +278,7 @@ static int fuse_service_request_path(const struct fuse_service *sf,
 	return ret;
 }
 
-int fuse_service_request_file(struct fuse_service *sf, const char *path,
+int fuse_service_request_file(const struct fuse_service *sf, const char *path,
 			      int open_flags, mode_t create_mode,
 			      unsigned int request_flags)
 {
@@ -286,7 +286,8 @@ int fuse_service_request_file(struct fuse_service *sf, const char *path,
 					 create_mode, request_flags, 0);
 }
 
-int fuse_service_request_blockdev(struct fuse_service *sf, const char *path,
+int fuse_service_request_blockdev(const struct fuse_service *sf,
+				  const char *path,
 				  int open_flags, mode_t create_mode,
 				  unsigned int request_flags,
 				  unsigned int block_size)
@@ -752,7 +753,7 @@ int fuse_service_append_args(struct fuse_service *sf,
 }
 
 #ifdef SO_PASSRIGHTS
-int fuse_service_finish_file_requests(struct fuse_service *sf)
+int fuse_service_finish_file_requests(const struct fuse_service *sf)
 {
 	int zero = 0;
 	int ret;
@@ -777,7 +778,7 @@ int fuse_service_finish_file_requests(struct fuse_service *sf)
 	return 0;
 }
 #else
-int fuse_service_finish_file_requests(struct fuse_service *sf)
+int fuse_service_finish_file_requests(const struct fuse_service *sf)
 {
 	(void)sf;
 	return 0;
@@ -1102,7 +1103,7 @@ int fuse_service_session_mount(struct fuse_service *sf, struct fuse_session *se,
 	return ret;
 }
 
-int fuse_service_session_unmount(struct fuse_service *sf)
+int fuse_service_session_unmount(const struct fuse_service *sf)
 {
 	struct fuse_service_simple_reply reply = { };
 	struct fuse_service_unmount_command c = {
lib/fuse_service_stub.c +6 -5
index 83f749bc15c0cc..1e27f5ea0c6b57 100644
@@ -20,21 +20,22 @@
 #include "fuse_i.h"
 #include "fuse_service.h"
 
-int fuse_service_receive_file(struct fuse_service *sf, const char *path,
+int fuse_service_receive_file(const struct fuse_service *sf, const char *path,
 			      int *fdp)
 {
 	*fdp = -1;
 	return -EOPNOTSUPP;
 }
 
-int fuse_service_request_file(struct fuse_service *sf, const char *path,
+int fuse_service_request_file(const struct fuse_service *sf, const char *path,
 			      int open_flags, mode_t create_mode,
 			      unsigned int request_flags)
 {
 	return -EOPNOTSUPP;
 }
 
-int fuse_service_request_blockdev(struct fuse_service *sf, const char *path,
+int fuse_service_request_blockdev(const struct fuse_service *sf,
+				  const char *path,
 				  int open_flags, mode_t create_mode,
 				  unsigned int request_flags,
 				  unsigned int block_size)
@@ -70,7 +71,7 @@ char *fuse_service_cmdline(int argc, const char * const *argv,
 	return NULL;
 }
 
-int fuse_service_finish_file_requests(struct fuse_service *sf)
+int fuse_service_finish_file_requests(const struct fuse_service *sf)
 {
 	return -EOPNOTSUPP;
 }
@@ -87,7 +88,7 @@ int fuse_service_session_mount(struct fuse_service *sf, struct fuse_session *se,
 	return -EOPNOTSUPP;
 }
 
-int fuse_service_session_unmount(struct fuse_service *sf)
+int fuse_service_session_unmount(const struct fuse_service *sf)
 {
 	return -EOPNOTSUPP;
 }
#24 lore raw

PATCH 8/10 util: fix cppcheck complaints about constifying pointers

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix various cppcheck complaints about pointers that could be const pointers instead.

---
 util/fuservicemount.c |    2 +
 util/mount_service.c  |   68 ++++++++++++++++++++++++++-----------------------
 2 files changed, 37 insertions(+), 33 deletions(-)
util/fuservicemount.c +1 -1
index 4d4cad6cb9253c..a17ae0be290794 100644
@@ -29,7 +29,7 @@ static int check_service(const char *fstype)
 
 int main(int argc, char *argv[])
 {
-	char *fstype = NULL;
+	const char *fstype = NULL;
 	bool check = false;
 	int i;
 
util/mount_service.c +36 -32

225 lines not on this page · raw message

#25 lore raw

PATCH 9/10 fuser_conf: fix cppcheck complaints

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Since I touched this file recently, let's fix the cppcheck complaints.

---
 util/fuser_conf.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
util/fuser_conf.c +5 -4
index 2ce149cee38dcb..8203b145cceaca 100644
@@ -103,16 +103,15 @@ static int count_fuse_fs_ls_mnt(const char *progname)
 	#define MNT_ID_LEN 128
 
 	int fuse_count = 0;
-	int n_mounts = 0;
-	int ret = 0;
 	uint64_t mnt_ids[MNT_ID_LEN];
 	unsigned char smbuf[SMBUF_SIZE];
 	struct mnt_id_req req = {
 		.size = sizeof(struct mnt_id_req),
 	};
-	struct statmount *sm;
 
 	for (;;) {
+		int n_mounts;
+
 		req.mnt_id = LSMT_ROOT;
 
 		n_mounts = syscall(SYS_listmount, &req, &mnt_ids, MNT_ID_LEN, 0);
@@ -125,6 +124,8 @@ static int count_fuse_fs_ls_mnt(const char *progname)
 		}
 
 		for (int i = 0; i < n_mounts; i++) {
+			int ret;
+
 			req.mnt_id = mnt_ids[i];
 			req.param = STATMOUNT_FS_TYPE;
 			ret = syscall(SYS_statmount, &req, &smbuf, SMBUF_SIZE, 0);
@@ -137,7 +138,7 @@ static int count_fuse_fs_ls_mnt(const char *progname)
 				return -1;
 			}
 
-			sm = (struct statmount *)smbuf;
+			const struct statmount *sm = (struct statmount *)smbuf;
 			if (sm->mask & STATMOUNT_FS_TYPE &&
 			    strcmp(&sm->str[sm->fs_type], "fuse") == 0)
 				fuse_count++;
#26 lore raw

PATCH 10/10 example: fix cppcheck complaints about constifying pointers

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix various cppcheck complaints about pointers that could be const pointers instead.

---
 example/single_file.h |    2 +-
 example/single_file.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
example/single_file.h +1 -1
index 290dd6051ed6f5..6ca536a70cf682 100644
@@ -114,7 +114,7 @@ int single_file_opt_proc(void *data, const char *arg, int key,
 unsigned long long parse_num_blocks(const char *arg, int log_block_size);
 
 struct fuse_service;
-int single_file_service_open(struct fuse_service *sf, const char *path);
+int single_file_service_open(const struct fuse_service *sf, const char *path);
 
 void single_file_check_read(off_t pos, size_t *count);
 int single_file_check_write(off_t pos, size_t *count);
example/single_file.c +1 -1
index a962232d576e17..59dbc6bbac5e77 100644
@@ -756,7 +756,7 @@ int single_file_opt_proc(void *data, const char *arg, int key,
 	return 1;
 }
 
-int single_file_service_open(struct fuse_service *sf, const char *path)
+int single_file_service_open(const struct fuse_service *sf, const char *path)
 {
 	int open_flags = single_file.ro ? O_RDONLY : O_RDWR;
 	int fd;
#29 lore raw

[GIT PULL 1/2] libfuse: new mount API and SYNC_INIT fixes

In reply to Darrick J. Wong

Hi Bernd,

Please pull this branch with changes for libfuse.

As usual, I did a test-merge with the main upstream branch as of a few minutes ago, and didn't see any conflicts. Please let me know if you encounter any problems.

--D

The following changes since commit d454f681fdd0e31217261d1656071a3d5c87d61e:

Show a feature config summary the end of meson setup --reconfigure (2026-05-04 17:29:41 +0200)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git tags/fuse-mount-api-fixes_2026-05-04

for you to fetch changes up to ce2feba31ef7ab81807dcba3ae8f64d314ffd14a:

libfuse: always send the subtype to the kernel when using fsconfig() (2026-05-04 16:22:43 -0700)

----------------------------------------------------------------
libfuse: new mount API and SYNC_INIT fixes [01/10]

Here's a collection of bug fixes and cppcheck cleanups for the new mount API code and the new SYNC_INIT code that landed in main recently.

With a bit of luck, this should all go splendidly.

----------------------------------------------------------------
Darrick J. Wong (2):
libfuse: don't use SYNC_INIT unless asked for
libfuse: always send the subtype to the kernel when using fsconfig()

lib/fuse_lowlevel.c  |  6 +++---
lib/mount_fsmount.c  | 13 +++++++++++++
util/mount_service.c |  3 ++-
3 files changed, 18 insertions(+), 4 deletions(-)
#30 lore raw

[GIT PULL 2/2] libfuse: new mount service container fixes

In reply to Darrick J. Wong

Hi Bernd,

Please pull this branch with changes for libfuse.

As usual, I did a test-merge with the main upstream branch as of a few minutes ago, and didn't see any conflicts. Please let me know if you encounter any problems.

--D

The following changes since commit ce2feba31ef7ab81807dcba3ae8f64d314ffd14a:

libfuse: always send the subtype to the kernel when using fsconfig() (2026-05-04 16:22:43 -0700)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/djwong/libfuse.git tags/fuse-service-container-fixes_2026-05-04

for you to fetch changes up to e3db9d31953fc5640999adcc8b74a54dfde0e651:

example: fix cppcheck complaints about constifying pointers (2026-05-04 16:22:44 -0700)

----------------------------------------------------------------
libfuse: new mount service container fixes [02/10]

This is a collection of bug fixes and cppcheck cleanups for the new fuse service container code.

With a bit of luck, this should all go splendidly.

----------------------------------------------------------------
Darrick J. Wong (10):
util/mount.fuse.c: loop in waitpid
fuse_service: handle weird behavior during SCM_RIGHTS fd transfers
examples: improve documentation of the new systemd service fuse servers example/single_file: sync backing fd when statx wants us to fsync example/single_file: fix ctime handling
libfuse: fix cppcheck complaints about constifying pointers
libfuse: fix cppcheck complaints about constifying pointers in user-visible ABI
util: fix cppcheck complaints about constifying pointers
fuser_conf: fix cppcheck complaints
example: fix cppcheck complaints about constifying pointers

example/single_file.h   |  6 +++-
include/fuse_service.h  | 18 ++++++------
example/service_hl.c    | 20 +++++++++++--
example/service_ll.c    | 20 +++++++++++--
example/single_file.c   | 31 ++++++++++++++++----
lib/fuse_service.c      | 76 +++++++++++++++++++++++++++++++++----------------
lib/fuse_service_stub.c | 17 ++++++-----
util/fuser_conf.c       |  9 +++---
util/fuservicemount.c   |  2 +-
util/mount.fuse.c       |  4 ++-
util/mount_service.c    | 68 ++++++++++++++++++++++---------------------
11 files changed, 183 insertions(+), 88 deletions(-)
#3 lore raw

Re: [PATCH 1/2] libfuse: don't use SYNC_INIT unless asked for

In reply to Darrick J. Wong
Quoted 21 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")
---
 lib/fuse_lowlevel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +0 -0
index 0e16845d2f14ff..0a801132590079 100644
@@ -4475,9 +4475,9 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4483

Quoted 10 lines
lib/fuse_lowlevel.c +3 -3
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/* SYNC_INIT is required for io_uring(?) */
+		if ((se->uring.enable && !fuse_daemonize_is_used()) || se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");
 		return 0;

Hmm, but mounting is kind of a libuse internal part? If this is really needed the commit message should mention the exact reason - what is the issue with old fuse servers and sync init?

Thanks,
Bernd

#13 lore raw

Re: [PATCH 2/2] libfuse: always send the subtype to the kernel when using fsconfig()

In reply to Darrick J. Wong
Quoted 42 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Although it's possible to supply a filesystem subtype when calling fsopen(), it does not pass the stuff after the dot to the mount option parsing mechanism like the legacy mount() call does. Therefore, it's necessary to pass the subtype explicitly via fsconfig() or else the subtype will be missing from the /proc/mounts output.

For example, fuse4fs with the old mount API produces this:

/dev/sda /mnt fuse.ext4 rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0

But with the new mount API, we only get:

/dev/sda /mnt fuse rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0

...which breaks fstests, which requires the fsname to match the string that it passes to mount -t. Update the comment in mount_service.c to match this requirement.

Fixes 14cb7b93bb9688 ("Add support for the new linux mount API")
---
 lib/mount_fsmount.c  |   13 +++++++++++++
 util/mount_service.c |    3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)
lib/mount_fsmount.c +6 -0
index 615271b09758c3..5e13b34ccfc610 100644
@@ -359,6 +359,19 @@ int fuse_kern_fsmount(const char *mnt, unsigned long flags, int blkdev,
 		goto out_free;
 	}
 
+	/* Configure subtype */
+	if (subtype) {
+		res = fsconfig(fsfd, FSCONFIG_SET_STRING, "subtype",
+			       subtype, 0);
+		if (res) {
+			err = -errno;

lib/mount_fsmount.c int fuse_kern_fsmount(const char *mnt, unsigned long flags, int blkdev, · line 377

Quoted 10 lines
lib/mount_fsmount.c +7 -0
+			log_fsconfig_kmsg(fsfd);
+			fprintf(stderr, "fuse: fsconfig subtype failed: %s\n",
+				strerror(-err));
+			goto out_free;
+		}
+	}
+
 	/* Configure source */
 	res = fsconfig(fsfd, FSCONFIG_SET_STRING, "source", source, 0);
 	if (res == -1) {

Oh yes, that had slipped through. Going to apply this.

Quoted 6 lines
util/mount_service.c +0 -0
index bc5940bc900dad..3fbabfdd69300d 100644

util/mount_service.c static void try_fsopen(struct mount_service *mo) · line 828

Quoted 9 lines
util/mount_service.c +2 -1
@@ -821,7 +821,8 @@ static void try_fsopen(struct mount_service *mo)
 	/*
 	 * As of Linux 7.0 you can pass subtypes to fsopen, but the manpage for
 	 * fsopen only says that you can pass any value of the second column of
-	 * /proc/filesystems into fsopen.
+	 * /proc/filesystems into fsopen.  You must still call fsconfig() for
+	 * the subtype separately, however.
 	 */
 	mo->fsopenfd = fsopen(fsname(mo), FSOPEN_CLOEXEC);
 }

Can we integrate that into you series separately, as it is not merged yet?

Thanks,
Bernd

#4 lore raw

Re: [PATCH 1/2] libfuse: don't use SYNC_INIT unless asked for

In reply to Bernd Schubert
Quoted 24 lines · Bernd Schubert
Quoted 21 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")
---
 lib/fuse_lowlevel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +0 -0
index 0e16845d2f14ff..0a801132590079 100644
@@ -4475,9 +4475,9 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
Quoted 15 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4483

Quoted 10 lines
lib/fuse_lowlevel.c +3 -3
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/* SYNC_INIT is required for io_uring(?) */
+		if ((se->uring.enable && !fuse_daemonize_is_used()) || se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");
 		return 0;

Hmm, but mounting is kind of a libuse internal part? If this is really needed the commit message should mention the exact reason - what is the issue with old fuse servers and sync init?

One reason I can think off is if the ->init() method starts new threads. In that case we could still do allow the new mount API when the new daemonize API is used.

#5 lore raw

Re: [PATCH 1/2] libfuse: don't use SYNC_INIT unless asked for

Quoted 27 lines · Bernd Schubert
Quoted 24 lines · Bernd Schubert
Quoted 21 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")
---
 lib/fuse_lowlevel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +0 -0
index 0e16845d2f14ff..0a801132590079 100644
@@ -4475,9 +4475,9 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
lib/fuse_lowlevel.c +3 -3
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/* SYNC_INIT is required for io_uring(?) */
+		if ((se->uring.enable && !fuse_daemonize_is_used()) || se->debug)
Quoted 8 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4483

Quoted 4 lines
lib/fuse_lowlevel.c +0 -0
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");
 		return 0;

Hmm, but mounting is kind of a libuse internal part? If this is really needed the commit message should mention the exact reason - what is the issue with old fuse servers and sync init?

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

Looking at that logic a little more, I /think/ you could enable sync init for fuse servers if they've called fuse_daemonize_early_start even if they haven't called fuse_session_want_sync_init:

	/*
	 * The fuse server didn't explicitly ask for SYNC_INIT and it
	 * didn't call fuse_daemonize_early_start.  Assume this server
	 * was written before SYNC_INIT and continue using async init.
	 */
	if (!se->want_sync_init && !fuse_daemonize_is_used()) {
		/*
		 * The io_uring backend requires SYNC_INIT because
		 * $reasons, so log a message if we're not enabling
		 * that.
		 */
		if (se->uring.enable)
			fuse_log(..., "io_uring broken with async init");
		else if (se->debug)
			fuse_log(..., "sync init not enabled");
		return 0;
	}

Since (to the extent that I'm familiar with what fuse servers really do with libfuse) I haven't seen anything that would be a problem. However the more cautious thing to do would be to continue using async init unless fuse_session_want_sync_init is called.

Quoted 3 lines

One reason I can think off is if the ->init() method starts new threads. In that case we could still do allow the new mount API when the new daemonize API is used.

Yes. The new mount api still works (modulo patch 2) even if the SYNC_INIT stuff isn't used.

--D

#14 lore raw

Re: [PATCH 2/2] libfuse: always send the subtype to the kernel when using fsconfig()

In reply to Bernd Schubert
Quoted 49 lines · Bernd Schubert
Quoted 46 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Although it's possible to supply a filesystem subtype when calling fsopen(), it does not pass the stuff after the dot to the mount option parsing mechanism like the legacy mount() call does. Therefore, it's necessary to pass the subtype explicitly via fsconfig() or else the subtype will be missing from the /proc/mounts output.

For example, fuse4fs with the old mount API produces this:

/dev/sda /mnt fuse.ext4 rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0

But with the new mount API, we only get:

/dev/sda /mnt fuse rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0

...which breaks fstests, which requires the fsname to match the string that it passes to mount -t. Update the comment in mount_service.c to match this requirement.

Fixes 14cb7b93bb9688 ("Add support for the new linux mount API")
---
 lib/mount_fsmount.c  |   13 +++++++++++++
 util/mount_service.c |    3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)
lib/mount_fsmount.c +10 -0
index 615271b09758c3..5e13b34ccfc610 100644
@@ -359,6 +359,19 @@ int fuse_kern_fsmount(const char *mnt, unsigned long flags, int blkdev,
 		goto out_free;
 	}
 
+	/* Configure subtype */
+	if (subtype) {
+		res = fsconfig(fsfd, FSCONFIG_SET_STRING, "subtype",
+			       subtype, 0);
+		if (res) {
+			err = -errno;
+			log_fsconfig_kmsg(fsfd);
+			fprintf(stderr, "fuse: fsconfig subtype failed: %s\n",
+				strerror(-err));
+			goto out_free;
Quoted 8 lines

lib/mount_fsmount.c int fuse_kern_fsmount(const char *mnt, unsigned long flags, int blkdev, · line 377

Quoted 6 lines
lib/mount_fsmount.c +3 -0
+		}
+	}
+
 	/* Configure source */
 	res = fsconfig(fsfd, FSCONFIG_SET_STRING, "source", source, 0);
 	if (res == -1) {

Oh yes, that had slipped through. Going to apply this.

Thanks!

Quoted 9 lines
Quoted 9 lines
util/mount_service.c +0 -1
index bc5940bc900dad..3fbabfdd69300d 100644
@@ -821,7 +821,8 @@ static void try_fsopen(struct mount_service *mo)
 	/*
 	 * As of Linux 7.0 you can pass subtypes to fsopen, but the manpage for
 	 * fsopen only says that you can pass any value of the second column of
-	 * /proc/filesystems into fsopen.
Quoted 8 lines

util/mount_service.c static void try_fsopen(struct mount_service *mo) · line 828

Quoted 6 lines
util/mount_service.c +2 -0
+	 * /proc/filesystems into fsopen.  You must still call fsconfig() for
+	 * the subtype separately, however.
 	 */
 	mo->fsopenfd = fsopen(fsname(mo), FSOPEN_CLOEXEC);
 }

Can we integrate that into you series separately, as it is not merged yet?

I'll separate this hunk into a separate patch.

--D

Quoted 4 lines

Thanks,
Bernd

#6 lore raw

PATCH 1/2 libfuse: don't use SYNC_INIT unless asked for

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")

---
v1.1: improve commit message, refine logging logic

---
 lib/fuse_lowlevel.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +15 -3
index 0e16845d2f14ff..83158d02bb8827 100644
@@ -4475,9 +4475,21 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/*
+		 * SYNC_INIT is required for io_uring to initialize without
+		 * deadlocking the kernel if the fuse server crashes.
+		 *
+		 * !fuse_daemonize_is_used implies the fuse server doesn't know
+		 * about any of the SYNC_INIT APIs, so we don't enable sync
+		 * init or generate log messages.
+		 */
+		if (se->uring.enable)
+			fuse_log(FUSE_LOG_DEBUG,
+					"fuse: io_uring broken with async init\n");
+		else if (!fuse_daemonize_is_used())
+			; /* empty */
+		else if (se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");
 		return 0;
#7 lore raw

Re: [PATCH v1.1 1/2] libfuse: don't use SYNC_INIT unless asked for

Quoted 45 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")

---
v1.1: improve commit message, refine logging logic

---
 lib/fuse_lowlevel.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +2 -3
index 0e16845d2f14ff..83158d02bb8827 100644
@@ -4475,9 +4475,21 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/*

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4489

Quoted 10 lines
lib/fuse_lowlevel.c +10 -0
+		 * SYNC_INIT is required for io_uring to initialize without
+		 * deadlocking the kernel if the fuse server crashes.
+		 *
+		 * !fuse_daemonize_is_used implies the fuse server doesn't know
+		 * about any of the SYNC_INIT APIs, so we don't enable sync
+		 * init or generate log messages.
+		 */
+		if (se->uring.enable)
+			fuse_log(FUSE_LOG_DEBUG,
+					"fuse: io_uring broken with async init\n");

So want_sync_init is not enabled and it still logs this? Note that default libfuse does not have a way to set log levels.

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4491

Quoted 2 lines
lib/fuse_lowlevel.c +2 -0
+		else if (!fuse_daemonize_is_used())
+			; /* empty */

Unless I misread it, it would still go into the return 0?

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4494

Quoted 3 lines
lib/fuse_lowlevel.c +1 -0
+		else if (se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");

And now every time a log message here.

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4495

Quoted 1 line
lib/fuse_lowlevel.c +0 -0
 		return 0;

Why can't we change it to

if (!fuse_daemonize_is_used() && !want_sync_init)

       return 0;

If someone uses then new mount API, that someone has also tested sync init. At best we could change want_sync_init to an integer so that a daemon could disable sync init.
For testing I'm probably also going to add an env variable that allows to disable sync init.

Btw, during the meetings I had asked AI to write tests for sync init, looks like "ro" doesn't work yet. AI had created patch to fix that, but I don't apply either the test nor the fix yet, need to carefully read through it, but need to do something else before going to bed.

Thanks,
Bernd

#8 lore raw

Re: [PATCH v1.1 1/2] libfuse: don't use SYNC_INIT unless asked for

Quoted 53 lines · Bernd Schubert
Quoted 50 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")

---
v1.1: improve commit message, refine logging logic

---
 lib/fuse_lowlevel.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +7 -3
index 0e16845d2f14ff..83158d02bb8827 100644
@@ -4475,9 +4475,21 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/*
+		 * SYNC_INIT is required for io_uring to initialize without
+		 * deadlocking the kernel if the fuse server crashes.
+		 *
+		 * !fuse_daemonize_is_used implies the fuse server doesn't know
+		 * about any of the SYNC_INIT APIs, so we don't enable sync
Quoted 8 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4489

Quoted 5 lines
lib/fuse_lowlevel.c +5 -0
+		 * init or generate log messages.
+		 */
+		if (se->uring.enable)
+			fuse_log(FUSE_LOG_DEBUG,
+					"fuse: io_uring broken with async init\n");

So want_sync_init is not enabled and it still logs this? Note that default libfuse does not have a way to set log levels.

I'm not

Quoted 4 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4491

Quoted 2 lines
lib/fuse_lowlevel.c +2 -0
+		else if (!fuse_daemonize_is_used())
+			; /* empty */

Unless I misread it, it would still go into the return 0?

Correct.

Quoted 5 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4494

Quoted 3 lines
lib/fuse_lowlevel.c +1 -0
+		else if (se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");

And now every time a log message here.

Only if you enable debug mode.

Quoted 6 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4495

Quoted 1 line
lib/fuse_lowlevel.c +0 -0
 		return 0;

Why can't we change it to

if (!fuse_daemonize_is_used() && !want_sync_init)

       return 0;

That works for me.

Quoted 2 lines

If someone uses then new mount API, that someone has also tested sync init.

I'm confused by this statement.

In this early bailout case (fuse server did not call fuse_daemonize_early_start or fuse_session_want_sync_init) we return 0 without actually setting SYNC_INIT, correct?

Next, fuse_session_mount_new_api calls fuse_kern_fsmount_mo and libfuse proceeds to mount with the new mount API. The kernel uses the old async init code, because nobody told it to do a synchronous init.

That sequence works fine, and I can prove it by strace'ing fuse2fs startup. The new mount API is used, but FUSE_INIT isn't seen by fuse2fs until after the fuse_daemonize() call and the event loop gets set up.

In other words, fuse2fs uses the new mount API and does not use sync init. I think the correct statement is the inverse:

If someone uses sync_init, that someone has also tested the new mount API.

My understanding of where we are right now is:

1. If a fuse server starts up the new daemonize code or sets want_sync_init, it will get SYNC_INIT.

(I'm not sure what it means if they set want_sync_init and try to use the old daemonize code)

2. If it does neither of those things, it will not get SYNC_INIT.

In both cases we try the new fsmount(). If the fsmount API fails, then we fall back to the classic mount().

Is that correct?

Quoted 4 lines

At best we could change want_sync_init to an integer so that a daemon could disable sync init.
For testing I'm probably also going to add an env variable that allows to disable sync init.

<shrug> That sounds ok to me.

Quoted 4 lines

Btw, during the meetings I had asked AI to write tests for sync init, looks like "ro" doesn't work yet. AI had created patch to fix that, but I don't apply either the test nor the fix yet, need to carefully read through it, but need to do something else before going to bed.

Oh, yeah, mount_flags[] needs to have:

{"rw",           MS_RDONLY,        0,  1,    MOUNT_ATTR_RDONLY},
{"ro",           MS_RDONLY,        1,  1,    MOUNT_ATTR_RDONLY},

Sorry I missed that in the review. I also missed that mount_service.c should be ported to use mount_flags[].

--D

#9 lore raw

Re: [PATCH v1.1 1/2] libfuse: don't use SYNC_INIT unless asked for

Quoted 63 lines · Darrick J. Wong
Quoted 53 lines · Bernd Schubert
Quoted 50 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")

---
v1.1: improve commit message, refine logging logic

---
 lib/fuse_lowlevel.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +7 -3
index 0e16845d2f14ff..83158d02bb8827 100644
@@ -4475,9 +4475,21 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/*
+		 * SYNC_INIT is required for io_uring to initialize without
+		 * deadlocking the kernel if the fuse server crashes.
+		 *
+		 * !fuse_daemonize_is_used implies the fuse server doesn't know
+		 * about any of the SYNC_INIT APIs, so we don't enable sync
Quoted 8 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4489

Quoted 5 lines
lib/fuse_lowlevel.c +5 -0
+		 * init or generate log messages.
+		 */
+		if (se->uring.enable)
+			fuse_log(FUSE_LOG_DEBUG,
+					"fuse: io_uring broken with async init\n");

So want_sync_init is not enabled and it still logs this? Note that default libfuse does not have a way to set log levels.

Quoted 1 line

I'm not

I need to work on libfuse log level setting, the current way doesn't distinguish between log levels. But given all the other things to do and given daemons I had been working with have their own logging system, this always had a very low prio for me.

Quoted 8 lines
Quoted 5 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4491

Quoted 3 lines
lib/fuse_lowlevel.c +2 -0
+		else if (!fuse_daemonize_is_used())
+			; /* empty */

Unless I misread it, it would still go into the return 0?

Correct.

Quoted 7 lines
Quoted 5 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4494

Quoted 3 lines
lib/fuse_lowlevel.c +1 -0
+		else if (se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");

And now every time a log message here.

Only if you enable debug mode.

Ah right.

Quoted 9 lines
Quoted 7 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4495

Quoted 2 lines
lib/fuse_lowlevel.c +0 -0
 		return 0;

Why can't we change it to

if (!fuse_daemonize_is_used() && !want_sync_init)

       return 0;

That works for me.

Let's do that with another variable and also env to disable sync init and new mount api.

Quoted 5 lines
Quoted 3 lines

If someone uses then new mount API, that someone has also tested sync init.

I'm confused by this statement.

I'm deeply sorry, I wanted to write "If someone uses the new daemonize API, that someone ...". Oh well, that wold only be true for kernels that have sync init.

Quoted 46 lines

In this early bailout case (fuse server did not call fuse_daemonize_early_start or fuse_session_want_sync_init) we return 0 without actually setting SYNC_INIT, correct?

Next, fuse_session_mount_new_api calls fuse_kern_fsmount_mo and libfuse proceeds to mount with the new mount API. The kernel uses the old async init code, because nobody told it to do a synchronous init.

That sequence works fine, and I can prove it by strace'ing fuse2fs startup. The new mount API is used, but FUSE_INIT isn't seen by fuse2fs until after the fuse_daemonize() call and the event loop gets set up.

In other words, fuse2fs uses the new mount API and does not use sync init. I think the correct statement is the inverse:

If someone uses sync_init, that someone has also tested the new mount API.

My understanding of where we are right now is:

1. If a fuse server starts up the new daemonize code or sets want_sync_init, it will get SYNC_INIT.

(I'm not sure what it means if they set want_sync_init and try to use the old daemonize code)

2. If it does neither of those things, it will not get SYNC_INIT.

In both cases we try the new fsmount(). If the fsmount API fails, then we fall back to the classic mount().

Is that correct?

Quoted 4 lines

At best we could change want_sync_init to an integer so that a daemon could disable sync init.
For testing I'm probably also going to add an env variable that allows to disable sync init.

<shrug> That sounds ok to me.

Quoted 4 lines

Btw, during the meetings I had asked AI to write tests for sync init, looks like "ro" doesn't work yet. AI had created patch to fix that, but I don't apply either the test nor the fix yet, need to carefully read through it, but need to do something else before going to bed.

Quoted 7 lines

Oh, yeah, mount_flags[] needs to have:

{"rw",           MS_RDONLY,        0,  1,    MOUNT_ATTR_RDONLY},
{"ro",           MS_RDONLY,        1,  1,    MOUNT_ATTR_RDONLY},

Sorry I missed that in the review. I also missed that mount_service.c should be ported to use mount_flags[].

Thanks, I need to read through the docs again. I think we update mount_service.c after merging your series.

Thanks,\Bernd

#10 lore raw

Re: [PATCH v1.1 1/2] libfuse: don't use SYNC_INIT unless asked for

Quoted 66 lines · Bernd Schubert
Quoted 63 lines · Darrick J. Wong
Quoted 61 lines · Bernd Schubert
Quoted 45 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")

---
v1.1: improve commit message, refine logging logic

---
 lib/fuse_lowlevel.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
lib/fuse_lowlevel.c +2 -3
index 0e16845d2f14ff..83158d02bb8827 100644
@@ -4475,9 +4475,21 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
-		if (se->debug)
+	if (!se->want_sync_init) {
+		/*

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4489

Quoted 10 lines
lib/fuse_lowlevel.c +10 -0
+		 * SYNC_INIT is required for io_uring to initialize without
+		 * deadlocking the kernel if the fuse server crashes.
+		 *
+		 * !fuse_daemonize_is_used implies the fuse server doesn't know
+		 * about any of the SYNC_INIT APIs, so we don't enable sync
+		 * init or generate log messages.
+		 */
+		if (se->uring.enable)
+			fuse_log(FUSE_LOG_DEBUG,
+					"fuse: io_uring broken with async init\n");

So want_sync_init is not enabled and it still logs this? Note that default libfuse does not have a way to set log levels.

Quoted 6 lines
Quoted 1 line

I'm not

I need to work on libfuse log level setting, the current way doesn't distinguish between log levels. But given all the other things to do and given daemons I had been working with have their own logging system, this always had a very low prio for me.

<nod> I'll leave it at this:

	/*
	 * Older fuse servers do not set want_sync_init or start the new
	 * daemonize code, so they get async init.
	 */
	if (!fuse_daemonize_is_used() || !se->want_sync_init) {
		if (se->debug)
			fuse_log(FUSE_LOG_DEBUG,
					"fuse: sync init not enabled\n");
		return 0;
	}

and then we can work on another commit that adds the magic env variable that disables sync_init and/or fsmount.

Quoted 32 lines
Quoted 8 lines
Quoted 5 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4491

Quoted 3 lines
lib/fuse_lowlevel.c +2 -0
+		else if (!fuse_daemonize_is_used())
+			; /* empty */

Unless I misread it, it would still go into the return 0?

Correct.

Quoted 7 lines
Quoted 5 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4494

Quoted 3 lines
lib/fuse_lowlevel.c +1 -0
+		else if (se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");

And now every time a log message here.

Only if you enable debug mode.

Ah right.

Quoted 9 lines
Quoted 7 lines

lib/fuse_lowlevel.c static int session_start_sync_init(struct fuse_session *se, int fd) · line 4495

Quoted 2 lines
lib/fuse_lowlevel.c +0 -0
 		return 0;

Why can't we change it to

if (!fuse_daemonize_is_used() && !want_sync_init)

       return 0;

That works for me.

Let's do that with another variable and also env to disable sync init and new mount api.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If someone uses then new mount API, that someone has also tested sync init.

I'm confused by this statement.

I'm deeply sorry, I wanted to write "If someone uses the new daemonize API, that someone ...". Oh well, that wold only be true for kernels that have sync init.

Ah, I got it now. :)

Quoted 47 lines
Quoted 47 lines

In this early bailout case (fuse server did not call fuse_daemonize_early_start or fuse_session_want_sync_init) we return 0 without actually setting SYNC_INIT, correct?

Next, fuse_session_mount_new_api calls fuse_kern_fsmount_mo and libfuse proceeds to mount with the new mount API. The kernel uses the old async init code, because nobody told it to do a synchronous init.

That sequence works fine, and I can prove it by strace'ing fuse2fs startup. The new mount API is used, but FUSE_INIT isn't seen by fuse2fs until after the fuse_daemonize() call and the event loop gets set up.

In other words, fuse2fs uses the new mount API and does not use sync init. I think the correct statement is the inverse:

If someone uses sync_init, that someone has also tested the new mount API.

My understanding of where we are right now is:

1. If a fuse server starts up the new daemonize code or sets want_sync_init, it will get SYNC_INIT.

(I'm not sure what it means if they set want_sync_init and try to use the old daemonize code)

2. If it does neither of those things, it will not get SYNC_INIT.

In both cases we try the new fsmount(). If the fsmount API fails, then we fall back to the classic mount().

Is that correct?

Quoted 4 lines

At best we could change want_sync_init to an integer so that a daemon could disable sync init.
For testing I'm probably also going to add an env variable that allows to disable sync init.

<shrug> That sounds ok to me.

Quoted 4 lines

Btw, during the meetings I had asked AI to write tests for sync init, looks like "ro" doesn't work yet. AI had created patch to fix that, but I don't apply either the test nor the fix yet, need to carefully read through it, but need to do something else before going to bed.

Oh, yeah, mount_flags[] needs to have:

Quoted 8 lines
Quoted 5 lines
{"rw",           MS_RDONLY,        0,  1,    MOUNT_ATTR_RDONLY},
{"ro",           MS_RDONLY,        1,  1,    MOUNT_ATTR_RDONLY},

Sorry I missed that in the review. I also missed that mount_service.c should be ported to use mount_flags[].

Thanks, I need to read through the docs again. I think we update mount_service.c after merging your series.

<nod> I'll post the fix for mount_flags shortly, and the mount_service.c port whenever I get to another round of patchset 2.

--D

Quoted 3 lines

Thanks,\Bernd

#15 lore raw

[PATCH 3/2] mount_util: fix mount_flags entries for MS_RDONLY

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

MS_RDONLY maps to MOUNT_ATTR_RDONLY in the new fsmount API, but the table omitted that. Fix that.

Fixes 0d7e72541564a5 ("Unify mount flag structures and remove redundant is_mount_attr field")
---
 lib/mount_util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/mount_util.c +2 -2
index 1a0aec9bfe1a70..7ab1dba91e28e3 100644
@@ -110,8 +110,8 @@
 
 const struct mount_flags mount_flags[] = {
 /* opt            flag             on  safe  mount_attr */
-{"rw",           MS_RDONLY,        0,  1,    0},                      /* fsconfig */
-{"ro",           MS_RDONLY,        1,  1,    0},                      /* fsconfig */
+{"rw",           MS_RDONLY,        0,  1,    MOUNT_ATTR_RDONLY},     /* fsconfig */
+{"ro",           MS_RDONLY,        1,  1,    MOUNT_ATTR_RDONLY},     /* fsconfig */
 {"suid",         MS_NOSUID,        0,  0,    MOUNT_ATTR_NOSUID},     /* fsmount  */
 {"nosuid",       MS_NOSUID,        1,  1,    MOUNT_ATTR_NOSUID},     /* fsmount  */
 {"dev",          MS_NODEV,         0,  1,    MOUNT_ATTR_NODEV},      /* fsmount  */
#11 lore raw

PATCH 1/2 libfuse: don't use SYNC_INIT unless asked for

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

fuse2fs calls fuse_main, then starts threads from ->init. It doesn't call fuse_daemonize_early_start because I haven't ported it to use any of the new APIs. I don't have io_uring enabled for fuse on my dev box.

fuse_main calls fuse_session_mount calls fuse_session_mount_new_api calls session_start_sync_init. At the start of the function, se->want_sync_init, se->uring.enable, and daemonize.active are all false. The first branch is not taken, so we call FUSE_DEV_IOC_SYNC_INIT and enable sync_init even though the user didn't ask for that and didn't prepare for it either.

FUSE_DEV_IOC_SYNC_INIT succeeds, so we send the synchronous FUSE_INIT from mount, which calls fuse2fs' init() method. That starts the background threads and returns. Upon return to the kernel, the mount() now succeeds, and the next thing that fuse_main does is call fuse_daemonize(). Since we didn't call fuse_daemonize_early_start, the daemonize forks the process and the threads die with the parent.

If we didn't ask for SYNC_INIT, don't enable it. This is needed to maintain compatibility with older fuse servers that only support asynchronous FUSE_INIT.

Fixes 3e1101057aea57 ("fuse mount: Support synchronous FUSE_INIT (privileged daemon)")

--
v1.2: simplify the logic even more
v1.1: improve commit message, refine logging logic

---
 lib/fuse_lowlevel.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
lib/fuse_lowlevel.c +5 -2
index 0e16845d2f14ff..6e078e820eddec 100644
@@ -4475,8 +4475,11 @@ static int session_start_sync_init(struct fuse_session *se, int fd)
 {
 	int err, res;
 
-	if (!se->want_sync_init &&
-		(se->uring.enable && !fuse_daemonize_is_used())) {
+	/*
+	 * Older fuse servers do not set want_sync_init or start the new
+	 * daemonize code, so they get async init.
+	 */
+	if (!fuse_daemonize_is_used() || !se->want_sync_init) {
 		if (se->debug)
 			fuse_log(FUSE_LOG_DEBUG,
 					"fuse: sync init not enabled\n");
#27 lore raw

Re: [PATCHSET 2/2] libfuse: new mount service container fixes

In reply to Darrick J. Wong
Quoted 7 lines · Darrick J. Wong

Hi all,

This is a collection of bug fixes and cppcheck cleanups for the new fuse service container code.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

Hi Darrick,

do you have by any chance a branch I could pull from? With PATCHSET 1 in the same thread I don't know how to handle it with "b4 shazam". Alternatively, I'm also open to learn new b4 or git am commands.

I will try to review it at airport or during the flight, but would reallu help me, if I could just get the patches into a branch for offline processing.

Thanks,
Bernd

Quoted 28 lines

--D
---
Commits in this patchset:
* util/mount.fuse.c: loop in waitpid
* fuse_service: handle weird behavior during SCM_RIGHTS fd transfers
* examples: improve documentation of the new systemd service fuse servers
* example/single_file: sync backing fd when statx wants us to fsync
* example/single_file: fix ctime handling
* libfuse: fix cppcheck complaints about constifying pointers
* libfuse: fix cppcheck complaints about constifying pointers in user-visible ABI
* util: fix cppcheck complaints about constifying pointers
* fuser_conf: fix cppcheck complaints
* example: fix cppcheck complaints about constifying pointers

---
 example/single_file.h   |    6 +++-
 include/fuse_service.h  |   18 ++++++-----
 example/service_hl.c    |   20 +++++++++++-
 example/service_ll.c    |   20 +++++++++++-
 example/single_file.c   |   31 ++++++++++++++++---
 lib/fuse_service.c      |   76 ++++++++++++++++++++++++++++++++---------------
 lib/fuse_service_stub.c |   17 ++++++-----
 util/fuser_conf.c       |    9 +++---
 util/fuservicemount.c   |    2 +
 util/mount.fuse.c       |    4 ++
 util/mount_service.c    |   68 ++++++++++++++++++++++--------------------
 11 files changed, 183 insertions(+), 88 deletions(-)
#28 lore raw

Re: [PATCHSET 2/2] libfuse: new mount service container fixes

Quoted 13 lines · Bernd Schubert
Quoted 7 lines · Darrick J. Wong

Hi all,

This is a collection of bug fixes and cppcheck cleanups for the new fuse service container code.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

Hi Darrick,

Quoted 8 lines

do you have by any chance a branch I could pull from? With PATCHSET 1 in the same thread I don't know how to handle it with "b4 shazam". Alternatively, I'm also open to learn new b4 or git am commands.

I will try to review it at airport or during the flight, but would reallu help me, if I could just get the patches into a branch for offline processing.

Sorry, never mind, just found the pull request mail. Thanks a lot for that! Pull and pushed to my github repo. Let's see how tests go :)

Thanks,
Bernd