#include "block/write-threshold.h"
#include "qmp-commands.h"
#include "qapi-visit.h"
+#include "qapi/error.h"
#include "qapi/qobject-output-visitor.h"
-#include "qapi/qmp/types.h"
+#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qlist.h"
+#include "qapi/qmp/qnum.h"
+#include "qapi/qmp/qstring.h"
#include "sysemu/block-backend.h"
#include "qemu/cutils.h"
{
ImageInfo **p_image_info;
BlockDriverState *bs0;
- BlockDeviceInfo *info = g_malloc0(sizeof(*info));
+ BlockDeviceInfo *info;
+ if (!bs->drv) {
+ error_setg(errp, "Block device %s is ejected", bs->node_name);
+ return NULL;
+ }
+
+ info = g_malloc0(sizeof(*info));
info->file = g_strdup(bs->filename);
info->ro = bs->read_only;
info->drv = g_strdup(bs->drv->format_name);
info->encrypted = bs->encrypted;
- info->encryption_key_missing = bdrv_key_required(bs);
+ info->encryption_key_missing = false;
info->cache = g_new(BlockdevCacheInfo, 1);
*info->cache = (BlockdevCacheInfo) {
info->backing_file = g_strdup(bs->backing_file);
}
- info->backing_file_depth = bdrv_get_backing_file_depth(bs);
info->detect_zeroes = bs->detect_zeroes;
- if (blk && blk_get_public(blk)->throttle_state) {
+ if (blk && blk_get_public(blk)->throttle_group_member.throttle_state) {
ThrottleConfig cfg;
+ BlockBackendPublic *blkp = blk_get_public(blk);
- throttle_group_get_config(blk, &cfg);
+ throttle_group_get_config(&blkp->throttle_group_member, &cfg);
info->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg;
info->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg;
info->iops_size = cfg.op_size;
info->has_group = true;
- info->group = g_strdup(throttle_group_get_name(blk));
+ info->group =
+ g_strdup(throttle_group_get_name(&blkp->throttle_group_member));
}
info->write_threshold = bdrv_write_threshold_get(bs);
bs0 = bs;
p_image_info = &info->image;
+ info->backing_file_depth = 0;
while (1) {
Error *local_err = NULL;
bdrv_query_image_info(bs0, p_image_info, &local_err);
qapi_free_BlockDeviceInfo(info);
return NULL;
}
+
if (bs0->drv && bs0->backing) {
+ info->backing_file_depth++;
bs0 = bs0->backing->bs;
(*p_image_info)->has_backing_image = true;
p_image_info = &((*p_image_info)->backing_image);
} else {
break;
}
+
+ /* Skip automatically inserted nodes that the user isn't aware of for
+ * query-block (blk != NULL), but not for query-named-block-nodes */
+ while (blk && bs0->drv && bs0->implicit) {
+ bs0 = backing_bs(bs0);
+ assert(bs0);
+ }
}
return info;
{
BlockInfo *info = g_malloc0(sizeof(*info));
BlockDriverState *bs = blk_bs(blk);
+ char *qdev;
+
+ /* Skip automatically inserted nodes that the user isn't aware of */
+ while (bs && bs->drv && bs->implicit) {
+ bs = backing_bs(bs);
+ }
+
info->device = g_strdup(blk_name(blk));
info->type = g_strdup("unknown");
info->locked = blk_dev_is_medium_locked(blk);
info->removable = blk_dev_has_removable_media(blk);
+ qdev = blk_get_attached_dev_id(blk);
+ if (qdev && *qdev) {
+ info->has_qdev = true;
+ info->qdev = qdev;
+ } else {
+ g_free(qdev);
+ }
+
if (blk_dev_has_tray(blk)) {
info->has_tray_open = true;
info->tray_open = blk_dev_is_tray_open(blk);
}
}
-static BlockStats *bdrv_query_bds_stats(const BlockDriverState *bs,
- bool query_backing)
+static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
+ bool blk_level)
{
BlockStats *s = NULL;
return s;
}
+ /* Skip automatically inserted nodes that the user isn't aware of in
+ * a BlockBackend-level command. Stay at the exact node for a node-level
+ * command. */
+ while (blk_level && bs->drv && bs->implicit) {
+ bs = backing_bs(bs);
+ assert(bs);
+ }
+
if (bdrv_get_node_name(bs)[0]) {
s->has_node_name = true;
s->node_name = g_strdup(bdrv_get_node_name(bs));
if (bs->file) {
s->has_parent = true;
- s->parent = bdrv_query_bds_stats(bs->file->bs, query_backing);
+ s->parent = bdrv_query_bds_stats(bs->file->bs, blk_level);
}
- if (query_backing && bs->backing) {
+ if (blk_level && bs->backing) {
s->has_backing = true;
- s->backing = bdrv_query_bds_stats(bs->backing->bs, query_backing);
+ s->backing = bdrv_query_bds_stats(bs->backing->bs, blk_level);
}
return s;
BlockBackend *blk;
Error *local_err = NULL;
- for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
- BlockInfoList *info = g_malloc0(sizeof(*info));
+ for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
+ BlockInfoList *info;
+
+ if (!*blk_name(blk) && !blk_get_attached_dev(blk)) {
+ continue;
+ }
+
+ info = g_malloc0(sizeof(*info));
bdrv_query_info(blk, &info->value, &local_err);
if (local_err) {
error_propagate(errp, local_err);