From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891062; cv=pass; d=zohomail.com; s=zohoarc; b=i39/Yo+TxHINdi4I6BGoPhg8JgKiy2QiUXkS0l40RhHNCrhzNqJ68QRxHVkhpD++0cF50xVJBvp8vdANW4HGYRKz3paKHLWHnbPC/1ZaS4Sj77cEpITDk3h3/j/ZAbS/s7OoICI44evRhqZZWElkzseHX5+maqWvU2zsE/v++MA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891062; 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=XsfWNxdqsTyQWCubunuyEGnuzVEsvSsWNlXjnATH0js=; b=QwswqmE9eCXseWcFCEKsFYfpfzKv9VHrpDQ7Dvqoap62otp9cEH7gNHgOmDy3DH4W14qUV0cwIWPbSbweUME4h5MV5hNR/1sLNGWBNyRsH5htUmjLpMIgbHokm7dgMLR1WjALB6NFHvbThWI/f5xDYwKumx6qSei0alTs30qPrg= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891061823338.5307955757486; Thu, 8 Apr 2021 07:11:01 -0700 (PDT) Received: from localhost ([::1]:43224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVN5-0007AF-JY for importer@patchew.org; Thu, 08 Apr 2021 10:10:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVLf-0005Fq-NG; Thu, 08 Apr 2021 10:09:31 -0400 Received: from mail-eopbgr30133.outbound.protection.outlook.com ([40.107.3.133]:41857 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 1lUVLU-0001dU-85; Thu, 08 Apr 2021 10:09:31 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5909.eurprd08.prod.outlook.com (2603:10a6:20b:297::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Thu, 8 Apr 2021 14:08:43 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:43 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uh4GPkEirGwuL57KLVXK9DLC6RLzkGCLUW1GS1XZoBHtXMbyb2rtUYf2KcvupYKVCf7ZrmJA6EISo+PfbLcToCXBsTnR6X734Ejq6RE96h+wqxKc4/5rQFM40E/gHR494SXeeXWkChfGFY5LpKLgUyCipZJAXRpOtLIHXy2ReijYRU5o+aMQ+0MjlMk5UwfQ/7nhX5KZ6pxNUcGldWEpJ+G6F0ipwozBNLhRi8Sz0EfmMtk4I85ojn/AmyRyzX698hXSh8WzGxyrKXQqA1npS5Pzt0vmTyAZFsv2/s0Hm2dCqDO/iNbGJidKcPXjvuPicNwNAVkLqE4Kx9ODI/pbdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XsfWNxdqsTyQWCubunuyEGnuzVEsvSsWNlXjnATH0js=; b=XDpDeof+JbMHM7gqCbZq2OHEh1AR/KuhOfhZJHJNYmiJ+JrCaMZI64M1p7JbraYKw4zKwGW+O7mYfI808nopIZutuo/tXp98HsPO05d2b3iTs5sj4xCQhn6AG2JKa4NDUw8Al3JEn0i/BY/kMYHo7N7pK5o29wo++8Q1Q5HsjRg2zcw9NsYRmtw0OIjzWWiWIFwo3c1JlFlCg95xgTT/frO5oMFegOy7zenBEqlx1czHS6aUJrTOz6UHhdWZ/XF03Cyi23WoY2S9a1qCp0bMQfHxdznSyFG/qrZK3wvHaIckDY0sUoxlnt9od5siI/ziSkBX6qfJLEgFa8hgcpylzA== 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=XsfWNxdqsTyQWCubunuyEGnuzVEsvSsWNlXjnATH0js=; b=l+eEir/OngUmcHvT0Y4y08sQ0RTaDsfFwY6gqK7KUyPakVrvfJMJzlPu8avqygFmhwaoGKNPhRsr2WqHWKxncXiVjyimC6Y03UPG8ZPWjy28PnT6iqqQtyoFq77oCTmvKOBCzrMrZwW1soz4RefcR+a+7mNA63ENun9qMSvcGqg= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 01/10] block/nbd: introduce NBDConnectThread reference counter Date: Thu, 8 Apr 2021 17:08:18 +0300 Message-Id: <20210408140827.332915-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 02dad2b6-98fc-4ad8-c746-08d8fa97d17e X-MS-TrafficTypeDiagnostic: AS8PR08MB5909: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:747; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /yH3PivnAIC5EukxXS4kHKTFK+Kze4YB+ynmqFFD9jrEfzpTDrpF96nnjcBRy/PxvKyaRfWPVOiXEFMsvbPzfMPQX/i25aRdW2HHUcK0KgmiA7VlCUnQE+V5Q20Jgi3RpKTi6c7ZscoS9vHAc+rBM97v7toZa+7L4skw/I4O3PtmMjc0Kn0oV8RBOUsuXiuS2py8tMofsC5zsXAdPnekyllW3sk1iy0kXkMf7gfkzd7QnNfi+xZHqx6mitfrTSPyv+c3skg+2nU2IkkJF+3EO7qaPGOhhx5mqU7dTXszrFcfTSbgWP3lRd28qVpzXq7VgkE3oQssFPwAt8vutsVlc+Q9iFB5+FrTZ/JSHR2dPAVhFSAwNv1YgHJmCTNXFNoch5hckjMQvgLpPForGV0tTLMu9Fos8hvfuXokLmGmRa3Rj1x4/tuJpk6hv05p9tT4cJpNwJbpUoRRN4lRE9lvsQEjDJPh6MWrGZrpbGaTHZ5PebbdUydrA886pgoF87YFs135suK4CIYfdGxXZuPHXHl4s5vuH0onO1nrkOws2iQsg9gvZwdZQGU/knFBrJUhBY1ogtKqQRTRv0ONfSyN56HbNx2gpOPKdOYrtJDucLTV01l6P4W9p46+RBhH7Dms0DBh3+BzIdaz/ktND8QhewXNXpbuHlvMed9gVfgXcWayQbZ6LoxTsfRE/5ao5KdidKz0hCF2B1GOTUCtfZiZU0I4h/ig3IfOGVuhqy8bnvE= 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)(396003)(366004)(346002)(136003)(39840400004)(376002)(36756003)(5660300002)(38100700001)(66946007)(316002)(478600001)(86362001)(66556008)(66476007)(2906002)(69590400012)(6512007)(38350700001)(6916009)(186003)(6666004)(26005)(8936002)(6486002)(4326008)(1076003)(16526019)(52116002)(8676002)(6506007)(956004)(2616005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?TpsoOg6IzRJwCHTU49pS9GCWJnVGLxhBeynv3VrD4kQScwiVfkDh1G6RSVyZ?= =?us-ascii?Q?0ZKN4uuxyU3G8D7wODkCwmpMpQDFVyJm3eW76EmgCG5wOP6Nl6UxuArQCak/?= =?us-ascii?Q?TOURDjTUQcg5GXHvFaFK58i7me9x1yuUI4eXMsGdD9lOJDIueoBBNEEcwUkR?= =?us-ascii?Q?qLANyO06eBULQ+lGaJdo2C4hogPN/sShKk1GRTvjpAkZR2AwHMMhNcLhwtbG?= =?us-ascii?Q?xsjZpWBcaeUFTd8ObvnDBFLM8YmSK8+aG8buxrz+iOu3uUNyTh1p0gRDVdLB?= =?us-ascii?Q?vUKR/tlbWFQFLoiBiFx9vGXdFu+8So2qxKCLmWvQmesPgLU8VM+GL3ymhW9W?= =?us-ascii?Q?QnS1V5olaCtD9L/uVR/G7obSrHg+sgZRRSh4q7AwLeA/fR9/JmTAPYR+4xbm?= =?us-ascii?Q?QMVpz0grGEoi4WuxGaGkYjZhFHekapAyQUazuUsdrBhzwUfZXyluIXEGjcsy?= =?us-ascii?Q?3WLywzRm/WwGHBnnT+Hm36qSuNYF9i6Tvbb8YP+etutvR1OPV6sSxncjUxDW?= =?us-ascii?Q?7w9VtX1a47jpGIMhM6sqMgpHgRvzE7EaMKqIqZ6tden9XGDxILoddaG9GCAu?= =?us-ascii?Q?bz8p9HOK5mA7owfkmVdtAyaEWF1O140WNtlFLkOlWTw9kAJcs4hYIpguZehD?= =?us-ascii?Q?pOaZJiCnLQ14lO0iQrhFHoe4lzG54U1iW9FGD2AyVExzwJpR825beZSXyngl?= =?us-ascii?Q?wQ25odB9gFhyQ1JHVw9f7Abp3/hsIg35kdZks26wJp667DidiagGF8AUkeUt?= =?us-ascii?Q?09EGPhZAJCiSHJa7x3tMfnKX/iT4DYIx3KgOu1WCyFHQvFhBgUdTLxKzaDKh?= =?us-ascii?Q?hvrkVeAjKnD7TJglXwmzf7j04+pwfhW/BwE+Ka7Aw40K35uQtynw+2BozoLY?= =?us-ascii?Q?Y+5cJC42RMDEBkj330tT/Edf3+SQpvVYdDTA6/mRPLJaoW5PSDObQhpUKq4p?= =?us-ascii?Q?7T5Sw0pIz+9BJSlx8G/w9Un/uvDFWYbBrdycELDDK0aRLbNX0z0wcOZ93UDQ?= =?us-ascii?Q?IBQXXGpqS03o1FswJvWSl30WvS22hN8cllDoSM6uziQeoq2eB8ylQj3hBqgP?= =?us-ascii?Q?4VzebWcNtlipe17ZcJ6AhHFAE1zdEUwyRzDPANt68sMc73pV6GSKNBwXWzDt?= =?us-ascii?Q?JPgmsZ7U9Su8RKkj8+DKyurpWpDJeDZG65nC++Luu81DSZyxd/RujlKttIAg?= =?us-ascii?Q?So3uqSRYv+E9qwi2RXV4o6HmYRQEO4P4TgxiYS3Mv/HhGVsRlNAiK3fO645H?= =?us-ascii?Q?+I6IAroHHrGI1wLh1jvTAIC3bbDyXVj6M80LYhKu3iwLgSZItY6xA29GPplT?= =?us-ascii?Q?b3xKrzzfAofoUP1ZmUcnCDcr?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02dad2b6-98fc-4ad8-c746-08d8fa97d17e X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:43.6559 (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: YgrlkGQDKc7i19zQAus24w0JR1w64RgPtH88eU0PSeZFlxTogz//3EGRFFp7HIg2kPnKOua46ZwvuO/GUav/2ZBfVPD4pFmxsPzXTuOk180= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5909 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.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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) Content-Type: text/plain; charset="utf-8" The structure is shared between NBD BDS and connection thread. And it is possible the connect thread will finish after closing and releasing for the bs. To handle this we have a concept of CONNECT_THREAD_RUNNING_DETACHED state and when thread is running and BDS is going to be closed we don't free the structure, but instead move it to CONNECT_THREAD_RUNNING_DETACHED state, so that thread will free it. Still more native way to solve the problem is using reference counter for shared structure. Let's use it. It makes code smaller and more readable. New approach also makes checks in nbd_co_establish_connection() redundant: now we are sure that s->connect_thread is valid during the whole life of NBD BDS. This also fixes possible use-after-free of s->connect_thread if nbd_co_establish_connection_cancel() clears it during nbd_co_establish_connection(), and nbd_co_establish_connection() uses local copy of s->connect_thread after yield point. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 62 +++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index c26dc5a54f..64b2977dc8 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -73,12 +73,6 @@ typedef enum NBDConnectThreadState { /* Thread is running, no results for now */ CONNECT_THREAD_RUNNING, =20 - /* - * Thread is running, but requestor exited. Thread should close - * the new socket and free the connect state on exit. - */ - CONNECT_THREAD_RUNNING_DETACHED, - /* Thread finished, results are stored in a state */ CONNECT_THREAD_FAIL, CONNECT_THREAD_SUCCESS @@ -101,6 +95,8 @@ typedef struct NBDConnectThread { QIOChannelSocket *sioc; Error *err; =20 + int refcnt; /* atomic access */ + /* state and bh_ctx are protected by mutex */ QemuMutex mutex; NBDConnectThreadState state; /* current state of the thread */ @@ -144,16 +140,18 @@ typedef struct BDRVNBDState { NBDConnectThread *connect_thread; } BDRVNBDState; =20 +static void connect_thread_state_unref(NBDConnectThread *thr); static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *s= addr, Error **errp); static int nbd_co_establish_connection(BlockDriverState *bs, Error **errp); -static void nbd_co_establish_connection_cancel(BlockDriverState *bs, - bool detach); +static void nbd_co_establish_connection_cancel(BlockDriverState *bs); static int nbd_client_handshake(BlockDriverState *bs, Error **errp); static void nbd_yank(void *opaque); =20 static void nbd_clear_bdrvstate(BDRVNBDState *s) { + connect_thread_state_unref(s->connect_thread); + s->connect_thread =3D NULL; object_unref(OBJECT(s->tlscreds)); qapi_free_SocketAddress(s->saddr); s->saddr =3D NULL; @@ -293,7 +291,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) qemu_co_sleep_wake(s->connection_co_sleep_ns_state); } =20 - nbd_co_establish_connection_cancel(bs, false); + nbd_co_establish_connection_cancel(bs); =20 reconnect_delay_timer_del(s); =20 @@ -333,7 +331,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) if (s->connection_co_sleep_ns_state) { qemu_co_sleep_wake(s->connection_co_sleep_ns_state); } - nbd_co_establish_connection_cancel(bs, true); + nbd_co_establish_connection_cancel(bs); } if (qemu_in_coroutine()) { s->teardown_co =3D qemu_coroutine_self(); @@ -376,26 +374,28 @@ static void nbd_init_connect_thread(BDRVNBDState *s) .state =3D CONNECT_THREAD_NONE, .bh_func =3D connect_bh, .bh_opaque =3D s, + .refcnt =3D 1, }; =20 qemu_mutex_init(&s->connect_thread->mutex); } =20 -static void nbd_free_connect_thread(NBDConnectThread *thr) +static void connect_thread_state_unref(NBDConnectThread *thr) { - if (thr->sioc) { - qio_channel_close(QIO_CHANNEL(thr->sioc), NULL); + if (qatomic_dec_fetch(&thr->refcnt) =3D=3D 0) { + if (thr->sioc) { + qio_channel_close(QIO_CHANNEL(thr->sioc), NULL); + } + error_free(thr->err); + qapi_free_SocketAddress(thr->saddr); + g_free(thr); } - error_free(thr->err); - qapi_free_SocketAddress(thr->saddr); - g_free(thr); } =20 static void *connect_thread_func(void *opaque) { NBDConnectThread *thr =3D opaque; int ret; - bool do_free =3D false; =20 thr->sioc =3D qio_channel_socket_new(); =20 @@ -419,18 +419,13 @@ static void *connect_thread_func(void *opaque) thr->bh_ctx =3D NULL; } break; - case CONNECT_THREAD_RUNNING_DETACHED: - do_free =3D true; - break; default: abort(); } =20 qemu_mutex_unlock(&thr->mutex); =20 - if (do_free) { - nbd_free_connect_thread(thr); - } + connect_thread_state_unref(thr); =20 return NULL; } @@ -451,6 +446,7 @@ nbd_co_establish_connection(BlockDriverState *bs, Error= **errp) error_free(thr->err); thr->err =3D NULL; thr->state =3D CONNECT_THREAD_RUNNING; + qatomic_inc(&thr->refcnt); /* for thread */ qemu_thread_create(&thread, "nbd-connect", connect_thread_func, thr, QEMU_THREAD_DETACHED); break; @@ -503,7 +499,6 @@ nbd_co_establish_connection(BlockDriverState *bs, Error= **errp) ret =3D (s->sioc ? 0 : -1); break; case CONNECT_THREAD_RUNNING: - case CONNECT_THREAD_RUNNING_DETACHED: /* * Obviously, drained section wants to start. Report the attempt as * failed. Still connect thread is executing in background, and its @@ -533,18 +528,12 @@ nbd_co_establish_connection(BlockDriverState *bs, Err= or **errp) * nbd_co_establish_connection_cancel * Cancel nbd_co_establish_connection asynchronously: it will finish soon,= to * allow drained section to begin. - * - * If detach is true, also cleanup the state (or if thread is running, mov= e it - * to CONNECT_THREAD_RUNNING_DETACHED state). s->connect_thread becomes NU= LL if - * detach is true. */ -static void nbd_co_establish_connection_cancel(BlockDriverState *bs, - bool detach) +static void nbd_co_establish_connection_cancel(BlockDriverState *bs) { BDRVNBDState *s =3D bs->opaque; NBDConnectThread *thr =3D s->connect_thread; bool wake =3D false; - bool do_free =3D false; =20 qemu_mutex_lock(&thr->mutex); =20 @@ -555,21 +544,10 @@ static void nbd_co_establish_connection_cancel(BlockD= riverState *bs, s->wait_connect =3D false; wake =3D true; } - if (detach) { - thr->state =3D CONNECT_THREAD_RUNNING_DETACHED; - s->connect_thread =3D NULL; - } - } else if (detach) { - do_free =3D true; } =20 qemu_mutex_unlock(&thr->mutex); =20 - if (do_free) { - nbd_free_connect_thread(thr); - s->connect_thread =3D NULL; - } - if (wake) { aio_co_wake(s->connection_co); } --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891351; cv=pass; d=zohomail.com; s=zohoarc; b=hFCWacnN3RE3U8n0RLze5hSsUaf4HQufoGIhXS82fEodCGGrSFUbrtRPh81J/loduUOVYKDS9ysuZKTtdiYAnbG8e6jBiur4T6ajeQEpjFU+TFzh5fCTQuO6nOKDHnF/Tb36nX81qMaIC0W3+yj5YRtOLtSQqLZVXPqYV6dbipY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891351; 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=oRpkgfJ62SJ3UWOtgw4nHRNxnVASjbMRraPiWVPiDHU=; b=WANfEo169vqu4N0nDgYmQLTezoJ60U6tUeidKwyXeRTsmG1OIbcqKhb28+yJlxhtNbpYnYJsPoZrmYQPQU5uzms3+jN2fC+q/1IVetmzxBTXhP0xoKaI+Ik89ri88nndgw5rvlLMycjC9+09iYD8cG1nPuEhmSdB4LIUABYzz2o= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891351531165.1384940308451; Thu, 8 Apr 2021 07:15:51 -0700 (PDT) Received: from localhost ([::1]:59614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVRj-0005Nb-VV for importer@patchew.org; Thu, 08 Apr 2021 10:15:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVMe-0006xW-HU; Thu, 08 Apr 2021 10:10:32 -0400 Received: from mail-vi1eur05on2131.outbound.protection.outlook.com ([40.107.21.131]:17888 helo=EUR05-VI1-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 1lUVMV-0001oz-FG; Thu, 08 Apr 2021 10:10:32 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5909.eurprd08.prod.outlook.com (2603:10a6:20b:297::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Thu, 8 Apr 2021 14:08:45 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:45 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AAsDJ71mTXwxNDiYvPtw2BB4LyRL9NnkgYJhGGbm8jbUFr/jb6XQXJ1a0JrKOilh/xQVrbTe5eqWNsJRo1bLlH5CgSRC99Tp9+w6ypxrGSY+eFhOegY/tbg4d/BcfFkf3TLBtGJh3sYZBdUEguLhOyZn3cdoM5A3RMOjeu7GCdrJnLr3jAbg6/wDKLXAPh918rzQKSb6y3BMCkItCVxIGPYGXpbfoL/qcvkFHxlCWMc8AaLwZguqvmN6/3bg2iLHFDEtSJeuA1oSJkD8EkDQvDg8hfpNUVP/0mC9/f5BHtkitA4tNiCsWCC3fH7YeUtDua6XSuvL1KZc2sjSKLsC4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oRpkgfJ62SJ3UWOtgw4nHRNxnVASjbMRraPiWVPiDHU=; b=Is34lLTMAPfSZTZggyNa8sggwP/5XC1P621nndAhw9n+ObSMYkqqRr+tBt20L54rHikbbU0qLotcsH5U0LlmeJDYoVvoHvK6WkkloTADqy9RGY6whUxCQ9TjpGBcEd0Q5ZeBpLVlHEgfb7slQPDdZHtQWhyNR9+14zfEVlOcJ9/8wmaZX7Prz5Il30CSZ4bh3hBHwd3Yn0EH5YHbqxyHbCJWJqR+7tt4oUnA5NHTZ+3dqsfdbCMyZZcOPGqfZDzBEIXij6yqoLUxJhZ0wKnAl8rjBiDcUFRv7Dlznk6cldFsX7UjxfucO4x7NOlXqPX3Qrh9Qgp/Pkbs7lpVDsYUVQ== 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=oRpkgfJ62SJ3UWOtgw4nHRNxnVASjbMRraPiWVPiDHU=; b=JoMcq+i/jxkH2CfnAgYzlKxD3WyS+YQQ0UJEOI9z2NnXQsooaFI6LK5pGE7HAPCij3v6VSjFnZ0rZ4GXeBqiVmrgf7M+47bfyyvk1sa06tNSiK9U3/TfsfBRHBhWARNsNyd/C30HpUFf6Uco5aBpZp6n8XH+N8OI1etVcwqFT78= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 02/10] block/nbd: BDRVNBDState: drop unused connect_err and connect_status Date: Thu, 8 Apr 2021 17:08:19 +0300 Message-Id: <20210408140827.332915-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 906b375a-0fc3-4ebc-e38b-08d8fa97d268 X-MS-TrafficTypeDiagnostic: AS8PR08MB5909: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:109; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zIa6K+SuhynfV2xvPDICZ1ixFFSnd++4bN/MyqqfoHIImCagZV35Pju8ODG3pLFlPk/dOmsktOXFfuWmOJ896MSDINy9q6K1AmqQJVAZ4+i4yI7dqZSIe28CDr3SessXsWDPby2nYPrjhLWEzeM8g9qKiIDhFvoLNRdC74YBxk2EnV8llOfn69m8VmQXALwgW0ex9XWEiMDTQBxLprfb/RKTGdIDPwG7B4bGzQzFMXAp3YfTTW4jWm4UgYuaKGvh+mVfG0OaeYP6Dc0zt7gtSgFswUD2uDV+IX0qepnfW75YtyHxM6PY7jU4I+Hj6iVLmbgosDuYmhRxvahHWoWcZqMA8IMWUPkpeF75A48TXxECWsG+1Gp3WPzWrEC1rVcE+uMrzJUFrIiFbYokO1xHuAql8rUVa/rk02UwQSJB9/6Kx4J+5A0gYlyYZxEnQC+lwYrjQzxU4DaHqSxF7eHt+LET5DMtt/PxAb+vwKjlwvzItoF4M2k5BdfoygMKjpc6pzp413Hm92cvd7t87gosY1ntj4sMXWWE0Zg5Nt2fMRHNb1tvHbJxDAZHIYWsA8YmJHlm9kidfrVlAVNKe0CBX6zKXXNjP7Ow5IzJB8rdH0++buJjWCtlLdXiZlWUQ7U4J2e+8eDDgjn1nGfy9Q8xhHt7w4Wrfm0uGKMqXaRIxufJzVDydCJPGahbCpEEGSYmVfA62xEcV1xfSCQ3iRF822mmR2o9RdnCPE49RsbhQ9s= 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)(396003)(366004)(346002)(136003)(39840400004)(376002)(36756003)(5660300002)(38100700001)(66946007)(316002)(478600001)(86362001)(66556008)(66476007)(2906002)(69590400012)(6512007)(38350700001)(6916009)(186003)(6666004)(26005)(8936002)(6486002)(4326008)(1076003)(16526019)(52116002)(8676002)(6506007)(956004)(2616005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?mKMpdiEXBkT5R7Iw/D+YQ0QpvJDBQOd9ag29pu7vhyGwAF2gkhLVptW2Jfev?= =?us-ascii?Q?3T4VuQmvNauqjJqSMXs6kdry6T4lyL9+QDTQUyGK5G5qb8JU4tveJoKDt1FA?= =?us-ascii?Q?eelTIOSUhLWdT3YXsNdpf46lSUm2/7tvfZcQ1bHdQRrFDg7MQ6rMqv1EEn/h?= =?us-ascii?Q?oyNMaS5HEdTDE6qSE83ICFGC21AX1m8Fc8+HynHvGYDpqFAB1iG98qLlNNpJ?= =?us-ascii?Q?HGd4I1gDxZ9kxFSiqhmbbaZu0BV93jXEPJ9oL8iP7TqrU2PTbjK/6XtUSRxt?= =?us-ascii?Q?IoZxAuuOeNui4j61KJzGa6UdO2zt/COkUY9RAiOkxB86CFKpWTFM6tWkO/mu?= =?us-ascii?Q?YvU9dWhay/CvKznG2t5y9IT+/QmtGYixUl50eMvraN31qm5lkNDgNI+XJbTy?= =?us-ascii?Q?4d2FqD5aGNxjGsY56ytie8IcQnmGw7tvoK0DuEOGQYx0vxQyVxmRqo1jKMb3?= =?us-ascii?Q?I9qZgeO5JkzxTTWBWN4bxgRXZT+D+kU1AzdgSXnCupvdg1nGQ4aQkNvc/AS3?= =?us-ascii?Q?3/M1diewWV5S7u/jIH69tf5RAEswF4ojGzf3Cqnx+6ddFejzmSjjB3x9v4Jx?= =?us-ascii?Q?8hRfQvgw6NGtZcDZuka4yaPU+EquEXLthhB9nm/4nc3zoYX5LEQLw3J6yPWO?= =?us-ascii?Q?WEQkrVmlPHBmSIWXGCOEloWXQKJFBT5nHOT1VQr4Js+Q/hD+NXu6nwDW8T45?= =?us-ascii?Q?Bt+6QqrBBGgenOEDPth4x2+yntpRSMDnPzVQeo9FapHgBmNXk131ablA0E96?= =?us-ascii?Q?nvQ3akdITAmKOmkQvQc9g/8UHSleO/4Pgg1rcImPO29qnSL9qwa9kE40Qw2r?= =?us-ascii?Q?3J0vdT7MdZJIvNWOCLlxKeugq5Fx+pfUH8TQga/7zjwBLJnIG7sbhxH9lZg4?= =?us-ascii?Q?6UAjAM7/SZoszp5W7JcJ+qrT6Lex7xjXpLjvvyvFVqNW5iKCqs+KIcnTMfSS?= =?us-ascii?Q?0v0jJLvA1tEL305IIw2qCY7Kn556s3LmJNU+VC9guSnn1y/7y4H+5MBygaAb?= =?us-ascii?Q?7xmOcS+meIIo6wz9HaqtzEgN2QzoX9g/6Oz5M65PvGXv7lWUGTfXIA/wK4CE?= =?us-ascii?Q?/7MPKd5AEh8SGksWENOegyFcXnzkan2QxFC5qV2GyZ38dVS0Viw5s76PYGpY?= =?us-ascii?Q?mHP8VKoDCRWqVXAiIYkGu5WxGQaWgzyCIjS76YuysmNPJf9HBeRqmVgHYmgI?= =?us-ascii?Q?RKruqY+sOQZCSnMUrEAf1Mq93gVaCVgkqBGieYVTD3n7Qzads48YE17Y0NZB?= =?us-ascii?Q?WDDwj2S/YWMC8bIntnWue591Xw1DMWqYOu3HPP37dMJFHsI4KtZwEmlCyvYH?= =?us-ascii?Q?MCqFxQTUrC17lHmf9yEp+3rt?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 906b375a-0fc3-4ebc-e38b-08d8fa97d268 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:45.2369 (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: N3Q9yFrFflD7EVkEvXse0fcaq+0lRx3JSledBNx+bBYvYRC2fUIWNb+eMs5gRYcA1kzjsk4MpciTmemtGworg0K08oBecbkgG6IH3Sn34xI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5909 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.21.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-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) Content-Type: text/plain; charset="utf-8" These fields are write-only. Drop them. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 64b2977dc8..b0bbde741a 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -117,8 +117,6 @@ typedef struct BDRVNBDState { bool wait_drained_end; int in_flight; NBDClientState state; - int connect_status; - Error *connect_err; bool wait_in_flight; =20 QEMUTimer *reconnect_delay_timer; @@ -556,7 +554,6 @@ static void nbd_co_establish_connection_cancel(BlockDri= verState *bs) static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) { int ret; - Error *local_err =3D NULL; =20 if (!nbd_client_connecting(s)) { return; @@ -597,14 +594,14 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNB= DState *s) s->ioc =3D NULL; } =20 - if (nbd_co_establish_connection(s->bs, &local_err) < 0) { + if (nbd_co_establish_connection(s->bs, NULL) < 0) { ret =3D -ECONNREFUSED; goto out; } =20 bdrv_dec_in_flight(s->bs); =20 - ret =3D nbd_client_handshake(s->bs, &local_err); + ret =3D nbd_client_handshake(s->bs, NULL); =20 if (s->drained) { s->wait_drained_end =3D true; @@ -619,11 +616,6 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBD= State *s) bdrv_inc_in_flight(s->bs); =20 out: - s->connect_status =3D ret; - error_free(s->connect_err); - s->connect_err =3D NULL; - error_propagate(&s->connect_err, local_err); - if (ret >=3D 0) { /* successfully connected */ s->state =3D NBD_CLIENT_CONNECTED; --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891854; cv=pass; d=zohomail.com; s=zohoarc; b=Cd+/djbPPOPNAYUGKltJasHU3osKKxLqF6/4bz3noKTRffki+PnztElCMoK+favdYmSs8l6VebYcthI+pKySdDRtou9y0mx4wSvUB6xWJfggpeEJJy77KcXSARGTty1exC92niWl1dAy+xlMFgt7AQLbRfmBo7LTzUrhC7ZtI1g= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891854; 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=jWSezsaOBS6sPFWBkZtqPiG0dmz5LipYe56swsx30p8=; b=VNhTAsguC8PgeBEp+6ZwtsXT+y0gL4XssQypL1X3RPNByNTfpHVdbpGzWAy9p0zVg9fmjjsjOffFXEoOVqElUY0tf11ne1FlDdvd6ZH3APbip98dt7NJf5U2eXtDZHbV2i92/JjBc67ZTZmXbSi9E2sAngi+jY9zMs3GhZH/q20= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891854448858.7827308011986; Thu, 8 Apr 2021 07:24:14 -0700 (PDT) Received: from localhost ([::1]:45982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVZt-0003T9-Dh for importer@patchew.org; Thu, 08 Apr 2021 10:24:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVWx-0000Sk-Np; Thu, 08 Apr 2021 10:21:12 -0400 Received: from mail-vi1eur05on2121.outbound.protection.outlook.com ([40.107.21.121]:29482 helo=EUR05-VI1-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 1lUVWl-0007ST-5n; Thu, 08 Apr 2021 10:21:10 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB5909.eurprd08.prod.outlook.com (2603:10a6:20b:297::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Thu, 8 Apr 2021 14:08:46 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:46 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W43PNAk+5lVhfdKUBf8s/dcnodBNPfOWbwVNFB+tioeoPv0i8qaa91j/3bTC56dhj33hyi1sRqcjX6cfLiuBSdD77JoBO1asUkALiMtk4GIV1djUBOSJy7ncl3Wf2Hn5DQmlnhxDcKZvnFt2bj6E0auUfM6vPWOQHTzKRVAQLonuVhPFEaloqNQO55wDC63BvEYv/+91W7G9Jo8HuyQ+8onjUtfBzgX9TOn8I9swcNN0wyyw5QrMLJGC+XNd/pusAkvwqB2r930/+2ZV0T1mMUF05n5U3/eb6iI+YRE5mincPwj8Uw7luKsHB89M0dB6s9dwctB8DCIwQydC3i+nMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jWSezsaOBS6sPFWBkZtqPiG0dmz5LipYe56swsx30p8=; b=aJSpA5j0qqUBPVZMUYTs2DcLEMdGap5pvRwKhCmBL7FjplAehEUHt01QsAPwWiBDKvnhWDbM/CescPW0a7CYa42luqKdFHc8c64NzeFLV4jOF6jqtajvvFIeSARAd7mXctZxhRXMpufiSE/tT0WZQol0qXE1hduEZtNjBuUF+pW4zNT+371z14jUi2mXAEEe7F/ufPII7Bu0PS5SfjL65egHLOM2soAnWcPM9b4ug66DlDAxNheWWwH0lrGuok0WVhtn0sdu7QUqxAKx4i24/GxnQKIlpNPtZehxEZGxRYK5Iz0MxKfSBGJ+ONFSOeQABz6HEve9vWJUyls3m7ytPw== 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=jWSezsaOBS6sPFWBkZtqPiG0dmz5LipYe56swsx30p8=; b=W/z/NyK5M9HevNeBiiaZ74vo3ZBbz/sxufqk6d4CCuucUBQmpP6VTif4QKTXWaxLwkGDXbWINPA31D46gwyWqlUcesdk4zsnRe3jmGdfMVdZCT3PFLeb970hMG6qkaI+aqYr/9eIFsmSOI0bFPNaEpWteBjgE1oU2v162AVwQFY= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 03/10] util/async: aio_co_enter(): do aio_co_schedule in general case Date: Thu, 8 Apr 2021 17:08:20 +0300 Message-Id: <20210408140827.332915-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 808c8e78-e918-4948-46a1-08d8fa97d349 X-MS-TrafficTypeDiagnostic: AS8PR08MB5909: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gWXXisYXb2DOWPjeCMnF7anMtWJ4Kf/7xdmeAdMRgj+AXmXlIakaSOSUigRJ1/I376qBBAZ03ocpCgkBg//24TOrN7jMDkLEsElQYOiouzJEQRN4AGRuW40/m4LBCwVYb1zw6/v+IifZNzgs4eNRzTSV1bIdBwe4cBygpZpesbeXjpS7L5lxdkejdu52jpuhVSQLGjtFvUxIdpvabPrO7EQ/ulwS8Je73rG/dcvus7AnOtrIg/8KuB7deRLmiqpyt+DV173wiMfzCSh0WEZh4tVGR6DqCD9k/Fu1yxAfCiLfEokRFZLXm8ua8f21O8wQKUDPaFpoWvn0NBE/h82ifeeTBhsqKY/GQtrYaTVmwuNlwvpKKAJv6ZFyPSr+7G7Du/z83je3N3V/kPf4x9A4uvWADrzHGKtPbu5gQffd8VWSLMJPjBPPfv4hJZSzvASU3v4qixKmsqrmiSzV0S2mqZMX+cZZoEXoziF7kadZ0OzhK02//13O7Ta+JdS3d50fxTE37C8iOXw9KpokEwX5wDutGynOlMdaBpiYHfCu2JPbwDylGya/VpIwCYrd/QRfXL0c8LX1AuD/Y2pGXO7slURSMJWym/9PyH+Vr3HowpFYPf0a7TS1n7/Qxw9lHzbBh0XiXR8PBrBCdvCPS8CxyzcLAr97n1FzN0nvxjO0jHevWpv9BCS8uWWXY0x8m/6KCX5jQKd/eEADInUDTnFZhpKNV6qmZEQx0dpWKvS0TDo= 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)(396003)(366004)(346002)(136003)(39840400004)(376002)(36756003)(5660300002)(38100700001)(66946007)(316002)(478600001)(86362001)(66556008)(66476007)(2906002)(69590400012)(6512007)(38350700001)(6916009)(186003)(6666004)(26005)(8936002)(6486002)(4326008)(1076003)(16526019)(52116002)(8676002)(6506007)(956004)(2616005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?LkCm1Z1aJ+0FOzLcNlrgVMdJbvg8F8mQWgmeleJ9ICsUbzt35ASsoaauZBlz?= =?us-ascii?Q?zr63KRqQZvsZrMXoMwaQYMr739dB1SZDqLcX3VL6c5c8lsSCqjJJZb3A2qLv?= =?us-ascii?Q?QPll4r+aXDo3q6VonA9dRepTcr9nkO1A5z9DtyhtBWiAHLoaWVm8v0vWwCvh?= =?us-ascii?Q?qXFvR1DNeK+wOIg52uP/zlmIrsi/GncbfLtJQP4mm2WS08ewq/N5uYh41L3h?= =?us-ascii?Q?eHLsTJHaI6nekFdhpn/cmlyq2S6tNQ4SSml3Fqw2B171yDsIS6j0AlaVHJxP?= =?us-ascii?Q?mTyHX4aZGaiEeZSgbfmYnm6GNJfoBDVn0E6EGaEl11CPyLs500ZPa76yao3A?= =?us-ascii?Q?Vb8QFVufYlbWsVkhhMeDHdr/2E/b689gYTYJ4ErNL3Z4kk2nIfHIvP8pdGRY?= =?us-ascii?Q?Hr+LMTYSQyI6abzLmWSPFz8y9tcwjEpwDYec9VgVf7QUHK08D8GsLN3enzSw?= =?us-ascii?Q?4KClHKX3Gn5YwzDId9DvMBTXCv0gIDDjZmqm7ef1uwTr1r7Ow+x9YzZYtts7?= =?us-ascii?Q?jUXVYJDq24YoW72xs079ztWnp/h7bPpkZhSWaw+PcC+jo2ov48TrcBFQtDR4?= =?us-ascii?Q?SEQK2xAVLbR4c3+nk0aP7p1w27IXao+iI9BN7Vyq5PmTL90W241wFBu31tGt?= =?us-ascii?Q?hqgbbHT7Fn0+0CAiy6GSUdRxC+T4iq3XInbA7XYYmH6N3JT8c8sC5PQ6rNYh?= =?us-ascii?Q?RcygHAq5QuVtj13BtmEp45d90AtmOUEVLDw9X1CbFTZIII+9OoU2czqFfEMv?= =?us-ascii?Q?BvawXAg8tdFk23KnIjMm4I6SKKSW+w1HQdfoLqnzFtF4W9Js308mr1an1aBl?= =?us-ascii?Q?z2mq6accm2YAEe7RC4XAvabZjBTsiMJPb9vLVxQJnPCfgpsg1tJTCJALmn5x?= =?us-ascii?Q?ttcvJvf0yQcCiRXRxNWGEDa2aLtW+57bTktTbwu/6AgSEqY8uFiwEVu28Kdf?= =?us-ascii?Q?e9lBcpaq4uAYxZY7u79HWaBAC6wr9bABvdkPT3HkyFbTUaU7DynrhcQNHroz?= =?us-ascii?Q?tmYEGY0LC32WwrtZwIiaqqTTwyP4uK21Fcz8LnmoYUyHwCC82oacinTaWep4?= =?us-ascii?Q?4VPSsfnqJU4O5oQYQHPKhPaLr073Fw/5QZZj5c/98e9nx90quQ1yb/pSkcQI?= =?us-ascii?Q?3gFJCRlAp37EZXWYIu7s1GQruToYLde180+RpVyts+xdhZHtLTnorMLguer6?= =?us-ascii?Q?QdsSTuiznVJrGBE5TyMlduv0f6pCjUG31MXFc8evEezmqL3EfZiYtIcA0ORW?= =?us-ascii?Q?61fxjTX0nKOo44F3MI2g5Xcu7udsYhVaMwte66gEaZ4FjqdDsR96P3uXBJLb?= =?us-ascii?Q?gquDDnaBssCpypFYzbm5Yvvr?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 808c8e78-e918-4948-46a1-08d8fa97d349 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:46.6388 (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: oCTWFdt3DE7n6B8qrkPHUHwuf4AsJ4Eey/6XL+dcVBmuTfpE93Yada/OHgwguMVNUnvzM4Z5+lUpU0IIRNtJYIfImrdUkvGSXwtyzqDvd8I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5909 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.21.121; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-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=unavailable 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) Content-Type: text/plain; charset="utf-8" With the following patch we want to call aio_co_wake() from thread. And it works bad. Assume we have no iothreads. Assume we have a coroutine A, which waits in the yield point for external aio_co_wake(), and no progress can be done until it happen. Main thread is in blocking aio_poll() (for example, in blk_read()). Now, in a separate thread we do aio_co_wake(). It calls aio_co_enter(), which goes through last "else" branch and do aio_context_acquire(ctx). Now we have a deadlock, as aio_poll() will not release the context lock until some progress is done, and progress can't be done until aio_co_wake() wake the coroutine A. And it can't because it wait for aio_context_acquire(). Still, aio_co_schedule() works well in parallel with blocking aio_poll(). So let's use it in generic case and drop aio_context_acquire/aio_context_release branch from aio_co_enter(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- util/async.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/util/async.c b/util/async.c index 674dbefb7c..f05b883a39 100644 --- a/util/async.c +++ b/util/async.c @@ -614,19 +614,12 @@ void aio_co_wake(struct Coroutine *co) =20 void aio_co_enter(AioContext *ctx, struct Coroutine *co) { - if (ctx !=3D qemu_get_current_aio_context()) { - aio_co_schedule(ctx, co); - return; - } - - if (qemu_in_coroutine()) { + if (ctx =3D=3D qemu_get_current_aio_context() && qemu_in_coroutine()) { Coroutine *self =3D qemu_coroutine_self(); assert(self !=3D co); QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, co, co_queue_next); } else { - aio_context_acquire(ctx); - qemu_aio_coroutine_enter(ctx, co); - aio_context_release(ctx); + aio_co_schedule(ctx, co); } } =20 --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891152; cv=pass; d=zohomail.com; s=zohoarc; b=NUWoklx3zoPSADwWrxUmu64vnS4nJIJLARNv+TdgbtfSRP0wwhUc54uEPvRhoPrw9GeW4yie++2GB/fwN2KVM+ECuAlhOsROUtk2sMyzJMPrcmtNYMYgsTSoib4bAZYJdFwTwu3z896Onbmbi+4VuHe48KCzI7n0PRMWsl6oo+Q= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891152; 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=8MSNekdnhLU/Ph5oyR/fN8+Fn6TYkQnNEUtW48VHjMc=; b=kbncg48InpNU6ByqmEzKwV708024S3yefBdSDxI5MJM2X+SRBc0NJF+/l7Wgh2hwOmhkXxMeLAPHVLgzhRBt6Yt8hZYu8gNgQ9KiiF8lf7k6pXG+iavsNMgjtZAgphjeuFvcKXlZ7LG01ofmg6AbwTUSBtXqAto61E3wJyVcFf4= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891152510115.4492479182685; Thu, 8 Apr 2021 07:12:32 -0700 (PDT) Received: from localhost ([::1]:48822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVOZ-00013D-B6 for importer@patchew.org; Thu, 08 Apr 2021 10:12:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVLW-000544-28; Thu, 08 Apr 2021 10:09:22 -0400 Received: from mail-eopbgr140103.outbound.protection.outlook.com ([40.107.14.103]:51570 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVL1-0001b3-98; Thu, 08 Apr 2021 10:09:20 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1713.eurprd08.prod.outlook.com (2603:10a6:203:34::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Thu, 8 Apr 2021 14:08:48 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:48 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RpYB0nNlKad880AgrW0pkVf4gUnTr96pfDizOVg96Mb6pVWAI6uBxui54j3XcEkZw5vkzKv8FipVntGgv2Oh7bcTMJkEqv0Md3gHADn6cKAnhkHXEmwg/Z/3bGUpGhGY4GezE79cqfs7bqJWu9fkLugG859mTP53AAY5wBYSFyoz/Rwx2GcOV+Hr+oSF793KeEX6ApphrhS2TtsLB0Kzl6/OXKaKXZF65BR//2ePlmPPPrfgCQ19hnYUNKu0EXOKqZwYY9kj9lheEwVFe8GaA50sIq+HTwvdHIk5YrmWWQ7VcmOED4hY6JzHolWEzLAuoSNEsOnR91f8Q5sRLte3MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8MSNekdnhLU/Ph5oyR/fN8+Fn6TYkQnNEUtW48VHjMc=; b=KO/Tt54sqxg3hpjlePAGTgHJLQCJdArUQQS/P+ZUeJRaH37YkUOsmaLNZWMbhwDmv05H+m8MtuwLzLRYsnD2s60Ufv64I4k9N93r92rCyynkYAjRH2lsrpug2W1yAjDNNs77d8I3bWbYkbDD5eoBmSwqtTqO4pH9EOBPaf/0P+cHWONT1R2SSgn7k5Qb6z+HLCOnT/CYVDedByDGIA7/Im4etHDVE2A2l51RQTtcHVb9icuTO/yZed2TR1kuuBn+7PYY5ll9apBv1N6tX6v7WT4s0EKImjVxT4jXJ8xFMbgXUiNU0MF5uzZDOKhOGepCfxDDaZxwit+BFkysckZ0nQ== 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=8MSNekdnhLU/Ph5oyR/fN8+Fn6TYkQnNEUtW48VHjMc=; b=iIUxGBHfBYnFCp1hxB2rKTuW+QDN6WDXxmXs5ONGtcpK5hIj+O3HZzl8SpHl90Cq8sILqxvpwbzZZyWL/PR8B6SIiXKOQKLLQ8X0DYWhMo9JB5IcwDYwpNTNf7K2YcJ2Sc/OcKOY0pAn2ABvdHo8220ueHXA4y9OsMgeLAl8tOg= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 04/10] block/nbd: simplify waking of nbd_co_establish_connection() Date: Thu, 8 Apr 2021 17:08:21 +0300 Message-Id: <20210408140827.332915-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: e73e5974-22f7-48ac-61f5-08d8fa97d41b X-MS-TrafficTypeDiagnostic: AM5PR0801MB1713: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:164; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6Um4L0AU1i4YwYmBjktsoNvLU9n/N38GWCrFA6dEVCvjVQl9V5PYYeZfzfPhSQAbJppUqwSUB7c0X8f1ZvyR9c2ia0+jowpQhofkqggKuchD47a8iGMIqwSsIWC4EPZ6/iWCC3RrlB0hyrfzujZpfar/cMWdCl9zd0yMYh0YNfZSIPzUqWqSRvohO//esYc3WH54lIMntktoabZK/juuy0cj4AZrmdoFBtFUPMw18UIjTRNLU1XWP1ru9QDhWaUTLed+J93Jf2fDYU8anSKCRRSEJmbFjfudum5LhBgAa/EYFGaF0rkH+VakVtAwl38s2g3qAhyteE1HCbnwPm2qRUb8E+K0T5Z/+QJ9VWjaR6LGPktMZdVzHK25n/Aj295lVLk5jMsoENjPPx83q21kl1JBmvn+D7OFKYfv1m/9MTgsLVksDxjNZakAikzzOgTdedFG8V8Jw4sQwn1qa4loQfuH5/3c88Pc93G7x8HDVmX9+BGqAS15Md6KN9X+6QN2t/XWnvTjv1wShn6x4d1rcbv3pUMcbHpz1m6gohBC0HOMlUkAGZHwRiFKtRmxMSnPgyLiYKgSUyeNZ2YaaK+KJHOMSN6bMrWhafNhAV3HQJpITjHjgFYTPP4iOrfdL33buJo+9E8hy70rVhbvdXm+oBH0WS/jHoHPaier6JHV0WzDeKLrmJ+fgN045juZ9Q3X3C7IcztHrBRGPPXOE1cvpvCcXWgkCW/THOnb2jeks2M= 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)(39840400004)(366004)(376002)(136003)(396003)(346002)(86362001)(956004)(26005)(2616005)(69590400012)(8676002)(52116002)(38350700001)(38100700001)(316002)(6486002)(5660300002)(6512007)(83380400001)(36756003)(66556008)(66476007)(6666004)(4326008)(8936002)(6506007)(2906002)(1076003)(478600001)(6916009)(66946007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?le5D3MNs057NgK8kYUuSAULJIcdkZSrNvRb064nUUs3DAuncTbIFnDjpGP+Q?= =?us-ascii?Q?LstyOAb1Xq8yuEO2M7TcpptkJNpMyYeFxNn0Z6cSgpNV+Gap7h2Ln9bdmlSn?= =?us-ascii?Q?QFvZLmSVQyIfQTVSJSv2ckk6yPPPHumlSY3KhA1WsQ7ruyYhBMnlNaA2yXkT?= =?us-ascii?Q?KjIg/HusJeeDHNdLzo8Etgtp9pu0/4eO++RNYivZ9WS4pUTLZHgpLhrgTuiq?= =?us-ascii?Q?VwKRoOr7Kyl1+aqjwth+s+dDoT4wWldJsBk8IBSEMF5LAtBBclnQBvJBuZtz?= =?us-ascii?Q?jkN/VtcDP00ivyQr+cgvQGuMPFjB7PzKk9D0NtsbFGY8/gHH+ajHVrn3Hjq+?= =?us-ascii?Q?eIDTxYrmHYpjmd4NAJ8cGOVe0OA6h5jYp7DK9dzQj3LBG1bYKkXhPBXnINS7?= =?us-ascii?Q?jsoDVrG91VYLTWT1/5lpeXW0LushBeZqOJbw4fq2ua/u1vOOoobokx8YrS7L?= =?us-ascii?Q?iTcPqpNUPoEX9aC/6vTWicMMhHQ+67rsRfhqTM9L48DK1bJP2nzPzP0ZSqSJ?= =?us-ascii?Q?Z2g0FsYv5yEVJObSIxCyWsQxoXpR4imd0CFPT3D4gTjUfw6WkI43ap/3EVma?= =?us-ascii?Q?VrFWC8ReVN86Wd1R7InkB8qeOrX4lbHF9o0499xXZynmS+to49W87ffgFvds?= =?us-ascii?Q?3kpaWBEtvCB5Mzv/6wVH8oKIiDmFHMhyxXNwaBTpa+Gd8FK59343ORNg2i+7?= =?us-ascii?Q?FAubSQAIZq46q9PyqE5cSy/KHjsIXjv7RIFPWStZUVUZIFAZCfKRjByEPz1O?= =?us-ascii?Q?5PSBSe64nWzKeW94WGEGvtnGeHO5Xt9pzEJfEv0TNd5JrLu9I6jfYyXFgsU0?= =?us-ascii?Q?DkDdZk0q74OOLmZ1hqpki0JnfnGCAePWHD5+jyqRJhlMFWOaVJeqwWhWGV14?= =?us-ascii?Q?rzPitbyIVNFIhgwf6wyddNOFIJUxSKk4wCvIKlbO/BfKUh0sq5rCTSnfB3QZ?= =?us-ascii?Q?NVmk6j2DBojh6NSmHH51f7lyb5AHp2Oued0rbl+iFuveWhARu8Jr12r3NSS8?= =?us-ascii?Q?8JPtHOmi2XydASopJOuZevR2DWnjHpPUON8TDK43OiJR5TWI9KJ+lkpSOCbY?= =?us-ascii?Q?SVFBSRcU9vA22z1lxrcqLon2H4eG7B/7vokZLi8DLXyymileIkVofrNNX50K?= =?us-ascii?Q?mYQsKFxCVu901IaRv1c7fUSwPbDe9Y14+f+YEEIjwtb5b3yobzRRTAh3ToHU?= =?us-ascii?Q?NCvXzCmRpVqzE7GaD4uP6iphXytKRmSnkvuQ3TvzxCBlsxTEZcvbXbI0uNBp?= =?us-ascii?Q?IJ8P5ZV3m0pgPs7eIi0WOnQEaRFdyN1BZBTY49Wxm1neFFI+JDFig6zpRfdE?= =?us-ascii?Q?1pVFMTs+KgwlTexzu1YblNkz?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e73e5974-22f7-48ac-61f5-08d8fa97d41b X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:48.0227 (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: SHr2Xe4/RbGqkRvSDHKIgtRgS1NkHHps0KE+ve7RYP18Ec8F3tXudQvby4vb47Tm98qAgLhMZrvs1iX99bGiJfwDEDkbJ9RxqDDlCIYfAQo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1713 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.14.103; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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) Content-Type: text/plain; charset="utf-8" Instead of connect_bh, bh_ctx and wait_connect fields we can live with only one link to waiting coroutine, protected by mutex. So new logic is: nbd_co_establish_connection() sets wait_co under mutex, release the mutex and do yield(). Note, that wait_co may be scheduled by thread immediately after unlocking the mutex. Still, in main thread (or iothread) we'll not reach the code for entering the coroutine until the yield() so we are safe. Both connect_thread_func() and nbd_co_establish_connection_cancel() do the following to handle wait_co: Under mutex, if thr->wait_co is not NULL, call aio_co_wake() (which never tries to acquire aio context since previous commit, so we are safe to do it under thr->mutex) and set thr->wait_co to NULL. This way we protect ourselves of scheduling it twice. Also this commit make nbd_co_establish_connection() less connected to bs (we have generic pointer to the coroutine, not use s->connection_co directly). So, we are on the way of splitting connection API out of nbd.c (which is overcomplicated now). Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd.c | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index b0bbde741a..4e28982e53 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -81,12 +81,6 @@ typedef enum NBDConnectThreadState { typedef struct NBDConnectThread { /* Initialization constants */ SocketAddress *saddr; /* address to connect to */ - /* - * Bottom half to schedule on completion. Scheduled only if bh_ctx is = not - * NULL - */ - QEMUBHFunc *bh_func; - void *bh_opaque; =20 /* * Result of last attempt. Valid in FAIL and SUCCESS states. @@ -97,10 +91,10 @@ typedef struct NBDConnectThread { =20 int refcnt; /* atomic access */ =20 - /* state and bh_ctx are protected by mutex */ QemuMutex mutex; + /* All further fields are protected by mutex */ NBDConnectThreadState state; /* current state of the thread */ - AioContext *bh_ctx; /* where to schedule bh (NULL means don't schedule= ) */ + Coroutine *wait_co; /* nbd_co_establish_connection() wait in yield() */ } NBDConnectThread; =20 typedef struct BDRVNBDState { @@ -134,7 +128,6 @@ typedef struct BDRVNBDState { char *x_dirty_bitmap; bool alloc_depth; =20 - bool wait_connect; NBDConnectThread *connect_thread; } BDRVNBDState; =20 @@ -354,15 +347,6 @@ static bool nbd_client_connecting_wait(BDRVNBDState *s) return qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WA= IT; } =20 -static void connect_bh(void *opaque) -{ - BDRVNBDState *state =3D opaque; - - assert(state->wait_connect); - state->wait_connect =3D false; - aio_co_wake(state->connection_co); -} - static void nbd_init_connect_thread(BDRVNBDState *s) { s->connect_thread =3D g_new(NBDConnectThread, 1); @@ -370,8 +354,6 @@ static void nbd_init_connect_thread(BDRVNBDState *s) *s->connect_thread =3D (NBDConnectThread) { .saddr =3D QAPI_CLONE(SocketAddress, s->saddr), .state =3D CONNECT_THREAD_NONE, - .bh_func =3D connect_bh, - .bh_opaque =3D s, .refcnt =3D 1, }; =20 @@ -410,11 +392,9 @@ static void *connect_thread_func(void *opaque) switch (thr->state) { case CONNECT_THREAD_RUNNING: thr->state =3D ret < 0 ? CONNECT_THREAD_FAIL : CONNECT_THREAD_SUCC= ESS; - if (thr->bh_ctx) { - aio_bh_schedule_oneshot(thr->bh_ctx, thr->bh_func, thr->bh_opa= que); - - /* play safe, don't reuse bh_ctx on further connection attempt= s */ - thr->bh_ctx =3D NULL; + if (thr->wait_co) { + aio_co_wake(thr->wait_co); + thr->wait_co =3D NULL; } break; default: @@ -464,20 +444,14 @@ nbd_co_establish_connection(BlockDriverState *bs, Err= or **errp) abort(); } =20 - thr->bh_ctx =3D qemu_get_current_aio_context(); + thr->wait_co =3D qemu_coroutine_self(); =20 qemu_mutex_unlock(&thr->mutex); =20 - /* * We are going to wait for connect-thread finish, but * nbd_client_co_drain_begin() can interrupt. - * - * Note that wait_connect variable is not visible for connect-thread. = It - * doesn't need mutex protection, it used only inside home aio context= of - * bs. */ - s->wait_connect =3D true; qemu_coroutine_yield(); =20 qemu_mutex_lock(&thr->mutex); @@ -531,24 +505,19 @@ static void nbd_co_establish_connection_cancel(BlockD= riverState *bs) { BDRVNBDState *s =3D bs->opaque; NBDConnectThread *thr =3D s->connect_thread; - bool wake =3D false; =20 qemu_mutex_lock(&thr->mutex); =20 if (thr->state =3D=3D CONNECT_THREAD_RUNNING) { /* We can cancel only in running state, when bh is not yet schedul= ed */ - thr->bh_ctx =3D NULL; - if (s->wait_connect) { - s->wait_connect =3D false; - wake =3D true; + if (thr->wait_co) { + aio_co_wake(thr->wait_co); + thr->wait_co =3D NULL; } } =20 qemu_mutex_unlock(&thr->mutex); =20 - if (wake) { - aio_co_wake(s->connection_co); - } } =20 static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891203; cv=pass; d=zohomail.com; s=zohoarc; b=Oe1ZMa8ozlUvcenmCh8SraPLSmHlG5Iz31aDveJbDvfzL1dFAAXhvk987uzA5LTsHlEvvF6U66obEDsmRVZqrOeS4lmaWFQFjV+SHht7NNOWiEfd0FRv1Adx9qzxuiPv5PGyY6cw585WiKL2660p5ZNOh/SshRNd/8XJm/zNyp0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891203; 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=ERQn4Ji29EMYJge3a7F+oZJrx3BKw/wWoj5Z74nNQyk=; b=V1qoOEqJRII9rc3yMggdJa0LXuB4jGkTI/mZ+BgjlgrrLzAWMUi1SQwR/HyD9L21Y8P/lfe4HuhOTh+yKXVDxKoZdvcA5ZS1p4l5CSF6p91JPtbhmn5vbG9zR3LPWFvMZwACTpGlyV1hrqzWH4oJ84lPyC/l7ou89BQlw9ovc7I= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891203355349.9411434278462; Thu, 8 Apr 2021 07:13:23 -0700 (PDT) Received: from localhost ([::1]:51286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVPO-00023N-2I for importer@patchew.org; Thu, 08 Apr 2021 10:13:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVLt-0005Td-2A; Thu, 08 Apr 2021 10:09:45 -0400 Received: from mail-eopbgr140118.outbound.protection.outlook.com ([40.107.14.118]:48256 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVLa-0001dy-QO; Thu, 08 Apr 2021 10:09:43 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1713.eurprd08.prod.outlook.com (2603:10a6:203:34::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Thu, 8 Apr 2021 14:08:49 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:49 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Be1dRJ8BpEuz6q4cjx2xKOrHw+uMTm226QC9DHv0ZA4oJFwnSm4mQT73frLdmKwvwTkOz9oScUqePwA4a8Os2SfaUBH+QDHleJOLfPvk6wilKw4rp3UVrwytC+pCVYShfd+HDxIs7M4goMHC/2PRQbIaliEv4aDsHfpE7QSFsoXfahr01WnjJ1v98FMtE1f7CN8g+tF4uVNyG0DsBcPaLpwT5ZSYTKXvhGi1V/OFBlLLb+fklWreneVUjaX809IH6yKB14j8GK6h++Q60iNjC9aBP6dLcKzxLfPX9ibKYTzaa8/lsFuTTepAggl6QQQVAr3c092cBsKXcKU5RVMApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ERQn4Ji29EMYJge3a7F+oZJrx3BKw/wWoj5Z74nNQyk=; b=llWbqdin1cQx0Nmlrtjp/3tYBX7R7h1V7oQIiEZQ1W7xYA8hjLGi4+Y6vjojG2c5y3YIvI1/bEO0yAfiqS2DcHs+sYiQxQbJHNgZCrezJilfmFiaPRrQ9ZeSixwgu+8Wi5msxCfTNOMWZFkg5f9iFR+zdYAjgy5KtNpztcPakbHHk5LSJhPSGvlPVtn2YglzmWinLu/OG7IargSBdn/xt3KYmXJ8XIsUVaTT7azbpz1OtKqvJEJSQlupT/hqNxpMNgpLX9gO2gN44fc5VFoyvSy6EgAKvDM4X5KBdFPuedHmp/XwjjW1U93Ezjn0oUuPH7uJcZxea5RgzMLUdJZX+Q== 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=ERQn4Ji29EMYJge3a7F+oZJrx3BKw/wWoj5Z74nNQyk=; b=aVu4U2ybyyvPFuyQkG6pOikUkEV422L+5QCjWs8uitxXBIFsiMWlOrYzwmM771km5wQYOjb0n8yAdlNX/x3pd4HrZApZDp7E9QTqRsG4B9dxHC7+bwIlPZu+5nruu6M09qJaxYhn8i1It9YwVR1v8jNTFbaNFcl64tN8HVKflZ0= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 05/10] block/nbd: drop thr->state Date: Thu, 8 Apr 2021 17:08:22 +0300 Message-Id: <20210408140827.332915-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 91761c93-43f0-45e8-93ed-08d8fa97d4ec X-MS-TrafficTypeDiagnostic: AM5PR0801MB1713: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qS7NKmjaJKPXJfV6j4EQ5wRD3EQBSzNgtyXWBDzEGXKozsQwFaGg3CPRUsVbdfC6gSHoGZyYLizcz8ikUPFHp0dP+xLg+3t5Z1WmUe6QpvoY1/iZgvbo8xralyihVTohT6ZOWAGrrP1ct2LrYiGnYJyNPRNnkJ7NceFuK8nlAVWLNKGdpED/oZjsYVAi4aSLt/cRIVXp+uMuzjnzHzRv5LCNlWKTCdtQqHcbKIjXgE6PKLQbFYktfivgY4tmmN+h1qw73YgIRygeVDMauYJAkBO0irP7QZpB42VcX/toAyvj4E6w32ECVCpbTZO+0e7d6GbA6tBq1wGi20pPyc/9YTdflG9XWFyRhPMUpy7R792SqqWZN/CA1bYt2TZ6TCALGlbAlBHo9t0roXn45IHOiRJ7nzt5NnC5uMbeRMIOuGdNydJNQQMIKVf2o/jWfMcvM8Yjcs75er6/iK+l3MHw3fp2PieM/l2kI1Oe2uLBUJRjoYPpbtORtB/UqKFz6fhUFXPiZmdAJHBDfycHGQHpqGZ3F5tc+rXEfFB02qA1AQDBCIL3C2zM18NbmvL0L00rtqLZT8c21IxtJuF1sacxA7LvcbxPV9hL53ebQOY4Nf8pjGYqzmAhr0QLlbzzE5Uy1EJibCG9whqqAy31y4NYmJ3f716i8LWmX4Ig1UeDM6amMp9ElK0ffdZ1s/G/Yw+GUBmqhN3HWuw1sQF7Uqvmylnu+m0FraCCYJo3Pd/LiNs= 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)(39840400004)(366004)(376002)(136003)(396003)(346002)(86362001)(956004)(26005)(2616005)(69590400012)(8676002)(52116002)(38350700001)(38100700001)(316002)(6486002)(5660300002)(6512007)(83380400001)(36756003)(66556008)(66476007)(6666004)(4326008)(8936002)(6506007)(2906002)(1076003)(478600001)(6916009)(66946007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?VGg6YSWw2zS7jEvq9MJ5IUWjdltjxGpzezJJQJk2S3wzZcOdJ56XHF5GCoc3?= =?us-ascii?Q?ETlIqJMWzhT8Yvg74I63gRw6Mn23LMMlueae8UyxtcGLggzF6ZYJYQWpodEF?= =?us-ascii?Q?vEWNvneoRpfHTZPJarTvnApb1t6ukefOmH25fCqPS6P4e3dJhPC2ORh60vuU?= =?us-ascii?Q?c90uiZbb8M7L1RbftUPL3r4jH6gDtPVWUuf3Y7orDjSVI/02M34ghJSbzIEc?= =?us-ascii?Q?ukBO88hqMZzWnGMgWf1JR6nTP/spjrklnTZ+hqk7g384EFXSffgYhkqnpRk8?= =?us-ascii?Q?EUWJhvyszgCfIlCcmhgi6dqxy7Q5r1RRfTTWmR4o2YkUjgdpXFFPxMdB2G20?= =?us-ascii?Q?F2fE44asi8d9iZa4gQhQe8jqlKEszVE2GQC3HC8zwQMA2wGbfnY6JjaMYZp6?= =?us-ascii?Q?K7+6YwwdxDRvqt6g859xrVfhoDVi9B4aDepFLXWRoSzYaxjHVv1cKuZPONim?= =?us-ascii?Q?W74BtXCf/C9VZhTlTRALLFd8w/Mps6xQJt/xEsS1l+zym8QDgUzkN8ofH0mj?= =?us-ascii?Q?txNIRLGPTlw13CtKjInTjGvAgSLMIUS1b45owVJ/RpcmQ6PQVRJypmlYWx69?= =?us-ascii?Q?+dDPtvAFs4i2EIxaOEBZ1Bnj06am2uOdp3tOrETom1fR/ePFW9fRVZpgTviv?= =?us-ascii?Q?RppYaZRsd7QUk1UB8elaeDmZ9ZJ+wIxW7M5Izu6B5tp6p9fhIvTSvNzPvXaP?= =?us-ascii?Q?Ki6C0Xpp3YOX2NP9ivE9suLuPkFor/j/odhd54/ToX/UywXqWQceUa48gK8o?= =?us-ascii?Q?GwIvebsaffncehiiXnjGy3JYj5+QzPhDe21HlOfc58ewU4VXB7xmf9/UGduH?= =?us-ascii?Q?aQsV96NKBwku8g9ltJpbRrjJiccEsPwaK+XVjsUKRet4sSgkWqIMjjIhe39I?= =?us-ascii?Q?S3nCFnCQocEmGZuPpZS6zRsH2hZ2ZVrKR5xW2JmDvMA8EGu5sDn9VLa/rsjr?= =?us-ascii?Q?Zri+qWGSTlNpzdfb8WPs5OTmcxyzvs4wnfKTlL/uYT2qh2+SgayQrChCWV+E?= =?us-ascii?Q?NKx9GC4S0vVCJ7uOYiu331jepx3uKDqfqejYFNUZ6gqbT3jawm6YwUyU3ENd?= =?us-ascii?Q?FW+6OISR7Q3IfWjNo9x78rRV4G8qXAYvIr/Z6PNM39XCrscW7YQkAusGujml?= =?us-ascii?Q?wen6S10ExfiJvEfDjLE40Y08N+X8gatBIvjzdgrEqHj63cC7umblwrRyFftw?= =?us-ascii?Q?msZWayOU1cueruvtzTA3wqZaquZZT/Qhcj7rnPr1a+kJkfyU8A43FHtEaBku?= =?us-ascii?Q?Mmcp1Xa3t7G9FAbsySkabM9+knTIj3l8dSvywz2rDiJkaTOrvMwm3MWUbVyu?= =?us-ascii?Q?V1KQ23wIToe37I8wm+y2u1tt?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91761c93-43f0-45e8-93ed-08d8fa97d4ec X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:49.3817 (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: LIyWBtlsHCoQKxeqC1nyXbchwT2c6nr4DHyADgY/uWhY7bYA6V0S7kjL4ijXL7ad8IQ7jT0HDEVHNRDzEJdvI25EI1a6YsGRBbKLpCGBlaE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1713 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.14.118; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-VE1-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=unavailable 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) Content-Type: text/plain; charset="utf-8" Actually, the only bit of information we need is "is thread running or not". We don't need all these states. So, instead of thr->state add boolean variable thr->running and refactor the code. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 103 ++++++++++++++-------------------------------------- 1 file changed, 27 insertions(+), 76 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 4e28982e53..85c20e7810 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -66,18 +66,6 @@ typedef enum NBDClientState { NBD_CLIENT_QUIT } NBDClientState; =20 -typedef enum NBDConnectThreadState { - /* No thread, no pending results */ - CONNECT_THREAD_NONE, - - /* Thread is running, no results for now */ - CONNECT_THREAD_RUNNING, - - /* Thread finished, results are stored in a state */ - CONNECT_THREAD_FAIL, - CONNECT_THREAD_SUCCESS -} NBDConnectThreadState; - typedef struct NBDConnectThread { /* Initialization constants */ SocketAddress *saddr; /* address to connect to */ @@ -93,7 +81,7 @@ typedef struct NBDConnectThread { =20 QemuMutex mutex; /* All further fields are protected by mutex */ - NBDConnectThreadState state; /* current state of the thread */ + bool running; /* thread is running now */ Coroutine *wait_co; /* nbd_co_establish_connection() wait in yield() */ } NBDConnectThread; =20 @@ -353,7 +341,6 @@ static void nbd_init_connect_thread(BDRVNBDState *s) =20 *s->connect_thread =3D (NBDConnectThread) { .saddr =3D QAPI_CLONE(SocketAddress, s->saddr), - .state =3D CONNECT_THREAD_NONE, .refcnt =3D 1, }; =20 @@ -389,16 +376,11 @@ static void *connect_thread_func(void *opaque) =20 qemu_mutex_lock(&thr->mutex); =20 - switch (thr->state) { - case CONNECT_THREAD_RUNNING: - thr->state =3D ret < 0 ? CONNECT_THREAD_FAIL : CONNECT_THREAD_SUCC= ESS; - if (thr->wait_co) { - aio_co_wake(thr->wait_co); - thr->wait_co =3D NULL; - } - break; - default: - abort(); + assert(thr->running); + thr->running =3D false; + if (thr->wait_co) { + aio_co_wake(thr->wait_co); + thr->wait_co =3D NULL; } =20 qemu_mutex_unlock(&thr->mutex); @@ -411,37 +393,25 @@ static void *connect_thread_func(void *opaque) static int coroutine_fn nbd_co_establish_connection(BlockDriverState *bs, Error **errp) { - int ret; QemuThread thread; BDRVNBDState *s =3D bs->opaque; NBDConnectThread *thr =3D s->connect_thread; =20 + assert(!s->sioc); + qemu_mutex_lock(&thr->mutex); =20 - switch (thr->state) { - case CONNECT_THREAD_FAIL: - case CONNECT_THREAD_NONE: + if (!thr->running) { + if (thr->sioc) { + /* Previous attempt finally succeeded in background */ + goto out; + } + thr->running =3D true; error_free(thr->err); thr->err =3D NULL; - thr->state =3D CONNECT_THREAD_RUNNING; qatomic_inc(&thr->refcnt); /* for thread */ qemu_thread_create(&thread, "nbd-connect", connect_thread_func, thr, QEMU_THREAD_DETACHED); - break; - case CONNECT_THREAD_SUCCESS: - /* Previous attempt finally succeeded in background */ - thr->state =3D CONNECT_THREAD_NONE; - s->sioc =3D thr->sioc; - thr->sioc =3D NULL; - yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), - nbd_yank, bs); - qemu_mutex_unlock(&thr->mutex); - return 0; - case CONNECT_THREAD_RUNNING: - /* Already running, will wait */ - break; - default: - abort(); } =20 thr->wait_co =3D qemu_coroutine_self(); @@ -456,10 +426,15 @@ nbd_co_establish_connection(BlockDriverState *bs, Err= or **errp) =20 qemu_mutex_lock(&thr->mutex); =20 - switch (thr->state) { - case CONNECT_THREAD_SUCCESS: - case CONNECT_THREAD_FAIL: - thr->state =3D CONNECT_THREAD_NONE; +out: + if (thr->running) { + /* + * Obviously, drained section wants to start. Report the attempt as + * failed. Still connect thread is executing in background, and its + * result may be used for next connection attempt. + */ + error_setg(errp, "Connection attempt cancelled by other operation"= ); + } else { error_propagate(errp, thr->err); thr->err =3D NULL; s->sioc =3D thr->sioc; @@ -468,32 +443,11 @@ nbd_co_establish_connection(BlockDriverState *bs, Err= or **errp) yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), nbd_yank, bs); } - ret =3D (s->sioc ? 0 : -1); - break; - case CONNECT_THREAD_RUNNING: - /* - * Obviously, drained section wants to start. Report the attempt as - * failed. Still connect thread is executing in background, and its - * result may be used for next connection attempt. - */ - ret =3D -1; - error_setg(errp, "Connection attempt cancelled by other operation"= ); - break; - - case CONNECT_THREAD_NONE: - /* - * Impossible. We've seen this thread running. So it should be - * running or at least give some results. - */ - abort(); - - default: - abort(); } =20 qemu_mutex_unlock(&thr->mutex); =20 - return ret; + return s->sioc ? 0 : -1; } =20 /* @@ -508,12 +462,9 @@ static void nbd_co_establish_connection_cancel(BlockDr= iverState *bs) =20 qemu_mutex_lock(&thr->mutex); =20 - if (thr->state =3D=3D CONNECT_THREAD_RUNNING) { - /* We can cancel only in running state, when bh is not yet schedul= ed */ - if (thr->wait_co) { - aio_co_wake(thr->wait_co); - thr->wait_co =3D NULL; - } + if (thr->wait_co) { + aio_co_wake(thr->wait_co); + thr->wait_co =3D NULL; } =20 qemu_mutex_unlock(&thr->mutex); --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891700; cv=pass; d=zohomail.com; s=zohoarc; b=iGj0yTxKYo5KDQR1PWUlaR0D3rpZKNmbcwgrXZKq9V5xyPkM6vlGcWnI4eb+8PdSF5X/uz2PafUUNRhl38/wX8VAkTdPus/QjjXm/TBKcf9vRbEb0Wt4XQlC3BTOZEpAGJ93twjBo/kcLRhQSBMdRYDWtRcpWm9ACp4R6X1qQh8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891700; 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=wrs0RcXKqrz4xoMYNQhi65N8QPvot6ksqRLmQHc7eg4=; b=gSfVrVskRj3KQ9HTcm739Zwe3TyKwKjdJnoVpwzth7dfBBBxXlguT0CVZZNlTowTMBNnSUsuNWe+FKqCFb4+vOB4wMWAB8uA7c21HEo5IgsfeKF1uzD96WMbYUSa85+IacqROt2nkfYi6/ranhaGC93ZOqYu8cEUmGtqXjZEW/U= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891700408218.6617883164854; Thu, 8 Apr 2021 07:21:40 -0700 (PDT) Received: from localhost ([::1]:39254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVXP-0000fp-8K for importer@patchew.org; Thu, 08 Apr 2021 10:21:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVVF-0007Rj-0M; Thu, 08 Apr 2021 10:19:25 -0400 Received: from mail-eopbgr70127.outbound.protection.outlook.com ([40.107.7.127]:17439 helo=EUR04-HE1-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 1lUVVB-0006dY-41; Thu, 08 Apr 2021 10:19:24 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB5127.eurprd08.prod.outlook.com (2603:10a6:20b:e1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Thu, 8 Apr 2021 14:08:51 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:50 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JO0y0NGxF110NuCz9eybUKozjUZogGoHAHSbV1RrzVe5Lv2TuWU+v+Pdr7zeiFZNIIN4flV/pdLMavhykfDfUbBH7OYtI+Kww/y3XvPDugg5XRTMU/UtZisOBjtD7lFm/SYQRC3mbORTGsUo/8xB/Kxxh1HOANGHb0A86qittQbAmEHCpTPGAwlfnx0CWHoovmNOseqRn3pieNjsG8XyVK6bhCVcgi/v35wxIRfa54W+qqryJ5NQJ2fZv45hLIlEuy6wsKTr3jufefeQaM8uIwLNrjxINYC4//dAwXkDYPRzDNT3vHr6OBshKcyLNwso8I8r8pfek3IUBMEp+Z+Cbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wrs0RcXKqrz4xoMYNQhi65N8QPvot6ksqRLmQHc7eg4=; b=L4HA+hQZFRHOW83fiDIoaTAp/821mci7cHLVNY487AnnqtQ5EafP2L32OrGecU+pOImwEWQb2dzs/xQKWU5VCRN55I8M0maDwBPqvc4Eua85tIugJoUXoanFeRaygEyCgBM2FjcFN4OutTm3sEXkJFycvlJkGMwCyr3bQNbgeRhaQYPCbi4XTjb/E+496RAhgwZgu46x7SSn0vRU/SueoUfllfNH3qzZjwdG/uzJvf5teQSCbcpIIGrc2cQRv0uuHdb6IX6260hP2ggoLWhAykB8tlKJyGOqedtpwNfTM5BQjCkt9Nh2rZoj94JIBXSDv1eVFG7wd8dS0egvl6o6Ew== 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=wrs0RcXKqrz4xoMYNQhi65N8QPvot6ksqRLmQHc7eg4=; b=AU0n5FEuUb4oe/Q6Oq6EYr62+S5vyD6CKscAF1+mEp2q+74JRewIYAbOGdlVJKxHEFJ+A64SvuLVHC++iNVwrO6v8sHKJQPnsty5MvCRmpaQjwz8aSzAUlG8C99VsuUUjIZ3khfld1G5LEuXP/nyBhzn4VKRG4+w7Ml99yiQJ9E= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 06/10] block/nbd: bs-independent interface for nbd_co_establish_connection() Date: Thu, 8 Apr 2021 17:08:23 +0300 Message-Id: <20210408140827.332915-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 83a839f7-271b-4d00-0a4f-08d8fa97d5c7 X-MS-TrafficTypeDiagnostic: AM6PR08MB5127: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:663; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IG/jubqHyJmTZ9C0YZsAjvElJrTOYPSk+9BCAduPyPF+V1bpJYcBWDpxFdy9MJAQbtaL6OrPS0cwr8NHql7d9sbkKmoGbfQK/20CBKRgS1QdrzkgoEpFCFNVfmBuEw8pvzD8uOqRoK3hx7iWihUjBZ3Y6/MbUXj6ml9VztGBg1CZVCXyKfHn3ZOH/awmj06zYy4bcWjJVDp86o37GVQ+X8CQPLXuHmkF0cr8aEjQsUgivR+65UNyJ0OssfNZ1X0ygrimdtwPSbSRXRGv+I9SwjBtgWrTopKTnrqboKJDqx5xos8HfuK2Ac57la2NLRfmX+1iSDpeHjpFAhK2IX34LD6S2H2yqmEPPjZI9sKJbOIS90TYWsEDLlWWgSSTnLhWkuBZ73TRzqh+a4mzkzsz62V4XF1UZt7xkaSYJ/s+VgjbPzhk4Fx/R7aQfwjtbUTpnqzHCbIkhDKrt3L1aVE+DFVELX1jI6NR9nVHCWUljUKkf0/xfxef2iph/onf0t5bJWdsv1Z+Iu0dzoJbr8Rq9rkPsi4G2rBDG7F9fUOj4Izp9MA9nOPUN90Uie4QLOP1F95p7ZgUEhpA2sn1ZyjTSAPQNXTqj98oDUIDN8I98+AjYKqKh0GDYMRsX+zWo47tfUAHnzSfTBMmK3f3cCFyGGsVsG3HW2gxfjDxk8Jb3jUqgo8SZs2V9ZaM6oTFJuaSbI9FGH7nopL7REpN3RhgltdO3BaGuev/4MyLr3Pe1lo= 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)(376002)(396003)(39840400004)(366004)(346002)(136003)(6916009)(2906002)(38350700001)(86362001)(83380400001)(8936002)(6486002)(52116002)(5660300002)(4326008)(66946007)(66556008)(66476007)(69590400012)(36756003)(38100700001)(6666004)(6506007)(1076003)(6512007)(2616005)(8676002)(186003)(16526019)(316002)(956004)(478600001)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Zh3lpARWzL5n0mlEEhB7VSuThbfhTG5JbzwUd6teiaM3WNUv+Nz/npsyWCSp?= =?us-ascii?Q?kBPFLoyn9wACB2rXGQx8D0aEe1VHHD6ZlXUKS5ScqJll5jYIt0IvPNCJB1h5?= =?us-ascii?Q?0Dt5F1/6SUaP8B1hu5/XJtCdzhMfFSQ01bbmkwnuViq2SlPzMprBf2/68GBO?= =?us-ascii?Q?HWz0mhouqbxmS4YMGrZVePhzhJ5BmpfqpwKlhenEra+UA0w+PaaCdUbkr1kr?= =?us-ascii?Q?1+LRkyE8FBiNnozA70ZAFnKmiz6SL6f1DF4MFxLNwDMPiFWENmwHgOfDHU1z?= =?us-ascii?Q?u9hVLVOeqZUYK/gYUetvUBl7QKbPYuaeROGFRBIKvJr4V/e3F0lKzvrZPXyT?= =?us-ascii?Q?pjuwkcz9UmhmJpOjCY0jXgt8ij17ooZdsL/trOkT2D9eNEOp/Ou3A8z5p6SY?= =?us-ascii?Q?UaktUgUcsMWVktRjLo5xDpwKoIpy8tU/+6/lvArBsGxNjZPEGEc4WfQrivPa?= =?us-ascii?Q?BmkgSaokn3wDImFN1PWVkY7at9Y1gVNQfbHO2qtEw+hv5mUIC9fbl8hjqsLd?= =?us-ascii?Q?0e4g1J5Hg5/q76JyJ7Wjjh6+8LRzbS5OmXgIgAWvyXpfGYNjVwC+VqoD9DZf?= =?us-ascii?Q?f1PmdWCgWVUfFkJ0ZCSqUrUQq05oCgHjxL2ewGu2rPlAHJXQTVrbeMivIWto?= =?us-ascii?Q?z7C2l5YCqjiYsrf/DTGsXzYFpFbKApICbWemTzDtI12mIBuxH0aQrZzVFG1+?= =?us-ascii?Q?Y4R2RSZlD1HvyAT2hW9VCK/MtXiTbxBVwcXoa1fUvC5Mw/lnwPNweCDObZF3?= =?us-ascii?Q?nfPMhrTlVWyC4+Tr39sT37DGhWJk59oteQ8KFDRcv+QzSCcrahLI+CqeXmBE?= =?us-ascii?Q?q8u03Msu1RebwDA/6CBPRBaDYWYTmv61Upwmfwbe1obozPmdGWLu06AD/r3y?= =?us-ascii?Q?+H3Fy1oAnCp89blYuhCPQ3XauW2if41CWU37Qa8kcmGmaJFdO0ClPdzqg1Ed?= =?us-ascii?Q?MsgtpTEen7IArOE2zqoR8PaLbAw14sxGlGMAFWphx8v0J6BuW+KxTw/06al1?= =?us-ascii?Q?ZNzuE/FzDLaPm4bqL9cqrhCWmGMfZ3SpiD24iFed6Uy1Yoqt+6W2c15YjNL7?= =?us-ascii?Q?MUQGdYSEL1I51oUMeO21lnGDjkXBBWAm16rOAHAIVO3kODP27ZcNNXC8p2QN?= =?us-ascii?Q?uPss3cgtOkBBUOmta3j3qRtrCX3bo1t+v/yEyWYDkyAebkGOJs18OrBf51zc?= =?us-ascii?Q?0IG/wERNcUszqFpkoNjgwyWMLfygV2PltP3WvczA99U8KQdS0/VVC/AJ0r/p?= =?us-ascii?Q?vsilWbWQZOH4lvLRU7GOiG8UK+MRNqjAdTkoS5KDlP/93BWwm6atTfgQHD6T?= =?us-ascii?Q?2AlbxiwlJGaIOlWYNtJ/OW5j?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83a839f7-271b-4d00-0a4f-08d8fa97d5c7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:50.8652 (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: AXbSe5ZyJtznvCkEHF+bYM+BRXHNleI4rYXQkSxvPPl5FeVGrqU145/SmrZOgx8mVtfAeMMFPtRlANzcxoFkbrGkEy+ZS5DzUZlOF4S1ilk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5127 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.7.127; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-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) Content-Type: text/plain; charset="utf-8" We are going to split connection code to separate file. Now we are ready to give nbd_co_establish_connection() clean and bs-independent interface. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 85c20e7810..a487fd1e68 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -122,7 +122,8 @@ typedef struct BDRVNBDState { static void connect_thread_state_unref(NBDConnectThread *thr); static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *s= addr, Error **errp); -static int nbd_co_establish_connection(BlockDriverState *bs, Error **errp); +static coroutine_fn QIOChannelSocket * +nbd_co_establish_connection(NBDConnectThread *thr, Error **errp); static void nbd_co_establish_connection_cancel(BlockDriverState *bs); static int nbd_client_handshake(BlockDriverState *bs, Error **errp); static void nbd_yank(void *opaque); @@ -390,22 +391,36 @@ static void *connect_thread_func(void *opaque) return NULL; } =20 -static int coroutine_fn -nbd_co_establish_connection(BlockDriverState *bs, Error **errp) +/* + * Get a new connection in context of @thr: + * if thread is running, wait for completion + * if thread is already succeeded in background, and user didn't get the + * result, just return it now + * otherwise if thread is not running, start a thread and wait for compl= etion + */ +static coroutine_fn QIOChannelSocket * +nbd_co_establish_connection(NBDConnectThread *thr, Error **errp) { + QIOChannelSocket *sioc =3D NULL; QemuThread thread; - BDRVNBDState *s =3D bs->opaque; - NBDConnectThread *thr =3D s->connect_thread; - - assert(!s->sioc); =20 qemu_mutex_lock(&thr->mutex); =20 + /* + * Don't call nbd_co_establish_connection() in several coroutines in + * parallel. Only one call at once is supported. + */ + assert(!thr->wait_co); + if (!thr->running) { if (thr->sioc) { /* Previous attempt finally succeeded in background */ - goto out; + sioc =3D g_steal_pointer(&thr->sioc); + qemu_mutex_unlock(&thr->mutex); + + return sioc; } + thr->running =3D true; error_free(thr->err); thr->err =3D NULL; @@ -420,13 +435,12 @@ nbd_co_establish_connection(BlockDriverState *bs, Err= or **errp) =20 /* * We are going to wait for connect-thread finish, but - * nbd_client_co_drain_begin() can interrupt. + * nbd_co_establish_connection_cancel() can interrupt. */ qemu_coroutine_yield(); =20 qemu_mutex_lock(&thr->mutex); =20 -out: if (thr->running) { /* * Obviously, drained section wants to start. Report the attempt as @@ -437,17 +451,12 @@ out: } else { error_propagate(errp, thr->err); thr->err =3D NULL; - s->sioc =3D thr->sioc; - thr->sioc =3D NULL; - if (s->sioc) { - yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), - nbd_yank, bs); - } + sioc =3D g_steal_pointer(&thr->sioc); } =20 qemu_mutex_unlock(&thr->mutex); =20 - return s->sioc ? 0 : -1; + return sioc; } =20 /* @@ -514,11 +523,15 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNB= DState *s) s->ioc =3D NULL; } =20 - if (nbd_co_establish_connection(s->bs, NULL) < 0) { + s->sioc =3D nbd_co_establish_connection(s->connect_thread, NULL); + if (!s->sioc) { ret =3D -ECONNREFUSED; goto out; } =20 + yank_register_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), nbd_y= ank, + s->bs); + bdrv_dec_in_flight(s->bs); =20 ret =3D nbd_client_handshake(s->bs, NULL); --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891129; cv=pass; d=zohomail.com; s=zohoarc; b=MfE/FwEkvbUUnZz/xav7ji0OO2ojt6ElcGp71P3lFhTsD9bTA6YkikpsysoXVmf1t7eizCXs5xjWl0EE3YiLRj4kw4XY9vca5bPbHSN8ohIsp8XUgLWfWTd3zjoryLS3hw661Cs8AfJT3bmJhCe1d9P18mmSa20elISzjF9y9Us= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891129; 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=4OI2tDnUOEYeKwOSdAUYDGXSZQuRM/wZd9aQxJtkirI=; b=cd/qFrvNtuB+NOG0+ZCGl9VnyX9AOfJoePlOgC0MAi/IgVkVIHTBjYyMJESFdyX76IM5JTGpn77C9F4dbrGaH/KrPAU4E7LCiTaxGLIRzdqQJeTXNweeJY3Y1zf08vUohDWHqKs/xT/7P8UffaMqItAho2bIvyiYAFwbQgt6edg= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891129160979.140282781474; Thu, 8 Apr 2021 07:12:09 -0700 (PDT) Received: from localhost ([::1]:47022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVOC-0000LI-2y for importer@patchew.org; Thu, 08 Apr 2021 10:12:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVMg-00071O-8K; Thu, 08 Apr 2021 10:10:34 -0400 Received: from mail-eopbgr50100.outbound.protection.outlook.com ([40.107.5.100]:41486 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVMW-0001oo-Rv; Thu, 08 Apr 2021 10:10:33 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB5127.eurprd08.prod.outlook.com (2603:10a6:20b:e1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Thu, 8 Apr 2021 14:08:52 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:52 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EH2ux9dfB4Bbp3w/YAn5QF0FQ9MWLyKC6u7ds+OkMpj6dYPuQ9dOjCr+RXzyuD5muJzZkvAcWzL+hxXOQxuPpxPFf28Z0Cr7O8jMWp5OK9vE5bXNa/j9jXJz4Q7zDwZ75CnGbHXTmHkQeWnhhNC+dvNM+7yzBqj49ns5rdQop9mcirdrNqTp2fQXm06AObWQviLmoGMERkmOE/4af2CXNI7Vn/MJsEAnZljQ9NCexgVsSa6WTFCQtx8hE6WKy8Wk8kNDOhzXbKxVC2rE26u7rs5cxS5FTaS8Cnkc3G9xC4iUwywpk/2kCBbJMr9cPWUhjkk8DGj7uU9LhhZO+y5iDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4OI2tDnUOEYeKwOSdAUYDGXSZQuRM/wZd9aQxJtkirI=; b=ce0+fWdd4Rj9R1DuipNzEKVj+th189soFnM93I3OBfO03KO8vzEHzxEnz/CtIF7oaZCc23zaS8VChsJB0ryZZDwP0RMkNsUhiASQoWuRo4H/vZSAuS5kg57YMPt9xhXia1EkQFNyTR1c0FuUjBiO1VMy6RSDKPNgyucbKjARBbbdUpN/kwPrVcjP1m3zhfo4tdA+zp+Wd2B9acHTZbrrA3nQI4ntFDnZOwz0ih0FFu9q/Csd4A8BcAmfT1nYficqV9lR4M7H0UIdYjOQd+UEWjASgczjU8aLI1L2jlYIb1Muwf8crS6rz20mJBtY7o3bwUNmDR9k+OWNrmPfyZnYQA== 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=4OI2tDnUOEYeKwOSdAUYDGXSZQuRM/wZd9aQxJtkirI=; b=Iqy4JgXMWZxYk1yX/8/bCqQIh5awIVfeGXFQr/hkNb4Fhp2VyBU9/kVW6I7kVjjCUhbi7E8GKwaf66UxdCwv5avHcoBJxFJb3mVIrqPQchoBk5LZ0ZvtM1q2xJRM2Jlzf1lPvwlzmti2HsSp4i7VFKcmhRp38QdL9Dj7PrfQXKY= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 07/10] block/nbd: make nbd_co_establish_connection_cancel() bs-independent Date: Thu, 8 Apr 2021 17:08:24 +0300 Message-Id: <20210408140827.332915-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 3933d71d-b2c1-4138-4d6d-08d8fa97d6b1 X-MS-TrafficTypeDiagnostic: AM6PR08MB5127: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:376; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NZ9B3KexZWuTWp8vxmmB1TDgSNCjtFX+X6bP256+dkZpNYWurmisTw8Bwl2/CcFYGXb3I+vh2RhMQloHOE1Ht/VoL+xpFW0ClBYh2217gMMsix8sr2Lk5MIufQkMQK+VEZk5kTHeyEyJnBjcoC4q4IrISR4+cOY5ZoZQZuD7WVCJquvH+Q5yPjm0SFqxCG9YwnYROiXOtEj+hDKdkFTDJhk7mO33tLC7bwJAK7d8RdJzPj3F9IQA/80qtaaQoWHexs8620Vs74Vo+Ou1b7E01aHVzUtZYbXFH7qZPCiq4khgwm5Lcupip85CPfGZkAVu+WNAVdpLLtoNEmth7Nbyy70If7Yjl+YCKpocl1wsRlmm4ar+cSDhlQ6nyvVQKjQQCvIZcs1StuyfnORSnXljpVq6R8xtdnIsj+PAS1ycpC3QzkpK6SOwh7lHJKO43p3scGoJZuighQ4YV6usfda1eEBvwVX1jvhDdPcdH3naPuZd8msy2Ee2yFOZT1OVW5L7L0DE0jUZy26PM/LNeCjT9eILChvXS8URdDCJLvt2FP1nF27s5Bl60sBdVfay/TkF2YDXvZK3edUzL73uXfx8zitblxar7+hA+dhONDYfPqOLgfkCK8alkjpTQTTHF+/HpErZ8JehK7tQuA5JyXwQNAzWUPw8tm/kVEljHqYjmArMBd2e+zoVUtmlIzjyG1iCqMxpfCmIiq2jtKquFzBbn3iPKYizLoS4IkBZh+NujGE= 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)(376002)(396003)(39840400004)(366004)(346002)(136003)(6916009)(2906002)(38350700001)(86362001)(83380400001)(8936002)(6486002)(52116002)(5660300002)(4326008)(66946007)(66556008)(66476007)(69590400012)(36756003)(38100700001)(6666004)(6506007)(1076003)(6512007)(2616005)(8676002)(186003)(16526019)(316002)(956004)(478600001)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?yQydcdhVX8zKwCksHEjzx+5u7GPJpIy6mNHq4np0tvRFk97mZK4UVNJg0Itm?= =?us-ascii?Q?OwGQkg1SaQaHnCXY4INvBeBS2UINlDbJJnUgoMZgA677Tw7N22/WsydM21+i?= =?us-ascii?Q?xGM4o/YeZhhjTLBtFJfmMGrJD3PPNBn4qLewGRyiEKXMc2gjlxbGkfsY1iqx?= =?us-ascii?Q?ctDOlI3KHel9M51uLxwHqBqEqmV2RZ+TrJ4sLneB3J/VDlfAbQutabaQw/ZE?= =?us-ascii?Q?WeqZyDttMxN1SaypneeW0wYz2GjVCF8STg0Cpg2hKmugK/iUh72RmpnQvX4H?= =?us-ascii?Q?BY9d4htrcLDSql4UjM42l3YhNwTIsz89D2F33B6R1wFSmDRIwLcNMLJGXWwA?= =?us-ascii?Q?xVqnU9LhZCdXBgaC/46f9tEkfhejQTgH/kDZ2EF8zKyIyvRf99I3sH/twupI?= =?us-ascii?Q?/Rzhph5F6iyMBGtBRAWoKVC3EZowC5rCdeloBbDMntWdaZFAtsALAUwSKx7K?= =?us-ascii?Q?s4mlEwiDRP389xN3TDbvnpzLWY1xxGvB2e8G8plQZPVsW5LZ00ZQCyzyoHfp?= =?us-ascii?Q?mgKxjkk7w6U0LjjV9IJJoSOMrGIaVxEDMfZ5zkpF6s5Hj28X79rjA4G4DqoQ?= =?us-ascii?Q?glfmLrb+WwosEtayg0qLLOk8eI2Sic6cndhLuoaRwiGI5qyrsk7d0/pesfG4?= =?us-ascii?Q?dmjLpukBAl4nhId6k+X8XklRMZm9gfDW3DMTpNBhBiiZmHxGvrX5dwNP7dAo?= =?us-ascii?Q?yk5hFGhxDJJDzyTb3peJb46rDjAUyGb8z3sh4qHdjcYzscLVuHXUIwwSsS/P?= =?us-ascii?Q?JiWbrtX5UmneVT7b1QFvAjAAGoqsiGjzuazkzh5mVK+3dmDgHcLpvMZIx/u6?= =?us-ascii?Q?PtnAUEzlvkQ5b4z0ttK24vKNUzUoskA62UbAHh4xaJlqVKbuoy2WNsP5il8D?= =?us-ascii?Q?T8ISlxIoP10YHlShRS98zY2P/FVfeR8bv+VJU65Gcik+4ZXEQFF3r78F1fw5?= =?us-ascii?Q?0O30II6MlUaFHKZLtbDyalhMB+AmoL/KLAaFkYnvxOHVARDH9u/TWSJbVT1Z?= =?us-ascii?Q?TiMwKEAIlV2D8OnlqAcl7WVRMqeN6Jg+MvrY0Qmyy5v+Twww0+7GAVCQKaIN?= =?us-ascii?Q?7rPHcfKUjpGbH6Fe1Dpa9JBE5BMvkEFu1SooIw8/8dUSZuLNAcnC4TZRIQGW?= =?us-ascii?Q?ozVq7ZzJsmuli9wfJc3Wk6smc9ODWPLPAXYzyZRV6vvDpegkRmIpJ71DtCq0?= =?us-ascii?Q?vEgFhlHnAwA7arKCDcI7Jlnmng2bvrrqZ3nPPdUx4alMo2lhhd+yEQRs6m/7?= =?us-ascii?Q?YqZj5cXsKsBgL2pE9WS+RrmNn1RG8dAuWZ/Rjj1sxXZoIksGqETi91qiiFBI?= =?us-ascii?Q?a7l0Etim60tYX8LXeNFjEkES?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3933d71d-b2c1-4138-4d6d-08d8fa97d6b1 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:52.3686 (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: tucu7xAbywD/bZC3RYKTFBIELri+/KcSYbkfshTmGm/NZ1GJUoEWEwrERDruiImFDOvv6AK3RK3kP8YTePsHcfo76b7wbm32Ts+wYSek8UY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5127 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.5.100; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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) Content-Type: text/plain; charset="utf-8" nbd_co_establish_connection_cancel() actually needs only pointer to NBDConnectThread. So, make it clean. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index a487fd1e68..ebbb0bec6a 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -124,7 +124,7 @@ static int nbd_establish_connection(BlockDriverState *b= s, SocketAddress *saddr, Error **errp); static coroutine_fn QIOChannelSocket * nbd_co_establish_connection(NBDConnectThread *thr, Error **errp); -static void nbd_co_establish_connection_cancel(BlockDriverState *bs); +static void nbd_co_establish_connection_cancel(NBDConnectThread *thr); static int nbd_client_handshake(BlockDriverState *bs, Error **errp); static void nbd_yank(void *opaque); =20 @@ -271,7 +271,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) qemu_co_sleep_wake(s->connection_co_sleep_ns_state); } =20 - nbd_co_establish_connection_cancel(bs); + nbd_co_establish_connection_cancel(s->connect_thread); =20 reconnect_delay_timer_del(s); =20 @@ -311,7 +311,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) if (s->connection_co_sleep_ns_state) { qemu_co_sleep_wake(s->connection_co_sleep_ns_state); } - nbd_co_establish_connection_cancel(bs); + nbd_co_establish_connection_cancel(s->connect_thread); } if (qemu_in_coroutine()) { s->teardown_co =3D qemu_coroutine_self(); @@ -461,14 +461,12 @@ nbd_co_establish_connection(NBDConnectThread *thr, Er= ror **errp) =20 /* * nbd_co_establish_connection_cancel - * Cancel nbd_co_establish_connection asynchronously: it will finish soon,= to - * allow drained section to begin. + * Cancel nbd_co_establish_connection() asynchronously. Note, that it does= n't + * stop the thread itself neither close the socket. It just safely wakes + * nbd_co_establish_connection() sleeping in the yield(). */ -static void nbd_co_establish_connection_cancel(BlockDriverState *bs) +static void nbd_co_establish_connection_cancel(NBDConnectThread *thr) { - BDRVNBDState *s =3D bs->opaque; - NBDConnectThread *thr =3D s->connect_thread; - qemu_mutex_lock(&thr->mutex); =20 if (thr->wait_co) { --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891055; cv=pass; d=zohomail.com; s=zohoarc; b=IHW1mAkzc+QigF//0md1uMKQGjovXIHsGxRjTBsQ0dPAlvIroiPtFio3mw7DxInHEX5tdAHHMMBgxW1Y5SdIOV7s4UsjKrGtgvUJ6ydHgqIptnjWXT4qrweYge9Gc7XxXg6/rsFS057xTNLPm//ZQ2INdu45yR0Sk0Y2wzGv9Ig= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891055; 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=+5jiqsB/GccwtYQCqrqNoYIaehUhulhHRfym3T32OhA=; b=TtFEGCQWN0PN1QdoG9MR74HsKpqQ7rvGTXBtx6KWuinlUKweUK59qJH2HLitNNEUE4W9w2rCOuuB7uVJPhsBo8qSPveOPBwo7bNF3bjHw0HmpmGKIQrIjANkXn3qA7Bbizu97J6TvRi0TCe+2yGHpzrvvMlBleUk1p/A0g4ylZY= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891054568135.13716665304537; Thu, 8 Apr 2021 07:10:54 -0700 (PDT) Received: from localhost ([::1]:42690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVMy-0006uv-P2 for importer@patchew.org; Thu, 08 Apr 2021 10:10:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVLf-0005F5-4C; Thu, 08 Apr 2021 10:09:31 -0400 Received: from mail-eopbgr140103.outbound.protection.outlook.com ([40.107.14.103]:51570 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVLV-0001b3-Kj; Thu, 08 Apr 2021 10:09:30 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1713.eurprd08.prod.outlook.com (2603:10a6:203:34::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17; Thu, 8 Apr 2021 14:08:53 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:53 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P/y6OvRquF5cRTIqFkK8vlNz+MbFIr8Yu1BUCTuL+AWYpv16k9NsCe7dkTM61IgxJQ7TLNq/owT1tJoaup6J2Oa6COuxAy7w1pUmYJYc7EPW5H500dCGfYt6fvEb5s24ZBi7JjBBN01CUn1c1rSNpBB1K0sPOnmzwXKS7w/GKsKs79nrJMw6MTyjjE8C/R6LcL32sj4LsdOFm7yiDkm3ydbaKIpQSc1XCyJebKIlaojzdsLuX+xAYkQ9oC66vEUzv0KjW8m2QiqdQx7nQ68f4dSJZGwa7K7ZsfuRYaRAu1ttIE/KfuX8sJKRxnSHSPsbNrbNA2inpF6xHA6N0d+eEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+5jiqsB/GccwtYQCqrqNoYIaehUhulhHRfym3T32OhA=; b=K0gRDtQiqnd7iqFPqttuMI+zMehguL8FEkGvh/uvblsvksStYkLjTvx5vNpKteDJp6DpsQdlxTDMLKcUiNoaY1O8K2SS2ojBo/sMjQh9eBTvTA2AzG7OE7EVNhWmINUcEX7oqOb87KpXK3dbXPZssAVSReoGrKfagUMCGKTlMvvYT+QhhnMuuZ07U4IfEYF9G+RUPUfDvL0A/T1bUj6pLihbqmFQyBIcCAk/0t7sDSc/y87BpKuo+DX8ylOt71If5OPcD6G5OHGMvjfMKywIwVB6uPBEhDTrMFm9sNfq1wJU1O9JBghIz8/QJIf8Sw4F5Abxlk8lBVprAWprHqEHEQ== 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=+5jiqsB/GccwtYQCqrqNoYIaehUhulhHRfym3T32OhA=; b=tdIopiAkAhvhpkc/dYjGzfXO6ZW86F3zSjzSXnz/P+d/qRF436EWW9F1qP7LaLzO8eriRB0hyo9GRevL7jFGKuPwyOPD7EfbM61zulYGQHEdIhwsE4CGafGkUOjNOg1Oy+/fMxJLuNDU/ORh1uD4OLwiirGJr9QYOrl9UvgVlP4= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 08/10] block/nbd: rename NBDConnectThread to NBDClientConnection Date: Thu, 8 Apr 2021 17:08:25 +0300 Message-Id: <20210408140827.332915-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: b870ffae-40b6-4ade-6c2a-08d8fa97d788 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1713: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:173; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BHU0R320RMNRwcII9DSlPq/USbpNNz/iUmHZXy2C9TOSZk7kCWq7h2a7vm4mINKVr9sYvPwRVUPI7TrF0ajRhGtyOOUtMvx8C/WQYYFp8tQBoFG3pF7mewjcilRoYQbF96Lar7JQJIFoVzyJyKafBU6jkvC+BJsn1BDMjW5h6XPV8AAW3XZgbZz93vhW6QDeEebG626XnPNQSmjfuL3rcwCHDRYAvJR0c2/J/jiZj5Yb4BK9EpilB14Om+bkK1OOuN88YwNueNjfxobFlindocig3+xlaef7oUYdmG2gZXDDp1qCiLyoL8GHsCmqhA9JNX9NSbfC+RXbwgm6ojdYkxOyBxMWb/nRwUp2Vo9FHK+xiuWZd8udLsCR1oduHjlGcWf/APBu7JuR66tP3YY+3j3zp4NrnFsPwNkl41dlcKjJxC9GYJV59zByo8ha7gcyyW1ckze51GRnG2a01LT9xyKvaRb9idK30zRLGZe9PT8l1RVxiTF+Io5xYXmvQi3bOfVyklx630i7bhn0iGJAzZP079g7apGipapI0CyPRY4T8393LUsFwVcHQNB3GswMthwtPTzCJ0bAnEB1VFvzEQmQ9cJfnCG41t+/LJ/jwMLOeWSPZGuVMk6qwFeeb1pKHClR/YUhP2+DyQQwJ/tMUF4F6fRTgWVtSOaLwZuBBloPEwFzYwFTdubfobtVQntMyKJKp5W8/2cMlrDU+VV7Sg== 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)(346002)(396003)(136003)(376002)(366004)(39840400004)(6506007)(4326008)(8936002)(2906002)(83380400001)(6666004)(36756003)(66556008)(66476007)(66946007)(186003)(478600001)(6916009)(16526019)(1076003)(316002)(38350700001)(52116002)(86362001)(69590400012)(2616005)(8676002)(956004)(26005)(5660300002)(6512007)(38100700001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?fW4ix0eugdPmiwZfAyIsoXHKEpV/dY5q0bBQWb5/B/pS9a80aZJ+TD9ZGhkL?= =?us-ascii?Q?8H01wxcSJtbV2vDcPQdMu+/izt1BjPAGaaKokR0RgBJQaE90HYcPIC4XfmfZ?= =?us-ascii?Q?RTqbSdsvZ4JVfGVEypqGDPxJph9EB0zRtsNSnJ5TjPP0n3GQ79pY9IsMyVOX?= =?us-ascii?Q?r1/bLsLb854kPQjSdj5Ijy+rropmok8r0TKsrsTcVI6R8Ojg/X110LeSp+c5?= =?us-ascii?Q?umcDTqbb38r82ynwKQFbbIX5F/Xu/dSFkORGGTvn8kHKhJZSNjt6SpKAGiFa?= =?us-ascii?Q?P3Qmnk3YI4MQbC9ncSf4FfO/LernpPnczt9pBp+v0xyE4WeZGp+oqgGHhwUW?= =?us-ascii?Q?bHTJqNIMsa2NYQDjFKQGP8o/Bb8PASBgo1yu5FjpunHzjaYUBDB0o5SjpmSm?= =?us-ascii?Q?H9bNyIAL5VY1WOa+xdvSUNaitB6a5szH1+QlVEjZTy1bneR8f3cz/sjpppQV?= =?us-ascii?Q?YieddnQpqg6zbwLlpPWziv21PLPoB5yrTvZMzLEx+DmnOM30LDP8PQ8rJ3NE?= =?us-ascii?Q?QyVeW5+Gtp7TRxKe9uWJAohL7nTX+/5/5thwPCKsgaoZJE39rbZ7RajHJiyg?= =?us-ascii?Q?LOOM2lvf6OK1GOsfar00fQ4gszUg4rY22ii6MMd+pbiIj7vpPIZQuGStaY4H?= =?us-ascii?Q?gUley9426aRfRsSXfHQnuCYbbDOF8137gV70Acz6MYtX4ME+N6Pe1vKZox+I?= =?us-ascii?Q?XT2txo9HYxQ8FZwWT7DSjogw4YK37y9ShU8dumhlIUS9j1WStsIm6Tf120W0?= =?us-ascii?Q?Q9JPQd6/BWcdug5Qp/dZxD2yAH05vQfXBByrbb1TE/yByWhZQSthJplS1qmd?= =?us-ascii?Q?BtI6eeeiVBKRnaDX48H/igomEZQl7AxmNLzdXWxSH/oEB925op5rHqfVL8ge?= =?us-ascii?Q?EI7Dqd+uYIdiVCikx1Mt6JltMpLQS5J4SZiwYVTBVgBC316aIUJj46bO4xE/?= =?us-ascii?Q?FjcA4YEQspERcnerHGhveayENOrGQZclSEpHL16K+4aSxvkfrcRUjbjgQ+eP?= =?us-ascii?Q?ilPD4WzVKD4z5vv0QbMd8mk59ayriv65z/cDDTNF5OITN4hEYcYYBLWB753m?= =?us-ascii?Q?SAF07dyps+Sci7piTESuz1lfnid++PSrmUjhEJsGty2zifZTtc7fx8aYcSz4?= =?us-ascii?Q?RoYc4Bx1hDbcdFUDJcKYWXKFXygXN+iyQPC/l8uWbQwUWN0MvhDmS5QHyw9z?= =?us-ascii?Q?IPlesteg8h9i5tD1Kv6WPehFLRqnOXDPrdznIij6NG/h40Xr37j+tE7lh8FP?= =?us-ascii?Q?f49awH30G2rzGE9SuoVXAPg0CexcQ2vE+WAyxQK+5gJEbE8xL9cWaG08qpCg?= =?us-ascii?Q?pNZEKE/MQXahy6o6l5XpzOnd?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b870ffae-40b6-4ade-6c2a-08d8fa97d788 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:53.8501 (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: ck6fkbS006Hl0kWKmmccygkDmcgNLUt+ttyb8Yjv18i0MkQbaFqWy+LPBr1Jvrz3AL+y1onpMduAnZciVxDNDRsT2amqI+wKu8RZeY+icF0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1713 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.14.103; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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) Content-Type: text/plain; charset="utf-8" We are going to move connection code to own file and want clear names and APIs. The structure is shared between user and (possibly) several runs of connect-thread. So it's wrong to call it "thread". Let's rename to something more generic. Appropriately rename connect_thread and thr variables to conn. connect_thread_state_unref() function gets new appropriate name too Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 127 ++++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index ebbb0bec6a..ab3ef13366 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -66,7 +66,7 @@ typedef enum NBDClientState { NBD_CLIENT_QUIT } NBDClientState; =20 -typedef struct NBDConnectThread { +typedef struct NBDClientConnection { /* Initialization constants */ SocketAddress *saddr; /* address to connect to */ =20 @@ -83,7 +83,7 @@ typedef struct NBDConnectThread { /* All further fields are protected by mutex */ bool running; /* thread is running now */ Coroutine *wait_co; /* nbd_co_establish_connection() wait in yield() */ -} NBDConnectThread; +} NBDClientConnection; =20 typedef struct BDRVNBDState { QIOChannelSocket *sioc; /* The master data channel */ @@ -116,22 +116,22 @@ typedef struct BDRVNBDState { char *x_dirty_bitmap; bool alloc_depth; =20 - NBDConnectThread *connect_thread; + NBDClientConnection *conn; } BDRVNBDState; =20 -static void connect_thread_state_unref(NBDConnectThread *thr); +static void nbd_client_connection_unref(NBDClientConnection *conn); static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *s= addr, Error **errp); static coroutine_fn QIOChannelSocket * -nbd_co_establish_connection(NBDConnectThread *thr, Error **errp); -static void nbd_co_establish_connection_cancel(NBDConnectThread *thr); +nbd_co_establish_connection(NBDClientConnection *conn, Error **errp); +static void nbd_co_establish_connection_cancel(NBDClientConnection *conn); static int nbd_client_handshake(BlockDriverState *bs, Error **errp); static void nbd_yank(void *opaque); =20 static void nbd_clear_bdrvstate(BDRVNBDState *s) { - connect_thread_state_unref(s->connect_thread); - s->connect_thread =3D NULL; + nbd_client_connection_unref(s->conn); + s->conn =3D NULL; object_unref(OBJECT(s->tlscreds)); qapi_free_SocketAddress(s->saddr); s->saddr =3D NULL; @@ -271,7 +271,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) qemu_co_sleep_wake(s->connection_co_sleep_ns_state); } =20 - nbd_co_establish_connection_cancel(s->connect_thread); + nbd_co_establish_connection_cancel(s->conn); =20 reconnect_delay_timer_del(s); =20 @@ -311,7 +311,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) if (s->connection_co_sleep_ns_state) { qemu_co_sleep_wake(s->connection_co_sleep_ns_state); } - nbd_co_establish_connection_cancel(s->connect_thread); + nbd_co_establish_connection_cancel(s->conn); } if (qemu_in_coroutine()) { s->teardown_co =3D qemu_coroutine_self(); @@ -338,100 +338,100 @@ static bool nbd_client_connecting_wait(BDRVNBDState= *s) =20 static void nbd_init_connect_thread(BDRVNBDState *s) { - s->connect_thread =3D g_new(NBDConnectThread, 1); + s->conn =3D g_new(NBDClientConnection, 1); =20 - *s->connect_thread =3D (NBDConnectThread) { + *s->conn =3D (NBDClientConnection) { .saddr =3D QAPI_CLONE(SocketAddress, s->saddr), .refcnt =3D 1, }; =20 - qemu_mutex_init(&s->connect_thread->mutex); + qemu_mutex_init(&s->conn->mutex); } =20 -static void connect_thread_state_unref(NBDConnectThread *thr) +static void nbd_client_connection_unref(NBDClientConnection *conn) { - if (qatomic_dec_fetch(&thr->refcnt) =3D=3D 0) { - if (thr->sioc) { - qio_channel_close(QIO_CHANNEL(thr->sioc), NULL); + if (qatomic_dec_fetch(&conn->refcnt) =3D=3D 0) { + if (conn->sioc) { + qio_channel_close(QIO_CHANNEL(conn->sioc), NULL); } - error_free(thr->err); - qapi_free_SocketAddress(thr->saddr); - g_free(thr); + error_free(conn->err); + qapi_free_SocketAddress(conn->saddr); + g_free(conn); } } =20 static void *connect_thread_func(void *opaque) { - NBDConnectThread *thr =3D opaque; + NBDClientConnection *conn =3D opaque; int ret; =20 - thr->sioc =3D qio_channel_socket_new(); + conn->sioc =3D qio_channel_socket_new(); =20 - error_free(thr->err); - thr->err =3D NULL; - ret =3D qio_channel_socket_connect_sync(thr->sioc, thr->saddr, &thr->e= rr); + error_free(conn->err); + conn->err =3D NULL; + ret =3D qio_channel_socket_connect_sync(conn->sioc, conn->saddr, &conn= ->err); if (ret < 0) { - object_unref(OBJECT(thr->sioc)); - thr->sioc =3D NULL; + object_unref(OBJECT(conn->sioc)); + conn->sioc =3D NULL; } =20 - qemu_mutex_lock(&thr->mutex); + qemu_mutex_lock(&conn->mutex); =20 - assert(thr->running); - thr->running =3D false; - if (thr->wait_co) { - aio_co_wake(thr->wait_co); - thr->wait_co =3D NULL; + assert(conn->running); + conn->running =3D false; + if (conn->wait_co) { + aio_co_wake(conn->wait_co); + conn->wait_co =3D NULL; } =20 - qemu_mutex_unlock(&thr->mutex); + qemu_mutex_unlock(&conn->mutex); =20 - connect_thread_state_unref(thr); + nbd_client_connection_unref(conn); =20 return NULL; } =20 /* - * Get a new connection in context of @thr: + * Get a new connection in context of @conn: * if thread is running, wait for completion * if thread is already succeeded in background, and user didn't get the * result, just return it now * otherwise if thread is not running, start a thread and wait for compl= etion */ static coroutine_fn QIOChannelSocket * -nbd_co_establish_connection(NBDConnectThread *thr, Error **errp) +nbd_co_establish_connection(NBDClientConnection *conn, Error **errp) { QIOChannelSocket *sioc =3D NULL; QemuThread thread; =20 - qemu_mutex_lock(&thr->mutex); + qemu_mutex_lock(&conn->mutex); =20 /* * Don't call nbd_co_establish_connection() in several coroutines in * parallel. Only one call at once is supported. */ - assert(!thr->wait_co); + assert(!conn->wait_co); =20 - if (!thr->running) { - if (thr->sioc) { + if (!conn->running) { + if (conn->sioc) { /* Previous attempt finally succeeded in background */ - sioc =3D g_steal_pointer(&thr->sioc); - qemu_mutex_unlock(&thr->mutex); + sioc =3D g_steal_pointer(&conn->sioc); + qemu_mutex_unlock(&conn->mutex); =20 return sioc; } =20 - thr->running =3D true; - error_free(thr->err); - thr->err =3D NULL; - qatomic_inc(&thr->refcnt); /* for thread */ + conn->running =3D true; + error_free(conn->err); + conn->err =3D NULL; + qatomic_inc(&conn->refcnt); /* for thread */ qemu_thread_create(&thread, "nbd-connect", - connect_thread_func, thr, QEMU_THREAD_DETACHED); + connect_thread_func, conn, QEMU_THREAD_DETACHED= ); } =20 - thr->wait_co =3D qemu_coroutine_self(); + conn->wait_co =3D qemu_coroutine_self(); =20 - qemu_mutex_unlock(&thr->mutex); + qemu_mutex_unlock(&conn->mutex); =20 /* * We are going to wait for connect-thread finish, but @@ -439,9 +439,9 @@ nbd_co_establish_connection(NBDConnectThread *thr, Erro= r **errp) */ qemu_coroutine_yield(); =20 - qemu_mutex_lock(&thr->mutex); + qemu_mutex_lock(&conn->mutex); =20 - if (thr->running) { + if (conn->running) { /* * Obviously, drained section wants to start. Report the attempt as * failed. Still connect thread is executing in background, and its @@ -449,12 +449,12 @@ nbd_co_establish_connection(NBDConnectThread *thr, Er= ror **errp) */ error_setg(errp, "Connection attempt cancelled by other operation"= ); } else { - error_propagate(errp, thr->err); - thr->err =3D NULL; - sioc =3D g_steal_pointer(&thr->sioc); + error_propagate(errp, conn->err); + conn->err =3D NULL; + sioc =3D g_steal_pointer(&conn->sioc); } =20 - qemu_mutex_unlock(&thr->mutex); + qemu_mutex_unlock(&conn->mutex); =20 return sioc; } @@ -465,17 +465,16 @@ nbd_co_establish_connection(NBDConnectThread *thr, Er= ror **errp) * stop the thread itself neither close the socket. It just safely wakes * nbd_co_establish_connection() sleeping in the yield(). */ -static void nbd_co_establish_connection_cancel(NBDConnectThread *thr) +static void nbd_co_establish_connection_cancel(NBDClientConnection *conn) { - qemu_mutex_lock(&thr->mutex); + qemu_mutex_lock(&conn->mutex); =20 - if (thr->wait_co) { - aio_co_wake(thr->wait_co); - thr->wait_co =3D NULL; + if (conn->wait_co) { + aio_co_wake(conn->wait_co); + conn->wait_co =3D NULL; } =20 - qemu_mutex_unlock(&thr->mutex); - + qemu_mutex_unlock(&conn->mutex); } =20 static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) @@ -521,7 +520,7 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDS= tate *s) s->ioc =3D NULL; } =20 - s->sioc =3D nbd_co_establish_connection(s->connect_thread, NULL); + s->sioc =3D nbd_co_establish_connection(s->conn, NULL); if (!s->sioc) { ret =3D -ECONNREFUSED; goto out; --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891269; cv=pass; d=zohomail.com; s=zohoarc; b=E8WQPmTmQIJRTIGORT0S+GWKkssGgXArkcIi43XaXTGANZ4JLF3XRlEbscGUHFnVSGU/RparYjU9agOuvrUzyB3XwxUOfdD8K3S3S46ZDlZhVn1GvklvGMISg0T07aLnyqh0RaSxV8+kdcgDaqDwRMjGi3y2EJWzX8IiYAW6JeM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891269; 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=zITceg6mv4BZpl6oLaSwMbgBMcBYcUlsD+K4SXhYrhk=; b=kG4Y2AZqTqsqr++WQI7NUrLTGIpg1T5aaT17v1fAGqPp0B8L0rJN/d1bIRfYWVWlMclncPijhOCkZLUf99tt9zS5a1tGttKetm3tHvkiAyXAMd6dOEaiFw0HYeyoynrA6qYYW7Zlbwn8Y9RiNLPsULJ2j2jQ/u/ne5FB3BaBb0I= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891269807730.0688240752409; Thu, 8 Apr 2021 07:14:29 -0700 (PDT) Received: from localhost ([::1]:56322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVQS-00043V-8c for importer@patchew.org; Thu, 08 Apr 2021 10:14:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVN9-0007vQ-SU; Thu, 08 Apr 2021 10:11:03 -0400 Received: from mail-eopbgr50100.outbound.protection.outlook.com ([40.107.5.100]:41486 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVMh-0001oo-9h; Thu, 08 Apr 2021 10:11:03 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB5127.eurprd08.prod.outlook.com (2603:10a6:20b:e1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Thu, 8 Apr 2021 14:08:55 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:55 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H5b8I1NnQQaxlOPBbzovQ/4Y6/0iYpI+SqlgsA+VkpThDT6UTN2RHsFjWKAiSqLGGqtIS98O9FlNOKj3WtCtdiWaU7tvpIiY/Hhe1FOulg0lQ+yedtMl4JzDhJaOKXXg9r+meo5m187uY1rtarOndmjiQRSlPv9/sUsWI4QX1HNNH9QMt9XwxSbgJMAEA7WGIZ2OhQOT2BtXOyJDvqIs+5It7X4b52YKDxyarbq9htbpcXt8dOAz/jpg3yIZWgJ0AwRvhDG6om4laZyiHS+S+2E1MkQhVaNA0dENNA7vZI0h+BDmLreK57OOAUGUeEhMMGPwU50W8YBWoi71iTr7tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zITceg6mv4BZpl6oLaSwMbgBMcBYcUlsD+K4SXhYrhk=; b=cmKzfaUGMZt5uCfmwi23CO7h2BbqHL0TpcZgac5/wTbRIXyrATEtdbZZ04TM0P9o5w9kAvFWkpzVkHCW9wpzHcJRHMV+c8bTax3xtjHkg3dl45xrvF0yDH9o7chsqlEJQogtNkFvwtDUhsdn+/2Ax78+fmXzwzQaXv0TNKhfzkWO7D4JODA52lS68LxmW3XV2xxSI3hcKy7JxvSJbV4XG1loEboZyfWraTzfUM6Ky4d1ueWfG2rZDofW0qVrD7GqKB6Bp/gqsZx3W+di7uxwWx8kK7fofBpw1yn62xzYigxQ316tmdj/ymkstjcw3xTr4CMIwN37rSbtzi6+uOl23w== 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=zITceg6mv4BZpl6oLaSwMbgBMcBYcUlsD+K4SXhYrhk=; b=eom/gHrjJo4FYO8nvlcOzMKgN1TSjiwd05apYnNALacjo7Jh3TgBclaN7NDX/1kfnj0VMt3c+XbB+gNReWT2RQMw6dFZGE2GYmD7+lTB/Y3fuhF4lmt6SApBBvwRzoyelYjOn2MELaDS28u2ka4cjcsV+6dSnD6JkFp9lcr27VU= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 09/10] block/nbd: introduce nbd_client_connection_new() Date: Thu, 8 Apr 2021 17:08:26 +0300 Message-Id: <20210408140827.332915-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 4af20297-151c-4899-26f6-08d8fa97d86c X-MS-TrafficTypeDiagnostic: AM6PR08MB5127: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:64; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f1bbi4KP6lEW470+IYVdyUXLDHE4W4rqrW538+K0BOkc38zYiWUxcuHtNM3NxTxO0LzErjlWTaW8f4mvhx6J/lswR1zAedhZ+BBrmBTs+9eB9+yb3B0yWLyH3KUCzVlGIdq7OetBmL9CM2NSZ9eUMKo36pQcfPv0XVNaKeBgW/jZ9w0ncvQ8hSfpiV4LyX3ThsC8xuYdlMMCgABWSbVM4uptyb/vBFvrFTrcJcvq86gcTDDCEieshGdAzHF3rDbP5w9bb0DSG2jqy2MzNn30q/7tJm4XrHMpEqQ3B9CmBILUlEs/cyOPXOlS1o24p0OzNxWgMnDHpRrmSbvOOvkBFXRECqIynEXkiN8XnpLQHPJJEt2aRFIuPAFFGefSj/NAI7hEHQ/H/KxIdkbjO/a4LwqtI6COVXn6eojq4ujB07jowWM/m6dUM1+EAfe2EkHrJQEVqr74DjqOh+kuA8yiLalfX0lxD0YP9cm4UBwP2uMXH++1e9o3iGmrKJZ1GA7E2xhBoXW0DZOvCUG1ywziY1wu5kAFwbL8SFp/4m65nICtnCNZLdUQQB1cTV/W4mclUpo82+ejBFWeWNbpl+Xm8QvK+CLnDS1yg6FI4CkCMqOjtRYo2Sncb3+Jk/cWsaL4U8JeFwttJWPMvtoDUJreqr1Tfp3gLQjNbEN86QDQPbcIHxVe+oy0mX/gmXANBdP8r/ae7FpST8/DAyLhZrP0eg== 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)(376002)(396003)(39840400004)(366004)(346002)(136003)(6916009)(2906002)(38350700001)(86362001)(83380400001)(8936002)(6486002)(52116002)(5660300002)(4326008)(66946007)(66556008)(66476007)(69590400012)(36756003)(38100700001)(6666004)(6506007)(1076003)(6512007)(2616005)(8676002)(186003)(16526019)(316002)(956004)(478600001)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?CwNBdN+bVvLN02lWdQN1g3s5+8VoPCffGjZEIME4WU5M/kEbFjYnSlbitltP?= =?us-ascii?Q?klD4NEp7TJVFjsNuZtuWt/jTem8EvUStaM98qDTUuxEo9u2+9XUiuxtRqVb7?= =?us-ascii?Q?eNkJOrhZk8Tg9Wa1FP7aHEfpLRGazcfVNTwr1WPlrxKbB6fuDUP9INyIoTuO?= =?us-ascii?Q?kljRnzVKNJ9UyQ7z0o1L7ISh9yFcLGCPuw5pGZ6wYJ4/bHwbE9odvdJukUTq?= =?us-ascii?Q?Q+wGVhcQXxhm8H9EqszRrnquTQLl1AshlW0EDE82MLVzD2yOn1Fa+q+PjrF4?= =?us-ascii?Q?7ik2uRMV+imVJSnGasw8asem39mSl0XWE/QNwq6k4TxsVOjYeUYh69QoobyD?= =?us-ascii?Q?0vFa8av/RaURQUQexDh9XJ8zOJ6HBpRjEWfMGpd5E/NvMaEZTAJexahIxa5p?= =?us-ascii?Q?EdGRmjlB5HKUR2k3u8W4icyFqgeCo+x7vLnH3Zr7RBxyYD4y9/ZDzhrSYvKe?= =?us-ascii?Q?OVaocH4+iA2Z8kp94DIbIY98ZMlruOjhesJbBlqVyqUA8eYW+2YGEwUPOiZE?= =?us-ascii?Q?7Qr8qM4XuN/qyWINtT13fRtb3A+/LIAkzQPNHuwcHkq26Cbas4oGFu6u5Ufk?= =?us-ascii?Q?tI69d+LQBOnYWy6vNYAZmUFVg9ZsqVsHCvUdNYZMX+PNlxmdM8j5t66mESrT?= =?us-ascii?Q?KTbwyx/R91nJ9EGbnvjr8SVNpVu+DlAEl33bW52Npsjl9vmoKr6QusKsbVyj?= =?us-ascii?Q?umFarbB3CTIF3VncDKZJOqneWN+p5szJDp7q/Y1+GDtJzp1hS7a1V2hJ1KYw?= =?us-ascii?Q?dGUBPAsJIMbS4Csz5hAHjLzM6eY4vOvkxKYbElrIWyOTW8Im+KNbfx+4oAhR?= =?us-ascii?Q?st3o6vY2TAIi9CKj1D5JxiJsj/9XjpHbx9LclJEB/P6OV1x6/XlG0uH1gLR2?= =?us-ascii?Q?oArF+zyZEOTL5T+oGxnPT+XKRekKAOQFK6169t7L+I8XLAE3N8h2vNT5DCnQ?= =?us-ascii?Q?sSpTpEJraHNP0JFXTgV/ugU6YfKBrAtD+rIkTAB7vIFi2vKeGJlLsY0vL45j?= =?us-ascii?Q?tCt/sgO3IxrVHZ+3oJCh/6cDalkjt3fNu38BVnDpIzWyqV97Ki4bv0lfjDbF?= =?us-ascii?Q?ebNPZgrFWUMyVo/OQ1dGAOyBxSq6cbLKUSmdyo7+218jZjMZ+dKUFjq9OJ+8?= =?us-ascii?Q?14BMwejoe71kAfjngOfSVEcn276a7Bq6vIREVX8qMpLxzJaDXaYK1rZXHzq/?= =?us-ascii?Q?AkXpVH/wS86PVhc4kTNhObI+uot5XTGS/bBuaX6XQ0ykl8DC0Y6D32dPu2UR?= =?us-ascii?Q?i4kdpgrYZhsdVnHowmMg2aXoY3QaqAvUOEhMe+prJ+qjVUQLwxDI8tk/xond?= =?us-ascii?Q?SkSQ4gfIiO0CYA5U10o/m++G?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4af20297-151c-4899-26f6-08d8fa97d86c X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:55.2679 (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: jHNgfJqFMx52SyWAyqV10icb9yfpt4uACCwDkBlhtaQ0FmuR2bFPs8b/4GubZnhY2yzIpU44hOeH7WzNcSjBKtn84JegyZIdFUMr5ZpLIrI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5127 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.5.100; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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) Content-Type: text/plain; charset="utf-8" This is the last step of creating bs-independing nbd connection interface. With next commit we can finally move it to separate file. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- block/nbd.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index ab3ef13366..376ab9f92d 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -336,16 +336,19 @@ static bool nbd_client_connecting_wait(BDRVNBDState *= s) return qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WA= IT; } =20 -static void nbd_init_connect_thread(BDRVNBDState *s) +static NBDClientConnection * +nbd_client_connection_new(const SocketAddress *saddr) { - s->conn =3D g_new(NBDClientConnection, 1); + NBDClientConnection *conn =3D g_new(NBDClientConnection, 1); =20 - *s->conn =3D (NBDClientConnection) { - .saddr =3D QAPI_CLONE(SocketAddress, s->saddr), + *conn =3D (NBDClientConnection) { + .saddr =3D QAPI_CLONE(SocketAddress, saddr), .refcnt =3D 1, }; =20 - qemu_mutex_init(&s->conn->mutex); + qemu_mutex_init(&conn->mutex); + + return conn; } =20 static void nbd_client_connection_unref(NBDClientConnection *conn) @@ -2211,7 +2214,7 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, /* successfully connected */ s->state =3D NBD_CLIENT_CONNECTED; =20 - nbd_init_connect_thread(s); + s->conn =3D nbd_client_connection_new(s->saddr); =20 s->connection_co =3D qemu_coroutine_create(nbd_connection_entry, s); bdrv_inc_in_flight(bs); --=20 2.29.2 From nobody Sun Feb 8 23:44:26 2026 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1617891441; cv=pass; d=zohomail.com; s=zohoarc; b=hW1HdNAoYraHBwyRc+SEjRuxHNX1N6DjXj9s0V66D3kQ5LkNSy1hURyh4UW5a2qivCk6R8EWcUhd6gvo8luC0/cq/f97rHLljcw+K4kpPbi2RXAhqNpOHEMl5V1xGRceD+g2TsVjgcVzxpk0Z6pCdn3Vn0t6SdjyFM+bCVGuNrc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617891441; 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=PyjiggCU26sJ1S5IHOVKe2y4Hm1r7fyh9a4JUoUYRS0=; b=bc2Cp2raNpqGyNDj17If3ZP5Z1rqNb78g7LHE4rA8jXgfiGlYe4vGTL4AUOOhfnZioOkn+KdqmKHcClf8TQlzwx01ZMdC+bnhYncAmzJ1yeRI51C6hTRKGtk/XWlCCK3UpZkF3OCdIsQEEm7tKqbiAHr8GRXDPvCSBKPbaN3gKI= 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=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617891441846670.8775917943649; Thu, 8 Apr 2021 07:17:21 -0700 (PDT) Received: from localhost ([::1]:34488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUVTE-0006jm-Ab for importer@patchew.org; Thu, 08 Apr 2021 10:17:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVNU-00088w-51; Thu, 08 Apr 2021 10:11:24 -0400 Received: from mail-eopbgr50100.outbound.protection.outlook.com ([40.107.5.100]:41486 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUVNA-0001oo-S5; Thu, 08 Apr 2021 10:11:23 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB5127.eurprd08.prod.outlook.com (2603:10a6:20b:e1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Thu, 8 Apr 2021 14:08:57 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4020.017; Thu, 8 Apr 2021 14:08:57 +0000 Received: from localhost.localdomain (185.215.60.206) by HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.6 via Frontend Transport; Thu, 8 Apr 2021 14:08:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ntW65Nw5wI45RBmDe5dgOlmYFOGUyTiJW0dyBIK3kRdO692vY34aJbbpy8TmSnxqbaYHtljaTuATC7UjrmgCbVD0zkuUxabC/SwAyFspeElDhfkQ3m4/AHvFFjRnt2OfmjvLh59m/5P2RTzzKuISO22CfgU5QaE+JVGP6oJyKHXtTaup7x0Q6mrvc8YtRwFF4tKWrUK6a3X3vWOhkelYLHBksPDDLdV8JHsgC1MefKme3A2g/vFQJYepIYHVDIC/q0Y6rJDarzZnD+RLZSIROUC5r8OvhPNSUSNupS2viLx1IoYUBZpxUlv0fp/WYi38pns7wOuuflz6DGHR2O44Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PyjiggCU26sJ1S5IHOVKe2y4Hm1r7fyh9a4JUoUYRS0=; b=TmgJcrIXn+1kGpiXm0y9Rj3863De4W/AdK7Pqt1KqU2OosNXUnybf4hSweiUwsnRUM4qdvz2Spf1jcGFW4Pu+Kv0MV0P+x0E8Hg8eR7zMzRV78DVWkJWJAwWT5q/vEvdxbNR6Kw7V/poLaAi81f9C2tZPhrDOTPTaNeufOywy/r2fZlm6E80zXWIjwXHHCmT1v+Uc4BhjV8kADk65bLI75RJ4IhUCDOhX3p/V3yED0IPT5qW+pDnpZDYSQvXMOET0nKPNxQ/mmcXfY1aTCXUzMyzSwN1ulQRp42+a+sRpNI0c3Coug/CvXsIt9Kcpx6A2ZkSSHqx5/sJNMQMacOAkQ== 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=PyjiggCU26sJ1S5IHOVKe2y4Hm1r7fyh9a4JUoUYRS0=; b=RbBk17kvIvPMUH6p/HCZ7R7UvPTeMBL9dFff/xzymOTUf3GIU9p8ijJprVYAKJqXgCn0UntdJ7VYo+CpRdNHPMnaZPGnoC0Y6hQJohNHtDX5uCRYDZapR2irgd+zxSsXDO3pQwP+0ykIGRS0H/aJ7NJCAtvydvW4JhgS+FsMsuo= 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, rvkagan@yandex-team.ru Subject: [PATCH v2 10/10] nbd: move connection code from block/nbd to nbd/client-connection Date: Thu, 8 Apr 2021 17:08:27 +0300 Message-Id: <20210408140827.332915-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210408140827.332915-1-vsementsov@virtuozzo.com> References: <20210408140827.332915-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [185.215.60.206] X-ClientProxiedBy: HE1PR0701CA0052.eurprd07.prod.outlook.com (2603:10a6:3:9e::20) 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: 1ba393f0-a999-47c8-1141-08d8fa97d98a X-MS-TrafficTypeDiagnostic: AM6PR08MB5127: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:313; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SJtkr2GmFdn6LGdjWjV/XbTri6QQIDvKeXXPlkjUv45V85wAURFHuyq/TxN1VTg7VFog/8w0CQ594idxZ+1UVykko4WHCUyRVL2qDvYfvApKL+3iuHEiR5kTWJd9hA+rC4r/EzmdddYQ6c5cCasaH8azPw64W2qqHOHwXKnTcy3zKlHQfhoMUm1eS+ebtlaeHVCpyAYD32l0KA4hOJtT0/Xt1+hS2T6s1kyMJBX9eWHWJoSuMkFuLi9yPu5nykYXAHOL/iyVwcoIXg2wCEO6zTO1mtFHbgYqI5DGfLvvdL5NP9YRe+H31gb3c5olUgcr2fv3zCVXUT9dClJgBb7s+FKWCmJ3WkdVIDuD8wzDeqrTHrSqDyVd1xv1McOJC/WWQkqW5mELP6TMnKAsR4FOX9x2kMlcaNvJtisUm6fsMXiYwQVrrgzOP4Kns7XFaWO6ACXtD0/9zq0TPg98L5G9phBQd/S8LTBsThhVivQaQ0dLL4nEF6RWhzFDvIbeXk9akJOCjpee7kXR+vtHopHqxKx2Y6ZKSgUbqq+kHegjM+/j2TvWzJcv5jsXJQALW7a6ArxI/eYsQs44tybdJHhPy7cgtEgewo0Z2SVH2IdiV0GX9EIOGKSvCJYOEGZVPnFumdYt3bGOAdZTro2RjcYuA63V2Uva+FgkFlN2yGFy/wjbkIsDephgrnlgdsKGmlIEd3L28dSiw461sLfCgiXZXA== 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)(376002)(396003)(39840400004)(366004)(346002)(136003)(6916009)(2906002)(38350700001)(86362001)(83380400001)(8936002)(6486002)(52116002)(5660300002)(4326008)(66946007)(66556008)(66476007)(69590400012)(36756003)(38100700001)(6666004)(6506007)(1076003)(6512007)(2616005)(8676002)(186003)(16526019)(316002)(956004)(478600001)(26005)(30864003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?451n2nhX0JTsfOcpt9/zDXov5WlMTSJM0kqP8pyheokxKrbXueyrIoCbam0J?= =?us-ascii?Q?/YDluB5uG/AcsTQtFXWZ99mbqqxXfdcjUezM2QC9AIu8z0cy0xAwFWIXVklZ?= =?us-ascii?Q?8NnLEvG+PnjflHnXBTAJPTWxJgKZ3itWCpv3nZIRbc1fjmfk+tRMH6WM0LJt?= =?us-ascii?Q?AVNqZKCeM9fXgPUlmqcruiUBkWVZ6cD1VGN4YQDdxfHS9jhDlJq8v/HkuXQ5?= =?us-ascii?Q?UmUHXTnsyXFwY1mZNcoJkImqNPLC0d8DVmBaiQZPq9+Tw8hOGIQpr6ncPFpa?= =?us-ascii?Q?xZ+uodkPLfudaaU5bH+wOqPCXD/bxt+aS5cPfMg+25KusI7N+P6IsudAQMT7?= =?us-ascii?Q?FLjcguVQ8AMGw2YXYVtpEQwZNY7xTqeetI3Cu57zYVg+czRU0fPifKu3Ye8D?= =?us-ascii?Q?AtO+kY05g2jatMY5+jaEm7zT3H81nmIjjwiIuxDtWoThjkwkVc4vXPyeDAi6?= =?us-ascii?Q?qLPmkhe2YjYTL+zEvW/EB2e+uIk1v0fs6Qclslpb/18IsVMO1ZEOuUXKQWhY?= =?us-ascii?Q?0IgJY7kq/D8Gcn7XFO3sBD3b0ZS5PKBMmXOSGZcHarBdQKlWJFSWlOiH803O?= =?us-ascii?Q?pDtXrEfzBb1GAiSfGLwybYuqd409w8LUHCR6ehvCJR9bgj599AQHYiouDmhT?= =?us-ascii?Q?FWnr9GlPzeYolIU+06MPPmbrSs6/kGMyAY0az6UEWywHrFhdP3lF4mNfiG0p?= =?us-ascii?Q?z3oOPcNI6b8uqB7jJAtnOQh8r9/te0FzW1BREFT71gd3qijFA74BjyA9CMGv?= =?us-ascii?Q?m1hzW1v1rQjepPwTY3kLCaG2oelrqy1KAtrGcKK7EsdMDFF5ubPvUcvE4bpJ?= =?us-ascii?Q?lzAHAhfrkHBbbT4WRHHsGi9uZYaRqXM+h7GayDokm8/ogWmlj0Zk5T0WCYbD?= =?us-ascii?Q?TLScb25i8GZFNExdhMQYESafCqHV4rI9NViDQWO3jUk7gvoCaUYFQohblBSS?= =?us-ascii?Q?i1AJEtngRhWdwymgHlITfYzZcyosr7DTyd7yXXPSNp9pzhK+6wGi8AIs1oxl?= =?us-ascii?Q?3FgNIP02/UXL5wBfuVbaY8M8H1Lsd9FSj0pMWSYPb7cgTfq+9xMsXO3/3G5K?= =?us-ascii?Q?nSAPatXW4NWvfciBuO5gNt67D8xnFNGKjtZCzcJ3SnEeMbRswRxFuHwpfVNP?= =?us-ascii?Q?PfdE5wBguMIh6uATuUXLqNOqRbmitODgg3ulYWUyItVGb7lI7BV4gBQuKeLu?= =?us-ascii?Q?T/NwiAB++x1d+SgLEJtNuNq+q4rwNTUgbB/dCGaU+hwr5rAF7oFCGHBprAN9?= =?us-ascii?Q?znOCayUxtto0kZQd9uBT6ieP0Uo1L1o3hcqE4RiTLYCsHv/5EdE1TvQ4ILVo?= =?us-ascii?Q?0hKRtazoEsPlzgQhZqPT5516?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ba393f0-a999-47c8-1141-08d8fa97d98a X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2021 14:08:57.1437 (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: kMCAS7v8MnCRMiV4XzsT5cV2+ogP0CgXLEVSU8/8QKwVEzWqWxcY1A81Rx0WyrI72UqXT3sjWBduLMDRMX8HnQyifFDlg9UgnrulziGnPLI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5127 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.5.100; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-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) Content-Type: text/plain; charset="utf-8" We now have bs-independent connection API, which consists of four functions: nbd_client_connection_new() nbd_client_connection_unref() nbd_co_establish_connection() nbd_co_establish_connection_cancel() Move them to a separate file together with NBDClientConnection structure which becomes private to the new API. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Roman Kagan --- Hmm. I keep only Virtuozzo's copyright in a new file, as actually I've developed nbd-reconnection code. Still probably safer to save all copyrights. Let me now if you think so and I'll add them. include/block/nbd.h | 11 +++ block/nbd.c | 167 ---------------------------------- nbd/client-connection.c | 192 ++++++++++++++++++++++++++++++++++++++++ nbd/meson.build | 1 + 4 files changed, 204 insertions(+), 167 deletions(-) create mode 100644 nbd/client-connection.c diff --git a/include/block/nbd.h b/include/block/nbd.h index 5f34d23bb0..d4666b105e 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -406,4 +406,15 @@ const char *nbd_info_lookup(uint16_t info); const char *nbd_cmd_lookup(uint16_t info); const char *nbd_err_lookup(int err); =20 +/* nbd/client-connection.c */ +typedef struct NBDClientConnection NBDClientConnection; + +NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr); +void nbd_client_connection_unref(NBDClientConnection *conn); + +QIOChannelSocket *coroutine_fn +nbd_co_establish_connection(NBDClientConnection *conn, Error **errp); + +void coroutine_fn nbd_co_establish_connection_cancel(NBDClientConnection *= conn); + #endif diff --git a/block/nbd.c b/block/nbd.c index 376ab9f92d..1db86b7340 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -66,25 +66,6 @@ typedef enum NBDClientState { NBD_CLIENT_QUIT } NBDClientState; =20 -typedef struct NBDClientConnection { - /* Initialization constants */ - SocketAddress *saddr; /* address to connect to */ - - /* - * Result of last attempt. Valid in FAIL and SUCCESS states. - * If you want to steal error, don't forget to set pointer to NULL. - */ - QIOChannelSocket *sioc; - Error *err; - - int refcnt; /* atomic access */ - - QemuMutex mutex; - /* All further fields are protected by mutex */ - bool running; /* thread is running now */ - Coroutine *wait_co; /* nbd_co_establish_connection() wait in yield() */ -} NBDClientConnection; - typedef struct BDRVNBDState { QIOChannelSocket *sioc; /* The master data channel */ QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) = */ @@ -119,12 +100,8 @@ typedef struct BDRVNBDState { NBDClientConnection *conn; } BDRVNBDState; =20 -static void nbd_client_connection_unref(NBDClientConnection *conn); static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *s= addr, Error **errp); -static coroutine_fn QIOChannelSocket * -nbd_co_establish_connection(NBDClientConnection *conn, Error **errp); -static void nbd_co_establish_connection_cancel(NBDClientConnection *conn); static int nbd_client_handshake(BlockDriverState *bs, Error **errp); static void nbd_yank(void *opaque); =20 @@ -336,150 +313,6 @@ static bool nbd_client_connecting_wait(BDRVNBDState *= s) return qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WA= IT; } =20 -static NBDClientConnection * -nbd_client_connection_new(const SocketAddress *saddr) -{ - NBDClientConnection *conn =3D g_new(NBDClientConnection, 1); - - *conn =3D (NBDClientConnection) { - .saddr =3D QAPI_CLONE(SocketAddress, saddr), - .refcnt =3D 1, - }; - - qemu_mutex_init(&conn->mutex); - - return conn; -} - -static void nbd_client_connection_unref(NBDClientConnection *conn) -{ - if (qatomic_dec_fetch(&conn->refcnt) =3D=3D 0) { - if (conn->sioc) { - qio_channel_close(QIO_CHANNEL(conn->sioc), NULL); - } - error_free(conn->err); - qapi_free_SocketAddress(conn->saddr); - g_free(conn); - } -} - -static void *connect_thread_func(void *opaque) -{ - NBDClientConnection *conn =3D opaque; - int ret; - - conn->sioc =3D qio_channel_socket_new(); - - error_free(conn->err); - conn->err =3D NULL; - ret =3D qio_channel_socket_connect_sync(conn->sioc, conn->saddr, &conn= ->err); - if (ret < 0) { - object_unref(OBJECT(conn->sioc)); - conn->sioc =3D NULL; - } - - qemu_mutex_lock(&conn->mutex); - - assert(conn->running); - conn->running =3D false; - if (conn->wait_co) { - aio_co_wake(conn->wait_co); - conn->wait_co =3D NULL; - } - - qemu_mutex_unlock(&conn->mutex); - - nbd_client_connection_unref(conn); - - return NULL; -} - -/* - * Get a new connection in context of @conn: - * if thread is running, wait for completion - * if thread is already succeeded in background, and user didn't get the - * result, just return it now - * otherwise if thread is not running, start a thread and wait for compl= etion - */ -static coroutine_fn QIOChannelSocket * -nbd_co_establish_connection(NBDClientConnection *conn, Error **errp) -{ - QIOChannelSocket *sioc =3D NULL; - QemuThread thread; - - qemu_mutex_lock(&conn->mutex); - - /* - * Don't call nbd_co_establish_connection() in several coroutines in - * parallel. Only one call at once is supported. - */ - assert(!conn->wait_co); - - if (!conn->running) { - if (conn->sioc) { - /* Previous attempt finally succeeded in background */ - sioc =3D g_steal_pointer(&conn->sioc); - qemu_mutex_unlock(&conn->mutex); - - return sioc; - } - - conn->running =3D true; - error_free(conn->err); - conn->err =3D NULL; - qatomic_inc(&conn->refcnt); /* for thread */ - qemu_thread_create(&thread, "nbd-connect", - connect_thread_func, conn, QEMU_THREAD_DETACHED= ); - } - - conn->wait_co =3D qemu_coroutine_self(); - - qemu_mutex_unlock(&conn->mutex); - - /* - * We are going to wait for connect-thread finish, but - * nbd_co_establish_connection_cancel() can interrupt. - */ - qemu_coroutine_yield(); - - qemu_mutex_lock(&conn->mutex); - - if (conn->running) { - /* - * Obviously, drained section wants to start. Report the attempt as - * failed. Still connect thread is executing in background, and its - * result may be used for next connection attempt. - */ - error_setg(errp, "Connection attempt cancelled by other operation"= ); - } else { - error_propagate(errp, conn->err); - conn->err =3D NULL; - sioc =3D g_steal_pointer(&conn->sioc); - } - - qemu_mutex_unlock(&conn->mutex); - - return sioc; -} - -/* - * nbd_co_establish_connection_cancel - * Cancel nbd_co_establish_connection() asynchronously. Note, that it does= n't - * stop the thread itself neither close the socket. It just safely wakes - * nbd_co_establish_connection() sleeping in the yield(). - */ -static void nbd_co_establish_connection_cancel(NBDClientConnection *conn) -{ - qemu_mutex_lock(&conn->mutex); - - if (conn->wait_co) { - aio_co_wake(conn->wait_co); - conn->wait_co =3D NULL; - } - - qemu_mutex_unlock(&conn->mutex); -} - static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) { int ret; diff --git a/nbd/client-connection.c b/nbd/client-connection.c new file mode 100644 index 0000000000..f7000f7ee6 --- /dev/null +++ b/nbd/client-connection.c @@ -0,0 +1,192 @@ +/* + * QEMU Block driver for NBD + * + * Copyright (c) 2021 Virtuozzo International GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +#include "block/nbd.h" + +#include "qapi/qapi-visit-sockets.h" +#include "qapi/clone-visitor.h" + +struct NBDClientConnection { + /* Initialization constants */ + SocketAddress *saddr; /* address to connect to */ + + /* + * Result of last attempt. Valid in FAIL and SUCCESS states. + * If you want to steal error, don't forget to set pointer to NULL. + */ + QIOChannelSocket *sioc; + Error *err; + + int refcnt; /* atomic access */ + + QemuMutex mutex; + /* All further fields are protected by mutex */ + bool running; /* thread is running now */ + Coroutine *wait_co; /* nbd_co_establish_connection() wait in yield() */ +}; + +NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr) +{ + NBDClientConnection *conn =3D g_new(NBDClientConnection, 1); + + *conn =3D (NBDClientConnection) { + .saddr =3D QAPI_CLONE(SocketAddress, saddr), + .refcnt =3D 1, + }; + + qemu_mutex_init(&conn->mutex); + + return conn; +} + +void nbd_client_connection_unref(NBDClientConnection *conn) +{ + if (qatomic_dec_fetch(&conn->refcnt) =3D=3D 0) { + if (conn->sioc) { + qio_channel_close(QIO_CHANNEL(conn->sioc), NULL); + } + error_free(conn->err); + qapi_free_SocketAddress(conn->saddr); + g_free(conn); + } +} + +static void *connect_thread_func(void *opaque) +{ + NBDClientConnection *conn =3D opaque; + int ret; + + conn->sioc =3D qio_channel_socket_new(); + + error_free(conn->err); + conn->err =3D NULL; + ret =3D qio_channel_socket_connect_sync(conn->sioc, conn->saddr, &conn= ->err); + if (ret < 0) { + object_unref(OBJECT(conn->sioc)); + conn->sioc =3D NULL; + } + + qemu_mutex_lock(&conn->mutex); + + assert(conn->running); + conn->running =3D false; + if (conn->wait_co) { + aio_co_wake(conn->wait_co); + conn->wait_co =3D NULL; + } + + qemu_mutex_unlock(&conn->mutex); + + nbd_client_connection_unref(conn); + + return NULL; +} + +/* + * Get a new connection in context of @conn: + * if thread is running, wait for completion + * if thread is already succeeded in background, and user didn't get the + * result, just return it now + * otherwise if thread is not running, start a thread and wait for compl= etion + */ +QIOChannelSocket *coroutine_fn +nbd_co_establish_connection(NBDClientConnection *conn, Error **errp) +{ + QIOChannelSocket *sioc =3D NULL; + QemuThread thread; + + qemu_mutex_lock(&conn->mutex); + + /* + * Don't call nbd_co_establish_connection() in several coroutines in + * parallel. Only one call at once is supported. + */ + assert(!conn->wait_co); + + if (!conn->running) { + if (conn->sioc) { + /* Previous attempt finally succeeded in background */ + sioc =3D g_steal_pointer(&conn->sioc); + qemu_mutex_unlock(&conn->mutex); + + return sioc; + } + + conn->running =3D true; + error_free(conn->err); + conn->err =3D NULL; + qatomic_inc(&conn->refcnt); /* for thread */ + qemu_thread_create(&thread, "nbd-connect", + connect_thread_func, conn, QEMU_THREAD_DETACHED= ); + } + + conn->wait_co =3D qemu_coroutine_self(); + + qemu_mutex_unlock(&conn->mutex); + + /* + * We are going to wait for connect-thread finish, but + * nbd_co_establish_connection_cancel() can interrupt. + */ + qemu_coroutine_yield(); + + qemu_mutex_lock(&conn->mutex); + + if (conn->running) { + /* + * Obviously, drained section wants to start. Report the attempt as + * failed. Still connect thread is executing in background, and its + * result may be used for next connection attempt. + */ + error_setg(errp, "Connection attempt cancelled by other operation"= ); + } else { + error_propagate(errp, conn->err); + conn->err =3D NULL; + sioc =3D g_steal_pointer(&conn->sioc); + } + + qemu_mutex_unlock(&conn->mutex); + + return sioc; +} + +/* + * nbd_co_establish_connection_cancel + * Cancel nbd_co_establish_connection() asynchronously. Note, that it does= n't + * stop the thread itself neither close the socket. It just safely wakes + * nbd_co_establish_connection() sleeping in the yield(). + */ +void coroutine_fn nbd_co_establish_connection_cancel(NBDClientConnection *= conn) +{ + qemu_mutex_lock(&conn->mutex); + + if (conn->wait_co) { + aio_co_wake(conn->wait_co); + conn->wait_co =3D NULL; + } + + qemu_mutex_unlock(&conn->mutex); +} diff --git a/nbd/meson.build b/nbd/meson.build index 2baaa36948..b26d70565e 100644 --- a/nbd/meson.build +++ b/nbd/meson.build @@ -1,5 +1,6 @@ block_ss.add(files( 'client.c', + 'client-connection.c', 'common.c', )) blockdev_ss.add(files( --=20 2.29.2