[07/10] ploop: Add .complete_merge method

Submitted by Kirill Tkhai on March 26, 2019, 3:19 p.m.

Details

Message ID 155361355323.12708.7539514638168380422.stgit@localhost.localdomain
State New
Series "ploop: Discard with zeroing of ploop1 indexes support"
Headers show

Commit Message

Kirill Tkhai March 26, 2019, 3:19 p.m.
It will be used to reallocated holes bitmap
after merge.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/dev.c           |   17 ++++++++++++-----
 drivers/block/ploop/io_direct_map.c |    2 ++
 include/linux/ploop/ploop.h         |    1 +
 3 files changed, 15 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 57920a93129a..618d22bf02ec 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -3762,18 +3762,25 @@  static void ploop_update_fmt_version(struct ploop_device * plo)
 	}
 }
 
-static void ploop_merge_cleanup(struct ploop_device * plo,
-				struct ploop_map * map,
-				struct ploop_delta * delta, int err)
+static void ploop_merge_complete(struct ploop_device * plo,
+				 struct ploop_map * map,
+				 struct ploop_delta * delta, int err)
 {
+	struct ploop_delta *top_delta;
+
 	ploop_quiesce(plo);
 	mutex_lock(&plo->sysfs_mutex);
 	list_del(&delta->list);
 
 	if (err)
 		list_add(&delta->list, &plo->map.delta_list);
-	else
+	else {
+		top_delta = ploop_top_delta(plo);
+		if (top_delta->ops->complete_merge)
+			/* FIXME: How should we handle error here? */
+			top_delta->ops->complete_merge(top_delta);
 		ploop_update_fmt_version(plo);
+	}
 
 	plo->trans_map = NULL;
 	plo->maintenance_type = PLOOP_MNTN_OFF;
@@ -3873,7 +3880,7 @@  static int ploop_merge(struct ploop_device * plo)
 		err = -EIO;
 	}
 
-	ploop_merge_cleanup(plo, map, delta, err);
+	ploop_merge_complete(plo, map, delta, err);
 
 	if (!err) {
 		kobject_del(&delta->kobj);
diff --git a/drivers/block/ploop/io_direct_map.c b/drivers/block/ploop/io_direct_map.c
index bc65e60e72a3..7934bc8ecfb1 100644
--- a/drivers/block/ploop/io_direct_map.c
+++ b/drivers/block/ploop/io_direct_map.c
@@ -620,6 +620,8 @@  static int fallocate_cluster(struct ploop_io *io, struct inode *inode,
 	}
 
 	ret = file->f_op->fallocate(file, FALLOC_FL_KEEP_SIZE, start_off, len);
+	if (!ret)
+		ret = io->ops->sync(io);
 out:
 	return ret;
 }
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index 73141c536f65..a730c2de7873 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -283,6 +283,7 @@  struct ploop_delta_ops
 	int		(*complete_snapshot)(struct ploop_delta *, struct ploop_snapdata *);
 	int		(*prepare_merge)(struct ploop_delta *, struct ploop_snapdata *);
 	int		(*start_merge)(struct ploop_delta *, struct ploop_snapdata *);
+	int		(*complete_merge)(struct ploop_delta *);
 	int		(*truncate)(struct ploop_delta *, struct file *, __u32 alloc_head);
 	int		(*prepare_grow)(struct ploop_delta *, u64 *new_size, int *reloc);
 	int		(*complete_grow)(struct ploop_delta *, u64 new_size);