5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2024-12-22 13:34:06 +03:00
Commit Graph

23 Commits

Author SHA1 Message Date
Wolfgang Bumiller
812d22ee21 fix #5714: fix calloc parameter ordering
It's (count, size), not (size, count).
Newer compilers complain bout this.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-09-23 10:30:01 +02:00
Fiona Ebner
81a8c4e5ee qmeventd: also treat 'prelaunch' and 'suspended' states as active
Otherwise, a VM in those states would be terminated after a backup
in handle_qmp_return() with QMP 'quit', which is pretty bad in case
of the 'suspended' state.

Does not change the fact that a VM started in prelaunch mode for
backup is terminated later (that is handled by the Perl code).

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-04-23 16:46:20 +02:00
Fiona Ebner
742da46a44 qmeventd: VMID from PID: avoid goto
If strtol() returns an errno, make sure not to print the error message
twice after the refactoring.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-07-17 11:30:49 +02:00
Fiona Ebner
aaa77c9f7a qmeventd: VMID from PID: don't fail immediately when encountering unexpected entry
While such entries shuoldn't exist in practice without manually
messing around, it's not hard to imagine, and there's still a good
chance the actual VMID can still be found.

It's still unexpected to encounter such entries so keep the log line.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-07-17 11:30:48 +02:00
Fiona Ebner
a9f2e2d6f9 qmeventd: further improve getting VMID from PID
by also expecting the ".scope" part and trying the next entry if it is
not present instead of immediately failing.

It's still unexpected to encounter such entries, so keep the log line.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-07-17 11:30:47 +02:00
Fiona Ebner
d0b587533c qmeventd: improve getting VMID from PID in presence of legacy cgroup entries
On a hybrid cgroup system, the /proc/<PID>/cgroup file looks like

> 13:pids:/qemu.slice/110.scope
> 12:perf_event:/
> 11:devices:/qemu.slice
> 10:misc:/
> 9:hugetlb:/
> 8:freezer:/
> 7:cpu,cpuacct:/qemu.slice/110.scope
> 6:memory:/qemu.slice/110.scope
> 5:rdma:/
> 4:cpuset:/
> 3:blkio:/qemu.slice
> 2:net_cls,net_prio:/
> 1:name=systemd:/qemu.slice/110.scope
> 0::/qemu.slice/110.scope

but the order doesn't seem to be deterministic, so it can happen that
an entry like '11:devices:/qemu.slice' is the first to match the
'/qemu.slice' part, which previously made the code expect to find the
VMID.

To improve detection, as a first step, match the trailing slash too.

Reported in the community forum:
https://forum.proxmox.com/threads/129320/post-571654

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-07-17 11:30:45 +02:00
Fiona Ebner
502870a04c qmeventd: extract vmid from cgroup file instead of cmdline
This is the single remaining user of the id argument. The id argument
is a Proxmox-specific extension to QEMU, which we'd like to drop to
reduce our differences with upstream QEMU.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-06-07 19:37:09 +02:00
Fiona Ebner
2d7a026e99 fix #4737: qmeventd: gracefully handle interrupted epoll_wait call
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-05-24 17:11:01 +02:00
Dominik Csapak
b5c39b22f0 qmeventd: send QMP 'quit' command instead of SIGTERM
this is functionally the same, but sending SIGTERM has the ugly side
effect of printing the following to the log:

> QEMU[<pid>]: kvm: terminating on signal 15 from pid <pid> (/usr/sbin/qmeventd)

while sending a QMP quit command does not.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2022-09-23 12:00:22 +02:00
Dominik Csapak
0a1641aee5 qmeventd: rework 'forced_cleanup' handling and set timeout to 60s
currently, the 'forced_cleanup' (sending SIGKILL to the qemu process),
is intended to be triggered 5 seconds after sending the initial shutdown
signal (SIGTERM) which is sadly not enough for some setups.

Accidentally, it could be triggered earlier than 5 seconds, if a
SIGALRM triggers in the timespan directly before setting it again.

Also, this approach means that depending on when machines are shutdown
their forced cleanup may happen after 5 seconds, or any time after, if
new vms are shut off in the meantime.

Improve this situation by reworking the way we deal with this cleanup.
We save the pidfd, time incl. timeout in the Client, and set a timeout
to 'epoll_wait' of 10 seconds, which will then trigger a forced_cleanup.
Remove entries from the forced_cleanup list when that entry is killed,
or when the normal cleanup took place.

