Skip to content

Commit 908c549

Browse files
Christoph Hellwigkdave
authored andcommitted
iomap: allow the file system to provide a bio_set for direct I/O
Allow the file system to provide a specific bio_set for allocating direct I/O bios. This will allow file systems that use the ->submit_io hook to stash away additional information for file system use. To make use of this additional space for information in the completion path, the file system needs to override the ->bi_end_io callback and then call back into iomap, so export iomap_dio_bio_end_io for that. Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 36e8c62 commit 908c549

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

fs/iomap/direct-io.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ struct iomap_dio {
5151
};
5252
};
5353

54+
static struct bio *iomap_dio_alloc_bio(const struct iomap_iter *iter,
55+
struct iomap_dio *dio, unsigned short nr_vecs, unsigned int opf)
56+
{
57+
if (dio->dops && dio->dops->bio_set)
58+
return bio_alloc_bioset(iter->iomap.bdev, nr_vecs, opf,
59+
GFP_KERNEL, dio->dops->bio_set);
60+
return bio_alloc(iter->iomap.bdev, nr_vecs, opf, GFP_KERNEL);
61+
}
62+
5463
static void iomap_dio_submit_bio(const struct iomap_iter *iter,
5564
struct iomap_dio *dio, struct bio *bio, loff_t pos)
5665
{
@@ -144,7 +153,7 @@ static inline void iomap_dio_set_error(struct iomap_dio *dio, int ret)
144153
cmpxchg(&dio->error, 0, ret);
145154
}
146155

147-
static void iomap_dio_bio_end_io(struct bio *bio)
156+
void iomap_dio_bio_end_io(struct bio *bio)
148157
{
149158
struct iomap_dio *dio = bio->bi_private;
150159
bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY);
@@ -176,16 +185,16 @@ static void iomap_dio_bio_end_io(struct bio *bio)
176185
bio_put(bio);
177186
}
178187
}
188+
EXPORT_SYMBOL_GPL(iomap_dio_bio_end_io);
179189

180190
static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,
181191
loff_t pos, unsigned len)
182192
{
183193
struct inode *inode = file_inode(dio->iocb->ki_filp);
184194
struct page *page = ZERO_PAGE(0);
185-
int flags = REQ_SYNC | REQ_IDLE;
186195
struct bio *bio;
187196

188-
bio = bio_alloc(iter->iomap.bdev, 1, REQ_OP_WRITE | flags, GFP_KERNEL);
197+
bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE);
189198
fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
190199
GFP_KERNEL);
191200
bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos);
@@ -311,7 +320,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,
311320
goto out;
312321
}
313322

314-
bio = bio_alloc(iomap->bdev, nr_pages, bio_opf, GFP_KERNEL);
323+
bio = iomap_dio_alloc_bio(iter, dio, nr_pages, bio_opf);
315324
fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
316325
GFP_KERNEL);
317326
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);

include/linux/iomap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ struct iomap_dio_ops {
320320
unsigned flags);
321321
void (*submit_io)(const struct iomap_iter *iter, struct bio *bio,
322322
loff_t file_offset);
323+
324+
/*
325+
* Filesystems wishing to attach private information to a direct io bio
326+
* must provide a ->submit_io method that attaches the additional
327+
* information to the bio and changes the ->bi_end_io callback to a
328+
* custom function. This function should, at a minimum, perform any
329+
* relevant post-processing of the bio and end with a call to
330+
* iomap_dio_bio_end_io.
331+
*/
332+
struct bio_set *bio_set;
323333
};
324334

325335
/*
@@ -349,6 +359,7 @@ struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
349359
const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
350360
unsigned int dio_flags, size_t done_before);
351361
ssize_t iomap_dio_complete(struct iomap_dio *dio);
362+
void iomap_dio_bio_end_io(struct bio *bio);
352363

353364
#ifdef CONFIG_SWAP
354365
struct file;

0 commit comments

Comments
 (0)