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 "qemu/cutils.h"
27 #include "block/qapi.h"
28 #include "block/block_int.h"
29 #include "block/throttle-groups.h"
30 #include "block/write-threshold.h"
31 #include "qapi/error.h"
32 #include "qapi/qapi-commands-block-core.h"
33 #include "qapi/qobject-output-visitor.h"
34 #include "qapi/qapi-visit-block-core.h"
35 #include "qapi/qmp/qbool.h"
36 #include "qapi/qmp/qdict.h"
37 #include "qapi/qmp/qlist.h"
38 #include "qapi/qmp/qnum.h"
39 #include "qapi/qmp/qstring.h"
40 #include "qemu/qemu-print.h"
41 #include "sysemu/block-backend.h"
42 #include "qemu/cutils.h"
44 BlockDeviceInfo
*bdrv_block_device_info(BlockBackend
*blk
,
49 ImageInfo
**p_image_info
;
50 BlockDriverState
*bs0
, *backing
;
51 BlockDeviceInfo
*info
;
54 error_setg(errp
, "Block device %s is ejected", bs
->node_name
);
58 bdrv_refresh_filename(bs
);
60 info
= g_malloc0(sizeof(*info
));
61 info
->file
= g_strdup(bs
->filename
);
62 info
->ro
= bdrv_is_read_only(bs
);
63 info
->drv
= g_strdup(bs
->drv
->format_name
);
64 info
->encrypted
= bs
->encrypted
;
66 info
->cache
= g_new(BlockdevCacheInfo
, 1);
67 *info
->cache
= (BlockdevCacheInfo
) {
68 .writeback
= blk
? blk_enable_write_cache(blk
) : true,
69 .direct
= !!(bs
->open_flags
& BDRV_O_NOCACHE
),
70 .no_flush
= !!(bs
->open_flags
& BDRV_O_NO_FLUSH
),
73 if (bs
->node_name
[0]) {
74 info
->node_name
= g_strdup(bs
->node_name
);
77 backing
= bdrv_cow_bs(bs
);
79 info
->backing_file
= g_strdup(backing
->filename
);
82 if (!QLIST_EMPTY(&bs
->dirty_bitmaps
)) {
83 info
->has_dirty_bitmaps
= true;
84 info
->dirty_bitmaps
= bdrv_query_dirty_bitmaps(bs
);
87 info
->detect_zeroes
= bs
->detect_zeroes
;
89 if (blk
&& blk_get_public(blk
)->throttle_group_member
.throttle_state
) {
91 BlockBackendPublic
*blkp
= blk_get_public(blk
);
93 throttle_group_get_config(&blkp
->throttle_group_member
, &cfg
);
95 info
->bps
= cfg
.buckets
[THROTTLE_BPS_TOTAL
].avg
;
96 info
->bps_rd
= cfg
.buckets
[THROTTLE_BPS_READ
].avg
;
97 info
->bps_wr
= cfg
.buckets
[THROTTLE_BPS_WRITE
].avg
;
99 info
->iops
= cfg
.buckets
[THROTTLE_OPS_TOTAL
].avg
;
100 info
->iops_rd
= cfg
.buckets
[THROTTLE_OPS_READ
].avg
;
101 info
->iops_wr
= cfg
.buckets
[THROTTLE_OPS_WRITE
].avg
;
103 info
->has_bps_max
= cfg
.buckets
[THROTTLE_BPS_TOTAL
].max
;
104 info
->bps_max
= cfg
.buckets
[THROTTLE_BPS_TOTAL
].max
;
105 info
->has_bps_rd_max
= cfg
.buckets
[THROTTLE_BPS_READ
].max
;
106 info
->bps_rd_max
= cfg
.buckets
[THROTTLE_BPS_READ
].max
;
107 info
->has_bps_wr_max
= cfg
.buckets
[THROTTLE_BPS_WRITE
].max
;
108 info
->bps_wr_max
= cfg
.buckets
[THROTTLE_BPS_WRITE
].max
;
110 info
->has_iops_max
= cfg
.buckets
[THROTTLE_OPS_TOTAL
].max
;
111 info
->iops_max
= cfg
.buckets
[THROTTLE_OPS_TOTAL
].max
;
112 info
->has_iops_rd_max
= cfg
.buckets
[THROTTLE_OPS_READ
].max
;
113 info
->iops_rd_max
= cfg
.buckets
[THROTTLE_OPS_READ
].max
;
114 info
->has_iops_wr_max
= cfg
.buckets
[THROTTLE_OPS_WRITE
].max
;
115 info
->iops_wr_max
= cfg
.buckets
[THROTTLE_OPS_WRITE
].max
;
117 info
->has_bps_max_length
= info
->has_bps_max
;
118 info
->bps_max_length
=
119 cfg
.buckets
[THROTTLE_BPS_TOTAL
].burst_length
;
120 info
->has_bps_rd_max_length
= info
->has_bps_rd_max
;
121 info
->bps_rd_max_length
=
122 cfg
.buckets
[THROTTLE_BPS_READ
].burst_length
;
123 info
->has_bps_wr_max_length
= info
->has_bps_wr_max
;
124 info
->bps_wr_max_length
=
125 cfg
.buckets
[THROTTLE_BPS_WRITE
].burst_length
;
127 info
->has_iops_max_length
= info
->has_iops_max
;
128 info
->iops_max_length
=
129 cfg
.buckets
[THROTTLE_OPS_TOTAL
].burst_length
;
130 info
->has_iops_rd_max_length
= info
->has_iops_rd_max
;
131 info
->iops_rd_max_length
=
132 cfg
.buckets
[THROTTLE_OPS_READ
].burst_length
;
133 info
->has_iops_wr_max_length
= info
->has_iops_wr_max
;
134 info
->iops_wr_max_length
=
135 cfg
.buckets
[THROTTLE_OPS_WRITE
].burst_length
;
137 info
->has_iops_size
= cfg
.op_size
;
138 info
->iops_size
= cfg
.op_size
;
141 g_strdup(throttle_group_get_name(&blkp
->throttle_group_member
));
144 info
->write_threshold
= bdrv_write_threshold_get(bs
);
147 p_image_info
= &info
->image
;
148 info
->backing_file_depth
= 0;
150 Error
*local_err
= NULL
;
151 bdrv_query_image_info(bs0
, p_image_info
, &local_err
);
153 error_propagate(errp
, local_err
);
154 qapi_free_BlockDeviceInfo(info
);
158 /* stop gathering data for flat output */
163 if (bs0
->drv
&& bdrv_filter_or_cow_child(bs0
)) {
165 * Put any filtered child here (for backwards compatibility to when
166 * we put bs0->backing here, which might be any filtered child).
168 info
->backing_file_depth
++;
169 bs0
= bdrv_filter_or_cow_bs(bs0
);
170 p_image_info
= &((*p_image_info
)->backing_image
);
175 /* Skip automatically inserted nodes that the user isn't aware of for
176 * query-block (blk != NULL), but not for query-named-block-nodes */
178 bs0
= bdrv_skip_implicit_filters(bs0
);
186 * Returns 0 on success, with *p_list either set to describe snapshot
187 * information, or NULL because there are no snapshots. Returns -errno on
188 * error, with *p_list untouched.
190 int bdrv_query_snapshot_info_list(BlockDriverState
*bs
,
191 SnapshotInfoList
**p_list
,
195 QEMUSnapshotInfo
*sn_tab
= NULL
;
196 SnapshotInfoList
*head
= NULL
, **tail
= &head
;
199 sn_count
= bdrv_snapshot_list(bs
, &sn_tab
);
201 const char *dev
= bdrv_get_device_name(bs
);
204 error_setg(errp
, "Device '%s' is not inserted", dev
);
208 "Device '%s' does not support internal snapshots",
212 error_setg_errno(errp
, -sn_count
,
213 "Can't list snapshots of device '%s'", dev
);
219 for (i
= 0; i
< sn_count
; i
++) {
220 info
= g_new0(SnapshotInfo
, 1);
221 info
->id
= g_strdup(sn_tab
[i
].id_str
);
222 info
->name
= g_strdup(sn_tab
[i
].name
);
223 info
->vm_state_size
= sn_tab
[i
].vm_state_size
;
224 info
->date_sec
= sn_tab
[i
].date_sec
;
225 info
->date_nsec
= sn_tab
[i
].date_nsec
;
226 info
->vm_clock_sec
= sn_tab
[i
].vm_clock_nsec
/ 1000000000;
227 info
->vm_clock_nsec
= sn_tab
[i
].vm_clock_nsec
% 1000000000;
228 info
->icount
= sn_tab
[i
].icount
;
229 info
->has_icount
= sn_tab
[i
].icount
!= -1ULL;
231 QAPI_LIST_APPEND(tail
, info
);
240 * bdrv_query_image_info:
241 * @bs: block device to examine
242 * @p_info: location to store image information
243 * @errp: location to store error information
245 * Store "flat" image information in @p_info.
247 * "Flat" means it does *not* query backing image information,
248 * i.e. (*pinfo)->has_backing_image will be set to false and
249 * (*pinfo)->backing_image to NULL even when the image does in fact have
252 * @p_info will be set only on success. On error, store error in @errp.
254 void bdrv_query_image_info(BlockDriverState
*bs
,
259 const char *backing_filename
;
265 aio_context_acquire(bdrv_get_aio_context(bs
));
267 size
= bdrv_getlength(bs
);
269 error_setg_errno(errp
, -size
, "Can't get image size '%s'",
274 bdrv_refresh_filename(bs
);
276 info
= g_new0(ImageInfo
, 1);
277 info
->filename
= g_strdup(bs
->filename
);
278 info
->format
= g_strdup(bdrv_get_format_name(bs
));
279 info
->virtual_size
= size
;
280 info
->actual_size
= bdrv_get_allocated_file_size(bs
);
281 info
->has_actual_size
= info
->actual_size
>= 0;
283 info
->encrypted
= true;
284 info
->has_encrypted
= true;
286 if (bdrv_get_info(bs
, &bdi
) >= 0) {
287 if (bdi
.cluster_size
!= 0) {
288 info
->cluster_size
= bdi
.cluster_size
;
289 info
->has_cluster_size
= true;
291 info
->dirty_flag
= bdi
.is_dirty
;
292 info
->has_dirty_flag
= true;
294 info
->format_specific
= bdrv_get_specific_info(bs
, &err
);
296 error_propagate(errp
, err
);
297 qapi_free_ImageInfo(info
);
300 backing_filename
= bs
->backing_file
;
301 if (backing_filename
[0] != '\0') {
302 char *backing_filename2
;
304 info
->backing_filename
= g_strdup(backing_filename
);
305 backing_filename2
= bdrv_get_full_backing_filename(bs
, NULL
);
307 /* Always report the full_backing_filename if present, even if it's the
308 * same as backing_filename. That they are same is useful info. */
309 if (backing_filename2
) {
310 info
->full_backing_filename
= g_strdup(backing_filename2
);
313 if (bs
->backing_format
[0]) {
314 info
->backing_filename_format
= g_strdup(bs
->backing_format
);
316 g_free(backing_filename2
);
319 ret
= bdrv_query_snapshot_info_list(bs
, &info
->snapshots
, &err
);
322 if (info
->snapshots
) {
323 info
->has_snapshots
= true;
326 /* recoverable error */
332 error_propagate(errp
, err
);
333 qapi_free_ImageInfo(info
);
340 aio_context_release(bdrv_get_aio_context(bs
));
343 /* @p_info will be set only on success. */
344 static void bdrv_query_info(BlockBackend
*blk
, BlockInfo
**p_info
,
347 BlockInfo
*info
= g_malloc0(sizeof(*info
));
348 BlockDriverState
*bs
= blk_bs(blk
);
351 /* Skip automatically inserted nodes that the user isn't aware of */
352 bs
= bdrv_skip_implicit_filters(bs
);
354 info
->device
= g_strdup(blk_name(blk
));
355 info
->type
= g_strdup("unknown");
356 info
->locked
= blk_dev_is_medium_locked(blk
);
357 info
->removable
= blk_dev_has_removable_media(blk
);
359 qdev
= blk_get_attached_dev_id(blk
);
366 if (blk_dev_has_tray(blk
)) {
367 info
->has_tray_open
= true;
368 info
->tray_open
= blk_dev_is_tray_open(blk
);
371 if (blk_iostatus_is_enabled(blk
)) {
372 info
->has_io_status
= true;
373 info
->io_status
= blk_iostatus(blk
);
377 info
->inserted
= bdrv_block_device_info(blk
, bs
, false, errp
);
378 if (info
->inserted
== NULL
) {
387 qapi_free_BlockInfo(info
);
390 static uint64List
*uint64_list(uint64_t *list
, int size
)
393 uint64List
*out_list
= NULL
;
394 uint64List
**tail
= &out_list
;
396 for (i
= 0; i
< size
; i
++) {
397 QAPI_LIST_APPEND(tail
, list
[i
]);
403 static BlockLatencyHistogramInfo
*
404 bdrv_latency_histogram_stats(BlockLatencyHistogram
*hist
)
406 BlockLatencyHistogramInfo
*info
;
412 info
= g_new0(BlockLatencyHistogramInfo
, 1);
413 info
->boundaries
= uint64_list(hist
->boundaries
, hist
->nbins
- 1);
414 info
->bins
= uint64_list(hist
->bins
, hist
->nbins
);
418 static void bdrv_query_blk_stats(BlockDeviceStats
*ds
, BlockBackend
*blk
)
420 BlockAcctStats
*stats
= blk_get_stats(blk
);
421 BlockAcctTimedStats
*ts
= NULL
;
422 BlockLatencyHistogram
*hgram
;
424 ds
->rd_bytes
= stats
->nr_bytes
[BLOCK_ACCT_READ
];
425 ds
->wr_bytes
= stats
->nr_bytes
[BLOCK_ACCT_WRITE
];
426 ds
->unmap_bytes
= stats
->nr_bytes
[BLOCK_ACCT_UNMAP
];
427 ds
->rd_operations
= stats
->nr_ops
[BLOCK_ACCT_READ
];
428 ds
->wr_operations
= stats
->nr_ops
[BLOCK_ACCT_WRITE
];
429 ds
->unmap_operations
= stats
->nr_ops
[BLOCK_ACCT_UNMAP
];
431 ds
->failed_rd_operations
= stats
->failed_ops
[BLOCK_ACCT_READ
];
432 ds
->failed_wr_operations
= stats
->failed_ops
[BLOCK_ACCT_WRITE
];
433 ds
->failed_flush_operations
= stats
->failed_ops
[BLOCK_ACCT_FLUSH
];
434 ds
->failed_unmap_operations
= stats
->failed_ops
[BLOCK_ACCT_UNMAP
];
436 ds
->invalid_rd_operations
= stats
->invalid_ops
[BLOCK_ACCT_READ
];
437 ds
->invalid_wr_operations
= stats
->invalid_ops
[BLOCK_ACCT_WRITE
];
438 ds
->invalid_flush_operations
=
439 stats
->invalid_ops
[BLOCK_ACCT_FLUSH
];
440 ds
->invalid_unmap_operations
= stats
->invalid_ops
[BLOCK_ACCT_UNMAP
];
442 ds
->rd_merged
= stats
->merged
[BLOCK_ACCT_READ
];
443 ds
->wr_merged
= stats
->merged
[BLOCK_ACCT_WRITE
];
444 ds
->unmap_merged
= stats
->merged
[BLOCK_ACCT_UNMAP
];
445 ds
->flush_operations
= stats
->nr_ops
[BLOCK_ACCT_FLUSH
];
446 ds
->wr_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_WRITE
];
447 ds
->rd_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_READ
];
448 ds
->flush_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_FLUSH
];
449 ds
->unmap_total_time_ns
= stats
->total_time_ns
[BLOCK_ACCT_UNMAP
];
451 ds
->has_idle_time_ns
= stats
->last_access_time_ns
> 0;
452 if (ds
->has_idle_time_ns
) {
453 ds
->idle_time_ns
= block_acct_idle_time_ns(stats
);
456 ds
->account_invalid
= stats
->account_invalid
;
457 ds
->account_failed
= stats
->account_failed
;
459 while ((ts
= block_acct_interval_next(stats
, ts
))) {
460 BlockDeviceTimedStats
*dev_stats
= g_malloc0(sizeof(*dev_stats
));
462 TimedAverage
*rd
= &ts
->latency
[BLOCK_ACCT_READ
];
463 TimedAverage
*wr
= &ts
->latency
[BLOCK_ACCT_WRITE
];
464 TimedAverage
*fl
= &ts
->latency
[BLOCK_ACCT_FLUSH
];
466 dev_stats
->interval_length
= ts
->interval_length
;
468 dev_stats
->min_rd_latency_ns
= timed_average_min(rd
);
469 dev_stats
->max_rd_latency_ns
= timed_average_max(rd
);
470 dev_stats
->avg_rd_latency_ns
= timed_average_avg(rd
);
472 dev_stats
->min_wr_latency_ns
= timed_average_min(wr
);
473 dev_stats
->max_wr_latency_ns
= timed_average_max(wr
);
474 dev_stats
->avg_wr_latency_ns
= timed_average_avg(wr
);
476 dev_stats
->min_flush_latency_ns
= timed_average_min(fl
);
477 dev_stats
->max_flush_latency_ns
= timed_average_max(fl
);
478 dev_stats
->avg_flush_latency_ns
= timed_average_avg(fl
);
480 dev_stats
->avg_rd_queue_depth
=
481 block_acct_queue_depth(ts
, BLOCK_ACCT_READ
);
482 dev_stats
->avg_wr_queue_depth
=
483 block_acct_queue_depth(ts
, BLOCK_ACCT_WRITE
);
485 QAPI_LIST_PREPEND(ds
->timed_stats
, dev_stats
);
488 hgram
= stats
->latency_histogram
;
489 ds
->rd_latency_histogram
490 = bdrv_latency_histogram_stats(&hgram
[BLOCK_ACCT_READ
]);
491 ds
->wr_latency_histogram
492 = bdrv_latency_histogram_stats(&hgram
[BLOCK_ACCT_WRITE
]);
493 ds
->flush_latency_histogram
494 = bdrv_latency_histogram_stats(&hgram
[BLOCK_ACCT_FLUSH
]);
497 static BlockStats
*bdrv_query_bds_stats(BlockDriverState
*bs
,
500 BdrvChild
*parent_child
;
501 BlockDriverState
*filter_or_cow_bs
;
502 BlockStats
*s
= NULL
;
504 s
= g_malloc0(sizeof(*s
));
505 s
->stats
= g_malloc0(sizeof(*s
->stats
));
511 /* Skip automatically inserted nodes that the user isn't aware of in
512 * a BlockBackend-level command. Stay at the exact node for a node-level
515 bs
= bdrv_skip_implicit_filters(bs
);
518 if (bdrv_get_node_name(bs
)[0]) {
519 s
->node_name
= g_strdup(bdrv_get_node_name(bs
));
522 s
->stats
->wr_highest_offset
= stat64_get(&bs
->wr_highest_offset
);
524 s
->driver_specific
= bdrv_get_specific_stats(bs
);
526 parent_child
= bdrv_primary_child(bs
);
528 !(parent_child
->role
& (BDRV_CHILD_DATA
| BDRV_CHILD_FILTERED
)))
533 * Look for a unique data-storing child. We do not need to look for
534 * filtered children, as there would be only one and it would have been
538 QLIST_FOREACH(c
, &bs
->children
, next
) {
539 if (c
->role
& BDRV_CHILD_DATA
) {
542 * There are multiple data-storing children and we cannot
543 * choose between them.
553 s
->parent
= bdrv_query_bds_stats(parent_child
->bs
, blk_level
);
556 filter_or_cow_bs
= bdrv_filter_or_cow_bs(bs
);
557 if (blk_level
&& filter_or_cow_bs
) {
559 * Put any filtered or COW child here (for backwards
560 * compatibility to when we put bs0->backing here, which might
563 s
->backing
= bdrv_query_bds_stats(filter_or_cow_bs
, blk_level
);
569 BlockInfoList
*qmp_query_block(Error
**errp
)
571 BlockInfoList
*head
= NULL
, **p_next
= &head
;
573 Error
*local_err
= NULL
;
575 for (blk
= blk_all_next(NULL
); blk
; blk
= blk_all_next(blk
)) {
578 if (!*blk_name(blk
) && !blk_get_attached_dev(blk
)) {
582 info
= g_malloc0(sizeof(*info
));
583 bdrv_query_info(blk
, &info
->value
, &local_err
);
585 error_propagate(errp
, local_err
);
587 qapi_free_BlockInfoList(head
);
592 p_next
= &info
->next
;
598 BlockStatsList
*qmp_query_blockstats(bool has_query_nodes
,
602 BlockStatsList
*head
= NULL
, **tail
= &head
;
604 BlockDriverState
*bs
;
606 /* Just to be safe if query_nodes is not always initialized */
607 if (has_query_nodes
&& query_nodes
) {
608 for (bs
= bdrv_next_node(NULL
); bs
; bs
= bdrv_next_node(bs
)) {
609 AioContext
*ctx
= bdrv_get_aio_context(bs
);
611 aio_context_acquire(ctx
);
612 QAPI_LIST_APPEND(tail
, bdrv_query_bds_stats(bs
, false));
613 aio_context_release(ctx
);
616 for (blk
= blk_all_next(NULL
); blk
; blk
= blk_all_next(blk
)) {
617 AioContext
*ctx
= blk_get_aio_context(blk
);
621 if (!*blk_name(blk
) && !blk_get_attached_dev(blk
)) {
625 aio_context_acquire(ctx
);
626 s
= bdrv_query_bds_stats(blk_bs(blk
), true);
627 s
->device
= g_strdup(blk_name(blk
));
629 qdev
= blk_get_attached_dev_id(blk
);
636 bdrv_query_blk_stats(s
->stats
, blk
);
637 aio_context_release(ctx
);
639 QAPI_LIST_APPEND(tail
, s
);
646 void bdrv_snapshot_dump(QEMUSnapshotInfo
*sn
)
649 char icount_buf
[128] = {0};
654 qemu_printf("%-10s%-17s%8s%20s%13s%11s",
655 "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK", "ICOUNT");
657 g_autoptr(GDateTime
) date
= g_date_time_new_from_unix_local(sn
->date_sec
);
658 g_autofree
char *date_buf
= g_date_time_format(date
, "%Y-%m-%d %H:%M:%S");
660 secs
= sn
->vm_clock_nsec
/ 1000000000;
661 snprintf(clock_buf
, sizeof(clock_buf
),
662 "%02d:%02d:%02d.%03d",
664 (int)((secs
/ 60) % 60),
666 (int)((sn
->vm_clock_nsec
/ 1000000) % 1000));
667 sizing
= size_to_str(sn
->vm_state_size
);
668 if (sn
->icount
!= -1ULL) {
669 snprintf(icount_buf
, sizeof(icount_buf
),
670 "%"PRId64
, sn
->icount
);
672 qemu_printf("%-9s %-16s %8s%20s%13s%11s",
673 sn
->id_str
, sn
->name
,
682 static void dump_qdict(int indentation
, QDict
*dict
);
683 static void dump_qlist(int indentation
, QList
*list
);
685 static void dump_qobject(int comp_indent
, QObject
*obj
)
687 switch (qobject_type(obj
)) {
689 QNum
*value
= qobject_to(QNum
, obj
);
690 char *tmp
= qnum_to_string(value
);
691 qemu_printf("%s", tmp
);
695 case QTYPE_QSTRING
: {
696 QString
*value
= qobject_to(QString
, obj
);
697 qemu_printf("%s", qstring_get_str(value
));
701 QDict
*value
= qobject_to(QDict
, obj
);
702 dump_qdict(comp_indent
, value
);
706 QList
*value
= qobject_to(QList
, obj
);
707 dump_qlist(comp_indent
, value
);
711 QBool
*value
= qobject_to(QBool
, obj
);
712 qemu_printf("%s", qbool_get_bool(value
) ? "true" : "false");
720 static void dump_qlist(int indentation
, QList
*list
)
722 const QListEntry
*entry
;
725 for (entry
= qlist_first(list
); entry
; entry
= qlist_next(entry
), i
++) {
726 QType type
= qobject_type(entry
->value
);
727 bool composite
= (type
== QTYPE_QDICT
|| type
== QTYPE_QLIST
);
728 qemu_printf("%*s[%i]:%c", indentation
* 4, "", i
,
729 composite
? '\n' : ' ');
730 dump_qobject(indentation
+ 1, entry
->value
);
737 static void dump_qdict(int indentation
, QDict
*dict
)
739 const QDictEntry
*entry
;
741 for (entry
= qdict_first(dict
); entry
; entry
= qdict_next(dict
, entry
)) {
742 QType type
= qobject_type(entry
->value
);
743 bool composite
= (type
== QTYPE_QDICT
|| type
== QTYPE_QLIST
);
744 char *key
= g_malloc(strlen(entry
->key
) + 1);
747 /* replace dashes with spaces in key (variable) names */
748 for (i
= 0; entry
->key
[i
]; i
++) {
749 key
[i
] = entry
->key
[i
] == '-' ? ' ' : entry
->key
[i
];
752 qemu_printf("%*s%s:%c", indentation
* 4, "", key
,
753 composite
? '\n' : ' ');
754 dump_qobject(indentation
+ 1, entry
->value
);
762 void bdrv_image_info_specific_dump(ImageInfoSpecific
*info_spec
)
765 Visitor
*v
= qobject_output_visitor_new(&obj
);
767 visit_type_ImageInfoSpecific(v
, NULL
, &info_spec
, &error_abort
);
768 visit_complete(v
, &obj
);
769 data
= qdict_get(qobject_to(QDict
, obj
), "data");
770 dump_qobject(1, data
);
775 void bdrv_image_info_dump(ImageInfo
*info
)
777 char *size_buf
, *dsize_buf
;
778 if (!info
->has_actual_size
) {
779 dsize_buf
= g_strdup("unavailable");
781 dsize_buf
= size_to_str(info
->actual_size
);
783 size_buf
= size_to_str(info
->virtual_size
);
784 qemu_printf("image: %s\n"
786 "virtual size: %s (%" PRId64
" bytes)\n"
788 info
->filename
, info
->format
, size_buf
,
794 if (info
->has_encrypted
&& info
->encrypted
) {
795 qemu_printf("encrypted: yes\n");
798 if (info
->has_cluster_size
) {
799 qemu_printf("cluster_size: %" PRId64
"\n",
803 if (info
->has_dirty_flag
&& info
->dirty_flag
) {
804 qemu_printf("cleanly shut down: no\n");
807 if (info
->backing_filename
) {
808 qemu_printf("backing file: %s", info
->backing_filename
);
809 if (!info
->full_backing_filename
) {
810 qemu_printf(" (cannot determine actual path)");
811 } else if (strcmp(info
->backing_filename
,
812 info
->full_backing_filename
) != 0) {
813 qemu_printf(" (actual path: %s)", info
->full_backing_filename
);
816 if (info
->backing_filename_format
) {
817 qemu_printf("backing file format: %s\n",
818 info
->backing_filename_format
);
822 if (info
->has_snapshots
) {
823 SnapshotInfoList
*elem
;
825 qemu_printf("Snapshot list:\n");
826 bdrv_snapshot_dump(NULL
);
829 /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
830 * we convert to the block layer's native QEMUSnapshotInfo for now.
832 for (elem
= info
->snapshots
; elem
; elem
= elem
->next
) {
833 QEMUSnapshotInfo sn
= {
834 .vm_state_size
= elem
->value
->vm_state_size
,
835 .date_sec
= elem
->value
->date_sec
,
836 .date_nsec
= elem
->value
->date_nsec
,
837 .vm_clock_nsec
= elem
->value
->vm_clock_sec
* 1000000000ULL +
838 elem
->value
->vm_clock_nsec
,
839 .icount
= elem
->value
->has_icount
?
840 elem
->value
->icount
: -1ULL,
843 pstrcpy(sn
.id_str
, sizeof(sn
.id_str
), elem
->value
->id
);
844 pstrcpy(sn
.name
, sizeof(sn
.name
), elem
->value
->name
);
845 bdrv_snapshot_dump(&sn
);
850 if (info
->format_specific
) {
851 qemu_printf("Format specific information:\n");
852 bdrv_image_info_specific_dump(info
->format_specific
);