render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From 61f6ae8700cb06aeb73bf8bcb447b50c1af701e4 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <61f6ae8700cb06aeb73bf8bcb447b50c1af701e4@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Mon, 24 Nov 2014 17:51:13 +0100
9119d9
Subject: [PATCH] qemu: monitor: Rename and improve qemuMonitorGetPtyPaths
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1146944
9119d9
9119d9
To unify future additions that require information from "query-chardev"
9119d9
rename qemuMonitorGetPtyPaths and friends to qemuMonitorGetChardevInfo
9119d9
and move the allocation of the returned hash into the top level
9119d9
function.
9119d9
9119d9
(cherry picked from commit e9a4506963fb70d2b8cbf31a2fe77ec68bacd397)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_monitor.c      | 31 +++++++++++++++++++++++--------
9119d9
 src/qemu/qemu_monitor.h      |  4 ++--
9119d9
 src/qemu/qemu_monitor_json.c | 15 +++++++++------
9119d9
 src/qemu/qemu_monitor_json.h |  4 ++--
9119d9
 src/qemu/qemu_monitor_text.c |  6 +++---
9119d9
 src/qemu/qemu_monitor_text.h |  4 ++--
9119d9
 src/qemu/qemu_process.c      | 28 ++++++++++++----------------
9119d9
 tests/qemumonitorjsontest.c  | 26 +++++++++++++-------------
9119d9
 8 files changed, 66 insertions(+), 52 deletions(-)
9119d9
9119d9
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
9119d9
index d2f0b46..09935f5 100644
9119d9
--- a/src/qemu/qemu_monitor.c
9119d9
+++ b/src/qemu/qemu_monitor.c
9119d9
@@ -2972,24 +2972,39 @@ qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
9119d9
 }
9119d9
 
9119d9
 
9119d9
-int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
9119d9
-                           virHashTablePtr paths)
9119d9
+int
9119d9
+qemuMonitorGetChardevInfo(qemuMonitorPtr mon,
9119d9
+                          virHashTablePtr *retinfo)
9119d9
 {
9119d9
     int ret;
9119d9
-    VIR_DEBUG("mon=%p",
9119d9
-          mon);
9119d9
+    virHashTablePtr info = NULL;
9119d9
+
9119d9
+    VIR_DEBUG("mon=%p retinfo=%p", mon, retinfo);
9119d9
 
9119d9
     if (!mon) {
9119d9
         virReportError(VIR_ERR_INVALID_ARG, "%s",
9119d9
                        _("monitor must not be NULL"));
9119d9
-        return -1;
9119d9
+        goto error;
9119d9
     }
9119d9
 
9119d9
+    if (!(info = virHashCreate(10, virHashValueFree)))
9119d9
+        goto error;
9119d9
+
9119d9
     if (mon->json)
9119d9
-        ret = qemuMonitorJSONGetPtyPaths(mon, paths);
9119d9
+        ret = qemuMonitorJSONGetChardevInfo(mon, info);
9119d9
     else
9119d9
-        ret = qemuMonitorTextGetPtyPaths(mon, paths);
9119d9
-    return ret;
9119d9
+        ret = qemuMonitorTextGetChardevInfo(mon, info);
9119d9
+
9119d9
+    if (ret < 0)
9119d9
+        goto error;
9119d9
+
9119d9
+    *retinfo = info;
9119d9
+    return 0;
9119d9
+
9119d9
+ error:
9119d9
+    virHashFree(info);
9119d9
+    *retinfo = NULL;
9119d9
+    return -1;
9119d9
 }
9119d9
 
9119d9
 
9119d9
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
9119d9
index 70bb608..b63799b 100644
9119d9
--- a/src/qemu/qemu_monitor.h
9119d9
+++ b/src/qemu/qemu_monitor.h
9119d9
@@ -639,8 +639,8 @@ int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
9119d9
 int qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
9119d9
                              virNetDevRxFilterPtr *filter);
9119d9
 
9119d9
-int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
9119d9
-                           virHashTablePtr paths);
9119d9
+int qemuMonitorGetChardevInfo(qemuMonitorPtr mon,
9119d9
+                              virHashTablePtr *retinfo);
9119d9
 
9119d9
 int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
9119d9
                                        const char *bus,
9119d9
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
9119d9
index f1f65ea..bf28832 100644
9119d9
--- a/src/qemu/qemu_monitor_json.c
9119d9
+++ b/src/qemu/qemu_monitor_json.c
9119d9
@@ -3539,8 +3539,9 @@ qemuMonitorJSONQueryRxFilter(qemuMonitorPtr mon, const char *alias,
9119d9
  * ]}
