]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Generate agent socket path if missing
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Apr 2013 17:04:00 +0000 (19:04 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 2 May 2013 14:40:24 +0000 (16:40 +0200)
It's not desired to force users imagine path for a socket they
are not even supposed to connect to. On the other hand, we
already have a release where the qemu agent socket path is
exposed to XML, so we cannot silently drop it from there.
The new path is generated in form:

$LOCALSTATEDIR/lib/libvirt/qemu/channel/target/$domain.$name

for qemu system mode, and

$XDG_CONFIG_HOME/qemu/lib/channel/target/$domain.$name

for qemu session mode.

docs/formatdomain.html.in
libvirt.spec.in
src/Makefile.am
src/conf/domain_conf.c
src/qemu/qemu_domain.c

index 8870e4630a9a62fd90bdc95b059bc106324689d3..8d4edfb163cf8d058703341b8c9718624a55478e 100644 (file)
@@ -3999,7 +3999,12 @@ qemu-kvm -net nic,model=? /dev/null
         then libvirt can interact with a guest agent installed in the
         guest, for actions such as guest shutdown or file system quiescing.
         <span class="since">Since 0.7.7, guest agent interaction
-        since 0.9.10</span></dd>
+        since 0.9.10</span> Moreover, <span class="since">since 1.0.5</span>
+        it is possible to have source path auto generated for virtio unix channels.
+        This is very useful in case of a qemu guest agent, where users don't
+        usually care about the source path since it's libvirt who talks to
+        the guest agent. In case users want to utilize this feature, they should
+        leave <code>&lt;source&gt;</code> element out.
 
       <dt><code>spicevmc</code></dt>
       <dd>Paravirtualized SPICE channel. The domain must also have a
index 24e347cd7403839f4d4de6c78e8ee871f6a27a98..6f250313ddbdbad505d2d3143bd5045d8c16f1d2 100644 (file)
@@ -1721,6 +1721,7 @@ fi
     %if %{with_qemu}
 %ghost %dir %attr(0700, root, root) %{_localstatedir}/run/libvirt/qemu/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
+%dir %attr{0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/target/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
     %endif
     %if %{with_lxc}
index cd098dbf5f94235929f6fc6539aae9ec83fddaf4..299b8fd0dc59fce0bf46ab73da384fef83d0ab6d 100644 (file)
@@ -2157,6 +2157,7 @@ if WITH_SANLOCK
 endif
 if WITH_QEMU
        $(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/qemu"
+       $(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channel/target"
        $(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/qemu"
        $(MKDIR_P) "$(DESTDIR)$(localstatedir)/cache/libvirt/qemu"
        $(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/libvirt/qemu"
index a8b5dfd655dd9a11f46ae52518b937f7ebb20d6e..608870f1575d4e1cf2fd14216678a4011c01803b 100644 (file)
@@ -6634,7 +6634,9 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
         break;
 
     case VIR_DOMAIN_CHR_TYPE_UNIX:
-        if (path == NULL) {
+        /* path can be auto generated */
+        if (!path &&
+            chr_def->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Missing source path attribute for char device"));
             goto error;
@@ -6729,7 +6731,6 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
     char *type = NULL;
     const char *nodeName;
     virDomainChrDefPtr def;
-    int remaining;
     bool seenTarget = false;
 
     if (!(def = virDomainChrDefNew()))
@@ -6753,29 +6754,26 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
     }
 
     cur = node->children;
-    remaining = virDomainChrSourceDefParseXML(&def->source, cur, flags,
-                                              def, ctxt,
-                                              vmSeclabels, nvmSeclabels);
-    if (remaining < 0)
-        goto error;
-    if (remaining) {
-        while (cur != NULL) {
-            if (cur->type == XML_ELEMENT_NODE) {
-                if (xmlStrEqual(cur->name, BAD_CAST "target")) {
-                    seenTarget = true;
-                    if (virDomainChrDefParseTargetXML(def, cur) < 0) {
-                        goto error;
-                    }
+    while (cur != NULL) {
+        if (cur->type == XML_ELEMENT_NODE) {
+            if (xmlStrEqual(cur->name, BAD_CAST "target")) {
+                seenTarget = true;
+                if (virDomainChrDefParseTargetXML(def, cur) < 0) {
+                    goto error;
                 }
             }
-            cur = cur->next;
         }
+        cur = cur->next;
     }
 
     if (!seenTarget &&
         ((def->targetType = virDomainChrDefaultTargetType(def->deviceType)) < 0))
         goto cleanup;
 
+    if (virDomainChrSourceDefParseXML(&def->source, node->children, flags, def,
+                                      ctxt, vmSeclabels, nvmSeclabels) < 0)
+        goto error;
+
     if (def->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
         if (def->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -14288,8 +14286,8 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         virBufferAsprintf(buf, "      <source mode='%s'",
                           def->data.nix.listen ? "bind" : "connect");
-        virBufferEscapeString(buf, " path='%s'/>\n",
-                              def->data.nix.path);
+        virBufferEscapeString(buf, " path='%s'", def->data.nix.path);
+        virBufferAddLit(buf, "/>\n");
         break;
     }
 
index 62c3382031ab7f61f9b5d24f90098cbfa2ab942d..1ea2bcd76e95919d86ff8fe9ddb2931124edf3ee 100644 (file)
@@ -792,6 +792,22 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         (def->os.arch == VIR_ARCH_S390 || def->os.arch == VIR_ARCH_S390X))
         dev->data.controller->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE;
 
+    /* auto generate unix socket path */
+    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
+        dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
+        dev->data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
+        dev->data.chr->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
+        !dev->data.chr->source.data.nix.path &&
+        (driver && (cfg = virQEMUDriverGetConfig(driver)))) {
+
+        if (virAsprintf(&dev->data.chr->source.data.nix.path,
+                        "%s/channel/target/%s.%s",
+                        cfg->libDir, def->name,
+                        dev->data.chr->target.name) < 0)
+            goto no_memory;
+        dev->data.chr->source.data.nix.listen = true;
+    }
+
     ret = 0;
 
 cleanup: