From nobody Mon Apr 29 08:02:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1630579326; cv=pass; d=zohomail.com; s=zohoarc; b=B+ONRKnX5tvYnnI+9U3wbal9mPpueQyPq8TO9dyNRaf3E7YqqeHYgIb4WLDnLd8xqqKxZRK81SyGTaNSpLbSMnd2lZFW0rgIYWeQDy8rBgtgz667GecfG3pCRy6OLpp88r/PlELZf3Q65r/sbQTqwDJXPOgBzTzvkNRo66AM/5c= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630579326; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rZymh/Mn2y2PEqQKhaEyjBjDdoi1qVit12CS1hn4lGk=; b=dMXmNyRtM17/AMwBRDqFSnYEcqY0dZV4qbPsEx9KgOVuZlq9nCAqvDjrcinFleBBlZfCDL7JGPEcA+gH+hSY0hw9wDyM/dOMB/EcVxj4TGJTreVovYct23CZKwDRmbsR8bBeHBUYYkzZ0S5Euol71dz4Lmub0Ny9aA34ScO+6hI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630579326589916.3026614969722; Thu, 2 Sep 2021 03:42:06 -0700 (PDT) Received: from localhost ([::1]:33512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkAX-00028z-J6 for importer@patchew.org; Thu, 02 Sep 2021 06:42:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLk74-0004Cw-W1; Thu, 02 Sep 2021 06:38:31 -0400 Received: from mail-eopbgr30115.outbound.protection.outlook.com ([40.107.3.115]:38273 helo=EUR03-AM5-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 1mLk72-0005xI-G9; Thu, 02 Sep 2021 06:38:29 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4472.eurprd08.prod.outlook.com (2603:10a6:20b:bf::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20; Thu, 2 Sep 2021 10:38:23 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%8]) with mapi id 15.20.4478.019; Thu, 2 Sep 2021 10:38:23 +0000 Received: from localhost.localdomain (185.215.60.196) by HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:38:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dgmBfjJFbp+2NGZys87eQ9FU1ee+74V2jwElj63HyzLCF1zZfjL/nyVgVRblmKqWANkgH01s1Z1hgWO5o0wCk8DInWE+0pygERWDdqn4np3HR9aS1Wkyj/aoRl2FzFV284FZ3ijg4iEzlX+PFZEqwLTVz0u/8sL/wuD2GHNl3gV7q4+upBFHslAcxrOIy02cNERbzRNYX85bGt1NTeW9TOFleQgdAp0IcXZ0PDTVWzwun0A7IoybOuMosVm0DMS+/YzO3qQp9LZ4YeDOcuAAmFya3KPky3AI4vjesm2YAdH2zvkmlcx0gL5kO1kqDFc0CNWzXjoaquemzfgd6/qNag== 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; bh=rZymh/Mn2y2PEqQKhaEyjBjDdoi1qVit12CS1hn4lGk=; b=fcK1pMmAsFBT9O/iSZyDdIeWgi87UP/qTlInNMhZ0Ok0u9l5BacByDmeFXsJ0BRbUtVwthBSUNysQ/GjeDTDG2eyN4lq3uDJUdwQAbnYmk0LksTAtRsF0yCUoCxw65KNka47D4jbo0YbPf1Tz9+FF4aFGtsm2BW+t4lVOcjmH5CDcPMLLI8pDnDQeAd72MvqOGi0hMimZJJxNTIRaZ3NBcDyqG84q0qbzxNL+decbuzM/unrcPfI/Q75FZ9MF6KYq+QPKWoTgHBbp4q0tu1vSmON2xeemRxqwmPIbq5wD+OMDKrByJvVrB/QMcL4wmftp3qqFAIwYHieCiEZYOgQ1Q== 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=rZymh/Mn2y2PEqQKhaEyjBjDdoi1qVit12CS1hn4lGk=; b=c1qtetXsqtCEyw8wep7YUz3dAf/hocX8DchaITcyNnd/rml6qJ0uKSyJuGm9v2oWBrfBoqVyX6BJNI7bMkvLZDqDfFp50v0gNtGOshLW/l/7ueQgPeZauB0b1qQRPLky3liyO6d9ZauXIJzjeT/CRp/6YhVDJtAjS6IOZQKeCHI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rkagan@virtuozzo.com Subject: [PATCH v6 1/5] block/nbd: nbd_channel_error() shutdown channel unconditionally Date: Thu, 2 Sep 2021 13:38:01 +0300 Message-Id: <20210902103805.25686-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210902103805.25686-1-vsementsov@virtuozzo.com> References: <20210902103805.25686-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbc3e794-039f-4643-a256-08d96dfdca1c X-MS-TrafficTypeDiagnostic: AM6PR08MB4472: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:366; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WOMAABLwjtDEkJRrx6qlxRxZXcdV8N5vWuq5LILvNyC/ECoR2F3U0YBsFXeFdNLBO18mu/n85iwmIj0JCnZfBixyjquwGI/PSStPM04s3pId4dXsig9Vf0PtsQeSHmdbvg5kex34YkMpm0GxmbCjqJAXfYyLRSFK75ZzqsO3cMw0+R9/G46GKAkEfThgxCBbfJSrsktwEppC/AvUF8R5rdNOqU9UNarSsjpjF/V8Tbxl93v+knyoRLcFabp6dS9t2MzsRapyahLunmtbKOgKu+UWuXqz/QXB7nywGezCpK4jRYSEJfhW1VzFKp37t3mEoKA2aCvXONXeivNs7/NenN9rlfH4HUAkjWas8hzIHz0wwntxS5Wug0hornnHhFMUm2DnkIfg54Gv1vlBj3WcDKS3jNzW4NRtxMxHyWjCcV/tzQK6vcQPZQ99YYyVh0/iBbWZzWV7MuK0K0VHNpoD4R9lkgvgl2PEdUNXpvdHDhgvsj9JE/V4UuHSA0fc0nC8vxH1FablpqxDN0omccJUlqf2c1vEuiJ49bQtrLKivk1+ordvmUZAqNw3Zk05nlgbTWIckpPC9jEWBggWS95TlvvVO7rNKOI2GcS/FsN1AlVpZ3YU8YFUYwqHnhwUk54juR7c21jDlPgVM4aVOWwId9AGDhf1Nb/JZmHjW2UOF2oex6epk20whBxr79EZZqX9Na5e245P2UMefEO2NWtjpQ== 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)(136003)(376002)(366004)(396003)(346002)(39840400004)(66476007)(4326008)(26005)(6506007)(66946007)(6666004)(8936002)(1076003)(5660300002)(316002)(83380400001)(186003)(8676002)(6512007)(38100700002)(38350700002)(4744005)(2906002)(107886003)(66556008)(36756003)(6916009)(52116002)(956004)(2616005)(86362001)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?C6TFzY5NxSQATtQGtMEd7ZA/6vKQbvAnKsmAbgIKIJ3f2dAs7UJ/s3BDU5/Z?= =?us-ascii?Q?wYmtxmaIlmq48oXz1HgBUKCEKHVf9hU4EndGgf09vlu+UwBzTvdG6hS3d9Wy?= =?us-ascii?Q?CEDllWghXGXIaCO84Qu6aJT/1E4ZYSQizslcQVSc8E3DzVm3w6KpAi0kpcO2?= =?us-ascii?Q?6TtNZ8kVLbkTDEpY2RLEoatmHjJyHFzP/9yNjU9I6KjxPNxFvuDuTN26W9no?= =?us-ascii?Q?i8BGoyucLQ34JmENX83DWyRKWrBGEEJ6zENKQp1mOj0Mk6Xyo++h4B8EsMnG?= =?us-ascii?Q?G4Tl3tFUH+WLcPCtbh3xjMJIRTFVLpPtSqL/7N3CL+kMogOHQ9kKk+q+u6cW?= =?us-ascii?Q?dRF4yLOgigyQmGBET5oKwFjL+MrVBC16rHcVbN5EtjlY+4kdA2wrCgIBesOB?= =?us-ascii?Q?2uZeP47oA2qxetBZ0mxwAU3gsvmeftwlsdKeE1Gz+h8qzeEwxLXaCzKQvhBT?= =?us-ascii?Q?40huIdMhmZXerIHMpSKrxjrZ0rpnDnsuVAV67TGxL7KYZWg6c2IYE9ECcfPO?= =?us-ascii?Q?Y2ZABR9S2Kd0AKsYkY6GSVTpVmoz+Xb3tUe7i+U6RERoSS9e3ZhSHtxb1Oeh?= =?us-ascii?Q?z3oflQPRxAVf9kpnFso7M2TL644HwTewReuJq9rMWNkdEoG+L9Z23pKo04nx?= =?us-ascii?Q?9wNoz+2A6ywXdVLsZCw0d5cqhJ9K3oYA4KZ+JKt39EQFgNuSadaECVhyvBeO?= =?us-ascii?Q?Kbqg/LIp4hCPeXJtaKx8bL9HMaH86Ag9pcX7wJgY9uYa2gYzK9C9cTMgrFpk?= =?us-ascii?Q?uOTysyKSeenpY16mbX3AcZrZuhF8Oq1nzddB6TCwO5e1Gz3N5UKbREg/v6XF?= =?us-ascii?Q?j0LvKsdTvcRqGZhdqm2yiSV4+3brVKVlfPPX0a/+7eq2oz/IOOq1vO/fR9C6?= =?us-ascii?Q?/tf1v8O3gP8eRDB9si9YVRz8coHR5b24SkDjEgVFph8mQQeaJf/DKIAesT3V?= =?us-ascii?Q?HBTGeEhOshNSAJlvUniI+PjMWW7R9Byekx6iExhBjnw30+trFcg/W/FkoAc/?= =?us-ascii?Q?ql8pdjmuf59ikehOLyZXRfCI3aZQEIH4mDpi97N0CRDSJMI0fT/uSkFGxLmp?= =?us-ascii?Q?/JXtH6sg1ziLVw3z4MCW5dTlMkSRQmUvlX7z785RHilyuJCGhKMBEBD2nDAK?= =?us-ascii?Q?XH1hoEFM/3wBm04PCLSWR6UtpTNZ7TzSq4FThKCWlJirXnhnxv/I5IP2gzRP?= =?us-ascii?Q?ZtC2iVXEWxM8lv6ejzDGqW2c88QpiwNpaE6rvEz85S9rzMBmQQxdgYGZk0Ju?= =?us-ascii?Q?iLPtWqyR4OBubdy0VUVOTW/RNPvnT+ojSFH33Bkbjs7GvtNxKpdjEh4RuP1L?= =?us-ascii?Q?3uXQ3NWZs/xHWXe0sloQ5g2X?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbc3e794-039f-4643-a256-08d96dfdca1c X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:38:23.6037 (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: fzgvxNrbnd0d5LYeEo7mxbjVvkbq4fVYqvSWBO0yr9oqNySUXfoG76JRxagpsF4pRrpE9tmho+bWgjZT+KDGYPCtB6DD0yK3qeznCCd/q5g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4472 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.3.115; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-AM5-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1630579328512100001 Content-Type: text/plain; charset="utf-8" Don't rely on connection being totally broken in case of -EIO. More safe and correct just shutdown the channel anyway, as we change the state and going to reconnect. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index f6ff1c4fb4..d88f4b954c 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -129,15 +129,16 @@ static bool nbd_client_connected(BDRVNBDState *s) =20 static void nbd_channel_error(BDRVNBDState *s, int ret) { + if (nbd_client_connected(s)) { + qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + } + if (ret =3D=3D -EIO) { if (nbd_client_connected(s)) { s->state =3D s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT : NBD_CLIENT_CONNECTING_NOWAIT; } } else { - if (nbd_client_connected(s)) { - qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - } s->state =3D NBD_CLIENT_QUIT; } } --=20 2.29.2 From nobody Mon Apr 29 08:02:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1630579243; cv=pass; d=zohomail.com; s=zohoarc; b=cywsSXStbMJyDRXkjDtft+kKWFMWxfHcCVpbS8r33gwzNObJB72NImKsYgun7s3jtWxjGFEuQ25Mdj7cjAVUp8ypRX2KInv3oolihYKuvaClGgy9D+GMxL1vT/TPMi5grWxrN9e4GpQaXFiU03OhsYn8XZ7bSks0qqQB9o6aI0A= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630579243; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dTm4enJTHvjAfmrpTfyVs1BEIpzvYa/LwcXeDPe6c3I=; b=IoBCDZP8In6ghitCspWs0mvprhOIOjoH7uexu2r4sbI8rbuiq6potbj/f3IOuFRRJCeAoN3GocZLWP0O5V9ARgO+LlNXpyla999vbhgCZhFleRUzJWqNN2Q6gG2pWperoGg49Nz8MEv4VC6whdDZdEHFN2I1mJijEqmMiVS9AHw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630579243852927.1977482222912; Thu, 2 Sep 2021 03:40:43 -0700 (PDT) Received: from localhost ([::1]:57066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLk9C-0007JI-QA for importer@patchew.org; Thu, 02 Sep 2021 06:40:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLk77-0004HX-2l; Thu, 02 Sep 2021 06:38:33 -0400 Received: from mail-eopbgr30115.outbound.protection.outlook.com ([40.107.3.115]:38273 helo=EUR03-AM5-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 1mLk74-0005xI-Hf; Thu, 02 Sep 2021 06:38:32 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4472.eurprd08.prod.outlook.com (2603:10a6:20b:bf::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20; Thu, 2 Sep 2021 10:38:24 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%8]) with mapi id 15.20.4478.019; Thu, 2 Sep 2021 10:38:24 +0000 Received: from localhost.localdomain (185.215.60.196) by HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:38:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gkzsgDgHRUmEsh8JUwtCsbRj9mDJA7VFxXlGbh4wfHrcKnP4bXETtse/b5KMmgriLwjshlhKlSvOLHr4gGPhNPaZ8Z00rUm0k69jUc69hYjE4zQ5zptWlXO3pgyeUlXorLK6ps7JcGqc1eY+l5PgIp6FYc6MhJFA8XvfyV83kBTtoHYu4O30E2vTiPXeNCUujziwn+C4qMdX6XO4PyaufsNsSXxPeCmNN+AKC2y8YJSigllcPl2/qkWlO+Y/gJZ+vzITnbMZdu0VeW9VqFp0F1bRb0ifBKF5I3NtgEPahXZa8GGHunK4zFLcMCavcsKXI4GL+a1Mmkd+p8hTmxI1og== 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; bh=dTm4enJTHvjAfmrpTfyVs1BEIpzvYa/LwcXeDPe6c3I=; b=gQ9uDE/3GQwSg5XAloAB2pLBCLozhAJttxH05qW+dahu7YOJ7ErzGiAd9X9PhZOjVU7+hwy8vk9l8qLOtM8mLOi85m8t7oS1bY3Gx2Ksyy2p5yhX6gCOrCMUxTkIurF0FKfUTGKgDHX9XBT/EWmX3tv6ZctHRQC3hpc/7AxdY73wMaE7uyXDPaIn1veluTuKGEyPPFgNpiR+4MomTu8LDPsZDvnihsq/OABWT2ltcFATKZQ5H2DWvf0tSTdElCrMtbHFxMbxKwJSxktkKSumDTkoovXJHNWwOZo+ZAw5rYIk+hjyJGRVTc2TVQ/hed94pfkumPN/wKXvEL14/FG3FQ== 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=dTm4enJTHvjAfmrpTfyVs1BEIpzvYa/LwcXeDPe6c3I=; b=al/DU/m2tgk3U31W3nhYm0NCg2kWWzGm+llS9uCeR80846cJ0bZoZB/CqctfPno35OX842UINOZokSR+u/ZBN8stts5kxsIP3JGHU+4u9szYkXcc6ERHPCnEbGpv/JI+e4Ld67cvpALfGx7d5363I4Wcsj9RpYqrl7CAe3oy9Lc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rkagan@virtuozzo.com Subject: [PATCH v6 2/5] block/nbd: move nbd_recv_coroutines_wake_all() up Date: Thu, 2 Sep 2021 13:38:02 +0300 Message-Id: <20210902103805.25686-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210902103805.25686-1-vsementsov@virtuozzo.com> References: <20210902103805.25686-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4be8f96f-8694-4e0e-4035-08d96dfdcab4 X-MS-TrafficTypeDiagnostic: AM6PR08MB4472: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:207; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aO6HiVRwy6PXBqy5EPHtd2zAoNquO/H6ocVDrXcfSDHPv/O4T/yHkU1NYKbPBp8s/lsxDNCj3fKZLXyDvDr6TMTReD4vo5aWThOMzHbH0sM2LxGa0ljPL5TjEPjYUImKSyCLxNXSBDAHigEJvZnJQjMBEtKLhYaw4o7MykbXx7l5oMkj2Q4oUo7iWtwBUlYZEFPcjGv319zzzkxrt4vM6oBqBxbO/601K8gygc46882yAKen5hnfEpuEylntwBSXEsFnEd2AxwwwF32J9UMywHUdQuHrKkhU00lhJ62Q7nPT7ustoBdO0axPVtYh050iMZzc6es0bR89n881WI4V9pqwJCIjI5vBUV03MWG9mIJDXpGZ6eVZYXCaxhtk1y0XcVV9hYOKO7pozSmF9X5FkB/Bi+AwQyRDzn4R0tz1rFBVKkkn8IJPgF9syO1mOyYlqS6J9iTFfjSc6u+JcLCGeKzmQls/s1n8b7O8SodhgmdTKdWi8W1BdTV+iqUSCJ3wcHGU1TLXfRbSZZH+TYQDZ80x9soi+xwkCBUfTjTwxXuybM5ip91SCI0QogMVuHAAGqPcTNz9ONrviugnVSi6vJKsNIlU9tOyMzdN8pBY3Hx5hFXx6OG8yVROzkpmC5Chs/BccePDn9xxejSwZTk9qzERPMx7Rxp3QpMXQBm8B1J66+eDx8MVDZbCESzCvlQkcEn6Gv7tr3zrA6bMDJUohQ== 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)(136003)(376002)(366004)(396003)(346002)(39840400004)(66476007)(4326008)(26005)(6506007)(66946007)(6666004)(8936002)(1076003)(5660300002)(316002)(83380400001)(186003)(8676002)(6512007)(38100700002)(38350700002)(2906002)(107886003)(66556008)(36756003)(6916009)(52116002)(956004)(2616005)(86362001)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?WPwJnWmCEYAd9ADxCMH6RhBgUI6PUCmv5nr7CVi4r1J53+d8BQRrCAbGBJae?= =?us-ascii?Q?TfvE7aZ4L8NOE4Dgkl312Bc2kzIuxfki6vqk7uUEtwvPxfGi25wKwD8T18np?= =?us-ascii?Q?A1LVl1zW45kH+3FuoCVps4KLHJsI1BB8EpJvR67/zq3ORlucIqQNhEyREzRX?= =?us-ascii?Q?a45BMHwWCXUZoK5YOblMNUN15c/WQn4yx577Ci+Ii5A3sThsKEnCzD4okAdi?= =?us-ascii?Q?okzROtyrK6yfmpKjSB+tgY1FFMV+XTydBM4qtMWGPD7SzKfCwoIvrl0obz9z?= =?us-ascii?Q?fQd8h/xSGc38jn7u3DyJnexX7wgnZUqcVuLirqUp0pN/4krHOH8xVZtFCK6a?= =?us-ascii?Q?Bc642Y4PKSGN6NjeXHAewMxpOgu7/ZYXFHpa5FSM8tHwaYtbrn4lJteeeVvo?= =?us-ascii?Q?aTmRj1eFivmm6dZQKVDswQgk1GyJ1ZPc2AZWctKlAeHJV/ChiYua6dRLCFyB?= =?us-ascii?Q?cp+jj86JHSL3N6y/cF8CE8uC3F/62PGzJokS5yxmWdtLvQFsxHQX+ePpSJ0v?= =?us-ascii?Q?pfyRtWMctP0p7zCki+BCr5Z0zukInEPFy4j0sMOAsUXgdEqQ5BUKGVAD1phB?= =?us-ascii?Q?gnDQv4ouNo5Ut5QaYKRSaPX5g2EF7hRy60ju3kKoLg5tGhBo/m5Xjr+OGPnK?= =?us-ascii?Q?fht+D6NJYgpBDYV4YgtbIZfwrEq+dR43634ZEsTsF/KG0G62+eJGxS/QNnxX?= =?us-ascii?Q?4/e/7pLkn0huGIURpzzSIQqXghcWhCAZ7HCuzviMqJNx66Q6B5af01l+Psny?= =?us-ascii?Q?8v2/OaVzbHsb8qhtXU+Xhun9arcKSy6QXQMRz6LK7yAVEs1iDEXqfPt7Z4/q?= =?us-ascii?Q?Xigsc2dA9JLuSER0il3Koa4dM7KI4PTAjtR3UnfSwe/kg21HoS3KoqTOw6+G?= =?us-ascii?Q?uPfegztdBOrqyugeB+FW9vgdfH2l7UTie3C5ODSXmRvlWu23mj+bPOxjLYyh?= =?us-ascii?Q?n7px5Ti+DY1RANMwVDXKN0GQ6xxOPxpPED5EE5UeRv7ivG/eG/3a/W5L+Jhk?= =?us-ascii?Q?BszE3RrBqbnzvYQiq2Bjw2MqeZXlWgQiE2LRs8ABJZiLCekmx8y7cHkfGekn?= =?us-ascii?Q?+DsNykvMH8QUiumaVxAVYHCrGaTyuHIOHEHyzJDuoExGpKQv1/YFoLACHxk5?= =?us-ascii?Q?7y41+7ipeCxQnHIRWiQdHI1PiAx2il7zZOTTpZ8tj4sjzN6moWvZ/hfZ17qc?= =?us-ascii?Q?NRBEJhdDepFJJndo5qM3ilEKQmgLNOlgJPm/pkNs0rDNdlGaui9ys0nqPYky?= =?us-ascii?Q?XDOVjwZ7yDQh2lFXQ+yblD8hXaG/HG964jAoctnHPCcfUXJ+Wr5plybP7c0E?= =?us-ascii?Q?Q29tveAN7GQxpqDGibvQvLsh?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4be8f96f-8694-4e0e-4035-08d96dfdcab4 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:38:24.5834 (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: 8rWXPVkombbVMts4EhXy6UPVh86QY4t5KyMjcNxNwH1W+IMLLiLzoPlL858xDjJkXfu+zcHYxBjJqwjaKUVC/f/7EBxVQWB7BI2DK8+dyBo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4472 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.3.115; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-AM5-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1630579246092100001 Content-Type: text/plain; charset="utf-8" We are going to use it in nbd_channel_error(), so move it up. Note, that we are going also refactor and rename nbd_recv_coroutines_wake_all() in future anyway, so keeping it where it is and making forward declaration doesn't make real sense. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index d88f4b954c..32e3826ba2 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -127,6 +127,20 @@ static bool nbd_client_connected(BDRVNBDState *s) return qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTED; } =20 +static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) +{ + int i; + + for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { + NBDClientRequest *req =3D &s->requests[i]; + + if (req->coroutine && req->receiving) { + req->receiving =3D false; + aio_co_wake(req->coroutine); + } + } +} + static void nbd_channel_error(BDRVNBDState *s, int ret) { if (nbd_client_connected(s)) { @@ -143,20 +157,6 @@ static void nbd_channel_error(BDRVNBDState *s, int ret) } } =20 -static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) -{ - int i; - - for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { - NBDClientRequest *req =3D &s->requests[i]; - - if (req->coroutine && req->receiving) { - req->receiving =3D false; - aio_co_wake(req->coroutine); - } - } -} - static void reconnect_delay_timer_del(BDRVNBDState *s) { if (s->reconnect_delay_timer) { --=20 2.29.2 From nobody Mon Apr 29 08:02:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1630579253; cv=pass; d=zohomail.com; s=zohoarc; b=M52gFmpqThCy5Q+AHfOV9qdS07A1RHM54wRXwFFCMeU/X/ccmhp5Sq+lq6OB1UWfnDG7DF8FWn0nBMX2uGR7GvzDpXpOPogpg3KwZohO9Y4jgx5MaYeW2dztOjdTrV6I2phPGA7TyjvKSsRHbC7fNRDvLC8M2wkY43rrNiDO+tw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630579253; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xlbGgnSWwiIR5tBhQ3+VOQbEG77BISpE7o5B7KRFsOY=; b=PH2PHy9/51V1TJZncw3WjEvcB8drek3lNGriNrnriF8Z6u/k6t8BXcB60BRO/S55NAyziicnYBa6nQgEX80QN2PFdsaDt9Ron1+nsjqnF8Oazu1fu4XUQ1iK4gcJyrMpLC3jGiKLSL5/nfOEQtKUfk15iBkSOyWnIHOC9yczrlM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630579252822326.4522951985631; Thu, 2 Sep 2021 03:40:52 -0700 (PDT) Received: from localhost ([::1]:57778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLk9L-0007rV-Ph for importer@patchew.org; Thu, 02 Sep 2021 06:40:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLk7A-0004QM-JG; Thu, 02 Sep 2021 06:38:36 -0400 Received: from mail-eopbgr30115.outbound.protection.outlook.com ([40.107.3.115]:38273 helo=EUR03-AM5-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 1mLk77-0005xI-Ro; Thu, 02 Sep 2021 06:38:36 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4472.eurprd08.prod.outlook.com (2603:10a6:20b:bf::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20; Thu, 2 Sep 2021 10:38:25 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%8]) with mapi id 15.20.4478.019; Thu, 2 Sep 2021 10:38:25 +0000 Received: from localhost.localdomain (185.215.60.196) by HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:38:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ldt61tY9U/IX/0IO0X7nSH/5ZqzPpRF0DAPYmLlGqGLBBxe552vAPVm2WaLfhWaU67qwq6FwkkGbSUKXq1YKJoWx42rTxgYjJpQphOOA6eS5Het7aNXW9pV1HZoVujEzY/G8Fsn9wJT1WMPaKOgPlS4k2JUGrdgpg0Es1wVv8Ss9PniLtG/psaf6eWRorRke2Ft+CN4BSCW5fLdbOPz5ZfTgmWklLE9SYG+aNcD3JNTzCsAGwJ8vPnqyAG5NWMjwOMefjjvwcgTow0cnByJCpK395igOEIGle9c8AN70z7MJG2XGSiemdLSCOI5wLT+LbqNkrQZ6v4KaNadqRSqYYQ== 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; bh=xlbGgnSWwiIR5tBhQ3+VOQbEG77BISpE7o5B7KRFsOY=; b=EuaoUxH0WpuUSVrR4cbrShcpz1Y5FkJbcyVl9+KQ1A5xv/HA+HRQGd6POeo2/Xo3JL0wDDenRRlcy4AIeyS43vvtEj9+8Sta05XorXiDj/B3rCy8uhbQ86yowhBOJFzaF7gSrMM3LZK6lsjZbJfGVgzV4b2eWwZR/q6mHVwJ5PHgkHfYUtux0F7Xq3ufT7tTrHnadI4BB1QMflvnuTHr3wqciIBVAeqdpqH4qjpwQRWDsuOXxHpLs8PtKPWkiDUQ+KpHfC56EmULYexcWEhs5F5wtTVzZlRezpMQXY+OOKVUOLtrlpc/3bN5rlkbL/vEPJj1a+or1yx3DrJGHapChg== 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=xlbGgnSWwiIR5tBhQ3+VOQbEG77BISpE7o5B7KRFsOY=; b=N5d2IXghhES8FTf89mZCKELSEGL7lBu9l0TOG9Bcpl501u36fbg9MOb9EBXxHE5Wx0c4Rvl7gtCBLZ9m++U8V7L0l9apcpEKPGST0tNVSHAO3wgZk+orGDkwJZ/NPPVk3auhrrwHPsTgeMaQbcDW+wDygyD0ZYZ8hlONjn006oc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rkagan@virtuozzo.com Subject: [PATCH v6 3/5] block/nbd: refactor nbd_recv_coroutines_wake_all() Date: Thu, 2 Sep 2021 13:38:03 +0300 Message-Id: <20210902103805.25686-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210902103805.25686-1-vsementsov@virtuozzo.com> References: <20210902103805.25686-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b00357cd-54d5-44f8-f825-08d96dfdcb4f X-MS-TrafficTypeDiagnostic: AM6PR08MB4472: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:751; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wusoiT81vnDZjPWv3I+Us0TxI+MpOhkUCB4MeBkalvZkZtZsWnQ9S/KpWISrJ03EsJesWlsXvAGzmJ8PMDR1bxhTfD85525fci21vDEnE6KuOkQy8Ojafdquhkofdbt3kSZ+oVgalmOLPhOthANChU3zSZ1sPPkAcWKRGffOCN6n821HRvSc7hyGbOm/RpUMQiWLRSJVW6kM0WwxlQ4aQdzWE6lrib7wC3P8c/KtrkwYeHuX+AktOW+nvuLr6zAsj2Fzu6NwFjkrwrRkJO2sKzziCOnYmGXmrgkYT0lmfWM4Xhi9lALic9g8csmbTIpI0Fhr3nXvltTWwdB5h9nyJEs17kA8AhbrX67rR6t2a0VyRD7s60x8Bc6Nz2nYASnlWbTIiISio3ZfFtA6aUJOAem1pLkY0m21r1dlpKF58CB5ydVLbYjIkU0Wy/xqhGeaBAAjaFUsnnvTganaMlG1FFxD2ZMpHT4SB+TV8BapAsDoBk+MONHSmqsUfDGxAtMbK32wdgKsZZgHO4JyNxuVbFfAFCql12UZ/3jBggcssMaWS+gmevBp1o6aWxKPp8DRYxsGn0BsH7mOer8H5Y28bDVTqQ4FX87WKEtwjKpbdvKEeiN+cOLwemYYadKx5YfAT27Af6Y+8USGp96K9oiK/l6IA+cVZyXu/nz/NroT6aVQrVl91RMKyI+WsBCt68LbfITmPHdakf1CRqs6u1p82A== 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)(136003)(376002)(366004)(396003)(346002)(39840400004)(66476007)(4326008)(26005)(6506007)(66946007)(6666004)(8936002)(1076003)(5660300002)(316002)(83380400001)(186003)(8676002)(6512007)(38100700002)(38350700002)(2906002)(107886003)(66556008)(36756003)(6916009)(52116002)(956004)(2616005)(86362001)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kTkZXK43B0DZ67boFEg+HjuygAaCNliTEFPjV0Pmd2HRdE5ctR9WpFzABGMK?= =?us-ascii?Q?32LwZdf8J4Nh7qJLDaaOFlqhVHjgmoJrN9a3St56N9db+LwM7i6PR3TTPFas?= =?us-ascii?Q?pvyAcXkTmdGz4HpoXX+TzAh+6LPJEIKTNCPpbbYRnZDoU0TxCRENNTFVnnzy?= =?us-ascii?Q?D207QWJ0inkLlVp+XZRcS+fJKUgEuMTWZftDbnrQDVI1chcTuf96yfItsYGT?= =?us-ascii?Q?jBvdlHFx8ufoZeHQFkSh6Jbi2RlgV98c9DQIlFWqWnXVldpvW5WEO8BHUaPF?= =?us-ascii?Q?Ezmp4pjiialnbBOlJTt+qUUZB5Srwc0nJ27w7xnA+v6e3ImvlQwK30+mUxp8?= =?us-ascii?Q?J4kAYF0uNbcg7airno73NYKlU8f5wb9v7ztMdrt2W8IpqhGFFQrcUIhAxBIM?= =?us-ascii?Q?mgGPqLW08nkwskIFO/ZlIPnDa8r0lzz63Gfp5OdTmTzMxBNZ5p/K6M6d/rV1?= =?us-ascii?Q?WrLqhN+ViIVIvj3DRxOIh/5/iribl/yTDo/3mhggsTUm6ZT01WWb/IvuxeyY?= =?us-ascii?Q?Ji+FT0KvaK4NXR1DJetpbxwEMoYkEmT83cCZ2NmkGeU6D6MQbdhBZjEQ386w?= =?us-ascii?Q?IFZxJnd9bv0X55cZ2fehr8WBjc26ZDGTSdms3pD5ZEcyPVNMcW7xZbqXzorr?= =?us-ascii?Q?cHvYQgO2AExO6nrdCh0m6U3Tj75rvG0b5Wj3F1H41CMwRxLOuuNOrafveyHj?= =?us-ascii?Q?7HiX1F08dA9xrDyfR0JMILiBccve3mO3Dbxj4mWkp5n5yjkj+ClPinp2B2Ea?= =?us-ascii?Q?jCa0zw6G0iiTElYBSdMnzik9gjNqaZOY4ijY+4nWnY3WPEIeZ3n/w/o71uZQ?= =?us-ascii?Q?cDRksiYFWx0k+qXLI+vicpPvHDee1bvUCfTztXEbobO1RIJ5ZDpp5p+41wxF?= =?us-ascii?Q?gbrlLrYZSrCAp+ws4Jmi1oLRnn+gAP61qNBMp3z032oUnn6JkiIYDVQjnpRI?= =?us-ascii?Q?1V6S8LaXWuXAWI2aYV2ysSvt1kwgg4E3bP8qmMsLVtcUP1IMcL/eXqAvoNsv?= =?us-ascii?Q?lo9lJGOt86CPeeFA1bT0j94nizIMvbT0Tp8XfyibtzYF4pT2q6TE4+9gu1Jr?= =?us-ascii?Q?AXU8j/j/EMiDDDTWIJDIU5sNeu3eAXFwhxJcSX5qIEqxbJOWU1dBmPn69JOK?= =?us-ascii?Q?mVyzHyDDuR/TJzo24ABWOpqYHnSQmHJ6Lx5j4HS6JL4N0n51L2B/JCu1F7kT?= =?us-ascii?Q?gzjxtmbFrqDCUe5FBezi0pAQedYqSUYosdMw8Uf+d5NQIe05wzGCAhORM5bF?= =?us-ascii?Q?5ZNvg8Awg7srqGxJtSbXOctg01kJWqZtc8NsGtjdfc78vrIvZmjOeIwLAe1L?= =?us-ascii?Q?YYmFsM4UBhQdMpTFnv4KxKbg?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b00357cd-54d5-44f8-f825-08d96dfdcb4f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:38:25.5880 (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: x9FOWLQrnzVTloPjDe06FWUW/xiWxNtdueO8iINu2QswPBtiH2ZT+B+DpqQY3gMVNAKG6/mTPZhRuBh1jntmZGpogE0Y6uST2v5USoCxTDc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4472 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.3.115; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-AM5-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1630579255024100003 Content-Type: text/plain; charset="utf-8" Split out nbd_recv_coroutine_wake_one(), as it will be used in separate. Rename the function and add a possibility to wake only first found sleeping coroutine. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 32e3826ba2..52b0733684 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -127,16 +127,24 @@ static bool nbd_client_connected(BDRVNBDState *s) return qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTED; } =20 -static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) +static bool nbd_recv_coroutine_wake_one(NBDClientRequest *req) +{ + if (req->receiving) { + req->receiving =3D false; + aio_co_wake(req->coroutine); + return true; + } + + return false; +} + +static void nbd_recv_coroutines_wake(BDRVNBDState *s, bool all) { int i; =20 for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { - NBDClientRequest *req =3D &s->requests[i]; - - if (req->coroutine && req->receiving) { - req->receiving =3D false; - aio_co_wake(req->coroutine); + if (nbd_recv_coroutine_wake_one(&s->requests[i]) && !all) { + return; } } } @@ -415,7 +423,7 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDS= tate *s) =20 while (s->in_flight > 0) { qemu_co_mutex_unlock(&s->send_mutex); - nbd_recv_coroutines_wake_all(s); + nbd_recv_coroutines_wake(s, true); s->wait_in_flight =3D true; qemu_coroutine_yield(); s->wait_in_flight =3D false; @@ -558,7 +566,7 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) } =20 qemu_co_queue_restart_all(&s->free_sema); - nbd_recv_coroutines_wake_all(s); + nbd_recv_coroutines_wake(s, true); bdrv_dec_in_flight(s->bs); =20 s->connection_co =3D NULL; @@ -1035,7 +1043,7 @@ static coroutine_fn int nbd_co_receive_one_chunk( if (s->connection_co && !s->wait_in_flight) { /* * We must check s->wait_in_flight, because we may entered by - * nbd_recv_coroutines_wake_all(), in this case we should not + * nbd_recv_coroutines_wake(), in this case we should not * wake connection_co here, it will woken by last request. */ aio_co_wake(s->connection_co); --=20 2.29.2 From nobody Mon Apr 29 08:02:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1630579455; cv=pass; d=zohomail.com; s=zohoarc; b=BwB6fsB4rn+AvTOoVx5xzI+mqE7QncFmimLrmhS04qoscgLP7+yw7FnS9h5BdGt69jKGF5gWLhaNpGJHm6JoY7902K/bVyl9QZlpPkSbgkr0/Z16UhwtqhMgOkJt46EWTR6kyD7lLhnMmOx2ToyY9P5ChpdH/StzQpU7Fewo7bo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630579455; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BWOVYrcHRowZ0RnLHErw0HJp4jMaVJkHhzsCDDm6cJc=; b=l7EaaAOwVV8CIIbrKcNDbwbM8lLVRNcOupsd8uevJ7cwexKF8VOHMRrMCE/BxQUDG9Z8oNdYI2uV/PHm1xremwy/Gg4BMlvaSlCknq8BN2oBzQkO5Dd/8AiUhsEKwjqvojcNfmEmIB/yCCRGdyd9ndLIhxTwuhZLRYnCelGcbT0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630579454823660.5524383941491; Thu, 2 Sep 2021 03:44:14 -0700 (PDT) Received: from localhost ([::1]:36366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkCb-00045y-Mg for importer@patchew.org; Thu, 02 Sep 2021 06:44:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLk7E-0004aW-Bd; Thu, 02 Sep 2021 06:38:40 -0400 Received: from mail-eopbgr30115.outbound.protection.outlook.com ([40.107.3.115]:38273 helo=EUR03-AM5-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 1mLk7B-0005xI-9n; Thu, 02 Sep 2021 06:38:40 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4472.eurprd08.prod.outlook.com (2603:10a6:20b:bf::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20; Thu, 2 Sep 2021 10:38:26 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%8]) with mapi id 15.20.4478.019; Thu, 2 Sep 2021 10:38:26 +0000 Received: from localhost.localdomain (185.215.60.196) by HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:38:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PhBkVhSpzh7HxGHY967Ls/6lZgxKoLR7/iodaStwqhouJLsaiZiABfHLiFx3uadskEMphR1GHdXEU12p6j17jb/iyZD6iAL9IPvTKQB/Zmqy0AC1Vzw508Id5D1d45/LIA2LmEq1mGXT9CNHhJCJEjnID3c4CYgPgaetQxJ0a6FtNGGz/FXQk8xk5H0NHL0CWl27JOQYF6WW7BSgzupP6cjmwkYs5hzJ41PdUfV4aZVSTa6+YcQ2IhDJXnqcXrw0wWEVu2/eRidoe4hzFTo5aKfEMQcEUj2aHBD95dZYL5K/BIWKATnegGIZaCYMwmwrwjWhU+kjhUQ6VYBtsZx9kA== 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; bh=BWOVYrcHRowZ0RnLHErw0HJp4jMaVJkHhzsCDDm6cJc=; b=mspe497siIm0TWwmWFTuntIw9BCfA+UxDS9fENY11iH7mbqIg6uyaMmiDwI2frc7h8Mekfleddsu4ebiLXrzxsjv93FhntgGRiKgHL7GXxHaD1z85p7xIwNyNkMkdRkt1nICWNT8b2m5TDjIxTaMPBy/GL3r4pwxrVaO1DD0tM8hh97EPcUzbKZGZgaTG7JpGG4CvnSgavEZHmYKZlhCbvrMQLqcGzHT9WPket7kOKgKjZwXvK0k0RjEQ1F6dinT9SGN4vkYj14lgKL0Cqp3l7UatKvp19x4SXzeROTRG7C128CC4UnKF68+UQwWDR2U7sjrNaYShND8Zz8Fmv6oFQ== 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=BWOVYrcHRowZ0RnLHErw0HJp4jMaVJkHhzsCDDm6cJc=; b=QTb6gS7eQ/ZYrZsS6JfhTU6BECNEUSoilTOQ77hPonZ6jJtyAHUEn6ZYDDZv0iyTri0vz4o/MnV+BP72590pq40pxgRg5G9gE8ZvFUxc2qApsbP4+qNogIGCt/1EfbGqCU94fHys69lyZdNV0aiRiHkr6Z9BunQ7PC+evh2DZrY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rkagan@virtuozzo.com Subject: [PATCH v6 4/5] block/nbd: drop connection_co Date: Thu, 2 Sep 2021 13:38:04 +0300 Message-Id: <20210902103805.25686-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210902103805.25686-1-vsementsov@virtuozzo.com> References: <20210902103805.25686-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94379e14-0e26-4fea-6bad-08d96dfdcbe2 X-MS-TrafficTypeDiagnostic: AM6PR08MB4472: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DNf+0pH/BwRGdM24yV9Nc7iiZf/T/hrphFuJr6SYFYRbgxCoNyqNJD/EVi6ylLEEpGKAqA0y51M1VSs3CnTuRrDGgaU/uBwTFwJHg29ZG9SLEPc4nQ4DUGroT3AMbH11jm8NAC69FxxR2CEbBpscpP/SrPpBnW4tZhxoQHlX7pflxXb+y0pqPHAuQjT/Evj5OM0/uepo/aFhrZQnH2TTuQJbRmKJpbBb6l5YIfxNmekZ9PvEnznXDxpYUObg+3T/Ks35zxI1LAGCXoFTE8z9QDLYNJj5hed1Rc7yN8Dl/vt4yJ9XrObQkJmNehOY0c/2SJq6wMGkkg/+MDwHkKwQdUeqoTXP2s1pbtRHk6ZnjvAVDWSaVUBQo2M4KPL8jiBQ5Xb8tkIkQnpOZhOSiTem+UByClIOOrg94wHo5Do+KoarurXXd49OPIzPqCWLDqs7R/U4DMpRpG3AQIYUBJXYvxseHV8zCPOsTEqD2seGcrVlPywFuO3Ys2Snz0QZiPgHEP5DMuqFBjhORlu3q/2PkT62jqThiFnaV3t4uCEPNsjZUDbzTKm3dGGUJw8hPXxb/o0Uuv0sVIwpfcvleK/upnl/OyjAQdyaRdFapP8evoXaGaD1j01hsETH23JCpIURPQp7dBxudgnOt680XSVVK2ehrVO2V/PRS2UDjSFTdR/bsslov4ar95W4w2HWcjfWs/uHIXlqnwTnOP7jJE0jRA== 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)(136003)(376002)(366004)(396003)(346002)(39840400004)(66476007)(4326008)(26005)(6506007)(66946007)(6666004)(8936002)(1076003)(5660300002)(316002)(83380400001)(186003)(8676002)(6512007)(38100700002)(38350700002)(30864003)(2906002)(107886003)(66556008)(36756003)(6916009)(52116002)(956004)(2616005)(86362001)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?C0sRqXGYD7j9BWaaAse4lUu7BRN+9eB4J4yP3Y9uxuUgdmA2H5P2LHI+6WPB?= =?us-ascii?Q?7l5fhP4k7SE4mEOfL/R46mlR9Y4gFdwk8KeUj1r2hsbwzD96Vq4vfuCqXUx5?= =?us-ascii?Q?OmLyXafBgiPX8GQx5cpACyaHHRQPi2nwAgUrZLaXxMNk9HqOutQvWjDFxJY0?= =?us-ascii?Q?uvCAG7uIUns3uI8/XCR1gWF6y7l5dCdYEAUYoy+dSor7wdfRTCPWvdsZMCeq?= =?us-ascii?Q?YGNZBLKptwuzNjarWK5fZAj/8anXrHXltCakAY9jbpe+YvZ8mzKNoF+MEojf?= =?us-ascii?Q?y8VRXL1lVbbw1olOzDlwMjQA2OitLQveAa1F8xwR64dS1C+Ll43iNjBGqEnK?= =?us-ascii?Q?+43EWJdCWaFAisLNDEAwWVTX9BqgUenhl+d9dDUv7MHJqbXI8QvVveYjlwwy?= =?us-ascii?Q?PMpwF13wRWFjwQxL4f4ufU9meuVlZzYfYqtlpfgJ1o/e0YdgqJQXu2lz2/aX?= =?us-ascii?Q?vIDrwnu5+fsGC+tV8oa5QD341eNSfUxh9o9gY/JIEJqWvIEtsaMplwCeiFAz?= =?us-ascii?Q?OyFMC103D33le4XAdqkKSV2XvWjStoLKzbrVgMYqf+ovCdk9LQQvwIM8ES1N?= =?us-ascii?Q?JEjE8PyHtrEI0VzKMV1CJr2O/5EfEEVwdCV39srC4ZjRZHs7EuHtVwxYFpyT?= =?us-ascii?Q?ciIQmHHzflKJ9Y0hio5ExOW5bh9aW7peAKrI0k4UWC1xzN4EOsl6NFpWw4BO?= =?us-ascii?Q?7EIvXDFb41L2rKQ+/c3Tt7GW8IZmWVABH8Eh515GiwzQ9TnDFCZKtXxNxb0P?= =?us-ascii?Q?KT/vmNf727gxiDU/zzV9IwG1v88nllVHAXUGsoQKguXjq53CrUaMXoeBWQIX?= =?us-ascii?Q?TiNlEuVMXGEMcNs4CuuaWNu8aJWWB9GfMxwdFzW/I6V0HGPsjJqmKFSSPT5D?= =?us-ascii?Q?5Mieja29ScbDRyof0sg+gSTyZ1jX1ua8yBsCR7OcviMleSfOCncEVtJv4Gom?= =?us-ascii?Q?lHJihaFDmwXLOsGCybMd8kXwhn97RK5rquuOqVF9as7LiuFJUBQftugjADgk?= =?us-ascii?Q?xMCIZbgWDyzBEC2ix+Rgkj9AZRnUCsiMKgh3u1sxAbnsgm5MahpESYUe3CU5?= =?us-ascii?Q?wnyeOM4EJCEkOEYcY8PE2WeItj6H8wmy4ru4/lH/s6G0tN1XoMjxlxM2LPv1?= =?us-ascii?Q?4G7RNk2oDnnDVYrG2Ym01PslU+OJw/EJhkugURNUsxh0YCche34ok66j2blq?= =?us-ascii?Q?piL8b0m3/Ghnu74ce52iA+lO6M415IqUFFsbm1yzCQbgfZUmRJzvn0/d/Wdj?= =?us-ascii?Q?OMkIX4DYGDmyl7JHFj6EljQaYJpsZDXPIM3Yt7P2EUpOmwZYYJ0f4lxJmYxy?= =?us-ascii?Q?A4ujgtOFR/kuOYP4VFp12Kza?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94379e14-0e26-4fea-6bad-08d96dfdcbe2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:38:26.6692 (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: +jmTVJp/XVdQ2FARaSu/o0NgUSs2rqIVO1+1ETOkke8ioU2Jh21CLV2G4H0WA2L0GN2ugQNLnRoCNzvSjpbj9bhWdV2ANrsApUq2c2SLybo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4472 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.3.115; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-AM5-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1630579457182100001 Content-Type: text/plain; charset="utf-8" OK, that's a big rewrite of the logic. Pre-patch we have an always running coroutine - connection_co. It does reply receiving and reconnecting. And it leads to a lot of difficult and unobvious code around drained sections and context switch. We also abuse bs->in_flight counter which is increased for connection_co and temporary decreased in points where we want to allow drained section to begin. One of these place is in another file: in nbd_read_eof() in nbd/client.c. We also cancel reconnect and requests waiting for reconnect on drained begin which is not correct. And this patch fixes that. Let's finally drop this always running coroutine and go another way: do both reconnect and receiving in request coroutines. The detailed list of changes below (in the sequence of diff hunks). 1. receiving coroutines are woken directly from nbd_channel_error, when we change s->state 2. nbd_co_establish_connection_cancel(): we don't have drain_begin now, and in nbd_teardown_connection() all requests should already be finished (and reconnect is done from request). So nbd_co_establish_connection_cancel() is called from nbd_cancel_in_flight() (to cancel the request that is doing nbd_co_establish_connection()) and from reconnect_delay_timer_cb() (previously we didn't need it, as reconnect delay only should cancel active requests not the reconnection itself. But now reconnection itself is done in the separate thread (we now call nbd_client_connection_enable_retry() in nbd_open()), and we need to cancel the requests that waits in nbd_co_establish_connection() now). 2. We do receive headers in request coroutine. But we also should dispatch replies for another pending requests. So, nbd_connection_entry() is turned into nbd_receive_replies(), which does reply dispatching until it receive another request headers, and returns when it receive the requested header. 3. All old staff around drained sections and context switch is dropped. In details: - we don't need to move connection_co to new aio context, as we don't have connection_co anymore - we don't have a fake "request" of connection_co (extra increasing in_flight), so don't care with it in drain_begin/end - we don't stop reconnection during drained section anymore. This means that drain_begin may wait for a long time (up to reconnect_delay). But that's an improvement and more correct behavior see below[*] 4. In nbd_teardown_connection() we don't have to wait for connection_co, as it is dropped. And cleanup for s->ioc and nbd_yank is moved here from removed connection_co. 5. In nbd_co_do_establish_connection() we now should handle NBD_CLIENT_CONNECTING_NOWAIT: if new request comes when we are in NBD_CLIENT_CONNECTING_NOWAIT, it still should call nbd_co_establish_connection() (who knows, maybe connection already established by thread in background). But we shouldn't wait: if nbd_co_establish_connection() can't return new channel immediately the request should fail (we are in NBD_CLIENT_CONNECTING_NOWAIT state). 6. nbd_reconnect_attempt() is simplified: it's now easier to wait for other requests in the caller, so here we just assert that fact. Also delay time is now initialized here: we can easily detect first attempt and start a timer. 7. nbd_co_reconnect_loop() is dropped, we don't need it. Reconnect retries are fully handle by thread (nbd/client-connection.c), delay timer we initialize in nbd_reconnect_attempt(), we don't have to bother with s->drained and friends. nbd_reconnect_attempt() now called from nbd_co_send_request(). 8. nbd_connection_entry is dropped: reconnect is now handled by nbd_co_send_request(), receiving reply is now handled by nbd_receive_replies(): all handled from request coroutines. 9. So, welcome new nbd_receive_replies() called from request coroutine, that receives reply header instead of nbd_connection_entry(). Like with sending requests, only one coroutine may receive in a moment. So we introduce receive_mutex, which is locked around nbd_receive_reply(). It also protects some related fields. Still, full audit of thread-safety in nbd driver is a separate task. New function waits for a reply with specified handle being received and works rather simple: Under mutex: - if current handle is 0, do receive by hand. If another handle received - switch to other request coroutine, release mutex and yield. Otherwise return success - if current handle =3D=3D requested handle, we are done - otherwise, release mutex and yield 10: in nbd_co_send_request() we now do nbd_reconnect_attempt() if needed. Also waiting in free_sema queue we now wait for one of two conditions: - connectED, in_flight < MAX_NBD_REQUESTS (so we can start new one) - connectING, in_flight =3D=3D 0, so we can call nbd_reconnect_attempt() And this logic is protected by s->send_mutex Also, on failure we don't have to care of removed s->connection_co 11. nbd_co_do_receive_one_chunk(): now instead of yield() and wait for s->connection_co we just call new nbd_receive_replies(). 12. nbd_co_receive_one_chunk(): place where s->reply.handle becomes 0, which means that handling of the whole reply is finished. Here we need to wake one of coroutines sleeping in nbd_receive_replies(). If now one sleeps - do nothing. That's another behavior change: we don't have endless recv() in the idle time. It may be considered as a drawback. If so, it may be fixed later. 13. nbd_reply_chunk_iter_receive(): don't care about removed connection_co, just ping in_flight waiters. 14. Don't create connection_co, enable retry in the connection thread (we don't have own reconnect loop anymore) 15. We need now nbd_co_establish_connection_cancel() call in nbd_cancel_in_flight(), to cancel the request that doing connection attempt. [*], ok, now we don't cancel reconnect on drain begin. That's correct: reconnect feature leads to possibility of long-running requests (up to reconnect delay). Still, drain begin is not a reason to kill long requests. We should wait for them. This also means, that we can again reproduce a dead-lock, described in 8c517de24a8a1dcbeb54e7e12b5b0fda42a90ace. Why we are OK with it: 1. Now this is not absolutely-dead dead-lock: the vm is unfrozen after reconnect delay. Actually 8c517de24a8a1dc fixed a bug in NBD logic, that was not described in 8c517de24a8a1dc and led to forever dead-lock. The problem was that nobody woken free_sema queue, but drain_begin can't finish until there is a request in free_sema queue. Now we have a reconnect delay timer that works well. 2. It's not a problem of NBD driver, it's a problem of ide code, that does drain_begin under global mutex 3. That doesn't reproduce if chose scsi instead of ide. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd.c | 374 ++++++++++++++------------------------------------- nbd/client.c | 2 - 2 files changed, 99 insertions(+), 277 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 52b0733684..170a8c8eeb 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -57,7 +57,7 @@ typedef struct { Coroutine *coroutine; uint64_t offset; /* original offset of the request */ - bool receiving; /* waiting for connection_co? */ + bool receiving; /* sleeping in the yield in nbd_receive_replie= s */ } NBDClientRequest; =20 typedef enum NBDClientState { @@ -73,14 +73,10 @@ typedef struct BDRVNBDState { =20 CoMutex send_mutex; CoQueue free_sema; - Coroutine *connection_co; - Coroutine *teardown_co; - QemuCoSleep reconnect_sleep; - bool drained; - bool wait_drained_end; + + CoMutex receive_mutex; int in_flight; NBDClientState state; - bool wait_in_flight; =20 QEMUTimer *reconnect_delay_timer; =20 @@ -163,6 +159,8 @@ static void nbd_channel_error(BDRVNBDState *s, int ret) } else { s->state =3D NBD_CLIENT_QUIT; } + + nbd_recv_coroutines_wake(s, true); } =20 static void reconnect_delay_timer_del(BDRVNBDState *s) @@ -179,6 +177,7 @@ static void reconnect_delay_timer_cb(void *opaque) =20 if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WAIT)= { s->state =3D NBD_CLIENT_CONNECTING_NOWAIT; + nbd_co_establish_connection_cancel(s->conn); while (qemu_co_enter_next(&s->free_sema, NULL)) { /* Resume all queued requests */ } @@ -201,113 +200,21 @@ static void reconnect_delay_timer_init(BDRVNBDState = *s, uint64_t expire_time_ns) timer_mod(s->reconnect_delay_timer, expire_time_ns); } =20 -static void nbd_client_detach_aio_context(BlockDriverState *bs) -{ - BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - - /* Timer is deleted in nbd_client_co_drain_begin() */ - assert(!s->reconnect_delay_timer); - /* - * If reconnect is in progress we may have no ->ioc. It will be - * re-instantiated in the proper aio context once the connection is - * reestablished. - */ - if (s->ioc) { - qio_channel_detach_aio_context(QIO_CHANNEL(s->ioc)); - } -} - -static void nbd_client_attach_aio_context_bh(void *opaque) -{ - BlockDriverState *bs =3D opaque; - BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - - if (s->connection_co) { - /* - * The node is still drained, so we know the coroutine has yielded= in - * nbd_read_eof(), the only place where bs->in_flight can reach 0,= or - * it is entered for the first time. Both places are safe for ente= ring - * the coroutine. - */ - qemu_aio_coroutine_enter(bs->aio_context, s->connection_co); - } - bdrv_dec_in_flight(bs); -} - -static void nbd_client_attach_aio_context(BlockDriverState *bs, - AioContext *new_context) -{ - BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - - /* - * s->connection_co is either yielded from nbd_receive_reply or from - * nbd_co_reconnect_loop() - */ - if (nbd_client_connected(s)) { - qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context); - } - - bdrv_inc_in_flight(bs); - - /* - * Need to wait here for the BH to run because the BH must run while t= he - * node is still drained. - */ - aio_wait_bh_oneshot(new_context, nbd_client_attach_aio_context_bh, bs); -} - -static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs) -{ - BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - - s->drained =3D true; - qemu_co_sleep_wake(&s->reconnect_sleep); - - nbd_co_establish_connection_cancel(s->conn); - - reconnect_delay_timer_del(s); - - if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WAIT)= { - s->state =3D NBD_CLIENT_CONNECTING_NOWAIT; - qemu_co_queue_restart_all(&s->free_sema); - } -} - -static void coroutine_fn nbd_client_co_drain_end(BlockDriverState *bs) -{ - BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - - s->drained =3D false; - if (s->wait_drained_end) { - s->wait_drained_end =3D false; - aio_co_wake(s->connection_co); - } -} - - static void nbd_teardown_connection(BlockDriverState *bs) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; =20 + assert(!s->in_flight); + if (s->ioc) { - /* finish any pending coroutines */ qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), + nbd_yank, s->bs); + object_unref(OBJECT(s->ioc)); + s->ioc =3D NULL; } =20 s->state =3D NBD_CLIENT_QUIT; - if (s->connection_co) { - qemu_co_sleep_wake(&s->reconnect_sleep); - nbd_co_establish_connection_cancel(s->conn); - } - if (qemu_in_coroutine()) { - s->teardown_co =3D qemu_coroutine_self(); - /* connection_co resumes us when it terminates */ - qemu_coroutine_yield(); - s->teardown_co =3D NULL; - } else { - BDRV_POLL_WHILE(bs, s->connection_co); - } - assert(!s->connection_co); } =20 static bool nbd_client_connecting(BDRVNBDState *s) @@ -372,10 +279,11 @@ int coroutine_fn nbd_co_do_establish_connection(Block= DriverState *bs, { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; int ret; + bool blocking =3D nbd_client_connecting_wait(s); =20 assert(!s->ioc); =20 - s->ioc =3D nbd_co_establish_connection(s->conn, &s->info, true, errp); + s->ioc =3D nbd_co_establish_connection(s->conn, &s->info, blocking, er= rp); if (!s->ioc) { return -ECONNREFUSED; } @@ -411,29 +319,22 @@ int coroutine_fn nbd_co_do_establish_connection(Block= DriverState *bs, return 0; } =20 +/* called under s->send_mutex */ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) { - if (!nbd_client_connecting(s)) { - return; - } + assert(nbd_client_connecting(s)); + assert(s->in_flight =3D=3D 0); =20 - /* Wait for completion of all in-flight requests */ - - qemu_co_mutex_lock(&s->send_mutex); - - while (s->in_flight > 0) { - qemu_co_mutex_unlock(&s->send_mutex); - nbd_recv_coroutines_wake(s, true); - s->wait_in_flight =3D true; - qemu_coroutine_yield(); - s->wait_in_flight =3D false; - qemu_co_mutex_lock(&s->send_mutex); - } - - qemu_co_mutex_unlock(&s->send_mutex); - - if (!nbd_client_connecting(s)) { - return; + if (nbd_client_connecting_wait(s) && s->reconnect_delay && + !s->reconnect_delay_timer) + { + /* + * It's first reconnect attempt after switching to + * NBD_CLIENT_CONNECTING_WAIT + */ + reconnect_delay_timer_init(s, + qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + + s->reconnect_delay * NANOSECONDS_PER_SECOND); } =20 /* @@ -453,135 +354,79 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVN= BDState *s) nbd_co_do_establish_connection(s->bs, NULL); } =20 -static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s) +static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t hand= le) { - uint64_t timeout =3D 1 * NANOSECONDS_PER_SECOND; - uint64_t max_timeout =3D 16 * NANOSECONDS_PER_SECOND; + int ret; + uint64_t ind =3D HANDLE_TO_INDEX(s, handle), ind2; + QEMU_LOCK_GUARD(&s->receive_mutex); =20 - if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WAIT)= { - reconnect_delay_timer_init(s, qemu_clock_get_ns(QEMU_CLOCK_REALTIM= E) + - s->reconnect_delay * NANOSECONDS_PER_SE= COND); - } - - nbd_reconnect_attempt(s); - - while (nbd_client_connecting(s)) { - if (s->drained) { - bdrv_dec_in_flight(s->bs); - s->wait_drained_end =3D true; - while (s->drained) { - /* - * We may be entered once from nbd_client_attach_aio_conte= xt_bh - * and then from nbd_client_co_drain_end. So here is a loo= p. - */ - qemu_coroutine_yield(); - } - bdrv_inc_in_flight(s->bs); - } else { - qemu_co_sleep_ns_wakeable(&s->reconnect_sleep, - QEMU_CLOCK_REALTIME, timeout); - if (s->drained) { - continue; - } - if (timeout < max_timeout) { - timeout *=3D 2; - } + while (true) { + if (s->reply.handle =3D=3D handle) { + /* We are done */ + return 0; } =20 - nbd_reconnect_attempt(s); - } - - reconnect_delay_timer_del(s); -} + if (!nbd_client_connected(s)) { + return -EIO; + } =20 -static coroutine_fn void nbd_connection_entry(void *opaque) -{ - BDRVNBDState *s =3D opaque; - uint64_t i; - int ret =3D 0; - Error *local_err =3D NULL; + if (s->reply.handle !=3D 0) { + /* + * Some other request is being handling now. It should already= be + * woken by thous who set s->reply.handle (or never wait in th= is + * yield). So, we should not wake it here. + */ + ind2 =3D HANDLE_TO_INDEX(s, s->reply.handle); + assert(!s->requests[ind2].receiving); =20 - while (qatomic_load_acquire(&s->state) !=3D NBD_CLIENT_QUIT) { - /* - * The NBD client can only really be considered idle when it has - * yielded from qio_channel_readv_all_eof(), waiting for data. Thi= s is - * the point where the additional scheduled coroutine entry happens - * after nbd_client_attach_aio_context(). - * - * Therefore we keep an additional in_flight reference all the tim= e and - * only drop it temporarily here. - */ + s->requests[ind].receiving =3D true; + qemu_co_mutex_unlock(&s->receive_mutex); =20 - if (nbd_client_connecting(s)) { - nbd_co_reconnect_loop(s); - } + qemu_coroutine_yield(); + /* + * We may be woken for 3 reasons: + * 1. From this function, executing in parallel coroutine, whe= n our + * handle received. + * 2. From nbd_channel_error(), when connection is lost. + * 3. From nbd_co_receive_one_chunk(), when previous request is + * finished and s->reply.handle set to 0. + * Anyway, it's OK to lock the mutex and go to the next iterat= ion. + */ =20 - if (!nbd_client_connected(s)) { + qemu_co_mutex_lock(&s->receive_mutex); + assert(!s->requests[ind].receiving); continue; } =20 + /* We are under mutex and handle is 0. We have to do the dirty wor= k. */ assert(s->reply.handle =3D=3D 0); - ret =3D nbd_receive_reply(s->bs, s->ioc, &s->reply, &local_err); - - if (local_err) { - trace_nbd_read_reply_entry_fail(ret, error_get_pretty(local_er= r)); - error_free(local_err); - local_err =3D NULL; - } + ret =3D nbd_receive_reply(s->bs, s->ioc, &s->reply, NULL); if (ret <=3D 0) { - nbd_channel_error(s, ret ? ret : -EIO); - continue; + ret =3D ret ? ret : -EIO; + nbd_channel_error(s, ret); + return ret; } - - /* - * There's no need for a mutex on the receive side, because the - * handler acts as a synchronization point and ensures that only - * one coroutine is called until the reply finishes. - */ - i =3D HANDLE_TO_INDEX(s, s->reply.handle); - if (i >=3D MAX_NBD_REQUESTS || - !s->requests[i].coroutine || - !s->requests[i].receiving || - (nbd_reply_is_structured(&s->reply) && !s->info.structured_rep= ly)) - { + if (nbd_reply_is_structured(&s->reply) && !s->info.structured_repl= y) { nbd_channel_error(s, -EINVAL); - continue; + return -EINVAL; } - - /* - * We're woken up again by the request itself. Note that there - * is no race between yielding and reentering connection_co. This - * is because: - * - * - if the request runs on the same AioContext, it is only - * entered after we yield - * - * - if the request runs on a different AioContext, reentering - * connection_co happens through a bottom half, which can only - * run after we yield. - */ - s->requests[i].receiving =3D false; - aio_co_wake(s->requests[i].coroutine); - qemu_coroutine_yield(); - } - - qemu_co_queue_restart_all(&s->free_sema); - nbd_recv_coroutines_wake(s, true); - bdrv_dec_in_flight(s->bs); - - s->connection_co =3D NULL; - if (s->ioc) { - qio_channel_detach_aio_context(QIO_CHANNEL(s->ioc)); - yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), - nbd_yank, s->bs); - object_unref(OBJECT(s->ioc)); - s->ioc =3D NULL; - } - - if (s->teardown_co) { - aio_co_wake(s->teardown_co); + if (s->reply.handle =3D=3D handle) { + /* We are done */ + return 0; + } + ind2 =3D HANDLE_TO_INDEX(s, s->reply.handle); + if (ind2 >=3D MAX_NBD_REQUESTS || !s->requests[ind2].coroutine) { + /* + * We only check that ind2 request exists. But don't check is = it now + * waiting for the reply header or not. We can't just check + * s->requests[ind2].receiving: ind2 request may wait in tryin= g to + * lock receive_mutex. So that's a TODO. + */ + nbd_channel_error(s, -EINVAL); + return -EINVAL; + } + nbd_recv_coroutine_wake_one(&s->requests[ind2]); } - aio_wait_kick(); } =20 static int nbd_co_send_request(BlockDriverState *bs, @@ -592,10 +437,17 @@ static int nbd_co_send_request(BlockDriverState *bs, int rc, i =3D -1; =20 qemu_co_mutex_lock(&s->send_mutex); - while (s->in_flight =3D=3D MAX_NBD_REQUESTS || nbd_client_connecting_w= ait(s)) { + + while (s->in_flight =3D=3D MAX_NBD_REQUESTS || + (!nbd_client_connected(s) && s->in_flight > 0)) + { qemu_co_queue_wait(&s->free_sema, &s->send_mutex); } =20 + if (nbd_client_connecting(s)) { + nbd_reconnect_attempt(s); + } + if (!nbd_client_connected(s)) { rc =3D -EIO; goto err; @@ -642,10 +494,6 @@ err: if (i !=3D -1) { s->requests[i].coroutine =3D NULL; s->in_flight--; - } - if (s->in_flight =3D=3D 0 && s->wait_in_flight) { - aio_co_wake(s->connection_co); - } else { qemu_co_queue_next(&s->free_sema); } } @@ -944,10 +792,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( } *request_ret =3D 0; =20 - /* Wait until we're woken up by nbd_connection_entry. */ - s->requests[i].receiving =3D true; - qemu_coroutine_yield(); - assert(!s->requests[i].receiving); + nbd_receive_replies(s, handle); if (!nbd_client_connected(s)) { error_setg(errp, "Connection closed"); return -EIO; @@ -1040,14 +885,7 @@ static coroutine_fn int nbd_co_receive_one_chunk( } s->reply.handle =3D 0; =20 - if (s->connection_co && !s->wait_in_flight) { - /* - * We must check s->wait_in_flight, because we may entered by - * nbd_recv_coroutines_wake(), in this case we should not - * wake connection_co here, it will woken by last request. - */ - aio_co_wake(s->connection_co); - } + nbd_recv_coroutines_wake(s, false); =20 return ret; } @@ -1158,11 +996,7 @@ break_loop: =20 qemu_co_mutex_lock(&s->send_mutex); s->in_flight--; - if (s->in_flight =3D=3D 0 && s->wait_in_flight) { - aio_co_wake(s->connection_co); - } else { - qemu_co_queue_next(&s->free_sema); - } + qemu_co_queue_next(&s->free_sema); qemu_co_mutex_unlock(&s->send_mutex); =20 return false; @@ -1978,6 +1812,7 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, s->bs =3D bs; qemu_co_mutex_init(&s->send_mutex); qemu_co_queue_init(&s->free_sema); + qemu_co_mutex_init(&s->receive_mutex); =20 if (!yank_register_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name), err= p)) { return -EEXIST; @@ -1992,14 +1827,13 @@ static int nbd_open(BlockDriverState *bs, QDict *op= tions, int flags, s->x_dirty_bitmap, s->tlscreds); =20 /* TODO: Configurable retry-until-timeout behaviour. */ + s->state =3D NBD_CLIENT_CONNECTING_WAIT; ret =3D nbd_do_establish_connection(bs, errp); if (ret < 0) { goto fail; } =20 - s->connection_co =3D qemu_coroutine_create(nbd_connection_entry, s); - bdrv_inc_in_flight(bs); - aio_co_schedule(bdrv_get_aio_context(bs), s->connection_co); + nbd_client_connection_enable_retry(s->conn); =20 return 0; =20 @@ -2153,6 +1987,8 @@ static void nbd_cancel_in_flight(BlockDriverState *bs) s->state =3D NBD_CLIENT_CONNECTING_NOWAIT; qemu_co_queue_restart_all(&s->free_sema); } + + nbd_co_establish_connection_cancel(s->conn); } =20 static BlockDriver bdrv_nbd =3D { @@ -2173,10 +2009,6 @@ static BlockDriver bdrv_nbd =3D { .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, .bdrv_getlength =3D nbd_getlength, - .bdrv_detach_aio_context =3D nbd_client_detach_aio_context, - .bdrv_attach_aio_context =3D nbd_client_attach_aio_context, - .bdrv_co_drain_begin =3D nbd_client_co_drain_begin, - .bdrv_co_drain_end =3D nbd_client_co_drain_end, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, @@ -2202,10 +2034,6 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, .bdrv_getlength =3D nbd_getlength, - .bdrv_detach_aio_context =3D nbd_client_detach_aio_context, - .bdrv_attach_aio_context =3D nbd_client_attach_aio_context, - .bdrv_co_drain_begin =3D nbd_client_co_drain_begin, - .bdrv_co_drain_end =3D nbd_client_co_drain_end, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, @@ -2231,10 +2059,6 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, .bdrv_getlength =3D nbd_getlength, - .bdrv_detach_aio_context =3D nbd_client_detach_aio_context, - .bdrv_attach_aio_context =3D nbd_client_attach_aio_context, - .bdrv_co_drain_begin =3D nbd_client_co_drain_begin, - .bdrv_co_drain_end =3D nbd_client_co_drain_end, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, diff --git a/nbd/client.c b/nbd/client.c index 0c2db4bcba..30d5383cb1 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1434,9 +1434,7 @@ nbd_read_eof(BlockDriverState *bs, QIOChannel *ioc, v= oid *buffer, size_t size, =20 len =3D qio_channel_readv(ioc, &iov, 1, errp); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - bdrv_dec_in_flight(bs); qio_channel_yield(ioc, G_IO_IN); - bdrv_inc_in_flight(bs); continue; } else if (len < 0) { return -EIO; --=20 2.29.2 From nobody Mon Apr 29 08:02:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1630579563; cv=pass; d=zohomail.com; s=zohoarc; b=iVhxIYg7rGKeHTpx6shGFcaqEEPr7vCn3hWXv7rwM2/nrtJjkwaoWtUqdI1/J+g8giW4o2ZJi9JKdsCMpHinWflM4lcG04KKRbHSHQT/eOeEglNbB5KaSfi1LpDVhhhN51RrnZszAdN+wMlcHRpNtvYhciom4v9uJe/Yt/aFFN8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630579563; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=41fG26z6Y13c8eQ9Vjz254CYkrQZnvXTimV1p+MiFR0=; b=htn2BePc5W8NUqf9+ZTAaWy8RX4iDmALJLeMeoTXUm+NxGvxdwEgrZZsMLgTN1YinYXBxPVEY0AsMTdkor++ah55iqtUW7/KjT0D2xCCuuLX0ZuQUcNqcjWIS7Awv90OmbCrrnc8cjr5aH7PDqgKYm+Bqt58bM+ix3bo+4Qw0oQ= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630579563155917.3597619075722; Thu, 2 Sep 2021 03:46:03 -0700 (PDT) Received: from localhost ([::1]:39456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkEM-0006Ar-3B for importer@patchew.org; Thu, 02 Sep 2021 06:46:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLk7G-0004d6-RX; Thu, 02 Sep 2021 06:38:46 -0400 Received: from mail-eopbgr30115.outbound.protection.outlook.com ([40.107.3.115]:38273 helo=EUR03-AM5-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 1mLk7E-0005xI-Vf; Thu, 02 Sep 2021 06:38:42 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4472.eurprd08.prod.outlook.com (2603:10a6:20b:bf::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20; Thu, 2 Sep 2021 10:38:27 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%8]) with mapi id 15.20.4478.019; Thu, 2 Sep 2021 10:38:27 +0000 Received: from localhost.localdomain (185.215.60.196) by HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:38:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JXm1GC2PvhXRn95RdnrlkamT6pRHzLY/qv7KMvubCDHdvAwRo7exKjyESFy4W9Guif9KkXs1hwLiMwTAMc2lQGnEv4S/JJWSbn6Mw+dTmti8OycZyuMFQjvm21pX8IPzcB7BztQJT5WAonFWeobJ9mc6NDXYt0hsY9EAxytRRg+vqjegIrxgZt7LUCeluDqiZu04JX/PjxaUIp1RT92OoRz7m2iI6RRRSm4mvc/1P1kH1xYDX7JwM8geSoPZVWQ4/qP6dHafjONphx0A5eQosvXL7LXPgNRYoJPFFKGAmOpM7HxKBv+GORBO1z+q/w0MIvP/lW+H5N23miOaI0qTXw== 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; bh=41fG26z6Y13c8eQ9Vjz254CYkrQZnvXTimV1p+MiFR0=; b=Z9yf2ryo6p9npF9NrS+3lfA8Cvj66HQMpW1JxvwTW8dGrJyQUZ6ZD7212px3ShGDdrJRFOXvmcUl1b8bNcpNY64PsEJpGYfRgpMVmcn0Zt5AZyLM8O58bLCYUXTr4wT/rYUIHnIkEbExg8xjoDMN5pv5se2Gk8Ta7WRnwmJ7JbI94Cr64mtBRbtPbKC4u8ywKOE11utsBqUmkLHO7Qhesrvh0O7RiOyTydb3+iYr46+meAkpWpPiFjrPREWxy/qIJFrUkHORCjQfwu7Lm/+iJ9BzPFaWLKJnED7aoP5oOsJedf6yt345tpnyqXsgOn3tQYA6XWd66fUHmzAyD4C3XQ== 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=41fG26z6Y13c8eQ9Vjz254CYkrQZnvXTimV1p+MiFR0=; b=Alz52g4IdG+fNXzocKRh1ClFjHVZ5x6+RUiBhZ/AAtCcB9rUWm0aV+IlgpEPdwlvHjPpesuG6rkU6Z1Ha4T5UYKgf2APFeW2Q4YNsrzVU/c/coDxy0F9GgJ0xIiUS8WczBcE7x14V03Po1DWml39GuwL5/zwFOVzCXCO0thz9Qs= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rkagan@virtuozzo.com Subject: [PATCH v6 5/5] block/nbd: check that received handle is valid Date: Thu, 2 Sep 2021 13:38:05 +0300 Message-Id: <20210902103805.25686-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210902103805.25686-1-vsementsov@virtuozzo.com> References: <20210902103805.25686-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HE1PR0402CA0037.eurprd04.prod.outlook.com (2603:10a6:7:7c::26) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab0e0faf-483c-4a6b-106d-08d96dfdcc84 X-MS-TrafficTypeDiagnostic: AM6PR08MB4472: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8D27mNo8pYjPOQfmsoOMSAKcyJWhOEbW/tTFcGPgtmxd1HvxWMIT9XfbW3j9l6rcw7D4j7wU12daFxbbACBx+cgNZsRt303nxaoVvuo8DIfES+xgH4zc762OpIwCNEIeg8V5MRkgEsSWeScOKSdXJ8XxFsucIZVbB8AV8AOdV/rcLsWXvSCsyPE4UVnYzEUECbFK38Nk5lEbDO0JdzXLoy3tzMys67615rfB5oRIqum0T2OeJuHd9WZ0C15Eb3sNDt+SFvVraObgoW0fQbCfpFvRS5bLtb7ip7DTmxUjkVrcoEQHcORWUA57F1G4dcMq3mtCp0giKtBtjLh8XspJahLkqS8eUBfH3JyRf5cxK4XjIloumE1BZLamAUP0V9vXnLoPp77AIfdToqmHrTrKsr7Yfoq/G+frX/qSY9gWNN7XiipAZ1yZYZGddNAePnI1q+1xYL599VlY/rWW0oYPMkT3TdZba+N2J3BSd2Sd4LutcnHEJ9IvWEp9nTG+8DGH2RVp33tZPb3SC8Y+seyUB8X/wu4HmC4zFVds/0WqpRVSN/pOn3obd0eVEEGi/fDbk6qvpxoXll37vlbWMTSBTSsiSBTPshPK4qJTIDzCHCXyaH2lcfBA9SiqU+E0KSXWdf9cNlBF01gTfWgcr/7QaeQQ2FlD7CmVu5ykjtFqftcHXlwW8oVOP6gs32l+E0pkwu1RRJi1J3B8xh7RNgbXdQ== 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)(136003)(376002)(366004)(396003)(346002)(39840400004)(66476007)(4326008)(26005)(6506007)(66946007)(6666004)(8936002)(1076003)(5660300002)(316002)(83380400001)(186003)(8676002)(6512007)(38100700002)(38350700002)(2906002)(107886003)(66556008)(36756003)(6916009)(52116002)(956004)(2616005)(86362001)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?OfGqQgWBShBc+z4jWnVaqF7gfaiyWSRWzOyWHj/cIb92lL+HZvC4heMDXJdN?= =?us-ascii?Q?kQwf5D0ClrOxhQv/4JxlWDC0kSIKa9UBjx0e3i2Oc3nXBFkv6l9qOP9/RLHx?= =?us-ascii?Q?qpAuBSsvzY7LeCSbXEyi5m2zmvKLr5PqmyDC2P/3IshXYBoZAFeEv8tzHGAC?= =?us-ascii?Q?ibPAv9U0s3z7aef0qBrmKpCc7kD/gnzWtQHwRX0UZ00apzsVojB47pR9XFJY?= =?us-ascii?Q?4QihlZgh9x2PsWxvfuSRC26Bbvyt9tiIazUxfER/NlIwbINva74HE7T4poW/?= =?us-ascii?Q?B8a3OdyvGSUoTB0220tWctZ+bD+abkvvpIVwgSMXduDLlRc+hCO6P9z2s/bf?= =?us-ascii?Q?74WplXC146NkFKcdA68gQqOtIf4A6o6qrzvRU4+MgxOyX8kOMJFwfbnkirqi?= =?us-ascii?Q?zxxRUXBeYuwtthmW1FpiAIrcYXaXEB7EiaNFioVb37osI2M8k/X8axcQkKR7?= =?us-ascii?Q?JyeG4uFBTxCJscANV6Lu42fGLgQj8QNAt6J4M9TqWozbMXG++DNzxN/q+q+i?= =?us-ascii?Q?IdO+sBPl7AcVjsQ+itTiPqkoG5yXsWWakxAxGfQoFI1BB/kio57tnne0Ypwr?= =?us-ascii?Q?w/736llZKPIuXjEUwC6TzJgL6QG0cW5w+kKPYxX1ekq4XCGZrGPUGSbCmX2y?= =?us-ascii?Q?zZXo0+uEZ4CtClBdPEWY/exjGLPwBSbhXlVUjcXJrMdgsVC4eUGl4pp4ZLA3?= =?us-ascii?Q?XKuJmZdfmqJr3gPj4Bg28ZBPaGKXRYnxNleSUqPqcOKptnkgdIGO1xoj1q+I?= =?us-ascii?Q?3t72S2gDQMNnJhnMY8gckbLs+fQlYbGMGx7QGveGWWiMYU2AQdrUYcC+ZLo7?= =?us-ascii?Q?Eul2jCTYGmeLvAzqYuP/OTqzqHoKJPQloBSjr/9Sba0kaSamPq5NDDljG6OX?= =?us-ascii?Q?wc2IftWH0cpOKSwonrJ5hN5Psue6w77QcUTcHs6nP4RU3QEmh7aW33jlRGLV?= =?us-ascii?Q?wrVCojP4HThQRrmcywgnEdpW0Akz7vYPGbrH8j+hbP6WwnEBGC4HZNr7RWm5?= =?us-ascii?Q?n9HcYUPLsQyUG8Qurl5zNc3wVe0av1DQ3QcMt2NY62vu/JMAJRFYCZS2FqxL?= =?us-ascii?Q?x3OqZwtn+35GZKouM9v1qbRlBdwOj/ld2eWxuKGprKYdterSgSY0OqZsXRy7?= =?us-ascii?Q?Z/hf71eMzwzT7Is3nHafiJ8vw8KLhFB3Oxu+hky/4A1afd4qQ4IHsOEj9BfD?= =?us-ascii?Q?d6QvDVaaAQSGOJylPxRw2Q/ZOvj8e1dKHyt334B81toBddDjLIW4Guv6BYD+?= =?us-ascii?Q?QZiFQy4YZWa6mvrEgaciuQtvea8EhzbYJgWoCQBc71JhhpVU5WLAP7EhEkMi?= =?us-ascii?Q?rnXZGA7s0EfL8prog7v+zeap?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab0e0faf-483c-4a6b-106d-08d96dfdcc84 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:38:27.6270 (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: MJCE9AHc1XmY1CFiOiBEzb+fv/+fZtVFmF/Lg97JwoAQDknNwgOHRk5Q2ojlP6wa0CYxxaPTwuzQrNXmHAOcmULazSKP4/F0RmCg+9XYkHs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4472 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.3.115; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-AM5-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1630579563681100001 Content-Type: text/plain; charset="utf-8" If we don't have active request, that waiting for this handle to be received, we should report an error. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 170a8c8eeb..306b2de9f2 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -58,6 +58,7 @@ typedef struct { Coroutine *coroutine; uint64_t offset; /* original offset of the request */ bool receiving; /* sleeping in the yield in nbd_receive_replie= s */ + bool reply_possible; /* reply header not yet received */ } NBDClientRequest; =20 typedef enum NBDClientState { @@ -415,16 +416,11 @@ static coroutine_fn int nbd_receive_replies(BDRVNBDSt= ate *s, uint64_t handle) return 0; } ind2 =3D HANDLE_TO_INDEX(s, s->reply.handle); - if (ind2 >=3D MAX_NBD_REQUESTS || !s->requests[ind2].coroutine) { - /* - * We only check that ind2 request exists. But don't check is = it now - * waiting for the reply header or not. We can't just check - * s->requests[ind2].receiving: ind2 request may wait in tryin= g to - * lock receive_mutex. So that's a TODO. - */ + if (ind2 >=3D MAX_NBD_REQUESTS || !s->requests[ind2].reply_possibl= e) { nbd_channel_error(s, -EINVAL); return -EINVAL; } + s->requests[ind2].reply_possible =3D false; nbd_recv_coroutine_wake_one(&s->requests[ind2]); } } @@ -467,6 +463,7 @@ static int nbd_co_send_request(BlockDriverState *bs, s->requests[i].coroutine =3D qemu_coroutine_self(); s->requests[i].offset =3D request->from; s->requests[i].receiving =3D false; + s->requests[i].reply_possible =3D true; =20 request->handle =3D INDEX_TO_HANDLE(s, i); =20 --=20 2.29.2