Skip to contentSkip to conversation

decruft bio.h

PATCH In review Christoph Hellwig 3 participants 18 messages Oct 12, 2021 – Oct 13, 2021 Block layer

lore
Share & tools
lore
#0 lore raw

Hi Jens,

this series moves various declarations that do not need to be global out of bio.h.

Diffstat:

 block/bio.c            |  100 ++++++++++++++++++++++++++++---------------------
 block/blk-merge.c      |   31 +++++++++++++++
 block/blk-mq-sched.h   |    5 ++
 include/linux/bio.h    |   78 --------------------------------------
 include/linux/blk-mq.h |    6 ++
 5 files changed, 99 insertions(+), 121 deletions(-)
#1 lore raw

PATCH 1/8 block: remove BIO_BUG_ON

BIO_DEBUG is always defined, so just switch the two instances to use BUG_ON directly.

---
 block/bio.c         | 4 ++--
 include/linux/bio.h | 8 --------
 2 files changed, 2 insertions(+), 10 deletions(-)
block/bio.c +2 -2
index a6fb6a0b42955..35b875563c8ba 100644
@@ -156,7 +156,7 @@ static void bio_put_slab(struct bio_set *bs)
 
 void bvec_free(mempool_t *pool, struct bio_vec *bv, unsigned short nr_vecs)
 {
-	BIO_BUG_ON(nr_vecs > BIO_MAX_VECS);
+	BUG_ON(nr_vecs > BIO_MAX_VECS);
 
 	if (nr_vecs == BIO_MAX_VECS)
 		mempool_free(bv, pool);
@@ -677,7 +677,7 @@ static void bio_alloc_cache_destroy(struct bio_set *bs)
 void bio_put(struct bio *bio)
 {
 	if (unlikely(bio_flagged(bio, BIO_REFFED))) {
-		BIO_BUG_ON(!atomic_read(&bio->__bi_cnt));
+		BUG_ON(!atomic_read(&bio->__bi_cnt));
 		if (!atomic_dec_and_test(&bio->__bi_cnt))
 			return;
 	}
include/linux/bio.h +0 -8
index 00952e92eae1b..65a356fa71109 100644
@@ -11,14 +11,6 @@
 #include <linux/blk_types.h>
 #include <linux/uio.h>
 
-#define BIO_DEBUG
-
-#ifdef BIO_DEBUG
-#define BIO_BUG_ON	BUG_ON
-#else
-#define BIO_BUG_ON
-#endif
-
 #define BIO_MAX_VECS		256U
 
 static inline unsigned int bio_max_segs(unsigned int nr_segs)
Signature · 1 line
2.30.2
#3 lore raw

PATCH 2/8 block: don't include <linux/ioprio.h> in <linux/bio.h>

In reply to Christoph Hellwig

bio.h doesn't need any of the definitions from ioprio.h.

---
 include/linux/bio.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/bio.h +0 -1
index 65a356fa71109..ae94794d07c9d 100644
@@ -6,7 +6,6 @@
 #define __LINUX_BIO_H
 
 #include <linux/mempool.h>
-#include <linux/ioprio.h>
 /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */
 #include <linux/blk_types.h>
 #include <linux/uio.h>
Signature · 1 line
2.30.2
#5 lore raw

PATCH 3/8 block: move bio_mergeable out of bio.h

In reply to Christoph Hellwig

bio_mergeable is only needed by I/O schedulers, so move it to blk-mq-sched.h.

---
 block/blk-mq-sched.h | 5 +++++
 include/linux/bio.h  | 8 --------
 2 files changed, 5 insertions(+), 8 deletions(-)
block/blk-mq-sched.h +5 -0
index e4d367e0b2a30..a38d593a5e7a9 100644
@@ -31,6 +31,11 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
 void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
 void blk_mq_sched_free_rqs(struct request_queue *q);
 
+static inline bool bio_mergeable(struct bio *bio)
+{
+	return !(bio->bi_opf & REQ_NOMERGE_FLAGS);
+}
+
 static inline bool
 blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio,
 		unsigned int nr_segs)
include/linux/bio.h +0 -8
index ae94794d07c9d..ec255f2829948 100644
@@ -69,14 +69,6 @@ static inline bool bio_no_advance_iter(const struct bio *bio)
 	       bio_op(bio) == REQ_OP_WRITE_ZEROES;
 }
 
