Bug 843560 - Add live migration support for USB
Add live migration support for USB
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
All Linux
high Severity high
: rc
: ---
Assigned To: Jiri Denemark
Virtualization Bugs
Depends On: 805172
Blocks: 832177 798682 804821 838170 840804 852624
  Show dependency treegraph
Reported: 2012-07-26 11:50 EDT by Bhavna Sarathy
Modified: 2015-06-10 21:10 EDT (History)
21 users (show)

See Also:
Fixed In Version: libvirt-0.10.2-5.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 805172
: 852624 (view as bug list)
Last Closed: 2013-02-21 02:20:06 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Comment 2 Dave Allan 2012-09-13 13:45:57 EDT
Jirka, what's going on with this BZ?
Comment 3 Hans de Goede 2012-09-20 09:11:53 EDT
At least from the spice usb-redir migration pov, after adding seamless migration support, no additional changes are needed for USB migration, so I believe that this bug can be closed.
Comment 4 Jiri Denemark 2012-10-01 04:50:58 EDT
qemuMigrationIsAllowed is not called during save/restore, which means
everything will work just fine when saving/restoring a domain with USB passed
through devices as long as the devices remain attach at the same address. In
other words, if the host is not rebooted and the device is not detached from
the host in the meantime. To make it work even if any of this happens, we need
to make some changes to libvirt.

First, we may add support for startupPolicy to USB devices which (similarly to
disk devices) would tell if the device is really required to be present when
starting or migrating a domain. With this, we could support device unplug
between save and restore since qemu should support -device usb-host,id=...
with no address and thus no real USB device.

To support change in USB address, we would need to (partially) ignore the USB
address in domain XML (since libvirt is able to find the right device using
vendor/product), however, this would not work that well in case several
identical devices are attached to the host and we need to make sure we use the
right one. I'll try to think more about how to handle this.
Comment 7 Jiri Denemark 2012-10-10 04:07:09 EDT
Both issues are fixed with the series I sent upstream yesterday: https://www.redhat.com/archives/libvir-list/2012-October/msg00335.html
Comment 8 Jiri Denemark 2012-10-12 05:09:00 EDT
This is now implemented upstream by commits v0.10.2-129-ge658dae through v0.10.2-134-gbd1282d and v0.10.2-139-gf95560b:

commit e658daeb58ec88deec5dd60fd3279f4feb4eac5b
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Tue Oct 2 15:14:02 2012 +0200

    conf: Add support for startupPolicy for USB devices
    USB devices can disappear without OS being mad about it, which makes
    them ideal for startupPolicy. With this attribute, USB devices can be
    configured to be mandatory (the default), requisite (will disappear
    during migration if they cannot be found), or completely optional.

commit 7bcc7278bf145e2628831823f77192307f09bfa1
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Wed Oct 3 13:55:35 2012 +0200

    qemu: Introduce qemuFindHostdevUSBDevice
    The code which looks up a USB device specified by hostdev is duplicated
    in two places. This patch creates a dedicated function that can be
    called in both places.

commit 059aff6b9860b18634709bc76d64ea78f7e609db
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Wed Oct 3 16:57:28 2012 +0200

    qemu: Add option to treat missing USB devices as success
    All USB device lookup functions emit an error when they cannot find the
    requested device. With this patch, their caller can choose if a missing
    device is an error or normal condition.

commit edc9269a2a80082a6898e14b1c10b4a94197b731
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Thu Oct 4 16:18:16 2012 +0200

    qemu: Implement startupPolicy for USB passed through devices

commit 28f8dfdcccd4c0f69063ef741545b37d8a7f7935
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Mon Oct 8 11:58:05 2012 +0200

    Add MIGRATABLE flag for virDomainGetXMLDesc
    Using VIR_DOMAIN_XML_MIGRATABLE flag, one can request domain's XML
    configuration that is suitable for migration or save/restore. Such XML
    may contain extra run-time stuff internal to libvirt and some default
    configuration may be removed for better compatibility of the XML with
    older libvirt releases.
    This flag may serve as an easy way to get the XML that can be passed
    (after desired modifications) to APIs that accept custom XMLs, such as
    virDomainMigrate{,ToURI}2 or virDomainSaveFlags.

commit bd1282d6247742d732f0076811521cfdc6b13472
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Tue Oct 9 13:15:46 2012 +0200

    qemu: Make save/restore with USB devices usable
    Save/restore with passed through USB devices currently only works if the
    USB device can be found at the same USB address where it used to be
    before saving a domain. This makes sense in case a user explicitly
    configure the USB address in domain XML. However, if the device was
    found automatically by vendor/product identification, we should try to
    search for that device when restoring the domain and use any device we
    find as long as there is only one available. In other words, the USB
    device can now be removed and plugged again or the host can be rebooted
    between saving and restoring the domain.

