From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39251C2D0E8 for ; Thu, 26 Mar 2020 14:31:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E58AB2073E for ; Thu, 26 Mar 2020 14:31:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OXtadP0W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E58AB2073E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHTXQ-0005au-1F for qemu-devel@archiver.kernel.org; Thu, 26 Mar 2020 10:31:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41310) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHTW4-0003TY-Gl for qemu-devel@nongnu.org; Thu, 26 Mar 2020 10:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHTW2-0002o4-6j for qemu-devel@nongnu.org; Thu, 26 Mar 2020 10:29:52 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:44236) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHTW2-0002nj-2A for qemu-devel@nongnu.org; Thu, 26 Mar 2020 10:29:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585232989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yjIVsItgcOWyMDqRRb8cyvi6tc2z9I6ImxYrKE3Nslk=; b=OXtadP0WdyzseMGPYGnZjnWXF0Mm7A5rhtZCduEJcQYsYJrvAHhxvI1YspdTzAj7qvdVql NC4Pydb51RNvrPp4xX5EDsN3sut9nbUl369/lvw9QDhDKurkp8KhfZCT5nvYBE80jMEy2O Q+imZwPFAMNDJfdX31Fv60qha6d9qxA= 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-297-EVEImvgwNveed1xvW-S0Bw-1; Thu, 26 Mar 2020 10:29:47 -0400 X-MC-Unique: EVEImvgwNveed1xvW-S0Bw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B0A88018AC; Thu, 26 Mar 2020 14:29:46 +0000 (UTC) Received: from localhost (ovpn-112-132.ams2.redhat.com [10.36.112.132]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53DF719C70; Thu, 26 Mar 2020 14:29:45 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 03/10] block: trickle down the fallback image creation function use to the block drivers Date: Thu, 26 Mar 2020 15:29:26 +0100 Message-Id: <20200326142933.625037-4-mreitz@redhat.com> In-Reply-To: <20200326142933.625037-1-mreitz@redhat.com> References: <20200326142933.625037-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 216.205.24.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Maxim Levitsky Instead of checking the .bdrv_co_create_opts to see if we need the fallback, just implement the .bdrv_co_create_opts in the drivers that need it. This way we don't break various places that need to know if the underlying protocol/format really supports image creation, and this way we still allow some drivers to not support image creation. Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1816007 Note that technically this driver reverts the image creation fallback for the vxhs driver since I don't have a means to test it, and IMHO it is better to leave it not supported as it was prior to generic image creation patches. Also drop iscsi_create_opts which was left accidentally. Signed-off-by: Maxim Levitsky Message-Id: <20200326011218.29230-3-mlevitsk@redhat.com> Reviewed-by: Denis V. Lunev [mreitz: Fixed alignment, and moved bdrv_co_create_opts_simple() and bdrv_create_opts_simple from block.h into block_int.h] Signed-off-by: Max Reitz --- include/block/block.h | 1 + include/block/block_int.h | 11 +++++++++++ block.c | 35 ++++++++++++++++++++--------------- block/file-posix.c | 7 ++++++- block/iscsi.c | 16 ++++------------ block/nbd.c | 6 ++++++ block/nvme.c | 3 +++ 7 files changed, 51 insertions(+), 28 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index e569a4d747..b05995fe9c 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -283,6 +283,7 @@ BlockDriver *bdrv_find_format(const char *format_name); int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *opts, Error **errp); int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp); + BlockDriverState *bdrv_new(void); void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, Error **errp); diff --git a/include/block/block_int.h b/include/block/block_int.h index 57c8ea24b2..4c3587ea19 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1331,4 +1331,15 @@ int refresh_total_sectors(BlockDriverState *bs, int6= 4_t hint); void bdrv_set_monitor_owned(BlockDriverState *bs); BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp); =20 +/** + * Simple implementation of bdrv_co_create_opts for protocol drivers + * which only support creation via opening a file + * (usually existing raw storage device) + */ +int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv, + const char *filename, + QemuOpts *opts, + Error **errp); +extern QemuOptsList bdrv_create_opts_simple; + #endif /* BLOCK_INT_H */ diff --git a/block.c b/block.c index ff23e20443..af3faf664e 100644 --- a/block.c +++ b/block.c @@ -598,8 +598,15 @@ static int create_file_fallback_zero_first_sector(Bloc= kBackend *blk, return 0; } =20 -static int bdrv_create_file_fallback(const char *filename, BlockDriver *dr= v, - QemuOpts *opts, Error **errp) +/** + * Simple implementation of bdrv_co_create_opts for protocol drivers + * which only support creation via opening a file + * (usually existing raw storage device) + */ +int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv, + const char *filename, + QemuOpts *opts, + Error **errp) { BlockBackend *blk; QDict *options; @@ -663,11 +670,7 @@ int bdrv_create_file(const char *filename, QemuOpts *o= pts, Error **errp) return -ENOENT; } =20 - if (drv->bdrv_co_create_opts) { - return bdrv_create(drv, filename, opts, errp); - } else { - return bdrv_create_file_fallback(filename, drv, opts, errp); - } + return bdrv_create(drv, filename, opts, errp); } =20 int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp) @@ -1592,9 +1595,9 @@ QemuOptsList bdrv_runtime_opts =3D { }, }; =20 -static QemuOptsList fallback_create_opts =3D { - .name =3D "fallback-create-opts", - .head =3D QTAILQ_HEAD_INITIALIZER(fallback_create_opts.head), +QemuOptsList bdrv_create_opts_simple =3D { + .name =3D "simple-create-opts", + .head =3D QTAILQ_HEAD_INITIALIZER(bdrv_create_opts_simple.head), .desc =3D { { .name =3D BLOCK_OPT_SIZE, @@ -5963,13 +5966,15 @@ void bdrv_img_create(const char *filename, const ch= ar *fmt, return; } =20 + if (!proto_drv->create_opts) { + error_setg(errp, "Protocol driver '%s' does not support image crea= tion", + proto_drv->format_name); + return; + } + /* Create parameter list */ create_opts =3D qemu_opts_append(create_opts, drv->create_opts); - if (proto_drv->create_opts) { - create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); - } else { - create_opts =3D qemu_opts_append(create_opts, &fallback_create_opt= s); - } + create_opts =3D qemu_opts_append(create_opts, proto_drv->create_opts); =20 opts =3D qemu_opts_create(create_opts, NULL, 0, &error_abort); =20 diff --git a/block/file-posix.c b/block/file-posix.c index 65bc980bc4..7e19bbff5f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3513,6 +3513,8 @@ static BlockDriver bdrv_host_device =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .mutable_opts =3D mutable_opts, .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, .bdrv_co_pwrite_zeroes =3D hdev_co_pwrite_zeroes, @@ -3639,10 +3641,11 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .mutable_opts =3D mutable_opts, .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, =20 - .bdrv_co_preadv =3D raw_co_preadv, .bdrv_co_pwritev =3D raw_co_pwritev, .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, @@ -3771,6 +3774,8 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .mutable_opts =3D mutable_opts, =20 .bdrv_co_preadv =3D raw_co_preadv, diff --git a/block/iscsi.c b/block/iscsi.c index 682abd8e09..14680a436a 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2399,18 +2399,6 @@ out_unlock: return r; } =20 -static QemuOptsList iscsi_create_opts =3D { - .name =3D "iscsi-create-opts", - .head =3D QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head), - .desc =3D { - { - .name =3D BLOCK_OPT_SIZE, - .type =3D QEMU_OPT_SIZE, - .help =3D "Virtual disk size" - }, - { /* end of list */ } - } -}; =20 static const char *const iscsi_strong_runtime_opts[] =3D { "transport", @@ -2434,6 +2422,8 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_parse_filename =3D iscsi_parse_filename, .bdrv_file_open =3D iscsi_open, .bdrv_close =3D iscsi_close, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, @@ -2471,6 +2461,8 @@ static BlockDriver bdrv_iser =3D { .bdrv_parse_filename =3D iscsi_parse_filename, .bdrv_file_open =3D iscsi_open, .bdrv_close =3D iscsi_close, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, diff --git a/block/nbd.c b/block/nbd.c index 976be76647..2160859f64 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -2038,6 +2038,8 @@ static BlockDriver bdrv_nbd =3D { .protocol_name =3D "nbd", .instance_size =3D sizeof(BDRVNBDState), .bdrv_parse_filename =3D nbd_parse_filename, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .bdrv_file_open =3D nbd_open, .bdrv_reopen_prepare =3D nbd_client_reopen_prepare, .bdrv_co_preadv =3D nbd_client_co_preadv, @@ -2063,6 +2065,8 @@ static BlockDriver bdrv_nbd_tcp =3D { .protocol_name =3D "nbd+tcp", .instance_size =3D sizeof(BDRVNBDState), .bdrv_parse_filename =3D nbd_parse_filename, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .bdrv_file_open =3D nbd_open, .bdrv_reopen_prepare =3D nbd_client_reopen_prepare, .bdrv_co_preadv =3D nbd_client_co_preadv, @@ -2088,6 +2092,8 @@ static BlockDriver bdrv_nbd_unix =3D { .protocol_name =3D "nbd+unix", .instance_size =3D sizeof(BDRVNBDState), .bdrv_parse_filename =3D nbd_parse_filename, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, .bdrv_file_open =3D nbd_open, .bdrv_reopen_prepare =3D nbd_client_reopen_prepare, .bdrv_co_preadv =3D nbd_client_co_preadv, diff --git a/block/nvme.c b/block/nvme.c index d41c4bda6e..7b7c0cc5d6 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1333,6 +1333,9 @@ static BlockDriver bdrv_nvme =3D { .protocol_name =3D "nvme", .instance_size =3D sizeof(BDRVNVMeState), =20 + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, + .bdrv_parse_filename =3D nvme_parse_filename, .bdrv_file_open =3D nvme_file_open, .bdrv_close =3D nvme_close, --=20 2.25.1