* [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
@ 2018-08-16 9:43 linzhecheng
2018-08-16 10:45 ` Gerd Hoffmann
0 siblings, 1 reply; 8+ messages in thread
From: linzhecheng @ 2018-08-16 9:43 UTC (permalink / raw)
To: qemu-devel; +Cc: kraxel, wangxinxin.wang, 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 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.
Signed-off-by: linzhecheng <linzhecheng@huawei.com>
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index f31e9cbbb8..632abaa390 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -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;
}
}
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-16 9:43 [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned linzhecheng
@ 2018-08-16 10:45 ` Gerd Hoffmann
2018-08-16 10:52 ` linzhecheng
0 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2018-08-16 10:45 UTC (permalink / raw)
To: linzhecheng; +Cc: qemu-devel, wangxinxin.wang
On Thu, Aug 16, 2018 at 05:43:56PM +0800, linzhecheng wrote:
> 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.
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-16 10:45 ` Gerd Hoffmann
@ 2018-08-16 10:52 ` linzhecheng
2018-08-16 13:01 ` Gerd Hoffmann
0 siblings, 1 reply; 8+ messages in thread
From: linzhecheng @ 2018-08-16 10:52 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel@nongnu.org, wangxin (U)
> -----Original Message-----
> From: Gerd Hoffmann [mailto:kraxel@redhat.com]
> Sent: Thursday, August 16, 2018 6:46 PM
> To: linzhecheng <linzhecheng@huawei.com>
> Cc: qemu-devel@nongnu.org; wangxin (U) <wangxinxin.wang@huawei.com>
> Subject: Re: [PATCH] usb-host: insert usb device into hostdevs to be scaned
>
> On Thu, Aug 16, 2018 at 05:43:56PM +0800, linzhecheng wrote:
> > 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.
>
> 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?
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?
>
> cheers,
> Gerd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-16 10:52 ` linzhecheng
@ 2018-08-16 13:01 ` Gerd Hoffmann
2018-08-16 15:17 ` CheneyLin
0 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2018-08-16 13:01 UTC (permalink / raw)
To: linzhecheng; +Cc: qemu-devel@nongnu.org, wangxin (U)
> > 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?
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-16 13:01 ` Gerd Hoffmann
@ 2018-08-16 15:17 ` CheneyLin
2018-08-17 6:07 ` gerd hoffmann
0 siblings, 1 reply; 8+ messages in thread
From: CheneyLin @ 2018-08-16 15:17 UTC (permalink / raw)
To: gerd hoffmann; +Cc: linzhecheng, wangxin (u), qemu-devel@nongnu.org
> -----原始邮件-----
> 发件人: "Gerd Hoffmann" <kraxel@redhat.com>
> 发送时间: 2018-08-16 21:01:31 (星期四)
> 收件人: linzhecheng <linzhecheng@huawei.com>
> 抄送: "wangxin (U)" <wangxinxin.wang@huawei.com>, "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
> 主题: Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
>
> > > 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?
> > 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?
>
> 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
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-16 15:17 ` CheneyLin
@ 2018-08-17 6:07 ` gerd hoffmann
2018-08-20 2:08 ` linzhecheng
0 siblings, 1 reply; 8+ messages in thread
From: gerd hoffmann @ 2018-08-17 6:07 UTC (permalink / raw)
To: CheneyLin; +Cc: linzhecheng, wangxin (u), qemu-devel@nongnu.org
> > 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)?
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.
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-17 6:07 ` gerd hoffmann
@ 2018-08-20 2:08 ` linzhecheng
2018-08-20 5:11 ` gerd hoffmann
0 siblings, 1 reply; 8+ messages in thread
From: linzhecheng @ 2018-08-20 2:08 UTC (permalink / raw)
To: gerd hoffmann, CheneyLin; +Cc: wangxin (U), qemu-devel@nongnu.org
> -----Original Message-----
> From: gerd hoffmann [mailto:kraxel@redhat.com]
> Sent: Friday, August 17, 2018 2:08 PM
> To: CheneyLin <linzc@zju.edu.cn>
> Cc: linzhecheng <linzhecheng@huawei.com>; wangxin (U)
> <wangxinxin.wang@huawei.com>; qemu-devel@nongnu.org
> Subject: Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to
> be scaned
>
> > > 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)?
>
> 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.
>
> > 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.
>
> So instead we virtually un-plug and re-plug the device, to make the guest driver
> re-initialize the device.
>
> HTH,
> Gerd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned
2018-08-20 2:08 ` linzhecheng
@ 2018-08-20 5:11 ` gerd hoffmann
0 siblings, 0 replies; 8+ messages in thread
From: gerd hoffmann @ 2018-08-20 5:11 UTC (permalink / raw)
To: linzhecheng; +Cc: CheneyLin, wangxin (U), qemu-devel@nongnu.org
Hi,
> > 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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-08-20 5:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-16 9:43 [Qemu-devel] [PATCH] usb-host: insert usb device into hostdevs to be scaned linzhecheng
2018-08-16 10:45 ` Gerd Hoffmann
2018-08-16 10:52 ` linzhecheng
2018-08-16 13:01 ` Gerd Hoffmann
2018-08-16 15:17 ` CheneyLin
2018-08-17 6:07 ` gerd hoffmann
2018-08-20 2:08 ` linzhecheng
2018-08-20 5:11 ` gerd hoffmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).