Skip to content
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

qemu-ga: fix working guest-shutdown #44836

Merged
merged 1 commit into from Aug 15, 2018
Merged

qemu-ga: fix working guest-shutdown #44836

merged 1 commit into from Aug 15, 2018

Conversation

Izorkin
Copy link
Contributor

@Izorkin Izorkin commented Aug 9, 2018

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@xeji
Copy link
Contributor

xeji commented Aug 9, 2018

Version update is a duplicate of #44711.

--replace '"/sbin/shutdown"' '"/run/current-system/sw/bin/shutdown"' \
--replace '"/sbin/hwclock"' '"/run/current-system/sw/bin/hwclock"'
'';

Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain which bug you are trying to fix here and how to reproduce that bug.
Note that /run/current-system/sw/bin only exists on NixOS systems.

Copy link
Contributor Author

@Izorkin Izorkin Aug 9, 2018

Choose a reason for hiding this comment

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

If runnig command qm agent <vmid> shutdown (host system Proxmox) an error -

{
   "error" : {
      "class" : "GenericError",
      "desc" : "child process has failed to shutdown"
   }
}

strace on on the guest system

socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5
connect(5, {sa_family=AF_UNIX, sun_path="/dev/log"}, 110) = 0
sendto(5, "<14>Aug  9 23:39:10 qemu-ga: inf"..., 70, MSG_NOSIGNAL, NULL, 0) = 70
clone(strace: Process 734 attached
child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fbc4b79b5d0) = 734
[pid   485] wait4(734,  <unfinished ...>
[pid   734] set_robust_list(0x7fbc4b79b5e0, 24) = 0
[pid   734] setsid()                    = 734
[pid   734] openat(AT_FDCWD, "/dev/null", O_RDWR) = 6
[pid   734] dup2(6, 0)                  = 0
[pid   734] close(6)                    = 0
[pid   734] openat(AT_FDCWD, "/dev/null", O_RDWR) = 6
[pid   734] dup2(6, 1)                  = 1
[pid   734] close(6)                    = 0
[pid   734] openat(AT_FDCWD, "/dev/null", O_RDWR) = 6
[pid   734] dup2(6, 2)                  = 2
[pid   734] close(6)                    = 0
[pid   734] execve("/sbin/shutdown", ["shutdown", "-h", "-P", "+0", "hypervisor initiated shutdown"], 0x7ffeff9da0f8 /* 6 vars */) = -1 ENOENT (No such file or directory)
[pid   734] exit_group(1)               = ?
[pid   734] +++ exited with 1 +++
<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 734

By default running command /sbin/shutdown - the result is an error.

Copy link
Member

Choose a reason for hiding this comment

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

You can add a execle("/run/current-system/sw/bin/shutdown, ....); right after: https://github.com/qemu/qemu/blob/master/qga/commands-posix.c#L106
This would then be executed when /sbin/shutdown fails.

@Izorkin Izorkin changed the title qemu: update version and fix working guest-shutdown qemu-ga: fix working guest-shutdown Aug 9, 2018
@Izorkin
Copy link
Contributor Author

Izorkin commented Aug 10, 2018

Updated commit.


+ execle("/run/current-system/sw/bin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
+ "hypervisor initiated shutdown", (char*)NULL, environ);
execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
Copy link
Member

Choose a reason for hiding this comment

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

This assumes it is running on NixOS, why would this be the case? Packages should also be able to run on other OSes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If error running command /run/current-system/sw/bin/shutdown, it will running /sbin/shutdown

@dezgeg
Copy link
Contributor

dezgeg commented Aug 15, 2018

@GrahamcOfBorg test simple

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: tests.simple

Partial log (click to expand)

machine# [    6.262847] systemd-shutdown[1]: Detaching DM devices.
machine# [    6.265983] ACPI: Preparing to enter system sleep state S5
machine# [    6.266756] reboot: Power down
vde_switch: EOF data port: Interrupted system call
collecting coverage data
syncing
test script finished in 7.19s
vde_switch: EOF on stdin, cleaning up and exiting
cleaning up
/nix/store/x3n49rh6ghzsfd4w1ymdz32ajm3yx1h9-vm-test-run-simple

@dezgeg dezgeg merged commit e2c9852 into NixOS:master Aug 15, 2018
@Izorkin
Copy link
Contributor Author

Izorkin commented Aug 15, 2018

Thanks!

@Izorkin Izorkin deleted the qemu-ga branch August 15, 2018 08:20
@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: tests.simple

Partial log (click to expand)

machine# [   23.878767] systemd-shutdown[1]: All loop devices detached.
machine# [   23.883354] systemd-shutdown[1]: Detaching DM devices.
machine# [   23.913106] reboot: Power down
vde_switch: EOF data port: Interrupted system call
collecting coverage data
syncing
test script finished in 24.80s
vde_switch: EOF on stdin, cleaning up and exiting
cleaning up
/nix/store/xsr1ybnli1k8s73yvwpq8jqi7j3kf9i9-vm-test-run-simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants