From patchwork Mon Aug 22 07:55:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reda Sallahi X-Patchwork-Id: 9293091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B217560574 for ; Mon, 22 Aug 2016 08:01:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1CCE287E8 for ; Mon, 22 Aug 2016 08:01:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 965DA28843; Mon, 22 Aug 2016 08:01:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63A16287E8 for ; Mon, 22 Aug 2016 08:01:14 +0000 (UTC) Received: from localhost ([::1]:40145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbkAT-0000WY-Ha for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Aug 2016 04:01:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbk5b-0004Zg-On for qemu-devel@nongnu.org; Mon, 22 Aug 2016 03:56:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bbk5V-0004hS-4g for qemu-devel@nongnu.org; Mon, 22 Aug 2016 03:56:10 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35473) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbk5U-0004hL-N2; Mon, 22 Aug 2016 03:56:05 -0400 Received: by mail-wm0-x243.google.com with SMTP id i5so12205438wmg.2; Mon, 22 Aug 2016 00:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yfctSU2yGOxCTP9k04BiEBErdxlDmcu4K83bVc+rZv8=; b=g8NfaT3LuodvvC3OCv+4tO6/OdswUH7sgWNM9ZcIKxxF2/KIx1htNMMJXAbHj5ZmAV GPh1p7j0cEybcTjMEZKlDFRYqSmgrG8Xm/wurj14YU1pMlPv5kKDdVbGvXNo061FN+wD G4MEnytutq0edRtvWkRECUyxI3crLpmVwqYuN6sO3TBQ4KjnzXrvMUifwv3tTCYIcT+c vfH3nybFvdcI0tlLJ6Yt/zE02W1RSQAcuNoQW2VfBo9rSPZzHepV3xEbHlRb8obUEi5d 20ovy8hiFf+XqLNMN+SnPDEGtZnu5xX4T2x5pENvugasv+uiPHzkPoe6X4O+D30ku3Gm ZRQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yfctSU2yGOxCTP9k04BiEBErdxlDmcu4K83bVc+rZv8=; b=XJExZM1avsOu3TFb1gU/sHuWbMlKUrtQMWOsGOQT6CP1NXTTdazdEHSau/iWBxd7vp z9UryewCXNcCTJ32r40lsYwvWqugiQ4s3DbjyuoEwcaJzIXfDeII8xDcaulzr/uWDnuc FO3mCbUPNHlY/xxckd549PUquSbdYLu2kbPmabd+J2X61GexNKxoW47W04ndQ0DlBmHR XPbJGdOyd33XpWORjlPYV0lB9A1YIotP2aPgdy4iGUlq/rALb5LCPZsk5kVpptBPYvPz UJU7qfnZLcpd6uRiz4KHUWP3DygNJrBEcqIC0xrA2qSLcn3mBsqiStUpptCUBOt2Vc90 F+5A== X-Gm-Message-State: AEkoousZSTa/zZ4n7eHLIcpmnEP7HPI5YxpZbSvs2/7DpFPT2tC70DxK5bis3TCToi0wbA== X-Received: by 10.194.186.231 with SMTP id fn7mr16374957wjc.164.1471852563692; Mon, 22 Aug 2016 00:56:03 -0700 (PDT) Received: from cinque_stelle.sm14.sm.cri.epita.net ([163.5.208.89]) by smtp.gmail.com with ESMTPSA id uo4sm22329922wjc.36.2016.08.22.00.56.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Aug 2016 00:56:03 -0700 (PDT) From: Reda Sallahi To: qemu-devel@nongnu.org Date: Mon, 22 Aug 2016 09:55:15 +0200 Message-Id: <20160822075517.5859-6-fullmanet@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160822075517.5859-1-fullmanet@gmail.com> References: <20160822075517.5859-1-fullmanet@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 5/7] qemu-img: add status option to dd 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 , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Reda Sallahi , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the status option to the subcommand dd. With this dd will display by default the number of blocks read/written, the transfer rate, etc. like dd(1). The noxfer and none levels will allow the user to surpress the final transfer statistics and everything except error messages respectively. A test case was added to test the status option. Signed-off-by: Reda Sallahi --- qemu-img-cmds.hx | 4 +-- qemu-img.c | 90 ++++++++++++++++++++++++++++++++++++++++++---- qemu-img.texi | 9 ++++- tests/qemu-iotests/159 | 2 +- tests/qemu-iotests/160 | 2 +- tests/qemu-iotests/161 | 2 +- tests/qemu-iotests/163 | 4 +-- tests/qemu-iotests/164 | 4 +-- tests/qemu-iotests/165 | 11 +++--- tests/qemu-iotests/166 | 2 +- tests/qemu-iotests/167 | 77 +++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/167.out | 17 +++++++++ tests/qemu-iotests/group | 1 + 13 files changed, 202 insertions(+), 23 deletions(-) create mode 100755 tests/qemu-iotests/167 create mode 100644 tests/qemu-iotests/167.out diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 933ce3c..6315c64 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -46,9 +46,9 @@ STEXI ETEXI DEF("dd", img_dd, - "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [seek=blocks] [conv=convs] [iflag=flags] [oflag=flags] if=input of=output") + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [seek=blocks] [conv=convs] [iflag=flags] [oflag=flags] [status=level] if=input of=output") STEXI - @item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] if=@var{input} of=@var{output} + @item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] [status=@var{level}] if=@var{input} of=@var{output} ETEXI DEF("info", img_info, diff --git a/qemu-img.c b/qemu-img.c index cf78dfe..00b15c5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -178,7 +178,11 @@ static void QEMU_NORETURN help(void) " 'seek=N' seek N bs-sized blocks at the start of output\n" " 'conv=CONVS' do not truncate the output file\n" " 'iflags=FLAGS' read using the comma-separated flags list\n" - " 'oflags=FLAGS' read using the comma-separated flags list\n\n" + " 'oflags=FLAGS' read using the comma-separated flags list\n" + " 'status=LEVEL' the LEVEL of information to print to stderr\n\n" + "List of LEVELS for dd:\n" + " 'none' surpresses everything but error messages\n" + " 'noxfer' surpresses the final transfer statistics\n\n" "List of CONVS for dd:\n" " 'notrunc' do not truncate the output file\n" " 'noerror' continue in the event of read errors\n" @@ -3832,11 +3836,13 @@ out: #define C_CONV 0100 #define C_IFLAG 0200 #define C_OFLAG 0400 +#define C_STATUS 01000 struct DdInfo { unsigned int flags; int64_t count; unsigned int conv; + unsigned status; }; struct DdIo { @@ -4077,6 +4083,31 @@ static int img_dd_oflag(const char *arg, return ret; } +#define C_STATUS_DEFAULT 00 +#define C_STATUS_NONE 01 +#define C_STATUS_NOXFER 02 + +static int img_dd_status(const char *arg, + struct DdIo *in, struct DdIo *out, + struct DdInfo *dd) +{ + const struct DdSymbols dd_status[] = { + { "none", C_STATUS_NONE }, + { "noxfer", C_STATUS_NOXFER }, + { NULL, 0 } + }; + + for (int j = 0; dd_status[j].name != NULL; j++) { + if (!strcmp(arg, dd_status[j].name)) { + dd->status = dd_status[j].value; + return 0; + } + } + + error_report("invalid status level: '%s'", arg); + return 1; +} + static int img_dd(int argc, char **argv) { int ret = 0; @@ -4094,13 +4125,16 @@ static int img_dd(int argc, char **argv) const char *fmt = NULL; int64_t size = 0, out_size = 0; int64_t out_pos, in_pos, sparse_count = 0; + int64_t in_read = 0, out_wrt = 0; /* Read/write count for status= */ bool writethrough = false; int flags = 0; int ibsz = 0, obsz = 0, bsz; + struct timeval starttv, endtv; struct DdInfo dd = { .flags = 0, .count = 0, - .conv = 0 + .conv = 0, + .status = C_STATUS_DEFAULT }; struct DdIo in = { .bsz = 512, /* Block size is by default 512 bytes */ @@ -4127,6 +4161,7 @@ static int img_dd(int argc, char **argv) { "conv", img_dd_conv, C_CONV }, { "iflag", img_dd_iflag, C_IFLAG }, { "oflag", img_dd_oflag, C_OFLAG }, + { "status", img_dd_status, C_STATUS }, { NULL, NULL, 0 } }; const struct option long_options[] = { @@ -4374,16 +4409,21 @@ static int img_dd(int argc, char **argv) } if (in.offset > INT64_MAX / ibsz || size < in.offset * ibsz) { - /* We give a warning if the skip option is bigger than the input - * size and create an empty output disk image (i.e. like dd(1)). - */ - error_report("%s: cannot skip to specified offset", in.filename); - in_pos = size; + if (!(dd.status & C_STATUS_NONE)) { + /* We give a warning if the skip option is bigger than the input + * size and create an empty output disk image (i.e. like dd(1)). + */ + error_report("%s: cannot skip to specified offset", in.filename); + in_pos = size; + } } else { in_pos = in.offset * ibsz; } in.buf = g_new(uint8_t, in.bsz); + if (dd.status & C_STATUS_DEFAULT) { + gettimeofday(&starttv, NULL); + } for (out_pos = out.offset * obsz; in_pos < size;) { int in_ret, out_ret; @@ -4412,10 +4452,12 @@ static int img_dd(int argc, char **argv) in_ret = bsz; } in_pos += in_ret; + in_read += in_ret; if (dd.conv & C_SPARSE) { if (buffer_is_zero(in.buf, bsz)) { sparse_count++; + out_wrt += bsz; continue; } if (sparse_count > 0) { @@ -4433,12 +4475,46 @@ static int img_dd(int argc, char **argv) goto out; } out_pos += out_ret; + out_wrt += out_ret; } if (dd.conv & C_FDATASYNC || dd.conv & C_FSYNC) { blk_flush(blk2); } + if (dd.status & C_STATUS_NOXFER || dd.status & C_STATUS_DEFAULT) { + fprintf(stderr, "%" PRId64 "+%" PRId64 " records in\n", + in_read / in.bsz, in_read % in.bsz); + fprintf(stderr, "%" PRId64 "+%" PRId64 " records out\n", + out_wrt / out.bsz, out_wrt % out.bsz); + } + if (dd.status & C_STATUS_DEFAULT) { + gchar *hsize; + double nb_microsec; + + gettimeofday(&endtv, NULL); + timersub(&endtv, &starttv, &endtv); + + if (out_wrt >= 1024) { + /* human-readable size in IEC format (base 1024) */ + gchar *iecsize = g_format_size_full(out_wrt, + G_FORMAT_SIZE_IEC_UNITS); + /* Standard base (e.g. KB = 1000 bytes) */ + hsize = g_format_size(out_wrt); + fprintf(stderr, "%" PRId64 " bytes (%s, %s) copied, ", out_wrt, + hsize, iecsize); + g_free(hsize); + g_free(iecsize); + } else { + fprintf(stderr, "%" PRId64 " copied, ", out_wrt); + } + nb_microsec = (double)endtv.tv_sec * 1000000 + endtv.tv_usec; + hsize = g_format_size((double)out_wrt * 1000000 / nb_microsec); + fprintf(stderr, "%ld.%08ld s, %s/s\n", (long)endtv.tv_sec, + (long)endtv.tv_usec, hsize); + g_free(hsize); + } + out: g_free(arg); qemu_opts_del(opts); diff --git a/qemu-img.texi b/qemu-img.texi index 85c3cd3..c8905c6 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -202,6 +202,13 @@ interpret 'skip=blocks' as a byte count. Only iflag. @item seek_bytes interpret 'seek=blocks' as a byte count. Only oflag. +@item status=@var{level} +Define the level of information to print to stderr. +@item none +Only error messages are printed. +@item noxfer +Do not print the final transfer rate. + @end table Command description: @@ -375,7 +382,7 @@ skipped. This is useful for formats such as @code{rbd} if the target volume has already been created with site specific options that cannot be supplied through qemu-img. -@item dd [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] if=@var{input} of=@var{output} +@item dd [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] [status=@var{level}] if=@var{input} of=@var{output} Dd copies from @var{input} file to @var{output} file converting it from @var{fmt} format to @var{output_fmt} format. diff --git a/tests/qemu-iotests/159 b/tests/qemu-iotests/159 index d68a19f..55f5242 100755 --- a/tests/qemu-iotests/159 +++ b/tests/qemu-iotests/159 @@ -56,7 +56,7 @@ for bs in $TEST_SIZES; do echo "== Converting the image with dd with a block size of $bs ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" bs=$bs conv=notrunc \ - -O "$IMGFMT" + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img echo diff --git a/tests/qemu-iotests/160 b/tests/qemu-iotests/160 index 53b3c30..d59228c 100755 --- a/tests/qemu-iotests/160 +++ b/tests/qemu-iotests/160 @@ -56,7 +56,7 @@ for skip in $TEST_SKIP_BLOCKS; do echo "== Converting the image with dd with skip=$skip ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" conv=notrunc \ - -O "$IMGFMT" 2> /dev/null + -O "$IMGFMT" 2> /dev/null status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" conv=notrunc \ status=none diff --git a/tests/qemu-iotests/161 b/tests/qemu-iotests/161 index bc99102..27376d3 100755 --- a/tests/qemu-iotests/161 +++ b/tests/qemu-iotests/161 @@ -56,7 +56,7 @@ for seek in $TEST_SEEK_BLOCKS; do echo "== Converting the image with dd with seek=$seek ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" seek="$seek" conv=notrunc \ - -O "$IMGFMT" 2> /dev/null + -O "$IMGFMT" 2> /dev/null status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" seek="$seek" conv=notrunc \ status=none diff --git a/tests/qemu-iotests/163 b/tests/qemu-iotests/163 index e236ea4..00ebcfa 100755 --- a/tests/qemu-iotests/163 +++ b/tests/qemu-iotests/163 @@ -58,7 +58,7 @@ for skip in $TEST_SKIP_BLOCKS; do echo "== Converting the image with dd with skip=$skip iflag=skip_bytes ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" \ - iflag=skip_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + iflag=skip_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" iflag=skip_bytes \ conv=notrunc status=none @@ -86,7 +86,7 @@ for count in $TEST_COUNT_BLOCKS; do "iflag=count_bytes ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" count="$skip" \ - iflag=count_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + iflag=count_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" count="$skip" iflag=count_bytes \ conv=notrunc status=none diff --git a/tests/qemu-iotests/164 b/tests/qemu-iotests/164 index 4cc69c2..62ee766 100755 --- a/tests/qemu-iotests/164 +++ b/tests/qemu-iotests/164 @@ -57,7 +57,7 @@ for seek in $TEST_SEEK_BLOCKS; do echo "== Converting the image with dd with seek=$seek oflag=seek_bytes ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" seek="$seek" \ - oflag=seek_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + oflag=seek_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" seek="$seek" \ oflag=seek_bytes status=none @@ -83,7 +83,7 @@ echo "== Converting the image with dd with seek=$seek" \ "oflag=seek_bytes,direct ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" seek="$seek" \ - oflag=seek_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + oflag=seek_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" seek="$seek" \ oflag=seek_bytes,direct conv=notrunc status=none diff --git a/tests/qemu-iotests/165 b/tests/qemu-iotests/165 index 749920d..b077322 100755 --- a/tests/qemu-iotests/165 +++ b/tests/qemu-iotests/165 @@ -53,7 +53,8 @@ $QEMU_IO -c "write -P 0xa 215k 212k" "$TEST_IMG" | _filter_qemu_io echo echo "== Converting the image with dd with conv=excl ==" -$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc -O "$IMGFMT" +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc \ + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img @@ -67,7 +68,7 @@ $QEMU_IMG compare "$TEST_IMG.out.dd" "$TEST_IMG.out" echo echo "== Converting the image with dd with conv=excl ==" -$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc \ +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc status=none \ -O "$IMGFMT" 2>&1 | sed -e "s#$TEST_DIR#TEST_DIR#g" \ -e "s#$IMGFMT#IMGFMT#g" @@ -83,7 +84,7 @@ echo echo "== Converting the image with dd with conv=nocreat ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=nocreat,notrunc \ - -O "$IMGFMT" + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img @@ -100,8 +101,8 @@ echo echo "== Converting the image with dd with conv=nocreat ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=nocreat,notrunc \ - -O "$IMGFMT" 2>&1 | sed -e "s#$TEST_DIR#TEST_DIR#g" \ - -e "s#$IMGFMT#IMGFMT#g" + -O "$IMGFMT" 2>&1 status=none | sed -e "s#$TEST_DIR#TEST_DIR#g" \ + -e "s#$IMGFMT#IMGFMT#g" echo echo "*** done" diff --git a/tests/qemu-iotests/166 b/tests/qemu-iotests/166 index 409ffa8..4e434f2 100755 --- a/tests/qemu-iotests/166 +++ b/tests/qemu-iotests/166 @@ -56,7 +56,7 @@ echo echo "== Converting the image with dd with conv=sparse ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=sparse,notrunc \ - -O "$IMGFMT" + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img diff --git a/tests/qemu-iotests/167 b/tests/qemu-iotests/167 new file mode 100755 index 0000000..ccfd441 --- /dev/null +++ b/tests/qemu-iotests/167 @@ -0,0 +1,77 @@ +#! /bin/bash +# +# qemu-img dd test for the status option +# +# Copyright (C) 2016 Reda Sallahi +# +# 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 . +# + +owner=fullmanet@gmail.com + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +status=1 + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.out" "$TEST_IMG.out.stat" "$TEST_IMG.out.dd" \ + "$TEST_IMG.out.dd.stat" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +echo +echo "== Creating image ==" + +size=1M +_make_test_img $size +_check_test_img + +$QEMU_IO -c "write -P 0xa 149k 512k" "$TEST_IMG" | _filter_qemu_io + +echo +echo "== Converting the image with dd status=noxfer ==" + +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=notrunc -O "$IMGFMT" \ + status=noxfer 2> "$TEST_IMG.out.stat" +TEST_IMG="$TEST_IMG.out" _check_test_img + +dd if="$TEST_IMG" of="$TEST_IMG.out.dd" conv=notrunc status=noxfer \ + 2> "$TEST_IMG.out.dd.stat" + +echo +echo "== Compare the images with qemu-img compare ==" + +$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.out" + +echo +echo "== Compare the stat output ==" + +diff "$TEST_IMG.out.dd.stat" "$TEST_IMG.out.stat" + +echo +echo "*** done" +rm -f "$seq.full" +status=0 diff --git a/tests/qemu-iotests/167.out b/tests/qemu-iotests/167.out new file mode 100644 index 0000000..39aad10 --- /dev/null +++ b/tests/qemu-iotests/167.out @@ -0,0 +1,17 @@ +QA output created by 167 + +== Creating image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +No errors were found on the image. +wrote 524288/524288 bytes at offset 152576 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== Converting the image with dd status=noxfer == +No errors were found on the image. + +== Compare the images with qemu-img compare == +Images are identical. + +== Compare the stat output == + +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 9ba23e5..fbe0ffe 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -166,3 +166,4 @@ 164 rw auto quick 165 rw auto quick 166 rw auto quick +167 rw auto quick