From nobody Fri Oct 24 09:45:36 2025 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 1519414698861234.15364881834898; Fri, 23 Feb 2018 11:38:18 -0800 (PST) Received: from localhost ([::1]:46752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epJAe-0001uz-VZ for importer@patchew.org; Fri, 23 Feb 2018 14:38:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epIzV-00014T-3P for qemu-devel@nongnu.org; Fri, 23 Feb 2018 14:26:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epIzT-0004ve-8L for qemu-devel@nongnu.org; Fri, 23 Feb 2018 14:26:45 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42270 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 1epIzP-0004pL-KI; Fri, 23 Feb 2018 14:26:39 -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 3D17C40FB646; Fri, 23 Feb 2018 19:26:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-118.ams2.redhat.com [10.36.117.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id A26102024CAC; Fri, 23 Feb 2018 19:26:37 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 23 Feb 2018 20:25:35 +0100 Message-Id: <20180223192549.26666-23-kwolf@redhat.com> In-Reply-To: <20180223192549.26666-1-kwolf@redhat.com> References: <20180223192549.26666-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.7]); Fri, 23 Feb 2018 19:26:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 23 Feb 2018 19:26:39 +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 v3 22/36] rbd: Support .bdrv_co_create 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 the .bdrv_co_create driver callback to rbd, which enables image creation over QMP. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- qapi/block-core.json | 19 ++++++- block/rbd.c | 146 ++++++++++++++++++++++++++++++++++-------------= ---- 2 files changed, 116 insertions(+), 49 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 74021c51d7..6c0c16ebe3 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3436,6 +3436,23 @@ '*refcount-bits': 'int' } } =20 ## +# @BlockdevCreateOptionsRbd: +# +# Driver specific image creation options for rbd/Ceph. +# +# @location Where to store the new image file. This location cannot +# point to a snapshot. +# @size Size of the virtual disk in bytes +# @cluster-size RBD object size +# +# Since: 2.12 +## +{ 'struct': 'BlockdevCreateOptionsRbd', + 'data': { 'location': 'BlockdevOptionsRbd', + 'size': 'size', + '*cluster-size' : 'size' } } + +## # @BlockdevCreateNotSupported: # # This is used for all drivers that don't support creating images. @@ -3484,7 +3501,7 @@ 'qed': 'BlockdevCreateNotSupported', 'quorum': 'BlockdevCreateNotSupported', 'raw': 'BlockdevCreateNotSupported', - 'rbd': 'BlockdevCreateNotSupported', + 'rbd': 'BlockdevCreateOptionsRbd', 'replication': 'BlockdevCreateNotSupported', 'sheepdog': 'BlockdevCreateNotSupported', 'ssh': 'BlockdevCreateNotSupported', diff --git a/block/rbd.c b/block/rbd.c index 9b247f020d..ee71dc8941 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -332,69 +332,55 @@ static QemuOptsList runtime_opts =3D { }, }; =20 -static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **e= rrp) +/* FIXME Deprecate and remove keypairs or make it available in QMP. + * password_secret should eventually be configurable in opts->location. Su= pport + * for it in .bdrv_open will make it work here as well. */ +static int qemu_rbd_do_create(BlockdevCreateOptions *options, + const char *keypairs, const char *password_s= ecret, + Error **errp) { - Error *local_err =3D NULL; - int64_t bytes =3D 0; - int64_t objsize; - int obj_order =3D 0; - const char *pool, *image_name, *conf, *user, *keypairs; - const char *secretid; + BlockdevCreateOptionsRbd *opts =3D &options->u.rbd; rados_t cluster; rados_ioctx_t io_ctx; - QDict *options =3D NULL; - int ret =3D 0; + int obj_order =3D 0; + int ret; =20 - secretid =3D qemu_opt_get(opts, "password-secret"); + assert(options->driver =3D=3D BLOCKDEV_DRIVER_RBD); + if (opts->location->has_snapshot) { + error_setg(errp, "Can't use snapshot name for image creation"); + return -EINVAL; + } =20 - /* Read out options */ - bytes =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); - objsize =3D qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0); - if (objsize) { + /* TODO Remove the limitation */ + if (opts->location->has_server) { + error_setg(errp, "Can't specify server for image creation"); + return -EINVAL; + } + + if (opts->has_cluster_size) { + int64_t objsize =3D opts->cluster_size; if ((objsize - 1) & objsize) { /* not a power of 2? */ error_setg(errp, "obj size needs to be power of 2"); - ret =3D -EINVAL; - goto exit; + return -EINVAL; } if (objsize < 4096) { error_setg(errp, "obj size too small"); - ret =3D -EINVAL; - goto exit; + return -EINVAL; } obj_order =3D ctz32(objsize); } =20 - options =3D qdict_new(); - qemu_rbd_parse_filename(filename, options, &local_err); - if (local_err) { - ret =3D -EINVAL; - error_propagate(errp, local_err); - goto exit; - } - - /* - * Caution: while qdict_get_try_str() is fine, getting non-string - * types would require more care. When @options come from -blockdev - * or blockdev_add, its members are typed according to the QAPI - * schema, but when they come from -drive, they're all QString. - */ - pool =3D qdict_get_try_str(options, "pool"); - conf =3D qdict_get_try_str(options, "conf"); - user =3D qdict_get_try_str(options, "user"); - image_name =3D qdict_get_try_str(options, "image"); - keypairs =3D qdict_get_try_str(options, "=3Dkeyvalue-pairs"); - - ret =3D rados_create(&cluster, user); + ret =3D rados_create(&cluster, opts->location->user); if (ret < 0) { error_setg_errno(errp, -ret, "error initializing"); - goto exit; + return ret; } =20 /* try default location when conf=3DNULL, but ignore failure */ - ret =3D rados_conf_read_file(cluster, conf); - if (conf && ret < 0) { - error_setg_errno(errp, -ret, "error reading conf file %s", conf); + ret =3D rados_conf_read_file(cluster, opts->location->conf); + if (opts->location->conf && ret < 0) { + error_setg_errno(errp, -ret, "error reading conf file %s", + opts->location->conf); ret =3D -EIO; goto shutdown; } @@ -405,7 +391,7 @@ static int qemu_rbd_create(const char *filename, QemuOp= ts *opts, Error **errp) goto shutdown; } =20 - if (qemu_rbd_set_auth(cluster, secretid, errp) < 0) { + if (qemu_rbd_set_auth(cluster, password_secret, errp) < 0) { ret =3D -EIO; goto shutdown; } @@ -416,24 +402,87 @@ static int qemu_rbd_create(const char *filename, Qemu= Opts *opts, Error **errp) goto shutdown; } =20 - ret =3D rados_ioctx_create(cluster, pool, &io_ctx); + ret =3D rados_ioctx_create(cluster, opts->location->pool, &io_ctx); if (ret < 0) { - error_setg_errno(errp, -ret, "error opening pool %s", pool); + error_setg_errno(errp, -ret, "error opening pool %s", + opts->location->pool); goto shutdown; } =20 - ret =3D rbd_create(io_ctx, image_name, bytes, &obj_order); + ret =3D rbd_create(io_ctx, opts->location->image, opts->size, &obj_ord= er); if (ret < 0) { error_setg_errno(errp, -ret, "error rbd create"); } =20 rados_ioctx_destroy(io_ctx); =20 + ret =3D 0; shutdown: rados_shutdown(cluster); + return ret; +} + +static int qemu_rbd_co_create(BlockdevCreateOptions *options, Error **errp) +{ + return qemu_rbd_do_create(options, NULL, NULL, errp); +} + +static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **e= rrp) +{ + BlockdevCreateOptions *create_options; + BlockdevCreateOptionsRbd *rbd_opts; + BlockdevOptionsRbd *loc; + Error *local_err =3D NULL; + const char *keypairs, *password_secret; + QDict *options =3D NULL; + int ret =3D 0; + + create_options =3D g_new0(BlockdevCreateOptions, 1); + create_options->driver =3D BLOCKDEV_DRIVER_RBD; + rbd_opts =3D &create_options->u.rbd; + + rbd_opts->location =3D g_new0(BlockdevOptionsRbd, 1); + + password_secret =3D qemu_opt_get(opts, "password-secret"); + + /* Read out options */ + rbd_opts->size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE= , 0), + BDRV_SECTOR_SIZE); + rbd_opts->cluster_size =3D qemu_opt_get_size_del(opts, + BLOCK_OPT_CLUSTER_SIZE,= 0); + rbd_opts->has_cluster_size =3D (rbd_opts->cluster_size !=3D 0); + + options =3D qdict_new(); + qemu_rbd_parse_filename(filename, options, &local_err); + if (local_err) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + goto exit; + } + + /* + * Caution: while qdict_get_try_str() is fine, getting non-string + * types would require more care. When @options come from -blockdev + * or blockdev_add, its members are typed according to the QAPI + * schema, but when they come from -drive, they're all QString. + */ + loc =3D rbd_opts->location; + loc->pool =3D g_strdup(qdict_get_try_str(options, "pool")); + loc->conf =3D g_strdup(qdict_get_try_str(options, "conf")); + loc->has_conf =3D !!loc->conf; + loc->user =3D g_strdup(qdict_get_try_str(options, "user")); + loc->has_user =3D !!loc->user; + loc->image =3D g_strdup(qdict_get_try_str(options, "image")); + keypairs =3D qdict_get_try_str(options, "=3Dkeyvalue-pairs"); + + ret =3D qemu_rbd_do_create(create_options, keypairs, password_secret, = errp); + if (ret < 0) { + goto exit; + } =20 exit: QDECREF(options); + qapi_free_BlockdevCreateOptions(create_options); return ret; } =20 @@ -1144,6 +1193,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_close =3D qemu_rbd_close, .bdrv_reopen_prepare =3D qemu_rbd_reopen_prepare, .bdrv_create =3D qemu_rbd_create, + .bdrv_co_create =3D qemu_rbd_co_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_get_info =3D qemu_rbd_getinfo, .create_opts =3D &qemu_rbd_create_opts, --=20 2.13.6