1 iomap: Switch from blkno to disk offset
3 From: Andreas Gruenbacher <agruenba@redhat.com>
5 Replace iomap->blkno, the sector number, with iomap->addr, the disk
6 offset in bytes. For invalid disk offsets, use the special value
7 IOMAP_NULL_ADDR instead of IOMAP_NULL_BLOCK.
9 This allows to use iomap for mappings which are not block aligned, such
10 as inline data on ext4.
12 Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> # iomap, xfs
15 Reviewed-by: Jan Kara <jack@suse.cz>
19 fs/ext2/inode.c | 4 ++--
20 fs/ext4/inode.c | 4 ++--
21 fs/iomap.c | 11 +++++------
22 fs/nfsd/blocklayout.c | 4 ++--
23 fs/xfs/xfs_iomap.c | 6 +++---
24 include/linux/iomap.h | 10 +++++-----
25 8 files changed, 22 insertions(+), 23 deletions(-)
27 diff --git a/fs/buffer.c b/fs/buffer.c
28 index 170df856bdb9..bd4d0923cdce 100644
31 @@ -1978,8 +1978,8 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,
33 if (offset >= i_size_read(inode))
35 - bh->b_blocknr = (iomap->blkno >> (inode->i_blkbits - 9)) +
36 - ((offset - iomap->offset) >> inode->i_blkbits);
37 + bh->b_blocknr = (iomap->addr + offset - iomap->offset) >>
39 set_buffer_mapped(bh);
42 diff --git a/fs/dax.c b/fs/dax.c
43 index 6afcacb3a87b..feccb4ec45d2 100644
46 @@ -938,7 +938,7 @@ EXPORT_SYMBOL_GPL(__dax_zero_page_range);
48 static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos)
50 - return iomap->blkno + (((pos & PAGE_MASK) - iomap->offset) >> 9);
51 + return (iomap->addr + (pos & PAGE_MASK) - iomap->offset) >> 9;
55 diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
56 index 4dca6f348714..1b8fc73de4a1 100644
59 @@ -820,11 +820,11 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
62 iomap->type = IOMAP_HOLE;
63 - iomap->blkno = IOMAP_NULL_BLOCK;
64 + iomap->addr = IOMAP_NULL_ADDR;
65 iomap->length = 1 << blkbits;
67 iomap->type = IOMAP_MAPPED;
68 - iomap->blkno = (sector_t)bno << (blkbits - 9);
69 + iomap->addr = (u64)bno << blkbits;
70 iomap->length = (u64)ret << blkbits;
71 iomap->flags |= IOMAP_F_MERGED;
73 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
74 index 31db875bc7a1..d9e633c12aae 100644
77 @@ -3472,7 +3472,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
80 iomap->type = IOMAP_HOLE;
81 - iomap->blkno = IOMAP_NULL_BLOCK;
82 + iomap->addr = IOMAP_NULL_ADDR;
83 iomap->length = (u64)map.m_len << blkbits;
85 if (map.m_flags & EXT4_MAP_MAPPED) {
86 @@ -3483,7 +3483,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
90 - iomap->blkno = (sector_t)map.m_pblk << (blkbits - 9);
91 + iomap->addr = (u64)map.m_pblk << blkbits;
92 iomap->length = (u64)map.m_len << blkbits;
95 diff --git a/fs/iomap.c b/fs/iomap.c
96 index 269b24a01f32..622c731c57a0 100644
99 @@ -350,8 +350,8 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,
100 static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,
103 - sector_t sector = iomap->blkno +
104 - (((pos & ~(PAGE_SIZE - 1)) - iomap->offset) >> 9);
105 + sector_t sector = (iomap->addr +
106 + (pos & PAGE_MASK) - iomap->offset) >> 9;
108 return __dax_zero_page_range(iomap->bdev, iomap->dax_dev, sector,
110 @@ -512,9 +512,8 @@ static int iomap_to_fiemap(struct fiemap_extent_info *fi,
111 flags |= FIEMAP_EXTENT_SHARED;
113 return fiemap_fill_next_extent(fi, iomap->offset,
114 - iomap->blkno != IOMAP_NULL_BLOCK ? iomap->blkno << 9: 0,
115 + iomap->addr != IOMAP_NULL_ADDR ? iomap->addr : 0,
116 iomap->length, flags);
121 @@ -807,7 +806,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,
122 bio = bio_alloc(GFP_KERNEL, 1);
123 bio_set_dev(bio, iomap->bdev);
124 bio->bi_iter.bi_sector =
125 - iomap->blkno + ((pos - iomap->offset) >> 9);
126 + (iomap->addr + pos - iomap->offset) >> 9;
127 bio->bi_private = dio;
128 bio->bi_end_io = iomap_dio_bio_end_io;
130 @@ -886,7 +885,7 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length,
131 bio = bio_alloc(GFP_KERNEL, nr_pages);
132 bio_set_dev(bio, iomap->bdev);
133 bio->bi_iter.bi_sector =
134 - iomap->blkno + ((pos - iomap->offset) >> 9);
135 + (iomap->addr + pos - iomap->offset) >> 9;
136 bio->bi_write_hint = dio->iocb->ki_hint;
137 bio->bi_private = dio;
138 bio->bi_end_io = iomap_dio_bio_end_io;
139 diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
140 index c862c2489df0..2d1d37b27dc7 100644
141 --- a/fs/nfsd/blocklayout.c
142 +++ b/fs/nfsd/blocklayout.c
143 @@ -65,7 +65,7 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp,
144 bex->es = PNFS_BLOCK_READ_DATA;
146 bex->es = PNFS_BLOCK_READWRITE_DATA;
147 - bex->soff = (iomap.blkno << 9);
148 + bex->soff = iomap.addr;
150 case IOMAP_UNWRITTEN:
151 if (seg->iomode & IOMODE_RW) {
152 @@ -78,7 +78,7 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp,
155 bex->es = PNFS_BLOCK_INVALID_DATA;
156 - bex->soff = (iomap.blkno << 9);
157 + bex->soff = iomap.addr;
161 diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
162 index a1909bc064e9..ac22a5c00079 100644
163 --- a/fs/xfs/xfs_iomap.c
164 +++ b/fs/xfs/xfs_iomap.c
165 @@ -54,13 +54,13 @@ xfs_bmbt_to_iomap(
166 struct xfs_mount *mp = ip->i_mount;
168 if (imap->br_startblock == HOLESTARTBLOCK) {
169 - iomap->blkno = IOMAP_NULL_BLOCK;
170 + iomap->addr = IOMAP_NULL_ADDR;
171 iomap->type = IOMAP_HOLE;
172 } else if (imap->br_startblock == DELAYSTARTBLOCK) {
173 - iomap->blkno = IOMAP_NULL_BLOCK;
174 + iomap->addr = IOMAP_NULL_ADDR;
175 iomap->type = IOMAP_DELALLOC;
177 - iomap->blkno = xfs_fsb_to_db(ip, imap->br_startblock);
178 + iomap->addr = BBTOB(xfs_fsb_to_db(ip, imap->br_startblock));
179 if (imap->br_state == XFS_EXT_UNWRITTEN)
180 iomap->type = IOMAP_UNWRITTEN;
182 diff --git a/include/linux/iomap.h b/include/linux/iomap.h
183 index f64dc6ce5161..7b8a615fa021 100644
184 --- a/include/linux/iomap.h
185 +++ b/include/linux/iomap.h
186 @@ -15,8 +15,8 @@ struct vm_fault;
188 #define IOMAP_HOLE 0x01 /* no blocks allocated, need allocation */
189 #define IOMAP_DELALLOC 0x02 /* delayed allocation blocks */
190 -#define IOMAP_MAPPED 0x03 /* blocks allocated @blkno */
191 -#define IOMAP_UNWRITTEN 0x04 /* blocks allocated @blkno in unwritten state */
192 +#define IOMAP_MAPPED 0x03 /* blocks allocated at @addr */
193 +#define IOMAP_UNWRITTEN 0x04 /* blocks allocated at @addr in unwritten state */
196 * Flags for all iomap mappings:
197 @@ -30,12 +30,12 @@ struct vm_fault;
198 #define IOMAP_F_SHARED 0x20 /* block shared with another file */
201 - * Magic value for blkno:
202 + * Magic value for addr:
204 -#define IOMAP_NULL_BLOCK -1LL /* blkno is not valid */
205 +#define IOMAP_NULL_ADDR -1ULL /* addr is not valid */
208 - sector_t blkno; /* 1st sector of mapping, 512b units */
209 + u64 addr; /* disk offset of mapping, bytes */
210 loff_t offset; /* file offset of mapping, bytes */
211 u64 length; /* length of mapping, bytes */
212 u16 type; /* type of mapping */