From nobody Wed May 14 17:29:02 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522242528553973.3023811250296; Wed, 28 Mar 2018 06:08:48 -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 A7F377D4FE; Wed, 28 Mar 2018 13:08:46 +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 476EB60BE0; Wed, 28 Mar 2018 13:08:46 +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 48C404CA99; Wed, 28 Mar 2018 13:08:45 +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 w2SD8iOr013621 for ; Wed, 28 Mar 2018 09:08:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 44F46200BCCD; Wed, 28 Mar 2018 13:08:44 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id C10622026DFD; Wed, 28 Mar 2018 13:08:43 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 15:08:29 +0200 Message-Id: <6f748005a6206fba4abedb6206bf073386e0d845.1522241949.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 1/3] qemu: hotplug: Introduce hot plug support for mediated devices 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.28]); Wed, 28 Mar 2018 13:08:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Mediated devices support hot-{plug,unplug} since their introduction in kernel 4.10, however libvirt has still been missing support for this. Signed-off-by: Erik Skultety --- src/qemu/qemu_hotplug.c | 86 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 86 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 49af4d4ff..92e4d1cc9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2567,6 +2567,88 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr dri= ver, } =20 =20 +static int +qemuDomainAttachMediatedDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainHostdevDefPtr hostdev) +{ + int ret =3D -1; + char *devstr =3D NULL; + bool added =3D false; + bool teardowncgroup =3D false; + bool teardownlabel =3D false; + bool teardowndevice =3D false; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virDomainDeviceDef dev =3D { VIR_DOMAIN_DEVICE_HOSTDEV, + { .hostdev =3D hostdev } }; + + if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0) + return -1; + + if (qemuHostdevPrepareMediatedDevices(driver, + vm->def->name, + &hostdev, + 1) < 0) + goto cleanup; + added =3D true; + + if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + goto cleanup; + teardowndevice =3D true; + + if (qemuSetupHostdevCgroup(vm, hostdev) < 0) + goto cleanup; + teardowncgroup =3D true; + + if (qemuSecuritySetHostdevLabel(driver, vm, hostdev) < 0) + goto cleanup; + teardownlabel =3D true; + + if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) <= 0) + goto cleanup; + + if (!(devstr =3D qemuBuildHostdevMediatedDevStr(vm->def, hostdev, + priv->qemuCaps))) + goto cleanup; + + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) + goto cleanup; + + qemuDomainObjEnterMonitor(driver, vm); + ret =3D qemuMonitorAddDevice(priv->mon, devstr); + if (qemuDomainObjExitMonitor(driver, vm) < 0) { + ret =3D -1; + goto cleanup; + } + + virDomainAuditHostdev(vm, hostdev, "attach", ret =3D=3D 0); + if (ret < 0) + goto cleanup; + + VIR_APPEND_ELEMENT_INPLACE(vm->def->hostdevs, vm->def->nhostdevs, host= dev); + ret =3D 0; + cleanup: + if (ret < 0) { + if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0) + VIR_WARN("Unable to remove host device cgroup ACL on hotplug f= ail"); + if (teardownlabel && + qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) + VIR_WARN("Unable to restore host device labelling on hotplug f= ail"); + if (teardowndevice && + qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0) + VIR_WARN("Unable to remove host device from /dev"); + if (added) + qemuHostdevReAttachMediatedDevices(driver, + vm->def->name, + &hostdev, + 1); + qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL); + } + VIR_FREE(devstr); + return ret; +} + + int qemuDomainAttachHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -2602,6 +2684,10 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver, if (qemuDomainAttachSCSIVHostDevice(driver, vm, hostdev) < 0) goto error; break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + if (qemuDomainAttachMediatedDevice(driver, vm, hostdev) < 0) + goto error; + break; =20 default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list