From patchwork Thu Oct 7 15:39:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12542145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3954DC433F5 for ; Thu, 7 Oct 2021 15:42:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD022610EA for ; Thu, 7 Oct 2021 15:42:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CD022610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:58672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYVXj-0005dM-SB for qemu-devel@archiver.kernel.org; Thu, 07 Oct 2021 11:42:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUe-0002Y7-Nm; Thu, 07 Oct 2021 11:39:36 -0400 Received: from mail-am6eur05on20719.outbound.protection.outlook.com ([2a01:111:f400:7e1b::719]:49281 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUc-0007Fx-3Q; Thu, 07 Oct 2021 11:39:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jiLi0ama/XwBTkRCpLtjSDYDyowc49JY0fOGigO+UdxHnSXpNRw+i5oMHNgR9KBFWg/o9a3QCnFzprkfXXX+QFVmeoSnYjPez2BQc5b1rkKrceNr/hPvyrYPF7M+zXdiX+2w049ZNDaCfIrEC+ulunw//EiFDn8WKj2JgOh+NoqDmcVcerwhqdyZuqOKrgyGuNwjYZoMR6Wa+nP8j1sxLuIXOIGQ85TE/dSwREUaP886s+s8RN48CQNu7Ghvtng/wkg8cCnScyz3T+8YonNGvoIv0zi7PqMeDSb0YP+MhtaymcwS1VKGW9Zmy0y8JOHoPptDt3p1lm76gP2YbB2gmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wid2L+9imfwPEuSCp7YnrG47bsLS1JFpSPlgukYTavU=; b=UANp2/2gP/Ck6O6hRVKTnWc2Mq7SBAAhwv9hXiPleeJ+B09qSkeI0D77qYNZoSHizxDaLkkDg6EdFh+1EJLUly8QYoC9/H6SkDUgdJouaNCH7Pj9IZpdi5QmR+TzqVkyhvObZ7gluv2NOnQsjghCL/QfIX2W9LrSRswN8/p0xt0tT3bLLfnEhuWp7aVOYIYStrMt37gOyDKjkPrvcfejo2PnHYPSpiiTICpfocrKsEfFsEws6YyYgpmuq2Uv2o3u57Jbj2BqUfF3UrBUiPZAa4qw3bKGAL57R+V6sZr8QpS6voUW7MpHkcKZ7M0l6rEySL8CG/Y45rnQVgZuKyHX4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wid2L+9imfwPEuSCp7YnrG47bsLS1JFpSPlgukYTavU=; b=dX0iEo/31BR2OsEtFdQjOU9QS12wJX3tECr6OmYKKCZQd7iqx4Pz8sHCW/cDisKWtKAD1uiLz962/0bd3P+HW6g+0CilY7As3JLPFOB7O1XLVfug3it3agT2xJI+WXSx0C1J9HTawLT9y51rbQJXmMz0arRY5Zm98zKdWN4WIqo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB6134.eurprd08.prod.outlook.com (2603:10a6:20b:291::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22; Thu, 7 Oct 2021 15:39:19 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4566.023; Thu, 7 Oct 2021 15:39:19 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, richard.henderson@linaro.org, Stefano Garzarella Subject: [PULL v2 01/15] block/backup: avoid integer overflow of `max-workers` Date: Thu, 7 Oct 2021 17:39:01 +0200 Message-Id: <20211007153904.445009-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007153904.445009-1-vsementsov@virtuozzo.com> References: <20211007153904.445009-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Thu, 7 Oct 2021 15:39:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 097eb58f-6a1c-4196-881f-08d989a8a05f X-MS-TrafficTypeDiagnostic: AS8PR08MB6134: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P7N67IJ2zmFcviiz8azIy+3kZZxbpyEHwjvMHKYKsJtivhteaAD1PkvohxxD4N2vDp2fabbpJ/sxEHLbfIf+5iKfJ50S7bBHTdrOrG2fmW5fPTBjxB7k+qukF/GRZ5XsEygfC2ifKXUGvJRr8mCAsQ5rvxLnW4FI9QczFDdgQN0mcLIyzUvq9gHDzDu+vGyaAamUchY/uXy6T6ghW1LIeSllXb9R8DT5tJ2VUopPXGi8s3sv9LQ8hS/WEjD3rFfp234AyigAHgQgbxlsvDYqcpJMDJoUt7cxJM6wNBmJI+Gjw1WTutDHgMqK3D23ZXleSdq1q9KjYTK9yMOo7bO7tZ/smgADOrMkq3dx2pb8FkCGsYsGjxUk5yO4SSzJs3Rdv4Os5dZlRA7aDjDBXdToKks1KBeb1uQ0T/1LXndgU1+r0FQ9KjTiyfMRtaX1B/y4rn+TlpINCaE1h9oHabt/3+kh11S8jvoirVhf28Cbz2Y9ISGYqM3EPL6W7pe135O23qsE8dWKXE2cMi82uBHPeGCfFgjcRJs6mV3Z7bLxnwjs3MqQeZ3I2PQXruHjFj3tlU75jdgvSIsdhDV0qKSMNP1wMVcrGekRBYztVtSFgIW2amEt1tQS/8ku4sx5sBLzlvk9EncYJy4e2CdZ7EYVwOJjodkwkH+OmktudyV+ZHlRfiNoIVgbH9YVc+SiBkBZ0WqTW13d3K/BAGYnhXHt3Z1eniiRtcASZF9Lo23eCm/xl92SBildbhVI/wZ0rhp1IFmQ7SIwJBtgBaFQ2q2XjF0anMTkN48/BpvbA32xDOBQ+xA0hw/7vDRTHCVcdYwo X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(36756003)(38350700002)(83380400001)(6486002)(2906002)(38100700002)(316002)(508600001)(4326008)(6512007)(8936002)(86362001)(966005)(1076003)(2616005)(8676002)(5660300002)(6666004)(6506007)(66476007)(66556008)(186003)(52116002)(66946007)(956004)(26005)(6916009)(81973001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gtdt1iecwK6fi1aTg18ogVFG5Em+jPWH8NLu2pmJ+241o3vXwztH0ZNqKK3jyt30jzdE7vUbxq6gCI0tAFv8Tq343zDzMfKI4JrJeebPsErRYmbC9G803SJUoQVuMTuKMfS0PXMGhbcF+rNmY5eNXTpjAU79EjDlu+g5xGYa8knSZNbLpw+pSwL4apBXUX18dckkNHhPPDcrdJlf028kg3reDpkm+Kms08dtkz2U2h318XOT9BlCqxkELMerNzJWUNmW9lJP9HDc7QOJSJZL7G+ok4fvxi5MevV1g1ftFuO/y9UgbmpGqScVZVQBoIeMaC4CZez//H25d0nBwUt4ofEW3FK5cqg0OAOU4mtVd/yAQ67YEnB0D5DVjKhDWZw8syuv/HiQUfQp9fUTRiqiqRA/Fn8A3dHa20hdvrm7bhF8CsWMPlhIOYBK9e8p/bKwArJtZ2dazM058ytOuqyZWuanpSYnyLbyG6UqqM7u5IqTF/4nT8sIKTLllI8UkAD8glm+72275aggJISFPcXp0e5+4uX4OsjQD+/IxGazP29Rw6XN+kCfQOdYh8DKAKwesaLmGH288UC1ubn+i2iC75UINFg7ygPnwi9OFE8pmj1axH03OLjrGsamPa2kjGjUYNWtq3L3ng/k6CBkoNYbfM/7vbYHAQwjneb9gfpDFgwIDrbh+akNb9mDe8y4xMHuBFM0KQFWRDR7aCmVyjzBEMFP6yQfJPTYJj9zMzOgJnU4MuioAaAcXmd+zMJldl5O X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 097eb58f-6a1c-4196-881f-08d989a8a05f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2021 15:39:18.9116 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: y50knpWB6z2UEGyl8u88VVMJvqQ12by3ZQhl3GNs7Kdwtktkt2sUSbD+ykJytWYUYvCbjlXvjznE5nKZmzrMgA6/pj5EO1Zvk1BCifUBOow= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6134 Received-SPF: pass client-ip=2a01:111:f400:7e1b::719; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefano Garzarella QAPI generates `struct BackupPerf` where `max-workers` value is stored in an `int64_t` variable. But block_copy_async(), and the underlying code, uses an `int` parameter. At the end that variable is used to initialize `max_busy_tasks` in block/aio_task.c causing the following assertion failure if a value greater than INT_MAX(2147483647) is used: ../block/aio_task.c:63: aio_task_pool_wait_one: Assertion `pool->busy_tasks > 0' failed. Let's check that `max-workers` doesn't exceed INT_MAX and print an error in that case. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2009310 Signed-off-by: Stefano Garzarella Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20211005161157.282396-2-sgarzare@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/backup.c b/block/backup.c index 687d2882bc..8b072db5d9 100644 --- a/block/backup.c +++ b/block/backup.c @@ -407,8 +407,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, return NULL; } - if (perf->max_workers < 1) { - error_setg(errp, "max-workers must be greater than zero"); + if (perf->max_workers < 1 || perf->max_workers > INT_MAX) { + error_setg(errp, "max-workers must be between 1 and %d", INT_MAX); return NULL; } From patchwork Thu Oct 7 15:39:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12542167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D110CC433EF for ; Thu, 7 Oct 2021 15:44:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37204610EA for ; Thu, 7 Oct 2021 15:44:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 37204610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYVZc-00014b-EV for qemu-devel@archiver.kernel.org; Thu, 07 Oct 2021 11:44:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUi-0002ef-KV; Thu, 07 Oct 2021 11:39:40 -0400 Received: from mail-am6eur05on20719.outbound.protection.outlook.com ([2a01:111:f400:7e1b::719]:49281 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUg-0007Fx-2B; Thu, 07 Oct 2021 11:39:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QwyfTA+4vFII1sjsTCuP4HNBiXWPbRman51AnEZ4XWa2WOBGcwaM66bSjstM9oSnhkKvOTIZTMXYi8URr6X+jTTxCyl469O6Mjf3kGj2jGHGQUgR0EQSgM0Umfoyyg2fRcdWr6wAD0zom2/hP+UOOJjVocXX1uzEdziXPG6qKs8GosxTBZt1ncCd9klWeDtiM4c14CClwMG4iVll90IysIqkxGLlmAzMf24bOtAKA39K36D73pQnqXkrs6UXnzrbbvnvuOXhQ1UZRgoD43dv0DKm3NLTXe+00Fu+iE+4nhMxfh+uUAxjd451R22iL9zbB33MuNZ2n4vkx0j+cHpO+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zKZPmX/LcSladWMQoWU2IfHJEGNcrvXsGQSDIk+COHw=; b=kdLW0/1Pe5ICIHJ0VuKl37pI+2H2G/uVjJcMZ+ThU5IaqK7EsQxR7sy1B76eCuIKmXqykzkjsM2V7j4lz7U5mmJupQkiv2RnlAjb0+oKrmEj+joYhainIWPTCrpF3XFg7/G00v4UD9UHQIydyhaZKXdnZT5rBFMUYq71vwwBLmeaggqU3/3aI+aVwiZwqLWGAV2J16zByjbyT5v5Mj2t5fr/LhX6k1UUWU2gXfhuSUJYenw4Wvn/2Lbz7A/q3//oZNuYqbUyi9bbLiQ9FfYTmoaE8Zd7ng165D/Z1nHLR3iJR/a67otiKFkiUxlJV0G9HH7LqfFRdnWiyRZWae0YLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zKZPmX/LcSladWMQoWU2IfHJEGNcrvXsGQSDIk+COHw=; b=mrLKWUCLd+q40v3YXiMvjd1LA93spzIB0dkYNiZdlHg+fOOFLJy67j5G2wXDea6vDNVx9gVv80uk/gRs9b3tPvxN5ZAnnkSD5AmpCFUpTSPIhUp3P5E0GD+igWXdQHxonIenk7MR++504YkXcbMKWEXKm+TElQiazllvH8X9mtE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB6134.eurprd08.prod.outlook.com (2603:10a6:20b:291::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22; Thu, 7 Oct 2021 15:39:19 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4566.023; Thu, 7 Oct 2021 15:39:19 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, richard.henderson@linaro.org, Stefano Garzarella Subject: [PULL v2 02/15] block/aio_task: assert `max_busy_tasks` is greater than 0 Date: Thu, 7 Oct 2021 17:39:02 +0200 Message-Id: <20211007153904.445009-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007153904.445009-1-vsementsov@virtuozzo.com> References: <20211007153904.445009-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Thu, 7 Oct 2021 15:39:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4a32b1d-8edb-4b10-16a8-08d989a8a0b3 X-MS-TrafficTypeDiagnostic: AS8PR08MB6134: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VdvUYV8ktZBZcXSEYgxh5U71bj+SE5L991FQBcRwdgfEX3ii+cTIZbgx9Nj8ji0YXadOR/sKSFaC2MjlbNtrAUX1si36QQ4kvUDeny567FtIHNUc5h3j4LDQ2mqDLkAbF4kOEff3OJVRmLyCAN0wLbGeRzPP0eevKQ5mIg/kdFpahUK4oFEvhPi4UYDGz7o0aWW2zEwjpO9PTVfcPeHXOKgo69bbHdCLg55KEWLO2Kt3rR8jIc4jJiqAbO+7Y1RE6DFkMg60U5K0Z3Pk7FHKxTCWMbzu81oCYuOlEZ53H18WlSFRByWT3Tusu63HkBBYkUG1Ro527NhmLhyqAp5cgFN/i5UhQhSWiaCpfkJuKAysPlXaqdT5JCvYyOUVhc3kTWFj04X+dYttOR7F2yos1rTA0NbgQlyO9BkNfsXoFCf+gyXYQAe0hx8aobQYlrLqXHOnfpADr5MRe/jOVhbjbMeMLc3EbnLPE6lncKcyEXJzwLI/9kDDDe/7g5VBFStksZiudeywCwTRO7yM9Ozq7Z44eVEVeQy9CfetIyYmliX6xL2/UJ1V6a/5K21I48KFCEYJITndcPPZSeXUbzBy5TwtS8SWNK0gI4BQJ+FImuvqeboixrcPWsQYW0dME0ga+Q7btkzUbSoe3JOnjCxe1wyaG4whcq4eqclKkuTBPocGLh7iQDY3bLUBYiK74Q3QVuV0pudKtHs3NbkEQg06Irt2ROV4Xzrmpzxes4vjCXc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(36756003)(38350700002)(83380400001)(6486002)(2906002)(38100700002)(316002)(508600001)(4326008)(6512007)(8936002)(86362001)(1076003)(2616005)(8676002)(5660300002)(6666004)(6506007)(66476007)(66556008)(186003)(52116002)(66946007)(4744005)(956004)(26005)(6916009)(81973001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T5Y7d/q1hhoNEqsET2QtwxfrguwQ4x00MbjnWMj+tQm9AvsTNIP9LH8wNvnGzW5IRtY+8xjsJoHBqk5Gne5ggYmZ3sHEbJ0j3ZwJ7dGUZRBpSEuJL9ZX+H84tXgkV91vB9QCSEIOyazx/RFOreohx48Bl3fweJ8BPHzBwHp++tv1ze8RvibNSQJaDGvSVDql9njua1Dq4ahT+8+NMFD65IdDWK4wIrOcfRsiD5s+cdfQ++uGYayWLqv2EDEQp5AIdyMbfEhkNzhb6XIVbtYzXZDEUWoZDjIqd9vby1/diAYO+UzCH98rgTvH9jIPjMf9r1uDbt5NfDeVscB3dDX29ijmfkLj9JLwDnPURGJKCIkcojLfQWvM4w3Gd+lQRWW1EPYo3GB6QmLmTOpz3CEEKgx3uy4UHws6TY1rgfF7utis+m5Rqe+LONT+cY/3a0tm7Oj2sft09rCdcSGOsCNt/1XgMOzUjK32IO2+0F3aAnrxbyL+xWTRxnNFua4sDo80zjpQAhsACvcy0coIzogMkaQb3pYx6g6nWEtQOvHPE5tj2B1NWlIyCU1GfHV2DONEH1KadETOeY6TCP80PXhYw8GoUn55gt6qnvNyyu4bbJivUfOLMA5S/HG1mGoizPDh7X3980nqFeOGM6RGkXWO3U8caOsbVS4nHSXWvVF+eLL3udo+6UUT+/eyIAGtxYg+wTKOAKg2W9DsJ+Uc2t5eYU6KK1FAaKdDTG267NChPGl60D6Tg2MdVhtJhA3IWQuk X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4a32b1d-8edb-4b10-16a8-08d989a8a0b3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2021 15:39:19.4502 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ovo48DIyxCFGfKXHB6tRuVU4pT/ogJNiYdibYNWRtExayMJ+BakebpL4HXZLPNGr7sFrTLJoLPokxDrntVfzDsqNQG9ckEUMHY/bXW5Rb1Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6134 Received-SPF: pass client-ip=2a01:111:f400:7e1b::719; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefano Garzarella All code in block/aio_task.c expects `max_busy_tasks` to always be greater than 0. Assert this condition during the AioTaskPool creation where `max_busy_tasks` is set. Signed-off-by: Stefano Garzarella Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20211005161157.282396-3-sgarzare@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/aio_task.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/aio_task.c b/block/aio_task.c index 88989fa248..9bd17ea2c1 100644 --- a/block/aio_task.c +++ b/block/aio_task.c @@ -98,6 +98,8 @@ AioTaskPool *coroutine_fn aio_task_pool_new(int max_busy_tasks) { AioTaskPool *pool = g_new0(AioTaskPool, 1); + assert(max_busy_tasks > 0); + pool->main_co = qemu_coroutine_self(); pool->max_busy_tasks = max_busy_tasks; From patchwork Thu Oct 7 15:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12542169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60BFAC433F5 for ; Thu, 7 Oct 2021 15:45:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 00E2F610E6 for ; Thu, 7 Oct 2021 15:45:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 00E2F610E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYVaN-0001XP-2X for qemu-devel@archiver.kernel.org; Thu, 07 Oct 2021 11:45:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUs-0002y1-0o; Thu, 07 Oct 2021 11:39:50 -0400 Received: from mail-am6eur05on2122.outbound.protection.outlook.com ([40.107.22.122]:51642 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUp-0008Og-Rp; Thu, 07 Oct 2021 11:39:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dlpdS5FlgUCmKhRqvyWP3ZyP5PS+enE7JYGaojdth+SekvQ49iHuehTOEh/u2j4Gbq9mcdvBqijcIoOJK3FUHgkJULn31agXQEcVWCiaOy02qnxQhxrqa5MrdDXdNuq28Tcj/NTkgg6mqggt5kh4x8QLOoBYqlGIuqcCD+Zx2vLITe2n6ZQIxQ6TNBZwVAmCvNvzM8NiWhd3FC/tcyn+OAeEbtjE4HjOua01lyQaSapLcotytws1Wf3SqFJcWa78ChriqYCE92Mxykcs/2nSAPH/8VIFwOn+Di6yIPGEJ9P/HRDiZGTMfbAo2yjC/XfLE4ZAWKDNBOqqkkHZ1a9Ucg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+8NSIavpzuYvJwBA9LzrrSXWZKBe+OgV/I2GQXuypy0=; b=nOzNr482tSPVgH2opZ0U+oOLexSBxRar3xgrBNzyB/B93RRFpgVi96nfZcvtWQ1MtuOSmMzi4cwVLNae0brDbCZE2Ul5gWmr0sbjeGNf13qdmF9cxWG4Ie9XoO1TbswWw/3lTZ326vNoRSGvWLgtEC/XM20fOkz8Jo+ttr5eaCczCsUVrjI6+SU3Y5Wmo/ZqrgRJww+HJ1lETVdoWupTT+YV0ZyBJKH8TFgK2wdi6wqJBJSK7fqSg8IouSWS0rHa+QuiViSdNSsjoybIz8NtcvHZLLTd/KFWb+I0Fn3uj8ekmhAHTdTes9XZNHZvZFIJtHt9OyKdx/DFnV+jpXYXdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+8NSIavpzuYvJwBA9LzrrSXWZKBe+OgV/I2GQXuypy0=; b=rnbcbc41dTVGIoj7MPR9NzmuPdzZHxu77eRDzrMS+JM8iMj+ERV9zDsoCN5vWysFyYkXjQYfKUlhPl/8zqCMTEkF20i8WAvXbD66JboAMRgIKWt741EzXB6CCQm8GmxAGRJ8krsiuI25hCZnWKbNQidRuzXGVpGbXmTJ7k2hOLU= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB6134.eurprd08.prod.outlook.com (2603:10a6:20b:291::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22; Thu, 7 Oct 2021 15:39:20 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4566.023; Thu, 7 Oct 2021 15:39:19 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, richard.henderson@linaro.org, Eric Blake Subject: [PULL v2 09/15] job: Do not soft-cancel after a job is done Date: Thu, 7 Oct 2021 17:39:03 +0200 Message-Id: <20211007153904.445009-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007153904.445009-1-vsementsov@virtuozzo.com> References: <20211007153904.445009-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Thu, 7 Oct 2021 15:39:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: be69e6ad-d6d3-400d-cb93-08d989a8a0fa X-MS-TrafficTypeDiagnostic: AS8PR08MB6134: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RsS719LpBvbZM6Deu/s5f+93+YuLm1OZqZq51Cm0Ds96+RAnX2oklbNaQLhkTR6AVWZjE+moXYhlJkR7AXA2d3h+xiWMM+UkFrwkZhJ5N7ASk9j02lVV6hvkr0saBwohnMqBMHIqfC8bnRSLtjl4xV92F/zx80DZizc+E7txFQhl3jVil1zG35T0wzRUK4H/Ehf7Nlt6w+cwqWmz3qJE5aBmtuzJhiALxqE7oEwYzecLKF7E3HVJZkCFFqvcjE4EyFwxydrEIPpMBgupgEDsZ0Lzf8w66GQN98E5aFHBz6hQfB0SuCNnK76hCnZyYxs0SCuyx05/o2JQhnZsBLAlW5wSA8q+HawMp3WEDXpxWUbUq103nj7F+G2y8gR9/ayTCKyPTr4czuqrnNsWDpNOiw7ok1T0Hs5hLnMlywyALOjArg+kf8LRL5JofTuxUSjp865OaG/AST51Go/uIHo5+jiQEEgNooj7zE+EHjtPJ7yY+p4URT2V4JVGwt5D7YbTdRzqkb6xZrAGf9WeqDe0GQbOxKVUMOOa96eHaaxpnfGnb+jyLYgEt9diM0PXGeMU1yllCUV2WbhMIBUWvPFvuQ5Y3wNyn0j0BghRlEPdAzNjXgESKtigA4CsFPP1X8Z6tTGiaP/Sa9Ok0nyZf4x1QjwUOsCjaJ2Mcl9dMYCkyC3x+sPhHx0ncGSjSHlK6YX3v6tJlH37LG5ufQyjWl6wxA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(36756003)(38350700002)(83380400001)(6486002)(2906002)(38100700002)(316002)(508600001)(4326008)(6512007)(8936002)(86362001)(1076003)(2616005)(8676002)(5660300002)(6666004)(6506007)(66476007)(66556008)(186003)(52116002)(66946007)(956004)(26005)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VPCjYrw+5tfJYb7PNYHpScoJEudEIQzM4YmtiOfXBLCxbumLIX3cv0GfKWETDWa8mPgToxIoIazQSHrlGP9yAmOL1KNJcTOIr5zIEakiguKE+tHGGB9kVsngYAyYC2CphCDQLzxmJz9quglFpPYXbeHR37+WvxE5eLxc0vechLttFLfINf8W6dDghsdGEJwoFt9eZDXxfHsqVCNE0qhqIBCi0Kx3f7EG4JGEEmUZDJ70zmbofXoLaLOQIFuOYvsQXtWFblkOUxR8HB0JHtPGbE1cED6QtqyGXdhT/L8FiHhqysFSUI2M/diAczjJzTRN5xPvDNVMuY3ffJdkl2otrAFnROQI3TX8pwUZ+n/OT2BLjPAn++pzxhL5DIqk1m1tXDUmGvyqHWxbYwoNW4CDZcemsNGRjrjSqFW6NdV0gLSuybVXZsEOmIghIy8+4UWGfVU5JB18sQxvOB8Dv+qa0D1RdxrXlejqJg4AhqWf6R/OLqKxB1d9m4gieiDAObTCh5xJ2NH6jTJEmE1g1RCpObqsiKAHOBRyvr2el99EU9w95HllFCjxGuc9A9vWRUvWjvutREHmPr2T2Q7C/oA/sevGc2QJu9sRCA1loxVs3QXVOXckyoumeX0LhAj09P6ig2CQHMucJPp3UveXzyOtta8bbxc0CJfnJGcl/ukrAV6kharyzYzksxZPSqdVHuG5kBjHDiXtryKMc5aU0TEm9xcAB1M/OcsaPWy/222ifrsH0F4A+ln9WYAOnLf2/lX8 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: be69e6ad-d6d3-400d-cb93-08d989a8a0fa X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2021 15:39:19.9321 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RNwUD8DIEAoKnT/6bJppkPDCWIic8LYmUMGc+41g8+ASy+7LX8FZPT4esxVKmQCXRdNk6ZdMbDLl0cENwwqvPNCIpSsMdKJtjKXrpXXJA1E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6134 Received-SPF: pass client-ip=40.107.22.122; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Hanna Reitz The only job that supports a soft cancel mode is the mirror job, and in such a case it resets its .cancelled field before it leaves its .run() function, so it does not really count as cancelled. However, it is possible to cancel the job after .run() returns and before job_exit() (which is run in the main loop) is executed. Then, .cancelled would still be true and the job would count as cancelled. This does not seem to be in the interest of the mirror job, so adjust job_cancel_async() to not set .cancelled in such a case, and job_cancel() to not invoke job_completed_txn_abort(). Signed-off-by: Hanna Reitz Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20211006151940.214590-8-hreitz@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy --- job.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/job.c b/job.c index 81c016eb10..44e741ebd4 100644 --- a/job.c +++ b/job.c @@ -734,9 +734,19 @@ static void job_cancel_async(Job *job, bool force) assert(job->pause_count > 0); job->pause_count--; } - job->cancelled = true; - /* To prevent 'force == false' overriding a previous 'force == true' */ - job->force_cancel |= force; + + /* + * Ignore soft cancel requests after the job is already done + * (We will still invoke job->driver->cancel() above, but if the + * job driver supports soft cancelling and the job is done, that + * should be a no-op, too. We still call it so it can override + * @force.) + */ + if (force || !job->deferred_to_main_loop) { + job->cancelled = true; + /* To prevent 'force == false' overriding a previous 'force == true' */ + job->force_cancel |= force; + } } static void job_completed_txn_abort(Job *job) @@ -963,7 +973,14 @@ void job_cancel(Job *job, bool force) if (!job_started(job)) { job_completed(job); } else if (job->deferred_to_main_loop) { - job_completed_txn_abort(job); + /* + * job_cancel_async() ignores soft-cancel requests for jobs + * that are already done (i.e. deferred to the main loop). We + * have to check again whether the job is really cancelled. + */ + if (job_is_cancelled(job)) { + job_completed_txn_abort(job); + } } else { job_enter(job); } From patchwork Thu Oct 7 15:39:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12542147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 375DDC433EF for ; Thu, 7 Oct 2021 15:42:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6DA15610EA for ; Thu, 7 Oct 2021 15:42:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6DA15610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:58892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYVXm-0005mG-K9 for qemu-devel@archiver.kernel.org; Thu, 07 Oct 2021 11:42:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUp-0002uX-6c; Thu, 07 Oct 2021 11:39:47 -0400 Received: from mail-am6eur05on2122.outbound.protection.outlook.com ([40.107.22.122]:51642 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYVUl-0008Og-35; Thu, 07 Oct 2021 11:39:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mPY46pRvQGPCOwA46I1lsvSfPUwZ8Cp+X9FZXxln7orWVfCe3dAnLY82MpHpP6UEQ0UMNCCBssidCaXx6zydV8LkNcGb2+S7RqFaQvJbm6mS767QODsHUbz2iWHE9UJ+Z9fh3GGxvpLVcNMAkRIfkkwoXObMHdXYlYFSOgLBstFwHUdzWk1CzGQPTrNycxxPRvmF5TDZos/C4dggFx5PPXcnsX9BRhJVAmwehKa+HyA/ydKtC6KEfYI/SyHg/XctQbH1PuIpAjxjDlK0EEl7ssfyULYbz0VA9rEls5ZHvYX0MW/KPf/qJMyfP6q7QPJ7TNy5giR5m++6g7Jteu0IgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MrCl9AWb819mRfRhUPO2Xpx6fLXfgyodSuyh6gW/ZOY=; b=N9N8tNcjGO1/kpim9aoMALDOL30gWgPZ77QQ6VRHjccEC48/gQVsbbC/BSthN/+En31yX/5ra7wW7Cq4gGdq+TbWnMv4whHmWesX/Z8D/bs5kubRH9YBm09l+q6qpFqIspTP92IEkmd+a1SBTZgFVct64GLGYmr/w7fja+29w4THkSlPddlnV19yMatw+glQ+MMlSXN3bVMh/MqkXV+/0VSK4o+y2LZtRFcApVMsbDwsv7SG6HzhJGmaGA6Iknyc2aqQ9XJb+jCyHs6ZApbGGT2j+X9N8GGIdEarEjZ5Sj/OSVGESZNI28QDoWnUYwpDkttTd6NBkLIp87QKnuPnEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MrCl9AWb819mRfRhUPO2Xpx6fLXfgyodSuyh6gW/ZOY=; b=czLvlsMyrLnaW9p57PYkrUlPvjy0XS/lB6HtHKxL5EpK08T49G8+HRHn40Ubtug+HkRCPLJN1v5lLh1TcdOFfQok5mzZT/s5/PYLE76Yw0iYj5bWwjiG1vUsOVW7rpDJcl2AXyj2esL+eFkQh9QACpjJldUj84tlGN+11TCTMY8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB6134.eurprd08.prod.outlook.com (2603:10a6:20b:291::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22; Thu, 7 Oct 2021 15:39:20 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4566.023; Thu, 7 Oct 2021 15:39:20 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, kwolf@redhat.com, hreitz@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, richard.henderson@linaro.org, Eric Blake Subject: [PULL v2 10/15] job: Add job_cancel_requested() Date: Thu, 7 Oct 2021 17:39:04 +0200 Message-Id: <20211007153904.445009-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007153904.445009-1-vsementsov@virtuozzo.com> References: <20211007153904.445009-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AS9PR06CA0347.eurprd06.prod.outlook.com (2603:10a6:20b:466::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Thu, 7 Oct 2021 15:39:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 88937bd1-08d8-4d78-b4bf-08d989a8a14a X-MS-TrafficTypeDiagnostic: AS8PR08MB6134: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:800; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g+vsMMQlhDci9sjEd7zshIg/HlVuXExApTriZHTWuvQ747I4euZcrvvgbVz/Uoa0Rkremo0Z34OYHvUin9CpLQRM8wo8HTwxpRjSQoHOSiEVbw04re//K/Gi1TNXIff5llOormiJH+49LrISDCoEJnInoUzx0F0Xbo/+rw6TT+a51zg+6hFjtSHl8dUi1QJvlgEipF3x3gFoUdH8EPoyyEmxi4oQzM+UG3uwzOKfIUu0GQSG5HnMRalNRmvGqDy9wZH6PQRUFL+Mb4z5h8LzCqBocidu0YnN7p1W29F3v6+dZBX/+K5ttOTlf4bipAGMjzLkmpi/B8t23k2TA4njp+kENURsxMhnETAeN2idD1R/2pAFKD5SZoJRst3/JNMVhCf8MUs7mnHj8CzQJR4OM1MNsg80ESFV9ymFka+ZCXS9GQ4vC6vZBk4nA3W1Gih5r7hy/prMJgPERYCtH3rJANVCKek+Kt7c464AVLUY5Wm8WLHPvjkMSI547CnPZhlDDBQ9m+PtIL701J5h3DA+yw727LmoDMWvHomdpCRBAopB/X+KYwUugWGXhxccg7AJFpi/d3rhsLBR7ucGnspXIbHEkNRmqDO1p4fMp7Pd1pEkFn63kYlTsX0r2fhNm1TFgCHxLOhNpaTisH7AgOF3+pWNiDK2ZRXBlLAH3Px4p080PSBPo+vYx4Dg1++ou7vkucSqYdEVH02ihP2UW4R7xcyba6UfL4+QF0Lb8IFuh2Q77+ce5lojTqZVdrTLUSfy5WsJr1D+IVrjrqw88KTHZx3425E4KeZquy/dcrt8mwM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(36756003)(38350700002)(83380400001)(6486002)(2906002)(38100700002)(316002)(508600001)(4326008)(6512007)(8936002)(86362001)(966005)(1076003)(2616005)(8676002)(5660300002)(6666004)(6506007)(66476007)(66556008)(186003)(52116002)(66946007)(956004)(26005)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VUxMTUh0JBoN3t9/3iikwUb44OELLxOer0ADQ6Q+EPDySGt2++vMRx+9Xornsove3CgdBkMmzMaY5PVbgIN4ecIc1573aN2LQPHEkAwhV8IDpKIC32jqdctSEe6D0G/+Yn9fduSTus9ZYwAyK3fbDfEdMOV2yeax8QghzokhQGO+yqN5feJLrfy4myU5GRfQLwcOD3X2ohIJwr5xlh9bhLbhYjOlkq2bwOpR7484V8TykdOplx7KR387jHF4IpL5Z2LrXrZ7vir2j2SfPFuwXKr6iaaS4Xe4MMDHLu4bDmKfrYSxRX0nZhQmGfgG8Mw5KYd/EUrgclrX9JXG/yU1ANr+6kY6WVGiJq00B1O8RP4Ta+WxP5Jm4xvJkF8v4sstM5lwNbm0jq9TDCjFSI6INEkE7LGlnLZl2ok7OEffKTJmhBNPLLxZ3lpJYi0G+99pglQrCHSevApXy9X3IQWhM7s7C6A/9E+l6hlghz618Zt7khIaZl7mukvKIkmnVa8SSA4h7ekii843xuq2M9pPyprCURsebF+3ER6mxnZpCV1q74tvhtCXJcgNr5Y+Jrt32ltPGdd9U3Bx9K4DITbKVKqwfdHvP2mUDAZ/vJqFC8KKHFf9N5FFAfg6/cpuIPCgwnG9RZKREmvOvojEK4YIZ6jgEpmqYgK3gi22fsWh6pQ+Apbs2m9zrIgAncz0wNizB6MHDZqhsaQMgfNDHlXb3MU4USC/XAQbTDkjIao2hdp2g12054NwNMQRWZ2aTHSw X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88937bd1-08d8-4d78-b4bf-08d989a8a14a X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2021 15:39:20.4887 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1GgtNIRmqdJGY/+pleKWnicsn8brTqxmY6W1q2CE/+l6qr3VbIgHWQe7Emf+xlvf5fNdjp14esfZhSInYeGfcL10aFyoabbGHAQzkx4Fpfs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6134 Received-SPF: pass client-ip=40.107.22.122; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Hanna Reitz Most callers of job_is_cancelled() actually want to know whether the job is on its way to immediate termination. For example, we refuse to pause jobs that are cancelled; but this only makes sense for jobs that are really actually cancelled. A mirror job that is cancelled during READY with force=false should absolutely be allowed to pause. This "cancellation" (which is actually a kind of completion) may take an indefinite amount of time, and so should behave like any job during normal operation. For example, with on-target-error=stop, the job should stop on write errors. (In contrast, force-cancelled jobs should not get write errors, as they should just terminate and not do further I/O.) Therefore, redefine job_is_cancelled() to only return true for jobs that are force-cancelled (which as of HEAD^ means any job that interprets the cancellation request as a request for immediate termination), and add job_cancel_requested() as the general variant, which returns true for any jobs which have been requested to be cancelled, whether it be immediately or after an arbitrarily long completion phase. Finally, here is a justification for how different job_is_cancelled() invocations are treated by this patch: - block/mirror.c (mirror_run()): - The first invocation is a while loop that should loop until the job has been cancelled or scheduled for completion. What kind of cancel does not matter, only the fact that the job is supposed to end. - The second invocation wants to know whether the job has been soft-cancelled. Calling job_cancel_requested() is a bit too broad, but if the job were force-cancelled, we should leave the main loop as soon as possible anyway, so this should not matter here. - The last two invocations already check force_cancel, so they should continue to use job_is_cancelled(). - block/backup.c, block/commit.c, block/stream.c, anything in tests/: These jobs know only force-cancel, so there is no difference between job_is_cancelled() and job_cancel_requested(). We can continue using job_is_cancelled(). - job.c: - job_pause_point(), job_yield(), job_sleep_ns(): Only force-cancelled jobs should be prevented from being paused. Continue using job_is_cancelled(). - job_update_rc(), job_finalize_single(), job_finish_sync(): These functions are all called after the job has left its main loop. The mirror job (the only job that can be soft-cancelled) will clear .cancelled before leaving the main loop if it has been soft-cancelled. Therefore, these functions will observe .cancelled to be true only if the job has been force-cancelled. We can continue to use job_is_cancelled(). (Furthermore, conceptually, a soft-cancelled mirror job should not report to have been cancelled. It should report completion (see also the block-job-cancel QAPI documentation). Therefore, it makes sense for these functions not to distinguish between a soft-cancelled mirror job and a job that has completed as normal.) - job_completed_txn_abort(): All jobs other than @job have been force-cancelled. job_is_cancelled() must be true for them. Regarding @job itself: job_completed_txn_abort() is mostly called when the job's return value is not 0. A soft-cancelled mirror has a return value of 0, and so will not end up here then. However, job_cancel() invokes job_completed_txn_abort() if the job has been deferred to the main loop, which is mostly the case for completed jobs (which skip the assertion), but not for sure. To be safe, use job_cancel_requested() in this assertion. - job_complete(): This is function eventually invoked by the user (through qmp_block_job_complete() or qmp_job_complete(), or job_complete_sync(), which comes from qemu-img). The intention here is to prevent a user from invoking job-complete after the job has been cancelled. This should also apply to soft cancelling: After a mirror job has been soft-cancelled, the user should not be able to decide otherwise and have it complete as normal (i.e. pivoting to the target). - job_cancel(): Both functions are equivalent (see comment there), but we want to use job_is_cancelled(), because this shows that we call job_completed_txn_abort() only for force-cancelled jobs. (As explained for job_update_rc(), soft-cancelled jobs should be treated as if they have completed as normal.) Buglink: https://gitlab.com/qemu-project/qemu/-/issues/462 Signed-off-by: Hanna Reitz Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20211006151940.214590-9-hreitz@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qemu/job.h | 8 +++++++- block/mirror.c | 10 ++++------ job.c | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/qemu/job.h b/include/qemu/job.h index 90f6abbd6a..6e67b6977f 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -436,9 +436,15 @@ const char *job_type_str(const Job *job); /** Returns true if the job should not be visible to the management layer. */ bool job_is_internal(Job *job); -/** Returns whether the job is scheduled for cancellation. */ +/** Returns whether the job is being cancelled. */ bool job_is_cancelled(Job *job); +/** + * Returns whether the job is scheduled for cancellation (at an + * indefinite point). + */ +bool job_cancel_requested(Job *job); + /** Returns whether the job is in a completed state. */ bool job_is_completed(Job *job); diff --git a/block/mirror.c b/block/mirror.c index 010b9e1672..2d9642cb00 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -943,7 +943,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) /* Transition to the READY state and wait for complete. */ job_transition_to_ready(&s->common.job); s->actively_synced = true; - while (!job_is_cancelled(&s->common.job) && !s->should_complete) { + while (!job_cancel_requested(&s->common.job) && !s->should_complete) { job_yield(&s->common.job); } s->common.job.cancelled = false; @@ -1050,7 +1050,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) } should_complete = s->should_complete || - job_is_cancelled(&s->common.job); + job_cancel_requested(&s->common.job); cnt = bdrv_get_dirty_count(s->dirty_bitmap); } @@ -1094,7 +1094,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job), delay_ns); job_sleep_ns(&s->common.job, delay_ns); - if (job_is_cancelled(&s->common.job) && s->common.job.force_cancel) { + if (job_is_cancelled(&s->common.job)) { break; } s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); @@ -1106,9 +1106,7 @@ immediate_exit: * or it was cancelled prematurely so that we do not guarantee that * the target is a copy of the source. */ - assert(ret < 0 || - (s->common.job.force_cancel && - job_is_cancelled(&s->common.job))); + assert(ret < 0 || job_is_cancelled(&s->common.job)); assert(need_drain); mirror_wait_for_all_io(s); } diff --git a/job.c b/job.c index 44e741ebd4..b0cf2d8374 100644 --- a/job.c +++ b/job.c @@ -216,6 +216,11 @@ const char *job_type_str(const Job *job) } bool job_is_cancelled(Job *job) +{ + return job->cancelled && job->force_cancel; +} + +bool job_cancel_requested(Job *job) { return job->cancelled; } @@ -798,7 +803,7 @@ static void job_completed_txn_abort(Job *job) ctx = other_job->aio_context; aio_context_acquire(ctx); if (!job_is_completed(other_job)) { - assert(job_is_cancelled(other_job)); + assert(job_cancel_requested(other_job)); job_finish_sync(other_job, NULL, NULL); } job_finalize_single(other_job); @@ -977,6 +982,11 @@ void job_cancel(Job *job, bool force) * job_cancel_async() ignores soft-cancel requests for jobs * that are already done (i.e. deferred to the main loop). We * have to check again whether the job is really cancelled. + * (job_cancel_requested() and job_is_cancelled() are equivalent + * here, because job_cancel_async() will make soft-cancel + * requests no-ops when deferred_to_main_loop is true. We + * choose to call job_is_cancelled() to show that we invoke + * job_completed_txn_abort() only for force-cancelled jobs.) */ if (job_is_cancelled(job)) { job_completed_txn_abort(job); @@ -1044,7 +1054,7 @@ void job_complete(Job *job, Error **errp) if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) { return; } - if (job_is_cancelled(job) || !job->driver->complete) { + if (job_cancel_requested(job) || !job->driver->complete) { error_setg(errp, "The active block job '%s' cannot be completed", job->id); return;