From nobody Sun Dec 22 06:14:05 2024 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 1726824930082877.2432894044898; Fri, 20 Sep 2024 02:35:30 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 49ADB15B8; Fri, 20 Sep 2024 05:35:27 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 56160148F; Fri, 20 Sep 2024 05:35:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9E8D41472; Fri, 20 Sep 2024 05:35:01 -0400 (EDT) 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 409DF140E for ; Fri, 20 Sep 2024 05:35:00 -0400 (EDT) Received: from mx-prod-mc-03.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-257-YU3szN3MMoSkT3E4FgOvMA-1; Fri, 20 Sep 2024 05:34:58 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (unknown [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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DA3331933194 for ; Fri, 20 Sep 2024 09:34:57 +0000 (UTC) Received: from ajulis-thinkpadt14gen4.remote.csb (unknown [10.45.225.63]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 10D423000238 for ; Fri, 20 Sep 2024 09:34: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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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=1726824899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K3jejx2hUUkbV5co+00C8f0urpmOxmYq40clMxkIl8Y=; b=BdNn+nGyNYnyPirTL3fS4J82Vhgftlk/TCghMw5hlCoLEw5ICuZxpzfPUXWP9TusHLBEw7 Ge52k7cPG7U5bprPDtk9BJuJu6mcAMKR5KISG2MR6Af4+LwhFKkEGDfTF0Xsn+6YkkuubF TVLpXVjrRL+UXPLMzr5NhzZsJJis81w= X-MC-Unique: YU3szN3MMoSkT3E4FgOvMA-1 From: Adam Julis To: devel@lists.libvirt.org Subject: [PATCH] qemu: add hook script event "stop" Date: Fri, 20 Sep 2024 11:34:51 +0200 Message-ID: <87135f8a692a618335c149aafd6ed30208f3a4ae.1726824825.git.ajulis@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-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QPV6RFITAEDI2KMB6WQHSIIX33XZW7K5 X-Message-ID-Hash: QPV6RFITAEDI2KMB6WQHSIIX33XZW7K5 X-MailFrom: ajulis@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: 1726824932581116600 Content-Type: text/plain; charset="utf-8"; x-default="true" The "stop" hook is called when the process of stopping a guest started and it is known that the process can be completed (e.g. the guest is still active). Resolves: https://gitlab.com/libvirt/libvirt/-/issues/647 Signed-off-by: Adam Julis --- docs/hooks.rst | 14 +++++++++++--- src/qemu/qemu_process.c | 10 ++++++++++ src/util/virhook.c | 1 + src/util/virhook.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/hooks.rst b/docs/hooks.rst index 48128ba3d8..508d5afc4e 100644 --- a/docs/hooks.rst +++ b/docs/hooks.rst @@ -202,9 +202,17 @@ operation. There is no specific operation to indicate = a "restart" is occurring. =20 /etc/libvirt/hooks/qemu guest_name started begin - =20 -- When a QEMU guest is stopped, the qemu hook script is called in two - locations, to match the startup. First, :since:`since 0.8.0`, the hook = is - called before libvirt restores any labels: +- Before a QEMU guest is stopped, the qemu hook script is called in three + locations, to match the startup. First, :since:`since 10.8.0`, the hook= is + called after libvirt checks that guest is still active and whole stoppi= ng + procedure should be run: + + :: + + /etc/libvirt/hooks/qemu guest_name stop begin - + + The second location, :since:`since 0.8.0`, the hook is called before li= bvirt + restores any labels: =20 :: =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2e4ee9e305..f12c4a97a6 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8615,6 +8615,7 @@ qemuProcessBeginStopJob(virDomainObj *vm, * is supposed to call qemuProcessStop (which will reset it after * 'vm->def->id' is set to -1) and/or qemuProcessEndStopJob to do prop= er * cleanup. */ + return 0; =20 error: @@ -8676,6 +8677,15 @@ void qemuProcessStop(virQEMUDriver *driver, goto endjob; } =20 + if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { + g_autofree char *xml =3D qemuDomainDefFormatXML(driver, NULL, vm->= def, 0); + + /* we can't stop the operation even if the script raised an error = */ + ignore_value(virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, + VIR_HOOK_QEMU_OP_STOP, VIR_HOOK_SUBOP_BEG= IN, + NULL, xml, NULL)); + } + /* BEWARE: At this point 'vm->def->id' is not cleared yet. Any code th= at * requires the id (e.g. to call virDomainDefGetShortName()) must be p= laced * between here (after the VM is killed) and the statement clearing th= e id. diff --git a/src/util/virhook.c b/src/util/virhook.c index d012bb1825..01ba17e406 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -76,6 +76,7 @@ VIR_ENUM_IMPL(virHookSubop, VIR_ENUM_IMPL(virHookQemuOp, VIR_HOOK_QEMU_OP_LAST, "start", + "stop", "stopped", "prepare", "release", diff --git a/src/util/virhook.h b/src/util/virhook.h index d8237c837e..ea8c540c3f 100644 --- a/src/util/virhook.h +++ b/src/util/virhook.h @@ -52,6 +52,7 @@ typedef enum { =20 typedef enum { VIR_HOOK_QEMU_OP_START, /* domain is about to start */ + VIR_HOOK_QEMU_OP_STOP, /* domain is about to stop */ VIR_HOOK_QEMU_OP_STOPPED, /* domain has stopped */ VIR_HOOK_QEMU_OP_PREPARE, /* domain startup initiated */ VIR_HOOK_QEMU_OP_RELEASE, /* domain destruction is over */ --=20 2.45.2