Skip to content

Simplify qemu shutdown script? #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 9 additions & 38 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -331,59 +331,30 @@ lib.warnIf (mem == 2048) ''
then
''
(
${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 = "query-commands"; }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your motivation to change this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below, I did not know this was required.

${writeQmp { execute = "system_powerdown"; }}
# wait for exit
cat
) | \
${pkgs.socat}/bin/socat STDIO UNIX:${socket},shut-none
''
else throw "Cannot shutdown without socket";

setBalloonScript =
if socket != null
then ''
if balloon
then
if socket != null then
''
Comment on lines +344 to +347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change this again, we can drop the change in the last commit, to make the history cleaner.

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 | \
Comment on lines -378 to -382
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test that this did not break anything?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because I removed the echo capabilities line, which doesn't do anything because it gets tailed away. That line doesn't seem to do anything at all because the user won't be able to see the output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry I just read the docs; I did not realise you had to execute capabilities to establish a connection, what a strange requirement

${pkgs.jq}/bin/jq -r .data.actual \
)
echo $(( $SIZE / 1024 / 1024 ))
''
''
else throw "Cannot balloon without socket"
else null;

requiresMacvtapAsFds = true;
Expand Down