From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com,
vsementsov@virtuozzo.com, eblake@redhat.com, jsnow@redhat.com,
armbru@redhat.com, mreitz@redhat.com, kwolf@redhat.com,
den@openvz.org, andrey.shinkevich@virtuozzo.com
Subject: [PATCH 3/4] block: add dbg_dump_block_layer()
Date: Thu, 19 Nov 2020 16:16:33 +0300 [thread overview]
Message-ID: <20201119131634.14009-4-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20201119131634.14009-1-vsementsov@virtuozzo.com>
Add function for debugging: we already have x-debug-query-block-graph
qmp command and scripts/render_block_graph.py which can dump
block-layer graph for running vm using qmp command. But when debug
block layer code, its often needed to dump some intermediate state
during some operation, so separate qmp command doesn't help.
So, let's introduce a function which can dump needed information into
json file.
In next commit we'll update scripts/render_block_graph.py so that it
will be able to parse json files.
For new function to not crash if we have mirror_top filter node not yet
bdrv_append()ed (to debug why it can't be appended), make
bdrv_get_allocated_file_size() and bdrv_refresh_filename() not crash on
filters without a child.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
qapi/block-core.json | 13 +++++++++++
include/block/block.h | 3 +++
block.c | 51 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 04ad80bc1e..3f8e5a3822 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1908,6 +1908,19 @@
##
{ 'command': 'x-debug-query-block-graph', 'returns': 'XDbgBlockGraph' }
+##
+# @XDbgBlockLayerDump:
+#
+# Unite query-named-block-nodes, query-block-jobs and
+# x-debug-query-block-graph results into one structure for block_layer_dump()
+# function.
+#
+# Since: 5.3
+##
+{ 'struct': 'XDbgBlockLayerDump',
+ 'data': { 'nodes': ['BlockDeviceInfo'], 'jobs': ['BlockJobInfo'],
+ 'graph': 'XDbgBlockGraph' } }
+
##
# @drive-mirror:
#
diff --git a/include/block/block.h b/include/block/block.h
index d17151abd7..6a75bbc84c 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -836,4 +836,7 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, uint64_t src_offset,
BdrvChild *dst, uint64_t dst_offset,
uint64_t bytes, BdrvRequestFlags read_flags,
BdrvRequestFlags write_flags);
+
+int dbg_dump_block_layer(const char *filename, Error **errp);
+
#endif
diff --git a/block.c b/block.c
index eca16a5e29..82f847a88e 100644
--- a/block.c
+++ b/block.c
@@ -5035,7 +5035,8 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
return -ENOTSUP;
} else if (drv->is_filter) {
/* Filter drivers default to the size of their filtered child */
- return bdrv_get_allocated_file_size(bdrv_filter_bs(bs));
+ return bdrv_filter_child(bs) ?
+ bdrv_get_allocated_file_size(bdrv_filter_bs(bs)) : -ENOMEDIUM;
} else {
/* Other drivers default to summing their children's sizes */
return bdrv_sum_allocated_file_size(bs);
@@ -5382,6 +5383,51 @@ XDbgBlockGraph *bdrv_get_xdbg_block_graph(void)
return xdbg_graph_finalize(gr);
}
+int dbg_dump_block_layer(const char *filename, Error **errp)
+{
+ ERRP_GUARD();
+ Visitor *v;
+ g_autoptr(XDbgBlockLayerDump) dump = g_new0(XDbgBlockLayerDump, 1);
+ QObject *obj = NULL;
+ QString *json;
+ FILE *f;
+
+ dump->nodes = bdrv_named_nodes_list(false, errp);
+ if (*errp) {
+ return -EINVAL;
+ }
+ dump->jobs = block_jobs_info_list(errp);
+ if (*errp) {
+ return -EINVAL;
+ }
+ dump->graph = bdrv_get_xdbg_block_graph();
+
+ v = qobject_output_visitor_new(&obj);
+ if (visit_type_XDbgBlockLayerDump(v, "unused", &dump, errp)) {
+ visit_complete(v, &obj);
+ }
+ visit_free(v);
+ if (*errp) {
+ return -EINVAL;
+ }
+
+ json = qobject_to_json_pretty(obj);
+ qobject_unref(obj);
+
+ f = fopen(filename, "w");
+ if (!f) {
+ error_setg_errno(errp, errno, "Can't open file '%s'", filename);
+ qobject_unref(json);
+ return -EINVAL;
+ }
+
+ fputs(qstring_get_str(json), f);
+ fclose(f);
+ qobject_unref(json);
+
+ return 0;
+}
+
BlockDriverState *bdrv_lookup_bs(const char *device,
const char *node_name,
Error **errp)
@@ -6885,6 +6931,9 @@ void bdrv_refresh_filename(BlockDriverState *bs)
if (bs->implicit) {
/* For implicit nodes, just copy everything from the single child */
child = QLIST_FIRST(&bs->children);
+ if (!child) {
+ return;
+ }
assert(QLIST_NEXT(child, next) == NULL);
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
--
2.21.3
next prev parent reply other threads:[~2020-11-19 13:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-19 13:16 [PATCH 0/4] Add function to dump block layer for debugging Vladimir Sementsov-Ogievskiy
2020-11-19 13:16 ` [PATCH 1/4] block: bdrv_get_xdbg_block_graph() drop unused errp argument Vladimir Sementsov-Ogievskiy
2020-11-19 13:16 ` [PATCH 2/4] blockjob: add block_jobs_info_list() Vladimir Sementsov-Ogievskiy
2020-11-19 13:16 ` Vladimir Sementsov-Ogievskiy [this message]
2020-11-19 17:02 ` [PATCH 3/4] block: add dbg_dump_block_layer() Eric Blake
2020-11-19 13:16 ` [PATCH 4/4] scripts/render_block_graph.py: add ability to parse json files Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201119131634.14009-4-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=andrey.shinkevich@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).