From nobody Sun Dec 22 08:08:36 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=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1733507548576382.90267622201645; Fri, 6 Dec 2024 09:52:28 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A8E55139A; Fri, 6 Dec 2024 12:52:27 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 04F96146F; Fri, 6 Dec 2024 12:48:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B38F4140E; Fri, 6 Dec 2024 12:48:18 -0500 (EST) Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 33D40147A for ; Fri, 6 Dec 2024 12:48:02 -0500 (EST) Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-294ec8e1d8aso2216828fac.1 for ; Fri, 06 Dec 2024 09:48:02 -0800 (PST) Received: from home.. ([2603:8081:c640:1::100a]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29f566ea976sm932125fac.15.2024.12.06.09.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:48:00 -0800 (PST) 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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733507281; x=1734112081; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0GJOq4kM4UcnXAhLXl68hU71Afy29qcZO5F/JWYQvYw=; b=NkNZN/FRUMX1/t9g5dEzlxQk/ysyxjhO30F5SLNSJ+uLTFLnsVnPuHyVYgStmwlzLI fKzXjiWkzT093+O6f8rhILEv8d7mCA/IAI903DRPj7Mxb65x9GaMcZM0jPf3vbWzvLq4 mIO1ziBpYVOoRdN9211JDM3N956x39r5gQigYC3qL8Tum5gBIIurSwaUolFkRZPZXqOl KfEpHhRhYlF/0NSQwKdv6ZM1t99+FOWCKd9BSa8/HXoVBhAEhVqHlD9KdEoNzOw26Oni CYcNk/g/bEJL8iu0VFBd97Se5bQKFT9Hi2AoLfI/pnbJy8oLZldXsfOkf6dLGvfZRccy wb6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733507281; x=1734112081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0GJOq4kM4UcnXAhLXl68hU71Afy29qcZO5F/JWYQvYw=; b=fLdTv/bWCBFXKSoKGbobRifFVbnwl+C6Wk/v7cH8JQWrcJVGuHEYX5bzykAitCnBYY oex5v0fVCMRUjtmZAv3XPXAvkRpAQDYpI5hr0lEgPl56LRuHgRXPow0cyuiq3ztilbQg zI1TfJs6R7ebexUVfbjWwwwadTwNxNvnBkkrhWXXWUivFZOERoOANnHnr26HFeuFOXEQ sTsuwdaW8IlhA33R5wGGGZke5Jl/CMxEGyF3m1DhJJhqp5rIz7eSj8YYJNXdvKPjGMsA tcPcTGRL7tBLEROZBk8K59a5/TGPw8JDBzMzKVtFbQkpTCHgXZnGzFN9dV1Nug2XYPuV tZMw== X-Gm-Message-State: AOJu0YzSNvA3nmzbeXw0c+JllfGoGI3M3Xvdcp3whpPL4liwaiUjkNIU rgXDaaj1qVwHHROyYNpy0BeRmQDhZGNGtOKvh6bk0bYC0r847s5k8ePG5MmD X-Gm-Gg: ASbGncuDQwcSLgq4k0FadiE3gQ/yJvpLC155StYK0i3YXPtS8/bEOjTi8oHJeTKIQTO 51Zk3UDWaGVoFobmiBuVem83irxcCN4pggRyjaWuSVJu958NchzJ9xeQYi6ee0DvCPTZYyoWqjG /kwSWx9xvAHHHkWXlH6UMdQskd5aBkaJ6WXkGYE1XSYrCEW9Hmv21+SSRvLeQKn4fBi8WK7lEN0 S3pE6Ba8k0oc8nbbbnEE4K6T3TnMleQIQ== X-Google-Smtp-Source: AGHT+IGkRBXx6MVFr64aDNkDnKfuCijg5E3+rP33xFIZo95IjnV3GM2ArKT6R9MLuvEI9sSshUS3tQ== X-Received: by 2002:a05:6871:4182:b0:28c:8476:dd76 with SMTP id 586e51a60fabf-29f73540f3amr2566820fac.29.1733507281263; Fri, 06 Dec 2024 09:48:01 -0800 (PST) From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH 8/8] ch: Enable logging curl responses from ch Date: Fri, 6 Dec 2024 11:47:49 -0600 Message-ID: <20241206174749.33455-9-praveenkpaladugu@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241206174749.33455-1-praveenkpaladugu@gmail.com> References: <20241206174749.33455-1-praveenkpaladugu@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FME4ZLSGXK6DVQJZP5PG7NQQ3E224CWR X-Message-ID-Hash: FME4ZLSGXK6DVQJZP5PG7NQQ3E224CWR X-MailFrom: praveenkpaladugu@gmail.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: liuwe@microsoft.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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1733507549534116600 Content-Type: text/plain; charset="utf-8" Log curl responses from cloud-hypervisor process during Boot request, using domain's logContext. Signed-off-by: Praveen K Paladugu --- src/ch/ch_monitor.c | 35 ++++++++++++++++++++++++++--------- src/ch/ch_monitor.h | 3 ++- src/ch/ch_process.c | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 88df9d4a03..d3f969e01a 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -56,7 +56,8 @@ static int virCHMonitorOnceInit(void) VIR_ONCE_GLOBAL_INIT(virCHMonitor); =20 int virCHMonitorShutdownVMM(virCHMonitor *mon); -int virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint); +int virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint, + domainLogContext *logCtxt); =20 static int virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef) @@ -694,12 +695,15 @@ curl_callback(void *contents, size_t size, size_t nme= mb, void *userp) } =20 int -virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint) +virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint, + domainLogContext *logCtxt) { VIR_LOCK_GUARD lock =3D virObjectLockGuard(mon); g_autofree char *url =3D NULL; int responseCode =3D 0; int ret =3D -1; + struct curl_data data =3D {0}; + struct curl_slist *headers =3D NULL; =20 url =3D g_strdup_printf("%s/%s", URL_ROOT, endpoint); =20 @@ -712,8 +716,21 @@ virCHMonitorPutNoContent(virCHMonitor *mon, const char= *endpoint) curl_easy_setopt(mon->handle, CURLOPT_HTTPHEADER, NULL); curl_easy_setopt(mon->handle, CURLOPT_INFILESIZE, 0L); =20 + headers =3D curl_slist_append(headers, "Accept: application/json"); + curl_easy_setopt(mon->handle, CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(mon->handle, CURLOPT_WRITEFUNCTION, curl_callback); + curl_easy_setopt(mon->handle, CURLOPT_WRITEDATA, (void *)&data); + responseCode =3D virCHMonitorCurlPerform(mon->handle); =20 + if (logCtxt && data.size) { + /* Do this to append a NULL char at the end of data */ + data.content =3D g_realloc(data.content, data.size + 1); + data.content[data.size] =3D 0; + domainLogContextWrite(logCtxt, "HTTP response code from CH: %d\n",= responseCode); + domainLogContextWrite(logCtxt, "Response =3D %s\n", data.content); + } + if (responseCode =3D=3D 200 || responseCode =3D=3D 204) ret =3D 0; =20 @@ -863,7 +880,7 @@ virCHMonitorGetThreadInfo(virCHMonitor *mon, int virCHMonitorShutdownVMM(virCHMonitor *mon) { - return virCHMonitorPutNoContent(mon, URL_VMM_SHUTDOWN); + return virCHMonitorPutNoContent(mon, URL_VMM_SHUTDOWN, NULL); } =20 int @@ -903,33 +920,33 @@ virCHMonitorCreateVM(virCHDriver *driver, virCHMonito= r *mon) } =20 int -virCHMonitorBootVM(virCHMonitor *mon) +virCHMonitorBootVM(virCHMonitor *mon, domainLogContext *logCtxt) { - return virCHMonitorPutNoContent(mon, URL_VM_BOOT); + return virCHMonitorPutNoContent(mon, URL_VM_BOOT, logCtxt); } =20 int virCHMonitorShutdownVM(virCHMonitor *mon) { - return virCHMonitorPutNoContent(mon, URL_VM_SHUTDOWN); + return virCHMonitorPutNoContent(mon, URL_VM_SHUTDOWN, NULL); } =20 int virCHMonitorRebootVM(virCHMonitor *mon) { - return virCHMonitorPutNoContent(mon, URL_VM_REBOOT); + return virCHMonitorPutNoContent(mon, URL_VM_REBOOT, NULL); } =20 int virCHMonitorSuspendVM(virCHMonitor *mon) { - return virCHMonitorPutNoContent(mon, URL_VM_Suspend); + return virCHMonitorPutNoContent(mon, URL_VM_Suspend, NULL); } =20 int virCHMonitorResumeVM(virCHMonitor *mon) { - return virCHMonitorPutNoContent(mon, URL_VM_RESUME); + return virCHMonitorPutNoContent(mon, URL_VM_RESUME, NULL); } =20 int diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 5c02447116..ca23301723 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -25,6 +25,7 @@ #include "virobject.h" #include "virjson.h" #include "domain_conf.h" +#include "domain_logcontext.h" #include "ch_conf.h" =20 #define URL_ROOT "http://localhost/api/v1" @@ -110,7 +111,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonito= rClose); =20 =20 int virCHMonitorCreateVM(virCHDriver *driver, virCHMonitor *mon); -int virCHMonitorBootVM(virCHMonitor *mon); +int virCHMonitorBootVM(virCHMonitor *mon, domainLogContext *logCtxt); int virCHMonitorShutdownVM(virCHMonitor *mon); int virCHMonitorRebootVM(virCHMonitor *mon); int virCHMonitorSuspendVM(virCHMonitor *mon); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index af44aa81a2..9a85f7869e 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -964,7 +964,7 @@ virCHProcessStart(virCHDriver *driver, if (virDomainInterfaceStartDevices(vm->def) < 0) return -1; =20 - if (virCHMonitorBootVM(priv->monitor) < 0) { + if (virCHMonitorBootVM(priv->monitor, logCtxt) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to boot guest VM")); goto cleanup; --=20 2.47.0