From nobody Thu Dec 18 17:51:59 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 1520615495403521.0938032643618; Fri, 9 Mar 2018 09:11:35 -0800 (PST) Received: from localhost ([::1]:46616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLYM-0003IM-EZ for importer@patchew.org; Fri, 09 Mar 2018 12:11:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euKl5-0001E3-Kc for qemu-devel@nongnu.org; Fri, 09 Mar 2018 11:20:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euKl3-00073h-BH for qemu-devel@nongnu.org; Fri, 09 Mar 2018 11:20:39 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59492 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 1euKkz-0006yK-UJ; Fri, 09 Mar 2018 11:20:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87B21F641F; Fri, 9 Mar 2018 16:20:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6D16215CDAA; Fri, 9 Mar 2018 16:20:32 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 17:19:09 +0100 Message-Id: <20180309161933.8168-33-kwolf@redhat.com> In-Reply-To: <20180309161933.8168-1-kwolf@redhat.com> References: <20180309161933.8168-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 09 Mar 2018 16:20:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 09 Mar 2018 16:20:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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] [PULL 32/56] gluster: 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, qemu-devel@nongnu.org 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 gluster, which enables image creation over QMP. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- qapi/block-core.json | 18 ++++++- block/gluster.c | 135 ++++++++++++++++++++++++++++++++++-------------= ---- 2 files changed, 108 insertions(+), 45 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 41955b097f..9170fbf6e6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3377,6 +3377,22 @@ '*nocow': 'bool' } } =20 ## +# @BlockdevCreateOptionsGluster: +# +# Driver specific image creation options for gluster. +# +# @location Where to store the new image file +# @size Size of the virtual disk in bytes +# @preallocation Preallocation mode for the new image (default: off) +# +# Since: 2.12 +## +{ 'struct': 'BlockdevCreateOptionsGluster', + 'data': { 'location': 'BlockdevOptionsGluster', + 'size': 'size', + '*preallocation': 'PreallocMode' } } + +## # @BlockdevQcow2Version: # # @v2: The original QCOW2 format as introduced in qemu 0.10 (version 2) @@ -3450,7 +3466,7 @@ 'file': 'BlockdevCreateOptionsFile', 'ftp': 'BlockdevCreateNotSupported', 'ftps': 'BlockdevCreateNotSupported', - 'gluster': 'BlockdevCreateNotSupported', + 'gluster': 'BlockdevCreateOptionsGluster', 'host_cdrom': 'BlockdevCreateNotSupported', 'host_device': 'BlockdevCreateNotSupported', 'http': 'BlockdevCreateNotSupported', diff --git a/block/gluster.c b/block/gluster.c index 79b4cfdf74..63d3c37d4c 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -655,9 +655,11 @@ out: return -errno; } =20 -static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, - const char *filename, - QDict *options, Error **errp) +/* Converts options given in @filename and the @options QDict into the QAPI + * object @gconf. */ +static int qemu_gluster_parse(BlockdevOptionsGluster *gconf, + const char *filename, + QDict *options, Error **errp) { int ret; if (filename) { @@ -668,8 +670,7 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGl= uster *gconf, "[host[:port]]volume/path[?socket=3D..= .]" "[,file.debug=3DN]" "[,file.logfile=3D/path/filename.log]\= n"); - errno =3D -ret; - return NULL; + return ret; } } else { ret =3D qemu_gluster_parse_json(gconf, options, errp); @@ -685,10 +686,23 @@ static struct glfs *qemu_gluster_init(BlockdevOptions= Gluster *gconf, "file.server.1.transport=3Dunix," "file.server.1.socket=3D/var/run/glusterd.soc= ket ..." "\n"); - errno =3D -ret; - return NULL; + return ret; } + } =20 + return 0; +} + +static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf, + const char *filename, + QDict *options, Error **errp) +{ + int ret; + + ret =3D qemu_gluster_parse(gconf, filename, options, errp); + if (ret < 0) { + errno =3D -ret; + return NULL; } =20 return qemu_gluster_glfs_init(gconf, errp); @@ -1021,20 +1035,72 @@ static int qemu_gluster_do_truncate(struct glfs_fd = *fd, int64_t offset, return 0; } =20 +static int qemu_gluster_co_create(BlockdevCreateOptions *options, + Error **errp) +{ + BlockdevCreateOptionsGluster *opts =3D &options->u.gluster; + struct glfs *glfs; + struct glfs_fd *fd =3D NULL; + int ret =3D 0; + + assert(options->driver =3D=3D BLOCKDEV_DRIVER_GLUSTER); + + glfs =3D qemu_gluster_glfs_init(opts->location, errp); + if (!glfs) { + ret =3D -errno; + goto out; + } + + fd =3D glfs_creat(glfs, opts->location->path, + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_I= WUSR); + if (!fd) { + ret =3D -errno; + goto out; + } + + ret =3D qemu_gluster_do_truncate(fd, opts->size, opts->preallocation, = errp); + +out: + if (fd) { + if (glfs_close(fd) !=3D 0 && ret =3D=3D 0) { + ret =3D -errno; + } + } + glfs_clear_preopened(glfs); + return ret; +} + static int coroutine_fn qemu_gluster_co_create_opts(const char *filename, QemuOpts *opts, Error **errp) { + BlockdevCreateOptions *options; + BlockdevCreateOptionsGluster *gopts; BlockdevOptionsGluster *gconf; - struct glfs *glfs; - struct glfs_fd *fd =3D NULL; - int ret =3D 0; - PreallocMode prealloc; - int64_t total_size =3D 0; char *tmp =3D NULL; Error *local_err =3D NULL; + int ret; + + options =3D g_new0(BlockdevCreateOptions, 1); + options->driver =3D BLOCKDEV_DRIVER_GLUSTER; + gopts =3D &options->u.gluster; =20 gconf =3D g_new0(BlockdevOptionsGluster, 1); + gopts->location =3D gconf; + + gopts->size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0= ), + BDRV_SECTOR_SIZE); + + tmp =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); + gopts->preallocation =3D qapi_enum_parse(&PreallocMode_lookup, tmp, + PREALLOC_MODE_OFF, &local_err); + g_free(tmp); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fail; + } + gconf->debug =3D qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG, GLUSTER_DEBUG_DEFAULT); if (gconf->debug < 0) { @@ -1050,42 +1116,19 @@ static int coroutine_fn qemu_gluster_co_create_opts= (const char *filename, } gconf->has_logfile =3D true; =20 - glfs =3D qemu_gluster_init(gconf, filename, NULL, errp); - if (!glfs) { - ret =3D -errno; - goto out; - } - - total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); - - tmp =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - prealloc =3D qapi_enum_parse(&PreallocMode_lookup, tmp, PREALLOC_MODE_= OFF, - &local_err); - g_free(tmp); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - goto out; + ret =3D qemu_gluster_parse(gconf, filename, NULL, errp); + if (ret < 0) { + goto fail; } =20 - fd =3D glfs_creat(glfs, gconf->path, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_I= WUSR); - if (!fd) { - ret =3D -errno; - goto out; + ret =3D qemu_gluster_co_create(options, errp); + if (ret < 0) { + goto fail; } =20 - ret =3D qemu_gluster_do_truncate(fd, total_size, prealloc, errp); - -out: - if (fd) { - if (glfs_close(fd) !=3D 0 && ret =3D=3D 0) { - ret =3D -errno; - } - } - qapi_free_BlockdevOptionsGluster(gconf); - glfs_clear_preopened(glfs); + ret =3D 0; +fail: + qapi_free_BlockdevCreateOptions(options); return ret; } =20 @@ -1436,6 +1479,7 @@ static BlockDriver bdrv_gluster =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, @@ -1464,6 +1508,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, @@ -1492,6 +1537,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, @@ -1526,6 +1572,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_reopen_commit =3D qemu_gluster_reopen_commit, .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, --=20 2.13.6