mirror of https://gitee.com/openkylin/libvirt.git
qemu: Generate agent socket path if missing
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.
This commit is contained in:
parent
ca75c44310
commit
297c99a567
|
@ -3999,7 +3999,12 @@ qemu-kvm -net nic,model=? /dev/null
|
||||||
then libvirt can interact with a guest agent installed in the
|
then libvirt can interact with a guest agent installed in the
|
||||||
guest, for actions such as guest shutdown or file system quiescing.
|
guest, for actions such as guest shutdown or file system quiescing.
|
||||||
<span class="since">Since 0.7.7, guest agent interaction
|
<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><source></code> element out.
|
||||||
|
|
||||||
<dt><code>spicevmc</code></dt>
|
<dt><code>spicevmc</code></dt>
|
||||||
<dd>Paravirtualized SPICE channel. The domain must also have a
|
<dd>Paravirtualized SPICE channel. The domain must also have a
|
||||||
|
|
|
@ -1721,6 +1721,7 @@ fi
|
||||||
%if %{with_qemu}
|
%if %{with_qemu}
|
||||||
%ghost %dir %attr(0700, root, root) %{_localstatedir}/run/libvirt/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/
|
||||||
|
%dir %attr{0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/channel/target/
|
||||||
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
|
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
|
||||||
%endif
|
%endif
|
||||||
%if %{with_lxc}
|
%if %{with_lxc}
|
||||||
|
|
|
@ -2157,6 +2157,7 @@ if WITH_SANLOCK
|
||||||
endif
|
endif
|
||||||
if WITH_QEMU
|
if WITH_QEMU
|
||||||
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/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)/run/libvirt/qemu"
|
||||||
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/cache/libvirt/qemu"
|
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/cache/libvirt/qemu"
|
||||||
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/libvirt/qemu"
|
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/libvirt/qemu"
|
||||||
|
|
|
@ -6634,7 +6634,9 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
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",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source path attribute for char device"));
|
_("Missing source path attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -6729,7 +6731,6 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
|
||||||
char *type = NULL;
|
char *type = NULL;
|
||||||
const char *nodeName;
|
const char *nodeName;
|
||||||
virDomainChrDefPtr def;
|
virDomainChrDefPtr def;
|
||||||
int remaining;
|
|
||||||
bool seenTarget = false;
|
bool seenTarget = false;
|
||||||
|
|
||||||
if (!(def = virDomainChrDefNew()))
|
if (!(def = virDomainChrDefNew()))
|
||||||
|
@ -6753,12 +6754,6 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = node->children;
|
cur = node->children;
|
||||||
remaining = virDomainChrSourceDefParseXML(&def->source, cur, flags,
|
|
||||||
def, ctxt,
|
|
||||||
vmSeclabels, nvmSeclabels);
|
|
||||||
if (remaining < 0)
|
|
||||||
goto error;
|
|
||||||
if (remaining) {
|
|
||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if (xmlStrEqual(cur->name, BAD_CAST "target")) {
|
if (xmlStrEqual(cur->name, BAD_CAST "target")) {
|
||||||
|
@ -6770,12 +6765,15 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!seenTarget &&
|
if (!seenTarget &&
|
||||||
((def->targetType = virDomainChrDefaultTargetType(def->deviceType)) < 0))
|
((def->targetType = virDomainChrDefaultTargetType(def->deviceType)) < 0))
|
||||||
goto cleanup;
|
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->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
|
||||||
if (def->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
|
if (def->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
@ -14288,8 +14286,8 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
|
||||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||||
virBufferAsprintf(buf, " <source mode='%s'",
|
virBufferAsprintf(buf, " <source mode='%s'",
|
||||||
def->data.nix.listen ? "bind" : "connect");
|
def->data.nix.listen ? "bind" : "connect");
|
||||||
virBufferEscapeString(buf, " path='%s'/>\n",
|
virBufferEscapeString(buf, " path='%s'", def->data.nix.path);
|
||||||
def->data.nix.path);
|
virBufferAddLit(buf, "/>\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -792,6 +792,22 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||||
(def->os.arch == VIR_ARCH_S390 || def->os.arch == VIR_ARCH_S390X))
|
(def->os.arch == VIR_ARCH_S390 || def->os.arch == VIR_ARCH_S390X))
|
||||||
dev->data.controller->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE;
|
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;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
Loading…
Reference in New Issue