From patchwork Thu Sep 2 10:38:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12471231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8332C432BE for ; Thu, 2 Sep 2021 10:42:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6161961074 for ; Thu, 2 Sep 2021 10:42:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6161961074 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:33512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkAU-00028z-LC for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 06:42:02 -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 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; 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 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> 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 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 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: C6TFzY5NxSQATtQGtMEd7ZA/6vKQbvAnKsmAbgIKIJ3f2dAs7UJ/s3BDU5/ZwYmtxmaIlmq48oXz1HgBUKCEKHVf9hU4EndGgf09vlu+UwBzTvdG6hS3d9WyCEDllWghXGXIaCO84Qu6aJT/1E4ZYSQizslcQVSc8E3DzVm3w6KpAi0kpcO26TtNZ8kVLbkTDEpY2RLEoatmHjJyHFzP/9yNjU9I6KjxPNxFvuDuTN26W9noi8BGoyucLQ34JmENX83DWyRKWrBGEEJ6zENKQp1mOj0Mk6Xyo++h4B8EsMnGG4Tl3tFUH+WLcPCtbh3xjMJIRTFVLpPtSqL/7N3CL+kMogOHQ9kKk+q+u6cWdRF4yLOgigyQmGBET5oKwFjL+MrVBC16rHcVbN5EtjlY+4kdA2wrCgIBesOB2uZeP47oA2qxetBZ0mxwAU3gsvmeftwlsdKeE1Gz+h8qzeEwxLXaCzKQvhBT40huIdMhmZXerIHMpSKrxjrZ0rpnDnsuVAV67TGxL7KYZWg6c2IYE9ECcfPOY2ZABR9S2Kd0AKsYkY6GSVTpVmoz+Xb3tUe7i+U6RERoSS9e3ZhSHtxb1Oehz3oflQPRxAVf9kpnFso7M2TL644HwTewReuJq9rMWNkdEoG+L9Z23pKo04nx9wNoz+2A6ywXdVLsZCw0d5cqhJ9K3oYA4KZ+JKt39EQFgNuSadaECVhyvBeOKbqg/LIp4hCPeXJtaKx8bL9HMaH86Ag9pcX7wJgY9uYa2gYzK9C9cTMgrFpkuOTysyKSeenpY16mbX3AcZrZuhF8Oq1nzddB6TCwO5e1Gz3N5UKbREg/v6XFj0LvKsdTvcRqGZhdqm2yiSV4+3brVKVlfPPX0a/+7eq2oz/IOOq1vO/fR9C6/tf1v8O3gP8eRDB9si9YVRz8coHR5b24SkDjEgVFph8mQQeaJf/DKIAesT3VHBTGeEhOshNSAJlvUniI+PjMWW7R9Byekx6iExhBjnw30+trFcg/W/FkoAc/ql8pdjmuf59ikehOLyZXRfCI3aZQEIH4mDpi97N0CRDSJMI0fT/uSkFGxLmp/JXtH6sg1ziLVw3z4MCW5dTlMkSRQmUvlX7z785RHilyuJCGhKMBEBD2nDAKXH1hoEFM/3wBm04PCLSWR6UtpTNZ7TzSq4FThKCWlJirXnhnxv/I5IP2gzRPZtC2iVXEWxM8lv6ejzDGqW2c88QpiwNpaE6rvEz85S9rzMBmQQxdgYGZk0JuiLPtWqyR4OBubdy0VUVOTW/RNPvnT+ojSFH33Bkbjs7GvtNxKpdjEh4RuP1L3uXQ3NWZs/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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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) 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 == -EIO) { if (nbd_client_connected(s)) { s->state = 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 = NBD_CLIENT_QUIT; } } From patchwork Thu Sep 2 10:38:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12471227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C1F8C432BE for ; Thu, 2 Sep 2021 10:40:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3534E610CE for ; Thu, 2 Sep 2021 10:40:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3534E610CE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLk98-0007JI-DK for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 06:40:38 -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 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; 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 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> 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 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 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: WPwJnWmCEYAd9ADxCMH6RhBgUI6PUCmv5nr7CVi4r1J53+d8BQRrCAbGBJaeTfvE7aZ4L8NOE4Dgkl312Bc2kzIuxfki6vqk7uUEtwvPxfGi25wKwD8T18npA1LVl1zW45kH+3FuoCVps4KLHJsI1BB8EpJvR67/zq3ORlucIqQNhEyREzRXa45BMHwWCXUZoK5YOblMNUN15c/WQn4yx577Ci+Ii5A3sThsKEnCzD4okAdiokzROtyrK6yfmpKjSB+tgY1FFMV+XTydBM4qtMWGPD7SzKfCwoIvrl0obz9zfQd8h/xSGc38jn7u3DyJnexX7wgnZUqcVuLirqUp0pN/4krHOH8xVZtFCK6aBc642Y4PKSGN6NjeXHAewMxpOgu7/ZYXFHpa5FSM8tHwaYtbrn4lJteeeVvoaTmRj1eFivmm6dZQKVDswQgk1GyJ1ZPc2AZWctKlAeHJV/ChiYua6dRLCFyBcp+jj86JHSL3N6y/cF8CE8uC3F/62PGzJokS5yxmWdtLvQFsxHQX+ePpSJ0vpfyRtWMctP0p7zCki+BCr5Z0zukInEPFy4j0sMOAsUXgdEqQ5BUKGVAD1phBgnDQv4ouNo5Ut5QaYKRSaPX5g2EF7hRy60ju3kKoLg5tGhBo/m5Xjr+OGPnKfht+D6NJYgpBDYV4YgtbIZfwrEq+dR43634ZEsTsF/KG0G62+eJGxS/QNnxX4/e/7pLkn0huGIURpzzSIQqXghcWhCAZ7HCuzviMqJNx66Q6B5af01l+Psny8v2/OaVzbHsb8qhtXU+Xhun9arcKSy6QXQMRz6LK7yAVEs1iDEXqfPt7Z4/qXigsc2dA9JLuSER0il3Koa4dM7KI4PTAjtR3UnfSwe/kg21HoS3KoqTOw6+GuPfegztdBOrqyugeB+FW9vgdfH2l7UTie3C5ODSXmRvlWu23mj+bPOxjLYyhn7px5Ti+DY1RANMwVDXKN0GQ6xxOPxpPED5EE5UeRv7ivG/eG/3a/W5L+JhkBszE3RrBqbnzvYQiq2Bjw2MqeZXlWgQiE2LRs8ABJZiLCekmx8y7cHkfGekn+DsNykvMH8QUiumaVxAVYHCrGaTyuHIOHEHyzJDuoExGpKQv1/YFoLACHxk57y41+7ipeCxQnHIRWiQdHI1PiAx2il7zZOTTpZ8tj4sjzN6moWvZ/hfZ17qcNRBEJhdDepFJJndo5qM3ilEKQmgLNOlgJPm/pkNs0rDNdlGaui9ys0nqPYkyXDOVjwZ7yDQh2lFXQ+yblD8hXaG/HG964jAoctnHPCcfUXJ+Wr5plybP7c0EQ29tveAN7GQxpqDGibvQvLsh 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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) == NBD_CLIENT_CONNECTED; } +static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) +{ + int i; + + for (i = 0; i < MAX_NBD_REQUESTS; i++) { + NBDClientRequest *req = &s->requests[i]; + + if (req->coroutine && req->receiving) { + req->receiving = 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) } } -static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) -{ - int i; - - for (i = 0; i < MAX_NBD_REQUESTS; i++) { - NBDClientRequest *req = &s->requests[i]; - - if (req->coroutine && req->receiving) { - req->receiving = false; - aio_co_wake(req->coroutine); - } - } -} - static void reconnect_delay_timer_del(BDRVNBDState *s) { if (s->reconnect_delay_timer) { From patchwork Thu Sep 2 10:38:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12471229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E151C432BE for ; Thu, 2 Sep 2021 10:40:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C604D610CE for ; Thu, 2 Sep 2021 10:40:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C604D610CE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLk9H-0007rV-RX for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 06:40:47 -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 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; 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 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> 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 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 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: kTkZXK43B0DZ67boFEg+HjuygAaCNliTEFPjV0Pmd2HRdE5ctR9WpFzABGMK32LwZdf8J4Nh7qJLDaaOFlqhVHjgmoJrN9a3St56N9db+LwM7i6PR3TTPFaspvyAcXkTmdGz4HpoXX+TzAh+6LPJEIKTNCPpbbYRnZDoU0TxCRENNTFVnnzyD207QWJ0inkLlVp+XZRcS+fJKUgEuMTWZftDbnrQDVI1chcTuf96yfItsYGTjBvdlHFx8ufoZeHQFkSh6Jbi2RlgV98c9DQIlFWqWnXVldpvW5WEO8BHUaPFEzmp4pjiialnbBOlJTt+qUUZB5Srwc0nJ27w7xnA+v6e3ImvlQwK30+mUxp8J4kAYF0uNbcg7airno73NYKlU8f5wb9v7ztMdrt2W8IpqhGFFQrcUIhAxBIMmgGPqLW08nkwskIFO/ZlIPnDa8r0lzz63Gfp5OdTmTzMxBNZ5p/K6M6d/rV1WrLqhN+ViIVIvj3DRxOIh/5/iribl/yTDo/3mhggsTUm6ZT01WWb/IvuxeyYJi+FT0KvaK4NXR1DJetpbxwEMoYkEmT83cCZ2NmkGeU6D6MQbdhBZjEQ386wIFZxJnd9bv0X55cZ2fehr8WBjc26ZDGTSdms3pD5ZEcyPVNMcW7xZbqXzorrcHvYQgO2AExO6nrdCh0m6U3Tj75rvG0b5Wj3F1H41CMwRxLOuuNOrafveyHj7HiX1F08dA9xrDyfR0JMILiBccve3mO3Dbxj4mWkp5n5yjkj+ClPinp2B2EajCa0zw6G0iiTElYBSdMnzik9gjNqaZOY4ijY+4nWnY3WPEIeZ3n/w/o71uZQcDRksiYFWx0k+qXLI+vicpPvHDee1bvUCfTztXEbobO1RIJ5ZDpp5p+41wxFgbrlLrYZSrCAp+ws4Jmi1oLRnn+gAP61qNBMp3z032oUnn6JkiIYDVQjnpRI1V6S8LaXWuXAWI2aYV2ysSvt1kwgg4E3bP8qmMsLVtcUP1IMcL/eXqAvoNsvlo9lJGOt86CPeeFA1bT0j94nizIMvbT0Tp8XfyibtzYF4pT2q6TE4+9gu1JrAXU8j/j/EMiDDDTWIJDIU5sNeu3eAXFwhxJcSX5qIEqxbJOWU1dBmPn69JOKmVyzHyDDuR/TJzo24ABWOpqYHnSQmHJ6Lx5j4HS6JL4N0n51L2B/JCu1F7kTgzjxtmbFrqDCUe5FBezi0pAQedYqSUYosdMw8Uf+d5NQIe05wzGCAhORM5bF5ZNvg8Awg7srqGxJtSbXOctg01kJWqZtc8NsGtjdfc78vrIvZmjOeIwLAe1LYYmFsM4UBhQdMpTFnv4KxKbg 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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) == NBD_CLIENT_CONNECTED; } -static void nbd_recv_coroutines_wake_all(BDRVNBDState *s) +static bool nbd_recv_coroutine_wake_one(NBDClientRequest *req) +{ + if (req->receiving) { + req->receiving = false; + aio_co_wake(req->coroutine); + return true; + } + + return false; +} + +static void nbd_recv_coroutines_wake(BDRVNBDState *s, bool all) { int i; for (i = 0; i < MAX_NBD_REQUESTS; i++) { - NBDClientRequest *req = &s->requests[i]; - - if (req->coroutine && req->receiving) { - req->receiving = 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(BDRVNBDState *s) 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 = true; qemu_coroutine_yield(); s->wait_in_flight = false; @@ -558,7 +566,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque) } 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); s->connection_co = 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); From patchwork Thu Sep 2 10:38:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12471233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C83EC432BE for ; Thu, 2 Sep 2021 10:44:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 45DA7610A2 for ; Thu, 2 Sep 2021 10:44:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 45DA7610A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkCY-00045y-Ef for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 06:44:10 -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 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; 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 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> 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 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 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: C0sRqXGYD7j9BWaaAse4lUu7BRN+9eB4J4yP3Y9uxuUgdmA2H5P2LHI+6WPB7l5fhP4k7SE4mEOfL/R46mlR9Y4gFdwk8KeUj1r2hsbwzD96Vq4vfuCqXUx5OmLyXafBgiPX8GQx5cpACyaHHRQPi2nwAgUrZLaXxMNk9HqOutQvWjDFxJY0uvCAG7uIUns3uI8/XCR1gWF6y7l5dCdYEAUYoy+dSor7wdfRTCPWvdsZMCeqYGNZBLKptwuzNjarWK5fZAj/8anXrHXltCakAY9jbpe+YvZ8mzKNoF+MEojfy8VRXL1lVbbw1olOzDlwMjQA2OitLQveAa1F8xwR64dS1C+Ll43iNjBGqEnK+43EWJdCWaFAisLNDEAwWVTX9BqgUenhl+d9dDUv7MHJqbXI8QvVveYjlwwyPMpwF13wRWFjwQxL4f4ufU9meuVlZzYfYqtlpfgJ1o/e0YdgqJQXu2lz2/aXvIDrwnu5+fsGC+tV8oa5QD341eNSfUxh9o9gY/JIEJqWvIEtsaMplwCeiFAzOyFMC103D33le4XAdqkKSV2XvWjStoLKzbrVgMYqf+ovCdk9LQQvwIM8ES1NJEjE8PyHtrEI0VzKMV1CJr2O/5EfEEVwdCV39srC4ZjRZHs7EuHtVwxYFpyTciIQmHHzflKJ9Y0hio5ExOW5bh9aW7peAKrI0k4UWC1xzN4EOsl6NFpWw4BO7EIvXDFb41L2rKQ+/c3Tt7GW8IZmWVABH8Eh515GiwzQ9TnDFCZKtXxNxb0PKT/vmNf727gxiDU/zzV9IwG1v88nllVHAXUGsoQKguXjq53CrUaMXoeBWQIXTiNlEuVMXGEMcNs4CuuaWNu8aJWWB9GfMxwdFzW/I6V0HGPsjJqmKFSSPT5D5Mieja29ScbDRyof0sg+gSTyZ1jX1ua8yBsCR7OcviMleSfOCncEVtJv4GomlHJihaFDmwXLOsGCybMd8kXwhn97RK5rquuOqVF9as7LiuFJUBQftugjADgkxMCIZbgWDyzBEC2ix+Rgkj9AZRnUCsiMKgh3u1sxAbnsgm5MahpESYUe3CU5wnyeOM4EJCEkOEYcY8PE2WeItj6H8wmy4ru4/lH/s6G0tN1XoMjxlxM2LPv14G7RNk2oDnnDVYrG2Ym01PslU+OJw/EJhkugURNUsxh0YCche34ok66j2blqpiL8b0m3/Ghnu74ce52iA+lO6M415IqUFFsbm1yzCQbgfZUmRJzvn0/d/WdjOMkIX4DYGDmyl7JHFj6EljQaYJpsZDXPIM3Yt7P2EUpOmwZYYJ0f4lxJmYxyA4ujgtOFR/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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 == 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 == 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_replies */ } NBDClientRequest; typedef enum NBDClientState { @@ -73,14 +73,10 @@ typedef struct BDRVNBDState { 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; QEMUTimer *reconnect_delay_timer; @@ -163,6 +159,8 @@ static void nbd_channel_error(BDRVNBDState *s, int ret) } else { s->state = NBD_CLIENT_QUIT; } + + nbd_recv_coroutines_wake(s, true); } static void reconnect_delay_timer_del(BDRVNBDState *s) @@ -179,6 +177,7 @@ static void reconnect_delay_timer_cb(void *opaque) if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT) { s->state = 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); } -static void nbd_client_detach_aio_context(BlockDriverState *bs) -{ - BDRVNBDState *s = (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 = opaque; - BDRVNBDState *s = (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 entering - * 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 = (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 the - * 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 = (BDRVNBDState *)bs->opaque; - - s->drained = 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) == NBD_CLIENT_CONNECTING_WAIT) { - s->state = 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 = (BDRVNBDState *)bs->opaque; - - s->drained = false; - if (s->wait_drained_end) { - s->wait_drained_end = false; - aio_co_wake(s->connection_co); - } -} - - static void nbd_teardown_connection(BlockDriverState *bs) { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; + 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 = NULL; } s->state = 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 = qemu_coroutine_self(); - /* connection_co resumes us when it terminates */ - qemu_coroutine_yield(); - s->teardown_co = NULL; - } else { - BDRV_POLL_WHILE(bs, s->connection_co); - } - assert(!s->connection_co); } static bool nbd_client_connecting(BDRVNBDState *s) @@ -372,10 +279,11 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDriverState *bs, { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; int ret; + bool blocking = nbd_client_connecting_wait(s); assert(!s->ioc); - s->ioc = nbd_co_establish_connection(s->conn, &s->info, true, errp); + s->ioc = nbd_co_establish_connection(s->conn, &s->info, blocking, errp); if (!s->ioc) { return -ECONNREFUSED; } @@ -411,29 +319,22 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDriverState *bs, return 0; } +/* 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 == 0); - /* 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 = true; - qemu_coroutine_yield(); - s->wait_in_flight = 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); } /* @@ -453,135 +354,79 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) nbd_co_do_establish_connection(s->bs, NULL); } -static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s) +static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t handle) { - uint64_t timeout = 1 * NANOSECONDS_PER_SECOND; - uint64_t max_timeout = 16 * NANOSECONDS_PER_SECOND; + int ret; + uint64_t ind = HANDLE_TO_INDEX(s, handle), ind2; + QEMU_LOCK_GUARD(&s->receive_mutex); - if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT) { - reconnect_delay_timer_init(s, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + - s->reconnect_delay * NANOSECONDS_PER_SECOND); - } - - nbd_reconnect_attempt(s); - - while (nbd_client_connecting(s)) { - if (s->drained) { - bdrv_dec_in_flight(s->bs); - s->wait_drained_end = true; - while (s->drained) { - /* - * We may be entered once from nbd_client_attach_aio_context_bh - * and then from nbd_client_co_drain_end. So here is a loop. - */ - 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 *= 2; - } + while (true) { + if (s->reply.handle == handle) { + /* We are done */ + return 0; } - nbd_reconnect_attempt(s); - } - - reconnect_delay_timer_del(s); -} + if (!nbd_client_connected(s)) { + return -EIO; + } -static coroutine_fn void nbd_connection_entry(void *opaque) -{ - BDRVNBDState *s = opaque; - uint64_t i; - int ret = 0; - Error *local_err = NULL; + if (s->reply.handle != 0) { + /* + * Some other request is being handling now. It should already be + * woken by thous who set s->reply.handle (or never wait in this + * yield). So, we should not wake it here. + */ + ind2 = HANDLE_TO_INDEX(s, s->reply.handle); + assert(!s->requests[ind2].receiving); - while (qatomic_load_acquire(&s->state) != 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. This 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 time and - * only drop it temporarily here. - */ + s->requests[ind].receiving = true; + qemu_co_mutex_unlock(&s->receive_mutex); - 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, when 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 iteration. + */ - if (!nbd_client_connected(s)) { + qemu_co_mutex_lock(&s->receive_mutex); + assert(!s->requests[ind].receiving); continue; } + /* We are under mutex and handle is 0. We have to do the dirty work. */ assert(s->reply.handle == 0); - ret = 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_err)); - error_free(local_err); - local_err = NULL; - } + ret = nbd_receive_reply(s->bs, s->ioc, &s->reply, NULL); if (ret <= 0) { - nbd_channel_error(s, ret ? ret : -EIO); - continue; + ret = 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 = HANDLE_TO_INDEX(s, s->reply.handle); - if (i >= MAX_NBD_REQUESTS || - !s->requests[i].coroutine || - !s->requests[i].receiving || - (nbd_reply_is_structured(&s->reply) && !s->info.structured_reply)) - { + if (nbd_reply_is_structured(&s->reply) && !s->info.structured_reply) { 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 = 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 = 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 = NULL; - } - - if (s->teardown_co) { - aio_co_wake(s->teardown_co); + if (s->reply.handle == handle) { + /* We are done */ + return 0; + } + ind2 = HANDLE_TO_INDEX(s, s->reply.handle); + if (ind2 >= 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 trying 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(); } static int nbd_co_send_request(BlockDriverState *bs, @@ -592,10 +437,17 @@ static int nbd_co_send_request(BlockDriverState *bs, int rc, i = -1; qemu_co_mutex_lock(&s->send_mutex); - while (s->in_flight == MAX_NBD_REQUESTS || nbd_client_connecting_wait(s)) { + + while (s->in_flight == MAX_NBD_REQUESTS || + (!nbd_client_connected(s) && s->in_flight > 0)) + { qemu_co_queue_wait(&s->free_sema, &s->send_mutex); } + if (nbd_client_connecting(s)) { + nbd_reconnect_attempt(s); + } + if (!nbd_client_connected(s)) { rc = -EIO; goto err; @@ -642,10 +494,6 @@ err: if (i != -1) { s->requests[i].coroutine = NULL; s->in_flight--; - } - if (s->in_flight == 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 = 0; - /* Wait until we're woken up by nbd_connection_entry. */ - s->requests[i].receiving = 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 = 0; - 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); return ret; } @@ -1158,11 +996,7 @@ break_loop: qemu_co_mutex_lock(&s->send_mutex); s->in_flight--; - if (s->in_flight == 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); return false; @@ -1978,6 +1812,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, s->bs = bs; qemu_co_mutex_init(&s->send_mutex); qemu_co_queue_init(&s->free_sema); + qemu_co_mutex_init(&s->receive_mutex); if (!yank_register_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name), errp)) { return -EEXIST; @@ -1992,14 +1827,13 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, s->x_dirty_bitmap, s->tlscreds); /* TODO: Configurable retry-until-timeout behaviour. */ + s->state = NBD_CLIENT_CONNECTING_WAIT; ret = nbd_do_establish_connection(bs, errp); if (ret < 0) { goto fail; } - s->connection_co = 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); return 0; @@ -2153,6 +1987,8 @@ static void nbd_cancel_in_flight(BlockDriverState *bs) s->state = NBD_CLIENT_CONNECTING_NOWAIT; qemu_co_queue_restart_all(&s->free_sema); } + + nbd_co_establish_connection_cancel(s->conn); } static BlockDriver bdrv_nbd = { @@ -2173,10 +2009,6 @@ static BlockDriver bdrv_nbd = { .bdrv_refresh_limits = nbd_refresh_limits, .bdrv_co_truncate = nbd_co_truncate, .bdrv_getlength = nbd_getlength, - .bdrv_detach_aio_context = nbd_client_detach_aio_context, - .bdrv_attach_aio_context = nbd_client_attach_aio_context, - .bdrv_co_drain_begin = nbd_client_co_drain_begin, - .bdrv_co_drain_end = nbd_client_co_drain_end, .bdrv_refresh_filename = nbd_refresh_filename, .bdrv_co_block_status = nbd_client_co_block_status, .bdrv_dirname = nbd_dirname, @@ -2202,10 +2034,6 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_refresh_limits = nbd_refresh_limits, .bdrv_co_truncate = nbd_co_truncate, .bdrv_getlength = nbd_getlength, - .bdrv_detach_aio_context = nbd_client_detach_aio_context, - .bdrv_attach_aio_context = nbd_client_attach_aio_context, - .bdrv_co_drain_begin = nbd_client_co_drain_begin, - .bdrv_co_drain_end = nbd_client_co_drain_end, .bdrv_refresh_filename = nbd_refresh_filename, .bdrv_co_block_status = nbd_client_co_block_status, .bdrv_dirname = nbd_dirname, @@ -2231,10 +2059,6 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_refresh_limits = nbd_refresh_limits, .bdrv_co_truncate = nbd_co_truncate, .bdrv_getlength = nbd_getlength, - .bdrv_detach_aio_context = nbd_client_detach_aio_context, - .bdrv_attach_aio_context = nbd_client_attach_aio_context, - .bdrv_co_drain_begin = nbd_client_co_drain_begin, - .bdrv_co_drain_end = nbd_client_co_drain_end, .bdrv_refresh_filename = nbd_refresh_filename, .bdrv_co_block_status = nbd_client_co_block_status, .bdrv_dirname = 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, void *buffer, size_t size, len = qio_channel_readv(ioc, &iov, 1, errp); if (len == 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; From patchwork Thu Sep 2 10:38:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12471235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38B6CC432BE for ; Thu, 2 Sep 2021 10:45:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6838260238 for ; Thu, 2 Sep 2021 10:45:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6838260238 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkEH-0006Ar-GQ for qemu-devel@archiver.kernel.org; Thu, 02 Sep 2021 06:45:57 -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 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; 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 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> 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 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 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: OfGqQgWBShBc+z4jWnVaqF7gfaiyWSRWzOyWHj/cIb92lL+HZvC4heMDXJdNkQwf5D0ClrOxhQv/4JxlWDC0kSIKa9UBjx0e3i2Oc3nXBFkv6l9qOP9/RLHxqpAuBSsvzY7LeCSbXEyi5m2zmvKLr5PqmyDC2P/3IshXYBoZAFeEv8tzHGACibPAv9U0s3z7aef0qBrmKpCc7kD/gnzWtQHwRX0UZ00apzsVojB47pR9XFJY4QihlZgh9x2PsWxvfuSRC26Bbvyt9tiIazUxfER/NlIwbINva74HE7T4poW/B8a3OdyvGSUoTB0220tWctZ+bD+abkvvpIVwgSMXduDLlRc+hCO6P9z2s/bf74WplXC146NkFKcdA68gQqOtIf4A6o6qrzvRU4+MgxOyX8kOMJFwfbnkirqizxxRUXBeYuwtthmW1FpiAIrcYXaXEB7EiaNFioVb37osI2M8k/X8axcQkKR7JyeG4uFBTxCJscANV6Lu42fGLgQj8QNAt6J4M9TqWozbMXG++DNzxN/q+q+iIdO+sBPl7AcVjsQ+itTiPqkoG5yXsWWakxAxGfQoFI1BB/kio57tnne0Ypwrw/736llZKPIuXjEUwC6TzJgL6QG0cW5w+kKPYxX1ekq4XCGZrGPUGSbCmX2yzZXo0+uEZ4CtClBdPEWY/exjGLPwBSbhXlVUjcXJrMdgsVC4eUGl4pp4ZLA3XKuJmZdfmqJr3gPj4Bg28ZBPaGKXRYnxNleSUqPqcOKptnkgdIGO1xoj1q+I3t72S2gDQMNnJhnMY8gckbLs+fQlYbGMGx7QGveGWWiMYU2AQdrUYcC+ZLo7Eul2jCTYGmeLvAzqYuP/OTqzqHoKJPQloBSjr/9Sba0kaSamPq5NDDljG6OXwc2IftWH0cpOKSwonrJ5hN5Psue6w77QcUTcHs6nP4RU3QEmh7aW33jlRGLVwrVCojP4HThQRrmcywgnEdpW0Akz7vYPGbrH8j+hbP6WwnEBGC4HZNr7RWm5n9HcYUPLsQyUG8Qurl5zNc3wVe0av1DQ3QcMt2NY62vu/JMAJRFYCZS2FqxLx3OqZwtn+35GZKouM9v1qbRlBdwOj/ld2eWxuKGprKYdterSgSY0OqZsXRy7Z/hf71eMzwzT7Is3nHafiJ8vw8KLhFB3Oxu+hky/4A1afd4qQ4IHsOEj9BfDd6QvDVaaAQSGOJylPxRw2Q/ZOvj8e1dKHyt334B81toBddDjLIW4Guv6BYD+QZiFQy4YZWa6mvrEgaciuQtvea8EhzbYJgWoCQBc71JhhpVU5WLAP7EhEkMirnXZGA7s0EfL8prog7v+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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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_replies */ + bool reply_possible; /* reply header not yet received */ } NBDClientRequest; typedef enum NBDClientState { @@ -415,16 +416,11 @@ static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t handle) return 0; } ind2 = HANDLE_TO_INDEX(s, s->reply.handle); - if (ind2 >= 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 trying to - * lock receive_mutex. So that's a TODO. - */ + if (ind2 >= MAX_NBD_REQUESTS || !s->requests[ind2].reply_possible) { nbd_channel_error(s, -EINVAL); return -EINVAL; } + s->requests[ind2].reply_possible = 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 = qemu_coroutine_self(); s->requests[i].offset = request->from; s->requests[i].receiving = false; + s->requests[i].reply_possible = true; request->handle = INDEX_TO_HANDLE(s, i);