Skip to content

Commit

Permalink
QemuHCK: Restart QMP along with QEMU
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiko Odaki <[email protected]>
  • Loading branch information
akihikodaki committed Nov 20, 2023
1 parent 4a74f9d commit bab34bc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/setupmanagers/qemuhck/qemu_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
Expand All @@ -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
Expand All @@ -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?

Expand All @@ -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?

Expand Down

0 comments on commit bab34bc

Please sign in to comment.