[RHEL7,COMMIT] ploop: Extrack extent-related logic from dio_sync_io()

Submitted by Konstantin Khorenko on July 5, 2019, 7:50 a.m.

Details

Message ID 201907050750.x657o46h010827@finist-ce7.sw.ru
State New
Series "ploop: Remove duplicated and unused functions"
Headers show

Commit Message

Konstantin Khorenko July 5, 2019, 7:50 a.m.
The commit is pushed to "branch-rh7-3.10.0-957.21.3.vz7.106.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.21.3.vz7.106.4
------>
commit a3f5c130b3511faa8a0da0735cd5a050825238bf
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Fri Jul 5 10:50:04 2019 +0300

    ploop: Extrack extent-related logic from dio_sync_io()
    
    This patch moves the code related to extents to separate
    function.
    
    Since we don't know the number of bios, which will be
    submitted, we set counter into INT_MAX, and then decrement
    it in required number.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/io_direct.c | 58 +++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 20 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index 4681ee980c66..238ecb0f1cdb 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -1065,26 +1065,19 @@  DEFINE_BIO_CB(dio_endio_sync)
 END_BIO_CB(dio_endio_sync)
 
 static int
-dio_sync_io(struct ploop_io * io, int rw, struct page * page,
-	    unsigned int len, unsigned int off, sector_t sec)
+dio_make_io(struct ploop_io *io, int rw, struct page *page,
+	    unsigned int len, unsigned int off, sector_t sec,
+	    bio_end_io_t *bi_end_io, void *bi_private)
 {
 	struct bio_list bl = BIO_EMPTY_LIST;
 	struct bio * bio;
-	struct dio_comp comp;
 	struct extent_map * em;
+	int nr_bios = 0, err;
 	sector_t nsec;
-	int err;
-
-	BUG_ON(len & 511);
-	BUG_ON(off & 511);
 
 	bio = NULL;
 	em = NULL;
 
-	init_completion(&comp.comp);
-	atomic_set(&comp.count, 1);
-	comp.error = 0;
-
 	while (len > 0) {
 		int copy;
 
@@ -1130,18 +1123,13 @@  dio_sync_io(struct ploop_io * io, int rw, struct page * page,
 		bl.head = b->bi_next;
 
 		b->bi_next = NULL;
-		b->bi_end_io = dio_endio_sync;
-		b->bi_private = &comp;
-		atomic_inc(&comp.count);
+		b->bi_end_io = bi_end_io;
+		b->bi_private = bi_private;
+		nr_bios++;
 		submit_bio(rw, b);
 	}
 
-	if (atomic_dec_and_test(&comp.count))
-		complete(&comp.comp);
-
-	wait_for_completion(&comp.comp);
-
-	return comp.error;
+	return nr_bios;
 
 
 enomem:
@@ -1160,6 +1148,36 @@  dio_sync_io(struct ploop_io * io, int rw, struct page * page,
 	return err;
 }
 
+static int
+dio_sync_io(struct ploop_io *io, int rw, struct page *page,
+	    unsigned int len, unsigned int off, sector_t sec)
+{
+	struct dio_comp comp;
+	int nr_bios;
+
+	BUG_ON((len & 511) || (off & 511));
+
+	/*
+	 * We set initial count to INT_MAX, so dio_endio_sync()
+	 * never makes it 0 before we've done atomic_sub_and_test().
+	 */
+	atomic_set(&comp.count, INT_MAX);
+	init_completion(&comp.comp);
+	comp.error = 0;
+
+	nr_bios = dio_make_io(io, rw, page, len, off, sec,
+			      dio_endio_sync, &comp);
+	if (nr_bios < 0)
+		return nr_bios;
+
+	if (atomic_sub_and_test(INT_MAX - nr_bios, &comp.count))
+		complete(&comp.comp);
+
+	wait_for_completion(&comp.comp);
+
+	return comp.error;
+}
+
 static int
 dio_sync_read(struct ploop_io * io, struct page * page, unsigned int len,
 	      unsigned int off, sector_t pos)