]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: agent: Differentiate errors when the agent channel was hotplugged
authorPeter Krempa <pkrempa@redhat.com>
Fri, 24 Apr 2015 14:43:38 +0000 (16:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Sun, 26 Apr 2015 15:19:22 +0000 (17:19 +0200)
When the guest agent channel gets hotplugged to a VM, libvirt would
still report that "QEMU guest agent is not configured" rather than
stating that the connection was not established yet.

Currently the code won't be able to connect to the agent after hotplug
but that will change in a later patch.

As the qemuFindAgentConfig() helper is quite helpful in this case move
it to a more usable place and export it.

src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_process.c

index 39973a918278bd2e174ffe37848fa9f85e2748df..154a81ea718dff4767e6d179c9cc243783b810d2 100644 (file)
@@ -2975,11 +2975,19 @@ qemuDomainAgentAvailable(virDomainObjPtr vm,
         return false;
     }
     if (!priv->agent) {
-        if (reportError) {
-            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                           _("QEMU guest agent is not configured"));
+        if (qemuFindAgentConfig(vm->def)) {
+            if (reportError) {
+                virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
+                               _("QEMU guest agent is not connected"));
+            }
+            return false;
+        } else {
+            if (reportError) {
+                virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                               _("QEMU guest agent is not configured"));
+            }
+            return false;
         }
-        return false;
     }
     if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
         if (reportError) {
@@ -3077,3 +3085,32 @@ qemuDomainSupportsBlockJobs(virDomainObjPtr vm,
 
     return 0;
 }
+
+
+/**
+ * qemuFindAgentConfig:
+ * @def: domain definition
+ *
+ * Returns the pointer to the channel definition that is used to access the
+ * guest agent if the agent is configured or NULL otherwise.
+ */
+virDomainChrSourceDefPtr
+qemuFindAgentConfig(virDomainDefPtr def)
+{
+    virDomainChrSourceDefPtr config = NULL;
+    size_t i;
+
+    for (i = 0; i < def->nchannels; i++) {
+        virDomainChrDefPtr channel = def->channels[i];
+
+        if (channel->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO)
+            continue;
+
+        if (STREQ_NULLABLE(channel->target.name, "org.qemu.guest_agent.0")) {
+            config = &channel->source;
+            break;
+        }
+    }
+
+    return config;
+}
index d550ae38fe6e7a1e785d766f1dcd4200d5d741e9..76a48195e2d71aaccf874d904de7ed8d9acb9087 100644 (file)
@@ -439,4 +439,6 @@ bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
 int qemuDomainAlignMemorySizes(virDomainDefPtr def);
 void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem);
 
+virDomainChrSourceDefPtr qemuFindAgentConfig(virDomainDefPtr def);
+
 #endif /* __QEMU_DOMAIN_H__ */
index fb83d51a5b8d0baff28f697e3a8127b3a8036c89..75ccb66ff58c7f9c7852c99609dc5ee2acc5c5a7 100644 (file)
@@ -201,26 +201,6 @@ static qemuAgentCallbacks agentCallbacks = {
     .errorNotify = qemuProcessHandleAgentError,
 };
 
-static virDomainChrSourceDefPtr
-qemuFindAgentConfig(virDomainDefPtr def)
-{
-    virDomainChrSourceDefPtr config = NULL;
-    size_t i;
-
-    for (i = 0; i < def->nchannels; i++) {
-        virDomainChrDefPtr channel = def->channels[i];
-
-        if (channel->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO)
-            continue;
-
-        if (STREQ_NULLABLE(channel->target.name, "org.qemu.guest_agent.0")) {
-            config = &channel->source;
-            break;
-        }
-    }
-
-    return config;
-}
 
 static int
 qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm)