render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From 85a402fb00157daedc875f1047a2e4fe54db601a Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <85a402fb00157daedc875f1047a2e4fe54db601a@dist-git>
6ae9ed
From: Pavel Hrdina <phrdina@redhat.com>
6ae9ed
Date: Mon, 25 Jul 2016 16:26:51 +0200
6ae9ed
Subject: [PATCH] qemu_monitor_json: add support to search QOM device path by
6ae9ed
 device alias
6ae9ed
6ae9ed
Commit ce745914 introduced detection of actual video ram sizes to fix migration
6ae9ed
if QEMU decide to modify the values provided by libvirt.  This works perfectly
6ae9ed
for domains with number of video devices up to two.
6ae9ed
6ae9ed
If there are more than two video devices in the guest all the secondary devices
6ae9ed
in the XML will have the same memory values.  This is because our current code
6ae9ed
search for QOM device path only by the device type name and all the secondary
6ae9ed
video devices has the same name "qxl".
6ae9ed
6ae9ed
This patch introduces a new search function that will try to search a QOM device
6ae9ed
path using also device's alias if the alias is available. After that it will
6ae9ed
fallback to the old recursive code if the alias search found no results.
6ae9ed
6ae9ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1358728
6ae9ed
6ae9ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6ae9ed
(cherry picked from commit 4a585a884fc8cfd11f6206cd6f1a7db824395e86)
6ae9ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6ae9ed
---
6ae9ed
 src/qemu/qemu_monitor.c      | 11 ++++---
6ae9ed
 src/qemu/qemu_monitor_json.c | 77 ++++++++++++++++++++++++++++++++++++++------
6ae9ed
 src/qemu/qemu_monitor_json.h |  3 +-
6ae9ed
 3 files changed, 77 insertions(+), 14 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
6ae9ed
index 1d3d98a..e3a5e0b 100644
6ae9ed
--- a/src/qemu/qemu_monitor.c
6ae9ed
+++ b/src/qemu/qemu_monitor.c
6ae9ed
@@ -1084,10 +1084,11 @@ qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
6ae9ed
     }
6ae9ed
     mon->ballooninit = true;
6ae9ed
 
6ae9ed
-    flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", &path);
6ae9ed
+    flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", NULL, &path);
6ae9ed
     if (flp_ret == -2) {
6ae9ed
         /* pci object was not found retry search for ccw object */
6ae9ed
-        if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw", &path) < 0)
6ae9ed
+        if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw",
6ae9ed
+                                        NULL, &path) < 0)
6ae9ed
             return;
