render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
127bba
From 27452e33f75a6bc6562d6a6992b496e9e0e25f93 Mon Sep 17 00:00:00 2001
127bba
Message-Id: <27452e33f75a6bc6562d6a6992b496e9e0e25f93@dist-git>
127bba
From: Martin Kletzander <mkletzan@redhat.com>
127bba
Date: Fri, 4 Nov 2016 10:29:43 +0100
127bba
Subject: [PATCH] qemu: Add qemuAssignDeviceShmemAlias and use it
127bba
127bba
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
127bba
(cherry picked from commit a9996a45992d6d204ec922d836b26da65e3f7191)
127bba
127bba
https://bugzilla.redhat.com/show_bug.cgi?id=1392031
127bba
127bba
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
127bba
---
127bba
 src/qemu/qemu_alias.c | 32 +++++++++++++++++++++++++++++++-
127bba
 src/qemu/qemu_alias.h |  4 ++++
127bba
 2 files changed, 35 insertions(+), 1 deletion(-)
127bba
127bba
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
127bba
index a85d3d1..9d4b1d6 100644
127bba
--- a/src/qemu/qemu_alias.c
127bba
+++ b/src/qemu/qemu_alias.c
127bba
@@ -351,6 +351,36 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
127bba
 
127bba
 
127bba
 int
127bba
+qemuAssignDeviceShmemAlias(virDomainDefPtr def,
127bba
+                           virDomainShmemDefPtr shmem,
127bba
+                           int idx)
127bba
+{
127bba
+    if (idx == -1) {
127bba
+        size_t i;
127bba
+        idx = 0;
127bba
+        for (i = 0; i < def->nshmems; i++) {
127bba
+            int thisidx;
127bba
+
127bba
+            if ((thisidx = qemuDomainDeviceAliasIndex(&def->shmems[i]->info,
127bba
+                                                      "shmem")) < 0) {
127bba
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
127bba
+                               _("Unable to determine device index "
127bba
+                                 "for shmem device"));
127bba
+                return -1;
127bba
+            }
127bba
+
127bba
+            if (thisidx >= idx)
127bba
+                idx = thisidx + 1;
127bba
+        }
127bba
+    }
127bba
+
127bba
+    if (virAsprintf(&shmem->info.alias, "shmem%d", idx) < 0)
127bba
+        return -1;
127bba
+    return 0;
127bba
+}
127bba
+
127bba
+
127bba
+int
127bba
 qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
127bba
 {
127bba
     size_t i;
127bba
@@ -419,7 +449,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
127bba
             return -1;
127bba
     }
127bba
     for (i = 0; i < def->nshmems; i++) {
127bba
-        if (virAsprintf(&def->shmems[i]->info.alias, "shmem%zu", i) < 0)
127bba
+        if (qemuAssignDeviceShmemAlias(def, def->shmems[i], i) < 0)
127bba
             return -1;
127bba
     }
127bba
     for (i = 0; i < def->nsmartcards; i++) {
127bba
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
127bba
index bb19710..6aee457 100644
127bba
--- a/src/qemu/qemu_alias.h
127bba
+++ b/src/qemu/qemu_alias.h
127bba
@@ -60,6 +60,10 @@ int qemuAssignDeviceRNGAlias(virDomainDefPtr def,
127bba
 int qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
127bba
                                 virDomainMemoryDefPtr mems);
127bba
 
127bba
+int qemuAssignDeviceShmemAlias(virDomainDefPtr def,
127bba
+                               virDomainShmemDefPtr shmem,
127bba
+                               int idx);
127bba
+
127bba
 int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
127bba
 
127bba
 int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info,
127bba
-- 
127bba
2.10.2
127bba