From nobody Sun Feb 8 11:16:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652196244; cv=none; d=zohomail.com; s=zohoarc; b=Y7CGGyMhDPorq2MOy5N3kbY46+dIppQr2y6ie8vvDYb/+vCqMFpOkp52bFY0/pxCL3rRVSml/JpOmM4teIlS69nPfimwJ0WE0a8k8BQdsErYeM/6dCpEG6gqQw5oa7cWSaLwv7nXRQlfqWGlrv3Y37s9FSs8HKC4E6U/4UlKUVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652196244; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5X8lIL9QvWEYYGqM4BWtOkbmXLULmOenV185rb/wI1Y=; b=Zk+Xis+7cw9cj4Virrxu23hBb5kT+I1agjRXgkISt92hQBbuspFcp1T1/3iNOFE6ZMdjCtVcu5KKCkxYLKDrmXu5Hkn7N1DmnoQS3HlV3cbOF74A3NyAgiFCuVwbwZZgV/QW7UgEGPmgywuBMM81lY6HNzHBMjyPzwJaqZupScQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1652196244868712.8990464399469; Tue, 10 May 2022 08:24:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-PVBHY1Q8Psq-ndRJYPV2WA-1; Tue, 10 May 2022 11:22:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2BB11382ECED; Tue, 10 May 2022 15:21:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14B4540D1B9A; Tue, 10 May 2022 15:21:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3A789194706B; Tue, 10 May 2022 15:21:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5BB2C1947077 for ; Tue, 10 May 2022 15:21:48 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4A73014E0B4C; Tue, 10 May 2022 15:21:48 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0E89814E0B4D for ; Tue, 10 May 2022 15:21:48 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 9EE3624460A; Tue, 10 May 2022 17:21:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652196243; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5X8lIL9QvWEYYGqM4BWtOkbmXLULmOenV185rb/wI1Y=; b=AlGeHTVMMhYm2TMofdzZcw3aOqmtMNni7pWqFolDs3FQzkzP007AHCrgSq6M3UqTFjztmO OlC7jhutcHJeKXKiqBg/BCAiB6qA5OzyENxPfDrGFnpSEPTBuJW1YLyn8ajHwYki+Grtdi eiQRhZsHzNIiX/8qx4J5d9Spu4kpGD4= X-MC-Unique: PVBHY1Q8Psq-ndRJYPV2WA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 35/80] qemu: Introduce qemuMigrationDstFinishActive Date: Tue, 10 May 2022 17:20:56 +0200 Message-Id: <7d9fb1dec92f782970ed97a61137bea922da9efe.1652196064.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652196245055100003 Content-Type: text/plain; charset="utf-8" Refactors qemuMigrationDstFinish by moving some parts to a dedicated function for easier introduction of postcopy resume code without duplicating common parts of the Finish phase. The goal is to have the following call graph: - qemuMigrationDstFinish - qemuMigrationDstFinishOffline - qemuMigrationDstFinishActive - qemuMigrationDstFinishFresh - qemuMigrationDstFinishResume Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/qemu/qemu_migration.c | 173 +++++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 70 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 170d99d789..d02e8132e4 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -6004,71 +6004,32 @@ qemuMigrationDstFinishFresh(virQEMUDriver *driver, } =20 =20 -virDomainPtr -qemuMigrationDstFinish(virQEMUDriver *driver, - virConnectPtr dconn, - virDomainObj *vm, - const char *cookiein, - int cookieinlen, - char **cookieout, - int *cookieoutlen, - unsigned long flags, - int retcode, - bool v3proto) +static virDomainPtr +qemuMigrationDstFinishActive(virQEMUDriver *driver, + virConnectPtr dconn, + virDomainObj *vm, + int cookie_flags, + const char *cookiein, + int cookieinlen, + char **cookieout, + int *cookieoutlen, + unsigned long flags, + int retcode, + bool v3proto, + unsigned long long timeReceived, + virErrorPtr *orig_err) { virDomainPtr dom =3D NULL; g_autoptr(qemuMigrationCookie) mig =3D NULL; - virErrorPtr orig_err =3D NULL; - int cookie_flags =3D 0; qemuDomainObjPrivate *priv =3D vm->privateData; qemuDomainJobPrivate *jobPriv =3D priv->job.privateData; - unsigned short port; - unsigned long long timeReceived =3D 0; virObjectEvent *event; bool inPostCopy =3D false; bool doKill =3D true; int rc; =20 - VIR_DEBUG("driver=3D%p, dconn=3D%p, vm=3D%p, cookiein=3D%s, cookieinle= n=3D%d, " - "cookieout=3D%p, cookieoutlen=3D%p, flags=3D0x%lx, retcode= =3D%d", - driver, dconn, vm, NULLSTR(cookiein), cookieinlen, - cookieout, cookieoutlen, flags, retcode); - - port =3D priv->migrationPort; - priv->migrationPort =3D 0; - - if (!qemuMigrationJobIsActive(vm, VIR_ASYNC_JOB_MIGRATION_IN)) { - qemuMigrationDstErrorReport(driver, vm->def->name); - goto cleanup; - } - - ignore_value(virTimeMillisNow(&timeReceived)); - - qemuMigrationJobStartPhase(vm, - v3proto ? QEMU_MIGRATION_PHASE_FINISH3 - : QEMU_MIGRATION_PHASE_FINISH2); - - qemuDomainCleanupRemove(vm, qemuMigrationDstPrepareCleanup); - g_clear_pointer(&priv->job.completed, virDomainJobDataFree); - - cookie_flags =3D QEMU_MIGRATION_COOKIE_NETWORK | - QEMU_MIGRATION_COOKIE_STATS | - QEMU_MIGRATION_COOKIE_NBD; - /* Some older versions of libvirt always send persistent XML in the co= okie - * even though VIR_MIGRATE_PERSIST_DEST was not used. */ - cookie_flags |=3D QEMU_MIGRATION_COOKIE_PERSISTENT; - - if (flags & VIR_MIGRATE_OFFLINE) { - if (retcode =3D=3D 0) { - dom =3D qemuMigrationDstFinishOffline(driver, dconn, vm, - cookie_flags, - cookiein, cookieinlen, - cookieout, cookieoutlen); - } - - qemuMigrationJobFinish(vm); - goto cleanup; - } + VIR_DEBUG("vm=3D%p, flags=3D0x%lx, retcode=3D%d", + vm, flags, retcode); =20 if (!(mig =3D qemuMigrationCookieParse(driver, vm->def, priv->origname= , priv, cookiein, cookieinlen, cookie_fla= gs))) @@ -6106,25 +6067,12 @@ qemuMigrationDstFinish(virQEMUDriver *driver, =20 qemuMigrationJobFinish(vm); =20 - cleanup: - virPortAllocatorRelease(port); - if (priv->mon) - qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL); - VIR_FREE(priv->origname); - virDomainObjEndAPI(&vm); - virErrorRestore(&orig_err); - - /* Set a special error if Finish is expected to return NULL as a resul= t of - * successful call with retcode !=3D 0 - */ - if (retcode !=3D 0 && !dom && virGetLastErrorCode() =3D=3D VIR_ERR_OK) - virReportError(VIR_ERR_MIGRATE_FINISH_OK, NULL); return dom; =20 error: /* Need to save the current error, in case shutting down the process * overwrites it. */ - virErrorPreserveLast(&orig_err); + virErrorPreserveLast(orig_err); =20 if (virDomainObjIsActive(vm)) { if (doKill) { @@ -6155,7 +6103,92 @@ qemuMigrationDstFinish(virQEMUDriver *driver, if (!virDomainObjIsActive(vm)) qemuDomainRemoveInactive(driver, vm); =20 - goto cleanup; + return NULL; +} + + +virDomainPtr +qemuMigrationDstFinish(virQEMUDriver *driver, + virConnectPtr dconn, + virDomainObj *vm, + const char *cookiein, + int cookieinlen, + char **cookieout, + int *cookieoutlen, + unsigned long flags, + int retcode, + bool v3proto) +{ + virDomainPtr dom =3D NULL; + virErrorPtr orig_err =3D NULL; + int cookie_flags =3D 0; + qemuDomainObjPrivate *priv =3D vm->privateData; + unsigned short port; + unsigned long long timeReceived =3D 0; + + VIR_DEBUG("driver=3D%p, dconn=3D%p, vm=3D%p, cookiein=3D%s, cookieinle= n=3D%d, " + "cookieout=3D%p, cookieoutlen=3D%p, flags=3D0x%lx, retcode= =3D%d", + driver, dconn, vm, NULLSTR(cookiein), cookieinlen, + cookieout, cookieoutlen, flags, retcode); + + port =3D priv->migrationPort; + priv->migrationPort =3D 0; + + if (!qemuMigrationJobIsActive(vm, VIR_ASYNC_JOB_MIGRATION_IN)) { + qemuMigrationDstErrorReport(driver, vm->def->name); + goto cleanup; + } + + ignore_value(virTimeMillisNow(&timeReceived)); + + qemuMigrationJobStartPhase(vm, + v3proto ? QEMU_MIGRATION_PHASE_FINISH3 + : QEMU_MIGRATION_PHASE_FINISH2); + + qemuDomainCleanupRemove(vm, qemuMigrationDstPrepareCleanup); + g_clear_pointer(&priv->job.completed, virDomainJobDataFree); + + cookie_flags =3D QEMU_MIGRATION_COOKIE_NETWORK | + QEMU_MIGRATION_COOKIE_STATS | + QEMU_MIGRATION_COOKIE_NBD; + /* Some older versions of libvirt always send persistent XML in the co= okie + * even though VIR_MIGRATE_PERSIST_DEST was not used. */ + cookie_flags |=3D QEMU_MIGRATION_COOKIE_PERSISTENT; + + if (flags & VIR_MIGRATE_OFFLINE) { + if (retcode =3D=3D 0) { + dom =3D qemuMigrationDstFinishOffline(driver, dconn, vm, + cookie_flags, + cookiein, cookieinlen, + cookieout, cookieoutlen); + } + + qemuMigrationJobFinish(vm); + goto cleanup; + } + + dom =3D qemuMigrationDstFinishActive(driver, dconn, vm, cookie_flags, + cookiein, cookieinlen, + cookieout, cookieoutlen, + flags, retcode, v3proto, timeReceiv= ed, + &orig_err); + if (!dom) + goto cleanup; + + cleanup: + virPortAllocatorRelease(port); + if (priv->mon) + qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL); + VIR_FREE(priv->origname); + virDomainObjEndAPI(&vm); + virErrorRestore(&orig_err); + + /* Set a special error if Finish is expected to return NULL as a resul= t of + * successful call with retcode !=3D 0 + */ + if (retcode !=3D 0 && !dom && virGetLastErrorCode() =3D=3D VIR_ERR_OK) + virReportError(VIR_ERR_MIGRATE_FINISH_OK, NULL); + return dom; } =20 =20 --=20 2.35.1