porting the GETFSUUID ioctl to xfs
Subsystems (3)
cover porting the GETFSUUID ioctl to xfs
Hi all,
This patch aims to hoist the ext4 get/set ioctls to the VFS so we have a common interface for tools such as coreutils. The second patch adds support for FS_IOC_GETFSUUID in xfs (with FS_IOC_SETFSUUID planned for future patches). In addition, the new xfs_spaceman fsuuid command uses this ioctl to retrieve the UUID of a mounted filesystem.
Comments and feedback appreciated!
Catherine
Catherine Hoang (2):
fs: hoist get/set UUID ioctls
xfs: add FS_IOC_GETFSUUID ioctl
fs/ext4/ext4.h | 13 ++----------- fs/xfs/xfs_ioctl.c | 32 ++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 11 +++++++++++ 3 files changed, 45 insertions(+), 11 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 fs: hoist get/set UUID ioctls
Hoist the EXT4_IOC_[GS]ETFSUUID ioctls so that they can be used by all filesystems. This allows us to have a common interface for tools such as coreutils.
--- fs/ext4/ext4.h | 13 ++----------- include/uapi/linux/fs.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +2 -11
@@ -722,8 +722,8 @@ enum {#define EXT4_IOC_GETSTATE _IOW('f', 41, __u32)#define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap)#define EXT4_IOC_CHECKPOINT _IOW('f', 43, __u32) -#define EXT4_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) -#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid) +#define EXT4_IOC_GETFSUUID FS_IOC_GETFSUUID +#define EXT4_IOC_SETFSUUID FS_IOC_SETFSUUID#define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32)
@@ -753,15 +753,6 @@ enum { EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT | \ EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN) -/* -* Structure for EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID -*/ -struct fsuuid { -__u32 fsu_len; -__u32 fsu_flags; -__u8 fsu_uuid[]; -}; -#if defined(__KERNEL__) && defined(CONFIG_COMPAT )/* * ioctl commands in 32 bit emulation
include/uapi/linux/fs.h +11 -0
@@ -121,6 +121,15 @@ struct fsxattr {unsigned char fsx_pad[8 ]; }; +/* +* Structure for FS_IOC_GETFSUUID/FS_IOC_SETFSUUID +*/ +struct fsuuid { +__u32 fsu_len; +__u32 fsu_flags; +__u8 fsu_uuid[]; +}; +/* * Flags for the fsx_xflags field */
@@ -215,6 +224,8 @@ struct fsxattr {#define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)#define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX])#define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) +#define FS_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) +#define FS_IOC_SETFSUUID _IOW('f', 44, struct fsuuid)/* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
Signature · 1 line
2.25.1
Re: [PATCH v1 1/2] fs: hoist get/set UUID ioctls
Quoted 5 lines · Catherine Hoang
Hoist the EXT4_IOC_[GS]ETFSUUID ioctls so that they can be used by all filesystems. This allows us to have a common interface for tools such as coreutils.
Signed-off-by Catherine Hoang <[email protected]>
Looks good,
Also, for the inevitable v2 patchset after we sort out some weird bugs in the ext4 implementation of this, can you please cc [email protected]?
--D
Quoted 68 lines
--- fs/ext4/ext4.h | 13 ++----------- include/uapi/linux/fs.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-)fs/ext4/ext4.h +2
-11@@ -722,8 +722,8 @@ enum {#define EXT4_IOC_GETSTATE _IOW('f', 41, __u32)#define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap)#define EXT4_IOC_CHECKPOINT _IOW('f', 43, __u32) -#define EXT4_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) -#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid) +#define EXT4_IOC_GETFSUUID FS_IOC_GETFSUUID +#define EXT4_IOC_SETFSUUID FS_IOC_SETFSUUID#define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32)@@ -753,15 +753,6 @@ enum { EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT | \ EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN) -/* -* Structure for EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID -*/ -struct fsuuid { -__u32 fsu_len; -__u32 fsu_flags; -__u8 fsu_uuid[]; -}; -#if defined(__KERNEL__) && defined(CONFIG_COMPAT )/* * ioctl commands in 32 bit emulation include/uapi/linux/fs.h +11
-0@@ -121,6 +121,15 @@ struct fsxattr {unsigned char fsx_pad[8 ]; }; +/* +* Structure for FS_IOC_GETFSUUID/FS_IOC_SETFSUUID +*/ +struct fsuuid { +__u32 fsu_len; +__u32 fsu_flags; +__u8 fsu_uuid[]; +}; +/* * Flags for the fsx_xflags field */ @@ -215,6 +224,8 @@ struct fsxattr {#define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)#define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX])#define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) +#define FS_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) +#define FS_IOC_SETFSUUID _IOW('f', 44, struct fsuuid)/* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) Signature · 1 line
2.25.1
Re: [PATCH v1 1/2] fs: hoist get/set UUID ioctls
Quoted 7 lines · Darrick J. Wong
Quoted 4 lines · Catherine Hoang
Hoist the EXT4_IOC_[GS]ETFSUUID ioctls so that they can be used by all filesystems. This allows us to have a common interface for tools such as coreutils.
Quoted 8 lines
Quoted 1 line
Signed-off-by Catherine Hoang <[email protected]>Looks good,
Reviewed-by Darrick J. Wong <[email protected]>Also, for the inevitable v2 patchset after we sort out some weird bugs in the ext4 implementation of this, can you please cc [email protected]?
Thanks for reviewing! And sure, I’ll cc them in the next version
Quoted 71 lines
--D
Quoted 68 lines
---
fs/ext4/ext4.h| 13 ++-----------include/uapi/linux/fs.h| 11 +++++++++++2 files changed, 13 insertions(+), 11 deletions(-)fs/ext4/ext4.h +2
-11@@ -722,8 +722,8 @@ enum {#define EXT4_IOC_GETSTATE _IOW('f', 41, __u32)#define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap)#define EXT4_IOC_CHECKPOINT _IOW('f', 43, __u32) -#define EXT4_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) -#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid) +#define EXT4_IOC_GETFSUUID FS_IOC_GETFSUUID +#define EXT4_IOC_SETFSUUID FS_IOC_SETFSUUID#define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32)@@ -753,15 +753,6 @@ enum { EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT | \ EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN) -/* -* Structure for EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID -*/ -struct fsuuid { -__u32 fsu_len; -__u32 fsu_flags; -__u8 fsu_uuid[]; -}; -#if defined(__KERNEL__) && defined(CONFIG_COMPAT )/* * ioctl commands in 32 bit emulation include/uapi/linux/fs.h +11
-0@@ -121,6 +121,15 @@ struct fsxattr {unsigned char fsx_pad[8 ]; }; +/* +* Structure for FS_IOC_GETFSUUID/FS_IOC_SETFSUUID +*/ +struct fsuuid { +__u32 fsu_len; +__u32 fsu_flags; +__u8 fsu_uuid[]; +}; +/* * Flags for the fsx_xflags field */ @@ -215,6 +224,8 @@ struct fsxattr {#define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)#define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX])#define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) +#define FS_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) +#define FS_IOC_SETFSUUID _IOW('f', 44, struct fsuuid)/* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) Signature · 1 line
2.25.1
Re: [PATCH v1 1/2] fs: hoist get/set UUID ioctls
In reply to Catherine HoangQuoted 7 lines · Catherine Hoang
Hoist the EXT4_IOC_[GS]ETFSUUID ioctls so that they can be used by all
filesystems. This allows us to have a common interface for tools such as
coreutils.Signed-off-by Catherine Hoang <[email protected]>
Looks straight forward to me
Quoted 69 lines
---
fs/ext4/ext4.h | 13 ++-----------
include/uapi/linux/fs.h | 11 +++++++++++2 files changed, 13 insertions(+), 11 deletions(-)fs/ext4/ext4.h +2
-2@@ -722,8 +722,8 @@ enum { #define EXT4_IOC_GETSTATE _IOW('f', 41, __u32) #define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap) #define EXT4_IOC_CHECKPOINT _IOW('f', 43, __u32) -#define EXT4_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) -#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid) +#define EXT4_IOC_GETFSUUID FS_IOC_GETFSUUID +#define EXT4_IOC_SETFSUUID FS_IOC_SETFSUUID
#defineEXT4_IOC_SHUTDOWN_IOR('X', 125,__u32)fs/ext4/ext4.h +0
-0@@ -753,15 +753,6 @@ enum {EXT4_IOC_CHECKPOINT_F
LAG_ZEROOUT| \
EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN)fs/ext4/ext4.h +0
-9-/* -* Structure for EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID -*/ -struct fsuuid { - __u32 fsu_len; - __u32 fsu_flags; - __u8 fsu_uuid[]; -}; -#if
defined(__KERNEL__)&&defined(CONFIG_COMPAT)/*
* ioctl commands in 32 bit emulationinclude/uapi/linux/fs.h +0
-0@@ -121,6 +121,15 @@ struct fsxattr { unsigned char fsx_pad[8]; };include/uapi/linux/fs.h +9
-0+/* +* Structure for FS_IOC_GETFSUUID/FS_IOC_SETFSUUID +*/ +struct fsuuid { + __u32 fsu_len; + __u32 fsu_flags; + __u8 fsu_uuid[]; +}; +/*
* Flags for thefsx_xflagsfield
*/include/uapi/linux/fs.h +2
-0@@ -215,6 +224,8 @@ struct fsxattr { #define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr) #define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX]) #define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) +#define FS_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) +#define FS_IOC_SETFSUUID _IOW('f', 44, struct fsuuid)
/*
* Inode flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS)
PATCH 2/2 xfs: add FS_IOC_GETFSUUID ioctl
In reply to Catherine HoangAdd a new ioctl to retrieve the UUID of a mounted xfs filesystem.
--- fs/xfs/xfs_ioctl.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
fs/xfs/xfs_ioctl.c +32 -0
@@ -1865,6 +1865,35 @@ xfs_fs_eofblocks_from_user(return 0 ; } +static int xfs_ioctl_getuuid ( +struct xfs_mount *mp, +struct fsuuid __user *ufsuuid) +{ +struct fsuuid fsuuid; +__u8 uuid[UUID_SIZE ]; + +if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +return -EFAULT ; + +if (fsuuid.fsu_len ==0 ) { + fsuuid.fsu_len =UUID_SIZE ; +if (copy_to_user (ufsuuid, &fsuuid,sizeof (fsuuid.fsu_len))) +return -EFAULT ; +return -EINVAL ; + } + +if (fsuuid.fsu_len !=UUID_SIZE || fsuuid.fsu_flags !=0 ) +return -EINVAL ; + +spin_lock (&mp->m_sb_lock); +memcpy (uuid, &mp->m_sb.sb_uuid,UUID_SIZE ); +spin_unlock (&mp->m_sb_lock); + +if (copy_to_user (&ufsuuid->fsu_uuid[0 ], uuid,UUID_SIZE )) +return -EFAULT ; +return 0 ; +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -2153,6 +2182,9 @@ xfs_file_ioctl(return error; } +case FS_IOC_GETFSUUID : +return xfs_ioctl_getuuid (mp, arg); +default :return -ENOTTY ; }
Signature · 1 line
2.25.1
Re: [PATCH v1 2/2] xfs: add FS_IOC_GETFSUUID ioctl
Quoted 1 line · Catherine Hoang
Add a new ioctl to retrieve the UUID of a mounted xfs filesystem.
I think it's worth mentioning that this is the precursor to trying to implement SETFSUUID... but that's something for a future series, since changing the uuid will upset the log, and we have to figure out how to deal with that gracefully.
Quoted 10 lines
Signed-off-by Catherine Hoang <[email protected]>--- fs/xfs/xfs_ioctl.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)fs/xfs/xfs_ioctl.c +0
-0
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1868
Quoted 4 lines
fs/xfs/xfs_ioctl.c +1
-0@@ -1865,6 +1865,35 @@ xfs_fs_eofblocks_from_user(return 0 ; } +static int xfs_ioctl_getuuid(
Nit: function names should start on a new line.
Quoted 4 lines
fs/xfs/xfs_ioctl.c +4
-0+struct xfs_mount *mp, + struct fsuuid __user *ufsuuid) +{ + struct fsuuid fsuuid;
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1882
Quoted 10 lines
fs/xfs/xfs_ioctl.c +10
-0+__u8 uuid[UUID_SIZE ]; + +if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +return -EFAULT ; + +if (fsuuid.fsu_len ==0 ) { + fsuuid.fsu_len =UUID_SIZE ; +if (copy_to_user (ufsuuid, &fsuuid,sizeof (fsuuid.fsu_len))) +return -EFAULT ; +return -EINVAL ;
Ted and I were looking through the ext4_ioctl_getuuid function on this morning's ext4 concall, and we decided that copying the desired uuid buffer length out to userspace shouldn't result in an EINVAL return here...
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1885
Quoted 3 lines
fs/xfs/xfs_ioctl.c +3
-0+ } + +if (fsuuid.fsu_len !=UUID_SIZE || fsuuid.fsu_flags !=0 )
...and that we shouldn't reject the case where fsu_len > UUID_SIZE. Instead, we should copy the uuid and update the caller's fsu_len to reflect however many bytes we copied out. I'll send patches to do that shortly.
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1893
Quoted 8 lines
fs/xfs/xfs_ioctl.c +8
-0+return -EINVAL ; + +spin_lock (&mp->m_sb_lock); +memcpy (uuid, &mp->m_sb.sb_uuid,UUID_SIZE ); +spin_unlock (&mp->m_sb_lock); + +if (copy_to_user (&ufsuuid->fsu_uuid[0 ], uuid,UUID_SIZE )) +return -EFAULT ;
The rest of this logic looks correct to me. Thanks for getting this out there.
--D
Quoted 19 lines
fs/xfs/xfs_ioctl.c +6
-0+return 0 ; +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them. @@ -2153,6 +2182,9 @@ xfs_file_ioctl(return error; } +case FS_IOC_GETFSUUID : +return xfs_ioctl_getuuid (mp, arg); +default :return -ENOTTY ; }Signature · 1 line
2.25.1
Re: [PATCH v1 2/2] xfs: add FS_IOC_GETFSUUID ioctl
Quoted 23 lines · Darrick J. Wong
Quoted 1 line · Catherine Hoang
Add a new ioctl to retrieve the UUID of a mounted xfs filesystem.
I think it's worth mentioning that this is the precursor to trying to implement SETFSUUID... but that's something for a future series, since changing the uuid will upset the log, and we have to figure out how to deal with that gracefully.
Quoted 13 lines
Signed-off-by Catherine Hoang <[email protected]>---
fs/xfs/xfs_ioctl.c| 32 ++++++++++++++++++++++++++++++++1 file changed, 32 insertions(+)fs/xfs/xfs_ioctl.c +0
-0@@ -1865,6 +1865,35 @@ xfs_fs_eofblocks_from_user(return 0 ; }
Quoted 4 lines
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1868
Quoted 1 line
fs/xfs/xfs_ioctl.c +1
-0+static int xfs_ioctl_getuuid(Nit: function names should start on a new line.
Ok, will fix that
Quoted 20 lines
Quoted 4 lines
fs/xfs/xfs_ioctl.c +4
-0+struct xfs_mount *mp, + struct fsuuid __user *ufsuuid) +{ + struct fsuuid fsuuid;fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1882
Quoted 10 lines
fs/xfs/xfs_ioctl.c +10
-0+__u8 uuid[UUID_SIZE ]; + +if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +return -EFAULT ; + +if (fsuuid.fsu_len ==0 ) { + fsuuid.fsu_len =UUID_SIZE ; +if (copy_to_user (ufsuuid, &fsuuid,sizeof (fsuuid.fsu_len))) +return -EFAULT ; +return -EINVAL ;Ted and I were looking through the
ext4_ioctl_getuuidfunction on this morning's ext4 concall, and we decided that copying the desired uuid buffer length out to userspace shouldn't result in an EINVAL return here...
Quoted 8 lines
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1885
Quoted 3 lines
fs/xfs/xfs_ioctl.c +3
-0+ } + +if (fsuuid.fsu_len !=UUID_SIZE || fsuuid.fsu_flags !=0 )...and that we shouldn't reject the case where
fsu_len>UUID_SIZE. Instead, we should copy the uuid and update the caller'sfsu_lento reflect however many bytes we copied out. I'll send patches to do that shortly.
Ok, that makes sense. I’ll apply those changes over to xfs. Thanks!
Quoted 33 lines
fs/xfs/xfs_ioctl.c xfs_fs_eofblocks_from_user( · line 1893
Quoted 9 lines
fs/xfs/xfs_ioctl.c +8
-0+return -EINVAL ; + +spin_lock (&mp->m_sb_lock); +memcpy (uuid, &mp->m_sb.sb_uuid,UUID_SIZE ); +spin_unlock (&mp->m_sb_lock); + +if (copy_to_user (&ufsuuid->fsu_uuid[0 ], uuid,UUID_SIZE )) +return -EFAULT ;The rest of this logic looks correct to me. Thanks for getting this out there.
--D
Quoted 18 lines
fs/xfs/xfs_ioctl.c +6
-0+return 0 ; +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them. @@ -2153,6 +2182,9 @@ xfs_file_ioctl(return error; } +case FS_IOC_GETFSUUID : +return xfs_ioctl_getuuid (mp, arg); +default :return -ENOTTY ; }Signature · 1 line
2.25.1
Re: [PATCH v1 2/2] xfs: add FS_IOC_GETFSUUID ioctl
In reply to Catherine HoangQuoted 3 lines · Catherine Hoang
Add a new ioctl to retrieve the UUID of a mounted xfs filesystem.
Signed-off-by Catherine Hoang <[email protected]>
With Darricks commentary addressed, I think this one looks good
Quoted 57 lines
---
fs/xfs/xfs_ioctl.c | 32 ++++++++++++++++++++++++++++++++1 file changed, 32 insertions(+)fs/xfs/xfs_ioctl.c +0
-0@@ -1865,6 +1865,35 @@ xfs_fs_eofblocks_from_user( return 0; }fs/xfs/xfs_ioctl.c +13
-0+static int xfs_ioctl_getuuid ( + struct xfs_mount *mp, + struct fsuuid __user *ufsuuid) +{ + struct fsuuid fsuuid; + __u8 uuid[UUID_SIZE]; + + if (copy_from_user(&fsuuid, ufsuuid, sizeof(fsuuid))) + return -EFAULT; + + if (fsuuid.fsu_len == 0) { + fsuuid.fsu_len = UUID_SIZE; + if (copy_to_user(ufsuuid, &fsuuid,
sizeof(fsuuid.fsu_len)))
+ return-EFAULT;
+ return-EINVAL;
+ }fs/xfs/xfs_ioctl.c +13
-0+ + if (fsuuid.fsu_len != UUID_SIZE || fsuuid.fsu_flags != 0) + return -EINVAL; + + spin_lock(&mp->m_sb_lock); + memcpy(uuid, &mp->m_sb.sb_uuid, UUID_SIZE); + spin_unlock(&mp->m_sb_lock); + + if (copy_to_user(&ufsuuid->fsu_uuid[0], uuid, UUID_SIZE)) + return -EFAULT; + return 0; +} +/*
* These long-unused ioctls were removed from the official ioctl API in 5.17,
* but retain these definitions so that we can log warnings about them.fs/xfs/xfs_ioctl.c +0
-0@@ -2153,6 +2182,9 @@ xfs_file_ioctl( return error; }
+ caseFS_IOC_GETFSUUID:
+ returnxfs_ioctl_getuuid(mp, arg); +
default:
return-ENOTTY;
}