From bab34bce3bc2d74d4d12c2424be4cddbfdb154bf Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Mon, 20 Nov 2023 19:57:31 +0900 Subject: [PATCH] QemuHCK: Restart QMP along with QEMU Signed-off-by: Akihiko Odaki --- lib/setupmanagers/qemuhck/qemu_machine.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/setupmanagers/qemuhck/qemu_machine.rb b/lib/setupmanagers/qemuhck/qemu_machine.rb index 86b5e6dd..c38ee038 100644 --- a/lib/setupmanagers/qemuhck/qemu_machine.rb +++ b/lib/setupmanagers/qemuhck/qemu_machine.rb @@ -65,7 +65,6 @@ def initialize(scope, logger, machine, run_name, run_opts) @run_opts = run_opts @keep_alive = run_opts[:keep_alive] @delete_snapshot = run_opts[:create_snapshot] - @qmp = QMP.new(scope, @run_name, @logger) @machine.run_config_commands run_vm scope << self @@ -75,8 +74,16 @@ def keep_snapshot @delete_snapshot = false end - def run_qemu + def try_with_qmp + yield @qmp unless @qmp.nil? + rescue Errno::EPIPE, IOError + # Errno::EPIPE if the peer closed the socket. + # IOError if I closed the socket. + end + + def run_qemu(scope) @logger.info("Starting #{@run_name}") + @qmp = QMP.new(scope, @run_name, @logger) cmd = replace_string_recursive(@machine.dirty_command.join(' '), @machine.full_replacement_list) cmd += " -chardev socket,id=qmp,fd=#{@qmp.socket.fileno},server=off -mon chardev=qmp,mode=control" qemu = CmdRun.new(@logger, cmd, { @qmp.socket.fileno => @qmp.socket.fileno }) @@ -90,10 +97,10 @@ def run_vm @qemu_thread = Thread.new do loop do qemu = nil - Thread.handle_interrupt(Object => :on_blocking) do + ResourceScope.open do |scope| @machine.run_pre_start_commands - qemu = run_qemu + qemu = run_qemu(scope) qemu.wait_no_fail qemu = nil ensure @@ -115,7 +122,7 @@ def wait(...) def soft_abort SOFT_ABORT_RETRIES.times do - @qmp.powerdown + try_with_qmp(&:powerdown) return true unless @qemu_thread.join(ABORT_SLEEP).nil? @@ -125,7 +132,7 @@ def soft_abort end def hard_abort - @qmp.quit + try_with_qmp(&:quit) return true unless @qemu_thread.join(ABORT_SLEEP).nil?