]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: refactor virCHMonitorSaveVM
authorPurna Pavan Chandra <paekkaladevi@linux.microsoft.com>
Mon, 5 Aug 2024 14:40:58 +0000 (14:40 +0000)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Aug 2024 13:03:07 +0000 (15:03 +0200)
Remove the unwanted utility function and make api calls directly from
virCHMonitorSaveVM fn

Signed-off-by: Purna Pavan Chandra <paekkaladevi@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_monitor.c
src/ch/ch_monitor.h

index e76277855e9976719bcd4825aaea6d008a93091b..58590266f0e0a7523e7c559bb7c4fd5aef4e0096 100644 (file)
@@ -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)
index 11bac0c2327e4ff7b5b67ceaf0718742dc1d2758..9d4c315d0444d1ab495787a19934f0b1200eefe2 100644 (file)
@@ -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);