diff mbox series

[v2,01/14] block: bio: separation to reuse a part of the function

Message ID 20230510084657epcms2p69b0c426899251151a5cc7d84cedeacc7@epcms2p6 (mailing list archive)
State New, archived
Headers show
Series Change the integrity configuration method in block | expand

Commit Message

Jinyoung Choi May 10, 2023, 8:46 a.m. UTC
__bio_try_merge_page(), which is called by the general page-add functions
and the function considering the constraints of hw, was separated.

Condition tests for general page-add functions were performed in
bio_try_merge_page(). And when the parameters of __bio_try_merge_page()
were changed, there were fewer functions affected by this.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Martin K. Petersen <martin.petersen@oracle.com>

Signed-off-by: Jinyoung Choi <j-young.choi@samsung.com>
---
 block/bio.c | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index fd11614bba4d..1be17dea603a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -926,8 +926,28 @@  static inline bool page_is_mergeable(const struct bio_vec *bv,
 	return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
 }
 
+static bool __bio_try_merge_page(struct bio *bio, struct page *page,
+				 unsigned int len, unsigned int off,
+				 bool *same_page)
+{
+	struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
+
+	if (!page_is_mergeable(bv, page, len, off, same_page))
+		return false;
+
+	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;
+}
+
 /**
- * __bio_try_merge_page - try appending data to an existing bvec.
+ * 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
@@ -942,26 +962,17 @@  static inline bool page_is_mergeable(const struct bio_vec *bv,
  *
  * 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)
+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;
+	if (!bio->bi_vcnt)
+		return false;
+
+	return __bio_try_merge_page(bio, page, len, off, same_page);
 }
 
 /*
@@ -1129,7 +1140,7 @@  int bio_add_page(struct bio *bio, struct page *page,
 {
 	bool same_page = false;
 
-	if (!__bio_try_merge_page(bio, page, len, offset, &same_page)) {
+	if (!bio_try_merge_page(bio, page, len, offset, &same_page)) {
 		if (bio_full(bio, len))
 			return 0;
 		__bio_add_page(bio, page, len, offset);
@@ -1199,7 +1210,7 @@  static int bio_iov_add_page(struct bio *bio, struct page *page,
 {
 	bool same_page = false;
 
-	if (!__bio_try_merge_page(bio, page, len, offset, &same_page)) {
+	if (!bio_try_merge_page(bio, page, len, offset, &same_page)) {
 		__bio_add_page(bio, page, len, offset);
 		return 0;
 	}