From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 2/3] fuse2fs: hoist lockfile code
Date: Mon, 15 Sep 2025 17:01:55 -0700 [thread overview]
Message-ID: <175798064428.349669.9439688431509746889.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <175798064383.349669.5686318690824770898.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
Hoist the lockfile handling code into separate helpers before we start
rearranging the code that opens and closes filesystems.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 94 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 53 insertions(+), 41 deletions(-)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 948a12c2812b65..a66c0496e66dcf 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -859,6 +859,54 @@ static int check_inum_access(struct fuse2fs *ff, ext2_ino_t ino, int mask)
return -EACCES;
}
+static errcode_t fuse2fs_acquire_lockfile(struct fuse2fs *ff)
+{
+ char *resolved;
+ int lockfd;
+ errcode_t err;
+
+ lockfd = open(ff->lockfile, O_RDWR | O_CREAT | O_EXCL, 0400);
+ if (lockfd < 0) {
+ if (errno == EEXIST)
+ err = EWOULDBLOCK;
+ else
+ err = errno;
+ err_printf(ff, "%s: %s: %s\n", ff->lockfile,
+ _("opening lockfile failed"),
+ strerror(err));
+ ff->lockfile = NULL;
+ return err;
+ }
+ close(lockfd);
+
+ resolved = realpath(ff->lockfile, NULL);
+ if (!resolved) {
+ err = errno;
+ err_printf(ff, "%s: %s: %s\n", ff->lockfile,
+ _("resolving lockfile failed"),
+ strerror(err));
+ unlink(ff->lockfile);
+ ff->lockfile = NULL;
+ return err;
+ }
+ free(ff->lockfile);
+ ff->lockfile = resolved;
+
+ return 0;
+}
+
+static void fuse2fs_release_lockfile(struct fuse2fs *ff)
+{
+ if (unlink(ff->lockfile)) {
+ errcode_t err = errno;
+
+ err_printf(ff, "%s: %s: %s\n", ff->lockfile,
+ _("removing lockfile failed"),
+ strerror(err));
+ }
+ free(ff->lockfile);
+}
+
static void op_destroy(void *p EXT2FS_ATTR((unused)))
{
struct fuse2fs *ff = fuse2fs_get();
@@ -4962,38 +5010,9 @@ int main(int argc, char *argv[])
fctx.alloc_all_blocks = 1;
}
- if (fctx.lockfile) {
- char *resolved;
- int lockfd;
-
- lockfd = open(fctx.lockfile, O_RDWR | O_CREAT | O_EXCL, 0400);
- if (lockfd < 0) {
- if (errno == EEXIST)
- err = EWOULDBLOCK;
- else
- err = errno;
- err_printf(&fctx, "%s: %s: %s\n", fctx.lockfile,
- _("opening lockfile failed"),
- strerror(err));
- fctx.lockfile = NULL;
- ret |= 32;
- goto out;
- }
- close(lockfd);
-
- resolved = realpath(fctx.lockfile, NULL);
- if (!resolved) {
- err = errno;
- err_printf(&fctx, "%s: %s: %s\n", fctx.lockfile,
- _("resolving lockfile failed"),
- strerror(err));
- unlink(fctx.lockfile);
- fctx.lockfile = NULL;
- ret |= 32;
- goto out;
- }
- free(fctx.lockfile);
- fctx.lockfile = resolved;
+ if (fctx.lockfile && fuse2fs_acquire_lockfile(&fctx)) {
+ ret |= 32;
+ goto out;
}
/* Start up the fs (while we still can use stdout) */
@@ -5224,15 +5243,8 @@ int main(int argc, char *argv[])
}
fctx.fs = NULL;
}
- if (fctx.lockfile) {
- if (unlink(fctx.lockfile)) {
- err = errno;
- err_printf(&fctx, "%s: %s: %s\n", fctx.lockfile,
- _("removing lockfile failed"),
- strerror(err));
- }
- free(fctx.lockfile);
- }
+ if (fctx.lockfile)
+ fuse2fs_release_lockfile(&fctx);
if (fctx.device)
free(fctx.device);
fuse_opt_free_args(&args);
next prev parent reply other threads:[~2025-09-16 0:01 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 ` Darrick J. Wong [this message]
2025-09-16 0:02 ` [PATCH 3/3] fuse2fs: hoist unmount code from main Darrick J. Wong
-- 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 2/3] fuse2fs: hoist lockfile code 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=175798064428.349669.9439688431509746889.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