From nobody Thu Sep 19 01:01:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1720091740603195.44004856341587; Thu, 4 Jul 2024 04:15:40 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8900A1550; Thu, 4 Jul 2024 07:15:39 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CF1CE1589; Thu, 4 Jul 2024 07:13:52 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1668D1419; Thu, 4 Jul 2024 07:13:43 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 95C8C1357 for ; Thu, 4 Jul 2024 07:13:42 -0400 (EDT) Received: from paekkaladevi-dev-u22.gi4irqh5pfqublruu4yyku2wof.phxx.internal.cloudapp.net (unknown [20.125.125.171]) by linux.microsoft.com (Postfix) with ESMTPSA id 3278120B700B; Thu, 4 Jul 2024 04:13:41 -0700 (PDT) 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=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3278120B700B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1720091621; bh=r6OTMSOAPtIv9IVMxZs25C3naBEqIW7R/Ob7yVJOTAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UAefyO/KE1azn1aN21OwOnKDWLvpLeibaLGqcgyJi4PuoBD84LcjyzDYw1syg6ZBu PfKrDNq3n+IGMub5LoD+HHbUjpil6JbAd9ivKlkUMY61NBl1mrJM+gSVQb604KgYRm WZzZyvx4G/vhwk9sxyEUF18KPR2gmBSqxruxHx90= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH v2 4/8] ch: support poll with -1 in chSocketRecv Date: Thu, 4 Jul 2024 11:13:34 +0000 Message-Id: <20240704111338.13133-5-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240704111338.13133-1-paekkaladevi@linux.microsoft.com> References: <20240704111338.13133-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: G4CQ75XNZKZP5OW3S7A4K2A4JRCGQ5PV X-Message-ID-Hash: G4CQ75XNZKZP5OW3S7A4K2A4JRCGQ5PV X-MailFrom: paekkaladevi@linux.microsoft.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: paekkaladevi@microsoft.com, prapal@linux.microsoft.com, liuwe@microsoft.com, kumarpraveen@linux.microsoft.com, Purna Pavan Chandra 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: X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZM-MESSAGEID: 1720091741162100001 Content-Type: text/plain; charset="utf-8" chSocketRecv fn can be used by operations such as restore, which cannot have a specific poll timeout. The runtime of these operations at server side (vmm) cannot be determined or capped as it depends on the guest configuration. Hence, add a new parameter 'use_timeout' which when set will pass -1 as timeout to poll, otherwise the default PKT_TIMEOUT_MS is used. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_process.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 1943c4381b..851ab7545c 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -534,11 +534,12 @@ chMonitorSocketConnect(virCHMonitor *mon) #define PKT_TIMEOUT_MS 500 /* ms */ =20 static char * -chSocketRecv(int sock) +chSocketRecv(int sock, bool use_timeout) { struct pollfd pfds[1]; char *buf =3D NULL; size_t buf_len =3D 1024; + int timeout =3D PKT_TIMEOUT_MS; int ret; =20 buf =3D g_new0(char, buf_len); @@ -546,8 +547,11 @@ chSocketRecv(int sock) pfds[0].fd =3D sock; pfds[0].events =3D POLLIN; =20 + if (!use_timeout) + timeout =3D -1; + do { - ret =3D poll(pfds, G_N_ELEMENTS(pfds), PKT_TIMEOUT_MS); + ret =3D poll(pfds, G_N_ELEMENTS(pfds), timeout); } while (ret < 0 && errno =3D=3D EINTR); =20 if (ret <=3D 0) { @@ -574,12 +578,12 @@ chSocketRecv(int sock) #undef PKT_TIMEOUT_MS =20 static int -chSocketProcessHttpResponse(int sock) +chSocketProcessHttpResponse(int sock, bool use_poll_timeout) { g_autofree char *response =3D NULL; int http_res; =20 - response =3D chSocketRecv(sock); + response =3D chSocketRecv(sock, use_poll_timeout); if (response =3D=3D NULL) { return -1; } @@ -705,7 +709,7 @@ chProcessAddNetworkDevices(virCHDriver *driver, return -1; } =20 - if (chSocketProcessHttpResponse(mon_sockfd) < 0) + if (chSocketProcessHttpResponse(mon_sockfd, true) < 0) return -1; } =20 --=20 2.34.1