From nobody Tue May 7 09:35:34 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548272722504455.58720389225357; Wed, 23 Jan 2019 11:45:22 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 600138AE73; Wed, 23 Jan 2019 19:45:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F2641001F4A; Wed, 23 Jan 2019 19:45:17 +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 64063180339D; Wed, 23 Jan 2019 19:45:14 +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 x0NJjCWo015655 for ; Wed, 23 Jan 2019 14:45:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id C9AF11727C; Wed, 23 Jan 2019 19:45:12 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-44.phx2.redhat.com [10.3.117.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93CB068866 for ; Wed, 23 Jan 2019 19:45:08 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 23 Jan 2019 13:45:07 -0600 Message-Id: <20190123194507.11168-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: improve compile-time check of qemuBlockjobState mapping 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 23 Jan 2019 19:45:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Asserting the value we set four lines earlier in qemuBlockjobState doesn't buy us any safety (if the public header adds a value, we end up skipping that value without the compiler warning us of our gap); what we really want is to assert that the value auto-assigned by the compiler matches the actual last value in the public headers (as was done below for qemuBlockJobType). Add useful comments while at it. Signed-off-by: Eric Blake --- The spelling VIR_DOMAIN_BLOCK_JOB_LAST vs. VIR_DOMAIN_BLOCK_JOB_TYPE_LAST took me on a wild goose chase; the least I can do is make the code nicer for the next reader. src/qemu/qemu_blockjob.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index ed63f2c709..c7325c6daf 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -29,15 +29,17 @@ * This enum has to map all known block job states from enum virDomainBloc= kJobType * to the same values. All internal blockjobs can be mapped after and don't * need to have stable values. */ typedef enum { + /* Mapped to public enum */ QEMU_BLOCKJOB_STATE_COMPLETED =3D VIR_DOMAIN_BLOCK_JOB_COMPLETED, QEMU_BLOCKJOB_STATE_FAILED =3D VIR_DOMAIN_BLOCK_JOB_FAILED, QEMU_BLOCKJOB_STATE_CANCELLED =3D VIR_DOMAIN_BLOCK_JOB_CANCELED, QEMU_BLOCKJOB_STATE_READY =3D VIR_DOMAIN_BLOCK_JOB_READY, - QEMU_BLOCKJOB_STATE_NEW =3D VIR_DOMAIN_BLOCK_JOB_LAST, + /* Additional enum values local to qemu */ + QEMU_BLOCKJOB_STATE_NEW, QEMU_BLOCKJOB_STATE_RUNNING, QEMU_BLOCKJOB_STATE_LAST } qemuBlockjobState; verify((int)QEMU_BLOCKJOB_STATE_NEW =3D=3D VIR_DOMAIN_BLOCK_JOB_LAST); @@ -45,15 +47,17 @@ verify((int)QEMU_BLOCKJOB_STATE_NEW =3D=3D VIR_DOMAIN_B= LOCK_JOB_LAST); * This enum has to map all known block job types from enum virDomainBlock= JobType * to the same values. All internal blockjobs can be mapped after and don't * need to have stable values. */ typedef enum { + /* Mapped to public enum */ QEMU_BLOCKJOB_TYPE_NONE =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN, QEMU_BLOCKJOB_TYPE_PULL =3D VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, QEMU_BLOCKJOB_TYPE_COPY =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY, QEMU_BLOCKJOB_TYPE_COMMIT =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT, QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT =3D VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_= COMMIT, + /* Additional enum values local to qemu */ QEMU_BLOCKJOB_TYPE_INTERNAL, QEMU_BLOCKJOB_TYPE_LAST } qemuBlockJobType; verify((int)QEMU_BLOCKJOB_TYPE_INTERNAL =3D=3D VIR_DOMAIN_BLOCK_JOB_TYPE_L= AST); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list