diff options
author | Max Reitz <mreitz@redhat.com> | 2020-04-29 16:11:26 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2020-05-18 19:05:25 +0200 |
commit | 2d97fde43991829f74e1e258bb82031605bf9bca (patch) | |
tree | 49987a318be3fbebcdcd0a2726cec8d2c7ac41d1 /qemu-img.c | |
parent | 2b7bbdbdefe203cf8468c61b4217e578981d6fce (diff) |
block: Use blk_make_empty() after commits
bdrv_commit() already has a BlockBackend pointing to the BDS that we
want to empty, it just has the wrong permissions.
qemu-img commit has no BlockBackend pointing to the old backing file
yet, but introducing one is simple.
After this commit, bdrv_make_empty() is the only remaining caller of
BlockDriver.bdrv_make_empty().
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200429141126.85159-5-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[kwolf: Fixed up reference output for 098]
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r-- | qemu-img.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/qemu-img.c b/qemu-img.c index 6a4327aaba..f1795c788c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1104,11 +1104,20 @@ static int img_commit(int argc, char **argv) goto unref_backing; } - if (!drop && bs->drv->bdrv_make_empty) { - ret = bs->drv->bdrv_make_empty(bs); - if (ret) { - error_setg_errno(&local_err, -ret, "Could not empty %s", - filename); + if (!drop) { + BlockBackend *old_backing_blk; + + old_backing_blk = blk_new_with_bs(bs, BLK_PERM_WRITE, BLK_PERM_ALL, + &local_err); + if (!old_backing_blk) { + goto unref_backing; + } + ret = blk_make_empty(old_backing_blk, &local_err); + blk_unref(old_backing_blk); + if (ret == -ENOTSUP) { + error_free(local_err); + local_err = NULL; + } else if (ret < 0) { goto unref_backing; } } |