summaryrefslogtreecommitdiffstats
path: root/block/bio.c
diff options
context:
space:
mode:
authorMing Lei <tom.leiming@gmail.com>2017-03-17 00:12:29 +0800
committerShaohua Li <shli@fb.com>2017-03-24 10:41:37 -0700
commit6f8802852f7e58a12177a86179803b9efaad98e2 (patch)
treebc5c56bd8c109ebd1b293708e2a4024b1ea68d2e /block/bio.c
parent60928a91b0b3beca4a1cf2739118f967c783f79a (diff)
downloadlinux-stable-6f8802852f7e58a12177a86179803b9efaad98e2.tar.gz
linux-stable-6f8802852f7e58a12177a86179803b9efaad98e2.tar.bz2
linux-stable-6f8802852f7e58a12177a86179803b9efaad98e2.zip
block: introduce bio_copy_data_partial
Turns out we can use bio_copy_data in raid1's write behind, and we can make alloc_behind_pages() more clean/efficient, but we need to partial version of bio_copy_data(). Signed-off-by: Ming Lei <tom.leiming@gmail.com> Reviewed-by: Jens Axboe <axboe@fb.com> Signed-off-by: Shaohua Li <shli@fb.com>
Diffstat (limited to 'block/bio.c')
-rw-r--r--block/bio.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/block/bio.c b/block/bio.c
index e75878f8b14a..1ccff0dace89 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1025,19 +1025,8 @@ int bio_alloc_pages(struct bio *bio, gfp_t gfp_mask)
}
EXPORT_SYMBOL(bio_alloc_pages);
-/**
- * bio_copy_data - copy contents of data buffers from one chain of bios to
- * another
- * @src: source bio list
- * @dst: destination bio list
- *
- * If @src and @dst are single bios, bi_next must be NULL - otherwise, treats
- * @src and @dst as linked lists of bios.
- *
- * Stops when it reaches the end of either @src or @dst - that is, copies
- * min(src->bi_size, dst->bi_size) bytes (or the equivalent for lists of bios).
- */
-void bio_copy_data(struct bio *dst, struct bio *src)
+static void __bio_copy_data(struct bio *dst, struct bio *src,
+ int offset, int size)
{
struct bvec_iter src_iter, dst_iter;
struct bio_vec src_bv, dst_bv;
@@ -1047,6 +1036,12 @@ void bio_copy_data(struct bio *dst, struct bio *src)
src_iter = src->bi_iter;
dst_iter = dst->bi_iter;
+ /* for supporting partial copy */
+ if (offset || size != src->bi_iter.bi_size) {
+ bio_advance_iter(src, &src_iter, offset);
+ src_iter.bi_size = size;
+ }
+
while (1) {
if (!src_iter.bi_size) {
src = src->bi_next;
@@ -1083,8 +1078,47 @@ void bio_copy_data(struct bio *dst, struct bio *src)
bio_advance_iter(dst, &dst_iter, bytes);
}
}
+
+/**
+ * bio_copy_data - copy contents of data buffers from one chain of bios to
+ * another
+ * @src: source bio list
+ * @dst: destination bio list
+ *
+ * If @src and @dst are single bios, bi_next must be NULL - otherwise, treats
+ * @src and @dst as linked lists of bios.
+ *
+ * Stops when it reaches the end of either @src or @dst - that is, copies
+ * min(src->bi_size, dst->bi_size) bytes (or the equivalent for lists of bios).
+ */
+void bio_copy_data(struct bio *dst, struct bio *src)
+{
+ __bio_copy_data(dst, src, 0, src->bi_iter.bi_size);
+}
EXPORT_SYMBOL(bio_copy_data);
+/**
+ * bio_copy_data_partial - copy partial contents of data buffers from one
+ * chain of bios to another
+ * @dst: destination bio list
+ * @src: source bio list
+ * @offset: starting copy from the offset
+ * @size: how many bytes to copy
+ *
+ * If @src and @dst are single bios, bi_next must be NULL - otherwise, treats
+ * @src and @dst as linked lists of bios.
+ *
+ * Stops when it reaches the end of either @src or @dst - that is, copies
+ * min(src->bi_size, dst->bi_size) bytes (or the equivalent for lists of bios).
+ */
+void bio_copy_data_partial(struct bio *dst, struct bio *src,
+ int offset, int size)
+{
+ __bio_copy_data(dst, src, offset, size);
+
+}
+EXPORT_SYMBOL(bio_copy_data_partial);
+
struct bio_map_data {
int is_our_pages;
struct iov_iter iter;