Block patches:

- New debugging QMP command to explore block graphs
 - Converted DPRINTF()s to trace events
 - Fixed qemu-io's use of getopt() for systems with optreset
 - Minor NVMe emulation fixes
 - An iotest fix
 -----BEGIN PGP SIGNATURE-----
 
 iQEcBAABAgAGBQJcUkaiAAoJEPQH2wBh1c9AHsEIAIU0+FNjtdz7lNgyeBCSFCFa
 /qWNk4+w6QBfhTTx/N0hGwh5/FvNYQhby8VHtZitE4/QcLbJwHYgWf14pwce3tP3
 3qNB87AdQpKMpbajQM2x2Xy8lnlPeM7fe21Q/12vuX7AlEDT3gH+W9rg94bw2oFN
 r+xBk6H5F2aVElw3CwMM7eary4+dPnnCQwAnoqM+g5hdpL+0scrIyARGw7v0hmSn
 LDWESCM4a55lEYmwj1wS3J3uj6Fj00yzBvcEuCcT1GO+lXlV8/ciO9r2HqxVKwgz
 4GAi/BERoMKjfn+/77/yI5flprPx2voNGgkyBY4C3z9ncnN6u02QBZSusBIWpSg=
 =Kt4r
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/xanclic/tags/pull-block-2019-01-31' into staging

Block patches:
- New debugging QMP command to explore block graphs
- Converted DPRINTF()s to trace events
- Fixed qemu-io's use of getopt() for systems with optreset
- Minor NVMe emulation fixes
- An iotest fix

# gpg: Signature made Thu 31 Jan 2019 00:51:46 GMT
# gpg:                using RSA key F407DB0061D5CF40
# gpg: Good signature from "Max Reitz <mreitz@redhat.com>" [full]
# Primary key fingerprint: 91BE B60A 30DB 3E88 57D1  1829 F407 DB00 61D5 CF40

* remotes/xanclic/tags/pull-block-2019-01-31:
  iotests: Allow 147 to be run concurrently
  iotests: Bind qemu-nbd to localhost in 147
  iotests.py: Add qemu_nbd_pipe()
  nvme: use pci_dev directly in nvme_realize
  nvme: ensure the num_queues is not zero
  nvme: use TYPE_NVME instead of constant string
  qemu-io: Add generic function for reinitializing optind.
  block/sheepdog: Convert from DPRINTF() macro to trace events
  block/file-posix: Convert from DPRINTF() macro to trace events
  block/curl: Convert from DPRINTF() macro to trace events
  block/ssh: Convert from DPRINTF() macro to trace events
  scripts: add render_block_graph function for QEMUMachine
  qapi: add x-debug-query-block-graph

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2019-01-31 19:26:09 +00:00
commit cfe6c54769
19 changed files with 608 additions and 136 deletions

120
scripts/render_block_graph.py Executable file
View file

@ -0,0 +1,120 @@
#!/usr/bin/env python
#
# Render Qemu Block Graph
#
# Copyright (c) 2018 Virtuozzo International GmbH. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
import subprocess
import json
from graphviz import Digraph
from qemu import MonitorResponseError
def perm(arr):
s = 'w' if 'write' in arr else '_'
s += 'r' if 'consistent-read' in arr else '_'
s += 'u' if 'write-unchanged' in arr else '_'
s += 'g' if 'graph-mod' in arr else '_'
s += 's' if 'resize' in arr else '_'
return s
def render_block_graph(qmp, filename, format='png'):
'''
Render graph in text (dot) representation into "@filename" and
representation in @format into "@filename.@format"
'''
bds_nodes = qmp.command('query-named-block-nodes')
bds_nodes = {n['node-name']: n for n in bds_nodes}
job_nodes = qmp.command('query-block-jobs')
job_nodes = {n['device']: n for n in job_nodes}
block_graph = qmp.command('x-debug-query-block-graph')
graph = Digraph(comment='Block Nodes Graph')
graph.format = format
graph.node('permission symbols:\l'
' w - Write\l'
' r - consistent-Read\l'
' u - write - Unchanged\l'
' g - Graph-mod\l'
' s - reSize\l'
'edge label scheme:\l'
' <child type>\l'
' <perm>\l'
' <shared_perm>\l', shape='none')
for n in block_graph['nodes']:
if n['type'] == 'block-driver':
info = bds_nodes[n['name']]
label = n['name'] + ' [' + info['drv'] + ']'
if info['drv'] == 'file':
label += '\n' + os.path.basename(info['file'])
shape = 'ellipse'
elif n['type'] == 'block-job':
info = job_nodes[n['name']]
label = info['type'] + ' job (' + n['name'] + ')'
shape = 'box'
else:
assert n['type'] == 'block-backend'
label = n['name'] if n['name'] else 'unnamed blk'
shape = 'box'
graph.node(str(n['id']), label, shape=shape)
for e in block_graph['edges']:
label = '%s\l%s\l%s\l' % (e['name'], perm(e['perm']),
perm(e['shared-perm']))
graph.edge(str(e['parent']), str(e['child']), label=label)
graph.render(filename)
class LibvirtGuest():
def __init__(self, name):
self.name = name
def command(self, cmd):
# only supports qmp commands without parameters
m = {'execute': cmd}
ar = ['virsh', 'qemu-monitor-command', self.name, json.dumps(m)]
reply = json.loads(subprocess.check_output(ar))
if 'error' in reply:
raise MonitorResponseError(reply)
return reply['return']
if __name__ == '__main__':
obj = sys.argv[1]
out = sys.argv[2]
if os.path.exists(obj):
# assume unix socket
qmp = QEMUMonitorProtocol(obj)
qmp.connect()
else:
# assume libvirt guest name
qmp = LibvirtGuest(obj)
render_block_graph(qmp, out)