On Wed, Jan 08, 2025 at 19:42:57 +0000, Daniel P. Berrangé wrote: > The daemons are wired up to shutdown in responsible to UNIX process > signals, as well as in response to login1 dbus signals, or loss of > desktop session. The latter two options can optionally preserve state > (ie running VMs). > > In non-systemd environments, as well as for testing, it would be useful > to have a way to trigger shutdown with state preservation more directly. > > Thus a new admin protocol API is introduced > > virAdmConnectDaemonShutdown > > which will trigger a daemon shutdown, and preserve running VMs if the > VIR_DAEMON_SHUTDOWN_PRESERVE flag is set. > > It has a corresponding 'virt-admin daemon-shutdown [--preserve]' command > binding. > > Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> > --- > include/libvirt/libvirt-admin.h | 13 +++++++++ > src/admin/admin_protocol.x | 11 +++++++- > src/admin/admin_server_dispatch.c | 13 +++++++++ > src/admin/libvirt-admin.c | 33 +++++++++++++++++++++++ > src/admin/libvirt_admin_public.syms | 5 ++++ > src/rpc/virnetdaemon.c | 4 +++ > tools/virt-admin.c | 41 +++++++++++++++++++++++++++++ Missing man-page addition for the 'virt-admin' tool. > 7 files changed, 119 insertions(+), 1 deletion(-) > > diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h > index ae4703f89b..1926202e97 100644 > --- a/include/libvirt/libvirt-admin.h > +++ b/include/libvirt/libvirt-admin.h > @@ -484,6 +484,19 @@ int virAdmConnectSetDaemonTimeout(virAdmConnectPtr conn, > unsigned int timeout, > unsigned int flags); > > +/** > + * virAdmConnectDaemonShutdownFlags: > + * > + * Since: 11.0.0 > + */ > +typedef enum { > + /* Preserve state before shutting down daemon (Since: 11.0.0) */ > + VIR_DAEMON_SHUTDOWN_PRESERVE = (1 << 0), > +} virAdmConnectDaemonShutdownFlags; Don't forget to fix version numbers. Especially in the public.syms file. > diff --git a/src/admin/libvirt_admin_public.syms b/src/admin/libvirt_admin_public.syms > index 17930e4fac..d39656bc53 100644 > --- a/src/admin/libvirt_admin_public.syms > +++ b/src/admin/libvirt_admin_public.syms > @@ -53,3 +53,8 @@ LIBVIRT_ADMIN_8.6.0 { > global: > virAdmConnectSetDaemonTimeout; > } LIBVIRT_ADMIN_3.0.0; > + > +LIBVIRT_ADMIN_11.0.0 { ^^^ > + global: > + virAdmConnectDaemonShutdown; > +} LIBVIRT_ADMIN_8.6.0; > diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c > index d1d7bae569..8cc7af1182 100644 > --- a/src/rpc/virnetdaemon.c > +++ b/src/rpc/virnetdaemon.c > @@ -815,8 +815,10 @@ virNetDaemonRun(virNetDaemon *dmn) > } > } > > + VIR_DEBUG("Main loop exited"); > if (dmn->graceful) { > virThreadJoin(&shutdownThread); > + VIR_DEBUG("Graceful shutdown complete"); > } else { > VIR_WARN("Make forcefull daemon shutdown"); > exit(EXIT_FAILURE); > @@ -946,6 +948,8 @@ virNetDaemonSetShutdownCallbacks(virNetDaemon *dmn, > { > VIR_LOCK_GUARD lock = virObjectLockGuard(dmn); > > + VIR_DEBUG("Shutdown callbacks preserve=%p prepare=%p wait=%p", > + preserveCb, prepareCb, waitCb); > dmn->shutdownPreserveCb = preserveCb; > dmn->shutdownPrepareCb = prepareCb; > dmn->shutdownWaitCb = waitCb; These debug statements don't seem to belong to this patch. Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>