[rh7,1/2] ploop: Assign holes_bitmap before merge on merge-no-return point

Submitted by Kirill Tkhai on Oct. 3, 2019, 11:21 a.m.

Details

Message ID 157010164606.19364.14169211212124715933.stgit@localhost.localdomain
State New
Series "Series without cover letter"
Headers show

Commit Message

Kirill Tkhai Oct. 3, 2019, 11:21 a.m.
Since we merge clusters back into base image, we should take into
account holes into base image and reuse them firstly. Otherwise
base image may grow unexpected.

Thus, we move populate_holes_bitmap() into start_merge.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/fmt_ploop1.c |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 232f34f0e45b..4e81416f9cbe 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -599,17 +599,26 @@  ploop1_start_merge(struct ploop_delta * delta, struct ploop_snapdata * sd)
 
 	ph->bd_size = get_SizeInSectors_from_le(vh, delta->plo->fmt_version);
 
-	return delta->io.ops->sync(&delta->io);
+	err = delta->io.ops->sync(&delta->io);
+	if (err)
+		return err;
+
+	/*
+	 * Do this as last of operations, which may fail. After this,
+	 * nothing can stop killing current top_delta. Otherwise,
+	 * in case of other operation fail, we will have two deltas
+	 * and holes_bitmap assigned.
+	 */
+	if (delta->level == 0)
+		err = populate_holes_bitmap(delta, ph);
+
+	return err;
 }
 
 static int
 ploop1_complete_merge(struct ploop_delta *delta)
 {
-	struct ploop1_private *ph = delta->priv;
-
-	if (delta->level != 0)
-		return 0;
-	return populate_holes_bitmap(delta, ph);
+	return 0;
 }
 
 static int