admin: Introduce virAdmConnectSetDaemonTimeout

Use of the admin APIs to modify logging temporarily has a rather serious
deficiency when the daemon whose config is being changed is using
auto-shutdown (default with socket-activated deployments) as the
configuration is discarded if there is no client or VM/other object
blocking auto shutdown.

This API allows users to disable/postpone shutdown timeout so that the
configuration doesn't change under their hands.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2022-06-13 13:02:09 +02:00
parent 12a76fb81e
commit 8b2bf0f1d7
6 changed files with 71 additions and 1 deletions

View File

@ -480,6 +480,10 @@ int virAdmConnectSetLoggingFilters(virAdmConnectPtr conn,
const char *filters, const char *filters,
unsigned int flags); unsigned int flags);
int virAdmConnectSetDaemonTimeout(virAdmConnectPtr conn,
unsigned int timeout,
unsigned int flags);
# ifdef __cplusplus # ifdef __cplusplus
} }
# endif # endif

View File

@ -214,6 +214,11 @@ struct admin_connect_set_logging_filters_args {
unsigned int flags; unsigned int flags;
}; };
struct admin_connect_set_daemon_timeout_args {
unsigned int timeout;
unsigned int flags;
};
/* Define the program number, protocol version and procedure numbers here. */ /* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690; const ADMIN_PROGRAM = 0x06900690;
const ADMIN_PROTOCOL_VERSION = 1; const ADMIN_PROTOCOL_VERSION = 1;
@ -324,5 +329,10 @@ enum admin_procedure {
/** /**
* @generate: both * @generate: both
*/ */
ADMIN_PROC_SERVER_UPDATE_TLS_FILES = 18 ADMIN_PROC_SERVER_UPDATE_TLS_FILES = 18,
/**
* @generate: both
*/
ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19
}; };

View File

@ -463,6 +463,18 @@ adminConnectSetLoggingFilters(virNetDaemon *dmn G_GNUC_UNUSED,
return virLogSetFilters(filters); return virLogSetFilters(filters);
} }
static int
adminConnectSetDaemonTimeout(virNetDaemon *dmn,
unsigned int timeout,
unsigned int flags)
{
virCheckFlags(0, -1);
return virNetDaemonAutoShutdown(dmn, timeout);
}
static int static int
adminDispatchConnectGetLoggingOutputs(virNetServer *server G_GNUC_UNUSED, adminDispatchConnectGetLoggingOutputs(virNetServer *server G_GNUC_UNUSED,
virNetServerClient *client G_GNUC_UNUSED, virNetServerClient *client G_GNUC_UNUSED,

View File

@ -1327,3 +1327,37 @@ virAdmConnectSetLoggingFilters(virAdmConnectPtr conn,
virDispatchError(NULL); virDispatchError(NULL);
return -1; return -1;
} }
/**
* virAdmConnectSetDaemonTimeout:
* @conn: pointer to an active admin connection
* @timeout: timeout to set in seconds (0 disables timeout)
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Reconfigure the existing timeout of the daemon to @timeout. Setting timeout
* to 0 disables the daemon timeout.
*
* Returns 0 on success, -1 on error.
*
* Since: 8.6.0
*/
int
virAdmConnectSetDaemonTimeout(virAdmConnectPtr conn,
unsigned int timeout,
unsigned int flags)
{
int ret;
VIR_DEBUG("conn=%p, timeout=%u, flags=0x%x", conn, timeout, flags);
virResetLastError();
virCheckAdmConnectReturn(conn, -1);
if ((ret = remoteAdminConnectSetDaemonTimeout(conn, timeout, flags)) < 0) {
virDispatchError(NULL);
return -1;
}
return ret;
}

View File

@ -48,3 +48,8 @@ LIBVIRT_ADMIN_3.0.0 {
virAdmConnectSetLoggingOutputs; virAdmConnectSetLoggingOutputs;
virAdmConnectSetLoggingFilters; virAdmConnectSetLoggingFilters;
} LIBVIRT_ADMIN_2.0.0; } LIBVIRT_ADMIN_2.0.0;
LIBVIRT_ADMIN_8.6.0 {
global:
virAdmConnectSetDaemonTimeout;
} LIBVIRT_ADMIN_3.0.0;

View File

@ -144,6 +144,10 @@ struct admin_connect_set_logging_filters_args {
admin_string filters; admin_string filters;
u_int flags; u_int flags;
}; };
struct admin_connect_set_daemon_timeout_args {
u_int timeout;
u_int flags;
};
enum admin_procedure { enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1, ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2, ADMIN_PROC_CONNECT_CLOSE = 2,
@ -163,4 +167,5 @@ enum admin_procedure {
ADMIN_PROC_CONNECT_SET_LOGGING_OUTPUTS = 16, ADMIN_PROC_CONNECT_SET_LOGGING_OUTPUTS = 16,
ADMIN_PROC_CONNECT_SET_LOGGING_FILTERS = 17, ADMIN_PROC_CONNECT_SET_LOGGING_FILTERS = 17,
ADMIN_PROC_SERVER_UPDATE_TLS_FILES = 18, ADMIN_PROC_SERVER_UPDATE_TLS_FILES = 18,
ADMIN_PROC_CONNECT_SET_DAEMON_TIMEOUT = 19,
}; };