From nobody Thu Jan 9 02:54:45 2025 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 173461988592596.1970773069047; Thu, 19 Dec 2024 06:51:25 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E10DD153F; Thu, 19 Dec 2024 09:51:24 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8FBB2160C; Thu, 19 Dec 2024 09:46:34 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 32B81161E; Thu, 19 Dec 2024 09:46:21 -0500 (EST) Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 50DB2160B for ; Thu, 19 Dec 2024 09:46:14 -0500 (EST) Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-71e2bb84fe3so385287a34.1 for ; Thu, 19 Dec 2024 06:46:14 -0800 (PST) Received: from home.. ([2603:8081:c640:1::1009]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-71fc97a40afsm272978a34.25.2024.12.19.06.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 06:46:12 -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.5 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=1734619573; x=1735224373; 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=LOXWW2d5cxaE4LDPi81BVC7GjOKt7juicsdeqWcK2c/O6k1tfGhuloNWm0RoOq4GNd 1kQ91xDf7ojTiObVDa4dG5o0e3RS2Teh3HtKITewxM5Wrjg/1rTZmLCH/dx2xmeBKlCl jsM6CoT4pchUei8iofvbzn+cjZgD2oueqoowCVfM9AvyhVYYqAv3LyonEtPxBRapiYJj ElUlHHKnnfrT25zR74QsFBaB6CWewg4Tr1KYcaLWidw9Uy/ukxpV6it5xfduH5rw/KVl FWhRIoOYABO4hDYBlI1/QyX/diPHbjRNqIvbA2o4aIc0J01cjLZwJDXM9vCxXmzXJsn/ 26VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619573; x=1735224373; 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=ZInhMkCbs+vQ6U3ni0rDUTUcf+lwtfD3Tsp7KviFoUDtXd7qIL6nyR3+n725p008vl 1OlDIcWHdjJaiochKfxgg18OX7F7gV5iB+K05zoMMaScefdGVwngvT48OUtGG265YDFT AjmJJa1+F0pW5Xf5ImmcKFEAhDjjo0O2i2P25Vnoljz+2hsmJYk/JHosK+dnCgFWbVQ1 zVdNPCJKCKs8g7Q1ZQ+YrT7DnUpdYEBf0TNBT3Hzgw6MpbUtQ1Ubj6u46Iq4zw561XXY mYU/KPdBWjwjZxXr+AUZq2JmLekyOj7MIo+xdp9y1Ip5EFRXu3EtAeVdxHmv8vm6FiEB Neug== X-Gm-Message-State: AOJu0YyBhQJK1zIfnbMM08lgXRmqTkLYwcRtazrAwwHFIOgGqr2xYMdP ReS28C2+z9jZ58tMMIQfI4qqu0DL+wE6NciZHpxaHimKdYwACBzSYRciumzy X-Gm-Gg: ASbGncv0gh+HqwNzwwOeBotFxUY8G+/sOEhJs43hl8NpB4VQceySmxFZF2Y0mINOCD7 g5BLWTgv8t6l67bzKIudSq2y4KbxCs7Uqt5h5Fz6PxC/JWXTBlIZXcvR/tdbkKhC+22eRDS45fC 5QHgS+KV0tixKkjBsKlifPhzKxIYWLxdPm8s8ltnO8xBcTac17aR3fpUNvyB+0wT3GKm8bukOnv n1CUVjmL3J6BIr/42pmEOncMHWaDNh60L+/xrEY X-Google-Smtp-Source: AGHT+IEh+b1hhJpJXv+nS5lOCULjtKpJiKx9tUGWLtd6n1J2LzhniB5h9oSNgFRnZLFrxeH9oNoJ5g== X-Received: by 2002:a05:6830:6606:b0:718:17b6:56f5 with SMTP id 46e09a7af769-71fb7639e4fmr4842439a34.29.1734619573199; Thu, 19 Dec 2024 06:46:13 -0800 (PST) From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH 10/10] ch: Enable logging curl responses from ch Date: Thu, 19 Dec 2024 08:46:01 -0600 Message-ID: <20241219144601.16394-11-praveenkpaladugu@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241219144601.16394-1-praveenkpaladugu@gmail.com> References: <20241219144601.16394-1-praveenkpaladugu@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HZAS4KM74YG6XAOZKULLWWWGOU3XULXN X-Message-ID-Hash: HZAS4KM74YG6XAOZKULLWWWGOU3XULXN 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: 1734619886712116600 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