There are several error messages that identify a BlockDriverState by its device name. However those errors can be produced in nodes that don't have a device name associated.
In those cases we should use bdrv_get_device_or_node_name() to fall back to the node name and produce a more meaningful message. Signed-off-by: Alberto Garcia <be...@igalia.com> --- block.c | 13 +++++++------ block/qcow.c | 4 ++-- block/qcow2.c | 2 +- block/qed.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 4 ++-- block/vpc.c | 2 +- block/vvfat.c | 3 ++- 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index af284e3..655d9aa 100644 --- a/block.c +++ b/block.c @@ -1225,7 +1225,7 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd) } else if (backing_hd) { error_setg(&bs->backing_blocker, "device is used as backing hd of '%s'", - bdrv_get_device_name(bs)); + bdrv_get_device_or_node_name(bs)); } bs->backing_hd = backing_hd; @@ -1813,7 +1813,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, if (!(reopen_state->bs->open_flags & BDRV_O_ALLOW_RDWR) && reopen_state->flags & BDRV_O_RDWR) { error_set(errp, QERR_DEVICE_IS_READ_ONLY, - bdrv_get_device_name(reopen_state->bs)); + bdrv_get_device_or_node_name(reopen_state->bs)); goto error; } @@ -1840,7 +1840,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, /* It is currently mandatory to have a bdrv_reopen_prepare() * handler for each supported drv. */ error_set(errp, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - drv->format_name, bdrv_get_device_name(reopen_state->bs), + drv->format_name, + bdrv_get_device_or_node_name(reopen_state->bs), "reopening of file"); ret = -1; goto error; @@ -3765,7 +3766,7 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) if (key) { if (!bdrv_is_encrypted(bs)) { error_setg(errp, "Device '%s' is not encrypted", - bdrv_get_device_name(bs)); + bdrv_get_device_or_node_name(bs)); } else if (bdrv_set_key(bs, key) < 0) { error_set(errp, QERR_INVALID_PASSWORD); } @@ -3773,7 +3774,7 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) if (bdrv_key_required(bs)) { error_set(errp, ERROR_CLASS_DEVICE_ENCRYPTED, "'%s' (%s) is encrypted", - bdrv_get_device_name(bs), + bdrv_get_device_or_node_name(bs), bdrv_get_encrypted_filename(bs)); } } @@ -5545,7 +5546,7 @@ bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp) blocker = QLIST_FIRST(&bs->op_blockers[op]); if (errp) { error_setg(errp, "Device '%s' is busy: %s", - bdrv_get_device_name(bs), + bdrv_get_device_or_node_name(bs), error_get_pretty(blocker->reason)); } return true; diff --git a/block/qcow.c b/block/qcow.c index 0558969..d4287ca 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -124,7 +124,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, snprintf(version, sizeof(version), "QCOW version %" PRIu32, header.version); error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_name(bs), "qcow", version); + bdrv_get_device_or_node_name(bs), "qcow", version); ret = -ENOTSUP; goto fail; } @@ -231,7 +231,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, /* Disable migration when qcow images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - "qcow", bdrv_get_device_name(bs), "live migration"); + "qcow", bdrv_get_device_or_node_name(bs), "live migration"); migrate_add_blocker(s->migration_blocker); qemu_co_mutex_init(&s->lock); diff --git a/block/qcow2.c b/block/qcow2.c index 32bdf75..168006b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -207,7 +207,7 @@ static void GCC_FMT_ATTR(3, 4) report_unsupported(BlockDriverState *bs, va_end(ap); error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_name(bs), "qcow2", msg); + bdrv_get_device_or_node_name(bs), "qcow2", msg); } static void report_unsupported_feature(BlockDriverState *bs, diff --git a/block/qed.c b/block/qed.c index 892b13c..7d32ce4 100644 --- a/block/qed.c +++ b/block/qed.c @@ -408,7 +408,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, snprintf(buf, sizeof(buf), "%" PRIx64, s->header.features & ~QED_FEATURE_MASK); error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_name(bs), "QED", buf); + bdrv_get_device_or_node_name(bs), "QED", buf); return -ENOTSUP; } if (!qed_is_cluster_size_valid(s->header.cluster_size)) { diff --git a/block/vdi.c b/block/vdi.c index 53bd02f..f0dc364 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -504,7 +504,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, /* Disable migration when vdi images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - "vdi", bdrv_get_device_name(bs), "live migration"); + "vdi", bdrv_get_device_or_node_name(bs), "live migration"); migrate_add_blocker(s->migration_blocker); qemu_co_mutex_init(&s->write_lock); diff --git a/block/vhdx.c b/block/vhdx.c index bb3ed45..d5dfe00 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1004,7 +1004,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, /* Disable migration when VHDX images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - "vhdx", bdrv_get_device_name(bs), "live migration"); + "vhdx", bdrv_get_device_or_node_name(bs), "live migration"); migrate_add_blocker(s->migration_blocker); return 0; diff --git a/block/vmdk.c b/block/vmdk.c index 8410a15..0230070 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -669,7 +669,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, snprintf(buf, sizeof(buf), "VMDK version %" PRId32, le32_to_cpu(header.version)); error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, - bdrv_get_device_name(bs), "vmdk", buf); + bdrv_get_device_or_node_name(bs), "vmdk", buf); return -ENOTSUP; } else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR)) { /* VMware KB 2064959 explains that version 3 added support for @@ -964,7 +964,7 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, /* Disable migration when VMDK images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - "vmdk", bdrv_get_device_name(bs), "live migration"); + "vmdk", bdrv_get_device_or_node_name(bs), "live migration"); migrate_add_blocker(s->migration_blocker); g_free(buf); return 0; diff --git a/block/vpc.c b/block/vpc.c index 43e768e..fd418b9 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -320,7 +320,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, /* Disable migration when VHD images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - "vpc", bdrv_get_device_name(bs), "live migration"); + "vpc", bdrv_get_device_or_node_name(bs), "live migration"); migrate_add_blocker(s->migration_blocker); return 0; diff --git a/block/vvfat.c b/block/vvfat.c index 9be632f..9ed3291 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1182,7 +1182,8 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, if (s->qcow) { error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, - "vvfat (rw)", bdrv_get_device_name(bs), "live migration"); + "vvfat (rw)", bdrv_get_device_or_node_name(bs), + "live migration"); migrate_add_blocker(s->migration_blocker); } -- 2.1.4