public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH 3/3] fuse2fs: enable the shutdown ioctl
Date: Wed, 8 Oct 2025 15:04:34 -0700	[thread overview]
Message-ID: <20251008220434.GA6170@frogsfrogsfrogs> (raw)
In-Reply-To: <175798065210.350393.10163706639168342705.stgit@frogsfrogsfrogs>

On Mon, Sep 15, 2025 at 05:05:35PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.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@kernel.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;
> 
> 

  reply	other threads:[~2025-10-08 22:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 23:59 [PATCHSET 6/6] fuse2fs: better tracking of writable state Darrick J. Wong
2025-09-16  0:05 ` [PATCH 1/3] fuse2fs: pass a struct fuse2fs to fs_writeable Darrick J. Wong
2025-09-16  0:05 ` [PATCH 2/3] fuse2fs: track our own writable state Darrick J. Wong
2025-09-16  0:05 ` [PATCH 3/3] fuse2fs: enable the shutdown ioctl Darrick J. Wong
2025-10-08 22:04   ` Darrick J. Wong [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-11-06 22:29 [PATCHSET 7/9] fuse2fs: better tracking of writable state Darrick J. Wong
2025-11-06 22:41 ` [PATCH 3/3] fuse2fs: enable the shutdown ioctl 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=20251008220434.GA6170@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