From nobody Sun Feb 8 09:11:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520450180869823.0673352320174; Wed, 7 Mar 2018 11:16:20 -0800 (PST) Received: from localhost ([::1]:35140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eteXy-00026N-OT for importer@patchew.org; Wed, 07 Mar 2018 14:16:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eteIh-0004rX-CI for qemu-devel@nongnu.org; Wed, 07 Mar 2018 14:00:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eteIg-0004aR-1l for qemu-devel@nongnu.org; Wed, 07 Mar 2018 14:00:31 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58062 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eteIa-0004Y1-2R; Wed, 07 Mar 2018 14:00:24 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BEC64001851; Wed, 7 Mar 2018 19:00:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-216.ams2.redhat.com [10.36.116.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEF272023227; Wed, 7 Mar 2018 19:00:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 7 Mar 2018 19:59:24 +0100 Message-Id: <20180307185946.29366-16-kwolf@redhat.com> In-Reply-To: <20180307185946.29366-1-kwolf@redhat.com> References: <20180307185946.29366-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 07 Mar 2018 19:00:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 07 Mar 2018 19:00:23 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 15/37] block: x-blockdev-create QMP command 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, jdurgin@redhat.com, pkrempa@redhat.com, mitake.hitoshi@lab.ntt.co.jp, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, namei.unix@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This adds a synchronous x-blockdev-create QMP command that can create qcow2 images on a given node name. We don't want to block while creating an image, so this is not the final interface in all aspects, but BlockdevCreateOptionsQcow2 and .bdrv_co_create() are what they actually might look like in the end. In any case, this should be good enough to test whether we interpret BlockdevCreateOptions as we should. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- qapi/block-core.json | 12 ++++++++ include/block/block_int.h | 5 +++- block/create.c | 76 +++++++++++++++++++++++++++++++++++++++++++= ++++ block/qcow2.c | 1 + block/Makefile.objs | 2 +- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 block/create.c diff --git a/qapi/block-core.json b/qapi/block-core.json index dfea7b0102..88d7a8678d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3464,6 +3464,18 @@ } } =20 ## +# @x-blockdev-create: +# +# Create an image format on a given node. +# TODO Replace with something asynchronous (block job?) +# +# Since: 2.12 +## +{ 'command': 'x-blockdev-create', + 'data': 'BlockdevCreateOptions', + 'boxed': true } + +## # @blockdev-open-tray: # # Opens a block device's tray. If there is a block driver state tree inser= ted as diff --git a/include/block/block_int.h b/include/block/block_int.h index a84cc04d55..27e17addba 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -129,8 +129,11 @@ struct BlockDriver { int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, Error **errp); void (*bdrv_close)(BlockDriverState *bs); - int coroutine_fn (*bdrv_co_create_opts)(const char *filename, QemuOpts= *opts, + int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts, Error **errp); + int coroutine_fn (*bdrv_co_create_opts)(const char *filename, + QemuOpts *opts, + Error **errp); int (*bdrv_make_empty)(BlockDriverState *bs); =20 void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); diff --git a/block/create.c b/block/create.c new file mode 100644 index 0000000000..8bd8a03719 --- /dev/null +++ b/block/create.c @@ -0,0 +1,76 @@ +/* + * Block layer code related to image creation + * + * Copyright (c) 2018 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "qapi/qapi-commands-block-core.h" +#include "qapi/error.h" + +typedef struct BlockdevCreateCo { + BlockDriver *drv; + BlockdevCreateOptions *opts; + int ret; + Error **errp; +} BlockdevCreateCo; + +static void coroutine_fn bdrv_co_create_co_entry(void *opaque) +{ + BlockdevCreateCo *cco =3D opaque; + cco->ret =3D cco->drv->bdrv_co_create(cco->opts, cco->errp); +} + +void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp) +{ + const char *fmt =3D BlockdevDriver_str(options->driver); + BlockDriver *drv =3D bdrv_find_format(fmt); + Coroutine *co; + BlockdevCreateCo cco; + + /* If the driver is in the schema, we know that it exists. But it may = not + * be whitelisted. */ + assert(drv); + if (bdrv_uses_whitelist() && !bdrv_is_whitelisted(drv, false)) { + error_setg(errp, "Driver is not whitelisted"); + return; + } + + /* Call callback if it exists */ + if (!drv->bdrv_co_create) { + error_setg(errp, "Driver does not support blockdev-create"); + return; + } + + cco =3D (BlockdevCreateCo) { + .drv =3D drv, + .opts =3D options, + .ret =3D -EINPROGRESS, + .errp =3D errp, + }; + + co =3D qemu_coroutine_create(bdrv_co_create_co_entry, &cco); + qemu_coroutine_enter(co); + while (cco.ret =3D=3D -EINPROGRESS) { + aio_poll(qemu_get_aio_context(), true); + } +} diff --git a/block/qcow2.c b/block/qcow2.c index 37b0e36c1e..7472af6931 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4490,6 +4490,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_join_options =3D qcow2_join_options, .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_create_opts =3D qcow2_co_create_opts, + .bdrv_co_create =3D qcow2_co_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D qcow2_co_block_status, =20 diff --git a/block/Makefile.objs b/block/Makefile.objs index aede94f105..d644bac60a 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -9,7 +9,7 @@ block-obj-y +=3D block-backend.o snapshot.o qapi.o block-obj-$(CONFIG_WIN32) +=3D file-win32.o win32-aio.o block-obj-$(CONFIG_POSIX) +=3D file-posix.o block-obj-$(CONFIG_LINUX_AIO) +=3D linux-aio.o -block-obj-y +=3D null.o mirror.o commit.o io.o +block-obj-y +=3D null.o mirror.o commit.o io.o create.o block-obj-y +=3D throttle-groups.o block-obj-$(CONFIG_LINUX) +=3D nvme.o =20 --=20 2.13.6