2 * Block layer qmp and info dump related functions
4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "block/qapi.h"
27 #include "block/block_int.h"
28 #include "block/throttle-groups.h"
29 #include "block/write-threshold.h"
30 #include "qmp-commands.h"
31 #include "qapi-visit.h"
32 #include "qapi/qobject-output-visitor.h"
33 #include "qapi/qmp/types.h"
34 #include "sysemu/block-backend.h"
35 #include "qemu/cutils.h"
37 BlockDeviceInfo
*bdrv_block_device_info(BlockBackend
*blk
,
38 BlockDriverState
*bs
, Error
**errp
)
40 ImageInfo
**p_image_info
;
41 BlockDriverState
*bs0
;
42 BlockDeviceInfo
*info
= g_malloc0(sizeof(*info
));
44 info
->file
= g_strdup(bs
->filename
);
45 info
->ro
= bs
->read_only
;
46 info
->drv
= g_strdup(bs
->drv
->format_name
);
47 info
->encrypted
= bs
->encrypted
;
48 info
->encryption_key_missing
= bdrv_key_required(bs
);
50 info
->cache
= g_new(BlockdevCacheInfo
, 1);
51 *info
->cache
= (BlockdevCacheInfo
) {
52 .writeback
= blk
? blk_enable_write_cache(blk
) : true,
53 .direct
= !!(bs
->open_flags
& BDRV_O_NOCACHE
),
54 .no_flush
= !!(bs
->open_flags
& BDRV_O_NO_FLUSH
),
57 if (bs
->node_name
[0]) {
58 info
->has_node_name
= true;
59 info
->node_name
= g_strdup(bs
->node_name
);
62 if (bs
->backing_file
[0]) {
63 info
->has_backing_file
= true;
64 info
->backing_file
= g_strdup(bs
->backing_file
);
67 info
->backing_file_depth
= bdrv_get_backing_file_depth(bs
);
68 info
->detect_zeroes
= bs
->detect_zeroes
;
70 if (blk
&& blk_get_public(blk
)->throttle_state
) {
73 throttle_group_get_config(blk
, &cfg
);
75 info
->bps
= cfg
.buckets
[THROTTLE_BPS_TOTAL
].avg
;
76 info
->bps_rd
= cfg
.buckets
[THROTTLE_BPS_READ
].avg
;
77 info
->bps_wr
= cfg
.buckets
[THROTTLE_BPS_WRITE
].avg
;
79 info
->iops
= cfg
.buckets
[THROTTLE_OPS_TOTAL
].avg
;
80 info
->iops_rd
= cfg
.buckets
[THROTTLE_OPS_READ
].avg
;
81 info
->iops_wr
= cfg
.buckets
[THROTTLE_OPS_WRITE
].avg
;
83 info
->has_bps_max
= cfg
.buckets
[THROTTLE_BPS_TOTAL
].max
;
84 info
->bps_max
= cfg
.buckets
[THROTTLE_BPS_TOTAL
].max
;
85 info
->has_bps_rd_max
= cfg
.buckets
[THROTTLE_BPS_READ
].max
;
86 info
->bps_rd_max
= cfg
.buckets
[THROTTLE_BPS_READ
].max
;
87 info
->has_bps_wr_max
= cfg
.buckets
[THROTTLE_BPS_WRITE
].max
;
88 info
->bps_wr_max
= cfg
.buckets
[THROTTLE_BPS_WRITE
].max
;
90 info
->has_iops_max
= cfg
.buckets
[THROTTLE_OPS_TOTAL
].max
;
91 info
->iops_max
= cfg
.buckets
[THROTTLE_OPS_TOTAL
].max
;
92 info
->has_iops_rd_max
= cfg
.buckets
[THROTTLE_OPS_READ
].max
;
93 info
->iops_rd_max
= cfg
.buckets
[THROTTLE_OPS_READ
].max
;
94 info
->has_iops_wr_max
= cfg
.buckets
[THROTTLE_OPS_WRITE
].max
;
95 info
->iops_wr_max
= cfg
.buckets
[THROTTLE_OPS_WRITE
].max
;
97 info
->has_bps_max_length
= info
->has_bps_max
;
98 info
->bps_max_length
=
99 cfg
.buckets
[THROTTLE_BPS_TOTAL
].burst_length
;
100 info
->has_bps_rd_max_length
= info
->has_bps_rd_max
;
101 info
->bps_rd_max_length
=
102 cfg
.buckets
[THROTTLE_BPS_READ
].burst_length
;
103 info
->has_bps_wr_max_length
= info
->has_bps_wr_max
;
104 info
->bps_wr_max_length
=
105 cfg
.buckets
[THROTTLE_BPS_WRITE
].burst_length
;
107 info
->has_iops_max_length
= info
->has_iops_max
;
108 info
->iops_max_length
=
109 cfg
.buckets
[THROTTLE_OPS_TOTAL
].burst_length
;
110 info
->has_iops_rd_max_length
= info
->has_iops_rd_max
;
111 info
->iops_rd_max_length
=
112 cfg
.buckets
[THROTTLE_OPS_READ
].burst_length
;
113 info
->has_iops_wr_max_length
= info
->has_iops_wr_max
;
114 info
->iops_wr_max_length
=
115 cfg
.buckets
[THROTTLE_OPS_WRITE
].burst_length
;
117 info
->has_iops_size
= cfg
.op_size
;
118 info
->iops_size
= cfg
.op_size
;
120 info
->has_group
= true;
121 info
->group
= g_strdup(throttle_group_get_name(blk
));
124 info
->write_threshold
= bdrv_write_threshold_get(bs
);
127 p_image_info
= &info
->image
;
129 Error
*local_err
= NULL
;
130 bdrv_query_image_info(bs0
, p_image_info
, &local_err
);
132 error_propagate(errp
, local_err
);
133 qapi_free_BlockDeviceInfo(info
);
136 if (bs0
->drv
&& bs0
->backing
) {
137 bs0
= bs0
->backing
->bs
;
138 (*p_image_info
)->has_backing_image
= true;
139 p_image_info
= &((*p_image_info
)->backing_image
);
149 * Returns 0 on success, with *p_list either set to describe snapshot
150 * information, or NULL because there are no snapshots. Returns -errno on
151 * error, with *p_list untouched.
153 int bdrv_query_snapshot_info_list(BlockDriverState
*bs
,
154 SnapshotInfoList
**p_list
,
158 QEMUSnapshotInfo
*sn_tab
= NULL
;
159 SnapshotInfoList
*info_list
, *cur_item
= NULL
, *head
= NULL
;
162 sn_count
= bdrv_snapshot_list(bs
, &sn_tab
);
164 const char *dev
= bdrv_get_device_name(bs
);
167 error_setg(errp
, "Device '%s' is not inserted", dev
);
171 "Device '%s' does not support internal snapshots",
175 error_setg_errno(errp
, -sn_count
,
176 "Can't list snapshots of device '%s'", dev
);
182 for (i
= 0; i
< sn_count
; i
++) {
183 info
= g_new0(SnapshotInfo
, 1);
184 info
->id
= g_strdup(sn_tab
[i
].id_str
);
185 info
->name
= g_strdup(sn_tab
[i
].name
);
186 info
->vm_state_size
= sn_tab
[i
].vm_state_size
;
187 info
->date_sec
= sn_tab
[i
].date_sec
;
188 info
->date_nsec
= sn_tab
[i
].date_nsec
;
189 info
->vm_clock_sec
= sn_tab
[i
].vm_clock_nsec
/ 1000000000;
190 info
->vm_clock_nsec
= sn_tab
[i
].vm_clock_nsec
% 1000000000;
192 info_list
= g_new0(SnapshotInfoList
, 1);
193 info_list
->value
= info
;
195 /* XXX: waiting for the qapi to support qemu-queue.h types */
197 head
= cur_item
= info_list
;
199 cur_item
->next
= info_list
;
200 cur_item
= info_list
;
211 * bdrv_query_image_info:
212 * @bs: block device to examine
213 * @p_info: location to store image information
214 * @errp: location to store error information
216 * Store "flat" image information in @p_info.
218 * "Flat" means it does *not* query backing image information,
219 * i.e. (*pinfo)->has_backing_image will be set to false and
220 * (*pinfo)->backing_image to NULL even when the image does in fact have
223 * @p_info will be set only on success. On error, store error in @errp.
225 void bdrv_query_image_info(BlockDriverState
*bs
,
230 const char *backing_filename
;
236 aio_context_acquire(bdrv_get_aio_context(bs
));
238 size
= bdrv_getlength(bs
);
240 error_setg_errno(errp
, -size
, "Can't get image size '%s'",
245 info
= g_new0(ImageInfo
, 1);
246 info
->filename
= g_strdup(bs
->filename
);
247 info
->format
= g_strdup(bdrv_get_format_name(bs
));
248 info
->virtual_size
= size
;
249 info
->actual_size
= bdrv_get_allocated_file_size(bs
);
250 info
->has_actual_size
= info
->actual_size
>= 0;
251 if (bdrv_is_encrypted(bs
)) {
252 info
->encrypted
= true;
253 info
->has_encrypted
= true;
255 if (bdrv_get_info(bs
, &bdi
) >= 0) {
256 if (bdi
.cluster_size
!= 0) {
257 info
->cluster_size
= bdi
.cluster_size
;
258 info
->has_cluster_size
= true;
260 info
->dirty_flag
= bdi
.is_dirty
;
261 info
->has_dirty_flag
= true;
263 info
->format_specific
= bdrv_get_specific_info(bs
);
264 info
->has_format_specific
= info
->format_specific
!= NULL
;
266 backing_filename
= bs
->backing_file
;
267 if (backing_filename
[0] != '\0') {
268 char *backing_filename2
= g_malloc0(PATH_MAX
);
269 info
->backing_filename
= g_strdup(backing_filename
);
270 info
->has_backing_filename
= true;
271 bdrv_get_full_backing_filename(bs
, backing_filename2
, PATH_MAX
, &err
);
273 /* Can't reconstruct the full backing filename, so we must omit
274 * this field and apply a Best Effort to this query. */
275 g_free(backing_filename2
);
276 backing_filename2
= NULL
;
281 /* Always report the full_backing_filename if present, even if it's the
282 * same as backing_filename. That they are same is useful info. */
283 if (backing_filename2
) {
284 info
->full_backing_filename
= g_strdup(backing_filename2
);
285 info
->has_full_backing_filename
= true;
288 if (bs
->backing_format
[0]) {
289 info
->backing_filename_format
= g_strdup(bs
->backing_format
);
290 info
->has_backing_filename_format
= true;
292 g_free(backing_filename2
);
295 ret
= bdrv_query_snapshot_info_list(bs
, &info
->snapshots
, &err
);
298 if (info
->snapshots
) {
299 info
->has_snapshots
= true;
302 /* recoverable error */
308 error_propagate(errp
, err
);
309 qapi_free_ImageInfo(info
);
316 aio_context_release(bdrv_get_aio_context(bs
));
319 /* @p_info will be set only on success. */
320 static void bdrv_query_info(BlockBackend
*blk
, BlockInfo
**p_info
,
323 BlockInfo
*info
= g_malloc0(sizeof(*info
));
324 BlockDriverState
*bs
= blk_bs(blk
);
325 info
->device
= g_strdup(blk_name(blk
));
326 info
->type
= g_strdup("unknown");
327 info
->locked
= blk_dev_is_medium_locked(blk
);
328 info
->removable
= blk_dev_has_removable_media(blk
);
330 if (blk_dev_has_tray(blk
)) {
331 info
->has_tray_open
= true;
332 info
->tray_open
= blk_dev_is_tray_open(blk
);
335 if (blk_iostatus_is_enabled(blk
)) {
336 info
->has_io_status
= true;
337 info
->io_status
= blk_iostatus(blk
);
340 if (bs
&& !QLIST_EMPTY(&bs
->dirty_bitmaps
)) {
341 info
->has_dirty_bitmaps
= true;
342 info
->dirty_bitmaps
= bdrv_query_dirty_bitmaps(bs
);
346 info
->has_inserted
= true;
347 info
->inserted
= bdrv_block_device_info(blk
, bs
, errp
);
348 if (info
->inserted
== NULL
) {
357 qapi_free_BlockInfo(info
);
360 static void bdrv_query_blk_stats(BlockDeviceStats
*ds
, BlockBackend
*blk
)
362 BlockAcctStats
*stats
= blk_get_stats(blk
);
363 BlockAcctTimedStats
*ts
= NULL
;
365 ds
->rd_bytes
= stats
->nr_bytes
[BLOCK_ACCT_READ
];
366 ds
->wr_bytes
= stats
->nr_bytes
[BLOCK_ACCT_WRITE
];
367 ds
->rd_operations
= stats
->nr_ops
[BLOCK_ACCT_READ
];
368 ds
->wr_operations
= stats
->nr_ops
[BLOCK_ACCT_WRITE
];
370 ds
->failed_rd_operations
= stats
->failed_ops
[BLOCK_ACCT_READ
];
371 ds
->failed_wr_operations
= stats
->failed_ops
[BLOCK_ACCT_WRITE
];
372 ds
->failed_flush_operations
= stats
->failed_ops
[BLOCK_ACCT_FLUSH
];
374 ds
->invalid_rd_operations
= stats
->invalid_ops
[BLOCK_ACCT_READ
];
375 ds
->invalid_wr_operations
= stats
->invalid_ops
[BLOCK_ACCT_WRITE
];
376 ds
->invalid_flush_operations
=
377 stats
->invalid_ops
[BLOCK_ACCT_FLUSH
];
379 ds
->rd_merged
= stats
->merged
[BLOCK_ACCT_READ
];
380 ds
->wr_merged
= stats
->merged
[BLOCK_ACCT_WRITE
];
381 ds
->flush_operations
= stats
->nr_ops
[BLOCK_ACCT_FLUSH
];
382 ds
->wr_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_WRITE
];
383 ds
->rd_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_READ
];
384 ds
->flush_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_FLUSH
];
386 ds
->has_idle_time_ns
= stats
->last_access_time_ns
> 0;
387 if (ds
->has_idle_time_ns
) {
388 ds
->idle_time_ns
= block_acct_idle_time_ns(stats
);
391 ds
->account_invalid
= stats
->account_invalid
;
392 ds
->account_failed
= stats
->account_failed
;
394 while ((ts
= block_acct_interval_next(stats
, ts
))) {
395 BlockDeviceTimedStatsList
*timed_stats
=
396 g_malloc0(sizeof(*timed_stats
));
397 BlockDeviceTimedStats
*dev_stats
= g_malloc0(sizeof(*dev_stats
));
398 timed_stats
->next
= ds
->timed_stats
;
399 timed_stats
->value
= dev_stats
;
400 ds
->timed_stats
= timed_stats
;
402 TimedAverage
*rd
= &ts
->latency
[BLOCK_ACCT_READ
];
403 TimedAverage
*wr
= &ts
->latency
[BLOCK_ACCT_WRITE
];
404 TimedAverage
*fl
= &ts
->latency
[BLOCK_ACCT_FLUSH
];
406 dev_stats
->interval_length
= ts
->interval_length
;
408 dev_stats
->min_rd_latency_ns
= timed_average_min(rd
);
409 dev_stats
->max_rd_latency_ns
= timed_average_max(rd
);
410 dev_stats
->avg_rd_latency_ns
= timed_average_avg(rd
);
412 dev_stats
->min_wr_latency_ns
= timed_average_min(wr
);
413 dev_stats
->max_wr_latency_ns
= timed_average_max(wr
);
414 dev_stats
->avg_wr_latency_ns
= timed_average_avg(wr
);
416 dev_stats
->min_flush_latency_ns
= timed_average_min(fl
);
417 dev_stats
->max_flush_latency_ns
= timed_average_max(fl
);
418 dev_stats
->avg_flush_latency_ns
= timed_average_avg(fl
);
420 dev_stats
->avg_rd_queue_depth
=
421 block_acct_queue_depth(ts
, BLOCK_ACCT_READ
);
422 dev_stats
->avg_wr_queue_depth
=
423 block_acct_queue_depth(ts
, BLOCK_ACCT_WRITE
);
427 static BlockStats
*bdrv_query_bds_stats(const BlockDriverState
*bs
,
430 BlockStats
*s
= NULL
;
432 s
= g_malloc0(sizeof(*s
));
433 s
->stats
= g_malloc0(sizeof(*s
->stats
));
439 if (bdrv_get_node_name(bs
)[0]) {
440 s
->has_node_name
= true;
441 s
->node_name
= g_strdup(bdrv_get_node_name(bs
));
444 s
->stats
->wr_highest_offset
= bs
->wr_highest_offset
;
447 s
->has_parent
= true;
448 s
->parent
= bdrv_query_bds_stats(bs
->file
->bs
, query_backing
);
451 if (query_backing
&& bs
->backing
) {
452 s
->has_backing
= true;
453 s
->backing
= bdrv_query_bds_stats(bs
->backing
->bs
, query_backing
);
459 BlockInfoList
*qmp_query_block(Error
**errp
)
461 BlockInfoList
*head
= NULL
, **p_next
= &head
;
463 Error
*local_err
= NULL
;
465 for (blk
= blk_next(NULL
); blk
; blk
= blk_next(blk
)) {
466 BlockInfoList
*info
= g_malloc0(sizeof(*info
));
467 bdrv_query_info(blk
, &info
->value
, &local_err
);
469 error_propagate(errp
, local_err
);
471 qapi_free_BlockInfoList(head
);
476 p_next
= &info
->next
;
482 BlockStatsList
*qmp_query_blockstats(bool has_query_nodes
,
486 BlockStatsList
*head
= NULL
, **p_next
= &head
;
488 BlockDriverState
*bs
;
490 /* Just to be safe if query_nodes is not always initialized */
491 if (has_query_nodes
&& query_nodes
) {
492 for (bs
= bdrv_next_node(NULL
); bs
; bs
= bdrv_next_node(bs
)) {
493 BlockStatsList
*info
= g_malloc0(sizeof(*info
));
494 AioContext
*ctx
= bdrv_get_aio_context(bs
);
496 aio_context_acquire(ctx
);
497 info
->value
= bdrv_query_bds_stats(bs
, false);
498 aio_context_release(ctx
);
501 p_next
= &info
->next
;
504 for (blk
= blk_next(NULL
); blk
; blk
= blk_next(blk
)) {
505 BlockStatsList
*info
= g_malloc0(sizeof(*info
));
506 AioContext
*ctx
= blk_get_aio_context(blk
);
509 aio_context_acquire(ctx
);
510 s
= bdrv_query_bds_stats(blk_bs(blk
), true);
511 s
->has_device
= true;
512 s
->device
= g_strdup(blk_name(blk
));
513 bdrv_query_blk_stats(s
->stats
, blk
);
514 aio_context_release(ctx
);
518 p_next
= &info
->next
;
525 #define NB_SUFFIXES 4
527 static char *get_human_readable_size(char *buf
, int buf_size
, int64_t size
)
529 static const char suffixes
[NB_SUFFIXES
] = {'K', 'M', 'G', 'T'};
534 snprintf(buf
, buf_size
, "%" PRId64
, size
);
537 for (i
= 0; i
< NB_SUFFIXES
; i
++) {
538 if (size
< (10 * base
)) {
539 snprintf(buf
, buf_size
, "%0.1f%c",
543 } else if (size
< (1000 * base
) || i
== (NB_SUFFIXES
- 1)) {
544 snprintf(buf
, buf_size
, "%" PRId64
"%c",
545 ((size
+ (base
>> 1)) / base
),
555 void bdrv_snapshot_dump(fprintf_function func_fprintf
, void *f
,
556 QEMUSnapshotInfo
*sn
)
558 char buf1
[128], date_buf
[128], clock_buf
[128];
565 "%-10s%-20s%7s%20s%15s",
566 "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
569 localtime_r(&ti
, &tm
);
570 strftime(date_buf
, sizeof(date_buf
),
571 "%Y-%m-%d %H:%M:%S", &tm
);
572 secs
= sn
->vm_clock_nsec
/ 1000000000;
573 snprintf(clock_buf
, sizeof(clock_buf
),
574 "%02d:%02d:%02d.%03d",
576 (int)((secs
/ 60) % 60),
578 (int)((sn
->vm_clock_nsec
/ 1000000) % 1000));
580 "%-10s%-20s%7s%20s%15s",
581 sn
->id_str
, sn
->name
,
582 get_human_readable_size(buf1
, sizeof(buf1
),
589 static void dump_qdict(fprintf_function func_fprintf
, void *f
, int indentation
,
591 static void dump_qlist(fprintf_function func_fprintf
, void *f
, int indentation
,
594 static void dump_qobject(fprintf_function func_fprintf
, void *f
,
595 int comp_indent
, QObject
*obj
)
597 switch (qobject_type(obj
)) {
599 QInt
*value
= qobject_to_qint(obj
);
600 func_fprintf(f
, "%" PRId64
, qint_get_int(value
));
603 case QTYPE_QSTRING
: {
604 QString
*value
= qobject_to_qstring(obj
);
605 func_fprintf(f
, "%s", qstring_get_str(value
));
609 QDict
*value
= qobject_to_qdict(obj
);
610 dump_qdict(func_fprintf
, f
, comp_indent
, value
);
614 QList
*value
= qobject_to_qlist(obj
);
615 dump_qlist(func_fprintf
, f
, comp_indent
, value
);
619 QFloat
*value
= qobject_to_qfloat(obj
);
620 func_fprintf(f
, "%g", qfloat_get_double(value
));
624 QBool
*value
= qobject_to_qbool(obj
);
625 func_fprintf(f
, "%s", qbool_get_bool(value
) ? "true" : "false");
633 static void dump_qlist(fprintf_function func_fprintf
, void *f
, int indentation
,
636 const QListEntry
*entry
;
639 for (entry
= qlist_first(list
); entry
; entry
= qlist_next(entry
), i
++) {
640 QType type
= qobject_type(entry
->value
);
641 bool composite
= (type
== QTYPE_QDICT
|| type
== QTYPE_QLIST
);
642 func_fprintf(f
, "%*s[%i]:%c", indentation
* 4, "", i
,
643 composite
? '\n' : ' ');
644 dump_qobject(func_fprintf
, f
, indentation
+ 1, entry
->value
);
646 func_fprintf(f
, "\n");
651 static void dump_qdict(fprintf_function func_fprintf
, void *f
, int indentation
,
654 const QDictEntry
*entry
;
656 for (entry
= qdict_first(dict
); entry
; entry
= qdict_next(dict
, entry
)) {
657 QType type
= qobject_type(entry
->value
);
658 bool composite
= (type
== QTYPE_QDICT
|| type
== QTYPE_QLIST
);
659 char *key
= g_malloc(strlen(entry
->key
) + 1);
662 /* replace dashes with spaces in key (variable) names */
663 for (i
= 0; entry
->key
[i
]; i
++) {
664 key
[i
] = entry
->key
[i
] == '-' ? ' ' : entry
->key
[i
];
667 func_fprintf(f
, "%*s%s:%c", indentation
* 4, "", key
,
668 composite
? '\n' : ' ');
669 dump_qobject(func_fprintf
, f
, indentation
+ 1, entry
->value
);
671 func_fprintf(f
, "\n");
677 void bdrv_image_info_specific_dump(fprintf_function func_fprintf
, void *f
,
678 ImageInfoSpecific
*info_spec
)
681 Visitor
*v
= qobject_output_visitor_new(&obj
);
683 visit_type_ImageInfoSpecific(v
, NULL
, &info_spec
, &error_abort
);
684 visit_complete(v
, &obj
);
685 data
= qdict_get(qobject_to_qdict(obj
), "data");
686 dump_qobject(func_fprintf
, f
, 1, data
);
691 void bdrv_image_info_dump(fprintf_function func_fprintf
, void *f
,
694 char size_buf
[128], dsize_buf
[128];
695 if (!info
->has_actual_size
) {
696 snprintf(dsize_buf
, sizeof(dsize_buf
), "unavailable");
698 get_human_readable_size(dsize_buf
, sizeof(dsize_buf
),
701 get_human_readable_size(size_buf
, sizeof(size_buf
), info
->virtual_size
);
705 "virtual size: %s (%" PRId64
" bytes)\n"
707 info
->filename
, info
->format
, size_buf
,
711 if (info
->has_encrypted
&& info
->encrypted
) {
712 func_fprintf(f
, "encrypted: yes\n");
715 if (info
->has_cluster_size
) {
716 func_fprintf(f
, "cluster_size: %" PRId64
"\n",
720 if (info
->has_dirty_flag
&& info
->dirty_flag
) {
721 func_fprintf(f
, "cleanly shut down: no\n");
724 if (info
->has_backing_filename
) {
725 func_fprintf(f
, "backing file: %s", info
->backing_filename
);
726 if (!info
->has_full_backing_filename
) {
727 func_fprintf(f
, " (cannot determine actual path)");
728 } else if (strcmp(info
->backing_filename
,
729 info
->full_backing_filename
) != 0) {
730 func_fprintf(f
, " (actual path: %s)", info
->full_backing_filename
);
732 func_fprintf(f
, "\n");
733 if (info
->has_backing_filename_format
) {
734 func_fprintf(f
, "backing file format: %s\n",
735 info
->backing_filename_format
);
739 if (info
->has_snapshots
) {
740 SnapshotInfoList
*elem
;
742 func_fprintf(f
, "Snapshot list:\n");
743 bdrv_snapshot_dump(func_fprintf
, f
, NULL
);
744 func_fprintf(f
, "\n");
746 /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
747 * we convert to the block layer's native QEMUSnapshotInfo for now.
749 for (elem
= info
->snapshots
; elem
; elem
= elem
->next
) {
750 QEMUSnapshotInfo sn
= {
751 .vm_state_size
= elem
->value
->vm_state_size
,
752 .date_sec
= elem
->value
->date_sec
,
753 .date_nsec
= elem
->value
->date_nsec
,
754 .vm_clock_nsec
= elem
->value
->vm_clock_sec
* 1000000000ULL +
755 elem
->value
->vm_clock_nsec
,
758 pstrcpy(sn
.id_str
, sizeof(sn
.id_str
), elem
->value
->id
);
759 pstrcpy(sn
.name
, sizeof(sn
.name
), elem
->value
->name
);
760 bdrv_snapshot_dump(func_fprintf
, f
, &sn
);
761 func_fprintf(f
, "\n");
765 if (info
->has_format_specific
) {
766 func_fprintf(f
, "Format specific information:\n");
767 bdrv_image_info_specific_dump(func_fprintf
, f
, info
->format_specific
);