add and use a per-mapping stable writes flag
Subsystems (5)
Hi all
A while ago Ilya pointer out that since commit 1cb039f3dc16 ("bdi:
replace BDI_CAP_STABLE_WRITES with a queue and a sb flag"), the stable write flag on the queue wasn't used for writes to the block devices nodes any more, and willy suggested fixing this by adding a stable write flags on each address_space. This series implements this fix, and also fixes the stable write flag when the XFS RT device requires it, but the main device doesn't (which is probably more a theoretical than a practical problem).
Diffstat:
block/bdev.c | 2 ++ fs/inode.c | 2 ++ fs/xfs/xfs_inode.h | 8 ++++++++ fs/xfs/xfs_ioctl.c | 9 +++++++++ fs/xfs/xfs_iops.c | 7 +++++++ include/linux/pagemap.h | 17 +++++++++++++++++ mm/page-writeback.c | 2 +- 7 files changed, 46 insertions(+), 1 deletion(-)
PATCH 1/3 filemap: add a per-mapping stable writes flag
folio_wait_stable waits for writeback to finish before modifying the contents of a folio again, e.g. to support check summing of the data in the block integrity code.
Currently this behavior is controlled by the SB_I_STABLE_WRITES flag on the super_block, which means it is uniform for the entire file system. This is wrong for the block device pseudofs which is shared by all block devices, or file systems that can use multiple devices like XFS witht the RT subvolume or btrfs (although btrfs currently reimplements folio_wait_stable anyway).
Add a per-address_space AS_STABLE_WRITES flag to control the behavior in a more fine grained way. The existing SB_I_STABLE_WRITES is kept to initialize AS_STABLE_WRITES to the existing default which covers most cases.
--- fs/inode.c | 2 ++ include/linux/pagemap.h | 17 +++++++++++++++++ mm/page-writeback.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-)
fs/inode.c +2 -0
@@ -215,6 +215,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)lockdep_set_class_and_name (&mapping->invalidate_lock, &sb->s_type->invalidate_lock_key,"mapping.invalidate_lock" ); +if (sb->s_iflags &SB_I_STABLE_WRITES ) +mapping_set_stable_writes (mapping); inode->i_private =NULL ; inode->i_mapping = mapping;INIT_HLIST_HEAD (&inode->i_dentry);/* buggered by rcu freeing */
include/linux/pagemap.h +17 -0
@@ -204,6 +204,8 @@ enum mapping_flags {AS_NO_WRITEBACK_TAGS =5 ,AS_LARGE_FOLIO_SUPPORT =6 ,AS_RELEASE_ALWAYS ,/* Call ->release_folio(), even if no private data */ + AS_STABLE_WRITES, /* must wait for writeback before modifying + folio contents */ };/**
@@ -289,6 +291,21 @@ static inline void mapping_clear_release_always(struct address_space *mapping)clear_bit (AS_RELEASE_ALWAYS , &mapping->flags); } +static inline bool mapping_stable_writes (const struct address_space *mapping) +{ +return test_bit (AS_STABLE_WRITES , &mapping->flags); +} + +static inline void mapping_set_stable_writes (struct address_space *mapping) +{ +set_bit (AS_STABLE_WRITES , &mapping->flags); +} + +static inline void mapping_clear_stable_writes (struct address_space *mapping) +{ +clear_bit (AS_STABLE_WRITES , &mapping->flags); +} +static inline gfp_t mapping_gfp_mask (struct address_space * mapping) {return mapping->gfp_mask;
mm/page-writeback.c +1 -1
@@ -3110,7 +3110,7 @@ EXPORT_SYMBOL_GPL(folio_wait_writeback_killable);*/ void folio_wait_stable (struct folio *folio) { -if (folio_inode (folio)->i_sb->s_iflags &SB_I_STABLE_WRITES ) +if (mapping_stable_writes (folio_mapping (folio)))folio_wait_writeback (folio); }EXPORT_SYMBOL_GPL (folio_wait_stable);
Signature · 1 line
2.39.2
Re: [PATCH 1/3] filemap: add a per-mapping stable writes flag
Quoted 11 lines · Christoph Hellwig
folio_wait_stablewaits for writeback to finish before modifying the contents of a folio again, e.g. to support check summing of the data in the block integrity code.Currently this behavior is controlled by the
SB_I_STABLE_WRITESflag on thesuper_block, which means it is uniform for the entire file system. This is wrong for the block device pseudofs which is shared by all block devices, or file systems that can use multiple devices like XFS witht the RT subvolume or btrfs (although btrfs currently reimplementsfolio_wait_stableanyway).
Quoted 6 lines
Add a per-address_space
AS_STABLE_WRITESflag to control the behavior in a more fine grained way. The existingSB_I_STABLE_WRITESis kept to initializeAS_STABLE_WRITESto the existing default which covers most cases.Signed-off-by Christoph Hellwig <[email protected]>
mm/page-writeback.c EXPORT_SYMBOL_GPL(folio_wait_writeback_killable); · line 3114
Quoted 8 lines
+++
b/mm/page-writeback.cmm/page-writeback.c +1
-1@@ -3110,7 +3110,7 @@ EXPORT_SYMBOL_GPL(folio_wait_writeback_killable);*/ void folio_wait_stable (struct folio *folio) { -if (folio_inode (folio)->i_sb->s_iflags &SB_I_STABLE_WRITES ) +if (mapping_stable_writes (folio_mapping (folio)))folio_wait_writeback (folio);
What I really like about this is that we've gone from
folio->mapping->host->i_sb->s_iflags to folio->mapping->flags
which saves us two pointer dereferences. Sure, probably cached, but maybe not, and cache misses are expensive.
Re: [PATCH 1/3] filemap: add a per-mapping stable writes flag
In reply to Christoph HellwigQuoted 55 lines · Christoph Hellwig
folio_wait_stablewaits for writeback to finish before modifying the contents of a folio again, e.g. to support check summing of the data in the block integrity code.Currently this behavior is controlled by the
SB_I_STABLE_WRITESflag on thesuper_block, which means it is uniform for the entire file system. This is wrong for the block device pseudofs which is shared by all block devices, or file systems that can use multiple devices like XFS witht the RT subvolume or btrfs (although btrfs currently reimplementsfolio_wait_stableanyway).Add a per-address_space
AS_STABLE_WRITESflag to control the behavior in a more fine grained way. The existingSB_I_STABLE_WRITESis kept to initializeAS_STABLE_WRITESto the existing default which covers most cases.Signed-off-by Christoph Hellwig <[email protected]>--- fs/inode.c | 2 ++ include/linux/pagemap.h | 17 +++++++++++++++++ mm/page-writeback.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-)fs/inode.c +2
-0@@ -215,6 +215,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)lockdep_set_class_and_name (&mapping->invalidate_lock, &sb->s_type->invalidate_lock_key,"mapping.invalidate_lock" ); +if (sb->s_iflags &SB_I_STABLE_WRITES ) +mapping_set_stable_writes (mapping); inode->i_private =NULL ; inode->i_mapping = mapping;INIT_HLIST_HEAD (&inode->i_dentry);/* buggered by rcu freeing */ include/linux/pagemap.h +3
-0@@ -204,6 +204,8 @@ enum mapping_flags {AS_NO_WRITEBACK_TAGS =5 ,AS_LARGE_FOLIO_SUPPORT =6 ,AS_RELEASE_ALWAYS ,/* Call ->release_folio(), even if no private data */ + AS_STABLE_WRITES, /* must wait for writeback before modifying + folio contents */ };/** @@ -289,6 +291,21 @@ static inline void mapping_clear_release_always(struct address_space *mapping)clear_bit (AS_RELEASE_ALWAYS , &mapping->flags); } +static inline bool mapping_stable_writes (const struct address_space *mapping)
include/linux/pagemap.h static inline void mapping_clear_release_always(struct address_space *mapping) · line 304
Quoted 10 lines
include/linux/pagemap.h +10
-0+{ +return test_bit (AS_STABLE_WRITES , &mapping->flags); +} + +static inline void mapping_set_stable_writes (struct address_space *mapping) +{ +set_bit (AS_STABLE_WRITES , &mapping->flags); +} + +static inline void mapping_clear_stable_writes (struct address_space *mapping)
Hi Christoph,
Nit: mapping_clear_stable_writes() is unused.
Quoted 21 lines
include/linux/pagemap.h +4
-0+{ +clear_bit (AS_STABLE_WRITES , &mapping->flags); +} +static inline gfp_t mapping_gfp_mask (struct address_space * mapping) {return mapping->gfp_mask;mm/page-writeback.c +1
-2@@ -3110,7 +3110,7 @@ EXPORT_SYMBOL_GPL(folio_wait_writeback_killable);*/ void folio_wait_stable (struct folio *folio) { -if (folio_inode (folio)->i_sb->s_iflags &SB_I_STABLE_WRITES ) +if (mapping_stable_writes (folio_mapping (folio)))folio_wait_writeback (folio); }EXPORT_SYMBOL_GPL (folio_wait_stable); --
Quoted 2 lines
2.39.2
Tested with RBD which behaves like a DIF/DIX device (i.e. requires stable pages):
Thanks,
Ilya
Matthew Wilcox
maintainerRe: [PATCH 1/3] filemap: add a per-mapping stable writes flag
Quoted 5 lines · Ilya Dryomov
Quoted 1 line
+static inline void
mapping_clear_stable_writes(struct address_space *mapping)Hi Christoph,
Nit:
mapping_clear_stable_writes()is unused.
It's used in patch 3
Re: [PATCH 1/3] filemap: add a per-mapping stable writes flag
Quoted 9 lines · Matthew Wilcox
Quoted 5 lines · Ilya Dryomov
Quoted 1 line
+static inline void
mapping_clear_stable_writes(struct address_space *mapping)Hi Christoph,
Nit:
mapping_clear_stable_writes()is unused.It's used in patch 3
My apologies, I was too quick to archive it as specific to XFS.
Thanks,
Ilya
Re: [PATCH 1/3] filemap: add a per-mapping stable writes flag
In reply to Christoph HellwigQuoted 16 lines · Christoph Hellwig
folio_wait_stablewaits for writeback to finish before modifying the contents of a folio again, e.g. to support check summing of the data in the block integrity code.Currently this behavior is controlled by the
SB_I_STABLE_WRITESflag on thesuper_block, which means it is uniform for the entire file system. This is wrong for the block device pseudofs which is shared by all block devices, or file systems that can use multiple devices like XFS witht the RT subvolume or btrfs (although btrfs currently reimplementsfolio_wait_stableanyway).Add a per-address_space
AS_STABLE_WRITESflag to control the behavior in a more fine grained way. The existingSB_I_STABLE_WRITESis kept to initializeAS_STABLE_WRITESto the existing default which covers most cases.
Quoted 5 lines
Signed-off-by Christoph Hellwig <[email protected]>--- fs/inode.c | 2 ++ include/linux/pagemap.h | 17 +++++++++++++++++ mm/page-writeback.c | 2 +-
For a hot second I wondered if we could get rid of SB_I_STABLE_WRITES too, but then had an AHA moment when I saw that NFS also sets it.
This looks reasonable,
--D
Quoted 66 lines
3 files changed, 20 insertions(+), 1 deletion(-)fs/inode.c +2
-0@@ -215,6 +215,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)lockdep_set_class_and_name (&mapping->invalidate_lock, &sb->s_type->invalidate_lock_key,"mapping.invalidate_lock" ); +if (sb->s_iflags &SB_I_STABLE_WRITES ) +mapping_set_stable_writes (mapping); inode->i_private =NULL ; inode->i_mapping = mapping;INIT_HLIST_HEAD (&inode->i_dentry);/* buggered by rcu freeing */ include/linux/pagemap.h +17
-0@@ -204,6 +204,8 @@ enum mapping_flags {AS_NO_WRITEBACK_TAGS =5 ,AS_LARGE_FOLIO_SUPPORT =6 ,AS_RELEASE_ALWAYS ,/* Call ->release_folio(), even if no private data */ + AS_STABLE_WRITES, /* must wait for writeback before modifying + folio contents */ };/** @@ -289,6 +291,21 @@ static inline void mapping_clear_release_always(struct address_space *mapping)clear_bit (AS_RELEASE_ALWAYS , &mapping->flags); } +static inline bool mapping_stable_writes (const struct address_space *mapping) +{ +return test_bit (AS_STABLE_WRITES , &mapping->flags); +} + +static inline void mapping_set_stable_writes (struct address_space *mapping) +{ +set_bit (AS_STABLE_WRITES , &mapping->flags); +} + +static inline void mapping_clear_stable_writes (struct address_space *mapping) +{ +clear_bit (AS_STABLE_WRITES , &mapping->flags); +} +static inline gfp_t mapping_gfp_mask (struct address_space * mapping) {return mapping->gfp_mask;mm/page-writeback.c +1
-1@@ -3110,7 +3110,7 @@ EXPORT_SYMBOL_GPL(folio_wait_writeback_killable);*/ void folio_wait_stable (struct folio *folio) { -if (folio_inode (folio)->i_sb->s_iflags &SB_I_STABLE_WRITES ) +if (mapping_stable_writes (folio_mapping (folio)))folio_wait_writeback (folio); }EXPORT_SYMBOL_GPL (folio_wait_stable);Signature · 1 line
2.39.2
Matthew Wilcox
maintainerRe: [PATCH 1/3] filemap: add a per-mapping stable writes flag
Quoted 8 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig
Add a per-address_space
AS_STABLE_WRITESflag to control the behavior in a more fine grained way. The existingSB_I_STABLE_WRITESis kept to initializeAS_STABLE_WRITESto the existing default which covers most cases.For a hot second I wondered if we could get rid of
SB_I_STABLE_WRITEStoo, but then had an AHA moment when I saw that NFS also sets it.
I mean, we could if we're short on flags, or it just offends our aesthetics to have it. NFS (and others) would just have to call mapping_set_stable_writes() in their inode initialisation routines. I don't personally find it a big deal either way.
Re: [PATCH 1/3] filemap: add a per-mapping stable writes flag
In reply to Darrick J. WongQuoted 2 lines · Darrick J. Wong
For a hot second I wondered if we could get rid of
SB_I_STABLE_WRITEStoo, but then had an AHA moment when I saw that NFS also sets it.
It's not just NFS, but still the general way of propagating the flag. I don't really want to add bdev-specific code to new_inode.
PATCH 2/3 block: update the stable_writes flag in bdev_add
In reply to Christoph HellwigPropagate the per-queue stable_write flags into each bdev inode in bdev_add. This makes sure devices that require stable writes have it set for I/O on the block device node as well.
Note that this doesn't cover the case of a flag changing on a live device yet. We should handle that as well, but I plan to cover it as part of a more general rework of how changing runtime paramters on block devices works.
--- block/bdev.c | 2 ++ 1 file changed, 2 insertions(+)
block/bdev.c +2 -0
@@ -425,6 +425,8 @@ void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)void bdev_add (struct block_device *bdev,dev_t dev) { +if (bdev_stable_writes (bdev)) +mapping_set_stable_writes (bdev->bd_inode->i_mapping); bdev->bd_dev = dev; bdev->bd_inode->i_rdev = dev; bdev->bd_inode->i_ino = dev;
Signature · 1 line
2.39.2
Re: [PATCH 2/3] block: update the stable_writes flag in bdev_add
Quoted 31 lines · Christoph Hellwig
Propagate the per-queue
stable_writeflags into each bdev inode inbdev_add. This makes sure devices that require stable writes have it set for I/O on the block device node as well.Note that this doesn't cover the case of a flag changing on a live device yet. We should handle that as well, but I plan to cover it as part of a more general rework of how changing runtime paramters on block devices works.
Fixes 1cb039f3dc16 ("bdi: replace BDI_CAP_STABLE_WRITES with a queue and a sb flag")Reported-by Ilya Dryomov <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- block/bdev.c | 2 ++ 1 file changed, 2 insertions(+)block/bdev.c +2
-1@@ -425,6 +425,8 @@ void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)void bdev_add (struct block_device *bdev,dev_t dev) { +if (bdev_stable_writes (bdev)) +mapping_set_stable_writes (bdev->bd_inode->i_mapping); bdev->bd_dev = dev; bdev->bd_inode->i_rdev = dev; bdev->bd_inode->i_ino = dev; --
Quoted 2 lines
2.39.2
Tested with RBD which behaves like a DIF/DIX device (i.e. requires stable pages):
Thanks,
Ilya
Re: [PATCH 2/3] block: update the stable_writes flag in bdev_add
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
Propagate the per-queue
stable_writeflags into each bdev inode inbdev_add. This makes sure devices that require stable writes have it set for I/O on the block device node as well.Note that this doesn't cover the case of a flag changing on a live device yet. We should handle that as well, but I plan to cover it as part of a more general rework of how changing runtime paramters on block devices works.
Yessssssssss! :)
Quoted 3 lines
Fixes 1cb039f3dc16 ("bdi: replace BDI_CAP_STABLE_WRITES with a queue and a sb flag")Reported-by Ilya Dryomov <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
Seems sane to me,
--D
Quoted 20 lines
--- block/bdev.c | 2 ++ 1 file changed, 2 insertions(+)block/bdev.c +2
-0@@ -425,6 +425,8 @@ void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)void bdev_add (struct block_device *bdev,dev_t dev) { +if (bdev_stable_writes (bdev)) +mapping_set_stable_writes (bdev->bd_inode->i_mapping); bdev->bd_dev = dev; bdev->bd_inode->i_rdev = dev; bdev->bd_inode->i_ino = dev;Signature · 1 line
2.39.2
PATCH 3/3 xfs: respect the stable writes flag on the RT device
In reply to Christoph HellwigUpdate the per-folio stable writes flag dependening on which device an inode resides on.
--- fs/xfs/xfs_inode.h | 8 ++++++++ fs/xfs/xfs_ioctl.c | 9 +++++++++ fs/xfs/xfs_iops.c | 7 +++++++ 3 files changed, 24 insertions(+)
fs/xfs/xfs_inode.h +8 -0
@@ -561,6 +561,14 @@ extern void xfs_setup_inode(struct xfs_inode *ip);extern void xfs_setup_iops (struct xfs_inode *ip);extern void xfs_diflags_to_iflags (struct xfs_inode *ip,bool init); +static inline void xfs_update_stable_writes (struct xfs_inode *ip) +{ +if (bdev_stable_writes (xfs_inode_buftarg (ip)->bt_bdev)) +mapping_set_stable_writes (VFS_I (ip)->i_mapping); +else +mapping_clear_stable_writes (VFS_I (ip)->i_mapping); +} +/* * When setting up a newly allocated inode, we need to call * xfs_finish_inode_setup() once the inode is fully instantiated at
fs/xfs/xfs_ioctl.c +9 -0
@@ -1147,6 +1147,15 @@ xfs_ioctl_setattr_xflags( ip->i_diflags2 = i_flags2;xfs_diflags_to_iflags (ip, false); + +/* +* Make the stable writes flag match that of the device the inode +* resides on when flipping the RT flag. +*/ +if (S_ISREG (VFS_I (ip)->i_mode) && +XFS_IS_REALTIME_INODE (ip) != (fa->fsx_xflags &FS_XFLAG_REALTIME )) +xfs_update_stable_writes (ip); +xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG );xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );XFS_STATS_INC (mp, xs_ig_attrchg);
fs/xfs/xfs_iops.c +7 -0
@@ -1298,6 +1298,13 @@ xfs_setup_inode( gfp_mask =mapping_gfp_mask (inode->i_mapping);mapping_set_gfp_mask (inode->i_mapping, (gfp_mask & ~(__GFP_FS))); +/* +* For real-time inodes update the stable write flags to that of the RT +* device instead of the data device. +*/ +if (S_ISREG (inode->i_mode) &&XFS_IS_REALTIME_INODE (ip)) +xfs_update_stable_writes (ip); +/* * If there is no attribute fork no ACL can exist on this inode, * and it can't have any file capabilities attached to it either.
Signature · 1 line
2.39.2
Re: [PATCH 3/3] xfs: respect the stable writes flag on the RT device
Quoted 35 lines · Christoph Hellwig
Update the per-folio stable writes flag dependening on which device an inode resides on.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_inode.h | 8 ++++++++ fs/xfs/xfs_ioctl.c | 9 +++++++++ fs/xfs/xfs_iops.c | 7 +++++++ 3 files changed, 24 insertions(+)fs/xfs/xfs_inode.h +8
-0@@ -561,6 +561,14 @@ extern void xfs_setup_inode(struct xfs_inode *ip);extern void xfs_setup_iops (struct xfs_inode *ip);extern void xfs_diflags_to_iflags (struct xfs_inode *ip,bool init); +static inline void xfs_update_stable_writes (struct xfs_inode *ip) +{ +if (bdev_stable_writes (xfs_inode_buftarg (ip)->bt_bdev)) +mapping_set_stable_writes (VFS_I (ip)->i_mapping); +else +mapping_clear_stable_writes (VFS_I (ip)->i_mapping); +} +/* * When setting up a newly allocated inode, we need to call * xfs_finish_inode_setup() once the inode is fully instantiated at fs/xfs/xfs_ioctl.c +0
-0@@ -1147,6 +1147,15 @@ xfs_ioctl_setattr_xflags( ip->i_diflags2 = i_flags2;
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_xflags( · line 1157
Quoted 10 lines
fs/xfs/xfs_ioctl.c +8
-0xfs_diflags_to_iflags (ip, false); + +/* +* Make the stable writes flag match that of the device the inode +* resides on when flipping the RT flag. +*/ +if (S_ISREG (VFS_I (ip)->i_mode) && +XFS_IS_REALTIME_INODE (ip) != (fa->fsx_xflags &FS_XFLAG_REALTIME )) +xfs_update_stable_writes (ip);
Hmm. Won't the masking operation here result in the if test comparing 0 or FS_XFLAG_REALTIME to 0 or 1?
Oh. FS_XFLAG_REALTIME == 1, so that's not an issue in this one case. That's a bit subtle though, I'd have preferred
XFS_IS_REALTIME_INODE(ip) != !!(fa->fsx_xflags & FS_XFLAG_REALTIME))
to make it more obvious that the if test isn't comparing apples to oranges.
Quoted 9 lines
fs/xfs/xfs_ioctl.c +1
-0+xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG );xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );XFS_STATS_INC (mp, xs_ig_attrchg);fs/xfs/xfs_iops.c +0
-0
fs/xfs/xfs_iops.c xfs_setup_inode( · line 1306
Quoted 9 lines
fs/xfs/xfs_iops.c +6
-0@@ -1298,6 +1298,13 @@ xfs_setup_inode( gfp_mask =mapping_gfp_mask (inode->i_mapping);mapping_set_gfp_mask (inode->i_mapping, (gfp_mask & ~(__GFP_FS))); +/* +* For real-time inodes update the stable write flags to that of the RT +* device instead of the data device. +*/ +if (S_ISREG (inode->i_mode) &&XFS_IS_REALTIME_INODE (ip)) +xfs_update_stable_writes (ip);
I wonder if xfs_update_stable_writes should become an empty function for the CONFIG_XFS_RT=n case, to avoid the atomic flags update?
(The extra code is probably not worth the microoptimization.)
With the !! nit addressed,
--D
Quoted 7 lines
fs/xfs/xfs_iops.c +1
-0+/* * If there is no attribute fork no ACL can exist on this inode, * and it can't have any file capabilities attached to it either. Signature · 1 line
2.39.2
Matthew Wilcox
maintainerRe: [PATCH 3/3] xfs: respect the stable writes flag on the RT device
Quoted 7 lines · Darrick J. Wong
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_xflags( · line 1157
Quoted 3 lines
fs/xfs/xfs_ioctl.c +3
-0+if (S_ISREG (VFS_I (ip)->i_mode) && +XFS_IS_REALTIME_INODE (ip) != (fa->fsx_xflags &FS_XFLAG_REALTIME )) +xfs_update_stable_writes (ip);Hmm. Won't the masking operation here result in the if test comparing 0 or
FS_XFLAG_REALTIMEto 0 or 1?
Quoted 7 lines
Oh.
FS_XFLAG_REALTIME== 1, so that's not an issue in this one case. That's a bit subtle though, I'd have preferredXFS_IS_REALTIME_INODE(ip) != !!(fa->fsx_xflags & FS_XFLAG_REALTIME))to make it more obvious that the if test isn't comparing apples to oranges.
!= !! might be going a bit far. Would you settle for
XFS_IS_REALTIME_INODE(ip) == !(fa->fsx_xflags & FS_XFLAG_REALTIME)
? Although none of these read particularly nicely. Maybe
XFS_IS_REALTIME_INODE(ip) != ((fa->fsx_xflags & FS_XFLAG_REALTIME) == 0))
Perhaps we need a bool helper for (fa->fsx_xflags & FS_XFLAG_REALTIME)
Re: [PATCH 3/3] xfs: respect the stable writes flag on the RT device
In reply to Darrick J. WongQuoted 11 lines · Darrick J. Wong
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_xflags( · line 1157
Quoted 7 lines
fs/xfs/xfs_ioctl.c +7
-0+/* +* Make the stable writes flag match that of the device the inode +* resides on when flipping the RT flag. +*/ +if (S_ISREG (VFS_I (ip)->i_mode) && +XFS_IS_REALTIME_INODE (ip) != (fa->fsx_xflags &FS_XFLAG_REALTIME )) +xfs_update_stable_writes (ip);Hmm. Won't the masking operation here result in the if test comparing 0 or
FS_XFLAG_REALTIMEto 0 or 1?
Quoted 7 lines
Oh.
FS_XFLAG_REALTIME== 1, so that's not an issue in this one case. That's a bit subtle though, I'd have preferredXFS_IS_REALTIME_INODE(ip) != !!(fa->fsx_xflags & FS_XFLAG_REALTIME))to make it more obvious that the if test isn't comparing apples to oranges.
This is all copy and pasted from a check a few lines above :)
I guess I could clean it up as well or even add a rt_flag_changed local variable instead of duplicating the check.
Quoted 11 lines
fs/xfs/xfs_iops.c xfs_setup_inode( · line 1306
Quoted 6 lines
fs/xfs/xfs_iops.c +6
-0+/* +* For real-time inodes update the stable write flags to that of the RT +* device instead of the data device. +*/ +if (S_ISREG (inode->i_mode) &&XFS_IS_REALTIME_INODE (ip)) +xfs_update_stable_writes (ip);I wonder if
xfs_update_stable_writesshould become an empty function for theCONFIG_XFS_RT=ncase, to avoid the atomic flags update?(The extra code is probably not worth the microoptimization.)
The compiler already eliminates the code because XFS_IS_REALTIME_INODE(ip) has a stub for CONFIG_XFS_RT=n that always returns 0.