Martin Polednik has uploaded a new change for review.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
vdsm: add support for hot(un)plug of pci-passthrough devices
Hot(un)plug ability for pci-passthrough devices is extremely important in order to allow for hotunplugging/migrating/hotplugging workflow as VM cannot be migrated with pci device attached.
This patch implements the ability adding new API verbs: hotplugHostdev and hotunplugHostdev, which attempts to append/remove the device from domain XML and reports back the state.
Change-Id: I8fbf4a1d62789d9404e5977eb7eb01b17a1a43fb Signed-off-by: Martin Polednik mpoledni@redhat.com --- M client/vdsClient.py M vdsm/API.py M vdsm/BindingXMLRPC.py M vdsm/vm.py M vdsm_api/vdsmapi-schema.json 5 files changed, 166 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/23/22523/1
diff --git a/client/vdsClient.py b/client/vdsClient.py index d549500..f00180e 100644 --- a/client/vdsClient.py +++ b/client/vdsClient.py @@ -245,6 +245,14 @@ params = {'vmId': args[0], 'drive': drive} return self.ExecAndExit(self.s.hotunplugDisk(params))
+ def hotplugHostdev(self, args): + params = {'vmId': args[0], 'hostdevName': args[1]} + return self.ExecAndExit(self.s.hotplugNic(params)) + + def hotunplugHostdev(self, args): + params = {'vmId': args[0], 'hostdevName': args[2]} + return self.ExecAndExit(self.s.hotunplugNic(params)) + def do_changeCD(self, args): vmId = args[0] file = self._parseDriveSpec(args[1]) diff --git a/vdsm/API.py b/vdsm/API.py index 44d5817..51eb506 100644 --- a/vdsm/API.py +++ b/vdsm/API.py @@ -456,6 +456,40 @@
return curVm.hotunplugDisk(params)
+ def hotplugHostdev(self, params): + try: + utils.validateMinimalKeySet(params, ('vmId', 'hostdevName')) + except ValueError: + self.log.error('Missing one of required parameters: vmId, ' + 'hostdevName') + return {'status': {'code': errCode['MissParam']['status']['code'], + 'message': 'Missing one of required ' + 'parameters: vmId, hostdevName'}} + try: + curVm = self._cif.vmContainer[self._UUID] + except KeyError: + self.log.warning("vm %s doesn't exist", self._UUID) + return errCode['noVM'] + + return curVm.hotplugHostdev(params) + + def hotunplugHostdev(self, params): + try: + utils.validateMinimalKeySet(params, ('vmId', 'hostdevName')) + except ValueError: + self.log.error('Missing one of required parameters: vmId, ' + 'hostdevName') + return {'status': {'code': errCode['MissParam']['status']['code'], + 'message': 'Missing one of required ' + 'parameters: vmId, hostdevName'}} + try: + curVm = self._cif.vmContainer[self._UUID] + except KeyError: + self.log.warning("vm %s doesn't exist", self._UUID) + return errCode['noVM'] + + return curVm.hotunplugHostdev(params) + def migrate(self, params): """ Migrate a VM to a remote host. diff --git a/vdsm/BindingXMLRPC.py b/vdsm/BindingXMLRPC.py index 5bcd84c..847ceaf 100644 --- a/vdsm/BindingXMLRPC.py +++ b/vdsm/BindingXMLRPC.py @@ -279,6 +279,14 @@ vm = API.VM(params['vmId']) return vm.hotunplugNic(params)
+ def vmHotplugHostdev(self, params): + vm = API.VM(params['vmId']) + return vm.hotplugHostdev(params) + + def vmHotunplugHostdev(self, params): + vm = API.VM(params['vmId']) + return vm.hotunplugHostdev(params) + def vmUpdateDevice(self, vmId, params): vm = API.VM(vmId) return vm.vmUpdateDevice(params) @@ -861,6 +869,8 @@ (self.vmHotunplugDisk, 'hotunplugDisk'), (self.vmHotplugNic, 'hotplugNic'), (self.vmHotunplugNic, 'hotunplugNic'), + (self.vmHotplugHostdev, 'hotplugHostdev'), + (self.vmHotunplugHostdev, 'hotunplugHostdev'), (self.vmUpdateDevice, 'vmUpdateDevice'))
def getIrsMethods(self): diff --git a/vdsm/vm.py b/vdsm/vm.py index 90a6c0d..224bf7b 100644 --- a/vdsm/vm.py +++ b/vdsm/vm.py @@ -3183,6 +3183,84 @@
return {'status': doneCode, 'vmList': self.status()}
+ def hotplugHostdev(self, params): + hostdevName = params['hostdevName'] + hostdev = HostDevice(self.conf, self.log, **hostdevName) + hostdevXML = hostdev.getXML().toprettyxml(encoding='utf-8') + hostdev._deviceXML = hostdevXML + self.log.debug("Hotplug hostdev xml: %s", hostdevXML) + + try: + self._dom.attachDevice(hostdevXML) + except libvirt.libvirtError as e: + self.log.error("Hotplug failed", exc_info=True) + if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: + return errCode['noVM'] + return {'status': {'code': errCode['hotplugNic']['status']['code'], + 'message': e.message}} + else: + # FIXME! We may have a problem here if vdsm dies right after + # we sent command to libvirt and before save conf. In this case + # we will gather almost all needed info about this NIC from + # the libvirt during recovery process. + self._devices[HOSTDEV_DEVICES].append(hostdev) + with self._confLock: + self.conf['devices'].append(hostdev) + self.saveState() + + return {'status': doneCode, 'vmList': self.status()} + + def hotunplugHostdev(self, params): + hostdevName = params['hostdevName'] + + # Find hostdev object in vm's hostdev list + hostdev = None + for dev in self._devices[HOSTDEV_DEVICES][:]: + if dev.name == hostdevName: + hostdev = dev + break + + if hostdev: + hostdevXML = hostdev.getXML().toprettyxml(encoding='utf-8') + self.log.debug("Hotunplug hostdev xml: %s", hostdevXML) + self._devices[HOSTDEV_DEVICES].remove(hostdev) + else: + self.log.error("Hotunplug hostdev failed - hostdev not found: %s", + hostdevName) + return {'status': {'code': errCode['hotunplugNic'] + ['status']['code'], + 'message': "NIC not found"}} + + hostdevDev = None + for dev in self.conf['devices'][:]: + if (dev['type'] == HOSTDEV_DEVICES and + dev['name'] == hostdevName): + hostdevDev = dev + with self._confLock: + self.conf['devices'].remove(dev) + break + + self.saveState() + + try: + self._dom.detachDevice(hostdevXML) + except libvirt.libvirtError as e: + self.log.error("Hotunplug failed", exc_info=True) + if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: + return errCode['noVM'] + # Restore hostdev device in vm's conf and _devices + if hostdevDev: + with self._confLock: + self.conf['devices'].append(hostdevDev) + if hostdev: + self._devices[HOSTDEV_DEVICES].append(hostdev) + self.saveState() + return { + 'status': {'code': errCode['hotunplugNic']['status']['code'], + 'message': e.message}} + + return {'status': doneCode, 'vmList': self.status()} + def _lookupDeviceByAlias(self, devType, alias): for dev in self._devices[devType][:]: if dev.alias == alias: diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json index 1d4e499..85f2b28 100644 --- a/vdsm_api/vdsmapi-schema.json +++ b/vdsm_api/vdsmapi-schema.json @@ -5793,6 +5793,42 @@ 'returns': 'VmDefinition'}
## +# @VM.hotplugHostdev: +# +# Add a new host device to a running VM. +# +# @vmID: The UUID of the VM +# +# @hostdevName: The name of host's device +# +# Returns: +# The VM definition, as updated +# +# Since: 4.14.0 +## +{'command': {'class': 'VM', 'name': 'hotplugHostdev'}, + 'data': {'vmID': 'UUID', 'hostdevName': 'str'}, + 'returns': 'VmDefinition'} + +## +# @VM.hotunplugHostdev: +# +# Remove a host device from a running VM. +# +# @vmID: The UUID of the VM +# +# @hostdevName: The name of host's device +# +# Returns: +# The VM definition, as updated +# +# Since: 4.14.0 +## +{'command': {'class': 'VM', 'name': 'hotunplugHostdev'}, + 'data': {'vmID': 'UUID', 'hostdevName': 'str'}, + 'returns': 'VmDefinition'} + +## # @MigrateMode: # # An enumeration of VM migration modes.
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 1:
Build Successful
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/6159/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/5372/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/6263/ : SUCCESS
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 2:
Build Successful
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/6160/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/5373/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/6264/ : SUCCESS
Vinzenz Feenstra has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 2: Code-Review-1
(2 comments)
.................................................... File client/vdsClient.py Line 246: return self.ExecAndExit(self.s.hotunplugDisk(params)) Line 247: Line 248: def hotplugHostdev(self, args): Line 249: params = {'vmId': args[0], 'hostdevName': args[1]} Line 250: return self.ExecAndExit(self.s.hotplugNic(params)) hotplugNic? Line 251: Line 252: def hotunplugHostdev(self, args): Line 253: params = {'vmId': args[0], 'hostdevName': args[2]} Line 254: return self.ExecAndExit(self.s.hotunplugNic(params))
Line 250: return self.ExecAndExit(self.s.hotplugNic(params)) Line 251: Line 252: def hotunplugHostdev(self, args): Line 253: params = {'vmId': args[0], 'hostdevName': args[2]} Line 254: return self.ExecAndExit(self.s.hotunplugNic(params)) hotunplugNic? Line 255: Line 256: def do_changeCD(self, args): Line 257: vmId = args[0] Line 258: file = self._parseDriveSpec(args[1])
Martin Polednik has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 2:
(1 comment)
.................................................... File client/vdsClient.py Line 246: return self.ExecAndExit(self.s.hotunplugDisk(params)) Line 247: Line 248: def hotplugHostdev(self, args): Line 249: params = {'vmId': args[0], 'hostdevName': args[1]} Line 250: return self.ExecAndExit(self.s.hotplugNic(params)) noted, will be fixed in next patchset (same for below) Line 251: Line 252: def hotunplugHostdev(self, args): Line 253: params = {'vmId': args[0], 'hostdevName': args[2]} Line 254: return self.ExecAndExit(self.s.hotunplugNic(params))
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 3:
Build Successful
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/6509/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/5616/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/6422/ : SUCCESS
Itamar Heim has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 3:
ping
Martin Polednik has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 3:
waiting for http://gerrit.ovirt.org/#/c/22462/ in case of changes
Itamar Heim has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of pci-passthrough devices ......................................................................
Patch Set 3:
ping
Francesco Romani has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Patch Set 4:
(3 comments)
initial review - vm.py not yet considered
http://gerrit.ovirt.org/#/c/22523/4/vdsm/rpc/BindingXMLRPC.py File vdsm/rpc/BindingXMLRPC.py:
Line 1000: vmUpdateDevice vmUpdateDevice is listed twice
http://gerrit.ovirt.org/#/c/22523/4/vdsm/rpc/vdsmapi-schema.json File vdsm/rpc/vdsmapi-schema.json:
Line 6627: # Line 6628: # Returns: Line 6629: # The VM definition, as updated Line 6630: # Line 6631: # Since: 4.14.0 4.15.0 Line 6632: ## Line 6633: {'command': {'class': 'VM', 'name': 'hotplugHostdev'}, Line 6634: 'data': {'vmID': 'UUID', 'hostdevName': 'str'}, Line 6635: 'returns': 'VmDefinition'}
Line 6649: ditto
Martin Polednik has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Patch Set 4:
(1 comment)
http://gerrit.ovirt.org/#/c/22523/4/vdsm/rpc/vdsmapi-schema.json File vdsm/rpc/vdsmapi-schema.json:
Line 6627: # Line 6628: # Returns: Line 6629: # The VM definition, as updated Line 6630: # Line 6631: # Since: 4.14.0
4.15.0
shouldn't that be 4.16.0 already? Line 6632: ## Line 6633: {'command': {'class': 'VM', 'name': 'hotplugHostdev'}, Line 6634: 'data': {'vmID': 'UUID', 'hostdevName': 'str'}, Line 6635: 'returns': 'VmDefinition'}
oVirt Jenkins CI Server has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Patch Set 4:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/9528/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/10312/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit/10468/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_verify-error-codes_merged/5394/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_merged/3552/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/951/ : SUCCESS
Francesco Romani has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Patch Set 4:
(1 comment)
http://gerrit.ovirt.org/#/c/22523/4/vdsm/rpc/vdsmapi-schema.json File vdsm/rpc/vdsmapi-schema.json:
Line 6627: # Line 6628: # Returns: Line 6629: # The VM definition, as updated Line 6630: # Line 6631: # Since: 4.14.0
shouldn't that be 4.16.0 already?
sure, my comment was outdated as well :) Line 6632: ## Line 6633: {'command': {'class': 'VM', 'name': 'hotplugHostdev'}, Line 6634: 'data': {'vmID': 'UUID', 'hostdevName': 'str'}, Line 6635: 'returns': 'VmDefinition'}
Jenkins CI RO has abandoned this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Abandoned
Abandoned due to no activity - please restore if still relevant
Jenkins CI RO has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Patch Set 4:
Abandoned due to no activity - please restore if still relevant
automation@ovirt.org has posted comments on this change.
Change subject: vdsm: add support for hot(un)plug of host devices ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found
vdsm-patches@lists.fedorahosted.org