From nobody Tue Mar 24 01:15:30 2026 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1774102877; cv=none; d=zohomail.com; s=zohoarc; b=AVEMwC9AhWKfWuCizhyOLARDXEanztJgmkHbgn5jDgQri583DbxnNEOVmCZXFOuomF5cUQyusn5mMIldrbr5MMZMK6YoxQ+q/wWwoZmPZW2/wb15E1uRWML1jAKbAwVFp/ACfs8Dj08NhDKl/UwD8BfoYHLmS6xhUOIrsHQuuTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774102877; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=+6ebdc7pvIrWdxGvg5zH2AnKWg8PzlQFS5sc58DlATE=; b=hrOvkLHPrxBJaoHbdhPZIZrwNpJbFC/+jTwodZfcvbYbzHL5/o7P0hKgyc7N5VgbvniS4duW4c+KlARXZcI5i3E5bHb/qkToHCvvOHq8mnatW98f7Z5gPk3AoU/V3/ZPvfyLLFVn0v00tEofAlpJyHsUTG2eHbvQ00cC/nP2oqQ= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1774102877093425.9595128388585; Sat, 21 Mar 2026 07:21:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 1497C41ABA; Sat, 21 Mar 2026 10:21:16 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 0517441B54; Sat, 21 Mar 2026 10:19:46 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 23E103F362; Sat, 21 Mar 2026 10:19:40 -0400 (EDT) Received: from smtp-bc0c.mail.infomaniak.ch (smtp-bc0c.mail.infomaniak.ch [45.157.188.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2F9153F94A for ; Sat, 21 Mar 2026 10:19:39 -0400 (EDT) Received: from smtp-3-0000.mail.infomaniak.ch (unknown [IPv6:2001:1600:4:17::246b]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4fdLt704KMzFnm; Sat, 21 Mar 2026 15:10:07 +0100 (CET) Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4fdLt648Mfz2fG; Sat, 21 Mar 2026 15:10:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Greylist: delayed 571 seconds by postgrey-1.37 at lists.libvirt.org; Sat, 21 Mar 2026 10:19:39 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gugod.fr; s=20250112; t=1774102206; bh=+6ebdc7pvIrWdxGvg5zH2AnKWg8PzlQFS5sc58DlATE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SvK7zEI7rNQ+j7E2/n2209pEh8HU1uPDxX8dSpHyYUytkuvfOVjsIBliGRKo8ii9S ZQMFqe5oc2X+ergBflx6dm32uY19COobbIMRsLBbJUQ+lNxbIA5z0ceVmB1suygIxx ObPiOObVL9Co29n9YlnTeGRlRQUzLW5tun4mkHtkGoJw02yn84lJwlbQDs1JlLASKf B+L+9BTmFpePQL6EJGBcAtrq07HrjePh+EyL8YejweuItm3zVATJTRzi0zZ3fTwool HaoLHecHHSKrenPd6lyYNITcXdafHqow/tZ0bDL2dGgkTi9WAoYe+lQj41iaQvMQNG TAkst2lBIWqPg== To: devel@lists.libvirt.org Subject: [PATCHv2 3/4] qemu, libxl: migration: Call hook script on source host at migration start Date: Sat, 21 Mar 2026 15:09:03 +0100 Message-ID: <20260321140923.23807-4-guy.godfroy@gugod.fr> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260321140923.23807-1-guy.godfroy@gugod.fr> References: <20260321140923.23807-1-guy.godfroy@gugod.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Infomaniak-Routing: alpha Message-ID-Hash: XZRQWJG3SBWYTVGSN7TS53XOSX7KIRHQ X-Message-ID-Hash: XZRQWJG3SBWYTVGSN7TS53XOSX7KIRHQ X-MailFrom: guy.godfroy@gugod.fr X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pkrempa@redhat.com, Guy Godfroy X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Guy Godfroy via Devel Reply-To: Guy Godfroy X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774102879464158500 Content-Type: text/plain; charset="utf-8" Currently, the hook script with the "migrate" operation is only called on the destination host at the beginning of incoming migration. This makes it impossible for the source host to prepare for migration, for example to change storage locks from exclusive to shared mode when using shared LVM storage with lvmlockd. Add a hook call on the source host at the beginning of outgoing migration using the new "migrate-outgoing" operation. The hook is called with "source" as the extra argument and "begin" as the sub-operation. The script is not used as a filter; its output is ignored. If the script returns failure, the migration is canceled. The same change is also applied to the libxl driver for consistency. Signed-off-by: Guy Godfroy --- docs/hooks.rst | 32 ++++++++++++++++++++++++++++++-- src/libxl/libxl_migration.c | 17 +++++++++++++++++ src/qemu/qemu_migration.c | 17 +++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/docs/hooks.rst b/docs/hooks.rst index 0310e0d82c..cff1711536 100644 --- a/docs/hooks.rst +++ b/docs/hooks.rst @@ -257,6 +257,18 @@ operation. There is no specific operation to indicate = a "restart" is occurring. is not valid, incoming migration will be canceled. This hook may be use= d, e.g., to change location of disk images for incoming domains. =20 +- :since:`Since 12.3.0`, the qemu hook script is also called at the begin= ning + of outgoing migration on the **source** host. It is called as: + + :: + + /etc/libvirt/hooks/qemu guest_name migrate-outgoing begin source + + with domain XML sent to standard input of the script. Unlike the destin= ation + hook, this script does not act as a filter and any output is ignored. I= f the + script returns failure, the migration will be canceled. This hook may b= e used, + e.g., to change storage lock mode from exclusive to shared before migra= tion. + - :since:`Since 1.2.9`, the qemu hook script is also called when restorin= g a saved image either via the API or automatically when restoring a manage= d save machine. It is called as: @@ -430,6 +442,18 @@ operation. There is no specific operation to indicate = a "restart" is occurring. is not valid, incoming migration will be canceled. This hook may be use= d, e.g., to change location of disk images for incoming domains. =20 +- :since:`Since 12.3.0`, the libxl hook script is also called at the begi= nning + of outgoing migration on the **source** host. It is called as: + + :: + + /etc/libvirt/hooks/libxl guest_name migrate-outgoing begin source + + with domain XML sent to standard input of the script. Unlike the destin= ation + hook, this script does not act as a filter and any output is ignored. I= f the + script returns failure, the migration will be canceled. This hook may b= e used, + e.g., to change storage lock mode from exclusive to shared before migra= tion. + - :since:`Since 6.5.0`, you can also place several hook scripts in the directory ``/etc/libvirt/hooks/libxl.d/``. They are executed in alphabe= tical order after main script. In this case each script also acts as filter a= nd can @@ -566,10 +590,14 @@ Migration of a QEMU guest involves running hook scrip= ts on both the source and destination hosts: =20 #. At the beginning of the migration, the *qemu* hook script on the - **destination** host is executed with the "migrate" operation. + **source** host is executed with the "migrate-outgoing" operation and + "source" as the extra argument (:since:`since 12.3.0`). This allows the + source host to prepare for migration, e.g., changing storage locks. +#. Then, the *qemu* hook script on the **destination** host is executed + with the "migrate" operation. #. Before QEMU process is spawned, the two operations ("prepare" and "star= t") called for domain start are executed on **destination** host. -#. If both of these hook script executions exit successfully (exit status = 0), +#. If all of these hook script executions exit successfully (exit status 0= ), the migration continues. Any other exit code indicates failure, and the migration is aborted. #. The QEMU guest is then migrated to the destination host. diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index f5dee7627b..be51cfd316 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -411,6 +411,23 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn, if (!libxlDomainMigrationIsAllowed(def)) goto endjob; =20 + /* Call hook to allow source host to prepare for migration */ + if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) { + g_autofree char *hookxml =3D NULL; + int hookret; + + if (!(hookxml =3D virDomainDefFormat(def, driver->xmlopt, + VIR_DOMAIN_DEF_FORMAT_SECURE))) + goto endjob; + + hookret =3D virHookCall(VIR_HOOK_DRIVER_LIBXL, def->name, + VIR_HOOK_LIBXL_OP_MIGRATE_OUTGOING, VIR_HOOK= _SUBOP_BEGIN, + "source", hookxml, NULL); + + if (hookret < 0) + goto endjob; + } + xml =3D virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_= SECURE); /* Valid xml means success! EndJob in the confirm phase */ if (xml) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index fec808ccfb..e9ce2d8b8b 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2870,6 +2870,23 @@ qemuMigrationSrcBeginPhase(virQEMUDriver *driver, vm->newDef && !qemuDomainVcpuHotplugIsInOrder(vm->newDef))) cookieFlags |=3D QEMU_MIGRATION_COOKIE_CPU_HOTPLUG; =20 + /* Call hook to allow source host to prepare for migration */ + if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { + g_autofree char *xml =3D NULL; + int hookret; + + if (!(xml =3D qemuDomainDefFormatLive(driver, priv->qemuCaps, vm->= def, + priv->origCPU, false, true))) + return NULL; + + hookret =3D virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, + VIR_HOOK_QEMU_OP_MIGRATE_OUTGOING, VIR_HOOK_= SUBOP_BEGIN, + "source", xml, NULL); + + if (hookret < 0) + return NULL; + } + if (qemuBlockNodesEnsureActive(vm, vm->job->asyncJob) < 0) return NULL; =20 --=20 2.53.0