From nobody Sun Feb 8 06:49:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1662036612; cv=none; d=zohomail.com; s=zohoarc; b=cHUfo0E5nZa+RSWezI9PDX+FGY7UiKHM6fX/lHGRhi2xOP09rTGAMaJ1ZWPFhZKqWc7gPZVFw7iAu1QfpB8T61V6vytIasH6yakHeEIzBy20NBcbSC9NpJP5bvdxlLEh6mGB8/DM8Au/RBxiOqLg6BcnRQcoPvlmGfrzdnLOKvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662036612; 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=7bvAkTwieNQMtOi4MOhBuF9a2tI7ObFFGG0+DpORV9E=; b=D2tSH5G/oEzX9JHzIaRGjbct3idxuKp0cZwyohbYFcq4HBijiOgKc+Ndfexpu2PUMoqLCy8LRqCh2LlrHpFjovo8Yy3qhsBf/+sB3TXopdirdPuzh3Ie/419OcdQI8YwtjMLgd0hnCF7ag6XbcTldsqyAVVn8J8Gf15NnhqIzVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1662036612698732.5324794276679; Thu, 1 Sep 2022 05:50:12 -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-1-j9F2qlHOMQe_nrzLomuwRQ-1; Thu, 01 Sep 2022 08:50:08 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 13B163800C35; Thu, 1 Sep 2022 12:50:06 +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 00335492CA2; Thu, 1 Sep 2022 12:50:05 +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 D36D71943214; Thu, 1 Sep 2022 12:50:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D68451946A5E for ; Thu, 1 Sep 2022 12:47:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A6281403344; Thu, 1 Sep 2022 12:47:44 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D242492C3B for ; Thu, 1 Sep 2022 12:47:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 61302240A7C; Thu, 1 Sep 2022 14:47:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662036611; 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=7bvAkTwieNQMtOi4MOhBuF9a2tI7ObFFGG0+DpORV9E=; b=egmpYu/+tV5PfG41Elne+g0pVK2Lg7+lv2MOP0gjdbigVnulSqxG0PyAYtSV8t8Cv7Lur3 XRh/MUypaRFXT3/OfTc3/gpEzDJZjByPFlI0HEw1mAGM+Zbk7oREeT/cBaN/Sne7bJwQJH sJBR//m5Ep28VNlHftuE4Z6my2vPzVU= X-MC-Unique: j9F2qlHOMQe_nrzLomuwRQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 3/3] qemu: Make qemuMigrationSrcCancel optionally synchronous Date: Thu, 1 Sep 2022 14:47:41 +0200 Message-Id: <0c9b7fc17023923c574fa8a3e91f48226b76e449.1662036411.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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.85 on 10.11.54.9 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: 1662036614802100001 Content-Type: text/plain; charset="utf-8" We have always considered "migrate_cancel" QMP command to return after successfully cancelling the migration. But this is no longer true (to be honest I'm not sure it ever was) as it just changes the migration state to "cancelling". In most cases the migration is canceled pretty quickly and we don't really notice anything, but sometimes it takes so long we even get to clearing migration capabilities before the migration is actually canceled, which fails as capabilities can only be changed when no migration is running. So to avoid this issue, we can wait for the migration to be really canceled after sending migrate_cancel. The only place where we don't need synchronous behavior is when we're cancelling migration on user's request while it is actively watched by another thread. https://bugzilla.redhat.com/show_bug.cgi?id=3D2114866 Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 45 +++++++++++++++++++++++++++++++++++---- src/qemu/qemu_migration.h | 3 ++- src/qemu/qemu_process.c | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a86efc769a..71a1de19b8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12811,7 +12811,7 @@ qemuDomainAbortJobMigration(virDomainObj *vm) VIR_DEBUG("Cancelling migration job at client request"); =20 qemuDomainObjAbortAsyncJob(vm); - return qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); + return qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE, false); } =20 =20 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 5845dfdb9c..83c3ca4dcf 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4611,9 +4611,37 @@ qemuMigrationSrcStart(virDomainObj *vm, } =20 =20 +static bool +qemuMigrationSrcIsCanceled(virDomainObj *vm) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + virDomainJobData *jobData =3D priv->job.current; + + qemuMigrationUpdateJobType(jobData); + switch (jobData->status) { + case VIR_DOMAIN_JOB_STATUS_FAILED: + case VIR_DOMAIN_JOB_STATUS_CANCELED: + case VIR_DOMAIN_JOB_STATUS_COMPLETED: + case VIR_DOMAIN_JOB_STATUS_NONE: + return true; + + case VIR_DOMAIN_JOB_STATUS_MIGRATING: + case VIR_DOMAIN_JOB_STATUS_POSTCOPY: + case VIR_DOMAIN_JOB_STATUS_PAUSED: + case VIR_DOMAIN_JOB_STATUS_HYPERVISOR_COMPLETED: + case VIR_DOMAIN_JOB_STATUS_POSTCOPY_PAUSED: + case VIR_DOMAIN_JOB_STATUS_ACTIVE: + break; + } + + return false; +} + + int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob) + virDomainAsyncJob asyncJob, + bool wait) { qemuDomainObjPrivate *priv =3D vm->privateData; =20 @@ -4625,6 +4653,15 @@ qemuMigrationSrcCancel(virDomainObj *vm, qemuMonitorMigrateCancel(priv->mon); qemuDomainObjExitMonitor(vm); =20 + if (virDomainObjIsActive(vm) && wait) { + VIR_DEBUG("Waiting for migration to be canceled"); + + while (!qemuMigrationSrcIsCanceled(vm)) { + if (qemuDomainObjWait(vm) < 0) + return -1; + } + } + return 0; } =20 @@ -4971,7 +5008,7 @@ qemuMigrationSrcRun(virQEMUDriver *driver, =20 if (cancel && priv->job.current->status !=3D VIR_DOMAIN_JOB_STATUS_HYPERVISO= R_COMPLETED) - qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_MIGRATION_OUT); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_MIGRATION_OUT, true); =20 /* cancel any outstanding NBD jobs */ if (mig && mig->nbd) @@ -6916,7 +6953,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDoma= inObj *vm, virErrorPreserveLast(&orig_err); virCommandAbort(compressor); if (virDomainObjIsActive(vm)) - qemuMigrationSrcCancel(vm, asyncJob); + qemuMigrationSrcCancel(vm, asyncJob, true); } goto cleanup; } @@ -6963,7 +7000,7 @@ qemuMigrationSrcCancelUnattended(virDomainObj *vm) VIR_DEBUG("Canceling unfinished outgoing migration of domain %s", vm->def->name); =20 - qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE, true); =20 for (i =3D 0; i < vm->def->ndisks; i++) { virDomainDiskDef *disk =3D vm->def->disks[i]; diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index 31a5547399..fbea45ad4e 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -245,7 +245,8 @@ qemuMigrationSrcCancelUnattended(virDomainObj *vm); =20 int qemuMigrationSrcCancel(virDomainObj *vm, - virDomainAsyncJob asyncJob); + virDomainAsyncJob asyncJob, + bool wait); =20 int qemuMigrationAnyFetchStats(virDomainObj *vm, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4465fa89e9..08eefd0fba 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3696,7 +3696,7 @@ qemuProcessRecoverJob(virQEMUDriver *driver, case VIR_ASYNC_JOB_SAVE: case VIR_ASYNC_JOB_DUMP: case VIR_ASYNC_JOB_SNAPSHOT: - qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE); + qemuMigrationSrcCancel(vm, VIR_ASYNC_JOB_NONE, true); /* resume the domain but only if it was paused as a result of * running a migration-to-file operation. Although we are * recovering an async job, this function is run at startup --=20 2.37.2