[Devel] [PATCH RHEL7 COMMIT] ploop: Introduce ploop_submit_alloc() helper

Konstantin Khorenko khorenko at virtuozzo.com
Thu Mar 28 12:37:40 MSK 2019


The commit is pushed to "branch-rh7-3.10.0-957.10.1.vz7.85.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.10.1.vz7.85.5
------>
commit 21da5e566c60cb4d4b34ba9e3884ba827c67ad94
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu Mar 28 12:37:38 2019 +0300

    ploop: Introduce ploop_submit_alloc() helper
    
    Compress repeating code in single function.
    Add (currently unused) case, when desired
    block is passed directly.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    ploop: Discard with zeroing of ploop1 indexes support
    
    https://jira.sw.ru/browse/PSBM-92367
    https://pmc.acronis.com/browse/VSTOR-19972
    
    Kirill Tkhai (10):
          ploop: Export map defines to separate header file
          ploop: Make submit_alloc() return int value
          ploop: Introduce ploop_submit_alloc() helper
          ploop: Prohibit discard ioctls
          ploop: Prohibit PLOOP_IOC_UPDATE_INDEX on singular list
          ploop: Introduce data_off_in_clusters() helper
          ploop: Add .complete_merge method
          ploop: Zero indexes on discard
          ploop: Fallocate cluster in cached_submit() during hole reuse
          ploop: Populate and maintain holes bitmap
---
 drivers/block/ploop/fmt_ploop1.c |  2 +-
 drivers/block/ploop/fmt_raw.c    |  2 +-
 drivers/block/ploop/io.c         | 39 +++++++++++++++++++++++++++++++++++++++
 drivers/block/ploop/io_direct.c  | 14 ++------------
 drivers/block/ploop/io_kaio.c    | 13 +------------
 include/linux/ploop/ploop.h      |  5 +++--
 6 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 382737b4cb6c..eea15aac8790 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -235,7 +235,7 @@ ploop1_allocate(struct ploop_delta * delta, struct ploop_request * preq,
 		PLOOP_FAIL_REQUEST(preq, -E2BIG);
 		return;
 	}
-	delta->io.ops->submit_alloc(&delta->io, preq, sbl, size);
+	ploop_submit_alloc(delta, preq, sbl, size, 0);
 }
 
 /* Call this when data write is complete */
diff --git a/drivers/block/ploop/fmt_raw.c b/drivers/block/ploop/fmt_raw.c
index 529ea625e917..93164e282955 100644
--- a/drivers/block/ploop/fmt_raw.c
+++ b/drivers/block/ploop/fmt_raw.c
@@ -98,7 +98,7 @@ static void
 raw_allocate(struct ploop_delta * delta, struct ploop_request * preq,
 		struct bio_list * sbl, unsigned int size)
 {
-	delta->io.ops->submit_alloc(&delta->io, preq, sbl, size);
+	ploop_submit_alloc(delta, preq, sbl, size, 0);
 }
 
 int raw_map_index(struct ploop_delta * delta, unsigned long index, sector_t *sec)
diff --git a/drivers/block/ploop/io.c b/drivers/block/ploop/io.c
index eadcec4e1fcb..a6460c870bf8 100644
--- a/drivers/block/ploop/io.c
+++ b/drivers/block/ploop/io.c
@@ -11,6 +11,7 @@
 
 #include <linux/ploop/ploop.h>
 #include <linux/ploop/ploop_if.h>
+#include "ploop_events.h"
 
 /* Generic IO routines. */
 
@@ -148,3 +149,41 @@ void ploop_io_report_fn(struct file * file, char * msg)
 		free_page((unsigned long)path);
 }
 EXPORT_SYMBOL(ploop_io_report_fn);
