Merge pull request 'clan_vm_manager: Fix qmp shutdown command, bad socket error on retried shutdown' (#878) from Qubasa-main into main

This commit is contained in:
clan-bot
2024-02-25 18:21:43 +00:00
2 changed files with 11 additions and 16 deletions

View File

@@ -25,22 +25,18 @@ class VMAttr:
# the symlink will be dangling. # the symlink will be dangling.
self._qmp_socket: Path = state_dir / "qmp.sock" self._qmp_socket: Path = state_dir / "qmp.sock"
self._qga_socket: Path = state_dir / "qga.sock" self._qga_socket: Path = state_dir / "qga.sock"
self._qmp: QEMUMonitorProtocol | None = None
@contextmanager @contextmanager
def qmp_ctx(self) -> Generator[QEMUMonitorProtocol, None, None]: def qmp_ctx(self) -> Generator[QEMUMonitorProtocol, None, None]:
if self._qmp is None: rpath = self._qmp_socket.resolve()
rpath = self._qmp_socket.resolve() if not rpath.exists():
if not rpath.exists(): raise ClanError(f"qmp socket {rpath} does not exist. Is the VM running?")
raise ClanError( qmp = QEMUMonitorProtocol(str(rpath))
f"qmp socket {rpath} does not exist. Is the VM running?" qmp.connect()
)
self._qmp = QEMUMonitorProtocol(str(rpath))
self._qmp.connect()
try: try:
yield self._qmp yield qmp
finally: finally:
self._qmp.close() qmp.close()
class Machine: class Machine:

View File

@@ -286,12 +286,11 @@ class VM(GObject.Object):
try: try:
with self.machine.vm.qmp_ctx() as qmp: with self.machine.vm.qmp_ctx() as qmp:
qmp.command("system_powerdown") qmp.command("system_powerdown")
except (OSError, ClanError): except (OSError, ClanError) as ex:
# log.debug(f"QMP command 'system_powerdown' ignored. Error: {e}") log.debug(f"QMP command 'system_powerdown' ignored. Error: {ex}")
pass
# Try 2 times a second # Try 20 times to stop the VM
time.sleep(0.5) time.sleep(self.KILL_TIMEOUT / 20)
GLib.idle_add(self.emit, "vm_status_changed", self) GLib.idle_add(self.emit, "vm_status_changed", self)
log.debug(f"VM {self.get_id()} has stopped") log.debug(f"VM {self.get_id()} has stopped")