6ae9ed
     } else if (flp_ret < 0) {
6ae9ed
         return;
6ae9ed
@@ -1138,7 +1139,8 @@ qemuMonitorUpdateVideoMemorySize(qemuMonitorPtr mon,
6ae9ed
     QEMU_CHECK_MONITOR(mon);
6ae9ed
 
6ae9ed
     if (mon->json) {
6ae9ed
-        ret = qemuMonitorJSONFindLinkPath(mon, videoName, &path);
6ae9ed
+        ret = qemuMonitorJSONFindLinkPath(mon, videoName,
6ae9ed
+                                          video->info.alias, &path);
6ae9ed
         if (ret < 0) {
6ae9ed
             if (ret == -2)
6ae9ed
                 virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
@@ -1173,7 +1175,8 @@ qemuMonitorUpdateVideoVram64Size(qemuMonitorPtr mon,
6ae9ed
     QEMU_CHECK_MONITOR(mon);
6ae9ed
 
6ae9ed
     if (mon->json) {
6ae9ed
-        ret = qemuMonitorJSONFindLinkPath(mon, videoName, &path);
6ae9ed
+        ret = qemuMonitorJSONFindLinkPath(mon, videoName,
6ae9ed
+                                          video->info.alias, &path);
6ae9ed
         if (ret < 0) {
6ae9ed
             if (ret == -2)
6ae9ed
                 virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
6ae9ed
index 2890872..74bbf75 100644
6ae9ed
--- a/src/qemu/qemu_monitor_json.c
6ae9ed
+++ b/src/qemu/qemu_monitor_json.c
6ae9ed
@@ -6946,7 +6946,58 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
6ae9ed
 
6ae9ed
 
6ae9ed
 /**
6ae9ed
- * Recursively search for a QOM object link.
6ae9ed
+ * Search for a QOM object link by alias and name.
6ae9ed
+ *
6ae9ed
+ * For @alias and @name, this function tries to find QOM object named @name
6ae9ed
+ * with id @alias in /machine/peripheral.
6ae9ed
+ *
6ae9ed
+ * Returns:
6ae9ed
+ *   0  - Found
6ae9ed
+ *  -1  - Error - bail out
6ae9ed
+ *  -2  - Not found
6ae9ed
+ */
6ae9ed
+static int
6ae9ed
+qemuMonitorJSONFindObjectPathByAlias(qemuMonitorPtr mon,
6ae9ed
+                                     const char *name,
6ae9ed
+                                     const char *alias,
6ae9ed
+                                     char **path)
6ae9ed
+{
6ae9ed
+    qemuMonitorJSONListPathPtr *paths = NULL;
6ae9ed
+    char *child = NULL;
6ae9ed
+    int npaths;
6ae9ed
+    int ret = -1;
6ae9ed
+    size_t i;
6ae9ed
+
6ae9ed
+    npaths = qemuMonitorJSONGetObjectListPaths(mon, "/machine/peripheral", &paths);
6ae9ed
+    if (npaths < 0)
6ae9ed
+        return -1;
6ae9ed
+
6ae9ed
+    if (virAsprintf(&child, "child<%s>", name) < 0)
6ae9ed
+        goto cleanup;
6ae9ed
+
6ae9ed
+    for (i = 0; i < npaths; i++) {
6ae9ed
+        if (STREQ(paths[i]->name, alias) && STREQ(paths[i]->type, child)) {
6ae9ed
+            if (virAsprintf(path, "/machine/peripheral/%s", alias) < 0)
6ae9ed
+                goto cleanup;
6ae9ed
+
6ae9ed
+            ret = 0;
6ae9ed
+            goto cleanup;
6ae9ed
+        }
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    ret = -2;
6ae9ed
+
6ae9ed
+ cleanup:
6ae9ed
+    for (i = 0; i < npaths; i++)
6ae9ed
+        qemuMonitorJSONListPathFree(paths[i]);
6ae9ed
+    VIR_FREE(paths);
6ae9ed
+    VIR_FREE(child);
6ae9ed
+    return ret;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
+/**
6ae9ed
+ * Recursively search for a QOM object link only by name.
6ae9ed
  *
6ae9ed
  * For @name, this function finds the first QOM object
6ae9ed
  * named @name, recursively going through all the "child<>"
6ae9ed
@@ -6958,10 +7009,10 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
6ae9ed
  *  -2  - Not found
6ae9ed
  */
6ae9ed
 static int
6ae9ed
-qemuMonitorJSONFindObjectPath(qemuMonitorPtr mon,
6ae9ed
-                              const char *curpath,
6ae9ed
-                              const char *name,
6ae9ed
-                              char **path)
6ae9ed
+qemuMonitorJSONFindObjectPathByName(qemuMonitorPtr mon,
6ae9ed
+                                    const char *curpath,
6ae9ed
+                                    const char *name,
6ae9ed
+                                    char **path)
6ae9ed
 {
6ae9ed
     ssize_t i, npaths = 0;
6ae9ed
     int ret = -2;
6ae9ed
@@ -6995,7 +7046,7 @@ qemuMonitorJSONFindObjectPath(qemuMonitorPtr mon,
6ae9ed
                 goto cleanup;
6ae9ed
             }
6ae9ed
 
6ae9ed
-            ret = qemuMonitorJSONFindObjectPath(mon, nextpath, name, path);
6ae9ed
+            ret = qemuMonitorJSONFindObjectPathByName(mon, nextpath, name, path);
6ae9ed
             VIR_FREE(nextpath);
6ae9ed
         }
6ae9ed
     }
6ae9ed
@@ -7012,8 +7063,9 @@ qemuMonitorJSONFindObjectPath(qemuMonitorPtr mon,
6ae9ed
 /**
6ae9ed
  * Recursively search for a QOM object link.
6ae9ed
  *
6ae9ed
- * For @name, this function finds the first QOM object
6ae9ed
- * pointed to by a link in the form of 'link<@name>'
6ae9ed
+ * For @name and @alias, this function finds the first QOM object.
6ae9ed
+ * The search is done at first by @alias and @name and if nothing was found
6ae9ed
+ * it continues recursively only with @name.
6ae9ed
  *
6ae9ed
  * Returns:
6ae9ed
  *   0  - Found
6ae9ed
@@ -7023,15 +7075,22 @@ qemuMonitorJSONFindObjectPath(qemuMonitorPtr mon,
6ae9ed
 int
6ae9ed
 qemuMonitorJSONFindLinkPath(qemuMonitorPtr mon,
6ae9ed
                             const char *name,
6ae9ed
+                            const char *alias,
6ae9ed
                             char **path)
6ae9ed
 {
6ae9ed
     char *linkname = NULL;
6ae9ed
     int ret = -1;
6ae9ed
 
6ae9ed
+    if (alias) {
6ae9ed
+        ret = qemuMonitorJSONFindObjectPathByAlias(mon, name, alias, path);
6ae9ed
+        if (ret == -1 || ret == 0)
6ae9ed
+            return ret;
6ae9ed
+    }
6ae9ed
+
6ae9ed
     if (virAsprintf(&linkname, "link<%s>", name) < 0)
6ae9ed
         return -1;
6ae9ed
 
6ae9ed
-    ret = qemuMonitorJSONFindObjectPath(mon, "/", linkname, path);
6ae9ed
+    ret = qemuMonitorJSONFindObjectPathByName(mon, "/", linkname, path);
6ae9ed
     VIR_FREE(linkname);
6ae9ed
     return ret;
6ae9ed
 }
6ae9ed
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
6ae9ed
index c573ca2..114b567 100644
6ae9ed
--- a/src/qemu/qemu_monitor_json.h
6ae9ed
+++ b/src/qemu/qemu_monitor_json.h
6ae9ed
@@ -487,8 +487,9 @@ int qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
6ae9ed
 
6ae9ed
 int qemuMonitorJSONFindLinkPath(qemuMonitorPtr mon,
6ae9ed
                                 const char *name,
6ae9ed
+                                const char *alias,
6ae9ed
                                 char **path)
6ae9ed
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
6ae9ed
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
6ae9ed
 
6ae9ed
 int qemuMonitorJSONMigrateIncoming(qemuMonitorPtr mon,
6ae9ed
                                    const char *uri)
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed