Skip to content

Commit

Permalink
iomap: add a filesystem hook for direct I/O bio submission
Browse files Browse the repository at this point in the history
This helps filesystems to perform tasks on the bio while submitting for
I/O. This could be post-write operations such as data CRC or data
replication for fs-handled RAID.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Goldwyn Rodrigues authored and David Sterba committed May 25, 2020
1 parent d85dc2e commit 8cecd0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions fs/iomap/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ int iomap_dio_iopoll(struct kiocb *kiocb, bool spin)
EXPORT_SYMBOL_GPL(iomap_dio_iopoll);

static void iomap_dio_submit_bio(struct iomap_dio *dio, struct iomap *iomap,
struct bio *bio)
struct bio *bio, loff_t pos)
{
atomic_inc(&dio->ref);

if (dio->iocb->ki_flags & IOCB_HIPRI)
bio_set_polled(bio, dio->iocb);

dio->submit.last_queue = bdev_get_queue(iomap->bdev);
dio->submit.cookie = submit_bio(bio);
if (dio->dops && dio->dops->submit_io)
dio->submit.cookie = dio->dops->submit_io(
file_inode(dio->iocb->ki_filp),
iomap, bio, pos);
else
dio->submit.cookie = submit_bio(bio);
}

static ssize_t iomap_dio_complete(struct iomap_dio *dio)
Expand Down Expand Up @@ -191,7 +196,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,
get_page(page);
__bio_add_page(bio, page, len, 0);
bio_set_op_attrs(bio, REQ_OP_WRITE, flags);
iomap_dio_submit_bio(dio, iomap, bio);
iomap_dio_submit_bio(dio, iomap, bio, pos);
}

static loff_t
Expand Down Expand Up @@ -299,11 +304,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
}

dio->size += n;
pos += n;
copied += n;

nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
iomap_dio_submit_bio(dio, iomap, bio);
iomap_dio_submit_bio(dio, iomap, bio, pos);
pos += n;
} while (nr_pages);

/*
Expand Down
2 changes: 2 additions & 0 deletions include/linux/iomap.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ int iomap_writepages(struct address_space *mapping,
struct iomap_dio_ops {
int (*end_io)(struct kiocb *iocb, ssize_t size, int error,
unsigned flags);
blk_qc_t (*submit_io)(struct inode *inode, struct iomap *iomap,
struct bio *bio, loff_t file_offset);
};

ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
Expand Down

0 comments on commit 8cecd0b

Please sign in to comment.