From nobody Thu May 15 13:57:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508421417173244.7956440011218; Thu, 19 Oct 2017 06:56:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0301F7E44F; Thu, 19 Oct 2017 13:56:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB356DF98E; Thu, 19 Oct 2017 13:56:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 687CA3FAEE; Thu, 19 Oct 2017 13:56:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9JDugI6030152 for ; Thu, 19 Oct 2017 09:56:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 222FCD1C76; Thu, 19 Oct 2017 13:56:42 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB65AD1C85 for ; Thu, 19 Oct 2017 13:56:34 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 646381020BC; Thu, 19 Oct 2017 15:56:33 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0301F7E44F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 19 Oct 2017 15:56:28 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/7] qemu: Split cleanup and error code in qemuMigrationRun X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 19 Oct 2017 13:56:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let cleanup only do things common to both failure and success paths and move error handling code inside the new "error" section. Signed-off-by: Jiri Denemark --- src/qemu/qemu_migration.c | 79 ++++++++++++++++++++++++-------------------= ---- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index f0d4f9d98..6956901be 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3657,20 +3657,20 @@ qemuMigrationRun(virQEMUDriverPtr driver, if (persist_xml) { if (!(persistDef =3D qemuMigrationPrepareDef(driver, persist_x= ml, NULL, NULL))) - goto cleanup; + goto error; } else { virDomainDefPtr def =3D vm->newDef ? vm->newDef : vm->def; if (!(persistDef =3D qemuDomainDefCopy(driver, def, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_MIGRATABLE= ))) - goto cleanup; + goto error; } } =20 mig =3D qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen, cookieFlags | QEMU_MIGRATION_COOKIE_GRAPH= ICS); if (!mig) - goto cleanup; + goto error; =20 if (qemuDomainMigrateGraphicsRelocate(driver, vm, mig, graphicsuri) < = 0) VIR_WARN("unable to provide data for graphics client relocation"); @@ -3683,7 +3683,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, if (qemuMigrationAddTLSObjects(driver, vm, cfg, false, QEMU_ASYNC_JOB_MIGRATION_OUT, &tlsAlias, &secAlias, migParams) < = 0) - goto cleanup; + goto error; =20 /* We need to add tls-hostname whenever QEMU itself does not * connect directly to the destination. */ @@ -3691,17 +3691,17 @@ qemuMigrationRun(virQEMUDriverPtr driver, spec->destType =3D=3D MIGRATION_DEST_FD) { if (VIR_STRDUP(migParams->migrateTLSHostname, spec->dest.host.name) < 0) - goto cleanup; + goto error; } else { /* Be sure there's nothing from a previous migration */ if (VIR_STRDUP(migParams->migrateTLSHostname, "") < 0) - goto cleanup; + goto error; } } else { if (qemuMigrationSetEmptyTLSParams(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT, migParams) < 0) - goto cleanup; + goto error; } =20 if (migrate_flags & (QEMU_MONITOR_MIGRATE_NON_SHARED_DISK | @@ -3715,7 +3715,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, nmigrate_disks, migrate_disks, dconn) < 0) { - goto cleanup; + goto error; } } else { /* Destination doesn't support NBD server. @@ -3729,37 +3729,37 @@ qemuMigrationRun(virQEMUDriverPtr driver, if (!(flags & VIR_MIGRATE_LIVE) && virDomainObjGetState(vm, NULL) =3D=3D VIR_DOMAIN_RUNNING) { if (qemuMigrationSetOffline(driver, vm) < 0) - goto cleanup; + goto error; } =20 if (qemuMigrationSetCompression(driver, vm, QEMU_ASYNC_JOB_MIGRATION_O= UT, compression, migParams) < 0) - goto cleanup; + goto error; =20 if (qemuMigrationSetOption(driver, vm, QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE, flags & VIR_MIGRATE_AUTO_CONVERGE, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) - goto cleanup; + goto error; =20 if (qemuMigrationSetOption(driver, vm, QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL, flags & VIR_MIGRATE_RDMA_PIN_ALL, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) - goto cleanup; + goto error; =20 if (qemuMigrationSetPostCopy(driver, vm, flags & VIR_MIGRATE_POSTCOPY, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) - goto cleanup; + goto error; =20 if (qemuMigrationSetParams(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT, migParams) < 0) - goto cleanup; + goto error; =20 if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) - goto cleanup; + goto error; =20 if (priv->job.abortJob) { /* explicitly do this *after* we entered the monitor, @@ -3770,7 +3770,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"), qemuDomainAsyncJobTypeToString(priv->job.asyncJob), _("canceled by client")); - goto cleanup; + goto error; } =20 if (qemuMonitorSetMigrationSpeed(priv->mon, migrate_speed) < 0) @@ -3817,7 +3817,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, if (qemuDomainObjExitMonitor(driver, vm) < 0) ret =3D -1; if (ret < 0) - goto cleanup; + goto error; ret =3D -1; =20 /* From this point onwards we *must* call cancel to abort the @@ -3846,7 +3846,7 @@ qemuMigrationRun(virQEMUDriverPtr driver, if (rc =3D=3D -2) goto cancel; else if (rc =3D=3D -1) - goto cleanup; + goto error; =20 if (priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_POSTCOPY) inPostCopy =3D true; @@ -3901,28 +3901,10 @@ qemuMigrationRun(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: - if (ret < 0 && !orig_err) - orig_err =3D virSaveLastError(); - - /* cancel any outstanding NBD jobs */ - if (ret < 0 && mig && mig->nbd) - qemuMigrationCancelDriveMirror(driver, vm, false, - QEMU_ASYNC_JOB_MIGRATION_OUT, - dconn); - VIR_FREE(tlsAlias); VIR_FREE(secAlias); virObjectUnref(cfg); - - if (ret < 0 && iothread) - qemuMigrationStopTunnel(iothread, true); - VIR_FORCE_CLOSE(fd); - - if (priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_ACTIVE || - priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_MIGRATING) - priv->job.current->status =3D QEMU_DOMAIN_JOB_STATUS_FAILED; - virDomainDefFree(persistDef); qemuMigrationCookieFree(mig); =20 @@ -3936,9 +3918,28 @@ qemuMigrationRun(virQEMUDriverPtr driver, =20 return ret; =20 + error: + if (!orig_err) + orig_err =3D virSaveLastError(); + + /* cancel any outstanding NBD jobs */ + if (mig && mig->nbd) + qemuMigrationCancelDriveMirror(driver, vm, false, + QEMU_ASYNC_JOB_MIGRATION_OUT, + dconn); + + if (iothread) + qemuMigrationStopTunnel(iothread, true); + + if (priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_ACTIVE || + priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_MIGRATING) + priv->job.current->status =3D QEMU_DOMAIN_JOB_STATUS_FAILED; + + goto cleanup; + exit_monitor: ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto cleanup; + goto error; =20 cancel: orig_err =3D virSaveLastError(); @@ -3950,14 +3951,14 @@ qemuMigrationRun(virQEMUDriverPtr driver, ignore_value(qemuDomainObjExitMonitor(driver, vm)); } } - goto cleanup; + goto error; =20 cancelPostCopy: priv->job.current->status =3D QEMU_DOMAIN_JOB_STATUS_FAILED; if (inPostCopy) goto cancel; else - goto cleanup; + goto error; } =20 /* Perform migration using QEMU's native migrate support, --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list