</dd>
</dl>
+ <h3><a id="vsock">Vsock</a></h3>
+
+ <p>A vsock host/guest interface. The <code>model</code> attribute
+ defaults to <code>virtio</code>.
+ The optional attribute <code>cid</code> of the source element
+ specifies the CID assigned to the guest. If the attribute
+ <code>auto</code> is set to <code>yes</code>, libvirt
+ will assign a free CID automatically on domain startup.
+ <span class="since">Since 4.4.0</span></p>
+
+<pre>
+...
+<devices>
+ <vsock model='virtio'>
+ <source auto='no' cid='3'/>
+ </vsock>
+</devices>
+...</pre>
+
+
<h3><a id="seclabel">Security label</a></h3>
<p>
</optional>
</define>
+ <define name="vsock">
+ <element name="vsock">
+ <optional>
+ <attribute name="model">
+ <value>virtio</value>
+ </attribute>
+ </optional>
+ <interleave>
+ <optional>
+ <element name="source">
+ <optional>
+ <attribute name="auto">
+ <ref name="virYesNo"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="cid">
+ <ref name="unsignedInt"/>
+ </attribute>
+ </optional>
+ </element>
+ </optional>
+ <optional>
+ <ref name="address"/>
+ </optional>
+ </interleave>
+ </element>
+ </define>
<define name="iommu">
<element name="iommu">
<attribute name="model">
<optional>
<ref name="iommu"/>
</optional>
+ <optional>
+ <ref name="vsock"/>
+ </optional>
</interleave>
</element>
</define>
"tpm",
"panic",
"memory",
- "iommu")
+ "iommu",
+ "vsock")
VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
"none",
VIR_ENUM_IMPL(virDomainIOMMUModel, VIR_DOMAIN_IOMMU_MODEL_LAST,
"intel")
+VIR_ENUM_IMPL(virDomainVsockModel, VIR_DOMAIN_VSOCK_MODEL_LAST,
+ "default",
+ "virtio")
+
VIR_ENUM_IMPL(virDomainDiskDiscard, VIR_DOMAIN_DISK_DISCARD_LAST,
"default",
"unmap",
case VIR_DOMAIN_DEVICE_IOMMU:
VIR_FREE(def->data.iommu);
break;
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ virDomainVsockDefFree(def->data.vsock);
+ break;
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_NONE:
break;
return &device->data.panic->info;
case VIR_DOMAIN_DEVICE_MEMORY:
return &device->data.memory->info;
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ return &device->data.vsock->info;
/* The following devices do not contain virDomainDeviceInfo */
case VIR_DOMAIN_DEVICE_LEASE:
return rc;
}
+ device.type = VIR_DOMAIN_DEVICE_VSOCK;
+ if (def->vsock) {
+ device.data.vsock = def->vsock;
+ if ((rc = cb(def, &device, &def->vsock->info, opaque)) != 0)
+ return rc;
+ }
+
/* Coverity is not very happy with this - all dead_error_condition */
#if !STATIC_ANALYSIS
/* This switch statement is here to trigger compiler warning when adding
case VIR_DOMAIN_DEVICE_RNG:
case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
break;
}
#endif
}
+static int
+virDomainVsockDefPostParse(virDomainVsockDefPtr vsock)
+{
+ if (vsock->auto_cid == VIR_TRISTATE_BOOL_ABSENT) {
+ if (vsock->guest_cid != 0)
+ vsock->auto_cid = VIR_TRISTATE_BOOL_NO;
+ else
+ vsock->auto_cid = VIR_TRISTATE_BOOL_YES;
+ }
+
+ return 0;
+}
+
+
static int
virDomainDeviceDefPostParseCommon(virDomainDeviceDefPtr dev,
const virDomainDef *def,
return -1;
}
+ if (dev->type == VIR_DOMAIN_DEVICE_VSOCK &&
+ virDomainVsockDefPostParse(dev->data.vsock) < 0)
+ return -1;
+
return 0;
}
}
+static int
+virDomainVsockDefValidate(const virDomainVsockDef *vsock)
+{
+ if (vsock->guest_cid > 0 && vsock->guest_cid <= 2) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("guest CIDs must be >= 3"));
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
const virDomainDef *def)
case VIR_DOMAIN_DEVICE_MEMORY:
return virDomainMemoryDefValidate(dev->data.memory);
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ return virDomainVsockDefValidate(dev->data.vsock);
+
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
}
+static virDomainVsockDefPtr
+virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt,
+ xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
+ unsigned int flags)
+{
+ virDomainVsockDefPtr vsock = NULL, ret = NULL;
+ xmlNodePtr save = ctxt->node;
+ xmlNodePtr source;
+ char *tmp = NULL;
+ int val;
+
+ ctxt->node = node;
+
+ if (!(vsock = virDomainVsockDefNew(xmlopt)))
+ goto cleanup;
+
+ if ((tmp = virXMLPropString(node, "model"))) {
+ if ((val = virDomainVsockModelTypeFromString(tmp)) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, _("unknown vsock model: %s"), tmp);
+ goto cleanup;
+ }
+ vsock->model = val;
+ }
+
+ source = virXPathNode("./source", ctxt);
+
+ VIR_FREE(tmp);
+ if (source) {
+ if ((tmp = virXMLPropString(source, "cid"))) {
+ if (virStrToLong_uip(tmp, NULL, 10, &vsock->guest_cid) < 0 ||
+ vsock->guest_cid == 0) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("'cid' attribute must be a positive number: %s"),
+ tmp);
+ goto cleanup;
+ }
+ }
+
+ VIR_FREE(tmp);
+ if ((tmp = virXMLPropString(source, "auto"))) {
+ val = virTristateBoolTypeFromString(tmp);
+ if (val <= 0) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("'auto' attribute can be 'yes' or 'no': %s"),
+ tmp);
+ goto cleanup;
+ }
+ vsock->auto_cid = val;
+ }
+ }
+
+ if (virDomainDeviceInfoParseXML(xmlopt, node, &vsock->info, flags) < 0)
+ goto cleanup;
+
+ VIR_STEAL_PTR(ret, vsock);
+
+ cleanup:
+ ctxt->node = save;
+ VIR_FREE(vsock);
+ VIR_FREE(tmp);
+ return ret;
+}
+
virDomainDeviceDefPtr
virDomainDeviceDefParse(const char *xmlStr,
const virDomainDef *def,
if (!(dev->data.iommu = virDomainIOMMUDefParseXML(node, ctxt)))
goto error;
break;
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ if (!(dev->data.vsock = virDomainVsockDefParseXML(xmlopt, node, ctxt,
+ flags)))
+ goto error;
+ break;
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LAST:
break;
}
VIR_FREE(nodes);
+ if ((n = virXPathNodeSet("./devices/vsock", ctxt, &nodes)) < 0)
+ goto error;
+
+ if (n > 1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("only a single vsock device is supported"));
+ goto error;
+ }
+
+ if (n > 0) {
+ if (!(def->vsock = virDomainVsockDefParseXML(xmlopt, nodes[0],
+ ctxt, flags)))
+ goto error;
+ }
+ VIR_FREE(nodes);
+
/* analysis of the user namespace mapping */
if ((n = virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0)
goto error;
}
+static bool
+virDomainVsockDefCheckABIStability(virDomainVsockDefPtr src,
+ virDomainVsockDefPtr dst)
+{
+ if (src->model != dst->model) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Target domain vsock device model '%s' "
+ "does not match source '%s'"),
+ virDomainVsockModelTypeToString(dst->model),
+ virDomainVsockModelTypeToString(src->model));
+ return false;
+ }
+
+ if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
+ return false;
+
+ return true;
+}
+
+
static bool
virDomainDefVcpuCheckAbiStability(virDomainDefPtr src,
virDomainDefPtr dst)
!virDomainIOMMUDefCheckABIStability(src->iommu, dst->iommu))
goto error;
+ if (!!src->vsock != !!dst->vsock) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Target domain vsock device count "
+ "does not match source"));
+ goto error;
+ }
+
+ if (src->vsock &&
+ !virDomainVsockDefCheckABIStability(src->vsock, dst->vsock))
+ goto error;
+
if (xmlopt && xmlopt->abi.domain &&
!xmlopt->abi.domain(src, dst))
goto error;
case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
break;
}
#endif
}
+static int
+virDomainVsockDefFormat(virBufferPtr buf,
+ virDomainVsockDefPtr vsock)
+{
+ virBuffer childBuf = VIR_BUFFER_INITIALIZER;
+ virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
+ virBuffer sourceAttrBuf = VIR_BUFFER_INITIALIZER;
+ int ret = -1;
+
+ if (vsock->model) {
+ virBufferAsprintf(&attrBuf, " model='%s'",
+ virDomainVsockModelTypeToString(vsock->model));
+ }
+
+ virBufferSetChildIndent(&childBuf, buf);
+
+ if (vsock->auto_cid != VIR_TRISTATE_BOOL_ABSENT) {
+ virBufferAsprintf(&sourceAttrBuf, " auto='%s'",
+ virTristateBoolTypeToString(vsock->auto_cid));
+ }
+ if (vsock->guest_cid != 0)
+ virBufferAsprintf(&sourceAttrBuf, " cid='%u'", vsock->guest_cid);
+ if (virXMLFormatElement(&childBuf, "source", &sourceAttrBuf, NULL) < 0)
+ goto cleanup;
+
+ virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0);
+
+ if (virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virBufferFreeAndReset(&childBuf);
+ virBufferFreeAndReset(&attrBuf);
+ virBufferFreeAndReset(&sourceAttrBuf);
+ return ret;
+}
+
+
/* This internal version appends to an existing buffer
* (possibly with auto-indent), rather than flattening
* to string.
virDomainIOMMUDefFormat(buf, def->iommu) < 0)
goto error;
+ if (def->vsock &&
+ virDomainVsockDefFormat(buf, def->vsock) < 0)
+ goto error;
+
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</devices>\n");
case VIR_DOMAIN_DEVICE_SHMEM:
rc = virDomainShmemDefFormat(&buf, src->data.shmem, flags);
break;
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ rc = virDomainVsockDefFormat(&buf, src->data.vsock);
+ break;
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_SMARTCARD:
VIR_DOMAIN_DEVICE_PANIC,
VIR_DOMAIN_DEVICE_MEMORY,
VIR_DOMAIN_DEVICE_IOMMU,
+ VIR_DOMAIN_DEVICE_VSOCK,
VIR_DOMAIN_DEVICE_LAST
} virDomainDeviceType;
virDomainPanicDefPtr panic;
virDomainMemoryDefPtr memory;
virDomainIOMMUDefPtr iommu;
+ virDomainVsockDefPtr vsock;
} data;
};
virTristateSwitch iotlb;
};
+typedef enum {
+ VIR_DOMAIN_VSOCK_MODEL_DEFAULT,
+ VIR_DOMAIN_VSOCK_MODEL_VIRTIO,
+
+ VIR_DOMAIN_VSOCK_MODEL_LAST
+} virDomainVsockModel;
+
struct _virDomainVsockDef {
virObjectPtr privateData;
+
+ virDomainVsockModel model;
+ unsigned int guest_cid;
+ virTristateBool auto_cid;
+
+ virDomainDeviceInfo info;
};
struct _virDomainVirtioOptions {
virSysinfoDefPtr sysinfo;
virDomainRedirFilterDefPtr redirfilter;
virDomainIOMMUDefPtr iommu;
+ virDomainVsockDefPtr vsock;
void *namespaceData;
virDomainXMLNamespace ns;
VIR_ENUM_DECL(virDomainMemorySource)
VIR_ENUM_DECL(virDomainMemoryAllocation)
VIR_ENUM_DECL(virDomainIOMMUModel)
+VIR_ENUM_DECL(virDomainVsockModel)
VIR_ENUM_DECL(virDomainShmemModel)
/* from libvirt.h */
VIR_ENUM_DECL(virDomainState)
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LAST:
break;
}
+static int
+qemuDomainVsockDefPostParse(virDomainVsockDefPtr vsock)
+{
+ if (vsock->model == VIR_DOMAIN_VSOCK_MODEL_DEFAULT)
+ vsock->model = VIR_DOMAIN_VSOCK_MODEL_VIRTIO;
+
+ return 0;
+}
+
+
static int
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
const virDomainDef *def,
ret = qemuDomainChrDefPostParse(dev->data.chr, def, driver, parseFlags);
break;
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ ret = qemuDomainVsockDefPostParse(dev->data.vsock);
+ break;
+
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
}
break;
+ case VIR_DOMAIN_DEVICE_VSOCK:
+ return virtioFlags;
+
/* These devices don't ever connect with PCI */
case VIR_DOMAIN_DEVICE_NVRAM:
case VIR_DOMAIN_DEVICE_TPM:
/* Nada - none are PCI based (yet) */
}
+ if (def->vsock &&
+ virDeviceInfoPCIAddressWanted(&def->vsock->info)) {
+
+ if (qemuDomainPCIAddressReserveNextAddr(addrs,
+ &def->vsock->info) < 0)
+ goto error;
+ }
+
return 0;
error:
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("live attach of device '%s' is not supported"),
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("live detach of device '%s' is not supported"),
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("live update of device '%s' is not supported"),
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("persistent attach of device '%s' is not supported"),
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("persistent detach of device '%s' is not supported"),
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("persistent update of device '%s' is not supported"),
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
+ case VIR_DOMAIN_DEVICE_VSOCK:
case VIR_DOMAIN_DEVICE_LAST:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("don't know how to remove a %s device"),
--- /dev/null
+<domain type='qemu'>
+ <name>test</name>
+ <uuid>bba65c0e-c049-934f-b6aa-4e2c0582acdf</uuid>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-2.9'>hvm</type>
+ <boot dev='hd'/>
+ <bootmenu enable='yes'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='virtio-serial' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </controller>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='none'/>
+ <vsock>
+ <source auto='yes'/>
+ </vsock>
+ </devices>
+</domain>
--- /dev/null
+<domain type='qemu'>
+ <name>test</name>
+ <uuid>bba65c0e-c049-934f-b6aa-4e2c0582acdf</uuid>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-0.13'>hvm</type>
+ <boot dev='hd'/>
+ <bootmenu enable='yes'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='virtio-serial' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </controller>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='none'/>
+ <vsock model='virtio'>
+ <source auto='no' cid='4'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+ </vsock>
+ </devices>
+</domain>
--- /dev/null
+<domain type='qemu'>
+ <name>test</name>
+ <uuid>bba65c0e-c049-934f-b6aa-4e2c0582acdf</uuid>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-2.9'>hvm</type>
+ <boot dev='hd'/>
+ <bootmenu enable='yes'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='virtio-serial' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </controller>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='none'/>
+ <vsock model='virtio'>
+ <source auto='yes'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </vsock>
+ </devices>
+</domain>
--- /dev/null
+../qemuxml2argvdata/vhost-vsock.xml
\ No newline at end of file
DO_TEST_STATUS("migration-out-params");
DO_TEST_STATUS("migration-out-nbd-tls");
+ DO_TEST("vhost-vsock", NONE);
+ DO_TEST("vhost-vsock-auto", NONE);
+
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);