diff options
author | Denis V. Lunev <den@openvz.org> | 2015-11-19 09:42:03 +0300 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2015-11-19 11:50:00 +0100 |
commit | 9b00ea376d42e543feb12d7ce5435366d01aab1b (patch) | |
tree | 13e31dd2967caec0bca0b7d05a8c7e7ea2e3ee0f /migration | |
parent | 25af925fffc29f2e4c05aee10c61c823c4cdf398 (diff) |
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>
Diffstat (limited to 'migration')
-rw-r--r-- | migration/savevm.c | 54 |
1 files changed, 10 insertions, 44 deletions
diff --git a/migration/savevm.c b/migration/savevm.c index 4646aa1178..c52cbbeb3d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -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); } } |