From 4ae70b7c2d12e73461ec33fac71d4834f29c9f89 Mon Sep 17 00:00:00 2001 From: Purna Pavan Chandra Date: Mon, 5 Aug 2024 14:40:58 +0000 Subject: [PATCH] ch: refactor virCHMonitorSaveVM Remove the unwanted utility function and make api calls directly from virCHMonitorSaveVM fn Signed-off-by: Purna Pavan Chandra Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/ch/ch_monitor.c | 28 ++++++++-------------------- src/ch/ch_monitor.h | 3 ++- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index e76277855e..58590266f0 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -927,8 +927,9 @@ virCHMonitorResumeVM(virCHMonitor *mon) return virCHMonitorPutNoContent(mon, URL_VM_RESUME); } -static int -virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save) +int +virCHMonitorSaveVM(virCHMonitor *mon, + const char *to) { g_autofree char *url = NULL; int responseCode = 0; @@ -938,22 +939,15 @@ virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save) struct curl_slist *headers = NULL; struct curl_data data = {0}; - if (save) - url = g_strdup_printf("%s/%s", URL_ROOT, URL_VM_SAVE); - else - url = g_strdup_printf("%s/%s", URL_ROOT, URL_VM_RESTORE); + url = g_strdup_printf("%s/%s", URL_ROOT, URL_VM_SAVE); headers = curl_slist_append(headers, "Accept: application/json"); headers = curl_slist_append(headers, "Content-Type: application/json"); - path_url = g_strdup_printf("file://%s", path); - if (save) { - if (virCHMonitorBuildKeyValueStringJson(&payload, "destination_url", path_url) != 0) - return -1; - } else { - if (virCHMonitorBuildKeyValueStringJson(&payload, "source_url", path_url) != 0) - return -1; - } + path_url = g_strdup_printf("file://%s", to); + if (virCHMonitorBuildKeyValueStringJson(&payload, "destination_url", path_url) != 0) + return -1; + VIR_WITH_OBJECT_LOCK_GUARD(mon) { /* reset all options of a libcurl session handle at first */ @@ -986,12 +980,6 @@ virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save) return ret; } -int -virCHMonitorSaveVM(virCHMonitor *mon, const char *to) -{ - return virCHMonitorSaveRestoreVM(mon, to, true); -} - int virCHMonitorBuildRestoreJson(const char *from, char **jsonstr) diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 11bac0c232..9d4c315d04 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -114,7 +114,8 @@ int virCHMonitorShutdownVM(virCHMonitor *mon); int virCHMonitorRebootVM(virCHMonitor *mon); int virCHMonitorSuspendVM(virCHMonitor *mon); int virCHMonitorResumeVM(virCHMonitor *mon); -int virCHMonitorSaveVM(virCHMonitor *mon, const char *to); +int virCHMonitorSaveVM(virCHMonitor *mon, + const char *to); int virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info); void virCHMonitorCPUInfoFree(virCHMonitorCPUInfo *cpus); -- 2.47.2