Linux bcachefs list
 help / color / mirror / Atom feed
From: Thomas Bertschinger <tahbertschinger@gmail.com>
To: kent.overstreet@linux.dev, linux-bcachefs@vger.kernel.org
Cc: Thomas Bertschinger <tahbertschinger@gmail.com>
Subject: [PATCH TOOLS] fuse: graceful shutdown when startup fails
Date: Fri,  4 Oct 2024 20:06:54 -0600	[thread overview]
Message-ID: <20241005020654.93862-1-tahbertschinger@gmail.com> (raw)

When FUSE startup encounters an error after opening the filesystem--for
example because of a bad mountpoint--it exited uncleanly, which is a
bit unfriendly.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
---

Another mitigation could be to check access(2) for the mountpoint before
doing any work...

 c_src/cmd_fusemount.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/c_src/cmd_fusemount.c b/c_src/cmd_fusemount.c
index f43d29f5..50d35832 100644
--- a/c_src/cmd_fusemount.c
+++ b/c_src/cmd_fusemount.c
@@ -1203,6 +1203,7 @@ int cmd_fusemount(int argc, char *argv[])
 	struct bch_opts bch_opts = bch2_opts_empty();
 	struct bf_context ctx = { 0 };
 	struct bch_fs *c = NULL;
+	struct fuse_session *se = NULL;
 	int ret = 0, i;
 
 	/* Parse arguments. */
@@ -1263,17 +1264,22 @@ int cmd_fusemount(int argc, char *argv[])
 		    bch2_err_str(PTR_ERR(c)));
 
 	/* Fuse */
-	struct fuse_session *se =
-		fuse_session_new(&args, &bcachefs_fuse_ops,
-				 sizeof(bcachefs_fuse_ops), c);
-	if (!se)
-		die("fuse_lowlevel_new err: %m");
+	se = fuse_session_new(&args, &bcachefs_fuse_ops,
+				sizeof(bcachefs_fuse_ops), c);
+	if (!se) {
+		fprintf(stderr, "fuse_lowlevel_new err: %m\n");
+		goto err;
+	}
 
-	if (fuse_set_signal_handlers(se) < 0)
-		die("fuse_set_signal_handlers err: %m");
+	if (fuse_set_signal_handlers(se) < 0) {
+		fprintf(stderr, "fuse_set_signal_handlers err: %m\n");
+		goto err;
+	}
 
-	if (fuse_session_mount(se, fuse_opts.mountpoint))
-		die("fuse_mount err: %m");
+	if (fuse_session_mount(se, fuse_opts.mountpoint)) {
+		fprintf(stderr, "fuse_mount err: %m\n");
+		goto err;
+	}
 
 	/* This print statement is a trigger for tests. */
 	printf("Fuse mount initialized.\n");
@@ -1287,17 +1293,22 @@ int cmd_fusemount(int argc, char *argv[])
 
 	ret = fuse_session_loop(se);
 
-	/* Cleanup */
-	fuse_session_unmount(se);
-	fuse_remove_signal_handlers(se);
-	fuse_session_destroy(se);
-
 out:
+	if (se) {
+		fuse_session_unmount(se);
+		fuse_remove_signal_handlers(se);
+		fuse_session_destroy(se);
+	}
+
 	free(fuse_opts.mountpoint);
 	fuse_opt_free_args(&args);
 	bf_context_free(&ctx);
 
 	return ret ? 1 : 0;
+
+err:
+	bch2_fs_stop(c);
+	goto out;
 }
 
 #endif /* BCACHEFS_FUSE */
-- 
2.46.0


             reply	other threads:[~2024-10-05  2:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-05  2:06 Thomas Bertschinger [this message]
2024-10-05  2:49 ` [PATCH TOOLS] fuse: graceful shutdown when startup fails Kent Overstreet

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=20241005020654.93862-1-tahbertschinger@gmail.com \
    --to=tahbertschinger@gmail.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    /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