mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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:
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user