From nobody Fri Oct 24 09:38:23 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 15194145185191023.9501357925001; Fri, 23 Feb 2018 11:35:18 -0800 (PST) Received: from localhost ([::1]:46732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epJ7l-0007q2-MC for importer@patchew.org; Fri, 23 Feb 2018 14:35:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epIzL-0000wd-Eo for qemu-devel@nongnu.org; Fri, 23 Feb 2018 14:26:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epIzJ-0004i7-TC for qemu-devel@nongnu.org; Fri, 23 Feb 2018 14:26:35 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38872 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 1epIzG-0004ac-GQ; Fri, 23 Feb 2018 14:26:30 -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 1C45B402243B; Fri, 23 Feb 2018 19:26:30 +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 810342024CAC; Fri, 23 Feb 2018 19:26:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 23 Feb 2018 20:25:30 +0100 Message-Id: <20180223192549.26666-18-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.6]); Fri, 23 Feb 2018 19:26:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 23 Feb 2018 19:26:30 +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 17/36] 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, 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 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 0040795603..74021c51d7 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 1a07d221d1..6e2f0e3185 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,19 +1035,71 @@ static int qemu_gluster_do_truncate(struct glfs_fd = *fd, int64_t offset, return 0; } =20 -static int qemu_gluster_create(const char *filename, - QemuOpts *opts, Error **errp) +static int qemu_gluster_co_create(BlockdevCreateOptions *options, + Error **errp) { - BlockdevOptionsGluster *gconf; + BlockdevCreateOptionsGluster *opts =3D &options->u.gluster; struct glfs *glfs; struct glfs_fd *fd =3D NULL; int ret =3D 0; - PreallocMode prealloc; - int64_t total_size =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 qemu_gluster_create(const char *filename, + QemuOpts *opts, Error **errp) +{ + BlockdevCreateOptions *options; + BlockdevCreateOptionsGluster *gopts; + BlockdevOptionsGluster *gconf; 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) { @@ -1049,42 +1115,19 @@ static int qemu_gluster_create(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_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, @@ -1464,6 +1508,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, @@ -1492,6 +1537,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, @@ -1526,6 +1572,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_reopen_abort =3D qemu_gluster_reopen_abort, .bdrv_close =3D qemu_gluster_close, .bdrv_create =3D qemu_gluster_create, + .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_truncate =3D qemu_gluster_truncate, --=20 2.13.6