[RFC 11/12] bio: add bio_endio_errno

Andreas Gruenbacher <[email protected]>
Newsgroups gmane.linux.kernel.device-mapper.devel,gmane.linux.block,gmane.comp.file-systems.btrfs,gmane.linux.raid,gmane.linux.kernel
Message-ID <[email protected]>
Add a bio_endio_errno() helper as a shortcut for calling bio_set_errno()
and bio_endio() in sequence. Use the new helper throughout the code.

Created with Coccinelle using the following semantic patch:

@@
expression bio, errno;
@@
- bio_set_errno(bio, errno);
- bio_endio(bio);
+ bio_endio_errno(bio, errno);

Signed-off-by: Andreas Gruenbacher <[email protected]>
---
 block/blk-merge.c                | 6 ++----
 drivers/block/drbd/drbd_req.c    | 3 +--
 drivers/md/dm-integrity.c        | 9 +++------
 drivers/md/dm-pcache/dm_pcache.c | 3 +--
 drivers/md/dm-vdo/data-vio.c     | 3 +--
 drivers/md/raid10.c              | 6 ++----
 drivers/nvdimm/pmem.c            | 4 +---
 fs/btrfs/raid56.c                | 6 ++----
 fs/iomap/ioend.c                 | 3 +--
 fs/xfs/xfs_aops.c                | 3 +--
 include/linux/bio.h              | 6 ++++++
 11 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 441013bf59d7..25057d57e9ac 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -122,8 +122,7 @@ struct bio *bio_submit_split_bioset(struct bio *bio, unsigned int split_sectors,
 	struct bio *split = bio_split(bio, split_sectors, GFP_NOIO, bs);
 
 	if (IS_ERR(split)) {
-		bio_set_errno(bio, PTR_ERR(split));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(split));
 		return NULL;
 	}
 
@@ -143,8 +142,7 @@ EXPORT_SYMBOL_GPL(bio_submit_split_bioset);
 static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
 {
 	if (unlikely(split_sectors < 0)) {
-		bio_set_errno(bio, split_sectors);
-		bio_endio(bio);
+		bio_endio_errno(bio, split_sectors);
 		return NULL;
 	}
 
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 95a58ad6fdcf..5bedc972b622 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -176,8 +176,7 @@ void start_new_tl_epoch(struct drbd_connection *connection)
 void complete_master_bio(struct drbd_device *device,
 		struct bio_and_error *m)
 {
-	bio_set_errno(m->bio, m->error);
-	bio_endio(m->bio);
+	bio_endio_errno(m->bio, m->error);
 	dec_ap_bio(device);
 }
 
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 5220e15b6537..90780a112009 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -2594,8 +2594,7 @@ static int dm_integrity_map_inline(struct dm_integrity_io *dio, bool from_map)
 
 	bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
 	if (IS_ERR(bip)) {
-		bio_set_errno(bio, PTR_ERR(bip));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(bip));
 		return DM_MAPIO_SUBMITTED;
 	}
 
@@ -2662,8 +2661,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w)
 		bip = bio_integrity_alloc(outgoing_bio, GFP_NOIO, 1);
 		if (IS_ERR(bip)) {
 			bio_put(outgoing_bio);
-			bio_set_errno(bio, PTR_ERR(bip));
-			bio_endio(bio);
+			bio_endio_errno(bio, PTR_ERR(bip));
 			return;
 		}
 
@@ -2680,8 +2678,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w)
 		r = submit_bio_wait(outgoing_bio);
 		if (unlikely(r != 0)) {
 			bio_put(outgoing_bio);
-			bio_set_errno(bio, r);
-			bio_endio(bio);
+			bio_endio_errno(bio, r);
 			return;
 		}
 		bio_put(outgoing_bio);
