From nobody Tue Feb 10 01:16:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575546902; cv=none; d=zohomail.com; s=zohoarc; b=JR5ofK2H+BHNDtIGYrZ4Uch9PBKq8mDcvg22YnNuqw87mZeuCE4jU/glffWKZHNr0AYVEWwPSdVrB7guyNgEn4cCev4rVPawdDjkULIM31vwO1b8MEzkB+sAGxdwonbHqoFLkTHbsBDOAhPR7KtQmbOlPUG2NucSdsmQT9a56w0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575546902; 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=I4ppd25OG387ekmRtQb1UXVJ1/ORyhZIsPKmqoMKW3Q=; b=nlmQy0aPZinpsxK9CFkWqc1hiaHYItDqqYCkBYl6GCuz5Z3TTOVMaxu17kqbdT0LBA7LHkRRYjSWne3LVMUB5AVMl5rHypHQwGfnZTY1GhYdL56jSsryUcaTcABL64AOcNshzQKRYfDW6uBVDLPFkDmEiL/JL4NRZRKIQHSW6F4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575546902203706.999723911387; Thu, 5 Dec 2019 03:55:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-181-dNNulVTeOBKIGorB88nKLg-1; Thu, 05 Dec 2019 06:54:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FF6A801E74; Thu, 5 Dec 2019 11:54:52 +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 D42435D6AE; Thu, 5 Dec 2019 11:54:51 +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 57A0D65D1C; Thu, 5 Dec 2019 11:54:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB5BslIL009485 for ; Thu, 5 Dec 2019 06:54:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id A7ECE60126; Thu, 5 Dec 2019 11:54:47 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3039A600F0 for ; Thu, 5 Dec 2019 11:54:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575546901; 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=I4ppd25OG387ekmRtQb1UXVJ1/ORyhZIsPKmqoMKW3Q=; b=DwmXrktON4H2yhAhoSzi5BIWKHTP0B52gC7ObuHMFkCnQ3olxoSphtoL6wXxX3g+PRWSCK PqQ5H8ST28bjnBY2qb4TTSOr6dJx7auiRjVUo9vCMZYvrt3O5yV++GqRdusSvy2xTf50PY PH/SuR3rL9w5YfoDSO/wF8oPFq0WpBo= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 5 Dec 2019 12:54:39 +0100 Message-Id: <3bfdac541a4a38ec6372f312758ce0aef6f3571b.1575546793.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: Convert aborting of a domain job to a switch statement 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: dNNulVTeOBKIGorB88nKLg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Until now we only really aborted migration via qemuDomainAbortJob. This will change with the upcoming addition of the backup job. Additionally there were a bunch of if statements checking various aspects of the current job. To make it more obvious convert qemuDomainAbortJob to use a switch statement and move the individual conditions to the appropriate job type. Every job type has now it's own case despite multiple job types just plainly cancelling the job for clarity and future extension. Signed-off-by: Peter Krempa --- src/qemu/qemu_driver.c | 67 ++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4cfc1ca9e7..bad2fb52f3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14036,36 +14036,59 @@ static int qemuDomainAbortJob(virDomainPtr dom) priv =3D vm->privateData; - if (!priv->job.asyncJob) { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("no job is active on the domain")); - goto endjob; - } + switch (priv->job.asyncJob) { + case QEMU_ASYNC_JOB_NONE: + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("no job is active on the domain")); + break; - if (priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_IN) { + case QEMU_ASYNC_JOB_MIGRATION_IN: virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot abort incoming migration;" " use virDomainDestroy instead")); - goto endjob; - } + break; - if (priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_DUMP && - priv->job.apiFlags & VIR_DUMP_MEMORY_ONLY) { + case QEMU_ASYNC_JOB_START: virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("cannot abort memory-only dump")); - goto endjob; - } + _("cannot abort VM start;" + " use virDomainDestroy instead")); + break; - if (priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_OUT && - (priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_POSTCOPY = || - (virDomainObjGetState(vm, &reason) =3D=3D VIR_DOMAIN_PAUSED && - reason =3D=3D VIR_DOMAIN_PAUSED_POSTCOPY))) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("cannot abort migration in post-copy mode")); - goto endjob; - } + case QEMU_ASYNC_JOB_MIGRATION_OUT: + if ((priv->job.current->status =3D=3D QEMU_DOMAIN_JOB_STATUS_POSTC= OPY || + (virDomainObjGetState(vm, &reason) =3D=3D VIR_DOMAIN_PAUSED && + reason =3D=3D VIR_DOMAIN_PAUSED_POSTCOPY))) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot abort migration in post-copy mode")); + goto endjob; + } - ret =3D qemuDomainAbortJobMigration(vm); + ret =3D qemuDomainAbortJobMigration(vm); + break; + + case QEMU_ASYNC_JOB_SAVE: + ret =3D qemuDomainAbortJobMigration(vm); + break; + + case QEMU_ASYNC_JOB_DUMP: + if (priv->job.apiFlags & VIR_DUMP_MEMORY_ONLY) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot abort memory-only dump")); + goto endjob; + } + + ret =3D qemuDomainAbortJobMigration(vm); + break; + + case QEMU_ASYNC_JOB_SNAPSHOT: + ret =3D qemuDomainAbortJobMigration(vm); + break; + + case QEMU_ASYNC_JOB_LAST: + default: + virReportEnumRangeError(qemuDomainAsyncJob, priv->job.asyncJob); + break; + } endjob: qemuDomainObjEndJob(driver, vm); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list