From nobody Tue May 7 23:50:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=ovhcloud.com ARC-Seal: i=1; a=rsa-sha256; t=1664975576; cv=none; d=zohomail.com; s=zohoarc; b=DvAf63Pm03HtkgUFbGl5vxPT1UXx70cMimknrqKftEqb0lkRtHKb/liOdYCvdUxaixaY+4Kl3J/ze/ueegSLnRNPqCX+/hF74kAAtRbp0KftfZSLNN8bJv7ss2amtAEsmYWli+2P3v9aMGZKL+WsqHkqiWjfjSNCU6fI4w55lLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664975576; h=Content-Type: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; bh=3G5AOjtRzRiSvxyN/IvO3CajQTATD+uFbNiMCL3/JFY=; b=lI0ayabNtO2FioA9rPe1xRpM9eXEedZ5WQ/DyKfyNRPYQIA9zcVx1X+jkQpF5WhBoTWYZGp0AqTwSjVcy9cUb3qT2A+2VOo1RYVqmqg6IPuJMCvpoj5kcnbrqy7SrdWSGYs7PPtQg8k4SA1QvVK2K13VwX9MtEroG3xANf6Tf0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1664975576724838.1583808236745; Wed, 5 Oct 2022 06:12:56 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-AQXQF66iM1CHRHLNR-FJEw-1; Wed, 05 Oct 2022 09:12:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6492862E4A; Wed, 5 Oct 2022 13:12:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 248DA21568B7; Wed, 5 Oct 2022 13:11:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D5BA31946A5A; Wed, 5 Oct 2022 13:11:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 38D301946A4E for ; Wed, 5 Oct 2022 13:09:36 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1C619477F5C; Wed, 5 Oct 2022 13:09:36 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1476F477F55 for ; Wed, 5 Oct 2022 13:09:36 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E45601C0515B for ; Wed, 5 Oct 2022 13:09:35 +0000 (UTC) Received: from 2.mo302.mail-out.ovh.net (2.mo302.mail-out.ovh.net [137.74.110.75]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-q9qqSbxhMeaYWh912RQ18Q-1; Wed, 05 Oct 2022 09:09:32 -0400 Received: from DAGFR10EX1.OVH.local (unknown [51.255.55.251]) by mo302.mail-out.ovh.net (Postfix) with ESMTPS id 03A2D79418 for ; Wed, 5 Oct 2022 15:09:29 +0200 (CEST) Received: from DAGFR10EX2.OVH.local (172.16.2.31) by DAGFR10EX1.OVH.local (172.16.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.12; Wed, 5 Oct 2022 15:09:24 +0200 Received: from DAGFR10EX2.OVH.local ([fe80::8871:d1ba:5b7:ff64]) by DAGFR10EX2.OVH.local ([fe80::8871:d1ba:5b7:ff64%5]) with mapi id 15.02.1118.012; Wed, 5 Oct 2022 15:09:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664975575; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=3G5AOjtRzRiSvxyN/IvO3CajQTATD+uFbNiMCL3/JFY=; b=C4PY+V1m8JKyex7PaK7lLg4IAsd+JwaSOPvHzc0qkrquA9wDPewUbHqTr/LaspjOvkUY5J d9J8urWAJcAP7iNWCgvs4SAkUEy07cunxBLOHtszLjsIxYSnfnu2vg0QnqKlG9dyGiUNeW zCD2wDM1B373/1J+xrvxrqTUbwVBsBA= X-MC-Unique: AQXQF66iM1CHRHLNR-FJEw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: q9qqSbxhMeaYWh912RQ18Q-1 From: Pierre Libeau To: "libvir-list@redhat.com" Subject: RE: [PATCH] Fix race condition when detaching a device Thread-Topic: [PATCH] Fix race condition when detaching a device Thread-Index: AQHYvTRucAXgGmPXx0OHlpLiFl+mY63/+x+J Date: Wed, 5 Oct 2022 13:09:23 +0000 Message-ID: References: <20220831122251.74048-1-pierre.libeau@corp.ovh.com> In-Reply-To: <20220831122251.74048-1-pierre.libeau@corp.ovh.com> Accept-Language: fr-FR, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [109.190.254.58] x-ovh-corplimit-skip: true MIME-Version: 1.0 X-Ovh-Tracer-Id: 9370301977798495084 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeifedgiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvffuthffkfhfjghitgggsegrtdhjredttddunecuhfhrohhmpefrihgvrhhrvgcunfhisggvrghuuceophhivghrrhgvrdhlihgsvggruhesohhvhhgtlhhouhgurdgtohhmqeenucggtffrrghtthgvrhhnpedukefgheeugedthedvgeetheehfeegteethfeltedtueeuieetvdehvdeukeeiveenucfkpheptddrtddrtddrtddpuddtledrudeltddrvdehgedrheeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopefftefihfftuddtgfgiuddrqfggjfdrlhhotggrlhdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepphhivghrrhgvrdhlihgsvggruhesohhvhhgtlhhouhgurdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhisghvihhrqdhlihhsthesrhgvughhrghtrdgtohhmpdfovfetjfhoshhtpehmoheftddv X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mailman-Approved-At: Wed, 05 Oct 2022 13:11:55 +0000 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: fr-FR Content-Type: multipart/alternative; boundary="_000_ba04e8c3fb084f3ba979a4c0e9bc39aaovhcloudcom_" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664975578049100001 --_000_ba04e8c3fb084f3ba979a4c0e9bc39aaovhcloudcom_ Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Hello guys, I will very happy if you have time to give me feedback about this patch. It's the first time for me about libvirt project so don't hesitate to say m= e if I have missed something. I have pushed this change on my side internally and it's resolved my issue. Pierre ________________________________ De : Pierre Libeau Envoy=C3=A9 : mercredi 31 ao=C3=BBt 2022 14:22:51 =C3=80 : libvir-list@redhat.com Cc : Pierre Libeau Objet : [PATCH] Fix race condition when detaching a device Qemu reply to libvirt "DeviceNotFound" and libvirt didn't clean on the side the live configuration. qemuMonitorDelDevice() return -2 to qemuDomainDeleteDevice() and during this action in qemuDomainDetachDeviceLive() the remove is never call. Ref #359 Signed-off-by: Pierre LIBEAU --- src/qemu/qemu_hotplug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 9b508dc8f0..52a14a4476 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -93,6 +93,8 @@ qemuDomainResetDeviceRemoval(virDomainObj *vm); * * Returns: 0 on success, * -1 otherwise. + * -2 device does not exist in qemu, but it still + * exists in libvirt */ static int qemuDomainDeleteDevice(virDomainObj *vm, @@ -124,7 +126,6 @@ qemuDomainDeleteDevice(virDomainObj *vm, * domain XML is queried right after detach API the * device would still be there. */ VIR_DEBUG("Detaching of device %s failed and no event arrived"= , alias); - rc =3D 0; } } @@ -6055,7 +6056,11 @@ qemuDomainDetachDeviceLive(virDomainObj *vm, if (!async) qemuDomainMarkDeviceForRemoval(vm, info); - if (qemuDomainDeleteDevice(vm, info->alias) < 0) { + int rc; + rc =3D qemuDomainDeleteDevice(vm, info->alias); + if (rc < 0) { + if (rc =3D=3D -2) + ret =3D qemuDomainRemoveDevice(driver, vm, &detach); if (virDomainObjIsActive(vm)) qemuDomainRemoveAuditDevice(vm, &detach, false); goto cleanup; -- 2.37.3 --_000_ba04e8c3fb084f3ba979a4c0e9bc39aaovhcloudcom_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hello guys,


I will very happy if you have time to give me feedback about this patch.=

It's the first time for me about libvirt project so don't hesitate to sa= y me if I have missed something.


I have pushed this change on my side internally and it's resolved my iss= ue.


Pierre

De : Pierre Libeau
Envoy=E9 : mercredi 31 ao=FBt 2022 14:22:51
=C0 : libvir-list@redhat.com
Cc : Pierre Libeau
Objet : [PATCH] Fix race condition when detaching a device
 
Qemu reply to libvirt "DeviceNotFound" a= nd libvirt didn't clean on the
side the live configuration.

qemuMonitorDelDevice() return -2 to qemuDomainDeleteDevice() and during
this action in qemuDomainDetachDeviceLive() the remove is never call.

Ref #359

Signed-off-by: Pierre LIBEAU <pierre.libeau@corp.ovh.com>
---
 src/qemu/qemu_hotplug.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 9b508dc8f0..52a14a4476 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -93,6 +93,8 @@ qemuDomainResetDeviceRemoval(virDomainObj *vm);
  *
  * Returns: 0 on success,
  *         -1 otherwise.
+ *         -2 device does not = exist in qemu, but it still
+ *            e= xists in libvirt
  */
 static int
 qemuDomainDeleteDevice(virDomainObj *vm,
@@ -124,7 +126,6 @@ qemuDomainDeleteDevice(virDomainObj *vm,
            &nb= sp; * domain XML is queried right after detach API the
            &nb= sp; * device would still be there.  */
             VI= R_DEBUG("Detaching of device %s failed and no event arrived", ali= as);
-            rc =3D = 0;
         }
     }
 
@@ -6055,7 +6056,11 @@ qemuDomainDetachDeviceLive(virDomainObj *vm,
     if (!async)
         qemuDomainMarkDeviceForRem= oval(vm, info);
 
-    if (qemuDomainDeleteDevice(vm, info->alias) < 0) = {
+    int rc;
+    rc =3D qemuDomainDeleteDevice(vm, info->alias);<= br> +    if (rc < 0) {
+        if (rc =3D=3D -2)
+           &nbs= p;   ret =3D qemuDomainRemoveDevice(driver, vm, &detach);
         if (virDomainObjIsActive(v= m))
             qe= muDomainRemoveAuditDevice(vm, &detach, false);
         goto cleanup;
--
2.37.3

--_000_ba04e8c3fb084f3ba979a4c0e9bc39aaovhcloudcom_--