From patchwork Wed Apr 26 08:33:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9700659 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 BDD24603F4 for ; Wed, 26 Apr 2017 08:51:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4A4E27F95 for ; Wed, 26 Apr 2017 08:51:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A79F8284EA; Wed, 26 Apr 2017 08:51:26 +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 F0AC127F95 for ; Wed, 26 Apr 2017 08:51:25 +0000 (UTC) Received: from localhost ([::1]:53642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3IfU-0007tv-QC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Apr 2017 04:51:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3Idu-0007Gi-R8 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 04:49:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3Idq-0008EB-T7 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 04:49:46 -0400 Received: from mail-db5eur01on0100.outbound.protection.outlook.com ([104.47.2.100]:34976 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 1d3Idq-0008DL-DW; Wed, 26 Apr 2017 04:49:42 -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=tKlTpLf9BPTfbFhZWqG6f84ZEblwy9FH1VlUWflolEI=; b=BhyBV5vg7u/Mx7L/sZa+O4O3riVmL3YbH/5FcZYTt67X7Io82+bb+omVe29KGuSo+vrghYxAw9h3XN3hxTl7BzAEa9/8mX2ws3UxuhrLDY7IcAQwwn73lvvx9LLS6dpchOwUZc8XFhPcBhAuqhBBBq2rBcRuEofKkXwBPc9J89A= 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 AM5PR0801MB1985.eurprd08.prod.outlook.com (10.168.158.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1061.12; Wed, 26 Apr 2017 08:33:37 +0000 From: Anton Nefedov To: Date: Wed, 26 Apr 2017 11:33:15 +0300 Message-ID: <1493195595-4809-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: VI1PR06CA0014.eurprd06.prod.outlook.com (10.162.116.152) To AM5PR0801MB1985.eurprd08.prod.outlook.com (10.168.158.12) X-MS-Office365-Filtering-Correlation-Id: 33abfe95-9dff-4438-6a8a-08d48c7eef9a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031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/kL28qTUcwd92MfgaQ5PI4NKnRjDaepPKP7i0ObBh6qD1gTSOSYYiiMphlTFlbz7hVfF1yRbrbxeeKlfUkZeK1I8uHScCsybK7bzo9s5; 20:U8+AT5FjoYQn0G9rQRop0t3WqF4GikJXKlSN0/WLSQrJVxFm5nq5OOP/N15cYT6NVb7jZTO/tlrhp5BTr3JlHciZKMFR05Okp1Jx7MG4G/ifqB79YVkqy8Sn233sqzva5xxclN4t7S2AJa9zCHI/hdgEDStLxkrS5V/urZmQ1EkrbAxq2X07MdaRZl/sYvxCJfJeibbzDwBXtGahvwbzuKPbwfzXrE7t5qgS41YXPtl52+1b9vFH43pT0NXwgl0q1BfibmNGdzAlVR830JKKQg3m4x6mqLYiQF1okd1TkT+ouSuNylyXgmuefZMCChh2OiwCBbHb/+6QVD0xzmNo53rK/Z3kIPjAvy3ZtJ3SoTzD04jBRwCWwHHsDdgvdPU+N/vi9kLHdAj8cRK+HoorV1tTwxpxf2gpVX7TstzQ3z4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123560025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(6072148); SRVR:AM5PR0801MB1985; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0801MB1985; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1985; 4:XLwM73Nco96ceOaVWlVcTzyUUTSwOz5DYc3OpGYCo+i+emfIzdmaz3Vc5hb29XzU4B5msJWk9IbpAHFoxgDKTJLN7ttSl3tXx4dyhxfHPObr7sQRb4DjDOv3SFj6S5VRCoxpQ6VOnnwyGZXhIwqb3I/gXIgb1aq9utHXbyexr8wsmUtG8Yem8wcuOMSKZ5nudkHCXBsYGZ/rdGEAM5OHXvOqzPL805FABckn1KkQnAk/jpG7Ba/sp7CmSSFA/cyVKCC1Wb/NWWe+5KFhnBkmgMATrC48zdrcl7/O2bxh+D5ShKFeL49veYx7RTqNBZ1xUwQgrwhOjTJeHIziIRTCjv3paypiiwN8ht44kSUuXr3I9aYFC9VwJyAzxRzxXfj1DSVoBYlzk997rIFTjNPvYWHpBiIMYhwbCmsKRyQy30+YJugmyDSUw0N1ot19ZifvaoCESjPKbVbBNomvQRsqk63FdnHSRJtq/SA6QfRtr1k6DpeCICgsEPO9sTLnWbv+DYjeSY4pwRKZ87x343mtAFFB42b8YS54hy4/tNu5x2mHAOYcFRwB+TBzse7mGAfm8B7ID/PV2uJBNN10pxOBjUSquH6uEyPcjpavo9Dq7HU7vzIt0iqjcuZKmKEq/w940RE1q/bdwyz7+pNpemCdHwJRhXjKJNXd2wEw23hkUnpATEr1Ow69eTjLJavNFlwAPOG5oGPqMVWYJfq/wK6SPl0C+csDrIJsPlNGbsAqx0yI1Gg4OCt4XRAb3eGXe0y8AA+GShV4hjEoM6oOlbuOVz9JD70eK8CULPunJ7nzHeM= X-Forefront-PRVS: 0289B6431E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39400400002)(39410400002)(39450400003)(39840400002)(110136004)(50986999)(107886003)(6916009)(6666003)(6116002)(3846002)(5003940100001)(47776003)(8676002)(81166006)(6486002)(38730400002)(6506006)(6512007)(53936002)(66066001)(50226002)(54906002)(2906002)(86362001)(4326008)(25786009)(42186005)(50466002)(48376002)(53416004)(5660300001)(2351001)(33646002)(189998001)(36756003)(7736002)(305945005); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1985; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1985; 23:RDuZkQp9gaGY42mnYMoaybwEosAFAkA17t+YqoZ?= =?us-ascii?Q?Vnfe83CEX9712Rry+NPJL0H7s6hWo+elPEZKDaoo1j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vXWchXfsnK0HA3mm7MdenChALtBQFxi1tbeocLqsqHKWMwhsxa?= =?us-ascii?Q?N2X6Xj1N1Dtum65uneqLqCBIz?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1985; 6:/8zSPfzuuzn9I4fTqoJkcnnFkZECwYTLXaO3LYgZGTt0iZHumex3vOrZY//RaLw7TBT8qPs8b8nTD8RPQTjTatQ66T4jRw1syaFMWZACIS3wE++JE1eD/9PuwtnTZQaSeOOKW8jeev/UKXDre5NQq2J45eOz4EYehaAIwL0qxBuDUewr+Tq/aKkArwT/bznKERsjCyVID7ET6dvC7Hgzx0pCHNWg7CD7z4NAeWBy4DFm1k1KQxOupIAM/XXjYb8ewiFPLPiYCrK/PddHSfCPPur4saj1QYymJoXEswnjbGpHUhHwiPXWFH8J0j21NYhq3nShY0F9Wsca38RsSvkK//Dwcqy6rZaNbjCaVYEfKJGCtPhX9Q8tCtyuXMeIA84EpbFM/Be29tTcsxdQGZ/Npc0ekwNIQNkxJxpbeA4D6SebqBFbnX/sdpYEz9JG3Zi7yaIFKrJnEec6oJBPGd3zczEQegVqdZlas2fIy6PiADZV7f7F9H6UhMwCEFIe+m48ZGGl0jfOSKGVz0LLnSOr0A==; 5:nBSIkRjFlhTseh7bNMDjKir+y6qrY2rsIKS/tXDtCo56s1FyE6+RMNDNg21avkMYcxXjrFQuQfXPEur/3pmhRWQlwLJUgNwwCzvi3ulIM1YPt0+UG6VFvgfpUjDFmaRsWdocWUvVoW7hi2ONUp2LEA==; 24:Hrsja8rUv1ykEIN1V3KBVeUAvSD4QApt/gFJ1pd7mlESTcFGyBpNv7Lptw9zZ29oIoX9QdupUrdOXCALMthpm+9oT0l7i0tR9K471LyfhEA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1985; 7:DncOgZyRHmHN03KyrsIdPeMUvMgBrtLYByRRSgw4XgRxGVkFRALDrJxlz3E0ddt6rhdF4+EVKzdqWNFW6nUe/NUx52i6CCShr9wlYAzd3uAbBoDgrm/PBF3fl/Atfs8hRBGRb7tlykjWJNNIh3L/VdPf87IlII1tq0lfaMRpyo3mmY+yivBcKGRDMvzvEqjAGwiBrZwWXOfix6GDGXSFFC17TysHWtsZLCdjPwsmxhhNfLLuZ+DHxEdMGz5sEwiYnWAaiRMEYO5lOQrh60rFIddRY4G7x3OOdE/vRGgS6aXPy3trm7CdAwJhbZauI+tlW14huHGlXNEFh4JOY3fb4w==; 20:f4ASWNhIFBugbdOppKHPUxNlaronWkfpDmaLztRR3B04NYzM/Yv+OkOODptDE8W0RKhbpP4FkK6vpXOcVXPdBLC5b75ATmabsZFIDcEIxTnUee0DNwZjDqWqFjdrcmDXiEMgEVvEY6iQ6Z1K2FQvjylkrkIS056PMeWmLBfs5H8= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2017 08:33:37.1498 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1985 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.100 Subject: [Qemu-devel] [PATCH v3 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 Reviewed-by: Peter Lieven > --- qemu-img.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index bbe1574..8c50379 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1761,13 +1761,13 @@ static void coroutine_fn convert_co_do_copy(void *opaque) qemu_co_mutex_lock(&s->lock); if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) { qemu_co_mutex_unlock(&s->lock); - goto out; + break; } n = convert_iteration_sectors(s, s->sector_num); if (n < 0) { qemu_co_mutex_unlock(&s->lock); s->ret = n; - goto out; + break; } /* save current sector and allocation status to local variables */ sector_num = s->sector_num; @@ -1792,7 +1792,6 @@ 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; - goto out; } } else if (!s->min_sparse && status == BLK_ZERO) { status = BLK_DATA; @@ -1801,22 +1800,20 @@ static void coroutine_fn convert_co_do_copy(void *opaque) if (s->wr_in_order) { /* keep writes in order */ - while (s->wr_offs != sector_num) { - if (s->ret != -EINPROGRESS) { - goto out; - } + while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) { s->wait_sector_num[index] = sector_num; qemu_coroutine_yield(); } s->wait_sector_num[index] = -1; } - ret = convert_co_write(s, sector_num, n, buf, status); - if (ret < 0) { - error_report("error while writing sector %" PRId64 - ": %s", sector_num, strerror(-ret)); - s->ret = ret; - goto out; + if (s->ret == -EINPROGRESS) { + ret = convert_co_write(s, sector_num, n, buf, status); + if (ret < 0) { + error_report("error while writing sector %" PRId64 + ": %s", sector_num, strerror(-ret)); + s->ret = ret; + } } if (s->wr_in_order) { @@ -1837,7 +1834,6 @@ static void coroutine_fn convert_co_do_copy(void *opaque) } } -out: qemu_vfree(buf); s->co[index] = NULL; s->running_coroutines--; @@ -1899,7 +1895,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); }