Skip to content

Commit 034c29f

Browse files
Christoph Hellwigbrauner
authored andcommitted
iomap: add a IOMAP_F_ANON_WRITE flag
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> Link: https://lore.kernel.org/r/20250206064035.2323428-4-hch@lst.de Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 7102733 commit 034c29f

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

Documentation/filesystems/iomap/design.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ The fields are as follows:
246246
* **IOMAP_F_PRIVATE**: Starting with this value, the upper bits can
247247
be set by the filesystem for its own purposes.
248248

249+
* **IOMAP_F_ANON_WRITE**: Indicates that (write) I/O does not have a target
250+
block assigned to it yet and the file system will do that in the bio
251+
submission handler, splitting the I/O as needed.
252+
249253
These flags can be set by iomap itself during file operations.
250254
The filesystem should supply an ``->iomap_end`` function if it needs
251255
to observe these flags:

fs/iomap/buffered-io.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,10 +1691,14 @@ static int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)
16911691
* failure happened so that the file system end I/O handler gets called
16921692
* to clean up.
16931693
*/
1694-
if (wpc->ops->submit_ioend)
1694+
if (wpc->ops->submit_ioend) {
16951695
error = wpc->ops->submit_ioend(wpc, error);
1696-
else if (!error)
1697-
submit_bio(&wpc->ioend->io_bio);
1696+
} else {
1697+
if (WARN_ON_ONCE(wpc->iomap.flags & IOMAP_F_ANON_WRITE))
1698+
error = -EIO;
1699+
if (!error)
1700+
submit_bio(&wpc->ioend->io_bio);
1701+
}
16981702

16991703
if (error) {
17001704
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,
17441748
return false;
17451749
if (pos != wpc->ioend->io_offset + wpc->ioend->io_size)
17461750
return false;
1747-
if (iomap_sector(&wpc->iomap, pos) !=
1751+
if (!(wpc->iomap.flags & IOMAP_F_ANON_WRITE) &&
1752+
iomap_sector(&wpc->iomap, pos) !=
17481753
bio_end_sector(&wpc->ioend->io_bio))
17491754
return false;
17501755
/*

fs/iomap/direct-io.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter,
8181
WRITE_ONCE(iocb->private, bio);
8282
}
8383

84-
if (dio->dops && dio->dops->submit_io)
84+
if (dio->dops && dio->dops->submit_io) {
8585
dio->dops->submit_io(iter, bio, pos);
86-
else
86+
} else {
87+
WARN_ON_ONCE(iter->iomap.flags & IOMAP_F_ANON_WRITE);
8788
submit_bio(bio);
89+
}
8890
}
8991

9092
ssize_t iomap_dio_complete(struct iomap_dio *dio)

include/linux/iomap.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ struct vm_fault;
5656
*
5757
* IOMAP_F_BOUNDARY indicates that I/O and I/O completions for this iomap must
5858
* never be merged with the mapping before it.
59+
*
60+
* IOMAP_F_ANON_WRITE indicates that (write) I/O does not have a target block
61+
* assigned to it yet and the file system will do that in the bio submission
62+
* handler, splitting the I/O as needed.
5963
*/
6064
#define IOMAP_F_NEW (1U << 0)
6165
#define IOMAP_F_DIRTY (1U << 1)
@@ -68,6 +72,7 @@ struct vm_fault;
6872
#endif /* CONFIG_BUFFER_HEAD */
6973
#define IOMAP_F_XATTR (1U << 5)
7074
#define IOMAP_F_BOUNDARY (1U << 6)
75+
#define IOMAP_F_ANON_WRITE (1U << 7)
7176

7277
/*
7378
* Flags set by the core iomap code during operations:
@@ -111,6 +116,8 @@ struct iomap {
111116

112117
static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos)
113118
{
119+
if (iomap->flags & IOMAP_F_ANON_WRITE)
120+
return U64_MAX; /* invalid */
114121
return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT;
115122
}
116123

0 commit comments

Comments
 (0)