Skip to content

Commit

Permalink
bdrv_query_image_info Error parameter added
Browse files Browse the repository at this point in the history
Inform a user in case qcow2_get_specific_info fails to obtain
QCOW2 image specific information. This patch is preliminary to
the one "qcow2: Add list of bitmaps to ImageInfoSpecificQCow2".

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <1549638368-530182-2-git-send-email-andrey.shinkevich@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
a-shinkevich authored and ebblake committed Feb 11, 2019
1 parent 269ee27 commit 1bf6e9c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
5 changes: 3 additions & 2 deletions block.c
Expand Up @@ -4462,11 +4462,12 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return drv->bdrv_get_info(bs, bdi);
}

ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs)
ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs,
Error **errp)
{
BlockDriver *drv = bs->drv;
if (drv && drv->bdrv_get_specific_info) {
return drv->bdrv_get_specific_info(bs);
return drv->bdrv_get_specific_info(bs, errp);
}
return NULL;
}
Expand Down
9 changes: 3 additions & 6 deletions block/crypto.c
Expand Up @@ -594,20 +594,17 @@ static int block_crypto_get_info_luks(BlockDriverState *bs,
}

static ImageInfoSpecific *
block_crypto_get_specific_info_luks(BlockDriverState *bs)
block_crypto_get_specific_info_luks(BlockDriverState *bs, Error **errp)
{
BlockCrypto *crypto = bs->opaque;
ImageInfoSpecific *spec_info;
QCryptoBlockInfo *info;

info = qcrypto_block_get_info(crypto->block, NULL);
info = qcrypto_block_get_info(crypto->block, errp);
if (!info) {
return NULL;
}
if (info->format != Q_CRYPTO_BLOCK_FORMAT_LUKS) {
qapi_free_QCryptoBlockInfo(info);
return NULL;
}
assert(info->format == Q_CRYPTO_BLOCK_FORMAT_LUKS);

spec_info = g_new(ImageInfoSpecific, 1);
spec_info->type = IMAGE_INFO_SPECIFIC_KIND_LUKS;
Expand Down
7 changes: 6 additions & 1 deletion block/qapi.c
Expand Up @@ -282,7 +282,12 @@ void bdrv_query_image_info(BlockDriverState *bs,
info->dirty_flag = bdi.is_dirty;
info->has_dirty_flag = true;
}
info->format_specific = bdrv_get_specific_info(bs);
info->format_specific = bdrv_get_specific_info(bs, &err);
if (err) {
error_propagate(errp, err);
qapi_free_ImageInfo(info);
goto out;
}
info->has_format_specific = info->format_specific != NULL;

backing_filename = bs->backing_file;
Expand Down
10 changes: 8 additions & 2 deletions block/qcow2.c
Expand Up @@ -4368,14 +4368,20 @@ static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}

static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs)
static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs,
Error **errp)
{
BDRVQcow2State *s = bs->opaque;
ImageInfoSpecific *spec_info;
QCryptoBlockInfo *encrypt_info = NULL;
Error *local_err = NULL;

if (s->crypto != NULL) {
encrypt_info = qcrypto_block_get_info(s->crypto, &error_abort);
encrypt_info = qcrypto_block_get_info(s->crypto, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return NULL;
}
}

spec_info = g_new(ImageInfoSpecific, 1);
Expand Down
3 changes: 2 additions & 1 deletion block/vmdk.c
Expand Up @@ -2543,7 +2543,8 @@ static int coroutine_fn vmdk_co_check(BlockDriverState *bs,
return ret;
}

static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)
static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs,
Error **errp)
{
int i;
BDRVVmdkState *s = bs->opaque;
Expand Down
3 changes: 2 additions & 1 deletion include/block/block.h
Expand Up @@ -478,7 +478,8 @@ const char *bdrv_get_device_name(const BlockDriverState *bs);
const char *bdrv_get_device_or_node_name(const BlockDriverState *bs);
int bdrv_get_flags(BlockDriverState *bs);
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs);
ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs,
Error **errp);
void bdrv_round_to_clusters(BlockDriverState *bs,
int64_t offset, int64_t bytes,
int64_t *cluster_offset,
Expand Down
3 changes: 2 additions & 1 deletion include/block/block_int.h
Expand Up @@ -319,7 +319,8 @@ struct BlockDriver {
const char *name,
Error **errp);
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs);
ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs,
Error **errp);

int coroutine_fn (*bdrv_save_vmstate)(BlockDriverState *bs,
QEMUIOVector *qiov,
Expand Down
7 changes: 6 additions & 1 deletion qemu-io-cmds.c
Expand Up @@ -1661,6 +1661,7 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
BlockDriverState *bs = blk_bs(blk);
BlockDriverInfo bdi;
ImageInfoSpecific *spec_info;
Error *local_err = NULL;
char s1[64], s2[64];
int ret;

Expand All @@ -1682,7 +1683,11 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
printf("cluster size: %s\n", s1);
printf("vm state offset: %s\n", s2);

spec_info = bdrv_get_specific_info(bs);
spec_info = bdrv_get_specific_info(bs, &local_err);
if (local_err) {
error_report_err(local_err);
return -EIO;
}
if (spec_info) {
printf("Format specific information:\n");
bdrv_image_info_specific_dump(fprintf, stdout, spec_info);
Expand Down

0 comments on commit 1bf6e9c

Please sign in to comment.