Skip to content

Commit

Permalink
virt: switch domain to Defined once migrated VM is stopped
Browse files Browse the repository at this point in the history
When the VM is stopped on the source after migration, set VM status to
Down and also switch domain to Defined state. The domain is not running
and not all calls are available -- some would result in libvirt error.
Defined domain will throw virdomain.NotConnectedError which should be
handled by the caller.

Added handling of this exception into Vm._destroyVm* methods.
The methods are not called on not connected domain so this is only a
preventive measure to be on the safe side.

It would be more practical to change the domain to Defined much sooner,
ideally in _handle_libvirt_domain_stopped(). That would avoid any delays
especially from calling hooks. But postponing the change and doing it
together with state change later makes the behavior more predictable and
more consistent.

Bug-Url: https://bugzilla.redhat.com/2000046
Signed-off-by: Vojtech Juranek <[email protected]>
Signed-off-by: Tomáš Golembiovský <[email protected]>
  • Loading branch information
vjuranek authored and mz-pdm committed Jul 13, 2022
1 parent 84ff9dc commit 7ff8ae2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/vdsm/virt/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,10 @@ def setDownStatus(self, code, exitReasonCode, exitMessage=''):
self.guestAgent.stop()
except Exception:
pass
finally:
if self._dom.connected:
self.log.info("Switching domain to Defined")
self._dom = virdomain.Defined(self.id, self._dom.dom)
if event_data:
self.send_status_event(**event_data)

Expand Down Expand Up @@ -5384,7 +5388,6 @@ def _destroyVmGraceful(self):
try:
self._dom.destroyFlags(libvirt.VIR_DOMAIN_DESTROY_GRACEFUL)
except libvirt.libvirtError as e:
# after successful migrations
if (self.lastStatus == vmstatus.DOWN and
e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN):
self.log.info("VM '%s' already down and destroyed", self.id)
Expand All @@ -5400,6 +5403,8 @@ def _destroyVmGraceful(self):
libvirt.VIR_ERR_SYSTEM_ERROR,):
safe_to_force = True
return response.error('destroyErr'), safe_to_force
except virdomain.NotConnectedError:
self.log.info("VM already down")
return response.success(), safe_to_force

def _destroyVmForceful(self):
Expand All @@ -5410,6 +5415,8 @@ def _destroyVmForceful(self):
"Failed to destroy VM '%s' forcefully (error=%i)",
self.id, e.get_error_code())
return response.error('destroyErr')
except virdomain.NotConnectedError:
self.log.info("VM already down")
return response.success()

def _deleteVm(self):
Expand Down

0 comments on commit 7ff8ae2

Please sign in to comment.