From nobody Fri May 10 01:56:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1688474138; cv=none; d=zohomail.com; s=zohoarc; b=c5Z1ybztWSkkZgQi524ERWzHlvmp/WWaPXHLX8V2nDD6ibRG+i+nZVMSwMxSbss8FCTdckXu3aJARNy51QYeoeNmwDSsp8wdJKrB8tEv56TQZPRsRlmE85hT5yrYOBzlb7flgWEGvHzKOmlDztitQQagHxoKtBZKOdcewWENWpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688474138; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=q3kHwej/2cgkUK1og5DS8/g9d5yTDpEs86cdHnj3zwc=; b=ceQQ1btfFpwAS0+BCwt81G9C23rXZl5rsmfLvJafxdS0EvG0g+nUNRPo3LJZ74axhdQOT92BBzoK80Q7jeJ71cLPENbXnfOc458567wqKTOgLnQbn5d1pcIs+3yHzeglatTqbj4J1bh5q4rv465Eyh2AGRHULfEhTvduJi84pDU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688474138297336.5873094474297; Tue, 4 Jul 2023 05:35:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGfF5-00048B-Ai; Tue, 04 Jul 2023 08:34:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGfF3-00047j-1z for qemu-devel@nongnu.org; Tue, 04 Jul 2023 08:34:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGfF0-0002Nc-VU for qemu-devel@nongnu.org; Tue, 04 Jul 2023 08:34:48 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-3aZuP82-OqGD_nTO_eLfEQ-1; Tue, 04 Jul 2023 08:34:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9CEC88CC49; Tue, 4 Jul 2023 12:34:43 +0000 (UTC) Received: from localhost (unknown [10.39.194.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DFE0C478C7; Tue, 4 Jul 2023 12:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688474085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=q3kHwej/2cgkUK1og5DS8/g9d5yTDpEs86cdHnj3zwc=; b=TIpmciHhCIcFR88wZ5bI7zBUtpkXS7MDRCL3AUfczk7TY7QP8doB1Nmt/ngFV9yuGH5IkG yA63rJ2eQjsW+D1VuQvvpaxB+205LlLSZRJuGUe54Iaw2leZ/rBBXZbwlwnACwXPuw7mmN AUh6GanhXS+LOXNqv199kSMydnuS+Ss= X-MC-Unique: 3aZuP82-OqGD_nTO_eLfEQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: , Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , Qing Wang , Stefano Garzarella Subject: [PATCH v2] block/blkio: fix module_block.py parsing Date: Tue, 4 Jul 2023 14:34:36 +0200 Message-Id: <20230704123436.187761-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1688474139799100003 Content-Type: text/plain; charset="utf-8" When QEMU is built with --enable-modules, the module_block.py script parses block/*.c to find block drivers that are built as modules. The script generates a table of block drivers called block_driver_modules[]. This table is used for block driver module loading. The blkio.c driver uses macros to define its BlockDriver structs. This was done to avoid code duplication but the module_block.py script is unable to parse the macro. The result is that libblkio-based block drivers can be built as modules but will not be found at runtime. One fix is to make the module_block.py script or build system fancier so it can parse C macros (e.g. by parsing the preprocessed source code). I chose not to do this because it raises the complexity of the build, making future issues harder to debug. Keep things simple: use the macro to avoid duplicating BlockDriver function pointers but define .format_name and .protocol_name manually for each BlockDriver. This way the module_block.py is able to parse the code. Also get rid of the block driver name macros (e.g. DRIVER_IO_URING) because module_block.py cannot parse them either. Fixes: fd66dbd424f5 ("blkio: add libblkio block driver") Reported-by: Qing Wang Cc: Stefano Garzarella Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella --- v2: - Drop unnecessary backslashes [Stefano] --- block/blkio.c | 108 ++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index 527323d625..1798648134 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -22,16 +22,6 @@ =20 #include "block/block-io.h" =20 -/* - * Keep the QEMU BlockDriver names identical to the libblkio driver names. - * Using macros instead of typing out the string literals avoids typos. - */ -#define DRIVER_IO_URING "io_uring" -#define DRIVER_NVME_IO_URING "nvme-io_uring" -#define DRIVER_VIRTIO_BLK_VFIO_PCI "virtio-blk-vfio-pci" -#define DRIVER_VIRTIO_BLK_VHOST_USER "virtio-blk-vhost-user" -#define DRIVER_VIRTIO_BLK_VHOST_VDPA "virtio-blk-vhost-vdpa" - /* * Allocated bounce buffers are kept in a list sorted by buffer address. */ @@ -744,15 +734,15 @@ static int blkio_file_open(BlockDriverState *bs, QDic= t *options, int flags, return ret; } =20 - if (strcmp(blkio_driver, DRIVER_IO_URING) =3D=3D 0) { + if (strcmp(blkio_driver, "io_uring") =3D=3D 0) { ret =3D blkio_io_uring_open(bs, options, flags, errp); - } else if (strcmp(blkio_driver, DRIVER_NVME_IO_URING) =3D=3D 0) { + } else if (strcmp(blkio_driver, "nvme-io_uring") =3D=3D 0) { ret =3D blkio_nvme_io_uring(bs, options, flags, errp); - } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VFIO_PCI) =3D=3D 0) { + } else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") =3D=3D 0) { ret =3D blkio_virtio_blk_common_open(bs, options, flags, errp); - } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VHOST_USER) =3D=3D 0= ) { + } else if (strcmp(blkio_driver, "virtio-blk-vhost-user") =3D=3D 0) { ret =3D blkio_virtio_blk_common_open(bs, options, flags, errp); - } else if (strcmp(blkio_driver, DRIVER_VIRTIO_BLK_VHOST_VDPA) =3D=3D 0= ) { + } else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") =3D=3D 0) { ret =3D blkio_virtio_blk_common_open(bs, options, flags, errp); } else { g_assert_not_reached(); @@ -1028,49 +1018,63 @@ static void blkio_refresh_limits(BlockDriverState *= bs, Error **errp) * - truncate */ =20 -#define BLKIO_DRIVER(name, ...) \ - { \ - .format_name =3D name, \ - .protocol_name =3D name, \ - .instance_size =3D sizeof(BDRVBlkioState), \ - .bdrv_file_open =3D blkio_file_open, \ - .bdrv_close =3D blkio_close, \ - .bdrv_co_getlength =3D blkio_co_getlength, \ - .bdrv_co_truncate =3D blkio_truncate, \ - .bdrv_co_get_info =3D blkio_co_get_info, \ - .bdrv_attach_aio_context =3D blkio_attach_aio_context, \ - .bdrv_detach_aio_context =3D blkio_detach_aio_context, \ - .bdrv_co_pdiscard =3D blkio_co_pdiscard, \ - .bdrv_co_preadv =3D blkio_co_preadv, \ - .bdrv_co_pwritev =3D blkio_co_pwritev, \ - .bdrv_co_flush_to_disk =3D blkio_co_flush, \ - .bdrv_co_pwrite_zeroes =3D blkio_co_pwrite_zeroes, \ - .bdrv_refresh_limits =3D blkio_refresh_limits, \ - .bdrv_register_buf =3D blkio_register_buf, \ - .bdrv_unregister_buf =3D blkio_unregister_buf, \ - __VA_ARGS__ \ - } +/* + * Do not include .format_name and .protocol_name because module_block.py + * does not parse macros in the source code. + */ +#define BLKIO_DRIVER_COMMON \ + .instance_size =3D sizeof(BDRVBlkioState), \ + .bdrv_file_open =3D blkio_file_open, \ + .bdrv_close =3D blkio_close, \ + .bdrv_co_getlength =3D blkio_co_getlength, \ + .bdrv_co_truncate =3D blkio_truncate, \ + .bdrv_co_get_info =3D blkio_co_get_info, \ + .bdrv_attach_aio_context =3D blkio_attach_aio_context, \ + .bdrv_detach_aio_context =3D blkio_detach_aio_context, \ + .bdrv_co_pdiscard =3D blkio_co_pdiscard, \ + .bdrv_co_preadv =3D blkio_co_preadv, \ + .bdrv_co_pwritev =3D blkio_co_pwritev, \ + .bdrv_co_flush_to_disk =3D blkio_co_flush, \ + .bdrv_co_pwrite_zeroes =3D blkio_co_pwrite_zeroes, \ + .bdrv_refresh_limits =3D blkio_refresh_limits, \ + .bdrv_register_buf =3D blkio_register_buf, \ + .bdrv_unregister_buf =3D blkio_unregister_buf, =20 -static BlockDriver bdrv_io_uring =3D BLKIO_DRIVER( - DRIVER_IO_URING, +/* + * Use the same .format_name and .protocol_name as the libblkio driver nam= e for + * consistency. + */ + +static BlockDriver bdrv_io_uring =3D { + .format_name =3D "io_uring", + .protocol_name =3D "io_uring", .bdrv_needs_filename =3D true, -); + BLKIO_DRIVER_COMMON +}; =20 -static BlockDriver bdrv_nvme_io_uring =3D BLKIO_DRIVER( - DRIVER_NVME_IO_URING, -); +static BlockDriver bdrv_nvme_io_uring =3D { + .format_name =3D "nvme-io_uring", + .protocol_name =3D "nvme-io_uring", + BLKIO_DRIVER_COMMON +}; =20 -static BlockDriver bdrv_virtio_blk_vfio_pci =3D BLKIO_DRIVER( - DRIVER_VIRTIO_BLK_VFIO_PCI -); +static BlockDriver bdrv_virtio_blk_vfio_pci =3D { + .format_name =3D "virtio-blk-vfio-pci", + .protocol_name =3D "virtio-blk-vfio-pci", + BLKIO_DRIVER_COMMON +}; =20 -static BlockDriver bdrv_virtio_blk_vhost_user =3D BLKIO_DRIVER( - DRIVER_VIRTIO_BLK_VHOST_USER -); +static BlockDriver bdrv_virtio_blk_vhost_user =3D { + .format_name =3D "virtio-blk-vhost-user", + .protocol_name =3D "virtio-blk-vhost-user", + BLKIO_DRIVER_COMMON +}; =20 -static BlockDriver bdrv_virtio_blk_vhost_vdpa =3D BLKIO_DRIVER( - DRIVER_VIRTIO_BLK_VHOST_VDPA -); +static BlockDriver bdrv_virtio_blk_vhost_vdpa =3D { + .format_name =3D "virtio-blk-vhost-vdpa", + .protocol_name =3D "virtio-blk-vhost-vdpa", + BLKIO_DRIVER_COMMON +}; =20 static void bdrv_blkio_init(void) { --=20 2.40.1