You are not logged in.

#1 2023-10-19 20:08:30

kero
Member
Registered: 2012-08-26
Posts: 43

libvirt-guests.service fails in suspending a VM

Hi,

I'm trying to set up libvirt-guests.service to correctly suspend my KVM/QEMU VM (containing a Home Assistant instance) when rebooting the host (an Intel NUC running Archlinux). I'm trying to do this following this page: https://wiki.archlinux.org/title/libvir … e_a_domain

Now, the problem is that on host shutdown (and then on booting) I'm getting errors:

# journalctl -u libvirt-guests.service
[...]
oct. 19 15:50:19 kdomserv systemd[1]: Stopping Suspend/Resume Running libvirt Guests...
oct. 19 15:50:19 kdomserv libvirt-guests.sh[10340]: Running guests on default URI:
oct. 19 15:50:19 kdomserv libvirt-guests.sh[10320]: linux2022
oct. 19 15:50:19 kdomserv libvirt-guests.sh[10427]: Suspending guests on default URI...
oct. 19 15:50:19 kdomserv libvirt-guests.sh[10320]: Suspending linux2022: ...
oct. 19 15:50:24 kdomserv libvirt-guests.sh[10320]: Suspending linux2022: ...
oct. 19 15:50:25 kdomserv libvirt-guests.sh[10450]: error: Disconnected from qemu:///system due to end of file
oct. 19 15:50:25 kdomserv libvirt-guests.sh[10450]: error: Failed to save domain '6fe4edf8-a076-406a-a4b2-9c6fa04f2f28' state
oct. 19 15:50:25 kdomserv libvirt-guests.sh[10450]: error: End of file while reading data: Input/output error
oct. 19 15:50:26 kdomserv systemd[1]: libvirt-guests.service: Control process exited, code=exited, status=1/FAILURE
oct. 19 15:50:26 kdomserv systemd[1]: libvirt-guests.service: Failed with result 'exit-code'.
oct. 19 15:50:26 kdomserv systemd[1]: Stopped Suspend/Resume Running libvirt Guests.
-- Boot 93de70129dca4d3bb40f934bf9282069 --
oct. 19 15:50:41 kdomserv systemd[1]: Starting Suspend/Resume Running libvirt Guests...
oct. 19 15:50:41 kdomserv libvirt-guests.sh[421]: Resuming guests on default URI...
oct. 19 15:50:42 kdomserv libvirt-guests.sh[428]: Resuming guest linux2022:
oct. 19 15:50:42 kdomserv libvirt-guests.sh[434]: error: Failed to start domain 'linux2022'
oct. 19 15:50:42 kdomserv libvirt-guests.sh[434]: error: erreur interne : le processus s'est arrêté pendant la connexion au moniteur: 2023-10-19T13:50:41.914772Z qemu-system-x86_64: warning: Spice: ../spice-0.15.2/server/reds.cpp:2551:r>
oct. 19 15:50:42 kdomserv libvirt-guests.sh[434]: 2023-10-19T13:50:41.914872Z qemu-system-x86_64: warning: Spice: ../spice-0.15.2/server/reds.cpp:3441:do_spice_init: Failed to open SPICE sockets
oct. 19 15:50:42 kdomserv libvirt-guests.sh[434]: 2023-10-19T13:50:41.915428Z qemu-system-x86_64: failed to initialize spice server
oct. 19 15:50:42 kdomserv systemd[1]: libvirt-guests.service: Main process exited, code=exited, status=1/FAILURE

I can't figure out what's preventing libvirt-guests.service to suspend my VM.

Note that I can succesfully suspend the VM with "virsh managedsave". If I can't solve the problem I'm thinking about writing a simple systemd service using virsh but before that, I'd like to understand what's going on.

Thanks for reading.

Offline

#2 2023-10-20 13:12:30

kero
Member
Registered: 2012-08-26
Posts: 43

Re: libvirt-guests.service fails in suspending a VM

Ok,

Finally some exploration seems to show that the libvirt-guests.service conflicts with some other systemd service/unit. The service fails right after some QEMU shutdown messages. Here is the relevant part in journalctl (while libvirt-guests.service is suspending the VM):

oct. 20 12:04:11 kdomserv systemd[1]: machine-qemu\x2d1\x2dlinux2022.scope: Deactivated successfully.
oct. 20 12:04:11 kdomserv systemd[1]: Stopped Virtual Machine qemu-1-linux2022.
oct. 20 12:04:11 kdomserv systemd[1]: machine-qemu\x2d1\x2dlinux2022.scope: Consumed 2min 18.295s CPU time.
oct. 20 12:04:11 kdomserv systemd[1]: Stopping Virtualization daemon...
oct. 20 12:04:11 kdomserv libvirt-guests.sh[1120]: erreur : Déconnecté de qemu:///system en raison de la fin du fichier
oct. 20 12:04:11 kdomserv libvirt-guests.sh[1120]: erreur : Échec de la sauvegarde de l'état du domaine '6fe4edf8-a076-406a-a4b2-9c6fa04f2f28'
oct. 20 12:04:11 kdomserv libvirt-guests.sh[1120]: erreur : Fin du fichier pendant la lecture des données: Erreur d'entrée/sortie

