Subject: qemu-guest-agent: Guest agent does not shut down the guest when requested to

From: Fabio Muzzi <[email-masked]>
Date: Sat, 20 Nov 2021 20:06:15 +0100

Package: qemu-guest-agent
Version: 1:5.2+dfsg-11+deb11u1
Severity: grave
Justification: renders package unusable
X-Debbugs-Cc: [email-masked]

Dear Maintainer,

I have installed a Devuan 4 guest in a PVE 7.1 host, with Quemu guest
enabled in PVE and the guest agent package installed in the guest.

When commanding a guest shutdown from the host, a shutdown command is
sent to the guest agent (because the host knows the guest has the agent
installed, otherwise it would use an ACPI command to "press the power
button").

The guest gets the command, and writes in the syslog the following line:

Nov 20 18:50:09 fileserver qemu-ga: info: guest-shutdown called, mode:
(null)

Then a shutdown should be initiated, but nothing happens. The guest
keeps running.

I can send multiple shutdown commands from the host, they are all
received by the guest, but nothing happens, they just get logged in the
syslog.

I would expect the guest agent to start a shutdown.

Tried installing a Debian 11 virtual on the same PVE host, and the
shutdown command works as expected, logging the same line and then
immediately commanding a shutdown.

I suppose that this version of qemu-ga requires systemd to actually command a shutdown? 

Qemu-ga is version 5.2.0

It worked in Devuan 3.

Kind regards

-- System Information:
Distributor ID:	Devuan
Description:	Devuan GNU/Linux 4 (chimaera)
Release:	4
Codename:	chimaera
Architecture: x86_64

Kernel: Linux 5.10.0-9-amd64 (SMP w/2 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)
LSM: AppArmor: enabled

Versions of packages qemu-guest-agent depends on:
ii  init-system-helpers   1.60+devuan1
ii  libc6                 2.31-13+deb11u2
ii  libeudev1 [libudev1]  3.2.9-10~chimaera1
ii  libglib2.0-0          2.66.8-1
ii  liburing1             0.7-3
ii  lsb-base              11.1.0

qemu-guest-agent recommends no packages.

qemu-guest-agent suggests no packages.

-- no debconf information

---

From: Fabio Muzzi <[email-masked]>
Date: Sat, 20 Nov 2021 23:54:29 +0100

I have gone further and run gdb.

It seems that the agent actually tries to call /sbin/shutdown with the following parameters:

"-h -P +0 hypervisor initiated shutdown"

But if I run shutdown manually with  these parameters, I get an error and the help message shows up:

root@fileserver:/sbin# /sbin/shutdown -h -P +0 hypervisor initiated shutdown
Usage:    shutdown [-akrhPHfFnc] [-t sec] time [warning message]
                   -a:      use /etc/shutdown.allow
                   -k:      don't really shutdown, only warn.
                   -r:      reboot after shutdown.
                   -h:      halt after shutdown.
                   -P:      halt action is to turn off power.
                            can only be used along with -h flag.
                   -H:      halt action is to just halt.
                            can only be used along with -h flag.
                   -f:      do a 'fast' reboot (skip fsck).
                   -F:      Force fsck on reboot.
                   -n:      do not go through "init" but go down real fast.
                   -c:      cancel a running shutdown.
                   -q:      quiet mode - display fewer shutdown warnings.
                   -Q:      full quiet mode - display only final shutdown warning.
                   -t secs: delay between warning and kill signal.
                   ** the "time" argument is mandatory! (try "now") **

So it seems that /sbin/shutdown does not like the command line that qemu-agent uses.

It seems that the Devuan shutdown command wants a mandatory "time", so for example

shutdown -h -P now

works.

But the qemu agent uses a syntax that is wrong for the Devuan shutdown binary, while it works fine for the systemd-infested shutdown that is just a link to systemcl (in Debian 11).

A workaroung is to rename /sbin/shutdown and create a script that calls shutdown with a command line that it accepts, like:

/sbin/shutdown -h -P now hypervisor initiated shutdown

Notice the "now" instead of the "+0" in the arguments.

-- 
Fabio "Kurgan" Muzzi

- IZ4UFQ -

"Il massimo danno con il minimo sforzo"

---

From: Mark Hindley <[email-masked]>
Date: Sun, 21 Nov 2021 09:27:57 +0000

Control: tags -1 debian

Fabio,

Thanks for this and debugging what is going on.

> "-h -P +0 hypervisor initiated shutdown"

To me, this is a bug in qemu-agent which is assuming the guest is running
systemd.

qemu-agent is not a forked package and Devuan uses Debian's packages directly
without recompilation. So, in principle, this is an issue that needs reporting
to Debian's BTS to be fixed there. However, if there is a configuration option
to change the shutdown command sent, we might be able to override that in
Devuan.  I don't use the package myself, so it would be helpful if you could
investigate that?

Thanks

Mark

---

From: Mark Hindley <[email-masked]>
Date: Sun, 21 Nov 2021 12:32:51 +0000

Control: reassign -1 src:sysvinit
Control: found -1 2.96-7+devuan1
Control: notfount -1 3.00-1+devuan1
Control: tags -1 =chimaera

Fabio,

> > "-h -P +0 hypervisor initiated shutdown"

As rrq just pointed out on #devuan-infra, this is actually a bug in sysvinit
/sbin/shutdown not parsing the +0 argument.

This was fixed upstream in version 2.98:

sysvinit (2.98) released; urgency=low

    * Fixed time parsing in shutdown when there is a + in front of a 0 time offset.
      Commands with a positive time offset (+1) would work but +0 fails.
      This has been corrected by Arkadiusz Miskiewicz.

Reassigning and setting versions.

I will investigate backporting to chimaera.

Thanks.

Mark

---

From: Mark Hindley <[email-masked]>
Date: Sun, 21 Nov 2021 12:48:57 +0000

Control: found -1 2.96-7+devuan1
Control: notfound -1 3.00-1+devuan1

Fabio,

> I will investigate backporting to chimaera.

I have just added src:sysvinit 3.00-1+devuan1 to chimaera-backports.

Can you try that version, please?

Thanks.

Mark

---

From: Mark Hindley <[email-masked]>
Date: Sun, 21 Nov 2021 14:05:02 +0000

reassign 633 sysvinit
found 633 2.96-7+devuan1
notfound 633 3.00-1+devuan1
fixed 633 3.00-1+devuan1