From nobody Wed May 15 20:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=quarantine dis=quarantine) header.from=openvz.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702901284197906.0918007722307; Mon, 18 Dec 2023 04:08:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 245C319D2; Mon, 18 Dec 2023 07:08:03 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DF1C61B8E; Mon, 18 Dec 2023 07:03:26 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4F30B1A76; Mon, 18 Dec 2023 07:01:44 -0500 (EST) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 36D161A7A for ; Mon, 18 Dec 2023 07:01:43 -0500 (EST) Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rFC1t-0020fq-1n; Mon, 18 Dec 2023 12:45:23 +0100 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: "Denis V. Lunev" To: devel@lists.libvirt.org Subject: [PATCH 1/3] rpc: create virNetClientIOWakeup helper Date: Mon, 18 Dec 2023 12:45:28 +0100 Message-Id: <20231218114530.29326-2-den@openvz.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218114530.29326-1-den@openvz.org> References: <20231218114530.29326-1-den@openvz.org> MIME-Version: 1.0 X-MailFrom: den@openvz.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: JQBFKHYT37KOL6TIWHV232FJG7PYWLJE X-Message-ID-Hash: JQBFKHYT37KOL6TIWHV232FJG7PYWLJE X-Mailman-Approved-At: Mon, 18 Dec 2023 12:02:50 -0500 CC: den@openvz.org, efim.shevrin@virtuozzo.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702901286077100001 This functionality is to be extended, simple call to g_main_loop_quit() is not enough. In order to make changes convinient, the helper is required. Signed-off-by: Denis V. Lunev --- src/rpc/virnetclient.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index d29917df27..d9a508246f 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -150,6 +150,13 @@ void virNetClientSetCloseCallback(virNetClient *client, } =20 =20 +static void +virNetClientIOWakeup(virNetClient *client) +{ + g_main_loop_quit(client->eventLoop); +} + + static void virNetClientIncomingEvent(virNetSocket *sock, int events, void *opaque); @@ -851,7 +858,7 @@ static void virNetClientCloseInternal(virNetClient *cli= ent, * queue and close the client because we set client->wantClose. */ if (client->haveTheBuck) { - g_main_loop_quit(client->eventLoop); + virNetClientIOWakeup(client); } else { virNetClientIOEventLoopPassTheBuck(client, NULL); } @@ -918,7 +925,7 @@ virNetClientIOEventTLS(int fd G_GNUC_UNUSED, virNetClient *client =3D opaque; =20 if (!virNetClientTLSHandshake(client)) - g_main_loop_quit(client->eventLoop); + virNetClientIOWakeup(client); =20 return G_SOURCE_REMOVE; } @@ -931,7 +938,7 @@ virNetClientIOEventTLSConfirm(int fd G_GNUC_UNUSED, { virNetClient *client =3D opaque; =20 - g_main_loop_quit(client->eventLoop); + virNetClientIOWakeup(client); =20 return G_SOURCE_REMOVE; } @@ -1675,7 +1682,7 @@ virNetClientIOEventFD(int fd G_GNUC_UNUSED, { struct virNetClientIOEventData *data =3D opaque; data->rev =3D ev; - g_main_loop_quit(data->client->eventLoop); + virNetClientIOWakeup(data->client); return G_SOURCE_REMOVE; } =20 @@ -2006,8 +2013,7 @@ static int virNetClientIO(virNetClient *client, =20 /* Check to see if another thread is dispatching */ if (client->haveTheBuck) { - /* Force other thread to wakeup from poll */ - g_main_loop_quit(client->eventLoop); + virNetClientIOWakeup(client); =20 /* If we are non-blocking, detach the thread and keep the call in = the * queue. */ --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=quarantine dis=quarantine) header.from=openvz.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170290121307818.88945138677832; Mon, 18 Dec 2023 04:06:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id EFB831B40; Mon, 18 Dec 2023 07:06:51 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8A17E1BFA; Mon, 18 Dec 2023 07:03:15 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 99E761A7F; Mon, 18 Dec 2023 07:01:42 -0500 (EST) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 048081A1A for ; Mon, 18 Dec 2023 07:01:42 -0500 (EST) Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rFC1t-0020fq-2y; Mon, 18 Dec 2023 12:45:23 +0100 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: "Denis V. Lunev" To: devel@lists.libvirt.org Subject: [PATCH 2/3] rpc: mark GSourceFuncs functions in vireventglibwatch.c as static Date: Mon, 18 Dec 2023 12:45:29 +0100 Message-Id: <20231218114530.29326-3-den@openvz.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218114530.29326-1-den@openvz.org> References: <20231218114530.29326-1-den@openvz.org> MIME-Version: 1.0 X-MailFrom: den@openvz.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: J3BFRRNQS3YIDJHTZ55YZMKC4HDMAFCD X-Message-ID-Hash: J3BFRRNQS3YIDJHTZ55YZMKC4HDMAFCD X-Mailman-Approved-At: Mon, 18 Dec 2023 12:02:50 -0500 CC: den@openvz.org, efim.shevrin@virtuozzo.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702901213848100001 They are not exported from the module and thus should be static. Signed-off-by: Denis V. Lunev --- src/util/vireventglibwatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/vireventglibwatch.c b/src/util/vireventglibwatch.c index b7f3a8786a..b21e505731 100644 --- a/src/util/vireventglibwatch.c +++ b/src/util/vireventglibwatch.c @@ -71,7 +71,7 @@ virEventGLibFDSourceFinalize(GSource *source G_GNUC_UNUSE= D) } =20 =20 -GSourceFuncs virEventGLibFDSourceFuncs =3D { +static GSourceFuncs virEventGLibFDSourceFuncs =3D { .prepare =3D virEventGLibFDSourcePrepare, .check =3D virEventGLibFDSourceCheck, .dispatch =3D virEventGLibFDSourceDispatch, @@ -194,7 +194,7 @@ virEventGLibSocketSourceFinalize(GSource *source) } =20 =20 -GSourceFuncs virEventGLibSocketSourceFuncs =3D { +static GSourceFuncs virEventGLibSocketSourceFuncs =3D { .prepare =3D virEventGLibSocketSourcePrepare, .check =3D virEventGLibSocketSourceCheck, .dispatch =3D virEventGLibSocketSourceDispatch, --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Wed May 15 20:10:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=quarantine dis=quarantine) header.from=openvz.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1702901139739922.617248858822; Mon, 18 Dec 2023 04:05:39 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9ECEB1C1A; Mon, 18 Dec 2023 07:05:38 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2432B1BC2; Mon, 18 Dec 2023 07:03:02 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 83F731A1A; Mon, 18 Dec 2023 07:01:41 -0500 (EST) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CDD9F1A7F for ; Mon, 18 Dec 2023 07:01:40 -0500 (EST) Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rFC1u-0020fq-1A; Mon, 18 Dec 2023 12:45:24 +0100 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 From: "Denis V. Lunev" To: devel@lists.libvirt.org Subject: [PATCH 3/3] rpc: handle notifications properly Date: Mon, 18 Dec 2023 12:45:30 +0100 Message-Id: <20231218114530.29326-4-den@openvz.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218114530.29326-1-den@openvz.org> References: <20231218114530.29326-1-den@openvz.org> MIME-Version: 1.0 X-MailFrom: den@openvz.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: AUHQOVWQZDEB3XZBKB5XR4BOSYDCG7DN X-Message-ID-Hash: AUHQOVWQZDEB3XZBKB5XR4BOSYDCG7DN X-Mailman-Approved-At: Mon, 18 Dec 2023 12:02:50 -0500 CC: den@openvz.org, efim.shevrin@virtuozzo.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1702901141608100001 RPC client implementation uses the following paradigm. The critical section is organized via virObjectLock(client)/virObjectUnlock(client) braces. Though this is potentially problematic as main thread: side thread: virObjectUnlock(client); virObjectLock(client); g_main_loop_quit(client->eventLoop); virObjectUnlock(client); g_main_loop_run(client->eventLoop); This means in particular that is the main thread is executing very long request like VM migration, the wakeup from the side thread could be stuck until the main request will be fully completed. For us this means that Nova was reported as inaccessible. Anyway, this case is easily reproducible with the simple python scripts doing slow and fast requests in parallel from two different threads. This problem has been introduced with the rework for dropping gnulib inside the following commit: commit 7d4350bcac251bab2ecf85bd19eb1181db87fd07 Author: Daniel P. Berrang=C3=A9 Date: Thu Jan 16 11:21:44 2020 +0000 rpc: convert RPC client to use GMainLoop instead of poll The cure is to revert back to old roots and use file descriptor for wakeup notifications. The code written is well suited for Linux while it is completely unclear how it will behave on Windows. Signed-off-by: Denis V. Lunev --- src/rpc/virnetclient.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index d9a508246f..7fff5a7017 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -90,6 +90,7 @@ struct _virNetClient { =20 GMainLoop *eventLoop; GMainContext *eventCtx; + int pipeLoopNotify[2]; =20 /* * List of calls currently waiting for dispatch @@ -150,10 +151,25 @@ void virNetClientSetCloseCallback(virNetClient *clien= t, } =20 =20 +static gboolean +virNetClientIOEventNotify(int fd G_GNUC_UNUSED, + GIOCondition ev G_GNUC_UNUSED, + gpointer opaque) +{ + virNetClient *client =3D opaque; + char buf[1024]; + + while (saferead(client->pipeLoopNotify[0], buf, sizeof(buf)) > 0); + g_main_loop_quit(client->eventLoop); + + return G_SOURCE_CONTINUE; +} + static void virNetClientIOWakeup(virNetClient *client) { - g_main_loop_quit(client->eventLoop); + char c =3D 0; + ignore_value(safewrite(client->pipeLoopNotify[1], &c, sizeof(c))); } =20 =20 @@ -305,10 +321,15 @@ static virNetClient *virNetClientNew(virNetSocket *so= ck, const char *hostname) { virNetClient *client =3D NULL; + int pipenotify[2] =3D {-1, -1}; + g_autoptr(GSource) G_GNUC_UNUSED source =3D NULL; =20 if (virNetClientInitialize() < 0) goto error; =20 + if (virPipeNonBlock(pipenotify) < 0) + goto error; + if (!(client =3D virObjectLockableNew(virNetClientClass))) goto error; =20 @@ -320,12 +341,25 @@ static virNetClient *virNetClientNew(virNetSocket *so= ck, =20 client->hostname =3D g_strdup(hostname); =20 + client->pipeLoopNotify[0] =3D pipenotify[0]; + client->pipeLoopNotify[1] =3D pipenotify[1]; + + /* FIXME: good for Unix, buggy for Windows */ + source =3D virEventGLibAddSocketWatch(pipenotify[0], + G_IO_IN | G_IO_ERR | G_IO_HUP, + client->eventCtx, + virNetClientIOEventNotify, + client, NULL); + PROBE(RPC_CLIENT_NEW, "client=3D%p sock=3D%p", client, client->sock); return client; =20 error: + VIR_FORCE_CLOSE(pipenotify[0]); + VIR_FORCE_CLOSE(pipenotify[1]); + virObjectUnref(client); virObjectUnref(sock); return NULL; @@ -759,6 +793,9 @@ void virNetClientDispose(void *obj) g_main_loop_unref(client->eventLoop); g_main_context_unref(client->eventCtx); =20 + VIR_FORCE_CLOSE(client->pipeLoopNotify[0]); + VIR_FORCE_CLOSE(client->pipeLoopNotify[1]); + g_free(client->hostname); =20 if (client->sock) --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org