To improve the shutdown behaviour, increase the default timeout to 60
seconds, which should be enough, but add a commandline toggle where
users can set it to a different value.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2022-09-23 12:00:20 +02:00
Thomas Lamprecht
42edf94804 qmeventd: fix more early broken lines
increases readabillity, and up to 100 cc is just fine

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-12 09:52:51 +01:00
Thomas Lamprecht
654553a973 qmeventd: fix linker flags order
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-11 18:02:18 +01:00
Thomas Lamprecht
a2488e4c22 qmeventd: allow up to 100 columns per line
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-11 17:21:30 +01:00
Thomas Lamprecht
6d4f89b6a4 qmeventd: catch calloc error
even if close to impossible to happen, NULL dereferences are never
nice..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-11 16:48:53 +01:00
Thomas Lamprecht
aedf820870 qmeventd: rework description, mention s.reiter as author
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-11 16:03:31 +01:00
Thomas Lamprecht
649dbf4285 qmeventd: change license to AGPLv3 update copyright
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-11 16:02:44 +01:00
Stefan Reiter
0a279963b6 qmeventd: explicitly close() pidfds
In most circumstances a pidfd gets closed automatically once the child
dies, and that *should* be guaranteed by us calling SIGKILL - however,
it seems that sometimes that doesn't happen, leading to leaked file
descriptors[0].

Also add a small note to verbose mode showing when the late-cleanup
actually happens, helped during debug.

[0] https://forum.proxmox.com/threads/cannot-shutdown-vm.83911/

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2021-02-11 14:06:40 +01:00
Dominik Csapak
e8e0fd93bf qmeventd: flush after verbose printing
if one would try to use -v in a systemd service, systemd would disable
line buffering for stdout and no output would happen (until the buffer
is full)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-11-25 14:33:38 +01:00
Thomas Lamprecht
c0d096321a stop qmeventd after pve-guests and pve-ha-lrm services
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Co-developed-by: Stefan Reiter <s.reiter@proxmox.com>
2020-11-12 17:06:33 +01:00
Stefan Reiter
4c500f1696 qmeventd: add last-ditch effort SIGKILL cleanup
'alarm' is used to schedule an additionaly cleanup round 5 seconds after
sending SIGTERM via terminate_client. This then sends SIGKILL via a
pidfd (if supported by the kernel) or directly via kill, making sure
that the QEMU process is *really* dead and won't be left behind in an
undetermined state.

This shouldn't be an issue under normal circumstances, but can help
avoid dead processes lying around if QEMU hangs after SIGTERM.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-11-05 11:22:47 +01:00
Stefan Reiter
3ff8500175 qmeventd: add handling for -no-shutdown QEMU instances
We take care of killing QEMU processes when a guest shuts down manually.
QEMU will not exit itself, if started with -no-shutdown, but it will
still emit a "SHUTDOWN" event, which we await and then send SIGTERM.

This additionally allows us to handle backups in such situations. A
vzdump instance will connect to our socket and identify itself as such
in the handshake, sending along a VMID which will be marked as backing
up until the file handle is closed.

When a SHUTDOWN event is received while the VM is backing up, we do not
kill the VM. And when the vzdump handle is closed, we check if the
guest has started up since, and only if it's determined to still be
turned off, we then finally kill QEMU.

We cannot wait for QEMU directly to finish the backup (i.e. with
query-backup), as that would kill the VM too fast for vzdump to send the
last 'query-backup' to mark the backup as successful and done.

For handling 'query-status' messages sent to QEMU, a state-machine-esque
protocol is implemented into the Client struct (ClientState). This is
necessary, since QMP works asynchronously, and results arrive on the
same channel as events and even the handshake.

For referencing QEMU Clients from vzdump messages, they are kept in a
hash table. This requires linking against glib.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-11-05 11:22:47 +01:00
Thomas Lamprecht
4478c2ae2f buildsys: remove unused or duplicate directories
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-09-24 19:06:07 +02:00
Thomas Lamprecht
8752e5a3ec move qmeventd to own directory
It's really not nice if such many files, source code, meta-files, …
linger around in the top level directory..

Also, cleanup the build a bit, i.e., use LDFLAGS as dpkg-buildpackage
can set some LDFLAGS so it'd be nice if both CFLAFGS and LDFLAGS have
the same (related) ones.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-09-24 18:57:54 +02:00