From nobody Mon Sep 16 19:18:04 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 1719559637531137.80712623128022; Fri, 28 Jun 2024 00:27:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2E9DF1276; Fri, 28 Jun 2024 03:27:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 76EA7E91; Fri, 28 Jun 2024 03:26:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B3F471085; Fri, 28 Jun 2024 03:26:51 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 669B1E32 for ; Fri, 28 Jun 2024 03:26:50 -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 6F2B220B700B; Fri, 28 Jun 2024 00:26:48 -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.6 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 6F2B220B700B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559608; bh=msig3PTlbFGBKbPDIBOXhKy2E03gVwfQCzSx0V43hMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RS7XAXBJiYSslC3iTl4fpyAe8VKk5ttXZHndGPwQ0rWypEa5zHLKTmLwa7M6C9T8h DSFRuktn+AoCcV9O7qJTO2rmLpU4Kfedecl4VflRxJi6Vdsk+K2WrjhQDa02ameGU0 YM6rs+iRer5WIGQcikgO50hM4NrlucP6KpPlIHf8= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 1/8] ch: report response message instead of just code Date: Fri, 28 Jun 2024 07:26:40 +0000 Message-Id: <20240628072647.2674-2-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GE2IYMY4JUTPFN66B6J6DAD6FM56AQKN X-Message-ID-Hash: GE2IYMY4JUTPFN66B6J6DAD6FM56AQKN 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: 1719559637908100001 Content-Type: text/plain; charset="utf-8" The response message from CH for vm.add-net api will be more helpful in debugging. Hence, log the message instead of just response code. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 48190a1273..6f99fec900 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -665,7 +665,7 @@ chProcessAddNetworkDevices(virCHDriver *driver, } if (http_res !=3D 204 && http_res !=3D 200) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected response from CH: %1$d"), http_re= s); + _("Unexpected response from CH: %1$s"), respons= e); return -1; } } --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559709968633.2105793037018; Fri, 28 Jun 2024 00:28:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E391D1215; Fri, 28 Jun 2024 03:28:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A164E11EB; Fri, 28 Jun 2024 03:27:02 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 36E61C6B; Fri, 28 Jun 2024 03:26:52 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id DB2D8E77 for ; Fri, 28 Jun 2024 03:26:50 -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 D856120B700D; Fri, 28 Jun 2024 00:26:48 -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.6 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 D856120B700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559609; bh=GHrqZeLK8HWsw9lPwfIBYKcDpCDk2eBRW4YzKHRRut8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOWupOSjMNCXWfhpdnO3W0fWzyC0ZwwxQGhjGeWSBdWdexdniRjvIkS1rJt+89Ori EBqhWoP18SAaWNubq5xRgqS+b2vTxKEco20mdNgpFjVV3T4scItO7Ue+zm23+n6P9s LofR2/jCVDAKSNHeQuw5wvjKd1dIAZYgqUByliZo= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 2/8] ch: Pass net ids explicitly during vm creation Date: Fri, 28 Jun 2024 07:26:41 +0000 Message-Id: <20240628072647.2674-3-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OM46CTYIEDT5JKQOWJYQWPNMYPXXX6MA X-Message-ID-Hash: OM46CTYIEDT5JKQOWJYQWPNMYPXXX6MA 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: 1719559710183100001 Content-Type: text/plain; charset="utf-8" Pass "net_" as net id to CH. This is to have better control over the network configs. This id can be further used in performing operations like restore etc. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_monitor.c | 7 ++++++- src/ch/ch_monitor.h | 4 +++- src/ch/ch_process.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 7b6b77de1c..6af5b29d82 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -278,18 +278,23 @@ virCHMonitorBuildDisksJson(virJSONValue *content, vir= DomainDef *vmdef) /** * virCHMonitorBuildNetJson: * @net: pointer to a guest network definition + * @netindex: index of the guest network definition * @jsonstr: returned network json * * Build net json to send to CH * Returns 0 on success or -1 in case of error */ int -virCHMonitorBuildNetJson(virDomainNetDef *net, char **jsonstr) +virCHMonitorBuildNetJson(virDomainNetDef *net, int netindex, char **jsonst= r) { char macaddr[VIR_MAC_STRING_BUFLEN]; g_autoptr(virJSONValue) net_json =3D virJSONValueNewObject(); virDomainNetType actualType =3D virDomainNetGetActualType(net); =20 + g_autofree char *id =3D g_strdup_printf("%s_%d", CH_NET_ID_PREFIX, net= index); + if (virJSONValueObjectAppendString(net_json, "id", id) < 0) + return -1; + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_ETHERNET && net->guestIP.nips =3D=3D 1) { const virNetDevIPAddr *ip; diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index ea6b2a771b..bac80b5fcb 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -42,6 +42,8 @@ =20 #define VIRCH_THREAD_NAME_LEN 16 =20 +#define CH_NET_ID_PREFIX "net" + typedef enum { virCHThreadTypeEmulator, virCHThreadTypeVcpu, @@ -125,4 +127,4 @@ size_t virCHMonitorGetThreadInfo(virCHMonitor *mon, boo= l refresh, int virCHMonitorGetIOThreads(virCHMonitor *mon, virDomainIOThreadInfo ***iothreads); int -virCHMonitorBuildNetJson(virDomainNetDef *netdef, char **jsonstr); +virCHMonitorBuildNetJson(virDomainNetDef *netdef, int netindex, char **jso= nstr); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 6f99fec900..5907a6e81f 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -621,7 +621,7 @@ chProcessAddNetworkDevices(virCHDriver *driver, nicindexes, nnicindexes) < 0) return -1; =20 - if (virCHMonitorBuildNetJson(vmdef->nets[i], &payload) < 0) { + if (virCHMonitorBuildNetJson(vmdef->nets[i], i, &payload) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to build net json")); return -1; --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559663678140.94365431765823; Fri, 28 Jun 2024 00:27:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8F119135D; Fri, 28 Jun 2024 03:27:42 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 628E2136D; Fri, 28 Jun 2024 03:26:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DB9ED1122; Fri, 28 Jun 2024 03:26:51 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 5C322C6B for ; Fri, 28 Jun 2024 03:26:50 -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 4B95720B700E; Fri, 28 Jun 2024 00:26:49 -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.6 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 4B95720B700E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559609; bh=j6nAG8tjfZpc1Y5pXSO9EWmwgbAceIYIvX0ZsxHLxKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DN3iHmA0kRMKSaXLAT5HJIz82IAjeK33gyH4TFl+LrY8x54HcBk2B3V/ULSS/PdGN miKxj1qDpdm2Pp+De1XJsCDiFCUomCuH+3LzHcXGvfT/fV6DB5mEoU0yU5e+twx+70 L2WRKlfRTF2w5+6N/5kkJO0aviMzLFIsDDrkOiyQ= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 3/8] ch: refactor chProcessAddNetworkDevices Date: Fri, 28 Jun 2024 07:26:42 +0000 Message-Id: <20240628072647.2674-4-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DWTCQAEQ6T5XZ4E3WHM7ULPCNMA7Z7PO X-Message-ID-Hash: DWTCQAEQ6T5XZ4E3WHM7ULPCNMA7Z7PO 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: 1719559664268100001 Content-Type: text/plain; charset="utf-8" Move socket connection code to a new function. There could be other functions which might want to perform similar socket connection operation. Hence, move it to a new function. Similarly move http response processing and closing FDs to new functions. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_process.c | 121 +++++++++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 41 deletions(-) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 5907a6e81f..668a53a1c2 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -490,6 +490,47 @@ virCHProcessSetup(virDomainObj *vm) } =20 =20 +/** + * chMonitorSocketConnect: + * @mon: pointer to monitor object + * + * Connects to the monitor socket. Caller is reposible for closing the soc= ketfd + * + * Returns socket fd on success, -1 on error + */ +static int +chMonitorSocketConnect(virCHMonitor *mon) +{ + struct sockaddr_un server_addr; + int sock; + + sock =3D socket(AF_UNIX, SOCK_STREAM, 0); + if (sock < 0) { + virReportSystemError(errno, "%s", _("Failed to open a UNIX socket"= )); + return -1; + } + + memset(&server_addr, 0, sizeof(server_addr)); + server_addr.sun_family =3D AF_UNIX; + if (virStrcpyStatic(server_addr.sun_path, mon->socketpath) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("UNIX socket path '%1$s' too long"), mon->socketp= ath); + goto error; + } + + if (connect(sock, (struct sockaddr *)&server_addr, + sizeof(server_addr)) =3D=3D -1) { + virReportSystemError(errno, "%s", _("Failed to connect to mon sock= et")); + goto error; + } + + return sock; + error: + VIR_FORCE_CLOSE(sock); + return -1; +} + + #define PKT_TIMEOUT_MS 500 /* ms */ =20 static char * @@ -532,6 +573,42 @@ chSocketRecv(int sock) =20 #undef PKT_TIMEOUT_MS =20 +static int +chSocketProcessHttpResponse(int sock) +{ + g_autofree char *response =3D NULL; + int http_res; + + response =3D chSocketRecv(sock); + if (response =3D=3D NULL) { + return -1; + } + + /* Parse the HTTP response code */ + if (sscanf(response, "HTTP/1.%*d %d", &http_res) !=3D 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to parse HTTP response code")); + return -1; + } + if (http_res !=3D 204 && http_res !=3D 200) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected response from CH: %1$s"), response); + return -1; + } + + return 0; +} + +static int +chCloseFDs(int *fds, size_t nfds) +{ + size_t i; + for (i =3D 0; i < nfds; i++) { + VIR_FORCE_CLOSE(fds[i]); + } + return 0; +} + /** * chProcessAddNetworkDevices: * @driver: pointer to ch driver object @@ -554,7 +631,6 @@ chProcessAddNetworkDevices(virCHDriver *driver, { size_t i; VIR_AUTOCLOSE mon_sockfd =3D -1; - struct sockaddr_un server_addr; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) http_headers =3D VIR_BUFFER_INITIALIZER; =20 @@ -564,25 +640,8 @@ chProcessAddNetworkDevices(virCHDriver *driver, return -1; } =20 - mon_sockfd =3D socket(AF_UNIX, SOCK_STREAM, 0); - if (mon_sockfd < 0) { - virReportSystemError(errno, "%s", _("Failed to open a UNIX socket"= )); - return -1; - } - - memset(&server_addr, 0, sizeof(server_addr)); - server_addr.sun_family =3D AF_UNIX; - if (virStrcpyStatic(server_addr.sun_path, mon->socketpath) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("UNIX socket path '%1$s' too long"), mon->socketp= ath); - return -1; - } - - if (connect(mon_sockfd, (struct sockaddr *)&server_addr, - sizeof(server_addr)) =3D=3D -1) { - virReportSystemError(errno, "%s", _("Failed to connect to mon sock= et")); + if ((mon_sockfd =3D chMonitorSocketConnect(mon)) < 0) return -1; - } =20 virBufferAddLit(&http_headers, "PUT /api/v1/vm.add-net HTTP/1.1\r\n"); virBufferAddLit(&http_headers, "Host: localhost\r\n"); @@ -592,11 +651,9 @@ chProcessAddNetworkDevices(virCHDriver *driver, g_autofree int *tapfds =3D NULL; g_autofree char *payload =3D NULL; g_autofree char *response =3D NULL; - size_t j; size_t tapfd_len; size_t payload_len; int saved_errno; - int http_res; int rc; =20 if (vmdef->nets[i]->driver.virtio.queues =3D=3D 0) { @@ -640,9 +697,7 @@ chProcessAddNetworkDevices(virCHDriver *driver, saved_errno =3D errno; =20 /* Close sent tap fds in Libvirt, as they have been dup()ed in CH = */ - for (j =3D 0; j < tapfd_len; j++) { - VIR_FORCE_CLOSE(tapfds[j]); - } + chCloseFDs(tapfds, tapfd_len); =20 if (rc < 0) { virReportSystemError(saved_errno, "%s", @@ -650,24 +705,8 @@ chProcessAddNetworkDevices(virCHDriver *driver, return -1; } =20 - /* Process the response from CH */ - response =3D chSocketRecv(mon_sockfd); - if (response =3D=3D NULL) { + if (chSocketProcessHttpResponse(mon_sockfd) < 0) return -1; - } - - /* Parse the HTTP response code */ - rc =3D sscanf(response, "HTTP/1.%*d %d", &http_res); - if (rc !=3D 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Failed to parse HTTP response code")); - return -1; - } - if (http_res !=3D 204 && http_res !=3D 200) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected response from CH: %1$s"), respons= e); - return -1; - } } =20 return 0; --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559727945486.24738620575465; Fri, 28 Jun 2024 00:28:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E80AF1256; Fri, 28 Jun 2024 03:28:46 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8E52A1403; Fri, 28 Jun 2024 03:27:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 387F6E3B; Fri, 28 Jun 2024 03:26:52 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 58F8E110A for ; Fri, 28 Jun 2024 03:26:51 -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 B2A1620B7013; Fri, 28 Jun 2024 00:26:49 -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.6 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 B2A1620B7013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559610; bh=eaMM5ucKLJk0YRNon8VT65M8f2bLXULYxr+KjuDFC+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UsQg4NV0mxrDH2uCGgNJ10FlNWfycOSbJQUDyt0dVkOK2A5GU9vxGl6tqPOi+Hje3 VBeO1QA3qOGiOX7aJvB3JGdLy8yTH31WPUZzCrULjjDNEOsfmtheG40KIBctuwmsp6 NbvnwEU4Ekik+EiylOBMED41MQW5yKoH3bN1Z168= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 4/8] ch: poll with -1 in chSocketRecv Date: Fri, 28 Jun 2024 07:26:43 +0000 Message-Id: <20240628072647.2674-5-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3REJNWD3EB4GLFFSPQZNDEVJZ4ZMGN7N X-Message-ID-Hash: 3REJNWD3EB4GLFFSPQZNDEVJZ4ZMGN7N 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: 1719559728232100001 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, pass -1 as timeout to poll to make wait until there's a response from server. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_process.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 668a53a1c2..3f2a3f81e5 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -530,9 +530,6 @@ chMonitorSocketConnect(virCHMonitor *mon) return -1; } =20 - -#define PKT_TIMEOUT_MS 500 /* ms */ - static char * chSocketRecv(int sock) { @@ -547,7 +544,7 @@ chSocketRecv(int sock) pfds[0].events =3D POLLIN; =20 do { - ret =3D poll(pfds, G_N_ELEMENTS(pfds), PKT_TIMEOUT_MS); + ret =3D poll(pfds, G_N_ELEMENTS(pfds), -1); } while (ret < 0 && errno =3D=3D EINTR); =20 if (ret <=3D 0) { @@ -571,8 +568,6 @@ chSocketRecv(int sock) return g_steal_pointer(&buf); } =20 -#undef PKT_TIMEOUT_MS - static int chSocketProcessHttpResponse(int sock) { --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559751686950.8012667874502; Fri, 28 Jun 2024 00:29:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 909271223; Fri, 28 Jun 2024 03:29:10 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 503031421; Fri, 28 Jun 2024 03:27:06 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 54C13E39; Fri, 28 Jun 2024 03:26:52 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 2A4C5E91 for ; Fri, 28 Jun 2024 03:26:51 -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 257D220B7017; Fri, 28 Jun 2024 00:26:50 -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.6 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 257D220B7017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559610; bh=WU9IpAgxs4tR8lV+cFI7g6OMHqtnyQxMYM+ztG/V4Qo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXyWJfdPg4k9quF+Shee4f8k0cx9HyPdcFIwrGzDp73ElgAQ4mS6pasMmoHMDpyOn WKu661AW78qgOGm0nBC5ZT7WQYt3npYr2u631XiEXJqKGgjU0m2XFg/HSu+o/4Q6IR TkjvsasnxLsS9l+PFw9pmZokKZiC5gaE9PkvHsbY= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 5/8] ch: use monitor socket fd to send restore request Date: Fri, 28 Jun 2024 07:26:44 +0000 Message-Id: <20240628072647.2674-6-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KAAIYCI4X5RAKTQSVIGHO32RD52DEAJT X-Message-ID-Hash: KAAIYCI4X5RAKTQSVIGHO32RD52DEAJT 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: 1719559752335100001 Content-Type: text/plain; charset="utf-8" This change will later help in passing new net fds to CH during restore operation. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_monitor.c | 13 +++++++++++-- src/ch/ch_monitor.h | 2 +- src/ch/ch_process.c | 39 +++++++++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 6af5b29d82..0875887fd8 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -991,9 +991,18 @@ virCHMonitorSaveVM(virCHMonitor *mon, const char *to) } =20 int -virCHMonitorRestoreVM(virCHMonitor *mon, const char *from) +virCHMonitorBuildRestoreJson(const char *from, char **jsonstr) { - return virCHMonitorSaveRestoreVM(mon, from, false); + g_autoptr(virJSONValue) restore_json =3D virJSONValueNewObject(); + + g_autofree char *path_url =3D g_strdup_printf("file://%s", from); + if (virJSONValueObjectAppendString(restore_json, "source_url", path_ur= l)) + return -1; + + if (!(*jsonstr =3D virJSONValueToString(restore_json, false))) + return -1; + + return 0; } =20 /** diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index bac80b5fcb..375b7a49a4 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -115,7 +115,6 @@ int virCHMonitorRebootVM(virCHMonitor *mon); int virCHMonitorSuspendVM(virCHMonitor *mon); int virCHMonitorResumeVM(virCHMonitor *mon); int virCHMonitorSaveVM(virCHMonitor *mon, const char *to); -int virCHMonitorRestoreVM(virCHMonitor *mon, const char *from); int virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info); =20 void virCHMonitorCPUInfoFree(virCHMonitorCPUInfo *cpus); @@ -128,3 +127,4 @@ int virCHMonitorGetIOThreads(virCHMonitor *mon, virDomainIOThreadInfo ***iothreads); int virCHMonitorBuildNetJson(virDomainNetDef *netdef, int netindex, char **jso= nstr); +int virCHMonitorBuildRestoreJson(const char *from, char **jsonstr); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 3f2a3f81e5..b8c6080d5c 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -903,6 +903,12 @@ virCHProcessStartRestore(virCHDriver *driver, virDomai= nObj *vm, const char *from { virCHDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virCHDriverConfig) cfg =3D virCHDriverGetConfig(priv->driver= ); + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) http_headers =3D VIR_BUFFER_INITIALIZER; + g_autofree char *payload =3D NULL; + g_autofree char *response =3D NULL; + VIR_AUTOCLOSE mon_sockfd =3D -1; + size_t payload_len; =20 if (!priv->monitor) { /* Get the first monitor connection if not already */ @@ -917,12 +923,6 @@ virCHProcessStartRestore(virCHDriver *driver, virDomai= nObj *vm, const char *from vm->def->id =3D vm->pid; priv->machineName =3D virCHDomainGetMachineName(vm); =20 - if (virCHMonitorRestoreVM(priv->monitor, from) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to restore domain")); - return -1; - } - /* Pass 0, NULL as restore only works without networking support */ if (virDomainCgroupSetupCgroup("ch", vm, 0, NULL, /* nnicindexes, nicindexes */ @@ -933,6 +933,33 @@ virCHProcessStartRestore(virCHDriver *driver, virDomai= nObj *vm, const char *from priv->machineName) < 0) return -1; =20 + if (virCHMonitorBuildRestoreJson(from, &payload) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to restore domain")); + return -1; + } + + virBufferAddLit(&http_headers, "PUT /api/v1/vm.restore HTTP/1.1\r\n"); + virBufferAddLit(&http_headers, "Host: localhost\r\n"); + virBufferAddLit(&http_headers, "Content-Type: application/json\r\n"); + virBufferAsprintf(&buf, "%s", virBufferCurrentContent(&http_headers)); + virBufferAsprintf(&buf, "Content-Length: %ld\r\n\r\n", strlen(payload)= ); + virBufferAsprintf(&buf, "%s", payload); + payload_len =3D virBufferUse(&buf); + payload =3D virBufferContentAndReset(&buf); + + if ((mon_sockfd =3D chMonitorSocketConnect(priv->monitor)) < 0) + return -1; + + if (virSocketSendMsgWithFDs(mon_sockfd, payload, payload_len, NULL, 0)= < 0) { + virReportSystemError(errno, "%s", + _("Failed to send restore request to CH")); + return -1; + } + + if (chSocketProcessHttpResponse(mon_sockfd) < 0) + return -1; + if (virCHProcessSetup(vm) < 0) return -1; =20 --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559798138166.94725938188162; Fri, 28 Jun 2024 00:29:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 18B211210; Fri, 28 Jun 2024 03:29:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 34E0E13D9; Fri, 28 Jun 2024 03:27:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BE42FE32; Fri, 28 Jun 2024 03:26:52 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 49FD4AD4 for ; Fri, 28 Jun 2024 03:26:52 -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 8C4D720B700B; Fri, 28 Jun 2024 00:26:50 -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.6 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 8C4D720B700B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559610; bh=3eBV4cZ8bxhKYaIb8eH1UiShwoAgp2Fu46VInmPq0Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jtlDG6ISDfGVDaI+FjobxisBYi4zkeh4ezxVyinzBCYP0TU6VRNE9EtSJTGvgJ2lR BY89kO0/amW3DLZGmdadYw/Q0L671iF3h+km+HQhAre1eujeIgYo/9DZ4xPOoOtlU9 eWIOM53nJqLFRoZl5KMOv0Fq8MadZfA+sMG4jSOc= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 6/8] ch: refactor virCHMonitorSaveVM Date: Fri, 28 Jun 2024 07:26:45 +0000 Message-Id: <20240628072647.2674-7-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: XKK2NOPNECYYZJPDVERNWLXDTNZSQTU2 X-Message-ID-Hash: XKK2NOPNECYYZJPDVERNWLXDTNZSQTU2 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: 1719559798811100002 Content-Type: text/plain; charset="utf-8" Remove the unwanted utility function and make api calls directly from virCHMonitorSaveVM fn Signed-off-by: Purna Pavan Chandra --- src/ch/ch_monitor.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 0875887fd8..8d8be1f46e 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -925,8 +925,8 @@ virCHMonitorResumeVM(virCHMonitor *mon) return virCHMonitorPutNoContent(mon, URL_VM_RESUME); } =20 -static int -virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save) +int +virCHMonitorSaveVM(virCHMonitor *mon, const char *to) { g_autofree char *url =3D NULL; int responseCode =3D 0; @@ -936,22 +936,15 @@ virCHMonitorSaveRestoreVM(virCHMonitor *mon, const ch= ar *path, bool save) struct curl_slist *headers =3D NULL; struct curl_data data =3D {0}; =20 - if (save) - url =3D g_strdup_printf("%s/%s", URL_ROOT, URL_VM_SAVE); - else - url =3D g_strdup_printf("%s/%s", URL_ROOT, URL_VM_RESTORE); + url =3D g_strdup_printf("%s/%s", URL_ROOT, URL_VM_SAVE); =20 headers =3D curl_slist_append(headers, "Accept: application/json"); headers =3D curl_slist_append(headers, "Content-Type: application/json= "); =20 - path_url =3D g_strdup_printf("file://%s", path); - if (save) { - if (virCHMonitorBuildKeyValueStringJson(&payload, "destination_url= ", path_url) !=3D 0) - return -1; - } else { - if (virCHMonitorBuildKeyValueStringJson(&payload, "source_url", pa= th_url) !=3D 0) - return -1; - } + path_url =3D g_strdup_printf("file://%s", to); + if (virCHMonitorBuildKeyValueStringJson(&payload, "destination_url", p= ath_url) !=3D 0) + return -1; + =20 VIR_WITH_OBJECT_LOCK_GUARD(mon) { /* reset all options of a libcurl session handle at first */ @@ -984,12 +977,6 @@ virCHMonitorSaveRestoreVM(virCHMonitor *mon, const cha= r *path, bool save) return ret; } =20 -int -virCHMonitorSaveVM(virCHMonitor *mon, const char *to) -{ - return virCHMonitorSaveRestoreVM(mon, to, true); -} - int virCHMonitorBuildRestoreJson(const char *from, char **jsonstr) { --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559779926213.99180646416846; Fri, 28 Jun 2024 00:29:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DBDBD11C1; Fri, 28 Jun 2024 03:29:38 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4FE9913BF; Fri, 28 Jun 2024 03:27:09 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B19FBC6B; Fri, 28 Jun 2024 03:26:52 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id D19361085 for ; Fri, 28 Jun 2024 03:26:51 -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 0049820B7009; Fri, 28 Jun 2024 00:26:50 -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.6 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 0049820B7009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559611; bh=HcqWsgUm3KvER1O+Wp6a8yxgClBfgnyuSsqKGLHWHgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lTfsfuy4biwntnWVgUKryBtoUWTKWhl3vWukgj0CRZUBqm7aHaW7DExyJLwUXu3YC hW07cOSAdWLiLgsPcipSpTbf6ZxNRUFQfCi+Ws6oNGDI3YfUfLwuH1cfrThhdb6+s1 OlnwnXNfaNl+XNszLiXxVlyldearxnWS7/UyWP8c= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 7/8] ch: support restore with net devices Date: Fri, 28 Jun 2024 07:26:46 +0000 Message-Id: <20240628072647.2674-8-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: PRRKFZ7G2TRAYJSUDV7PLU6NWCZCENZW X-Message-ID-Hash: PRRKFZ7G2TRAYJSUDV7PLU6NWCZCENZW 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: 1719559780504100005 Content-Type: text/plain; charset="utf-8" Cloud-hypervisor now supports restoring with new net fds. Ref: https://github.com/cloud-hypervisor/cloud-hypervisor/pull/6402 So, pass new tap fds via SCM_RIGHTS to CH's restore api. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_driver.c | 9 +--- src/ch/ch_monitor.c | 21 ++++++++- src/ch/ch_monitor.h | 2 +- src/ch/ch_process.c | 104 ++++++++++++++++++++++++++++++++++++-------- 4 files changed, 107 insertions(+), 29 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index fbeac60825..7857515766 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -683,14 +683,9 @@ static int chDomainSaveAdditionalValidation(virDomainDef *vmdef) { /* - SAVE and RESTORE are functional only without any networking and - device passthrough configuration + SAVE and RESTORE are functional only without any host device + passthrough configuration */ - if (vmdef->nnets > 0) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("cannot save domain with network interfaces")); - return -1; - } if (vmdef->nhostdevs > 0) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot save domain with host devices")); diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 8d8be1f46e..3af5e7f2d1 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -978,14 +978,31 @@ virCHMonitorSaveVM(virCHMonitor *mon, const char *to) } =20 int -virCHMonitorBuildRestoreJson(const char *from, char **jsonstr) +virCHMonitorBuildRestoreJson(virDomainDef *vmdef, const char *from, char *= *jsonstr) { + size_t i; g_autoptr(virJSONValue) restore_json =3D virJSONValueNewObject(); - g_autofree char *path_url =3D g_strdup_printf("file://%s", from); + if (virJSONValueObjectAppendString(restore_json, "source_url", path_ur= l)) return -1; =20 + /* Pass the netconfig needed to restore with new netfds */ + if (vmdef->nnets) { + g_autoptr(virJSONValue) nets =3D virJSONValueNewArray(); + for (i =3D 0; i < vmdef->nnets; i++) { + g_autoptr(virJSONValue) net_json =3D virJSONValueNewObject(); + g_autofree char *id =3D g_strdup_printf("%s_%ld", CH_NET_ID_PR= EFIX, i); + if (virJSONValueObjectAppendString(net_json, "id", id) < 0) + return -1; + if (virJSONValueObjectAppendNumberInt(net_json, "num_fds", vmd= ef->nets[i]->driver.virtio.queues)) + return -1; + virJSONValueArrayAppend(nets, &net_json); + } + if (virJSONValueObjectAppend(restore_json, "net_fds", &nets)) + return -1; + } + if (!(*jsonstr =3D virJSONValueToString(restore_json, false))) return -1; =20 diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 375b7a49a4..02a6685d58 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -127,4 +127,4 @@ int virCHMonitorGetIOThreads(virCHMonitor *mon, virDomainIOThreadInfo ***iothreads); int virCHMonitorBuildNetJson(virDomainNetDef *netdef, int netindex, char **jso= nstr); -int virCHMonitorBuildRestoreJson(const char *from, char **jsonstr); +int virCHMonitorBuildRestoreJson(virDomainDef *vmdef, const char *from, ch= ar **jsonstr); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index b8c6080d5c..cb3539ebe5 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -29,6 +29,7 @@ #include "ch_process.h" #include "domain_cgroup.h" #include "domain_interface.h" +#include "viralloc.h" #include "virerror.h" #include "virfile.h" #include "virjson.h" @@ -707,6 +708,56 @@ chProcessAddNetworkDevices(virCHDriver *driver, return 0; } =20 +/** + * virCHRestoreCreateNetworkDevices: + * @driver: pointer to driver structure + * @vmdef: pointer to domain definition + * @vmtapfds: returned array of FDs of guest interfaces + * @nvmtapfds: returned number of network indexes + * @nicindexes: returned array of network indexes + * @nnicindexes: returned number of network indexes + * + * Create network devices for the domain. This function is called during + * domain restore. + * + * Returns 0 on success or -1 in case of error +*/ +static int +virCHRestoreCreateNetworkDevices(virCHDriver *driver, + virDomainDef *vmdef, + int **vmtapfds, + size_t *nvmtapfds, + int **nicindexes, + size_t *nnicindexes) +{ + size_t i, j; + size_t tapfd_len; + size_t index_vmtapfds; + for (i =3D 0; i < vmdef->nnets; i++) { + g_autofree int *tapfds =3D NULL; + tapfd_len =3D vmdef->nets[i]->driver.virtio.queues; + if (virCHDomainValidateActualNetDef(vmdef->nets[i]) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("net definition failed validation")); + return -1; + } + tapfds =3D g_new0(int, tapfd_len); + memset(tapfds, -1, (tapfd_len) * sizeof(int)); + + /* Connect Guest interfaces */ + if (virCHConnetNetworkInterfaces(driver, vmdef, vmdef->nets[i], ta= pfds, + nicindexes, nnicindexes) < 0) + return -1; + + index_vmtapfds =3D *nvmtapfds; + VIR_EXPAND_N(*vmtapfds, *nvmtapfds, tapfd_len); + for (j =3D 0; j < tapfd_len; j++) { + VIR_APPEND_ELEMENT_INPLACE(*vmtapfds, index_vmtapfds, tapfds[j= ]); + } + } + return 0; +} + /** * virCHProcessStartValidate: * @driver: pointer to driver structure @@ -908,14 +959,19 @@ virCHProcessStartRestore(virCHDriver *driver, virDoma= inObj *vm, const char *from g_autofree char *payload =3D NULL; g_autofree char *response =3D NULL; VIR_AUTOCLOSE mon_sockfd =3D -1; + g_autofree int *tapfds =3D NULL; + g_autofree int *nicindexes =3D NULL; size_t payload_len; + size_t ntapfds =3D 0; + size_t nnicindexes =3D 0; + int ret =3D -1; =20 if (!priv->monitor) { /* Get the first monitor connection if not already */ if (!(priv->monitor =3D virCHProcessConnectMonitor(driver, vm))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create connection to CH socket")); - return -1; + goto cleanup; } } =20 @@ -923,20 +979,10 @@ virCHProcessStartRestore(virCHDriver *driver, virDoma= inObj *vm, const char *from vm->def->id =3D vm->pid; priv->machineName =3D virCHDomainGetMachineName(vm); =20 - /* Pass 0, NULL as restore only works without networking support */ - if (virDomainCgroupSetupCgroup("ch", vm, - 0, NULL, /* nnicindexes, nicindexes */ - &priv->cgroup, - cfg->cgroupControllers, - 0, /*maxThreadsPerProc*/ - priv->driver->privileged, - priv->machineName) < 0) - return -1; - - if (virCHMonitorBuildRestoreJson(from, &payload) < 0) { + if (virCHMonitorBuildRestoreJson(vm->def, from, &payload) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to restore domain")); - return -1; + goto cleanup; } =20 virBufferAddLit(&http_headers, "PUT /api/v1/vm.restore HTTP/1.1\r\n"); @@ -949,21 +995,41 @@ virCHProcessStartRestore(virCHDriver *driver, virDoma= inObj *vm, const char *from payload =3D virBufferContentAndReset(&buf); =20 if ((mon_sockfd =3D chMonitorSocketConnect(priv->monitor)) < 0) - return -1; + goto cleanup; =20 - if (virSocketSendMsgWithFDs(mon_sockfd, payload, payload_len, NULL, 0)= < 0) { + if (virCHRestoreCreateNetworkDevices(driver, vm->def, &tapfds, &ntapfd= s, &nicindexes, &nnicindexes) < 0) + goto cleanup; + + if (virDomainCgroupSetupCgroup("ch", vm, + nnicindexes, nicindexes, + &priv->cgroup, + cfg->cgroupControllers, + 0, /*maxThreadsPerProc*/ + priv->driver->privileged, + priv->machineName) < 0) + goto cleanup; + + /* Bring up netdevs before restoring vm */ + if (virDomainInterfaceStartDevices(vm->def) < 0) + goto cleanup; + + if (virSocketSendMsgWithFDs(mon_sockfd, payload, payload_len, tapfds, = ntapfds) < 0) { virReportSystemError(errno, "%s", _("Failed to send restore request to CH")); - return -1; + goto cleanup; } =20 if (chSocketProcessHttpResponse(mon_sockfd) < 0) - return -1; + goto cleanup; =20 if (virCHProcessSetup(vm) < 0) - return -1; + goto cleanup; =20 virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_FROM_SNA= PSHOT); + ret =3D 0; =20 - return 0; + cleanup: + if (tapfds) + chCloseFDs(tapfds, ntapfds); + return ret; } --=20 2.34.1 From nobody Mon Sep 16 19:18:04 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 1719559820824541.2668832540526; Fri, 28 Jun 2024 00:30:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C099511C3; Fri, 28 Jun 2024 03:30:19 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 35581143F; Fri, 28 Jun 2024 03:27:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DEFD2C6B; Fri, 28 Jun 2024 03:26:52 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 7BF5DE3B for ; Fri, 28 Jun 2024 03:26:52 -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 6780C20B700D; Fri, 28 Jun 2024 00:26:51 -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.6 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 6780C20B700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1719559611; bh=P+W8aUNKnP8wi1LkTqXczBz0o5M+K1FkMkCxBnA4rTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ox2ai9rO1HDVDGkCTYzw90QEdAzcZcDxl47FhVKZ9oUxmSXaFFlRYJyhNVw1zRuuF wKr3xRvul/cV6+b/mkmi5ndyFcyq640RccQWgjDYk4fKR3XutN3Fwm24AdsKE20W4p 5t/Z9k+ULkp7FjalhbWb4PY/P5iSV85blSdm1QcM= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH 8/8] ch: kill CH process if restore fails Date: Fri, 28 Jun 2024 07:26:47 +0000 Message-Id: <20240628072647.2674-9-paekkaladevi@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> References: <20240628072647.2674-1-paekkaladevi@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TUBABW2XCSTGLYA3SJM5JJMC5VK5APEQ X-Message-ID-Hash: TUBABW2XCSTGLYA3SJM5JJMC5VK5APEQ 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: 1719559822698100001 Content-Type: text/plain; charset="utf-8" Invoke virCHProcessStop to kill CH process incase of any failures during restore operation. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index cb3539ebe5..acd542b24e 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -1031,5 +1031,7 @@ virCHProcessStartRestore(virCHDriver *driver, virDoma= inObj *vm, const char *from cleanup: if (tapfds) chCloseFDs(tapfds, ntapfds); + if (ret) + virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); return ret; } --=20 2.34.1