From nobody Sun Feb 8 16:33:59 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=1568728129; cv=none; d=zoho.com; s=zohoarc; b=j8LODG70e4yc2Bi8t0fUe/N61j6u7fWsNSjFJjtyBhexNEiGL1+PP4R2pJA+iKf2sRwBhSirTC5ngNZ7KNKM+Z8M3Oe8Oeht4OjurVSueThog14XQ0dRSWNxbIDCGQ2Z1Y5nk5AJmV5dJW7A8cD61oP9CB8TidskYFan5AvQENE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568728129; 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=4Uls/jaVAv2p+RrQfOwsDv7fmBa1Ao6qcb4CKOG/k5s=; b=dwH0s8KAIxPuvy5zZxGHPrSx+R151aQ73CCaeZsHg5vQswlAgynKwsz41yIpKCMzhj9Ym0Z930mC5O7lrWOL70x9T6YxAhcdcw++UPO3YczXw+xgdhwG9imIFahDodJygdSZHboCJ3blFSwbyhB6kVoe8rarWAGm7aUsfL3tlSs= 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 1568728129814827.0513480683288; Tue, 17 Sep 2019 06:48:49 -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 16746191864F; Tue, 17 Sep 2019 13:48:48 +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 CD76060625; Tue, 17 Sep 2019 13:48:47 +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 8C2174EE6F; Tue, 17 Sep 2019 13:48:47 +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 x8HDmaOX002332 for ; Tue, 17 Sep 2019 09:48:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C4FD5C57D; Tue, 17 Sep 2019 13:48:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx26.extmail.prod.ext.phx2.redhat.com [10.5.110.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5505B5C21E for ; Tue, 17 Sep 2019 13:48:29 +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 E79F08980EF for ; Tue, 17 Sep 2019 13:48:28 +0000 (UTC) Received: from [172.16.24.106] (helo=shiny.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iADqF-0001xB-Cz; Tue, 17 Sep 2019 16:48:27 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 17 Sep 2019 16:47:42 +0300 Message-Id: <20190917134747.13868-8-nshirokovskiy@virtuozzo.com> In-Reply-To: <20190917134747.13868-1-nshirokovskiy@virtuozzo.com> References: <20190917134747.13868-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.67]); Tue, 17 Sep 2019 13:48:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 17 Sep 2019 13:48:29 +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.67 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 07/12] 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.70]); Tue, 17 Sep 2019 13:48:48 +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. Currently 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 b12b39d61d..e5594835c4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4655,6 +4655,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, @@ -4682,6 +4720,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) @@ -5287,6 +5330,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