[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <175798065210.350393.10163706639168342705.stgit@frogsfrogsfrogs>
Date: Mon, 15 Sep 2025 17:05:35 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: linux-ext4@...r.kernel.org
Subject: [PATCH 3/3] fuse2fs: enable the shutdown ioctl
From: Darrick J. Wong <djwong@...nel.org>
Implement a bastardized version of EXT4_IOC_SHUTDOWN, because the people
who invented the ioctl got the direction wrong, so we can't actually
read the flags.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
misc/fuse2fs.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 80d1c79b5cce1c..101f0fa03c397d 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -221,6 +221,7 @@ struct fuse2fs_file_handle {
enum fuse2fs_opstate {
F2OP_READONLY,
F2OP_WRITABLE,
+ F2OP_SHUTDOWN,
};
/* Main program context */
@@ -276,7 +277,7 @@ struct fuse2fs {
} \
} while (0)
-#define __FUSE2FS_CHECK_CONTEXT(ff, retcode) \
+#define __FUSE2FS_CHECK_CONTEXT(ff, retcode, shutcode) \
do { \
if ((ff) == NULL || (ff)->magic != FUSE2FS_MAGIC) { \
fprintf(stderr, \
@@ -285,14 +286,17 @@ struct fuse2fs {
fflush(stderr); \
retcode; \
} \
+ if ((ff)->opstate == F2OP_SHUTDOWN) { \
+ shutcode; \
+ } \
} while (0)
#define FUSE2FS_CHECK_CONTEXT(ff) \
- __FUSE2FS_CHECK_CONTEXT((ff), return -EUCLEAN)
+ __FUSE2FS_CHECK_CONTEXT((ff), return -EUCLEAN, return -EIO)
#define FUSE2FS_CHECK_CONTEXT_RETURN(ff) \
- __FUSE2FS_CHECK_CONTEXT((ff), return)
+ __FUSE2FS_CHECK_CONTEXT((ff), return, return)
#define FUSE2FS_CHECK_CONTEXT_ABORT(ff) \
- __FUSE2FS_CHECK_CONTEXT((ff), abort())
+ __FUSE2FS_CHECK_CONTEXT((ff), abort(), abort())
static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
const char *func, int line);
@@ -4566,6 +4570,33 @@ static int ioctl_fitrim(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
}
#endif /* FITRIM */
+#ifndef EXT4_IOC_SHUTDOWN
+# define EXT4_IOC_SHUTDOWN _IOR('X', 125, __u32)
+#endif
+
+static int ioctl_shutdown(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
+ void *data)
+{
+ struct fuse_context *ctxt = fuse_get_context();
+ ext2_filsys fs = ff->fs;
+
+ if (!is_superuser(ff, ctxt))
+ return -EPERM;
+
+ err_printf(ff, "%s.\n", _("shut down requested"));
+
+ /*
+ * EXT4_IOC_SHUTDOWN inherited the inverted polarity on the ioctl
+ * direction from XFS. Unfortunately, that means we can't implement
+ * any of the flags. Flush whatever is dirty and shut down.
+ */
+ if (ff->opstate == F2OP_WRITABLE)
+ ext2fs_flush2(fs, 0);
+ ff->opstate = F2OP_SHUTDOWN;
+
+ return 0;
+}
+
#if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8)
static int op_ioctl(const char *path EXT2FS_ATTR((unused)),
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
@@ -4612,6 +4643,9 @@ static int op_ioctl(const char *path EXT2FS_ATTR((unused)),
ret = ioctl_fitrim(ff, fh, data);
break;
#endif
+ case EXT4_IOC_SHUTDOWN:
+ ret = ioctl_shutdown(ff, fh, data);
+ break;
default:
dbg_printf(ff, "%s: Unknown ioctl %d\n", __func__, cmd);
ret = -ENOTTY;
Powered by blists - more mailing lists