From: Peter Krempa Date: Mon, 25 Sep 2017 09:44:00 +0000 (+0200) Subject: qemu: block: Use correct alias when extracting disk node names X-Git-Tag: v3.8.0-rc1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93575f345116fe1413f6fe3109227b8be2f416da;p=thirdparty%2Flibvirt.git qemu: block: Use correct alias when extracting disk node names The alias recorded in disk->info.alias is the alias for the frontend device but we are interested in the backend drive. This messed up the disk node name extraction code as qemu reports the drive alias in the block query commands. This was broken in the node name detector refactoring done in commit 0175dc6ea024d Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1494327 --- diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index a3da80f888..6faecb0aeb 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -20,6 +20,7 @@ #include "qemu_block.h" #include "qemu_domain.h" +#include "qemu_alias.h" #include "viralloc.h" #include "virstring.h" @@ -271,36 +272,46 @@ qemuBlockDiskDetectNodes(virDomainDiskDefPtr disk, { qemuBlockNodeNameBackingChainDataPtr entry = NULL; virStorageSourcePtr src = disk->src; + char *alias = NULL; + int ret = -1; /* don't attempt the detection if the top level already has node names */ if (src->nodeformat || src->nodestorage) return 0; - if (!(entry = virHashLookup(disktable, disk->info.alias))) - return 0; + if (!(alias = qemuAliasFromDisk(disk))) + goto cleanup; + + if (!(entry = virHashLookup(disktable, alias))) { + ret = 0; + goto cleanup; + } while (src && entry) { if (src->nodeformat || src->nodestorage) { if (STRNEQ_NULLABLE(src->nodeformat, entry->nodeformat) || STRNEQ_NULLABLE(src->nodestorage, entry->nodestorage)) - goto error; + goto cleanup; break; } else { if (VIR_STRDUP(src->nodeformat, entry->nodeformat) < 0 || VIR_STRDUP(src->nodestorage, entry->nodestorage) < 0) - goto error; + goto cleanup; } entry = entry->backing; src = src->backingStore; } - return 0; + ret = 0; - error: - qemuBlockDiskClearDetectedNodes(disk); - return -1; + cleanup: + VIR_FREE(alias); + if (ret < 0) + qemuBlockDiskClearDetectedNodes(disk); + + return ret; }