-static inline bool bio_mergeable(struct bio *bio)
-{
-	if (bio->bi_opf & REQ_NOMERGE_FLAGS)
-		return false;
-
-	return true;
-}
-
 static inline unsigned int bio_cur_bytes(struct bio *bio)
 {
 	if (bio_has_data(bio))
Signature · 1 line
2.30.2
#7 lore raw

PATCH 4/8 block: fold bio_cur_bytes into blk_rq_cur_bytes

In reply to Christoph Hellwig

Fold bio_cur_bytes into the only caller.

---
 include/linux/bio.h    | 8 --------
 include/linux/blk-mq.h | 6 +++++-
 2 files changed, 5 insertions(+), 9 deletions(-)
include/linux/bio.h +0 -8
index ec255f2829948..cffd5eba401ed 100644
@@ -69,14 +69,6 @@ static inline bool bio_no_advance_iter(const struct bio *bio)
 	       bio_op(bio) == REQ_OP_WRITE_ZEROES;
 }
 
-static inline unsigned int bio_cur_bytes(struct bio *bio)
-{
-	if (bio_has_data(bio))
-		return bio_iovec(bio).bv_len;
-	else /* dataless requests such as discard */
-		return bio->bi_iter.bi_size;
-}
-
 static inline void *bio_data(struct bio *bio)
 {
 	if (bio_has_data(bio))
include/linux/blk-mq.h +5 -1
index 0e941f2175784..2219e92771186 100644
@@ -927,7 +927,11 @@ static inline unsigned int blk_rq_bytes(const struct request *rq)
 
 static inline int blk_rq_cur_bytes(const struct request *rq)
 {
-	return rq->bio ? bio_cur_bytes(rq->bio) : 0;
+	if (!rq->bio)
+		return 0;
+	if (!bio_has_data(rq->bio))	/* dataless requests such as discard */
+		return rq->bio->bi_iter.bi_size;
+	return bio_iovec(rq->bio).bv_len;
 }
 
 unsigned int blk_rq_err_bytes(const struct request *rq);
Signature · 1 line
2.30.2
#9 lore raw

PATCH 5/8 block: move bio_full out of bio.h

In reply to Christoph Hellwig

bio_full is only used in bio.c, so move it there.

---
 block/bio.c         | 17 +++++++++++++++++
 include/linux/bio.h | 19 -------------------
 2 files changed, 17 insertions(+), 19 deletions(-)
block/bio.c +17 -0
index 35b875563c8ba..7e2899071de26 100644
@@ -772,6 +772,23 @@ const char *bio_devname(struct bio *bio, char *buf)
 }
 EXPORT_SYMBOL(bio_devname);
 
+/**
+ * bio_full - check if the bio is full
+ * @bio:	bio to check
+ * @len:	length of one segment to be added
+ *
+ * Return true if @bio is full and one segment with @len bytes can't be
+ * added to the bio, otherwise return false
+ */
+static inline bool bio_full(struct bio *bio, unsigned len)
+{
+	if (bio->bi_vcnt >= bio->bi_max_vecs)
+		return true;
+	if (bio->bi_iter.bi_size > UINT_MAX - len)
+		return true;
+	return false;
+}
+
 static inline bool page_is_mergeable(const struct bio_vec *bv,
 		struct page *page, unsigned int len, unsigned int off,
 		bool *same_page)
include/linux/bio.h +0 -19
index cffd5eba401ed..2ffc7c768091c 100644
@@ -77,25 +77,6 @@ static inline void *bio_data(struct bio *bio)
 	return NULL;
 }
 
-/**
- * bio_full - check if the bio is full
- * @bio:	bio to check
- * @len:	length of one segment to be added
- *
- * Return true if @bio is full and one segment with @len bytes can't be
- * added to the bio, otherwise return false
- */
-static inline bool bio_full(struct bio *bio, unsigned len)
-{
-	if (bio->bi_vcnt >= bio->bi_max_vecs)
-		return true;
-
-	if (bio->bi_iter.bi_size > UINT_MAX - len)
-		return true;
-
-	return false;
-}
-
 static inline bool bio_next_segment(const struct bio *bio,
 				    struct bvec_iter_all *iter)
 {
Signature · 1 line
2.30.2
#11 lore raw

PATCH 6/8 block: mark __bio_try_merge_page static

In reply to Christoph Hellwig

Mark __bio_try_merge_page static and move it up a bit to avoid the need for a forward declaration.

---
 block/bio.c         | 77 ++++++++++++++++++++++-----------------------
 include/linux/bio.h |  2 --
 2 files changed, 38 insertions(+), 41 deletions(-)
block/bio.c +38 -39
index 7e2899071de26..c89e402356a59 100644
@@ -808,6 +808,44 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
 	return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
 }
 
