From nobody Fri May 17 08:24:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618919079; cv=none; d=zohomail.com; s=zohoarc; b=fW5IFDh+aJoZz87JHM/7Agwtd5rJNHPAKplWztHXh3dCKrurWj6yB38UCyZMqjSWxAeKpTIE2Hx9IRZzvWlp9Xv0HmvlL0MV1M12kyroCe5eV3C1nC4eX5XcCGlIcK+SWoCQfAfB6vD9+kjDMa6oKlPxKQBDsRs6uXoCt+YmhRo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618919079; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3kCmLclcLArL3uJWGak14ohnwAnJum5LE9B065FyqkE=; b=iNKJc8PdfztQUgfOg7klptndEGDmAkFCJyEdIM/9C0xSIhGEgXNVYEYc9eHvOaKkSHmguPQaHMA2/H9ajD7nXVXZL4BpN/sWdsTsj3bSd18gai2kVNvG1K4qSRGwQmxaGmo13OkXrPqEUOKT7BLjb3PrCQe8vJPUqU/rb7/7r4o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618919079521997.3598194846879; Tue, 20 Apr 2021 04:44:39 -0700 (PDT) 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-473-32YGE20wO7maIoIvE18wuA-1; Tue, 20 Apr 2021 07:44:36 -0400 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 313FC193578E; Tue, 20 Apr 2021 11:44:30 +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 977D25D743; Tue, 20 Apr 2021 11:44:29 +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 7EEAC4EA30; Tue, 20 Apr 2021 11:44:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13KBiQtv019576 for ; Tue, 20 Apr 2021 07:44:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id F32715C890; Tue, 20 Apr 2021 11:44:25 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3494A5C1D0 for ; Tue, 20 Apr 2021 11:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618919078; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3kCmLclcLArL3uJWGak14ohnwAnJum5LE9B065FyqkE=; b=CNWtV2d3ry4M78Z8Q95HdpQzfCrOTYanX6zdnFZ/ioKE480hSBJPqFbL+4wY6mSFby9IJd 6DU/RBIrtN/hAimgiktzZgdvvtirVns+dN+66VHMlczN22XyvhCH26barhkJVe9zOHu6fW NXzMdmVJcwJQZ6X/XCIcIjhlKa5TbyQ= X-MC-Unique: 32YGE20wO7maIoIvE18wuA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] qemu: blockjob: Transition into 'ready' state only from expected states Date: Tue, 20 Apr 2021 13:44:17 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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 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) Content-Type: text/plain; charset="utf-8" In certain rare occasions qemu can transition a block job which was already 'ready' into 'standby' and then back. If this happens in the following order libvirt will get confused about the actual job state: 1) the block copy job is 'ready' (job->state =3D=3D QEMU_BLOCKJOB_STATE_REA= DY) 2) user calls qemuDomainBlockJobAbort with VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT flag but without VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC 3) the block job is switched to synchronous event handling 4) the block job blips to 'standby' and back to 'ready', the event is not processed since the blockjob is in sync mode for now 5) qemuDomainBlockJobPivot is called: 5.1) 'job-complete' QMP command is issued 5.2) job->state is set to QEMU_BLOCKJOB_STATE_PIVOTING 6) code for synchronous-wait for the job completion in qemuDomainBlockJobAb= ort is invoked 7) the waiting loop calls qemuBlockJobUpdate: 7.1) job->newstate is QEMU_BLOCKJOB_STATE_READY due to 4) 7.2) qemuBlockJobEventProcess is called 7.3) the handler for QEMU_BLOCKJOB_STATE_READY overwrites job->state from QEMU_BLOCKJOB_STATE_PIVOTING to QEMU_BLOCKJOB_STAT= E_READY 8) qemuDomainBlockJobAbort is looking for a finished job, so waits again 9) qemu finishes the blockjob and transitions it into 'concluded' state 10) qemuBlockJobUpdate is triggered again, this time finalizing the job. 10.1) job->newstate is =3D QEMU_BLOCKJOB_STATE_CONCLUDED job->state is =3D QEMU_BLOCKJOB_STATE_READY 10.2) qemuBlockJobEventProcessConcluded is called, the function checks whether there was an error with the blockjob. Since there was no error job->newstate becomes QEMU_BLOCKJOB_STATE_COMPLETED. 10.3) qemuBlockJobEventProcessConcludedTransition selects the action for the appropriate block job type where we have: case QEMU_BLOCKJOB_TYPE_COPY: if (job->state =3D=3D QEMU_BLOCKJOB_STATE_PIVOTING && success) qemuBlockJobProcessEventConcludedCopyPivot(driver, vm, job, asy= ncJob); else qemuBlockJobProcessEventConcludedCopyAbort(driver, vm, job, asy= ncJob); break; Since job->state is QEMU_BLOCKJOB_STATE_READY, qemuBlockJobProcessEventConcludedCopyAbort is called. This patch forbids transitions to QEMU_BLOCKJOB_STATE_READY if the previous job state isn't QEMU_BLOCKJOB_STATE_RUNNING or QEMU_BLOCKJOB_STATE_NEW. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1951507 Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_blockjob.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 21fcc29ddb..9ae4500f4d 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -1697,14 +1697,21 @@ qemuBlockJobEventProcess(virQEMUDriver *driver, break; case QEMU_BLOCKJOB_STATE_READY: - /* mirror may be NULL for copy job corresponding to migration */ - if (job->disk) { - job->disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_READY; - qemuBlockJobEmitEvents(driver, vm, job->disk, job->type, job->= newstate); + /* in certain cases qemu can blip out and back into 'ready' state = for + * a blockjob. In cases when we already are past RUNNING the job s= uch + * as when pivoting/aborting this could reset the internally set j= ob + * state, thus we ignore it if the job isn't in expected state */ + if (job->state =3D=3D QEMU_BLOCKJOB_STATE_NEW || + job->state =3D=3D QEMU_BLOCKJOB_STATE_RUNNING) { + /* mirror may be NULL for copy job corresponding to migration = */ + if (job->disk) { + job->disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_RE= ADY; + qemuBlockJobEmitEvents(driver, vm, job->disk, job->type, j= ob->newstate); + } + job->state =3D job->newstate; + qemuDomainSaveStatus(vm); } - job->state =3D job->newstate; job->newstate =3D -1; - qemuDomainSaveStatus(vm); break; case QEMU_BLOCKJOB_STATE_NEW: --=20 2.30.2