diff --git a/drivers/md/dm-pcache/dm_pcache.c b/drivers/md/dm-pcache/dm_pcache.c
index 4acfaab91170..b3795e88f364 100644
--- a/drivers/md/dm-pcache/dm_pcache.c
+++ b/drivers/md/dm-pcache/dm_pcache.c
@@ -74,8 +74,7 @@ static void end_req(struct kref *ref)
 		pcache_req_get(pcache_req);
 		defer_req(pcache_req);
 	} else {
-		bio_set_errno(bio, ret);
-		bio_endio(bio);
+		bio_endio_errno(bio, ret);
 
 		if (atomic_dec_and_test(&pcache->inflight_reqs))
 			wake_up(&pcache->inflight_wq);
diff --git a/drivers/md/dm-vdo/data-vio.c b/drivers/md/dm-vdo/data-vio.c
index eaa435dd8e60..47827ea61d91 100644
--- a/drivers/md/dm-vdo/data-vio.c
+++ b/drivers/md/dm-vdo/data-vio.c
@@ -287,8 +287,7 @@ static void acknowledge_data_vio(struct data_vio *data_vio)
 	if (data_vio->is_partial)
 		vdo_count_bios(&vdo->stats.bios_acknowledged_partial, bio);
 
-	bio_set_errno(bio, error);
-	bio_endio(bio);
+	bio_endio_errno(bio, error);
 }
 
 static void copy_to_bio(struct bio *bio, char *data_ptr)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 62d5bc9f7b3e..7cc27819beb5 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1665,8 +1665,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
 		split_size = stripe_size - remainder;
 		split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split);
 		if (IS_ERR(split)) {
-			bio_set_errno(bio, PTR_ERR(split));
-			bio_endio(bio);
+			bio_endio_errno(bio, PTR_ERR(split));
 			return 0;
 		}
 
@@ -1682,8 +1681,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
 		split_size = bio_sectors(bio) - remainder;
 		split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split);
 		if (IS_ERR(split)) {
-			bio_set_errno(bio, PTR_ERR(split));
-			bio_endio(bio);
+			bio_endio_errno(bio, PTR_ERR(split));
 			return 0;
 		}
 
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index aa2a486522b5..ed763c1ec955 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -232,9 +232,7 @@ static void pmem_submit_bio(struct bio *bio)
 	if (bio->bi_opf & REQ_FUA)
 		ret = nvdimm_flush(nd_region, bio);
 
-	bio_set_errno(bio, ret);
-
-	bio_endio(bio);
+	bio_endio_errno(bio, ret);
 }
 
 /* see "strong" declaration in tools/testing/nvdimm/pmem-dax.c */
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index ff802b6513af..bf45e8fd3aa1 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1750,8 +1750,7 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc)
 
 	rbio = alloc_rbio(fs_info, bioc);
 	if (IS_ERR(rbio)) {
-		bio_set_errno(bio, PTR_ERR(rbio));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(rbio));
 		return;
 	}
 	rbio->operation = BTRFS_RBIO_WRITE;
@@ -2148,8 +2147,7 @@ void raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
 
 	rbio = alloc_rbio(fs_info, bioc);
 	if (IS_ERR(rbio)) {
-		bio_set_errno(bio, PTR_ERR(rbio));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(rbio));
 		return;
 	}
 
diff --git a/fs/iomap/ioend.c b/fs/iomap/ioend.c
index 67cd48180fb2..d9e9659b55b3 100644
--- a/fs/iomap/ioend.c
+++ b/fs/iomap/ioend.c
@@ -87,8 +87,7 @@ int iomap_ioend_writeback_submit(struct iomap_writepage_ctx *wpc, int error)
 		error = -EIO;
 
 	if (error) {
-		bio_set_errno(&ioend->io_bio, error);
-		bio_endio(&ioend->io_bio);
+		bio_endio_errno(&ioend->io_bio, error);
 		return error;
 	}
 
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 61368223a069..4da13a15cb62 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -653,8 +653,7 @@ xfs_zoned_writeback_submit(
 
 	ioend->io_bio.bi_end_io = xfs_end_bio;
 	if (error) {
-		bio_set_errno(&ioend->io_bio, error);
-		bio_endio(&ioend->io_bio);
+		bio_endio_errno(&ioend->io_bio, error);
 		return error;
 	}
 	xfs_zone_alloc_and_submit(ioend, &XFS_ZWPC(wpc)->open_zone);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index ad70a88cef09..06fb8ae018c4 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -403,6 +403,12 @@ static inline void bio_set_errno(struct bio *bio, int errno)
 		WRITE_ONCE(bio->bi_status, errno_to_blk_status(errno));
 }
 
+static inline void bio_endio_errno(struct bio *bio, int errno)
+{
+	bio_set_errno(bio, errno);
+	bio_endio(bio);
+}
+
 /*
  * Calculate number of bvec segments that should be allocated to fit data
  * pointed by @iter. If @iter is backed by bvec it's going to be reused
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.