From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028836; cv=none; d=zoho.com; s=zohoarc; b=eq0/lP/gIUMtApvh6QNkAdC8IJ13F/7tQMGHtD6Q/C1SGNHS0CMU5NNmSqQuy0ckbm/eKNbKQgTgffeIpoIlFZEsRHfTBMSHu4Rq8aAYQWxcwlsEmoK9Vf2nW4+ihHNANVzIc0vCu/brlR1tN46cnkfL2d+CnPANu5Ny71Imk+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028836; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Gbk7ua70YLYZ7nB5DK+yNomwnePRNwbnztA7/Pr6nbw=; b=QcMgj4vrVhJnfSVP1cEyUEAt0IVwxttDNlslshMf+91kdfL5ZDt/1hBaSnVbhQOML1lAYpii1Ob2X+X5AD2kf4wMyiKtzneBDdz0U87dRQrW6lM3QQn5CT5A7C4GFT5PLaOwhdwhlkkGwaMVMw/12W28f0kVCnuv8gGSOdJL1tc= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028836964320.44968113534037; Mon, 9 Sep 2019 04:33:56 -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 24293898113; Mon, 9 Sep 2019 11:33:55 +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 02C9860BE2; Mon, 9 Sep 2019 11:33:55 +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 ACDD02551B; Mon, 9 Sep 2019 11:33:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrXM013713 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 59D6C60F9E; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx21.extmail.prod.ext.phx2.redhat.com [10.5.110.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F74060C44 for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA55018C4276 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvX-0002RT-AJ; Mon, 09 Sep 2019 14:33:47 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:04 +0300 Message-Id: <20190909113314.22362-2-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.62 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 01/11] qemu: track hostdev delete intention 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-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.6.2 (mx1.redhat.com [10.5.110.67]); Mon, 09 Sep 2019 11:33:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We are going to call qemuDomainDetachDeviceLive when usb device is unplugged from host. But later when DEVICE_DELETED event is delivered we need to keep device in libvirt config. For this purpuse let's save delete intention in device config. Signed-off-by: Nikolay Shirokovskiy --- src/conf/domain_conf.h | 14 ++++++++++++++ src/qemu/qemu_driver.c | 4 ++-- src/qemu/qemu_hotplug.c | 23 ++++++++++++++++++++--- src/qemu/qemu_hotplug.h | 3 ++- tests/qemuhotplugtest.c | 2 +- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 33cef5b75c..19a5b21462 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -326,6 +326,19 @@ struct _virDomainHostdevCaps { } u; }; =20 +typedef enum { + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE =3D 0, + /* delete associated device from libvirt config + * as intended by client API call */ + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE, + /* keep associated device in libvirt config as + * qemu device is deleted as a result of unplugging + * device from host */ + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG, + + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST +} virDomainHostdevDeleteActionType; + =20 /* basic device for direct passthrough */ struct _virDomainHostdevDef { @@ -343,6 +356,7 @@ struct _virDomainHostdevDef { bool missing; bool readonly; bool shareable; + virDomainHostdevDeleteActionType deleteAction; union { virDomainHostdevSubsys subsys; virDomainHostdevCaps caps; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 78f5471b79..2378a2e7d0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9123,7 +9123,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr = driver, if (flags & VIR_DOMAIN_AFFECT_LIVE) { int rc; =20 - if ((rc =3D qemuDomainDetachDeviceLive(vm, dev_copy, driver, false= )) < 0) + if ((rc =3D qemuDomainDetachDeviceLive(vm, dev_copy, driver, false= , false)) < 0) goto cleanup; =20 if (rc =3D=3D 0 && qemuDomainUpdateDeviceList(driver, vm, QEMU_ASY= NC_JOB_NONE) < 0) @@ -9212,7 +9212,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDrive= rPtr driver, if (virDomainDefFindDevice(def, alias, &dev, true) < 0) goto cleanup; =20 - if ((rc =3D qemuDomainDetachDeviceLive(vm, &dev, driver, true)) < = 0) + if ((rc =3D qemuDomainDetachDeviceLive(vm, &dev, driver, true, fal= se)) < 0) goto cleanup; =20 if (rc =3D=3D 0 && qemuDomainUpdateDeviceList(driver, vm, QEMU_ASY= NC_JOB_NONE) < 0) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 63acb9c451..559254b234 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5348,7 +5348,8 @@ qemuDomainDetachPrepController(virDomainObjPtr vm, static int qemuDomainDetachPrepHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr match, - virDomainHostdevDefPtr *detach) + virDomainHostdevDefPtr *detach, + bool unplug) { virDomainHostdevSubsysPtr subsys =3D &match->source.subsys; virDomainHostdevSubsysUSBPtr usbsrc =3D &subsys->u.usb; @@ -5420,6 +5421,20 @@ qemuDomainDetachPrepHostdev(virDomainObjPtr vm, return -1; } =20 + /* + * Why having additional check in second branch? Suppose client + * asks for device detaching and we delete device from qemu + * but don't get DEVICE_DELETED event yet. Next USB is unplugged + * from host and we have this function called again. If we reset + * delete action to 'unplug' then device will be left in + * libvirt config after handling DEVICE_DELETED event while + * it should not as client asked to detach the device before. + */ + if (!unplug) + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE; + else if (hostdev->deleteAction !=3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_D= ELETE) + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG; + return 0; } =20 @@ -5721,7 +5736,8 @@ int qemuDomainDetachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr match, virQEMUDriverPtr driver, - bool async) + bool async, + bool unplug) { virDomainDeviceDef detach =3D { .type =3D match->type }; virDomainDeviceInfoPtr info =3D NULL; @@ -5766,7 +5782,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_HOSTDEV: if (qemuDomainDetachPrepHostdev(vm, match->data.hostdev, - &detach.data.hostdev) < 0) { + &detach.data.hostdev, + unplug) < 0) { return -1; } break; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 896e6c7b98..f7ebf3f505 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -116,7 +116,8 @@ int qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, int qemuDomainDetachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr match, virQEMUDriverPtr driver, - bool async); + bool async, + bool unplug); =20 void qemuDomainRemoveVcpuAlias(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index b6aad330a9..ef91d4f131 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -151,7 +151,7 @@ testQemuHotplugDetach(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_WATCHDOG: - ret =3D qemuDomainDetachDeviceLive(vm, dev, &driver, async); + ret =3D qemuDomainDetachDeviceLive(vm, dev, &driver, async, false); break; default: VIR_TEST_VERBOSE("device type '%s' cannot be detached", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028836; cv=none; d=zoho.com; s=zohoarc; b=Nc02VMVYfFIcjFJl5S7HJk86xbsiEQClmrb5idPfNqTlo+wRNBtsfjDarL+xQLdZ//5oluddqZjLF/waWkirx8OjKJ918xjKTeKjsLTeaoAbhhPimVqIvvNS6TeqKjew7Lmh15bIXrvt2GnvTyO4p5X3yE/t43E9n8crWDgbeaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028836; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Eoq5bpk/bX9p2VqYTJRB5uROjaFv/e1A8kLISp1ob4I=; b=CdRrM8nu3bAh4fn+UHZlAbbUVcW/mYgJzL3Ul8PlHEk9fYEEqhiWN/foOLuXv1RfvW9MGfwkPGOCSzVgcxItKKONfxyg5Ac5ZIhLNvuVdezKUfLVYzPtx4LHWTQ1zjZAWofh9s2nfLSvp9W7QT7RsIwZLuEf8aYRwuNT1omkAwE= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028836612721.931308210012; Mon, 9 Sep 2019 04:33:56 -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 B1DAE30A0104; Mon, 9 Sep 2019 11:33:54 +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 8D31C10018F9; Mon, 9 Sep 2019 11:33:54 +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 4BE0D2551B; Mon, 9 Sep 2019 11:33:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrc6013727 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E8D060BE2; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx27.extmail.prod.ext.phx2.redhat.com [10.5.110.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5038C60C5E for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F5B2A2F6A0 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvX-0002RT-DT; Mon, 09 Sep 2019 14:33:47 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:05 +0300 Message-Id: <20190909113314.22362-3-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.68 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 02/11] qemu: support host usb device unplug 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-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.43]); Mon, 09 Sep 2019 11:33:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Handle host usb device unplug in DEVICE_DELETED handle execution path. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 559254b234..b045735022 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4366,7 +4366,8 @@ qemuDomainRemoveUSBHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefPtr hostdev) { qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1); - qemuDomainReleaseDeviceAddress(vm, hostdev->info); + if (hostdev->deleteAction !=3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG) + qemuDomainReleaseDeviceAddress(vm, hostdev->info); } =20 static void @@ -4408,6 +4409,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, char *drivealias =3D NULL; char *objAlias =3D NULL; bool is_vfio =3D false; + bool unplug =3D hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTDEV_DELETE= _ACTION_UNPLUG; =20 VIR_DEBUG("Removing host device %s from domain %p %s", hostdev->info->alias, vm, vm->def->name); @@ -4454,16 +4456,24 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, } } =20 - for (i =3D 0; i < vm->def->nhostdevs; i++) { - if (vm->def->hostdevs[i] =3D=3D hostdev) { - virDomainHostdevRemove(vm->def, i); - break; + if (!unplug) { + for (i =3D 0; i < vm->def->nhostdevs; i++) { + if (vm->def->hostdevs[i] =3D=3D hostdev) { + virDomainHostdevRemove(vm->def, i); + break; + } } } =20 virDomainAuditHostdev(vm, hostdev, "detach", true); =20 - if (!is_vfio && + /* + * In case of unplug the attempt to restore label will fail. But we do= n't + * need to restore the label! In case of separate mount namespace for = the + * domain we remove device file later in this function. In case of glo= bal + * mount namespace the device file is deleted or being deleted by syst= emd. + */ + if (!is_vfio && !unplug && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -4497,7 +4507,13 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, break; } =20 - virDomainHostdevDefFree(hostdev); + if (unplug) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + usbsrc->bus =3D 0; + usbsrc->device =3D 0; + } else { + virDomainHostdevDefFree(hostdev); + } =20 if (net) { if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { @@ -4512,6 +4528,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainNetDefFree(net); } =20 + hostdev->deleteAction =3D VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE; + ret =3D 0; =20 cleanup: @@ -4981,6 +4999,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainDeviceInfoPtr info; virObjectEventPtr event; VIR_AUTOFREE(char *) alias =3D NULL; + bool unplug; =20 /* * save the alias to use when sending a DEVICE_REMOVED event after @@ -5021,8 +5040,13 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, return -1; break; case VIR_DOMAIN_DEVICE_HOSTDEV: + unplug =3D dev->data.hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTD= EV_DELETE_ACTION_UNPLUG; + if (qemuDomainRemoveHostDevice(driver, vm, dev->data.hostdev) < 0) return -1; + + if (unplug) + return 0; break; case VIR_DOMAIN_DEVICE_RNG: if (qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng) < 0) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028849; cv=none; d=zoho.com; s=zohoarc; b=FzuDfW7QlrQYqI+McXJ6eAe2zM0JAD+ZKW7YiP0aB1WmoFqWNH2ijie6wO/CsXLIF153dkRptmLbmaWdBJ9rihbGNynIADy2iI28AhyA4zqmpMarUZjYsK+eafEi5LhiyxzrUMNsSnvvtcKi7RgN4zzHptKBO1ZbmlFz8EcFjPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028849; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=EVvMYq73zXy9bm667PFoqOxFCG2Msoz20vd5Oo9Ngx8=; b=Ys+1EmmbZGkjYecH6WAkHRsek5sAjKfR90pU3x/YQAPqTbMBeo/WEKMbpjEFBkrlapFbbn27FpQYmlILBgNh2vhTwSMvxa9JMeBs5eBDRHvxSf0jiiDJkA9wRO3gwWs7PMWRIkSPRWbjctK7Rr87CgNoKMssrToqjcWyUFg2hGY= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156802884961340.77773140587328; Mon, 9 Sep 2019 04:34:09 -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 97B4F19B114D; Mon, 9 Sep 2019 11:34:06 +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 6B574100195F; Mon, 9 Sep 2019 11:34:06 +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 25AAF18034E0; Mon, 9 Sep 2019 11:34:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrYk013719 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7588110027AD; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 704A41001F43 for ; Mon, 9 Sep 2019 11:33:50 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE3CB308FFB1 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvX-0002RT-Hc; Mon, 09 Sep 2019 14:33:47 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:06 +0300 Message-Id: <20190909113314.22362-4-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 03/11] qemu: support usb hostdev plugging back 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-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.6.2 (mx1.redhat.com [10.5.110.63]); Mon, 09 Sep 2019 11:34:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We are going to use qemuDomainAttachHostUSBDevice when host usb device is plugged back to node. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b045735022..ea82cb54ef 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2437,8 +2437,18 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr drive= r, bool teardownlabel =3D false; bool teardowndevice =3D false; int ret =3D -1; + bool replug; + size_t i; + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + if (vm->def->hostdevs[i] =3D=3D hostdev) { + replug =3D true; + break; + } + } =20 - if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) + if (!replug && + virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) return -1; =20 if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0= ) < 0) @@ -2463,7 +2473,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, if (!(devstr =3D qemuBuildUSBHostdevDevStr(vm->def, hostdev, priv->qem= uCaps))) goto cleanup; =20 - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) + if (!replug && VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) = < 0) goto cleanup; =20 qemuDomainObjEnterMonitor(driver, vm); @@ -2476,7 +2486,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, if (ret < 0) goto cleanup; =20 - vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; + if (!replug) + vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; =20 ret =3D 0; cleanup: @@ -2489,9 +2500,17 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr drive= r, if (teardowndevice && qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0) VIR_WARN("Unable to remove host device from /dev"); - if (added) + if (added) { qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev,= 1); - virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info); + + if (replug) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.s= ubsys.u.usb; + usbsrc->bus =3D 0; + usbsrc->device =3D 0; + } + } + if (!replug) + virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info); } VIR_FREE(devstr); return ret; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028859; cv=none; d=zoho.com; s=zohoarc; b=Kp6aAb/pgX209/9kwMjnnljQVCf+T2wLGMyAtwE9EQ8Ntu7qTLEaygmkMfGpdnYhr69DWGDqb4t1p6M0XSiesuVrjBJkhJSEojC5ljCdk4fOTFJFbDJmDsHkH9YT4T8daUw43n6BLYEnIRD+xL2IKesLtDKW/SaSOvfCyLZIKbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028859; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=rkjfBRPkb8GqlbOdROP8iYE1JAlfLlAWqapR5F6L3Lk=; b=cGwo/e5gusvJsCjTjvVnCFhbaVHdrn6cRFJ7rPtfajEXLcOj6TG9AVdfiGH6EH6wtzAXoYsstjeY21WGjwO/K1cVCoh+AtbImQC2cmLDlkVtKQzuAmimr3j2DPyQQZEhZUayv6Fi7w1tw11yYlD5/oku89ibH8+4hS9SJWoF9+M= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028859692547.3223114970486; Mon, 9 Sep 2019 04:34:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7455814E2; Mon, 9 Sep 2019 11:34:17 +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 B97615C21E; Mon, 9 Sep 2019 11:34:17 +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 61C0F1802216; Mon, 9 Sep 2019 11:34:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXre6013749 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAC3C5D6C8; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1B23546EE for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A001081F11 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvX-0002RT-Nb; Mon, 09 Sep 2019 14:33:47 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:07 +0300 Message-Id: <20190909113314.22362-5-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 04/11] qemu: handle host usb device add/del udev events 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Mon, 09 Sep 2019 11:34:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now when code handling attaching/detaching usb hostdev is appropriately changed use it to handle host usb device udev add/del events. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/Makefile.inc.am | 2 + src/qemu/qemu_conf.h | 3 + src/qemu/qemu_domain.c | 2 + src/qemu/qemu_domain.h | 2 + src/qemu/qemu_driver.c | 351 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 359 insertions(+), 1 deletion(-) diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index d16b315ebc..8be0dee396 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -85,6 +85,7 @@ libvirt_driver_qemu_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(srcdir)/secret \ $(AM_CFLAGS) \ + $(UDEV_CFLAGS) \ $(NULL) libvirt_driver_qemu_impl_la_LDFLAGS =3D $(AM_LDFLAGS) libvirt_driver_qemu_impl_la_LIBADD =3D \ @@ -93,6 +94,7 @@ libvirt_driver_qemu_impl_la_LIBADD =3D \ $(LIBNL_LIBS) \ $(SELINUX_LIBS) \ $(LIBXML_LIBS) \ + $(UDEV_LIBS) \ $(NULL) libvirt_driver_qemu_impl_la_SOURCES =3D $(QEMU_DRIVER_SOURCES) =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 0cbddd7a9c..2e50bb0950 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -294,6 +294,9 @@ struct _virQEMUDriver { =20 /* Immutable pointer, self-locking APIs */ virHashAtomicPtr migrationErrors; + + struct udev_monitor *udev_monitor; + int udev_watch; }; =20 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 657f3ecfe4..4784804d1e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15034,6 +15034,8 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_SERIAL_CHANGED: case QEMU_PROCESS_EVENT_BLOCK_JOB: case QEMU_PROCESS_EVENT_MONITOR_EOF: + case QEMU_PROCESS_EVENT_USB_REMOVED: + case QEMU_PROCESS_EVENT_USB_ADDED: VIR_FREE(event->data); break; case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index d097f23342..94aea62693 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -521,6 +521,8 @@ typedef enum { QEMU_PROCESS_EVENT_MONITOR_EOF, QEMU_PROCESS_EVENT_PR_DISCONNECT, QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED, + QEMU_PROCESS_EVENT_USB_REMOVED, + QEMU_PROCESS_EVENT_USB_ADDED, =20 QEMU_PROCESS_EVENT_LAST } qemuProcessEventType; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2378a2e7d0..ce41b0a8d9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 =20 #include "qemu_driver.h" @@ -719,6 +720,254 @@ qemuDomainFindMaxID(virDomainObjPtr vm, } =20 =20 +struct qemuUdevUSBRemoveData { + unsigned int bus; + unsigned int device; +}; + +struct qemuUdevUSBAddData { + unsigned int vendor; + unsigned int product; +}; + +struct qemuUdevUSBEventData { + union { + struct qemuUdevUSBRemoveData remove; + struct qemuUdevUSBAddData add; + } data; + bool found; + bool remove; +}; + +static int +qemuUdevUSBHandleEvent(virDomainObjPtr vm, void *opaque) +{ + struct qemuUdevUSBEventData *data =3D opaque; + struct qemuProcessEvent *event =3D NULL; + size_t i; + + if (data->found) + return 0; + + virObjectLock(vm); + + if (!virDomainObjIsActive(vm)) + goto cleanup; + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev =3D vm->def->hostdevs[i]; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + if (data->remove) { + if (usbsrc->bus !=3D data->data.remove.bus || + usbsrc->device !=3D data->data.remove.device) + continue; + } else { + if (usbsrc->vendor !=3D data->data.add.vendor || + usbsrc->product !=3D data->data.add.product) + continue; + } + + data->found =3D true; + + if (VIR_ALLOC(event) < 0) + goto cleanup; + + if (data->remove) { + struct qemuUdevUSBRemoveData *rm_data; + + + if (VIR_ALLOC(rm_data) < 0) + goto cleanup; + + *rm_data =3D data->data.remove; + event->data =3D rm_data; + event->eventType =3D QEMU_PROCESS_EVENT_USB_REMOVED; + } else { + struct qemuUdevUSBAddData *add_data; + + if (VIR_ALLOC(add_data) < 0) + goto cleanup; + + *add_data =3D data->data.add; + event->data =3D add_data; + event->eventType =3D QEMU_PROCESS_EVENT_USB_ADDED; + } + + event->vm =3D virObjectRef(vm); + + if (virThreadPoolSendJob(qemu_driver->workerPool, 0, event) < 0) { + virObjectUnref(vm); + goto cleanup; + } + + event =3D NULL; + + break; + } + + cleanup: + virObjectUnlock(vm); + + qemuProcessEventFree(event); + + return 0; +} + + +static void +qemuUdevEventHandleCallback(int watch ATTRIBUTE_UNUSED, + int fd ATTRIBUTE_UNUSED, + int events ATTRIBUTE_UNUSED, + void *data ATTRIBUTE_UNUSED) +{ + struct qemuUdevUSBEventData event_data; + struct udev_device *dev =3D NULL; + const char *action; + const char *devtype; + const char *tmp; + + /* libvirtd daemon do not run event loop before full state drivers + * initialization. Also state drivers uninitialized only after + * full stop of event loop. In short driver initialization/uninitializ= ation + * and handling events occurs in same main loop thread. Thus we + * don't need any locking here. */ + + if (!(dev =3D udev_monitor_receive_device(qemu_driver->udev_monitor)))= { + VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR + if (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK) { + VIR_WARNINGS_RESET + return; + } + + virReportSystemError(errno, "%s", + _("failed to receive device from udev monitor= ")); + return; + } + + devtype =3D udev_device_get_devtype(dev); + + if (STRNEQ_NULLABLE(devtype, "usb_device")) + goto cleanup; + + if (!(action =3D udev_device_get_action(dev))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive action from udev monitor")); + goto cleanup; + } + + if (STREQ(action, "remove")) { + struct qemuUdevUSBRemoveData *rm_data =3D &event_data.data.remove; + + if (!(tmp =3D udev_device_get_property_value(dev, "BUSNUM"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive busnum from udev monitor")= ); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 10, &rm_data->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert busnum to int")); + goto cleanup; + } + + if (!(tmp =3D udev_device_get_property_value(dev, "DEVNUM"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive devnum from udev monitor")= ); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 10, &rm_data->device) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert devnum to int")); + goto cleanup; + } + event_data.remove =3D true; + } else if (STREQ(action, "add")) { + struct qemuUdevUSBAddData *add_data =3D &event_data.data.add; + + if (!(tmp =3D udev_device_get_property_value(dev, "ID_VENDOR_ID"))= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive vendor from udev monitor")= ); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 16, &add_data->vendor) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert vendor to int")); + goto cleanup; + } + + if (!(tmp =3D udev_device_get_property_value(dev, "ID_MODEL_ID")))= { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive product from udev monitor"= )); + goto cleanup; + } + if (virStrToLong_ui(tmp, NULL, 16, &add_data->product) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to convert product to int")); + goto cleanup; + } + event_data.remove =3D false; + } + + event_data.found =3D false; + virDomainObjListForEach(qemu_driver->domains, qemuUdevUSBHandleEvent, = &event_data); + + cleanup: + udev_device_unref(dev); +} + + +static int +qemuUdevInitialize(void) +{ + struct udev *udev; + + if (!(udev =3D udev_new())) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to create udev context")); + return -1; + } + + if (!(qemu_driver->udev_monitor =3D udev_monitor_new_from_netlink(udev= , "udev"))) { + udev_unref(udev); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("udev_monitor_new_from_netlink returned NULL")); + return -1; + } + + udev_monitor_enable_receiving(qemu_driver->udev_monitor); + + qemu_driver->udev_watch =3D virEventAddHandle(udev_monitor_get_fd(qemu= _driver->udev_monitor), + VIR_EVENT_HANDLE_READABLE, + qemuUdevEventHandleCallbac= k, NULL, NULL); + + if (qemu_driver->udev_watch < 0) + return -1; + + return 0; +} + + +static void +qemuUdevCleanup(void) +{ + if (qemu_driver->udev_monitor) { + struct udev *udev =3D udev_monitor_get_udev(qemu_driver->udev_moni= tor); + + udev_monitor_unref(qemu_driver->udev_monitor); + udev_unref(udev); + qemu_driver->udev_monitor =3D NULL; + } + + if (qemu_driver->udev_watch > 0) { + virEventRemoveHandle(qemu_driver->udev_watch); + qemu_driver->udev_watch =3D 0; + } +} + + /** * qemuStateInitialize: * @@ -1030,6 +1279,9 @@ qemuStateInitialize(bool privileged, if (!(qemu_driver->closeCallbacks =3D virCloseCallbacksNew())) goto error; =20 + if (qemuUdevInitialize() < 0) + goto error; + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(qemu_driver->domains, cfg->stateDir, @@ -1239,6 +1491,8 @@ qemuStateCleanup(void) =20 virLockManagerPluginUnref(qemu_driver->lockManager); =20 + qemuUdevCleanup(); + virMutexDestroy(&qemu_driver->lock); VIR_FREE(qemu_driver); =20 @@ -5011,7 +5265,96 @@ processRdmaGidStatusChangedEvent(virDomainObjPtr vm, } =20 =20 -static void qemuProcessEventHandler(void *data, void *opaque) +static void +processUSBAddedEvent(virQEMUDriverPtr driver, + virDomainObjPtr vm, + struct qemuUdevUSBAddData *data) +{ + virDomainHostdevDefPtr hostdev; + virDomainHostdevSubsysUSBPtr usbsrc; + size_t i; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto cleanup; + } + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + hostdev =3D vm->def->hostdevs[i]; + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + usbsrc =3D &hostdev->source.subsys.u.usb; + + if (usbsrc->vendor =3D=3D data->vendor && usbsrc->product =3D=3D d= ata->product) + break; + } + + if (i =3D=3D vm->def->nhostdevs) + goto cleanup; + + if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) + goto cleanup; + + cleanup: + qemuDomainObjEndJob(driver, vm); +} + + +static void +processUSBRemovedEvent(virQEMUDriverPtr driver, + virDomainObjPtr vm, + struct qemuUdevUSBRemoveData *data) +{ + size_t i; + virDomainHostdevDefPtr hostdev; + virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_HOSTDEV }; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto cleanup; + } + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevSubsysUSBPtr usbsrc; + + hostdev =3D vm->def->hostdevs[i]; + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + usbsrc =3D &hostdev->source.subsys.u.usb; + + /* don't mess with devices that don't use stable host addressing + * with respect to unplug/plug to host + */ + if (!usbsrc->vendor || !usbsrc->product) + continue; + + if (usbsrc->bus =3D=3D data->bus && usbsrc->device =3D=3D data->de= vice) + break; + } + + if (i =3D=3D vm->def->nhostdevs) + goto cleanup; + + dev.data.hostdev =3D hostdev; + if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 0) + goto cleanup; + + cleanup: + qemuDomainObjEndJob(driver, vm); +} + + +static void +qemuProcessEventHandler(void *data, void *opaque) { struct qemuProcessEvent *processEvent =3D data; virDomainObjPtr vm =3D processEvent->vm; @@ -5057,6 +5400,12 @@ static void qemuProcessEventHandler(void *data, void= *opaque) case QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED: processRdmaGidStatusChangedEvent(vm, processEvent->data); break; + case QEMU_PROCESS_EVENT_USB_REMOVED: + processUSBRemovedEvent(driver, vm, processEvent->data); + break; + case QEMU_PROCESS_EVENT_USB_ADDED: + processUSBAddedEvent(driver, vm, processEvent->data); + break; case QEMU_PROCESS_EVENT_LAST: break; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028855; cv=none; d=zoho.com; s=zohoarc; b=jq1FSz1iI6nIvZYt/ZosmIDzU8qVS4aDGQE6YOalU0plqGbVUVPObkswKoeWlWLSJ7oJM+is52d+qmy66oR9m8h7xNhJRFwMwYzAe8ZD8h49b6O6BsBtKZAP8gyWIUuW/Sl7Ob4QUduej6Culknc7SRg+JvAdo/sMTiib661pH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028855; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4G23c2rifigGsH0yBdSasAqelWodcefrJKwmdlbjj9k=; b=aC1xipVYcymIg8q0v/arc9k1DtzywoAnZjQbhd8UHq981mp/tMbsCXuYyOdfRCnpjuxUaLsXjQWgCZtkn9eXFKgeC+oteXYKbX0gwlmVkuUstCnx12N06xUrvQwYuv6NRmoEE1zc5H55/AdC3anjQqAzhXjmO7IvAmfyEDsNa+Y= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028855997867.3677167924099; Mon, 9 Sep 2019 04:34:15 -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 0F5DA30860D7; Mon, 9 Sep 2019 11:34:14 +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 DFD5B100195F; Mon, 9 Sep 2019 11:34:13 +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 9F4B424E68; Mon, 9 Sep 2019 11:34:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrPA013748 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id B51EC54527; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx24.extmail.prod.ext.phx2.redhat.com [10.5.110.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE8815D6C8 for ; Mon, 9 Sep 2019 11:33:52 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD96510CC219 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvX-0002RT-Sn; Mon, 09 Sep 2019 14:33:47 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:08 +0300 Message-Id: <20190909113314.22362-6-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.65 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 05/11] qemu: handle libvirtd restart after host usb device unplug 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-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.44]); Mon, 09 Sep 2019 11:34:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It is possible for libvirtd to go down before DEVICE_DELETED event is delivered upon usb hostdev unplug and to receive the event after the libvirtd is up. In order to handle this case we need to save usb hostdev deleteAction is status file. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 26 ++++++++++++++++++++++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_driver.c | 20 ++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b7a342bb91..c200af050c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1236,6 +1236,13 @@ VIR_ENUM_IMPL(virDomainShmemModel, "ivshmem-doorbell", ); =20 +VIR_ENUM_IMPL(virDomainHostdevDeleteAction, + VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST, + "none", + "delete", + "unplug" +); + VIR_ENUM_IMPL(virDomainLaunchSecurity, VIR_DOMAIN_LAUNCH_SECURITY_LAST, "", @@ -7533,6 +7540,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; VIR_AUTOFREE(char *) startupPolicy =3D NULL; VIR_AUTOFREE(char *) autoAddress =3D NULL; + VIR_AUTOFREE(char *) deleteAction =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7550,6 +7558,18 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, usbsrc->autoAddress =3D true; } =20 + if ((deleteAction =3D virXMLPropString(node, "deleteAction"))) { + def->deleteAction =3D + virDomainHostdevDeleteActionTypeFromString(deleteAction); + + if (def->deleteAction <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unknown deleteAction '%s'"), + deleteAction); + goto out; + } + } + /* Product can validly be 0, so we need some extra help to determine * if it is uninitialized*/ got_product =3D false; @@ -24905,6 +24925,12 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, =20 if (def->missing && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) virBufferAddLit(buf, " missing=3D'yes'"); + + if (def->deleteAction && (flags & VIR_DOMAIN_DEF_FORMAT_STATUS)) { + const char *deleteAction; + deleteAction =3D virDomainHostdevDeleteActionTypeToString(def-= >deleteAction); + virBufferAsprintf(buf, " deleteAction=3D'%s'", deleteAction); + } } =20 if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI= && diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 19a5b21462..df88790ac0 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -338,6 +338,7 @@ typedef enum { =20 VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST } virDomainHostdevDeleteActionType; +VIR_ENUM_DECL(virDomainHostdevDeleteAction); =20 =20 /* basic device for direct passthrough */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce41b0a8d9..f1802b5d44 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5272,10 +5272,13 @@ processUSBAddedEvent(virQEMUDriverPtr driver, { virDomainHostdevDefPtr hostdev; virDomainHostdevSubsysUSBPtr usbsrc; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); size_t i; =20 - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { + virObjectUnref(cfg); return; + } =20 if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain is not running"); @@ -5300,8 +5303,13 @@ processUSBAddedEvent(virQEMUDriverPtr driver, if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) goto cleanup; =20 + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->cap= s) < 0) + VIR_WARN("unable to save domain status after plugging device %s", + hostdev->info->alias); + cleanup: qemuDomainObjEndJob(driver, vm); + virObjectUnref(cfg); } =20 =20 @@ -5313,9 +5321,12 @@ processUSBRemovedEvent(virQEMUDriverPtr driver, size_t i; virDomainHostdevDefPtr hostdev; virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_HOSTDEV }; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); =20 - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { + virObjectUnref(cfg); return; + } =20 if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain is not running"); @@ -5348,8 +5359,13 @@ processUSBRemovedEvent(virQEMUDriverPtr driver, if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 0) goto cleanup; =20 + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->cap= s) < 0) + VIR_WARN("unable to save domain status after unplugging device %s", + hostdev->info->alias); + cleanup: qemuDomainObjEndJob(driver, vm); + virObjectUnref(cfg); } =20 =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028894; cv=none; d=zoho.com; s=zohoarc; b=WUF3URFQscuSU8VElWCKwJPf6E84o33D1kvAeDrx+maGFWxRBuYhrER1knZztS1ibzCX42xV9PntFSjuNERhNNR/g0a/ij6ujzVhhEGCFz8h9avEcCHfspyEuumd0GpdAoIJi47CPaL0BPEdL4e366E8RRzqPKuGqpx4hKPXIMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028894; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zqBvYvuHXuJtdpVxHJF2hVT0kac54+pGwqeg1fPfBYU=; b=gzF+A1Juu/Z+R/qx8bfZJ0tkQZG4NxsPkxrzOFGqGVo3Lq9ScNn+hQ4V1v4oPUONtl8jrSUVTdrJASoP/QH1rsORbMyhNubSegB4ep/oDlpzoVuuZxQ14OWSsqWyyZ8hfRqf0P2ltZrICf9UOKsOFnM1tE1OMFnmKWmc4A4vUBw= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15680288943211014.726752048536; Mon, 9 Sep 2019 04:34:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5C7319B114E; Mon, 9 Sep 2019 11:34:52 +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 8077960624; Mon, 9 Sep 2019 11:34:52 +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 36DB0180BA99; Mon, 9 Sep 2019 11:34:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXtnq013776 for ; Mon, 9 Sep 2019 07:33:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC8A16013A; Mon, 9 Sep 2019 11:33:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx23.extmail.prod.ext.phx2.redhat.com [10.5.110.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D670C6012C for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB1D510A8134 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvY-0002RT-01; Mon, 09 Sep 2019 14:33:48 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:09 +0300 Message-Id: <20190909113314.22362-7-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.64 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 06/11] qemu: handle race on device deletion and usb host device plugging 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Mon, 09 Sep 2019 11:34:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Imagine host usb device is unplugged from host and as a result we send command to qemu to delete appropriate device. Then before qemu device is deleted host usb device is plugged back. Currenly code supposes there is no remnant device in qemu and will try to add new device and the attempt will fail. Instead let's check the device is not yet deleted and postpone adding qemu device to device_deleted event handler. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f1802b5d44..21640e49c7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4671,6 +4671,44 @@ processGuestPanicEvent(virQEMUDriverPtr driver, } =20 =20 +static int +qemuCheckHostdevPlugged(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *devAlias) +{ + virDomainHostdevDefPtr hostdev; + virDomainHostdevSubsysUSBPtr usbsrc; + virDomainDeviceDef dev; + int num; + + if (virDomainDefFindDevice(vm->def, devAlias, &dev, false) < 0) + return 0; + + if (dev.type !=3D VIR_DOMAIN_DEVICE_HOSTDEV) + return 0; + + hostdev =3D dev.data.hostdev; + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_US= B) + return 0; + + usbsrc =3D &hostdev->source.subsys.u.usb; + if (!usbsrc->vendor || !usbsrc->product) + return 0; + + if ((num =3D virUSBDeviceFindByVendor(usbsrc->vendor, usbsrc->product, + NULL, false, NULL)) < 0) + return -1; + + if (num =3D=3D 0) + return 0; + + if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) + return -1; + + return 0; +} + + static void processDeviceDeletedEvent(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -4698,6 +4736,11 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, =20 if (qemuDomainRemoveDevice(driver, vm, &dev) < 0) goto endjob; + + /* Fall thru and save status file even on error condition because + * device is removed successfully and changed configuration need + * to be saved in status file. */ + qemuCheckHostdevPlugged(driver, vm, devAlias); } =20 if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->cap= s) < 0) @@ -5300,6 +5343,12 @@ processUSBAddedEvent(virQEMUDriverPtr driver, if (i =3D=3D vm->def->nhostdevs) goto cleanup; =20 + /* if device is not yet even deleted from qemu then handle plugging la= ter. + * Or we failed handling host usb device unplugging, then another atte= mpt of + * unplug/plug could help. */ + if (usbsrc->bus || usbsrc->device) + goto cleanup; + if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) goto cleanup; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028837; cv=none; d=zoho.com; s=zohoarc; b=eGmkBOjnpHGdDKPoykkbRrJotDr6MDiD+c4b45qroGl2oP7sXNmvabjGZvStvq5icfU2FklTPDbsNcY5wcJeQ04IwFQkyP7tjPz5dHo7v9Dk6aUO3xPPKPfP5hGjGhTb9sKA6lLFyibZxMN+1RbtaIOuXc5MBvKTHGI//VWugcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028837; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GOB2RIjH3xJizUSHSpy9tIfXfn8iatV9JyTpYr/D6Sc=; b=Bg1mJ6krXk4SZAvRNI9fYq+mB7MTlPxTOgQKNEa3PE9eyRZsqyTXKrAEu7e8a7Ll6AX6UbvIWkZaJhahcOtxS5QjtOteYSIZ+jQer90Rs6CJgNFVibgiifc/W7Y+ipm5AgZ1uPkLbml+9keST3kvBh532sYG0X1vA9ST1QvXHQU= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028837110224.27162852796084; Mon, 9 Sep 2019 04:33:57 -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 4DF0B3091761; Mon, 9 Sep 2019 11:33:55 +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 29D3310018FF; Mon, 9 Sep 2019 11:33:55 +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 D9516180B536; Mon, 9 Sep 2019 11:33:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrTH013712 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 597B960F88; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx29.extmail.prod.ext.phx2.redhat.com [10.5.110.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 503C860C63 for ; Mon, 9 Sep 2019 11:33:50 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B26F21918644 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvY-0002RT-4a; Mon, 09 Sep 2019 14:33:48 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:10 +0300 Message-Id: <20190909113314.22362-8-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.70 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 07/11] qemu: hotplug: update device list on device deleted event 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-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.41]); Mon, 09 Sep 2019 11:33:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" I guess this is the missing piece for [1]. It did not hurt before (like we didn't even see any errors/warns in logs) because in qemuProcessUpdateDevices function virDomainDefFindDevice does not find device deleted from libvirt config. But now in case of unpluggind usb device from host we leave device in config and thus needlessly try to call qemuDomainRemoveDevice second time. [1] 0dfb8a1b9: qemu: Unplug devices that disappeared when libvirtd was down Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_driver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 21640e49c7..b646642c99 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4731,6 +4731,9 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver, if (STRPREFIX(devAlias, "vcpu")) { qemuDomainRemoveVcpuAlias(driver, vm, devAlias); } else { + if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < = 0) + goto cleanup; + if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) < 0) goto endjob; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028852; cv=none; d=zoho.com; s=zohoarc; b=btrwnOi8Htms+oIkTEj3crovXsbPPRWfzQs0ROpSjKncuBrEvK69ygH9ZJ3rrNEqN/PAKy8up7aWNIQrogM5hVJ6NoQHyk2XOT39UMq51u6eqoY96tyXpO1QJ/HJ+0opQCUhvZL7HL5smzJ+fCW/k2+JAN0uGxv35jHql1AHA/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028852; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=K4M7P2DWp6AiJd80qgrL3XBHX+0eFZC7276MOwfzMfE=; b=d/ny5ADXisAid4LJiq1zhnBbqesa4bWhmU7tjIpmZ+/rA7JlklFo/9hJGVrQQ7uYSQ0nRTsis8ArUNiLN6Ynom98gPUn8uG65tm71sOVd+tJTdx0xzjGRG7SKDtQZKPjUbDTCOdVVdfrokz8lj47SvAPfITUKBJkMFmxR/qfKGA= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028852114288.3169968994398; Mon, 9 Sep 2019 04:34:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86C4610F2E8C; Mon, 9 Sep 2019 11:34:10 +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 5A8D46012D; Mon, 9 Sep 2019 11:34:10 +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 02D2124F37; Mon, 9 Sep 2019 11:34:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrEp013718 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 74C575C21A; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F4AB5C21E for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1C5AC08EC24 for ; Mon, 9 Sep 2019 11:33:49 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvY-0002RT-At; Mon, 09 Sep 2019 14:33:48 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:11 +0300 Message-Id: <20190909113314.22362-9-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 08/11] qemu: handle host usb device plug/unplug when libvirtd is down 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Mon, 09 Sep 2019 11:34:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Somebody can easily unplug usb device from host while libvirtd is being stopped. Also usb device can be plugged or unplugged/plugged back and so forth. Let's handle such cases. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_process.c | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c9921646e9..8bec36fe2c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3749,6 +3749,58 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver, return ret; } =20 + +static int +qemuProcessReattachUSBDevices(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + size_t i; + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev =3D vm->def->hostdevs[i]; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + /* don't mess with devices that don't use stable host addressing + * with respect to unplug/plug to host + */ + if (!usbsrc->vendor || !usbsrc->product) + continue; + + if (!usbsrc->bus && !usbsrc->device) { + int num; + + if ((num =3D virUSBDeviceFindByVendor(usbsrc->vendor, usbsrc->= product, + NULL, false, NULL)) < 0) + return -1; + + if (num > 0 && + qemuDomainAttachHostDevice(driver, vm, hostdev) < 0) + return -1; + } else { + virUSBDevicePtr usb; + + if (virUSBDeviceFindByBus(usbsrc->bus, usbsrc->device, + NULL, false, &usb) < 0) + return -1; + + if (!usb) { + virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_H= OSTDEV }; + + dev.data.hostdev =3D hostdev; + if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, tru= e) < 0) + return -1; + } + virUSBDeviceFree(usb); + } + } + + return 0; +} + + static int qemuDomainPerfRestart(virDomainObjPtr vm) { @@ -8206,6 +8258,9 @@ qemuProcessReconnect(void *opaque) if (qemuProcessUpdateDevices(driver, obj) < 0) goto error; =20 + if (qemuProcessReattachUSBDevices(driver, obj) < 0) + goto error; + if (qemuRefreshPRManagerState(driver, obj) < 0) goto error; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028845; cv=none; d=zoho.com; s=zohoarc; b=XOOa1rFj4b8jUHEyb5vajbcpf6uuuXEJYi9S65amkAPg/0/mgGHQyK+vXxLI0Km5osvo8aMEN53OPM3ou4F9ADKMlrLVYvu55Q2IQXa8soOYBcNMESOFRxO7rfn5VncTJ1cCoWhYBWxTn/tBM9CRiKlnphfdRaSR1O3PF+zzfhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028845; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Jab2+jYdWNlPt/+6tKb3X3XSqWByx8tswL3Aom0tjl4=; b=P41szfkOrNSF2zKHBQwvERmIqzw9EZMHB6ldHz8I2ScaHhxijuLXHGPCahBEZLtbYC6S0EJIJmsfIRC0LcflaaKI5LgnTOhLrWgDKSg7UwvwfRbkDqPrQqJw5+dQspXAJx50V+jTp/EWU7E7tA99NQo5Y3fNW2Xtwtx4Rbdwyog= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028845466333.46240811991856; Mon, 9 Sep 2019 04:34:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAA7118C428B; Mon, 9 Sep 2019 11:34:02 +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 96B616012A; Mon, 9 Sep 2019 11:34:02 +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 4E61C24F33; Mon, 9 Sep 2019 11:34:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXr70013726 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 877E46012E; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EE4D6017E for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A37A2F366E for ; Mon, 9 Sep 2019 11:33:50 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvY-0002RT-Ew; Mon, 09 Sep 2019 14:33:48 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:12 +0300 Message-Id: <20190909113314.22362-10-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 09/11] qemu: don't mess with non mandatory hostdevs on reattaching 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Mon, 09 Sep 2019 11:34:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" First I don't want to add code to handle dummy device that is used when host usb device is not present at the moment of starting/migrating etc. Second supporting non mandatory policies would require to handle races when host usb device is plugged to host and libvirtd starts adding device but if in the meanwhile host usb device it unplugged back then current code will use dummy device which is not desired in this case. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 8 ++++++++ src/qemu/qemu_process.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b646642c99..fe5fd94ac5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5337,6 +5337,10 @@ processUSBAddedEvent(virQEMUDriverPtr driver, if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) continue; =20 + if (hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_OPTION= AL || + hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUIS= ITE) + continue; + usbsrc =3D &hostdev->source.subsys.u.usb; =20 if (usbsrc->vendor =3D=3D data->vendor && usbsrc->product =3D=3D d= ata->product) @@ -5392,6 +5396,10 @@ processUSBRemovedEvent(virQEMUDriverPtr driver, if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) continue; =20 + if (hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_OPTION= AL || + hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUIS= ITE) + continue; + usbsrc =3D &hostdev->source.subsys.u.usb; =20 /* don't mess with devices that don't use stable host addressing diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8bec36fe2c..d87fb637ac 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3769,6 +3769,10 @@ qemuProcessReattachUSBDevices(virQEMUDriverPtr drive= r, if (!usbsrc->vendor || !usbsrc->product) continue; =20 + if (hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_OPTION= AL || + hostdev->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUIS= ITE) + continue; + if (!usbsrc->bus && !usbsrc->device) { int num; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028840; cv=none; d=zoho.com; s=zohoarc; b=EKLQg3PdzgyLoKWfsKCp5zQ9NEiIx4/eoTsHyK5iLlNFSc/p9H9Q0r93v7wg1Xocn+Wm+TEuHjLFfBXM/vQiRTF9PQ5vrpDKC5Sff1hMIW1VhpByL7szWg/G9pv+bjVY50Q3ziTziVvNMSdaTdemTfV1Xn8V7diklj/urEV3Jv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028840; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QaQsSzn8hvjP1VS6JBu/lVqYRKtrwDnb9kXI99muogk=; b=QKSpupZwj13nh5uRPd/kqt45YK2TIPIBaD/L8oUG8UAMoY/doY2vcqNdkqfKndhUJONdPlQyb/8m9z6vBuitg9lY8w6sj3qSyGY8H6g7ZgeDUX/ku8/d43KF5Fs/XgJ1xTwIWfhrTyxp1hsopa0fBPLu9i9ewXDujBxQHY0wQ9w= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028840888292.99438307734624; Mon, 9 Sep 2019 04:34:00 -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 124847F748; Mon, 9 Sep 2019 11:33:59 +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 DF37010018F9; Mon, 9 Sep 2019 11:33:58 +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 9C498180B536; Mon, 9 Sep 2019 11:33:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXrOq013750 for ; Mon, 9 Sep 2019 07:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA8835D6B2; Mon, 9 Sep 2019 11:33:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B119C5B6A5 for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B08B30C0624 for ; Mon, 9 Sep 2019 11:33:50 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvY-0002RT-Kq; Mon, 09 Sep 2019 14:33:48 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:13 +0300 Message-Id: <20190909113314.22362-11-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 10/11] qemu: handle detaching of unplugged hostdev 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-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.6.2 (mx1.redhat.com [10.5.110.71]); Mon, 09 Sep 2019 11:33:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If hostdev is unplugged we don't need to delete it's correspondent device from qemu etc. Just remove it from config immediately. Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_hotplug.c | 16 +++++++++++++++- src/util/virhostdev.c | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ea82cb54ef..cd1c1216fa 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4429,6 +4429,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, char *objAlias =3D NULL; bool is_vfio =3D false; bool unplug =3D hostdev->deleteAction =3D=3D VIR_DOMAIN_HOSTDEV_DELETE= _ACTION_UNPLUG; + bool unplugged =3D false; =20 VIR_DEBUG("Removing host device %s from domain %p %s", hostdev->info->alias, vm, vm->def->name); @@ -4486,13 +4487,17 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, =20 virDomainAuditHostdev(vm, hostdev, "detach", true); =20 + if (hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= USB) { + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + unplugged =3D !usbsrc->bus && !usbsrc->device; + } /* * In case of unplug the attempt to restore label will fail. But we do= n't * need to restore the label! In case of separate mount namespace for = the * domain we remove device file later in this function. In case of glo= bal * mount namespace the device file is deleted or being deleted by syst= emd. */ - if (!is_vfio && !unplug && + if (!is_vfio && !unplug && !unplugged && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 @@ -5829,6 +5834,15 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, unplug) < 0) { return -1; } + if (!unplug) { + virDomainHostdevDefPtr hostdev =3D detach.data.hostdev; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsy= s.u.usb; + + if (hostdev->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_OPTI= ONAL && + hostdev->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_REQU= ISITE && + usbsrc->device =3D=3D 0 && usbsrc->bus =3D=3D 0) + return qemuDomainRemoveDevice(driver, vm, &detach); + } break; case VIR_DOMAIN_DEVICE_RNG: if (qemuDomainDetachPrepRNG(vm, match->data.rng, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index d710193b94..90e4d2fb45 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1794,6 +1794,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, continue; if (hostdev->missing) continue; + if (!usbsrc->bus && !usbsrc->device) + continue; =20 if (!(usb =3D virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL)))= { VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s= ", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 06:37:27 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1568028945; cv=none; d=zoho.com; s=zohoarc; b=JYdW+jApETMrAVzyAp8eXV50FYWflewHL71Xydo8E7lWL2whsrdO28WZl3mijPnPYt29NydZnUebUfC2uxj530g7KQ7QaRZ0cDPLLpefdDOdFV8BKfpSmhCREM0iXwp8QpVeuTinH52G1Hrf6GFDdM+unZETvOg1GCMYo3RC8SY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568028945; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=RGUIao1t86GUZ8MkkvSXkwBqLMcGzHQ/Zun76gKfGgw=; b=cACdHf1ae9U8WW24ib4mmGGgofMSdCBFiqweSLEeqycCyv1jQ5EhgtIX9CLnwbaUxk9hCNaoecoYqGz0P21YjQWQHyMVCVKdE71W09T479obC+uHBafoUq2Svd4Kc4xLvXyPrCudFXjEwtzoSuDVdzne+6y8mTwyS9ajwfjivgI= ARC-Authentication-Results: i=1; mx.zoho.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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568028945540956.6172520398524; Mon, 9 Sep 2019 04:35:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB8393C928; Mon, 9 Sep 2019 11:35:43 +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 B4AB05C1D8; Mon, 9 Sep 2019 11:35: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 73C2E247BB; Mon, 9 Sep 2019 11:35:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89BXsUw013763 for ; Mon, 9 Sep 2019 07:33:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 261CD5DA8D; Mon, 9 Sep 2019 11:33:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 213255DA5B for ; Mon, 9 Sep 2019 11:33:51 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5921B309BF02 for ; Mon, 9 Sep 2019 11:33:50 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i7HvY-0002RT-PA; Mon, 09 Sep 2019 14:33:48 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 14:33:14 +0300 Message-Id: <20190909113314.22362-12-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> References: <20190909113314.22362-1-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 09 Sep 2019 11:33:50 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0 (SPF_HELO_NONE, SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 11/11] conf: parse hostdev missing flag 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 09 Sep 2019 11:35:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We want to keep this flag across libvirtd restarts. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c200af050c..862ca4bd3a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7541,6 +7541,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, VIR_AUTOFREE(char *) startupPolicy =3D NULL; VIR_AUTOFREE(char *) autoAddress =3D NULL; VIR_AUTOFREE(char *) deleteAction =3D NULL; + VIR_AUTOFREE(char *) missing =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7570,6 +7571,11 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, } } =20 + if ((missing =3D virXMLPropString(node, "missing"))) { + if (STREQ(missing, "yes")) + def->missing =3D true; + } + /* Product can validly be 0, so we need some extra help to determine * if it is uninitialized*/ got_product =3D false; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list