From nobody Fri May 3 10:30:42 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488549195619790.9699921765592; Fri, 3 Mar 2017 05:53:15 -0800 (PST) Received: from localhost ([::1]:58194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjndv-00006Q-4H for importer@patchew.org; Fri, 03 Mar 2017 08:53:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjncx-0008VZ-6C for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjncw-0005pI-4G for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjncv-0005p3-S5 for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:10 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECC30883A6; Fri, 3 Mar 2017 13:52:09 +0000 (UTC) Received: from localhost (ovpn-117-174.ams2.redhat.com [10.36.117.174]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v23Dq67J032646; Fri, 3 Mar 2017 08:52:08 -0500 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 21:51:47 +0800 Message-Id: <20170303135150.12145-2-stefanha@redhat.com> In-Reply-To: <20170303135150.12145-1-stefanha@redhat.com> References: <20170303135150.12145-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 03 Mar 2017 13:52:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 1/4] block: add bdrv_max_size() API 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: Kevin Wolf , John Snow , Nir Soffer , Maor Lipchuk , Stefan Hajnoczi , Alberto Garcia 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" bdrv_max_size() provides a conservative maximum for the size of a new image. This information is handy if storage needs to be allocated (e.g. a SAN or an LVM volume) ahead of time. Signed-off-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia --- include/block/block.h | 2 ++ include/block/block_int.h | 2 ++ block.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index c7c4a3a..12e1532 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -298,6 +298,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset); int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); +uint64_t bdrv_max_size(BlockDriver *drv, QemuOpts *opts, + BlockDriverState *in_bs, Error **errp); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); int bdrv_commit(BlockDriverState *bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index a57c0bf..0354e22 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -201,6 +201,8 @@ struct BlockDriver { int64_t (*bdrv_getlength)(BlockDriverState *bs); bool has_variable_length; int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); + uint64_t (*bdrv_max_size)(QemuOpts *opts, BlockDriverState *in_bs, + Error **errp); =20 int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov); diff --git a/block.c b/block.c index f293ccb..4a228f0 100644 --- a/block.c +++ b/block.c @@ -3188,6 +3188,43 @@ int64_t bdrv_get_allocated_file_size(BlockDriverStat= e *bs) return -ENOTSUP; } =20 +/* + * bdrv_max_size: + * @drv: Format driver + * @opts: Creation options + * @in_bs: Existing image containing data for new image (may be NULL) + * @errp: Error object + * + * Calculate maximum file size required by a new image. The value is + * conservative so actual creation of the image never requires more space = than + * what is returned by this function. + * + * Note that this value is the file size including sparse regions, not the + * allocated file size. A new 5 GB raw file therefore has a maximum size = of 5 + * GB, not 0! + * + * If @in_bs is given then space for allocated clusters and zero clusters + * from that image are included in the calculation. If @opts contains a + * backing file that is shared by @in_bs then backing clusters are omitted + * from the calculation. + * + * If @in_bs is NULL then the calculation includes no allocated clusters + * unless a preallocation option is given in @opts. + * + * Returns the maximum size for the new image or 0 on error. + */ +uint64_t bdrv_max_size(BlockDriver *drv, QemuOpts *opts, + BlockDriverState *in_bs, Error **errp) +{ + if (!drv->bdrv_max_size) { + error_setg(errp, "Block driver '%s' does not support max size " + "calculation", drv->format_name); + return 0; + } + + return drv->bdrv_max_size(opts, in_bs, errp); +} + /** * Return number of sectors on success, -errno on error. */ --=20 2.9.3 From nobody Fri May 3 10:30:42 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488549202614655.3929449069464; Fri, 3 Mar 2017 05:53:22 -0800 (PST) Received: from localhost ([::1]:58195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjne5-0000By-Eu for importer@patchew.org; Fri, 03 Mar 2017 08:53:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjnd1-00007m-Ms for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjnd0-0005qh-Uf for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57132) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjnd0-0005qU-PV for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:14 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6B9FC05680F; Fri, 3 Mar 2017 13:52:14 +0000 (UTC) Received: from localhost (ovpn-117-174.ams2.redhat.com [10.36.117.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEAF62D654; Fri, 3 Mar 2017 13:52:13 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 21:51:48 +0800 Message-Id: <20170303135150.12145-3-stefanha@redhat.com> In-Reply-To: <20170303135150.12145-1-stefanha@redhat.com> References: <20170303135150.12145-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 03 Mar 2017 13:52:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 2/4] raw-format: add bdrv_max_size() support 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: Kevin Wolf , John Snow , Nir Soffer , Maor Lipchuk , Stefan Hajnoczi , Alberto Garcia 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" Maximum size calculation is trivial for the raw format: it's just the requested image size (because there is no metadata). Signed-off-by: Stefan Hajnoczi --- block/raw-format.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 86fbc65..f8cb6b3 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -312,6 +312,21 @@ static int64_t raw_getlength(BlockDriverState *bs) return s->size; } =20 +static uint64_t raw_max_size(QemuOpts *opts, BlockDriverState *in_bs, + Error **errp) +{ + if (in_bs) { + int64_t size =3D bdrv_nb_sectors(in_bs); + if (size < 0) { + error_setg_errno(errp, -size, "Unable to get image size"); + return 0; + } + return (uint64_t)size * BDRV_SECTOR_SIZE; + } + + return qemu_opt_get_size(opts, "size", 0); +} + static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { return bdrv_get_info(bs->file->bs, bdi); @@ -477,6 +492,7 @@ BlockDriver bdrv_raw =3D { .bdrv_truncate =3D &raw_truncate, .bdrv_getlength =3D &raw_getlength, .has_variable_length =3D true, + .bdrv_max_size =3D &raw_max_size, .bdrv_get_info =3D &raw_get_info, .bdrv_refresh_limits =3D &raw_refresh_limits, .bdrv_probe_blocksizes =3D &raw_probe_blocksizes, --=20 2.9.3 From nobody Fri May 3 10:30:42 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488549427378202.30813717871774; Fri, 3 Mar 2017 05:57:07 -0800 (PST) Received: from localhost ([::1]:58216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjnhh-0003dC-Rt for importer@patchew.org; Fri, 03 Mar 2017 08:57:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjndA-0000EV-Gz for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjnd9-0005s4-CX for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjnd9-0005rt-4D for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:23 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3992A3B74F; Fri, 3 Mar 2017 13:52:23 +0000 (UTC) Received: from localhost (ovpn-117-174.ams2.redhat.com [10.36.117.174]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v23DqK92015102; Fri, 3 Mar 2017 08:52:21 -0500 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 21:51:49 +0800 Message-Id: <20170303135150.12145-4-stefanha@redhat.com> In-Reply-To: <20170303135150.12145-1-stefanha@redhat.com> References: <20170303135150.12145-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 03 Mar 2017 13:52:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 3/4] qemu-img: add max-size subcommand 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: Kevin Wolf , John Snow , Nir Soffer , Maor Lipchuk , Stefan Hajnoczi , Alberto Garcia 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" The max-size subcommand calculates the maximum size required by a new image file. This can be used by users or management tools that need to allocate space on an LVM volume, SAN LUN, etc before creating or converting an image file. Suggested-by: Maor Lipchuk Signed-off-by: Stefan Hajnoczi --- qemu-img.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ qemu-img-cmds.hx | 6 ++ 2 files changed, 202 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 98b836b..f0a5a85 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -59,6 +59,7 @@ enum { OPTION_PATTERN =3D 260, OPTION_FLUSH_INTERVAL =3D 261, OPTION_NO_DRAIN =3D 262, + OPTION_SIZE =3D 263, }; =20 typedef enum OutputFormat { @@ -4287,6 +4288,201 @@ out: return 0; } =20 +static int img_max_size(int argc, char **argv) +{ + static const struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"object", required_argument, 0, OPTION_OBJECT}, + {"output", required_argument, 0, OPTION_OUTPUT}, + {"size", required_argument, 0, OPTION_SIZE}, + {0, 0, 0, 0} + }; + OutputFormat output_format =3D OFORMAT_HUMAN; + BlockBackend *in_blk =3D NULL; + BlockDriver *drv; + const char *filename =3D NULL; + const char *fmt =3D NULL; + const char *out_fmt =3D "raw"; + char *options =3D NULL; + char *snapshot_name =3D NULL; + QemuOpts *opts =3D NULL; + QemuOpts *object_opts =3D NULL; + QemuOpts *sn_opts =3D NULL; + QemuOptsList *create_opts =3D NULL; + bool image_opts =3D false; + uint64_t img_size =3D ~0ULL; + uint64_t ret_size; + Error *local_err =3D NULL; + int ret =3D 1; + int c; + + while ((c =3D getopt_long(argc, argv, "hf:O:o:l:", + long_options, NULL)) !=3D -1) { + switch (c) { + case '?': + case 'h': + help(); + break; + case 'f': + fmt =3D optarg; + break; + case 'O': + out_fmt =3D optarg; + break; + case 'o': + if (!is_valid_option_list(optarg)) { + error_report("Invalid option list: %s", optarg); + goto fail; + } + if (!options) { + options =3D g_strdup(optarg); + } else { + char *old_options =3D options; + options =3D g_strdup_printf("%s,%s", options, optarg); + g_free(old_options); + } + break; + case 'l': + if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { + sn_opts =3D qemu_opts_parse_noisily(&internal_snapshot_opt= s, + optarg, false); + if (!sn_opts) { + error_report("Failed in parsing snapshot param '%s'", + optarg); + goto fail; + } + } else { + snapshot_name =3D optarg; + } + break; + case OPTION_OBJECT: + object_opts =3D qemu_opts_parse_noisily(&qemu_object_opts, + optarg, true); + if (!object_opts) { + goto fail; + } + break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + case OPTION_OUTPUT: + if (!strcmp(optarg, "json")) { + output_format =3D OFORMAT_JSON; + } else if (!strcmp(optarg, "human")) { + output_format =3D OFORMAT_HUMAN; + } else { + error_report("--output must be used with human or json " + "as argument."); + goto fail; + } + break; + case OPTION_SIZE: + { + int64_t sval; + + sval =3D cvtnum(optarg); + if (sval < 0) { + if (sval =3D=3D -ERANGE) { + error_report("Image size must be less than 8 EiB!"); + } else { + error_report("Invalid image size specified! You may us= e " + "k, M, G, T, P or E suffixes for "); + error_report("kilobytes, megabytes, gigabytes, terabyt= es, " + "petabytes and exabytes."); + } + goto fail; + } + img_size =3D (uint64_t)sval; + } + break; + } + } + + if (qemu_opts_foreach(&qemu_object_opts, + user_creatable_add_opts_foreach, + NULL, NULL)) { + goto fail; + } + + if (argc - optind > 1) { + error_report("At most one filename argument is allowed."); + goto fail; + } else if (argc - optind =3D=3D 1) { + filename =3D argv[optind]; + } + + if (!filename && + (object_opts || image_opts || fmt || snapshot_name || sn_opts)) { + error_report("--object, --image-opts, -f, and -l " + "require a filename argument."); + goto fail; + } + if (filename && img_size !=3D ~0ULL) { + error_report("--size N cannot be used together with a filename."); + goto fail; + } + if (!filename && img_size =3D=3D ~0ULL) { + error_report("Either --size N or one filename must be specified."); + goto fail; + } + + if (filename) { + in_blk =3D img_open(image_opts, filename, fmt, 0, false, false); + if (!in_blk) { + goto fail; + } + } + + drv =3D bdrv_find_format(out_fmt); + if (!drv) { + error_report("Unknown file format '%s'", out_fmt); + goto fail; + } + if (!drv->create_opts) { + error_report("Format driver '%s' does not support image creation", + drv->format_name); + goto fail; + } + + create_opts =3D qemu_opts_append(create_opts, drv->create_opts); + opts =3D qemu_opts_create(create_opts, NULL, 0, &error_abort); + if (options) { + qemu_opts_do_parse(opts, options, NULL, &local_err); + if (local_err) { + error_report_err(local_err); + error_report("Invalid options for file format '%s'", out_fmt); + goto fail; + } + } + if (img_size !=3D ~0ULL) { + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort); + } + + ret_size =3D bdrv_max_size(drv, opts, in_blk ? blk_bs(in_blk) : NULL, + &local_err); + if (local_err) { + error_report_err(local_err); + goto fail; + } + + if (output_format =3D=3D OFORMAT_HUMAN) { + printf("%" PRIu64 "\n", ret_size); + } else { + printf("{ \"size\": %" PRIu64 " }\n", ret_size); + } + + ret =3D 0; + +fail: + qemu_opts_del(object_opts); + qemu_opts_del(opts); + qemu_opts_del(sn_opts); + qemu_opts_free(create_opts); + g_free(options); + blk_unref(in_blk); + return ret; +} =20 static const img_cmd_t img_cmds[] =3D { #define DEF(option, callback, arg_string) \ diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 9c9702c..80997f9 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -87,3 +87,9 @@ STEXI @item amend [--object @var{objectdef}] [--image-opts] [-p] [-q] [-f @var{f= mt}] [-t @var{cache}] -o @var{options} @var{filename} @end table ETEXI + +DEF("max-size", img_max_size, +"max-size [--output=3Dofmt] [-O output_fmt] [-o options] [--size N | [--ob= ject objectdef] [--image-opts] [-f fmt] [-l snapshot_param] filename]") +STEXI +TODO max-size documentation +ETEXI --=20 2.9.3 From nobody Fri May 3 10:30:42 2024 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488549217738578.3522177237709; Fri, 3 Mar 2017 05:53:37 -0800 (PST) Received: from localhost ([::1]:58197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjneK-0000Mw-Gh for importer@patchew.org; Fri, 03 Mar 2017 08:53:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjndI-0000LC-Bs for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjndE-0005tU-FC for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39478) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjndE-0005tA-6X for qemu-devel@nongnu.org; Fri, 03 Mar 2017 08:52:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BDD87FB68; Fri, 3 Mar 2017 13:52:28 +0000 (UTC) Received: from localhost (ovpn-117-174.ams2.redhat.com [10.36.117.174]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v23DqOhQ011585; Fri, 3 Mar 2017 08:52:26 -0500 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 21:51:50 +0800 Message-Id: <20170303135150.12145-5-stefanha@redhat.com> In-Reply-To: <20170303135150.12145-1-stefanha@redhat.com> References: <20170303135150.12145-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 03 Mar 2017 13:52:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 4/4] iotests: add test 178 for qemu-img max-size 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: Kevin Wolf , John Snow , Nir Soffer , Maor Lipchuk , Stefan Hajnoczi , Alberto Garcia 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" Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/178 | 75 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/178.out | 25 ++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 101 insertions(+) create mode 100755 tests/qemu-iotests/178 create mode 100644 tests/qemu-iotests/178.out diff --git a/tests/qemu-iotests/178 b/tests/qemu-iotests/178 new file mode 100755 index 0000000..313981b --- /dev/null +++ b/tests/qemu-iotests/178 @@ -0,0 +1,75 @@ +#!/bin/bash +# +# qemu-img max-size tests +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dstefanha@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +echo "Input validation" +echo + +_make_test_img 1G + +$QEMU_IMG max-size # missing arguments +$QEMU_IMG max-size --size 2G "$TEST_IMG" # only one allowed +$QEMU_IMG max-size "$TEST_IMG" a # only one filename allowed +$QEMU_IMG max-size --object secret,id=3Dsec0,data=3DMTIzNDU2,format=3Dbase= 64 # missing filename +$QEMU_IMG max-size --image-opts # missing filename +$QEMU_IMG max-size -f qcow2 # missing filename +$QEMU_IMG max-size -l snap1 # missing filename +$QEMU_IMG max-size -o , # invalid option list +$QEMU_IMG max-size -l snapshot.foo # invalid snapshot option +$QEMU_IMG max-size --output foo # invalid output format +$QEMU_IMG max-size --size -1 # invalid image size +$QEMU_IMG max-size -O foo "$TEST_IMG" # unknown image file format + +echo +echo "Size calculation" +echo + +for ofmt in human json; do + $QEMU_IMG max-size --output=3D$ofmt -O "$IMGFMT" --size 2G + $QEMU_IMG max-size --output=3D$ofmt -f "$IMGFMT" -O "$IMGFMT" "$TEST_I= MG" +done + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/178.out b/tests/qemu-iotests/178.out new file mode 100644 index 0000000..6750ad6 --- /dev/null +++ b/tests/qemu-iotests/178.out @@ -0,0 +1,25 @@ +QA output created by 178 +Input validation + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 +qemu-img: Either --size N or one filename must be specified. +qemu-img: --size N cannot be used together with a filename. +qemu-img: At most one filename argument is allowed. +qemu-img: --object, --image-opts, -f, and -l require a filename argument. +qemu-img: --object, --image-opts, -f, and -l require a filename argument. +qemu-img: --object, --image-opts, -f, and -l require a filename argument. +qemu-img: --object, --image-opts, -f, and -l require a filename argument. +qemu-img: Invalid option list: , +qemu-img: Invalid parameter 'snapshot.foo' +qemu-img: Failed in parsing snapshot param 'snapshot.foo' +qemu-img: --output must be used with human or json as argument. +qemu-img: Image size must be less than 8 EiB! +qemu-img: Unknown file format 'foo' + +Size calculation + +2147483648 +1073741824 +{ "size": 2147483648 } +{ "size": 1073741824 } +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 1f4bf03..846f962 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -168,3 +168,4 @@ 173 rw auto 174 auto 175 auto quick +178 auto quick --=20 2.9.3