[Devel] [PATCH RHEL7 COMMIT] ploop: Merge repeating prepare_merge patterns in single function

Konstantin Khorenko khorenko at virtuozzo.com
Mon Apr 1 14:59:43 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.7
------>
commit af2a6cbeaafb53fc648630f045f49af5b1e6f497
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri Mar 29 11:47:08 2019 +0300

    ploop: Merge repeating prepare_merge patterns in single function
    
    Less code ==> better readability.
    Also rename prepare_merge methods for better grepping.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/dev.c        | 23 ++++++++++++++++++++++-
 drivers/block/ploop/fmt_ploop1.c |  7 +------
 drivers/block/ploop/fmt_raw.c    | 14 --------------
 drivers/block/ploop/io_direct.c  |  2 +-
 drivers/block/ploop/io_kaio.c    |  2 +-
 include/linux/ploop/ploop.h      |  4 ++--
 6 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index f8b9b0bcba78..1d2167552b26 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -3782,6 +3782,27 @@ static void ploop_merge_cleanup(struct ploop_device * plo,
 	ploop_relax(plo);
 }
 
+static int ploop_prepare_merge(struct ploop_delta *next,
+			       struct ploop_snapdata *sd)
+{
+	int ret;
+
+	if (next->ops->fmt_prepare_merge) {
+		/* Format callback */
+		ret = next->ops->fmt_prepare_merge(next, sd);
+		if (ret)
+			return ret;
+	}
+
+	/* io callback */
+	ret = next->io.ops->io_prepare_merge(&next->io, sd);
+	if (ret)
+		return ret;
+
+	next->flags &= ~PLOOP_FMT_RDONLY;
+	return 0;
+}
+
 static int ploop_merge(struct ploop_device * plo)
 {
 	int err;
@@ -3813,7 +3834,7 @@ static int ploop_merge(struct ploop_device * plo)
 
 	next = list_entry(delta->list.next, struct ploop_delta, list);
 
-	err = next->ops->prepare_merge(next, &sd);
+	err = ploop_prepare_merge(next, &sd);
 	if (err) {
 		printk(KERN_WARNING "prepare_merge for ploop%d failed (%d)\n",
 		       plo->index, err);
diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 1281a343bff4..4a4aa6bf7ae2 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -393,11 +393,6 @@ ploop1_prepare_merge(struct ploop_delta * delta, struct ploop_snapdata * sd)
 			 (delta->io.plo->cluster_log + 9);
 	delta->io.alloc_head = ph->alloc_head;
 
-	err = delta->io.ops->prepare_merge(&delta->io, sd);
-	if (err)
-		return err;
-
-	delta->flags &= ~PLOOP_FMT_RDONLY;
 	return 0;
 }
 
@@ -582,7 +577,7 @@ static struct ploop_delta_ops ploop1_delta_ops =
 	.sync		=	ploop1_sync,
 	.prepare_snapshot =	ploop1_prepare_snapshot,
 	.complete_snapshot =	ploop1_complete_snapshot,
-	.prepare_merge	=	ploop1_prepare_merge,
+	.fmt_prepare_merge =	ploop1_prepare_merge,
 	.start_merge	=	ploop1_start_merge,
 	.truncate	=	ploop1_truncate,
 	.prepare_grow	=	ploop1_prepare_grow,
diff --git a/drivers/block/ploop/fmt_raw.c b/drivers/block/ploop/fmt_raw.c
index 529ea625e917..d4881a4c3c12 100644
--- a/drivers/block/ploop/fmt_raw.c
+++ b/drivers/block/ploop/fmt_raw.c
@@ -182,19 +182,6 @@ raw_complete_snapshot(struct ploop_delta * delta, struct ploop_snapdata * sd)
 	return err;
 }
 
-static int
-raw_prepare_merge(struct ploop_delta * delta, struct ploop_snapdata * sd)
-{
-	int err;
-
-	err = delta->io.ops->prepare_merge(&delta->io, sd);
-	if (err)
-		return err;
-
-	delta->flags &= ~PLOOP_FMT_RDONLY;
-	return 0;
-}
-
 static int
 raw_start_merge(struct ploop_delta * delta, struct ploop_snapdata * sd)
 {
@@ -248,7 +235,6 @@ static struct ploop_delta_ops raw_delta_ops =
 	.refresh	=	raw_refresh,
 	.prepare_snapshot =	raw_prepare_snapshot,
 	.complete_snapshot =	raw_complete_snapshot,
-	.prepare_merge	=	raw_prepare_merge,
 	.start_merge	=	raw_start_merge,
 	.prepare_grow	=	raw_prepare_grow,
 };
diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index 21cfdeb7441b..6b8cab08a0b4 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -1921,7 +1921,7 @@ static struct ploop_io_ops ploop_io_ops_direct =
 	.stop		=	dio_stop,
 	.prepare_snapshot =	dio_prepare_snapshot,
 	.complete_snapshot =	dio_complete_snapshot,
-	.prepare_merge  =	dio_prepare_merge,
+	.io_prepare_merge =	dio_prepare_merge,
 	.start_merge	=	dio_start_merge,
 	.truncate	=	dio_truncate,
 
diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 84da1cec5643..13f374ba0fe2 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -1144,7 +1144,7 @@ static struct ploop_io_ops ploop_io_ops_kaio =
 	.stop		=	kaio_stop,
 	.prepare_snapshot =	kaio_prepare_snapshot,
 	.complete_snapshot =	kaio_complete_snapshot,
-	.prepare_merge	=	kaio_prepare_merge,
+	.io_prepare_merge =	kaio_prepare_merge,
 	.start_merge	=	kaio_start_merge,
 	.truncate	=	kaio_truncate,
 
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index b209c9f096a8..b4b6adb5c60e 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -191,7 +191,7 @@ struct ploop_io_ops
 	int	(*stop)(struct ploop_io * io);
 	int	(*prepare_snapshot)(struct ploop_io *, struct ploop_snapdata *);
 	int	(*complete_snapshot)(struct ploop_io *, struct ploop_snapdata *);
-	int	(*prepare_merge)(struct ploop_io *, struct ploop_snapdata *);
+	int	(*io_prepare_merge)(struct ploop_io *, struct ploop_snapdata *);
 	int	(*start_merge)(struct ploop_io *, struct ploop_snapdata *);
 	int	(*truncate)(struct ploop_io *, struct file *, __u32 alloc_head);
 	void	(*queue_settings)(struct ploop_io *, struct request_queue *q);
@@ -281,7 +281,7 @@ struct ploop_delta_ops
 	int		(*sync)(struct ploop_delta *);
 	int		(*prepare_snapshot)(struct ploop_delta *, struct ploop_snapdata *);
 	int		(*complete_snapshot)(struct ploop_delta *, struct ploop_snapdata *);
-	int		(*prepare_merge)(struct ploop_delta *, struct ploop_snapdata *);
+	int		(*fmt_prepare_merge)(struct ploop_delta *, struct ploop_snapdata *);
 	int		(*start_merge)(struct ploop_delta *, struct ploop_snapdata *);
 	int		(*truncate)(struct ploop_delta *, struct file *, __u32 alloc_head);
 	int		(*prepare_grow)(struct ploop_delta *, u64 *new_size, int *reloc);



More information about the Devel mailing list