9119d9
  *
9119d9
  */
9119d9
-static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
9119d9
-                                          virHashTablePtr paths)
9119d9
+static int
9119d9
+qemuMonitorJSONExtractChardevInfo(virJSONValuePtr reply,
9119d9
+                                  virHashTablePtr info)
9119d9
 {
9119d9
     virJSONValuePtr data;
9119d9
     int ret = -1;
9119d9
@@ -3585,7 +3586,7 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
9119d9
             if (VIR_STRDUP(path, type + strlen("pty:")) < 0)
9119d9
                 goto cleanup;
9119d9
 
9119d9
-            if (virHashAddEntry(paths, id, path) < 0) {
9119d9
+            if (virHashAddEntry(info, id, path) < 0) {
9119d9
                 virReportError(VIR_ERR_OPERATION_FAILED,
9119d9
                                _("failed to save chardev path '%s'"), path);
9119d9
                 VIR_FREE(path);
9119d9
@@ -3600,8 +3601,10 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
9119d9
     return ret;
9119d9
 }
9119d9
 
9119d9
-int qemuMonitorJSONGetPtyPaths(qemuMonitorPtr mon,
9119d9
-                               virHashTablePtr paths)
9119d9
+
9119d9
+int
9119d9
+qemuMonitorJSONGetChardevInfo(qemuMonitorPtr mon,
9119d9
+                              virHashTablePtr info)
9119d9
 
9119d9
 {
9119d9
     int ret;
9119d9
@@ -3618,7 +3621,7 @@ int qemuMonitorJSONGetPtyPaths(qemuMonitorPtr mon,
9119d9
         ret = qemuMonitorJSONCheckError(cmd, reply);
9119d9
 
9119d9
     if (ret == 0)
9119d9
-        ret = qemuMonitorJSONExtractPtyPaths(reply, paths);
9119d9
+        ret = qemuMonitorJSONExtractChardevInfo(reply, info);
9119d9
 
9119d9
     virJSONValueFree(cmd);
9119d9
     virJSONValueFree(reply);
9119d9
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
9119d9
index 97397fe..17f9718 100644
9119d9
--- a/src/qemu/qemu_monitor_json.h
9119d9
+++ b/src/qemu/qemu_monitor_json.h
9119d9
@@ -214,8 +214,8 @@ int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
9119d9
 int qemuMonitorJSONQueryRxFilter(qemuMonitorPtr mon, const char *alias,
9119d9
                                  virNetDevRxFilterPtr *filter);
9119d9
 
9119d9
-int qemuMonitorJSONGetPtyPaths(qemuMonitorPtr mon,
9119d9
-                               virHashTablePtr paths);
9119d9
+int qemuMonitorJSONGetChardevInfo(qemuMonitorPtr mon,
9119d9
+                                  virHashTablePtr info);
9119d9
 
9119d9
 int qemuMonitorJSONAttachPCIDiskController(qemuMonitorPtr mon,
9119d9
                                            const char *bus,
9119d9
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
9119d9
index fc54a11..634f9f3 100644
9119d9
--- a/src/qemu/qemu_monitor_text.c
9119d9
+++ b/src/qemu/qemu_monitor_text.c
9119d9
@@ -2172,8 +2172,8 @@ int qemuMonitorTextRemoveNetdev(qemuMonitorPtr mon,
9119d9
  * '/dev/pty/7'. The hash will contain only a single value.
9119d9
  */
9119d9
 
9119d9
-int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
9119d9
-                               virHashTablePtr paths)
9119d9
+int qemuMonitorTextGetChardevInfo(qemuMonitorPtr mon,
9119d9
+                                  virHashTablePtr info)
9119d9
 {
9119d9
     char *reply = NULL;
9119d9
     int ret = -1;
9119d9
@@ -2224,7 +2224,7 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
9119d9
         if (VIR_STRDUP(path, needle + strlen(NEEDLE)) < 0)
9119d9
             goto cleanup;
9119d9
 
9119d9
-        if (virHashAddEntry(paths, id, path) < 0) {
9119d9
+        if (virHashAddEntry(info, id, path) < 0) {
9119d9
             virReportError(VIR_ERR_OPERATION_FAILED,
9119d9
                            _("failed to save chardev path '%s'"),
9119d9
                            path);
9119d9
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
9119d9
index 49d4b88..f118a30 100644
9119d9
--- a/src/qemu/qemu_monitor_text.h
9119d9
+++ b/src/qemu/qemu_monitor_text.h
9119d9
@@ -179,8 +179,8 @@ int qemuMonitorTextAddNetdev(qemuMonitorPtr mon,
9119d9
 int qemuMonitorTextRemoveNetdev(qemuMonitorPtr mon,
9119d9
                                 const char *alias);
9119d9
 
9119d9
-int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
9119d9
-                               virHashTablePtr paths);
9119d9
+int qemuMonitorTextGetChardevInfo(qemuMonitorPtr mon,
9119d9
+                                  virHashTablePtr info);
9119d9
 
9119d9
 int qemuMonitorTextAttachPCIDiskController(qemuMonitorPtr mon,
9119d9
                                            const char *bus,
9119d9
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
9119d9
index fa8b7f8..b7b2d80 100644
9119d9
--- a/src/qemu/qemu_process.c
9119d9
+++ b/src/qemu/qemu_process.c
9119d9
@@ -1865,7 +1865,7 @@ qemuProcessLookupPTYs(virDomainDefPtr def,
9119d9
                       virQEMUCapsPtr qemuCaps,
9119d9
                       virDomainChrDefPtr *devices,
9119d9
                       int count,
9119d9
-                      virHashTablePtr paths)
9119d9
+                      virHashTablePtr info)
9119d9
 {
9119d9
     size_t i;
9119d9
 
9119d9
@@ -1882,7 +1882,7 @@ qemuProcessLookupPTYs(virDomainDefPtr def,
9119d9
                          chr->info.alias) >= sizeof(id))
9119d9
                 return -1;
9119d9
 
9119d9
-            path = (const char *) virHashLookup(paths, id);
9119d9
+            path = (const char *) virHashLookup(info, id);
9119d9
             if (path == NULL) {
9119d9
                 if (chr->source.data.file.path == NULL) {
9119d9
                     /* neither the log output nor 'info chardev' had a
9119d9
@@ -1911,23 +1911,23 @@ qemuProcessLookupPTYs(virDomainDefPtr def,
9119d9
 static int
9119d9
 qemuProcessFindCharDevicePTYsMonitor(virDomainObjPtr vm,
9119d9
                                      virQEMUCapsPtr qemuCaps,
9119d9
-                                     virHashTablePtr paths)
9119d9
+                                     virHashTablePtr info)
9119d9
 {
9119d9
     size_t i = 0;
9119d9
 
9119d9
     if (qemuProcessLookupPTYs(vm->def, qemuCaps,
9119d9
                               vm->def->serials, vm->def->nserials,
9119d9
-                              paths) < 0)
9119d9
+                              info) < 0)
9119d9
         return -1;
9119d9
 
9119d9
     if (qemuProcessLookupPTYs(vm->def, qemuCaps,
9119d9
                               vm->def->parallels, vm->def->nparallels,
9119d9
-                              paths) < 0)
9119d9
+                              info) < 0)
9119d9
         return -1;
9119d9
 
9119d9
     if (qemuProcessLookupPTYs(vm->def, qemuCaps,
9119d9
                               vm->def->channels, vm->def->nchannels,
9119d9
-                              paths) < 0)
9119d9
+                              info) < 0)
9119d9
         return -1;
9119d9
     /* For historical reasons, console[0] can be just an alias
9119d9
      * for serial[0]. That's why we need to update it as well. */
9119d9
@@ -1947,7 +1947,7 @@ qemuProcessFindCharDevicePTYsMonitor(virDomainObjPtr vm,
9119d9
 
9119d9
     if (qemuProcessLookupPTYs(vm->def, qemuCaps,
9119d9
                               vm->def->consoles + i, vm->def->nconsoles - i,
9119d9
-                              paths) < 0)
9119d9
+                              info) < 0)
9119d9
         return -1;
9119d9
 
9119d9
     return 0;
9119d9
@@ -2031,7 +2031,7 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
9119d9
     size_t buf_size = 4096; /* Plenty of space to get startup greeting */
9119d9
     int logfd = -1;
9119d9
     int ret = -1;
9119d9
-    virHashTablePtr paths = NULL;
9119d9
+    virHashTablePtr info = NULL;
9119d9
     qemuDomainObjPrivatePtr priv;
9119d9
 
9119d9
     if (pos != -1 &&
9119d9
@@ -2056,22 +2056,18 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
9119d9
      * reliable if it's available.
9119d9
      * Note that the monitor itself can be on a pty, so we still need to try the
9119d9
      * log output method. */
9119d9
-    paths = virHashCreate(0, virHashValueFree);
9119d9
-    if (paths == NULL)
9119d9
-        goto cleanup;
9119d9
-
9119d9
     priv = vm->privateData;
9119d9
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
9119d9
         goto cleanup;
9119d9
-    ret = qemuMonitorGetPtyPaths(priv->mon, paths);
9119d9
+    ret = qemuMonitorGetChardevInfo(priv->mon, &info;;
9119d9
     qemuDomainObjExitMonitor(driver, vm);
9119d9
 
9119d9
-    VIR_DEBUG("qemuMonitorGetPtyPaths returned %i", ret);
9119d9
+    VIR_DEBUG("qemuMonitorGetChardevInfo returned %i", ret);
9119d9
     if (ret == 0)
9119d9
-        ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, paths);
9119d9
+        ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, info);
9119d9
 
9119d9
  cleanup:
9119d9
-    virHashFree(paths);
9119d9
+    virHashFree(info);
9119d9
 
9119d9
     if (pos != -1 && kill(vm->pid, 0) == -1 && errno == ESRCH) {
9119d9
         int len;
9119d9
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
9119d9
index f7b7ea5..afa2561 100644
9119d9
--- a/tests/qemumonitorjsontest.c
9119d9
+++ b/tests/qemumonitorjsontest.c
9119d9
@@ -1765,24 +1765,24 @@ testHashEqualString(const void *value1, const void *value2)
9119d9
 }
9119d9
 
9119d9
 static int
9119d9
-testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
9119d9
+testQemuMonitorJSONqemuMonitorJSONGetChardevInfo(const void *data)
9119d9
 {
9119d9
     virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
9119d9
     qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
9119d9
     int ret = -1;
9119d9
-    virHashTablePtr paths = NULL, expectedPaths = NULL;
9119d9
+    virHashTablePtr info = NULL, expectedInfo = NULL;
9119d9
 
9119d9
     if (!test)
9119d9
         return -1;
9119d9
 
9119d9
-    if (!(paths = virHashCreate(32, (virHashDataFree) free)) ||
9119d9
-        !(expectedPaths = virHashCreate(32, NULL)))
9119d9
+    if (!(info = virHashCreate(32, (virHashDataFree) free)) ||
9119d9
+        !(expectedInfo = virHashCreate(32, NULL)))
9119d9
         goto cleanup;
9119d9
 
9119d9
-    if (virHashAddEntry(expectedPaths, "charserial1", (void *) "/dev/pts/21") < 0 ||
9119d9
-        virHashAddEntry(expectedPaths, "charserial0", (void *) "/dev/pts/20") < 0) {
9119d9
+    if (virHashAddEntry(expectedInfo, "charserial1", (void *) "/dev/pts/21") < 0 ||
9119d9
+        virHashAddEntry(expectedInfo, "charserial0", (void *) "/dev/pts/20") < 0) {
9119d9
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
9119d9
-                       "Unable to create expectedPaths hash table");
9119d9
+                       "Unable to create expectedInfo hash table");
9119d9
         goto cleanup;
9119d9
     }
9119d9
 
9119d9
@@ -1806,11 +1806,11 @@ testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
9119d9
                                "}") < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
-    if (qemuMonitorJSONGetPtyPaths(qemuMonitorTestGetMonitor(test),
9119d9
-                                   paths) < 0)
9119d9
+    if (qemuMonitorJSONGetChardevInfo(qemuMonitorTestGetMonitor(test),
9119d9
+                                      info) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
-    if (!virHashEqual(paths, expectedPaths, testHashEqualString)) {
9119d9
+    if (!virHashEqual(info, expectedInfo, testHashEqualString)) {
9119d9
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
9119d9
                        "Hashtable is different to the expected one");
9119d9
         goto cleanup;
9119d9
@@ -1818,8 +1818,8 @@ testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
9119d9
 
9119d9
     ret = 0;
9119d9
  cleanup:
9119d9
-    virHashFree(paths);
9119d9
-    virHashFree(expectedPaths);
9119d9
+    virHashFree(info);
9119d9
+    virHashFree(expectedInfo);
9119d9
     qemuMonitorTestFree(test);
9119d9
     return ret;
9119d9
 }
9119d9
@@ -2387,7 +2387,7 @@ mymain(void)
9119d9
     DO_TEST(qemuMonitorJSONGetMigrationCacheSize);
9119d9
     DO_TEST(qemuMonitorJSONGetMigrationStatus);
9119d9
     DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus);
9119d9
-    DO_TEST(qemuMonitorJSONGetPtyPaths);
9119d9
+    DO_TEST(qemuMonitorJSONGetChardevInfo);
9119d9
     DO_TEST(qemuMonitorJSONSetBlockIoThrottle);
9119d9
     DO_TEST(qemuMonitorJSONGetTargetArch);
9119d9
     DO_TEST(qemuMonitorJSONGetMigrationCapability);
9119d9
-- 
9119d9
2.1.3
9119d9