From nobody Tue Jan 21 07:37:10 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 1736365971091713.1286428115808; Wed, 8 Jan 2025 11:52:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2658D1558; Wed, 8 Jan 2025 14:52:50 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 32BFF14C7; Wed, 8 Jan 2025 14:44:13 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DD630144B; Wed, 8 Jan 2025 14:43: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 799A6140B for ; Wed, 8 Jan 2025 14:43:28 -0500 (EST) Received: from mx-prod-mc-02.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-33--CPRQtUpODSlXnnvc9rkiQ-1; Wed, 08 Jan 2025 14:43:26 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 158AC19560AF for ; Wed, 8 Jan 2025 19:43:25 +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 3B77A300018D; Wed, 8 Jan 2025 19:43:24 +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=1736365408; 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=CTpYzGiLEC0+Zjb9NECc7bo9K0bhcZlwebUtFD/JwnA=; b=akAKeP5y/grLTgGsbNMlfUeYdcj76y3FEfJ+KdTKcZGqhWzih+k0i06XhBDWDHQLz9gb5y W10UVjAdo77rspEJMy0/Q9o1EqJDdtVImxGug3tomA8A/QI7qaSgOHeDsLpE6Q0pDasLZc Tlp3LPCVxZQuttFg0Htcvw7khwhRH8Y= X-MC-Unique: -CPRQtUpODSlXnnvc9rkiQ-1 X-Mimecast-MFC-AGG-ID: -CPRQtUpODSlXnnvc9rkiQ 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 19/26] qemu: wire up support for once only autostart Date: Wed, 8 Jan 2025 19:42:52 +0000 Message-ID: <20250108194259.1171990-20-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: LT7WI2csVFTESY2G8qxEm210MWQAR-cPyczZ6RAB7aQ_1736365405 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ORO7G5ERZMIJ64O3YU3SCI7SPYEWLX5L X-Message-ID-Hash: ORO7G5ERZMIJ64O3YU3SCI7SPYEWLX5L 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: 1736365971285116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_driver.c | 95 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8729b0fab0..84bde503dd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7778,6 +7778,99 @@ static int qemuDomainSetAutostart(virDomainPtr dom, } =20 =20 +static int qemuDomainGetAutostartOnce(virDomainPtr dom, + int *autostart) +{ + virDomainObj *vm; + int ret =3D -1; + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + goto cleanup; + + if (virDomainGetAutostartOnceEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + *autostart =3D vm->autostartOnce; + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int qemuDomainSetAutostartOnce(virDomainPtr dom, + int autostart) +{ + virQEMUDriver *driver =3D dom->conn->privateData; + virDomainObj *vm; + g_autofree char *configFile =3D NULL; + g_autofree char *autostartLink =3D NULL; + g_autofree char *autostartOnceLink =3D NULL; + int ret =3D -1; + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainSetAutostartOnceEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (!vm->persistent) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot set autostart for transient domain"= )); + goto cleanup; + } + + autostart =3D (autostart !=3D 0); + + if (vm->autostartOnce !=3D autostart) { + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + configFile =3D virDomainConfigFile(cfg->configDir, vm->def->name); + autostartLink =3D virDomainConfigFile(cfg->autostartDir, vm->def->= name); + autostartOnceLink =3D g_strdup_printf("%s.once", autostartLink); + + if (autostart) { + if (g_mkdir_with_parents(cfg->autostartDir, 0777) < 0) { + virReportSystemError(errno, + _("cannot create autostart directory = %1$s"), + cfg->autostartDir); + goto endjob; + } + + if (symlink(configFile, autostartOnceLink) < 0) { + virReportSystemError(errno, + _("Failed to create symlink '%1$s' to= '%2$s'"), + autostartOnceLink, configFile); + goto endjob; + } + } else { + if (unlink(autostartOnceLink) < 0 && + errno !=3D ENOENT && + errno !=3D ENOTDIR) { + virReportSystemError(errno, + _("Failed to delete symlink '%1$s'"), + autostartOnceLink); + goto endjob; + } + } + + vm->autostartOnce =3D autostart; + + endjob: + virDomainObjEndJob(vm); + } + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static char *qemuDomainGetSchedulerType(virDomainPtr dom, int *nparams) { @@ -20257,6 +20350,8 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainSetLaunchSecurityState =3D qemuDomainSetLaunchSecurityState, /*= 8.0.0 */ .domainFDAssociate =3D qemuDomainFDAssociate, /* 9.0.0 */ .domainGraphicsReload =3D qemuDomainGraphicsReload, /* 10.2.0 */ + .domainGetAutostartOnce =3D qemuDomainGetAutostartOnce, /* 11.0.0 */ + .domainSetAutostartOnce =3D qemuDomainSetAutostartOnce, /* 11.0.0 */ }; =20 =20 --=20 2.47.1