+/**
+ * __bio_try_merge_page - try appending data to an existing bvec.
+ * @bio: destination bio
+ * @page: start page to add
+ * @len: length of the data to add
+ * @off: offset of the data relative to @page
+ * @same_page: return if the segment has been merged inside the same page
+ *
+ * Try to add the data at @page + @off to the last bvec of @bio.  This is a
+ * useful optimisation for file systems with a block size smaller than the
+ * page size.
+ *
+ * Warn if (@len, @off) crosses pages in case that @same_page is true.
+ *
+ * Return %true on success or %false on failure.
+ */
+static bool __bio_try_merge_page(struct bio *bio, struct page *page,
+		unsigned int len, unsigned int off, bool *same_page)
+{
+	if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
+		return false;
+
+	if (bio->bi_vcnt > 0) {
+		struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
+
+		if (page_is_mergeable(bv, page, len, off, same_page)) {
+			if (bio->bi_iter.bi_size > UINT_MAX - len) {
+				*same_page = false;
+				return false;
+			}
+			bv->bv_len += len;
+			bio->bi_iter.bi_size += len;
+			return true;
+		}
+	}
+	return false;
+}
+
 /*
  * Try to merge a page into a segment, while obeying the hardware segment
  * size limit.  This is not for normal read/write bios, but for passthrough
@@ -939,45 +977,6 @@ int bio_add_zone_append_page(struct bio *bio, struct page *page,
 }
 EXPORT_SYMBOL_GPL(bio_add_zone_append_page);
 
-/**
- * __bio_try_merge_page - try appending data to an existing bvec.
- * @bio: destination bio
- * @page: start page to add
- * @len: length of the data to add
- * @off: offset of the data relative to @page
- * @same_page: return if the segment has been merged inside the same page
- *
- * Try to add the data at @page + @off to the last bvec of @bio.  This is a
- * useful optimisation for file systems with a block size smaller than the
- * page size.
- *
- * Warn if (@len, @off) crosses pages in case that @same_page is true.
- *
- * Return %true on success or %false on failure.
- */
-bool __bio_try_merge_page(struct bio *bio, struct page *page,
-		unsigned int len, unsigned int off, bool *same_page)
-{
-	if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
-		return false;
-
-	if (bio->bi_vcnt > 0) {
-		struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
-
-		if (page_is_mergeable(bv, page, len, off, same_page)) {
-			if (bio->bi_iter.bi_size > UINT_MAX - len) {
-				*same_page = false;
-				return false;
-			}
-			bv->bv_len += len;
-			bio->bi_iter.bi_size += len;
-			return true;
-		}
-	}
-	return false;
-}
-EXPORT_SYMBOL_GPL(__bio_try_merge_page);
-
 /**
  * __bio_add_page - add page(s) to a bio in a new segment
  * @bio: destination bio
include/linux/bio.h +0 -2
index 2ffc7c768091c..faa0a2fabaf08 100644
@@ -425,8 +425,6 @@ extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
 			   unsigned int, unsigned int);
 int bio_add_zone_append_page(struct bio *bio, struct page *page,
 			     unsigned int len, unsigned int offset);
-bool __bio_try_merge_page(struct bio *bio, struct page *page,
-		unsigned int len, unsigned int off, bool *same_page);
 void __bio_add_page(struct bio *bio, struct page *page,
 		unsigned int len, unsigned int off);
 int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);
Signature · 1 line
2.30.2
#13 lore raw

PATCH 7/8 block: move bio_get_{first,last}_bvec out of bio.h

In reply to Christoph Hellwig

bio_get_first_bvec and bio_get_last_bvec are only used in blk-merge.c, so move them there.

---
 block/blk-merge.c   | 31 +++++++++++++++++++++++++++++++
 include/linux/bio.h | 31 -------------------------------
 2 files changed, 31 insertions(+), 31 deletions(-)
block/blk-merge.c +31 -0
index bf7aedaad8f8e..14ce19607cd8a 100644
@@ -15,6 +15,37 @@
 #include "blk-rq-qos.h"
 #include "blk-throttle.h"
 
+static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv)
+{
+	*bv = mp_bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
+}
+
+static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv)
+{
+	struct bvec_iter iter = bio->bi_iter;
+	int idx;
+
+	bio_get_first_bvec(bio, bv);
+	if (bv->bv_len == bio->bi_iter.bi_size)
+		return;		/* this bio only has a single bvec */
+
+	bio_advance_iter(bio, &iter, iter.bi_size);
+
+	if (!iter.bi_bvec_done)
+		idx = iter.bi_idx - 1;
+	else	/* in the middle of bvec */
+		idx = iter.bi_idx;
+
+	*bv = bio->bi_io_vec[idx];
+
+	/*
+	 * iter.bi_bvec_done records actual length of the last bvec
+	 * if this bio ends in the middle of one io vector
+	 */
+	if (iter.bi_bvec_done)
+		bv->bv_len = iter.bi_bvec_done;
+}
+
 static inline bool bio_will_gap(struct request_queue *q,
 		struct request *prev_rq, struct bio *prev, struct bio *next)
 {
include/linux/bio.h +0 -31
index faa0a2fabaf08..4c5106f2ed57e 100644
@@ -221,37 +221,6 @@ static inline void bio_clear_flag(struct bio *bio, unsigned int bit)
 	bio->bi_flags &= ~(1U << bit);
 }
 
