[libvirt] [PATCH] qemuProcess: update hostdevs before connectting qemu monitor

Wu Zongyong posted 1 patch 5 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1537497233-39529-1-git-send-email-cordius.wu@huawei.com
Test syntax-check passed
src/qemu/qemu_process.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[libvirt] [PATCH] qemuProcess: update hostdevs before connectting qemu monitor
Posted by Wu Zongyong 5 years, 7 months ago
In a following case:

    virsh start $domain
    service libvirtd stop
    <shutdown> the guest from within the $domain
    service libvirtd start

Notice that PCI devices which have been assigned to the $domain will
still be bound to stub drivers instead rebound to host drivers.
In that case the call stack is like below:

    libvirtd start
        qemuProcessReconnect
            qemuProcessStop
                qemuHostdevReAttachDomainDevices
                    qemuHostdevReAttachPCIDevices
                        virHostdevReAttachPCIDevices

qemuHostdevUpdateActiveDomainDevices won't be called because the monitor
channel is closed. So host devices in $domain will not be added to either
activePCIHostdevs list or inactivePCIHostdev list. And therefore,
virHostdevReAttachPCIDevices just neglects these host PCI devices which
are bound to stub drivers and don't rebind them to host drivers.

This patch fixs that by moving qemuHostdevUpdateActiveDomainDevices before
qemuConnectMonitor.

Signed-off-by: Wu Zongyong <cordius.wu@huawei.com>
---
 src/qemu/qemu_process.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f9a01da..d187271 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7783,6 +7783,9 @@ qemuProcessReconnect(void *opaque)
      * allowReboot in status XML and we need to initialize it. */
     qemuProcessPrepareAllowReboot(obj);
 
+    if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0)
+        goto error;
+
     if (priv->qemuCaps &&
         virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS))
         retry = false;
@@ -7794,9 +7797,6 @@ qemuProcessReconnect(void *opaque)
     if (qemuConnectMonitor(driver, obj, QEMU_ASYNC_JOB_NONE, retry, NULL) < 0)
         goto error;
 
-    if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0)
-        goto error;
-
     priv->machineName = qemuDomainGetMachineName(obj);
     if (!priv->machineName)
         goto error;
-- 
1.9.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuProcess: update hostdevs before connectting qemu monitor
Posted by John Ferlan 5 years, 6 months ago

On 9/20/18 10:33 PM, Wu Zongyong wrote:
> In a following case:
> 
>     virsh start $domain
>     service libvirtd stop
>     <shutdown> the guest from within the $domain
>     service libvirtd start
> 
> Notice that PCI devices which have been assigned to the $domain will
> still be bound to stub drivers instead rebound to host drivers.
> In that case the call stack is like below:
> 
>     libvirtd start
>         qemuProcessReconnect
>             qemuProcessStop
>                 qemuHostdevReAttachDomainDevices
>                     qemuHostdevReAttachPCIDevices
>                         virHostdevReAttachPCIDevices
> 
> qemuHostdevUpdateActiveDomainDevices won't be called because the monitor
> channel is closed. So host devices in $domain will not be added to either
> activePCIHostdevs list or inactivePCIHostdev list. And therefore,
> virHostdevReAttachPCIDevices just neglects these host PCI devices which
> are bound to stub drivers and don't rebind them to host drivers.
> 
> This patch fixs that by moving qemuHostdevUpdateActiveDomainDevices before
> qemuConnectMonitor.
> 
> Signed-off-by: Wu Zongyong <cordius.wu@huawei.com>
> ---
>  src/qemu/qemu_process.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 

I cleaned up the commit message a little bit and pushed.

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list