Btrfs iomap
Subsystems (8)
v2 cover Btrfs iomap
This is an effort to use iomap for btrfs. This would keep most responsibility of page handling during writes in iomap code, hence code reduction. For CoW support, changes are needed in iomap code to make sure we perform a copy before the write.
This is in line with the discussion we had during adding dax support in btrfs.
Efforts on adding dax support have been put on hold until MM experts can come with a way of performing multiple mappings to a single page (primarily the TODO before dax_associate_entry()). While we are waiting on that we could add support for buffered writes in btrfs.
[1] https://github.com/goldwynr/linux/tree/btrfs-iomap
Signature · 30 lines
Goldwyn Changes since v1 - Added Direct I/O support - Remove PagePrivate from btrfs pages for regular files fs/btrfs/Makefile | 2 fs/btrfs/compression.c | 1 fs/btrfs/ctree.h | 15 - fs/btrfs/extent_io.c | 13 fs/btrfs/extent_io.h | 2 fs/btrfs/file.c | 520 -------------------------------------- fs/btrfs/free-space-cache.c | 1 fs/btrfs/inode.c | 170 +++--------- fs/btrfs/ioctl.c | 4 fs/btrfs/iomap.c | 600 +++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/relocation.c | 2 fs/dax.c | 8 fs/ext2/inode.c | 2 fs/ext4/inode.c | 2 fs/gfs2/bmap.c | 3 fs/iomap/apply.c | 5 fs/iomap/buffered-io.c | 28 +- fs/iomap/direct-io.c | 18 - fs/iomap/fiemap.c | 4 fs/iomap/seek.c | 4 fs/iomap/swapfile.c | 3 fs/xfs/xfs_iomap.c | 9 include/linux/iomap.h | 7 23 files changed, 727 insertions(+), 696 deletions(-)
PATCH v2 1/13 iomap: Use a IOMAP_COW/srcmap for a read-modify-write I/O
From: Goldwyn Rodrigues <[email protected]>
Introduces a new type IOMAP_COW, which means the data at offset must be read from a srcmap and copied before performing the write on the offset.
The srcmap is used to identify where the read is to be performed from. This is passed to iomap->begin() of the respective filesystem, which is supposed to put in the details for reading before performing the copy for CoW.
--- fs/dax.c | 8 +++++--- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/gfs2/bmap.c | 3 ++- fs/iomap/apply.c | 5 +++-- fs/iomap/buffered-io.c | 14 +++++++------- fs/iomap/direct-io.c | 2 +- fs/iomap/fiemap.c | 4 ++-- fs/iomap/seek.c | 4 ++-- fs/iomap/swapfile.c | 3 ++- fs/xfs/xfs_iomap.c | 9 ++++++--- include/linux/iomap.h | 6 ++++-- 12 files changed, 36 insertions(+), 26 deletions(-)
fs/dax.c +5 -3
@@ -1090,7 +1090,7 @@ EXPORT_SYMBOL_GPL(__dax_zero_page_range);static loff_t dax_iomap_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct block_device *bdev = iomap->bdev;struct dax_device *dax_dev = iomap->dax_dev;
@@ -1248,6 +1248,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,unsigned long vaddr = vmf->address;loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;struct iomap iomap = {0 }; +struct iomap srcmap = {0 };unsigned flags =IOMAP_FAULT ;int error, major =0 ;bool write = vmf->flags &FAULT_FLAG_WRITE ;
@@ -1292,7 +1293,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,* the file system block size to be equal the page size, which means * that we never have to deal with more than a single extent here. */ - error = ops->iomap_begin (inode, pos,PAGE_SIZE , flags, &iomap); + error = ops->iomap_begin (inode, pos,PAGE_SIZE , flags, &iomap, &srcmap);if (iomap_errp) *iomap_errp = error;if (error) {
@@ -1472,6 +1473,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,struct inode *inode = mapping->host;vm_fault_t result =VM_FAULT_FALLBACK ;struct iomap iomap = {0 }; +struct iomap srcmap = {0 };pgoff_t max_pgoff;void *entry;loff_t pos;
@@ -1546,7 +1548,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,* to look up our filesystem block. */ pos = (loff_t )xas.xa_index <<PAGE_SHIFT ; - error = ops->iomap_begin (inode, pos,PMD_SIZE , iomap_flags, &iomap); + error = ops->iomap_begin (inode, pos,PMD_SIZE , iomap_flags, &iomap, &srcmap);if (error) goto unlock_entry;
fs/ext2/inode.c +1 -1
@@ -801,7 +801,7 @@ int ext2_get_block(struct inode *inode, sector_t iblock,#ifdef CONFIG_FS_DAX static int ext2_iomap_begin (struct inode *inode,loff_t offset,loff_t length, -unsigned flags,struct iomap *iomap) +unsigned flags,struct iomap *iomap,struct iomap *srcmap) {unsigned int blkbits = inode->i_blkbits;unsigned long first_block = offset >> blkbits;
fs/ext4/inode.c +1 -1
@@ -3453,7 +3453,7 @@ static bool ext4_inode_datasync_dirty(struct inode *inode) }static int ext4_iomap_begin (struct inode *inode,loff_t offset,loff_t length, -unsigned flags,struct iomap *iomap) +unsigned flags,struct iomap *iomap,struct iomap *srcmap) {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);unsigned int blkbits = inode->i_blkbits;
fs/gfs2/bmap.c +2 -1
@@ -1123,7 +1123,8 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, }static int gfs2_iomap_begin (struct inode *inode,loff_t pos,loff_t length, -unsigned flags,struct iomap *iomap) +unsigned flags,struct iomap *iomap, +struct iomap *srcmap) {struct gfs2_inode *ip =GFS2_I (inode);struct metapath mp = { .mp_aheight =1 , };
fs/iomap/apply.c +3 -2
@@ -24,6 +24,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, const struct iomap_ops *ops, void *data, iomap_actor_t actor) { struct iomap iomap = { 0 }; +struct iomap srcmap = {0 };loff_t written =0 , ret;/*
@@ -38,7 +39,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,* expose transient stale data. If the reserve fails, we can safely * back out at this point as there is nothing to undo. */ - ret = ops->iomap_begin (inode, pos, length, flags, &iomap); + ret = ops->iomap_begin (inode, pos, length, flags, &iomap, &srcmap);if (ret)return ret;if (WARN_ON (iomap.offset > pos))
@@ -58,7 +59,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,* we can do the copy-in page by page without having to worry about * failures exposing transient data. */ - written =actor (inode, pos, length, data, &iomap); + written =actor (inode, pos, length, data, &iomap, &srcmap);/* * Now the data has been copied, commit the range we've copied. This
fs/iomap/buffered-io.c +7 -7
@@ -205,7 +205,7 @@ iomap_read_inline_data(struct inode *inode, struct page *page,static loff_t iomap_readpage_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct iomap_readpage_ctx *ctx = data;struct page *page = ctx->cur_page;
@@ -351,7 +351,7 @@ iomap_next_page(struct inode *inode, struct list_head *pages, loff_t pos,static loff_t iomap_readpages_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {struct iomap_readpage_ctx *ctx = data;loff_t done, ret;
@@ -371,7 +371,7 @@ iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, ctx->cur_page_in_bio = false; } ret =iomap_readpage_actor (inode, pos + done, length - done, - ctx, iomap); + ctx, iomap, srcmap); }return done;
@@ -736,7 +736,7 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len,static loff_t iomap_write_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct iov_iter *i = data;long status =0 ;
@@ -853,7 +853,7 @@ __iomap_read_page(struct inode *inode, loff_t offset)static loff_t iomap_dirty_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {long status =0 ;ssize_t written =0 ;
@@ -942,7 +942,7 @@ static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,static loff_t iomap_zero_range_actor (struct inode *inode,loff_t pos,loff_t count, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {bool *did_zero = data;loff_t written =0 ;
@@ -1011,7 +1011,7 @@ EXPORT_SYMBOL_GPL(iomap_truncate_page);static loff_t iomap_page_mkwrite_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {struct page *page = data;int ret;
fs/iomap/direct-io.c +1 -1
@@ -362,7 +362,7 @@ iomap_dio_inline_actor(struct inode *inode, loff_t pos, loff_t length,static loff_t iomap_dio_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {struct iomap_dio *dio = data;
fs/iomap/fiemap.c +2 -2
@@ -44,7 +44,7 @@ static int iomap_to_fiemap(struct fiemap_extent_info *fi,static loff_t iomap_fiemap_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct fiemap_ctx *ctx = data;loff_t ret = length;
@@ -111,7 +111,7 @@ EXPORT_SYMBOL_GPL(iomap_fiemap);static loff_t iomap_bmap_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {sector_t *bno = data, addr;
fs/iomap/seek.c +2 -2
@@ -119,7 +119,7 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,static loff_t iomap_seek_hole_actor (struct inode *inode,loff_t offset,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {switch (iomap->type) {case IOMAP_UNWRITTEN :
@@ -165,7 +165,7 @@ EXPORT_SYMBOL_GPL(iomap_seek_hole);static loff_t iomap_seek_data_actor (struct inode *inode,loff_t offset,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {switch (iomap->type) {case IOMAP_HOLE :
fs/iomap/swapfile.c +2 -1
@@ -76,7 +76,8 @@ static int iomap_swapfile_add_extent(struct iomap_swapfile_info *isi)* distinction between written and unwritten extents. */ static loff_t iomap_swapfile_activate_actor (struct inode *inode,loff_t pos, -loff_t count,void *data,struct iomap *iomap) +loff_t count,void *data,struct iomap *iomap, +struct iomap *srcmap) {struct iomap_swapfile_info *isi = data;int error;
fs/xfs/xfs_iomap.c +6 -3
@@ -922,7 +922,8 @@ xfs_file_iomap_begin(loff_t offset, loff_t length, unsigned flags, - struct iomap *iomap) + struct iomap *iomap, + struct iomap *srcmap) { struct xfs_inode *ip = XFS_I(inode);struct xfs_mount *mp = ip->i_mount;
@@ -1145,7 +1146,8 @@ xfs_seek_iomap_begin(loff_t offset, loff_t length, unsigned flags, - struct iomap *iomap) + struct iomap *iomap, + struct iomap *srcmap) { struct xfs_inode *ip = XFS_I(inode);struct xfs_mount *mp = ip->i_mount;
@@ -1231,7 +1233,8 @@ xfs_xattr_iomap_begin(loff_t offset, loff_t length, unsigned flags, - struct iomap *iomap) + struct iomap *iomap, + struct iomap *srcmap) { struct xfs_inode *ip = XFS_I(inode);struct xfs_mount *mp = ip->i_mount;
include/linux/iomap.h +4 -2
@@ -26,6 +26,7 @@ struct vm_fault;#define IOMAP_MAPPED 0x03/* blocks allocated at @addr */ #define IOMAP_UNWRITTEN 0x04/* blocks allocated at @addr in unwritten state */ #define IOMAP_INLINE 0x05/* data inline in the inode */ +#define IOMAP_COW 0x06/* copy data from srcmap before writing */ /* * Flags for all iomap mappings:
@@ -110,7 +111,8 @@ struct iomap_ops {* The actual length is returned in iomap->length. */ int (*iomap_begin)(struct inode *inode,loff_t pos,loff_t length, -unsigned flags,struct iomap *iomap); +unsigned flags,struct iomap *iomap, +struct iomap *srcmap);/* * Commit and/or unreserve space previous allocated using iomap_begin.
@@ -126,7 +128,7 @@ struct iomap_ops {* Main iomap iterator function. */ typedef loff_t (*iomap_actor_t )(struct inode *inode,loff_t pos,loff_t len, -void *data,struct iomap *iomap); +void *data,struct iomap *iomap,struct iomap *srcmap); loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, const struct iomap_ops *ops, void *data,
Signature · 1 line
2.16.4
Re: [PATCH 01/13] iomap: Use a IOMAP_COW/srcmap for a read-modify-write I/O
Quoted 66 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Introduces a new type
IOMAP_COW, which means the data at offset must be read from a srcmap and copied before performing the write on the offset.The srcmap is used to identify where the read is to be performed from. This is passed to
iomap->begin()of the respective filesystem, which is supposed to put in the details for reading before performing the copy for CoW.Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/dax.c | 8 +++++--- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/gfs2/bmap.c | 3 ++- fs/iomap/apply.c | 5 +++-- fs/iomap/buffered-io.c | 14 +++++++------- fs/iomap/direct-io.c | 2 +- fs/iomap/fiemap.c | 4 ++-- fs/iomap/seek.c | 4 ++-- fs/iomap/swapfile.c | 3 ++- fs/xfs/xfs_iomap.c | 9 ++++++--- include/linux/iomap.h | 6 ++++-- 12 files changed, 36 insertions(+), 26 deletions(-)fs/dax.c +4
-2@@ -1090,7 +1090,7 @@ EXPORT_SYMBOL_GPL(__dax_zero_page_range);static loff_t dax_iomap_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct block_device *bdev = iomap->bdev;struct dax_device *dax_dev = iomap->dax_dev;@@ -1248,6 +1248,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,unsigned long vaddr = vmf->address;loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;struct iomap iomap = {0 }; +struct iomap srcmap = {0 };unsigned flags =IOMAP_FAULT ;int error, major =0 ;bool write = vmf->flags &FAULT_FLAG_WRITE ;@@ -1292,7 +1293,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,* the file system block size to be equal the page size, which means * that we never have to deal with more than a single extent here. */ - error = ops->iomap_begin (inode, pos,PAGE_SIZE , flags, &iomap); + error = ops->iomap_begin (inode, pos,PAGE_SIZE , flags, &iomap, &srcmap);if (iomap_errp) *iomap_errp = error;if (error) {@@ -1472,6 +1473,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,struct inode *inode = mapping->host;vm_fault_t result =VM_FAULT_FALLBACK ;struct iomap iomap = {0 }; +struct iomap srcmap = {0 };pgoff_t max_pgoff;void *entry;loff_t pos;
fs/dax.c static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, · line 1551
Quoted 5 lines
fs/dax.c +1
-1@@ -1546,7 +1548,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,* to look up our filesystem block. */ pos = (loff_t )xas.xa_index <<PAGE_SHIFT ; - error = ops->iomap_begin (inode, pos,PMD_SIZE , iomap_flags, &iomap); + error = ops->iomap_begin (inode, pos,PMD_SIZE , iomap_flags, &iomap, &srcmap);
/me wonders aloud if he ought to add a helper function to standardize at least some of validation of the iomap that gets returned from ->iomap_begin invocations...
Quoted 3 lines
fs/dax.c +0
-0if (error) goto unlock_entry;
<snip>
Quoted 13 lines
fs/iomap/apply.c +1
-0@@ -24,6 +24,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, const struct iomap_ops *ops, void *data, iomap_actor_t actor) { struct iomap iomap = { 0 }; +struct iomap srcmap = {0 };loff_t written =0 , ret;/*
fs/iomap/apply.c iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, · line 45
Quoted 8 lines
fs/iomap/apply.c +1
-1@@ -38,7 +39,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,* expose transient stale data. If the reserve fails, we can safely * back out at this point as there is nothing to undo. */ - ret = ops->iomap_begin (inode, pos, length, flags, &iomap); + ret = ops->iomap_begin (inode, pos, length, flags, &iomap, &srcmap);if (ret)return ret;if (WARN_ON (iomap.offset > pos))
...because I wonder if we ought to have a debugging assert here just in case an ->iomap_begin returns IOMAP_COW in response to an IOMAP_WRITE request? Basic sanity checks to catch accidental API misuse, etc.
Eh we probably ought to have a CONFIG_IOMAP_DEBUG so that non-developers don't necessarily have to pay the assert costs or something like that.
Quoted 136 lines
fs/iomap/apply.c +1
-1@@ -58,7 +59,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,* we can do the copy-in page by page without having to worry about * failures exposing transient data. */ - written =actor (inode, pos, length, data, &iomap); + written =actor (inode, pos, length, data, &iomap, &srcmap);/* * Now the data has been copied, commit the range we've copied. This fs/iomap/buffered-io.c +7
-7@@ -205,7 +205,7 @@ iomap_read_inline_data(struct inode *inode, struct page *page,static loff_t iomap_readpage_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct iomap_readpage_ctx *ctx = data;struct page *page = ctx->cur_page;@@ -351,7 +351,7 @@ iomap_next_page(struct inode *inode, struct list_head *pages, loff_t pos,static loff_t iomap_readpages_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {struct iomap_readpage_ctx *ctx = data;loff_t done, ret;@@ -371,7 +371,7 @@ iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, ctx->cur_page_in_bio = false; } ret =iomap_readpage_actor (inode, pos + done, length - done, - ctx, iomap); + ctx, iomap, srcmap); }return done;@@ -736,7 +736,7 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len,static loff_t iomap_write_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct iov_iter *i = data;long status =0 ;@@ -853,7 +853,7 @@ __iomap_read_page(struct inode *inode, loff_t offset)static loff_t iomap_dirty_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {long status =0 ;ssize_t written =0 ;@@ -942,7 +942,7 @@ static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,static loff_t iomap_zero_range_actor (struct inode *inode,loff_t pos,loff_t count, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {bool *did_zero = data;loff_t written =0 ;@@ -1011,7 +1011,7 @@ EXPORT_SYMBOL_GPL(iomap_truncate_page);static loff_t iomap_page_mkwrite_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {struct page *page = data;int ret;fs/iomap/direct-io.c +1
-1@@ -362,7 +362,7 @@ iomap_dio_inline_actor(struct inode *inode, loff_t pos, loff_t length,static loff_t iomap_dio_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {struct iomap_dio *dio = data;fs/iomap/fiemap.c +2
-2@@ -44,7 +44,7 @@ static int iomap_to_fiemap(struct fiemap_extent_info *fi,static loff_t iomap_fiemap_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct fiemap_ctx *ctx = data;loff_t ret = length;@@ -111,7 +111,7 @@ EXPORT_SYMBOL_GPL(iomap_fiemap);static loff_t iomap_bmap_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {sector_t *bno = data, addr;fs/iomap/seek.c +1
-2@@ -119,7 +119,7 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length,static loff_t iomap_seek_hole_actor (struct inode *inode,loff_t offset,loff_t length, -void *data,struct iomap *iomap) +void *data,struct iomap *iomap,struct iomap *srcmap) {switch (iomap->type) {case IOMAP_UNWRITTEN :@@ -165,7 +165,7 @@ EXPORT_SYMBOL_GPL(iomap_seek_hole);static loff_t iomap_seek_data_actor (struct inode *inode,loff_t offset,loff_t length, -void *data,struct iomap *iomap) switch (iomap->type) {case IOMAP_HOLE :fs/iomap/swapfile.c +0
-0
fs/iomap/swapfile.c static int iomap_swapfile_add_extent(struct iomap_swapfile_info *isi) · line 80
Quoted 6 lines
fs/iomap/swapfile.c +2
-1@@ -76,7 +76,8 @@ static int iomap_swapfile_add_extent(struct iomap_swapfile_info *isi)* distinction between written and unwritten extents. */ static loff_t iomap_swapfile_activate_actor (struct inode *inode,loff_t pos, -loff_t count,void *data,struct iomap *iomap) +loff_t count,void *data,struct iomap *iomap, +struct iomap *srcmap)
The switch(iomap->type) probably ought to have a separate printk for the IOMAP_COW case so that we don't go complaining about "unwritten" extents in the swap file.
Quoted 28 lines
fs/iomap/swapfile.c +0
-0{struct iomap_swapfile_info *isi = data;int error;fs/xfs/xfs_iomap.c +4
-2@@ -922,7 +922,8 @@ xfs_file_iomap_begin(loff_t offset, loff_t length, unsigned flags, - struct iomap *iomap) + struct iomap *iomap, + struct iomap *srcmap) { struct xfs_inode *ip = XFS_I(inode);struct xfs_mount *mp = ip->i_mount;@@ -1145,7 +1146,8 @@ xfs_seek_iomap_begin(loff_t offset, loff_t length, unsigned flags, - struct iomap *iomap) + struct iomap *iomap, + struct iomap *srcmap) { struct xfs_inode *ip = XFS_I(inode);struct xfs_mount *mp = ip->i_mount;
fs/xfs/xfs_iomap.c xfs_xattr_iomap_begin( · line 1240
Quoted 9 lines
fs/xfs/xfs_iomap.c +2
-1@@ -1231,7 +1233,8 @@ xfs_xattr_iomap_begin(loff_t offset, loff_t length, unsigned flags, - struct iomap *iomap) + struct iomap *iomap, + struct iomap *srcmap) { struct xfs_inode *ip = XFS_I(inode);struct xfs_mount *mp = ip->i_mount;
XFS part looks ok... I guess I'll get to Shiyuan's series next.
include/linux/iomap.h struct vm_fault; · line 29
Quoted 9 lines
include/linux/iomap.h +1
-0@@ -26,6 +26,7 @@ struct vm_fault;#define IOMAP_MAPPED 0x03/* blocks allocated at @addr */ #define IOMAP_UNWRITTEN 0x04/* blocks allocated at @addr in unwritten state */ #define IOMAP_INLINE 0x05/* data inline in the inode */ +#define IOMAP_COW 0x06/* copy data from srcmap before writing */
Hm, ok, at least the comment references that this is only for writes. Looks good!
--D
Quoted 25 lines
include/linux/iomap.h +3
-2/* * Flags for all iomap mappings: @@ -110,7 +111,8 @@ struct iomap_ops {* The actual length is returned in iomap->length. */ int (*iomap_begin)(struct inode *inode,loff_t pos,loff_t length, -unsigned flags,struct iomap *iomap); +unsigned flags,struct iomap *iomap, +struct iomap *srcmap);/* * Commit and/or unreserve space previous allocated using iomap_begin. @@ -126,7 +128,7 @@ struct iomap_ops {* Main iomap iterator function. */ typedef loff_t (*iomap_actor_t )(struct inode *inode,loff_t pos,loff_t len, -void *data,struct iomap *iomap); +void *data,struct iomap *iomap,struct iomap *srcmap); loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, const struct iomap_ops *ops, void *data,Signature · 1 line
2.16.4
Re: [PATCH 01/13] iomap: Use a IOMAP_COW/srcmap for a read-modify-write I/O
In reply to Goldwyn RodriguesQuoted 41 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Introduces a new type
IOMAP_COW, which means the data at offset must be read from a srcmap and copied before performing the write on the offset.The srcmap is used to identify where the read is to be performed from. This is passed to
iomap->begin()of the respective filesystem, which is supposed to put in the details for reading before performing the copy for CoW.Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/dax.c | 8 +++++--- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/gfs2/bmap.c | 3 ++- fs/iomap/apply.c | 5 +++-- fs/iomap/buffered-io.c | 14 +++++++------- fs/iomap/direct-io.c | 2 +- fs/iomap/fiemap.c | 4 ++-- fs/iomap/seek.c | 4 ++-- fs/iomap/swapfile.c | 3 ++- fs/xfs/xfs_iomap.c | 9 ++++++--- include/linux/iomap.h | 6 ++++-- 12 files changed, 36 insertions(+), 26 deletions(-)fs/dax.c +1
-1@@ -1090,7 +1090,7 @@ EXPORT_SYMBOL_GPL(__dax_zero_page_range);static loff_t dax_iomap_actor (struct inode *inode,loff_t pos,loff_t length,void *data, -struct iomap *iomap) +struct iomap *iomap,struct iomap *srcmap) {struct block_device *bdev = iomap->bdev;struct dax_device *dax_dev = iomap->dax_dev;
fs/dax.c static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, · line 1251
Quoted 4 lines
fs/dax.c +1
-0@@ -1248,6 +1248,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,unsigned long vaddr = vmf->address;loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;struct iomap iomap = {0 }; +struct iomap srcmap = {0 };
I'm not found of defining multiple iomaps everywhere and passing them explicitly to every function that might need them. Perhaps something like:
DEFINE_IOMAP(iomap);
#define IOMAP_BASE_MAP 0
#define IOMAP_SOURCE_MAP 1
#define IOMAP_MAX_MAPS 2
#define DEFINE_IOMAP(name) \
(struct iomap #name[IOMAP_MAX_MAPS] = {{0}})#define IOMAP_B(name) ((name)[IOMAP_BASE_MAP])
#define IOMAP_S(name) ((name)[IOMAP_SOURCE_MAP])
And now we only have to pass a single iomap parameter to each function as "struct iomap **iomap". This makes the code somewhat simpler, and we only ever need to use IOMAP_S(iomap) when IOMAP_B(iomap)->type == IOMAP_COW.
The other advantage of this is that if we even need new functionality that requires 2 (or more) iomaps, we don't have to change APIs again....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v2 2/13 iomap: Read page from srcmap for IOMAP_COW
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
In case of a IOMAP_COW, read a page from the srcmap before performing a write on the page.
--- fs/iomap/buffered-io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/iomap/buffered-io.c +8 -6
@@ -581,7 +581,7 @@ __iomap_write_begin(struct inode *inode, loff_t pos, unsigned len,static int iomap_write_begin (struct inode *inode,loff_t pos,unsigned len,unsigned flags, -struct page **pagep,struct iomap *iomap) +struct page **pagep,struct iomap *iomap,struct iomap *srcmap) {const struct iomap_page_ops *page_ops = iomap->page_ops;pgoff_t index = pos >>PAGE_SHIFT ;
@@ -607,6 +607,8 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,if (iomap->type ==IOMAP_INLINE )iomap_read_inline_data (inode, page, iomap); +else if (iomap->type ==IOMAP_COW ) + status =__iomap_write_begin (inode, pos, len, page, srcmap);else if (iomap->flags &IOMAP_F_BUFFER_HEAD ) status =__block_write_begin_int (page, pos, len,NULL , iomap);else
@@ -772,7 +774,7 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, } status =iomap_write_begin (inode, pos, bytes, flags, &page, - iomap); + iomap, srcmap);if (unlikely (status))break ;
@@ -871,7 +873,7 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,return PTR_ERR (rpage); status =iomap_write_begin (inode, pos, bytes, -AOP_FLAG_NOFS , &page, iomap); +AOP_FLAG_NOFS , &page, iomap, srcmap);put_page (rpage);if (unlikely (status))return status;
@@ -917,13 +919,13 @@ iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,EXPORT_SYMBOL_GPL (iomap_file_dirty);static int iomap_zero (struct inode *inode,loff_t pos,unsigned offset, -unsigned bytes,struct iomap *iomap) +unsigned bytes,struct iomap *iomap,struct iomap *srcmap) {struct page *page;int status; status =iomap_write_begin (inode, pos, bytes,AOP_FLAG_NOFS , &page, - iomap); + iomap, srcmap);if (status)return status;
@@ -961,7 +963,7 @@ iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,if (IS_DAX (inode)) status =iomap_dax_zero (pos, offset, bytes, iomap);else - status =iomap_zero (inode, pos, offset, bytes, iomap); + status =iomap_zero (inode, pos, offset, bytes, iomap, srcmap);if (status <0 )return status;
Signature · 1 line
2.16.4
Re: [PATCH 02/13] iomap: Read page from srcmap for IOMAP_COW
Quoted 4 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
In case of a
IOMAP_COW, read a page from the srcmap before performing a write on the page.
Looks ok, I think...
--D
Quoted 74 lines
Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/buffered-io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)fs/iomap/buffered-io.c +8
-6@@ -581,7 +581,7 @@ __iomap_write_begin(struct inode *inode, loff_t pos, unsigned len,static int iomap_write_begin (struct inode *inode,loff_t pos,unsigned len,unsigned flags, -struct page **pagep,struct iomap *iomap) +struct page **pagep,struct iomap *iomap,struct iomap *srcmap) {const struct iomap_page_ops *page_ops = iomap->page_ops;pgoff_t index = pos >>PAGE_SHIFT ;@@ -607,6 +607,8 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,if (iomap->type ==IOMAP_INLINE )iomap_read_inline_data (inode, page, iomap); +else if (iomap->type ==IOMAP_COW ) + status =__iomap_write_begin (inode, pos, len, page, srcmap);else if (iomap->flags &IOMAP_F_BUFFER_HEAD ) status =__block_write_begin_int (page, pos, len,NULL , iomap);else @@ -772,7 +774,7 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, } status =iomap_write_begin (inode, pos, bytes, flags, &page, - iomap); + iomap, srcmap);if (unlikely (status))break ;@@ -871,7 +873,7 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,return PTR_ERR (rpage); status =iomap_write_begin (inode, pos, bytes, -AOP_FLAG_NOFS , &page, iomap); +AOP_FLAG_NOFS , &page, iomap, srcmap);put_page (rpage);if (unlikely (status))return status;@@ -917,13 +919,13 @@ iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,EXPORT_SYMBOL_GPL (iomap_file_dirty);static int iomap_zero (struct inode *inode,loff_t pos,unsigned offset, -unsigned bytes,struct iomap *iomap) +unsigned bytes,struct iomap *iomap,struct iomap *srcmap) {struct page *page;int status; status =iomap_write_begin (inode, pos, bytes,AOP_FLAG_NOFS , &page, - iomap); + iomap, srcmap);if (status)return status;@@ -961,7 +963,7 @@ iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,if (IS_DAX (inode)) status =iomap_dax_zero (pos, offset, bytes, iomap);else - status =iomap_zero (inode, pos, offset, bytes, iomap); + status =iomap_zero (inode, pos, offset, bytes, iomap, srcmap);if (status <0 )return status;Signature · 1 line
2.16.4
Re: [PATCH 02/13] iomap: Read page from srcmap for IOMAP_COW
In reply to Goldwyn RodriguesQuoted 24 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
In case of a
IOMAP_COW, read a page from the srcmap before performing a write on the page.Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/buffered-io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)fs/iomap/buffered-io.c +1
-1@@ -581,7 +581,7 @@ __iomap_write_begin(struct inode *inode, loff_t pos, unsigned len,static int iomap_write_begin (struct inode *inode,loff_t pos,unsigned len,unsigned flags, -struct page **pagep,struct iomap *iomap) +struct page **pagep,struct iomap *iomap,struct iomap *srcmap) {const struct iomap_page_ops *page_ops = iomap->page_ops;pgoff_t index = pos >>PAGE_SHIFT ;
fs/iomap/buffered-io.c iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, · line 614
Quoted 8 lines
fs/iomap/buffered-io.c +2
-0@@ -607,6 +607,8 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,if (iomap->type ==IOMAP_INLINE )iomap_read_inline_data (inode, page, iomap); +else if (iomap->type ==IOMAP_COW ) + status =__iomap_write_begin (inode, pos, len, page, srcmap);else if (iomap->flags &IOMAP_F_BUFFER_HEAD ) status =__block_write_begin_int (page, pos, len,NULL , iomap);else
This looks busted w.r.t. IOMAP_F_BUFFER_HEAD. i.e. What's to stop someone returning iomap->type == IOMAP_COW, iomap->flags & IOMAP_F_BUFFER_HEAD?
In which case we can't call __iomap_write_begin(), right?
I'm with Darrick on CONFIG_IOMAP_DEBUG here - we need to start locking down invalid behaviour and invalid combinations with asserts that tell developers they've broken something.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v2 3/13 btrfs: Eliminate PagePrivate for btrfs data pages
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
While most of the code works just eliminating page's private field and related code, there is a problem when we are cloning. The extent assumes the data is uptodate. Clear the EXTENT_UPTODATE flag for the extent so the next time the file is read, it is forced to be read from the disk as opposed to pagecache.
This patch is required to make sure we don't conflict with iomap's usage of page->private.
--- fs/btrfs/compression.c | 1 - fs/btrfs/extent_io.c | 13 ------------- fs/btrfs/extent_io.h | 2 -- fs/btrfs/file.c | 1 - fs/btrfs/free-space-cache.c | 1 - fs/btrfs/inode.c | 15 +-------------- fs/btrfs/ioctl.c | 4 ++-- fs/btrfs/relocation.c | 2 -- 8 files changed, 3 insertions(+), 36 deletions(-)
fs/btrfs/compression.c +0 -1
@@ -481,7 +481,6 @@ static noinline int add_ra_bio_pages(struct inode *inode,* for these bytes in the file. But, we have to make * sure they map to this compressed extent on disk. */ -set_page_extent_mapped (page);lock_extent (tree, last_offset, end);read_lock (&em_tree->lock); em = lookup_extent_mapping(em_tree, last_offset,
fs/btrfs/extent_io.c +0 -13
@@ -3005,15 +3005,6 @@ static void attach_extent_buffer_page(struct extent_buffer *eb, } } -void set_page_extent_mapped (struct page *page) -{ -if (!PagePrivate (page)) { -SetPagePrivate (page); -get_page (page); -set_page_private (page,EXTENT_PAGE_PRIVATE ); - } -} -static struct extent_map * __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset, u64 start, u64 len, get_extent_t *get_extent,
@@ -3074,8 +3065,6 @@ static int __do_readpage(struct extent_io_tree *tree,size_t blocksize = inode->i_sb->s_blocksize;unsigned long this_bio_flag =0 ; -set_page_extent_mapped (page); -if (!PageUptodate (page)) {if (cleancache_get_page (page) ==0 ) {BUG_ON (blocksize !=PAGE_SIZE );
@@ -3589,8 +3578,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, pg_offset =0 ; -set_page_extent_mapped (page); -if (!epd->extent_locked) { ret =writepage_delalloc (inode, page, wbc, start, &nr_written);if (ret ==1 )
fs/btrfs/extent_io.h +0 -2
@@ -416,8 +416,6 @@ int extent_readpages(struct address_space *mapping, struct list_head *pages, unsigned nr_pages);int extent_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len); -void set_page_extent_mapped (struct page *page); -struct extent_buffer *alloc_extent_buffer (struct btrfs_fs_info *fs_info,u64 start); struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
fs/btrfs/file.c +0 -1
@@ -1539,7 +1539,6 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,* delalloc bits and dirty the pages as required. */ for (i =0 ; i < num_pages; i++) { -set_page_extent_mapped (pages[i]);WARN_ON (!PageLocked (pages[i])); }
fs/btrfs/free-space-cache.c +0 -1
@@ -395,7 +395,6 @@ static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, struct inode *inodefor (i =0 ; i < io_ctl->num_pages; i++) {clear_page_dirty_for_io (io_ctl->pages[i]); -set_page_extent_mapped (io_ctl->pages[i]); }return 0 ;
fs/btrfs/inode.c +1 -14
@@ -4932,7 +4932,6 @@ int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,wait_on_page_writeback (page);lock_extent_bits (io_tree, block_start, block_end, &cached_state); -set_page_extent_mapped (page); ordered =btrfs_lookup_ordered_extent (inode, block_start);if (ordered) {
@@ -8754,13 +8753,7 @@ btrfs_readpages(struct file *file, struct address_space *mapping,static int __btrfs_releasepage (struct page *page,gfp_t gfp_flags) { -int ret =try_release_extent_mapping (page, gfp_flags); -if (ret ==1 ) { -ClearPagePrivate (page); -set_page_private (page,0 ); -put_page (page); - } -return ret; +return try_release_extent_mapping (page, gfp_flags); }static int btrfs_releasepage (struct page *page,gfp_t gfp_flags)
@@ -8878,11 +8871,6 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, }ClearPageChecked (page); -if (PagePrivate (page)) { -ClearPagePrivate (page); -set_page_private (page,0 ); -put_page (page); - } }/*
@@ -8961,7 +8949,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)wait_on_page_writeback (page);lock_extent_bits (io_tree, page_start, page_end, &cached_state); -set_page_extent_mapped (page);/* * we can't set the delalloc bits if there are pending ordered
fs/btrfs/ioctl.c +2 -2
@@ -1355,7 +1355,6 @@ static int cluster_pages_for_defrag(struct inode *inode,for (i =0 ; i < i_done; i++) {clear_page_dirty_for_io (pages[i]);ClearPageChecked (pages[i]); -set_page_extent_mapped (pages[i]);set_page_dirty (pages[i]);unlock_page (pages[i]);put_page (pages[i]);
@@ -3550,6 +3549,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode,int ret;const u64 len = olen_aligned;u64 last_dest_end = destoff; +struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree; ret = -ENOMEM ; buf =kvmalloc (fs_info->nodesize,GFP_KERNEL );
@@ -3864,6 +3864,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode, destoff, olen, no_time_update); } +clear_extent_uptodate (tree, destoff, destoff+olen,NULL ); out:btrfs_free_path (path);kvfree (buf);
@@ -3935,7 +3936,6 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,truncate_inode_pages_range (&inode->i_data,round_down (destoff,PAGE_SIZE ),round_up (destoff + len,PAGE_SIZE ) -1 ); -return ret; }
fs/btrfs/relocation.c +0 -2
@@ -3300,8 +3300,6 @@ static int relocate_file_extent_cluster(struct inode *inode,lock_extent (&BTRFS_I (inode)->io_tree, page_start, page_end); -set_page_extent_mapped (page); -if (nr < cluster->nr && page_start + offset == cluster->boundary[nr]) { set_extent_bits(&BTRFS_I(inode)->io_tree,
Signature · 1 line
2.16.4
PATCH v2 4/13 btrfs: Add a simple buffered iomap write
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Introduce a new btrfs_iomap structure which contains information about the filesystem between the iomap_begin() and iomap_end() calls. This contains information about reservations and extent locking.
This one is a long patch. Most of the code is "inspired" by fs/btrfs/file.c. To keep the size small, all removals are in following patches.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 1 + fs/btrfs/file.c | 4 +- fs/btrfs/iomap.c | 381 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 385 insertions(+), 3 deletions(-) create mode 100644 fs/btrfs/iomap.c
fs/btrfs/Makefile +1 -1
@@ -11,7 +11,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \ - block-rsv.o delalloc-space.o + block-rsv.o delalloc-space.o iomap.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
fs/btrfs/ctree.h +1 -0
@@ -3247,6 +3247,7 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);loff_t btrfs_remap_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t len,unsigned int remap_flags); +size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +2 -2
@@ -1829,7 +1829,7 @@ static ssize_t __btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)return written; pos = iocb->ki_pos; - written_buffered =btrfs_buffered_write (iocb, from); + written_buffered =btrfs_buffered_iomap_write (iocb, from);if (written_buffered <0 ) { err = written_buffered; goto out;
@@ -1966,7 +1966,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,if (iocb->ki_flags &IOCB_DIRECT ) { num_written =__btrfs_direct_write (iocb, from); }else { - num_written =btrfs_buffered_write (iocb, from); + num_written =btrfs_buffered_iomap_write (iocb, from);if (num_written >0 ) iocb->ki_pos = pos + num_written;if (clean_page)
fs/btrfs/iomap.c new file +381 -0
381 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH 04/13] btrfs: Add a simple buffered iomap write
Quoted 9 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Introduce a new
btrfs_iomapstructure which contains information about the filesystem between theiomap_begin()andiomap_end()calls. This contains information about reservations and extent locking.This one is a long patch. Most of the code is "inspired" by
fs/btrfs/file.c. To keep the size small, all removals are in following patches.
I can't comment on the btrfs code but this:
fs/btrfs/iomap.c line 379
Quoted 10 lines
fs/btrfs/iomap.c new file +10
-0+size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from) +{ +ssize_t written; +struct inode *inode =file_inode (iocb->ki_filp); + written =iomap_file_buffered_write (iocb, from, &btrfs_buffered_iomap_ops); +if (written >0 ) + iocb->ki_pos += written; +if (iocb->ki_pos >i_size_read (inode)) +i_size_write (inode, iocb->ki_pos); +return written;
Looks like it fails to handle O_[D]SYNC writes.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 04/13] btrfs: Add a simple buffered iomap write
Quoted 13 lines · Dave Chinner
Quoted 9 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Introduce a new
btrfs_iomapstructure which contains information about the filesystem between theiomap_begin()andiomap_end()calls. This contains information about reservations and extent locking.This one is a long patch. Most of the code is "inspired" by
fs/btrfs/file.c. To keep the size small, all removals are in following patches.I can't comment on the btrfs code but this:
Quoted 13 lines
fs/btrfs/iomap.c line 379
Quoted 10 lines
fs/btrfs/iomap.c new file +10
-0+size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from) +{ +ssize_t written; +struct inode *inode =file_inode (iocb->ki_filp); + written =iomap_file_buffered_write (iocb, from, &btrfs_buffered_iomap_ops); +if (written >0 ) + iocb->ki_pos += written; +if (iocb->ki_pos >i_size_read (inode)) +i_size_write (inode, iocb->ki_pos); +return written;Looks like it fails to handle O_[D]SYNC writes.
It does in btrfs_file_write_iter(), which calls btrfs_buffered_iomap_write(). btrfs_file_write_iter() calls generic_write_sync().
Signature · 1 line
Goldwyn
PATCH v2 5/13 btrfs: Add CoW in iomap based writes
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Set iomap->type to IOMAP_COW and fill up the source map in case the I/O is not page aligned.
--- fs/btrfs/iomap.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
fs/btrfs/iomap.c +41 -0
@@ -165,6 +165,35 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode,return 0 ; } +/* +* get_iomap: Get the block map and fill the iomap structure +* @pos: file position +* @length: I/O length +* @iomap: The iomap structure to fill +*/ + +static int get_iomap (struct inode *inode,loff_t pos,loff_t length, +struct iomap *iomap) +{ +struct extent_map *em; + iomap->addr =IOMAP_NULL_ADDR ; + em =btrfs_get_extent (BTRFS_I (inode),NULL ,0 , pos, length,0 ); +if (IS_ERR (em)) +return PTR_ERR (em); +/* XXX Do we need to check for em->flags here? */ +if (em->block_start ==EXTENT_MAP_HOLE ) { + iomap->type =IOMAP_HOLE ; + }else { + iomap->addr = em->block_start; + iomap->type =IOMAP_MAPPED ; + } + iomap->offset = em->start; + iomap->bdev = em->bdev; + iomap->length = em->len; +free_extent_map (em); +return 0 ; +} +static void btrfs_buffered_page_done (struct inode *inode,loff_t pos,unsigned copied,struct page *page,struct iomap *iomap)
@@ -188,6 +217,7 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos,int ret;size_t write_bytes = length;struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +size_t end;size_t sector_offset = pos & (fs_info->sectorsize -1 );struct btrfs_iomap *bi;
@@ -255,6 +285,17 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, iomap->private = bi; iomap->length =round_up (write_bytes, fs_info->sectorsize); iomap->offset =round_down (pos, fs_info->sectorsize); + end = pos + write_bytes; +/* Set IOMAP_COW if start/end is not page aligned */ +if (((pos & (PAGE_SIZE -1 )) || (end & (PAGE_SIZE -1 )))) { + iomap->type =IOMAP_COW ; + ret =get_iomap (inode, pos, length, srcmap); +if (ret <0 ) + goto release; + }else { + iomap->type =IOMAP_DELALLOC ; + } + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_DELALLOC ; iomap->bdev = fs_info->fs_devices->latest_bdev;
Signature · 1 line
2.16.4
Re: [PATCH 05/13] btrfs: Add CoW in iomap based writes
Quoted 4 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Set
iomap->typetoIOMAP_COWand fill up the source map in case the I/O is not page aligned.
.....
Quoted 12 lines
static void btrfs_buffered_page_done(struct inode *inode,
loff_tpos,fs/btrfs/iomap.c +1
-0unsigned copied, struct page *page, struct iomap *iomap)@@ -188,6 +217,7 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos,int ret;size_t write_bytes = length;struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +size_t end;size_t sector_offset = pos & (fs_info->sectorsize -1 );struct btrfs_iomap *bi;
fs/btrfs/iomap.c static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, · line 294
Quoted 10 lines
fs/btrfs/iomap.c +7
-0@@ -255,6 +285,17 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, iomap->private = bi; iomap->length =round_up (write_bytes, fs_info->sectorsize); iomap->offset =round_down (pos, fs_info->sectorsize); + end = pos + write_bytes; +/* Set IOMAP_COW if start/end is not page aligned */ +if (((pos & (PAGE_SIZE -1 )) || (end & (PAGE_SIZE -1 )))) { + iomap->type =IOMAP_COW ; + ret =get_iomap (inode, pos, length, srcmap); +if (ret <0 ) + goto release;
I suspect you didn't test this case, because....
fs/btrfs/iomap.c static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, · line 300
Quoted 6 lines
fs/btrfs/iomap.c +4
-0+ }else { + iomap->type =IOMAP_DELALLOC ; + } + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_DELALLOC ;
The iomap->type is overwritten here and so IOMAP_COW will never be seen by the iomap infrastructure...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 05/13] btrfs: Add CoW in iomap based writes
Quoted 31 lines · Dave Chinner
Quoted 4 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Set
iomap->typetoIOMAP_COWand fill up the source map in case the I/O is not page aligned......
Quoted 12 lines
static void btrfs_buffered_page_done(struct inode *inode,
loff_tpos,fs/btrfs/iomap.c +1
-0unsigned copied, struct page *page, struct iomap *iomap)@@ -188,6 +217,7 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos,int ret;size_t write_bytes = length;struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +size_t end;size_t sector_offset = pos & (fs_info->sectorsize -1 );struct btrfs_iomap *bi;fs/btrfs/iomap.c static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, · line 294
Quoted 10 lines
fs/btrfs/iomap.c +7
-0@@ -255,6 +285,17 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, iomap->private = bi; iomap->length =round_up (write_bytes, fs_info->sectorsize); iomap->offset =round_down (pos, fs_info->sectorsize); + end = pos + write_bytes; +/* Set IOMAP_COW if start/end is not page aligned */ +if (((pos & (PAGE_SIZE -1 )) || (end & (PAGE_SIZE -1 )))) { + iomap->type =IOMAP_COW ; + ret =get_iomap (inode, pos, length, srcmap); +if (ret <0 ) + goto release;I suspect you didn't test this case, because....
Quoted 9 lines
fs/btrfs/iomap.c static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, · line 300
Quoted 6 lines
fs/btrfs/iomap.c +4
-0+ }else { + iomap->type =IOMAP_DELALLOC ; + } + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_DELALLOC ;The
iomap->typeis overwritten here and soIOMAP_COWwill never be seen by the iomap infrastructure...
Yes, thats correct. I will fix this.
Signature · 1 line
Goldwyn
PATCH v2 6/13 btrfs: remove buffered write code made unnecessary
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Better done in a separate patch to keep the main patch short(er)
--- fs/btrfs/file.c | 463 -------------------------------------------------------- 1 file changed, 463 deletions(-)
fs/btrfs/file.c +0 -463
@@ -390,79 +390,6 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)return 0 ; } -/* simple helper to fault in pages and copy. This should go away -* and be replaced with calls into generic code. -*/ -static noinline int btrfs_copy_from_user(loff_t pos, size_t write_bytes, -struct page **prepared_pages, -struct iov_iter *i) -{ -size_t copied =0 ; -size_t total_copied =0 ; -int pg =0 ; -int offset =offset_in_page (pos); - -while (write_bytes >0 ) { -size_t count =min_t (size_t, -PAGE_SIZE - offset, write_bytes); -struct page *page = prepared_pages[pg]; -/* -* Copy data from userspace to the current page -*/ - copied =iov_iter_copy_from_user_atomic (page, i, offset, count); - -/* Flush processor's dcache for this page */ -flush_dcache_page (page); - -/* -* if we get a partial write, we can end up with -* partially up to date pages. These add -* a lot of complexity, so make sure they don't -* happen by forcing this copy to be retried. -* -* The rest of the btrfs_file_write code will fall -* back to page at a time copies after we return 0. -*/ -if (!PageUptodate (page) && copied < count) - copied =0 ; - -iov_iter_advance (i, copied); - write_bytes -= copied; - total_copied += copied; - -/* Return to btrfs_file_write_iter to fault page */ -if (unlikely (copied ==0 )) -break ; - -if (copied <PAGE_SIZE - offset) { - offset += copied; - }else { - pg++; - offset =0 ; - } - } -return total_copied; -} - -/* -* unlocks pages after btrfs_file_write is done with them -*/ -static void btrfs_drop_pages (struct page **pages,size_t num_pages) -{ -size_t i; -for (i =0 ; i < num_pages; i++) { -/* page checked is some magic around finding pages that -* have been modified without going through btrfs_set_page_dirty -* clear it here. There should be no need to mark the pages -* accessed as prepare_pages should have marked them accessed -* in prepare_pages via find_or_create_page() -*/ -ClearPageChecked (pages[i]); -unlock_page (pages[i]); -put_page (pages[i]); - } -} - static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, const u64 start, const u64 len,
@@ -1387,164 +1314,6 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,return 0 ; } -/* -* on error we return an unlocked page and the error value -* on success we return a locked page and 0 -*/ -static int prepare_uptodate_page (struct inode *inode, -struct page *page,u64 pos, -bool force_uptodate) -{ -int ret =0 ; - -if (((pos & (PAGE_SIZE -1 )) || force_uptodate) && - !PageUptodate (page)) { - ret =btrfs_readpage (NULL , page); -if (ret) -return ret; -lock_page (page); -if (!PageUptodate (page)) { -unlock_page (page); -return -EIO ; - } -if (page->mapping != inode->i_mapping) { -unlock_page (page); -return -EAGAIN ; - } - } -return 0 ; -} - -/* -* this just gets pages into the page cache and locks them down. -*/ -static noinline int prepare_pages(struct inode *inode, struct page **pages, -size_t num_pages,loff_t pos, -size_t write_bytes,bool force_uptodate) -{ -int i; -unsigned long index = pos >>PAGE_SHIFT ; -gfp_t mask =btrfs_alloc_write_mask (inode->i_mapping); -int err =0 ; -int faili; - -for (i =0 ; i < num_pages; i++) { -again: - pages[i] =find_or_create_page (inode->i_mapping, index + i, - mask | __GFP_WRITE); -if (!pages[i]) { - faili = i -1 ; - err = -ENOMEM ; - goto fail; - } - -if (i ==0 ) - err =prepare_uptodate_page (inode, pages[i], pos, - force_uptodate); -if (!err && i == num_pages -1 ) - err =prepare_uptodate_page (inode, pages[i], - pos + write_bytes, false); -if (err) { -put_page (pages[i]); -if (err == -EAGAIN ) { - err =0 ; - goto again; - } - faili = i -1 ; - goto fail; - } -wait_on_page_writeback (pages[i]); - } - -return 0 ; -fail: -while (faili >=0 ) { -unlock_page (pages[faili]); -put_page (pages[faili]); - faili--; - } -return err; - -} - -/* -* This function locks the extent and properly waits for data=ordered extents -* to finish before allowing the pages to be modified if need. -* -* The return value: -* 1 - the extent is locked -* 0 - the extent is not locked, and everything is OK -* -EAGAIN - need re-prepare the pages -* the other < 0 number - Something wrong happens -*/ -static noinline int -lock_and_cleanup_extent_if_need (struct btrfs_inode *inode,struct page **pages, -size_t num_pages,loff_t pos, -size_t write_bytes, -u64 *lockstart,u64 *lockend, -struct extent_state **cached_state) -{ -struct btrfs_fs_info *fs_info = inode->root->fs_info; -u64 start_pos; -u64 last_pos; -int i; -int ret =0 ; - - start_pos =round_down (pos, fs_info->sectorsize); - last_pos = start_pos - +round_up (pos + write_bytes - start_pos, - fs_info->sectorsize) -1 ; - -if (start_pos < inode->vfs_inode.i_size) { -struct btrfs_ordered_extent *ordered; - -lock_extent_bits (&inode->io_tree, start_pos, last_pos, - cached_state); - ordered =btrfs_lookup_ordered_range (inode, start_pos, - last_pos - start_pos +1 ); -if (ordered && - ordered->file_offset + ordered->len > start_pos && - ordered->file_offset <= last_pos) { -unlock_extent_cached (&inode->io_tree, start_pos, - last_pos, cached_state); -for (i =0 ; i < num_pages; i++) { -unlock_page (pages[i]); -put_page (pages[i]); - } -btrfs_start_ordered_extent (&inode->vfs_inode, - ordered,1 ); -btrfs_put_ordered_extent (ordered); -return -EAGAIN ; - } -if (ordered) -btrfs_put_ordered_extent (ordered); - - *lockstart = start_pos; - *lockend = last_pos; - ret =1 ; - } - -/* -* It's possible the pages are dirty right now, but we don't want -* to clean them yet because copy_from_user may catch a page fault -* and we might have to fall back to one page at a time. If that -* happens, we'll unlock these pages and we'd have a window where -* reclaim could sneak in and drop the once-dirty page on the floor -* without writing it. -* -* We have the pages locked and the extent range locked, so there's -* no way someone can start IO on any dirty pages in this range. -* -* We'll call btrfs_dirty_pages() later on, and that will flip around -* delalloc bits and dirty the pages as required. -*/ -for (i =0 ; i < num_pages; i++) { -WARN_ON (!PageLocked (pages[i])); - } - -return ret; -} - static noinline int check_can_nocow(struct btrfs_inode *inode, loff_t pos,size_t *write_bytes) {
@@ -1581,238 +1350,6 @@ static noinline int check_can_nocow(struct btrfs_inode *inode, loff_t pos,return ret; } -static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, -struct iov_iter *i) -{ -struct file *file = iocb->ki_filp; -loff_t pos = iocb->ki_pos; -struct inode *inode =file_inode (file); -struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); -struct btrfs_root *root =BTRFS_I (inode)->root; -struct page **pages =NULL ; -struct extent_state *cached_state =NULL ; -struct extent_changeset *data_reserved =NULL ; -u64 release_bytes =0 ; -u64 lockstart; -u64 lockend; -size_t num_written =0 ; -int nrptrs; -int ret =0 ; -bool only_release_metadata = false; -bool force_page_uptodate = false; - - nrptrs =min (DIV_ROUND_UP (iov_iter_count (i),PAGE_SIZE ), -PAGE_SIZE / (sizeof (struct page *))); - nrptrs =min (nrptrs, current->nr_dirtied_pause - current->nr_dirtied); - nrptrs =max (nrptrs,8 ); - pages =kmalloc_array (nrptrs,sizeof (struct page *),GFP_KERNEL ); -if (!pages) -return -ENOMEM ; - -while (iov_iter_count (i) >0 ) { -size_t offset =offset_in_page (pos); -size_t sector_offset; -size_t write_bytes =min (iov_iter_count (i), - nrptrs * (size_t )PAGE_SIZE - - offset); -size_t num_pages =DIV_ROUND_UP (write_bytes + offset, -PAGE_SIZE ); -size_t reserve_bytes; -size_t dirty_pages; -size_t copied; -size_t dirty_sectors; -size_t num_sectors; -int extents_locked; - -WARN_ON (num_pages > nrptrs); - -/* -* Fault pages before locking them in prepare_pages -* to avoid recursive lock -*/ -if (unlikely (iov_iter_fault_in_readable (i, write_bytes))) { - ret = -EFAULT ; -break ; - } - - sector_offset = pos & (fs_info->sectorsize -1 ); - reserve_bytes =round_up (write_bytes + sector_offset, - fs_info->sectorsize); - -extent_changeset_release (data_reserved); - ret =btrfs_check_data_free_space (inode, &data_reserved, pos, - write_bytes); -if (ret <0 ) { -if ((BTRFS_I (inode)->flags & (BTRFS_INODE_NODATACOW | -BTRFS_INODE_PREALLOC )) && -check_can_nocow (BTRFS_I (inode), pos, - &write_bytes) >0 ) { -/* -* For nodata cow case, no need to reserve -* data space. -*/ - only_release_metadata = true; -/* -* our prealloc extent may be smaller than -* write_bytes, so scale down. -*/ - num_pages =DIV_ROUND_UP (write_bytes + offset, -PAGE_SIZE ); - reserve_bytes =round_up (write_bytes + - sector_offset, - fs_info->sectorsize); - }else { -break ; - } - } - -WARN_ON (reserve_bytes ==0 ); - ret =btrfs_delalloc_reserve_metadata (BTRFS_I (inode), - reserve_bytes); -if (ret) { -if (!only_release_metadata) -btrfs_free_reserved_data_space (inode, - data_reserved, pos, - write_bytes); -else -btrfs_end_write_no_snapshotting (root); -break ; - } - - release_bytes = reserve_bytes; -again: -/* -* This is going to setup the pages array with the number of -* pages we want, so we don't really need to worry about the -* contents of pages from loop to loop -*/ - ret =prepare_pages (inode, pages, num_pages, - pos, write_bytes, - force_page_uptodate); -if (ret) { -btrfs_delalloc_release_extents (BTRFS_I (inode), - reserve_bytes, true); -break ; - } - - extents_locked =lock_and_cleanup_extent_if_need ( -BTRFS_I (inode), pages, - num_pages, pos, write_bytes, &lockstart, - &lockend, &cached_state); -if (extents_locked <0 ) { -if (extents_locked == -EAGAIN ) - goto again; -btrfs_delalloc_release_extents (BTRFS_I (inode), - reserve_bytes, true); - ret = extents_locked; -break ; - } - - copied =btrfs_copy_from_user (pos, write_bytes, pages, i); - - num_sectors =BTRFS_BYTES_TO_BLKS (fs_info, reserve_bytes); - dirty_sectors =round_up (copied + sector_offset, - fs_info->sectorsize); - dirty_sectors =BTRFS_BYTES_TO_BLKS (fs_info, dirty_sectors); - -/* -* if we have trouble faulting in the pages, fall -* back to one page at a time -*/ -if (copied < write_bytes) - nrptrs =1 ; - -if (copied ==0 ) { - force_page_uptodate = true; - dirty_sectors =0 ; - dirty_pages =0 ; - }else { - force_page_uptodate = false; - dirty_pages =DIV_ROUND_UP (copied + offset, -PAGE_SIZE ); - } - -if (num_sectors > dirty_sectors) { -/* release everything except the sectors we dirtied */ - release_bytes -= dirty_sectors << - fs_info->sb->s_blocksize_bits; -if (only_release_metadata) { -btrfs_delalloc_release_metadata (BTRFS_I (inode), - release_bytes, true); - }else { -u64 __pos; - - __pos =round_down (pos, - fs_info->sectorsize) + - (dirty_pages <<PAGE_SHIFT ); -btrfs_delalloc_release_space (inode, - data_reserved, __pos, - release_bytes, true); - } - } - - release_bytes =round_up (copied + sector_offset, - fs_info->sectorsize); - -if (copied >0 ) - ret =btrfs_dirty_pages (inode, pages, dirty_pages, - pos, copied, &cached_state); -if (extents_locked) -unlock_extent_cached (&BTRFS_I (inode)->io_tree, - lockstart, lockend, &cached_state); -btrfs_delalloc_release_extents (BTRFS_I (inode), reserve_bytes, - true); -if (ret) { -btrfs_drop_pages (pages, num_pages); -break ; - } - - release_bytes =0 ; -if (only_release_metadata) -btrfs_end_write_no_snapshotting (root); - -if (only_release_metadata && copied >0 ) { - lockstart =round_down (pos, - fs_info->sectorsize); - lockend =round_up (pos + copied, - fs_info->sectorsize) -1 ; - -set_extent_bit (&BTRFS_I (inode)->io_tree, lockstart, - lockend,EXTENT_NORESERVE ,NULL , -NULL ,GFP_NOFS ); - only_release_metadata = false; - } - -btrfs_drop_pages (pages, num_pages); - -cond_resched (); - -balance_dirty_pages_ratelimited (inode->i_mapping); -if (dirty_pages < (fs_info->nodesize >>PAGE_SHIFT ) +1 ) -btrfs_btree_balance_dirty (fs_info); - - pos += copied; - num_written += copied; - } - -kfree (pages); - -if (release_bytes) { -if (only_release_metadata) { -btrfs_end_write_no_snapshotting (root); -btrfs_delalloc_release_metadata (BTRFS_I (inode), - release_bytes, true); - }else { -btrfs_delalloc_release_space (inode, data_reserved, -round_down (pos, fs_info->sectorsize), - release_bytes, true); - } - } - -extent_changeset_free (data_reserved); -return num_written ? num_written : ret; -} -static ssize_t __btrfs_direct_write (struct kiocb *iocb,struct iov_iter *from) {struct file *file = iocb->ki_filp;
Signature · 1 line
2.16.4
PATCH v2 7/13 btrfs: basic direct read operation
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Add btrfs_dio_iomap_ops for iomap.begin() function. In order to accomodate dio reads, add a new function btrfs_file_read_iter() which would call btrfs_dio_iomap_read() for DIO reads and fallback to generic_file_read_iter otherwise.
--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/file.c | 10 +++++++++- fs/btrfs/iomap.c | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-)
fs/btrfs/ctree.h +2 -0
@@ -3247,7 +3247,9 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);loff_t btrfs_remap_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t len,unsigned int remap_flags); +/* iomap.c */ size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from); +ssize_t btrfs_dio_iomap_read (struct kiocb *iocb,struct iov_iter *to);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +9 -1
@@ -2839,9 +2839,17 @@ static int btrfs_file_open(struct inode *inode, struct file *filp)return generic_file_open (inode, filp); } +static ssize_t btrfs_file_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +if (iocb->ki_flags &IOCB_DIRECT ) +return btrfs_dio_iomap_read (iocb, to); + +return generic_file_read_iter (iocb, to); +} +const struct file_operations btrfs_file_operations = { .llseek = btrfs_file_llseek, - .read_iter = generic_file_read_iter, + .read_iter = btrfs_file_read_iter, .splice_read = generic_file_splice_read, .write_iter = btrfs_file_write_iter, .mmap = btrfs_file_mmap,
fs/btrfs/iomap.c +20 -0
@@ -420,3 +420,23 @@ size_t btrfs_buffered_iomap_write(struct kiocb *iocb, struct iov_iter *from)return written; } +static int btrfs_dio_iomap_begin (struct inode *inode,loff_t pos, +loff_t length,unsigned flags,struct iomap *iomap, +struct iomap *srcmap) +{ +return get_iomap (inode, pos, length, iomap); +} + +static const struct iomap_ops btrfs_dio_iomap_ops = { + .iomap_begin = btrfs_dio_iomap_begin, +}; + +ssize_t btrfs_dio_iomap_read (struct kiocb *iocb,struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret; +inode_lock_shared (inode); + ret =iomap_dio_rw (iocb, to, &btrfs_dio_iomap_ops,NULL ); +inode_unlock_shared (inode); +return ret; +}
Signature · 1 line
2.16.4
Re: [PATCH 07/13] btrfs: basic direct read operation
Quoted 33 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Add
btrfs_dio_iomap_opsforiomap.begin()function. In order to accomodate dio reads, add a new functionbtrfs_file_read_iter()which would callbtrfs_dio_iomap_read()for DIO reads and fallback togeneric_file_read_iterotherwise.Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/file.c | 10 +++++++++- fs/btrfs/iomap.c | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-)fs/btrfs/ctree.h +2
-0@@ -3247,7 +3247,9 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);loff_t btrfs_remap_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t len,unsigned int remap_flags); +/* iomap.c */ size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from); +ssize_t btrfs_dio_iomap_read (struct kiocb *iocb,struct iov_iter *to);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,fs/btrfs/file.c +0
-0
fs/btrfs/file.c static int btrfs_file_open(struct inode *inode, struct file *filp) · line 2845
Quoted 7 lines
fs/btrfs/file.c +4
-0@@ -2839,9 +2839,17 @@ static int btrfs_file_open(struct inode *inode, struct file *filp)return generic_file_open (inode, filp); } +static ssize_t btrfs_file_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +if (iocb->ki_flags &IOCB_DIRECT ) +return btrfs_dio_iomap_read (iocb, to);
No provision to fallback to bufferedIO read? Not sure from btrfs perspective,
but earlier generic_file_read_iter may fall through to bufferedIO read say in case where directIO could not be completed (returned 0 or less than the requested read bytes). Is it not required anymore in case of btrfs when we move to iomap infrastructure, to still fall back to bufferedIO read?
Correct me if I am missing anything here.
Quoted 39 lines
fs/btrfs/file.c +5
-1+ +return generic_file_read_iter (iocb, to); +} +const struct file_operations btrfs_file_operations = { .llseek = btrfs_file_llseek, - .read_iter = generic_file_read_iter, + .read_iter = btrfs_file_read_iter, .splice_read = generic_file_splice_read, .write_iter = btrfs_file_write_iter, .mmap = btrfs_file_mmap,fs/btrfs/iomap.c +20
-0@@ -420,3 +420,23 @@ size_t btrfs_buffered_iomap_write(struct kiocb *iocb, struct iov_iter *from)return written; } +static int btrfs_dio_iomap_begin (struct inode *inode,loff_t pos, +loff_t length,unsigned flags,struct iomap *iomap, +struct iomap *srcmap) +{ +return get_iomap (inode, pos, length, iomap); +} + +static const struct iomap_ops btrfs_dio_iomap_ops = { + .iomap_begin = btrfs_dio_iomap_begin, +}; + +ssize_t btrfs_dio_iomap_read (struct kiocb *iocb,struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret; +inode_lock_shared (inode); + ret =iomap_dio_rw (iocb, to, &btrfs_dio_iomap_ops,NULL ); +inode_unlock_shared (inode); +return ret; +}
Re: [PATCH 07/13] btrfs: basic direct read operation
Quoted 41 lines · RITESH HARJANI
Quoted 32 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
Add
btrfs_dio_iomap_opsforiomap.begin()function. In order to accomodate dio reads, add a new functionbtrfs_file_read_iter()which would callbtrfs_dio_iomap_read()for DIO reads and fallback togeneric_file_read_iterotherwise.Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/file.c | 10 +++++++++- fs/btrfs/iomap.c | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-)fs/btrfs/ctree.h +2
-0@@ -3247,7 +3247,9 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);loff_t btrfs_remap_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t len,unsigned int remap_flags); +/* iomap.c */ size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from); +ssize_t btrfs_dio_iomap_read (struct kiocb *iocb,struct iov_iter *to);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,fs/btrfs/file.c +0
-0fs/btrfs/file.c static int btrfs_file_open(struct inode *inode, struct file *filp) · line 2844
Quoted 6 lines
fs/btrfs/file.c +4
-0@@ -2839,9 +2839,17 @@ static int btrfs_file_open(struct inode *inode, struct file *filp)return generic_file_open (inode, filp); } +static ssize_t btrfs_file_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +if (iocb->ki_flags &IOCB_DIRECT ) +return btrfs_dio_iomap_read (iocb, to);
Quoted 9 lines
No provision to fallback to bufferedIO read? Not sure from btrfs perspective,
but earliergeneric_file_read_itermay fall through to bufferedIO read say in case where directIO could not be completed (returned 0 or less than the requested read bytes).
Is it not required anymore in case of btrfs when we move to iomap infrastructure, to still fall back to bufferedIO read?
Correct me if I am missing anything here.
No, you are right here. We should fallback to buffered reads in case of incomplete reads. Thanks for pointing it out. I will incorporate it in the next series.
Signature · 1 line
Goldwyn
PATCH v2 8/13 btrfs: Carve out btrfs_get_extent_map_write() out of btrfs_get_blocks_write()
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
This makes btrfs_get_extent_map_write() independent of Direct I/O code.
--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/inode.c | 40 +++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-)
fs/btrfs/ctree.h +2 -0
@@ -3172,6 +3172,8 @@ struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location, struct btrfs_path *path);struct inode *btrfs_iget (struct super_block *s,struct btrfs_key *location,struct btrfs_root *root,int *was_new); +int btrfs_get_extent_map_write (struct extent_map **map,struct buffer_head *bh, +struct inode *inode,u64 start,u64 len);struct extent_map *btrfs_get_extent (struct btrfs_inode *inode,struct page *page,size_t pg_offset,u64 start,u64 end,int create);
fs/btrfs/inode.c +27 -13
@@ -7592,11 +7592,10 @@ static int btrfs_get_blocks_direct_read(struct extent_map *em,return 0 ; } -static int btrfs_get_blocks_direct_write (struct extent_map **map, -struct buffer_head *bh_result, -struct inode *inode, -struct btrfs_dio_data *dio_data, -u64 start,u64 len) +int btrfs_get_extent_map_write (struct extent_map **map, +struct buffer_head *bh, +struct inode *inode, +u64 start,u64 len) {struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);struct extent_map *em = *map;
@@ -7650,22 +7649,38 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,*/ btrfs_free_reserved_data_space_noquota (inode, start, len); - goto skip_cow; +/* skip COW */ + goto out; } }/* this will cow the extent */ - len = bh_result->b_size; +if (bh) + len = bh->b_size;free_extent_map (em); *map = em =btrfs_new_extent_direct (inode, start, len); -if (IS_ERR (em)) { - ret =PTR_ERR (em); - goto out; - } +if (IS_ERR (em)) +return PTR_ERR (em); +out: +return ret; +} +static int btrfs_get_blocks_direct_write (struct extent_map **map, +struct buffer_head *bh_result, +struct inode *inode, +struct btrfs_dio_data *dio_data, +u64 start,u64 len) +{ +int ret; +struct extent_map *em; + + ret =btrfs_get_extent_map_write (map, bh_result, inode, + start, len); +if (ret <0 ) +return ret; + em = *map; len =min (len, em->len - (start - em->start)); -skip_cow: bh_result->b_blocknr = (em->block_start + (start - em->start)) >> inode->i_blkbits; bh_result->b_size = len;
@@ -7686,7 +7701,6 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map, dio_data->reserve -= len; dio_data->unsubmitted_oe_range_end = start + len; current->journal_info = dio_data; -out:return ret; }
Signature · 1 line
2.16.4
PATCH v2 9/13 btrfs: Rename __endio_write_update_ordered() to btrfs_update_ordered_extent()
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Since we will be calling from another file, use a
better name to declare it non-static
--- fs/btrfs/ctree.h | 7 +++++-- fs/btrfs/inode.c | 14 +++++--------- 2 files changed, 10 insertions(+), 11 deletions(-)
fs/btrfs/ctree.h +5 -2
@@ -3175,8 +3175,11 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,int btrfs_get_extent_map_write (struct extent_map **map,struct buffer_head *bh,struct inode *inode,u64 start,u64 len);struct extent_map *btrfs_get_extent (struct btrfs_inode *inode, -struct page *page,size_t pg_offset, -u64 start,u64 end,int create); +struct page *page,size_t pg_offset, +u64 start,u64 end,int create); +void btrfs_update_ordered_extent (struct inode *inode, +const u64 offset,const u64 bytes, +const bool uptodate);int btrfs_update_inode (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct inode *inode);
fs/btrfs/inode.c +5 -9
@@ -89,10 +89,6 @@ static struct extent_map *create_io_em(struct inode *inode, u64 start, u64 len, u64 ram_bytes, int compress_type, int type); -static void __endio_write_update_ordered (struct inode *inode, -const u64 offset,const u64 bytes, -const bool uptodate); -/* * Cleanup all submitted ordered extents in specified range to handle errors * from the btrfs_run_delalloc_range() callback.
@@ -133,7 +129,7 @@ static inline void btrfs_cleanup_ordered_extents(struct inode *inode, bytes -=PAGE_SIZE ; } -return __endio_write_update_ordered (inode, offset, bytes, false); +return btrfs_update_ordered_extent (inode, offset, bytes, false); }static int btrfs_dirty_inode (struct inode *inode);
@@ -8176,7 +8172,7 @@ static void btrfs_endio_direct_read(struct bio *bio)bio_put (bio); } -static void __endio_write_update_ordered (struct inode *inode, +void btrfs_update_ordered_extent (struct inode *inode,const u64 offset,const u64 bytes,const bool uptodate) {
@@ -8229,7 +8225,7 @@ static void btrfs_endio_direct_write(struct bio *bio)struct btrfs_dio_private *dip = bio->bi_private;struct bio *dio_bio = dip->dio_bio; -__endio_write_update_ordered (dip->inode, dip->logical_offset, +btrfs_update_ordered_extent (dip->inode, dip->logical_offset, dip->bytes, !bio->bi_status);kfree (dip);
@@ -8546,7 +8542,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, bio =NULL ; }else {if (write) -__endio_write_update_ordered (inode, +btrfs_update_ordered_extent (inode, file_offset, dio_bio->bi_iter.bi_size, false);
@@ -8686,7 +8682,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)*/ if (dio_data.unsubmitted_oe_range_start < dio_data.unsubmitted_oe_range_end) - __endio_write_update_ordered(inode, + btrfs_update_ordered_extent(inode, dio_data.unsubmitted_oe_range_start, dio_data.unsubmitted_oe_range_end - dio_data.unsubmitted_oe_range_start,
Signature · 1 line
2.16.4
PATCH v2 10/13 iomap: use a function pointer for dio submits
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to iomap_dio_submit_bio()
The correct place for submit_io() is not page_ops. Would it better to rename the structure to something like iomap_io_ops or put it directly under struct iomap?
--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)
fs/iomap/direct-io.c +11 -5
@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll);static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {atomic_inc (&dio->ref);
@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap,bio_set_polled (bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io (bio,file_inode (dio->iocb->ki_filp), + pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + } }static ssize_t iomap_dio_complete (struct iomap_dio *dio)
@@ -195,7 +201,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,get_page (page);__bio_add_page (bio, page, len,0 );bio_set_op_attrs (bio,REQ_OP_WRITE , flags); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); } static loff_t
@@ -301,11 +307,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,iov_iter_advance (dio->submit.iter, n); dio->size += n; - pos += n; copied += n; nr_pages =iov_iter_npages (&iter,BIO_MAX_PAGES ); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); + pos += n; }while (nr_pages);/*
include/linux/iomap.h +1 -0
@@ -92,6 +92,7 @@ struct iomap_page_ops { struct iomap *iomap);void (*page_done)(struct inode *inode,loff_t pos,unsigned copied,struct page *page,struct iomap *iomap); +dio_submit_t *submit_io; };/*
Signature · 1 line
2.16.4
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 5 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()
What /does/ btrfs_submit_direct do, anyway? Looks like it's a custom submission function that ... does something related to setting checksums? And, uh, RAID?
Quoted 3 lines
The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?
Seeing as the ->iomap_begin handler knows if the requested op is a buffered write or a direct write, what if we just declare a union of ops?
e.g.
struct iomap_page_ops;
struct iomap_directio_ops;
struct iomap {
<usual stuff>
union {
const struct iomap_page_ops *page_ops;
const struct iomap_directio_ops *directio_ops;
};
};--D
Quoted 72 lines
Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +11
-5@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll);static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap,bio_set_polled (bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io (bio,file_inode (dio->iocb->ki_filp), + pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + } }static ssize_t iomap_dio_complete (struct iomap_dio *dio)@@ -195,7 +201,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,get_page (page);__bio_add_page (bio, page, len,0 );bio_set_op_attrs (bio,REQ_OP_WRITE , flags); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); } static loff_t@@ -301,11 +307,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,iov_iter_advance (dio->submit.iter, n); dio->size += n; - pos += n; copied += n; nr_pages =iov_iter_npages (&iter,BIO_MAX_PAGES ); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); + pos += n; }while (nr_pages);/* include/linux/iomap.h +1
-0@@ -92,6 +92,7 @@ struct iomap_page_ops { struct iomap *iomap);void (*page_done)(struct inode *inode,loff_t pos,unsigned copied,struct page *page,struct iomap *iomap); +dio_submit_t *submit_io; };/* Signature · 1 line
2.16.4
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 10 lines · Darrick J. Wong
Quoted 5 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()What /does/
btrfs_submit_directdo, anyway? Looks like it's a custom submission function that ... does something related to setting checksums? And, uh, RAID?
Yes and yes.
Quoted 14 lines
Quoted 4 lines
The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?Seeing as the ->iomap_begin handler knows if the requested op is a buffered write or a direct write, what if we just declare a union of ops?
e.g.
struct
iomap_page_ops;
structiomap_directio_ops;
Quoted 7 lines
struct iomap {
<usual stuff>
union {
const struct iomap_page_ops *page_ops;
const struct iomap_directio_ops *directio_ops;
};
};Yes, that looks good. Thanks. I will incorporate it.
Quoted 84 lines
--D
Quoted 79 lines
Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +1
-1@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll );static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {fs/iomap/direct-io.c +7
-1atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, bio_set_polled(bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io (bio,file_inode (dio- >iocb->ki_filp), + pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + } }static
ssize_tiomap_dio_complete(struct iomap_dio *dio)fs/iomap/direct-io.c +1
-1@@ -195,7 +201,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,get_page (page );__bio_add_page (bio, page, len,0 );bio_set_op_attrs (bio,REQ_OP_WRITE , flags); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); }static
loff_tfs/iomap/direct-io.c +2
-2@@ -301,11 +307,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, iov_iter_advance(dio->submit.iter, n); dio->size += n; - pos += n; copied += n; nr_pages =iov_iter_npages (&iter,BIO_MAX_PAGES ); -iomap_dio_submit_bio (dio, iomap, bio); +iomap_dio_submit_bio (dio, iomap, bio, pos); + pos += n; }while (nr_pages);fs/iomap/direct-io.c +0
-0/* include/linux/iomap.h +1
-0@@ -92,6 +92,7 @@ struct iomap_page_ops { struct iomap *iomap);void (*page_done)(struct inode *inode,loff_t pos,unsigned copied,struct page *page,struct iomap *iomap); +dio_submit_t *submit_io; };/*
Signature · 1 line
2.16.4
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Goldwyn RodriguesQuoted 31 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +1
-1@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll);static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap,bio_set_polled (bio, dio->iocb);
fs/iomap/direct-io.c static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, · line 76
Quoted 10 lines
fs/iomap/direct-io.c +7
-1dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io (bio,file_inode (dio->iocb->ki_filp), + pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + }
I don't really like this at all. Apart from the fact it doesn't work with block device polling (RWF_HIPRI), the iomap architecture is supposed to resolve the file offset -> block device + LBA mapping completely up front and so all that remains to be done is build and submit the bio(s) to the block device.
What I see here is a hack to work around the fact that btrfs has implemented both file data transformations and device mapping layer functionality as a filesystem layer between file data bio building and device bio submission. And as the btrfs file data mapping (->iomap_begin) is completely unaware that there is further block mapping to be done before block device bio submission, any generic code that btrfs uses requires special IO submission hooks rather than just calling submit_bio().
I'm not 100% sure what the solution here is, but the one thing we must resist is turning the iomap code into a mess of custom hooks that only one filesystem uses. We've been taught this lesson time and time again - the iomap infrastructure exists because stuff like bufferheads and the old direct IO code ended up so full of special case code that it ossified and became unmodifiable and unmaintainable.
We do not want to go down that path again.
IMO, the iomap IO model needs to be restructured to support post-IO and pre-IO data verification/calculation/transformation operations so all the work that needs to be done at the inode/offset context level can be done in the iomap path before bio submission/after bio completion. This will allow infrastructure like fscrypt, data compression, data checksums, etc to be suported generically, not just by individual filesystems that provide a ->submit_io hook.
As for the btrfs needing to slice and dice bios for multiple devices? That should be done via a block device ->make_request function, not a custom hook in the iomap code.
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 41 lines · Dave Chinner
Quoted 40 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +1
-1@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll );static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {fs/iomap/direct-io.c +2
-1atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, bio_set_polled(bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io(bio, file_inode(dio- >iocb->ki_filp),
Quoted 8 lines
fs/iomap/direct-io.c static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, · line 76
Quoted 5 lines
fs/iomap/direct-io.c +5
-0+ pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + }I don't really like this at all. Apart from the fact it doesn't work with block device polling (
RWF_HIPRI), the iomap architecture is
That can be added, no? Should be relayed when we clone the bio.
Quoted 31 lines
supposed to resolve the file offset -> block device + LBA mapping completely up front and so all that remains to be done is build and submit the bio(s) to the block device.
What I see here is a hack to work around the fact that btrfs has implemented both file data transformations and device mapping layer functionality as a filesystem layer between file data bio building and device bio submission. And as the btrfs file data mapping (->iomap_begin) is completely unaware that there is further block mapping to be done before block device bio submission, any generic code that btrfs uses requires special IO submission hooks rather than just calling
submit_bio().I'm not 100% sure what the solution here is, but the one thing we must resist is turning the iomap code into a mess of custom hooks that only one filesystem uses. We've been taught this lesson time and time again - the iomap infrastructure exists because stuff like bufferheads and the old direct IO code ended up so full of special case code that it ossified and became unmodifiable and unmaintainable.
We do not want to go down that path again.
IMO, the iomap IO model needs to be restructured to support post-IO and pre-IO data verification/calculation/transformation operations so all the work that needs to be done at the inode/offset context level can be done in the iomap path before bio submission/after bio completion. This will allow infrastructure like fscrypt, data compression, data checksums, etc to be suported generically, not just by individual filesystems that provide a ->submit_io hook.
Quoted 3 lines
As for the btrfs needing to slice and dice bios for multiple devices? That should be done via a block device ->make_request function, not a custom hook in the iomap code.
btrfs differentiates the way how metadata and data is handled/replicated/stored. We would still need an entry point in the iomap code to handle the I/O submission.
Quoted 8 lines
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quoted 4 lines
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Sure. I am open to ideas. What are you proposing?
Signature · 1 line
Goldwyn
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 51 lines · Goldwyn Rodrigues
Quoted 41 lines · Dave Chinner
Quoted 40 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +1
-1@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll );static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {fs/iomap/direct-io.c +2
-1atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, bio_set_polled(bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io(bio, file_inode(dio- >iocb->ki_filp),Quoted 8 lines
fs/iomap/direct-io.c static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, · line 76
Quoted 5 lines
fs/iomap/direct-io.c +5
-0+ pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + }I don't really like this at all. Apart from the fact it doesn't work with block device polling (
RWF_HIPRI), the iomap architecture is
Quoted 1 line
That can be added, no? Should be relayed when we clone the bio.
No idea how that all is supposed to work when you split a single bio into multiple bios. I'm pretty sure the iomap code is broken for that case, too - Jens was silent on how to fix other than to say "it wasn't important so we didn't care to make sure it worked". So it's not clear to me exactly how block polling is supposed to work when a an IO needs to be split into multiple submissions...
Quoted 31 lines
Quoted 31 lines
supposed to resolve the file offset -> block device + LBA mapping completely up front and so all that remains to be done is build and submit the bio(s) to the block device.
What I see here is a hack to work around the fact that btrfs has implemented both file data transformations and device mapping layer functionality as a filesystem layer between file data bio building and device bio submission. And as the btrfs file data mapping (->iomap_begin) is completely unaware that there is further block mapping to be done before block device bio submission, any generic code that btrfs uses requires special IO submission hooks rather than just calling
submit_bio().I'm not 100% sure what the solution here is, but the one thing we must resist is turning the iomap code into a mess of custom hooks that only one filesystem uses. We've been taught this lesson time and time again - the iomap infrastructure exists because stuff like bufferheads and the old direct IO code ended up so full of special case code that it ossified and became unmodifiable and unmaintainable.
We do not want to go down that path again.
IMO, the iomap IO model needs to be restructured to support post-IO and pre-IO data verification/calculation/transformation operations so all the work that needs to be done at the inode/offset context level can be done in the iomap path before bio submission/after bio completion. This will allow infrastructure like fscrypt, data compression, data checksums, etc to be suported generically, not just by individual filesystems that provide a ->submit_io hook.
Quoted 7 lines
Quoted 3 lines
As for the btrfs needing to slice and dice bios for multiple devices? That should be done via a block device ->make_request function, not a custom hook in the iomap code.
btrfs differentiates the way how metadata and data is handled/replicated/stored. We would still need an entry point in the iomap code to handle the I/O submission.
This is a data IO path. How metadata is stored/replicated is irrelevant to this code path...
Quoted 7 lines
Quoted 7 lines
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quoted 6 lines
Quoted 4 lines
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Sure. I am open to ideas. What are you proposing?
That you think about how to normalise the btrfs IO path to fit into the standard iomap/blockdev model, rather than adding special hacks to iomap to allow an opaque, custom, IO model to be shoe-horned into the generic code.
For example, post-read validation requires end-io processing, whether it be encryption, decompression, CRC/T10 validation, etc. The iomap end-io completion has all the information needed to run these things, whether it be a callout to the filesystem for custom processing checking, or a generic "decrypt into supplied data page" sort of thing. These all need to be done in the same place, so we should have common support for this. And I suspect the iomap should also state in a flag that something like this is necessary (e.g. IOMAP_FL_ENCRYPTED indicates post-IO decryption needs to be run).
Similarly, on the IO submit side we have need for a pre-IO processing hook. That can be used to encrypt, compress, calculate data CRCs, do pre-IO COW processing (XFS requires a hook for this), etc.
These hooks are needed for for both buffered and direct IO, and they are needed for more filesystems than just btrfs. fscrypt will need them, XFS needs them, etc. So rather than hide data CRCs, compression, and encryption deep inside the btrfs code, pull it up into common layers that are called by the generic code. THis will leave with just the things like mirroring, raid, IO retries, etc below the iomap code, and that's all stuff that can be done behind a ->make_request function that is passed a bio...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 122 lines · Dave Chinner
Quoted 51 lines · Goldwyn Rodrigues
Quoted 41 lines · Dave Chinner
Quoted 40 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +1
-1@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll );static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {fs/iomap/direct-io.c +2
-1atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, bio_set_polled(bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io(bio, file_inode(dio- >iocb->ki_filp),Quoted 8 lines
fs/iomap/direct-io.c static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, · line 76
Quoted 5 lines
fs/iomap/direct-io.c +5
-0+ pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + }I don't really like this at all. Apart from the fact it doesn't work with block device polling (
RWF_HIPRI), the iomap architecture isQuoted 1 line
That can be added, no? Should be relayed when we clone the bio.
No idea how that all is supposed to work when you split a single bio into multiple bios. I'm pretty sure the iomap code is broken for that case, too - Jens was silent on how to fix other than to say "it wasn't important so we didn't care to make sure it worked". So it's not clear to me exactly how block polling is supposed to work when a an IO needs to be split into multiple submissions...
Quoted 31 lines
Quoted 31 lines
supposed to resolve the file offset -> block device + LBA mapping completely up front and so all that remains to be done is build and submit the bio(s) to the block device.
What I see here is a hack to work around the fact that btrfs has implemented both file data transformations and device mapping layer functionality as a filesystem layer between file data bio building and device bio submission. And as the btrfs file data mapping (->iomap_begin) is completely unaware that there is further block mapping to be done before block device bio submission, any generic code that btrfs uses requires special IO submission hooks rather than just calling
submit_bio().I'm not 100% sure what the solution here is, but the one thing we must resist is turning the iomap code into a mess of custom hooks that only one filesystem uses. We've been taught this lesson time and time again - the iomap infrastructure exists because stuff like bufferheads and the old direct IO code ended up so full of special case code that it ossified and became unmodifiable and unmaintainable.
We do not want to go down that path again.
IMO, the iomap IO model needs to be restructured to support post-IO and pre-IO data verification/calculation/transformation operations so all the work that needs to be done at the inode/offset context level can be done in the iomap path before bio submission/after bio completion. This will allow infrastructure like fscrypt, data compression, data checksums, etc to be suported generically, not just by individual filesystems that provide a ->submit_io hook.
Quoted 7 lines
Quoted 3 lines
As for the btrfs needing to slice and dice bios for multiple devices? That should be done via a block device ->make_request function, not a custom hook in the iomap code.
btrfs differentiates the way how metadata and data is handled/replicated/stored. We would still need an entry point in the iomap code to handle the I/O submission.
This is a data IO path. How metadata is stored/replicated is irrelevant to this code path...
Quoted 7 lines
Quoted 7 lines
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quoted 6 lines
Quoted 4 lines
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Sure. I am open to ideas. What are you proposing?
That you think about how to normalise the btrfs IO path to fit into the standard iomap/blockdev model, rather than adding special hacks to iomap to allow an opaque, custom, IO model to be shoe-horned into the generic code.
Quoted 9 lines
For example, post-read validation requires end-io processing, whether it be encryption, decompression, CRC/T10 validation, etc. The iomap end-io completion has all the information needed to run these things, whether it be a callout to the filesystem for custom processing checking, or a generic "decrypt into supplied data page" sort of thing. These all need to be done in the same place, so we should have common support for this. And I suspect the iomap should also state in a flag that something like this is necessary (e.g.
IOMAP_FL_ENCRYPTEDindicates post-IO decryption needs to be run).
Add some word to this topic, I think introducing a generic full approach to IOMAP for encryption, decompression, verification is hard to meet all filesystems, and seems unnecessary, especially data compression is involved.
Since the data decompression will expand the data, therefore the logical data size is not same as the physical data size:
1) IO submission should be applied to all physical data, but data decompression will be eventually applied to logical mapping. As for EROFS, it submits all physical pages with page->private points to management structure which maintain all logical pages as well for further decompression. And time-sharing approach is used to save the L2P mapping array in these allocated pages itself.
In addition, IOMAP also needs to consider fixed-sized output/input difference which is filesystem specific and I have no idea whether involveing too many code for each requirement is really good for IOMAP;
2) The post-read processing order is another negotiable stuff. Although there is no benefit to select verity->decrypt rather than decrypt->verity; but when compression is involved, the different orders could be selected by different filesystem users:
1. decrypt->verity->decompress
2. verity->decompress->decrypt
3. decompress->decrypt->verity
1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Thanks,
Gao Xiang
Quoted 21 lines
Similarly, on the IO submit side we have need for a pre-IO processing hook. That can be used to encrypt, compress, calculate data CRCs, do pre-IO COW processing (XFS requires a hook for this), etc.
These hooks are needed for for both buffered and direct IO, and they are needed for more filesystems than just btrfs. fscrypt will need them, XFS needs them, etc. So rather than hide data CRCs, compression, and encryption deep inside the btrfs code, pull it up into common layers that are called by the generic code. THis will leave with just the things like mirroring, raid, IO retries, etc below the iomap code, and that's all stuff that can be done behind a ->make_request function that is passed a bio...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 156 lines · Gao Xiang
Quoted 122 lines · Dave Chinner
Quoted 51 lines · Goldwyn Rodrigues
Quoted 41 lines · Dave Chinner
Quoted 40 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This helps filesystems to perform tasks on the bio while submitting for I/O. Since btrfs requires the position we are working on, pass pos to
iomap_dio_submit_bio()The correct place for
submit_io()is notpage_ops. Would it better to rename the structure to something likeiomap_io_opsor put it directly under struct iomap?Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/iomap/direct-io.c | 16 +++++++++++----- include/linux/iomap.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)fs/iomap/direct-io.c +1
-1@@ -59,7 +59,7 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)EXPORT_SYMBOL_GPL (iomap_dio_iopoll );static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap, -struct bio *bio) +struct bio *bio,loff_t pos) {fs/iomap/direct-io.c +2
-1atomic_inc (&dio->ref);@@ -67,7 +67,13 @@ static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, bio_set_polled(bio, dio->iocb); dio->submit.last_queue =bdev_get_queue (iomap->bdev); - dio->submit.cookie =submit_bio (bio); +if (iomap->page_ops && iomap->page_ops->submit_io) { + iomap->page_ops->submit_io(bio, file_inode(dio- >iocb->ki_filp),Quoted 8 lines
fs/iomap/direct-io.c static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap, · line 76
Quoted 5 lines
fs/iomap/direct-io.c +5
-0+ pos); + dio->submit.cookie =BLK_QC_T_NONE ; + }else { + dio->submit.cookie =submit_bio (bio); + }I don't really like this at all. Apart from the fact it doesn't work with block device polling (
RWF_HIPRI), the iomap architecture isQuoted 1 line
That can be added, no? Should be relayed when we clone the bio.
No idea how that all is supposed to work when you split a single bio into multiple bios. I'm pretty sure the iomap code is broken for that case, too - Jens was silent on how to fix other than to say "it wasn't important so we didn't care to make sure it worked". So it's not clear to me exactly how block polling is supposed to work when a an IO needs to be split into multiple submissions...
Quoted 31 lines
Quoted 31 lines
supposed to resolve the file offset -> block device + LBA mapping completely up front and so all that remains to be done is build and submit the bio(s) to the block device.
What I see here is a hack to work around the fact that btrfs has implemented both file data transformations and device mapping layer functionality as a filesystem layer between file data bio building and device bio submission. And as the btrfs file data mapping (->iomap_begin) is completely unaware that there is further block mapping to be done before block device bio submission, any generic code that btrfs uses requires special IO submission hooks rather than just calling
submit_bio().I'm not 100% sure what the solution here is, but the one thing we must resist is turning the iomap code into a mess of custom hooks that only one filesystem uses. We've been taught this lesson time and time again - the iomap infrastructure exists because stuff like bufferheads and the old direct IO code ended up so full of special case code that it ossified and became unmodifiable and unmaintainable.
We do not want to go down that path again.
IMO, the iomap IO model needs to be restructured to support post-IO and pre-IO data verification/calculation/transformation operations so all the work that needs to be done at the inode/offset context level can be done in the iomap path before bio submission/after bio completion. This will allow infrastructure like fscrypt, data compression, data checksums, etc to be suported generically, not just by individual filesystems that provide a ->submit_io hook.
Quoted 7 lines
Quoted 3 lines
As for the btrfs needing to slice and dice bios for multiple devices? That should be done via a block device ->make_request function, not a custom hook in the iomap code.
btrfs differentiates the way how metadata and data is handled/replicated/stored. We would still need an entry point in the iomap code to handle the I/O submission.
This is a data IO path. How metadata is stored/replicated is irrelevant to this code path...
Quoted 7 lines
Quoted 7 lines
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quoted 6 lines
Quoted 4 lines
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Sure. I am open to ideas. What are you proposing?
That you think about how to normalise the btrfs IO path to fit into the standard iomap/blockdev model, rather than adding special hacks to iomap to allow an opaque, custom, IO model to be shoe-horned into the generic code.
Quoted 9 lines
For example, post-read validation requires end-io processing, whether it be encryption, decompression, CRC/T10 validation, etc. The iomap end-io completion has all the information needed to run these things, whether it be a callout to the filesystem for custom processing checking, or a generic "decrypt into supplied data page" sort of thing. These all need to be done in the same place, so we should have common support for this. And I suspect the iomap should also state in a flag that something like this is necessary (e.g.
IOMAP_FL_ENCRYPTEDindicates post-IO decryption needs to be run).Add some word to this topic, I think introducing a generic full approach to IOMAP for encryption, decompression, verification is hard to meet all filesystems, and seems unnecessary, especially data compression is involved.
Since the data decompression will expand the data, therefore the logical data size is not same as the physical data size:
1) IO submission should be applied to all physical data, but data decompression will be eventually applied to logical mapping. As for EROFS, it submits all physical pages with
page->privatepoints to management structure which maintain all logical pages as well for further decompression. And time-sharing approach is used to save the L2P mapping array in these allocated pages itself.In addition, IOMAP also needs to consider fixed-sized output/input difference which is filesystem specific and I have no idea whether involveing too many code for each requirement is really good for IOMAP;
2) The post-read processing order is another negotiable stuff. Although there is no benefit to select
verity->decryptrather thandecrypt->verity; but when compression is involved, the different orders could be selected by different filesystem users:
Quoted 5 lines
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity
maybe "4. decrypt->decompress->verity" is useful as well.
some post-read processing operates on physical data size and the other post-read processing operates on logical data size.
Quoted 2 lines
1. and 2. could cause less computation since it processes
and less verify data IO as well.
Quoted 6 lines
compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Correct the above word, I mean "all I want to say is the pre/post process is so complicated", therefore a full generic approach for decryption, decompression, verification is hard.
Thanks,
Gao Xiang
Quoted 29 lines
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Thanks,
Gao XiangQuoted 21 lines
Similarly, on the IO submit side we have need for a pre-IO processing hook. That can be used to encrypt, compress, calculate data CRCs, do pre-IO COW processing (XFS requires a hook for this), etc.
These hooks are needed for for both buffered and direct IO, and they are needed for more filesystems than just btrfs. fscrypt will need them, XFS needs them, etc. So rather than hide data CRCs, compression, and encryption deep inside the btrfs code, pull it up into common layers that are called by the generic code. THis will leave with just the things like mirroring, raid, IO retries, etc below the iomap code, and that's all stuff that can be done behind a ->make_request function that is passed a bio...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Gao XiangQuoted 64 lines · Gao Xiang
Quoted 20 lines
Quoted 8 lines
Quoted 8 lines
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quoted 6 lines
Quoted 4 lines
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Sure. I am open to ideas. What are you proposing?
That you think about how to normalise the btrfs IO path to fit into the standard iomap/blockdev model, rather than adding special hacks to iomap to allow an opaque, custom, IO model to be shoe-horned into the generic code.
Quoted 9 lines
For example, post-read validation requires end-io processing, whether it be encryption, decompression, CRC/T10 validation, etc. The iomap end-io completion has all the information needed to run these things, whether it be a callout to the filesystem for custom processing checking, or a generic "decrypt into supplied data page" sort of thing. These all need to be done in the same place, so we should have common support for this. And I suspect the iomap should also state in a flag that something like this is necessary (e.g.
IOMAP_FL_ENCRYPTEDindicates post-IO decryption needs to be run).Add some word to this topic, I think introducing a generic full approach to IOMAP for encryption, decompression, verification is hard to meet all filesystems, and seems unnecessary, especially data compression is involved.
Since the data decompression will expand the data, therefore the logical data size is not same as the physical data size:
1) IO submission should be applied to all physical data, but data decompression will be eventually applied to logical mapping. As for EROFS, it submits all physical pages with
page->privatepoints to management structure which maintain all logical pages as well for further decompression. And time-sharing approach is used to save the L2P mapping array in these allocated pages itself.In addition, IOMAP also needs to consider fixed-sized output/input difference which is filesystem specific and I have no idea whether involveing too many code for each requirement is really good for IOMAP;
2) The post-read processing order is another negotiable stuff. Although there is no benefit to select
verity->decryptrather thandecrypt->verity; but when compression is involved, the different orders could be selected by different filesystem users:1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
Quoted 7 lines
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
FWIW, the only order that actually makes sense is decrypt->decompress->verity.
Decrypt before decompress, i.e. encrypt after compress, because only the plaintext can be compressible; the ciphertext isn't.
Verity last, on the original data, because otherwise the file hash that fs-verity reports would be specific to that particular inode on-disk and therefore would be useless for authenticating the file's user-visible contents.
[By "verity" I mean specifically fs-verity. Integrity-only block checksums are a different case; those can be done at any point, but doing them on the compressed data would make sense as then there would be less to checksum.
And yes, compression+encryption leaks information about the original data, so may not be advisable. My point is just that if the two are nevertheless combined, it only makes sense to compress the plaintext.]
- Eric
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Hi Eric,
Quoted 68 lines · Eric Biggers
Quoted 67 lines · Gao Xiang
Quoted 20 lines
Quoted 8 lines
Quoted 8 lines
That's why I don't like this hook - I think hiding data operations and/or custom bio manipulations in opaque filesystem callouts is completely the wrong approach to be taking. We need to do these things in a generic manner so that all filesystems (and block devices!) that use the iomap infrastructure can take advantage of them, not just one of them.
Quoted 6 lines
Quoted 4 lines
Quite frankly, I don't care if it takes more time and work up front, I'm tired of expedient hacks to merge code quickly repeatedly biting us on the arse and wasting far more time sorting out than we would have spent getting it right in the first place.
Sure. I am open to ideas. What are you proposing?
That you think about how to normalise the btrfs IO path to fit into the standard iomap/blockdev model, rather than adding special hacks to iomap to allow an opaque, custom, IO model to be shoe-horned into the generic code.
Quoted 9 lines
For example, post-read validation requires end-io processing, whether it be encryption, decompression, CRC/T10 validation, etc. The iomap end-io completion has all the information needed to run these things, whether it be a callout to the filesystem for custom processing checking, or a generic "decrypt into supplied data page" sort of thing. These all need to be done in the same place, so we should have common support for this. And I suspect the iomap should also state in a flag that something like this is necessary (e.g.
IOMAP_FL_ENCRYPTEDindicates post-IO decryption needs to be run).Add some word to this topic, I think introducing a generic full approach to IOMAP for encryption, decompression, verification is hard to meet all filesystems, and seems unnecessary, especially data compression is involved.
Since the data decompression will expand the data, therefore the logical data size is not same as the physical data size:
1) IO submission should be applied to all physical data, but data decompression will be eventually applied to logical mapping. As for EROFS, it submits all physical pages with
page->privatepoints to management structure which maintain all logical pages as well for further decompression. And time-sharing approach is used to save the L2P mapping array in these allocated pages itself.In addition, IOMAP also needs to consider fixed-sized output/input difference which is filesystem specific and I have no idea whether involveing too many code for each requirement is really good for IOMAP;
2) The post-read processing order is another negotiable stuff. Although there is no benefit to select
verity->decryptrather thandecrypt->verity; but when compression is involved, the different orders could be selected by different filesystem users:1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Quoted 6 lines
Quoted 4 lines
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.
I am not just talking about fsverity as you mentioned below.
Quoted 3 lines
Decrypt before decompress, i.e. encrypt after compress, because only the plaintext can be compressible; the ciphertext isn't.
There could be some potential users need partially decrypt/decompress, but that is minor. I don't want to talk about this detail in this topic.
Quoted 5 lines
Verity last, on the original data, because otherwise the file hash that fs-verity reports would be specific to that particular inode on-disk and therefore would be useless for authenticating the file's user-visible contents.
Quoted 7 lines
[By "verity" I mean specifically fs-verity. Integrity-only block checksums are a different case; those can be done at any point, but doing them on the compressed data would make sense as then there would be less to checksum.
And yes, compression+encryption leaks information about the original data, so may not be advisable. My point is just that if the two are nevertheless combined, it only makes sense to compress the plaintext.]
I cannot fully agree with your point. (I was not talking of fs-verity, it's a generic approach of verity approach.)
Considering we introduce a block-based verity solution for all on-disk data to EROFS later. It means all data/compressed data and metadata are already from a trusted source at least (like dm-verity).
Either verity->decompress or decompress->verity is safe since either decompression algotithms or verity algorithms are _deterministic_ and should be considered _bugfree_ therefore it should have one result.
And if you say decompression algorithm is untrusted because of bug or somewhat, I think verity algorithm as well. In other words, if we consider software/hardware bugs, we cannot trust any combination of results.
A advantage of verity->decompress over decompress->verity is that the verity data is smaller than decompress->verity, so
1) we can have less I/O for most I/O patterns;
and
2) we can consume less CPUs.
Take a step back, there are many compression algorithm in the user-space like apk or what ever, so the plaintext is in a relatively speaking. We cannot consider the data to end-user is absolutely right.
Thanks,
Gao Xiang
Quoted 2 lines
- Eric
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Eric BiggersQuoted 1 line · Eric Biggers
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.
*nod*
Especially once we get the inline encryption support for fscrypt so the storage layer can offload the encrypt/decrypt to hardware via the bio containing plaintext. That pretty much forces fscrypt to be the lowest layer of the filesystem transformation stack. This hardware offload capability also places lots of limits on what you can do with block-based verity layers below the filesystem. e.g. using dm-verity when you don't know if there's hardware encryption below or software encryption on top becomes problematic...
So really, from a filesystem and iomap perspective, What Eric says is the right - it's the only order that makes sense...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner david at fromorbit.com
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Hi Dave,
Quoted 14 lines · Dave Chinner
Quoted 1 line · Eric Biggers
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.*nod*
Especially once we get the inline encryption support for fscrypt so the storage layer can offload the encrypt/decrypt to hardware via the bio containing plaintext. That pretty much forces fscrypt to be the lowest layer of the filesystem transformation stack. This hardware offload capability also places lots of limits on what you can do with block-based verity layers below the filesystem. e.g. using dm-verity when you don't know if there's hardware encryption below or software encryption on top becomes problematic...
Quoted 2 lines
So really, from a filesystem and iomap perspective, What Eric says is the right - it's the only order that makes sense...
Don't be surprised there will be a decrypt/verity/decompress all-in-one hardware approach for such stuff. 30% random IO (no matter hardware or software approach) can be saved that is greatly helpful for user experience on embedded devices with too limited source.
and I really got a SHA256 CPU hardware bug years ago.
I don't want to talk more on tendency, it depends on real scenerio and user selection (server or embedded device).
For security consideration, these approaches are all the same level --- these approaches all from the same signed key and storage source, all transformation A->B->C or A->C->B are equal.
For bug-free, we can fuzzer compression/verity algorithms even the whole file-system stack. There is another case other than security consideration.
Thanks,
Gao Xiang
Quoted 7 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Dave ChinnerQuoted 5 lines · Dave Chinner
Quoted 1 line · Eric Biggers
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.*nod*
Quoted 8 lines
Especially once we get the inline encryption support for fscrypt so the storage layer can offload the encrypt/decrypt to hardware via the bio containing plaintext. That pretty much forces fscrypt to be the lowest layer of the filesystem transformation stack. This hardware offload capability also places lots of limits on what you can do with block-based verity layers below the filesystem. e.g. using dm-verity when you don't know if there's hardware encryption below or software encryption on top becomes problematic...
Add a word, I was just talking benefits between "decrypt->decompress-> verity" and "decrypt->verity->decompress", I think both forms are compatible with inline en/decryption. I don't care which level "decrypt" is at... But maybe some user cares. Am I missing something?
Thanks,
Gao Xiang
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 6 lines · Gao Xiang
Quoted 5 lines · Dave Chinner
Quoted 1 line · Eric Biggers
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.*nod*
Quoted 8 lines
Quoted 8 lines
Especially once we get the inline encryption support for fscrypt so the storage layer can offload the encrypt/decrypt to hardware via the bio containing plaintext. That pretty much forces fscrypt to be the lowest layer of the filesystem transformation stack. This hardware offload capability also places lots of limits on what you can do with block-based verity layers below the filesystem. e.g. using dm-verity when you don't know if there's hardware encryption below or software encryption on top becomes problematic...
...and I'm not talking of fs-verity, I personally think fs-verity is great. I am only talking about a generic stuff.
In order to know which level becomes problematic, there even could be another choice "decrypt->verity1->decompress->verity2" for such requirement (assuming verity1/2 themselves are absolutely bug-free), verity1 can be a strong merkle tree and verity2 is a weak form (just like a simple Adler-32/crc32 in compressed block), thus we can locate whether it's a decrypt or decompress bug.
Many compression algorithm containers already have such a weak form such as gzip algorithm, so there is no need to add such an extra step to postprocess.
and I have no idea which (decrypt->verity1->decompress->verity2 or decrypt->decompress->verity) is faster since verity2 is rather simple. However, if we use the only strong form in the end, there could be a lot of extra IO and expensive multiple-level computations if files are highly compressible.
On the other hand, such verity2 can be computed offline / avoided by fuzzer tools for read-only scenerios (for example, after building these images and do a full image verification with the given kernel) in order to make sure its stability (In any case, I'm talking about how to make those algorithms bug-free).
All I want to say is I think "decrypt->verity->decompress" is reasonable as well.
Thanks,
Gao Xiang
Quoted 9 lines
Add a word, I was just talking benefits between "decrypt->decompress-> verity" and "
decrypt->verity->decompress", I think both forms are compatible with inline en/decryption. I don't care which level "decrypt" is at... But maybe some user cares. Am I missing something?Thanks,
Gao Xiang
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 36 lines · Gao Xiang
Quoted 6 lines · Gao Xiang
Quoted 5 lines · Dave Chinner
Quoted 1 line · Eric Biggers
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.*nod*
Quoted 8 lines
Quoted 8 lines
Especially once we get the inline encryption support for fscrypt so the storage layer can offload the encrypt/decrypt to hardware via the bio containing plaintext. That pretty much forces fscrypt to be the lowest layer of the filesystem transformation stack. This hardware offload capability also places lots of limits on what you can do with block-based verity layers below the filesystem. e.g. using dm-verity when you don't know if there's hardware encryption below or software encryption on top becomes problematic...
...and I'm not talking of fs-verity, I personally think fs-verity is great. I am only talking about a generic stuff.
In order to know which level becomes problematic, there even could be another choice "
decrypt->verity1->decompress->verity2" for such requirement (assuming verity1/2 themselves are absolutely bug-free), verity1 can be a strong merkle tree and verity2 is a weak form (just like a simple Adler-32/crc32 in compressed block), thus we can locate whether it's a decrypt or decompress bug.Many compression algorithm containers already have such a weak form such as gzip algorithm, so there is no need to add such an extra step to postprocess.
and I have no idea which (
decrypt->verity1->decompress->verity2ordecrypt->decompress->verity) is faster since verity2 is rather simple. However, if we use the only strong form in the end, there could be a lot of extra IO and expensive multiple-level computations if files are highly compressible.
Quoted 8 lines
On the other hand, such verity2 can be computed offline / avoided by fuzzer tools for read-only scenerios (for example, after building these images and do a full image verification with the given kernel) in order to make sure its stability (In any case, I'm talking about how to make those algorithms bug-free).
All I want to say is I think "
decrypt->verity->decompress" is reasonable as well.
... And another fundamental concern is that if we don't verify earlier (I mean on-disk data), then untrusted data will be transformed (decompressed and even decrypted if no inline encryption) with risk, and it seems _vulnerable_ if such decrypt / decompress algorithms have _security issues_ (such as Buffer Overflow). It seems that it's less security than do verity earlier.
Thanks,
Gao Xiang
Quoted 13 lines
Thanks,
Gao XiangQuoted 9 lines
Add a word, I was just talking benefits between "decrypt->decompress-> verity" and "
decrypt->verity->decompress", I think both forms are compatible with inline en/decryption. I don't care which level "decrypt" is at... But maybe some user cares. Am I missing something?Thanks,
Gao Xiang
Matthew Wilcox
reviewerRe: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Eric BiggersQuoted 15 lines · Eric Biggers
Quoted 14 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Quoted 6 lines
Quoted 4 lines
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.
That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759
It looks like it'd be computationally expensive to do, but feasible.
Quoted 2 lines
Decrypt before decompress, i.e. encrypt after compress, because only the plaintext can be compressible; the ciphertext isn't.
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Hi Willy,
Quoted 21 lines · Matthew Wilcox
Quoted 20 lines · Eric Biggers
Quoted 18 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Quoted 7 lines
Quoted 1 line
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759It looks like it'd be computationally expensive to do, but feasible.
Yes, maybe someone cares where encrypt is at due to their system design.
and I thought over these days, I have to repeat my thought of verity again :( the meaningful order ought to be "decrypt->verity->decompress" rather than "decrypt->decompress->verity" if compression is involved.
since most (de)compress algorithms are complex enough (allocate memory and do a lot of unsafe stuffes such as wildcopy) and even maybe unsafe by its design, we cannot do verity in the end for security consideration thus the whole system can be vulnerable by this order from malformed on-disk data. In other words, we need to verify on compressed data.
Fsverity is fine for me since most decrypt algorithms is stable and reliable and no compression by its design, but if some decrypt software algorithms is complicated enough, I'd suggest "verity->decrypt" as well to some extent.
Considering transformation "A->B->C->D->....->verity", if any of "A->B->C ->D->..." is attacked by the malformed on-disk data... It would crash or even root the whole operating system.
All in all, we have to verify data earlier in order to get trusted data for later complex transformation chains.
The performance benefit I described in my previous email, it seems no need to say again... please take them into consideration and I think it's no easy to get a unique generic post-read order for all real systems.
Thanks,
Gao Xiang
Quoted 3 lines
Quoted 3 lines
Decrypt before decompress, i.e. encrypt after compress, because only the plaintext can be compressible; the ciphertext isn't.
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 52 lines · Gao Xiang
Hi Willy,
Quoted 21 lines · Matthew Wilcox
Quoted 20 lines · Eric Biggers
Quoted 18 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Quoted 7 lines
Quoted 1 line
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759It looks like it'd be computationally expensive to do, but feasible.
Yes, maybe someone cares where encrypt is at due to their system design.
and I thought over these days, I have to repeat my thought of verity again :( the meaningful order ought to be "
decrypt->verity->decompress" rather than "decrypt->decompress->verity" if compression is involved.since most (de)compress algorithms are complex enough (allocate memory and do a lot of unsafe stuffes such as wildcopy) and even maybe unsafe by its design, we cannot do verity in the end for security consideration thus the whole system can be vulnerable by this order from malformed on-disk data. In other words, we need to verify on compressed data.
Fsverity is fine for me since most decrypt algorithms is stable and reliable and no compression by its design, but if some decrypt software algorithms is complicated enough, I'd suggest "
verity->decrypt" as well to some extent.Considering transformation "A->B->C->D->....->verity", if any of "
A->B->C->D->..." is attacked by the malformed on-disk data... It would crash or even root the whole operating system.
Quoted 7 lines
All in all, we have to verify data earlier in order to get trusted data for later complex transformation chains.
The performance benefit I described in my previous email, it seems no need to say again... please take them into consideration and I think it's no easy to get a unique generic post-read order for all real systems.
While it would be nice to protect against filesystem bugs, it's not the point of fs-verity. fs-verity is about authenticating the contents the *user* sees, so that e.g. a file can be distributed to many computers and it can be authenticated regardless of exactly what other filesystem features were used when it was stored on disk. Different computers may use:
- Different filesystems
- Different compression algorithms (or no compression)
- Different compression strengths, even with same algorithm
- Different divisions of the file into compression units
- Different encryption algorithms (or no encryption)
- Different encryption keys, even with same algorithm
- Different encryption nonces, even with same key
All those change the on-disk data; only the user-visible data stays the same.
Bugs in filesystems may also be exploited regardless of fs-verity, as the attacker (able to manipulate on-disk image) can create a malicious file without fs-verity enabled, somewhere else on the filesystem.
If you actually want to authenticate the full filesystem image, you need to use dm-verity, which is designed for that.
- Eric
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 75 lines · Eric Biggers
Quoted 52 lines · Gao Xiang
Hi Willy,
Quoted 21 lines · Matthew Wilcox
Quoted 20 lines · Eric Biggers
Quoted 18 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Quoted 7 lines
Quoted 1 line
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759It looks like it'd be computationally expensive to do, but feasible.
Yes, maybe someone cares where encrypt is at due to their system design.
and I thought over these days, I have to repeat my thought of verity again :( the meaningful order ought to be "
decrypt->verity->decompress" rather than "decrypt->decompress->verity" if compression is involved.since most (de)compress algorithms are complex enough (allocate memory and do a lot of unsafe stuffes such as wildcopy) and even maybe unsafe by its design, we cannot do verity in the end for security consideration thus the whole system can be vulnerable by this order from malformed on-disk data. In other words, we need to verify on compressed data.
Fsverity is fine for me since most decrypt algorithms is stable and reliable and no compression by its design, but if some decrypt software algorithms is complicated enough, I'd suggest "
verity->decrypt" as well to some extent.Considering transformation "A->B->C->D->....->verity", if any of "
A->B->C->D->..." is attacked by the malformed on-disk data... It would crash or even root the whole operating system.Quoted 7 lines
All in all, we have to verify data earlier in order to get trusted data for later complex transformation chains.
The performance benefit I described in my previous email, it seems no need to say again... please take them into consideration and I think it's no easy to get a unique generic post-read order for all real systems.
While it would be nice to protect against filesystem bugs, it's not the point of fs-verity. fs-verity is about authenticating the contents the *user* sees, so that e.g. a file can be distributed to many computers and it can be authenticated regardless of exactly what other filesystem features were used when it was stored on disk. Different computers may use:
- Different filesystems
- Different compression algorithms (or no compression)
- Different compression strengths, even with same algorithm
- Different divisions of the file into compression units
- Different encryption algorithms (or no encryption)
- Different encryption keys, even with same algorithm
- Different encryption nonces, even with same key
Quoted 9 lines
All those change the on-disk data; only the user-visible data stays the same.
Bugs in filesystems may also be exploited regardless of fs-verity, as the attacker (able to manipulate on-disk image) can create a malicious file without fs-verity enabled, somewhere else on the filesystem.
If you actually want to authenticate the full filesystem image, you need to use dm-verity, which is designed for that.
Also keep in mind that ideally the encryption layer would do authenticated encryption, so that during decrypt->decompress->verity the blocks only get past the decrypt step if they're authentically from someone with the encryption key. That's currently missing from fscrypt for practical reasons (read/write per-block metadata is really hard on most filesystems), but in an ideal world it would be there. The fs-verity step is conceptually different, but it seems it's being conflated with this missing step.
- Eric
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
Quoted 86 lines · Eric Biggers
Quoted 75 lines · Eric Biggers
Quoted 52 lines · Gao Xiang
Hi Willy,
Quoted 21 lines · Matthew Wilcox
Quoted 20 lines · Eric Biggers
Quoted 18 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Quoted 7 lines
Quoted 1 line
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759It looks like it'd be computationally expensive to do, but feasible.
Yes, maybe someone cares where encrypt is at due to their system design.
and I thought over these days, I have to repeat my thought of verity again :( the meaningful order ought to be "
decrypt->verity->decompress" rather than "decrypt->decompress->verity" if compression is involved.since most (de)compress algorithms are complex enough (allocate memory and do a lot of unsafe stuffes such as wildcopy) and even maybe unsafe by its design, we cannot do verity in the end for security consideration thus the whole system can be vulnerable by this order from malformed on-disk data. In other words, we need to verify on compressed data.
Fsverity is fine for me since most decrypt algorithms is stable and reliable and no compression by its design, but if some decrypt software algorithms is complicated enough, I'd suggest "
verity->decrypt" as well to some extent.Considering transformation "A->B->C->D->....->verity", if any of "
A->B->C->D->..." is attacked by the malformed on-disk data... It would crash or even root the whole operating system.Quoted 7 lines
All in all, we have to verify data earlier in order to get trusted data for later complex transformation chains.
The performance benefit I described in my previous email, it seems no need to say again... please take them into consideration and I think it's no easy to get a unique generic post-read order for all real systems.
While it would be nice to protect against filesystem bugs, it's not the point of fs-verity. fs-verity is about authenticating the contents the *user* sees, so that e.g. a file can be distributed to many computers and it can be authenticated regardless of exactly what other filesystem features were used when it was stored on disk. Different computers may use:
- Different filesystems
- Different compression algorithms (or no compression)
- Different compression strengths, even with same algorithm
- Different divisions of the file into compression units
- Different encryption algorithms (or no encryption)
- Different encryption keys, even with same algorithm
- Different encryption nonces, even with same keyQuoted 9 lines
All those change the on-disk data; only the user-visible data stays the same.
Bugs in filesystems may also be exploited regardless of fs-verity, as the attacker (able to manipulate on-disk image) can create a malicious file without fs-verity enabled, somewhere else on the filesystem.
If you actually want to authenticate the full filesystem image, you need to use dm-verity, which is designed for that.
Quoted 7 lines
Also keep in mind that ideally the encryption layer would do authenticated encryption, so that during
decrypt->decompress->veritythe blocks only get past the decrypt step if they're authentically from someone with the encryption key. That's currently missing from fscrypt for practical reasons (read/write per-block metadata is really hard on most filesystems), but in an ideal world it would be there. The fs-verity step is conceptually different, but it seems it's being conflated with this missing step.
Yes, but encryption could be not enabled mandatorily for all the post-read data, and not all encrypt algorithms are authenticated encryption...blah-blah-blah...
I want to stop here :) and I think it depends on real requirements, and I don't want the geneeric post-read process is too limited by specfic chains....
Thanks,
Gao XIang
Quoted 2 lines
- Eric
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Eric BiggersQuoted 75 lines · Eric Biggers
Quoted 52 lines · Gao Xiang
Hi Willy,
Quoted 21 lines · Matthew Wilcox
Quoted 20 lines · Eric Biggers
Quoted 18 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Quoted 7 lines
Quoted 1 line
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759It looks like it'd be computationally expensive to do, but feasible.
Yes, maybe someone cares where encrypt is at due to their system design.
and I thought over these days, I have to repeat my thought of verity again :( the meaningful order ought to be "
decrypt->verity->decompress" rather than "decrypt->decompress->verity" if compression is involved.since most (de)compress algorithms are complex enough (allocate memory and do a lot of unsafe stuffes such as wildcopy) and even maybe unsafe by its design, we cannot do verity in the end for security consideration thus the whole system can be vulnerable by this order from malformed on-disk data. In other words, we need to verify on compressed data.
Fsverity is fine for me since most decrypt algorithms is stable and reliable and no compression by its design, but if some decrypt software algorithms is complicated enough, I'd suggest "
verity->decrypt" as well to some extent.Considering transformation "A->B->C->D->....->verity", if any of "
A->B->C->D->..." is attacked by the malformed on-disk data... It would crash or even root the whole operating system.Quoted 7 lines
All in all, we have to verify data earlier in order to get trusted data for later complex transformation chains.
The performance benefit I described in my previous email, it seems no need to say again... please take them into consideration and I think it's no easy to get a unique generic post-read order for all real systems.
While it would be nice to protect against filesystem bugs, it's not the point of fs-verity. fs-verity is about authenticating the contents the *user* sees, so that e.g. a file can be distributed to many computers and it can be authenticated regardless of exactly what other filesystem features were used when it was stored on disk. Different computers may use:
- Different filesystems
- Different compression algorithms (or no compression)
- Different compression strengths, even with same algorithm
- Different divisions of the file into compression units
- Different encryption algorithms (or no encryption)
- Different encryption keys, even with same algorithm
- Different encryption nonces, even with same key
Quoted 1 line
All those change the on-disk data; only the user-visible data stays the same.
Yes, I agree with fs-verity use case, and I can get some limitation as well. (I am not arguing fs-verity in this topic at all...)
Quoted 7 lines
Bugs in filesystems may also be exploited regardless of fs-verity, as the attacker (able to manipulate on-disk image) can create a malicious file without fs-verity enabled, somewhere else on the filesystem.
If you actually want to authenticate the full filesystem image, you need to use dm-verity, which is designed for that.
Yes, but for generic consideration, there is a limitation for dm-verity since it needs filesystems should be read-only;
and that raises another consideration -- verity should be in block/fs, and I think what fscrypt answers is also appropriate to verity in fs (since we have dm-crypt as well), that is that we could consider multiple key R/W verification as well and blah-blah-blah-blah-blah...
I think all is fine at the moment, in this topic, again, I just try to say a generic post-read approach is hard and complicated, not for some specific feature.
Thanks,
Gao Xiang
Quoted 2 lines
- Eric
Re: [PATCH 10/13] iomap: use a function pointer for dio submits
In reply to Matthew WilcoxQuoted 21 lines · Matthew Wilcox
Quoted 20 lines · Eric Biggers
Quoted 18 lines · Gao Xiang
1.
decrypt->verity->decompress2.
verity->decompress->decrypt3.
decompress->decrypt->verity1. and 2. could cause less computation since it processes compressed data, and the security is good enough since the behavior of decompression algorithm is deterministic. 3 could cause more computation.
All I want to say is the post process is so complicated since we have many selection if encryption, decompression, verification are all involved.
Maybe introduce a core subset to IOMAP is better for long-term maintainment and better performance. And we should consider it more carefully.
Quoted 10 lines
Quoted 1 line
FWIW, the only order that actually makes sense is
decrypt->decompress->verity.That used to be true, but a paper in 2004 suggested it's not true. Further work in this space in 2009 based on block ciphers:
https://arxiv.org/pdf/1009.1759It looks like it'd be computationally expensive to do, but feasible.
Quoted 2 lines
Decrypt before decompress, i.e. encrypt after compress, because only the plaintext can be compressible; the ciphertext isn't.
It's an interesting paper, but even assuming that "compress after encrypt" could provide some actual benefit over the usual order (I can't think of any in this context), it doesn't sound practical. From what I understand from that paper:
- It assumes the compressor just *knows* a priori some pattern in the plaintext, i.e. it can't be arbitrary data. E.g. the compressor for CBC encrypted data assumes that each 128 bits of plaintext is drawn from a distibution much smaller than the 2^128 possible values, e.g. at most a certain number of bits are set. If any other data is encrypted+compressed, then the compressor will corrupt it, and it's impossible for it to detect that it did so.
That alone makes it unusable for any use case we're talking about here.
- It only works for some specific encryption modes, and even then each encryption mode needs a custom compression algorithm designed just for it. I don't see how it could work for XTS, let alone a wide-block mode.
- The decompressor needs access to the encryption key. [If that's allowed, why can't the compressor have access to it too?]
- It's almost certainly *much* slower and won't compress as well as conventional compression algorithms (gzip, LZ4, ZSTD, ...) that operate on the plaintext.
Eric
PATCH v2 11/13 btrfs: Use iomap_dio_rw for performing direct I/O writes
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Since btrfs Direct I/O needs to perform operations before submission, use the submit_io function which operates on the bio to perform checksum calculations etc.
--- fs/btrfs/ctree.h | 3 ++ fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 14 +++-- fs/btrfs/iomap.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 165 insertions(+), 12 deletions(-)
fs/btrfs/ctree.h +3 -0
@@ -3206,6 +3206,8 @@ int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);void btrfs_writepage_endio_finish_ordered (struct page *page,u64 start,u64 end,int uptodate);extern const struct dentry_operations btrfs_dentry_operations; +void btrfs_submit_direct (struct bio *dio_bio,struct inode *inode, +loff_t file_offset);/* ioctl.c */ long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);
@@ -3255,6 +3257,7 @@ loff_t btrfs_remap_file_range(struct file *file_in, loff_t pos_in,/* iomap.c */ size_t btrfs_buffered_iomap_write (struct kiocb *iocb,struct iov_iter *from);ssize_t btrfs_dio_iomap_read (struct kiocb *iocb,struct iov_iter *to); +ssize_t btrfs_dio_iomap_write (struct kiocb *iocb,struct iov_iter *from);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +1 -1
@@ -1501,7 +1501,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,atomic_inc (&BTRFS_I (inode)->sync_writers);if (iocb->ki_flags &IOCB_DIRECT ) { - num_written =__btrfs_direct_write (iocb, from); + num_written =btrfs_dio_iomap_write (iocb, from); }else { num_written =btrfs_buffered_iomap_write (iocb, from);if (num_written >0 )
fs/btrfs/inode.c +6 -8
@@ -8167,9 +8167,8 @@ static void btrfs_endio_direct_read(struct bio *bio)kfree (dip); dio_bio->bi_status = err; -dio_end_io (dio_bio); +bio_endio (dio_bio);btrfs_io_bio_free_csum (io_bio); -bio_put (bio); } void btrfs_update_ordered_extent(struct inode *inode,
@@ -8231,8 +8230,7 @@ static void btrfs_endio_direct_write(struct bio *bio)kfree (dip); dio_bio->bi_status = bio->bi_status; -dio_end_io (dio_bio); -bio_put (bio); +bio_endio (dio_bio); } static blk_status_t btrfs_submit_bio_start_direct_io(void *private_data,
@@ -8464,8 +8462,8 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip)return 0 ; } -static void btrfs_submit_direct (struct bio *dio_bio,struct inode *inode, -loff_t file_offset) +void btrfs_submit_direct (struct bio *dio_bio,struct inode *inode, +loff_t file_offset) {struct btrfs_dio_private *dip =NULL ;struct bio *bio =NULL ;
@@ -8536,7 +8534,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode,/* * The end io callbacks free our dip, do the final put on bio * and all the cleanup and final put for dio_bio (through -* dio_end_io()). +* end_io()). */ dip =NULL ; bio =NULL ;
@@ -8555,7 +8553,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode,* Releases and cleans up our dio_bio, no need to bio_put() * nor bio_endio()/bio_io_error() against dio_bio. */ -dio_end_io (dio_bio); +bio_endio (dio_bio); }if (bio)bio_put (bio);
fs/btrfs/iomap.c +155 -3
179 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH v2 12/13 btrfs: Remove btrfs_dio_data and __btrfs_direct_write
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
btrfs_dio_data is unnecessary since we are now storing all informaiton in btrfs_iomap.
Advantage: We don't abuse current->journal_info anymore :)
--- fs/btrfs/file.c | 40 ---------------------------- fs/btrfs/inode.c | 81 ++------------------------------------------------------ 2 files changed, 2 insertions(+), 119 deletions(-)
fs/btrfs/file.c +0 -40
@@ -1350,46 +1350,6 @@ static noinline int check_can_nocow(struct btrfs_inode *inode, loff_t pos,return ret; } -static ssize_t __btrfs_direct_write (struct kiocb *iocb,struct iov_iter *from) -{ -struct file *file = iocb->ki_filp; -struct inode *inode =file_inode (file); -loff_t pos; -ssize_t written; -ssize_t written_buffered; -loff_t endbyte; -int err; - - written =generic_file_direct_write (iocb, from); - -if (written <0 || !iov_iter_count (from)) -return written; - - pos = iocb->ki_pos; - written_buffered =btrfs_buffered_iomap_write (iocb, from); -if (written_buffered <0 ) { - err = written_buffered; - goto out; - } -/* -* Ensure all data is persisted. We want the next direct IO read to be -* able to read what was just written. -*/ - endbyte = pos + written_buffered -1 ; - err =btrfs_fdatawrite_range (inode, pos, endbyte); -if (err) - goto out; - err =filemap_fdatawait_range (inode->i_mapping, pos, endbyte); -if (err) - goto out; - written += written_buffered; - iocb->ki_pos = pos + written_buffered; -invalidate_mapping_pages (file->f_mapping, pos >>PAGE_SHIFT , - endbyte >>PAGE_SHIFT ); -out: -return written ? written : err; -} -static void update_time_for_write (struct inode *inode) {struct timespec64 now;
fs/btrfs/inode.c +2 -79
153 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH v2 13/13 btrfs: update inode size during bio completion
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Update the inode size for dio writes during bio completion. This ties the success of the underlying block layer whether to increase the size of the inode. Especially for in aio cases.
--- fs/btrfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +5 -1
@@ -8191,9 +8191,13 @@ static void btrfs_endio_direct_write(struct bio *bio) {struct btrfs_dio_private *dip = bio->bi_private;struct bio *dio_bio = dip->dio_bio; +struct inode *inode = dip->inode; -btrfs_update_ordered_extent (dip->inode, dip->logical_offset, +btrfs_update_ordered_extent (inode, dip->logical_offset, dip->bytes, !bio->bi_status); +if (!bio->bi_status && +i_size_read (inode) < dip->logical_offset + dip->bytes) +i_size_write (inode, dip->logical_offset + dip->bytes);kfree (dip);
Signature · 1 line
2.16.4