[PATCH v9 02/17] fs: add generic FS_IOC_SHUTDOWN definitions

Namjae Jeon posted 17 patches 1 month, 2 weeks ago
[PATCH v9 02/17] fs: add generic FS_IOC_SHUTDOWN definitions
Posted by Namjae Jeon 1 month, 2 weeks ago
Currently, several filesystems (e.g., xfs, ext4, btrfs) implement
a "shutdown" or "going down" ioctl to simulate filesystem force a shutdown.
While they often use the same underlying numeric value, the definition is
duplicated across filesystem headers or private definitions.

Add generic definitions for FS_IOC_SHUTDOWN in uapi/linux/fs.h.
This allows new filesystems (like ntfs) to implement this feature using
a standard VFS definition and paves the way for existing filesystems
to unify their definitions later.

The flag names are standardized as FS_SHUTDOWN_* to be consistent with
the ioctl name, replacing the historical GOING_DOWN naming convention.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 include/uapi/linux/fs.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 66ca526cf786..32e24778c9e5 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -656,4 +656,16 @@ struct procmap_query {
 	__u64 build_id_addr;		/* in */
 };
 
+/*
+ * Shutdown the filesystem.
+ */
+#define FS_IOC_SHUTDOWN _IOR('X', 125, __u32)
+
+/*
+ * Flags for FS_IOC_SHUTDOWN
+ */
+#define FS_SHUTDOWN_FLAGS_DEFAULT	0x0
+#define FS_SHUTDOWN_FLAGS_LOGFLUSH	0x1	/* flush log but not data*/
+#define FS_SHUTDOWN_FLAGS_NOLOGFLUSH	0x2	/* don't flush log nor data */
+
 #endif /* _UAPI_LINUX_FS_H */
-- 
2.25.1
Re: [PATCH v9 02/17] fs: add generic FS_IOC_SHUTDOWN definitions
Posted by David Timber 1 month, 1 week ago
> +/*
> + * Shutdown the filesystem.
> + */
> +#define FS_IOC_SHUTDOWN _IOR('X', 125, __u32)
Should've been _IOW, not _IOR. This is rather unfortunate.

Documentation/userspace-api/ioctl/ioctl-number.rst:
>     ====== ===========================
>     macro  parameters
>     ====== ===========================
>     _IO    none
>     _IOW   write (read from userspace)
>     _IOR   read (write to userspace)
>     _IOWR  write and read
>     ====== ===========================
>
> 'Write' and 'read' are from the user's point of view, just like the
> system calls 'write' and 'read'.  For example, a SET_FOO ioctl would
> be _IOW, although the kernel would actually read data from user space;
> a GET_FOO ioctl would be _IOR, although the kernel would actually write
> data to user space.
All the *_ioctl_shutdown() do get_user(..., arg).
Re: [PATCH v9 02/17] fs: add generic FS_IOC_SHUTDOWN definitions
Posted by Darrick J. Wong 1 month, 1 week ago
On Sat, Feb 21, 2026 at 03:17:30PM +0900, David Timber wrote:
> > +/*
> > + * Shutdown the filesystem.
> > + */
> > +#define FS_IOC_SHUTDOWN _IOR('X', 125, __u32)
> Should've been _IOW, not _IOR. This is rather unfortunate.

Yep, it's too bad that this has been encoded in XFS like this for
decades. :/

You /could/ send patches to add an _IOW definition and make
fstests/xfsprogs prefer the new ioctl number over the old one.

--D

> Documentation/userspace-api/ioctl/ioctl-number.rst:
> >     ====== ===========================
> >     macro  parameters
> >     ====== ===========================
> >     _IO    none
> >     _IOW   write (read from userspace)
> >     _IOR   read (write to userspace)
> >     _IOWR  write and read
> >     ====== ===========================
> >
> > 'Write' and 'read' are from the user's point of view, just like the
> > system calls 'write' and 'read'.  For example, a SET_FOO ioctl would
> > be _IOW, although the kernel would actually read data from user space;
> > a GET_FOO ioctl would be _IOR, although the kernel would actually write
> > data to user space.
> All the *_ioctl_shutdown() do get_user(..., arg).
>