From nobody Sun Dec 22 07:51:51 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 1734628396887197.99502231341023; Thu, 19 Dec 2024 09:13:16 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D6DEC17DF; Thu, 19 Dec 2024 12:13:15 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0A3A71899; Thu, 19 Dec 2024 12:08:35 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 686C917FE; Thu, 19 Dec 2024 12:08:25 -0500 (EST) Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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 AC7E017E6 for ; Thu, 19 Dec 2024 12:08:10 -0500 (EST) Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3ebbe804913so274366b6e.0 for ; Thu, 19 Dec 2024 09:08:10 -0800 (PST) Received: from home.. ([2603:8081:c640:1::1009]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-71fc9807c0fsm325938a34.41.2024.12.19.09.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 09:08:08 -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=-1.7 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_H2,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=1734628090; x=1735232890; 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=W6dbxC4M2C4NT25SUAxhvdOylMwiHheaIFcHp4s9d9SS/U9nQIqH7tHFTNo4IIXI1D 5n+jqLjxfNIlTCJ+vr8meqQl2Slz5zjsZ1/46nsfDm3wndoXpgaonvWUhG9TySVXnT4+ 1zD6T0LHZC93ZmtfYd2pOGvfsT0IHk/7AUdsvhUPw/yFpFsX3RsMDWoMxRUQ+DF3tIaF cHCTLMgnDfu2kYt2SKvpW4cqgK6ahjaPB2F4jn8mc2LDIyMJ4BBjnnGxO1YSNhT89zHz zwmogIwR8ZUKNtgiamqoOVp7GOvGs/zK0QJi4pTCq1SV387nGuRejcytfyE1EhbCRAyu EYsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734628090; x=1735232890; 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=PBtUkuQXvU0Rgm3O9uZREFlHaKOzacOVH7X9FQpJC6UGPATLeJwao2rV/5tvpesd1z uWcUfIZHieK/ePMRxnvB71IY+qn+XxYBsZeT8X5C9ZvyCehnicmEAj2SHi2JssL8Ejb5 HjD+NwoMCczcwxlJoieMRPHhv/Xpwb90sSCuvviM5ZUyXkMMTJa6ij+PriRVSBYL7nBf XykH8ZJ3aRQ1OHhjwuPk5agJL/OI8qHUWDdXkWfAklBe8dUbsu2jbmvI7E20YnhCovdR rE3JTpv3fjbdeuN2Yv65ARIM5qtPWxl5VTFKMiJ20n2yqcWUHPy14LGshgcr3c4NXzWs o9rQ== X-Gm-Message-State: AOJu0YysYwnQ7gljl39QEcO/qcCEv1tyo/vpD/qT6x9Ju/UYZgJdRDBh 4ozZUMtZTFE9iLjfMYDa0hZoBCGnVGxUCtRGH62IvHiErgs0RCrsHAXUBbxX X-Gm-Gg: ASbGncsB+1koL99DoDBd/zh0bWgryufeoeyFcVvCXZmHlFK+ABPGdVYZlE0aKkNdi6w 1THpt6qKMulYSJdCghYktNfC/K5dBmN4VfqZdQt26McVsSElU7mvVtWgj+u2l3XrbTj5vicitP7 TzEPA7vqB4i7wOjytR7dnBOScUDPIn6Zm2std0hjqMtmSxyos0i3E4GSbcoG2MyXUQlbYLxv3g7 VpImpdU4qbaSizfY2/KeBu/Ekq2EuM9Q28ZyD2D X-Google-Smtp-Source: AGHT+IHmczG7MjoE7V3GGJlcOjXqpisB6L+nDHEF5+xc/VM4xsOzmUVx/kdaa+Zr9Nut2D6J0CmLSQ== X-Received: by 2002:a05:6808:2187:b0:3e6:147:6c5 with SMTP id 5614622812f47-3ecdcbe0218mr2581504b6e.10.1734628089703; Thu, 19 Dec 2024 09:08:09 -0800 (PST) From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH v2 10/11] ch: Enable logging curl responses from ch Date: Thu, 19 Dec 2024 11:07:55 -0600 Message-ID: <20241219170756.30810-11-praveenkpaladugu@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241219170756.30810-1-praveenkpaladugu@gmail.com> References: <20241219170756.30810-1-praveenkpaladugu@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7YWPCSKMN5B2YEGYSGSOR5NNV6NTMDW3 X-Message-ID-Hash: 7YWPCSKMN5B2YEGYSGSOR5NNV6NTMDW3 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: 1734628397423116600 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