Revision c13163fb

b/block.c
32 32
#include "sysemu/sysemu.h"
33 33
#include "qemu/notify.h"
34 34
#include "block/coroutine.h"
35
#include "block/qapi.h"
35 36
#include "qmp-commands.h"
36 37
#include "qemu/timer.h"
37 38

  
......
3291 3292
    return NULL;
3292 3293
}
3293 3294

  
3295
/* Put this QMP function here so it can access the static graph_bdrv_states. */
3296
BlockDeviceInfoList *bdrv_named_nodes_list(void)
3297
{
3298
    BlockDeviceInfoList *list, *entry;
3299
    BlockDriverState *bs;
3300

  
3301
    list = NULL;
3302
    QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) {
3303
        entry = g_malloc0(sizeof(*entry));
3304
        entry->value = bdrv_block_device_info(bs);
3305
        entry->next = list;
3306
        list = entry;
3307
    }
3308

  
3309
    return list;
3310
}
3311

  
3294 3312
BlockDriverState *bdrv_next(BlockDriverState *bs)
3295 3313
{
3296 3314
    if (!bs) {
b/block/qapi.c
29 29
#include "qapi/qmp-output-visitor.h"
30 30
#include "qapi/qmp/types.h"
31 31

  
32
BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
33
{
34
    BlockDeviceInfo *info = g_malloc0(sizeof(*info));
35

  
36
    info->file                   = g_strdup(bs->filename);
37
    info->ro                     = bs->read_only;
38
    info->drv                    = g_strdup(bs->drv->format_name);
39
    info->encrypted              = bs->encrypted;
40
    info->encryption_key_missing = bdrv_key_required(bs);
41

  
42
    if (bs->node_name[0]) {
43
        info->has_node_name = true;
44
        info->node_name = g_strdup(bs->node_name);
45
    }
46

  
47
    if (bs->backing_file[0]) {
48
        info->has_backing_file = true;
49
        info->backing_file = g_strdup(bs->backing_file);
50
    }
51

  
52
    info->backing_file_depth = bdrv_get_backing_file_depth(bs);
53

  
54
    if (bs->io_limits_enabled) {
55
        ThrottleConfig cfg;
56
        throttle_get_config(&bs->throttle_state, &cfg);
57
        info->bps     = cfg.buckets[THROTTLE_BPS_TOTAL].avg;
58
        info->bps_rd  = cfg.buckets[THROTTLE_BPS_READ].avg;
59
        info->bps_wr  = cfg.buckets[THROTTLE_BPS_WRITE].avg;
60

  
61
        info->iops    = cfg.buckets[THROTTLE_OPS_TOTAL].avg;
62
        info->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg;
63
        info->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg;
64

  
65
        info->has_bps_max     = cfg.buckets[THROTTLE_BPS_TOTAL].max;
66
        info->bps_max         = cfg.buckets[THROTTLE_BPS_TOTAL].max;
67
        info->has_bps_rd_max  = cfg.buckets[THROTTLE_BPS_READ].max;
68
        info->bps_rd_max      = cfg.buckets[THROTTLE_BPS_READ].max;
69
        info->has_bps_wr_max  = cfg.buckets[THROTTLE_BPS_WRITE].max;
70
        info->bps_wr_max      = cfg.buckets[THROTTLE_BPS_WRITE].max;
71

  
72
        info->has_iops_max    = cfg.buckets[THROTTLE_OPS_TOTAL].max;
73
        info->iops_max        = cfg.buckets[THROTTLE_OPS_TOTAL].max;
74
        info->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max;
75
        info->iops_rd_max     = cfg.buckets[THROTTLE_OPS_READ].max;
76
        info->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max;
77
        info->iops_wr_max     = cfg.buckets[THROTTLE_OPS_WRITE].max;
78

  
79
        info->has_iops_size = cfg.op_size;
80
        info->iops_size = cfg.op_size;
81
    }
82

  
83
    return info;
84
}
85

  
32 86
/*
33 87
 * Returns 0 on success, with *p_list either set to describe snapshot
34 88
 * information, or NULL because there are no snapshots.  Returns -errno on
......
211 265

  
212 266
    if (bs->drv) {
213 267
        info->has_inserted = true;
214
        info->inserted = g_malloc0(sizeof(*info->inserted));
215
        info->inserted->file = g_strdup(bs->filename);
216
        info->inserted->ro = bs->read_only;
217
        info->inserted->drv = g_strdup(bs->drv->format_name);
218
        info->inserted->encrypted = bs->encrypted;
219
        info->inserted->encryption_key_missing = bdrv_key_required(bs);
220

  
221
        if (bs->backing_file[0]) {
222
            info->inserted->has_backing_file = true;
223
            info->inserted->backing_file = g_strdup(bs->backing_file);
224
        }
225

  
226
        info->inserted->backing_file_depth = bdrv_get_backing_file_depth(bs);
227

  
228
        if (bs->io_limits_enabled) {
229
            ThrottleConfig cfg;
230
            throttle_get_config(&bs->throttle_state, &cfg);
231
            info->inserted->bps     = cfg.buckets[THROTTLE_BPS_TOTAL].avg;
232
            info->inserted->bps_rd  = cfg.buckets[THROTTLE_BPS_READ].avg;
233
            info->inserted->bps_wr  = cfg.buckets[THROTTLE_BPS_WRITE].avg;
234

  
235
            info->inserted->iops    = cfg.buckets[THROTTLE_OPS_TOTAL].avg;
236
            info->inserted->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg;
237
            info->inserted->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg;
238

  
239
            info->inserted->has_bps_max     =
240
                cfg.buckets[THROTTLE_BPS_TOTAL].max;
241
            info->inserted->bps_max         =
242
                cfg.buckets[THROTTLE_BPS_TOTAL].max;
243
            info->inserted->has_bps_rd_max  =
244
                cfg.buckets[THROTTLE_BPS_READ].max;
245
            info->inserted->bps_rd_max      =
246
                cfg.buckets[THROTTLE_BPS_READ].max;
247
            info->inserted->has_bps_wr_max  =
248
                cfg.buckets[THROTTLE_BPS_WRITE].max;
249
            info->inserted->bps_wr_max      =
250
                cfg.buckets[THROTTLE_BPS_WRITE].max;
251

  
252
            info->inserted->has_iops_max    =
253
                cfg.buckets[THROTTLE_OPS_TOTAL].max;
254
            info->inserted->iops_max        =
255
                cfg.buckets[THROTTLE_OPS_TOTAL].max;
256
            info->inserted->has_iops_rd_max =
257
                cfg.buckets[THROTTLE_OPS_READ].max;
258
            info->inserted->iops_rd_max     =
259
                cfg.buckets[THROTTLE_OPS_READ].max;
260
            info->inserted->has_iops_wr_max =
261
                cfg.buckets[THROTTLE_OPS_WRITE].max;
262
            info->inserted->iops_wr_max     =
263
                cfg.buckets[THROTTLE_OPS_WRITE].max;
264

  
265
            info->inserted->has_iops_size = cfg.op_size;
266
            info->inserted->iops_size = cfg.op_size;
267
        }
268
        info->inserted = bdrv_block_device_info(bs);
268 269

  
269 270
        bs0 = bs;
270 271
        p_image_info = &info->inserted->image;
b/blockdev.c
1952 1952
    }
1953 1953
}
1954 1954

  
1955
BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp)
1956
{
1957
    return bdrv_named_nodes_list();
1958
}
1959

  
1955 1960
#define DEFAULT_MIRROR_BUF_SIZE   (10 << 20)
1956 1961

  
1957 1962
void qmp_drive_mirror(const char *device, const char *target,
b/include/block/block.h
379 379
const char *bdrv_get_format_name(BlockDriverState *bs);
380 380
BlockDriverState *bdrv_find(const char *name);
381 381
BlockDriverState *bdrv_find_node(const char *node_name);
382
BlockDeviceInfoList *bdrv_named_nodes_list(void);
382 383
BlockDriverState *bdrv_next(BlockDriverState *bs);
383 384
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
384 385
                  void *opaque);
b/include/block/qapi.h
29 29
#include "block/block.h"
30 30
#include "block/snapshot.h"
31 31

  
32
BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs);
32 33
int bdrv_query_snapshot_info_list(BlockDriverState *bs,
33 34
                                  SnapshotInfoList **p_list,
34 35
                                  Error **errp);
b/qapi-schema.json
810 810
#
811 811
# @file: the filename of the backing device
812 812
#
813
# @node-name: #optional the name of the block driver node (Since 2.0)
814
#
813 815
# @ro: true if the backing device was open read-only
814 816
#
815 817
# @drv: the name of the block format used to open the backing device. As of
......
857 859
#
858 860
# Since: 0.14.0
859 861
#
860
# Notes: This interface is only found in @BlockInfo.
861 862
##
862 863
{ 'type': 'BlockDeviceInfo',
863
  'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',
864
  'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str',
864 865
            '*backing_file': 'str', 'backing_file_depth': 'int',
865 866
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
866 867
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
......
2011 2012
{ 'command': 'drive-backup', 'data': 'DriveBackup' }
2012 2013

  
2013 2014
##
2015
# @query-named-block-nodes
2016
#
2017
# Get the named block driver list
2018
#
2019
# Returns: the list of BlockDeviceInfo
2020
#
2021
# Since 2.0
2022
##
2023
{ 'command': 'query-named-block-nodes', 'returns': [ 'BlockDeviceInfo' ] }
2024

  
2025
##
2014 2026
# @drive-mirror
2015 2027
#
2016 2028
# Start mirroring a block device's writes to a new destination.
b/qmp-commands.hx
3346 3346
<- { "return": {} }
3347 3347

  
3348 3348
EQMP
3349

  
3350
    {
3351
        .name       = "query-named-block-nodes",
3352
        .args_type  = "",
3353
        .mhandler.cmd_new = qmp_marshal_input_query_named_block_nodes,
3354
    },
3355

  
3356
SQMP
3357
@query-named-block-nodes
3358
------------------------
3359

  
3360
Return a list of BlockDeviceInfo for all the named block driver nodes
3361

  
3362
Example:
3363

  
3364
-> { "execute": "query-named-block-nodes" }
3365
<- { "return": [ { "ro":false,
3366
                   "drv":"qcow2",
3367
                   "encrypted":false,
3368
                   "file":"disks/test.qcow2",
3369
                   "node-name": "my-node",
3370
                   "backing_file_depth":1,
3371
                   "bps":1000000,
3372
                   "bps_rd":0,
3373
                   "bps_wr":0,
3374
                   "iops":1000000,
3375
                   "iops_rd":0,
3376
                   "iops_wr":0,
3377
                   "bps_max": 8000000,
3378
                   "bps_rd_max": 0,
3379
                   "bps_wr_max": 0,
3380
                   "iops_max": 0,
3381
                   "iops_rd_max": 0,
3382
                   "iops_wr_max": 0,
3383
                   "iops_size": 0,
3384
                   "image":{
3385
                      "filename":"disks/test.qcow2",
3386
                      "format":"qcow2",
3387
                      "virtual-size":2048000,
3388
                      "backing_file":"base.qcow2",
3389
                      "full-backing-filename":"disks/base.qcow2",
3390
                      "backing-filename-format:"qcow2",
3391
                      "snapshots":[
3392
                         {
3393
                            "id": "1",
3394
                            "name": "snapshot1",
3395
                            "vm-state-size": 0,
3396
                            "date-sec": 10000200,
3397
                            "date-nsec": 12,
3398
                            "vm-clock-sec": 206,
3399
                            "vm-clock-nsec": 30
3400
                         }
3401
                      ],
3402
                      "backing-image":{
3403
                          "filename":"disks/base.qcow2",
3404
                          "format":"qcow2",
3405
                          "virtual-size":2048000
3406
                      }
3407
                   } } ] }
3408

  
3409
EQMP

Also available in: Unified diff