From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158382722723.2846374274062; Thu, 24 May 2018 03:39:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF948C04C26F; Thu, 24 May 2018 10:39:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 835A6308BDA3; Thu, 24 May 2018 10:39:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3092B18033C1; Thu, 24 May 2018 10:39:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdJQv011598 for ; Thu, 24 May 2018 06:39:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 87BB71049466; Thu, 24 May 2018 10:39:19 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D70C1049465 for ; Thu, 24 May 2018 10:39:19 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:09 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 1/7] Introduce virDomainVsockDef X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 24 May 2018 10:39:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 A type to represent the new vsock device. Also implement an allocation function to allow future addition of private data. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 21 +++++++++++++++++++++ src/conf/domain_conf.h | 8 ++++++++ src/libvirt_private.syms | 1 + 3 files changed, 30 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3689ac0a82..5b4b182fd2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2027,6 +2027,27 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr d= ef) VIR_FREE(def); } =20 + +virDomainVsockDefPtr +virDomainVsockDefNew(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED) +{ + virDomainVsockDefPtr ret =3D NULL; + virDomainVsockDefPtr vsock; + + if (VIR_ALLOC(vsock) < 0) + return NULL; + + VIR_STEAL_PTR(ret, vsock); + return ret; +} + + +void +virDomainVsockDefFree(virDomainVsockDefPtr vsock ATTRIBUTE_UNUSED) +{ +} + + void virDomainNetDefClear(virDomainNetDefPtr def) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a78fdee40c..0eae14e732 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -157,6 +157,9 @@ typedef virDomainTPMDef *virDomainTPMDefPtr; typedef struct _virDomainIOMMUDef virDomainIOMMUDef; typedef virDomainIOMMUDef *virDomainIOMMUDefPtr; =20 +typedef struct _virDomainVsockDef virDomainVsockDef; +typedef virDomainVsockDef *virDomainVsockDefPtr; + typedef struct _virDomainVirtioOptions virDomainVirtioOptions; typedef virDomainVirtioOptions *virDomainVirtioOptionsPtr; =20 @@ -2310,6 +2313,9 @@ struct _virDomainIOMMUDef { virTristateSwitch iotlb; }; =20 +struct _virDomainVsockDef { +}; + struct _virDomainVirtioOptions { virTristateSwitch iommu; virTristateSwitch ats; @@ -2788,6 +2794,8 @@ bool virDomainControllerIsPSeriesPHB(const virDomainC= ontrollerDef *cont); virDomainFSDefPtr virDomainFSDefNew(void); void virDomainFSDefFree(virDomainFSDefPtr def); void virDomainActualNetDefFree(virDomainActualNetDefPtr def); +virDomainVsockDefPtr virDomainVsockDefNew(virDomainXMLOptionPtr xmlopt); +void virDomainVsockDefFree(virDomainVsockDefPtr vsock); void virDomainNetDefClear(virDomainNetDefPtr def); void virDomainNetDefFree(virDomainNetDefPtr def); void virDomainSmartcardDefFree(virDomainSmartcardDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3dece252df..8e33f3e9f6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -573,6 +573,7 @@ virDomainVideoVGAConfTypeFromString; virDomainVideoVGAConfTypeToString; virDomainVirtTypeFromString; virDomainVirtTypeToString; +virDomainVsockDefNew; virDomainWatchdogActionTypeFromString; virDomainWatchdogActionTypeToString; virDomainWatchdogDefFree; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158376677799.5214408182113; Thu, 24 May 2018 03:39:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6F0830D5AC6; Thu, 24 May 2018 10:39:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74C3165F6B; Thu, 24 May 2018 10:39:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 18F394CA85; Thu, 24 May 2018 10:39:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdKbK011603 for ; Thu, 24 May 2018 06:39:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 280541049466; Thu, 24 May 2018 10:39:20 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1EBE1049465 for ; Thu, 24 May 2018 10:39:19 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:10 +0200 Message-Id: <7e07d6780198ec202f11c5c1be6860b8db14c2d0.1527157595.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 2/7] Add privateData to virDomainVsockDef X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 24 May 2018 10:39:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 An object for storing driver-specific data in the vsock definition. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 16 ++++++++++++++-- src/conf/domain_conf.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5b4b182fd2..b2982fc3d4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2029,7 +2029,7 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr de= f) =20 =20 virDomainVsockDefPtr -virDomainVsockDefNew(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED) +virDomainVsockDefNew(virDomainXMLOptionPtr xmlopt) { virDomainVsockDefPtr ret =3D NULL; virDomainVsockDefPtr vsock; @@ -2037,14 +2037,26 @@ virDomainVsockDefNew(virDomainXMLOptionPtr xmlopt A= TTRIBUTE_UNUSED) if (VIR_ALLOC(vsock) < 0) return NULL; =20 + if (xmlopt && + xmlopt->privateData.vsockNew && + !(vsock->privateData =3D xmlopt->privateData.vsockNew())) + goto cleanup; + VIR_STEAL_PTR(ret, vsock); + cleanup: + virDomainVsockDefFree(vsock); return ret; } =20 =20 void -virDomainVsockDefFree(virDomainVsockDefPtr vsock ATTRIBUTE_UNUSED) +virDomainVsockDefFree(virDomainVsockDefPtr vsock) { + if (!vsock) + return; + + virObjectUnref(vsock->privateData); + vsock->privateData =3D NULL; } =20 =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0eae14e732..4fa67ae7b7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2314,6 +2314,7 @@ struct _virDomainIOMMUDef { }; =20 struct _virDomainVsockDef { + virObjectPtr privateData; }; =20 struct _virDomainVirtioOptions { @@ -2678,6 +2679,7 @@ struct _virDomainXMLPrivateDataCallbacks { virDomainXMLPrivateDataNewFunc diskNew; virDomainXMLPrivateDataNewFunc vcpuNew; virDomainXMLPrivateDataNewFunc chrSourceNew; + virDomainXMLPrivateDataNewFunc vsockNew; virDomainXMLPrivateDataFormatFunc format; virDomainXMLPrivateDataParseFunc parse; virDomainXMLPrivateDataStorageSourceParseFunc storageParse; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158387277795.2011658086182; Thu, 24 May 2018 03:39:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E0A030C0ED3; Thu, 24 May 2018 10:39:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 123CB65F73; Thu, 24 May 2018 10:39:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9DAD418033EF; Thu, 24 May 2018 10:39:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdKHD011613 for ; Thu, 24 May 2018 06:39:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9ACE1049466; Thu, 24 May 2018 10:39:20 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 625AB1049465 for ; Thu, 24 May 2018 10:39:20 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:11 +0200 Message-Id: <6a9a5d7592f1ee9186699fae085b4a7513a39bc4.1527157595.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 3/7] conf: introduce element X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 24 May 2018 10:39:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new 'vsock' element for the vsock device. The 'model' attribute is optional. A subelement should be used to specify the guest cid, or should be used. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 --- docs/formatdomain.html.in | 20 +++ docs/schemas/domaincommon.rng | 29 ++++ src/conf/domain_conf.c | 195 ++++++++++++++++++++++= +++- src/conf/domain_conf.h | 17 +++ src/qemu/qemu_domain.c | 1 + src/qemu/qemu_domain_address.c | 11 ++ src/qemu/qemu_driver.c | 6 + src/qemu/qemu_hotplug.c | 1 + tests/qemuxml2argvdata/vhost-vsock-auto.xml | 35 +++++ tests/qemuxml2argvdata/vhost-vsock.xml | 36 +++++ tests/qemuxml2xmloutdata/vhost-vsock-auto.xml | 36 +++++ tests/qemuxml2xmloutdata/vhost-vsock.xml | 1 + tests/qemuxml2xmltest.c | 3 + 13 files changed, 390 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/vhost-vsock-auto.xml create mode 100644 tests/qemuxml2argvdata/vhost-vsock.xml create mode 100644 tests/qemuxml2xmloutdata/vhost-vsock-auto.xml create mode 120000 tests/qemuxml2xmloutdata/vhost-vsock.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 0d0fd3b9f3..bfe7f757b8 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -8133,6 +8133,26 @@ qemu-kvm -net nic,model=3D? /dev/null =20 +

Vsock

+ +

A vsock host/guest interface. The model attribute + defaults to virtio. + The optional attribute cid of the source element + specifies the CID assigned to the guest. If the attribute + auto is set to yes, libvirt + will assign a free CID automatically on domain startup. + Since 4.4.0

+ +
+...
+<devices>
+  <vsock model=3D'virtio'>
+    <source auto=3D'no' cid=3D'3'/>
+  </vsock>
+</devices>
+...
+ +

Security label

=20

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 71ac3d079c..3ea5c91773 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4140,6 +4140,32 @@ =20 + + + + + virtio + + + + + + + + + + + + + + + + + + + + + @@ -4687,6 +4713,9 @@ + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b2982fc3d4..1a3dbf884b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -256,7 +256,8 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST, "tpm", "panic", "memory", - "iommu") + "iommu", + "vsock") =20 VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, "none", @@ -869,6 +870,10 @@ VIR_ENUM_IMPL(virDomainTPMBackend, VIR_DOMAIN_TPM_TYPE= _LAST, VIR_ENUM_IMPL(virDomainIOMMUModel, VIR_DOMAIN_IOMMU_MODEL_LAST, "intel") =20 +VIR_ENUM_IMPL(virDomainVsockModel, VIR_DOMAIN_VSOCK_MODEL_LAST, + "default", + "virtio") + VIR_ENUM_IMPL(virDomainDiskDiscard, VIR_DOMAIN_DISK_DISCARD_LAST, "default", "unmap", @@ -2777,6 +2782,9 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) 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; @@ -3641,6 +3649,8 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device) 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; =20 /* The following devices do not contain virDomainDeviceInfo */ case VIR_DOMAIN_DEVICE_LEASE: @@ -3838,6 +3848,12 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr d= ef, return rc; } =20 + if (def->vsock) { + device.type =3D VIR_DOMAIN_DEVICE_VSOCK; + if ((rc =3D cb(def, &device, &def->vsock->info, opaque)) !=3D 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 addi= ng @@ -3872,6 +3888,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr de= f, case VIR_DOMAIN_DEVICE_RNG: case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_VSOCK: break; } #endif @@ -5575,6 +5592,19 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem) } =20 =20 +static int +virDomainVsockDefValidate(const virDomainVsockDef *vsock) +{ + if (vsock->guest_cid > 0 && vsock->guest_cid <=3D 2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("guest CIDs must be >=3D 3")); + return -1; + } + + return 0; +} + + static int virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, const virDomainDef *def) @@ -5610,6 +5640,9 @@ virDomainDeviceDefValidateInternal(const virDomainDev= iceDef *dev, case VIR_DOMAIN_DEVICE_MEMORY: return virDomainMemoryDefValidate(dev->data.memory); =20 + 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: @@ -15878,6 +15911,68 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, } =20 =20 +static virDomainVsockDefPtr +virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, + xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned int flags) +{ + virDomainVsockDefPtr vsock =3D NULL, ret =3D NULL; + xmlNodePtr save =3D ctxt->node; + xmlNodePtr source; + char *tmp =3D NULL; + int val; + + ctxt->node =3D node; + + if (!(vsock =3D virDomainVsockDefNew(xmlopt))) + goto cleanup; + + if ((tmp =3D virXMLPropString(node, "model"))) { + if ((val =3D virDomainVsockModelTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, _("unknown vsock model: %s")= , tmp); + goto cleanup; + } + vsock->model =3D val; + } + + source =3D virXPathNode("./source", ctxt); + + VIR_FREE(tmp); + if (source && (tmp =3D virXMLPropString(source, "cid"))) { + if (virStrToLong_uip(tmp, NULL, 10, &vsock->guest_cid) < 0 || + vsock->guest_cid =3D=3D 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("'cid' attribute must be a positive number: %= s"), + tmp); + goto cleanup; + } + } + + VIR_FREE(tmp); + if (source && (tmp =3D virXMLPropString(source, "auto"))) { + val =3D virTristateBoolTypeFromString(tmp); + if (val < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("'auto' attribute can be 'yes' or 'no': %s"), + tmp); + goto cleanup; + } + vsock->auto_cid =3D val; + } + + if (virDomainDeviceInfoParseXML(xmlopt, node, NULL, &vsock->info, flag= s) < 0) + goto cleanup; + + VIR_STEAL_PTR(ret, vsock); + + cleanup: + ctxt->node =3D save; + VIR_FREE(vsock); + VIR_FREE(tmp); + return ret; +} + virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, @@ -16033,6 +16128,11 @@ virDomainDeviceDefParse(const char *xmlStr, if (!(dev->data.iommu =3D virDomainIOMMUDefParseXML(node, ctxt))) goto error; break; + case VIR_DOMAIN_DEVICE_VSOCK: + if (!(dev->data.vsock =3D virDomainVsockDefParseXML(xmlopt, node, = ctxt, + flags))) + goto error; + break; case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: break; @@ -20435,6 +20535,22 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); =20 + if ((n =3D 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 =3D virDomainVsockDefParseXML(xmlopt, nodes[0], + ctxt, flags))) + goto error; + } + VIR_FREE(nodes); + /* analysis of the user namespace mapping */ if ((n =3D virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0) goto error; @@ -21996,6 +22112,26 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUD= efPtr src, } =20 =20 +static bool +virDomainVsockDefCheckABIStability(virDomainVsockDefPtr src, + virDomainVsockDefPtr dst) +{ + if (src->model !=3D 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) @@ -22441,6 +22577,17 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr= src, !virDomainIOMMUDefCheckABIStability(src->iommu, dst->iommu)) goto error; =20 + if (!!src->vsock !=3D !!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; @@ -22478,6 +22625,7 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr = src, case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_VSOCK: break; } #endif @@ -26735,6 +26883,46 @@ virDomainMemtuneFormat(virBufferPtr buf, } =20 =20 +static int +virDomainVsockDefFormat(virBufferPtr buf, + virDomainVsockDefPtr vsock) +{ + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + if (vsock->model) { + virBufferAsprintf(&attrBuf, " model=3D'%s'", + virDomainVsockModelTypeToString(vsock->model)); + } + + virBufferSetChildIndent(&childBuf, buf); + + if (vsock->auto_cid !=3D VIR_TRISTATE_BOOL_ABSENT) { + virBufferAsprintf(&sourceAttrBuf, " auto=3D'%s'", + virTristateBoolTypeToString(vsock->auto_cid)); + } + if (vsock->guest_cid !=3D 0) + virBufferAsprintf(&sourceAttrBuf, " cid=3D'%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 =3D 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. @@ -27469,6 +27657,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, virDomainIOMMUDefFormat(buf, def->iommu) < 0) goto error; =20 + if (def->vsock && + virDomainVsockDefFormat(buf, def->vsock) < 0) + goto error; + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); =20 @@ -28595,6 +28787,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_VSOCK: case VIR_DOMAIN_DEVICE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("Copying definition of '%d' type " diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4fa67ae7b7..a5e45bfda5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -189,6 +189,7 @@ typedef enum { VIR_DOMAIN_DEVICE_PANIC, VIR_DOMAIN_DEVICE_MEMORY, VIR_DOMAIN_DEVICE_IOMMU, + VIR_DOMAIN_DEVICE_VSOCK, =20 VIR_DOMAIN_DEVICE_LAST } virDomainDeviceType; @@ -221,6 +222,7 @@ struct _virDomainDeviceDef { virDomainPanicDefPtr panic; virDomainMemoryDefPtr memory; virDomainIOMMUDefPtr iommu; + virDomainVsockDefPtr vsock; } data; }; =20 @@ -2313,8 +2315,21 @@ struct _virDomainIOMMUDef { virTristateSwitch iotlb; }; =20 +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; }; =20 struct _virDomainVirtioOptions { @@ -2462,6 +2477,7 @@ struct _virDomainDef { virSysinfoDefPtr sysinfo; virDomainRedirFilterDefPtr redirfilter; virDomainIOMMUDefPtr iommu; + virDomainVsockDefPtr vsock; =20 void *namespaceData; virDomainXMLNamespace ns; @@ -3366,6 +3382,7 @@ VIR_ENUM_DECL(virDomainMemoryBackingModel) 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) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d3beee5d87..6648933c80 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5132,6 +5132,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef = *dev, 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; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index b7c82cb6f1..e9f460d77a 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -859,6 +859,9 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, } break; =20 + 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: @@ -2152,6 +2155,14 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, /* Nada - none are PCI based (yet) */ } =20 + if (def->vsock && + virDeviceInfoPCIAddressWanted(&def->vsock->info)) { + + if (qemuDomainPCIAddressReserveNextAddr(addrs, + &def->vsock->info) < 0) + goto error; + } + return 0; =20 error: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3a328e5d46..9d5cf4d61a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7701,6 +7701,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, 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"), @@ -7800,6 +7801,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, 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"), @@ -7936,6 +7938,7 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm, 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"), @@ -8122,6 +8125,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, 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 support= ed"), @@ -8305,6 +8309,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, 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 supporte= d"), @@ -8403,6 +8408,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, 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 supporte= d"), diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b35594be5f..e429f54a43 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4626,6 +4626,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, 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"), diff --git a/tests/qemuxml2argvdata/vhost-vsock-auto.xml b/tests/qemuxml2ar= gvdata/vhost-vsock-auto.xml new file mode 100644 index 0000000000..729d58bea4 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock-auto.xml @@ -0,0 +1,35 @@ + + test + bba65c0e-c049-934f-b6aa-4e2c0582acdf + 1048576 + 1048576 + 1 + + hvm + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + +

+ + +
+ + +
+ + + + + + + + + + diff --git a/tests/qemuxml2argvdata/vhost-vsock.xml b/tests/qemuxml2argvdat= a/vhost-vsock.xml new file mode 100644 index 0000000000..ac210cb116 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock.xml @@ -0,0 +1,36 @@ + + test + bba65c0e-c049-934f-b6aa-4e2c0582acdf + 1048576 + 1048576 + 1 + + hvm + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + +
+ + +
+ + +
+ + + + + + + +
+ + + diff --git a/tests/qemuxml2xmloutdata/vhost-vsock-auto.xml b/tests/qemuxml2= xmloutdata/vhost-vsock-auto.xml new file mode 100644 index 0000000000..65f18b96d9 --- /dev/null +++ b/tests/qemuxml2xmloutdata/vhost-vsock-auto.xml @@ -0,0 +1,36 @@ + + test + bba65c0e-c049-934f-b6aa-4e2c0582acdf + 1048576 + 1048576 + 1 + + hvm + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + +
+ + +
+ + +
+ + + + + + + +
+ + + diff --git a/tests/qemuxml2xmloutdata/vhost-vsock.xml b/tests/qemuxml2xmlou= tdata/vhost-vsock.xml new file mode 120000 index 0000000000..bb24241fb2 --- /dev/null +++ b/tests/qemuxml2xmloutdata/vhost-vsock.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/vhost-vsock.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 7cedc2b999..cd6538a442 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1209,6 +1209,9 @@ mymain(void) DO_TEST_STATUS("migration-in-params"); DO_TEST_STATUS("migration-out-params"); =20 + DO_TEST("vhost-vsock", NONE); + DO_TEST("vhost-vsock-auto", NONE); + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158391738649.7018105267184; Thu, 24 May 2018 03:39:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7B4D58A4E; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A48A0308BDA3; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5409A4CA83; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdNpO011639 for ; Thu, 24 May 2018 06:39:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 601AC1049466; Thu, 24 May 2018 10:39:23 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 043471049465 for ; Thu, 24 May 2018 10:39:21 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:12 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 4/7] qemu: add private data for vsock X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 24 May 2018 10:39:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Introduce a structure and a class that will be used to store the private data. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_domain.c | 36 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 9 +++++++++ 2 files changed, 45 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6648933c80..527abe3b63 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1134,6 +1134,41 @@ qemuDomainChrSourcePrivateDispose(void *obj) } =20 =20 +static virClassPtr qemuDomainVsockPrivateClass; +static void qemuDomainVsockPrivateDispose(void *obj); + +static int +qemuDomainVsockPrivateOnceInit(void) +{ + if (!VIR_CLASS_NEW(qemuDomainVsockPrivate, virClassForObject())) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(qemuDomainVsockPrivate) + +static virObjectPtr +qemuDomainVsockPrivateNew(void) +{ + qemuDomainVsockPrivatePtr priv; + + if (qemuDomainVsockPrivateInitialize() < 0) + return NULL; + + if (!(priv =3D virObjectNew(qemuDomainVsockPrivateClass))) + return NULL; + + return (virObjectPtr) priv; +} + + +static void +qemuDomainVsockPrivateDispose(void *obj ATTRIBUTE_UNUSED) +{ +} + + /* qemuDomainSecretPlainSetup: * @secinfo: Pointer to secret info * @usageType: The virSecretUsageType @@ -2636,6 +2671,7 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivate= DataCallbacks =3D { .diskNew =3D qemuDomainDiskPrivateNew, .vcpuNew =3D qemuDomainVcpuPrivateNew, .chrSourceNew =3D qemuDomainChrSourcePrivateNew, + .vsockNew =3D qemuDomainVsockPrivateNew, .parse =3D qemuDomainObjPrivateXMLParse, .format =3D qemuDomainObjPrivateXMLFormat, .storageParse =3D qemuStorageSourcePrivateDataParse, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 40d1d095a3..2046741a17 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -441,6 +441,15 @@ struct _qemuDomainChrSourcePrivate { }; =20 =20 +typedef struct _qemuDomainVsockPrivate qemuDomainVsockPrivate; +typedef qemuDomainVsockPrivate *qemuDomainVsockPrivatePtr; +struct _qemuDomainVsockPrivate { + virObject parent; + + virTristateBool maybe; +}; + + typedef enum { QEMU_PROCESS_EVENT_WATCHDOG =3D 0, QEMU_PROCESS_EVENT_GUESTPANIC, --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15271583993214.028136537551745; Thu, 24 May 2018 03:39:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E5853189105; Thu, 24 May 2018 10:39:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D8C891D08; Thu, 24 May 2018 10:39:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E05C64CA86; Thu, 24 May 2018 10:39:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdO3e011652 for ; Thu, 24 May 2018 06:39:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 00A4A1049466; Thu, 24 May 2018 10:39:24 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A6781049465 for ; Thu, 24 May 2018 10:39:23 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:13 +0200 Message-Id: <0fe05a0f7cc755e6e9d38e06ff9e2b783b8f4d28.1527157595.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 5/7] Introduce QEMU_CAPS_DEVICE_VHOST_VSOCK X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 24 May 2018 10:39:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Add a new capability flag for vhost-vsock-device https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml | 1 + 16 files changed, 17 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index bface72de2..e3d2a7825b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -487,6 +487,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, /* 300 */ "sdl-gl", "screendump_device", + "vhost-vsock", ); =20 =20 @@ -1117,6 +1118,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[= ] =3D { { "pr-manager-helper", QEMU_CAPS_PR_MANAGER_HELPER }, { "virtual-css-bridge", QEMU_CAPS_CCW }, { "vfio-ccw", QEMU_CAPS_DEVICE_VFIO_CCW }, + { "vhost-vsock-device", QEMU_CAPS_DEVICE_VHOST_VSOCK }, }; =20 static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBalloon[]= =3D { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 6f9953478a..190b94bff4 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -471,6 +471,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ /* 300 */ QEMU_CAPS_SDL_GL, /* -sdl gl */ QEMU_CAPS_SCREENDUMP_DEVICE, /* screendump command accepts device & he= ad */ + QEMU_CAPS_DEVICE_VHOST_VSOCK, /* -device vhost-vsock-* */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml b/tests/qem= ucapabilitiesdata/caps_2.10.0.aarch64.xml index 5904306848..6d3b807435 100644 --- a/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.10.0.aarch64.xml @@ -155,6 +155,7 @@ + 2010000 0 303541 diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml b/tests/qemuc= apabilitiesdata/caps_2.10.0.ppc64.xml index 2912c8d66b..2e876fd7f1 100644 --- a/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_2.10.0.ppc64.xml @@ -154,6 +154,7 @@ + 2010000 0 382824 diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml b/tests/qemuc= apabilitiesdata/caps_2.10.0.s390x.xml index 518788ac13..e14591ed46 100644 --- a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml @@ -116,6 +116,7 @@ + 2010000 0 303434 diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml b/tests/qemu= capabilitiesdata/caps_2.10.0.x86_64.xml index 77ca3013b5..32e4b6a0bf 100644 --- a/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.10.0.x86_64.xml @@ -197,6 +197,7 @@ + 2010000 0 344938 diff --git a/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml b/tests/qemuc= apabilitiesdata/caps_2.11.0.s390x.xml index 9adca9d46b..b84d03f3a7 100644 --- a/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml @@ -122,6 +122,7 @@ + 2011000 0 342166 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml b/tests/qem= ucapabilitiesdata/caps_2.12.0.aarch64.xml index de41d96cd0..b6acc58304 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml @@ -163,6 +163,7 @@ + 2011090 0 343099 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml b/tests/qemuc= apabilitiesdata/caps_2.12.0.ppc64.xml index fc26f934ee..49924ff88c 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml @@ -160,6 +160,7 @@ + 2011090 0 419968 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml b/tests/qemuc= apabilitiesdata/caps_2.12.0.s390x.xml index bdfb81c998..cdffaed262 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml @@ -128,6 +128,7 @@ + 2012000 0 371055 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml b/tests/qemu= capabilitiesdata/caps_2.12.0.x86_64.xml index 820b3ef759..2b04c3d138 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml @@ -201,6 +201,7 @@ + 2011090 0 390813 diff --git a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml b/tests/qemuca= pabilitiesdata/caps_2.8.0.s390x.xml index 84546b72b9..841ff01acb 100644 --- a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml @@ -108,6 +108,7 @@ + 2007093 0 241741 diff --git a/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_2.8.0.x86_64.xml index 7c329ad4c7..16ce016e8f 100644 --- a/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml @@ -179,6 +179,7 @@ + 2008000 0 255684 diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_2.9.0.ppc64.xml index cfc9405095..ed2444dc8f 100644 --- a/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_2.9.0.ppc64.xml @@ -146,6 +146,7 @@ + 2009000 0 346538 diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml b/tests/qemuca= pabilitiesdata/caps_2.9.0.s390x.xml index 96521efb8a..23f0e33526 100644 --- a/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml @@ -111,6 +111,7 @@ + 2009000 0 265159 diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_2.9.0.x86_64.xml index 0701c244f6..e0da4d41db 100644 --- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml @@ -192,6 +192,7 @@ + 2009000 0 320947 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158392518133.25675649418963; Thu, 24 May 2018 03:39:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBC5F914F7; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 847381057FA4; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1DF3618033EE; Thu, 24 May 2018 10:39:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdOaA011660 for ; Thu, 24 May 2018 06:39:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9479E1049466; Thu, 24 May 2018 10:39:24 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A53F1049465 for ; Thu, 24 May 2018 10:39:24 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:14 +0200 Message-Id: <8766ea39c30484f26136d4e0ab66294fd48870b8.1527157595.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 6/7] util: create virvsock.c X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 24 May 2018 10:39:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 A file for vsock-related helper functions. virVsockSetGuestCid to set an already-known CID, virVsockAcquireGuestCid that will use the first available CID https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- configure.ac | 8 +++++ src/libvirt_private.syms | 5 +++ src/util/Makefile.inc.am | 2 ++ src/util/virvsock.c | 89 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virvsock.h | 29 ++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 src/util/virvsock.c create mode 100644 src/util/virvsock.h diff --git a/configure.ac b/configure.ac index cc005ea9e8..b869a17afe 100644 --- a/configure.ac +++ b/configure.ac @@ -641,6 +641,14 @@ if test "$with_linux" =3D "yes"; then [[#include ]]) fi =20 +dnl +dnl check for VHOST_VSOCK_SET_GUEST_CID +dnl +if test "$with_linux" =3D "yes"; then + AC_CHECK_DECLS([VHOST_VSOCK_SET_GUEST_CID], [], [], + [[#include ]]) +fi + dnl Allow perl/python overrides AC_PATH_PROGS([PYTHON], [python3 python2 python]) if test -z "$PYTHON"; then diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8e33f3e9f6..0f8045454b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3121,6 +3121,11 @@ virVHBAManageVport; virVHBAPathExists; =20 =20 +# util/virvsock.h +virVsockAcquireGuestCid; +virVsockSetGuestCid; + + # util/virxml.h virXMLCheckIllegalChars; virXMLChildElementCount; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index ec8745da7e..a22265606c 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -204,6 +204,8 @@ UTIL_SOURCES =3D \ util/viruuid.h \ util/virvhba.c \ util/virvhba.h \ + util/virvsock.c \ + util/virvsock.h \ util/virxdrdefs.h \ util/virxml.c \ util/virxml.h \ diff --git a/src/util/virvsock.c b/src/util/virvsock.c new file mode 100644 index 0000000000..8a5c88700b --- /dev/null +++ b/src/util/virvsock.c @@ -0,0 +1,89 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#include + +#include +/* #include */ + +#if HAVE_DECL_VHOST_VSOCK_SET_GUEST_CID +# include +#endif + +#include "virvsock.h" + +#include "virerror.h" +#include "virlog.h" + + +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("util.vsock"); + +#if HAVE_DECL_VHOST_VSOCK_SET_GUEST_CID +static int +virVsockSetGuestCidQuiet(int fd, + unsigned int guest_cid) +{ + uint64_t val =3D guest_cid; + + return ioctl(fd, VHOST_VSOCK_SET_GUEST_CID, &val); +} + +#else +static int +virVsockSetGuestCidQuiet(int fd ATTRIBUTE_UNUSED, + unsigned int guest_cid ATTRIBUTE_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} +#endif + + +int +virVsockSetGuestCid(int fd, + unsigned int guest_cid) +{ + if (virVsockSetGuestCidQuiet(fd, guest_cid) < 0) { + virReportSystemError(errno, "%s", + _("failed to set guest cid")); + return -1; + } + + return 0; +} + +#define VIR_VSOCK_GUEST_CID_MIN 3 + +int +virVsockAcquireGuestCid(int fd, + unsigned int *guest_cid) +{ + unsigned int cid =3D VIR_VSOCK_GUEST_CID_MIN; + + for (; virVsockSetGuestCidQuiet(fd, cid) < 0; cid++) { + if (errno !=3D EADDRINUSE) { + virReportSystemError(errno, "%s", + _("failed to acquire guest cid")); + return -1; + } + } + *guest_cid =3D cid; + + return 0; +} diff --git a/src/util/virvsock.h b/src/util/virvsock.h new file mode 100644 index 0000000000..080a322420 --- /dev/null +++ b/src/util/virvsock.h @@ -0,0 +1,29 @@ +/* + * virvsock.h - vsock related util functions + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef __VIR_VSOCK_H__ +# define __VIR_VSOCK_H__ + +int +virVsockSetGuestCid(int fd, + unsigned int guest_cid); + +int +virVsockAcquireGuestCid(int fd, + unsigned int *guest_cid); +#endif /* __VIR_VSOCK_H__ */ --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527158410585996.5386695451716; Thu, 24 May 2018 03:40:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78FACC0AD1F4; Thu, 24 May 2018 10:40:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CF6E5F90E; Thu, 24 May 2018 10:40:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BF99B18033EE; Thu, 24 May 2018 10:40:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4OAdP9l011678 for ; Thu, 24 May 2018 06:39:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3524F1049466; Thu, 24 May 2018 10:39:25 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CED821049465 for ; Thu, 24 May 2018 10:39:24 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 24 May 2018 12:39:15 +0200 Message-Id: <7bdcd95395f7e4b472a2653f58c5e439f4f95eec.1527157595.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 7/7] qemu: add support for vhost-vsock-pci X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 24 May 2018 10:40:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Create a new vsock endpoint by opening /dev/vhost-vsock, set the requested CID via ioctl (or assign a free one if auto=3D'yes'), pass the file descriptor to QEMU and build the command line. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_alias.c | 16 ++++++++ src/qemu/qemu_command.c | 45 ++++++++++++++++++= ++++ src/qemu/qemu_domain.c | 5 +++ src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_process.c | 35 +++++++++++++++++ .../vhost-vsock-auto.x86_64-latest.args | 32 +++++++++++++++ .../vhost-vsock.x86_64-latest.args | 32 +++++++++++++++ tests/qemuxml2argvtest.c | 14 +++++++ 8 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.a= rgs create mode 100644 tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 578a33b284..89dec91ed1 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -533,6 +533,18 @@ qemuAssignDeviceInputAlias(virDomainDefPtr def, } =20 =20 +static int +qemuAssignDeviceVsockAlias(virDomainVsockDefPtr vsock) +{ + if (vsock->info.alias) + return 0; + if (VIR_STRDUP(vsock->info.alias, "vsock0") < 0) + return -1; + + return 0; +} + + int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { @@ -629,6 +641,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCa= psPtr qemuCaps) if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0) return -1; } + if (def->vsock) { + if (qemuAssignDeviceVsockAlias(def->vsock) < 0) + return -1; + } =20 return 0; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9da2d609e8..ef0716d683 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9865,6 +9865,47 @@ qemuBuildSeccompSandboxCommandLine(virCommandPtr cmd, } =20 =20 +static int +qemuBuildVsockCommandLine(virCommandPtr cmd, + virDomainDefPtr def, + virDomainVsockDefPtr vsock, + const char *fdprefix, + virQEMUCapsPtr qemuCaps) +{ + qemuDomainVsockPrivatePtr priv =3D (qemuDomainVsockPrivatePtr)vsock->p= rivateData; + const char *device =3D "vhost-vsock-pci"; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *devstr =3D NULL; + int ret =3D -1; + + virBufferAsprintf(&buf, "%s", device); + virBufferAsprintf(&buf, ",id=3D%s", vsock->info.alias); + virBufferAsprintf(&buf, ",guest-cid=3D%u", vsock->guest_cid); + virBufferAsprintf(&buf, ",vhostfd=3D%s%u", fdprefix, priv->vhostfd); + if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info, qemuCaps) < 0) + goto cleanup; +#if 0 + if (qemuBuildVirtioOptionsStr(&buf, net->virtio, qemuCaps) < 0) + goto error; +#endif + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + devstr =3D virBufferContentAndReset(&buf); + + virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); + priv->vhostfd =3D -1; + virCommandAddArgList(cmd, "-device", devstr, NULL); + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&buf); + VIR_FREE(devstr); + return ret; +} + + /* * Constructs a argv suitable for launching qemu with config defined * for a given virtual machine. @@ -10111,6 +10152,10 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, goto error; } =20 + if (def->vsock && + qemuBuildVsockCommandLine(cmd, def, def->vsock, "", qemuCaps) < 0) + goto error; + /* In some situations, eg. VFIO passthrough, QEMU might need to lock a * significant amount of memory, so we need to set the limit according= ly */ virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def)); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 527abe3b63..ff24f4b0d2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1159,6 +1159,8 @@ qemuDomainVsockPrivateNew(void) if (!(priv =3D virObjectNew(qemuDomainVsockPrivateClass))) return NULL; =20 + priv->vhostfd =3D -1; + return (virObjectPtr) priv; } =20 @@ -1166,6 +1168,9 @@ qemuDomainVsockPrivateNew(void) static void qemuDomainVsockPrivateDispose(void *obj ATTRIBUTE_UNUSED) { + qemuDomainVsockPrivatePtr priv =3D obj; + + VIR_FORCE_CLOSE(priv->vhostfd); } =20 =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 2046741a17..6ddf016eb7 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -446,7 +446,7 @@ typedef qemuDomainVsockPrivate *qemuDomainVsockPrivateP= tr; struct _qemuDomainVsockPrivate { virObject parent; =20 - virTristateBool maybe; + int vhostfd; }; =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 174d932ae7..e318639963 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -79,6 +79,7 @@ #include "nwfilter_conf.h" #include "netdev_bandwidth_conf.h" #include "virresctrl.h" +#include "virvsock.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -5975,6 +5976,36 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr drive= r, } =20 =20 +static int +qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock) +{ + qemuDomainVsockPrivatePtr priv =3D (qemuDomainVsockPrivatePtr)vsock->p= rivateData; + const char *vsock_path =3D "/dev/vhost-vsock"; + int fd; + + if ((fd =3D open(vsock_path, O_RDWR)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("unable to open vhost-vsock device")); + return -1; + } + + if (vsock->guest_cid) { + if (virVsockSetGuestCid(fd, vsock->guest_cid) < 0) + goto error; + } else { + if (virVsockAcquireGuestCid(fd, &vsock->guest_cid) < 0) + goto error; + } + + priv->vhostfd =3D fd; + return 0; + + error: + VIR_FORCE_CLOSE(fd); + return -1; +} + + /** * qemuProcessPrepareHost: * @driver: qemu driver @@ -6000,6 +6031,10 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver, if (qemuPrepareNVRAM(cfg, vm) < 0) goto cleanup; =20 + if (vm->def->vsock) { + if (qemuProcessOpenVhostVsock(vm->def->vsock) < 0) + goto cleanup; + } /* network devices must be "prepared" before hostdevs, because * setting up a network device might create a new hostdev that * will need to be setup. diff --git a/tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args b/t= ests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args new file mode 100644 index 0000000000..cefd4e3009 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-0.13,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 1024 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid bba65c0e-c049-934f-b6aa-4e2c0582acdf \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-test/monitor.so= ck,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot menu=3Don,strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x6 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-device vhost-vsock-pci,id=3Dvsock0,guest-cid=3D42,vhostfd=3D6789,bus=3Dpc= i.0,addr=3D0x2 \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args b/tests/= qemuxml2argvdata/vhost-vsock.x86_64-latest.args new file mode 100644 index 0000000000..907af8bb99 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-0.13,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 1024 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid bba65c0e-c049-934f-b6aa-4e2c0582acdf \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-test/monitor.so= ck,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot menu=3Don,strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x6 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-device vhost-vsock-pci,id=3Dvsock0,guest-cid=3D4,vhostfd=3D6789,bus=3Dpci= .0,addr=3D0x7 \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 78454acb1a..759b045e4c 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -532,6 +532,17 @@ testCompareXMLToArgv(const void *data) } } =20 + if (vm->def->vsock) { + virDomainVsockDefPtr vsock =3D vm->def->vsock; + qemuDomainVsockPrivatePtr vsockPriv =3D + (qemuDomainVsockPrivatePtr)vsock->privateData; + + if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) + vsock->guest_cid =3D 42; + + vsockPriv->vhostfd =3D 6789; + } + if (!(cmd =3D qemuProcessCreatePretendCmd(&driver, vm, migrateURI, (flags & FLAG_FIPS), false, VIR_QEMU_PROCESS_START_COLD)))= { @@ -2848,6 +2859,9 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_MOUSE_CCW, QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW); =20 + DO_TEST_CAPS_LATEST("vhost-vsock"); + DO_TEST_CAPS_LATEST("vhost-vsock-auto"); + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 05:29:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527598418057761.5292881702637; Tue, 29 May 2018 05:53:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78F8E30C3A1D; Tue, 29 May 2018 12:53:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 307B817C4D; Tue, 29 May 2018 12:53:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D3DF24CA84; Tue, 29 May 2018 12:53:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4TCrG4U013525 for ; Tue, 29 May 2018 08:53:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13593202698A; Tue, 29 May 2018 12:53:16 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F85A2026988 for ; Tue, 29 May 2018 12:53:15 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 29 May 2018 14:53:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3] qemu: add support for vhost-vsock-pci X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 29 May 2018 12:53:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Create a new vsock endpoint by opening /dev/vhost-vsock, set the requested CID via ioctl (or assign a free one if auto=3D'yes'), pass the file descriptor to QEMU and build the command line. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- Rebased version with all the ACKed squash-ins for patches 1-6 available at: git://repo.or.cz/libvirt/jtomko.git vsock-v3 http://repo.or.cz/libvirt/jtomko.git/shortlog/refs/heads/vsock-v3 src/qemu/qemu_alias.c | 16 +++++++++ src/qemu/qemu_command.c | 40 ++++++++++++++++++= ++++ src/qemu/qemu_domain.c | 5 +++ src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_process.c | 35 +++++++++++++++++++ .../vhost-vsock-auto.x86_64-latest.args | 32 +++++++++++++++++ .../vhost-vsock.x86_64-latest.args | 32 +++++++++++++++++ tests/qemuxml2argvtest.c | 14 ++++++++ 8 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.a= rgs create mode 100644 tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 578a33b284..89dec91ed1 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -533,6 +533,18 @@ qemuAssignDeviceInputAlias(virDomainDefPtr def, } =20 =20 +static int +qemuAssignDeviceVsockAlias(virDomainVsockDefPtr vsock) +{ + if (vsock->info.alias) + return 0; + if (VIR_STRDUP(vsock->info.alias, "vsock0") < 0) + return -1; + + return 0; +} + + int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { @@ -629,6 +641,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCa= psPtr qemuCaps) if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0) return -1; } + if (def->vsock) { + if (qemuAssignDeviceVsockAlias(def->vsock) < 0) + return -1; + } =20 return 0; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c7ff074e29..0b5ec4f2ba 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9912,6 +9912,42 @@ qemuBuildSeccompSandboxCommandLine(virCommandPtr cmd, } =20 =20 +static int +qemuBuildVsockCommandLine(virCommandPtr cmd, + virDomainDefPtr def, + virDomainVsockDefPtr vsock, + virQEMUCapsPtr qemuCaps) +{ + qemuDomainVsockPrivatePtr priv =3D (qemuDomainVsockPrivatePtr)vsock->p= rivateData; + const char *device =3D "vhost-vsock-pci"; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *devstr =3D NULL; + int ret =3D -1; + + virBufferAsprintf(&buf, "%s", device); + virBufferAsprintf(&buf, ",id=3D%s", vsock->info.alias); + virBufferAsprintf(&buf, ",guest-cid=3D%u", vsock->guest_cid); + virBufferAsprintf(&buf, ",vhostfd=3D%u", priv->vhostfd); + if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info, qemuCaps) < 0) + goto cleanup; + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + devstr =3D virBufferContentAndReset(&buf); + + virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); + priv->vhostfd =3D -1; + virCommandAddArgList(cmd, "-device", devstr, NULL); + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&buf); + VIR_FREE(devstr); + return ret; +} + + /* * Constructs a argv suitable for launching qemu with config defined * for a given virtual machine. @@ -10161,6 +10197,10 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, goto error; } =20 + if (def->vsock && + qemuBuildVsockCommandLine(cmd, def, def->vsock, qemuCaps) < 0) + goto error; + /* In some situations, eg. VFIO passthrough, QEMU might need to lock a * significant amount of memory, so we need to set the limit according= ly */ virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def)); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 10f22b1cc2..2c51e4c0d8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1160,6 +1160,8 @@ qemuDomainVsockPrivateNew(void) if (!(priv =3D virObjectNew(qemuDomainVsockPrivateClass))) return NULL; =20 + priv->vhostfd =3D -1; + return (virObjectPtr) priv; } =20 @@ -1167,6 +1169,9 @@ qemuDomainVsockPrivateNew(void) static void qemuDomainVsockPrivateDispose(void *obj ATTRIBUTE_UNUSED) { + qemuDomainVsockPrivatePtr priv =3D obj; + + VIR_FORCE_CLOSE(priv->vhostfd); } =20 =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f298ebf785..2e0f4df0fb 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -447,7 +447,7 @@ typedef qemuDomainVsockPrivate *qemuDomainVsockPrivateP= tr; struct _qemuDomainVsockPrivate { virObject parent; =20 - virTristateBool maybe; + int vhostfd; }; =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5f5759c9c8..30cc5904e0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -79,6 +79,7 @@ #include "nwfilter_conf.h" #include "netdev_bandwidth_conf.h" #include "virresctrl.h" +#include "virvsock.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -5947,6 +5948,36 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr drive= r, } =20 =20 +static int +qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock) +{ + qemuDomainVsockPrivatePtr priv =3D (qemuDomainVsockPrivatePtr)vsock->p= rivateData; + const char *vsock_path =3D "/dev/vhost-vsock"; + int fd; + + if ((fd =3D open(vsock_path, O_RDWR)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("unable to open vhost-vsock device")); + return -1; + } + + if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) { + if (virVsockAcquireGuestCid(fd, &vsock->guest_cid) < 0) + goto error; + } else { + if (virVsockSetGuestCid(fd, vsock->guest_cid) < 0) + goto error; + } + + priv->vhostfd =3D fd; + return 0; + + error: + VIR_FORCE_CLOSE(fd); + return -1; +} + + /** * qemuProcessPrepareHost: * @driver: qemu driver @@ -5972,6 +6003,10 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver, if (qemuPrepareNVRAM(cfg, vm) < 0) goto cleanup; =20 + if (vm->def->vsock) { + if (qemuProcessOpenVhostVsock(vm->def->vsock) < 0) + goto cleanup; + } /* network devices must be "prepared" before hostdevs, because * setting up a network device might create a new hostdev that * will need to be setup. diff --git a/tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args b/t= ests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args new file mode 100644 index 0000000000..dd9b60ba3e --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-i440fx-2.9,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 1024 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid bba65c0e-c049-934f-b6aa-4e2c0582acdf \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-test/monitor.so= ck,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot menu=3Don,strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x6 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-device vhost-vsock-pci,id=3Dvsock0,guest-cid=3D42,vhostfd=3D6789,bus=3Dpc= i.0,addr=3D0x2 \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args b/tests/= qemuxml2argvdata/vhost-vsock.x86_64-latest.args new file mode 100644 index 0000000000..907af8bb99 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-0.13,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 1024 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid bba65c0e-c049-934f-b6aa-4e2c0582acdf \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-test/monitor.so= ck,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot menu=3Don,strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x6 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-device vhost-vsock-pci,id=3Dvsock0,guest-cid=3D4,vhostfd=3D6789,bus=3Dpci= .0,addr=3D0x7 \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2fe4390104..ddd2b88c0a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -532,6 +532,17 @@ testCompareXMLToArgv(const void *data) } } =20 + if (vm->def->vsock) { + virDomainVsockDefPtr vsock =3D vm->def->vsock; + qemuDomainVsockPrivatePtr vsockPriv =3D + (qemuDomainVsockPrivatePtr)vsock->privateData; + + if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) + vsock->guest_cid =3D 42; + + vsockPriv->vhostfd =3D 6789; + } + if (!(cmd =3D qemuProcessCreatePretendCmd(&driver, vm, migrateURI, (flags & FLAG_FIPS), false, VIR_QEMU_PROCESS_START_COLD)))= { @@ -2856,6 +2867,9 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_MOUSE_CCW, QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW); =20 + DO_TEST_CAPS_LATEST("vhost-vsock"); + DO_TEST_CAPS_LATEST("vhost-vsock-auto"); + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list