+
+int ploop_submit_alloc(struct ploop_delta *delta, struct ploop_request *preq,
+		       struct bio_list *sbl, unsigned int size, iblock_t iblk)
+{
+	struct ploop_io *io = &delta->io;
+	bool advanced = false;
+	int ret;
+
+	trace_submit_alloc(preq);
+
+	if (!(io->files.file->f_mode & FMODE_WRITE) ||
+	    (delta->flags & PLOOP_FMT_RDONLY)) {
+		PLOOP_FAIL_REQUEST(preq, -EBADF);
+		return -1;
+	}
+
+	if (!iblk)
+		iblk = io->alloc_head;
+	if (iblk == io->alloc_head) {
+		/*
+		 * Note, even if not zero iblk was passed as parameter,
+		 * alloc_head also must be incremented.
+		 */
+		io->alloc_head++;
+		advanced = true;
+	}
+
+	ret = io->ops->submit_alloc(io, preq, sbl, size, iblk);
+
+	/* FIXME: why original code handles only ENOSPC? */
+	if ((ret == 0 || ret == -ENOSPC) && advanced)
+		io->alloc_head--;
+
+	WARN_ON(iblk > io->alloc_head);
+
+	return ret;
+}
+EXPORT_SYMBOL(ploop_submit_alloc);
diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index b1955d339de5..ad95cce91f6e 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -732,24 +732,14 @@ dio_submit_pad(struct ploop_io *io, struct ploop_request * preq,
 
 static int
 dio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
-		 struct bio_list * sbl, unsigned int size)
+		 struct bio_list * sbl, unsigned int size, iblock_t iblk)
 {
 	int err;
-	iblock_t iblk = io->alloc_head++;
-
-	trace_submit_alloc(preq);
-
-	if (!(io->files.file->f_mode & FMODE_WRITE)) {
-		PLOOP_FAIL_REQUEST(preq, -EBADF);
-		return -1;
-	}
 
 	err = cached_submit(io, iblk, preq, sbl, size, true);
 	if (err) {
-		if (err == -ENOSPC)
-			io->alloc_head--;
 		PLOOP_FAIL_REQUEST(preq, err);
-		return -1;
+		return err;
 	}
 	preq->eng_state = PLOOP_E_DATA_WBI;
 	return 1;
diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 1e4ae6efbe70..b5eb92d9523a 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -548,21 +548,12 @@ static int kaio_fsync_thread(void * data)
 
 static int
 kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
-		 struct bio_list * sbl, unsigned int size)
+		 struct bio_list * sbl, unsigned int size, iblock_t iblk)
 {
-	struct ploop_delta *delta = container_of(io, struct ploop_delta, io);
-	iblock_t iblk;
 	int log = preq->plo->cluster_log + 9;
 	loff_t clu_siz = 1 << log;
 	loff_t end_pos = (loff_t)io->alloc_head << log;
 
-	if (delta->flags & PLOOP_FMT_RDONLY) {
-		PLOOP_FAIL_REQUEST(preq, -EBADF);
-		return -1;
-	}
-
-	iblk = io->alloc_head;
-
 	if (unlikely(preq->req_rw & REQ_FLUSH)) {
 		spin_lock_irq(&io->plo->lock);
 		kaio_queue_fsync_req(preq);
@@ -594,8 +585,6 @@ kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
 		}
 	}
 
-	io->alloc_head++;
-
 	preq->iblock = iblk;
 	preq->eng_state = PLOOP_E_DATA_WBI;
 
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index 599f7dbff7f2..73141c536f65 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -160,7 +160,7 @@ struct ploop_io_ops
 			  unsigned long rw,
 			  struct bio_list *sbl, iblock_t iblk, unsigned int size);
 	int	(*submit_alloc)(struct ploop_io *, struct ploop_request *,
-				struct bio_list *sbl, unsigned int size);
+				struct bio_list *, unsigned int, iblock_t);
 	void	(*post_submit)(struct ploop_io *, struct ploop_request *);
 
 	int	(*disable_merge)(struct ploop_io * io, sector_t isector, unsigned int len);
@@ -890,7 +890,8 @@ void ploop_index_wb_complete(struct ploop_request * preq);
 int __init ploop_map_init(void);
 void ploop_map_exit(void);
 void ploop_add_req_to_fsync_queue(struct ploop_request * preq);
-
+int ploop_submit_alloc(struct ploop_delta *delta, struct ploop_request *preq,
+		       struct bio_list *sbl, unsigned int size, iblock_t iblk);
 
 void ploop_quiesce(struct ploop_device * plo);
 void ploop_relax(struct ploop_device * plo);



More information about the Devel mailing list