[libvirt] [PATCH 0/2] qemu: block: Unbreak node name detection

I've messed up a refactor. See 2/2 for details. Peter Krempa (2): qemu: block: Don't lookup node names if they are already known qemu: block: Use correct alias when extracting disk node names src/qemu/qemu_block.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) -- 2.14.1

Move the check that skips node name detection if they are already present earlier so that the hash table lookup is skipped. --- src/qemu/qemu_block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 3437302dd..a3da80f88 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -272,13 +272,13 @@ qemuBlockDiskDetectNodes(virDomainDiskDefPtr disk, qemuBlockNodeNameBackingChainDataPtr entry = NULL; virStorageSourcePtr src = disk->src; - if (!(entry = virHashLookup(disktable, disk->info.alias))) - return 0; - /* 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; + while (src && entry) { if (src->nodeformat || src->nodestorage) { if (STRNEQ_NULLABLE(src->nodeformat, entry->nodeformat) || -- 2.14.1

For some arcane reason we don't use the alias from disk->info.alias directly but prepend drive in front of it. This messed up the disk node name extraction code as qemu reports the full alias. This was broken in the node name detector refactoring done in commit 0175dc6ea024d Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1494327 --- src/qemu/qemu_block.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index a3da80f88..6faecb0ae 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; } -- 2.14.1

On Mon, Sep 25, 2017 at 11:53:07AM +0200, Peter Krempa wrote:
For some arcane reason we don't use the alias from disk->info.alias directly but prepend drive in front of it.
'disk->info.alias' is used as the ID for the frontend device (eg virtio-blk) device. IDs must be globally unique in QEMU, so we can't use the same ID for the backend ('drive') object, hence we must invent a different ID, which we do by prepending 'drive'. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 09/25/2017 11:53 AM, Peter Krempa wrote:
I've messed up a refactor. See 2/2 for details.
Peter Krempa (2): qemu: block: Don't lookup node names if they are already known qemu: block: Use correct alias when extracting disk node names
src/qemu/qemu_block.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
ACK Michal
participants (3)
-
Daniel P. Berrange
-
Michal Privoznik
-
Peter Krempa