From nobody Sat Feb 7 09:29:33 2026 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=1567166965; cv=none; d=zoho.com; s=zohoarc; b=eRM8pH4Cf8wwz00NErVxiyvkOCS4fO2mxmV5qdHh5O9as/0lsXpXxfUBmDl25Hct7Bv1gKVmiHOeawFIzD1UQu6wJavDgX99J64VwGulDhLWmN8bLErgIB4f1jWiZAX4lDkvQL7ymS8USaRQIy887wdtOgnhKg0KBL8ULLas+/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567166965; h=Content-Type:Content-Transfer-Encoding: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=4+XeZvslMD1ggyESovsHG60TC9euMVeqIBehxrrmG5o=; b=Z+pruoFMnSGGtxUb69B735VfHmvHL6g693Z1mueKnvht26Gf5xIvLB7sXeDrJUlhzTPW5GhsmuHQ9+eO1nvB9Orh83/UC/+NkziZOMoJT4vayNqqy0mumSJzJhH9Koa0Fto72kIMwS4QHDwPie9Yj5TOUs0+OGTrpmQShJMlRlE= 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 1567166965428815.6793787574393; Fri, 30 Aug 2019 05:09:25 -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 3EEDD30860C7; Fri, 30 Aug 2019 12:09:24 +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 17E2960610; Fri, 30 Aug 2019 12:09:24 +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 C81BA180BA9C; Fri, 30 Aug 2019 12:09:23 +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 x7UC9BxI018351 for ; Fri, 30 Aug 2019 08:09:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFD925C221; Fri, 30 Aug 2019 12:09:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAFEB5C1D6 for ; Fri, 30 Aug 2019 12:09:06 +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 F026B3086218 for ; Fri, 30 Aug 2019 12:09:05 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1i3fiC-0000GK-7D for libvir-list@redhat.com; Fri, 30 Aug 2019 15:09:04 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 30 Aug 2019 15:08:34 +0300 Message-Id: <20190830120834.27404-7-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190830120834.27404-1-nshirokovskiy@virtuozzo.com> References: <20190830120834.27404-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.42]); Fri, 30 Aug 2019 12:09:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 30 Aug 2019 12:09:06 +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.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/6] qemu: handle hostdev add/del 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 30 Aug 2019 12:09:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Somebody can easily detach hostdev on node while libvirtd is being stopped. Also hostdev can be attached or detached and attached back and so forth. Let's handle such cases. Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_process.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5cb97de4f3..f70f0ae251 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3747,6 +3747,52 @@ 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++) { + virDomainDeviceDef dev =3D { .type =3D VIR_DOMAIN_DEVICE_HOSTDEV }; + virDomainHostdevDefPtr hostdev =3D vm->def->hostdevs[i]; + virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; + bool found; + + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_USB) + continue; + + if (hostdev->missing) { + int num; + + if ((num =3D virUSBDeviceFindByVendor(usbsrc->vendor, usbsrc->= product, + NULL, false, NULL)) < 0) + return -1; + + found =3D num !=3D 0; + } else { + virUSBDevicePtr usb; + + if (virUSBDeviceFindByBus(usbsrc->bus, usbsrc->device, + NULL, false, &usb) < 0) + return -1; + + found =3D usb !=3D NULL; + virUSBDeviceFree(usb); + } + + dev.data.hostdev =3D hostdev; + if ((hostdev->missing ^ !found) && + qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 0) + return -1; + } + + return 0; +} + + static int qemuDomainPerfRestart(virDomainObjPtr vm) { @@ -8204,6 +8250,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