[v2,12/14] block: add helper function for iteration of bip's bvec

Message ID 20230510085941epcms2p8ad574939bc3edbd65b8f208c80a85911@epcms2p8
State New
Headers
Series Change the integrity configuration method in block |

Commit Message

Jinyoung Choi May 10, 2023, 8:59 a.m. UTC
  bip_for_each_vec() performs the iteration in a page unit.

Since a bio_vec of bip is composed of multi-page in the block, a macro
that can be carried out in multi-page units has been added.

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

Signed-off-by: Jinyoung Choi <j-young.choi@samsung.com>
---
 include/linux/bio.h  | 4 ++++
 include/linux/bvec.h | 6 ++++++
 2 files changed, 10 insertions(+)
  

Comments

Christoph Hellwig May 12, 2023, 1:54 p.m. UTC | #1
On Wed, May 10, 2023 at 05:59:41PM +0900, Jinyoung CHOI wrote:
> bip_for_each_vec() performs the iteration in a page unit.
> 
> Since a bio_vec of bip is composed of multi-page in the block, a macro
> that can be carried out in multi-page units has been added.

The naming here is a bit confused.  The rest of the block layers uses
_segment for the per-page iterators and _vec for the one that doesn't
break up.  I'd suggest we follow this naming scheme here.  And also
skip the extra for_each_mp_bvec level, just like we don't have that
intermediate level for bio_for_each_vec
  
Jinyoung Choi May 17, 2023, 2:35 a.m. UTC | #2
>On Wed, May 10, 2023 at 05:59:41PM +0900, Jinyoung CHOI wrote:
>> bip_for_each_vec() performs the iteration in a page unit.
>> 
>> Since a bio_vec of bip is composed of multi-page in the block, a macro
>> that can be carried out in multi-page units has been added.
>
>The naming here is a bit confused.  The rest of the block layers uses
>_segment for the per-page iterators and _vec for the one that doesn't
>break up.  I'd suggest we follow this naming scheme here.  And also
>skip the extra for_each_mp_bvec level, just like we don't have that
>intermediate level for bio_for_each_vec

Thank you for letting me know. I was not aware of the rule.
And as you said, I will make one without making the middle level.

Best Regards,
Jinyoung.
  

Patch

diff --git a/include/linux/bio.h b/include/linux/bio.h
index d766be7152e1..8b65463d4a55 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -692,6 +692,10 @@  static inline bool bioset_initialized(struct bio_set *bs)
 
 #if defined(CONFIG_BLK_DEV_INTEGRITY)
 
+/* iterate over multi-page bvec for integrity */
+#define bip_for_each_mp_bvec(bvl, bip, iter)				\
+	for_each_mp_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
+
 #define bip_for_each_vec(bvl, bip, iter)				\
 	for_each_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
 
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 555aae5448ae..9364c258513e 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -184,6 +184,12 @@  static inline void bvec_iter_advance_single(const struct bio_vec *bv,
 		((bvl = bvec_iter_bvec((bio_vec), (iter))), 1);	\
 	     bvec_iter_advance_single((bio_vec), &(iter), (bvl).bv_len))
 
+#define for_each_mp_bvec(bvl, bio_vec, iter, start)			\
+	for (iter = (start);						\
+	     (iter).bi_size &&						\
+		((bvl = mp_bvec_iter_bvec((bio_vec), (iter))), 1);	\
+	     bvec_iter_advance_single((bio_vec), &(iter), (bvl).bv_len))
+
 /* for iterating one bio from start to end */
 #define BVEC_ITER_ALL_INIT (struct bvec_iter)				\
 {									\