RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 843560 - Add live migration support for USB
Summary: Add live migration support for USB
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt
Version: 6.4
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Jiri Denemark
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On: 805172
Blocks: 832177 798682 804821 838170 840804 852624
TreeView+ depends on / blocked
 
Reported: 2012-07-26 15:50 UTC by Bhavna Sarathy
Modified: 2015-06-11 01:10 UTC (History)
21 users (show)

Fixed In Version: libvirt-0.10.2-5.el6
Doc Type: Bug Fix
Doc Text:
Clone Of: 805172
: 852624 (view as bug list)
Environment:
Last Closed: 2013-02-21 07:20:06 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2013:0276 0 normal SHIPPED_LIVE Moderate: libvirt security, bug fix, and enhancement update 2013-02-20 21:18:26 UTC

Comment 2 Dave Allan 2012-09-13 17:45:57 UTC
Jirka, what's going on with this BZ?

Comment 3 Hans de Goede 2012-09-20 13:11:53 UTC
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 08:50:58 UTC
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 08:07:09 UTC
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 09:09:00 UTC
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>
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>
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>
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>
Date:   Thu Oct 4 16:18:16 2012 +0200

    qemu: Implement startupPolicy for USB passed through devices

commit 28f8dfdcccd4c0f69063ef741545b37d8a7f7935
Author: Jiri Denemark <jdenemar>
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>
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>
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 13:15:43 UTC
Test on 
qemu-kvm-0.12.1.2-2.327.el6.x86_64
libvirt-0.10.2-3.el6.x86_64
kernel-2.6.32-329.el6.x86_64

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

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'/>
    </controller>
device, but if I set 
    <hostdev mode='subsystem' type='usb' managed='yes'>
      <source>
        <address bus='2' device='2'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>
there is no change in dumpxml --migratable, is that right?

Comment 12 Jiri Denemark 2012-10-19 09:46:55 UTC
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 11:50:48 UTC
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 12:14:01 UTC
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 12:46:26 UTC
The missing part is fixed upstream by v0.10.2-204-g9fcc543:

commit 9fcc5436d3d824ceb82b44852e1a8023c3810655
Author: Jiri Denemark <jdenemar>
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 08:34:44 UTC
Verify pass on
qemu-kvm-rhev-0.12.1.2-2.317.el6.x86_64
libvirt-0.10.2-5.el6.x86_64
kernel-2.6.32-329.el6.x86_64

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://10.66.5.143/system --verbose
root.5.143'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'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>
...
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'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>

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 07:20:06 UTC
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.

http://rhn.redhat.com/errata/RHSA-2013-0276.html


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