[RHEL7,COMMIT] ploop: Extract extent-related logic from dio_io_page()

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

Details

Message ID 201907050750.x657o5Jw010878@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 ff98f707bf272e72fb67a8437e0b5d4b9b30e961
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Fri Jul 5 10:50:05 2019 +0300

    ploop: Extract extent-related logic from dio_io_page()
    
    Similar to previous patch, extract extent-related code
    into separate function.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/io_direct.c | 57 ++++++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 15 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index 238ecb0f1cdb..092a79bb4522 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -1299,16 +1299,16 @@  static int dio_alloc_sync(struct ploop_io * io, loff_t pos, loff_t len)
 	return err;
 }
 
-static void
-dio_io_page(struct ploop_io * io, unsigned long rw,
-	    struct ploop_request * preq, struct page * page,
-	    sector_t sec)
+static int
+__dio_io_page(struct ploop_io *io, unsigned long rw, struct page *page,
+	    sector_t sec, bio_end_io_t *bi_end_io, void *bi_private)
 {
 	struct bio_list bl = BIO_EMPTY_LIST;
 	struct bio * bio;
 	unsigned int len;
 	struct extent_map * em;
 	sector_t nsec;
+	int nr_bios = 0;
 	int err;
 	int off;
 
@@ -1316,10 +1316,6 @@  dio_io_page(struct ploop_io * io, unsigned long rw,
 	em = NULL;
 	off = 0;
 
-	ploop_prepare_io_request(preq);
-	if (rw & REQ_WRITE)
-		ploop_prepare_tracker(preq, sec);
-
 	len = PAGE_SIZE;
 
 	while (len > 0) {
@@ -1367,15 +1363,13 @@  dio_io_page(struct ploop_io * io, unsigned long rw,
 		bl.head = b->bi_next;
 
 		b->bi_next = NULL;
-		b->bi_end_io = dio_endio_async;
-		b->bi_private = preq;
-		atomic_inc(&preq->io_count);
-		ploop_acc_ff_out(preq->plo, rw | b->bi_rw);
+		b->bi_end_io = bi_end_io;
+		b->bi_private = bi_private;
+		nr_bios++;
 		submit_bio(rw, b);
 	}
 
-	ploop_complete_io_request(preq);
-	return;
+	return nr_bios;
 
 enomem:
 	err = -ENOMEM;
@@ -1390,9 +1384,42 @@  dio_io_page(struct ploop_io * io, unsigned long rw,
 		b->bi_next = NULL;
 		bio_put(b);
 	}
-	PLOOP_FAIL_REQUEST(preq, err);
+	return err;
 }
 
+static void
+dio_io_page(struct ploop_io * io, unsigned long rw,
+	    struct ploop_request * preq, struct page * page,
+	    sector_t sec)
+{
+	int nr_bios;
+
+	/*
+	 * The same as in dio_sync_io(). See comment there.
+	 *
+	 * ploop_prepare_io_request(preq).
+	 */
+	atomic_set(&preq->io_count, INT_MAX);
+
+	if (rw & REQ_WRITE)
+		ploop_prepare_tracker(preq, sec);
+
+	nr_bios = __dio_io_page(io, rw, page, sec, dio_endio_async, preq);
+	if (nr_bios < 0) {
+		/* Just for uniformity -- make the counter 1 */
+		ploop_prepare_io_request(preq);
+		PLOOP_FAIL_REQUEST(preq, nr_bios);
+		return;
+	}
+
+	ploop_acc_ff_out(preq->plo, rw);
+
+	/* ploop_complete_io_request(preq) */
+	if (atomic_sub_and_test(INT_MAX - nr_bios, &preq->io_count))
+                ploop_complete_io_state(preq);
+}
+
+
 static void
 dio_read_page(struct ploop_io * io, struct ploop_request * preq,
 	      struct page * page, sector_t sec)