-static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv)
-{
-	*bv = mp_bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
-}
-
-static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv)
-{
-	struct bvec_iter iter = bio->bi_iter;
-	int idx;
-
-	bio_get_first_bvec(bio, bv);
-	if (bv->bv_len == bio->bi_iter.bi_size)
-		return;		/* this bio only has a single bvec */
-
-	bio_advance_iter(bio, &iter, iter.bi_size);
-
-	if (!iter.bi_bvec_done)
-		idx = iter.bi_idx - 1;
-	else	/* in the middle of bvec */
-		idx = iter.bi_idx;
-
-	*bv = bio->bi_io_vec[idx];
-
-	/*
-	 * iter.bi_bvec_done records actual length of the last bvec
-	 * if this bio ends in the middle of one io vector
-	 */
-	if (iter.bi_bvec_done)
-		bv->bv_len = iter.bi_bvec_done;
-}
-
 static inline struct bio_vec *bio_first_bvec_all(struct bio *bio)
 {
 	WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
Signature · 1 line
2.30.2
#15 lore raw

PATCH 8/8 block: mark bio_truncate static

In reply to Christoph Hellwig

bio_truncate is only used in bio.c, so mark it static.

---
 block/bio.c         | 2 +-
 include/linux/bio.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
block/bio.c +1 -1
index c89e402356a59..d5120451c36a3 100644
@@ -546,7 +546,7 @@ EXPORT_SYMBOL(zero_fill_bio);
  *   REQ_OP_READ, zero the truncated part. This function should only
  *   be used for handling corner cases, such as bio eod.
  */
-void bio_truncate(struct bio *bio, unsigned new_size)
+static void bio_truncate(struct bio *bio, unsigned new_size)
 {
 	struct bio_vec bv;
 	struct bvec_iter iter;
include/linux/bio.h +0 -1
index 4c5106f2ed57e..d8d27742a75f9 100644
@@ -405,7 +405,6 @@ extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,
 			       struct bio *src, struct bvec_iter *src_iter);
 extern void bio_copy_data(struct bio *dst, struct bio *src);
 extern void bio_free_pages(struct bio *bio);
-void bio_truncate(struct bio *bio, unsigned new_size);
 void guard_bio_eod(struct bio *bio);
 void zero_fill_bio(struct bio *bio);
 
Signature · 1 line
2.30.2
maintainer Applied
#17 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

this series moves various declarations that do not need to be global out of bio.h.

Diffstat:

Quoted 8 lines
 block/bio.c            |  100 ++++++++++++++++++++++++++++---------------------
 block/blk-merge.c      |   31 +++++++++++++++
 block/blk-mq-sched.h   |    5 ++
 include/linux/bio.h    |   78 --------------------------------------
 include/linux/blk-mq.h |    6 ++
 5 files changed, 99 insertions(+), 121 deletions(-)

[...]

Applied, thanks!

[1/8] block: remove BIO_BUG_ON

      commit: 50c1c0fdacf093dca591e36db62ffa5b68db2ba5
[2/8] block: don't include <linux/ioprio.h> in <linux/bio.h>
      commit: 572f1bca6dfd38d5bf27bb617cffbd4788adaa16
[3/8] block: move bio_mergeable out of bio.h
      commit: 272ff6fb565b310b436f3348c482f6feaeee4915
[4/8] block: fold bio_cur_bytes into blk_rq_cur_bytes
      commit: 5eb9cd2ccdf779f83870370c815630a32b7df77d
[5/8] block: move bio_full out of bio.h
      commit: 8dc8d6c0124882a931b7f00400c546de36ba888f
[6/8] block: mark __bio_try_merge_page static
      commit: 3184916715244d9382c18102e509b995d9ddd2a0
[7/8] block: move bio_get_{first,last}_bvec out of bio.h
      commit: ca52cd788dc82151876484255580bbf5e09781ed
[8/8] block: mark bio_truncate static
      commit: 55b8648b7650e7b1d2eae81521c642f80f3fd152

Best regards,

Signature · 1 line
Jens Axboe