* [PATCH TOOLS] fuse: graceful shutdown when startup fails
@ 2024-10-05 2:06 Thomas Bertschinger
2024-10-05 2:49 ` Kent Overstreet
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Bertschinger @ 2024-10-05 2:06 UTC (permalink / raw)
To: kent.overstreet, linux-bcachefs; +Cc: Thomas Bertschinger
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH TOOLS] fuse: graceful shutdown when startup fails
2024-10-05 2:06 [PATCH TOOLS] fuse: graceful shutdown when startup fails Thomas Bertschinger
@ 2024-10-05 2:49 ` Kent Overstreet
0 siblings, 0 replies; 2+ messages in thread
From: Kent Overstreet @ 2024-10-05 2:49 UTC (permalink / raw)
To: Thomas Bertschinger; +Cc: linux-bcachefs
On Fri, Oct 04, 2024 at 08:06:54PM GMT, Thomas Bertschinger wrote:
> 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...
I don't like relying on access(2) because that's racy - this looks nice.
Applied
>
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-05 2:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-05 2:06 [PATCH TOOLS] fuse: graceful shutdown when startup fails Thomas Bertschinger
2024-10-05 2:49 ` Kent Overstreet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox