mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
snapshot: create bdrv_all_delete_snapshot helper
to delete snapshots from all loaded block drivers. The patch also ensures proper locking. Signed-off-by: Denis V. Lunev <den@openvz.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> CC: Kevin Wolf <kwolf@redhat.com> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
25af925fff
commit
9b00ea376d
3 changed files with 34 additions and 44 deletions
|
@ -1916,35 +1916,6 @@ static BlockDriverState *find_vmstate_bs(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deletes snapshots of a given name in all opened images.
|
||||
*/
|
||||
static int del_existing_snapshots(Monitor *mon, const char *name)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
QEMUSnapshotInfo sn1, *snapshot = &sn1;
|
||||
Error *err = NULL;
|
||||
|
||||
bs = NULL;
|
||||
while ((bs = bdrv_next(bs))) {
|
||||
if (bdrv_can_snapshot(bs) &&
|
||||
bdrv_snapshot_find(bs, snapshot, name) >= 0) {
|
||||
bdrv_snapshot_delete_by_id_or_name(bs, name, &err);
|
||||
if (err) {
|
||||
monitor_printf(mon,
|
||||
"Error while deleting snapshot on device '%s':"
|
||||
" %s\n",
|
||||
bdrv_get_device_name(bs),
|
||||
error_get_pretty(err));
|
||||
error_free(err);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hmp_savevm(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
BlockDriverState *bs, *bs1;
|
||||
|
@ -2002,7 +1973,11 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)
|
|||
}
|
||||
|
||||
/* Delete old snapshots of the same name */
|
||||
if (name && del_existing_snapshots(mon, name) < 0) {
|
||||
if (name && bdrv_all_delete_snapshot(name, &bs1, &local_err) < 0) {
|
||||
monitor_printf(mon,
|
||||
"Error while deleting snapshot on device '%s': %s\n",
|
||||
bdrv_get_device_name(bs1), error_get_pretty(local_err));
|
||||
error_free(local_err);
|
||||
goto the_end;
|
||||
}
|
||||
|
||||
|
@ -2162,20 +2137,11 @@ void hmp_delvm(Monitor *mon, const QDict *qdict)
|
|||
return;
|
||||
}
|
||||
|
||||
bs = NULL;
|
||||
while ((bs = bdrv_next(bs))) {
|
||||
if (bdrv_can_snapshot(bs)) {
|
||||
err = NULL;
|
||||
bdrv_snapshot_delete_by_id_or_name(bs, name, &err);
|
||||
if (err) {
|
||||
monitor_printf(mon,
|
||||
"Error while deleting snapshot on device '%s':"
|
||||
" %s\n",
|
||||
bdrv_get_device_name(bs),
|
||||
error_get_pretty(err));
|
||||
error_free(err);
|
||||
}
|
||||
}
|
||||
if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
|
||||
monitor_printf(mon,
|
||||
"Error while deleting snapshot on device '%s': %s\n",
|
||||
bdrv_get_device_name(bs), error_get_pretty(err));
|
||||
error_free(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue