mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-12 07:42:56 +00:00
rpc: remove logind support for virNetDaemon
The virNetDaemon code now only concerns itself with preventing auto shutdown of the local daemon. Logind is now handled by the new virInhibitor object, for QEMU, LXC and LibXL. This fixes two notable bugs * Running virtual networks would prevent system shutdown * Loaded ephemeral secrets would prevent system shutdown Fixes 9e3cc0ff5e81ed2056a6a528893fd2cb5609d70b Fixes 37800af9a400385801da6d73654249fdb51a93d8 Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
48f0b6dfa1
commit
8575724aef
src
@ -707,7 +707,7 @@ libxlStateInitialize(bool privileged,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
libxl_driver->inhibitor = virInhibitorNew(
|
libxl_driver->inhibitor = virInhibitorNew(
|
||||||
VIR_INHIBITOR_WHAT_NONE,
|
VIR_INHIBITOR_WHAT_SHUTDOWN,
|
||||||
_("Libvirt Xen"),
|
_("Libvirt Xen"),
|
||||||
_("Xen virtual machines are running"),
|
_("Xen virtual machines are running"),
|
||||||
VIR_INHIBITOR_MODE_DELAY,
|
VIR_INHIBITOR_MODE_DELAY,
|
||||||
|
@ -1452,7 +1452,7 @@ lxcStateInitialize(bool privileged,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
lxc_driver->inhibitor = virInhibitorNew(
|
lxc_driver->inhibitor = virInhibitorNew(
|
||||||
VIR_INHIBITOR_WHAT_NONE,
|
VIR_INHIBITOR_WHAT_SHUTDOWN,
|
||||||
_("Libvirt LXC"),
|
_("Libvirt LXC"),
|
||||||
_("LXC containers are running"),
|
_("LXC containers are running"),
|
||||||
VIR_INHIBITOR_MODE_DELAY,
|
VIR_INHIBITOR_MODE_DELAY,
|
||||||
|
@ -673,7 +673,7 @@ qemuStateInitialize(bool privileged,
|
|||||||
}
|
}
|
||||||
|
|
||||||
qemu_driver->inhibitor = virInhibitorNew(
|
qemu_driver->inhibitor = virInhibitorNew(
|
||||||
VIR_INHIBITOR_WHAT_NONE,
|
VIR_INHIBITOR_WHAT_SHUTDOWN,
|
||||||
_("Libvirt QEMU"),
|
_("Libvirt QEMU"),
|
||||||
_("QEMU/KVM virtual machines are running"),
|
_("QEMU/KVM virtual machines are running"),
|
||||||
VIR_INHIBITOR_MODE_DELAY,
|
VIR_INHIBITOR_MODE_DELAY,
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include "virutil.h"
|
#include "virutil.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "virnetserver.h"
|
#include "virnetserver.h"
|
||||||
#include "virgdbus.h"
|
|
||||||
#include "virhash.h"
|
#include "virhash.h"
|
||||||
#include "virprocess.h"
|
#include "virprocess.h"
|
||||||
#include "virsystemd.h"
|
#include "virsystemd.h"
|
||||||
@ -80,7 +79,6 @@ struct _virNetDaemon {
|
|||||||
int autoShutdownTimerID;
|
int autoShutdownTimerID;
|
||||||
bool autoShutdownTimerActive;
|
bool autoShutdownTimerActive;
|
||||||
size_t autoShutdownInhibitions;
|
size_t autoShutdownInhibitions;
|
||||||
int autoShutdownInhibitFd;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +107,6 @@ virNetDaemonDispose(void *obj)
|
|||||||
virEventRemoveHandle(dmn->sigwatch);
|
virEventRemoveHandle(dmn->sigwatch);
|
||||||
#endif /* !WIN32 */
|
#endif /* !WIN32 */
|
||||||
|
|
||||||
VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd);
|
|
||||||
g_free(dmn->stateStopThread);
|
g_free(dmn->stateStopThread);
|
||||||
|
|
||||||
g_clear_pointer(&dmn->servers, g_hash_table_unref);
|
g_clear_pointer(&dmn->servers, g_hash_table_unref);
|
||||||
@ -150,7 +147,6 @@ virNetDaemonNew(void)
|
|||||||
#endif /* !WIN32 */
|
#endif /* !WIN32 */
|
||||||
|
|
||||||
dmn->privileged = geteuid() == 0;
|
dmn->privileged = geteuid() == 0;
|
||||||
dmn->autoShutdownInhibitFd = -1;
|
|
||||||
|
|
||||||
virProcessActivateMaxFiles();
|
virProcessActivateMaxFiles();
|
||||||
|
|
||||||
@ -491,66 +487,6 @@ virNetDaemonAutoShutdown(virNetDaemon *dmn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
|
||||||
/* As per: https://www.freedesktop.org/wiki/Software/systemd/inhibit */
|
|
||||||
static void
|
|
||||||
virNetDaemonCallInhibit(virNetDaemon *dmn,
|
|
||||||
const char *what,
|
|
||||||
const char *who,
|
|
||||||
const char *why,
|
|
||||||
const char *mode)
|
|
||||||
{
|
|
||||||
g_autoptr(GVariant) reply = NULL;
|
|
||||||
g_autoptr(GUnixFDList) replyFD = NULL;
|
|
||||||
g_autoptr(GVariant) message = NULL;
|
|
||||||
GDBusConnection *systemBus;
|
|
||||||
int fd;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
VIR_DEBUG("dmn=%p what=%s who=%s why=%s mode=%s",
|
|
||||||
dmn, NULLSTR(what), NULLSTR(who), NULLSTR(why), NULLSTR(mode));
|
|
||||||
|
|
||||||
if (virSystemdHasLogind() < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(systemBus = virGDBusGetSystemBus()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
message = g_variant_new("(ssss)", what, who, why, mode);
|
|
||||||
|
|
||||||
rc = virGDBusCallMethodWithFD(systemBus,
|
|
||||||
&reply,
|
|
||||||
G_VARIANT_TYPE("(h)"),
|
|
||||||
&replyFD,
|
|
||||||
NULL,
|
|
||||||
"org.freedesktop.login1",
|
|
||||||
"/org/freedesktop/login1",
|
|
||||||
"org.freedesktop.login1.Manager",
|
|
||||||
"Inhibit",
|
|
||||||
message,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (rc < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (g_unix_fd_list_get_length(replyFD) <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fd = g_unix_fd_list_get(replyFD, 0, NULL);
|
|
||||||
if (fd < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (dmn->autoShutdownInhibitions) {
|
|
||||||
dmn->autoShutdownInhibitFd = fd;
|
|
||||||
VIR_DEBUG("Got inhibit FD %d", fd);
|
|
||||||
} else {
|
|
||||||
/* We stopped the last VM since we made the inhibit call */
|
|
||||||
VIR_DEBUG("Closing inhibit FD %d", fd);
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virNetDaemonAddShutdownInhibition(virNetDaemon *dmn)
|
virNetDaemonAddShutdownInhibition(virNetDaemon *dmn)
|
||||||
{
|
{
|
||||||
@ -559,15 +495,6 @@ virNetDaemonAddShutdownInhibition(virNetDaemon *dmn)
|
|||||||
dmn->autoShutdownInhibitions++;
|
dmn->autoShutdownInhibitions++;
|
||||||
|
|
||||||
VIR_DEBUG("dmn=%p inhibitions=%zu", dmn, dmn->autoShutdownInhibitions);
|
VIR_DEBUG("dmn=%p inhibitions=%zu", dmn, dmn->autoShutdownInhibitions);
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
|
||||||
if (dmn->autoShutdownInhibitions == 1)
|
|
||||||
virNetDaemonCallInhibit(dmn,
|
|
||||||
"shutdown",
|
|
||||||
_("Libvirt"),
|
|
||||||
_("Virtual machines need to be saved"),
|
|
||||||
"delay");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -579,11 +506,6 @@ virNetDaemonRemoveShutdownInhibition(virNetDaemon *dmn)
|
|||||||
dmn->autoShutdownInhibitions--;
|
dmn->autoShutdownInhibitions--;
|
||||||
|
|
||||||
VIR_DEBUG("dmn=%p inhibitions=%zu", dmn, dmn->autoShutdownInhibitions);
|
VIR_DEBUG("dmn=%p inhibitions=%zu", dmn, dmn->autoShutdownInhibitions);
|
||||||
|
|
||||||
if (dmn->autoShutdownInhibitions == 0) {
|
|
||||||
VIR_DEBUG("Closing inhibit FD %d", dmn->autoShutdownInhibitFd);
|
|
||||||
VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user