Any idea how to solve this ?

It looks like a packaging bug to me, so I posted a bugreport: https://bugs.archlinux.org/task/80030

Last edited by kero (2023-10-20 13:15:09)

Offline

#3 2023-10-20 19:22:19

kero
Member
Registered: 2012-08-26
Posts: 43

Re: libvirt-guests.service fails in suspending a VM

I did some further exploration on this. Thinking that the service file was maybee missing some dependencies, I added the line "After=libvirtd.service" in /usr/lib/systemd/system/libvirt-guests.service.

That solves the first part of the problem (suspending the VM):

# journalctl -u libvirt-guests.service
[...]
oct. 20 16:30:58 kdomserv systemd[1]: Stopping Suspend/Resume Running libvirt Guests...
oct. 20 16:30:58 kdomserv libvirt-guests.sh[895]: Exécution des invités sur default URI :
oct. 20 16:30:58 kdomserv libvirt-guests.sh[870]: linux2022
oct. 20 16:30:59 kdomserv libvirt-guests.sh[981]: Suspendre les invités sur default URI...
oct. 20 16:30:59 kdomserv libvirt-guests.sh[870]: Suspendre linux2022: ...
oct. 20 16:31:04 kdomserv libvirt-guests.sh[870]: Suspendre linux2022: ...
oct. 20 16:31:05 kdomserv libvirt-guests.sh[870]: Suspendre linux2022: terminé
oct. 20 16:31:05 kdomserv systemd[1]: libvirt-guests.service: Deactivated successfully.
oct. 20 16:31:05 kdomserv systemd[1]: Stopped Suspend/Resume Running libvirt Guests.
[...]

But: the service still fails in resuming the VM on boot.

Offline

#4 2023-10-21 04:52:28

kero
Member
Registered: 2012-08-26
Posts: 43

Re: libvirt-guests.service fails in suspending a VM

Finally I found (temporary ?) solutions for both suspend and resume.

All the problems comes from the (buggy?) integration of the service in the poweroff/boot process. The service works fine if I use it before/after poweroff/boot (without enabling but only starting/stopping it manually).

For the suspend part:
The problem is that the service doesnt't include libvirtd.service in its "After" dependencies (it only includes libvirtd.socket).
With "systemd edit" I created an /etc/systemd/system/libvirt-guests.service.d/override.conf file, containing:

[Unit]
After=libvirtd.service

For the resume part:
It looks that libvirt fails because of some network transitory state on bootup (https://bugs.launchpad.net/ubuntu/+sour … ug/1492621), which I don't perfectly understand.
Solution: In the file /etc/libvirt/qemu.conf add te following line:

spice_listen = "::1"

And now, it works:

journalctl -u libvirt-guests.service
[...]
oct. 20 23:17:11 kdomserv systemd[1]: Stopping Suspend/Resume Running libvirt Guests...
oct. 20 23:17:11 kdomserv libvirt-guests.sh[1239]: Running guests on default URI:
oct. 20 23:17:11 kdomserv libvirt-guests.sh[1218]: linux2022
oct. 20 23:17:11 kdomserv libvirt-guests.sh[1325]: Suspending guests on default URI...
oct. 20 23:17:11 kdomserv libvirt-guests.sh[1218]: Suspending linux2022: ...
oct. 20 23:17:16 kdomserv libvirt-guests.sh[1218]: Suspending linux2022: ...
oct. 20 23:17:17 kdomserv libvirt-guests.sh[1218]: Suspending linux2022: done
oct. 20 23:17:17 kdomserv systemd[1]: libvirt-guests.service: Deactivated successfully.
oct. 20 23:17:17 kdomserv systemd[1]: Stopped Suspend/Resume Running libvirt Guests.
-- Boot 6726d652041e4f7bb4a8d39d46a25c21 --
oct. 20 23:17:32 kdomserv systemd[1]: Starting Suspend/Resume Running libvirt Guests...
oct. 20 23:17:32 kdomserv libvirt-guests.sh[423]: Resuming guests on default URI...
oct. 20 23:17:38 kdomserv libvirt-guests.sh[430]: Resuming guest linux2022:
oct. 20 23:17:38 kdomserv libvirt-guests.sh[726]: done
oct. 20 23:17:38 kdomserv systemd[1]: Finished Suspend/Resume Running libvirt Guests.

Now, the solutions I found look quite dirty to me. If somebody has better solutions/suggestions...

Last edited by kero (2023-10-21 04:53:07)

Offline

Board footer

Powered by FluxBB