From patchwork Tue Apr 9 14:56:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 10891403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D6A3139A for ; Tue, 9 Apr 2019 14:57:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 294D8279E0 for ; Tue, 9 Apr 2019 14:57:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CE07288C3; Tue, 9 Apr 2019 14:57:34 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 84F56279E0 for ; Tue, 9 Apr 2019 14:57:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:42851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDsBo-0002aZ-Tn for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Apr 2019 10:57:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDsAv-0001us-Tg for qemu-devel@nongnu.org; Tue, 09 Apr 2019 10:56:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDsAu-0006mN-NM for qemu-devel@nongnu.org; Tue, 09 Apr 2019 10:56:37 -0400 Received: from relay.sw.ru ([185.231.240.75]:39716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDsAu-0006lJ-BP; Tue, 09 Apr 2019 10:56:36 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hDsAr-0007rL-4N; Tue, 09 Apr 2019 17:56:33 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 9 Apr 2019 17:56:31 +0300 Message-Id: <1554821792-968307-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1554821792-968307-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1554821792-968307-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/2] qemu-img convert: ignore read errors 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, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The 'qemu-img convert' new command option 'force read' with the key '-R' allows converting a damaged image to get all the available information in case of the read errors. The program reports read errors and continue the image conversion. The users should keep in their minds that the resulting image is inconsistent. Suggested-by: Denis V. Lunev Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 18 ++++++++++++++++-- qemu-img.texi | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 1526f32..09af9cb 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -44,9 +44,9 @@ STEXI ETEXI DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [-U] [-R] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename") STEXI -@item convert [--object @var{objectdef}] [--image-opts] [--target-image-opts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [--object @var{objectdef}] [--image-opts] [--target-image-opts] [-U] [-R] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI DEF("create", img_create, diff --git a/qemu-img.c b/qemu-img.c index aa6f81f..494e880 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -175,6 +175,7 @@ static void QEMU_NORETURN help(void) "Parameters to convert subcommand:\n" " '-m' specifies how many coroutines work in parallel during the convert\n" " process (defaults to 8)\n" + " '-R' continue the image conversion in case of the sector read error\n" " '-W' allow to write to the target out of order rather than sequential\n" "\n" "Parameters to snapshot subcommand:\n" @@ -1579,6 +1580,7 @@ typedef struct ImgConvertState { int64_t wait_sector_num[MAX_COROUTINES]; CoMutex lock; int ret; + bool force_read; } ImgConvertState; static void convert_select_part(ImgConvertState *s, int64_t sector_num, @@ -1693,7 +1695,15 @@ static int coroutine_fn convert_co_read(ImgConvertState *s, int64_t sector_num, blk, (sector_num - src_cur_offset) << BDRV_SECTOR_BITS, n << BDRV_SECTOR_BITS, &qiov, 0); if (ret < 0) { - return ret; + if (!s->force_read) { + return ret; + } + int64_t offset = (sector_num - src_cur_offset) << BDRV_SECTOR_BITS; + unsigned int bytes = n << BDRV_SECTOR_BITS; + error_report("failed to read %d bytes at offset %" PRId64 ": %s", + bytes, offset, strerror(-ret)); + memset(buf, 0, n * BDRV_SECTOR_SIZE); + /* TODO: retry to read smaller chunks */ } sector_num += n; @@ -2018,6 +2028,7 @@ static int img_convert(int argc, char **argv) .buf_sectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE, .wr_in_order = true, .num_coroutines = 8, + .force_read = false, }; for(;;) { @@ -2029,7 +2040,7 @@ static int img_convert(int argc, char **argv) {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU", + c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:RWU", long_options, NULL); if (c == -1) { break; @@ -2132,6 +2143,9 @@ static int img_convert(int argc, char **argv) case 'U': force_share = true; break; + case 'R': + s.force_read = true; + break; case OPTION_OBJECT: { QemuOpts *object_opts; object_opts = qemu_opts_parse_noisily(&qemu_object_opts, diff --git a/qemu-img.texi b/qemu-img.texi index 3b6710a..94f7d80 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -325,7 +325,7 @@ Error on reading data @end table -@item convert [--object @var{objectdef}] [--image-opts] [--target-image-opts] [-U] [-C] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [--object @var{objectdef}] [--image-opts] [--target-image-opts] [-U] [-R] [-C] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename} Convert the disk image @var{filename} or a snapshot @var{snapshot_param} to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c}