[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <175798064428.349669.9439688431509746889.stgit@frogsfrogsfrogs>
Date: Mon, 15 Sep 2025 17:01:55 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: linux-ext4@...r.kernel.org
Subject: [PATCH 2/3] fuse2fs: hoist lockfile code
From: Darrick J. Wong <djwong@...nel.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@...nel.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);
Powered by blists - more mailing lists