From nobody Tue Jan 21 07:31:57 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 1736365559995259.93029803585523; Wed, 8 Jan 2025 11:45:59 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0EE861489; Wed, 8 Jan 2025 14:45:59 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 54236146C; Wed, 8 Jan 2025 14:43:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id AB24413B7; Wed, 8 Jan 2025 14:43:18 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B0ED0136C for ; Wed, 8 Jan 2025 14:43:08 -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-689-bFtWM42VOguGsb-9lIu00w-1; Wed, 08 Jan 2025 14:43:07 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 821091944D05 for ; Wed, 8 Jan 2025 19:43:06 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.103]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9441B3000199; Wed, 8 Jan 2025 19:43:05 +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=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, 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=1736365388; 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=IizBvRB5aGXEAqvCKP0/MySTjxHEoYQUcAfXJjjuoLg=; b=GtD1qMr8Q8t+2F7G7lNq+D4/m/RM1cf4X+XLl2z+xd7J2jvm12i79VdXJa8N3k5KHsZm81 neoQhu/fnSqITSd4hB0r4dsbNaTWiYQUy1a5u5BRCLsSa6YipMNEMVSyihCEAsJ2/y4VSa ZApc0Ck9xe0+sK/UL73zLHeI6g/A2To= X-MC-Unique: bFtWM42VOguGsb-9lIu00w-1 X-Mimecast-MFC-AGG-ID: bFtWM42VOguGsb-9lIu00w 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 04/26] src: convert drivers over to use new autostart helper Date: Wed, 8 Jan 2025 19:42:37 +0000 Message-ID: <20250108194259.1171990-5-berrange@redhat.com> In-Reply-To: <20250108194259.1171990-1-berrange@redhat.com> References: <20250108194259.1171990-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: UJgY3nyiGLHs8n6nTNXJ0P-WEoFfycs6eGVGPMdDLNs_1736365386 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VG3QU36B2Y5KTQAKL5HAXLFDPZOXE6BB X-Message-ID-Hash: VG3QU36B2Y5KTQAKL5HAXLFDPZOXE6BB 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: 1736365560717116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_driver.c | 53 ++++++++++++--------------------------- src/libxl/libxl_driver.c | 36 ++++++++------------------- src/lxc/lxc_driver.c | 13 +++++----- src/lxc/lxc_process.c | 18 ++------------ src/lxc/lxc_process.h | 2 ++ src/qemu/qemu_driver.c | 54 ++++++++++++---------------------------- 6 files changed, 53 insertions(+), 123 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 8f97ac032c..ec997a38f5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -71,41 +71,19 @@ VIR_LOG_INIT("bhyve.bhyve_driver"); struct _bhyveConn *bhyve_driver =3D NULL; =20 static int -bhyveAutostartDomain(virDomainObj *vm, void *opaque) +bhyveAutostartDomain(virDomainObj *vm, void *opaque G_GNUC_UNUSED) { - const struct bhyveAutostartData *data =3D opaque; int ret =3D 0; - VIR_LOCK_GUARD lock =3D virObjectLockGuard(vm); - - if (vm->autostart && !virDomainObjIsActive(vm)) { - virResetLastError(); - ret =3D virBhyveProcessStart(data->conn, vm, - VIR_DOMAIN_RUNNING_BOOTED, 0); - if (ret < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to autostart VM '%1$s': %2$s"), - vm->def->name, virGetLastErrorMessage()); - } - } - return ret; -} - -static void -bhyveAutostartDomains(struct _bhyveConn *driver) -{ - /* XXX: Figure out a better way todo this. The domain - * startup code needs a connection handle in order - * to lookup the bridge associated with a virtual - * network - */ - virConnectPtr conn =3D virConnectOpen("bhyve:///system"); - /* Ignoring NULL conn which is mostly harmless here */ =20 - struct bhyveAutostartData data =3D { driver, conn }; - - virDomainObjListForEach(driver->domains, false, bhyveAutostartDomain, = &data); + ret =3D virBhyveProcessStart(NULL, vm, + VIR_DOMAIN_RUNNING_BOOTED, 0); + if (ret < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to autostart VM '%1$s': %2$s"), + vm->def->name, virGetLastErrorMessage()); + } =20 - virObjectUnref(conn); + return ret; } =20 /** @@ -1181,7 +1159,7 @@ bhyveStateInitialize(bool privileged, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { - bool autostart =3D true; + virDomainDriverAutoStartConfig autostartCfg; =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -1266,11 +1244,12 @@ bhyveStateInitialize(bool privileged, =20 virBhyveProcessReconnectAll(bhyve_driver); =20 - if (virDriverShouldAutostart(BHYVE_STATE_DIR, &autostart) < 0) - goto cleanup; - - if (autostart) - bhyveAutostartDomains(bhyve_driver); + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D BHYVE_STATE_DIR, + .callback =3D bhyveAutostartDomain, + .opaque =3D bhyve_driver, + }; + virDomainDriverAutoStart(bhyve_driver->domains, &autostartCfg); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 494b1ad9bc..b6e17b47de 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -315,36 +315,22 @@ libxlDomObjFromDomain(virDomainPtr dom) return vm; } =20 -static int +static void libxlAutostartDomain(virDomainObj *vm, void *opaque) { libxlDriverPrivate *driver =3D opaque; - int ret =3D -1; - - virObjectRef(vm); - virObjectLock(vm); - virResetLastError(); =20 if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) - goto cleanup; + return; =20 - if (vm->autostart && !virDomainObjIsActive(vm) && - libxlDomainStartNew(driver, vm, false) < 0) { + if (libxlDomainStartNew(driver, vm, false) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart VM '%1$s': %2$s"), vm->def->name, virGetLastErrorMessage()); - goto endjob; } =20 - ret =3D 0; - - endjob: virDomainObjEndJob(vm); - cleanup: - virDomainObjEndAPI(&vm); - - return ret; } =20 =20 @@ -654,7 +640,7 @@ libxlStateInitialize(bool privileged, { libxlDriverConfig *cfg; g_autofree char *driverConf =3D NULL; - bool autostart =3D true; + virDomainDriverAutoStartConfig autostartCfg; =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -807,14 +793,12 @@ libxlStateInitialize(bool privileged, NULL, NULL) < 0) goto error; =20 - if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) - goto error; - - if (autostart) { - virDomainObjListForEach(libxl_driver->domains, false, - libxlAutostartDomain, - libxl_driver); - } + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D cfg->stateDir, + .callback =3D libxlAutostartDomain, + .opaque =3D libxl_driver, + }; + virDomainDriverAutoStart(libxl_driver->domains, &autostartCfg); =20 virDomainObjListForEach(libxl_driver->domains, false, libxlDomainManagedSaveLoad, diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4740aeed52..e63732dbea 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1402,8 +1402,8 @@ lxcStateInitialize(bool privileged, void *opaque) { virLXCDriverConfig *cfg =3D NULL; - bool autostart =3D true; const char *defsecmodel; + virDomainDriverAutoStartConfig autostartCfg; =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -1499,11 +1499,12 @@ lxcStateInitialize(bool privileged, NULL, NULL) < 0) goto cleanup; =20 - if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) - goto cleanup; - - if (autostart) - virLXCProcessAutostartAll(lxc_driver); + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D cfg->stateDir, + .callback =3D virLXCProcessAutostartDomain, + .opaque =3D NULL, + }; + virDomainDriverAutoStart(lxc_driver->domains, &autostartCfg); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index c2982244f0..4e152c193c 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1562,19 +1562,14 @@ int virLXCProcessStart(virLXCDriver * driver, } =20 =20 -static int +void virLXCProcessAutostartDomain(virDomainObj *vm, void *opaque G_GNUC_UNUSED) { - VIR_LOCK_GUARD lock =3D virObjectLockGuard(vm); virLXCDomainObjPrivate *priv =3D vm->privateData; virObjectEvent *event; int rc =3D 0; =20 - if (!vm->autostart || - virDomainObjIsActive(vm)) - return 0; - rc =3D virLXCProcessStart(priv->driver, vm, 0, NULL, NULL, VIR_DOMAIN_= RUNNING_BOOTED); virDomainAuditStart(vm, "booted", rc >=3D 0); =20 @@ -1582,22 +1577,13 @@ virLXCProcessAutostartDomain(virDomainObj *vm, VIR_ERROR(_("Failed to autostart VM '%1$s': %2$s"), vm->def->name, virGetLastErrorMessage()); - return -1; + return; } =20 event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_BOO= TED); virObjectEventStateQueue(priv->driver->domainEventState, event); - - return 0; -} - - -void -virLXCProcessAutostartAll(virLXCDriver *driver) -{ - virDomainObjListForEach(driver->domains, false, virLXCProcessAutostart= Domain, NULL); } =20 =20 diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h index 95eacdd1e5..fc464690f8 100644 --- a/src/lxc/lxc_process.h +++ b/src/lxc/lxc_process.h @@ -34,6 +34,8 @@ int virLXCProcessStop(virLXCDriver *driver, unsigned int cleanupFlags); =20 void virLXCProcessAutostartAll(virLXCDriver *driver); +void virLXCProcessAutostartDomain(virDomainObj *vm, + void *opaque); int virLXCProcessReconnectAll(virLXCDriver *driver, virDomainObjList *doms); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2eddbd9ae..45bfbd3727 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -167,52 +167,29 @@ qemuDomObjFromSnapshot(virDomainSnapshotPtr snapshot) =20 =20 =20 -static int +static void qemuAutostartDomain(virDomainObj *vm, void *opaque) { virQEMUDriver *driver =3D opaque; int flags =3D 0; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - int ret =3D -1; =20 if (cfg->autoStartBypassCache) flags |=3D VIR_DOMAIN_START_BYPASS_CACHE; =20 - virObjectLock(vm); - virObjectRef(vm); - virResetLastError(); - if (vm->autostart && - !virDomainObjIsActive(vm)) { - if (qemuProcessBeginJob(vm, VIR_DOMAIN_JOB_OPERATION_START, - flags) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to start job on VM '%1$s': %2$s"), - vm->def->name, virGetLastErrorMessage()); - goto cleanup; - } + if (qemuProcessBeginJob(vm, VIR_DOMAIN_JOB_OPERATION_START, + flags) < 0) + return; =20 - if (qemuDomainObjStart(NULL, driver, vm, flags, - VIR_ASYNC_JOB_START) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to autostart VM '%1$s': %2$s"), + if (qemuDomainObjStart(NULL, driver, vm, flags, + VIR_ASYNC_JOB_START) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to autostart VM '%1$s': %2$s"), vm->def->name, virGetLastErrorMessage()); - } - - qemuProcessEndJob(vm); } =20 - ret =3D 0; - cleanup: - virDomainObjEndAPI(&vm); - return ret; -} - - -static void -qemuAutostartDomains(virQEMUDriver *driver) -{ - virDomainObjListForEach(driver->domains, false, qemuAutostartDomain, d= river); + qemuProcessEndJob(vm); } =20 =20 @@ -557,10 +534,10 @@ qemuStateInitialize(bool privileged, virQEMUDriverConfig *cfg; uid_t run_uid =3D -1; gid_t run_gid =3D -1; - bool autostart =3D true; size_t i; const char *defsecmodel =3D NULL; g_autoptr(virIdentity) identity =3D virIdentityGetCurrent(); + virDomainDriverAutoStartConfig autostartCfg; =20 qemu_driver =3D g_new0(virQEMUDriver, 1); =20 @@ -906,11 +883,12 @@ qemuStateInitialize(bool privileged, =20 qemuProcessReconnectAll(qemu_driver); =20 - if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0) - goto error; - - if (autostart) - qemuAutostartDomains(qemu_driver); + autostartCfg =3D (virDomainDriverAutoStartConfig) { + .stateDir =3D cfg->stateDir, + .callback =3D qemuAutostartDomain, + .opaque =3D qemu_driver, + }; + virDomainDriverAutoStart(qemu_driver->domains, &autostartCfg); =20 return VIR_DRV_STATE_INIT_COMPLETE; =20 --=20 2.47.1