<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>Hello guys,</p>
<p><br>
</p>
<p>I will very happy if you have time to give me feedback about this patch.</p>
<p>It's the first time for me about libvirt project so don't hesitate to say me if I have missed something.<br>
</p>
<p><br>
</p>
<p>I have pushed this change on my side internally and it's resolved my issue.<br>
</p>
<p><br>
</p>
<div id="x_Signature">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
Pierre</div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>De :</b> Pierre Libeau<br>
<b>Envoyé :</b> mercredi 31 août 2022 14:22:51<br>
<b>À :</b> libvir-list@redhat.com<br>
<b>Cc :</b> Pierre Libeau<br>
<b>Objet :</b> [PATCH] Fix race condition when detaching a device</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Qemu reply to libvirt "DeviceNotFound" and libvirt didn't clean on the<br>
side the live configuration.<br>
<br>
qemuMonitorDelDevice() return -2 to qemuDomainDeleteDevice() and during<br>
this action in qemuDomainDetachDeviceLive() the remove is never call.<br>
<br>
Ref #359<br>
<br>
Signed-off-by: Pierre LIBEAU <pierre.libeau@corp.ovh.com><br>
---<br>
 src/qemu/qemu_hotplug.c | 9 +++++++--<br>
 1 file changed, 7 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c<br>
index 9b508dc8f0..52a14a4476 100644<br>
--- a/src/qemu/qemu_hotplug.c<br>
+++ b/src/qemu/qemu_hotplug.c<br>
@@ -93,6 +93,8 @@ qemuDomainResetDeviceRemoval(virDomainObj *vm);<br>
  *<br>
  * Returns: 0 on success,<br>
  *         -1 otherwise.<br>
+ *         -2 device does not exist in qemu, but it still<br>
+ *            exists in libvirt<br>
  */<br>
 static int<br>
 qemuDomainDeleteDevice(virDomainObj *vm,<br>
@@ -124,7 +126,6 @@ qemuDomainDeleteDevice(virDomainObj *vm,<br>
              * domain XML is queried right after detach API the<br>
              * device would still be there.  */<br>
             VIR_DEBUG("Detaching of device %s failed and no event arrived", alias);<br>
-            rc = 0;<br>
         }<br>
     }<br>
 <br>
@@ -6055,7 +6056,11 @@ qemuDomainDetachDeviceLive(virDomainObj *vm,<br>
     if (!async)<br>
         qemuDomainMarkDeviceForRemoval(vm, info);<br>
 <br>
-    if (qemuDomainDeleteDevice(vm, info->alias) < 0) {<br>
+    int rc;<br>
+    rc = qemuDomainDeleteDevice(vm, info->alias);<br>
+    if (rc < 0) {<br>
+        if (rc == -2)<br>
+               ret = qemuDomainRemoveDevice(driver, vm, &detach);<br>
         if (virDomainObjIsActive(vm))<br>
             qemuDomainRemoveAuditDevice(vm, &detach, false);<br>
         goto cleanup;<br>
-- <br>
2.37.3<br>
<br>
</div>
</span></font>
</body>
</html>