setting uuid of online filesystems
Subsystems (4)
cover setting uuid of online filesystems
Hi all,
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the 'xfs_io fsuuid' command to allow userspace to update the uuid.
Comments and feedback appreciated!
Catherine
Catherine Hoang (4):
xfs: refactor xfs_uuid_mount and xfs_uuid_unmount
xfs: implement custom freeze/thaw functions
xfs: add XFS_IOC_SETFSUUID ioctl
xfs: export meta uuid via xfs_fsop_geom
fs/xfs/libxfs/xfs_fs.h | 4 +- fs/xfs/libxfs/xfs_sb.c | 5 ++ fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 +++++++ fs/xfs/xfs_log.h | 2 + fs/xfs/xfs_mount.c | 30 +++++++++-- fs/xfs/xfs_mount.h | 2 + fs/xfs/xfs_super.c | 112 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_super.h | 5 ++ 9 files changed, 280 insertions(+), 6 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 xfs: refactor xfs_uuid_mount and xfs_uuid_unmount
Separate out the code that adds and removes a uuid from the uuid table. The next patch uses these helpers to set the uuid of a mounted filesystem.
--- fs/xfs/xfs_mount.c | 30 +++++++++++++++++++++++++----- fs/xfs/xfs_mount.h | 2 ++ 2 files changed, 27 insertions(+), 5 deletions(-)
fs/xfs/xfs_mount.c +25 -5
@@ -58,7 +58,7 @@ xfs_uuid_mount( struct xfs_mount *mp) {uuid_t *uuid = &mp->m_sb.sb_uuid; -int hole, i; +int error;/* Publish UUID in struct super_block */ uuid_copy (&mp->m_super->s_uuid, uuid);
@@ -71,6 +71,21 @@ xfs_uuid_mount(return -EINVAL ; } + error =xfs_uuid_remember (uuid); +if (error) { +xfs_warn (mp,"Filesystem has duplicate UUID %pU - can't mount" , uuid); +return error; + } + +return 0 ; +} + +int +xfs_uuid_remember ( +const uuid_t *uuid) +{ +int hole, i; +mutex_lock (&xfs_uuid_table_mutex);for (i =0 , hole =-1 ; i < xfs_uuid_table_size; i++) {if (uuid_is_null (&xfs_uuid_table[i])) {
@@ -94,7 +109,6 @@ xfs_uuid_mount( out_duplicate:mutex_unlock (&xfs_uuid_table_mutex); -xfs_warn (mp,"Filesystem has duplicate UUID %pU - can't mount" , uuid);return -EINVAL ; }
@@ -102,12 +116,18 @@ STATIC voidxfs_uuid_unmount ( struct xfs_mount *mp) { -uuid_t *uuid = &mp->m_sb.sb_uuid; -int i; -if (xfs_has_nouuid (mp))return ; +xfs_uuid_forget (&mp->m_sb.sb_uuid); +} + +void +xfs_uuid_forget ( +const uuid_t *uuid) +{ +int i; +mutex_lock (&xfs_uuid_table_mutex);for (i =0 ; i < xfs_uuid_table_size; i++) {if (uuid_is_null (&xfs_uuid_table[i]))
fs/xfs/xfs_mount.h +2 -0
@@ -484,6 +484,8 @@ xfs_daddr_to_agbno(struct xfs_mount *mp, xfs_daddr_t d)int xfs_buf_hash_init (struct xfs_perag *pag);void xfs_buf_hash_destroy (struct xfs_perag *pag); +int xfs_uuid_remember (const uuid_t *uuid); +void xfs_uuid_forget (const uuid_t *uuid);extern void xfs_uuid_table_free (void );extern uint64_t xfs_default_resblks (xfs_mount_t *mp);extern int xfs_mountfs (xfs_mount_t *mp);
Signature · 1 line
2.34.1
PATCH 2/4 xfs: implement custom freeze/thaw functions
In reply to Catherine HoangImplement internal freeze/thaw functions and prevent other threads from changing the freeze level by adding a new SB_FREEZE_ECLUSIVE level. This is required to prevent concurrent transactions while we are updating the uuid.
--- fs/xfs/xfs_super.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_super.h | 5 ++ 2 files changed, 117 insertions(+)
fs/xfs/xfs_super.c +112 -0
@@ -2279,6 +2279,118 @@ static inline int xfs_cpu_hotplug_init(void) { return 0; }static inline void xfs_cpu_hotplug_destroy (void ) {}#endif +/* +* We need to disable all writer threads, which means taking the first two +* freeze levels to put userspace to sleep, and the third freeze level to +* prevent background threads from starting new transactions. Take one level +* more to prevent other callers from unfreezing the filesystem while we run. +*/ +int +xfs_internal_freeze ( +struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super; +int level; +int error =0 ; + +/* Wait until we're ready to freeze. */ +down_write (&sb->s_umount); +while (sb->s_writers.frozen !=SB_UNFROZEN ) { +up_write (&sb->s_umount); +delay (HZ /10 ); +down_write (&sb->s_umount); + } + +if (sb_rdonly (sb)) { + sb->s_writers.frozen =SB_FREEZE_EXCLUSIVE ; + goto done; + } + + sb->s_writers.frozen =SB_FREEZE_WRITE ; +/* Release s_umount to preserve sb_start_write -> s_umount ordering */ +up_write (&sb->s_umount); +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_WRITE -1 ); +down_write (&sb->s_umount); + +/* Now we go and block page faults... */ + sb->s_writers.frozen =SB_FREEZE_PAGEFAULT ; +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_PAGEFAULT -1 ); + +/* +* All writers are done so after syncing there won't be dirty data. +* Let xfs_fs_sync_fs flush dirty data so the VFS won't start writeback +* and to disable the background gc workers. +*/ + error =sync_filesystem (sb); +if (error) { + sb->s_writers.frozen =SB_UNFROZEN ; +for (level =SB_FREEZE_PAGEFAULT -1 ; level >=0 ; level--) +percpu_up_write (sb->s_writers.rw_sem + level); +wake_up (&sb->s_writers.wait_unfrozen); +up_write (&sb->s_umount); +return error; + } + +/* Now wait for internal filesystem counter */ + sb->s_writers.frozen =SB_FREEZE_FS ; +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_FS -1 ); + +xfs_log_clean (mp); + +/* +* To prevent anyone else from unfreezing us, set the VFS freeze +* level to one higher than FREEZE_COMPLETE. +*/ + sb->s_writers.frozen =SB_FREEZE_EXCLUSIVE ; +for (level =SB_FREEZE_LEVELS -1 ; level >=0 ; level--) +percpu_rwsem_release (sb->s_writers.rw_sem + level,0 , + _THIS_IP_); +done: +up_write (&sb->s_umount); +return 0 ; +} + +void +xfs_internal_unfreeze ( +struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super; +int level; + +down_write (&sb->s_umount); +if (sb->s_writers.frozen !=SB_FREEZE_EXCLUSIVE ) { +/* somebody snuck in and unfroze us? */ +ASSERT (0 ); +up_write (&sb->s_umount); +return ; + } + +if (sb_rdonly (sb)) { + sb->s_writers.frozen =SB_UNFROZEN ; + goto out; + } + +for (level =0 ; level <SB_FREEZE_LEVELS ; ++level) +percpu_rwsem_acquire (sb->s_writers.rw_sem + level,0 , + _THIS_IP_); + +/* +* We didn't call xfs_fs_freeze, so we can't call xfs_fs_thaw. Start +* the background gc workers that were shut down by xfs_fs_sync_fs +* when we froze. +*/ +xfs_blockgc_start (mp); +xfs_inodegc_start (mp); + + sb->s_writers.frozen =SB_UNFROZEN ; +for (level =SB_FREEZE_LEVELS -1 ; level >=0 ; level--) +percpu_up_write (sb->s_writers.rw_sem + level); +out: +wake_up (&sb->s_writers.wait_unfrozen); +up_write (&sb->s_umount); +return ; +} + STATIC int __initinit_xfs_fs (void ) {
fs/xfs/xfs_super.h +5 -0
@@ -81,6 +81,8 @@ extern void xfs_qm_exit(void);# define XFS_WQFLAGS (wqflags) (wqflags)#endif +#define SB_FREEZE_EXCLUSIVE (SB_FREEZE_COMPLETE + 1) +struct xfs_inode ;struct xfs_mount ;struct xfs_buftarg ;
@@ -98,6 +100,9 @@ extern void xfs_reinit_percpu_counters(struct xfs_mount *mp);extern struct workqueue_struct *xfs_discard_wq; +extern int xfs_internal_freeze (struct xfs_mount *mp); +extern void xfs_internal_unfreeze (struct xfs_mount *mp); +#define XFS_M (sb) ((struct xfs_mount *)((sb)->s_fs_info))#endif /* __XFS_SUPER_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v1 2/4] xfs: implement custom freeze/thaw functions
Quoted 3 lines · Catherine Hoang
Implement internal freeze/thaw functions and prevent other threads from changing the freeze level by adding a new
SB_FREEZE_ECLUSIVElevel. This is required to
This looks troubling in several ways:
- Layering violation
- Duplication of subtle vfs code
Quoted 2 lines
prevent concurrent transactions while we are updating the uuid.
Wouldn't it be easier to hold s_umount while updating the uuid? Let userspace freeze before XFS_IOC_SETFSUUID and let XFS_IOC_SETFSUUID take s_umount and verify that fs is frozen.
Quoted 25 lines
Signed-off-by Catherine Hoang <[email protected]>--- fs/xfs/xfs_super.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_super.h | 5 ++ 2 files changed, 117 insertions(+)fs/xfs/xfs_super.c +11
-0@@ -2279,6 +2279,118 @@ static inline int xfs_cpu_hotplug_init(void) { return 0; }static inline void xfs_cpu_hotplug_destroy (void ) {}#endif +/* +* We need to disable all writer threads, which means taking the first two +* freeze levels to put userspace to sleep, and the third freeze level to +* prevent background threads from starting new transactions. Take one level +* more to prevent other callers from unfreezing the filesystem while we run. +*/ +int +xfs_internal_freeze ( +struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super;
fs/xfs/xfs_super.c static inline int xfs_cpu_hotplug_init(void) { return 0; } · line 2302
Quoted 10 lines
fs/xfs/xfs_super.c +10
-0+int level; +int error =0 ; + +/* Wait until we're ready to freeze. */ +down_write (&sb->s_umount); +while (sb->s_writers.frozen !=SB_UNFROZEN ) { +up_write (&sb->s_umount); +delay (HZ /10 ); +down_write (&sb->s_umount); + }
That can easily wait forever, without any task holding any lock.
Quoted 35 lines
fs/xfs/xfs_super.c +35
-0+ +if (sb_rdonly (sb)) { + sb->s_writers.frozen =SB_FREEZE_EXCLUSIVE ; + goto done; + } + + sb->s_writers.frozen =SB_FREEZE_WRITE ; +/* Release s_umount to preserve sb_start_write -> s_umount ordering */ +up_write (&sb->s_umount); +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_WRITE -1 ); +down_write (&sb->s_umount); + +/* Now we go and block page faults... */ + sb->s_writers.frozen =SB_FREEZE_PAGEFAULT ; +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_PAGEFAULT -1 ); + +/* +* All writers are done so after syncing there won't be dirty data. +* Let xfs_fs_sync_fs flush dirty data so the VFS won't start writeback +* and to disable the background gc workers. +*/ + error =sync_filesystem (sb); +if (error) { + sb->s_writers.frozen =SB_UNFROZEN ; +for (level =SB_FREEZE_PAGEFAULT -1 ; level >=0 ; level--) +percpu_up_write (sb->s_writers.rw_sem + level); +wake_up (&sb->s_writers.wait_unfrozen); +up_write (&sb->s_umount); +return error; + } + +/* Now wait for internal filesystem counter */ + sb->s_writers.frozen =SB_FREEZE_FS ; +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_FS -1 ); +
fs/xfs/xfs_super.c static inline int xfs_cpu_hotplug_init(void) { return 0; } · line 2347
Quoted 10 lines
fs/xfs/xfs_super.c +10
-0+xfs_log_clean (mp); + +/* +* To prevent anyone else from unfreezing us, set the VFS freeze +* level to one higher than FREEZE_COMPLETE. +*/ + sb->s_writers.frozen =SB_FREEZE_EXCLUSIVE ; +for (level =SB_FREEZE_LEVELS -1 ; level >=0 ; level--) +percpu_rwsem_release (sb->s_writers.rw_sem + level,0 , + _THIS_IP_);
If you really must introduce a new freeze level, you should do it in vfs and not inside xfs, even if xfs is the only current user of the new leve.
Thanks,
Amir.
Re: [PATCH v1 2/4] xfs: implement custom freeze/thaw functions
Quoted 6 lines · Amir Goldstein
Quoted 3 lines · Catherine Hoang
Implement internal freeze/thaw functions and prevent other threads from changing the freeze level by adding a new
SB_FREEZE_ECLUSIVElevel. This is required to
Quoted 8 lines
This looks troubling in several ways:
- Layering violation
- Duplication of subtle vfs codeQuoted 2 lines
prevent concurrent transactions while we are updating the uuid.
Wouldn't it be easier to hold
s_umountwhile updating the uuid?
Why? Userspace holds an open file descriptor, the fs won't get unmounted.
Quoted 2 lines
Let userspace freeze before
XFS_IOC_SETFSUUIDand letXFS_IOC_SETFSUUIDtakes_umountand verify that fs is frozen.
Ugh, no, I don't want *userspace* to have to know how to do that.
Quoted 29 lines
Quoted 29 lines
Signed-off-by Catherine Hoang <[email protected]>--- fs/xfs/xfs_super.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_super.h | 5 ++ 2 files changed, 117 insertions(+)fs/xfs/xfs_super.c +15
-0@@ -2279,6 +2279,118 @@ static inline int xfs_cpu_hotplug_init(void) { return 0; }static inline void xfs_cpu_hotplug_destroy (void ) {}#endif +/* +* We need to disable all writer threads, which means taking the first two +* freeze levels to put userspace to sleep, and the third freeze level to +* prevent background threads from starting new transactions. Take one level +* more to prevent other callers from unfreezing the filesystem while we run. +*/ +int +xfs_internal_freeze ( +struct xfs_mount *mp) +{ +struct super_block *sb = mp->m_super; +int level; +int error =0 ; + +/* Wait until we're ready to freeze. */
Quoted 8 lines
fs/xfs/xfs_super.c static inline int xfs_cpu_hotplug_init(void) { return 0; } · line 2302
Quoted 6 lines
fs/xfs/xfs_super.c +6
-0+down_write (&sb->s_umount); +while (sb->s_writers.frozen !=SB_UNFROZEN ) { +up_write (&sb->s_umount); +delay (HZ /10 ); +down_write (&sb->s_umount); + }That can easily wait forever, without any task holding any lock.
Indeed, this needs at a bare minimum some kind of fatal_signal_pending check every time through the loop.
Quoted 28 lines
Quoted 28 lines
fs/xfs/xfs_super.c +28
-0+ +if (sb_rdonly (sb)) { + sb->s_writers.frozen =SB_FREEZE_EXCLUSIVE ; + goto done; + } + + sb->s_writers.frozen =SB_FREEZE_WRITE ; +/* Release s_umount to preserve sb_start_write -> s_umount ordering */ +up_write (&sb->s_umount); +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_WRITE -1 ); +down_write (&sb->s_umount); + +/* Now we go and block page faults... */ + sb->s_writers.frozen =SB_FREEZE_PAGEFAULT ; +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_PAGEFAULT -1 ); + +/* +* All writers are done so after syncing there won't be dirty data. +* Let xfs_fs_sync_fs flush dirty data so the VFS won't start writeback +* and to disable the background gc workers. +*/ + error =sync_filesystem (sb); +if (error) { + sb->s_writers.frozen =SB_UNFROZEN ; +for (level =SB_FREEZE_PAGEFAULT -1 ; level >=0 ; level--) +percpu_up_write (sb->s_writers.rw_sem + level); +wake_up (&sb->s_writers.wait_unfrozen); +up_write (&sb->s_umount);
Quoted 8 lines
fs/xfs/xfs_super.c static inline int xfs_cpu_hotplug_init(void) { return 0; } · line 2338
Quoted 8 lines
fs/xfs/xfs_super.c +8
-0+return error; + } + +/* Now wait for internal filesystem counter */ + sb->s_writers.frozen =SB_FREEZE_FS ; +percpu_down_write (sb->s_writers.rw_sem +SB_FREEZE_FS -1 ); + +xfs_log_clean (mp);
Hmm... some of these calls really ought to be returning errors.
Quoted 10 lines
fs/xfs/xfs_super.c static inline int xfs_cpu_hotplug_init(void) { return 0; } · line 2347
Quoted 9 lines
fs/xfs/xfs_super.c +9
-0+ +/* +* To prevent anyone else from unfreezing us, set the VFS freeze +* level to one higher than FREEZE_COMPLETE. +*/ + sb->s_writers.frozen =SB_FREEZE_EXCLUSIVE ; +for (level =SB_FREEZE_LEVELS -1 ; level >=0 ; level--) +percpu_rwsem_release (sb->s_writers.rw_sem + level,0 , + _THIS_IP_);
Quoted 2 lines
If you really must introduce a new freeze level, you should do it in vfs and not inside xfs, even if xfs is the only current user of the new leve.
Luis is already trying to do something similar to this. So far Jan and I seem to be the only ones who have taken a look at this fs-internal freeze...
https://lore.kernel.org/linux-fsdevel/[email protected]/
--D
Quoted 2 lines
Thanks,
Amir.
Re: [PATCH v1 2/4] xfs: implement custom freeze/thaw functions
Quoted 12 lines · Darrick J. Wong
Quoted 10 lines · Amir Goldstein
Quoted 3 lines · Catherine Hoang
Implement internal freeze/thaw functions and prevent other threads from changing the freeze level by adding a new
SB_FREEZE_ECLUSIVElevel. This is required toThis looks troubling in several ways:
- Layering violation
- Duplication of subtle vfs code
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
prevent concurrent transactions while we are updating the uuid.
Wouldn't it be easier to hold
s_umountwhile updating the uuid?Why? Userspace holds an open file descriptor, the fs won't get unmounted.
"Implement internal freeze/thaw functions and prevent other threads from changing
the freeze level..."
holding s_umount prevents changing freeze levels.
The special thing about the frozen state is that userspace is allowed to leave the fs frozen without holding any open fd, but because there is no such requirement from SET_FSUUID I don't understand the need for a new freeze level.
Thanks,
Amir.
Re: [PATCH v1 2/4] xfs: implement custom freeze/thaw functions
Quoted 25 lines · Amir Goldstein
Quoted 12 lines · Darrick J. Wong
Quoted 10 lines · Amir Goldstein
Quoted 3 lines · Catherine Hoang
Implement internal freeze/thaw functions and prevent other threads from changing the freeze level by adding a new
SB_FREEZE_ECLUSIVElevel. This is required toThis looks troubling in several ways:
- Layering violation
- Duplication of subtle vfs codeQuoted 7 lines
Quoted 4 lines
Quoted 2 lines
prevent concurrent transactions while we are updating the uuid.
Wouldn't it be easier to hold
s_umountwhile updating the uuid?Why? Userspace holds an open file descriptor, the fs won't get unmounted.
"Implement internal freeze/thaw functions and prevent other threads from changing
the freeze level..."
Quoted 6 lines
holding
s_umountprevents changing freeze levels.The special thing about the frozen state is that userspace is allowed to leave the fs frozen without holding any open fd, but because there is no such requirement from
SET_FSUUIDI don't understand the need for a new freeze level.
Hm. I think you could be right, since we can certainly run transactions with s_umount held. I wonder if we're going to run into problems with the weird xlog things that fsuuid setting will want, but I guess we have lockdep on our side, right? ;)
--D
Quoted 2 lines
Thanks,
Amir.
PATCH 3/4 xfs: add XFS_IOC_SETFSUUID ioctl
In reply to Catherine HoangAdd a new ioctl to set the uuid of a mounted filesystem.
--- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 ++++++++ fs/xfs/xfs_log.h | 2 + 4 files changed, 129 insertions(+)
fs/xfs/libxfs/xfs_fs.h +1 -0
@@ -831,6 +831,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_SETFSUUID _IOR ('X', 129, uuid_t)/* XFS_IOC_GETFSUUID ---------- deprecated 140 */
fs/xfs/xfs_ioctl.c +107 -0
125 lines not on this page · raw message
fs/xfs/xfs_log.c +19 -0
@@ -3921,3 +3921,22 @@ xlog_drop_incompat_feat( {up_read (&log->l_incompat_users); } + +/* +* Cycle all the iclog buffers and update the uuid. +*/ +void +xlog_iclog_update_uuid ( +struct xfs_mount *mp) +{ +int i; +struct xlog *log = mp->m_log; +struct xlog_in_core *iclog = log->l_iclog; +xlog_rec_header_t *head; + +for (i =0 ; i < log->l_iclog_bufs; i++) { + head = &iclog->ic_header; +memcpy (&head->h_fs_uuid, &mp->m_sb.sb_uuid,sizeof (uuid_t)); + iclog = iclog->ic_next; + } +}
fs/xfs/xfs_log.h +2 -0
@@ -163,4 +163,6 @@ void xlog_use_incompat_feat(struct xlog *log);void xlog_drop_incompat_feat (struct xlog *log);int xfs_attr_use_log_assist (struct xfs_mount *mp); +void xlog_iclog_update_uuid (struct xfs_mount *mp); +#endif /* __XFS_LOG_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v1 3/4] xfs: add XFS_IOC_SETFSUUID ioctl
Quoted 16 lines · Catherine Hoang
Add a new ioctl to set the uuid of a mounted filesystem.
Signed-off-by Catherine Hoang <[email protected]>--- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 ++++++++ fs/xfs/xfs_log.h | 2 + 4 files changed, 129 insertions(+)fs/xfs/libxfs/xfs_fs.h +0
-0
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 834
Quoted 4 lines
fs/xfs/libxfs/xfs_fs.h +1
-0@@ -831,6 +831,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_SETFSUUID _IOR ('X', 129, uuid_t)
Should be _IOW.
Would you consider defining that as FS_IOC_SETFSUUID in fs.h, so that other fs could implement it later on, instead of hoisting it later?
It would be easy to add support for FS_IOC_SETFSUUID to ext4 by generalizing ext4_ioctl_setuuid().
Alternatively, we could hoist EXT4_IOC_SETFSUUID and struct fsuuid to fs.h and use that ioctl also for xfs.
Using an extensible struct with flags for that ioctl may turn out to be useful, for example, to verify that the new uuid is unique, despite the fact that xfs was
mounted with -onouuid (useful IMO) or to explicitly request a restore of old uuid that would fail if new_uuid != meta uuid.
Thanks,
Amir.
Re: [PATCH v1 3/4] xfs: add XFS_IOC_SETFSUUID ioctl
Quoted 15 lines · Amir Goldstein
Quoted 11 lines · Catherine Hoang
Add a new ioctl to set the uuid of a mounted filesystem.
Signed-off-by Catherine Hoang <[email protected]>---
fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 ++++++++ fs/xfs/xfs_log.h | 2 + 4 files changed, 129 insertions(+)
Quoted 11 lines
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 834
Quoted 9 lines
fs/xfs/libxfs/xfs_fs.h +1
-0@@ -831,6 +831,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_SETFSUUID _IOR ('X', 129, uuid_t)Should be
_IOW.
Ok, will fix that.
Quoted 9 lines
Would you consider defining that as
FS_IOC_SETFSUUIDinfs.h, so that other fs could implement it later on, instead of hoisting it later?It would be easy to add support for
FS_IOC_SETFSUUIDto ext4 by generalizingext4_ioctl_setuuid().Alternatively, we could hoist
EXT4_IOC_SETFSUUIDand struct fsuuid tofs.hand use that ioctl also for xfs.
I actually did try to hoist the ext4 ioctls previously, but we weren’t able to come to a consensus on the implementation.
https://lore.kernel.org/linux-xfs/[email protected]/
I would prefer to keep this defined as an xfs specific ioctl to avoid all of the fsdevel bikeshedding.
Quoted 6 lines
Using an extensible struct with flags for that ioctl may turn out to be useful, for example, to verify that the new uuid is unique, despite the fact that xfs was
mounted with -onouuid (useful IMO) or to explicitly request a restore of old uuid that would fail ifnew_uuid!= meta uuid.
I think using a struct is probably a good idea, I can add that in the next version.
Quoted 3 lines
Thanks,
Amir.
Re: [PATCH v1 3/4] xfs: add XFS_IOC_SETFSUUID ioctl
Quoted 39 lines · Catherine Hoang
Quoted 16 lines · Amir Goldstein
Quoted 11 lines · Catherine Hoang
Add a new ioctl to set the uuid of a mounted filesystem.
Signed-off-by Catherine Hoang <[email protected]>---
fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 ++++++++ fs/xfs/xfs_log.h | 2 + 4 files changed, 129 insertions(+)Quoted 11 lines
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 834
Quoted 9 lines
fs/xfs/libxfs/xfs_fs.h +1
-0@@ -831,6 +831,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_SETFSUUID _IOR ('X', 129, uuid_t)Should be
_IOW.Ok, will fix that.
Quoted 9 lines
Would you consider defining that as
FS_IOC_SETFSUUIDinfs.h, so that other fs could implement it later on, instead of hoisting it later?It would be easy to add support for
FS_IOC_SETFSUUIDto ext4 by generalizingext4_ioctl_setuuid().Alternatively, we could hoist
EXT4_IOC_SETFSUUIDand struct fsuuid tofs.hand use that ioctl also for xfs.
Quoted 7 lines
I actually did try to hoist the ext4 ioctls previously, but we weren’t able to come to a consensus on the implementation.
https://lore.kernel.org/linux-xfs/[email protected]/
I would prefer to keep this defined as an xfs specific ioctl to avoid all of the fsdevel bikeshedding.
For the greater good, please do try to have this bikeshedding, before giving up. The discussion you pointed to wasn't so far from consensus IMO except fsdevel was not CCed.
Quoted 8 lines
Quoted 6 lines
Using an extensible struct with flags for that ioctl may turn out to be useful, for example, to verify that the new uuid is unique, despite the fact that xfs was
mounted with -onouuid (useful IMO) or to explicitly request a restore of old uuid that would fail ifnew_uuid!= meta uuid.I think using a struct is probably a good idea, I can add that in the next version.
Well, if you agree about a struct and agree about flags then the only thing left is Dave's concern about variable size arrays in ioctl and that could be addressed in a way that is compatible with ext4.
See untested patch below.
Thanks,
Amir.
include/uapi/linux/fs.h +11 -0
@@ -215,6 +215,17 @@ 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('v', 44, struct fsuuid) +#define FS_IOC_SETFSUUID _IOW('v', 44, struct fsuuid) + +/* +* Structure for FS_IOC_GETFSUUID/FS_IOC_SETFSUUID +*/ +struct fsuuid { +__u32 fsu_len;/* for backward compat has to be 16 */ +__u32 fsu_flags; +__u8 fsu_uuid[16 ]; +};
fs/ext4/ext4.h +3 -3
@@ -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 _IOR('f', 44, struct fsuuid_bdr) +#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid_hdr)#define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32)
@@ -756,7 +756,7 @@ enum {/* * Structure for EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID */ -struct fsuuid { +struct fsuuid_hdr {__u32 fsu_len;__u32 fsu_flags;__u8 fsu_uuid[];
fs/ext4/ioctl.c +3 -3
@@ -1149,7 +1149,7 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,struct fsuuid fsuuid;__u8 uuid[UUID_SIZE ]; -if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +if (copy_from_user (&fsuuid, ufsuuid, offsetof(fsuuid , fsu_uuid)))return -EFAULT ;if (fsuuid.fsu_len ==0 ) {
@@ -1168,7 +1168,7 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,unlock_buffer (sbi->s_sbh); fsuuid.fsu_len =UUID_SIZE ; -if (copy_to_user (ufsuuid, &fsuuid,sizeof (fsuuid)) || +if (copy_to_user (ufsuuid, &fsuuid, offsetof(fsuuid , fsu_uuid)) ||copy_to_user (&ufsuuid->fsu_uuid[0 ], uuid,UUID_SIZE ))return -EFAULT ;return 0 ;
@@ -1194,7 +1194,7 @@ static int ext4_ioctl_setuuid(struct file *filp, || ext4_has_feature_stable_inodes(sb))return -EOPNOTSUPP ; -if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +if (copy_from_user (&fsuuid, ufsuuid, offsetof(fsuuid , fsu_uuid)))return -EFAULT ;if (fsuuid.fsu_len !=UUID_SIZE || fsuuid.fsu_flags !=0 )
@@ -1596,8 +1596,10 @@ static long __ext4_ioctl(struct file *filp,
unsigned int cmd, unsigned long arg)
return ext4_ioctl_setlabel(filp,
(const void __user *)arg);+ case FS_IOC_GETFSUUID:
case EXT4_IOC_GETFSUUID:
return ext4_ioctl_getuuid(EXT4_SB(sb), (void __user *)arg);
+ case FS_IOC_SETFSUUID:
case EXT4_IOC_SETFSUUID:
return ext4_ioctl_setuuid(filp, (const void __user *)arg);
default:Re: [PATCH v1 3/4] xfs: add XFS_IOC_SETFSUUID ioctl
Quoted 44 lines · Amir Goldstein
Quoted 42 lines · Catherine Hoang
Quoted 16 lines · Amir Goldstein
Quoted 11 lines · Catherine Hoang
Add a new ioctl to set the uuid of a mounted filesystem.
Signed-off-by Catherine Hoang <[email protected]>---
fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 ++++++++ fs/xfs/xfs_log.h | 2 + 4 files changed, 129 insertions(+)Quoted 11 lines
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 834
Quoted 9 lines
fs/xfs/libxfs/xfs_fs.h +1
-0@@ -831,6 +831,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_SETFSUUID _IOR ('X', 129, uuid_t)Should be
_IOW.Ok, will fix that.
Quoted 9 lines
Would you consider defining that as
FS_IOC_SETFSUUIDinfs.h, so that other fs could implement it later on, instead of hoisting it later?It would be easy to add support for
FS_IOC_SETFSUUIDto ext4 by generalizingext4_ioctl_setuuid().Alternatively, we could hoist
EXT4_IOC_SETFSUUIDand struct fsuuid tofs.hand use that ioctl also for xfs.I actually did try to hoist the ext4 ioctls previously, but we weren’t able to come to a consensus on the implementation.
Quoted 8 lines
Quoted 4 lines
https://lore.kernel.org/linux-xfs/[email protected]/
I would prefer to keep this defined as an xfs specific ioctl to avoid all of the fsdevel bikeshedding.
For the greater good, please do try to have this bikeshedding, before giving up. The discussion you pointed to wasn't so far from consensus IMO except fsdevel was not CCed.
Why? fsdevel bikeshedding is a pointless waste of time. Jeremy ran four rounds of proposing the new api on linux-api, linux-fsdevel, and linux-ext4. Matthew Wilcox and I sent in our comments, including adding some flexibility for shorter or longer uuids, so he updated the proposal and it got merged:
https://lore.kernel.org/linux-api/?q=Bongio
The instant Catherine started talking about using this new API, Dave came in and said no, flex arrays for uuids are stupid, and told Catherine she ought to "fix" the landmines by changing the structure definition:
https://lore.kernel.org/linux-xfs/[email protected]/
Never mind that changing the struct size causes the output of _IOR to change, which means a new ioctl command number, which is effectively a new interface. I think we'll just put new ioctls in xfs_fs_staging.h, merge the code, let people kick the tires for a few months, and only then make it permanent.
Though really, that's the least of the problems, especially since Dave had a pretty good list of questions elsewhere in this thread.
--D
Quoted 26 lines
Quoted 8 lines
Quoted 6 lines
Using an extensible struct with flags for that ioctl may turn out to be useful, for example, to verify that the new uuid is unique, despite the fact that xfs was
mounted with -onouuid (useful IMO) or to explicitly request a restore of old uuid that would fail ifnew_uuid!= meta uuid.I think using a struct is probably a good idea, I can add that in the next version.
Well, if you agree about a struct and agree about flags then the only thing left is Dave's concern about variable size arrays in ioctl and that could be addressed in a way that is compatible with ext4.
See untested patch below.
Thanks,
Amir.include/uapi/linux/fs.h +0
-0@@ -215,6 +215,17 @@ 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])
include/uapi/linux/fs.h struct fsxattr { · line 227
Quoted 10 lines
include/uapi/linux/fs.h +10
-0+#define FS_IOC_GETFSUUID _IOR('v', 44, struct fsuuid) +#define FS_IOC_SETFSUUID _IOW('v', 44, struct fsuuid) + +/* +* Structure for FS_IOC_GETFSUUID/FS_IOC_SETFSUUID +*/ +struct fsuuid { +__u32 fsu_len;/* for backward compat has to be 16 */ +__u32 fsu_flags; +__u8 fsu_uuid[16 ];
Um, these two ioctls have different namespace /and/ different structure sizes. This is literally defining a new interface.
Quoted 70 lines
include/uapi/linux/fs.h +1
-0+};fs/ext4/ext4.h +3
-3@@ -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 _IOR('f', 44, struct fsuuid_bdr) +#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid_hdr)#define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32)@@ -756,7 +756,7 @@ enum {/* * Structure for EXT4_IOC_GETFSUUID/EXT4_IOC_SETFSUUID */ -struct fsuuid { +struct fsuuid_hdr {__u32 fsu_len;__u32 fsu_flags;__u8 fsu_uuid[];fs/ext4/ioctl.c +5
-3@@ -1149,7 +1149,7 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,struct fsuuid fsuuid;__u8 uuid[UUID_SIZE ]; -if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +if (copy_from_user (&fsuuid, ufsuuid, offsetof(fsuuid , fsu_uuid)))return -EFAULT ;if (fsuuid.fsu_len ==0 ) {@@ -1168,7 +1168,7 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,unlock_buffer (sbi->s_sbh); fsuuid.fsu_len =UUID_SIZE ; -if (copy_to_user (ufsuuid, &fsuuid,sizeof (fsuuid)) || +if (copy_to_user (ufsuuid, &fsuuid, offsetof(fsuuid , fsu_uuid)) ||copy_to_user (&ufsuuid->fsu_uuid[0 ], uuid,UUID_SIZE ))return -EFAULT ;return 0 ;@@ -1194,7 +1194,7 @@ static int ext4_ioctl_setuuid(struct file *filp, || ext4_has_feature_stable_inodes(sb))return -EOPNOTSUPP ; -if (copy_from_user (&fsuuid, ufsuuid,sizeof (fsuuid))) +if (copy_from_user (&fsuuid, ufsuuid, offsetof(fsuuid , fsu_uuid)))return -EFAULT ;if (fsuuid.fsu_len !=UUID_SIZE || fsuuid.fsu_flags !=0 )@@ -1596,8 +1596,10 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return ext4_ioctl_setlabel(filp, (const void __user *)arg); +case FS_IOC_GETFSUUID :case EXT4_IOC_GETFSUUID :return ext4_ioctl_getuuid (EXT4_SB (sb), (void __user *)arg); +case FS_IOC_SETFSUUID :case EXT4_IOC_SETFSUUID :return ext4_ioctl_setuuid (filp, (const void __user *)arg);default:
Re: [PATCH v1 3/4] xfs: add XFS_IOC_SETFSUUID ioctl
Quoted 48 lines · Darrick J. Wong
Quoted 46 lines · Amir Goldstein
Quoted 44 lines · Catherine Hoang
Quoted 16 lines · Amir Goldstein
Quoted 11 lines · Catherine Hoang
Add a new ioctl to set the uuid of a mounted filesystem.
Signed-off-by Catherine Hoang <[email protected]>---
fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_ioctl.c | 107 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_log.c | 19 ++++++++ fs/xfs/xfs_log.h | 2 + 4 files changed, 129 insertions(+)Quoted 11 lines
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 834
Quoted 9 lines
fs/xfs/libxfs/xfs_fs.h +1
-0@@ -831,6 +831,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_SETFSUUID _IOR ('X', 129, uuid_t)Should be
_IOW.Ok, will fix that.
Quoted 9 lines
Would you consider defining that as
FS_IOC_SETFSUUIDinfs.h, so that other fs could implement it later on, instead of hoisting it later?It would be easy to add support for
FS_IOC_SETFSUUIDto ext4 by generalizingext4_ioctl_setuuid().Alternatively, we could hoist
EXT4_IOC_SETFSUUIDand struct fsuuid tofs.hand use that ioctl also for xfs.I actually did try to hoist the ext4 ioctls previously, but we weren’t able to come to a consensus on the implementation.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I would prefer to keep this defined as an xfs specific ioctl to avoid all of the fsdevel bikeshedding.
For the greater good, please do try to have this bikeshedding, before giving up. The discussion you pointed to wasn't so far from consensus IMO except fsdevel was not CCed.
Why? fsdevel bikeshedding is a pointless waste of time. Jeremy ran
[+ linux-api]
I do not think that it was a waste of time at all...
Quoted 12 lines
four rounds of proposing the new api on linux-api, linux-fsdevel, and linux-ext4. Matthew Wilcox and I sent in our comments, including adding some flexibility for shorter or longer uuids, so he updated the proposal and it got merged:
https://lore.kernel.org/linux-api/?q=Bongio
The instant Catherine started talking about using this new API, Dave came in and said no, flex arrays for uuids are stupid, and told Catherine she ought to "fix" the landmines by changing the structure definition:
Quoted 8 lines
https://lore.kernel.org/linux-xfs/[email protected]/
Never mind that changing the struct size causes the output of
_IORto change, which means a new ioctl command number, which is effectively a new interface. I think we'll just put new ioctls inxfs_fs_staging.h, merge the code, let people kick the tires for a few months, and only then make it permanent.
What you perceive as a waste of time, I perceive as a healthy process. This is what I see when reading the threads:
- Serious and responsible API discussion with several important review inputs incorporated.
- New API was added as "staging" in ext4 only
- Less than 1 year later, another fs wants to use the new API
- Dave (who may have missed the original API discussion?) points out a problem
- In my understanding, in the original discussion there was a consensus that uuid size is limited to 16 bytes [1] so the fact that fsu_uuid[] ended up as a variable array is just a human mistake?
[1] https://lore.kernel.org/linux-api/[email protected]/
So we had a design discussion, we had a staging API and we found a problem in the staging API. This is what I call a healthy process.
When that happens it is not too late to fix the API problem.
and the fix is simple - increase the size of the struct to maximal uuid size and change the ioctl numbers.
Yes, ext4 tools and kernel driver have to pay the penalty of backward compat support for the V1 API, but as I showed in the sketch patch, that will be quite easy to do and that is the price that one has to pay for being a pioneer ;)
So for a workplan, Catherine can use the extended fsuuid struct and add it to staging in xfs as you proposed, with the intention of hoisting it to fs.h later on.
And that plan should be published to linux-api and linux-fsdevel.
Assuming that ext4 developers are fine with this plan, they could already adjust ext4 and e2fsprogs to the V2 API before being hoisted, because the adjustments are pretty simple.
Thanks,
Amir.
PATCH 4/4 xfs: export meta uuid via xfs_fsop_geom
In reply to Catherine HoangExport the meta uuid to userspace so that we can restore the original uuid after it has been changed.
--- fs/xfs/libxfs/xfs_fs.h | 3 ++- fs/xfs/libxfs/xfs_sb.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_fs.h +2 -1
@@ -186,7 +186,8 @@ struct xfs_fsop_geom {__u32 logsunit;/* log stripe unit, bytes */ uint32_t sick;/* o: unhealthy fs & rt metadata */ uint32_t checked;/* o: checked fs & rt metadata */ -__u64 reserved[17 ];/* reserved space */ +unsigned char metauuid[16 ];/* metadata id of the filesystem*/ +__u64 reserved[15 ];/* reserved space */ };#define XFS_FSOP_GEOM_SICK_COUNTERS (1 << 0)/* summary counters */
fs/xfs/libxfs/xfs_sb.c +5 -0
@@ -1213,6 +1213,11 @@ xfs_fs_geometry(return ; geo->version =XFS_FSOP_GEOM_VERSION_V5 ; + +if (xfs_has_metauuid (mp)) { +BUILD_BUG_ON (sizeof (geo->metauuid) !=sizeof (sbp->sb_meta_uuid)); +memcpy (geo->metauuid, &sbp->sb_meta_uuid,sizeof (sbp->sb_meta_uuid)); + } }/* Read a secondary superblock. */
Signature · 1 line
2.34.1
Quoted 7 lines · Catherine Hoang
Hi all,
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the '
xfs_iofsuuid' command to allow userspace to update the uuid.Comments and feedback appreciated!
What's the use case for this?
What are the pro's and cons of the implementation?
Some problems I see:
* How does this interact with pNFS exports (i.e. CONFIG_EXPORTFS_BLOCK_OPS). XFS hands the sb_uuid directly to pNFS server (and remote clients, I think) so that incoming mapping requests can be directed to the correct block device hosting the XFS filesystem the mapping information is for. IIRC, the pNFS data path is just given a byte offset into the device where the UUID in the superblock lives, and if it matches it allows the remote IO to go ahead - it doesn't actually know that there is a filesystem on that device at all...
* IIRC, the nfsd export table can also use the filesystem uuid to identify the filesystem being exported, and IIRC that gets encoded in the filehandle. Does changing the filesystem UUID then cause problems with export indentification and/or file handle creation/resolution?
* Is the VFS prepared for sb->s_uuid changing underneath running operations on mounted filesystems? I can see that this might cause problems with any sort of fscrypt implementation as it may encode the s_uuid into encryption keys held in xattrs, similarly IMA and EVM integrity protection keys.
* Should the VFS superblock sb->s_uuid use the XFS sb->sb_meta_uuid value and never change because we can encode it into other objects stored in the active filesystem? What does that mean for tools that identify block devices or filesystems by the VFS uuid rather than the filesystem uuid?
There's a whole can-o-worms here - the ability to dynamically change the UUID of a filesystem while it is mounted mean we need to think about these things - it's no longer as simple as "can only do it offline" which is typically only used to relabel a writeable snapshot of a golden image file during new VM deployment preparation.....
Quoted 6 lines
Catherine
Catherine Hoang (4):
xfs: refactorxfs_uuid_mountandxfs_uuid_unmount
xfs: implement custom freeze/thaw functions
The "custom" parts that XFS requires need to be added to the VFS level freeze/thaw functions, not duplicate the VFS functionality within XFS and then slight modify it for this additional feature. Doing this results in unmaintainable code over the long term.
Quoted 2 lines
xfs: add
XFS_IOC_SETFSUUIDioctl
xfs: export meta uuid viaxfs_fsop_geom
For what purpose does userspace ever need to know the sb_meta_uuid?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 5 lines · Dave Chinner
Quoted 2 lines · Catherine Hoang
Hi all,
Quoted 7 lines
Quoted 5 lines
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the '
xfs_iofsuuid' command to allow userspace to update the uuid.Comments and feedback appreciated!
What's the use case for this?
We want to be able to change the uuid on newly mounted clone vm images so that each deployed system has a different uuid. We need to do this the first time the system boots, but after the root fs is mounted so that fsuuid can run in parallel with other service startup to minimize deployment times.
Quoted 52 lines
What are the pro's and cons of the implementation?
Some problems I see:
* How does this interact with pNFS exports (i.e.
CONFIG_EXPORTFS_BLOCK_OPS). XFS hands thesb_uuiddirectly to pNFS server (and remote clients, I think) so that incoming mapping requests can be directed to the correct block device hosting the XFS filesystem the mapping information is for. IIRC, the pNFS data path is just given a byte offset into the device where the UUID in the superblock lives, and if it matches it allows the remote IO to go ahead - it doesn't actually know that there is a filesystem on that device at all...* IIRC, the nfsd export table can also use the filesystem uuid to identify the filesystem being exported, and IIRC that gets encoded in the filehandle. Does changing the filesystem UUID then cause problems with export indentification and/or file handle creation/resolution?
* Is the VFS prepared for
sb->s_uuidchanging underneath running operations on mounted filesystems? I can see that this might cause problems with any sort of fscrypt implementation as it may encode thes_uuidinto encryption keys held in xattrs, similarly IMA and EVM integrity protection keys.* Should the VFS superblock
sb->s_uuiduse the XFSsb->sb_meta_uuidvalue and never change because we can encode it into other objects stored in the active filesystem? What does that mean for tools that identify block devices or filesystems by the VFS uuid rather than the filesystem uuid?There's a whole can-o-worms here - the ability to dynamically change the UUID of a filesystem while it is mounted mean we need to think about these things - it's no longer as simple as "can only do it offline" which is typically only used to relabel a writeable snapshot of a golden image file during new VM deployment preparation.....
Quoted 6 lines
Catherine
Catherine Hoang (4):
xfs: refactorxfs_uuid_mountandxfs_uuid_unmount
xfs: implement custom freeze/thaw functionsThe "custom" parts that XFS requires need to be added to the VFS level freeze/thaw functions, not duplicate the VFS functionality within XFS and then slight modify it for this additional feature. Doing this results in unmaintainable code over the long term.
Quoted 4 lines
Quoted 2 lines
xfs: add
XFS_IOC_SETFSUUIDioctl
xfs: export meta uuid viaxfs_fsop_geomFor what purpose does userspace ever need to know the
sb_meta_uuid?
Userspace would need to know the meta uuid if we want to restore the original uuid after it has been changed.
Quoted 7 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 9 lines · Catherine Hoang
Quoted 9 lines · Dave Chinner
Quoted 6 lines · Catherine Hoang
Hi all,
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the '
xfs_iofsuuid' command to allow userspace to update the uuid.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Comments and feedback appreciated!
What's the use case for this?
We want to be able to change the uuid on newly mounted clone vm images so that each deployed system has a different uuid. We need to do this the first time the system boots, but after the root fs is mounted so that fsuuid can run in parallel with other service startup to minimize deployment times.
Why can't you do it offline immediately after the offline clone of the golden image? I mean, cloning images and setting up their contents is something the external orchestration software does and will always have to do, so i don't really understand why UUID needs to be modified at first mount vs at clone time. Can you describe why it actually needs to be done after first mount?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
xfs: add
XFS_IOC_SETFSUUIDioctl
xfs: export meta uuid viaxfs_fsop_geomFor what purpose does userspace ever need to know the
sb_meta_uuid?Userspace would need to know the meta uuid if we want to restore the original uuid after it has been changed.
I don't understand why you'd want to restore the original UUID given the use case you've describe. Can you explain the situation where you want to return a cloned image to the original golden image UUID?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 14 lines · Dave Chinner
Quoted 13 lines · Catherine Hoang
Quoted 12 lines · Dave Chinner
Quoted 7 lines · Catherine Hoang
Hi all,
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the '
xfs_iofsuuid' command to allow userspace to update the uuid.Comments and feedback appreciated!
What's the use case for this?
Quoted 7 lines
Quoted 4 lines
We want to be able to change the uuid on newly mounted clone vm images so that each deployed system has a different uuid. We need to do this the first time the system boots, but after the root fs is mounted so that fsuuid can run in parallel with other service startup to minimize deployment times.
Why can't you do it offline immediately after the offline clone of the golden image? I mean, cloning images and setting up their
That /is/ how they do it currently. The goal here was to reduce the number of scripts that then must be worked into every distro's bespoke initrd generation system (update-initramfs, dracut, etc.). Doing this from systemd bypasses that, and it means it can get done in the background during first boot, instead of rewriting superblocks in the singlethreaded initramfs hot path during deployments.
They need the fsuuid to change after the VM starts up, but it doesn't have to get done until just before we start handing out NFS leases. Granted that was before we hit the wall of "lots of subsystems encode the fs uuid into things and hand them out"...
Quoted 8 lines
contents is something the external orchestration software does and will always have to do, so i don't really understand why UUID needs to be modified at first mount vs at clone time. Can you describe why it actually needs to be done after first mount?
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
xfs: add
XFS_IOC_SETFSUUIDioctl
xfs: export meta uuid viaxfs_fsop_geom
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
For what purpose does userspace ever need to know the
sb_meta_uuid?Userspace would need to know the meta uuid if we want to restore the original uuid after it has been changed.
I don't understand why you'd want to restore the original UUID given the use case you've describe. Can you explain the situation where you want to return a cloned image to the original golden image UUID?
I can't think of any, and was assuming that Catherine did that to maintain parity with the offline fsuuid setting command...
--D
Quoted 5 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 15 lines · Dave Chinner
Quoted 7 lines · Catherine Hoang
Hi all,
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the '
xfs_iofsuuid' command to allow userspace to update the uuid.Comments and feedback appreciated!
What's the use case for this?
What are the pro's and cons of the implementation?
Some problems I see:
Quoted 9 lines
* How does this interact with pNFS exports (i.e.
CONFIG_EXPORTFS_BLOCK_OPS). XFS hands thesb_uuiddirectly to pNFS server (and remote clients, I think) so that incoming mapping requests can be directed to the correct block device hosting the XFS filesystem the mapping information is for. IIRC, the pNFS data path is just given a byte offset into the device where the UUID in the superblock lives, and if it matches it allows the remote IO to go ahead - it doesn't actually know that there is a filesystem on that device at all...
I think we're going to have to detect the presence of pNFS exports and EAGAIN if there are any active. That probably involves incrementing a counter during ->map_blocks and decreasing it during ->commit blocks.
That might still invite races between someone setting the fsuuid and exporting via NFS.
Quoted 5 lines
* IIRC, the nfsd export table can also use the filesystem uuid to identify the filesystem being exported, and IIRC that gets encoded in the filehandle. Does changing the filesystem UUID then cause problems with export indentification and/or file handle creation/resolution?
I thought NFS (when not being used for block layouts and pnfs stuff) still used the fsid that's also in the superblock? Presumably we'd leave the old m_fixedfsid unchanged while the fs is still mounted, and document the caveat that handles will not work after a remount.
On some level, we might simply have to document that changing the user-visible uuid will break file handles and pnfs exports, so sysadmins had better get that done early.
OTOH that is an argument for leaving the xfs_db-based version that we have now.
Quoted 5 lines
* Is the VFS prepared for
sb->s_uuidchanging underneath running operations on mounted filesystems? I can see that this might cause problems with any sort of fscrypt implementation as it may encode thes_uuidinto encryption keys held in xattrs, similarly IMA and EVM integrity protection keys.
I would hope it's not so hard to detect that EVM/fscrypt are active on a given xfs mount. EVM seems pretty hard to detect since it operates above the fs.
fscrypt might not be so difficult, since we likely need to add support in the ondisk metadata, which means xfs will know.
IMA seems to be using it for rule matching, so I'd say that if the sysadmin changes the fsuuid, they had better update the IMA rulebook too.
Come to think of it, perhaps reading a filesystem's uuid (whether via handle export, direct read of s_uuid, nfs, evm, ima, or fscrypt) should set a superblock flag that someone has accessed it; and only if nobody's yet accessed it do we allow the fsuuid update?
Quoted 5 lines
* Should the VFS superblock
sb->s_uuiduse the XFSsb->sb_meta_uuidvalue and never change because we can encode it into other objects stored in the active filesystem? What does that mean for tools that identify block devices or filesystems by the VFS uuid rather than the filesystem uuid?
I don't know of any other than the ones you found.
Quoted 6 lines
There's a whole can-o-worms here - the ability to dynamically change the UUID of a filesystem while it is mounted mean we need to think about these things - it's no longer as simple as "can only do it offline" which is typically only used to relabel a writeable snapshot of a golden image file during new VM deployment preparation.....
Agreed.
Quoted 11 lines
Quoted 6 lines
Catherine
Catherine Hoang (4):
xfs: refactorxfs_uuid_mountandxfs_uuid_unmount
xfs: implement custom freeze/thaw functionsThe "custom" parts that XFS requires need to be added to the VFS level freeze/thaw functions, not duplicate the VFS functionality within XFS and then slight modify it for this additional feature. Doing this results in unmaintainable code over the long term.
Yeah, I think for the next iteration we ought to try to pull in Luis's kernel-initiated-exclusive-freeze patch.
Quoted 4 lines
Quoted 2 lines
xfs: add
XFS_IOC_SETFSUUIDioctl
xfs: export meta uuid viaxfs_fsop_geomFor what purpose does userspace ever need to know the
sb_meta_uuid?
(No idea; once someone sets a fsuuid they usually don't want to go back.)
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 74 lines · Darrick J. Wong
Quoted 15 lines · Dave Chinner
Quoted 7 lines · Catherine Hoang
Hi all,
This series of patches implements a new ioctl to set the uuid of mounted filesystems. Eventually this will be used by the '
xfs_iofsuuid' command to allow userspace to update the uuid.Comments and feedback appreciated!
What's the use case for this?
What are the pro's and cons of the implementation?
Some problems I see:
Quoted 9 lines
* How does this interact with pNFS exports (i.e.
CONFIG_EXPORTFS_BLOCK_OPS). XFS hands thesb_uuiddirectly to pNFS server (and remote clients, I think) so that incoming mapping requests can be directed to the correct block device hosting the XFS filesystem the mapping information is for. IIRC, the pNFS data path is just given a byte offset into the device where the UUID in the superblock lives, and if it matches it allows the remote IO to go ahead - it doesn't actually know that there is a filesystem on that device at all...I think we're going to have to detect the presence of pNFS exports and EAGAIN if there are any active. That probably involves incrementing a counter during ->map_blocks and decreasing it during ->commit blocks.
That might still invite races between someone setting the fsuuid and exporting via NFS.
Quoted 5 lines
* IIRC, the nfsd export table can also use the filesystem uuid to identify the filesystem being exported, and IIRC that gets encoded in the filehandle. Does changing the filesystem UUID then cause problems with export indentification and/or file handle creation/resolution?
I thought NFS (when not being used for block layouts and pnfs stuff) still used the fsid that's also in the superblock? Presumably we'd leave the old
m_fixedfsidunchanged while the fs is still mounted, and document the caveat that handles will not work after a remount.On some level, we might simply have to document that changing the user-visible uuid will break file handles and pnfs exports, so sysadmins had better get that done early.
OTOH that is an argument for leaving the xfs_db-based version that we have now.
Quoted 5 lines
* Is the VFS prepared for
sb->s_uuidchanging underneath running operations on mounted filesystems? I can see that this might cause problems with any sort of fscrypt implementation as it may encode thes_uuidinto encryption keys held in xattrs, similarly IMA and EVM integrity protection keys.I would hope it's not so hard to detect that EVM/fscrypt are active on a given xfs mount. EVM seems pretty hard to detect since it operates above the fs.
fscrypt might not be so difficult, since we likely need to add support in the ondisk metadata, which means xfs will know.
IMA seems to be using it for rule matching, so I'd say that if the sysadmin changes the fsuuid, they had better update the IMA rulebook too.
Come to think of it, perhaps reading a filesystem's uuid (whether via handle export, direct read of
s_uuid, nfs, evm, ima, or fscrypt) should set a superblock flag that someone has accessed it; and only if nobody's yet accessed it do we allow the fsuuid update?
Quoted 7 lines
Quoted 5 lines
* Should the VFS superblock
sb->s_uuiduse the XFSsb->sb_meta_uuidvalue and never change because we can encode it into other objects stored in the active filesystem? What does that mean for tools that identify block devices or filesystems by the VFS uuid rather than the filesystem uuid?I don't know of any other than the ones you found.
FWIW, overlayfs also uses s_uuid in a similar manner to nfsd as a persistent reference to the origin lower file after copy up.
Like nfsd, the overlayfs persistent origin handle (fsuuid+filehandle) will break when changing lower fs uuid offline, but I don't see much difference from changing s_uuid online - worse case that I can think of is that an overlayfs inode will change its st_ino after evict/lookup on a mounted overlayfs.
Thanks,
Amir.