[elbe-devel] [PATCH 3/3] initvmaction: fix race condition during initvm shutdown

Manuel Traut manut at linutronix.de
Wed Mar 13 17:56:50 CET 2019


Sometimes "elbe initvm stop" fails:

Traceback (most recent call last):
  File "/usr/bin/elbe", line 55, in <module>
    cmdmod.run_command(sys.argv[2:])
  File "/usr/lib/python2.7/dist-packages/elbepack/commands/initvm.py", line 91, in run_command
    action.execute(directory, opt, args[1:])
  File "/usr/lib/python2.7/dist-packages/elbepack/initvmaction.py", line 188, in execute
    raise e
libvirt.libvirtError: Requested operation is not valid: domain is not running

There are two states in libvirt. SHUTOFF that is used if the machine is
off and SHUTDOWN during the machine is going down.

The code sends a "shutdown" commmand to the machine in a loop.
After sending the shutdown command a machine is expected to be in the state
SHUTDOWN and than in the state SHUTOFF. Currently the code expects the
machine only to be in the SHUTOFF state, but not in the SHUTDOWN state.

Don't raise an error if the machine is in the SHUTDOWN state.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/initvmaction.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 98ccdd00..f15b65cd 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -182,9 +182,10 @@ class StopAction(InitVMAction):
                 try:
                     self.initvm.shutdown()
                 except libvirt.libvirtError as e:
-                    # ignore that initvm is already shutdown but raise all
-                    # other errors
-                    if self.initvm_state() != libvirt.VIR_DOMAIN_SHUTOFF:
+                    # ignore that initvm is already shutoff or is currently
+                    # shutting down but raise all other errors
+                    if (self.initvm_state() != libvirt.VIR_DOMAIN_SHUTOFF and
+                        self.initvm_state() != libvirt.VIR_DOMAIN_SHUTDOWN):
                         raise e
                 sys.stdout.write("*")
                 sys.stdout.flush()
-- 
2.20.1




More information about the elbe-devel mailing list