render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
9119d9
From 6584db581b4044f5ec6bf6d01d0e1b32567cff1d Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <6584db581b4044f5ec6bf6d01d0e1b32567cff1d@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Mon, 24 Nov 2014 17:51:17 +0100
9119d9
Subject: [PATCH] qemu: process: Refresh virtio channel guest state when
9119d9
 connecting to mon
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1146944
9119d9
9119d9
Use data provided by "query-chardev" to refresh the guest frontend state
9119d9
of virtio channels.
9119d9
9119d9
(cherry picked from commit 21c676c2aa60f55fbb5ade884b4f4bb80281c789)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_process.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++--
9119d9
 1 file changed, 66 insertions(+), 2 deletions(-)
9119d9
9119d9
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
9119d9
index ebcd5e8..e68d9c6 100644
9119d9
--- a/src/qemu/qemu_process.c
9119d9
+++ b/src/qemu/qemu_process.c
9119d9
@@ -2065,6 +2065,61 @@ qemuProcessFindCharDevicePTYs(virDomainObjPtr vm,
9119d9
 
9119d9
 
9119d9
 static int
9119d9
+qemuProcessRefreshChannelVirtioState(virDomainObjPtr vm,
9119d9
+                                     virHashTablePtr info)
9119d9
+{
9119d9
+    size_t i;
9119d9
+    qemuMonitorChardevInfoPtr entry;
9119d9
+    char id[32];
9119d9
+
9119d9
+    for (i = 0; i < vm->def->nchannels; i++) {
9119d9
+        virDomainChrDefPtr chr = vm->def->channels[i];
9119d9
+        if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
9119d9
+            if (snprintf(id, sizeof(id), "char%s",
9119d9
+                         chr->info.alias) >= sizeof(id)) {
9119d9
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
9119d9
+                               _("failed to format device alias "
9119d9
+                                 "for PTY retrieval"));
9119d9
+                return -1;
9119d9
+            }
9119d9
+
9119d9
+            /* port state not reported */
9119d9
+            if (!(entry = virHashLookup(info, id)) ||
9119d9
+                !entry->state)
9119d9
+                continue;
9119d9
+
9119d9
+            chr->state = entry->state;
9119d9
+        }
9119d9
+    }
9119d9
+
9119d9
+    return 0;
9119d9
+}
9119d9
+
9119d9
+
9119d9
+static int
9119d9
+qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver,
9119d9
+                                              virDomainObjPtr vm)
9119d9
+{
9119d9
+    qemuDomainObjPrivatePtr priv = vm->privateData;
9119d9
+    virHashTablePtr info = NULL;
9119d9
+    int ret = -1;
9119d9
+
9119d9
+    qemuDomainObjEnterMonitor(driver, vm);
9119d9
+    ret = qemuMonitorGetChardevInfo(priv->mon, &info;;
9119d9
+    qemuDomainObjExitMonitor(driver, vm);
9119d9
+
9119d9
+    if (ret < 0)
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    ret = qemuProcessRefreshChannelVirtioState(vm, info);
9119d9
+
9119d9
+ cleanup:
9119d9
+    virHashFree(info);
9119d9
+    return ret;
9119d9
+}
9119d9
+
9119d9
+
9119d9
+static int
9119d9
 qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
9119d9
                           virDomainObjPtr vm,
9119d9
                           int asyncJob,
9119d9
@@ -2107,8 +2162,14 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
9119d9
     qemuDomainObjExitMonitor(driver, vm);
9119d9
 
9119d9
     VIR_DEBUG("qemuMonitorGetChardevInfo returned %i", ret);
9119d9
-    if (ret == 0)
9119d9
-        ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, info);
9119d9
+    if (ret == 0) {
9119d9
+        if ((ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps,
9119d9
+                                                        info)) < 0)
9119d9
+            goto cleanup;
9119d9
+
9119d9
+        if ((ret = qemuProcessRefreshChannelVirtioState(vm, info)) < 0)
9119d9
+            goto cleanup;
9119d9
+    }
9119d9
 
9119d9
  cleanup:
9119d9
     virHashFree(info);
9119d9
@@ -3584,6 +3645,9 @@ qemuProcessReconnect(void *opaque)
9119d9
     if (qemuDomainCheckEjectableMedia(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
9119d9
         goto error;
9119d9
 
9119d9
+    if (qemuProcessReconnectRefreshChannelVirtioState(driver, obj) < 0)
9119d9
+        goto error;
9119d9
+
9119d9
     if (qemuProcessRecoverJob(driver, obj, conn, &oldjob) < 0)
9119d9
         goto error;
9119d9
 
9119d9
-- 
9119d9
2.1.3
9119d9