qapi.c (7a9a5e72e8a62395649a46c53c3c224cc73ca52f) qapi.c (d5a8ee60a0fbc20a2c2d02f3bda1bb1bd365f1ee)
1/*
2 * Block layer qmp and info dump related functions
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
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

--- 17 unchanged lines hidden (view full) ---

26#include "block/block_int.h"
27#include "block/write-threshold.h"
28#include "qmp-commands.h"
29#include "qapi-visit.h"
30#include "qapi/qmp-output-visitor.h"
31#include "qapi/qmp/types.h"
32#include "sysemu/block-backend.h"
33
1/*
2 * Block layer qmp and info dump related functions
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
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

--- 17 unchanged lines hidden (view full) ---

26#include "block/block_int.h"
27#include "block/write-threshold.h"
28#include "qmp-commands.h"
29#include "qapi-visit.h"
30#include "qapi/qmp-output-visitor.h"
31#include "qapi/qmp/types.h"
32#include "sysemu/block-backend.h"
33
34BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
34BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)
35{
35{
36 ImageInfo **p_image_info;
37 BlockDriverState *bs0;
36 BlockDeviceInfo *info = g_malloc0(sizeof(*info));
37
38 info->file = g_strdup(bs->filename);
39 info->ro = bs->read_only;
40 info->drv = g_strdup(bs->drv->format_name);
41 info->encrypted = bs->encrypted;
42 info->encryption_key_missing = bdrv_key_required(bs);
43

--- 43 unchanged lines hidden (view full) ---

87 info->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max;
88
89 info->has_iops_size = cfg.op_size;
90 info->iops_size = cfg.op_size;
91 }
92
93 info->write_threshold = bdrv_write_threshold_get(bs);
94
38 BlockDeviceInfo *info = g_malloc0(sizeof(*info));
39
40 info->file = g_strdup(bs->filename);
41 info->ro = bs->read_only;
42 info->drv = g_strdup(bs->drv->format_name);
43 info->encrypted = bs->encrypted;
44 info->encryption_key_missing = bdrv_key_required(bs);
45

--- 43 unchanged lines hidden (view full) ---

89 info->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max;
90
91 info->has_iops_size = cfg.op_size;
92 info->iops_size = cfg.op_size;
93 }
94
95 info->write_threshold = bdrv_write_threshold_get(bs);
96
97 bs0 = bs;
98 p_image_info = &info->image;
99 while (1) {
100 Error *local_err = NULL;
101 bdrv_query_image_info(bs0, p_image_info, &local_err);
102 if (local_err) {
103 error_propagate(errp, local_err);
104 qapi_free_BlockDeviceInfo(info);
105 return NULL;
106 }
107 if (bs0->drv && bs0->backing_hd) {
108 bs0 = bs0->backing_hd;
109 (*p_image_info)->has_backing_image = true;
110 p_image_info = &((*p_image_info)->backing_image);
111 } else {
112 break;
113 }
114 }
115
95 return info;
96}
97
98/*
99 * Returns 0 on success, with *p_list either set to describe snapshot
100 * information, or NULL because there are no snapshots. Returns -errno on
101 * error, with *p_list untouched.
102 */

--- 156 unchanged lines hidden (view full) ---

259}
260
261/* @p_info will be set only on success. */
262static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
263 Error **errp)
264{
265 BlockInfo *info = g_malloc0(sizeof(*info));
266 BlockDriverState *bs = blk_bs(blk);
116 return info;
117}
118
119/*
120 * Returns 0 on success, with *p_list either set to describe snapshot
121 * information, or NULL because there are no snapshots. Returns -errno on
122 * error, with *p_list untouched.
123 */

--- 156 unchanged lines hidden (view full) ---

280}
281
282/* @p_info will be set only on success. */
283static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
284 Error **errp)
285{
286 BlockInfo *info = g_malloc0(sizeof(*info));
287 BlockDriverState *bs = blk_bs(blk);
267 BlockDriverState *bs0;
268 ImageInfo **p_image_info;
269 Error *local_err = NULL;
270 info->device = g_strdup(blk_name(blk));
271 info->type = g_strdup("unknown");
272 info->locked = blk_dev_is_medium_locked(blk);
273 info->removable = blk_dev_has_removable_media(blk);
274
275 if (blk_dev_has_removable_media(blk)) {
276 info->has_tray_open = true;
277 info->tray_open = blk_dev_is_tray_open(blk);

--- 6 unchanged lines hidden (view full) ---

284
285 if (!QLIST_EMPTY(&bs->dirty_bitmaps)) {
286 info->has_dirty_bitmaps = true;
287 info->dirty_bitmaps = bdrv_query_dirty_bitmaps(bs);
288 }
289
290 if (bs->drv) {
291 info->has_inserted = true;
288 info->device = g_strdup(blk_name(blk));
289 info->type = g_strdup("unknown");
290 info->locked = blk_dev_is_medium_locked(blk);
291 info->removable = blk_dev_has_removable_media(blk);
292
293 if (blk_dev_has_removable_media(blk)) {
294 info->has_tray_open = true;
295 info->tray_open = blk_dev_is_tray_open(blk);

--- 6 unchanged lines hidden (view full) ---

302
303 if (!QLIST_EMPTY(&bs->dirty_bitmaps)) {
304 info->has_dirty_bitmaps = true;
305 info->dirty_bitmaps = bdrv_query_dirty_bitmaps(bs);
306 }
307
308 if (bs->drv) {
309 info->has_inserted = true;
292 info->inserted = bdrv_block_device_info(bs);
293
294 bs0 = bs;
295 p_image_info = &info->inserted->image;
296 while (1) {
297 bdrv_query_image_info(bs0, p_image_info, &local_err);
298 if (local_err) {
299 error_propagate(errp, local_err);
300 goto err;
301 }
302 if (bs0->drv && bs0->backing_hd) {
303 bs0 = bs0->backing_hd;
304 (*p_image_info)->has_backing_image = true;
305 p_image_info = &((*p_image_info)->backing_image);
306 } else {
307 break;
308 }
310 info->inserted = bdrv_block_device_info(bs, errp);
311 if (info->inserted == NULL) {
312 goto err;
309 }
310 }
311
312 *p_info = info;
313 return;
314
315 err:
316 qapi_free_BlockInfo(info);

--- 349 unchanged lines hidden ---
313 }
314 }
315
316 *p_info = info;
317 return;
318
319 err:
320 qapi_free_BlockInfo(info);

--- 349 unchanged lines hidden ---