1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-21 13:34:06 +03:00

ch: Enable logging curl responses from ch

Log curl responses from cloud-hypervisor process during Boot request, using
domain's logContext.

Signed-off-by: Praveen K Paladugu <praveenkpaladugu@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Praveen K Paladugu 2024-12-19 08:46:01 -06:00 committed by Michal Privoznik
parent db4e837598
commit f7c33eeeb7
3 changed files with 29 additions and 11 deletions

View File

@ -56,7 +56,8 @@ static int virCHMonitorOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virCHMonitor);
int virCHMonitorShutdownVMM(virCHMonitor *mon);
int virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint);
int virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint,
domainLogContext *logCtxt);
static int
virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef)
@ -694,12 +695,15 @@ curl_callback(void *contents, size_t size, size_t nmemb, void *userp)
}
int
virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint)
virCHMonitorPutNoContent(virCHMonitor *mon, const char *endpoint,
domainLogContext *logCtxt)
{
VIR_LOCK_GUARD lock = virObjectLockGuard(mon);
g_autofree char *url = NULL;
int responseCode = 0;
int ret = -1;
struct curl_data data = {0};
struct curl_slist *headers = NULL;
url = g_strdup_printf("%s/%s", URL_ROOT, endpoint);
@ -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);
headers = 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 = virCHMonitorCurlPerform(mon->handle);
if (logCtxt && data.size) {
/* Do this to append a NULL char at the end of data */
data.content = g_realloc(data.content, data.size + 1);
data.content[data.size] = 0;
domainLogContextWrite(logCtxt, "HTTP response code from CH: %d\n", responseCode);
domainLogContextWrite(logCtxt, "Response = %s\n", data.content);
}
if (responseCode == 200 || responseCode == 204)
ret = 0;
@ -863,7 +880,7 @@ virCHMonitorGetThreadInfo(virCHMonitor *mon,
int
virCHMonitorShutdownVMM(virCHMonitor *mon)
{
return virCHMonitorPutNoContent(mon, URL_VMM_SHUTDOWN);
return virCHMonitorPutNoContent(mon, URL_VMM_SHUTDOWN, NULL);
}
int
@ -903,33 +920,33 @@ virCHMonitorCreateVM(virCHDriver *driver, virCHMonitor *mon)
}
int
virCHMonitorBootVM(virCHMonitor *mon)
virCHMonitorBootVM(virCHMonitor *mon, domainLogContext *logCtxt)
{
return virCHMonitorPutNoContent(mon, URL_VM_BOOT);
return virCHMonitorPutNoContent(mon, URL_VM_BOOT, logCtxt);
}
int
virCHMonitorShutdownVM(virCHMonitor *mon)
{
return virCHMonitorPutNoContent(mon, URL_VM_SHUTDOWN);
return virCHMonitorPutNoContent(mon, URL_VM_SHUTDOWN, NULL);
}
int
virCHMonitorRebootVM(virCHMonitor *mon)
{
return virCHMonitorPutNoContent(mon, URL_VM_REBOOT);
return virCHMonitorPutNoContent(mon, URL_VM_REBOOT, NULL);
}
int
virCHMonitorSuspendVM(virCHMonitor *mon)
{
return virCHMonitorPutNoContent(mon, URL_VM_Suspend);
return virCHMonitorPutNoContent(mon, URL_VM_Suspend, NULL);
}
int
virCHMonitorResumeVM(virCHMonitor *mon)
{
return virCHMonitorPutNoContent(mon, URL_VM_RESUME);
return virCHMonitorPutNoContent(mon, URL_VM_RESUME, NULL);
}
int

View File

@ -25,6 +25,7 @@
#include "virobject.h"
#include "virjson.h"
#include "domain_conf.h"
#include "domain_logcontext.h"
#include "ch_conf.h"
#define URL_ROOT "http://localhost/api/v1"
@ -110,7 +111,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonitorClose);
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);

View File

@ -964,7 +964,7 @@ virCHProcessStart(virCHDriver *driver,
if (virDomainInterfaceStartDevices(vm->def) < 0)
return -1;
if (virCHMonitorBootVM(priv->monitor) < 0) {
if (virCHMonitorBootVM(priv->monitor, logCtxt) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to boot guest VM"));
goto cleanup;