Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
991a20a
hypervisor: move support for auto-shutdown out of QEMU driver
berrange Dec 17, 2024
2b792b3
remote: always invoke virStateStop for all daemons
berrange Dec 17, 2024
f4f5e6b
hypervisor: expand available shutdown actions
berrange Dec 19, 2024
84bb136
hypervisor: custom shutdown actions for transient vs persistent VMs
berrange Dec 20, 2024
f48f700
qemu: support automatic VM managed save in system daemon
berrange Dec 17, 2024
eb51f97
qemu: improve shutdown defaults for session daemon
berrange Dec 20, 2024
faa7a08
qemu: configurable delay for shutdown before poweroff
berrange Dec 19, 2024
b11c76e
hypervisor: support bypassing cache for managed save
berrange Dec 19, 2024
543d259
qemu: add config parameter to control auto-save bypass cache
berrange Dec 19, 2024
65345db
src: add new APIs for marking a domain to autostart once
berrange Dec 20, 2024
c6018e5
conf: implement support for autostart once feature
berrange Dec 20, 2024
602f2e6
hypervisor: wire up support for auto restore of running domains
berrange Dec 20, 2024
7e15349
qemu: wire up support for once only autostart
berrange Dec 20, 2024
da1d0f3
qemu: add config to control if auto-shutdown VMs are restored
berrange Dec 20, 2024
256ed0c
src: clarify semantics of the various virStateNNN methods
berrange Mar 11, 2025
77c32d2
rpc: rename virNetDaemonSetShutdownCallbacks
berrange Mar 11, 2025
1cad0a1
rpc: move state stop into virNetDaemon class
berrange Jan 7, 2025
4acd18b
rpc: don't unconditionally quit after preserving state
berrange Jan 7, 2025
94029c9
rpc: fix shutdown sequence when preserving state
berrange Jan 7, 2025
27020d2
admin: add 'daemon-shutdown' command
berrange Jan 7, 2025
364977b
rpc: don't let systemd shutdown daemon while saving VMs
berrange Jan 7, 2025
563d3cf
hypervisor: emit systemd status & log messages while saving
berrange Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/manpages/virt-admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ Sets the daemon timeout to the value of '--timeout' argument. Use ``--timeout 0`
to disable auto-shutdown of the daemon.


daemon-shutdown
---------------

**Syntax:**

::

daemon-shutdown [--preserve]

Instruct the daemon to exit gracefully. If the ``--preserve`` flag is given,
it will save state in the same manner that would be done on a host OS shutdown
(privileged daemons) or a login session quit (unprivileged daemons).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick (typo): Minor typo: 'host OS shutdown'

It seems like there's a small typo. Should it be 'host OS shutdown' instead of just 'OS shutdown'?

Suggested implementation:

it will save state in the same manner that would be done on a host OS shutdown

Ensure that if there are any other occurrences of "OS shutdown" that lack the "host" prefix, they are updated similarly.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This is nonsense. The code is already written the way you've suggested to write it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I apologize for my previous review comment. Upon reviewing the code and the conversation, it's clear that my suggestion was unnecessary and incorrect. The original text is already correct and precise.

In this case, the best response is to acknowledge the maintainer's feedback and recognize that no change is needed. I'll refrain from making further comments on this specific detail.


SERVER COMMANDS
===============

Expand Down
13 changes: 13 additions & 0 deletions include/libvirt/libvirt-admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ int virAdmConnectSetDaemonTimeout(virAdmConnectPtr conn,
unsigned int timeout,
unsigned int flags);

/**
* virAdmConnectDaemonShutdownFlags:
*
* Since: 11.2.0
*/
typedef enum {
/* Preserve state before shutting down daemon (Since: 11.2.0) */
VIR_DAEMON_SHUTDOWN_PRESERVE = (1 << 0),
} virAdmConnectDaemonShutdownFlags;

int virAdmConnectDaemonShutdown(virAdmConnectPtr conn,
unsigned int flags);

# ifdef __cplusplus
}
# endif
Expand Down
4 changes: 4 additions & 0 deletions include/libvirt/libvirt-domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,10 @@ int virDomainGetAutostart (virDomainPtr domain,
int *autostart);
int virDomainSetAutostart (virDomainPtr domain,
int autostart);
int virDomainGetAutostartOnce(virDomainPtr domain,
int *autostart);
int virDomainSetAutostartOnce(virDomainPtr domain,
int autostart);

/**
* virVcpuState:
Expand Down
11 changes: 10 additions & 1 deletion src/admin/admin_protocol.x
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ struct admin_connect_set_daemon_timeout_args {
unsigned int flags;
};

struct admin_connect_daemon_shutdown_args {
unsigned int flags;
};

/* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690;
const ADMIN_PROTOCOL_VERSION = 1;
Expand Down Expand Up @@ -334,5 +338,10 @@ enum admin_procedure {
/**
* @generate: both
*/
ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19
ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19,

/**
* @generate: both
*/
ADMIN_PROC_CONNECT_DAEMON_SHUTDOWN = 20
};
13 changes: 13 additions & 0 deletions src/admin/admin_server_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ adminConnectSetDaemonTimeout(virNetDaemon *dmn,
return virNetDaemonAutoShutdown(dmn, timeout);
}

static int
adminConnectDaemonShutdown(virNetDaemon *dmn,
unsigned int flags)
{
virCheckFlags(VIR_DAEMON_SHUTDOWN_PRESERVE, -1);

if (flags & VIR_DAEMON_SHUTDOWN_PRESERVE)
virNetDaemonStop(dmn);

virNetDaemonQuit(dmn);

return 0;
}

static int
adminDispatchConnectGetLoggingOutputs(virNetServer *server G_GNUC_UNUSED,
Expand Down
33 changes: 33 additions & 0 deletions src/admin/libvirt-admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,3 +1357,36 @@ virAdmConnectSetDaemonTimeout(virAdmConnectPtr conn,

return ret;
}


/**
* virAdmConnectDaemonShutdown:
* @conn: pointer to an active admin connection
* @flags: optional extra falgs
*
* Trigger shutdown of the daemon, if @flags includes
* VIR_DAEMON_SHUTDOWN_PRESERVE then state will be
* preserved before shutting down
*
* Returns 0 on success, -1 on error.
*
* Since: 11.2.0
*/
int
virAdmConnectDaemonShutdown(virAdmConnectPtr conn,
unsigned int flags)
{
int ret;

VIR_DEBUG("conn=%p, flags=0x%x", conn, flags);

virResetLastError();
virCheckAdmConnectReturn(conn, -1);

if ((ret = remoteAdminConnectDaemonShutdown(conn, flags)) < 0) {
virDispatchError(NULL);
return -1;
}

return ret;
}
5 changes: 5 additions & 0 deletions src/admin/libvirt_admin_public.syms
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ LIBVIRT_ADMIN_8.6.0 {
global:
virAdmConnectSetDaemonTimeout;
} LIBVIRT_ADMIN_3.0.0;

LIBVIRT_ADMIN_11.2.0 {
global:
virAdmConnectDaemonShutdown;
} LIBVIRT_ADMIN_8.6.0;
4 changes: 4 additions & 0 deletions src/admin_protocol-structs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ struct admin_connect_set_daemon_timeout_args {
u_int timeout;
u_int flags;
};
struct admin_connect_daemon_shutdown_args {
u_int flags;
};
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2,
Expand All @@ -168,4 +171,5 @@ enum admin_procedure {
ADMIN_PROC_CONNECT_SET_LOGGING_FILTERS = 17,
ADMIN_PROC_SERVER_UPDATE_TLS_FILES = 18,
ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19,
ADMIN_PROC_CONNECT_DAEMON_SHUTDOWN = 20,
};
7 changes: 6 additions & 1 deletion src/conf/domain_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,7 @@ static void virDomainObjDispose(void *obj)
virDomainCheckpointObjListFree(dom->checkpoints);
virDomainJobObjFree(dom->job);
virObjectUnref(dom->closecallbacks);
g_free(dom->autostartOnceLink);
}

virDomainObj *
Expand Down Expand Up @@ -29159,13 +29160,17 @@ virDomainDeleteConfig(const char *configDir,
{
g_autofree char *configFile = NULL;
g_autofree char *autostartLink = NULL;
g_autofree char *autostartOnceLink = NULL;

configFile = virDomainConfigFile(configDir, dom->def->name);
autostartLink = virDomainConfigFile(autostartDir, dom->def->name);
autostartOnceLink = g_strdup_printf("%s.once", autostartLink);

/* Not fatal if this doesn't work */
/* Not fatal if these don't work */
unlink(autostartLink);
unlink(autostartOnceLink);
dom->autostart = 0;
dom->autostartOnce = 0;

if (unlink(configFile) < 0 &&
errno != ENOENT) {
Expand Down
2 changes: 2 additions & 0 deletions src/conf/domain_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3328,9 +3328,11 @@ struct _virDomainObj {
virDomainStateReason state;

unsigned int autostart : 1;
unsigned int autostartOnce : 1;
unsigned int persistent : 1;
unsigned int updated : 1;
unsigned int removing : 1;
char *autostartOnceLink;

virDomainDef *def; /* The current definition */
virDomainDef *newDef; /* New definition to activate at shutdown */
Expand Down
8 changes: 8 additions & 0 deletions src/conf/virdomainobjlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,11 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
{
g_autofree char *configFile = NULL;
g_autofree char *autostartLink = NULL;
g_autofree char *autostartOnceLink = NULL;
g_autoptr(virDomainDef) def = NULL;
virDomainObj *dom;
int autostart;
int autostartOnce;
g_autoptr(virDomainDef) oldDef = NULL;

configFile = virDomainConfigFile(configDir, name);
Expand All @@ -500,13 +502,19 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
return NULL;

autostartLink = virDomainConfigFile(autostartDir, name);
autostartOnceLink = g_strdup_printf("%s.once", autostartLink);

autostart = virFileLinkPointsTo(autostartLink, configFile);
autostartOnce = virFileLinkPointsTo(autostartOnceLink, configFile);

if (!(dom = virDomainObjListAddLocked(doms, &def, xmlopt, 0, &oldDef)))
return NULL;

dom->autostart = autostart;
dom->autostartOnce = autostartOnce;

if (autostartOnce)
dom->autostartOnceLink = g_steal_pointer(&autostartOnceLink);

if (notify)
(*notify)(dom, oldDef == NULL, opaque);
Expand Down
10 changes: 10 additions & 0 deletions src/driver-hypervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,14 @@ typedef int
(*virDrvDomainSetAutostart)(virDomainPtr domain,
int autostart);

typedef int
(*virDrvDomainGetAutostartOnce)(virDomainPtr domain,
int *autostart);

typedef int
(*virDrvDomainSetAutostartOnce)(virDomainPtr domain,
int autostart);

typedef char *
(*virDrvDomainGetSchedulerType)(virDomainPtr domain,
int *nparams);
Expand Down Expand Up @@ -1564,6 +1572,8 @@ struct _virHypervisorDriver {
virDrvDomainDetachDeviceAlias domainDetachDeviceAlias;
virDrvDomainGetAutostart domainGetAutostart;
virDrvDomainSetAutostart domainSetAutostart;
virDrvDomainGetAutostartOnce domainGetAutostartOnce;
virDrvDomainSetAutostartOnce domainSetAutostartOnce;
virDrvDomainGetSchedulerType domainGetSchedulerType;
virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
virDrvDomainGetSchedulerParametersFlags domainGetSchedulerParametersFlags;
Expand Down
Loading