Skip to content

Commit de20511

Browse files
Christoph Hellwigdjbw
authored andcommitted
fsdax: shift partition offset handling into the file systems
Remove the last user of ->bdev in dax.c by requiring the file system to pass in an address that already includes the DAX offset. As part of the only set ->bdev or ->daxdev when actually required in the ->iomap_begin methods. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Gao Xiang <[email protected]> [erofs] Reviewed-by: Darrick J. Wong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent cd913c7 commit de20511

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

fs/dax.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,7 @@ int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
711711

712712
static pgoff_t dax_iomap_pgoff(const struct iomap *iomap, loff_t pos)
713713
{
714-
phys_addr_t paddr = iomap->addr + (pos & PAGE_MASK) - iomap->offset;
715-
716-
if (iomap->bdev)
717-
paddr += (get_start_sect(iomap->bdev) << SECTOR_SHIFT);
718-
return PHYS_PFN(paddr);
714+
return PHYS_PFN(iomap->addr + (pos & PAGE_MASK) - iomap->offset);
719715
}
720716

721717
static int copy_cow_page_dax(struct vm_fault *vmf, const struct iomap_iter *iter)

fs/erofs/data.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
159159
/* primary device by default */
160160
map->m_bdev = sb->s_bdev;
161161
map->m_daxdev = EROFS_SB(sb)->dax_dev;
162+
map->m_dax_part_off = EROFS_SB(sb)->dax_part_off;
162163

163164
if (map->m_deviceid) {
164165
down_read(&devs->rwsem);
@@ -169,6 +170,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
169170
}
170171
map->m_bdev = dif->bdev;
171172
map->m_daxdev = dif->dax_dev;
173+
map->m_dax_part_off = dif->dax_part_off;
172174
up_read(&devs->rwsem);
173175
} else if (devs->extra_devices) {
174176
down_read(&devs->rwsem);
@@ -185,6 +187,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
185187
map->m_pa -= startoff;
186188
map->m_bdev = dif->bdev;
187189
map->m_daxdev = dif->dax_dev;
190+
map->m_dax_part_off = dif->dax_part_off;
188191
break;
189192
}
190193
}
@@ -215,9 +218,13 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
215218
if (ret)
216219
return ret;
217220

218-
iomap->bdev = mdev.m_bdev;
219-
iomap->dax_dev = mdev.m_daxdev;
220221
iomap->offset = map.m_la;
222+
if (flags & IOMAP_DAX) {
223+
iomap->dax_dev = mdev.m_daxdev;
224+
iomap->offset += mdev.m_dax_part_off;
225+
} else {
226+
iomap->bdev = mdev.m_bdev;
227+
}
221228
iomap->length = map.m_llen;
222229
iomap->flags = 0;
223230
iomap->private = NULL;

