From patchwork Tue Jul 5 15:24:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: clord@redhat.com X-Patchwork-Id: 9214695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6DC156048F for ; Tue, 5 Jul 2016 16:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D2EB269E2 for ; Tue, 5 Jul 2016 16:01:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F77326A5C; Tue, 5 Jul 2016 16:01:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5DBF7269E2 for ; Tue, 5 Jul 2016 16:01:35 +0000 (UTC) Received: from localhost ([::1]:56010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKSn0-0000So-AF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Jul 2016 12:01:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKSDe-0006Fp-Jv for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:25:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKSDc-0000BE-5m for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:25:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46101) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKSDY-00008v-At; Tue, 05 Jul 2016 11:24:56 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECF31C049E1B; Tue, 5 Jul 2016 15:24:55 +0000 (UTC) Received: from dhcp-17-138.bos.redhat.com (dhcp-17-5.bos.redhat.com [10.18.17.5]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u65FOWuQ006841; Tue, 5 Jul 2016 11:24:55 -0400 From: Colin Lord To: qemu-devel@nongnu.org Date: Tue, 5 Jul 2016 11:24:30 -0400 Message-Id: <1467732272-23368-31-git-send-email-clord@redhat.com> In-Reply-To: <1467732272-23368-1-git-send-email-clord@redhat.com> References: <1467732272-23368-1-git-send-email-clord@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 05 Jul 2016 15:24:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 30/32] blockdev: Remove the .bdrv_probe field from BlockDrivers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Colin Lord , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit finalizes the separation of the block driver and probe function by removing the .bdrv_probe field from all BlockDrivers. Probing is now accomplished solely by iterating over the array of probe function pointers in the format_probes array. Signed-off-by: Colin Lord Reviewed-by: Max Reitz --- block.c | 20 +------------------- block/raw-posix.c | 1 - include/block/block_int.h | 1 - scripts/modules/module_block.py | 10 ++-------- 4 files changed, 3 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index 8226124..7e441fe 100644 --- a/block.c +++ b/block.c @@ -599,34 +599,16 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, const char *format_max = NULL; const char *format; size_t i; - BlockDriver *drv = NULL, *d; - - for (i = 0; i < ARRAY_SIZE(block_driver_modules); ++i) { - if (block_driver_modules[i].has_probe) { - block_module_load_one(block_driver_modules[i].library_name); - } - } - - QLIST_FOREACH(d, &bdrv_drivers, list) { - if (d->bdrv_probe) { - score = d->bdrv_probe(buf, buf_size, filename); - if (score > score_max) { - score_max = score; - drv = d; - } - } - } for (i = 0; i < ARRAY_SIZE(format_probes); i++) { format = format_probes[i](buf, buf_size, filename, &score); if (score > score_max) { score_max = score; format_max = format; - drv = bdrv_find_format(format_max); } } - return drv; + return bdrv_find_format(format_max); } static int find_image_format(BlockDriverState *bs, const char *filename, diff --git a/block/raw-posix.c b/block/raw-posix.c index bef7a67..a6ad689 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1936,7 +1936,6 @@ BlockDriver bdrv_file = { .protocol_name = "file", .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, - .bdrv_probe = NULL, /* no probe for protocols */ .bdrv_parse_filename = raw_parse_filename, .bdrv_file_open = raw_open, .bdrv_reopen_prepare = raw_reopen_prepare, diff --git a/include/block/block_int.h b/include/block/block_int.h index 2057156..2bca115 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -99,7 +99,6 @@ struct BlockDriver { bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs, BlockDriverState *candidate); - int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); int (*bdrv_probe_device)(const char *filename); /* Any driver implementing this callback is expected to be able to handle diff --git a/scripts/modules/module_block.py b/scripts/modules/module_block.py index 4075574..18200e2 100644 --- a/scripts/modules/module_block.py +++ b/scripts/modules/module_block.py @@ -24,15 +24,13 @@ def get_string_struct(line): return data[2].replace('"', '')[:-1] def add_module(fheader, library, format_name, protocol_name, - probe, probe_device): + probe_device): lines = [] lines.append('.library_name = "' + library + '",') if format_name != "": lines.append('.format_name = "' + format_name + '",') if protocol_name != "": lines.append('.protocol_name = "' + protocol_name + '",') - if probe: - lines.append('.has_probe = true,') if probe_device: lines.append('.has_probe_device = true,') @@ -52,20 +50,17 @@ def process_file(fheader, filename): format_name = get_string_struct(line) elif line.find(".protocol_name") != -1: protocol_name = get_string_struct(line) - elif line.find(".bdrv_probe") != -1: - probe = True elif line.find(".bdrv_probe_device") != -1: probe_device = True elif line == "};": add_module(fheader, library, format_name, protocol_name, - probe, probe_device) + probe_device) found_start = False elif line.find("static BlockDriver") != -1: found_something = True found_start = True format_name = "" protocol_name = "" - probe = False probe_device = False if not found_something: @@ -93,7 +88,6 @@ static const struct { const char *format_name; const char *protocol_name; const char *library_name; - bool has_probe; bool has_probe_device; } block_driver_modules[] = {''')