From patchwork Wed Mar 2 16:24:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12766281 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A3EBAC433FE for ; Wed, 2 Mar 2022 16:29:44 +0000 (UTC) Received: from localhost ([::1]:39376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPRrD-0004WW-Oj for qemu-devel@archiver.kernel.org; Wed, 02 Mar 2022 11:29:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPRmi-0003pF-I4; Wed, 02 Mar 2022 11:25:04 -0500 Received: from [2a01:111:f400:fe06::70c] (port=37767 helo=EUR02-VE1-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 1nPRmg-0007je-PB; Wed, 02 Mar 2022 11:25:04 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uyzj7np9B8YdAuCY808H9TXHMUYALVnzpkL/b955jGR6AxBSYt8QrQ+xnBe2uqV5CbdXAlBvlXCAGr77NF4kxi1IR38oLXX2pRvFM5Limeqn4zf3N3w/E+ZYT55C0SF6NUfPaKsKK6TnHulO84+kzzgIe0LH0wha5uPUgVVgb3+17TP5FJ4aV8qpJcRYdaQSeqiL96BUYL9i4OEDHhVtpMrH0aelqIYmTh1iKj/NQOX3WgNAav7hyd4k4eQLaalHb+Y4qzYpk4w8lwiZUQVSSgS6gVYeVzlk6bigt2GAsN9HAYTUWKGgQA/0DXVS9UNNSX2mAy10HK37TJCf1uYvQA== 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=XjcSN+V7jUg4BbTkha0e0lrczm/uPm0NWYIfzxn6CTE=; b=mc/sx2EOcVBB2fqJzcXlMcwRCeamucW6Nar5tiQczHGRkf06xIyGZTmtwaknX8sHgu6offNNwp2DIjBesnv/mbjAsEHmhrxZv9ANGeNngjIlokMLlgcMH4QXst/NV2Hixj1r3TtQQL5oXeI7/fwaBV0afymOOPEkqM5F0E1u5ktqpERmJBukpKBweAEH/c8nWyCmTc3SkZUm3bQ7f1NR8RYv8ilwFEedj2s/J6hm9jWQBTXMB5txepZ5CiGYZFpLfuM4k1H6oZvv87QwmDGRBIyjjCVdSqg5K2tscOe/VgXDac4NFjKA2QAfJrQ4AGvcdTrl0WKR50CFsMgVPQxNdA== 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=XjcSN+V7jUg4BbTkha0e0lrczm/uPm0NWYIfzxn6CTE=; b=d7r4zMyS/GygVWI73AYHwzBeeVffgGQOnzqAFjb2l1K3qGiBkk9tBe+J6RwWn/dq3NNkt3CaJbKVeyPFRKCSpzYoOCKlHC4URrYCxrIbNWr+HgbG9gXXhMwa8WVsc6hgggyYj96jMP94tomTYgDVG1sAo/gkLcaADMlBGzd6Qfw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB3206.eurprd08.prod.outlook.com (2603:10a6:209:46::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.26; Wed, 2 Mar 2022 16:24:58 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d%5]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:24:58 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, stefanha@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com Subject: [PATCH 1/4] util: add qemu-co-timeout Date: Wed, 2 Mar 2022 17:24:39 +0100 Message-Id: <20220302162442.2052461-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220302162442.2052461-1-vsementsov@virtuozzo.com> References: <20220302162442.2052461-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: ZR0P278CA0064.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:21::15) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16b0ae5b-f440-4671-6d20-08d9fc6930f2 X-MS-TrafficTypeDiagnostic: AM6PR08MB3206:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x9CE0vir1WqKPtzherXgqrLQcNf3PI9ivHRLVh1mC3KDRmNa3bVldvYV/0viAmH9dnvqNPB/wCsVpm6jTcqvBABWlsRgeee96PhnW5V+25kRJIYqkbmNRorDbZu0DkvKaZH438CjWJINroYvLHcnGBni35gJa5eAKZQM6EyqFluQ188pB3c0uRfEUoLZeeScYaVO/s11vP3mzE23jSHC7/M1xFw9CU9Ezr7hOFFjF3n14i3yS2W7PtVUkouYmXx/ISGjSv2snBgK6IpLgIXXfw94QyIYKWlKD4vB3KSKK1067bIm2o2CQJ537t9Rrmcj8cQhxkIW27nfJPgdbaVGPHik6NL5kc9RuXIzdhpwOLczdcT0vYSu3tKylxuQSYzJ9KEqp2j0u0CoFGVWyiEAQamBAVgSGcjXuY98+P0qrS5bXF6b3AvE3w1ECrWc4jfCEgMhmirmf0QM76H5jxc+tYia2oN25fz411J+e2Gdg1haDaiD1yR9d6ymyDN0wt7htBdL9A9z7zjV/00GdWATQz9NzjYZFbWIPdvCYrhm4VLF5cPHVzwR01lfSBJKVlcvP5okiwpRTaI1ZT/T4K3S7ApuKZZdwUjlIAa4iKjqosIXu+3Om0a3jOYn31zrKOpr/uQSkp9rnsDTHHIvFUohHLGmpuCoyVSvCf0xoV0W0fjqj9Ys6qWMugbO7Rj2zzF+A9HGsyk5HLjyuPA+SWPY0Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(66556008)(8936002)(66946007)(66476007)(4326008)(86362001)(83380400001)(38350700002)(316002)(6916009)(186003)(38100700002)(1076003)(2616005)(26005)(2906002)(52116002)(6506007)(6512007)(6666004)(8676002)(5660300002)(508600001)(36756003)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jqzlDyE6eEqnbqesL4/8EMEp64lN/d7gnPr9h1EfGIoz36J7mzAEcumWqzaJg1vIriOlcG3CtC1m2HalT5MQ1qBgNIJL8TtxmAYyl6iDcORHb316rRSq1pNGrYYUUcu7O79piYxDsZgR22xzCGZnA0E0PlP0E2NKSSOZhafTI7pTpNEVahnneWkD85OUdzerYuiIhEaFcfnuuc0sKH3QEJsz2MiPAfu0uCXqjvAmPtNDIUvEjKJa5PHaxQWQ5DK/wRcNL0cs5STKsU2yeL3RMn9lHAQ44+07ZW8K08c9xQeWwiwMpOn01mM1SlQIrJnQtuoGSflEroFkXsOre3ktVpYvY4TuZ76QfnGgifogNrhhs4R+6lHofXKx+m3ESRu7BjSr2eT0aIVuY1Mxcd8oRJbkvcYpXoX4jnZDhf5/nRJhvh/PZ/kiCspuYhEamwt2OPz0nKOPDWhWO96mLAK8l9eS4vachRR1XuaEzwXV4xpRhfuJqHcgHi+pGs83eLPNYDn2bc/faCiNIwYYycxCZUgwg/TgFl1zcQgt1Otc6Z97UXC9bjWUQo8qIqKuRFDfeEx6MsQ9ClIn8r7u2tnx56LBEMLJDJnoSMRTv3wu+3Umt2xZEUx/he9HL05g93uoAC49m/WQRsQYk7sRTSKmToH25SVhJ0a/4qAE4jMx5Q5731JRfO+8iULYIB/IMvBZA5j4W1hvAnma/DoVO1blBa46iHGzy1998A+pgNv+3mNhK9HmVPxzis39bTdg12gLXo5PF42FYO44QQQ0X6w/xYw+Im6cuk9ADBx0CzLYGbSBSo4PZWCRs8oocFv5/5U4ahqeGjbZ343QT8fRhIJlHeQwstmCckG093mgR5P2vsOIK0EK/VMJgVJUjMlfWnlSXycbQUcMCEQSXYNZIcl1s9PVIVYqAiwx/g1dIQV6xuCrpzs4Pkeck3LEYap0TmBWSqgibJV5Mhyv6LRaAHieuOOFiolxr629Wl5YbprIhyRTQudvlvOHfStgKvF4MRqTIbUIWBgRCUTke0rNd/xqxQb40hCjqDqhtSC+xgS2aYJGrwK0bTF7NR4n/zvnqo+lztCnBSnpMASfd9fLca+S7T72Pv1iLB4RkeCc6EQxEGKbMIQ3lXqfgLzqsnck/EWFK7s0I4LKds0yJ2GYrEX+koZNFpFSdQesrVpHUFK77ULEsAne4P/1emKvIF7Na2NB+1J4r8EGvsaOhz4LUtBXXTh7PZURVad5AtsargrtY6tIq1DJ1+8Lplqq0ZG0Oods/Ot1l0bLUgLAODIINoFlWkKSy16cutv2XC4Y/rkrn00MU86kpdQVeoc34Nd2uP58+tQOveJMpFtGSh3yOqR6avN/r4vWDl18ne7zAZpjJrqmASK7v3ca0dH+t8zTK6tzXZO0IN47gd50fKOhzu6/tMElqfD1gjKtI9HnKF+qXHhlxgUJKNZn/XPYrUh9t+ktUmU9Okg3hjBhET9okBR79vgD8FpF9IjwOlLUqbnZAibgIBiRtKtZeEAaIGjE7gp39lGBNePtv3WL7VuArVeXOkUgHdhkr5bsacYMiDvCN/xc0DH7Btyx93iha+vfe5QijVuL+QVrIma5KEeyS0QGlhnK6jRup3f2HhVCa4m+IQhJaU6ODQBeBqqxLpEHId3iJHmyFFL8DEXISnOCthQ9Ow== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 16b0ae5b-f440-4671-6d20-08d9fc6930f2 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:24:57.5251 (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: z4YnvX0gq/yFgxfSWl8eaQD57hGVtHWm9Zdw7z43Qq5Ox5zvVPud4qm6aGx+Lrjo12vsFC+g9KApRehEmot4llG+Bw1YlJJOAyPwnYEW4TU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3206 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe06::70c (failed) Received-SPF: pass client-ip=2a01:111:f400:fe06::70c; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Add new API, to make a time limited call of the coroutine. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qemu/coroutine.h | 13 ++++++ util/qemu-co-timeout.c | 89 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 3 files changed, 103 insertions(+) create mode 100644 util/qemu-co-timeout.c diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index c828a95ee0..8704b05da8 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -316,6 +316,19 @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) qemu_co_sleep_ns_wakeable(&w, type, ns); } +typedef void CleanupFunc(void *opaque); +/** + * Run entry in a coroutine and start timer. Wait for entry to finish or for + * timer to elapse, what happen first. If entry finished, return 0, if timer + * elapsed earlier, return -ETIMEDOUT. + * + * Be careful, entry execution is not canceled, user should handle it somehow. + * If @clean is provided, it's called after coroutine finish if timeout + * happened. + */ +int coroutine_fn qemu_co_timeout(CoroutineEntry *entry, void *opaque, + uint64_t timeout_ns, CleanupFunc clean); + /** * Wake a coroutine if it is sleeping in qemu_co_sleep_ns. The timer will be * deleted. @sleep_state must be the variable whose address was given to diff --git a/util/qemu-co-timeout.c b/util/qemu-co-timeout.c new file mode 100644 index 0000000000..00cd335649 --- /dev/null +++ b/util/qemu-co-timeout.c @@ -0,0 +1,89 @@ +/* + * Helper functionality for distributing a fixed total amount of + * an abstract resource among multiple coroutines. + * + * Copyright (c) 2022 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/coroutine.h" +#include "block/aio.h" + +typedef struct QemuCoTimeoutState { + CoroutineEntry *entry; + void *opaque; + QemuCoSleep sleep_state; + bool marker; + CleanupFunc *clean; +} QemuCoTimeoutState; + +static void coroutine_fn qemu_co_timeout_entry(void *opaque) +{ + QemuCoTimeoutState *s = opaque; + + s->entry(s->opaque); + + if (s->marker) { + assert(!s->sleep_state.to_wake); + /* .marker set by qemu_co_timeout, it have been failed */ + if (s->clean) { + s->clean(s->opaque); + } + g_free(s); + } else { + s->marker = true; + qemu_co_sleep_wake(&s->sleep_state); + } +} + +int coroutine_fn qemu_co_timeout(CoroutineEntry *entry, void *opaque, + uint64_t timeout_ns, CleanupFunc clean) +{ + QemuCoTimeoutState *s; + Coroutine *co; + + if (timeout_ns == 0) { + entry(opaque); + return 0; + } + + s = g_new(QemuCoTimeoutState, 1); + *s = (QemuCoTimeoutState) { + .entry = entry, + .opaque = opaque, + .clean = clean + }; + + co = qemu_coroutine_create(qemu_co_timeout_entry, s); + + aio_co_enter(qemu_get_current_aio_context(), co); + qemu_co_sleep_ns_wakeable(&s->sleep_state, QEMU_CLOCK_REALTIME, timeout_ns); + + if (s->marker) { + /* .marker set by qemu_co_timeout_entry, success */ + g_free(s); + return 0; + } + + /* Don't free s, as we can't cancel qemu_co_timeout_entry execution */ + s->marker = true; + return -ETIMEDOUT; +} diff --git a/util/meson.build b/util/meson.build index 3736988b9f..44392e89a4 100644 --- a/util/meson.build +++ b/util/meson.build @@ -82,6 +82,7 @@ if have_block util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c')) + util_ss.add(files('qemu-co-timeout.c')) util_ss.add(files('thread-pool.c', 'qemu-timer.c')) util_ss.add(files('readline.c')) util_ss.add(files('throttle.c')) From patchwork Wed Mar 2 16:24:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12766263 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 30282C433F5 for ; Wed, 2 Mar 2022 16:27:08 +0000 (UTC) Received: from localhost ([::1]:58304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPRoh-0006gi-6f for qemu-devel@archiver.kernel.org; Wed, 02 Mar 2022 11:27:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPRmi-0003np-6a; Wed, 02 Mar 2022 11:25:04 -0500 Received: from [2a01:111:f400:fe1f::70e] (port=25703 helo=EUR01-VE1-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 1nPRmg-0007jt-J6; Wed, 02 Mar 2022 11:25:03 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jNmqMwBsnHNgSZY3tY/i7Uj6zhu6ysTY/mmK+cD3zCoeD/pHseVpSgvuOFKsxCUiXdxfYOXNBoVwJR2aqPRHcKtlbB298/NLr1jwCFpOYeAY1zHGL0tecoxJQ7IsplCdrQeTBqpVynulwVPfKN3teId0S+/hdgWui1NKeCAQbxYpMI0OwGOFY9NmmMunDenrs55tOMCzd6lZaqI7nV1oim8AUjsZPpmyHiBltnkC05G/bQAgnCXWiq7KDzsXnaRiLk0jFmaz6ApUJBhSNZKWCCb+D1/v8KnmnovyPVRg0P4OT9NJ8jIyR/auyVbfYi0xYd+6VW0ppb6QKYSZfez7hg== 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=SA/MsKR4rymW0A/gq5E0zSziC2COtExe8DXeN45nriE=; b=IyJzbeCj8dNnDxu9kHsAQ/SfzaG4hNT/KF/ts+DQeQBS9um0l09rze7nwOrHhkJP7R9iUH/7lvPZToyB21BocX6ysK4vX9fOVMcOoAFRrvsgT98kTpI8N54ldhLDrnJy6yqZvquq3NpUFrG3IhcPl1gYooHHCwnCaM/VyKNmI9ixyRwo5X2QpSzPO8qNzBLNlWlutFY5lvivBkrwvQBEjWDEBRTHL7oxAI/8sKBJv2kIv851vvtmlL8xX37q2ZWJpvFzCmMKu28E8WfyUq7bAertCuMp65dZ4E6sBhNE3ge4cGLBxzH0Bn1vekpf6o7espbSDyHm0e7fHW5jDC+S4w== 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=SA/MsKR4rymW0A/gq5E0zSziC2COtExe8DXeN45nriE=; b=e0b5qtTbdfu3h1+aKYy6fGw3AWw3G4jpkhs2PvLEx0odQ0feXWkAEew5XaC685VGDVU3QZ546urzs3uiRALlLs7iQC8cPxaqJfjt2aXhiryX2gJTxx8nSaQYkv6gIxysrcmsqS5Un5qgg1lFeTwicVl7gahYSKVn7DmzfLa0HW4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB3768.eurprd08.prod.outlook.com (2603:10a6:20b:90::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Wed, 2 Mar 2022 16:24:59 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d%5]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:24:59 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, stefanha@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com Subject: [PATCH 2/4] block/block-copy: block_copy(): add timeout_ns parameter Date: Wed, 2 Mar 2022 17:24:40 +0100 Message-Id: <20220302162442.2052461-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220302162442.2052461-1-vsementsov@virtuozzo.com> References: <20220302162442.2052461-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: ZR0P278CA0064.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:21::15) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 182dc62f-bbd9-4e20-e0e8-08d9fc69322f X-MS-TrafficTypeDiagnostic: AM6PR08MB3768:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gy7e9WYKet3C2qkM+MiSVp0nsfFW9U7qw5gcxh8j3Agu9mI0pbYvG+2OuRmSAYkTIYWhe+GL4lRLzRAbF08B7wmOpcnhvb3bwpFe3KaIJ1uTvhpsL7eNODSltLlhfBoDTFQC1jNLcLbpRln8prEbdAzkTSuPw0NPkjn+JH82LKw9bGWDO6j/VPw8ydcShn5Re8hpHM3o5ckUKo80zVoA6mtvdyebh17uMrQcUg7e1jDEhqxeojLH/S5d3jmCSEZZs6D+jit6RZU6mo59XkAlXwsHzAVCFvfX93e+1L9s9PrElIIndQGEQ3xTzKjm5tsNMT4kcbIGkz/8Y7mrbOzZLlzlz8X1TOXkZMsjJCNgMag0KHJFUjS2X3m3q1tw+1pxaB4DN2xE3cst3JZBZHLaSgn/bTUVacgdRxt/KjUh2a6/nPkM5YLoXObUi6pzVztBQ9yVq8Pg8T9/xG9yqR1O98TFEg6nzW8Dcblxnn17PYPzLZmAllFvb33LIlqt4Wcmx8pNU5fMHe4fNk3exbDXPMrGQGLJWWvEfIpxbaz+U/LmDQhmX+o9zAKYi5Y4uxvm0/m7dfI5u1d5S4W59ULn2aBPxANeze+077kZXXFz5Be3NEwrB05qLXzPy1LQbweSiyELO96nm6qf98jJL9PNFI5ChBNRhplFxvxDcCw/C/+JsDueRm7d+tJD1zdrobLQCLpaIeEm2JAP2+3DrEirwQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(26005)(186003)(2616005)(36756003)(8936002)(6512007)(38350700002)(1076003)(316002)(6666004)(6506007)(66556008)(8676002)(5660300002)(66946007)(2906002)(66476007)(52116002)(4326008)(38100700002)(508600001)(86362001)(6486002)(83380400001)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pB3ediXIhulBMvL85Y08NvsynlCarG1Zdnavj8NDjigNJwkb1dMUlkNBhjYRutWRTnMXhZ0vZzHjLLN/XpsrzHo7/MzmhDgcQFhh8AJIjz2mezdP5kO7ORHWdpmzgRn4qahCW2768d8cgV7Z1QLfwah1d96dLACVIgcQV59Y7ust8bfpJBVwLU6xOF3dcx/yyVrbwDEY/XCbQhq0C8MZITeoNqedW7Pk3fk+MJv3t1kiiGNZA8P1OOU3KQbBEiona6q8MILlAIeD2n8Rm524N1uEeQ5Cr0t/q2eBQFyybLe2TvbOgbpK1KRPetVRriiYuSso75ekGHRrGFPVYDNM3fVmecbYuj6Zx7b+EQuGY+l3OAyVnJc6WYRjEkEzfApzY/11OkKV/xy2MxE4Dur3b0AbazNYNQE5tdkXOMeJ4neeqQ+C6XwZPgrNuACvP+DxFVgfARTfxccFNUy3y+8qX8U4/I7J+wcOSKgW6vpvDHzzBqf5WWGbaq05LXtPCoy2xGdA8OYSwWyJIkgKOIRUE1OWKc4BO4N8OBInejkuqEMQ8zoCvUX4isAoje9B54MrB7DnhpqTEivXesgL0bU5HNP4BTMcCNTTZgSNlNsvQ4EO6ocpdlln1pwEDehbGJWL3aAU319RbAzWx9DJE378o3952s92obB8kyug5csT0v4d7uYpFVxy6SK3CMR5/JUxMRaHGJVUEv/njD0dlezDi6V9P+m+nvRw1WUK6PV2nPrez8zBl8wB+kZAssvuBXZyFY43ud9wJOZw+/pOn+d1LZsnD2uxaHEmEkE03bY6OwJQ1dGiwyTMkqLTOR3k4lEtz9kHDInMQvyshqTMmP0xjQhG2RnRxsQ0mRWR7PM8VbvTn3+PQyYc3nITqFmd95EJRkkwGz/Mi2smQk4ZebD1KhTgLFNlT55VvuGLaEmXKqX7kPVVFt/ViRwSdqDjKQ9OE/eMzGtOTy6I3H/db7HUAx6l0LqFs8WKjrTaHTeo8iMiylq9KdCXww9msAFLDIAYokh13B9sbcds8ppT99sZS5FnLjDB7Z6ko6MDHStPuaKbuF4OmbYNBMFQ9X872derOoxnojt02G55vCrwKpyEmKrobB3jquFeTDjH5+L+7o8qi1LJkSm1S+X3kZTLkarLcGDUgyhJiDcEM+lhDrThI/kPnGOHK2aJjd0vI8f7InaanwTEuteI2drSEXhNPhlGRRDPNPD1u+bnpL3vkMjlhmHa5svfT2SlloPPpU7mhIyggmf9C3Tb6K2sldH2P7HDVh3uL1ERZZnKZxkaKTm2nqu8H72pMCvtUSXXyNr3ZOLC7pOqYWMNaNtpM8AU423SoMyqSeALSwD2/qb/ha9ZNpbWFgP07TPO1/sdsFZ0VbdUanhfBjr6aFkfmCSx1IjMSgYdJVPfabbnUfwi/seLM79SZJ/BR22yzFJxdikqhjUbZHhxQvSfdQ2k2HRVJ0VWPCxEYSIKKWSZ2399fnFzaYUoTB01Px3P/c1Fd8+psmzoMS3ndpcW+0WNvab2ETcEfpySRc4yuJSneeNsx9Z//GZlcX/bcTpvnorsZH2zCFMWuR/LjRG8Ad9TjQ9TZRnnVZBsQSYDpYSAFjB24ZJBNUy2Bxqje0CIkjjSxxi9W3ZPaEWcNyBH8F7qsRO87NL0cNYCicqHwHcoubJnmw5sTg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 182dc62f-bbd9-4e20-e0e8-08d9fc69322f X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:24:59.4949 (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: 6xcIeuilRUyhlm0I016NiES+Qb+j9sWO1U+tL3uSJexzXrDkJ8l7ingI9YdAJhj73jRjyWe6zBHhudSrUKwqYY692NNkzLEER8A5a2YHY6o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3768 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe1f::70e (failed) Received-SPF: pass client-ip=2a01:111:f400:fe1f::70e; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Add possibility to limit block_copy() call in time. To be used in the next commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block-copy.h | 2 +- block/block-copy.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 68bbd344b2..1c9616cdee 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -40,7 +40,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes, - bool ignore_ratelimit); + bool ignore_ratelimit, uint64_t timeout_ns); /* * Run block-copy in a coroutine, create corresponding BlockCopyCallState diff --git a/block/block-copy.c b/block/block-copy.c index ef948dccec..e0f07e64ee 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -882,10 +882,18 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) return ret; } -int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, - bool ignore_ratelimit) +static void coroutine_fn block_copy_async_co_entry(void *opaque) { - BlockCopyCallState call_state = { + block_copy_common(opaque); +} + +int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, + bool ignore_ratelimit, uint64_t timeout_ns) +{ + int ret; + BlockCopyCallState *call_state = g_new(BlockCopyCallState, 1); + + *call_state = (BlockCopyCallState) { .s = s, .offset = start, .bytes = bytes, @@ -893,12 +901,16 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, .max_workers = BLOCK_COPY_MAX_WORKERS, }; - return block_copy_common(&call_state); -} + ret = qemu_co_timeout(block_copy_async_co_entry, call_state, timeout_ns, + g_free); + if (ret < 0) { + /* Timeout. call_state will be freed by running coroutine. */ + return ret; + } -static void coroutine_fn block_copy_async_co_entry(void *opaque) -{ - block_copy_common(opaque); + ret = call_state->ret; + + return ret; } BlockCopyCallState *block_copy_async(BlockCopyState *s, From patchwork Wed Mar 2 16:24:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12766280 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 395C9C433FE for ; Wed, 2 Mar 2022 16:29:18 +0000 (UTC) Received: from localhost ([::1]:37550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPRqn-0003Jj-AS for qemu-devel@archiver.kernel.org; Wed, 02 Mar 2022 11:29:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPRmk-0003w6-Nv; Wed, 02 Mar 2022 11:25:06 -0500 Received: from [2a01:111:f400:fe1f::70e] (port=25703 helo=EUR01-VE1-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 1nPRmi-0007jt-TS; Wed, 02 Mar 2022 11:25:06 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DGoZUdI74f+ooRBdpU9YH9pvKpXeJIqXVS0+M5yhR40KOUbyz8ARwVGfMGwr81YF6tOluaYjdux7WgkRMTH4Rg877NdlhpH5OSV2C5N/ifB9ehGd3xF7Qb0pQmAI/gRiWHoj4GMvjCIscubqpLUNeIH/ubA5/TSe3+F7xfad78OCkL3oR3BpazfMpOXGgcdZTV7TUK6FxF1THy0r2SkudDVQPOO8wqirOpXtfNyFcp1CWAuN1WQ90ImDLV0ZHv05+lQc6lF/MVA9LWWud+rQhGXN/OjFYBrYKpsU5sCh2mGgGZKzkdwGU/4+AbWjc/Zh/c9y/pfty01sviqXiWffvg== 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=QfaujT/65kfb2UByGD6ASV/gXT6CqqY6QsptqLKoffU=; b=mfAEwZjmoOMNCHEt4RWI38ZU6qdT8yCXM6HuB1kTAq7ZqkUWNC5EgoPCdGpw67HcB6f5APRziGEpzfvjdUTblkaCNSjZYWzbqNt1o01xdtKSgI0CFzqg8npefu6XdX8GqTRbteH833KtLPKamNyt7LUjEhT8/RifmK9ozf/Fox9S/YOIxobOtNpzlAmAIMBuOglYrHf8hsST3liGSGwFNLjeT9JlGJG17R9BvFL+Jbg/fDar06NFap0VSoz0++0NEssAKammNEakJywuIm46qgjFRzLPk8GOP1C2YTV0UHdNuHbhDFAApJyYMRmQICq6BDWOPVz4PTuLSQJsmgxM7Q== 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=QfaujT/65kfb2UByGD6ASV/gXT6CqqY6QsptqLKoffU=; b=OUOLyJhvuhBmcZ09S3ssMxAt7gaO73dE9cSSLuuGDLlxVTVB7eAAKdpcW+aHPavpqyzPdT5YyPn5jy8xqlYpj9zEh+nowa3rNTLLQpRvZN7MKENMgIwEPH7ZMApLQgpFrj2NYNFBwDG4S3+rkoHO7MXh+2qr8Og+odVByi4zsY4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB3768.eurprd08.prod.outlook.com (2603:10a6:20b:90::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Wed, 2 Mar 2022 16:25:00 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d%5]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:25:00 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, stefanha@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com Subject: [PATCH 3/4] block/copy-before-write: implement cbw-timeout option Date: Wed, 2 Mar 2022 17:24:41 +0100 Message-Id: <20220302162442.2052461-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220302162442.2052461-1-vsementsov@virtuozzo.com> References: <20220302162442.2052461-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: ZR0P278CA0064.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:21::15) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1e5c811d-10aa-46d3-69d4-08d9fc6932b0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3768:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PHPaGudwH8WjNSMLnPGnUY0+uuxXnwAJ79La7ewDTT7yN7LbYxnnig+y1AmJbAWSlV+BbEu85htYBdv86TwTV6FFfx5TCHShuqgELqb5O2VHK/zpOJfOS6IU+XYjv/Q7bNqlg7kY3WAaF6DgQBvmhFS3nUAw7s6vGXoRh+hoPYGcFbg+Mk4QiR08of0ZuaMntjcGg+Qy4mMyut6qB+6V/Jjaqk9JKA7d/BuwUstKWdeDRMWOaBc90LNcfqlNWYC219lVeR1KXa2tdCx/xXPFGUmdEMOvo3EvnZtxj/ah2JW5ouhA+Dp4o4o4oQvuVtMxQD+MXQSBL0cxa3u23AkEFk9Idm1zjjALidOwpvfammZatTSKWCqWTjw5W+JT4RpUUfQYcTf2I9UfqVeVZKRrLaU6zL36b6/5+vUQC9tlwo9tQSecl54CTidwED9G9CWG9fiI5TsrPdHoEwsg9rwoogZylor4SUNvyAGTZTOJ2hhrxh1KICenHy5AxN3XqcJ2EET+3vkAGOWeX8mrl6dgLtM8v8cXH3Y/due51EAmwPaIyhqrFLIb6X/4yw8HHZu9toXPcRFJvBUENQUrm3J6iA4oH7fDTv0Kb6aocCt+RjLlEPmOQAnOziYmJBnq9gbDBQDDO5Tb8pUnvHvAmIdIxRi/AE+1SGt+z8yc2s9m9hscOmAl8mKjI5t2KfVJC/ZmtUF87AM0zh6+WSOfN0kloA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(26005)(186003)(2616005)(36756003)(8936002)(6512007)(38350700002)(1076003)(316002)(6666004)(6506007)(66556008)(8676002)(5660300002)(66946007)(2906002)(66476007)(52116002)(4326008)(38100700002)(508600001)(86362001)(6486002)(83380400001)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JKcsqa8j+nZTRYX5vMd+IrhmsKMCtD4ZY8NGEU3Eiq4mdIae+5FXU3qZgH27pUOK5s+2To0C5wrfjbqcwztKOQKBBBinRR+k2UWuFw33Q6coXiogVcgofbvSSqEm0L/jdeU3cOPa4GHVVV+HApnlXmo6tjBXxwfhXvREYG4UOEtx3D8wWZf6cOCCr/uZZdaUM16wlLudMXeh+Ippb5LIKE5zEI/+eEZuElLsz8Vy+QdK+ijcIAghuMd/P40oyyKdcOKilAiAQothyZ7caW9vBnB/ggk/jf5zfx+ZsV1Wou8T2RWKUknM2tP9oouP01rc7CHaHjHyRksLdH8HxLMv46dP5yKkn9A4Lf6y9HwjgDfvcTxhPJKUJ8eYPglblVBItjpmXNW2dUoITOAUlt2xLj0Oa8bFCImgmwgSaMgQ0vuRir0sPY0rqG1wg+TIX5vVOYLX4ks4dDO+HckJPb7HaTg+okTU9wJVvwZ/qDNLT7XQAjtDhsIBBYUGy1fPzA8AwD9Rry3JO+ZXZAqGZl0uIlzeU0YDKntZB3oEoRZBWzLq5mn274qEY02Ex7hU2fkyLPcx4xaK9flZPaNKglM5QdeTD4howh2bFfzqaelpK6HzXg8YTh144FrBvOPQU10/U1lpgfv6rl3Ix48V2yqUUMU9U96T6jILgTvcrtfkrJIFfzyLzplVlLZ/NWeZOmwet5H85Zxe76TQeRaLDOLhn56lePIGhVDEe6GFA6+MwNcMHBg6ODPl+aq5P//S2iMVlXi6kZag1W/C0HDvFUmWaYpYoHfMOI48wMEpJ43bga66tM0SKyxOYQTXhc1C+7dCvWkQHSBjCYUftQA7Lp5JaH8ED9BGjv6FLRDsbE3ohq8nx/p4e5C2eNnNWke36e9SZU3joz8fT6Zfi6PfTj4bQ1NW4xhvT685GptJvOlEafMBJiBmlEscrdL1LdKB4HfaSP4rOXe8eYCKHQuoOyDovsS3qrqVIDesODpqphncwagJUCW3Y51HI/u9/vd9budvE940XF3y9eQEbexc9YQquGfaFdh9Iwr1jcRv7ETBLr7el1pAQIQ38DK3r+dW6llV3bIclQkG8HtbNOkUc5cpbi/udYVcRsgYo462GvjgZJRIbFMrwV1XzW7v1SSKQBDVoL4af2Cbvf+cXGATCPM+Fr+DJv54ZmmsMv+2FsUd4D0VSTPq2rNqFivZg6/FOg0K3PdQrk1i/YlN5W+eZ+l7q2djMDeD2vazhGintY6dToJK6iA6tblnvxfI08IT5looTaclbmR/MMHn4hqaDJOMLzRbAtaJSuHGotMF2X9zQacg0XP0XQOVQOsNQnUA6Ptx3gke9qfgz/DaUx3Y+teZoJR0eQMPm80pgIcMaVwQeOE8Tx0gA+ltWgtj1IwQMQ1KD+hWXWUBHF2bt4WVkvRIa6XQ1THgF6DIcW3M7THWcHyMI4Rn7Or+MBJKeyw1Wo2IkzUnEfp1B1qBdzeVR3CLL6jLO41exLTwxA+cy0+B/C+zTfr3orDA8FkyQqsX+1jIeg3wzWV2EdPG2bhusu22eeyu7A9HAmOIRaekVy8QskVCrkgf5tJKFDOabTCLU296gVW+uixJFgdVqnyigXVZWGZkBN/8ekqKaelMcUymIROh2RF9P2VWuF9UCV465aIRU4//Xa6zls/tJRLZA9my3w== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e5c811d-10aa-46d3-69d4-08d9fc6932b0 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:25:00.2776 (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: xF1DZsmbackoyGf69gU+PGtVSI6WcPmpZvaOOMlpcGPqHsP9hDQn+U+gmxMsBTgPUhttIOKz7P2bTCeEs/klNATOdDE88QnRsEMkC1auCZ8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3768 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe1f::70e (failed) Received-SPF: pass client-ip=2a01:111:f400:fe1f::70e; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In some scenarios, when copy-before-write operations lasts too long time, it's better to cancel it. Most useful would be to use the new option together with on-cbw-error=break-snapshot: this way if cbw operation takes too long time we'll just cancel backup process but do not disturb the guest too much. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 5 ++++- block/copy-before-write.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index e5206272aa..78c77049c3 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4204,12 +4204,15 @@ # @on-cbw-error: Behavior on failure of copy-before-write operation. # Default is @break-guest-write. (Since 7.0) # +# @cbw-timeout: Zero means no limit. Non-zero sets the timeout in seconds +# for copy-before-write operation. Default 0. (Since 7.0) +# # Since: 6.2 ## { 'struct': 'BlockdevOptionsCbw', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap', - '*on-cbw-error': 'OnCbwError' } } + '*on-cbw-error': 'OnCbwError', '*cbw-timeout': 'uint32' } } ## # @BlockdevOptions: diff --git a/block/copy-before-write.c b/block/copy-before-write.c index e89cc9799c..50681cc711 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -42,6 +42,7 @@ typedef struct BDRVCopyBeforeWriteState { BlockCopyState *bcs; BdrvChild *target; OnCbwError on_cbw_error; + uint32_t cbw_timeout_ns; /* * @lock: protects access to @access_bitmap, @done_bitmap and @@ -107,7 +108,7 @@ static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs, off = QEMU_ALIGN_DOWN(offset, cluster_size); end = QEMU_ALIGN_UP(offset + bytes, cluster_size); - ret = block_copy(s->bcs, off, end - off, true); + ret = block_copy(s->bcs, off, end - off, true, s->cbw_timeout_ns); if (ret < 0 && s->on_cbw_error == ON_CBW_ERROR_BREAK_GUEST_WRITE) { return ret; } @@ -405,6 +406,7 @@ static BlockdevOptionsCbw *cbw_parse_options(QDict *options, Error **errp) */ qdict_extract_subqdict(options, NULL, "bitmap"); qdict_del(options, "on-cbw-error"); + qdict_del(options, "cbw-timeout"); out: visit_free(v); @@ -448,6 +450,8 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, } s->on_cbw_error = opts->has_on_cbw_error ? opts->on_cbw_error : ON_CBW_ERROR_BREAK_GUEST_WRITE; + s->cbw_timeout_ns = opts->has_cbw_timeout ? + opts->cbw_timeout * NANOSECONDS_PER_SECOND : 0; bs->total_sectors = bs->file->bs->total_sectors; bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED | From patchwork Wed Mar 2 16:24:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12766264 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9B360C433EF for ; Wed, 2 Mar 2022 16:27:24 +0000 (UTC) Received: from localhost ([::1]:58758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPRox-00070M-Oo for qemu-devel@archiver.kernel.org; Wed, 02 Mar 2022 11:27:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPRmm-000441-R7; Wed, 02 Mar 2022 11:25:08 -0500 Received: from [2a01:111:f400:fe1f::70e] (port=25703 helo=EUR01-VE1-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 1nPRml-0007jt-4Q; Wed, 02 Mar 2022 11:25:08 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gAha+Idx0GAcrAELnKtChBtT7vcJr2+EtVj29hPN2shUZxB9aiJQSa8C4PJ/Bj+p+s9/OBjrIzKiEgZccWwcuzb2WXwYVEvUHk3f1NHFnzcEcdfZj5VRQMZZE2mIvbw8D7qRfEhPxSs9lnDMrnc/GUwB5ZPSnZTdGo88lanutqSayGNdazb5QOuhCNlEmjCE9BKvv3ywu2YIuA/woL9mqsVC/RwwwLINP4SXP4hqi9nkkAPCwHBzXMZnsnI0UigmkmYexe9VuqIpBxDUSdwxFeBC0chWvtrK2ia4fkrWDUYoXxzSuuk7qrVKfX2wzLm2npafdQrzqrE7aF0Pr5xzfw== 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=19nDqOrw0zuJumRVJ5By97zO/vTNvmNYgAZxeCgbji0=; b=UjJtceUYIyen200O+Ug/mexqJ0/K/hmtbdNB8boQcmKm0RthLPDDqocBp6zYoSBnV+wvRdAxjSq9Pxg6avUN/HQ9jhAf917NYaogWrKnHM7ibqL4v3wDauoKn01ERLckIZ6tMkEslc91rAMPrfEsQK2eVl6NPwNwfCyQAPZadJW/C9fmDRSAC6d4d4biP218MHsZytOFH0AG9QNevaP3XbyZYql7T7qgTueIaeiE0hRhPgFN+gBpn7aGl207zvii7JDSm39Qlj1an0YWaGp2WAve0FoyrmynKN6elc0KOObesaa+3vI1/RWyVrnMb4jWzbVK0495g9F3Bvg29DMtEA== 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=19nDqOrw0zuJumRVJ5By97zO/vTNvmNYgAZxeCgbji0=; b=TFKSu3aqkx3lZWi3GLEGYmASxT/I2i1FNvx7DovE2UggGXz+6oghPQIHFqBO7cnc9Nw3lY/3i12mf9DleoVhRNTMIHr0vpeKk01rvtf0s1GbmwkWrhPU/eVJsaG6SYvtM53dT+4HNU9cKiUUwAFBPDCe3pgvMMThX4FlcU/wLC4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB3768.eurprd08.prod.outlook.com (2603:10a6:20b:90::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Wed, 2 Mar 2022 16:25:02 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4545:8e0c:19c7:2a6d%5]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:25:02 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, stefanha@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com Subject: [PATCH 4/4] iotests: copy-before-write: add cases for cbw-timeout option Date: Wed, 2 Mar 2022 17:24:42 +0100 Message-Id: <20220302162442.2052461-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220302162442.2052461-1-vsementsov@virtuozzo.com> References: <20220302162442.2052461-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: ZR0P278CA0064.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:21::15) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e54f94dc-9138-470d-f61b-08d9fc69336c X-MS-TrafficTypeDiagnostic: AM6PR08MB3768:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jnPXm9melTrFZTwJ2wK/kG1Hza4vFzgy6YQuy+aZJjGct5Z5tEEAjR5HsA4y45bPQVxPI8uaiCN03ohgnI71MTs9iMinz4Eu9n5Njmr+oupcAMPpzBsv1y17UwK7E3TRRbmj90z6pj8FFiSXaYzjtFtT9BEBFvrI+ujv1fNfbe7TyXCpV5Mzm1Ye+JJd5VXQcDnxYd2/Ktz4+QvL2S6Fdw00tydHK+UTMOrycheq8StMFzlld71YXQvZzqH330pMSOTDFA68PLE7TZJLkbmgEt5qpNgB9qf/ZcV71bErCsMqijJYojOBne0+Aww+3igaDR8WSLYsqJhr3NVfsmPXHp5HVJwhzxOo0bW23QzXmCStpwe3P92Hl1h/WhOvWfsuOKao89WpWjqw9g6AstuRswS8Ro+pCID9fTvz/mNTR3AseKSfs6WnxwvR1Lhf6ngK3qj9DUs7uJMBSHw5vv+83mCWO2jF6jzi9DmzHkm8mGOjHSFIdFM3YCWcq31Z9XNt4loKcU87HbbGxV3iJXdn/dZsmk1q2ObZm9Q9EH2lKcAjX+1KxyG0lXDDbSnuOYhva5wJP1smKF7l+5PXzTz3tY9GfMVsnuDhroXRXOUKFGDlngAaQl18sOOn72WoW+Z+MK8NVDxTkmuiI/vGMhjA5nSfsGEWX6FrFMuKK3/P9mW4BLeFA4DvRr7isyEt7C1dgeadpYrkTqHYfxUuUP/VF8/8jEt7fCLsDT5lXNujTYc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(26005)(186003)(2616005)(36756003)(8936002)(6512007)(38350700002)(1076003)(316002)(6666004)(6506007)(66556008)(8676002)(5660300002)(66946007)(2906002)(66476007)(52116002)(4326008)(38100700002)(508600001)(86362001)(6486002)(83380400001)(6916009)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DvssyQcz1EuP/wregORelu4EcqnTOEaZaIQGHQ45aGkRunr/X2I8GqTBUQ6N9XW77JASg+VN1vpNCczs+Fmofhu6TnEGk6LKWDp0YcEgmoXe433sUemh2WP8efFfAX+CjiAE6fTz5ex6UX5WdmWmI6+548lntlLbD9DMPH/68ldah92dZz/mlxM7023/BGzIftHM2iECwn37O4wPuniqC0LJ+PbCI0xTopknt5q4aJmMa5whhbbSHpHqATDIaUSNsuuTef89lAhH1fRIqQxBjNo93bnP/OU+X9OjX36IOtVYhtLPTi2EkGhiFIOzp8fDIUeke+o1q9AOY+VcAZSa5weUtASC/Rzd4Xcacper3kGTo4VnWAbESs+/0r0f4pPCgkYY8ZWcoZNONlKzop6hcKNFxOKSrTQcXsy9qJZUssIp0z6A8RbmRLz7Lsx/6jPfgRNNFHk5Y5JMXPDE5QZubdHF7FZIpKOvFgf8JmcndC8JroGX+D736N121KmD4YvSdhv76e9L5d0oV4MsyyFqqzGHI8by8Jus6zTr6Yqime4SrVVm9j7j8dDChLFodaNiUwjX2EOTLw9xFqEG2tAKAM0vMEe8Xy7HWLxJY2cmaBrMRVu0EBVG5ancEiVFJc25uth0FiV4Z4rVdikkPl1HX3xbVWn6SY2je5raUnWP6dkr6hIoOgkOx2yIJLPOB23jurHv31BODajgyShaejPzlL1VTbrqMfcokHCPuQ1zq/epIOnmlVa/6Jl3+mGo+5j7q51gJQ1tY2aAmPr/M0zrMkkzi+NimcQQpWjE9fvdeuQljtVlGFauKrLiCtLnD5B9TWU8B8KauSPga2Zmd9EO/ZXNKfOyLSHniFuxaX4hpzZwI33ZayO15TXayVHsItuk7f+Lme2qV9VoMQ0Y+STqe8Jhs0S81mROOxup9gSVuTtcBBRQIhtcSJ+3P3y3zMm10Q1/gOKrc9bj4o+7UG1MJZRmgG/2KuVoe3Tzy8Z8dW8lTrre88Y/U6wbZcZ//T/AUPdK7lO3MBkv2JjuFuxWe3B/gjsLDwQBLqOgu/faSOO2Dq00Cge7diz9KxwqQJ0gb5+8ZhB3CueUbbpjequoQvsfXO3abfpX4hjyQogBvZQMxzLCpW/3pwGB5NN+Xnm/4KzNuLEvdPc+EX3KX1c+OmPcv15Mv20McQKW0Nmlxh51ZXH4C2nGSrtdi4ysnQ8oiz/sfpDx9xcCRniiw4kVmOdJkKpRhrQU72GtuA1w964pCitW0K85wp5clijkd+Qj+KraGQhwtA6OOhx1Uyc2utxR8dWx2K1OMsHDmbVtOkpqHysnH6A5QSh+4NqqBQda18NkpEj7oa3UFwjYUQNqIPwvOpm+Fw8/eJIAwjXwmopnWtDevY+wEOeNJ4TKTm1ZqMcgZe9A3UJPja2tlfLbBpGK3c5SxXxOO4BIre/diCDDsWyZNw+x03vBuuO1o6OTmnveTQX5TXp/GatADfdv2F5y2bc5AG+4Os4AisgjpuoL9Vle1oflXCpP0JKc8z7aYJUXTkN/7p2Io0ITlFdnEi6T74hk/zNQ1+t9Y5wZAS8jeIdMYayR2peCjUv17mZP6O6URQkj+w9mcwcXEFGH0xZOoW+4s7Gh+9eMxswnE3KjAzSDc27Hg74TYNXpkYFXoJFLjqAScZlwNLAtYtUWUg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e54f94dc-9138-470d-f61b-08d9fc69336c X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:25:01.9179 (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: 2519bDBR2wQWLg1pkGvtP0/yL6H7PRLXcmcmRUUcFnKu0llDvlFGwuhgygSEjKDyubf7vdo+mGuzivzlrIdce2+MRh+c3umH6P+8iUjKfNY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3768 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:fe1f::70e (failed) Received-SPF: pass client-ip=2a01:111:f400:fe1f::70e; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Add two simple test-cases: timeout failure with break-snapshot-on-cbw-error behavior and similar with break-guest-write-on-cbw-error behavior. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/tests/copy-before-write | 78 +++++++++++++++++++ .../qemu-iotests/tests/copy-before-write.out | 4 +- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/tests/copy-before-write b/tests/qemu-iotests/tests/copy-before-write index a32608f597..265299957c 100755 --- a/tests/qemu-iotests/tests/copy-before-write +++ b/tests/qemu-iotests/tests/copy-before-write @@ -122,6 +122,84 @@ read 1048576/1048576 bytes at offset 0 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) """) + def do_cbw_timeout(self, on_cbw_error): + result = self.vm.qmp('object-add', { + 'qom-type': 'throttle-group', + 'id': 'group0', + 'limits': {'bps-write': 1} + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', { + 'node-name': 'cbw', + 'driver': 'copy-before-write', + 'on-cbw-error': on_cbw_error, + 'cbw-timeout': 1, + 'file': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': source_img, + } + }, + 'target': { + 'driver': 'throttle', + 'throttle-group': 'group0', + 'file': { + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': temp_img + } + } + } + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-add', { + 'node-name': 'access', + 'driver': 'snapshot-access', + 'file': 'cbw' + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.hmp_qemu_io('cbw', 'write 0 512K') + self.assert_qmp(result, 'return', '') + + # We need second write to trigger throttling + result = self.vm.hmp_qemu_io('cbw', 'write 512K 512K') + self.assert_qmp(result, 'return', '') + + result = self.vm.hmp_qemu_io('access', 'read 0 1M') + self.assert_qmp(result, 'return', '') + + self.vm.shutdown() + log = self.vm.get_log() + log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log = iotests.filter_qemu_io(log) + return log + + def test_timeout_break_guest(self): + log = self.do_cbw_timeout('break-guest-write') + self.assertEqual(log, """\ +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +write failed: Connection timed out +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +""") + + def test_timeout_break_snapshot(self): + log = self.do_cbw_timeout('break-snapshot') + self.assertEqual(log, """\ +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 524288 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read failed: Permission denied +""") + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2'], diff --git a/tests/qemu-iotests/tests/copy-before-write.out b/tests/qemu-iotests/tests/copy-before-write.out index fbc63e62f8..89968f35d7 100644 --- a/tests/qemu-iotests/tests/copy-before-write.out +++ b/tests/qemu-iotests/tests/copy-before-write.out @@ -1,5 +1,5 @@ -.. +.... ---------------------------------------------------------------------- -Ran 2 tests +Ran 4 tests OK