From patchwork Fri Apr 21 10:04:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9693271 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 6BC076038D for ; Fri, 21 Apr 2017 17:39:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F22928655 for ; Fri, 21 Apr 2017 17:39:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53D6D2865C; Fri, 21 Apr 2017 17:39:21 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, 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 829F528655 for ; Fri, 21 Apr 2017 17:39:20 +0000 (UTC) Received: from localhost ([::1]:60772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1cWd-0000Av-SE for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Apr 2017 13:39:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1cVq-0008Sj-GH for qemu-devel@nongnu.org; Fri, 21 Apr 2017 13:38:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1cVl-0005z8-Im for qemu-devel@nongnu.org; Fri, 21 Apr 2017 13:38:30 -0400 Received: from mail-db5eur01on0119.outbound.protection.outlook.com ([104.47.2.119]:25600 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1cVk-0005yh-TU; Fri, 21 Apr 2017 13:38:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xzybHQLorhh2gae+Ypjnl8fO7jihOQsPofP7CV+ZGFo=; b=VDntMTiEUN5LRh+C2f6Yenb0xhmeGwk68HHkr3uXtiQ+NaSNySXspJKd1v87+bZBkwu6qJURrXb6JDe1RUErwRjEcLX6aZMpNzrV9uyp1K+pqmIFTQJufGOOuWR47KclHak5pXeS7qgqS9Q1Od/aPee5YY4lVaOLh/+y4lApZ1k= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB1998.eurprd08.prod.outlook.com (10.173.74.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Fri, 21 Apr 2017 10:04:46 +0000 From: Anton Nefedov To: Date: Fri, 21 Apr 2017 13:04:36 +0300 Message-ID: <1492769076-64466-1-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1P18901CA0007.EURP189.PROD.OUTLOOK.COM (10.173.66.145) To VI1PR0801MB1998.eurprd08.prod.outlook.com (10.173.74.19) X-MS-Office365-Filtering-Correlation-Id: 6ca6fcaa-54e3-4e80-f395-08d4889dd734 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133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Hvm38/lAcjjtXPZvSbIStlMUAc3+Y9AROBgQWOpk8jOkXZyhu78e0wse34xCwNMT3giQmzDL4vbX2C+F3hFKeN47rAdSoEGxbTlpOnAYpoXR; 20:bHXzfq3wYDj7SH7cd/OLhBHxNk6RS/5SH2A1ETMBuVAbgZOcCP0l7AwLVQNkp+l+1biqE88R0NKnkOB4EFZ/+lJHL5bCfGAeYlFoQE5qlE7261pHzNASC3jxweYlijabg+4Eg35RnOHRUjx+4zmiRon5VceejJwqWOUbsLwtTadnUIwboSTt6RjP53tzRHZfsU31UgNMpNK0pLtv3znY2/eDFmc44R4Pg/QsLAk5DHu/hdkXg7FCdNwXkGTy76XFJGMbuZDlX64Ykw6k1TgYruzq0/SK8PPI7UxZA2fX/i2wS9DJ6q3fDlzE1RL1aWUrgsp3L4QLDNaTbvzA9zUiQ1Z+d8e0TnwkcSG5bY+8khcaMymMrTOxYqF4/L14QZ16ecMxhr0yJ+5Nhpls+AahANkz0PrseytTchmUYKCYdCI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(6041248)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123555025)(6072148); SRVR:VI1PR0801MB1998; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1998; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1998; 4:MZN6znUJXQaVfcy68jRSXR+Gvw92DSOk6c+U9lhKBWEEa2aMALh8xTm/2ZvlPw0Iv/TinR8oAZ1OSHr/0Huku29tuy/541JdR6PGOgr0DoUUWrCveGwDUKiQ05CBXhHCPsyHi+9IaPV1MRMz7n9y27OgM0BU8ImJRPaX+YsMUrOrSHlSSbZshyG9iig4HBJJ/0vB3zRSVPvxfMeXvS+n+8jKJJXVsh2FedsQXWJxzu9jg1/RaxA9fkiZsV4uy9pNlHDTfPu3etjfS3jmAmb6qe1LMcaxGwEs6ci8XEMuaPL5jgO/Mqd5M9bB1G13PLeoVD6VOIDrod0AAKOBMuf7Arjg1awk59TjgHYwuHZsg5LwAv07F9YWCL4YGR+mC3Qs9drT8qk/EBUz8XyeKbVuHolfe2JFPEpiU4TH9/uzXL7NRsByqxGba7zzSOaXpgCF1euHYAFUAALYndvBxY6VYomBeCUL0P0sGKGCxzPgtFz3+SElNby4YsTm27zjCORVNZIO9VC6SOuzdE4DG3i2QqwKecTk+qXYnLguxGcj5GCqyCa4Zd079f+Rs3ldxzt0DmNCQzYXgze8qbu9mahH4q61p4atMqFgfG9ZvLdzAxbt5wNQfR/UJI0ryOtLBk2WGfV0h/EXxjD7OuTFSXmYfoP7P6UTVc7u6tcAt1F8EGJ5cbjxW2vqK/Ftyl+whreNAvZ6dUDg76VxxVrNPW1MvQ== X-Forefront-PRVS: 02843AA9E0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39840400002)(39400400002)(39410400002)(39450400003)(6666003)(86362001)(42186005)(50466002)(36756003)(66066001)(305945005)(53416004)(7736002)(6916009)(4326008)(6512007)(25786009)(8676002)(189998001)(5660300001)(38730400002)(50986999)(6486002)(110136004)(33646002)(6116002)(107886003)(2351001)(2906002)(81166006)(47776003)(5003940100001)(6506006)(3846002)(54906002)(53936002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1998; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1998; 23:yk6nn5zlXLhsHRZLVDyGWvQef5ImaLNNVYkOMxR?= =?us-ascii?Q?xwtCdm4bdY639CFWdKiXQmWzwmbzIipIBuGJenAOzKoAwgE1JXcLK0bc4du6?= =?us-ascii?Q?r+08b7CNVRvG9DwBM4jpGRj3SBaWdYmEP3m17d8FKHR8QvtRb9j6hnX+ngha?= =?us-ascii?Q?GqsH+YmaglbKTenKqzG/RHtUj2P0dYgCAP5k6bM9tagHta79gvYQ7Cr234OL?= =?us-ascii?Q?oZUg2PGELsi682EuP65kgZSDETSQm+yJz5Om7DIQF2dZqjH+z8VoDueWzo0W?= =?us-ascii?Q?JrnK7ikzC7nuXMNM1Bz+RlivdtE0vqd8G2AP1asofJDw+ULl0Y+KXc9utkeE?= =?us-ascii?Q?ayD5vDa6F5+f+fuqt4Swg6ic+Uqcc6TPwpuIbmEuGHf+QJhFYj+PUgT8fqSB?= =?us-ascii?Q?YhJylp5pr5vNP47sWXseiREI4owu4qGgL0s1digzZTGieT7D6/X3wcfOXy4Y?= =?us-ascii?Q?YRaX8aaOCMI6fiKAzf2CjUS1lBqiRxb6NKNa2ry4d2KFNIxH9qihgHHT2kqF?= =?us-ascii?Q?89B7Lm60Quyw1PFquz1PwqlrH2hNY1vYqvX9BrJPjcu2bBktYli8s5Bk16UI?= =?us-ascii?Q?am4WkJyIpn6S7KlerQKIboHnze+lPvLFxI3v76W3MU0OOLBV26tlPKjZ1UZb?= =?us-ascii?Q?iTTVjd6rnl5PUKnUWpvLegT5LVscfX+0ovTp/U3DP2sCdNXO+SSp6xVpqY4v?= =?us-ascii?Q?U3ruDtMixfGatiKDiOIPWAfV3k4I7aBX41tqzm1MXFFD2tyxYieXewkYirt8?= =?us-ascii?Q?dNaQLzJjhig3klZkYtwUANe/Gb0B33cytepDnWqBuJOJV0RJghvhVETGz7eo?= =?us-ascii?Q?nKzzHcaK/J5KV3riUnQYvyrWC7y1xyXc7DOKtB1Si00Zn99y9wPH9Az2wg/R?= =?us-ascii?Q?TVI9ZHPnLbqSXC9PftbSZ6QyKXWhdCVmQbQFSGgV5FWZRGKXln6V4Cw9autb?= =?us-ascii?Q?q+z95U/Dn7alo0/giu5dPXSzDb/uY3SiO9C64I6xw2A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1998; 6:TSs0Ixju9efvq2KravPoxUF/41JpJiMf+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BZTZtrdZexSNZEAIDnWyC13LlgAASEvsppGacuduKbOa3hA4oD9kvMr0MUMxcpe6gsI+aYRK9CDcxNLIRUtyWvGptdgwfAYYunFc4S9sngcnYrBAhsb5XPuMOw==; 20:7oeXuXdQufkqU/PkKdTmBMYZRBFNBBqSiErqtlPGD7rAARQ/osbmBNYhV+waGhAuG1kJolLqlvr4q+AJgSZ1soeYmDvtdzkOJZ9p5DIh1YekAvFIdtAcfSQTchAMcP7qSA07ABTmP9SM29oaKS9/4kT3iJ3D4wEcsuVYeFJgRFE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2017 10:04:46.1451 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1998 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.119 Subject: [Qemu-devel] [PATCH v2 1/1] qemu-img: wait for convert coroutines to complete 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, Anton Nefedov , den@virtuozzo.com, qemu-block@nongnu.org, pl@kamp.de, qemu-stable@nongnu.org, 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 On error path (like i/o error in one of the coroutines), it's required to - wait for coroutines completion before cleaning the common structures - reenter dependent coroutines so they ever finish Introduced in 2d9187bc65. Signed-off-by: Anton Nefedov --- qemu-img.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b220cf7..24950c1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1735,6 +1735,27 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num, return 0; } +static void coroutine_fn convert_reenter_waiting(ImgConvertState *s, + uint64_t wr_offs) +{ + int i; + if (s->wr_in_order) { + /* reenter the coroutine that might have waited + * for the write to complete */ + for (i = 0; i < s->num_coroutines; i++) { + if (s->co[i] && s->wait_sector_num[i] == wr_offs) { + /* + * A -> B -> A cannot occur because A has + * s->wait_sector_num[i] == -1 during A -> B. Therefore + * B will never enter A during this time window. + */ + qemu_coroutine_enter(s->co[i]); + break; + } + } + } +} + static void coroutine_fn convert_co_do_copy(void *opaque) { ImgConvertState *s = opaque; @@ -1792,6 +1813,7 @@ static void coroutine_fn convert_co_do_copy(void *opaque) error_report("error while reading sector %" PRId64 ": %s", sector_num, strerror(-ret)); s->ret = ret; + convert_reenter_waiting(s, sector_num + n); goto out; } } else if (!s->min_sparse && status == BLK_ZERO) { @@ -1803,6 +1825,7 @@ static void coroutine_fn convert_co_do_copy(void *opaque) /* keep writes in order */ while (s->wr_offs != sector_num) { if (s->ret != -EINPROGRESS) { + convert_reenter_waiting(s, sector_num + n); goto out; } s->wait_sector_num[index] = sector_num; @@ -1816,25 +1839,12 @@ static void coroutine_fn convert_co_do_copy(void *opaque) error_report("error while writing sector %" PRId64 ": %s", sector_num, strerror(-ret)); s->ret = ret; + convert_reenter_waiting(s, sector_num + n); goto out; } - if (s->wr_in_order) { - /* reenter the coroutine that might have waited - * for this write to complete */ - s->wr_offs = sector_num + n; - for (i = 0; i < s->num_coroutines; i++) { - if (s->co[i] && s->wait_sector_num[i] == s->wr_offs) { - /* - * A -> B -> A cannot occur because A has - * s->wait_sector_num[i] == -1 during A -> B. Therefore - * B will never enter A during this time window. - */ - qemu_coroutine_enter(s->co[i]); - break; - } - } - } + s->wr_offs = sector_num + n; + convert_reenter_waiting(s, s->wr_offs); } out: @@ -1899,7 +1909,7 @@ static int convert_do_copy(ImgConvertState *s) qemu_coroutine_enter(s->co[i]); } - while (s->ret == -EINPROGRESS) { + while (s->running_coroutines) { main_loop_wait(false); }