[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251008220434.GA6170@frogsfrogsfrogs>
Date: Wed, 8 Oct 2025 15:04:34 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: linux-ext4@...r.kernel.org
Subject: Re: [PATCH 3/3] fuse2fs: enable the shutdown ioctl
On Mon, Sep 15, 2025 at 05:05:35PM -0700, Darrick J. Wong wrote:
> 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)
This change means that we return early from op_destroy on a shut down
filesystem, which means that on iomap filesystems we don't actually
uphold the requirement that we've closed the block device before
replying to the FUSE_DESTROY message that the kernel gives us during
unmount. This causes odd regressions on generic/730 and generic/635,
both of which are due to fstests not being able to format a new
filesystem because fuse4fs hasn't quite exited yet.
> #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;
This needs to clear EXT2_FLAG_RW or else ext2fs_close2() will try to
write the group descriptors/superblock even though the filesystem was
supposedly shut down.
--D
> +
> + 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