]> www.infradead.org Git - users/hch/xfs.git/commitdiff
iomap: add a IOMAP_F_ANON_WRITE flag
authorChristoph Hellwig <hch@lst.de>
Sun, 5 Nov 2023 05:40:52 +0000 (06:40 +0100)
committerChristoph Hellwig <hch@lst.de>
Mon, 3 Feb 2025 04:49:03 +0000 (05:49 +0100)
Add a IOMAP_F_ANON_WRITE flag that indicates that the write I/O does not
have a target block assigned to it yet at iomap time and the file system
will do that in the bio submission handler, splitting the I/O as needed.

This is used to implement Zone Append based I/O for zoned XFS, where
splitting writes to the hardware limits and assigning a zone to them
happens just before sending the I/O off to the block layer, but could
also be useful for other things like compressed I/O.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Documentation/filesystems/iomap/design.rst
fs/iomap/buffered-io.c
fs/iomap/direct-io.c
include/linux/iomap.h

index b0d0188a095e55a869bd293f2a5b9cf19162baf3..28ab3758c474ec505174ab4890bde01ff33fd982 100644 (file)
@@ -246,6 +246,10 @@ The fields are as follows:
    * **IOMAP_F_PRIVATE**: Starting with this value, the upper bits can
      be set by the filesystem for its own purposes.
 
+   * **IOMAP_F_ANON_WRITE**: Indicates that (write) I/O does not have a target
+     block assigned to it yet and the file system will do that in the bio
+     submission handler, splitting the I/O as needed.
+
    These flags can be set by iomap itself during file operations.
    The filesystem should supply an ``->iomap_end`` function if it needs
    to observe these flags:
index d8d271107e60a570fb43987a0401ac4c40b9db3e..ba795d72e546bccfb688e5c02b3a80d75d9abb87 100644 (file)
@@ -1691,10 +1691,14 @@ static int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)
         * failure happened so that the file system end I/O handler gets called
         * to clean up.
         */
-       if (wpc->ops->submit_ioend)
+       if (wpc->ops->submit_ioend) {
                error = wpc->ops->submit_ioend(wpc, error);
-       else if (!error)
-               submit_bio(&wpc->ioend->io_bio);
+       } else {
+               if (WARN_ON_ONCE(wpc->iomap.flags & IOMAP_F_ANON_WRITE))
+                       error = -EIO;
+               if (!error)
+                       submit_bio(&wpc->ioend->io_bio);
+       }
 
        if (error) {
                wpc->ioend->io_bio.bi_status = errno_to_blk_status(error);
@@ -1744,7 +1748,8 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
                return false;
        if (pos != wpc->ioend->io_offset + wpc->ioend->io_size)
                return false;
-       if (iomap_sector(&wpc->iomap, pos) !=
+       if (!(wpc->iomap.flags & IOMAP_F_ANON_WRITE) &&
+           iomap_sector(&wpc->iomap, pos) !=
            bio_end_sector(&wpc->ioend->io_bio))
                return false;
        /*
index b521eb15759e8ba81f36b08d88a2e37702c70901..641649a04614e48fc6fa24e52d00f866ada2c43c 100644 (file)
@@ -81,10 +81,12 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter,
                WRITE_ONCE(iocb->private, bio);
        }
 
-       if (dio->dops && dio->dops->submit_io)
+       if (dio->dops && dio->dops->submit_io) {
                dio->dops->submit_io(iter, bio, pos);
-       else
+       } else {
+               WARN_ON_ONCE(iter->iomap.flags & IOMAP_F_ANON_WRITE);
                submit_bio(bio);
+       }
 }
 
 ssize_t iomap_dio_complete(struct iomap_dio *dio)
index 9583f6456165891ffdfb48514684b12eef05144d..eb0764945b42cccb3315ca887fb8e46720604ae7 100644 (file)
@@ -56,6 +56,10 @@ struct vm_fault;
  *
  * IOMAP_F_BOUNDARY indicates that I/O and I/O completions for this iomap must
  * never be merged with the mapping before it.
+ *
+ * IOMAP_F_ANON_WRITE indicates that (write) I/O does not have a target block
+ * assigned to it yet and the file system will do that in the bio submission
+ * handler, splitting the I/O as needed.
  */
 #define IOMAP_F_NEW            (1U << 0)
 #define IOMAP_F_DIRTY          (1U << 1)
@@ -68,6 +72,7 @@ struct vm_fault;
 #endif /* CONFIG_BUFFER_HEAD */
 #define IOMAP_F_XATTR          (1U << 5)
 #define IOMAP_F_BOUNDARY       (1U << 6)
+#define IOMAP_F_ANON_WRITE     (1U << 7)
 
 /*
  * Flags set by the core iomap code during operations:
@@ -111,6 +116,8 @@ struct iomap {
 
 static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos)
 {
+       if (iomap->flags & IOMAP_F_ANON_WRITE)
+               return U64_MAX; /* invalid */
        return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT;
 }