fs/erofs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ static inline int z_erofs_map_blocks_iter(struct inode *inode,
438438
struct erofs_map_dev {
439439
struct block_device *m_bdev;
440440
struct dax_device *m_daxdev;
441+
u64 m_dax_part_off;
441442

442443
erofs_off_t m_pa;
443444
unsigned int m_deviceid;

fs/ext2/inode.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,11 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
817817
return ret;
818818

819819
iomap->flags = 0;
820-
iomap->bdev = inode->i_sb->s_bdev;
821820
iomap->offset = (u64)first_block << blkbits;
822-
iomap->dax_dev = sbi->s_daxdev;
821+
if (flags & IOMAP_DAX)
822+
iomap->dax_dev = sbi->s_daxdev;
823+
else
824+
iomap->bdev = inode->i_sb->s_bdev;
823825

824826
if (ret == 0) {
825827
iomap->type = IOMAP_HOLE;
@@ -828,6 +830,8 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
828830
} else {
829831
iomap->type = IOMAP_MAPPED;
830832
iomap->addr = (u64)bno << blkbits;
833+
if (flags & IOMAP_DAX)
834+
iomap->addr += sbi->s_dax_part_off;
831835
iomap->length = (u64)ret << blkbits;
832836
iomap->flags |= IOMAP_F_MERGED;
833837
}

fs/ext4/inode.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,7 +3272,7 @@ static bool ext4_inode_datasync_dirty(struct inode *inode)
32723272

32733273
static void ext4_set_iomap(struct inode *inode, struct iomap *iomap,
32743274
struct ext4_map_blocks *map, loff_t offset,
3275-
loff_t length)
3275+
loff_t length, unsigned int flags)
32763276
{
32773277
u8 blkbits = inode->i_blkbits;
32783278

@@ -3289,8 +3289,10 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap,
32893289
if (map->m_flags & EXT4_MAP_NEW)
32903290
iomap->flags |= IOMAP_F_NEW;
32913291

3292-
iomap->bdev = inode->i_sb->s_bdev;
3293-
iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
3292+
if (flags & IOMAP_DAX)
3293+
iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
3294+
else
3295+
iomap->bdev = inode->i_sb->s_bdev;
32943296
iomap->offset = (u64) map->m_lblk << blkbits;
32953297
iomap->length = (u64) map->m_len << blkbits;
32963298

@@ -3310,9 +3312,13 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap,
33103312
if (map->m_flags & EXT4_MAP_UNWRITTEN) {
33113313
iomap->type = IOMAP_UNWRITTEN;
33123314
iomap->addr = (u64) map->m_pblk << blkbits;
3315+
if (flags & IOMAP_DAX)
3316+
iomap->addr += EXT4_SB(inode->i_sb)->s_dax_part_off;
33133317
} else if (map->m_flags & EXT4_MAP_MAPPED) {
33143318
iomap->type = IOMAP_MAPPED;
33153319
iomap->addr = (u64) map->m_pblk << blkbits;
3320+
if (flags & IOMAP_DAX)
3321+
iomap->addr += EXT4_SB(inode->i_sb)->s_dax_part_off;
33163322
} else {
33173323
iomap->type = IOMAP_HOLE;
33183324
iomap->addr = IOMAP_NULL_ADDR;
@@ -3421,7 +3427,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
34213427
if (ret < 0)
34223428
return ret;
34233429
out:
3424-
ext4_set_iomap(inode, iomap, &map, offset, length);
3430+
ext4_set_iomap(inode, iomap, &map, offset, length, flags);
34253431

34263432
return 0;
34273433
}
@@ -3541,7 +3547,7 @@ static int ext4_iomap_begin_report(struct inode *inode, loff_t offset,
35413547
delalloc = ext4_iomap_is_delalloc(inode, &map);
35423548

35433549
set_iomap:
3544-
ext4_set_iomap(inode, iomap, &map, offset, length);
3550+
ext4_set_iomap(inode, iomap, &map, offset, length, flags);
35453551
if (delalloc && iomap->type == IOMAP_HOLE)
35463552
iomap->type = IOMAP_DELALLOC;
35473553

fs/xfs/xfs_iomap.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,21 @@ xfs_bmbt_to_iomap(
7171
iomap->type = IOMAP_DELALLOC;
7272
} else {
7373
iomap->addr = BBTOB(xfs_fsb_to_db(ip, imap->br_startblock));
74+
if (mapping_flags & IOMAP_DAX)
75+
iomap->addr += target->bt_dax_part_off;
76+
7477
if (imap->br_state == XFS_EXT_UNWRITTEN)
7578
iomap->type = IOMAP_UNWRITTEN;
7679
else
7780
iomap->type = IOMAP_MAPPED;
81+
7882
}
7983
iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff);
8084
iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount);
81-
iomap->bdev = target->bt_bdev;
82-
iomap->dax_dev = target->bt_daxdev;
85+
if (mapping_flags & IOMAP_DAX)
86+
iomap->dax_dev = target->bt_daxdev;
87+
else
88+
iomap->bdev = target->bt_bdev;
8389
iomap->flags = iomap_flags;
8490

8591
if (xfs_ipincount(ip) &&

0 commit comments

Comments
 (0)