cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-dump-snapshot-and-image-info-to-specified-outp.patch

218e99
From 427c29cd043ba19a46096c66fafb321aecb8bc9b Mon Sep 17 00:00:00 2001
218e99
From: Max Reitz <mreitz@redhat.com>
218e99
Date: Wed, 6 Nov 2013 16:53:26 +0100
218e99
Subject: [PATCH 69/87] block: dump snapshot and image info to specified output
218e99
218e99
RH-Author: Max Reitz <mreitz@redhat.com>
218e99
Message-id: <1383756824-6921-4-git-send-email-mreitz@redhat.com>
218e99
Patchwork-id: 55558
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 03/21] block: dump snapshot and image info to specified output
218e99
Bugzilla: 980771
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
218e99
218e99
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
218e99
218e99
BZ: 980771
218e99
218e99
bdrv_snapshot_dump() and bdrv_image_info_dump() do not dump to a buffer now,
218e99
some internal buffers are still used for format control, which have no
218e99
chance to be truncated. As a result, these two functions have no more issue
218e99
of truncation, and they can be used by both qemu and qemu-img with correct
218e99
parameter specified.
218e99
218e99
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
(cherry picked from commit 5b91704469c0f801e0219f26458356872c4145ab)
218e99
218e99
Signed-off-by: Max Reitz <mreitz@redhat.com>
218e99
---
218e99
 block/qapi.c         | 66 ++++++++++++++++++++++++++++------------------------
218e99
 include/block/qapi.h |  6 +++--
218e99
 qemu-img.c           |  9 +++----
218e99
 savevm.c             |  7 +++---
218e99
 4 files changed, 49 insertions(+), 39 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block/qapi.c         |   66 +++++++++++++++++++++++++++----------------------
218e99
 include/block/qapi.h |    6 +++-
218e99
 qemu-img.c           |    9 ++++---
218e99
 savevm.c             |    7 +++--
218e99
 4 files changed, 49 insertions(+), 39 deletions(-)
218e99
218e99
diff --git a/block/qapi.c b/block/qapi.c
218e99
index 155e77e..794dbf8 100644
218e99
--- a/block/qapi.c
218e99
+++ b/block/qapi.c
218e99
@@ -259,7 +259,8 @@ static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
218e99
     return buf;
218e99
 }
218e99
 
218e99
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
218e99
+void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
218e99
+                        QEMUSnapshotInfo *sn)
218e99
 {
218e99
     char buf1[128], date_buf[128], clock_buf[128];
218e99
     struct tm tm;
218e99
@@ -267,9 +268,9 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
218e99
     int64_t secs;
218e99
 
218e99
     if (!sn) {
218e99
-        snprintf(buf, buf_size,
218e99
-                 "%-10s%-20s%7s%20s%15s",
218e99
-                 "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
218e99
+        func_fprintf(f,
218e99
+                     "%-10s%-20s%7s%20s%15s",
218e99
+                     "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
218e99
     } else {
218e99
         ti = sn->date_sec;
218e99
         localtime_r(&ti, &tm;;
218e99
@@ -282,17 +283,18 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
218e99
                  (int)((secs / 60) % 60),
218e99
                  (int)(secs % 60),
218e99
                  (int)((sn->vm_clock_nsec / 1000000) % 1000));
218e99
-        snprintf(buf, buf_size,
218e99
-                 "%-10s%-20s%7s%20s%15s",
218e99
-                 sn->id_str, sn->name,
218e99
-                 get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),
218e99
-                 date_buf,
218e99
-                 clock_buf);
218e99
+        func_fprintf(f,
218e99
+                     "%-10s%-20s%7s%20s%15s",
218e99
+                     sn->id_str, sn->name,
218e99
+                     get_human_readable_size(buf1, sizeof(buf1),
218e99
+                                             sn->vm_state_size),
218e99
+                     date_buf,
218e99
+                     clock_buf);
218e99
     }
218e99
-    return buf;
218e99
 }
218e99
 
218e99
-void bdrv_image_info_dump(ImageInfo *info)
218e99
+void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
218e99
+                          ImageInfo *info)
218e99
 {
218e99
     char size_buf[128], dsize_buf[128];
218e99
     if (!info->has_actual_size) {
218e99
@@ -302,43 +304,46 @@ void bdrv_image_info_dump(ImageInfo *info)
218e99
                                 info->actual_size);
218e99
     }
218e99
     get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
218e99
-    printf("image: %s\n"
218e99
-           "file format: %s\n"
218e99
-           "virtual size: %s (%" PRId64 " bytes)\n"
218e99
-           "disk size: %s\n",
218e99
-           info->filename, info->format, size_buf,
218e99
-           info->virtual_size,
218e99
-           dsize_buf);
218e99
+    func_fprintf(f,
218e99
+                 "image: %s\n"
218e99
+                 "file format: %s\n"
218e99
+                 "virtual size: %s (%" PRId64 " bytes)\n"
218e99
+                 "disk size: %s\n",
218e99
+                 info->filename, info->format, size_buf,
218e99
+                 info->virtual_size,
218e99
+                 dsize_buf);
218e99
 
218e99
     if (info->has_encrypted && info->encrypted) {
218e99
-        printf("encrypted: yes\n");
218e99
+        func_fprintf(f, "encrypted: yes\n");
218e99
     }
218e99
 
