Skip to contentSkip to conversation

Add function to dump block layer for debugging

PATCH In review Vladimir Sementsov-Ogievskiy 2 participants 6 messages Nov 19, 2020

lore
Share & tools
lore
#0 lore raw

cover Add function to dump block layer for debugging

Hi all!

Here is a new function dbg_dump_block_layer() to help with block layer code debugging.

Usage:

1. Add dbg_dump_block_layer("/path/to/dump.json") call in some place were you are trying to understand the relations in block graph and run your test. Or just call dbg_dump_block_layer("/path/to/dump.json") from gdb session if attached to running Qemu.

2. Convert json to png image:

.scripts/render_block_graph.py --json /path/to/dump.json /path/to/out

And get your /path/to/out dot file and /path/to/out.png image.

Vladimir Sementsov-Ogievskiy (4):
block: bdrv_get_xdbg_block_graph() drop unused errp argument
blockjob: add block_jobs_info_list()
block: add dbg_dump_block_layer() scripts/render_block_graph.py: add ability to parse json files

 qapi/block-core.json          | 13 +++++++++
 include/block/block.h         |  5 +++-
 include/block/blockjob.h      |  7 +++++
 block.c                       | 53 +++++++++++++++++++++++++++++++++--
 blockdev.c                    | 28 ++----------------
 blockjob.c                    | 29 +++++++++++++++++++
 MAINTAINERS                   |  5 ++++
 scripts/render_block_graph.py | 53 ++++++++++++++++++++++-------------
 8 files changed, 145 insertions(+), 48 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/4 block: bdrv_get_xdbg_block_graph() drop unused errp argument

---
 include/block/block.h | 2 +-
 block.c               | 2 +-
 blockdev.c            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/block/block.h +1 -1
index c9d7c58765..d17151abd7 100644
@@ -524,7 +524,7 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag);
 const char *bdrv_get_format_name(BlockDriverState *bs);
 BlockDriverState *bdrv_find_node(const char *node_name);
 BlockDeviceInfoList *bdrv_named_nodes_list(bool flat, Error **errp);
-XDbgBlockGraph *bdrv_get_xdbg_block_graph(Error **errp);
+XDbgBlockGraph *bdrv_get_xdbg_block_graph(void);
 BlockDriverState *bdrv_lookup_bs(const char *device,
                                  const char *node_name,
                                  Error **errp);
block.c +1 -1
index f1cedac362..eca16a5e29 100644
@@ -5338,7 +5338,7 @@ static void xdbg_graph_add_edge(XDbgBlockGraphConstructor *gr, void *parent,
 }
 
 
-XDbgBlockGraph *bdrv_get_xdbg_block_graph(Error **errp)
+XDbgBlockGraph *bdrv_get_xdbg_block_graph(void)
 {
     BlockBackend *blk;
     BlockJob *job;
blockdev.c +1 -1
index fe6fb5dc1d..6f103e5ce7 100644
@@ -2911,7 +2911,7 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(bool has_flat,
 
 XDbgBlockGraph *qmp_x_debug_query_block_graph(Error **errp)
 {
-    return bdrv_get_xdbg_block_graph(errp);
+    return bdrv_get_xdbg_block_graph();
 }
 
 void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp)
Signature · 1 line
2.21.3
#2 lore raw

PATCH 2/4 blockjob: add block_jobs_info_list()

In reply to Vladimir Sementsov-Ogievskiy

Move qmp_query_block_jobs() functionality to blockjob.c. We'll need it in block.c which is not always compiled together with blockdev.c

---
 include/block/blockjob.h |  7 +++++++
 blockdev.c               | 26 +-------------------------
 blockjob.c               | 29 +++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 25 deletions(-)
include/block/blockjob.h +7 -0
index 35faa3aa26..2e66d529e2 100644
@@ -173,4 +173,11 @@ bool block_job_is_internal(BlockJob *job);
  */
 const BlockJobDriver *block_job_driver(BlockJob *job);
 
+/**
+ * block_jobs_info_list:
+ *
+ * Returns the list of jobs info.
+ */
+BlockJobInfoList *block_jobs_info_list(Error **errp);
+
 #endif
blockdev.c +1 -25
index 6f103e5ce7..b5f11c524b 100644
@@ -3670,31 +3670,7 @@ void qmp_x_blockdev_change(const char *parent, bool has_child,
 
 BlockJobInfoList *qmp_query_block_jobs(Error **errp)
 {
-    BlockJobInfoList *head = NULL, **p_next = &head;
-    BlockJob *job;
-
-    for (job = block_job_next(NULL); job; job = block_job_next(job)) {
-        BlockJobInfoList *elem;
-        AioContext *aio_context;
-
-        if (block_job_is_internal(job)) {
-            continue;
-        }
-        elem = g_new0(BlockJobInfoList, 1);
-        aio_context = blk_get_aio_context(job->blk);
-        aio_context_acquire(aio_context);
-        elem->value = block_job_query(job, errp);
-        aio_context_release(aio_context);
-        if (!elem->value) {
-            g_free(elem);
-            qapi_free_BlockJobInfoList(head);
-            return NULL;
-        }
-        *p_next = elem;
-        p_next = &elem->next;
-    }
-
-    return head;
+    return block_jobs_info_list(errp);
 }
 
 void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread,
blockjob.c +29 -0
index 98ac8af982..9d0bed01c2 100644
@@ -515,3 +515,32 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
     }
     return action;
 }
+
+BlockJobInfoList *block_jobs_info_list(Error **errp)
+{
+    BlockJobInfoList *head = NULL, **p_next = &head;
+    BlockJob *job;
+
+    for (job = block_job_next(NULL); job; job = block_job_next(job)) {
+        BlockJobInfoList *elem;
+        AioContext *aio_context;
+
+        if (block_job_is_internal(job)) {
+            continue;
+        }
+        elem = g_new0(BlockJobInfoList, 1);
+        aio_context = blk_get_aio_context(job->blk);
+        aio_context_acquire(aio_context);
+        elem->value = block_job_query(job, errp);
+        aio_context_release(aio_context);
+        if (!elem->value) {
+            g_free(elem);
+            qapi_free_BlockJobInfoList(head);
+            return NULL;
+        }
+        *p_next = elem;
+        p_next = &elem->next;
+    }
+
+    return head;
+}
Signature · 1 line
2.21.3
#3 lore raw

PATCH 3/4 block: add dbg_dump_block_layer()

In reply to Vladimir Sementsov-Ogievskiy

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.

---
 qapi/block-core.json  | 13 +++++++++++
 include/block/block.h |  3 +++
 block.c               | 51 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 66 insertions(+), 1 deletion(-)
qapi/block-core.json +13 -0
index 04ad80bc1e..3f8e5a3822 100644
@@ -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:
 #
include/block/block.h +3 -0
index d17151abd7..6a75bbc84c 100644
@@ -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
block.c +50 -1

69 lines not on this page · raw message

Signature · 1 line
2.21.3
#5 lore raw

PATCH 4/4 scripts/render_block_graph.py: add ability to parse json files

In reply to Vladimir Sementsov-Ogievskiy

Add an option to use json file (generated by dbg_dump_block_layer()) as input.

Also, add myself as maintainer of the script.

---
 MAINTAINERS                   |  5 ++++
 scripts/render_block_graph.py | 53 ++++++++++++++++++++++-------------
 2 files changed, 39 insertions(+), 19 deletions(-)
MAINTAINERS +5 -0
index 2e018a0c1d..e780c89e0e 100644
@@ -2408,6 +2408,11 @@ M: Vladimir Sementsov-Ogievskiy <[email protected]>
 S: Maintained
 F: scripts/simplebench/
 
+Block graph visualization
+M: Vladimir Sementsov-Ogievskiy <[email protected]>
+S: Maintained
+F: scripts/render_block_graph.py
+
 QAPI
 M: Markus Armbruster <[email protected]>
 M: Michael Roth <[email protected]>
scripts/render_block_graph.py +34 -19

81 lines not on this page · raw message

Signature · 1 line
2.21.3
#4 lore raw

Re: [PATCH 3/4] block: add dbg_dump_block_layer()

In reply to Vladimir Sementsov-Ogievskiy
Quoted 23 lines · Vladimir Sementsov-Ogievskiy

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.

---

+++ b/qapi/block-core.json

qapi/block-core.json +0 -0
@@ -1908,6 +1908,19 @@
 ##

qapi/block-core.json line 1918

Quoted 10 lines
qapi/block-core.json +8 -0
 { '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

The next release will be numbered 6.0, not 5.3.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org