usb-host: insert usb device into hostdevs to be scaned
PATCH 1/1 usb-host: insert usb device into hostdevs to be scaned
According to the comment of usb_host_post_load_bh, after removing the
usb device passed through, we will kick host to scan it again, but the emulated usb device is not added to global list hostdevs, so it can never be discovered then. So just do it before usb_host_auto_check. What's more, it's futile to walk devs in usb_host_auto_check periodically if hostdevs is empty, so let's delete the usb_auto_timer.
hw/usb/host-libusb.c +14 -0
@@ -1534,6 +1534,10 @@ static void usb_host_post_load_bh(void *opaque)usb_device_detach (udev); } dev->bh_postld_pending = false; +if (!dev->needs_autoscan) { + dev->needs_autoscan = true; +QTAILQ_INSERT_TAIL (&hostdevs, dev, next); + }usb_host_auto_check (NULL ); }
@@ -1631,6 +1635,14 @@ static void usb_host_auto_check(void *unused)int unconnected =0 ;int i, n; +if (QTAILQ_EMPTY (&hostdevs)) { +if (usb_auto_timer) { +timer_del (usb_auto_timer); + usb_auto_timer =NULL ; + } +return ; + } +if (usb_host_init () !=0 ) {return ; }
@@ -1682,6 +1694,8 @@ static void usb_host_auto_check(void *unused) s->errcount++;continue ; } + s->needs_autoscan = false; +QTAILQ_REMOVE (&hostdevs, s, next);break ; } }
Signature · 1 line
2.12.2.windows.2
Quoted 5 lines · linzhecheng
According to the comment of
usb_host_post_load_bh, after removing the
usb device passed through, we will kick host to scan it again, but the emulated usb device is not added to global list hostdevs, so it can never be discovered then. So just do it beforeusb_host_auto_check. What's more, it's futile to walk devs inusb_host_auto_checkperiodically if hostdevs is empty, so let's delete theusb_auto_timer.
Hmm, needs_autoscan is a fixed property of the device (depending on configuration), it should not be switched on and off.
What problem you are trying to solve?
cheers,
Gerd
Quoted 13 lines
-----Original Message-----
From: Gerd Hoffmann [mailto:[email protected]]
Sent: Thursday, August 16, 2018 6:46 PM
To: linzhecheng <[email protected]>
Cc: [email protected]; wangxin (U) <[email protected]>
Subject: Re: [PATCH] usb-host: insert usb device into hostdevs to be scanedQuoted 3 lines · linzhecheng
According to the comment of
usb_host_post_load_bh, after removing the usb device passed through, we will kick host to scan it again, but the emulated usb device is not added to global list hostdevs, so it can never bediscovered then.
Quoted 8 lines
Quoted 2 lines
So just do it before
usb_host_auto_check. What's more, it's futile to walk devs inusb_host_auto_checkperiodically if hostdevs is empty, so let'sdelete the
usb_auto_timer.Hmm,
needs_autoscanis a fixed property of the device (depending on configuration), it should not be switched on and off.What problem you are trying to solve?
I'm trying to live migrate a vm to local host, but found the host-usb device was removed then. Is it possible not to remove it after migrating vm?
Quoted 3 lines
cheers,
Gerd
Quoted 6 lines
Quoted 4 lines
Hmm,
needs_autoscanis a fixed property of the device (depending on configuration), it should not be switched on and off.What problem you are trying to solve?
I'm trying to live migrate a vm to local host, but found the host-usb device was removed then. Is it possible not to remove it after migrating vm?
Why live-migrate to localhost? That is rather tricky due to both source and target qemu accessing host resources at the same time, and I guess this is the reason you are seeing the problems here.
If it is for QA purposes I'd suggest to use two machines for actual live migration tests, or store the live migration stream in a file so the two qemu instances never run at the same time (this is what "virsh save" is doing).
cheers,
Gerd
Quoted 13 lines
-----原始邮件-----
发件人: "Gerd Hoffmann" <[email protected]>
发送时间: 2018-08-16 21:01:31 (星期四)
收件人: linzhecheng <[email protected]>
抄送: "wangxin (U)" <[email protected]>, "[email protected]" <[email protected]> 主题: Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scanedQuoted 3 lines
Quoted 3 lines
Hmm,
needs_autoscanis a fixed property of the device (depending on configuration), it should not be switched on and off.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
What problem you are trying to solve?
I'm trying to live migrate a vm to local host, but found the host-usb device was removed then. Is it possible not to remove it after migrating vm?
Why live-migrate to localhost? That is rather tricky due to both source and target qemu accessing host resources at the same time, and I guess this is the reason you are seeing the problems here.
Thanks for your reply, but I'm still confused about these issues:
1. If local live migration is not supported for host-usb device, why we have to detach it and rescan it in usb_host_post_load_bh? If a device's property *needs_autoscan* is false, how can we scan it(because we have detached it)?
2. Normal live migration between two remote hostes makes a vm access diffrent host usb devices, how can we copy states and data of them?
Quoted 9 lines
If it is for QA purposes I'd suggest to use two machines for actual live migration tests, or store the live migration stream in a file so the two qemu instances never run at the same time (this is what "virsh save" is doing).
cheers,
Gerd
Quoted 7 lines
Quoted 3 lines
Why live-migrate to localhost? That is rather tricky due to both source and target qemu accessing host resources at the same time, and I guess this is the reason you are seeing the problems here.
Thanks for your reply, but I'm still confused about these issues:
1. If local live migration is not supported for host-usb device, why we have to detach it and rescan it inusb_host_post_load_bh? If a device's property *needs_autoscan* is false, how can we scan it(because we have detached it)?
autoscan is for hotplug. You can un-plug and re-plug a usb device on the physical host, and the guest will see these un-plugs and re-plugs.
autoscan is turned off in case the usb device is specified using hostbus+hostaddr attributes, because hostaddr is a moving target. Each time the device is plugged in it gets a different address, for hotplug to work properly you must specify the device using attributes which don't change. You can use hostport instead of hostaddr for example.
Quoted 2 lines
2. Normal live migration between two remote hostes makes a vm access differnt host usb devices, how can we copy states and data of them?
We don't copy any state. It is rather pointless, even for save/resume on the same machine we don't know what state the usb device has and whenever it is still in the state the guest has left it.
So instead we virtually un-plug and re-plug the device, to make the guest driver re-initialize the device.
HTH,
Gerd
Quoted 29 lines
-----Original Message-----
From: gerd hoffmann [mailto:[email protected]]
Sent: Friday, August 17, 2018 2:08 PM
To: CheneyLin <[email protected]>
Cc: linzhecheng <[email protected]>; wangxin (U) <[email protected]>; [email protected]
Subject: Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scanedQuoted 7 lines
Quoted 3 lines
Why live-migrate to localhost? That is rather tricky due to both source and target qemu accessing host resources at the same time, and I guess this is the reason you are seeing the problems here.
Thanks for your reply, but I'm still confused about these issues:
1. If local live migration is not supported for host-usb device, why we have to detach it and rescan it inusb_host_post_load_bh? If a device's property *needs_autoscan* is false, how can we scan it(because wehave detached it)?
autoscan is for hotplug. You can un-plug and re-plug a usb device on the physical host, and the guest will see these un-plugs and re-plugs.
autoscan is turned off in case the usb device is specified using hostbus+hostaddr attributes, because hostaddr is a moving target. Each time the device is plugged in it gets a different address, for hotplug to work properly you must specify the device using attributes which don't change. You can use hostport instead of hostaddr for example.
Quoted 6 lines
Quoted 2 lines
2. Normal live migration between two remote hostes makes a vm access differnt host usb devices, how can we copy states and data of them?
We don't copy any state. It is rather pointless, even for save/resume on the same machine we don't know what state the usb device has and whenever it is still in the state the guest has left it.
I have tried stop/cont a vm with host-usb device during coping large files(makes usb device busy woking), but usb device was not detached/attached and coping task was completed properly.
It seems that we can restart it where we left it off.
Quoted 6 lines
So instead we virtually un-plug and re-plug the device, to make the guest driver re-initialize the device.
HTH,
Gerd
Hi,
Quoted 6 lines
Quoted 3 lines
We don't copy any state. It is rather pointless, even for save/resume on the same machine we don't know what state the usb device has and whenever it is still in the state the guest has left it.
I have tried stop/cont a vm with host-usb device during coping large files(makes usb device busy woking), but usb device was not detached/attached and coping task was completed properly.
It seems that we can restart it where we left it off.
stop/cont isn't a problem.
save/resume means "virsh save" + "virsh resume". This sends the live migration stream to a file (using "migrate exec:cat>file" monitor command for save, then 'qemu -incoming "exec:cat file' for resume).
cheers,
Gerd