Skip to content

Commit 952da06

Browse files
Christoph Hellwigdjbw
authored andcommitted
iomap: add a IOMAP_DAX flag
Add a flag so that the file system can easily detect DAX operations based just on the iomap operation requested instead of looking at inode state using IS_DAX. This will be needed to apply the to be added partition offset only for operations that actually use DAX, but not things like fiemap that are based on the block device. In the long run it should also allow turning the bdev, dax_dev and inline_data into a union. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 740fd67 commit 952da06

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

fs/dax.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
11801180
.inode = inode,
11811181
.pos = pos,
11821182
.len = len,
1183-
.flags = IOMAP_ZERO,
1183+
.flags = IOMAP_DAX | IOMAP_ZERO,
11841184
};
11851185
int ret;
11861186

@@ -1308,6 +1308,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
13081308
.inode = iocb->ki_filp->f_mapping->host,
13091309
.pos = iocb->ki_pos,
13101310
.len = iov_iter_count(iter),
1311+
.flags = IOMAP_DAX,
13111312
};
13121313
loff_t done = 0;
13131314
int ret;
@@ -1461,7 +1462,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
14611462
.inode = mapping->host,
14621463
.pos = (loff_t)vmf->pgoff << PAGE_SHIFT,
14631464
.len = PAGE_SIZE,
1464-
.flags = IOMAP_FAULT,
1465+
.flags = IOMAP_DAX | IOMAP_FAULT,
14651466
};
14661467
vm_fault_t ret = 0;
14671468
void *entry;
@@ -1570,7 +1571,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
15701571
struct iomap_iter iter = {
15711572
.inode = mapping->host,
15721573
.len = PMD_SIZE,
1573-
.flags = IOMAP_FAULT,
1574+
.flags = IOMAP_DAX | IOMAP_FAULT,
15741575
};
15751576
vm_fault_t ret = VM_FAULT_FALLBACK;
15761577
pgoff_t max_pgoff;

fs/ext4/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,8 +3349,8 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
33493349
* DAX and direct I/O are the only two operations that are currently
33503350
* supported with IOMAP_WRITE.
33513351
*/
3352-
WARN_ON(!IS_DAX(inode) && !(flags & IOMAP_DIRECT));
3353-
if (IS_DAX(inode))
3352+
WARN_ON(!(flags & (IOMAP_DAX | IOMAP_DIRECT)));
3353+
if (flags & IOMAP_DAX)
33543354
m_flags = EXT4_GET_BLOCKS_CREATE_ZERO;
33553355
/*
33563356
* We use i_size instead of i_disksize here because delalloc writeback

fs/xfs/xfs_iomap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ xfs_iomap_write_direct(
188188
struct xfs_inode *ip,
189189
xfs_fileoff_t offset_fsb,
190190
xfs_fileoff_t count_fsb,
191+
unsigned int flags,
191192
struct xfs_bmbt_irec *imap)
192193
{
193194
struct xfs_mount *mp = ip->i_mount;
@@ -229,7 +230,7 @@ xfs_iomap_write_direct(
229230
* the reserve block pool for bmbt block allocation if there is no space
230231
* left but we need to do unwritten extent conversion.
231232
*/
232-
if (IS_DAX(VFS_I(ip))) {
233+
if (flags & IOMAP_DAX) {
233234
bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
234235
if (imap->br_state == XFS_EXT_UNWRITTEN) {
235236
force = true;
@@ -620,7 +621,7 @@ imap_needs_alloc(
620621
imap->br_startblock == DELAYSTARTBLOCK)
621622
return true;
622623
/* we convert unwritten extents before copying the data for DAX */
623-
if (IS_DAX(inode) && imap->br_state == XFS_EXT_UNWRITTEN)
624+
if ((flags & IOMAP_DAX) && imap->br_state == XFS_EXT_UNWRITTEN)
624625
return true;
625626
return false;
626627
}
@@ -826,7 +827,7 @@ xfs_direct_write_iomap_begin(
826827
xfs_iunlock(ip, lockmode);
827828

828829
error = xfs_iomap_write_direct(ip, offset_fsb, end_fsb - offset_fsb,
829-
&imap);
830+
flags, &imap);
830831
if (error)
831832
return error;
832833

fs/xfs/xfs_iomap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ struct xfs_inode;
1212
struct xfs_bmbt_irec;
1313

1414
int xfs_iomap_write_direct(struct xfs_inode *ip, xfs_fileoff_t offset_fsb,
15-
xfs_fileoff_t count_fsb, struct xfs_bmbt_irec *imap);
15+
xfs_fileoff_t count_fsb, unsigned int flags,
16+
struct xfs_bmbt_irec *imap);
1617
int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool);
1718
xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,
1819
xfs_fileoff_t end_fsb);

fs/xfs/xfs_pnfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ xfs_fs_map_blocks(
155155
xfs_iunlock(ip, lock_flags);
156156

157157
error = xfs_iomap_write_direct(ip, offset_fsb,
158-
end_fsb - offset_fsb, &imap);
158+
end_fsb - offset_fsb, 0, &imap);
159159
if (error)
160160
goto out_unlock;
161161

include/linux/iomap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ struct iomap_page_ops {
141141
#define IOMAP_NOWAIT (1 << 5) /* do not block */
142142
#define IOMAP_OVERWRITE_ONLY (1 << 6) /* only pure overwrites allowed */
143143
#define IOMAP_UNSHARE (1 << 7) /* unshare_file_range */
144+
#ifdef CONFIG_FS_DAX
145+
#define IOMAP_DAX (1 << 8) /* DAX mapping */
146+
#else
147+
#define IOMAP_DAX 0
148+
#endif /* CONFIG_FS_DAX */
144149

145150
struct iomap_ops {
146151
/*

0 commit comments

Comments
 (0)