Defragmentation may increase size of ploop image. In that case,
'ploop-discard --defrag --to-free X' command will not give us expected
result, because delta added by defrag won't be taken into account.
This patch calculates such change of image size and adds it to 'to_free'
parameter so it we will discarded later.

https://jira.sw.ru/browse/PSBM-42548
https://jira.sw.ru/browse/PSBM-45364

Signed-off-by: Andrey Ryabinin <aryabi...@virtuozzo.com>
---
 lib/balloon.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/balloon.c b/lib/balloon.c
index 6346f7c..612a6bd 100644
--- a/lib/balloon.c
+++ b/lib/balloon.c
@@ -1343,9 +1343,26 @@ int ploop_discard(struct ploop_disk_images_data *di,
        ploop_unlock_dd(di);
 
        if (param->defrag) {
+               struct ploop_discard_stat pds, pds_after;
+
+               ret = ploop_discard_get_stat_by_dev(dev, mnt, &pds);
+               if (ret)
+                       goto out;
+
                ret = ploop_defrag(di, dev, mnt);
                if (ret)
                        goto out;
+
+               ret = ploop_discard_get_stat_by_dev(dev, mnt, &pds_after);
+               if (ret)
+                       goto out;
+
+               /*
+                * Take into account possible change of ploop image size caused
+                * by defrag operation defrag operation.
+                */
+               if (param->to_free)
+                       param->to_free += pds_after.image_size - pds.image_size;
        }
 
        ret = do_ploop_discard(di, dev, mnt, param->minlen_b,
-- 
2.7.3

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to