block atomic writes for xfs
Subsystems (13)
v4 cover block atomic writes for xfs
This series expands atomic write support to filesystems, specifically XFS. Extent alignment is based on new feature forcealign.
Flag FS_XFLAG_ATOMICWRITES is added as an enabling flag for atomic writes.
XFS can be formatted for atomic writes as follows:
mkfs.xfs -i forcealign=1 -d extsize=16384 -d atomic-writes=1 /dev/sda
atomic-writes=1 just enables atomic writes in the SB, but does not auto- enable atomic writes for each file.
Support can be enabled through xfs_io command:
$xfs_io -c "lsattr -v" filename
[extsize, force-align]
$xfs_io -c "extsize" filename
[16384] filename
$xfs_io -c "chattr +W" filename
$xfs_io -c "lsattr -v" filename
[extsize, force-align, atomic-writes] filename
$xfs_io -c statx filename
...
stat.stx_atomic_write_unit_min = 4096
stat.stx_atomic_write_unit_max = 16384
stat.stx_atomic_write_segments_max = 1
...
A known issue - as reported in
https://urldefense.com/v3/__https://lore.kernel.org/linux-xfs/[email protected]/T/*m7093bc85a8e0cbe13c111284768476d294aa077a__;Iw!!ACWV5N9M2RV99hQ!NbuQfXN8ZuUf_an3A6jHUXg3L1oCzefzyTYl0QWgJP1WbQCO8J_NPT9GHdGothSf36d0vxzJAjVUvcIB6IoU9nq3XExF$
-
is that forcealign is broken for !power-of-2 sizes. That needs fixing.
New in this series is a re-work of the iomap extent granularity zeroing code. In the earlier series, iomap would consider a larger block zeroing size when a member is set in struct iomap. Now each fs is responsible for setting this size, which is i_blocksize(inode) when we just want regular sub-fs block zeroing. All relevant FSes which use iomap are fixing up for this.
Baseline is following series (which is based on Jens' block-6.10 branch):
https://lore.kernel.org/linux-nvme/[email protected]/T/#mb980c084be402472601831c47fb2b66d0bfa8f0e
Basic xfsprogs support at:
https://github.com/johnpgarry/xfsprogs-dev/tree/forcealign_and_atomicwrites_for_v4_xfs_block_atomic_writes
Patches for this series can be found at:
https://github.com/johnpgarry/linux/commits/atomic-writes-v6.10-v7-fs-v4/
Changes since v3:
https://lore.kernel.org/linux-xfs/[email protected]/T/#m9424b3cd1ccfde795d04474fdb4456520b6b4242
- Only enforce forcealign extsize is power-of-2 for atomic writes
- Re-org some validation code
- Fix xfs_bmap_process_allocated_extent() for forcealign
- Support iomap->io_block_size and make each fs support it
- Add !power-of-2 iomap support for io_block_size
- Make iomap dio iter handle atomic write failure properly by zeroing the remaining io_block_size
Changes since v2:
https://lore.kernel.org/linux-xfs/[email protected]/
- Incorporate forcealign patches from
https://lore.kernel.org/linux-xfs/[email protected]/
- Put bdev awu min and max in buftarg
- Extra forcealign patches to deal with truncate and fallocate punch, insert, collapse
- Add generic_atomic_write_valid_size()
- Change iomap.extent_shift -> .extent_size
Darrick J. Wong (2):
xfs: Introduce FORCEALIGN inode flag
xfs: Enable file data forcealign feature
Dave Chinner (6):
xfs: only allow minlen allocations when near ENOSPC
xfs: always tail align maxlen allocations
xfs: simplify extent allocation alignment
xfs: make EOF allocation simpler
xfs: introduce forced allocation alignment
xfs: align args->minlen for forced allocation alignment
John Garry (14):
fs: Add generic_atomic_write_valid_size()
iomap: Allow filesystems set IO block zeroing size
xfs: Use extent size granularity for iomap->io_block_size
xfs: Do not free EOF blocks for forcealign
xfs: Update xfs_inode_alloc_unitsize_fsb() for forcealign
xfs: Unmap blocks according to forcealign
xfs: Only free full extents for forcealign
xfs: Don't revert allocated offset for forcealign
fs: Add FS_XFLAG_ATOMICWRITES flag
iomap: Atomic write support
xfs: Support FS_XFLAG_ATOMICWRITES for forcealign
xfs: Support atomic write for statx
xfs: Validate atomic writes
xfs: Support setting FMODE_CAN_ATOMIC_WRITE
block/fops.c | 1 + fs/btrfs/inode.c | 1 + fs/erofs/data.c | 1 + fs/erofs/zmap.c | 1 + fs/ext2/inode.c | 1 + fs/ext4/extents.c | 1 + fs/ext4/inode.c | 1 + fs/f2fs/data.c | 1 + fs/fuse/dax.c | 1 + fs/gfs2/bmap.c | 1 + fs/hpfs/file.c | 1 + fs/iomap/direct-io.c | 41 ++++- fs/xfs/libxfs/xfs_alloc.c | 33 ++-- fs/xfs/libxfs/xfs_alloc.h | 3 +- fs/xfs/libxfs/xfs_bmap.c | 308 ++++++++++++++++++---------------- fs/xfs/libxfs/xfs_format.h | 16 +- fs/xfs/libxfs/xfs_ialloc.c | 12 +- fs/xfs/libxfs/xfs_inode_buf.c | 105 ++++++++++++ fs/xfs/libxfs/xfs_inode_buf.h | 5 + fs/xfs/libxfs/xfs_sb.c | 4 + fs/xfs/xfs_bmap_util.c | 14 +- fs/xfs/xfs_buf.c | 15 +- fs/xfs/xfs_buf.h | 4 +- fs/xfs/xfs_buf_mem.c | 2 +- fs/xfs/xfs_file.c | 49 +++++- fs/xfs/xfs_inode.c | 41 ++++- fs/xfs/xfs_inode.h | 29 ++++ fs/xfs/xfs_ioctl.c | 83 ++++++++- fs/xfs/xfs_iomap.c | 7 + fs/xfs/xfs_iops.c | 28 ++++ fs/xfs/xfs_mount.h | 4 + fs/xfs/xfs_reflink.h | 10 -- fs/xfs/xfs_super.c | 8 + fs/xfs/xfs_trace.h | 8 +- fs/zonefs/file.c | 2 + include/linux/fs.h | 12 ++ include/linux/iomap.h | 2 + include/uapi/linux/fs.h | 3 + 38 files changed, 656 insertions(+), 203 deletions(-)
Signature · 1 line
2.31.1
PATCH v4 1/22 fs: Add generic_atomic_write_valid_size()
Add a generic helper for FSes to validate that an atomic write is appropriately sized (along with the other checks).
--- include/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/fs.h +12 -0
@@ -3645,4 +3645,16 @@ bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter) return true; } +static inline +bool generic_atomic_write_valid_size (loff_t pos,struct iov_iter *iter, +unsigned int unit_min,unsigned int unit_max) +{ +size_t len =iov_iter_count (iter); + +if (len < unit_min || len > unit_max) +return false; + +return generic_atomic_write_valid (pos, iter); +} +#endif /* _LINUX_FS_H */
Signature · 1 line
2.31.1
Re: [PATCH v4 01/22] fs: Add generic_atomic_write_valid_size()
Quoted 17 lines · John Garry
Add a generic helper for FSes to validate that an atomic write is appropriately sized (along with the other checks).
Signed-off-by John Garry <[email protected]>--- include/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/fs.h +1
-0@@ -3645,4 +3645,16 @@ bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter)return true; } +static inline
include/linux/fs.h bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter) · line 3658
Quoted 10 lines
include/linux/fs.h +10
-0+bool generic_atomic_write_valid_size (loff_t pos,struct iov_iter *iter, +unsigned int unit_min,unsigned int unit_max) +{ +size_t len =iov_iter_count (iter); + +if (len < unit_min || len > unit_max) +return false; + +return generic_atomic_write_valid (pos, iter); +}
Now that I look back at "fs: Initial atomic write support" I wonder why not pass the iocb and the iov_iter instead of pos and the iov_iter? And can these be collapsed into a single generic_atomic_write_checks() function?
--D
Quoted 6 lines
include/linux/fs.h +1
-0+#endif /* _LINUX_FS_H */ Signature · 1 line
2.31.1
Re: [PATCH v4 01/22] fs: Add generic_atomic_write_valid_size()
Quoted 17 lines · Darrick J. Wong
Quoted 16 lines · John Garry
Add a generic helper for FSes to validate that an atomic write is appropriately sized (along with the other checks).
Signed-off-by John Garry <[email protected]>--- include/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/fs.h +0
-0@@ -3645,4 +3645,16 @@ bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter)return true; }
Quoted 14 lines
include/linux/fs.h bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter) · line 3658
Quoted 11 lines
include/linux/fs.h +11
-0+static inline +bool generic_atomic_write_valid_size (loff_t pos,struct iov_iter *iter, +unsigned int unit_min,unsigned int unit_max) +{ +size_t len =iov_iter_count (iter); + +if (len < unit_min || len > unit_max) +return false; + +return generic_atomic_write_valid (pos, iter); +}Now that I look back at "fs: Initial atomic write support" I wonder why not pass the iocb and the
iov_iterinstead of pos and theiov_iter?
The original user of generic_atomic_write_valid() [blkdev_dio_unaligned() or blkdev_dio_invalid() with the rename] used these same args, so I just went with that.
Quoted 2 lines
And can these be collapsed into a single
generic_atomic_write_checks()function?
bdev file operations would then need to use generic_atomic_write_valid_size(), and there is no unit_min and unit_max size there, apart from bdev awu min and max. And if I checked them, we would be duplicating checks (of awu min and max) in the block layer.
Cheers,
John
Re: [PATCH v4 01/22] fs: Add generic_atomic_write_valid_size()
Quoted 32 lines · John Garry
Quoted 22 lines · Darrick J. Wong
Quoted 21 lines · John Garry
Add a generic helper for FSes to validate that an atomic write is appropriately sized (along with the other checks).
Signed-off-by John Garry <[email protected]>--- include/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/fs.h +6
-0@@ -3645,4 +3645,16 @@ bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter)return true; } +static inline +bool generic_atomic_write_valid_size (loff_t pos,struct iov_iter *iter, +unsigned int unit_min,unsigned int unit_max) +{ +size_t len =iov_iter_count (iter); +Quoted 8 lines
include/linux/fs.h bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter) · line 3658
Quoted 5 lines
include/linux/fs.h +5
-0+if (len < unit_min || len > unit_max) +return false; + +return generic_atomic_write_valid (pos, iter); +}Now that I look back at "fs: Initial atomic write support" I wonder why not pass the iocb and the
iov_iterinstead of pos and theiov_iter?
Quoted 3 lines
The original user of
generic_atomic_write_valid()[blkdev_dio_unaligned()orblkdev_dio_invalid()with the rename] used these same args, so I just went with that.
Don't let the parameter types of static blockdev helpers determine the VFS API that filesystems need to implement untorn writes.
In the block layer enablement patch, this could easily be:
bool generic_atomic_write_valid(const struct kiocb *iocb,
const struct iov_iter *iter)
{
size_t len = iov_iter_count(iter);
if (!iter_is_ubuf(iter))
return false;
if (!is_power_of_2(len))
return false;
if (!IS_ALIGNED(iocb->ki_pos, len))
return false;
return true;
}Then this becomes:
bool generic_atomic_write_valid_size(const struct kiocb *iocb,
const struct iov_iter *iter, unsigned int unit_min, unsigned int unit_max)
{
size_t len = iov_iter_count(iter);
if (len < unit_min || len > unit_max)
return false;
return generic_atomic_write_valid(iocb, iter);
}Yes, that means you have to rearrange the calling conventions of blkdev_dio_invalid a little bit, but the first two arguments match ->read_iter and ->write_iter. Filesystem writers can see that the first two arguments are the first two parameters to foofs_write_iter() and focus on the hard part, which is figuring out unit_{min,max}.
static ssize_t
xfs_file_dio_write(
struct kiocb *iocb,
struct iov_iter *from)
{
...
if ((iocb->ki_flags & IOCB_ATOMIC) && !generic_atomic_write_valid_size(iocb, from, i_blocksize(inode), XFS_FSB_TO_B(mp, ip->i_extsize))) return -EINVAL; }
Quoted 7 lines
Quoted 2 lines
And can these be collapsed into a single
generic_atomic_write_checks()function?bdev file operations would then need to use
generic_atomic_write_valid_size(), and there is nounit_minandunit_maxsize there, apart from bdev awu min and max. And if I checked them, we would be duplicating checks (of awu min and max) in the block layer.
Fair enough, I concede this point.
--D
Quoted 4 lines
Cheers,
John
PATCH v4 2/22 iomap: Allow filesystems set IO block zeroing size
In reply to John GarryAllow filesystems to set the io_block_size for sub-fs block size zeroing, as in future we will want to extend this feature to support zeroing of block sizes of larger than the inode block size.
The value in io_block_size does not have to be a power-of-2, so fix up zeroing code to handle that.
--- block/fops.c | 1 + fs/btrfs/inode.c | 1 + fs/erofs/data.c | 1 + fs/erofs/zmap.c | 1 + fs/ext2/inode.c | 1 + fs/ext4/extents.c | 1 + fs/ext4/inode.c | 1 + fs/f2fs/data.c | 1 + fs/fuse/dax.c | 1 + fs/gfs2/bmap.c | 1 + fs/hpfs/file.c | 1 + fs/iomap/direct-io.c | 23 +++++++++++++++++++---- fs/xfs/xfs_iomap.c | 1 + fs/zonefs/file.c | 2 ++ include/linux/iomap.h | 2 ++ 15 files changed, 35 insertions(+), 4 deletions(-)
block/fops.c +1 -0
@@ -402,6 +402,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->addr = iomap->offset; iomap->length = isize - iomap->offset; iomap->flags |=IOMAP_F_BUFFER_HEAD ;/* noop for !CONFIG_BUFFER_HEAD */ + iomap->io_block_size =i_blocksize (inode);return 0 ; }
fs/btrfs/inode.c +1 -0
@@ -7740,6 +7740,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, iomap->offset = start; iomap->bdev = fs_info->fs_devices->latest_dev->bdev; iomap->length = len; + iomap->io_block_size =i_blocksize (inode);free_extent_map (em);return 0 ;
fs/erofs/data.c +1 -0
@@ -305,6 +305,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,if (flags &IOMAP_DAX ) iomap->addr += mdev.m_dax_part_off; } + iomap->io_block_size =i_blocksize (inode);return 0 ; }
fs/erofs/zmap.c +1 -0
@@ -749,6 +749,7 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,if (iomap->offset >= inode->i_size) iomap->length = length + offset - map.m_la; } + iomap->io_block_size =i_blocksize (inode); iomap->flags =0 ;return 0 ; }
fs/ext2/inode.c +1 -0
@@ -862,6 +862,7 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->length = (u64 )ret << blkbits; iomap->flags |=IOMAP_F_MERGED ; } + iomap->io_block_size =i_blocksize (inode);if (new) iomap->flags |=IOMAP_F_NEW ;
fs/ext4/extents.c +1 -0
@@ -4933,6 +4933,7 @@ static int ext4_iomap_xattr_fiemap(struct inode *inode, struct iomap *iomap) iomap->length = length; iomap->type = iomap_type; iomap->flags =0 ; + iomap->io_block_size =i_blocksize (inode); out:return error; }
fs/ext4/inode.c +1 -0
@@ -3235,6 +3235,7 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, iomap->bdev = inode->i_sb->s_bdev; iomap->offset = (u64 ) map->m_lblk << blkbits; iomap->length = (u64 ) map->m_len << blkbits; + iomap->io_block_size =i_blocksize (inode);if ((map->m_flags &EXT4_MAP_MAPPED ) && !ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))
fs/f2fs/data.c +1 -0
@@ -4233,6 +4233,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, } iomap->addr =IOMAP_NULL_ADDR ; } + iomap->io_block_size =i_blocksize (inode);if (map.m_flags &F2FS_MAP_NEW ) iomap->flags |=IOMAP_F_NEW ;
fs/fuse/dax.c +1 -0
@@ -577,6 +577,7 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t length, iomap->flags =0 ; iomap->bdev =NULL ; iomap->dax_dev = fc->dax->dev; + iomap->io_block_size =i_blocksize (inode);/* * Both read/write and mmap path can race here. So we need something
fs/gfs2/bmap.c +1 -0
@@ -927,6 +927,7 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, out: iomap->bdev = inode->i_sb->s_bdev; + iomap->io_block_size =i_blocksize (inode); unlock:up_read (&ip->i_rw_mutex);return ret;
fs/hpfs/file.c +1 -0
@@ -149,6 +149,7 @@ static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->addr =IOMAP_NULL_ADDR ; iomap->length =1 << blkbits; } + iomap->io_block_size =i_blocksize (inode);hpfs_unlock (sb);return 0 ;
fs/iomap/direct-io.c +19 -4
@@ -277,7 +277,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, {const struct iomap *iomap = &iter->iomap;struct inode *inode = iter->inode; -unsigned int fs_block_size =i_blocksize (inode), pad; +u64 io_block_size = iomap->io_block_size;loff_t length =iomap_length (iter);loff_t pos = iter->pos;blk_opf_t bio_opf;
@@ -287,6 +287,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,int nr_pages, ret =0 ;size_t copied =0 ;size_t orig_count; +unsigned int pad;if ((pos | length) & (bdev_logical_block_size (iomap->bdev) -1 ) || !bdev_iter_is_aligned (iomap->bdev, dio->submit.iter))
@@ -355,7 +356,14 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout) {/* zero out from the start of the block to the write offset */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + } +if (pad)iomap_dio_zero (iter, dio, pos - pad, pad); }
@@ -429,9 +437,16 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout || ((dio->flags &IOMAP_DIO_WRITE ) && pos >=i_size_read (inode))) {/* zero out from the end of the write to the end of the block */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + } +if (pad) -iomap_dio_zero (iter, dio, pos, fs_block_size - pad); +iomap_dio_zero (iter, dio, pos, io_block_size - pad); } out:/* Undo iter limitation to current extent */
fs/xfs/xfs_iomap.c +1 -0
@@ -127,6 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); + iomap->io_block_size =i_blocksize (VFS_I (ip));if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else
fs/zonefs/file.c +2 -0
@@ -50,6 +50,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, iomap->addr = (z->z_sector <<SECTOR_SHIFT ) + iomap->offset; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);
@@ -99,6 +100,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, iomap->type =IOMAP_MAPPED ; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);
include/linux/iomap.h +2 -0
@@ -103,6 +103,8 @@ struct iomap {void *private;/* filesystem private */ const struct iomap_folio_ops *folio_ops;u64 validity_cookie;/* used with .iomap_valid() */ +/* io block zeroing size, not necessarily a power-of-2 */ +u64 io_block_size; };static inline sector_t iomap_sector (const struct iomap *iomap,loff_t pos)
Signature · 1 line
2.31.1
Re: [PATCH v4 02/22] iomap: Allow filesystems set IO block zeroing size
Quoted 31 lines · John Garry
Allow filesystems to set the
io_block_sizefor sub-fs block size zeroing, as in future we will want to extend this feature to support zeroing of block sizes of larger than the inode block size.The value in
io_block_sizedoes not have to be a power-of-2, so fix up zeroing code to handle that.Signed-off-by John Garry <[email protected]>--- block/fops.c | 1 + fs/btrfs/inode.c | 1 + fs/erofs/data.c | 1 + fs/erofs/zmap.c | 1 + fs/ext2/inode.c | 1 + fs/ext4/extents.c | 1 + fs/ext4/inode.c | 1 + fs/f2fs/data.c | 1 + fs/fuse/dax.c | 1 + fs/gfs2/bmap.c | 1 + fs/hpfs/file.c | 1 + fs/iomap/direct-io.c | 23 +++++++++++++++++++---- fs/xfs/xfs_iomap.c | 1 + fs/zonefs/file.c | 2 ++ include/linux/iomap.h | 2 ++ 15 files changed, 35 insertions(+), 4 deletions(-)block/fops.c +0
-0
block/fops.c static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 408
Quoted 7 lines
block/fops.c +1
-0@@ -402,6 +402,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->addr = iomap->offset; iomap->length = isize - iomap->offset; iomap->flags |=IOMAP_F_BUFFER_HEAD ;/* noop for !CONFIG_BUFFER_HEAD */ + iomap->io_block_size =i_blocksize (inode);return 0 ; }
<snip a bunch of filesystems setting io_block_size to i_blocksize>
fs/hpfs/file.c static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 152
Quoted 9 lines
fs/hpfs/file.c +1
-0@@ -149,6 +149,7 @@ static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->addr =IOMAP_NULL_ADDR ; iomap->length =1 << blkbits; } + iomap->io_block_size =i_blocksize (inode);
HPFS does iomap now? Yikes.
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 280
Quoted 13 lines
fs/hpfs/file.c +0
-0hpfs_unlock (sb);return 0 ;fs/iomap/direct-io.c +1
-1@@ -277,7 +277,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, {const struct iomap *iomap = &iter->iomap;struct inode *inode = iter->inode; -unsigned int fs_block_size =i_blocksize (inode), pad; +u64 io_block_size = iomap->io_block_size;
I wonder, should iomap be nice and not require filesystems to set io_block_size themselves unless they really need it? Anyone working on an iomap port while this patchset is in progress may or may not remember to add this bit if they get their port merged after atomicwrites is merged; and you might not remember to prevent the bitrot if the reverse order happens.
u64 io_block_size = iomap->io_block_size ?: i_blocksize(inode);
Quoted 13 lines
fs/iomap/direct-io.c +1
-0loff_t length =iomap_length (iter);loff_t pos = iter->pos;blk_opf_t bio_opf;@@ -287,6 +287,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,int nr_pages, ret =0 ;size_t copied =0 ;size_t orig_count; +unsigned int pad;if ((pos | length) & (bdev_logical_block_size (iomap->bdev) -1 ) || !bdev_iter_is_aligned (iomap->bdev, dio->submit.iter))@@ -355,7 +356,14 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 365
Quoted 10 lines
fs/iomap/direct-io.c +7
-1if (need_zeroout) {/* zero out from the start of the block to the write offset */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + }
Please don't opencode this twice.
static unsigned int offset_in_block(loff_t pos, u64 blocksize)
{
if (likely(is_power_of_2(blocksize)))
return pos & (blocksize - 1);
return do_div(pos, blocksize);
}pad = offset_in_block(pos, io_block_size); if (pad) ...
Also, what happens if pos-pad points to a byte before the mapping?
Quoted 10 lines
fs/iomap/direct-io.c +2
-1+if (pad)iomap_dio_zero (iter, dio, pos - pad, pad); }@@ -429,9 +437,16 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout || ((dio->flags &IOMAP_DIO_WRITE ) && pos >=i_size_read (inode))) {/* zero out from the end of the write to the end of the block */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) {
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 449
Quoted 10 lines
fs/iomap/direct-io.c +8
-1+ pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + } +if (pad) -iomap_dio_zero (iter, dio, pos, fs_block_size - pad); +iomap_dio_zero (iter, dio, pos, io_block_size - pad);
What if pos + io_block_size - pad points to a byte after the end of the mapping?
Quoted 40 lines
fs/iomap/direct-io.c +0
-0} out:/* Undo iter limitation to current extent */ fs/xfs/xfs_iomap.c +1
-0@@ -127,6 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); + iomap->io_block_size =i_blocksize (VFS_I (ip));if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else fs/zonefs/file.c +2
-0@@ -50,6 +50,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, iomap->addr = (z->z_sector <<SECTOR_SHIFT ) + iomap->offset; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);@@ -99,6 +100,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, iomap->type =IOMAP_MAPPED ; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);include/linux/iomap.h +0
-0
include/linux/iomap.h struct iomap { · line 106
Quoted 4 lines
include/linux/iomap.h +1
-0@@ -103,6 +103,8 @@ struct iomap {void *private;/* filesystem private */ const struct iomap_folio_ops *folio_ops;u64 validity_cookie;/* used with .iomap_valid() */ +/* io block zeroing size, not necessarily a power-of-2 */
size in bytes?
I'm not sure what "io block zeroing" means. What are you trying to accomplish here? Let's say the fsblock size is 4k and the allocation unit (aka the atomic write size) is 16k. Userspace wants a direct write to file offset 8192-12287, and that space is unwritten:
uuuu
^
Currently we'd just write the 4k and run the io completion handler, so the final state is:
uuWu
Instead, if the fs sets io_block_size to 16384, does this direct write now amplify into a full 16k write? With the end result being:
ZZWZ
only.... I don't see the unwritten areas being converted to written? I guess for an atomic write you'd require the user to write 0-16383?
<still confused about why we need to do this, maybe i'll figure it out as I go along>
--D
Quoted 8 lines
include/linux/iomap.h +1
-0+u64 io_block_size; };static inline sector_t iomap_sector (const struct iomap *iomap,loff_t pos)Signature · 1 line
2.31.1
Re: [PATCH v4 02/22] iomap: Allow filesystems set IO block zeroing size
Quoted 4 lines · Darrick J. Wong
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 280
Quoted 2 lines
unsigned int
fs_block_size=i_blocksize(inode), pad;fs/iomap/direct-io.c +1
-0+u64 io_block_size = iomap->io_block_size;I wonder, should iomap be nice and not require filesystems to set
io_block_sizethemselves unless they really need it?
That's what I had in v3, like:
if (iomap->io_block_size)
io_block_size = iomap->io_block_size;
else
io_block_size = i_block_size(inode)
but it was suggested to change that (to like what I have here).
Quoted 5 lines
Anyone working on
an iomap port while this patchset is in progress may or may not remember to add this bit if they get their port merged after atomicwrites is merged; and you might not remember to prevent the bitrot if the reverse order happens.
Sure, I get your point.
However, OTOH, if we check xfs_bmbt_to_iomap(), it does set all or close to all members of struct iomap, so we are just continuing that trend, i.e. it is the job of the FS callback to set all these members.
Quoted 28 lines
u64 io_block_size = iomap->io_block_size ?: i_blocksize(inode);Quoted 13 lines
loff_t length = iomap_length(iter); loff_t pos = iter->pos; blk_opf_t bio_opf;fs/iomap/direct-io.c +1
-0@@ -287,6 +287,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,int nr_pages, ret =0 ;size_t copied =0 ;size_t orig_count; +unsigned int pad;if ((pos | length) & (bdev_logical_block_size (iomap->bdev) -1 ) || !bdev_iter_is_aligned (iomap->bdev, dio->submit.iter))@@ -355,7 +356,14 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 365
Quoted 10 lines
fs/iomap/direct-io.c +7
-1if (need_zeroout) {/* zero out from the start of the block to the write offset */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + }Please don't opencode this twice.
Quoted 6 lines
static unsigned int
offset_in_block(loff_t pos, u64 blocksize){ if (likely(is_power_of_2(blocksize))) return pos & (blocksize - 1); return do_div(pos, blocksize); }
ok, fine
Quoted 6 lines
pad = offset_in_block(pos, io_block_size); if (pad) ...Also, what happens if pos-pad points to a byte before the mapping?
It's the job of the FS to map in something aligned to io_block_size. Having said that, I don't think we are doing that for XFS (which sets io_block_size > i_block_size(inode)), so I need to check that.
Quoted 15 lines
Quoted 15 lines
fs/iomap/direct-io.c +6
-1+if (pad)iomap_dio_zero (iter, dio, pos - pad, pad); }@@ -429,9 +437,16 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout || ((dio->flags &IOMAP_DIO_WRITE ) && pos >=i_size_read (inode))) {/* zero out from the end of the write to the end of the block */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; +
Quoted 8 lines
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 449
Quoted 6 lines
fs/iomap/direct-io.c +4
-1+ pad =do_div (_pos, io_block_size); + } +if (pad) -iomap_dio_zero (iter, dio, pos, fs_block_size - pad); +iomap_dio_zero (iter, dio, pos, io_block_size - pad);What if pos +
io_block_size- pad points to a byte after the end of the mapping?
as above, we expect this to be mapped in (so ok to zero)
Quoted 47 lines
Quoted 41 lines
fs/iomap/direct-io.c +0
-0} out:/* Undo iter limitation to current extent */ fs/xfs/xfs_iomap.c +1
-0@@ -127,6 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); + iomap->io_block_size =i_blocksize (VFS_I (ip));if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else fs/zonefs/file.c +2
-0@@ -50,6 +50,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, iomap->addr = (z->z_sector <<SECTOR_SHIFT ) + iomap->offset; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);@@ -99,6 +100,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, iomap->type =IOMAP_MAPPED ; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);include/linux/iomap.h +0
-0include/linux/iomap.h struct iomap { · line 106
Quoted 4 lines
include/linux/iomap.h +1
-0@@ -103,6 +103,8 @@ struct iomap {void *private;/* filesystem private */ const struct iomap_folio_ops *folio_ops;u64 validity_cookie;/* used with .iomap_valid() */ +/* io block zeroing size, not necessarily a power-of-2 */ size in bytes?
Quoted 1 line
I'm not sure what "io block zeroing" means.
Naming is hard. Essentally we are trying to reuse the sub-fs block zeroing code for sub-extent granule writes. More below.
Quoted 3 lines
What are you trying to
accomplish here? Let's say the fsblock size is 4k and the allocation unit (aka the atomic write size) is 16k.
ok, so I say here that the extent granule is 16k
Quoted 6 lines
Userspace wants a direct write
to file offset 8192-12287, and that space is unwritten:uuuu
^
Quoted 7 lines
Currently we'd just write the 4k and run the io completion handler, so the final state is:
uuWu
Instead, if the fs sets
io_block_sizeto 16384, does this direct write now amplify into a full 16k write?
Yes, but only when the extent is newly allocated and we require zeroing.
Quoted 2 lines
With the end result being:
ZZWZ
Yes
Quoted 2 lines
only.... I don't see the unwritten areas being converted to written?
See xfs_iomap_write_unwritten() change in the next patch
Quoted 1 line
I guess for an atomic write you'd require the user to write 0-16383?
Not exactly
Quoted 3 lines
<still confused about why we need to do this, maybe i'll figure it out as I go along>
This zeroing is just really required for atomic writes. The purpose is to zero the extent granule for any write within a newly allocated granule.
Consider we have uuWu, above. If the user then attempts to write the full 16K as an atomic write, the iomap iter code would generate writes for sizes 8k, 4k, and 4k, i.e. not a single 16K write. This is not acceptable. So the idea is to zero the full extent granule when allocated, so we have ZZWZ after the 4k write at offset 8192, above. As such, if we then attempt this 16K atomic write, we get a single 16K BIO, i.e. there is no unwritten extent conversion.
I am not sure if we should be doing this only for atomic writes inodes, or also forcealign only or RT.
Thanks,
John
Re: [PATCH v4 02/22] iomap: Allow filesystems set IO block zeroing size
Quoted 6 lines · John Garry
Quoted 4 lines · Darrick J. Wong
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 280
Quoted 2 lines
unsigned int
fs_block_size=i_blocksize(inode), pad;fs/iomap/direct-io.c +1
-0+u64 io_block_size = iomap->io_block_size;I wonder, should iomap be nice and not require filesystems to set
io_block_sizethemselves unless they really need it?
Quoted 8 lines
That's what I had in v3, like:
if (
iomap->io_block_size)io_block_size = iomap->io_block_size;else
io_block_size=i_block_size(inode)but it was suggested to change that (to like what I have here).
oh, ok. Ignore that comment, then. :)
Quoted 48 lines
Quoted 5 lines
Anyone working on
an iomap port while this patchset is in progress may or may not remember to add this bit if they get their port merged after atomicwrites is merged; and you might not remember to prevent the bitrot if the reverse order happens.Sure, I get your point.
However, OTOH, if we check
xfs_bmbt_to_iomap(), it does set all or close to all members of struct iomap, so we are just continuing that trend, i.e. it is the job of the FS callback to set all these members.Quoted 26 lines
u64 io_block_size = iomap->io_block_size ?: i_blocksize(inode);Quoted 11 lines
loff_t length = iomap_length(iter); loff_t pos = iter->pos; blk_opf_t bio_opf;fs/iomap/direct-io.c +1
-0@@ -287,6 +287,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,int nr_pages, ret =0 ;size_t copied =0 ;size_t orig_count; +unsigned int pad;if ((pos | length) & (bdev_logical_block_size (iomap->bdev) -1 ) || !bdev_iter_is_aligned (iomap->bdev, dio->submit.iter))fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 364
Quoted 10 lines
fs/iomap/direct-io.c +7
-1@@ -355,7 +356,14 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout) {/* zero out from the start of the block to the write offset */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + }Please don't opencode this twice.
Quoted 6 lines
static unsigned int
offset_in_block(loff_t pos, u64 blocksize){ if (likely(is_power_of_2(blocksize))) return pos & (blocksize - 1); return do_div(pos, blocksize); }ok, fine
Quoted 1 line
Quoted 9 lines
Quoted 5 lines
pad = offset_in_block(pos, io_block_size); if (pad) ...Also, what happens if pos-pad points to a byte before the mapping?
It's the job of the FS to map in something aligned to
io_block_size. Having said that, I don't think we are doing that for XFS (which setsio_block_sizeQuoted 1 line
i_block_size(inode)), so I need to check that.
<nod> You can only play with the mapping that the fs gave you. If xfs doesn't give you a big enough mapping, then that's a programming bug to WARN_ON_ONCE about and return EIO.
I hadn't realized that the ->iomap_begin function is required to provide mappings that are aligned to io_block_size.
Quoted 72 lines
Quoted 16 lines
Quoted 16 lines
fs/iomap/direct-io.c +6
-1+if (pad)iomap_dio_zero (iter, dio, pos - pad, pad); }@@ -429,9 +437,16 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout || ((dio->flags &IOMAP_DIO_WRITE ) && pos >=i_size_read (inode))) {/* zero out from the end of the write to the end of the block */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; +Quoted 8 lines
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 449
Quoted 6 lines
fs/iomap/direct-io.c +4
-1+ pad =do_div (_pos, io_block_size); + } +if (pad) -iomap_dio_zero (iter, dio, pos, fs_block_size - pad); +iomap_dio_zero (iter, dio, pos, io_block_size - pad);What if pos +
io_block_size- pad points to a byte after the end of the mapping?as above, we expect this to be mapped in (so ok to zero)
Quoted 45 lines
Quoted 39 lines
fs/iomap/direct-io.c +0
-0} out:/* Undo iter limitation to current extent */ fs/xfs/xfs_iomap.c +1
-0@@ -127,6 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); + iomap->io_block_size =i_blocksize (VFS_I (ip));if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else fs/zonefs/file.c +2
-0@@ -50,6 +50,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, iomap->addr = (z->z_sector <<SECTOR_SHIFT ) + iomap->offset; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);@@ -99,6 +100,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, iomap->type =IOMAP_MAPPED ; iomap->length = isize - iomap->offset; } + iomap->io_block_size =i_blocksize (inode);mutex_unlock (&zi->i_truncate_mutex);trace_zonefs_iomap_begin (inode, iomap);include/linux/iomap.h +0
-0include/linux/iomap.h struct iomap { · line 106
Quoted 4 lines
include/linux/iomap.h +1
-0@@ -103,6 +103,8 @@ struct iomap {void *private;/* filesystem private */ const struct iomap_folio_ops *folio_ops;u64 validity_cookie;/* used with .iomap_valid() */ +/* io block zeroing size, not necessarily a power-of-2 */ size in bytes?
Quoted 4 lines
Quoted 1 line
I'm not sure what "io block zeroing" means.
Naming is hard. Essentally we are trying to reuse the sub-fs block zeroing code for sub-extent granule writes. More below.
Yeah. For sub-fsblock zeroing we issue (chained) bios to write zeroes to the sectors surrounding the part we're actually writing, then we're issuing the write itself, and finally the ioend converts the mapping to unwritten.
For untorn writes we're doing the same thing, but now on the level of multiple fsblocks. I guess this is all going to support a
<nod> "IO granularity" ? For untorn writes I guess you want mappings that are aligned to a supported untorn write granularity; for bs > ps filesystems I guess the IO granularity is
Quoted 43 lines
Quoted 3 lines
What are you trying to
accomplish here? Let's say the fsblock size is 4k and the allocation unit (aka the atomic write size) is 16k.ok, so I say here that the extent granule is 16k
Quoted 6 lines
Userspace wants a direct write
to file offset 8192-12287, and that space is unwritten:uuuu
^Quoted 7 lines
Currently we'd just write the 4k and run the io completion handler, so the final state is:
uuWu
Instead, if the fs sets
io_block_sizeto 16384, does this direct write now amplify into a full 16k write?Yes, but only when the extent is newly allocated and we require zeroing.
Quoted 2 lines
With the end result being:
ZZWZYes
Quoted 2 lines
only.... I don't see the unwritten areas being converted to written?
See
xfs_iomap_write_unwritten()change in the next patchQuoted 1 line
I guess for an atomic write you'd require the user to write 0-16383?
Not exactly
Quoted 3 lines
<still confused about why we need to do this, maybe i'll figure it out as I go along>
This zeroing is just really required for atomic writes. The purpose is to zero the extent granule for any write within a newly allocated granule.
Quoted 7 lines
Consider we have uuWu, above. If the user then attempts to write the full 16K as an atomic write, the iomap iter code would generate writes for sizes 8k, 4k, and 4k, i.e. not a single 16K write. This is not acceptable. So the idea is to zero the full extent granule when allocated, so we have ZZWZ after the 4k write at offset 8192, above. As such, if we then attempt this 16K atomic write, we get a single 16K BIO, i.e. there is no unwritten extent conversion.
Wait, are we issuing zeroing writes for 0-8191 and 12288-16383, then issuing a single atomic write for 0-16383? That won't work, because all the bios attached to an iomap_dio are submitted and execute asynchronously. I think you need ->iomap_begin to do XFS_BMAPI_ZERO allocations if the writes aren't aligned to the minimum untorn write granularity.
Quoted 2 lines
I am not sure if we should be doing this only for atomic writes inodes, or also forcealign only or RT.
I think it only applies to untorn writes because the default behavior everywhere is is that writes can tear.
--D
Quoted 5 lines
Thanks,
John
Re: [PATCH v4 02/22] iomap: Allow filesystems set IO block zeroing size
Quoted 9 lines · Darrick J. Wong
Quoted 8 lines · John Garry
Quoted 4 lines · Darrick J. Wong
fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 280
Quoted 2 lines
unsigned int
fs_block_size=i_blocksize(inode), pad;fs/iomap/direct-io.c +1
-0+u64 io_block_size = iomap->io_block_size;I wonder, should iomap be nice and not require filesystems to set
io_block_sizethemselves unless they really need it?That's what I had in v3, like:
Quoted 9 lines
Quoted 6 lines
if (
iomap->io_block_size)io_block_size = iomap->io_block_size;else
io_block_size=i_block_size(inode)but it was suggested to change that (to like what I have here).
oh, ok. Ignore that comment, then. :)
To be clear, Dave actually suggested that change.
Quoted 54 lines
Quoted 54 lines
Quoted 5 lines
Anyone working on
an iomap port while this patchset is in progress may or may not remember to add this bit if they get their port merged after atomicwrites is merged; and you might not remember to prevent the bitrot if the reverse order happens.Sure, I get your point.
However, OTOH, if we check
xfs_bmbt_to_iomap(), it does set all or close to all members of struct iomap, so we are just continuing that trend, i.e. it is the job of the FS callback to set all these members.Quoted 26 lines
u64 io_block_size = iomap->io_block_size ?: i_blocksize(inode);Quoted 11 lines
loff_t length = iomap_length(iter); loff_t pos = iter->pos; blk_opf_t bio_opf;fs/iomap/direct-io.c +1
-0@@ -287,6 +287,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,int nr_pages, ret =0 ;size_t copied =0 ;size_t orig_count; +unsigned int pad;if ((pos | length) & (bdev_logical_block_size (iomap->bdev) -1 ) || !bdev_iter_is_aligned (iomap->bdev, dio->submit.iter))fs/iomap/direct-io.c static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, · line 364
Quoted 10 lines
fs/iomap/direct-io.c +7
-1@@ -355,7 +356,14 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,if (need_zeroout) {/* zero out from the start of the block to the write offset */ - pad = pos & (fs_block_size -1 ); +if (is_power_of_2 (io_block_size)) { + pad = pos & (io_block_size -1 ); + }else { +loff_t _pos = pos; + + pad =do_div (_pos, io_block_size); + }Please don't opencode this twice.
Quoted 6 lines
static unsigned int
offset_in_block(loff_t pos, u64 blocksize){ if (likely(is_power_of_2(blocksize))) return pos & (blocksize - 1); return do_div(pos, blocksize); }ok, fine
Quoted 6 lines
pad = offset_in_block(pos, io_block_size); if (pad) ...Also, what happens if pos-pad points to a byte before the mapping?
Quoted 7 lines
Quoted 3 lines
It's the job of the FS to map in something aligned to
io_block_size. Having said that, I don't think we are doing that for XFS (which setsio_block_sizeQuoted 1 line
i_block_size(inode)), so I need to check that.<nod> You can only play with the mapping that the fs gave you. If xfs doesn't give you a big enough mapping, then that's a programming bug to
WARN_ON_ONCEabout and return EIO.
I think that this is pretty easy to solve by just ensuring that for an atomic write inode, the call xfs_direct_write_iomap_being() -> xfs_bmapi_read(bno, len) is such that bno and len are extent size aligned.
Quoted 9 lines
Quoted 3 lines
Naming is hard. Essentally we are trying to reuse the sub-fs block zeroing code for sub-extent granule writes. More below.
Yeah. For sub-fsblock zeroing we issue (chained) bios to write zeroes to the sectors surrounding the part we're actually writing, then we're issuing the write itself, and finally the ioend converts the mapping to unwritten.
Quoted 7 lines
For untorn writes we're doing the same thing, but now on the level of multiple fsblocks. I guess this is all going to support a
<nod> "IO granularity" ? For untorn writes I guess you want mappings that are aligned to a supported untorn write granularity; for bs > ps filesystems I guess the IO granularity is
For LBS, it's still going to be inode block size.
Quoted 15 lines
Quoted 7 lines
Quoted 3 lines
<still confused about why we need to do this, maybe i'll figure it out as I go along>
This zeroing is just really required for atomic writes. The purpose is to zero the extent granule for any write within a newly allocated granule.
Quoted 7 lines
Consider we have uuWu, above. If the user then attempts to write the full 16K as an atomic write, the iomap iter code would generate writes for sizes 8k, 4k, and 4k, i.e. not a single 16K write. This is not acceptable. So the idea is to zero the full extent granule when allocated, so we have ZZWZ after the 4k write at offset 8192, above. As such, if we then attempt this 16K atomic write, we get a single 16K BIO, i.e. there is no unwritten extent conversion.
Quoted 2 lines
Wait, are we issuing zeroing writes for 0-8191 and 12288-16383, then issuing a single atomic write for 0-16383?
When we have uuuu and attempt the first 4k write @ offset 4k, we also issue zeroes for 0-8191 and 12288-16383.
But this is done synchronously. We are leveraging the existing code to issue the write with the exclusive IOLOCK in xfs_file_dio_write_unaligned(), so no one else can access that data while we do that initial write+zeroing to the extent.
Quoted 6 lines
That won't work, because all
the bios attached to aniomap_dioare submitted and execute asynchronously. I think you need ->iomap_begin to doXFS_BMAPI_ZEROallocations if the writes aren't aligned to the minimum untorn write granularity.
Quoted 6 lines
Quoted 2 lines
I am not sure if we should be doing this only for atomic writes inodes, or also forcealign only or RT.
I think it only applies to untorn writes because the default behavior everywhere is is that writes can tear.
ok, fine.
Thanks,
John
PATCH v4 3/22 xfs: Use extent size granularity for iomap->io_block_size
In reply to John GarryCurrently iomap->io_block_size is set to the i_blocksize() value for the inode.
Expand the sub-fs block size zeroing to now cover RT extents, by calling setting iomap->io_block_size as xfs_inode_alloc_unitsize().
In xfs_iomap_write_unwritten(), update the unwritten range fsb to cover this extent granularity.
In xfs_file_dio_write(), handle a write which is not aligned to extent size granularity as unaligned. Since the extent size granularity need not be a power-of-2, handle this also.
--- fs/xfs/xfs_file.c | 24 +++++++++++++++++++----- fs/xfs/xfs_inode.c | 17 +++++++++++------ fs/xfs/xfs_inode.h | 1 + fs/xfs/xfs_iomap.c | 8 +++++++- 4 files changed, 38 insertions(+), 12 deletions(-)
fs/xfs/xfs_file.c +19 -5
@@ -601,7 +601,7 @@ xfs_file_dio_write_aligned( }/* -* Handle block unaligned direct I/O writes +* Handle unaligned direct IO writes. * * In most cases direct I/O writes will be done holding IOLOCK_SHARED, allowing * them to be done in parallel with reads and other direct I/O writes. However,
@@ -630,9 +630,9 @@ xfs_file_dio_write_unaligned(ssize_t ret;/* -* Extending writes need exclusivity because of the sub-block zeroing -* that the DIO code always does for partial tail blocks beyond EOF, so -* don't even bother trying the fast path in this case. +* Extending writes need exclusivity because of the sub-block/extent +* zeroing that the DIO code always does for partial tail blocks +* beyond EOF, so don't even bother trying the fast path in this case. */ if (iocb->ki_pos > isize || iocb->ki_pos + count >= isize) {if (iocb->ki_flags &IOCB_NOWAIT )
@@ -698,11 +698,25 @@ xfs_file_dio_write(struct xfs_inode *ip =XFS_I (file_inode (iocb->ki_filp));struct xfs_buftarg *target =xfs_inode_buftarg (ip);size_t count =iov_iter_count (from); +bool unaligned; +u64 unitsize;/* direct I/O must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)return -EINVAL ; -if ((iocb->ki_pos | count) & ip->i_mount->m_blockmask) + + unitsize =xfs_inode_alloc_unitsize (ip); +if (!is_power_of_2 (unitsize)) { +if (isaligned_64 (iocb->ki_pos, unitsize) && +isaligned_64 (count, unitsize)) + unaligned = false; +else + unaligned = true; + }else { + unaligned = (iocb->ki_pos | count) & (unitsize -1 ); + } + +if (unaligned)return xfs_file_dio_write_unaligned (ip, iocb, from);return xfs_file_dio_write_aligned (ip, iocb, from); }
fs/xfs/xfs_inode.c +11 -6
@@ -4264,15 +4264,20 @@ xfs_break_layouts(return error; } -/* Returns the size of fundamental allocation unit for a file, in bytes. */ unsigned int -xfs_inode_alloc_unitsize ( +xfs_inode_alloc_unitsize_fsb (struct xfs_inode *ip) { -unsigned int blocks =1 ; -if (XFS_IS_REALTIME_INODE (ip)) - blocks = ip->i_mount->m_sb.sb_rextsize; +return ip->i_mount->m_sb.sb_rextsize; + +return 1 ; +} -return XFS_FSB_TO_B (ip->i_mount, blocks); +/* Returns the size of fundamental allocation unit for a file, in bytes. */ +unsigned int +xfs_inode_alloc_unitsize ( +struct xfs_inode *ip) +{ +return XFS_FSB_TO_B (ip->i_mount,xfs_inode_alloc_unitsize_fsb (ip)); }
fs/xfs/xfs_inode.h +1 -0
@@ -643,6 +643,7 @@ int xfs_inode_reload_unlinked(struct xfs_inode *ip);bool xfs_ifork_zapped (const struct xfs_inode *ip,int whichfork);void xfs_inode_count_blocks (struct xfs_trans *tp,struct xfs_inode *ip,xfs_filblks_t *dblocks,xfs_filblks_t *rblocks); +unsigned int xfs_inode_alloc_unitsize_fsb (struct xfs_inode *ip);unsigned int xfs_inode_alloc_unitsize (struct xfs_inode *ip);struct xfs_dir_update_params {
fs/xfs/xfs_iomap.c +7 -1
@@ -127,7 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); - iomap->io_block_size =i_blocksize (VFS_I (ip)); + iomap->io_block_size =xfs_inode_alloc_unitsize (ip);if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else
@@ -577,11 +577,17 @@ xfs_iomap_write_unwritten(xfs_fsize_t i_size;uint resblks;int error; +unsigned int rounding;trace_xfs_unwritten_convert (ip, offset, count); offset_fsb =XFS_B_TO_FSBT (mp, offset); count_fsb =XFS_B_TO_FSB (mp, (xfs_ufsize_t )offset + count); + rounding =xfs_inode_alloc_unitsize_fsb (ip); +if (rounding >1 ) { + offset_fsb =rounddown_64 (offset_fsb, rounding); + count_fsb =roundup_64 (count_fsb, rounding); + } count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);/*
Signature · 1 line
2.31.1
Re: [PATCH v4 03/22] xfs: Use extent size granularity for iomap->io_block_size
Quoted 35 lines · John Garry
Currently
iomap->io_block_sizeis set to thei_blocksize()value for the inode.Expand the sub-fs block size zeroing to now cover RT extents, by calling setting
iomap->io_block_sizeasxfs_inode_alloc_unitsize().In
xfs_iomap_write_unwritten(), update the unwritten range fsb to cover this extent granularity.In
xfs_file_dio_write(), handle a write which is not aligned to extent size granularity as unaligned. Since the extent size granularity need not be a power-of-2, handle this also.Signed-off-by John Garry <[email protected]>--- fs/xfs/xfs_file.c | 24 +++++++++++++++++++----- fs/xfs/xfs_inode.c | 17 +++++++++++------ fs/xfs/xfs_inode.h | 1 + fs/xfs/xfs_iomap.c | 8 +++++++- 4 files changed, 38 insertions(+), 12 deletions(-)fs/xfs/xfs_file.c +1
-1@@ -601,7 +601,7 @@ xfs_file_dio_write_aligned( }/* -* Handle block unaligned direct I/O writes +* Handle unaligned direct IO writes. * * In most cases direct I/O writes will be done holding IOLOCK_SHARED, allowing * them to be done in parallel with reads and other direct I/O writes. However,
fs/xfs/xfs_file.c xfs_file_dio_write_unaligned( · line 635
Quoted 9 lines
fs/xfs/xfs_file.c +3
-3@@ -630,9 +630,9 @@ xfs_file_dio_write_unaligned(ssize_t ret;/* -* Extending writes need exclusivity because of the sub-block zeroing -* that the DIO code always does for partial tail blocks beyond EOF, so -* don't even bother trying the fast path in this case. +* Extending writes need exclusivity because of the sub-block/extent +* zeroing that the DIO code always does for partial tail blocks +* beyond EOF, so don't even bother trying the fast path in this case.
Hummm. So let's say the fsblock size is 4k, the rt extent size is 16k, and you want to write bytes 8192-12287 of a file. Currently we'd use xfs_file_dio_write_aligned for that, but now we'd use xfs_file_dio_write_unaligned? Even though we don't need zeroing or any of that stuff?
Quoted 15 lines
fs/xfs/xfs_file.c +3
-1*/ if (iocb->ki_pos > isize || iocb->ki_pos + count >= isize) {if (iocb->ki_flags &IOCB_NOWAIT )@@ -698,11 +698,25 @@ xfs_file_dio_write(struct xfs_inode *ip =XFS_I (file_inode (iocb->ki_filp));struct xfs_buftarg *target =xfs_inode_buftarg (ip);size_t count =iov_iter_count (from); +bool unaligned; +u64 unitsize;/* direct I/O must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)return -EINVAL ; -if ((iocb->ki_pos | count) & ip->i_mount->m_blockmask) +
fs/xfs/xfs_file.c xfs_file_dio_write( · line 717
Quoted 10 lines
fs/xfs/xfs_file.c +10
-0+ unitsize =xfs_inode_alloc_unitsize (ip); +if (!is_power_of_2 (unitsize)) { +if (isaligned_64 (iocb->ki_pos, unitsize) && +isaligned_64 (count, unitsize)) + unaligned = false; +else + unaligned = true; + }else { + unaligned = (iocb->ki_pos | count) & (unitsize -1 ); + }
Didn't I already write this?
fs/xfs/xfs_file.c xfs_file_dio_write( · line 719
Quoted 1 line
fs/xfs/xfs_file.c +1
-0+if (unaligned)
if (!xfs_is_falloc_aligned(ip, iocb->ki_pos, count))
fs/xfs/xfs_inode.c xfs_break_layouts( · line 4267
Quoted 12 lines
fs/xfs/xfs_file.c +0
-0return xfs_file_dio_write_unaligned (ip, iocb, from);return xfs_file_dio_write_aligned (ip, iocb, from); }fs/xfs/xfs_inode.c +0
-1@@ -4264,15 +4264,20 @@ xfs_break_layouts(return error; } -/* Returns the size of fundamental allocation unit for a file, in bytes. */
Don't delete the comment, it has useful return type information.
/*
* Returns the size of fundamental allocation unit for a file, in
* fsblocks.
*/
Quoted 39 lines
fs/xfs/xfs_inode.c +11
-5unsigned int -xfs_inode_alloc_unitsize ( +xfs_inode_alloc_unitsize_fsb (struct xfs_inode *ip) { -unsigned int blocks =1 ; -if (XFS_IS_REALTIME_INODE (ip)) - blocks = ip->i_mount->m_sb.sb_rextsize; +return ip->i_mount->m_sb.sb_rextsize; + +return 1 ; +} -return XFS_FSB_TO_B (ip->i_mount, blocks); +/* Returns the size of fundamental allocation unit for a file, in bytes. */ +unsigned int +xfs_inode_alloc_unitsize ( +struct xfs_inode *ip) +{ +return XFS_FSB_TO_B (ip->i_mount,xfs_inode_alloc_unitsize_fsb (ip)); }fs/xfs/xfs_inode.h +1
-0@@ -643,6 +643,7 @@ int xfs_inode_reload_unlinked(struct xfs_inode *ip);bool xfs_ifork_zapped (const struct xfs_inode *ip,int whichfork);void xfs_inode_count_blocks (struct xfs_trans *tp,struct xfs_inode *ip,xfs_filblks_t *dblocks,xfs_filblks_t *rblocks); +unsigned int xfs_inode_alloc_unitsize_fsb (struct xfs_inode *ip);unsigned int xfs_inode_alloc_unitsize (struct xfs_inode *ip);struct xfs_dir_update_params {fs/xfs/xfs_iomap.c +0
-0
fs/xfs/xfs_iomap.c xfs_bmbt_to_iomap( · line 130
Quoted 5 lines
fs/xfs/xfs_iomap.c +1
-1@@ -127,7 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); - iomap->io_block_size =i_blocksize (VFS_I (ip)); + iomap->io_block_size =xfs_inode_alloc_unitsize (ip);
Oh, I see. So io_block_size causes iomap to write zeroes to the storage backing surrounding areas of the file range. In this case, for direct writes to the unwritten middle 4k of an otherwise written 16k extent, we'll write zeroes to 0-4k and 8k-16k even though that wasn't what the caller asked for?
IOWs, if you start with:
WWuW
write to the "U", then it'll write zeroes to the "W" areas? That doesn't sound good...
Quoted 8 lines
fs/xfs/xfs_iomap.c +1
-0if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else @@ -577,11 +577,17 @@ xfs_iomap_write_unwritten(xfs_fsize_t i_size;uint resblks;int error; +unsigned int rounding;
fs/xfs/xfs_iomap.c xfs_iomap_write_unwritten( · line 590
Quoted 10 lines
fs/xfs/xfs_iomap.c +5
-0trace_xfs_unwritten_convert (ip, offset, count); offset_fsb =XFS_B_TO_FSBT (mp, offset); count_fsb =XFS_B_TO_FSB (mp, (xfs_ufsize_t )offset + count); + rounding =xfs_inode_alloc_unitsize_fsb (ip); +if (rounding >1 ) { + offset_fsb =rounddown_64 (offset_fsb, rounding); + count_fsb =roundup_64 (count_fsb, rounding); + }
...and then the ioend handler is supposed to be smart enough to know that iomap quietly wrote to other parts of the disk.
Um, does this cause unwritten extent conversion for entire rtextents after writeback to a rtextsize > 1fsb file?
Or am I really misunderstanding what's going on here with the io paths?
--D
Quoted 7 lines
fs/xfs/xfs_iomap.c +0
-0count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);/* Signature · 1 line
2.31.1
Re: [PATCH v4 03/22] xfs: Use extent size granularity for iomap->io_block_size
Quoted 38 lines · Darrick J. Wong
Quoted 37 lines · John Garry
Currently
iomap->io_block_sizeis set to thei_blocksize()value for the inode.Expand the sub-fs block size zeroing to now cover RT extents, by calling setting
iomap->io_block_sizeasxfs_inode_alloc_unitsize().In
xfs_iomap_write_unwritten(), update the unwritten range fsb to cover this extent granularity.In
xfs_file_dio_write(), handle a write which is not aligned to extent size granularity as unaligned. Since the extent size granularity need not be a power-of-2, handle this also.Signed-off-by John Garry <[email protected]>--- fs/xfs/xfs_file.c | 24 +++++++++++++++++++----- fs/xfs/xfs_inode.c | 17 +++++++++++------ fs/xfs/xfs_inode.h | 1 + fs/xfs/xfs_iomap.c | 8 +++++++- 4 files changed, 38 insertions(+), 12 deletions(-)fs/xfs/xfs_file.c +1
-1@@ -601,7 +601,7 @@ xfs_file_dio_write_aligned( }/* -* Handle block unaligned direct I/O writes +* Handle unaligned direct IO writes. * * In most cases direct I/O writes will be done holding IOLOCK_SHARED, allowing * them to be done in parallel with reads and other direct I/O writes. However, @@ -630,9 +630,9 @@ xfs_file_dio_write_unaligned(ssize_t ret;
Quoted 13 lines
fs/xfs/xfs_file.c xfs_file_dio_write_unaligned( · line 635
Quoted 7 lines
fs/xfs/xfs_file.c +3
-3/* -* Extending writes need exclusivity because of the sub-block zeroing -* that the DIO code always does for partial tail blocks beyond EOF, so -* don't even bother trying the fast path in this case. +* Extending writes need exclusivity because of the sub-block/extent +* zeroing that the DIO code always does for partial tail blocks +* beyond EOF, so don't even bother trying the fast path in this case. Hummm. So let's say the fsblock size is 4k, the rt extent size is 16k, and you want to write bytes 8192-12287 of a file. Currently we'd use
xfs_file_dio_write_alignedfor that, but now we'd usexfs_file_dio_write_unaligned? Even though we don't need zeroing or any of that stuff?
Right, this is something which I mentioned in response to the previous patch.
I doubt whether we should only do this for atomic writes inodes, or also RT and forcealign-only inodes.
I got the impression from Dave in review of the previous version of this series that it should include RT and forcealign-only.
Quoted 20 lines
Quoted 20 lines
fs/xfs/xfs_file.c +7
-1*/ if (iocb->ki_pos > isize || iocb->ki_pos + count >= isize) {if (iocb->ki_flags &IOCB_NOWAIT )@@ -698,11 +698,25 @@ xfs_file_dio_write(struct xfs_inode *ip =XFS_I (file_inode (iocb->ki_filp));struct xfs_buftarg *target =xfs_inode_buftarg (ip);size_t count =iov_iter_count (from); +bool unaligned; +u64 unitsize;/* direct I/O must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)return -EINVAL ; -if ((iocb->ki_pos | count) & ip->i_mount->m_blockmask) + + unitsize =xfs_inode_alloc_unitsize (ip); +if (!is_power_of_2 (unitsize)) { +if (isaligned_64 (iocb->ki_pos, unitsize) && +isaligned_64 (count, unitsize))
Quoted 8 lines
fs/xfs/xfs_file.c xfs_file_dio_write( · line 717
Quoted 6 lines
fs/xfs/xfs_file.c +6
-0+ unaligned = false; + else + unaligned = true; + }else { + unaligned = (iocb->ki_pos | count) & (unitsize -1 ); + }Didn't I already write this?
It's from xfs_is_falloc_aligned(). Let's reuse that fully here. I did look at doing that before, though...
Quoted 16 lines
fs/xfs/xfs_file.c xfs_file_dio_write( · line 719
Quoted 2 lines
fs/xfs/xfs_file.c +1
-0+if (unaligned)if (!xfs_is_falloc_aligned(ip, iocb->ki_pos, count))Quoted 11 lines
fs/xfs/xfs_file.c +0
-0return xfs_file_dio_write_unaligned (ip, iocb, from);return xfs_file_dio_write_aligned (ip, iocb, from); }fs/xfs/xfs_inode.c +0
-0@@ -4264,15 +4264,20 @@ xfs_break_layouts(return error; }
Quoted 3 lines
fs/xfs/xfs_inode.c xfs_break_layouts( · line 4267
Quoted 1 line
fs/xfs/xfs_inode.c +0
-1-/* Returns the size of fundamental allocation unit for a file, in bytes. */ Don't delete the comment, it has useful return type information.
It wasn't deleted, it is still below.
Quoted 39 lines
/*
* Returns the size of fundamental allocation unit for a file, in
* fsblocks.
*/Quoted 33 lines
fs/xfs/xfs_inode.c +11
-5unsigned int -xfs_inode_alloc_unitsize ( +xfs_inode_alloc_unitsize_fsb (struct xfs_inode *ip) { -unsigned int blocks =1 ; -if (XFS_IS_REALTIME_INODE (ip)) - blocks = ip->i_mount->m_sb.sb_rextsize; +return ip->i_mount->m_sb.sb_rextsize; + +return 1 ; +} -return XFS_FSB_TO_B (ip->i_mount, blocks); +/* Returns the size of fundamental allocation unit for a file, in bytes. */ +unsigned int +xfs_inode_alloc_unitsize ( +struct xfs_inode *ip) +{ +return XFS_FSB_TO_B (ip->i_mount,xfs_inode_alloc_unitsize_fsb (ip)); }fs/xfs/xfs_inode.h +1
-0@@ -643,6 +643,7 @@ int xfs_inode_reload_unlinked(struct xfs_inode *ip);bool xfs_ifork_zapped (const struct xfs_inode *ip,int whichfork);void xfs_inode_count_blocks (struct xfs_trans *tp,struct xfs_inode *ip,xfs_filblks_t *dblocks,xfs_filblks_t *rblocks); +unsigned int xfs_inode_alloc_unitsize_fsb (struct xfs_inode *ip);unsigned int xfs_inode_alloc_unitsize (struct xfs_inode *ip);
Quoted 14 lines
fs/xfs/xfs_iomap.c xfs_bmbt_to_iomap( · line 130
Quoted 11 lines
fs/xfs/xfs_inode.h +0
-0struct xfs_dir_update_params {fs/xfs/xfs_iomap.c +1
-1@@ -127,7 +127,7 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); - iomap->io_block_size =i_blocksize (VFS_I (ip)); + iomap->io_block_size =xfs_inode_alloc_unitsize (ip);Oh, I see. So
io_block_sizecauses iomap to write zeroes to the storage backing surrounding areas of the file range.
Yes
Quoted 4 lines
In this case, for direct
writes to the unwritten middle 4k of an otherwise written 16k extent, we'll write zeroes to 0-4k and 8k-16k even though that wasn't what the caller asked for?
We would only do that for a newly allocated extent. We should not overwrite existing data.
Quoted 7 lines
IOWs, if you start with:
WWuW
write to the "U", then it'll write zeroes to the "W" areas? That doesn't sound good...
No, that definitely should not happen.
We only would zero once when do a sub-extent granule write to an unallocated extent.
In iomap_dio_bio_iter(), we only zero for IOMAP_UNWRITTEN or IOMAP_F_NEW.
Quoted 12 lines
Quoted 12 lines
fs/xfs/xfs_iomap.c +1
-0if (mapping_flags &IOMAP_DAX ) iomap->dax_dev = target->bt_daxdev;else @@ -577,11 +577,17 @@ xfs_iomap_write_unwritten(xfs_fsize_t i_size;uint resblks;int error; +unsigned int rounding;trace_xfs_unwritten_convert (ip, offset, count);
Quoted 10 lines
fs/xfs/xfs_iomap.c xfs_iomap_write_unwritten( · line 590
Quoted 7 lines
fs/xfs/xfs_iomap.c +5
-0offset_fsb =XFS_B_TO_FSBT (mp, offset); count_fsb =XFS_B_TO_FSB (mp, (xfs_ufsize_t )offset + count); + rounding =xfs_inode_alloc_unitsize_fsb (ip); +if (rounding >1 ) { + offset_fsb =rounddown_64 (offset_fsb, rounding); + count_fsb =roundup_64 (count_fsb, rounding); + }...and then the ioend handler is supposed to be smart enough to know that iomap quietly wrote to other parts of the disk.
iomap_io_complete() only knows about the non-zeroing written data. I am not changing that really.
Quoted 3 lines
Um, does this cause unwritten extent conversion for entire rtextents after writeback to a rtextsize > 1fsb file?
Yes.
Quoted 2 lines
Or am I really misunderstanding what's going on here with the io paths?
Thanks,
John
PATCH v4 4/22 xfs: only allow minlen allocations when near ENOSPC
In reply to John GarryFrom: Dave Chinner <[email protected]>
When we are near ENOSPC and don't have enough free
space for an args->maxlen allocation, xfs_alloc_space_available() will trim args->maxlen to equal the available space. However, this function has only checked that there is enough contiguous free space for an aligned args->minlen allocation to succeed. Hence there is no guarantee that an args->maxlen allocation will succeed, nor that the available space will allow for correct alignment of an args->maxlen allocation.
Further, by trimming args->maxlen arbitrarily, it breaks an assumption made in xfs_alloc_fix_len() that if the caller wants aligned allocation, then args->maxlen will be set to an aligned value. It then skips the tail alignment and so we end up with extents that aren't aligned to extent size hint boundaries as we approach ENOSPC.
To avoid this problem, don't reduce args->maxlen by some random, arbitrary amount. If args->maxlen is too large for the available space, reduce the allocation to a minlen allocation as we know we have contiguous free space available for this to succeed and always be correctly aligned.
--- fs/xfs/libxfs/xfs_alloc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +14 -5
@@ -2409,14 +2409,23 @@ xfs_alloc_space_available(if (available < (int )max (args->total, alloc_len))return false; +if (flags &XFS_ALLOC_FLAG_CHECK ) +return true; +/* -* Clamp maxlen to the amount of free space available for the actual -* extent allocation. +* If we can't do a maxlen allocation, then we must reduce the size of +* the allocation to match the available free space. We know how big +* the largest contiguous free space we can allocate is, so that's our +* upper bound. However, we don't exaclty know what alignment/size +* constraints have been placed on the allocation, so we can't +* arbitrarily select some new max size. Hence make this a minlen +* allocation as we know that will definitely succeed and match the +* callers alignment constraints. */ -if (available < (int )args->maxlen && !(flags &XFS_ALLOC_FLAG_CHECK )) { - args->maxlen = available; + alloc_len = args->maxlen + (args->alignment -1 ) + args->minalignslop; +if (longest < alloc_len) { + args->maxlen = args->minlen;ASSERT (args->maxlen >0 ); -ASSERT (args->maxlen >= args->minlen); }return true;
Signature · 1 line
2.31.1
PATCH v4 5/22 xfs: always tail align maxlen allocations
In reply to John GarryFrom: Dave Chinner <[email protected]>
When we do a large allocation, the core free space allocation code assumes that args->maxlen is aligned to args->prod/args->mod. hence if we get a maximum sized extent allocated, it does not do tail alignment of the extent.
However, this assumes that nothing modifies args->maxlen between the original allocation context setup and trimming the selected free space extent to size. This assumption has recently been found to be invalid - xfs_alloc_space_available() modifies args->maxlen in low space situations - and there may be more situations we haven't yet found like this.
Force aligned allocation introduces the requirement that extents are correctly tail aligned, resulting in this occasional latent alignment failure to e reclassified from an unimportant curiousity to a must-fix bug.
Removing the assumption about args->maxlen allocations always being tail aligned is trivial, and should not impact anything because args->maxlen for inodes with extent size hints configured are already aligned. Hence all this change does it avoid weird corner cases that would have resulted in unaligned extent sizes by always trimming the extent down to an aligned size.
--- fs/xfs/libxfs/xfs_alloc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +5 -7
@@ -432,20 +432,18 @@ xfs_alloc_compute_diff(* Fix up the length, based on mod and prod. * len should be k * prod + mod for some k. * If len is too small it is returned unchanged. -* If len hits maxlen it is left alone. */ -STATIC void +static void xfs_alloc_fix_len ( -xfs_alloc_arg_t *args)/* allocation argument structure */ +struct xfs_alloc_arg *args) { -xfs_extlen_t k; -xfs_extlen_t rlen; +xfs_extlen_t k; +xfs_extlen_t rlen = args->len;ASSERT (args->mod < args->prod); - rlen = args->len;ASSERT (rlen >= args->minlen);ASSERT (rlen <= args->maxlen); -if (args->prod <=1 || rlen < args->mod || rlen == args->maxlen || +if (args->prod <=1 || rlen < args->mod || (args->mod ==0 && rlen < args->prod))return ; k = rlen % args->prod;
Signature · 1 line
2.31.1
PATCH v4 6/22 xfs: simplify extent allocation alignment
In reply to John GarryFrom: Dave Chinner <[email protected]>
We currently align extent allocation to stripe unit or stripe width. That is specified by an external parameter to the allocation code, which then manipulates the xfs_alloc_args alignment configuration in interesting ways.
The args->alignment field specifies extent start alignment, but because we may be attempting non-aligned allocation first there are also slop variables that allow for those allocation attempts to account for aligned allocation if they fail.
This gets much more complex as we introduce forced allocation alignment, where extent size hints are used to generate the extent start alignment. extent size hints currently only affect extent lengths (via args->prod and args->mod) and so with this change we will have two different start alignment conditions.
Avoid this complexity by always using args->alignment to indicate extent start alignment, and always using args->prod/mod to indicate extent length adjustment.
jpg: fixup alignslop references in xfs_trace.h and xfs_ialloc.c
--- fs/xfs/libxfs/xfs_alloc.c | 4 +- fs/xfs/libxfs/xfs_alloc.h | 2 +- fs/xfs/libxfs/xfs_bmap.c | 96 +++++++++++++++++--------------------- fs/xfs/libxfs/xfs_ialloc.c | 10 ++-- fs/xfs/xfs_trace.h | 8 ++-- 5 files changed, 54 insertions(+), 66 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +2 -2
@@ -2391,7 +2391,7 @@ xfs_alloc_space_available( reservation =xfs_ag_resv_needed (pag, args->resv);/* do we have enough contiguous free space for the allocation? */ - alloc_len = args->minlen + (args->alignment -1 ) + args->minalignslop; + alloc_len = args->minlen + (args->alignment -1 ) + args->alignslop; longest =xfs_alloc_longest_free_extent (pag, min_free, reservation);if (longest < alloc_len)return false;
@@ -2420,7 +2420,7 @@ xfs_alloc_space_available(* allocation as we know that will definitely succeed and match the * callers alignment constraints. */ - alloc_len = args->maxlen + (args->alignment -1 ) + args->minalignslop; + alloc_len = args->maxlen + (args->alignment -1 ) + args->alignslop;if (longest < alloc_len) { args->maxlen = args->minlen;ASSERT (args->maxlen >0 );
fs/xfs/libxfs/xfs_alloc.h +1 -1
@@ -46,7 +46,7 @@ typedef struct xfs_alloc_arg {xfs_extlen_t minleft;/* min blocks must be left after us */ xfs_extlen_t total;/* total blocks needed in xaction */ xfs_extlen_t alignment;/* align answer to multiple of this */ -xfs_extlen_t minalignslop;/* slop for minlen+alignment calcs */ +xfs_extlen_t alignslop;/* slop for alignment calcs */ xfs_agblock_t min_agbno;/* set an agbno range for NEAR allocs */ xfs_agblock_t max_agbno;/* ... */ xfs_extlen_t len;/* output: actual size of extent */
fs/xfs/libxfs/xfs_bmap.c +42 -54
238 lines not on this page · raw message
fs/xfs/libxfs/xfs_ialloc.c +5 -5
@@ -758,12 +758,12 @@ xfs_ialloc_ag_alloc(* * For an exact allocation, alignment must be 1, * however we need to take cluster alignment into account when -* fixing up the freelist. Use the minalignslop field to -* indicate that extra blocks might be required for alignment, -* but not to use them in the actual exact allocation. +* fixing up the freelist. Use the alignslop field to indicate +* that extra blocks might be required for alignment, but not +* to use them in the actual exact allocation. */ args.alignment =1 ; - args.minalignslop = igeo->cluster_align -1 ; + args.alignslop = igeo->cluster_align -1 ;/* Allow space for the inode btree to split. */ args.minleft = igeo->inobt_maxlevels;
@@ -783,7 +783,7 @@ xfs_ialloc_ag_alloc(* on, so reset minalignslop to ensure it is not included in * subsequent requests. */ - args.minalignslop =0 ; + args.alignslop =0 ; }if (unlikely (args.fsbno ==NULLFSBLOCK )) {
fs/xfs/xfs_trace.h +4 -4
@@ -1808,7 +1808,7 @@ DECLARE_EVENT_CLASS(xfs_alloc_class, __field(xfs_extlen_t, minleft) __field(xfs_extlen_t, total) __field(xfs_extlen_t, alignment) - __field(xfs_extlen_t, minalignslop) + __field(xfs_extlen_t, alignslop) __field(xfs_extlen_t, len) __field(char, wasdel)__field (char, wasfromfl)
@@ -1827,7 +1827,7 @@ DECLARE_EVENT_CLASS(xfs_alloc_class, __entry->minleft = args->minleft; __entry->total = args->total; __entry->alignment = args->alignment; - __entry->minalignslop = args->minalignslop; + __entry->alignslop = args->alignslop; __entry->len = args->len; __entry->wasdel = args->wasdel; __entry->wasfromfl = args->wasfromfl;
@@ -1836,7 +1836,7 @@ DECLARE_EVENT_CLASS(xfs_alloc_class, __entry->highest_agno = args->tp->t_highest_agno; ), TP_printk("dev %d:%d agno 0x%x agbno 0x%x minlen %u maxlen %u mod %u " - "prod %u minleft %u total %u alignment %u minalignslop %u " + "prod %u minleft %u total %u alignment %u alignslop %u " "len %u wasdel %d wasfromfl %d resv %d " "datatype 0x%x highest_agno 0x%x", MAJOR(__entry->dev), MINOR(__entry->dev),
@@ -1849,7 +1849,7 @@ DECLARE_EVENT_CLASS(xfs_alloc_class, __entry->minleft, __entry->total, __entry->alignment, - __entry->minalignslop, + __entry->alignslop, __entry->len, __entry->wasdel, __entry->wasfromfl,
Signature · 1 line
2.31.1
PATCH v4 7/22 xfs: make EOF allocation simpler
In reply to John GarryFrom: Dave Chinner <[email protected]>
Currently the allocation at EOF is broken into two cases - when the offset is zero and when the offset is non-zero. When the offset is non-zero, we try to do exact block allocation for contiguous extent allocation. When the offset is zero, the allocation is simply an aligned allocation.
We want aligned allocation as the fallback when exact block allocation fails, but that complicates the EOF allocation in that it now has to handle two different allocation cases. The caller also has to handle allocation when not at EOF, and for the upcoming forced alignment changes we need that to also be aligned allocation.
To simplify all this, pull the aligned allocation cases back into the callers and leave the EOF allocation path for exact block allocation only. This means that the EOF exact block allocation fallback path is the normal aligned allocation path and that ends up making things a lot simpler when forced alignment is introduced.
--- fs/xfs/libxfs/xfs_bmap.c | 129 +++++++++++++++---------------------- fs/xfs/libxfs/xfs_ialloc.c | 2 +- 2 files changed, 54 insertions(+), 77 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +53 -76
@@ -3310,12 +3310,12 @@ xfs_bmap_select_minlen(static int xfs_bmap_btalloc_select_lengths (struct xfs_bmalloca *ap, -struct xfs_alloc_arg *args, -xfs_extlen_t *blen) +struct xfs_alloc_arg *args) {struct xfs_mount *mp = args->mp;struct xfs_perag *pag;xfs_agnumber_t agno, startag; +xfs_extlen_t blen =0 ;int error =0 ;if (ap->tp->t_flags &XFS_TRANS_LOWMODE ) {
@@ -3329,19 +3329,18 @@ xfs_bmap_btalloc_select_lengths(if (startag ==NULLAGNUMBER ) startag =0 ; - *blen =0 ;for_each_perag_wrap (mp, startag, agno, pag) { - error =xfs_bmap_longest_free_extent (pag, args->tp, blen); + error =xfs_bmap_longest_free_extent (pag, args->tp, &blen);if (error && error != -EAGAIN )break ; error =0 ; -if (*blen >= args->maxlen) +if (blen >= args->maxlen)break ; }if (pag)xfs_perag_rele (pag); - args->minlen =xfs_bmap_select_minlen (ap, args, *blen); + args->minlen =xfs_bmap_select_minlen (ap, args, blen);return error; }
@@ -3551,78 +3550,40 @@ xfs_bmap_exact_minlen_extent_alloc(* If we are not low on available data blocks and we are allocating at * EOF, optimise allocation for contiguous file extension and/or stripe * alignment of the new extent. -* -* NOTE: ap->aeof is only set if the allocation length is >= the -* stripe unit and the allocation offset is at the end of file. */ static int xfs_bmap_btalloc_at_eof (struct xfs_bmalloca *ap, -struct xfs_alloc_arg *args, -xfs_extlen_t blen, -bool ag_only) +struct xfs_alloc_arg *args) {struct xfs_mount *mp = args->mp;struct xfs_perag *caller_pag = args->pag; +xfs_extlen_t alignment = args->alignment;int error; +ASSERT (ap->aeof && ap->offset); +ASSERT (args->alignment >=1 ); +/* -* If there are already extents in the file, try an exact EOF block -* allocation to extend the file as a contiguous extent. If that fails, -* or it's the first allocation in a file, just try for a stripe aligned -* allocation. +* Compute the alignment slop for the fallback path so we ensure +* we account for the potential alignemnt space required by the +* fallback paths before we modify the AGF and AGFL here. */ -if (ap->offset) { -xfs_extlen_t alignment = args->alignment; - -/* -* Compute the alignment slop for the fallback path so we ensure -* we account for the potential alignemnt space required by the -* fallback paths before we modify the AGF and AGFL here. -*/ - args->alignment =1 ; - args->alignslop = alignment - args->alignment; - -if (!caller_pag) - args->pag =xfs_perag_get (mp,XFS_FSB_TO_AGNO (mp, ap->blkno)); - error =xfs_alloc_vextent_exact_bno (args, ap->blkno); -if (!caller_pag) { -xfs_perag_put (args->pag); - args->pag =NULL ; - } -if (error) -return error; - -if (args->fsbno !=NULLFSBLOCK ) -return 0 ; -/* -* Exact allocation failed. Reset to try an aligned allocation -* according to the original allocation specification. -*/ - args->alignment = alignment; - args->alignslop =0 ; - } + args->alignment =1 ; + args->alignslop = alignment - args->alignment; -if (ag_only) { - error =xfs_alloc_vextent_near_bno (args, ap->blkno); - }else { +if (!caller_pag) + args->pag =xfs_perag_get (mp,XFS_FSB_TO_AGNO (mp, ap->blkno)); + error =xfs_alloc_vextent_exact_bno (args, ap->blkno); +if (!caller_pag) { +xfs_perag_put (args->pag); args->pag =NULL ; - error =xfs_alloc_vextent_start_ag (args, ap->blkno); -ASSERT (args->pag ==NULL ); - args->pag = caller_pag; } -if (error) -return error; -if (args->fsbno !=NULLFSBLOCK ) -return 0 ; - -/* -* Aligned allocation failed, so all fallback paths from here drop the -* start alignment requirement as we know it will not succeed. -*/ - args->alignment =1 ; -return 0 ; +/* Reset alignment to original specifications. */ + args->alignment = alignment; + args->alignslop =0 ; +return error; }/*
@@ -3688,12 +3649,19 @@ xfs_bmap_btalloc_filestreams( } args->minlen =xfs_bmap_select_minlen (ap, args, blen); -if (ap->aeof) - error =xfs_bmap_btalloc_at_eof (ap, args, blen, true); +if (ap->aeof && ap->offset) + error =xfs_bmap_btalloc_at_eof (ap, args); +/* This may be an aligned allocation attempt. */ if (!error && args->fsbno ==NULLFSBLOCK ) error =xfs_alloc_vextent_near_bno (args, ap->blkno); +/* Attempt non-aligned allocation if we haven't already. */ +if (!error && args->fsbno ==NULLFSBLOCK && args->alignment >1 ) { + args->alignment =1 ; + error =xfs_alloc_vextent_near_bno (args, ap->blkno); + } + out_low_space:/* * We are now done with the perag reference for the filestreams
@@ -3715,7 +3683,6 @@ xfs_bmap_btalloc_best_length(struct xfs_bmalloca *ap, struct xfs_alloc_arg *args) { - xfs_extlen_t blen = 0; int error; ap->blkno =XFS_INO_TO_FSB (args->mp, ap->ip->i_ino);
@@ -3726,23 +3693,33 @@ xfs_bmap_btalloc_best_length(* the request. If one isn't found, then adjust the minimum allocation * size to the largest space found. */ - error =xfs_bmap_btalloc_select_lengths (ap, args, &blen); + error =xfs_bmap_btalloc_select_lengths (ap, args);if (error)return error;/* -* Don't attempt optimal EOF allocation if previous allocations barely -* succeeded due to being near ENOSPC. It is highly unlikely we'll get -* optimal or even aligned allocations in this case, so don't waste time -* trying. +* If we are in low space mode, then optimal allocation will fail so +* prepare for minimal allocation and run the low space algorithm +* immediately. */ -if (ap->aeof && !(ap->tp->t_flags &XFS_TRANS_LOWMODE )) { - error =xfs_bmap_btalloc_at_eof (ap, args, blen, false); -if (error || args->fsbno !=NULLFSBLOCK ) -return error; +if (ap->tp->t_flags &XFS_TRANS_LOWMODE ) { +ASSERT (args->fsbno ==NULLFSBLOCK ); +return xfs_bmap_btalloc_low_space (ap, args); + } + +if (ap->aeof && ap->offset) + error =xfs_bmap_btalloc_at_eof (ap, args); + +/* This may be an aligned allocation attempt. */ +if (!error && args->fsbno ==NULLFSBLOCK ) + error =xfs_alloc_vextent_start_ag (args, ap->blkno); + +/* Attempt non-aligned allocation if we haven't already. */ +if (!error && args->fsbno ==NULLFSBLOCK && args->alignment >1 ) { + args->alignment =1 ; + error =xfs_alloc_vextent_start_ag (args, ap->blkno); } - error =xfs_alloc_vextent_start_ag (args, ap->blkno);if (error || args->fsbno !=NULLFSBLOCK )return error;
fs/xfs/libxfs/xfs_ialloc.c +1 -1
@@ -780,7 +780,7 @@ xfs_ialloc_ag_alloc(* the exact agbno requirement and increase the alignment * instead. It is critical that the total size of the request * (len + alignment + slop) does not increase from this point -* on, so reset minalignslop to ensure it is not included in +* on, so reset alignslop to ensure it is not included in * subsequent requests. */ args.alignslop =0 ;
Signature · 1 line
2.31.1
PATCH v4 8/22 xfs: introduce forced allocation alignment
In reply to John GarryFrom: Dave Chinner <[email protected]>
When forced allocation alignment is specified, the extent will be aligned to the extent size hint size rather than stripe alignment. If aligned allocation cannot be done, then the allocation is failed rather than attempting non-aligned fallbacks.
Note: none of the per-inode force align configuration is present yet, so this just triggers off an "always false" wrapper function for the moment.
--- fs/xfs/libxfs/xfs_alloc.h | 1 + fs/xfs/libxfs/xfs_bmap.c | 29 +++++++++++++++++++++++------ fs/xfs/xfs_inode.h | 5 +++++ 3 files changed, 29 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_alloc.h +1 -0
@@ -66,6 +66,7 @@ typedef struct xfs_alloc_arg {#define XFS_ALLOC_USERDATA (1 << 0)/* allocation is for user data*/ #define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */ #define XFS_ALLOC_NOBUSY (1 << 2)/* Busy extents not allowed */ +#define XFS_ALLOC_FORCEALIGN (1 << 3)/* forced extent alignment */ /* freespace limit calculations */ unsigned int xfs_alloc_set_aside (struct xfs_mount *mp);
fs/xfs/libxfs/xfs_bmap.c +23 -6
@@ -3401,9 +3401,10 @@ xfs_bmap_alloc_account(* Calculate the extent start alignment and the extent length adjustments that * constrain this allocation. * -* Extent start alignment is currently determined by stripe configuration and is -* carried in args->alignment, whilst extent length adjustment is determined by -* extent size hints and is carried by args->prod and args->mod. +* Extent start alignment is currently determined by forced inode alignment or +* stripe configuration and is carried in args->alignment, whilst extent length +* adjustment is determined by extent size hints and is carried by args->prod +* and args->mod. * * Low level allocation code is free to either ignore or override these values * as required.
@@ -3416,11 +3417,18 @@ xfs_bmap_compute_alignments(struct xfs_mount *mp = args->mp;xfs_extlen_t align =0 ;/* minimum allocation alignment */ -/* stripe alignment for allocation is determined by mount parameters */ -if (mp->m_swidth &&xfs_has_swalloc (mp)) +/* +* Forced inode alignment takes preference over stripe alignment. +* Stripe alignment for allocation is determined by mount parameters. +*/ +if (xfs_inode_has_forcealign (ap->ip)) { + args->alignment =xfs_get_extsz_hint (ap->ip); + args->datatype |=XFS_ALLOC_FORCEALIGN ; + }else if (mp->m_swidth &&xfs_has_swalloc (mp)) { args->alignment = mp->m_swidth; -else if (mp->m_dalign) + }else if (mp->m_dalign) { args->alignment = mp->m_dalign; + }if (ap->flags &XFS_BMAPI_COWFORK ) align =xfs_get_cowextsz_hint (ap->ip);
@@ -3607,6 +3615,11 @@ xfs_bmap_btalloc_low_space( {int error; +if (args->alignment >1 && (args->datatype &XFS_ALLOC_FORCEALIGN )) { + args->fsbno =NULLFSBLOCK ; +return 0 ; + } + args->alignment =1 ;if (args->minlen > ap->minlen) { args->minlen = ap->minlen;
@@ -3658,6 +3671,8 @@ xfs_bmap_btalloc_filestreams(/* Attempt non-aligned allocation if we haven't already. */ if (!error && args->fsbno ==NULLFSBLOCK && args->alignment >1 ) { +if (args->datatype &XFS_ALLOC_FORCEALIGN ) +return error; args->alignment =1 ; error =xfs_alloc_vextent_near_bno (args, ap->blkno); }
@@ -3716,6 +3731,8 @@ xfs_bmap_btalloc_best_length(/* Attempt non-aligned allocation if we haven't already. */ if (!error && args->fsbno ==NULLFSBLOCK && args->alignment >1 ) { +if (args->datatype &XFS_ALLOC_FORCEALIGN ) +return error; args->alignment =1 ; error =xfs_alloc_vextent_start_ag (args, ap->blkno); }
fs/xfs/xfs_inode.h +5 -0
@@ -311,6 +311,11 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)return ip->i_diflags2 &XFS_DIFLAG2_NREXT64 ; } +static inline bool xfs_inode_has_forcealign (struct xfs_inode *ip) +{ +return false; +} +/* * Decide if this file is a realtime file whose data allocation unit is larger * than a single filesystem block.
Signature · 1 line
2.31.1
PATCH v4 9/22 xfs: align args->minlen for forced allocation alignment
In reply to John GarryFrom: Dave Chinner <[email protected]>
If args->minlen is not aligned to the constraints of forced alignment, we may do minlen allocations that are not aligned when we approach ENOSPC. Avoid this by always aligning args->minlen appropriately. If alignment of minlen results in a value smaller than the alignment constraint, fail the allocation immediately.
--- fs/xfs/libxfs/xfs_bmap.c | 45 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +31 -14
@@ -3278,33 +3278,48 @@ xfs_bmap_longest_free_extent(return 0 ; } -static xfs_extlen_t +static int xfs_bmap_select_minlen (struct xfs_bmalloca *ap,struct xfs_alloc_arg *args,xfs_extlen_t blen) { -/* Adjust best length for extent start alignment. */ if (blen > args->alignment) blen -= args->alignment;/* * Since we used XFS_ALLOC_FLAG_TRYLOCK in _longest_free_extent(), it is -* possible that there is enough contiguous free space for this request. +* possible that there is enough contiguous free space for this request +* even if best length is less that the minimum length we need. +* +* If the best length won't satisfy the maximum length we requested, +* then use it as the minimum length so we get as large an allocation +* as possible. */ if (blen < ap->minlen) -return ap->minlen; + blen = ap->minlen; +else if (blen > args->maxlen) + blen = args->maxlen;/* -* If the best seen length is less than the request length, -* use the best as the minimum, otherwise we've got the maxlen we -* were asked for. +* If we have alignment constraints, round the minlen down to match the +* constraint so that alignment will be attempted. This may reduce the +* allocation to smaller than was requested, so clamp the minimum to +* ap->minlen to allow unaligned allocation to succeed. If we are forced +* to align the allocation, return ENOSPC at this point because we don't +* have enough contiguous free space to guarantee aligned allocation. */ -if (blen < args->maxlen) -return blen; -return args->maxlen; - +if (args->alignment >1 ) { + blen =rounddown (blen, args->alignment); +if (blen < ap->minlen) { +if (args->datatype &XFS_ALLOC_FORCEALIGN ) +return -ENOSPC ; + blen = ap->minlen; + } + } + args->minlen = blen; +return 0 ; } static int
@@ -3340,8 +3355,7 @@ xfs_bmap_btalloc_select_lengths(if (pag)xfs_perag_rele (pag); - args->minlen =xfs_bmap_select_minlen (ap, args, blen); -return error; +return xfs_bmap_select_minlen (ap, args, blen); }/* Update all inode and quota accounting for the allocation we just did. */
@@ -3661,7 +3675,10 @@ xfs_bmap_btalloc_filestreams( goto out_low_space; } - args->minlen =xfs_bmap_select_minlen (ap, args, blen); + error =xfs_bmap_select_minlen (ap, args, blen); +if (error) + goto out_low_space; +if (ap->aeof && ap->offset) error =xfs_bmap_btalloc_at_eof (ap, args);
Signature · 1 line
2.31.1
PATCH v4 10/22 xfs: Introduce FORCEALIGN inode flag
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Add a new inode flag to require that all file data extent mappings must be aligned (both the file offset range and the allocated space itself) to the extent size hint. Having a separate COW extent size hint is no longer allowed.
The goal here is to enable sysadmins and users to mandate that all space mappings in a file must have a startoff/blockcount that are aligned to (say) a 2MB alignment and that the startblock/blockcount will follow the same alignment.
--- fs/xfs/libxfs/xfs_format.h | 6 +++- fs/xfs/libxfs/xfs_inode_buf.c | 53 +++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_buf.h | 3 ++ fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_inode.c | 13 +++++++++ fs/xfs/xfs_inode.h | 20 ++++++++++++- fs/xfs/xfs_ioctl.c | 47 +++++++++++++++++++++++++++++-- fs/xfs/xfs_mount.h | 2 ++ fs/xfs/xfs_reflink.h | 10 ------- fs/xfs/xfs_super.c | 4 +++ include/uapi/linux/fs.h | 2 ++ 11 files changed, 148 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_format.h +5 -1
@@ -353,6 +353,7 @@ xfs_sb_has_compat_feature(#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ +#define XFS_SB_FEAT_RO_COMPAT_FORCEALIGN (1 << 30)/* aligned file data extents */ #define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
@@ -1094,16 +1095,19 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)#define XFS_DIFLAG2_COWEXTSIZE_BIT 2/* copy on write extent size hint */ #define XFS_DIFLAG2_BIGTIME_BIT 3/* big timestamps */ #define XFS_DIFLAG2_NREXT64_BIT 4/* large extent counters */ +/* data extent mappings for regular files must be aligned to extent size hint */ +#define XFS_DIFLAG2_FORCEALIGN_BIT 5#define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT)#define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT)#define XFS_DIFLAG2_COWEXTSIZE (1 << XFS_DIFLAG2_COWEXTSIZE_BIT)#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT)#define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT) +#define XFS_DIFLAG2_FORCEALIGN (1 << XFS_DIFLAG2_FORCEALIGN_BIT)#define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_FORCEALIGN)static inline bool xfs_dinode_has_bigtime (const struct xfs_dinode *dip) {
fs/xfs/libxfs/xfs_inode_buf.c +53 -0
62 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_buf.h +3 -0
@@ -33,6 +33,9 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp,xfs_failaddr_t xfs_inode_validate_cowextsize (struct xfs_mount *mp,uint32_t cowextsize,uint16_t mode,uint16_t flags,uint64_t flags2); +xfs_failaddr_t xfs_inode_validate_forcealign (struct xfs_mount *mp, +uint32_t extsize,uint32_t cowextsize,uint16_t mode, +uint16_t flags,uint64_t flags2);static inline uint64_t xfs_inode_encode_bigtime (struct timespec64 tv) {
fs/xfs/libxfs/xfs_sb.c +2 -0
@@ -164,6 +164,8 @@ xfs_sb_version_to_features( features |=XFS_FEAT_REFLINK ;if (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_INOBTCNT ) features |=XFS_FEAT_INOBTCNT ; +if (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_FORCEALIGN ) + features |=XFS_FEAT_FORCEALIGN ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_FTYPE ) features |=XFS_FEAT_FTYPE ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_SPINODES )
fs/xfs/xfs_inode.c +13 -0
@@ -608,6 +608,8 @@ xfs_ip2xflags( flags |=FS_XFLAG_DAX ;if (ip->i_diflags2 &XFS_DIFLAG2_COWEXTSIZE ) flags |=FS_XFLAG_COWEXTSIZE ; +if (ip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ) + flags |=FS_XFLAG_FORCEALIGN ; }if (xfs_inode_has_attr_fork (ip))
@@ -737,6 +739,8 @@ xfs_inode_inherit_flags2( }if (pip->i_diflags2 &XFS_DIFLAG2_DAX ) ip->i_diflags2 |=XFS_DIFLAG2_DAX ; +if (pip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ) + ip->i_diflags2 |=XFS_DIFLAG2_FORCEALIGN ;/* Don't let invalid cowextsize hints propagate. */ failaddr = xfs_inode_validate_cowextsize(ip->i_mount, ip->i_cowextsize,
@@ -745,6 +749,15 @@ xfs_inode_inherit_flags2( ip->i_diflags2 &= ~XFS_DIFLAG2_COWEXTSIZE ; ip->i_cowextsize =0 ; } + +if (ip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ) { + failaddr =xfs_inode_validate_forcealign (ip->i_mount, + ip->i_extsize, ip->i_cowextsize, +VFS_I (ip)->i_mode, ip->i_diflags, + ip->i_diflags2); +if (failaddr) + ip->i_diflags2 &= ~XFS_DIFLAG2_FORCEALIGN ; + } }/*
fs/xfs/xfs_inode.h +19 -1
@@ -301,6 +301,16 @@ static inline bool xfs_inode_has_cow_data(struct xfs_inode *ip)return ip->i_cowfp && ip->i_cowfp->if_bytes; } +static inline bool xfs_is_always_cow_inode (struct xfs_inode *ip) +{ +return ip->i_mount->m_always_cow &&xfs_has_reflink (ip->i_mount); +} + +static inline bool xfs_is_cow_inode (struct xfs_inode *ip) +{ +return xfs_is_reflink_inode (ip) ||xfs_is_always_cow_inode (ip); +} +static inline bool xfs_inode_has_bigtime (struct xfs_inode *ip) {return ip->i_diflags2 &XFS_DIFLAG2_BIGTIME ;
@@ -313,7 +323,15 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)static inline bool xfs_inode_has_forcealign (struct xfs_inode *ip) { -return false; +if (!(ip->i_diflags &XFS_DIFLAG_EXTSIZE )) +return false; +if (ip->i_extsize <=1 ) +return false; +if (xfs_is_cow_inode (ip)) +return false; +if (ip->i_diflags &XFS_DIFLAG_REALTIME ) +return false; +return ip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ; }/*
fs/xfs/xfs_ioctl.c +45 -2
71 lines not on this page · raw message
fs/xfs/xfs_mount.h +2 -0
@@ -299,6 +299,7 @@ typedef struct xfs_mount {#define XFS_FEAT_NEEDSREPAIR (1ULL << 25)/* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26)/* large extent counters */ #define XFS_FEAT_EXCHANGE_RANGE (1ULL << 27)/* exchange range */ +#define XFS_FEAT_FORCEALIGN (1ULL << 28)/* aligned file data extents */ /* Mount features */ #define XFS_FEAT_NOATTR2 (1ULL << 48)/* disable attr2 creation */
@@ -385,6 +386,7 @@ __XFS_ADD_V4_FEAT(projid32, PROJID32) __XFS_HAS_V4_FEAT(v3inodes, V3INODES) __XFS_HAS_V4_FEAT(crc, CRC) __XFS_HAS_V4_FEAT(pquotino, PQUOTINO) +__XFS_HAS_FEAT (forcealign,FORCEALIGN )/* * Mount features
fs/xfs/xfs_reflink.h +0 -10
@@ -6,16 +6,6 @@#ifndef __XFS_REFLINK_H#define __XFS_REFLINK_H 1 -static inline bool xfs_is_always_cow_inode (struct xfs_inode *ip) -{ -return ip->i_mount->m_always_cow &&xfs_has_reflink (ip->i_mount); -} - -static inline bool xfs_is_cow_inode (struct xfs_inode *ip) -{ -return xfs_is_reflink_inode (ip) ||xfs_is_always_cow_inode (ip); -} -extern int xfs_reflink_trim_around_shared (struct xfs_inode *ip,struct xfs_bmbt_irec *irec,bool *shared); int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
fs/xfs/xfs_super.c +4 -0
@@ -1721,6 +1721,10 @@ xfs_fs_fill_super( mp->m_features &= ~XFS_FEAT_DISCARD ; } +if (xfs_has_forcealign (mp)) +xfs_warn (mp, +"EXPERIMENTAL forced data extent alignment feature in use. Use at your own risk!" ); +if (xfs_has_reflink (mp)) {if (mp->m_sb.sb_rblocks) { xfs_alert(mp,
include/uapi/linux/fs.h +2 -0
@@ -158,6 +158,8 @@ struct fsxattr {#define FS_XFLAG_FILESTREAM 0x00004000/* use filestream allocator */ #define FS_XFLAG_DAX 0x00008000/* use DAX for IO */ #define FS_XFLAG_COWEXTSIZE 0x00010000/* CoW extent size allocator hint */ +/* data extent mappings for regular files must be aligned to extent size hint */ +#define FS_XFLAG_FORCEALIGN 0x00020000#define FS_XFLAG_HASATTR 0x80000000/* no DIFLAG for this */ /* the read-only stuff doesn't really belong here, but any other place is
Signature · 1 line
2.31.1
PATCH v4 11/22 xfs: Do not free EOF blocks for forcealign
In reply to John GarryFor when forcealign is enabled, we want the EOF to be aligned as well, so do not free EOF blocks.
--- fs/xfs/xfs_bmap_util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/xfs/xfs_bmap_util.c +6 -1
@@ -539,8 +539,13 @@ xfs_can_free_eofblocks(* forever. */ end_fsb =XFS_B_TO_FSB (mp, (xfs_ufsize_t )XFS_ISIZE (ip)); -if (xfs_inode_has_bigrtalloc (ip)) + +/* Do not free blocks when forcing extent sizes */ +if (xfs_inode_has_forcealign (ip)) + end_fsb =roundup_64 (end_fsb, ip->i_extsize); +else if (xfs_inode_has_bigrtalloc (ip)) end_fsb =xfs_rtb_roundup_rtx (mp, end_fsb); + last_fsb =XFS_B_TO_FSB (mp, mp->m_super->s_maxbytes);if (last_fsb <= end_fsb)return false;
Signature · 1 line
2.31.1
PATCH v4 12/22 xfs: Update xfs_inode_alloc_unitsize_fsb() for forcealign
In reply to John GarryFor forcealign enabled, the allocation unit size is in ip->i_extsize, and this must never be zero.
--- fs/xfs/xfs_inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/xfs/xfs_inode.c +2 -0
@@ -4281,6 +4281,8 @@ unsigned intxfs_inode_alloc_unitsize_fsb ( struct xfs_inode *ip) { +if (xfs_inode_has_forcealign (ip)) +return ip->i_extsize;if (XFS_IS_REALTIME_INODE (ip))return ip->i_mount->m_sb.sb_rextsize;
Signature · 1 line
2.31.1
PATCH v4 13/22 xfs: Unmap blocks according to forcealign
In reply to John GarryFor when forcealign is enabled, blocks in an inode need to be unmapped according to extent alignment, like what is already done for rtvol.
--- fs/xfs/libxfs/xfs_bmap.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +28 -5
@@ -5380,6 +5380,20 @@ xfs_bmap_del_extent_real(return 0 ; } +static xfs_extlen_t +xfs_bunmapi_align ( +struct xfs_inode *ip, +xfs_fsblock_t bno) +{ +if (xfs_inode_has_forcealign (ip)) { +if (is_power_of_2 (ip->i_extsize)) +return bno & (ip->i_extsize -1 ); +return do_div (bno, ip->i_extsize); + } +ASSERT (XFS_IS_REALTIME_INODE (ip)); +return xfs_rtb_to_rtxoff (ip->i_mount, bno); +} +/* * Unmap (remove) blocks from a file. * If nexts is nonzero then the number of extents to remove is limited to
@@ -5402,6 +5416,7 @@ __xfs_bunmapi(struct xfs_bmbt_irec got;/* current extent record */ struct xfs_ifork *ifp;/* inode fork pointer */ int isrt;/* freeing in rt area */ +int isforcealign;/* freeing for inode with forcealign */ int logflags;/* transaction logging flags */ xfs_extlen_t mod;/* rt extent offset */ struct xfs_mount *mp = ip->i_mount;
@@ -5439,6 +5454,8 @@ __xfs_bunmapi( }XFS_STATS_INC (mp, xs_blk_unmap); isrt =xfs_ifork_is_realtime (ip, whichfork); + isforcealign = (whichfork !=XFS_ATTR_FORK ) && +xfs_inode_has_forcealign (ip); end = start + len;if (!xfs_iext_lookup_extent_before (ip, ifp, &end, &icur, &got)) {
@@ -5490,11 +5507,10 @@ __xfs_bunmapi(if (del.br_startoff + del.br_blockcount > end +1 ) del.br_blockcount = end +1 - del.br_startoff; -if (!isrt || (flags &XFS_BMAPI_REMAP )) +if ((!isrt && !isforcealign) || (flags &XFS_BMAPI_REMAP )) goto delete; - mod =xfs_rtb_to_rtxoff (mp, - del.br_startblock + del.br_blockcount); + mod =xfs_bunmapi_align (ip, del.br_startblock + del.br_blockcount);if (mod) {/* * Realtime extent not lined up at the end.
@@ -5542,9 +5558,16 @@ __xfs_bunmapi( goto nodelete; } - mod =xfs_rtb_to_rtxoff (mp, del.br_startblock); + mod =xfs_bunmapi_align (ip, del.br_startblock);if (mod) { -xfs_extlen_t off = mp->m_sb.sb_rextsize - mod; +xfs_extlen_t off; + +if (isforcealign) { + off = ip->i_extsize - mod; + }else { +ASSERT (isrt); + off = mp->m_sb.sb_rextsize - mod; + }/* * Realtime extent is lined up at the end but not
Signature · 1 line
2.31.1
Re: [PATCH v4 13/22] xfs: Unmap blocks according to forcealign
Quoted 19 lines · John Garry
For when forcealign is enabled, blocks in an inode need to be unmapped according to extent alignment, like what is already done for rtvol.
Signed-off-by John Garry <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)fs/xfs/libxfs/xfs_bmap.c +3
-0@@ -5380,6 +5380,20 @@ xfs_bmap_del_extent_real(return 0 ; } +static xfs_extlen_t +xfs_bunmapi_align( + struct xfs_inode *ip,
fs/xfs/libxfs/xfs_bmap.c xfs_bmap_del_extent_real( · line 5395
Quoted 10 lines
fs/xfs/libxfs/xfs_bmap.c +10
-0+ xfs_fsblock_t bno) +{ +if (xfs_inode_has_forcealign (ip)) { +if (is_power_of_2 (ip->i_extsize)) +return bno & (ip->i_extsize -1 ); +return do_div (bno, ip->i_extsize); + } +ASSERT (XFS_IS_REALTIME_INODE (ip)); +return xfs_rtb_to_rtxoff (ip->i_mount, bno); +}
This following updated version of xfs_bunmapi_align() seems to fix the issue reported in https://lore.kernel.org/linux-xfs/[email protected]/
static xfs_extlen_t
xfs_bunmapi_align(
struct xfs_inode *ip,
xfs_fsblock_t fsbno)
{
if (xfs_inode_has_forcealign(ip)) {
struct xfs_mount *mp = ip->i_mount;
xfs_agblock_t agbno = XFS_FSB_TO_AGBNO(mp, fsbno);
if (is_power_of_2(ip->i_extsize))
return agbno & (ip->i_extsize - 1);
return do_div(agbno, ip->i_extsize);
}
ASSERT(XFS_IS_REALTIME_INODE(ip));
return xfs_rtb_to_rtxoff(ip->i_mount, fsbno);
}Quoted 54 lines
fs/xfs/libxfs/xfs_bmap.c +15
-5+/* * Unmap (remove) blocks from a file. * If nexts is nonzero then the number of extents to remove is limited to @@ -5402,6 +5416,7 @@ __xfs_bunmapi(struct xfs_bmbt_irec got;/* current extent record */ struct xfs_ifork *ifp;/* inode fork pointer */ int isrt;/* freeing in rt area */ +int isforcealign;/* freeing for inode with forcealign */ int logflags;/* transaction logging flags */ xfs_extlen_t mod;/* rt extent offset */ struct xfs_mount *mp = ip->i_mount;@@ -5439,6 +5454,8 @@ __xfs_bunmapi( }XFS_STATS_INC (mp, xs_blk_unmap); isrt =xfs_ifork_is_realtime (ip, whichfork); + isforcealign = (whichfork !=XFS_ATTR_FORK ) && +xfs_inode_has_forcealign (ip); end = start + len;if (!xfs_iext_lookup_extent_before (ip, ifp, &end, &icur, &got)) {@@ -5490,11 +5507,10 @@ __xfs_bunmapi(if (del.br_startoff + del.br_blockcount > end +1 ) del.br_blockcount = end +1 - del.br_startoff; -if (!isrt || (flags &XFS_BMAPI_REMAP )) +if ((!isrt && !isforcealign) || (flags &XFS_BMAPI_REMAP )) goto delete; - mod =xfs_rtb_to_rtxoff (mp, - del.br_startblock + del.br_blockcount); + mod =xfs_bunmapi_align (ip, del.br_startblock + del.br_blockcount);if (mod) {/* * Realtime extent not lined up at the end. @@ -5542,9 +5558,16 @@ __xfs_bunmapi( goto nodelete; } - mod =xfs_rtb_to_rtxoff (mp, del.br_startblock); + mod =xfs_bunmapi_align (ip, del.br_startblock);if (mod) { -xfs_extlen_t off = mp->m_sb.sb_rextsize - mod; +xfs_extlen_t off; + +if (isforcealign) { + off = ip->i_extsize - mod; + }else { +ASSERT (isrt); + off = mp->m_sb.sb_rextsize - mod; + }/* * Realtime extent is lined up at the end but not
PATCH v4 14/22 xfs: Only free full extents for forcealign
In reply to John GarryLike we already do for rtvol, only free full extents for forcealign in xfs_free_file_space().
--- fs/xfs/xfs_bmap_util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/xfs/xfs_bmap_util.c +5 -2
@@ -842,8 +842,11 @@ xfs_free_file_space( startoffset_fsb =XFS_B_TO_FSB (mp, offset); endoffset_fsb =XFS_B_TO_FSBT (mp, offset + len); -/* We can only free complete realtime extents. */ -if (xfs_inode_has_bigrtalloc (ip)) { +/* Free only complete extents. */ +if (xfs_inode_has_forcealign (ip)) { + startoffset_fsb =roundup_64 (startoffset_fsb, ip->i_extsize); + endoffset_fsb =rounddown_64 (endoffset_fsb, ip->i_extsize); + }else if (xfs_inode_has_bigrtalloc (ip)) { startoffset_fsb =xfs_rtb_roundup_rtx (mp, startoffset_fsb); endoffset_fsb =xfs_rtb_rounddown_rtx (mp, endoffset_fsb); }
Signature · 1 line
2.31.1
PATCH v4 15/22 xfs: Don't revert allocated offset for forcealign
In reply to John GarryIn xfs_bmap_process_allocated_extent(), for when we found that we could not provide the requested length completely, the mapping is moved so that we can provide as much as possible for the original request.
For forcealign, this would mean ignoring alignment guaranteed, so don't do this.
--- fs/xfs/libxfs/xfs_bmap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +8 -4
@@ -3492,11 +3492,15 @@ xfs_bmap_process_allocated_extent(* original request as possible. Free space is apparently * very fragmented so we're unlikely to be able to satisfy the * hints anyway. +* However, for an inode with forcealign, continue with the +* found offset as we need to honour the alignment hint. */ -if (ap->length <= orig_length) - ap->offset = orig_offset; -else if (ap->offset + ap->length < orig_offset + orig_length) - ap->offset = orig_offset + orig_length - ap->length; +if (!xfs_inode_has_forcealign (ap->ip)) { +if (ap->length <= orig_length) + ap->offset = orig_offset; +else if (ap->offset + ap->length < orig_offset + orig_length) + ap->offset = orig_offset + orig_length - ap->length; + }xfs_bmap_alloc_account (ap); }
Signature · 1 line
2.31.1
PATCH v4 16/22 xfs: Enable file data forcealign feature
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Enable this feature.
--- fs/xfs/libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_format.h +2 -1
@@ -358,7 +358,8 @@ xfs_sb_has_compat_feature( (XFS_SB_FEAT_RO_COMPAT_FINOBT | \XFS_SB_FEAT_RO_COMPAT_RMAPBT | \XFS_SB_FEAT_RO_COMPAT_REFLINK | \ - XFS_SB_FEAT_RO_COMPAT_INOBTCNT) +XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \ + XFS_SB_FEAT_RO_COMPAT_FORCEALIGN)#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALLstatic inline bool xfs_sb_has_ro_compat_feature(
Signature · 1 line
2.31.1
PATCH v4 17/22 fs: Add FS_XFLAG_ATOMICWRITES flag
In reply to John GarryAdd a flag indicating that a regular file is enabled for atomic writes.
This is a file attribute that mirrors an ondisk inode flag. Actual support for untorn file writes (for now) depends on both the iflag and the underlying storage devices, which we can only really check at statx and pwritev2() time. This is the same story as FS_XFLAG_DAX, which signals to the fs that we should try to enable the fsdax IO path on the file (instead of the regular page cache), but applications have to query STAT_ATTR_DAX to find out if they really got that IO path.
--- include/uapi/linux/fs.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/fs.h +1 -0
@@ -160,6 +160,7 @@ struct fsxattr {#define FS_XFLAG_COWEXTSIZE 0x00010000/* CoW extent size allocator hint */ /* data extent mappings for regular files must be aligned to extent size hint */ #define FS_XFLAG_FORCEALIGN 0x00020000 +#define FS_XFLAG_ATOMICWRITES 0x00040000/* atomic writes enabled */ #define FS_XFLAG_HASATTR 0x80000000/* no DIFLAG for this */ /* the read-only stuff doesn't really belong here, but any other place is
Signature · 1 line
2.31.1
PATCH v4 18/22 iomap: Atomic write support
In reply to John GarrySupport atomic writes by producing a single BIO with REQ_ATOMIC flag set.
We rely on the FS to guarantee extent alignment, such that an atomic write should never straddle two or more extents. The FS should also check for validity of an atomic write length/alignment.
--- fs/iomap/direct-io.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fs/iomap/direct-io.c +16 -2
@@ -256,7 +256,7 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,* clearing the WRITE_THROUGH flag in the dio request. */ static inline blk_opf_t iomap_dio_bio_opflags (struct iomap_dio *dio, -const struct iomap *iomap,bool use_fua) +const struct iomap *iomap,bool use_fua,bool is_atomic) {blk_opf_t opflags =REQ_SYNC |REQ_IDLE ;
@@ -268,6 +268,8 @@ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio, opflags |=REQ_FUA ; else dio->flags &= ~IOMAP_DIO_WRITE_THROUGH; +if (is_atomic) + opflags |=REQ_ATOMIC ;return opflags; }
@@ -275,6 +277,7 @@ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio,static loff_t iomap_dio_bio_iter (const struct iomap_iter *iter,struct iomap_dio *dio) { +bool is_atomic = dio->iocb->ki_flags &IOCB_ATOMIC ;const struct iomap *iomap = &iter->iomap;struct inode *inode = iter->inode;u64 io_block_size = iomap->io_block_size;
@@ -373,7 +376,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,* can set up the page vector appropriately for a ZONE_APPEND * operation. */ - bio_opf =iomap_dio_bio_opflags (dio, iomap, use_fua); + bio_opf =iomap_dio_bio_opflags (dio, iomap, use_fua, is_atomic); nr_pages =bio_iov_vecs_to_alloc (dio->submit.iter,BIO_MAX_VECS ); do {
@@ -406,6 +409,17 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, } n = bio->bi_iter.bi_size; +if (is_atomic && (n != orig_count)) { +/* +* This bio should have covered the complete length, +* which it doesn't, so error. We may need to zero out +* the tail, similar to when bio_iov_iter_get_pages() +* returns an error, above. +*/ + ret = -EINVAL ; +bio_put (bio); + goto zero_tail; + }if (dio->flags &IOMAP_DIO_WRITE ) {task_io_account_write (n); }else {
Signature · 1 line
2.31.1
PATCH v4 19/22 xfs: Support FS_XFLAG_ATOMICWRITES for forcealign
In reply to John GarryAdd initial support for FS_XFLAG_ATOMICWRITES for forcealign enabled.
Current kernel support for atomic writes is based on HW support (for atomic writes). As such, it is required to ensure extent alignment with atomic_write_unit_max so that an atomic write can result in a single HW-compliant IO operation.
rtvol also guarantees extent alignment, but we are basing support initially on forcealign, which is not supported for rtvol yet.
--- fs/xfs/libxfs/xfs_format.h | 11 ++++++-- fs/xfs/libxfs/xfs_inode_buf.c | 52 +++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_buf.h | 2 ++ fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_buf.c | 15 +++++++++- fs/xfs/xfs_buf.h | 4 ++- fs/xfs/xfs_buf_mem.c | 2 +- fs/xfs/xfs_inode.c | 9 ++++++ fs/xfs/xfs_inode.h | 5 ++++ fs/xfs/xfs_ioctl.c | 36 ++++++++++++++++++++++++ fs/xfs/xfs_mount.h | 2 ++ fs/xfs/xfs_super.c | 4 +++ 12 files changed, 139 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_format.h +9 -2
@@ -354,12 +354,16 @@ xfs_sb_has_compat_feature(#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ #define XFS_SB_FEAT_RO_COMPAT_FORCEALIGN (1 << 30)/* aligned file data extents */ +#define XFS_SB_FEAT_RO_COMPAT_ATOMICWRITES (1 << 31)/* atomicwrites enabled */ +#define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ XFS_SB_FEAT_RO_COMPAT_REFLINK| \ XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \ - XFS_SB_FEAT_RO_COMPAT_FORCEALIGN) + XFS_SB_FEAT_RO_COMPAT_FORCEALIGN | \ + XFS_SB_FEAT_RO_COMPAT_ATOMICWRITES) +#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALLstatic inline bool xfs_sb_has_ro_compat_feature(
@@ -1098,6 +1102,7 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)#define XFS_DIFLAG2_NREXT64_BIT 4/* large extent counters */ /* data extent mappings for regular files must be aligned to extent size hint */ #define XFS_DIFLAG2_FORCEALIGN_BIT 5 +#define XFS_DIFLAG2_ATOMICWRITES_BIT 6#define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT)#define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT)
@@ -1105,10 +1110,12 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT)#define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT)#define XFS_DIFLAG2_FORCEALIGN (1 << XFS_DIFLAG2_FORCEALIGN_BIT) +#define XFS_DIFLAG2_ATOMICWRITES (1 << XFS_DIFLAG2_ATOMICWRITES_BIT)#define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_FORCEALIGN) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_FORCEALIGN | \ + XFS_DIFLAG2_ATOMICWRITES)static inline bool xfs_dinode_has_bigtime (const struct xfs_dinode *dip) {
fs/xfs/libxfs/xfs_inode_buf.c +52 -0
74 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_buf.h +2 -0
@@ -36,6 +36,8 @@ xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp,xfs_failaddr_t xfs_inode_validate_forcealign (struct xfs_mount *mp,uint32_t extsize,uint32_t cowextsize,uint16_t mode,uint16_t flags,uint64_t flags2); +xfs_failaddr_t xfs_inode_validate_atomicwrites (struct xfs_mount *mp, +uint32_t extsize,uint64_t flags2);static inline uint64_t xfs_inode_encode_bigtime (struct timespec64 tv) {
fs/xfs/libxfs/xfs_sb.c +2 -0
@@ -166,6 +166,8 @@ xfs_sb_version_to_features( features |=XFS_FEAT_INOBTCNT ;if (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_FORCEALIGN ) features |=XFS_FEAT_FORCEALIGN ; +if (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_ATOMICWRITES ) + features |=XFS_FEAT_ATOMICWRITES ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_FTYPE ) features |=XFS_FEAT_FTYPE ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_SPINODES )
fs/xfs/xfs_buf.c +14 -1
@@ -2060,6 +2060,8 @@ intxfs_init_buftarg ( struct xfs_buftarg *btp, size_t logical_sectorsize, + unsigned int awu_min, + unsigned int awu_max, const char *descr) {/* Set up device logical sector size mask */
@@ -2086,6 +2088,9 @@ xfs_init_buftarg( btp->bt_shrinker->scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker->private_data = btp;shrinker_register (btp->bt_shrinker); + + btp->bt_bdev_awu_min = awu_min; + btp->bt_bdev_awu_max = awu_max;return 0 ; out_destroy_io_count:
@@ -2102,6 +2107,7 @@ xfs_alloc_buftarg( {struct xfs_buftarg *btp;const struct dax_holder_operations *ops =NULL ; +unsigned int awu_min =0 , awu_max =0 ;#if defined(CONFIG_FS_DAX ) && defined(CONFIG_MEMORY_FAILURE ) ops = &xfs_dax_holder_operations;
@@ -2115,6 +2121,13 @@ xfs_alloc_buftarg( btp->bt_daxdev =fs_dax_get_by_bdev (btp->bt_bdev, &btp->bt_dax_part_off, mp, ops); +if (bdev_can_atomic_write (btp->bt_bdev)) { +struct request_queue *q =bdev_get_queue (btp->bt_bdev); + + awu_min =queue_atomic_write_unit_min_bytes (q); + awu_max =queue_atomic_write_unit_max_bytes (q); + } +/* * When allocating the buftargs we have not yet read the super block and * thus don't know the file system sector size yet.
@@ -2122,7 +2135,7 @@ xfs_alloc_buftarg(if (xfs_setsize_buftarg (btp,bdev_logical_block_size (btp->bt_bdev))) goto error_free;if (xfs_init_buftarg (btp,bdev_logical_block_size (btp->bt_bdev), - mp->m_super->s_id)) + awu_min, awu_max, mp->m_super->s_id)) goto error_free;return btp;
fs/xfs/xfs_buf.h +3 -1
@@ -124,6 +124,8 @@ struct xfs_buftarg {struct percpu_counter bt_io_count;struct ratelimit_state bt_ioerror_rl; +unsigned int bt_bdev_awu_min, bt_bdev_awu_max; +/* built-in cache, if we're not using the perag one */ struct xfs_buf_cache bt_cache[]; };
@@ -393,7 +395,7 @@ bool xfs_verify_magic16(struct xfs_buf *bp, __be16 dmagic);/* for xfs_buf_mem.c only: */ int xfs_init_buftarg (struct xfs_buftarg *btp,size_t logical_sectorsize, -const char *descr); +unsigned int awu_min,unsigned int awu_max,const char *descr);void xfs_destroy_buftarg (struct xfs_buftarg *btp);#endif /* __XFS_BUF_H__ */
fs/xfs/xfs_buf_mem.c +1 -1
@@ -93,7 +93,7 @@ xmbuf_alloc( btp->bt_meta_sectorsize =XMBUF_BLOCKSIZE ; btp->bt_meta_sectormask =XMBUF_BLOCKSIZE -1 ; - error =xfs_init_buftarg (btp,XMBUF_BLOCKSIZE , descr); + error =xfs_init_buftarg (btp,XMBUF_BLOCKSIZE ,0 ,0 , descr);if (error) goto out_bcache;
fs/xfs/xfs_inode.c +9 -0
@@ -610,6 +610,8 @@ xfs_ip2xflags( flags |=FS_XFLAG_COWEXTSIZE ;if (ip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ) flags |=FS_XFLAG_FORCEALIGN ; +if (ip->i_diflags2 &XFS_DIFLAG2_ATOMICWRITES ) + flags |=FS_XFLAG_ATOMICWRITES ; }if (xfs_inode_has_attr_fork (ip))
@@ -758,6 +760,13 @@ xfs_inode_inherit_flags2(if (failaddr) ip->i_diflags2 &= ~XFS_DIFLAG2_FORCEALIGN ; } + +if (ip->i_diflags2 &XFS_DIFLAG2_ATOMICWRITES ) { + failaddr =xfs_inode_validate_atomicwrites (ip->i_mount, + ip->i_extsize, ip->i_diflags2); +if (failaddr) + ip->i_diflags2 &= ~XFS_DIFLAG2_ATOMICWRITES ; + } }/*
fs/xfs/xfs_inode.h +5 -0
@@ -334,6 +334,11 @@ static inline bool xfs_inode_has_forcealign(struct xfs_inode *ip)return ip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ; } +static inline bool xfs_inode_has_atomicwrites (struct xfs_inode *ip) +{ +return ip->i_diflags2 &XFS_DIFLAG2_ATOMICWRITES ; +} +/* * Decide if this file is a realtime file whose data allocation unit is larger * than a single filesystem block.
fs/xfs/xfs_ioctl.c +36 -0
@@ -527,6 +527,8 @@ xfs_flags2diflags2( di_flags2 |=XFS_DIFLAG2_COWEXTSIZE ;if (xflags &FS_XFLAG_FORCEALIGN ) di_flags2 |=XFS_DIFLAG2_FORCEALIGN ; +if (xflags &FS_XFLAG_ATOMICWRITES ) + di_flags2 |=XFS_DIFLAG2_ATOMICWRITES ;return di_flags2; }
@@ -567,15 +569,45 @@ xfs_ioctl_setattr_forcealign(return 0 ; } +static int +xfs_ioctl_setattr_atomicwrites ( +struct xfs_inode *ip, +struct fileattr *fa, +struct xfs_buftarg *target) +{ +struct xfs_mount *mp = ip->i_mount; +struct xfs_sb *sbp = &mp->m_sb; + +if (!xfs_has_atomicwrites (mp)) +return -EINVAL ; + +if (!(fa->fsx_xflags &FS_XFLAG_FORCEALIGN )) +return -EINVAL ; + +if (!is_power_of_2 (fa->fsx_extsize)) +return -EINVAL ; + +/* bdev can actually support atomic writes range required */ +if (target->bt_bdev_awu_min > sbp->sb_blocksize) +return -EINVAL ; + +if (target->bt_bdev_awu_max < fa->fsx_extsize) +return -EINVAL ; + +return 0 ; +} +static int xfs_ioctl_setattr_xflags (struct xfs_trans *tp,struct xfs_inode *ip,struct fileattr *fa) { +struct xfs_buftarg *target =xfs_inode_buftarg (ip);struct xfs_mount *mp = ip->i_mount;bool rtflag = (fa->fsx_xflags &FS_XFLAG_REALTIME );bool forcealign = fa->fsx_xflags &FS_XFLAG_FORCEALIGN ; +bool atomicwrites = fa->fsx_xflags &FS_XFLAG_ATOMICWRITES ;uint64_t i_flags2;/* Can't change RT or forcealign flags if any extents are allocated. */
@@ -604,6 +636,10 @@ xfs_ioctl_setattr_xflags(if (forcealign && (xfs_ioctl_setattr_forcealign (ip, fa) <0 ))return -EINVAL ; +if (atomicwrites && + (xfs_ioctl_setattr_atomicwrites (ip, fa, target) <0 )) +return -EINVAL ; + ip->i_diflags =xfs_flags2diflags (ip, fa->fsx_xflags); ip->i_diflags2 = i_flags2;
fs/xfs/xfs_mount.h +2 -0
@@ -300,6 +300,7 @@ typedef struct xfs_mount {#define XFS_FEAT_NREXT64 (1ULL << 26)/* large extent counters */ #define XFS_FEAT_EXCHANGE_RANGE (1ULL << 27)/* exchange range */ #define XFS_FEAT_FORCEALIGN (1ULL << 28)/* aligned file data extents */ +#define XFS_FEAT_ATOMICWRITES (1ULL << 29)/* atomic writes support */ /* Mount features */ #define XFS_FEAT_NOATTR2 (1ULL << 48)/* disable attr2 creation */
@@ -387,6 +388,7 @@ __XFS_HAS_V4_FEAT(v3inodes, V3INODES) __XFS_HAS_V4_FEAT(crc, CRC) __XFS_HAS_V4_FEAT(pquotino, PQUOTINO) __XFS_HAS_FEAT(forcealign, FORCEALIGN) +__XFS_HAS_FEAT (atomicwrites,ATOMICWRITES )/* * Mount features
fs/xfs/xfs_super.c +4 -0
@@ -1725,6 +1725,10 @@ xfs_fs_fill_super(xfs_warn (mp,"EXPERIMENTAL forced data extent alignment feature in use. Use at your own risk!" ); +if (xfs_has_atomicwrites (mp)) +xfs_warn (mp, +"EXPERIMENTAL atomicwrites feature in use. Use at your own risk!" ); +if (xfs_has_reflink (mp)) {if (mp->m_sb.sb_rblocks) { xfs_alert(mp,
Signature · 1 line
2.31.1
PATCH v4 20/22 xfs: Support atomic write for statx
In reply to John GarrySupport providing info on atomic write unit min and max for an inode.
For simplicity, currently we limit the min at the FS block size, but a lower limit could be supported in future. This is required by iomap DIO.
The atomic write unit min and max is limited by the guaranteed extent alignment for the inode.
--- fs/xfs/xfs_iops.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
fs/xfs/xfs_iops.c +28 -0
@@ -563,6 +563,27 @@ xfs_stat_blksize(return PAGE_SIZE ; } +static void +xfs_get_atomic_write_attr ( +struct xfs_inode *ip, +unsigned int *unit_min, +unsigned int *unit_max) +{ +struct xfs_buftarg *target =xfs_inode_buftarg (ip); +struct xfs_mount *mp = ip->i_mount; +struct xfs_sb *sbp = &mp->m_sb; +unsigned int extsz_bytes =XFS_FSB_TO_B (mp, ip->i_extsize); + +if (!xfs_inode_has_atomicwrites (ip)) { + *unit_min =0 ; + *unit_max =0 ; +return ; + } + + *unit_min = sbp->sb_blocksize; + *unit_max =min (target->bt_bdev_awu_max, extsz_bytes); +} + STATIC int xfs_vn_getattr( struct mnt_idmap *idmap,
@@ -636,6 +657,13 @@ xfs_vn_getattr( stat->dio_mem_align =bdev_dma_alignment (bdev) +1 ; stat->dio_offset_align =bdev_logical_block_size (bdev); } +if (request_mask &STATX_WRITE_ATOMIC ) { +unsigned int unit_min, unit_max; + +xfs_get_atomic_write_attr (ip, &unit_min, &unit_max); +generic_fill_statx_atomic_writes (stat, + unit_min, unit_max); + } fallthrough;default : stat->blksize =xfs_stat_blksize (ip);
Signature · 1 line
2.31.1
PATCH v4 21/22 xfs: Validate atomic writes
In reply to John GarryValidate that an atomic write adheres to length/offset rules. Since we require extent alignment for atomic writes, this effectively also enforces that the BIO which iomap produces is aligned.
For an IOCB with IOCB_ATOMIC set to get as far as xfs_file_dio_write(), FMODE_CAN_ATOMIC_WRITE will need to be set for the file; for this, FORCEALIGN and also ATOMICWRITES flags would also need to be set for the inode.
--- fs/xfs/xfs_file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/xfs/xfs_file.c +10 -1
@@ -695,12 +695,21 @@ xfs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) { - struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); + struct inode *inode = file_inode(iocb->ki_filp); +struct xfs_inode *ip =XFS_I (inode);struct xfs_buftarg *target =xfs_inode_buftarg (ip);size_t count =iov_iter_count (from); +struct xfs_mount *mp = ip->i_mount;bool unaligned;u64 unitsize; +if (iocb->ki_flags &IOCB_ATOMIC ) { +if (!generic_atomic_write_valid_size (iocb->ki_pos, from, +i_blocksize (inode),XFS_FSB_TO_B (mp, ip->i_extsize))) { +return -EINVAL ; + } + } +/* direct I/O must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)return -EINVAL ;
Signature · 1 line
2.31.1
PATCH v4 22/22 xfs: Support setting FMODE_CAN_ATOMIC_WRITE
In reply to John GarryFor when an inode is enabled for atomic writes, set FMODE_CAN_ATOMIC_WRITE flag. Only direct IO is currently supported, so check for that also.
We rely on the block layer to reject atomic writes which exceed the bdev request_queue limits, so don't bother checking any such thing here.
--- fs/xfs/xfs_file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/xfs/xfs_file.c +14 -0
@@ -1172,6 +1172,18 @@ xfs_file_remap_range(return remapped >0 ? remapped : ret; } +static bool xfs_file_open_can_atomicwrite ( +struct inode *inode, +struct file *file) +{ +struct xfs_inode *ip =XFS_I (inode); + +if (!(file->f_flags &O_DIRECT )) +return false; + +return xfs_inode_has_atomicwrites (ip); +} + STATIC int xfs_file_open( struct inode *inode,
@@ -1180,6 +1192,8 @@ xfs_file_open(if (xfs_is_shutdown (XFS_M (inode->i_sb)))return -EIO ; file->f_mode |=FMODE_NOWAIT |FMODE_CAN_ODIRECT ; +if (xfs_file_open_can_atomicwrite (inode, file)) + file->f_mode |=FMODE_CAN_ATOMIC_WRITE ;return generic_file_open (inode, file); }
Signature · 1 line
2.31.1