218e99
     if (info->has_cluster_size) {
218e99
-        printf("cluster_size: %" PRId64 "\n", info->cluster_size);
218e99
+        func_fprintf(f, "cluster_size: %" PRId64 "\n",
218e99
+                       info->cluster_size);
218e99
     }
218e99
 
218e99
     if (info->has_dirty_flag && info->dirty_flag) {
218e99
-        printf("cleanly shut down: no\n");
218e99
+        func_fprintf(f, "cleanly shut down: no\n");
218e99
     }
218e99
 
218e99
     if (info->has_backing_filename) {
218e99
-        printf("backing file: %s", info->backing_filename);
218e99
+        func_fprintf(f, "backing file: %s", info->backing_filename);
218e99
         if (info->has_full_backing_filename) {
218e99
-            printf(" (actual path: %s)", info->full_backing_filename);
218e99
+            func_fprintf(f, " (actual path: %s)", info->full_backing_filename);
218e99
         }
218e99
-        putchar('\n');
218e99
+        func_fprintf(f, "\n");
218e99
         if (info->has_backing_filename_format) {
218e99
-            printf("backing file format: %s\n", info->backing_filename_format);
218e99
+            func_fprintf(f, "backing file format: %s\n",
218e99
+                         info->backing_filename_format);
218e99
         }
218e99
     }
218e99
 
218e99
     if (info->has_snapshots) {
218e99
         SnapshotInfoList *elem;
218e99
-        char buf[256];
218e99
 
218e99
-        printf("Snapshot list:\n");
218e99
-        printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
218e99
+        func_fprintf(f, "Snapshot list:\n");
218e99
+        bdrv_snapshot_dump(func_fprintf, f, NULL);
218e99
+        func_fprintf(f, "\n");
218e99
 
218e99
         /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
218e99
          * we convert to the block layer's native QEMUSnapshotInfo for now.
218e99
@@ -354,7 +359,8 @@ void bdrv_image_info_dump(ImageInfo *info)
218e99
 
218e99
             pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
218e99
             pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
218e99
-            printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
218e99
+            bdrv_snapshot_dump(func_fprintf, f, &sn;;
218e99
+            func_fprintf(f, "\n");
218e99
         }
218e99
     }
218e99
 }
218e99
diff --git a/include/block/qapi.h b/include/block/qapi.h
218e99
index 55d1848..e6e568d 100644
218e99
--- a/include/block/qapi.h
218e99
+++ b/include/block/qapi.h
218e99
@@ -36,6 +36,8 @@ void bdrv_collect_image_info(BlockDriverState *bs,
218e99
 BlockInfo *bdrv_query_info(BlockDriverState *s);
218e99
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
218e99
 
218e99
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
218e99
-void bdrv_image_info_dump(ImageInfo *info);
218e99
+void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
218e99
+                        QEMUSnapshotInfo *sn);
218e99
+void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
218e99
+                          ImageInfo *info);
218e99
 #endif
218e99
diff --git a/qemu-img.c b/qemu-img.c
218e99
index 0bc084d..97b4212 100644
218e99
--- a/qemu-img.c
218e99
+++ b/qemu-img.c
218e99
@@ -1575,16 +1575,17 @@ static void dump_snapshots(BlockDriverState *bs)
218e99
 {
218e99
     QEMUSnapshotInfo *sn_tab, *sn;
218e99
     int nb_sns, i;
218e99
-    char buf[256];
218e99
 
218e99
     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
218e99
     if (nb_sns <= 0)
218e99
         return;
218e99
     printf("Snapshot list:\n");
218e99
-    printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
218e99
+    bdrv_snapshot_dump(fprintf, stdout, NULL);
218e99
+    printf("\n");
218e99
     for(i = 0; i < nb_sns; i++) {
218e99
         sn = &sn_tab[i];
218e99
-        printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
218e99
+        bdrv_snapshot_dump(fprintf, stdout, sn);
218e99
+        printf("\n");
218e99
     }
218e99
     g_free(sn_tab);
218e99
 }
218e99
@@ -1634,7 +1635,7 @@ static void dump_human_image_info_list(ImageInfoList *list)
218e99
         }
218e99
         delim = true;
218e99
 
218e99
-        bdrv_image_info_dump(elem->value);
218e99
+        bdrv_image_info_dump(fprintf, stdout, elem->value);
218e99
     }
218e99
 }
218e99
 
218e99
diff --git a/savevm.c b/savevm.c
218e99
index f126bff..4d12d92 100644
218e99
--- a/savevm.c
218e99
+++ b/savevm.c
218e99
@@ -2540,7 +2540,6 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
218e99
     int nb_sns, i, ret, available;
218e99
     int total;
218e99
     int *available_snapshots;
218e99
-    char buf[256];
218e99
 
218e99
     bs = find_vmstate_bs();
218e99
     if (!bs) {
218e99
@@ -2583,10 +2582,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
218e99
     }
218e99
 
218e99
     if (total > 0) {
218e99
-        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
218e99
+        bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
218e99
+        monitor_printf(mon, "\n");
218e99
         for (i = 0; i < total; i++) {
218e99
             sn = &sn_tab[available_snapshots[i]];
218e99
-            monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
218e99
+            bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
218e99
+            monitor_printf(mon, "\n");
218e99
         }
218e99
     } else {
218e99
         monitor_printf(mon, "There is no suitable snapshot available\n");
218e99
-- 
218e99
1.7.1
218e99