]> git.proxmox.com Git - mirror_qemu.git/blobdiff - block/qapi.c
block: drop bs->job
[mirror_qemu.git] / block / qapi.c
index e3e74f898fe4eed4a851e0f9a7f3b60a557476bc..917435f02262a7b2190ffa2d7858ff2e5ffaf2cb 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "block/qapi.h"
 #include "block/block_int.h"
 #include "block/throttle-groups.h"
@@ -631,42 +632,13 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
     return head;
 }
 
-#define NB_SUFFIXES 4
-
-static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
-{
-    static const char suffixes[NB_SUFFIXES] = {'K', 'M', 'G', 'T'};
-    int64_t base;
-    int i;
-
-    if (size <= 999) {
-        snprintf(buf, buf_size, "%" PRId64, size);
-    } else {
-        base = 1024;
-        for (i = 0; i < NB_SUFFIXES; i++) {
-            if (size < (10 * base)) {
-                snprintf(buf, buf_size, "%0.1f%c",
-                         (double)size / base,
-                         suffixes[i]);
-                break;
-            } else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {
-                snprintf(buf, buf_size, "%" PRId64 "%c",
-                         ((size + (base >> 1)) / base),
-                         suffixes[i]);
-                break;
-            }
-            base = base * 1024;
-        }
-    }
-    return buf;
-}
-
 void bdrv_snapshot_dump(QEMUSnapshotInfo *sn)
 {
-    char buf1[128], date_buf[128], clock_buf[128];
+    char date_buf[128], clock_buf[128];
     struct tm tm;
     time_t ti;
     int64_t secs;
+    char *sizing = NULL;
 
     if (!sn) {
         qemu_printf("%-10s%-20s%7s%20s%15s",
@@ -683,13 +655,14 @@ void bdrv_snapshot_dump(QEMUSnapshotInfo *sn)
                  (int)((secs / 60) % 60),
                  (int)(secs % 60),
                  (int)((sn->vm_clock_nsec / 1000000) % 1000));
+        sizing = size_to_str(sn->vm_state_size);
         qemu_printf("%-10s%-20s%7s%20s%15s",
                     sn->id_str, sn->name,
-                    get_human_readable_size(buf1, sizeof(buf1),
-                                            sn->vm_state_size),
+                    sizing,
                     date_buf,
                     clock_buf);
     }
+    g_free(sizing);
 }
 
 static void dump_qdict(int indentation, QDict *dict);
@@ -787,14 +760,13 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec)
 
 void bdrv_image_info_dump(ImageInfo *info)
 {
-    char size_buf[128], dsize_buf[128];
+    char *size_buf, *dsize_buf;
     if (!info->has_actual_size) {
-        snprintf(dsize_buf, sizeof(dsize_buf), "unavailable");
+        dsize_buf = g_strdup("unavailable");
     } else {
-        get_human_readable_size(dsize_buf, sizeof(dsize_buf),
-                                info->actual_size);
+        dsize_buf = size_to_str(info->actual_size);
     }
-    get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
+    size_buf = size_to_str(info->virtual_size);
     qemu_printf("image: %s\n"
                 "file format: %s\n"
                 "virtual size: %s (%" PRId64 " bytes)\n"
@@ -802,6 +774,8 @@ void bdrv_image_info_dump(ImageInfo *info)
                 info->filename, info->format, size_buf,
                 info->virtual_size,
                 dsize_buf);
+    g_free(size_buf);
+    g_free(dsize_buf);
 
     if (info->has_encrypted && info->encrypted) {
         qemu_printf("encrypted: yes\n");