From patchwork Fri May 19 09:34:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9736787 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 D5DDD6034C for ; Fri, 19 May 2017 09:40:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D767728927 for ; Fri, 19 May 2017 09:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2B6628A30; Fri, 19 May 2017 09:40:32 +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 02F1D28940 for ; Fri, 19 May 2017 09:40:31 +0000 (UTC) Received: from localhost ([::1]:57485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBeOc-0001TY-PF for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 05:40:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBeJj-0006rt-EL for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBeJf-0006p5-HR for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:27 -0400 Received: from mail-db5eur01on0137.outbound.protection.outlook.com ([104.47.2.137]:19829 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 1dBeJf-0006ox-81 for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:23 -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=CkEozNLU9bIUmXZJ/M2uFZJEJXrP7CQH3AhJhnkyl3k=; b=RXtfnsc8R8106H681Us01aj3lUi5c3kOg/lQXAI2JXCQ20zabdgaiYIkin7UZiFr1m77rGEjcDaJugpzQmlBqiHKDleKFDUD+nbdZ3d/9vbwVBL7YgVwouhHac3aprPjVI09QidlQJ9yLYJv+ncqiqpYN5tHX6m4BVlTbtf2rKk= 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 AM5PR0801MB1988.eurprd08.prod.outlook.com (2603:10a6:203:4b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Fri, 19 May 2017 09:35:20 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 12:34:38 +0300 Message-ID: <1495186480-114192-12-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495186480-114192-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1495186480-114192-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR09CA0073.eurprd09.prod.outlook.com (2603:10a6:7:3d::17) To AM5PR0801MB1988.eurprd08.prod.outlook.com (2603:10a6:203:4b::15) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM5PR0801MB1988: X-MS-Office365-Filtering-Correlation-Id: 43c58e40-c740-41ea-6bb0-08d49e9a5e6c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:AM5PR0801MB1988; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 3:bO0D59lOuixRO8BXjzmcbwe8XgLna9+GFeurY+R8fyYhNFB3TALY/QwdCg87ojk8R/PqzkEvQ+utcFFKZ7qxWCRCD9DF9Fo/TGZgYbJWm+KWOCmFuc7/dAfNWJc+4pxd48SztGk1v8LVw+z9QC8Fn+un+I0L0ALD2hIrC9VueJEgXLq+U7/zE2ToHNc0NgD2nxCdu1v8YrpEAXjL9mC3qKiNJuBNUxXtGtAtj3wxSLoAtQfMRI1Q1sWiITrqz1CxVkg+jg+zs8stsZwGLNJ8YdmhCRDBNFcYRIFMF3YE/JoBzJlRnkz5xaTmuA/RkVz1zxlCEG5LXj/bx14ccvTOYA==; 25:aUYPxY/aSHbMKA/LX/0HemchvFa5syTNt3I8aFI9+my9qxU3qYvcxbTeuLbtigOGIGlzi9aNpBivpanGe1r5N9jwhv1G4Hhx1EbO8XOaCt38I+cPYiaz0a7xM+7N4FcDvRulMJNpX2as1g0SpqJw6/gN+/hpL2mBBtUw+xK0VhfGokqsKGj9dLq5ActQyVUrvglh4CGJTZVZ0qsvpFzr+hTu/dfXI6Znzh6xN7o41cSMp5szU0U9Jye8QviqnTsXZYpqyZG9sE5bJdne+TyiGKKvNTm3oUQSGA4CgJmrMngGMca9XheXB8f2vCcEtopsqRESk8PLw7Khc0pFGpQerIH4yDZlaY6ox7BaNV1Ju0nIe3JC+qBa7bd9EKkMmvokoFmWj1vP6mGkek1m8xMScSRnlKRxKjNFlYHZmnINlLTcI74vWI+4MZAfol7CFFmRTf2AQ3avLdL1BggHPWjJEvLMSfdxMxkGevtlY1AuZs0= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 31:95rYGc2Xsk+YKF21q+gRuAvMvGISXg9BQnaezIbxl1t8jyGUPcTJE/Q7Knv9iISZlPYB4hzWBhPoeS6F3zhGYTmvcvT4Ayz5BQ/lXb2MY6AELmarq+aLqzWMNbamDNPY6okn9rKRvK5gXm+U7KIX7oWoTacUDMVkLrecENxy4FtF0cINkJ+2IJM1fHtjYV7vgDp8u0E1i+0XtFd5grEWbRu61GyX1wIE6dSxkBmJpVU=; 20:sRr3MWSGmpS8EC87ta9Rvhco0Fh8/EuEFQmuOShskAI4OfB9v7qi+9Ugeap0bWiQJCBhMa4R+CX0XJmMM0w1mIjMLbrqAW2yuepLMdGscdFR+VxtC01mTXJ2IeqmbrhShnHL432a7dkhxrhLKawAJ+lxsWxtB8us41HdGQgggyz7FPVjhUz7IVfR9m2I64+n3GrpePGSrdaPFmEdyLK9X+fkMu4+PkEAj8pFM89mwrmjvbV3CZGc9k2DZ6kFXivG14wkzrkSOnnbwJgXkgbOOyLSytpYTDEGIO1fT0ufJovzA8RZq9RPmV4+7o9YNgRZUR/LdNMBZnL3yDlKRAxiaGB22c1FPLM68Eu4JHdkyFvPbel/hvd0F3bXq/EBEa0cnKFwJJJ6GsxHXXG28Qukn3GJ0/z/q/+lKligTDPADR0= 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)(3002001)(93006095)(93001095)(10201501046)(6041248)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148); SRVR:AM5PR0801MB1988; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0801MB1988; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 4:EM7HZLJokq35+b1D7BJWEBfwynUbL3Ve29CB3sDIcP4FGZq7fhQfF3cNm2N+EN5lC5Ipv7V2l46fjP9MgiVVV34inMlnrEAPfUDpeQzzvwABNp4eAf87GmbmyX5vWl/0v/auQ/0Exb8b323G88J1Ettc9TUUaAj6jwJ8IpCe0ncbCWm4OSRhj8+G/eI1I0EtQvTk2p1TqYTK7AUCTcZPB/iIMZnQpyzFrm1dbmuVNxy5mxMGLUcJxovzpcdZHEev7+q/yXuXc+I6f/j5BTlukVrgrPD4FKMlvc+kvWkSNbrIaUHGqhVrLcxOhH3sMPDPt6oPaiKWk7VPMj8xJ8UYeDcqfGKwykE7kq9pH/0oyFHjWSWSx2Dsxo1+KBjkkxl6GeAwo+grjTHfC3MnFzB8EBJ0jXv9tgOzVdjt7mRGWR3C2Egug0ea+a27RkWmo4z3rBqejTPPgVHo8CXeJu6Cx974y+Vp8nJGgJCN3KTgxMfFqLE9YEuE8SDGJPWGq4dbxO0oGCvNBpkuXyKiRx1Odv1xzX2Gy0NIjg2fSEHwXzxw/uu/oTETGg35uLbJe6oUvoum/yETRgz6ODRCO4FLhPz/RGid26hSTJ/aQtWT1BZ+rxTwnCn7yOSeRsewNp5487TLRjQPvGdDEV6goxQihf3IO7FIx9JncA8h4VEwh+IdESFTYjNF2FC0b2t1yHgkqYEri2GATM8t7hxXMa546nES4/VuKi0E6mZebyI1rRJA5p4No2YJOFOzmb59DLD56mdVia9Is6bGAoVo5yceVxtQw0pcxSBM1Vdehj/PnVE= X-Forefront-PRVS: 031257FE13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39450400003)(39840400002)(39410400002)(39400400002)(48376002)(8676002)(7736002)(81166006)(53416004)(305945005)(50226002)(33646002)(5003940100001)(42186005)(3846002)(4326008)(25786009)(66066001)(189998001)(50466002)(2351001)(2906002)(478600001)(6486002)(6506006)(50986999)(6512007)(54906002)(36756003)(5660300001)(86362001)(53936002)(2950100002)(110136004)(6666003)(6916009)(107886003)(38730400002)(76176999); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1988; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1988; 23:yVsuWF/1rHFdDeuVyYmUE2BTKyNrES6BsQ5WJqG?= =?us-ascii?Q?4TINYx5H9ll5SjrnF7siFGDGKy1PB8xVESz++opFZpg5kKi5VXgKuQz2ac9C?= =?us-ascii?Q?xsgAGN+AOq515M86U36jWENkjTGJ1KxEmZpYWClUnremeQl7/oflBZ5RPDBk?= =?us-ascii?Q?2gxuL3sRVpEX1PkjBFuh3dq1jRkyKXkmZJ1oUe4jAZEEjG+qHumCMSZ//h1U?= =?us-ascii?Q?fmfRJSnBJQoo9qUxwLVMZc4As4o8wuXJ9mTl0ksgbSnZXwbYxBf7mn+yMecc?= =?us-ascii?Q?oNoqTkoFETddqbgg3SMpOVMgs6Hmtp/1FOskjW+Wqed4HSMGACgBhgBR7m1Y?= =?us-ascii?Q?aWNAXzyyd7gqPvlPz/04ZJKKWKwo0M92c2Hw6FK4zV5EJE3WEJ22bTJ9sOQJ?= =?us-ascii?Q?f4DNnWgolaMrYVxV7Z+h5xsGZWlfEi0IN9CKzVa0bEieWILgLQ7/3D1UeqaG?= =?us-ascii?Q?vVFYt+3vS9qHRZa1mkbySreNdtohyTEm5k+R+FGrIAdemuw3ZWRHv6+rIOhD?= =?us-ascii?Q?BhjVdcOrhAHnKvNprvddXLHP0qTs+ukBxYSAusk9eHGQHSoc7pwW13eNYQnY?= =?us-ascii?Q?qntMP9cPoxNbVJz95mQK530Ww/Mb+gcf/JkzePSqqhTfnUDcYxyXtvAye8RV?= =?us-ascii?Q?rJXt3QypvRYB1s52J243xR1iz8K3BoeNDUEYlBCUVm3V6KHJoMOICCeXFWhI?= =?us-ascii?Q?lxknKNrZlFBrlsLyxZFCYiUgnBsEA6nhy3lX6XkCyq1zrqltyHiPsTCkTwyX?= =?us-ascii?Q?PSmxG+K6mBAYWxCjgSkhFBHPvd87Gfr/ewInihEMEraYoyWtTveKi3wbORnd?= =?us-ascii?Q?7ksUrZ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pVsrfsq1427249a0Z1NKX2A0cjPcM3kaz+iqAad+4LOhayc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 7:bmP66Xkw0bIXtlXOOGBCEIlgAMNMGe3oWDs5nZ5w/1CTBDCgGy6qdantcqoH5Zk3ZqqyF6VG9y8O/JQuKE90z/wx3XLvlwuAFalZkqTTmUNnbmuA9hT4oYgUDrN/FfGg1BaikxmoqlcIKnVepku65NFyLT5ETyEEkc1PNNV9rVdw0NDnq2QIPbLGecHWq/OYHFrSLQNeODkw5SN0dncwiQfm1DziCRa9cEaRQyFqkSTReqwBthus09wy/obnDnjIUxKM7G4RtkQehD1MwJYdOWzuZ7XcbIaDFc7D4gdk+mLCzddP3ohcoF44Npqnvt9WW50an8WkYvU5TIxdtYHZWA==; 20:vUrHW9w7MIETuiTwDzmUFoQgfxu4V6QZVxpSungF55+0nGKe+RhOTBNZ/peBRQdx3MalMLs9NT2LwtgNZ3QMnAHdbGL4pAoxglbp1NOv0C6mqSrEPt1kSjpoT7XdolIUf/NwnwgXx5i8bAM7By85E/2iQkWEqpDVcNBwloumsLM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 09:35:20.5572 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1988 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.137 Subject: [Qemu-devel] [PATCH v1 11/13] qcow2-cluster: make handle_dependencies() logic easier to follow 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, "Denis V . Lunev" , Anton Nefedov , den@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 Avoid complicated nested conditions; return or continue asap instead. The logic is not changed. Signed-off-by: Anton Nefedov Signed-off-by: Denis V. Lunev --- block/qcow2-cluster.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 03d6f7e..c0974e8 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -926,32 +926,31 @@ static int handle_dependencies(BlockDriverState *bs, uint64_t guest_offset, if (end <= old_start || start >= old_end) { /* No intersection */ - } else { - if (start < old_start) { - /* Stop at the start of a running allocation */ - bytes = old_start - start; - } else { - bytes = 0; - } + continue; + } - /* Stop if already an l2meta exists. After yielding, it wouldn't - * be valid any more, so we'd have to clean up the old L2Metas - * and deal with requests depending on them before starting to - * gather new ones. Not worth the trouble. */ - if (bytes == 0 && *m) { - /* start must be cluster aligned at this point */ - assert(start == start_of_cluster(s, start)); - *cur_bytes = 0; - return 0; - } + if (start < old_start) { + /* Stop at the start of a running allocation */ + bytes = old_start - start; + /* ..if there is no other conflict, keep checking */ + continue; + } - if (bytes == 0) { - /* Wait for the dependency to complete. We need to recheck - * the free/allocated clusters when we continue. */ - qemu_co_queue_wait(&old_alloc->dependent_requests, &s->lock); - return -EAGAIN; - } + /* Stop if already an l2meta exists. After yielding, it wouldn't + * be valid any more, so we'd have to clean up the old L2Metas + * and deal with requests depending on them before starting to + * gather new ones. Not worth the trouble. */ + if (*m) { + /* start must be cluster aligned at this point */ + assert(start == start_of_cluster(s, start)); + *cur_bytes = 0; + return 0; } + + /* Wait for the dependency to complete. We need to recheck + * the free/allocated clusters when we continue. */ + qemu_co_queue_wait(&old_alloc->dependent_requests, &s->lock); + return -EAGAIN; } /* Make sure that existing clusters and new allocations are only used up to