virt-format: Discard the data on the disks.

If possible, this means that the host will be able to reclaim most of
the space used by formatted disks.
This commit is contained in:
Richard W.M. Jones
2014-03-11 14:20:53 +00:00
parent 93f1bfcad7
commit fb3afdff47
3 changed files with 19 additions and 0 deletions

View File

@@ -188,6 +188,11 @@ main (int argc, char *argv[])
case 'a':
OPTION_a;
/* Enable discard on all drives added on the command line. */
assert (drvs != NULL);
assert (drvs->type == drv_a);
drvs->a.discard = "besteffort";
break;
case 'v':
@@ -342,6 +347,14 @@ do_format (void)
}
}
/* Send TRIM/UNMAP to all block devices, to give back the space to
* the host. However don't fail if this doesn't work.
*/
guestfs_push_error_handler (g, NULL, NULL);
for (i = 0; devices[i] != NULL; ++i)
guestfs_blkdiscard (g, devices[i]);
guestfs_pop_error_handler (g);
if (do_rescan (devices))
return 1; /* which means, reopen the handle and retry */