[02/15] block: blk-integiry: add helper functions for bio_integrity_add_page
Commit Message
Add functions that use the hardware limit to merge the page with
integrity's bio_vec.
Using the added functions, the physically continuous pages are made of
one bio_vec.
Previously, physically continuous pages were not created as one
bio_vec, but separately created.
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-integrity.c | 58 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
Comments
s/blk-integiry/blk-integrity/ in the subject.
> +static inline bool bip_full(struct bio_integrity_payload *bip, unsigned int len)
> +static bool bip_try_merge_hw_seg(struct request_queue *q,
> + struct bio_integrity_payload *bip,
> + struct page *page, unsigned int len,
> + unsigned int offset, bool *same_page)
... but adding static functions without users will cause a compile
error anyway, so I'd suggest to just merge it into the patch adding
users.
But I wonder if we really want to duplicate all this logic anyway.
If we passed a bio_vec array, the vec count and an iter, we should
be able to just share the logic with the bio data payload.
>s/blk-integiry/blk-integrity/ in the subject.
>
>> +static inline bool bip_full(struct bio_integrity_payload *bip, unsigned int len)
>
>> +static bool bip_try_merge_hw_seg(struct request_queue *q,
>> + struct bio_integrity_payload *bip,
>> + struct page *page, unsigned int len,
>> + unsigned int offset, bool *same_page)
>
>... but adding static functions without users will cause a compile
>error anyway, so I'd suggest to just merge it into the patch adding
>users.
>
>But I wonder if we really want to duplicate all this logic anyway.
>If we passed a bio_vec array, the vec count and an iter, we should
>be able to just share the logic with the bio data payload.
Thank you, Christoph.
I made a mistake while dividing the patch. I will be careful.
I will merge with the code that uses the function and put it on the next patch.
And as you mentioned, it is duplicated with the configuration of bio's data payload.
I will improve this by reflecting your proposal.
Best regards,
Jinyoung.
@@ -111,6 +111,64 @@ void bio_integrity_free(struct bio *bio)
bio->bi_opf &= ~REQ_INTEGRITY;
}
+/**
+ * bip_full - check if the bip is full
+ * @bip: bip to check
+ * @len: length of one segment to be added
+ *
+ * Return true if @bip is full and one segment with @len bytes can't be
+ * added to the bip, otherwise return false
+ */
+static inline bool bip_full(struct bio_integrity_payload *bip, unsigned int len)
+{
+ if (bip->bip_vcnt >= bip->bip_max_vcnt)
+ return true;
+ if (bip->bip_iter.bi_size > UINT_MAX - len)
+ return true;
+ return false;
+}
+
+/**
+ * bip_try_merge_hw_seg - try to merge a page into a segment, while
+ * obeying the hardware segment size limit
+ * @q: the target queue
+ * @bip: bip to check
+ * @page: page containing integrity metadata
+ * @len: number of bytes of integrity metadata in page
+ * @offset: start offset within page
+ * @same_page: return if the segment has been merged inside the same page
+ *
+ * Return true if @page is merged to @bip, otherwise return false
+ */
+static bool bip_try_merge_hw_seg(struct request_queue *q,
+ struct bio_integrity_payload *bip,
+ struct page *page, unsigned int len,
+ unsigned int offset, bool *same_page)
+{
+ struct bio_vec *bv = &bip->bip_vec[bip->bip_vcnt - 1];
+ unsigned long mask = queue_segment_boundary(q);
+ phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
+ phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;
+
+ if ((addr1 | mask) != (addr2 | mask))
+ return false;
+ if (bv->bv_len + len > queue_max_segment_size(q))
+ return false;
+
+ if (bip->bip_vcnt > 0) {
+ if (bio_page_is_mergeable(bv, page, len, offset, same_page)) {
+ if (bip->bip_iter.bi_size > UINT_MAX - len) {
+ *same_page = false;
+ return false;
+ }
+ bv->bv_len += len;
+ bip->bip_iter.bi_size += len;
+ return true;
+ }
+ }
+ return false;
+}
+
/**
* bio_integrity_add_page - Attach integrity metadata
* @bio: bio to update