mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
virNetDaemonAutoShutdown: Allow live update of shutdown timeout
Modify the code so that calling 'virNetDaemonAutoShutdown' will update the auto shutdown timeout also for running daemons. This involves changing the logic when to do the update of the timer so that it can be called from both when the daemon is not yet runnign and when doing a live update. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
fbc18725f2
commit
c53e0c9535
@ -1049,9 +1049,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
VIR_DEBUG("Registering shutdown timeout %d", timeout);
|
||||
virNetDaemonAutoShutdown(lockDaemon->dmn,
|
||||
timeout);
|
||||
if (virNetDaemonAutoShutdown(lockDaemon->dmn, timeout) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((virLockDaemonSetupSignals(lockDaemon->dmn)) < 0) {
|
||||
|
@ -854,9 +854,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
VIR_DEBUG("Registering shutdown timeout %d", timeout);
|
||||
virNetDaemonAutoShutdown(logDaemon->dmn,
|
||||
timeout);
|
||||
if (virNetDaemonAutoShutdown(logDaemon->dmn, timeout) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((virLogDaemonSetupSignals(logDaemon->dmn)) < 0) {
|
||||
|
@ -1123,8 +1123,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
VIR_DEBUG("Registering shutdown timeout %d", timeout);
|
||||
virNetDaemonAutoShutdown(dmn, timeout);
|
||||
if (virNetDaemonAutoShutdown(dmn, timeout) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((daemonSetupSignals(dmn)) < 0) {
|
||||
|
@ -73,6 +73,7 @@ struct _virNetDaemon {
|
||||
bool finished;
|
||||
bool graceful;
|
||||
bool execRestart;
|
||||
bool running; /* the daemon has reached the running phase */
|
||||
|
||||
unsigned int autoShutdownTimeout;
|
||||
int autoShutdownTimerID;
|
||||
@ -422,7 +423,7 @@ virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED,
|
||||
static int
|
||||
virNetDaemonShutdownTimerRegister(virNetDaemon *dmn)
|
||||
{
|
||||
if (dmn->autoShutdownTimeout == 0)
|
||||
if (dmn->autoShutdownTimerID != -1)
|
||||
return 0;
|
||||
|
||||
if ((dmn->autoShutdownTimerID = virEventAddTimeout(-1,
|
||||
@ -440,7 +441,7 @@ virNetDaemonShutdownTimerRegister(virNetDaemon *dmn)
|
||||
static void
|
||||
virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn)
|
||||
{
|
||||
if (dmn->autoShutdownTimeout == 0)
|
||||
if (dmn->autoShutdownTimerID == -1)
|
||||
return;
|
||||
|
||||
/* A shutdown timeout is specified, so check
|
||||
@ -448,13 +449,15 @@ virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn)
|
||||
* shutdown after timeout seconds
|
||||
*/
|
||||
if (dmn->autoShutdownTimerActive) {
|
||||
if (virNetDaemonHasClients(dmn)) {
|
||||
if (virNetDaemonHasClients(dmn) ||
|
||||
dmn->autoShutdownTimeout == 0) {
|
||||
VIR_DEBUG("Deactivating shutdown timer %d", dmn->autoShutdownTimerID);
|
||||
virEventUpdateTimeout(dmn->autoShutdownTimerID, -1);
|
||||
dmn->autoShutdownTimerActive = false;
|
||||
}
|
||||
} else {
|
||||
if (!virNetDaemonHasClients(dmn)) {
|
||||
if (!virNetDaemonHasClients(dmn) &&
|
||||
dmn->autoShutdownTimeout != 0) {
|
||||
VIR_DEBUG("Activating shutdown timer %d", dmn->autoShutdownTimerID);
|
||||
virEventUpdateTimeout(dmn->autoShutdownTimerID,
|
||||
dmn->autoShutdownTimeout * 1000);
|
||||
@ -464,13 +467,25 @@ virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
int
|
||||
virNetDaemonAutoShutdown(virNetDaemon *dmn,
|
||||
unsigned int timeout)
|
||||
{
|
||||
VIR_LOCK_GUARD lock = virObjectLockGuard(dmn);
|
||||
|
||||
VIR_DEBUG("Registering shutdown timeout %u", timeout);
|
||||
|
||||
if (timeout > 0) {
|
||||
if (virNetDaemonShutdownTimerRegister(dmn) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
dmn->autoShutdownTimeout = timeout;
|
||||
|
||||
if (dmn->running)
|
||||
virNetDaemonShutdownTimerUpdate(dmn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -809,9 +824,7 @@ virNetDaemonRun(virNetDaemon *dmn)
|
||||
dmn->finishTimer = -1;
|
||||
dmn->finished = false;
|
||||
dmn->graceful = false;
|
||||
|
||||
if (virNetDaemonShutdownTimerRegister(dmn) < 0)
|
||||
goto cleanup;
|
||||
dmn->running = true;
|
||||
|
||||
/* We are accepting connections now. Notify systemd
|
||||
* so it can start dependent services. */
|
||||
|
@ -46,8 +46,8 @@ virJSONValue *virNetDaemonPreExecRestart(virNetDaemon *dmn);
|
||||
|
||||
bool virNetDaemonIsPrivileged(virNetDaemon *dmn);
|
||||
|
||||
void virNetDaemonAutoShutdown(virNetDaemon *dmn,
|
||||
unsigned int timeout);
|
||||
int virNetDaemonAutoShutdown(virNetDaemon *dmn,
|
||||
unsigned int timeout) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
void virNetDaemonAddShutdownInhibition(virNetDaemon *dmn);
|
||||
void virNetDaemonRemoveShutdownInhibition(virNetDaemon *dmn);
|
||||
|
Loading…
Reference in New Issue
Block a user