commit f95560b3fe5e239ed85ec01885ed5eb872439e98
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Thu Oct 11 22:33:46 2012 +0200

    conf: Mark missing optional USB devices in domain XML
    When startupPolicy set for a USB devices allows such device to be
    missing, there was no way this could be detected from domain XML. With
    this patch, libvirt emits a new missing='yes' attribute for such devices
    when active domain XML is generated.
Comment 11 weizhang 2012-10-17 09:15:43 EDT
Test on 

Migrate a guest with
    <hostdev mode='subsystem' type='usb' managed='yes'>
      <source startupPolicy='requisite'>
        <address bus='2' device='2'/>
      <alias name='hostdev0'/>

report error
error: Requested operation is not valid: Domain with assigned host devices cannot be migrated

and with --migratable, it ony remove the 
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
device, but if I set 
    <hostdev mode='subsystem' type='usb' managed='yes'>
        <address bus='2' device='2'/>
      <alias name='hostdev0'/>
there is no change in dumpxml --migratable, is that right?
Comment 12 Jiri Denemark 2012-10-19 05:46:55 EDT
Oops, I forgot to change one check that forbids migration ir there are any hostdev devices configured for the domain. It will work for save/restore/managedsave scenario, though. I'll prepare the patch for fixing the migration check and include it in the next build.
Comment 13 Jiri Denemark 2012-10-19 07:50:48 EDT
BTW, to really test all scenarios (such as usb device replug after managedsaving a domain), you should rather identify the usb device using vendor/product. And the --migratable flag will have greater impact in that case, too. It should remove the automatically detected address of the device.
Comment 14 Jiri Denemark 2012-10-19 08:14:01 EDT
Actually, the automatically detected address should still be there but a new attribute autoAddress='yes' should appeare in the source element. I'm sorry about the confusion.
Comment 15 Jiri Denemark 2012-10-19 08:46:26 EDT
The missing part is fixed upstream by v0.10.2-204-g9fcc543:

commit 9fcc5436d3d824ceb82b44852e1a8023c3810655
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Fri Oct 19 13:36:33 2012 +0200

    qemu: Allow migration with host USB devices
    Recently, patches were added support for (managed)saving, restoring, and
    migrating domains with host USB devices. However, qemu driver would
    still forbid migration of such domains because qemuMigrationIsAllowed
    was not updated.
Comment 18 weizhang 2012-10-25 04:34:44 EDT
Verify pass on

Test scenario 
1. With startupPolicy='requisite'
virsh start vr-rhel6u3-x86_64-kvm
error: Failed to start domain vr-rhel6u3-x86_64-kvm
error: internal error Did not find USB device 951:1646

Migration, restore succeed

2. With startupPolicy='optional'
Start, Migration and restore succeed

3. With startpolicy='mandatory'
# virsh start vr-rhel6u3-x86_64-kvm
error: Failed to start domain vr-rhel6u3-x86_64-kvm
error: internal error Did not find USB device 951:1646

# virsh restore /tmp/vr-rhel6u3-x86_64-kvm.save
error: Failed to restore domain from /tmp/vr-rhel6u3-x86_64-kvm.save
error: internal error Did not find USB device 951:1646

# virsh migrate --live vr-rhel6u3-x86_64-kvm qemu+ssh:// --verbose
root@'s password: 
error: internal error Did not find USB device 951:1646

4. Check the --migratable in dumpxml
# virsh dumpxml vr-rhel6u3-x86_64-kvm --migratable
    <hostdev mode='subsystem' type='usb' managed='yes'>
      <source startupPolicy='mandatory' autoAddress='yes'>
        <vendor id='0x0951'/>
        <product id='0x1646'/>
        <address bus='2' device='41'/>
      <alias name='hostdev0'/>
and the usb controller section will be removed

5. Migrate to target without host usb or restore guest without host usb, the xml in target changed to
 <hostdev mode='subsystem' type='usb' managed='yes'>
      <source startupPolicy='optional' missing='yes'>
        <vendor id='0x0951'/>
        <product id='0x1646'/>
        <address bus='2' device='41'/>
      <alias name='hostdev0'/>

If have the usb device with the same verdor and product id on target, then the address change to new bus and device num and migration/restore can succeed with all 3 policies
Comment 19 errata-xmlrpc 2013-02-21 02:20:06 EST
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.