From nobody Wed Jan 8 21:41:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1734434186270143.7396410154546; Tue, 17 Dec 2024 03:16:26 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 31A5A1568; Tue, 17 Dec 2024 06:16:25 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 293F015D7; Tue, 17 Dec 2024 06:15:30 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0262015C4; Tue, 17 Dec 2024 06:15:25 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0AC4D15B5 for ; Tue, 17 Dec 2024 06:15:18 -0500 (EST) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-zH2omLaKPySqP0VKQmCR3A-1; Tue, 17 Dec 2024 06:15:16 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4DF619560B2 for ; Tue, 17 Dec 2024 11:15:15 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.136]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 59EBF19560AD; Tue, 17 Dec 2024 11:15:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734434117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vs/zr3RteomrGtvQexRaX+wgIeqSfO+HgrP6xvuSnkU=; b=CNFzfj7zD1DFHoNuNyRX4fCD8GZ7HHGQ21IzAqJ4F3I6U3xPNGuTJ84861nFarBo8JHs5N wpKaQc+0+c5oMMzGUtK1JXLn0m9uzJvWdb7LvoZ0yydK+o29M5OGJuugGmkvQeb+0FQTff IHOgbDnihpesqJ6cOe41mxB1NSBk8wM= X-MC-Unique: zH2omLaKPySqP0VKQmCR3A-1 X-Mimecast-MFC-AGG-ID: zH2omLaKPySqP0VKQmCR3A From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 2/3] src: convert drivers over to new virInhibitor APIs Date: Tue, 17 Dec 2024 11:15:08 +0000 Message-ID: <20241217111509.3779007-3-berrange@redhat.com> In-Reply-To: <20241217111509.3779007-1-berrange@redhat.com> References: <20241217111509.3779007-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -2l3e7tamBkTPwDeY47D6oZjE9MlaBR6lQFa8uDRb1c_1734434115 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NXSWJCPECD7A3LF4SR3DBDX2RB7M7XUJ X-Message-ID-Hash: NXSWJCPECD7A3LF4SR3DBDX2RB7M7XUJ X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1734434188731116600 Content-Type: text/plain; charset="utf-8" This initial conversion of the drivers switches them over to use the virInhibitor APIs in local daemon only mode. Communication to logind is still handled by the virNetDaemon class logic. This mostly just replaces upto 3 fields in the driver state with a single new virInhibitor object, but otherwise should not change functionality besides replacing atomics with mutex protected APIs. The exception is the LXC driver which has been trying to inhibit shutdown shutdown but silently failing to, since nothing ever remembered to set the 'inhibitCallback' pointer in the driver state struct. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_conf.h | 9 +++---- src/libxl/libxl_domain.c | 6 ++--- src/libxl/libxl_driver.c | 15 +++++++---- src/lxc/lxc_conf.h | 9 +++---- src/lxc/lxc_driver.c | 13 +++++++-- src/lxc/lxc_process.c | 9 +++---- src/network/bridge_driver.c | 20 +++++++------- src/network/bridge_driver_conf.h | 9 +++---- src/qemu/qemu_conf.h | 9 +++---- src/qemu/qemu_driver.c | 12 ++++++--- src/qemu/qemu_process.c | 9 +++---- src/secret/secret_driver.c | 46 +++++++++++++------------------- 12 files changed, 80 insertions(+), 86 deletions(-) diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 7087b41079..0edcde079d 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -35,6 +35,7 @@ #include "virfirmware.h" #include "libxl_capabilities.h" #include "libxl_logger.h" +#include "virinhibitor.h" =20 #define LIBXL_DRIVER_EXTERNAL_NAME "Xen" /* @@ -117,12 +118,8 @@ struct _libxlDriverPrivate { /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ int lockFD; =20 - /* Atomic inc/dec only */ - unsigned int nactive; - - /* Immutable pointers. Caller must provide locking */ - virStateInhibitCallback inhibitCallback; - void *inhibitOpaque; + /* Immutable pointer, self-locking APIs */ + virInhibitor *inhibitor; =20 /* Immutable pointer, self-locking APIs */ virDomainObjList *domains; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index cad6c9ce42..a049cdb30f 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -873,8 +873,7 @@ libxlDomainCleanup(libxlDriverPrivate *driver, priv->deathW =3D NULL; } =20 - if (g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCall= back) - driver->inhibitCallback(false, driver->inhibitOpaque); + virInhibitorRelease(driver->inhibitor); =20 /* Release auto-allocated graphics ports */ for (i =3D 0; i < vm->def->ngraphics; i++) { @@ -1421,8 +1420,7 @@ libxlDomainStart(libxlDriverPrivate *driver, return -1; } =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhibitC= allback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_START= ED, restore_fd < 0 ? diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index e72553603d..eb293172f7 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -437,8 +437,7 @@ libxlReconnectDomain(virDomainObj *vm, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNKNOWN); =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhibitC= allback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 /* Enable domain death events */ libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW); @@ -514,6 +513,7 @@ libxlStateCleanup(void) =20 virObjectUnref(libxl_driver->domainEventState); virSysinfoDefFree(libxl_driver->hostsysinfo); + virInhibitorFree(libxl_driver->inhibitor); =20 if (libxl_driver->lockFD !=3D -1) virPidFileRelease(libxl_driver->config->stateDir, "driver", libxl_= driver->lockFD); @@ -675,9 +675,6 @@ libxlStateInitialize(bool privileged, return VIR_DRV_STATE_INIT_ERROR; } =20 - libxl_driver->inhibitCallback =3D callback; - libxl_driver->inhibitOpaque =3D opaque; - /* Allocate bitmap for vnc port reservation */ if (!(libxl_driver->reservedGraphicsPorts =3D virPortAllocatorRangeNew(_("VNC"), @@ -709,6 +706,14 @@ libxlStateInitialize(bool privileged, if (libxlDriverConfigLoadFile(cfg, driverConf) < 0) goto error; =20 + libxl_driver->inhibitor =3D virInhibitorNew( + VIR_INHIBITOR_WHAT_NONE, + _("Libvirt Xen"), + _("Xen virtual machines are running"), + VIR_INHIBITOR_MODE_DELAY, + callback, + opaque); + /* Register the callbacks providing access to libvirt's event loop */ libxl_osevent_register_hooks(cfg->ctx, &libxl_osevent_callbacks, cfg->= ctx); =20 diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h index a639e3989f..1969ed74cb 100644 --- a/src/lxc/lxc_conf.h +++ b/src/lxc/lxc_conf.h @@ -30,6 +30,7 @@ #include "virsysinfo.h" #include "virclosecallbacks.h" #include "virhostdev.h" +#include "virinhibitor.h" =20 #define LXC_DRIVER_NAME "LXC" =20 @@ -75,12 +76,8 @@ struct _virLXCDriver { /* Immutable pointer, lockless APIs */ virSysinfoDef *hostsysinfo; =20 - /* Atomic inc/dec only */ - unsigned int nactive; - - /* Immutable pointers. Caller must provide locking */ - virStateInhibitCallback inhibitCallback; - void *inhibitOpaque; + /* Immutable pointer, self-locking APIs */ + virInhibitor *inhibitor; =20 /* Immutable pointer, self-locking APIs */ virDomainObjList *domains; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 2488940feb..08516c8297 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1398,8 +1398,8 @@ static virDrvStateInitResult lxcStateInitialize(bool privileged, const char *root, bool monolithic G_GNUC_UNUSED, - virStateInhibitCallback callback G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED) + virStateInhibitCallback callback, + void *opaque) { virLXCDriverConfig *cfg =3D NULL; bool autostart =3D true; @@ -1451,6 +1451,14 @@ lxcStateInitialize(bool privileged, if (virLXCLoadDriverConfig(cfg, SYSCONFDIR "/libvirt/lxc.conf") < 0) goto cleanup; =20 + lxc_driver->inhibitor =3D virInhibitorNew( + VIR_INHIBITOR_WHAT_NONE, + _("Libvirt LXC"), + _("LXC containers are running"), + VIR_INHIBITOR_MODE_DELAY, + callback, + opaque); + if (!(lxc_driver->securityManager =3D lxcSecurityInit(cfg))) goto cleanup; =20 @@ -1555,6 +1563,7 @@ static int lxcStateCleanup(void) virObjectUnref(lxc_driver->caps); virObjectUnref(lxc_driver->securityManager); virObjectUnref(lxc_driver->xmlopt); + virInhibitorFree(lxc_driver->inhibitor); =20 if (lxc_driver->lockFD !=3D -1) virPidFileRelease(lxc_driver->config->stateDir, "driver", lxc_driv= er->lockFD); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index cd8bcfc282..c2982244f0 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -203,8 +203,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver, vm->pid =3D 0; vm->def->id =3D -1; =20 - if (g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCall= back) - driver->inhibitCallback(false, driver->inhibitOpaque); + virInhibitorRelease(driver->inhibitor); =20 virLXCDomainReAttachHostDevices(driver, vm->def); =20 @@ -1466,8 +1465,7 @@ int virLXCProcessStart(virLXCDriver * driver, if (virCommandHandshakeNotify(cmd) < 0) goto cleanup; =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhibitC= allback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 /* The first synchronization point is when the controller creates CGro= ups. */ if (lxcContainerWaitForContinue(handshakefds[0]) < 0) { @@ -1665,8 +1663,7 @@ virLXCProcessReconnectDomain(virDomainObj *vm, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNKNOWN); =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhi= bitCallback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 if (!(priv->monitor =3D virLXCProcessConnectMonitor(driver, vm))) goto error; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index e700a614a9..ce793c12ef 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -504,8 +504,7 @@ networkUpdateState(virNetworkObj *obj, if (virNetworkObjIsActive(obj)) { virNetworkObjPortForEach(obj, networkUpdatePort, obj); =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhi= bitCallback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); } =20 /* Try and read dnsmasq pids of both active and inactive networks, jus= t in @@ -644,9 +643,6 @@ networkStateInitialize(bool privileged, goto error; } =20 - network_driver->inhibitCallback =3D callback; - network_driver->inhibitOpaque =3D opaque; - network_driver->privileged =3D privileged; =20 if (!(network_driver->xmlopt =3D networkDnsmasqCreateXMLConf())) @@ -655,6 +651,14 @@ networkStateInitialize(bool privileged, if (!(network_driver->config =3D cfg =3D virNetworkDriverConfigNew(pri= vileged))) goto error; =20 + network_driver->inhibitor =3D virInhibitorNew( + VIR_INHIBITOR_WHAT_NONE, + _("Libvirt Network"), + _("Virtual networks are active"), + VIR_INHIBITOR_MODE_DELAY, + callback, + opaque); + if ((network_driver->lockFD =3D virPidFileAcquire(cfg->stateDir, "driver", getpid())) < 0) goto error; @@ -2432,8 +2436,7 @@ networkStartNetwork(virNetworkDriverState *driver, obj, network_driver->xmlopt) < 0) goto cleanup; =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhibitC= allback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 virNetworkObjSetActive(obj, true); VIR_INFO("Network '%s' started up", def->name); @@ -2509,8 +2512,7 @@ networkShutdownNetwork(virNetworkDriverState *driver, =20 virNetworkObjSetActive(obj, false); =20 - if (g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCall= back) - driver->inhibitCallback(false, driver->inhibitOpaque); + virInhibitorRelease(driver->inhibitor); =20 virNetworkObjUnsetDefTransient(obj); return ret; diff --git a/src/network/bridge_driver_conf.h b/src/network/bridge_driver_c= onf.h index 1beed01efb..2a2e2bc16d 100644 --- a/src/network/bridge_driver_conf.h +++ b/src/network/bridge_driver_conf.h @@ -27,6 +27,7 @@ #include "virnetworkobj.h" #include "object_event.h" #include "virfirewall.h" +#include "virinhibitor.h" =20 typedef struct _virNetworkDriverConfig virNetworkDriverConfig; struct _virNetworkDriverConfig { @@ -49,12 +50,8 @@ typedef struct _virNetworkDriverState virNetworkDriverSt= ate; struct _virNetworkDriverState { virMutex lock; =20 - /* Atomic inc/dec only */ - unsigned int nactive; - - /* Immutable pointers. Caller must provide locking */ - virStateInhibitCallback inhibitCallback; - void *inhibitOpaque; + /* Immutable pointer, self-locking APIs */ + virInhibitor *inhibitor; =20 /* Read-only */ bool privileged; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 23a900193e..42cdb6f883 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -42,6 +42,7 @@ #include "virfile.h" #include "virfilecache.h" #include "virfirmware.h" +#include "virinhibitor.h" =20 #define QEMU_DRIVER_NAME "QEMU" =20 @@ -257,16 +258,12 @@ struct _virQEMUDriver { /* Atomic increment only */ int lastvmid; =20 - /* Atomic inc/dec only */ - unsigned int nactive; - /* Immutable values */ bool privileged; char *embeddedRoot; =20 - /* Immutable pointers. Caller must provide locking */ - virStateInhibitCallback inhibitCallback; - void *inhibitOpaque; + /* Immutable pointer, self-locking APIs */ + virInhibitor *inhibitor; =20 /* Immutable pointer, self-locking APIs */ virDomainObjList *domains; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f1a633fdd3..c4cb9b2a9a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -573,9 +573,6 @@ qemuStateInitialize(bool privileged, return VIR_DRV_STATE_INIT_ERROR; } =20 - qemu_driver->inhibitCallback =3D callback; - qemu_driver->inhibitOpaque =3D opaque; - qemu_driver->privileged =3D privileged; qemu_driver->hostarch =3D virArchFromHost(); if (root !=3D NULL) @@ -675,6 +672,14 @@ qemuStateInitialize(bool privileged, goto error; } =20 + qemu_driver->inhibitor =3D virInhibitorNew( + VIR_INHIBITOR_WHAT_NONE, + _("Libvirt QEMU"), + _("QEMU/KVM virtual machines are running"), + VIR_INHIBITOR_MODE_DELAY, + callback, + opaque); + if ((qemu_driver->lockFD =3D virPidFileAcquire(cfg->stateDir, "driver", getpid())) < 0) goto error; @@ -1065,6 +1070,7 @@ qemuStateCleanup(void) ebtablesContextFree(qemu_driver->ebtables); virObjectUnref(qemu_driver->domains); virObjectUnref(qemu_driver->nbdkitCapsCache); + virInhibitorFree(qemu_driver->inhibitor); =20 if (qemu_driver->lockFD !=3D -1) virPidFileRelease(qemu_driver->config->stateDir, "driver", qemu_dr= iver->lockFD); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bee7a39e4e..c3b6f95493 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5809,8 +5809,7 @@ qemuProcessInit(virQEMUDriver *driver, qemuDomainSetFakeReboot(vm, false); virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_STAR= TING_UP); =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhi= bitCallback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 /* Run an early hook to set-up missing devices */ if (qemuProcessStartHook(driver, vm, @@ -8812,8 +8811,7 @@ void qemuProcessStop(virQEMUDriver *driver, if (priv->eventThread) g_object_unref(g_steal_pointer(&priv->eventThread)); =20 - if (g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCall= back) - driver->inhibitCallback(false, driver->inhibitOpaque); + virInhibitorRelease(driver->inhibitor); =20 /* Clear network bandwidth */ virDomainClearNetBandwidth(vm->def); @@ -9571,8 +9569,7 @@ qemuProcessReconnect(void *opaque) goto error; } =20 - if (g_atomic_int_add(&driver->nactive, 1) =3D=3D 0 && driver->inhibitC= allback) - driver->inhibitCallback(true, driver->inhibitOpaque); + virInhibitorHold(driver->inhibitor); =20 cleanup: if (jobStarted) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index a2d6b879d0..04c3ca49f1 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -41,6 +41,7 @@ #include "viraccessapicheck.h" #include "secret_event.h" #include "virutil.h" +#include "virinhibitor.h" =20 #define VIR_FROM_THIS VIR_FROM_SECRET =20 @@ -67,9 +68,8 @@ struct _virSecretDriverState { /* Immutable pointer, self-locking APIs */ virObjectEventState *secretEventState; =20 - /* Immutable pointers. Caller must provide locking */ - virStateInhibitCallback inhibitCallback; - void *inhibitOpaque; + /* Immutable pointer, self-locking APIs */ + virInhibitor *inhibitor; }; =20 static virSecretDriverState *driver; @@ -90,23 +90,6 @@ secretObjFromSecret(virSecretPtr secret) } =20 =20 -static bool -secretNumOfEphemeralSecretsHelper(virConnectPtr conn G_GNUC_UNUSED, - virSecretDef *def) -{ - return def->isephemeral; -} - - -static int -secretNumOfEphemeralSecrets(void) -{ - return virSecretObjListNumOfSecrets(driver->secrets, - secretNumOfEphemeralSecretsHelper, - NULL); -} - - /* Driver functions */ =20 static int @@ -271,6 +254,10 @@ secretDefineXML(virConnectPtr conn, objDef->uuid, objDef->usage_type, objDef->usage_id); + + if (objDef->isephemeral) + virInhibitorHold(driver->inhibitor); + goto cleanup; =20 restore_backup: @@ -288,8 +275,6 @@ secretDefineXML(virConnectPtr conn, virSecretDefFree(def); virSecretObjEndAPI(&obj); =20 - if (secretNumOfEphemeralSecrets() > 0) - driver->inhibitCallback(true, driver->inhibitOpaque); =20 virObjectEventStateQueue(driver->secretEventState, event); =20 @@ -440,6 +425,9 @@ secretUndefine(virSecretPtr secret) VIR_SECRET_EVENT_UNDEFINED, 0); =20 + if (def->isephemeral) + virInhibitorRelease(driver->inhibitor); + virSecretObjDeleteData(obj); =20 virSecretObjListRemove(driver->secrets, obj); @@ -450,9 +438,6 @@ secretUndefine(virSecretPtr secret) cleanup: virSecretObjEndAPI(&obj); =20 - if (secretNumOfEphemeralSecrets() =3D=3D 0) - driver->inhibitCallback(false, driver->inhibitOpaque); - virObjectEventStateQueue(driver->secretEventState, event); =20 return ret; @@ -469,6 +454,7 @@ secretStateCleanupLocked(void) VIR_FREE(driver->configDir); =20 virObjectUnref(driver->secretEventState); + virInhibitorFree(driver->inhibitor); =20 if (driver->lockFD !=3D -1) virPidFileRelease(driver->stateDir, "driver", driver->lockFD); @@ -502,8 +488,6 @@ secretStateInitialize(bool privileged, driver->lockFD =3D -1; driver->secretEventState =3D virObjectEventStateNew(); driver->privileged =3D privileged; - driver->inhibitCallback =3D callback; - driver->inhibitOpaque =3D opaque; =20 if (root) { driver->embeddedRoot =3D g_strdup(root); @@ -535,6 +519,14 @@ secretStateInitialize(bool privileged, goto error; } =20 + driver->inhibitor =3D virInhibitorNew( + VIR_INHIBITOR_WHAT_NONE, + _("Libvirt Secret"), + _("Ephemeral secrets are loaded"), + VIR_INHIBITOR_MODE_DELAY, + callback, + opaque); + if ((driver->lockFD =3D virPidFileAcquire(driver->stateDir, "driver", getpid())) < 0) goto error; --=20 2.46.0