From 45054b6409d748094cb3f5781de5be0892ea5cd7 Mon Sep 17 00:00:00 2001 From: "xiaodong.jia" Date: Thu, 17 Jul 2025 19:46:36 +0800 Subject: [PATCH 1/2] simplify qemu shutdown script? --- lib/runners/qemu.nix | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/lib/runners/qemu.nix b/lib/runners/qemu.nix index f9514b12..a047c001 100644 --- a/lib/runners/qemu.nix +++ b/lib/runners/qemu.nix @@ -332,38 +332,8 @@ lib.warnIf (mem == 2048) '' '' ( ${writeQmp { execute = "qmp_capabilities"; }} - ${writeQmp { - execute = "input-send-event"; - arguments.events = [ { - type = "key"; - data = { - down = true; - key = { - type = "qcode"; - data = "ctrl"; - }; - }; - } { - type = "key"; - data = { - down = true; - key = { - type = "qcode"; - data = "alt"; - }; - }; - } { - type = "key"; - data = { - down = true; - key = { - type = "qcode"; - data = "delete"; - }; - }; - } ]; - }} - # wait for exit + ${writeQmp { execute = "system_powerdown"; }} + # wait for exit cat ) | \ ${pkgs.socat}/bin/socat STDIO UNIX:${socket},shut-none @@ -371,7 +341,7 @@ lib.warnIf (mem == 2048) '' else throw "Cannot shutdown without socket"; setBalloonScript = - if socket != null + if socket != null && balloon then '' VALUE=$(( $SIZE * 1024 * 1024 )) SIZE=$( ( From 463f4c268ce22234cca829affb27076a2ae0c3d9 Mon Sep 17 00:00:00 2001 From: "xiaodong.jia" Date: Thu, 17 Jul 2025 19:53:26 +0800 Subject: [PATCH 2/2] tweak balloon script a little --- lib/runners/qemu.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/runners/qemu.nix b/lib/runners/qemu.nix index a047c001..3b729dde 100644 --- a/lib/runners/qemu.nix +++ b/lib/runners/qemu.nix @@ -331,7 +331,7 @@ lib.warnIf (mem == 2048) '' then '' ( - ${writeQmp { execute = "qmp_capabilities"; }} + ${writeQmp { execute = "query-commands"; }} ${writeQmp { execute = "system_powerdown"; }} # wait for exit cat @@ -341,19 +341,20 @@ lib.warnIf (mem == 2048) '' else throw "Cannot shutdown without socket"; setBalloonScript = - if socket != null && balloon - then '' + if balloon + then + if socket != null then + '' VALUE=$(( $SIZE * 1024 * 1024 )) SIZE=$( ( - ${writeQmp { execute = "qmp_capabilities"; }} ${writeQmp { execute = "balloon"; arguments.value = 987; }} ) | sed -e s/987/$VALUE/ | \ ${pkgs.socat}/bin/socat STDIO UNIX:${socket},shut-none | \ - tail -n 1 | \ ${pkgs.jq}/bin/jq -r .data.actual \ ) echo $(( $SIZE / 1024 / 1024 )) - '' + '' + else throw "Cannot balloon without socket" else null; requiresMacvtapAsFds = true;