From nobody Tue Dec 16 21:01:36 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 1739375261609525.5010809896617; Wed, 12 Feb 2025 07:47:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 16E7418A4; Wed, 12 Feb 2025 10:47:41 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2F749199D; Wed, 12 Feb 2025 10:46:58 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BD2DE11E3; Wed, 12 Feb 2025 10:46:53 -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 47765167A for ; Wed, 12 Feb 2025 10:46:53 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-BLPheEZTNzuK8F3N-vYokA-1; Wed, 12 Feb 2025 10:46:51 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DD4201801A0D for ; Wed, 12 Feb 2025 15:46:50 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9F4461955F1B; Wed, 12 Feb 2025 15:46:49 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1739375213; 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=4V1ZpT9YDuXpwNymYY82UbfSEVKfMK8SUUjAwSg0At0=; b=erbJxnoD1PLkSxLMa8UTvaQUEiFCQpwmDj4ZQqD2qk2L5+034lxfJeOZXM929T0Y+8Hxxx bASGDBLbTgsbDOA98PL1Lacrn2sSYXx76dUaPUnob86rS49974i3J5+fGQOe57VgvtJhzp cq78T6+7B0hXI7J0F5zusr6VjjUDVbQ= X-MC-Unique: BLPheEZTNzuK8F3N-vYokA-1 X-Mimecast-MFC-AGG-ID: BLPheEZTNzuK8F3N-vYokA_1739375211 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 v2 1/8] bhyve: add 'driver' to bhyveProcessStart method Date: Wed, 12 Feb 2025 15:46:39 +0000 Message-ID: <20250212154646.913282-2-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: k5DZ6iGx7z-1OTkh42-AX8U7NSAMQXGhFfiJgZYvcWg_1739375211 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: V4D43AIZHRDMOPWMDYEBBEWY3GUF2VGB X-Message-ID-Hash: V4D43AIZHRDMOPWMDYEBBEWY3GUF2VGB 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: 1739375262266019000 Content-Type: text/plain; charset="utf-8" This allows for passinga NULL connection object in cases where domain autodestroy is not required. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/bhyve/bhyve_driver.c | 6 +++--- src/bhyve/bhyve_process.c | 5 ++--- src/bhyve/bhyve_process.h | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 8f97ac032c..ea5a9be4fb 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -79,7 +79,7 @@ bhyveAutostartDomain(virDomainObj *vm, void *opaque) =20 if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); - ret =3D virBhyveProcessStart(data->conn, vm, + ret =3D virBhyveProcessStart(bhyve_driver, data->conn, vm, VIR_DOMAIN_RUNNING_BOOTED, 0); if (ret < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -834,7 +834,7 @@ bhyveDomainCreateWithFlags(virDomainPtr dom, goto cleanup; } =20 - ret =3D virBhyveProcessStart(dom->conn, vm, + ret =3D virBhyveProcessStart(privconn, dom->conn, vm, VIR_DOMAIN_RUNNING_BOOTED, start_flags); =20 @@ -892,7 +892,7 @@ bhyveDomainCreateXML(virConnectPtr conn, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NUL= L))) goto cleanup; =20 - if (virBhyveProcessStart(conn, vm, + if (virBhyveProcessStart(privconn, conn, vm, VIR_DOMAIN_RUNNING_BOOTED, start_flags) < 0) { /* If domain is not persistent, remove its data */ diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 41feabcbe7..3e6f678cf5 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -270,13 +270,12 @@ bhyveProcessPrepareDomain(bhyveConn *driver, } =20 int -virBhyveProcessStart(virConnectPtr conn, +virBhyveProcessStart(bhyveConn *driver, + virConnectPtr conn, virDomainObj *vm, virDomainRunningReason reason, unsigned int flags) { - struct _bhyveConn *driver =3D conn->privateData; - /* Run an early hook to setup missing devices. */ if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0) return -1; diff --git a/src/bhyve/bhyve_process.h b/src/bhyve/bhyve_process.h index 668411db57..e69db41fc2 100644 --- a/src/bhyve/bhyve_process.h +++ b/src/bhyve/bhyve_process.h @@ -28,7 +28,8 @@ bhyveProcessPrepareDomain(bhyveConn *driver, virDomainObj *vm, unsigned int flags); =20 -int virBhyveProcessStart(virConnect *conn, +int virBhyveProcessStart(bhyveConn *driver, + virConnectPtr conn, virDomainObj *vm, virDomainRunningReason reason, unsigned int flags); --=20 2.47.1 From nobody Tue Dec 16 21:01:36 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 1739375288896698.7967800505955; Wed, 12 Feb 2025 07:48:08 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AB8B019AB; Wed, 12 Feb 2025 10:48:07 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9AC961A2C; Wed, 12 Feb 2025 10:47:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8EFC91863; Wed, 12 Feb 2025 10:46:56 -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 2FEAF167A for ; Wed, 12 Feb 2025 10:46:55 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-3uPNzHDzNBmddoYW8uYNVw-1; Wed, 12 Feb 2025 10:46:53 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E906E180087B for ; Wed, 12 Feb 2025 15:46:52 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 78F821955F1B; Wed, 12 Feb 2025 15:46:51 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1739375214; 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=VMmv9wGeHh29o2u7pFfw+FFuWWbqiTztwsqFNes3YAU=; b=dH5r/NkTY3CTcLrTTiPXWkx32/bRuEsobr2xax1GX0GcdLLkheOJ2t+aYN+rnsauV6ZPAe DV14sCJGbTew9THJQtwsQWOGtCEhSJjd0i/BX8U5UEnkZtS+2lcWO6T9Xewcvq/6EPleAr ew8sZ597jpffcYr78GaI37JMkZciFiE= X-MC-Unique: 3uPNzHDzNBmddoYW8uYNVw-1 X-Mimecast-MFC-AGG-ID: 3uPNzHDzNBmddoYW8uYNVw 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 v2 2/8] bhyve: stop opening & passing connection to bhyveProcessStart Date: Wed, 12 Feb 2025 15:46:40 +0000 Message-ID: <20250212154646.913282-3-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7oIi9AkBBN9tKFCRGUuGt-PbgqSdEcsj5Nwage4ngEQ_1739375213 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: XUX6WFUKKWCA5DTJCC4XOHMVDSIN62DG X-Message-ID-Hash: XUX6WFUKKWCA5DTJCC4XOHMVDSIN62DG 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: 1739375291102019100 Content-Type: text/plain; charset="utf-8" A connection object is not required because autostarted domains are never marked for autodestroy. The comment about needing a connection for the network driver is obsolete since we can auto-open a connection on demand. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/bhyve/bhyve_driver.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index ea5a9be4fb..f6b0417014 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -71,15 +71,14 @@ 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); =20 if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); - ret =3D virBhyveProcessStart(bhyve_driver, data->conn, vm, + ret =3D virBhyveProcessStart(bhyve_driver, NULL, vm, VIR_DOMAIN_RUNNING_BOOTED, 0); if (ret < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -93,19 +92,7 @@ bhyveAutostartDomain(virDomainObj *vm, void *opaque) 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 */ - - struct bhyveAutostartData data =3D { driver, conn }; - - virDomainObjListForEach(driver->domains, false, bhyveAutostartDomain, = &data); - - virObjectUnref(conn); + virDomainObjListForEach(driver->domains, false, bhyveAutostartDomain, = NULL); } =20 /** --=20 2.47.1 From nobody Tue Dec 16 21:01:36 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 1739375311013258.3113965435366; Wed, 12 Feb 2025 07:48:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7067D1A20; Wed, 12 Feb 2025 10:48:30 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 68AEF1AC8; Wed, 12 Feb 2025 10:47:11 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D6ED018CF; Wed, 12 Feb 2025 10:47:06 -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 4201218FE for ; Wed, 12 Feb 2025 10:46:57 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-6xddiyZiOqap1kV9CFAP6Q-1; Wed, 12 Feb 2025 10:46:55 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BFF5A1800360 for ; Wed, 12 Feb 2025 15:46:54 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 850381955F1B; Wed, 12 Feb 2025 15:46:53 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1739375216; 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=zkQ1weQIB8Jf7/CnFcg9Edgsy/SBG3j9bkXrXD/yWhk=; b=UBW+aLQG/Y6udPGRCS1dOageB866Gb8ouuhXLFWPMc0QB3pz5TEVuFq9VLmBH4CZvOviZH Yht6ru3vap1akKfxF2bp235mf8Z5lucVYi3U8XD5hE24ROpm51bIaszCpNjOwLengbxj7V B6tMiRDcFBnX4JW+sMQ9V4xjI16jfQg= X-MC-Unique: 6xddiyZiOqap1kV9CFAP6Q-1 X-Mimecast-MFC-AGG-ID: 6xddiyZiOqap1kV9CFAP6Q 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 v2 3/8] util: add APIs for more systemd notifications Date: Wed, 12 Feb 2025 15:46:41 +0000 Message-ID: <20250212154646.913282-4-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7UK741SUChUVctTXm6qaFmlHYfSLW8wvuQn8l9UcRKE_1739375214 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VPEFU7IQKEB473EXQK6MOVUEMXXEPJV2 X-Message-ID-Hash: VPEFU7IQKEB473EXQK6MOVUEMXXEPJV2 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: 1739375312296019000 Content-Type: text/plain; charset="utf-8" We have a way to notify systemd when we're done starting the daemon. Systemd supports many more notifications, however, and many of them are quite relevant to our needs: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html This renames the existing notification API to better reflect its semantics, and adds new APIs for reporting * Initiation of config file reload * Initiation of daemon shutdown process * Adhoc progress status messages * Request to extend service shutdown timeout Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 6 +++++- src/rpc/virnetdaemon.c | 2 +- src/util/virsystemd.c | 44 +++++++++++++++++++++++++++++++++++++--- src/util/virsystemd.h | 6 +++++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6888f6b599..4eca252b2a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3531,7 +3531,11 @@ virSystemdHasResolved; virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; -virSystemdNotifyStartup; +virSystemdNotifyExtendTimeout; +virSystemdNotifyReady; +virSystemdNotifyReload; +virSystemdNotifyStatus; +virSystemdNotifyStopping; virSystemdResolvedRegisterNameServer; virSystemdTerminateMachine; =20 diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index f647cf60ba..e6bdfe0f88 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -753,7 +753,7 @@ virNetDaemonRun(virNetDaemon *dmn) =20 /* We are accepting connections now. Notify systemd * so it can start dependent services. */ - virSystemdNotifyStartup(); + virSystemdNotifyReady(); =20 VIR_DEBUG("dmn=3D%p quit=3D%d", dmn, dmn->quit); while (!dmn->finished) { diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index d46e5f74fc..bbcf77a41f 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -624,12 +624,11 @@ int virSystemdTerminateMachine(const char *name) return 0; } =20 -void -virSystemdNotifyStartup(void) +static void +virSystemdNotify(const char *msg) { #ifndef WIN32 const char *path; - const char *msg =3D "READY=3D1"; int fd; struct sockaddr_un un =3D { .sun_family =3D AF_UNIX, @@ -644,6 +643,8 @@ virSystemdNotifyStartup(void) .msg_iovlen =3D 1, }; =20 + VIR_DEBUG("Notify '%s'", msg); + if (!(path =3D getenv("NOTIFY_SOCKET"))) { VIR_DEBUG("Skipping systemd notify, not requested"); return; @@ -674,6 +675,43 @@ virSystemdNotifyStartup(void) #endif /* !WIN32 */ } =20 +void virSystemdNotifyReady(void) +{ + virSystemdNotify("READY=3D1"); +} + +void virSystemdNotifyReload(void) +{ + gint64 now =3D g_get_monotonic_time(); + g_autofree char *msg =3D g_strdup_printf( + "RELOADING=3D1\nMONOTONIC_USEC=3D%lld", (long long int)now); + virSystemdNotify(msg); +} + +void virSystemdNotifyStopping(void) +{ + virSystemdNotify("STOPPING=3D1"); +} + +void virSystemdNotifyExtendTimeout(int secs) +{ + g_autofree char *msg =3D g_strdup_printf("EXTEND_TIMEOUT_USEC=3D%llu", + secs * 1000ull * 1000ul); + virSystemdNotify(msg); +} + +void virSystemdNotifyStatus(const char *fmt, ...) +{ + g_autofree char *msg1 =3D NULL; + g_autofree char *msg2 =3D NULL; + va_list ap; + va_start(ap, fmt); + msg1 =3D g_strdup_vprintf(fmt, ap); + va_end(ap); + msg2 =3D g_strdup_printf("STATUS=3D%s", msg1); + virSystemdNotify(msg2); +} + static int virSystemdPMSupportTarget(const char *methodName, bool *result) { diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index b7fdaf67df..98460dbc3a 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -44,7 +44,11 @@ int virSystemdCreateMachine(const char *name, =20 int virSystemdTerminateMachine(const char *name); =20 -void virSystemdNotifyStartup(void); +void virSystemdNotifyReady(void); +void virSystemdNotifyReload(void); +void virSystemdNotifyStopping(void); +void virSystemdNotifyExtendTimeout(int secs); +void virSystemdNotifyStatus(const char *fmt, ...) G_GNUC_PRINTF(1, 2); =20 int virSystemdHasMachined(void); =20 --=20 2.47.1 From nobody Tue Dec 16 21:01:36 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 17393753294261.6109551968248752; Wed, 12 Feb 2025 07:48:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8996716F7; Wed, 12 Feb 2025 10:48:48 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 99B471879; Wed, 12 Feb 2025 10:47:16 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1020816AD; Wed, 12 Feb 2025 10:47:12 -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 DACD617A6 for ; Wed, 12 Feb 2025 10:46:58 -0500 (EST) Received: from mx-prod-mc-01.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-479-j_c8RrIvNLiNAWAH3K8tgw-1; Wed, 12 Feb 2025 10:46:57 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 988EC195608C for ; Wed, 12 Feb 2025 15:46:56 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EFB11955F1B; Wed, 12 Feb 2025 15:46:55 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1739375218; 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=Q3i4u7b9HyqUknQCcUP0RelwFYUkEyxrzyUF6CFj1Hc=; b=YPhrc3h57dggdG6EWmZGVGoo/PfY7QDcUa5uTdOZVett0tmqfCxBN771GceDsXha/k7wWB SRXq2hUFd8TtSFi/4Bw8y0/IHBQcDmlGhCfEe2n1Ra2Y+sRoTsXd+5OpaNyRJCmXgRFc9B aefiBqY2WAlEA7dpgwJd2Xu208SXgKg= X-MC-Unique: j_c8RrIvNLiNAWAH3K8tgw-1 X-Mimecast-MFC-AGG-ID: j_c8RrIvNLiNAWAH3K8tgw 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 v2 4/8] remote: notify systemd when reloading config Date: Wed, 12 Feb 2025 15:46:42 +0000 Message-ID: <20250212154646.913282-5-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6YUYXHw7-fnnojhi3y9RTnB06P3ZMlRvACSh5Y_tN34_1739375216 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: X4JHFGHQQRO4MURLBW2YRGV4AWTJPTQB X-Message-ID-Hash: X4JHFGHQQRO4MURLBW2YRGV4AWTJPTQB 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: 1739375330324019000 Content-Type: text/plain; charset="utf-8" Switch to the 'notify-reload' service type and send notifications to systemd when reloading configuration. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/remote/libvirtd.service.in | 2 +- src/remote/remote_daemon.c | 2 ++ src/virtd.service.in | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/remote/libvirtd.service.in b/src/remote/libvirtd.service.in index 250b4a6fc3..b0a062e885 100644 --- a/src/remote/libvirtd.service.in +++ b/src/remote/libvirtd.service.in @@ -26,7 +26,7 @@ After=3Dxencommons.service Conflicts=3Dxendomains.service =20 [Service] -Type=3Dnotify +Type=3Dnotify-reload Environment=3DLIBVIRTD_ARGS=3D"--timeout 120" EnvironmentFile=3D-@initconfdir@/libvirtd ExecStart=3D@sbindir@/libvirtd $LIBVIRTD_ARGS diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 1d079c7e4b..d44a365000 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -452,9 +452,11 @@ static void daemonReloadHandlerThread(void *opaque G_G= NUC_UNUSED) virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL, NULL); =20 + virSystemdNotifyReload(); if (virStateReload() < 0) { VIR_WARN("Error while reloading drivers"); } + virSystemdNotifyReady(); =20 /* Drivers are initialized again. */ g_atomic_int_set(&driversInitialized, 1); diff --git a/src/virtd.service.in b/src/virtd.service.in index 651a8d82d7..7ffb77e339 100644 --- a/src/virtd.service.in +++ b/src/virtd.service.in @@ -15,7 +15,7 @@ After=3Ddbus.service After=3Dapparmor.service =20 [Service] -Type=3Dnotify +Type=3Dnotify-reload Environment=3D@SERVICE@_ARGS=3D"--timeout 120" EnvironmentFile=3D-@initconfdir@/@service@ ExecStart=3D@sbindir@/@service@ $@SERVICE@_ARGS --=20 2.47.1 From nobody Tue Dec 16 21:01:36 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 1739375350653799.5604065518311; Wed, 12 Feb 2025 07:49:10 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0F5B2199D; Wed, 12 Feb 2025 10:49:10 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D5DE618CC; Wed, 12 Feb 2025 10:47:19 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 630851A4C; Wed, 12 Feb 2025 10:47:14 -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 B0F83180E for ; Wed, 12 Feb 2025 10:47:00 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-mlgGM0kvPEK27Zvp7SbgnA-1; Wed, 12 Feb 2025 10:46:59 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6D79C1800875 for ; Wed, 12 Feb 2025 15:46:58 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 38D601955F1B; Wed, 12 Feb 2025 15:46:56 +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.8 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=1739375220; 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=pS3z/agib1yNx8XzF59saLaBM5orDKJvYnwrPse1ABs=; b=ZpN3QyuhxgGmA5NMYG5WD0St418r70R1JEFaYJ1CAoDZLdYO9m6lkgW/aube1XGcNyVpRd Rd86gkqa3ls356TqB6HzL2ZCiR9K5sOwZVHbvzFWdtqs1/HtOEWf5r/YA0f5J2wPoxooPi AN8aY8cSZ1uZ1KQFeUdIgci59dihfRw= X-MC-Unique: mlgGM0kvPEK27Zvp7SbgnA-1 X-Mimecast-MFC-AGG-ID: mlgGM0kvPEK27Zvp7SbgnA 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 v2 5/8] hypervisor: introduce helper for autostart Date: Wed, 12 Feb 2025 15:46:43 +0000 Message-ID: <20250212154646.913282-6-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kuLDuT2GzjqKeBmexUqE7jqM1ptgf2O6ApCMR4Ujvbw_1739375218 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DVKXH4VALA26RRPYLJ7K5QSZQYIDFVKV X-Message-ID-Hash: DVKXH4VALA26RRPYLJ7K5QSZQYIDFVKV 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: 1739375352469019000 Content-Type: text/plain; charset="utf-8" There's a common pattern for autostart of iterating over VMs, acquiring a lock and ref count, then checking the autostart & is-active flags. Wrap this all up into a helper method. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 41 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 17 ++++++++++++++ src/libvirt_private.syms | 1 + 3 files changed, 59 insertions(+) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 85d68b056c..596157545b 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -29,9 +29,12 @@ #include "viraccessapicheck.h" #include "datatypes.h" #include "driver.h" +#include "virlog.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 +VIR_LOG_INIT("hypervisor.domain_driver"); + char * virDomainDriverGenerateRootHash(const char *drivername, const char *root) @@ -652,3 +655,41 @@ virDomainDriverGetIOThreadsConfig(virDomainDef *target= Def, =20 return ret; } + +static int +virDomainDriverAutoStartOne(virDomainObj *vm, + void *opaque) +{ + virDomainDriverAutoStartConfig *cfg =3D opaque; + + virObjectLock(vm); + virObjectRef(vm); + + VIR_DEBUG("Autostart %s: autostart=3D%d", + vm->def->name, vm->autostart); + + if (vm->autostart && !virDomainObjIsActive(vm)) { + virResetLastError(); + cfg->callback(vm, cfg->opaque); + } + + virDomainObjEndAPI(&vm); + virResetLastError(); + + return 0; +} + +void +virDomainDriverAutoStart(virDomainObjList *domains, + virDomainDriverAutoStartConfig *cfg) +{ + bool autostart; + VIR_DEBUG("Run autostart stateDir=3D%s", cfg->stateDir); + if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0 || + !autostart) { + VIR_DEBUG("Autostart already processed"); + return; + } + + virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, c= fg); +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 9942f58fda..2ad4e96f3e 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -23,6 +23,7 @@ #include "node_device_conf.h" #include "virhostdev.h" #include "virpci.h" +#include "virdomainobjlist.h" =20 char * virDomainDriverGenerateRootHash(const char *drivername, @@ -71,3 +72,19 @@ int virDomainDriverDelIOThreadCheck(virDomainDef *def, int virDomainDriverGetIOThreadsConfig(virDomainDef *targetDef, virDomainIOThreadInfoPtr **info, unsigned int bitmap_size); + +/* + * Will be called with 'vm' locked and ref count held, + * which will be released when this returns. + */ +typedef void (*virDomainDriverAutoStartCallback)(virDomainObj *vm, + void *opaque); + +typedef struct _virDomainDriverAutoStartConfig { + const char *stateDir; + virDomainDriverAutoStartCallback callback; + void *opaque; +} virDomainDriverAutoStartConfig; + +void virDomainDriverAutoStart(virDomainObjList *domains, + virDomainDriverAutoStartConfig *cfg); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4eca252b2a..bd9564f2a7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1647,6 +1647,7 @@ virDomainCgroupSetupVcpuBW; =20 # hypervisor/domain_driver.h virDomainDriverAddIOThreadCheck; +virDomainDriverAutoStart; virDomainDriverDelIOThreadCheck; virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; --=20 2.47.1 From nobody Tue Dec 16 21:01:36 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 1739375379388697.1644244379273; Wed, 12 Feb 2025 07:49:39 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id ECD4C18EA; Wed, 12 Feb 2025 10:49:39 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9DBA71923; Wed, 12 Feb 2025 10:47:20 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1591B1A6A; Wed, 12 Feb 2025 10:47:16 -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 AA0FA17E7 for ; Wed, 12 Feb 2025 10:47:02 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-z408o7pLNx2rmliUUFbbSA-1; Wed, 12 Feb 2025 10:47:01 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3885C1800872 for ; Wed, 12 Feb 2025 15:47:00 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EDA7A1955F1B; Wed, 12 Feb 2025 15:46:58 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1739375222; 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=BzeImhss7xCKPjhOD0dr37mkUMI9N97m3TOxLl1uXOg=; b=ezDuAPQ9fMZtg2YPfMmwljVP9CuYnxR4Hi61OsYK1Q97TIQzIaAMRGVNLGLRxmyP8XzJmP USlP69fDeEAfIbH0CLqXL6sf369wGDxhzpcTGO+3722q37pZn4HANdgj4yMPtDmYaAyhJj ZzDN+EvCMTmiMkjXODZztZqTy8rqmEQ= X-MC-Unique: z408o7pLNx2rmliUUFbbSA-1 X-Mimecast-MFC-AGG-ID: z408o7pLNx2rmliUUFbbSA_1739375220 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 v2 6/8] src: convert drivers over to use new autostart helper Date: Wed, 12 Feb 2025 15:46:44 +0000 Message-ID: <20250212154646.913282-7-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: EfVxjb2LrZOLgw1ikMxi9zyqgfieEBjAwR8uODTYUik_1739375220 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6AAOHWJEP3TGV3ZPBPZU2MB2ADVENYHJ X-Message-ID-Hash: 6AAOHWJEP3TGV3ZPBPZU2MB2ADVENYHJ 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: 1739375382272019000 Content-Type: text/plain; charset="utf-8" This eliminates some duplicated code patterns aross drivers. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/bhyve/bhyve_driver.c | 41 ++++++++++++------------------ 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(+), 111 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index f6b0417014..4d83a0dd8a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -54,6 +54,7 @@ #include "virportallocator.h" #include "conf/domain_capabilities.h" #include "virutil.h" +#include "domain_driver.h" =20 #include "bhyve_conf.h" #include "bhyve_device.h" @@ -70,29 +71,18 @@ VIR_LOG_INIT("bhyve.bhyve_driver"); =20 struct _bhyveConn *bhyve_driver =3D NULL; =20 -static int +static void bhyveAutostartDomain(virDomainObj *vm, void *opaque G_GNUC_UNUSED) { int ret =3D 0; - VIR_LOCK_GUARD lock =3D virObjectLockGuard(vm); - - if (vm->autostart && !virDomainObjIsActive(vm)) { - virResetLastError(); - ret =3D virBhyveProcessStart(bhyve_driver, 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()); - } - } - return ret; -} =20 -static void -bhyveAutostartDomains(struct _bhyveConn *driver) -{ - virDomainObjListForEach(driver->domains, false, bhyveAutostartDomain, = NULL); + ret =3D virBhyveProcessStart(bhyve_driver, 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 /** @@ -1168,7 +1158,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", @@ -1253,11 +1243,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 a76545c9ff..bd858d8127 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 d785244dde..1bca9e8dae 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 78bfaa5b3a..0a4e423e70 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 From nobody Tue Dec 16 21:01:36 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 1739375406824146.63264811902945; Wed, 12 Feb 2025 07:50:06 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3362E1D88; Wed, 12 Feb 2025 10:50:06 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D215C1B58; Wed, 12 Feb 2025 10:47:23 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D5E211A91; Wed, 12 Feb 2025 10:47:19 -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 A2F1B18A6 for ; Wed, 12 Feb 2025 10:47:04 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-474-janCaQh9N9W0wAxqr1fzqQ-1; Wed, 12 Feb 2025 10:47:03 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 121FA1800873 for ; Wed, 12 Feb 2025 15:47:02 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BDA341955F21; Wed, 12 Feb 2025 15:47:00 +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.8 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=1739375224; 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=eY0ssBes3FdocbSq3wgZlV7CLTWCDRHpQmNsByAiOhA=; b=Lrn7taBG52fxOBSeoVxwEj1DoDZqxZXVERFCgK+RGJN4Fdbp6Q/L0BgzPVwMY6G9Dr6emz 4Z37b0qwt2KIvnfx43aI0DCDb7Hk9pytH9HUSKvSOcFI/3+8Ib8c5jTrPZqWiXRNUeDFwp 2LiRnbPDS3wYeALItdIK+GFo6E0oGaE= X-MC-Unique: janCaQh9N9W0wAxqr1fzqQ-1 X-Mimecast-MFC-AGG-ID: janCaQh9N9W0wAxqr1fzqQ 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 v2 7/8] hypervisor: add support for delay interval during autostart Date: Wed, 12 Feb 2025 15:46:45 +0000 Message-ID: <20250212154646.913282-8-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: nESJFm5Q7msP7_nMBk6cPWEeyKTFpVAgvZ71DqugNO0_1739375222 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: X7LUQW6SXTMRSMUJQFMYH4ONZEALGOVZ X-Message-ID-Hash: X7LUQW6SXTMRSMUJQFMYH4ONZEALGOVZ 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: 1739375408726019000 Content-Type: text/plain; charset="utf-8" This delay can reduce the CPU/IO load storm when autostarting many guests. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 20 +++++++++++++++++--- src/hypervisor/domain_driver.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 596157545b..bea84cd09d 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -656,11 +656,16 @@ virDomainDriverGetIOThreadsConfig(virDomainDef *targe= tDef, return ret; } =20 +typedef struct _virDomainDriverAutoStartState { + virDomainDriverAutoStartConfig *cfg; + bool first; +} virDomainDriverAutoStartState; + static int virDomainDriverAutoStartOne(virDomainObj *vm, void *opaque) { - virDomainDriverAutoStartConfig *cfg =3D opaque; + virDomainDriverAutoStartState *state =3D opaque; =20 virObjectLock(vm); virObjectRef(vm); @@ -670,7 +675,15 @@ virDomainDriverAutoStartOne(virDomainObj *vm, =20 if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); - cfg->callback(vm, cfg->opaque); + if (state->cfg->delayMS) { + if (!state->first) { + g_usleep(state->cfg->delayMS * 1000ull); + } else { + state->first =3D false; + } + } + + state->cfg->callback(vm, state->cfg->opaque); } =20 virDomainObjEndAPI(&vm); @@ -683,6 +696,7 @@ void virDomainDriverAutoStart(virDomainObjList *domains, virDomainDriverAutoStartConfig *cfg) { + virDomainDriverAutoStartState state =3D { .cfg =3D cfg, .first =3D tru= e }; bool autostart; VIR_DEBUG("Run autostart stateDir=3D%s", cfg->stateDir); if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0 || @@ -691,5 +705,5 @@ virDomainDriverAutoStart(virDomainObjList *domains, return; } =20 - virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, c= fg); + virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, &= state); } diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 2ad4e96f3e..f81d436c2c 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -84,6 +84,8 @@ typedef struct _virDomainDriverAutoStartConfig { const char *stateDir; virDomainDriverAutoStartCallback callback; void *opaque; + unsigned int delayMS; /* milliseconds to wait between initiating the + * startup of each guest */ } virDomainDriverAutoStartConfig; =20 void virDomainDriverAutoStart(virDomainObjList *domains, --=20 2.47.1 From nobody Tue Dec 16 21:01:36 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 1739375427373728.6011423803637; Wed, 12 Feb 2025 07:50:27 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6E1831AC8; Wed, 12 Feb 2025 10:50:26 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A15391D1A; Wed, 12 Feb 2025 10:47:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id F33B51A7A; Wed, 12 Feb 2025 10:47:24 -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 33DA218F7 for ; Wed, 12 Feb 2025 10:47:06 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-ujMtDfxENTyW2JDbrDxIdQ-1; Wed, 12 Feb 2025 10:47:04 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D621B180087A for ; Wed, 12 Feb 2025 15:47:03 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0C081955F1B; Wed, 12 Feb 2025 15:47:02 +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.8 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=1739375225; 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=JlEJ1kj9nJBdRVWVm+Yjoaj54yDagANXzoNzbbNyPQA=; b=fYJwZmGjchn7+6aZ0O1lAvJAANOBs3oPvHyOos5GMLS6jxXhR7D1mmyDW0Ds7HZMVlvPC6 Vrdk3hKN5WHEdvTe8gey2Bvyh1FTuQp3h12m7UiTJ2q9MsgWN3qrUMUkgTWGfbAr6B5nCd dRVco1sGzqGwcs8fc6Knf7iFcTmitLs= X-MC-Unique: ujMtDfxENTyW2JDbrDxIdQ-1 X-Mimecast-MFC-AGG-ID: ujMtDfxENTyW2JDbrDxIdQ 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 v2 8/8] qemu: add 'auto_start_delay' configuration parameter Date: Wed, 12 Feb 2025 15:46:46 +0000 Message-ID: <20250212154646.913282-9-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: swDljfPERJdmL9YP1gPIQN-TpsfMupEJTMhCj_0ktJs_1739375224 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5K4FT5AEZFS5V6RKCMCNDTHHS3WWRLRY X-Message-ID-Hash: 5K4FT5AEZFS5V6RKCMCNDTHHS3WWRLRY 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: 1739375429536019100 Content-Type: text/plain; charset="utf-8" This allows a user specified delay between autostart of each VM, giving parity with the equivalent feature of libvirt-guests. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 5 +++++ src/qemu/qemu_conf.c | 2 ++ src/qemu/qemu_conf.h | 1 + src/qemu/qemu_driver.c | 1 + src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 11 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 1377fd89cc..642093c40b 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -97,6 +97,7 @@ module Libvirtd_qemu =3D | str_entry "auto_dump_path" | bool_entry "auto_dump_bypass_cache" | bool_entry "auto_start_bypass_cache" + | int_entry "auto_start_delay" =20 let process_entry =3D str_entry "hugetlbfs_mount" | str_entry "bridge_helper" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index d853136f10..31172303dc 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -634,6 +634,11 @@ # #auto_start_bypass_cache =3D 0 =20 +# Delay in milliseconds between initiating the startup for +# each VM, during autostart +# +#auto_start_delay =3D 0 + # If provided by the host and a hugetlbfs mount point is configured, # a guest may request huge page backing. When this mount point is # unspecified here, determination of a host mount point in /proc/mounts diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 8b9fe4e381..b73dda7e10 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -638,6 +638,8 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *c= fg, return -1; if (virConfGetValueBool(conf, "auto_start_bypass_cache", &cfg->autoSta= rtBypassCache) < 0) return -1; + if (virConfGetValueUInt(conf, "auto_start_delay", &cfg->autoStartDelay= MS) < 0) + return -1; =20 return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 42cdb6f883..97214f72d0 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -200,6 +200,7 @@ struct _virQEMUDriverConfig { char *autoDumpPath; bool autoDumpBypassCache; bool autoStartBypassCache; + unsigned int autoStartDelayMS; =20 char *lockManagerName; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0a4e423e70..1bdf3c1622 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -887,6 +887,7 @@ qemuStateInitialize(bool privileged, .stateDir =3D cfg->stateDir, .callback =3D qemuAutostartDomain, .opaque =3D qemu_driver, + .delayMS =3D cfg->autoStartDelayMS, }; virDomainDriverAutoStart(qemu_driver->domains, &autostartCfg); =20 diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 69fdae215a..c2a1d7d829 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -75,6 +75,7 @@ module Test_libvirtd_qemu =3D { "auto_dump_path" =3D "/var/lib/libvirt/qemu/dump" } { "auto_dump_bypass_cache" =3D "0" } { "auto_start_bypass_cache" =3D "0" } +{ "auto_start_delay" =3D "0" } { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "qemu-bridge-helper" } { "set_process_name" =3D "1" } --=20 2.47.1