Skip to content

Commit

Permalink
block/snapshot: remove bdrv_snapshot_delete_by_id_or_name
Browse files Browse the repository at this point in the history
After the previous patch, the only instance of this function left
is inside qemu-img.c.

qemu-img is using it inside the 'img_snapshot' function to delete
snapshots in the SNAPSHOT_DELETE case, based on a "snapshot_name"
string that refers to the tag, not ID, of the QEMUSnapshotInfo struct.
This can be verified by checking the SNAPSHOT_CREATE case that
comes shortly before SNAPSHOT_DELETE. In that case, the same
"snapshot_name" variable is being strcpy to the 'name' field
of the QEMUSnapshotInfo struct sn:

pstrcpy(sn.name, sizeof(sn.name), snapshot_name);

Based on that, it is unlikely that "snapshot_name" might contain
an "id" in SNAPSHOT_DELETE.

This patch changes SNAPSHOT_DELETE to use snapshot_find() and
snapshot_delete() instead of bdrv_snapshot_delete_by_id_or_name.
After that, there is no instances left of bdrv_snapshot_delete_by_id_or_name
in the code, so it is safe to remove it entirely.

Suggested-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
danielhb authored and kevmw committed Feb 25, 2019
1 parent 6ca0804 commit 8c04093
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
20 changes: 0 additions & 20 deletions block/snapshot.c
Expand Up @@ -301,26 +301,6 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
return ret;
}

int bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs,
const char *id_or_name,
Error **errp)
{
int ret;
Error *local_err = NULL;

ret = bdrv_snapshot_delete(bs, id_or_name, NULL, &local_err);
if (ret == -ENOENT || ret == -EINVAL) {
error_free(local_err);
local_err = NULL;
ret = bdrv_snapshot_delete(bs, NULL, id_or_name, &local_err);
}

if (ret < 0) {
error_propagate(errp, local_err);
}
return ret;
}

int bdrv_snapshot_list(BlockDriverState *bs,
QEMUSnapshotInfo **psn_info)
{
Expand Down
3 changes: 0 additions & 3 deletions include/block/snapshot.h
Expand Up @@ -61,9 +61,6 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
const char *snapshot_id,
const char *name,
Error **errp);
int bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs,
const char *id_or_name,
Error **errp);
int bdrv_snapshot_list(BlockDriverState *bs,
QEMUSnapshotInfo **psn_info);
int bdrv_snapshot_load_tmp(BlockDriverState *bs,
Expand Down
15 changes: 11 additions & 4 deletions qemu-img.c
Expand Up @@ -3123,11 +3123,18 @@ static int img_snapshot(int argc, char **argv)
break;

case SNAPSHOT_DELETE:
bdrv_snapshot_delete_by_id_or_name(bs, snapshot_name, &err);
if (err) {
error_reportf_err(err, "Could not delete snapshot '%s': ",
snapshot_name);
ret = bdrv_snapshot_find(bs, &sn, snapshot_name);
if (ret < 0) {
error_report("Could not delete snapshot '%s': snapshot not "
"found", snapshot_name);
ret = 1;
} else {
ret = bdrv_snapshot_delete(bs, sn.id_str, sn.name, &err);
if (ret < 0) {
error_reportf_err(err, "Could not delete snapshot '%s': ",
snapshot_name);
ret = 1;
}
}
break;
}
Expand Down

0 comments on commit 8c04093

Please sign in to comment.