From nobody Thu Sep 19 01:16:42 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 1720091766341119.20122681097189; Thu, 4 Jul 2024 04:16:06 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2B2081580; Thu, 4 Jul 2024 07:16:05 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9A03A1551; Thu, 4 Jul 2024 07:13:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1C9EF1357; 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 6EF181359 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 9BBF820B7004; 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 9BBF820B7004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1720091621; bh=D9If4dKuWkJvMMSQNcCmmRDeBH/ocPZFS9/O70Jjusk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fmlTg/GIJZ0nbVsQhVeBWWx4Lx0k9iRBkIPZctV9p9oAJFMzaQCo/VlO1zraQiBqy NWhEfOlMfxg6nUngALctBLgkkymZOD3h9zCo5gryeLOtV3SiapyKDIq4lO1BZCTsie fpiC1Y21FFOQNXJwn3n55KiJKn1nTfbeVQvtKOQI= From: Purna Pavan Chandra To: devel@lists.libvirt.org Subject: [PATCH v2 5/8] ch: use monitor socket fd to send restore request Date: Thu, 4 Jul 2024 11:13:35 +0000 Message-Id: <20240704111338.13133-6-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: 2HSKBP7PXDGLJXZZ5ICVPPX4SFH76LP6 X-Message-ID-Hash: 2HSKBP7PXDGLJXZZ5ICVPPX4SFH76LP6 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: 1720091767065100001 Content-Type: text/plain; charset="utf-8" Instead of curl, use low-level socket connections to make restore api request to CH. This will enable passing new net FDs to CH while restoring domains with network configuration. Signed-off-by: Purna Pavan Chandra --- src/ch/ch_monitor.c | 13 +++++++++++-- src/ch/ch_monitor.h | 2 +- src/ch/ch_process.c | 40 ++++++++++++++++++++++++++++++++++------ 3 files changed, 46 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 851ab7545c..0ac0a5c9a2 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -912,6 +912,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 */ @@ -926,12 +932,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 */ @@ -942,6 +942,34 @@ 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; + } + + /* Restore is a syncronous operationin CH. so, pass false to wait unti= l there's a reponse */ + if (chSocketProcessHttpResponse(mon_sockfd, false) < 0) + return -1; + if (virCHProcessSetup(vm) < 0) return -1; =20 --=20 2.34.1