Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 3/3] fuse2fs: hoist unmount code from main
Date: Mon, 15 Sep 2025 17:02:10 -0700	[thread overview]
Message-ID: <175798064444.349669.1767392407737387794.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <175798064383.349669.5686318690824770898.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

Hoist the unmount code into a separate function so that we can reduce
the complexity of main().  This also sets us up for unmounting the
filesystem from op_destroy, which we'll need for fuse2fs+iomap mode to
maintain the expected behavior that the block device is free when
umount(8) returns.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |   30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index a66c0496e66dcf..23a1cd8d5d5d0a 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -907,6 +907,25 @@ static void fuse2fs_release_lockfile(struct fuse2fs *ff)
 	free(ff->lockfile);
 }
 
+static void fuse2fs_unmount(struct fuse2fs *ff)
+{
+	errcode_t err;
+
+	if (!ff->fs)
+		return;
+
+	err = ext2fs_close(ff->fs);
+	if (err) {
+		err_printf(ff, "%s: %s\n", _("while closing fs"),
+			   error_message(err));
+		ext2fs_free(ff->fs);
+	}
+	ff->fs = NULL;
+
+	if (ff->lockfile)
+		fuse2fs_release_lockfile(ff);
+}
+
 static void op_destroy(void *p EXT2FS_ATTR((unused)))
 {
 	struct fuse2fs *ff = fuse2fs_get();
@@ -5235,16 +5254,7 @@ int main(int argc, char *argv[])
  _("Mount failed while opening filesystem.  Check dmesg(1) for details."));
 		fflush(orig_stderr);
 	}
-	if (fctx.fs) {
-		err = ext2fs_close(fctx.fs);
-		if (err) {
-			com_err(argv[0], err, "while closing fs");
-			ext2fs_free(fctx.fs);
-		}
-		fctx.fs = NULL;
-	}
-	if (fctx.lockfile)
-		fuse2fs_release_lockfile(&fctx);
+	fuse2fs_unmount(&fctx);
 	if (fctx.device)
 		free(fctx.device);
 	fuse_opt_free_args(&args);


  parent reply	other threads:[~2025-09-16  0:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 23:58 [PATCHSET 2/6] fuse2fs: refactor unmount code Darrick J. Wong
2025-09-16  0:01 ` [PATCH 1/3] fuse2fs: get rid of the global_fs variable Darrick J. Wong
2025-09-16  0:01 ` [PATCH 2/3] fuse2fs: hoist lockfile code Darrick J. Wong
2025-09-16  0:02 ` Darrick J. Wong [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-11-06 22:28 [PATCHSET 4/9] fuse2fs: refactor unmount code Darrick J. Wong
2025-11-06 22:39 ` [PATCH 3/3] fuse2fs: hoist unmount code from main 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=175798064444.349669.1767392407737387794.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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