Martin Polednik has uploaded a new change for review.
Change subject: vdsm hostdev: add support for USB devices ......................................................................
vdsm hostdev: add support for USB devices
Libvirt allows passthrough of USB devices (not busses) - this patch exposes the functionality in vdsm
Change-Id: Iac74e7537d56bcb940ef07a4654d45cbcdbb1fb0 Signed-off-by: Martin Polednik mpoledni@redhat.com --- M vdsm/caps.py M vdsm/rpc/vdsmapi-schema.json M vdsm/virt/vm.py 3 files changed, 71 insertions(+), 10 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/54/29054/1
diff --git a/vdsm/caps.py b/vdsm/caps.py index d937d4e..8c16af6 100644 --- a/vdsm/caps.py +++ b/vdsm/caps.py @@ -530,7 +530,12 @@ # back that we could use to uniquely identify and initiate a device continue
- if capability in ('pci',): + if capability in ('pci', 'usb_device'): + # Libvirt only allows to attach USB device with capability 'usb', + # but the bus identifies itself as 'usb' while device as + # 'usb_device' + if dev['capability'] == 'usb_device': + dev['capability'] = 'usb' devices.append(dev)
return devices diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json index 921f3d4..ac10144 100644 --- a/vdsm/rpc/vdsmapi-schema.json +++ b/vdsm/rpc/vdsmapi-schema.json @@ -3156,33 +3156,55 @@ 'specParams': 'VmRngDeviceSpecParams'}}
## +# @StartupPolicy: +# +# Possible policies for startup with device +# +# @mandatory: fail if missing for any reason (the default) +# +# @requisite: fail if missing on boot up, drop if missing +# on migrate/restore/revert +# +# @optional: drop if missing at any start attempt +# +# Since: 4.16.0 +## +{'enum': 'StartupPolicy', 'data': ['mandatory', 'requisite', 'optional']} + +## # @HostDeviceCapability: # # Properties of a host device. # # @pci: PCI device # +# @usb: USB device +# # Since: 4.16.0 ## -{'enum': 'HostDeviceCapability', 'data': ['pci']} +{'enum': 'HostDeviceCapability', 'data': ['pci', 'usb']}
## # @HostDeviceSpecParams: # # Properties of a host device. # -# @bootorder: #optional If specified, this device is part of the boot -# sequence at the specified position +# @bootorder: #optional If specified, this device is part of the boot +# sequence at the specified position (for @pci and @usb) # -# @bar: #optional ROM visibility in the guest's memory map (for @pci) +# @bar: #optional ROM visibility in the guest's +# memory map (for @pci) # -# @file: #optional Binary file to be used as device's ROM (for @pci) +# @file: #optional Binary file to be used as device's ROM (for @pci) +# +# @startupPolicy: #optional Possible boot handling with attached device +# (for @usb) # # Since: 4.16.0 ## {'type': 'HostDeviceSpecParams', - 'data': {'*bootorder': 'int', '*bar': 'bool', - '*file': 'str'}} + 'data': {'*bootorder': 'int', '*bar': 'bool', '*file': 'str', + '*startupPolicy': 'StartupPolicy'}}
## # @HostDevice: diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index 6143cfa..6a6978e 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -1631,13 +1631,16 @@ self.log.debug('Detaching hostdev %s', self.name) self._node.dettach()
- def getPciAddr(self): + def _parsecaps(self): capsxml = _domParseStr(self._node.XMLDesc(0)).childNodes[0]
self.log.debug('Got nodeDevice XML:\n%s', capsxml.toprettyxml(encoding='utf-8'))
- capsxml = capsxml.getElementsByTagName('capability')[0] + return capsxml.getElementsByTagName('capability')[0] + + def getPciAddr(self): + capsxml = self._parsecaps() domain = capsxml.getElementsByTagName('domain')[0]. \ firstChild.nodeValue bus = capsxml.getElementsByTagName('bus')[0].firstChild.nodeValue @@ -1646,6 +1649,26 @@ self.log.debug('PCI device %s at address {domain: %s bus: %s ' 'slot: %s}', self.name, domain, bus, slot) return {'domain': domain, 'bus': bus, 'slot': slot} + + def getUsbAddr(self): + capsxml = self._parsecaps() + addr = {} + + addr['bus'] = capsxml.getElementsByTagName('bus')[0].firstChild. \ + nodeValue + addr['device'] = capsxml.getElementsByTagName('device')[0]. \ + firstChild.nodeValue + # TODO: handle nonexistant product_id and vendor_id by not adding them + # to addr + addr['product_id'] = capsxml.getElementsByTagName('product')[0].\ + getAttribute('id') + addr['vendor_id'] = capsxml.getElementsByTagName('vendor')[0].\ + getAttribute('id') + + self.log.debug('USB device %s {product: %s, vendor: %s} at address ' + '{bus: %s device: %s}', self.name, addr['product_id'], + addr['vendor_id'], addr['bus'], addr['device']) + return addr
def getXML(self): """ @@ -1683,6 +1706,17 @@
rom.setAttrs(**romAttrs)
+ elif self.capability == 'usb_device': + addr = self.getPciAddr() + try: + source.appendChildWithArgs('vendor', None, addr['vendor']) + source.appendChildWithArgs('vendor', None, addr['product']) + except: + source.appendChildWithArgs('address', None, **addr) + + if 'startupPolicy' in self.specParams: + source.setAttrs(startupPolicy=self.specParams['startupPolicy']) + return hostdev
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsm hostdev: add support for USB devices ......................................................................
Patch Set 1:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/9531/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/10315/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit/10471/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_verify-error-codes_merged/5397/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_merged/3555/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/953/ : SUCCESS
Francesco Romani has posted comments on this change.
Change subject: vdsm hostdev: add support for USB devices ......................................................................
Patch Set 1:
(3 comments)
http://gerrit.ovirt.org/#/c/29054/1/vdsm/rpc/vdsmapi-schema.json File vdsm/rpc/vdsmapi-schema.json:
Line 3160: # Line 3161: # Possible policies for startup with device Line 3162: # Line 3163: # @mandatory: fail if missing for any reason (the default) Line 3164: # trailing whitespace Line 3165: # @requisite: fail if missing on boot up, drop if missing Line 3166: # on migrate/restore/revert Line 3167: # Line 3168: # @optional: drop if missing at any start attempt
Line 3164: # Line 3165: # @requisite: fail if missing on boot up, drop if missing Line 3166: # on migrate/restore/revert Line 3167: # Line 3168: # @optional: drop if missing at any start attempt ditto Line 3169: # Line 3170: # Since: 4.16.0 Line 3171: ## Line 3172: {'enum': 'StartupPolicy', 'data': ['mandatory', 'requisite', 'optional']}
http://gerrit.ovirt.org/#/c/29054/1/vdsm/virt/vm.py File vdsm/virt/vm.py:
Line 1706: Line 1707: rom.setAttrs(**romAttrs) Line 1708: Line 1709: elif self.capability == 'usb_device': Line 1710: addr = self.getPciAddr() getUsbAddr maybe? Line 1711: try: Line 1712: source.appendChildWithArgs('vendor', None, addr['vendor']) Line 1713: source.appendChildWithArgs('vendor', None, addr['product']) Line 1714: except:
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsm hostdev: add support for USB devices ......................................................................
Patch Set 2: Code-Review-1 Verified-1
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10407/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11192/ : UNSTABLE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1362/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11349/ : SUCCESS
Martin Polednik has abandoned this change.
Change subject: vdsm hostdev: add support for USB devices ......................................................................
Abandoned
automation@ovirt.org has posted comments on this change.
Change subject: vdsm hostdev: add support for USB devices ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found
vdsm-patches@lists.fedorahosted.org