iomap: add a IOMAP_DAX flag
authorChristoph Hellwig <hch@lst.de>
Mon, 29 Nov 2021 10:21:58 +0000 (11:21 +0100)
committerDan Williams <dan.j.williams@intel.com>
Sat, 4 Dec 2021 16:58:53 +0000 (08:58 -0800)
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 <hch@lst.de>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20211129102203.2243509-25-hch@lst.de
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
fs/dax.c
fs/ext4/inode.c
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iomap.h
fs/xfs/xfs_pnfs.c
include/linux/iomap.h

index 43d58b4219fd0ffd38a7a758ea5a423a24fbeabd..148e8b0967f356b63d55c7ab06ee4d4abd7a00a2 100644 (file)
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1180,7 +1180,7 @@ int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
                .inode          = inode,
                .pos            = pos,
                .len            = len,
-               .flags          = IOMAP_ZERO,
+               .flags          = IOMAP_DAX | IOMAP_ZERO,
        };
        int ret;
 
@@ -1308,6 +1308,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
                .inode          = iocb->ki_filp->f_mapping->host,
                .pos            = iocb->ki_pos,
                .len            = iov_iter_count(iter),
+               .flags          = IOMAP_DAX,
        };
        loff_t done = 0;
        int ret;
@@ -1461,7 +1462,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
                .inode          = mapping->host,
                .pos            = (loff_t)vmf->pgoff << PAGE_SHIFT,
                .len            = PAGE_SIZE,
-               .flags          = IOMAP_FAULT,
+               .flags          = IOMAP_DAX | IOMAP_FAULT,
        };
        vm_fault_t ret = 0;
        void *entry;
@@ -1570,7 +1571,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
        struct iomap_iter iter = {
                .inode          = mapping->host,
                .len            = PMD_SIZE,
-               .flags          = IOMAP_FAULT,
+               .flags          = IOMAP_DAX | IOMAP_FAULT,
        };
        vm_fault_t ret = VM_FAULT_FALLBACK;
        pgoff_t max_pgoff;
index d316a2009489bab2b9e68c0763521bed4529e335..89c4a174bd393058552d23b5c973d9aec40911a0 100644 (file)
@@ -3349,8 +3349,8 @@ retry:
         * DAX and direct I/O are the only two operations that are currently
         * supported with IOMAP_WRITE.
         */
-       WARN_ON(!IS_DAX(inode) && !(flags & IOMAP_DIRECT));
-       if (IS_DAX(inode))
+       WARN_ON(!(flags & (IOMAP_DAX | IOMAP_DIRECT)));
+       if (flags & IOMAP_DAX)
                m_flags = EXT4_GET_BLOCKS_CREATE_ZERO;
        /*
         * We use i_size instead of i_disksize here because delalloc writeback
index d6beb1502f8bc2bdad3e106fb79674b3e56a8197..0ed3e7674353bc82bd0bb7baa6bbbf615866129c 100644 (file)
@@ -188,6 +188,7 @@ xfs_iomap_write_direct(
        struct xfs_inode        *ip,
        xfs_fileoff_t           offset_fsb,
        xfs_fileoff_t           count_fsb,
+       unsigned int            flags,
        struct xfs_bmbt_irec    *imap)
 {
        struct xfs_mount        *mp = ip->i_mount;
@@ -229,7 +230,7 @@ xfs_iomap_write_direct(
         * the reserve block pool for bmbt block allocation if there is no space
         * left but we need to do unwritten extent conversion.
         */
-       if (IS_DAX(VFS_I(ip))) {
+       if (flags & IOMAP_DAX) {
                bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
                if (imap->br_state == XFS_EXT_UNWRITTEN) {
                        force = true;
@@ -620,7 +621,7 @@ imap_needs_alloc(
            imap->br_startblock == DELAYSTARTBLOCK)
                return true;
        /* we convert unwritten extents before copying the data for DAX */
-       if (IS_DAX(inode) && imap->br_state == XFS_EXT_UNWRITTEN)
+       if ((flags & IOMAP_DAX) && imap->br_state == XFS_EXT_UNWRITTEN)
                return true;
        return false;
 }
@@ -826,7 +827,7 @@ allocate_blocks:
        xfs_iunlock(ip, lockmode);
 
        error = xfs_iomap_write_direct(ip, offset_fsb, end_fsb - offset_fsb,
-                       &imap);
+                       flags, &imap);
        if (error)
                return error;
 
index 657cc02290f22d0f01a2b8fbbdd900c13b7b177d..e88dc162c785ee05f67ecebe4fcdc49d21160568 100644 (file)
@@ -12,7 +12,8 @@ struct xfs_inode;
 struct xfs_bmbt_irec;
 
 int xfs_iomap_write_direct(struct xfs_inode *ip, xfs_fileoff_t offset_fsb,
-               xfs_fileoff_t count_fsb, struct xfs_bmbt_irec *imap);
+               xfs_fileoff_t count_fsb, unsigned int flags,
+               struct xfs_bmbt_irec *imap);
 int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool);
 xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,
                xfs_fileoff_t end_fsb);
index 7ce1ea11fc3f3f207e0d957cdf2e3ef7ed26595b..d6334abbc0b3e309fca6e2fc4df0f261739edb30 100644 (file)
@@ -155,7 +155,7 @@ xfs_fs_map_blocks(
                xfs_iunlock(ip, lock_flags);
 
                error = xfs_iomap_write_direct(ip, offset_fsb,
-                               end_fsb - offset_fsb, &imap);
+                               end_fsb - offset_fsb, 0, &imap);
                if (error)
                        goto out_unlock;
 
index 6d1b08d0ae9309eb34c632827fc6d3ced42e078c..5b9432f9f79eb49640091db64f181a83d49e01d7 100644 (file)
@@ -141,6 +141,11 @@ struct iomap_page_ops {
 #define IOMAP_NOWAIT           (1 << 5) /* do not block */
 #define IOMAP_OVERWRITE_ONLY   (1 << 6) /* only pure overwrites allowed */
 #define IOMAP_UNSHARE          (1 << 7) /* unshare_file_range */
+#ifdef CONFIG_FS_DAX
+#define IOMAP_DAX              (1 << 8) /* DAX mapping */
+#else
+#define IOMAP_DAX              0
+#endif /* CONFIG_FS_DAX */
 
 struct iomap_ops {
        /*