mirror of
https://github.com/mii443/qemu.git
synced 2025-12-16 17:18:49 +00:00
qmp: add interface blockdev-snapshot-delete-internal-sync
This interface use id and name as optional parameters, to handle the case that one image contain multiple snapshots with same name which may be '', but with different id. Adding parameter id is for historical compatiability reason, and that case is not possible in qemu's new interface for internal snapshot at block device level, but still possible in qemu-img. Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
61
blockdev.c
61
blockdev.c
@@ -871,6 +871,67 @@ void qmp_blockdev_snapshot_internal_sync(const char *device,
|
||||
&snapshot, errp);
|
||||
}
|
||||
|
||||
SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device,
|
||||
bool has_id,
|
||||
const char *id,
|
||||
bool has_name,
|
||||
const char *name,
|
||||
Error **errp)
|
||||
{
|
||||
BlockDriverState *bs = bdrv_find(device);
|
||||
QEMUSnapshotInfo sn;
|
||||
Error *local_err = NULL;
|
||||
SnapshotInfo *info = NULL;
|
||||
int ret;
|
||||
|
||||
if (!bs) {
|
||||
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!has_id) {
|
||||
id = NULL;
|
||||
}
|
||||
|
||||
if (!has_name) {
|
||||
name = NULL;
|
||||
}
|
||||
|
||||
if (!id && !name) {
|
||||
error_setg(errp, "Name or id must be provided");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = bdrv_snapshot_find_by_id_and_name(bs, id, name, &sn, &local_err);
|
||||
if (error_is_set(&local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
return NULL;
|
||||
}
|
||||
if (!ret) {
|
||||
error_setg(errp,
|
||||
"Snapshot with id '%s' and name '%s' does not exist on "
|
||||
"device '%s'",
|
||||
STR_OR_NULL(id), STR_OR_NULL(name), device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bdrv_snapshot_delete(bs, id, name, &local_err);
|
||||
if (error_is_set(&local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info = g_malloc0(sizeof(SnapshotInfo));
|
||||
info->id = g_strdup(sn.id_str);
|
||||
info->name = g_strdup(sn.name);
|
||||
info->date_nsec = sn.date_nsec;
|
||||
info->date_sec = sn.date_sec;
|
||||
info->vm_state_size = sn.vm_state_size;
|
||||
info->vm_clock_nsec = sn.vm_clock_nsec % 1000000000;
|
||||
info->vm_clock_sec = sn.vm_clock_nsec / 1000000000;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/* New and old BlockDriverState structs for group snapshots */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user