From patchwork Thu Aug 11 09:31:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reda Sallahi X-Patchwork-Id: 9274801 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 19BF860231 for ; Thu, 11 Aug 2016 09:31:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06BB5285B5 for ; Thu, 11 Aug 2016 09:31:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFA52285B8; Thu, 11 Aug 2016 09:31:40 +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 5881F285B5 for ; Thu, 11 Aug 2016 09:31:40 +0000 (UTC) Received: from localhost ([::1]:47109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXmKw-00013X-VT for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Aug 2016 05:31:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXmKf-00013C-9U for qemu-devel@nongnu.org; Thu, 11 Aug 2016 05:31:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXmKc-0001JJ-0f for qemu-devel@nongnu.org; Thu, 11 Aug 2016 05:31:21 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXmKb-0001JD-MF; Thu, 11 Aug 2016 05:31:17 -0400 Received: by mail-wm0-x242.google.com with SMTP id i5so238400wmg.2; Thu, 11 Aug 2016 02:31:17 -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; bh=1/RqrKXxejUD9vXeEfP1FeyWSLjDopBZjRGTV4I9Z1o=; b=CYKDtxxK4BCEEvDwpx1jDgIy0cq1aqrwLTW0/pIVoUyLUhAfZPZTtwNuf/C9lOwefv DVBcyF8a1eiujHd4MU/0TbG+zcNqfp+PCtfR9e1aXUZeUA7JGSzkUbYrV4VaYUvT4JUp 85ex/UWWvzAg54wyQE1HfQ3gzsWpiB+byIAE1uq+XCIe0Lc4eGLwXIZUPi+YOcu+2BB+ hXmrkYYhOqJwJWQLiNwCNn47TALbVKxRHqix4jROrS9kh7lny6mZ1CVEWq9uLApeRld3 VwhYYzTPd+WIdIdRIa03aAZxt3H6jsUQ8U7sPotOvZMAVDSyc6ajT6NGKqjNMkCt5Mb0 n/jA== 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; bh=1/RqrKXxejUD9vXeEfP1FeyWSLjDopBZjRGTV4I9Z1o=; b=jowLsrdU0pxRmuXlPpDHbvhdeah942wQVxPvrGvDU2yJsXQhdCD7BnWQBK2ikpfOUs MU7ZvcavZqkBY0bGoRxhH/n8pIHvciHExOrmCygBVJtTNG2NFWS2xCCybGrAVTGUsbMJ w/qYlR4dIhBzhNblQX8GFvqJEzEXPvUCQ8DJN07LZVjN7ioCjNeibaJG9V7RJ70FW5P3 /91VmO3yQQ0K0iluWx431yb9X4Ta8jns0UN5hJYvVa79MPdtTbYopRgksyEn6CoA2llx RXJUWADxal73/VqhO6hGxM6R07wzdhJebzW88f7Ec5/9wqgiMDNTS6A+lRos+qSbLBkh ZF5g== X-Gm-Message-State: AEkoousNRXGpE1uke9QIz0DR/69CTZij4N9uYr3nMeNMaxk559Li/tDddJTyzAremY4akQ== X-Received: by 10.28.71.197 with SMTP id m66mr8351918wmi.26.1470907876865; Thu, 11 Aug 2016 02:31:16 -0700 (PDT) Received: from localhost.localdomain (ram94-2-82-66-69-246.fbx.proxad.net. [82.66.69.246]) by smtp.gmail.com with ESMTPSA id vv2sm1750502wjc.29.2016.08.11.02.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 02:31:16 -0700 (PDT) From: Reda Sallahi To: qemu-devel@nongnu.org Date: Thu, 11 Aug 2016 11:31:05 +0200 Message-Id: <20160811093105.7606-1-fullmanet@gmail.com> X-Mailer: git-send-email 2.9.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH v3] qemu-img: add conv=notrunc 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 adds the conv=notrunc option to dd which tells dd to not truncate the output. Signed-off-by: Reda Sallahi Reviewed-by: Fam Zheng --- Depends on: [PATCH v5] qemu-img: add skip option to dd Changes from v2: * Delete the mandatory conv=notrunc Changes from v1: * Added comment qemu-img-cmds.hx | 4 ++-- qemu-img.c | 22 +++++++++++++++++++++- qemu-img.texi | 7 +++++-- tests/qemu-iotests/158 | 2 +- tests/qemu-iotests/159 | 3 ++- tests/qemu-iotests/160 | 7 ++++--- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index f054599..18685ac 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] if=input of=output") + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [conv=notrunc] 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}] 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}] [conv=notrunc] if=@var{input} of=@var{output} ETEXI DEF("info", img_info, diff --git a/qemu-img.c b/qemu-img.c index 3adec86..d08905b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -174,7 +174,8 @@ static void QEMU_NORETURN help(void) " 'count=N' copy only N input blocks\n" " 'if=FILE' read from FILE\n" " 'of=FILE' write to FILE\n" - " 'skip=N' skip N bs-sized blocks at the start of input\n"; + " 'skip=N' skip N bs-sized blocks at the start of input\n" + " 'conv=notrunc' do not truncate the output file\n"; printf("%s\nSupported formats:", help_msg); bdrv_iterate_format(format_print, NULL); @@ -3807,10 +3808,12 @@ out: #define C_IF 04 #define C_OF 010 #define C_SKIP 020 +#define C_CONV 040 struct DdInfo { unsigned int flags; int64_t count; + unsigned int conv; }; struct DdIo { @@ -3894,6 +3897,21 @@ static int img_dd_skip(const char *arg, return 0; } +#define C_NOTRUNC 01 + +static int img_dd_conv(const char *arg, + struct DdIo *in, struct DdIo *out, + struct DdInfo *dd) +{ + if (!strcmp(arg, "notrunc")) { + dd->conv |= C_NOTRUNC; + return 0; + } else { + error_report("invalid conversion: '%s'", arg); + return 1; + } +} + static int img_dd(int argc, char **argv) { int ret = 0; @@ -3913,6 +3931,7 @@ static int img_dd(int argc, char **argv) struct DdInfo dd = { .flags = 0, .count = 0, + .conv = 0 }; struct DdIo in = { .bsz = 512, /* Block size is by default 512 bytes */ @@ -3933,6 +3952,7 @@ static int img_dd(int argc, char **argv) { "if", img_dd_if, C_IF }, { "of", img_dd_of, C_OF }, { "skip", img_dd_skip, C_SKIP }, + { "conv", img_dd_conv, C_CONV }, { NULL, NULL, 0 } }; const struct option long_options[] = { diff --git a/qemu-img.texi b/qemu-img.texi index 174aae3..002dde2 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -150,9 +150,12 @@ sets the number of input blocks to copy @item if=@var{input} sets the input file @item of=@var{output} -sets the output file +sets the output file. dd truncates the output file to zero if 'conv=notrunc' +is not specified. @item skip=@var{blocks} sets the number of input blocks to skip +@item conv=notrunc +makes dd not truncate output file to zero @end table Command description: @@ -326,7 +329,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}] 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}] [conv=notrunc] 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/158 b/tests/qemu-iotests/158 index 5b335db..63e2a10 100755 --- a/tests/qemu-iotests/158 +++ b/tests/qemu-iotests/158 @@ -53,7 +53,7 @@ $QEMU_IO -c "write -P 0xa 0 $size" "$TEST_IMG" | _filter_qemu_io echo echo "== Converting the image with dd ==" -$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" -O "$IMGFMT" +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=notrunc -O "$IMGFMT" TEST_IMG="$TEST_IMG.out" _check_test_img echo diff --git a/tests/qemu-iotests/159 b/tests/qemu-iotests/159 index 825f05f..d68a19f 100755 --- a/tests/qemu-iotests/159 +++ b/tests/qemu-iotests/159 @@ -55,7 +55,8 @@ for bs in $TEST_SIZES; do echo echo "== Converting the image with dd with a block size of $bs ==" - $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" bs=$bs -O "$IMGFMT" + $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" bs=$bs conv=notrunc \ + -O "$IMGFMT" TEST_IMG="$TEST_IMG.out" _check_test_img echo diff --git a/tests/qemu-iotests/160 b/tests/qemu-iotests/160 index 5c910e5..53b3c30 100755 --- a/tests/qemu-iotests/160 +++ b/tests/qemu-iotests/160 @@ -55,10 +55,11 @@ for skip in $TEST_SKIP_BLOCKS; do echo echo "== Converting the image with dd with skip=$skip ==" - $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" -O "$IMGFMT" \ - 2> /dev/null + $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" conv=notrunc \ + -O "$IMGFMT" 2> /dev/null TEST_IMG="$TEST_IMG.out" _check_test_img - dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" status=none + dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" conv=notrunc \ + status=none echo echo "== Compare the images with qemu-img compare =="