Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iomap: switch iomap_bmap to use iomap_iter

Rewrite the ->bmap implementation based on iomap_iter.

Signed-off-by: Christoph Hellwig <hch@lst.de>
[djwong: restructure the loop to make its behavior a little clearer]
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

authored by

Christoph Hellwig and committed by
Darrick J. Wong
6d8a1287 7892386d

+13 -18
+13 -18
fs/iomap/fiemap.c
··· 92 92 } 93 93 EXPORT_SYMBOL_GPL(iomap_fiemap); 94 94 95 - static loff_t 96 - iomap_bmap_actor(struct inode *inode, loff_t pos, loff_t length, 97 - void *data, struct iomap *iomap, struct iomap *srcmap) 98 - { 99 - sector_t *bno = data, addr; 100 - 101 - if (iomap->type == IOMAP_MAPPED) { 102 - addr = (pos - iomap->offset + iomap->addr) >> inode->i_blkbits; 103 - *bno = addr; 104 - } 105 - return 0; 106 - } 107 - 108 95 /* legacy ->bmap interface. 0 is the error return (!) */ 109 96 sector_t 110 97 iomap_bmap(struct address_space *mapping, sector_t bno, 111 98 const struct iomap_ops *ops) 112 99 { 113 - struct inode *inode = mapping->host; 114 - loff_t pos = bno << inode->i_blkbits; 115 - unsigned blocksize = i_blocksize(inode); 100 + struct iomap_iter iter = { 101 + .inode = mapping->host, 102 + .pos = (loff_t)bno << mapping->host->i_blkbits, 103 + .len = i_blocksize(mapping->host), 104 + .flags = IOMAP_REPORT, 105 + }; 106 + const unsigned int blkshift = mapping->host->i_blkbits - SECTOR_SHIFT; 116 107 int ret; 117 108 118 109 if (filemap_write_and_wait(mapping)) 119 110 return 0; 120 111 121 112 bno = 0; 122 - ret = iomap_apply(inode, pos, blocksize, 0, ops, &bno, 123 - iomap_bmap_actor); 113 + while ((ret = iomap_iter(&iter, ops)) > 0) { 114 + if (iter.iomap.type == IOMAP_MAPPED) 115 + bno = iomap_sector(&iter.iomap, iter.pos) >> blkshift; 116 + /* leave iter.processed unset to abort loop */ 117 + } 124 118 if (ret) 125 119 return 0; 120 + 126 121 return bno; 127 122 } 128 123 EXPORT_SYMBOL_GPL(iomap_bmap);