Skip to content

Instantly share code, notes, and snippets.

@rgl
Last active June 21, 2024 17:45
Show Gist options
  • Save rgl/dc38c6875a53469fdebb2e9c0a220c6c to your computer and use it in GitHub Desktop.
Save rgl/dc38c6875a53469fdebb2e9c0a220c6c to your computer and use it in GitHub Desktop.
qemu qmp

QEMU Machine Protocol (QMP) socket

Start QEMU with QMP UNIX socket and connect:

qemu-system-x86_64 -qmp unix:test.socket,server,nowait ...
nc -U test.socket
qmp-shell test.socket    # use the raw qmp interface. see https://github.com/0xef53/qmp-shell
qmp-shell -H test.socket # use the human interface.   see https://github.com/0xef53/qmp-shell

Or start QEMU with QMP TCP socket and connect:

qemu-system-x86_64 -qmp tcp:127.0.0.1:12345,server,nowait ...
nc localhost 12345

Examples

After you open the socket, the first command is always:

{ "execute": "qmp_capabilities" }

Then you can either execute human or machine friendly commands.

Human friendly commands examples

{ "execute": "human-monitor-command", "arguments": { "command-line": "help" } }
{ "execute": "human-monitor-command", "arguments": { "command-line": "info version" } }
{ "execute": "human-monitor-command", "arguments": { "command-line": "info network" } }
{ "execute": "human-monitor-command", "arguments": { "command-line": "info qtree" } }

Machine friendly commands examples

{ "execute": "query-qmp-schema" }

{ "execute": "query-machines" }

{ "execute": "query-version" }
{ "execute": "query-name" }
{ "execute": "query-status" }
{ "execute": "query-kvm" }
{ "execute": "query-pci" }

{ "execute": "device-list-properties", "arguments": { "typename": "vmxnet3" } }

{ "execute": "qom-list-types" }

{ "execute": "qom-list", "arguments": { "path": "/" } }
{ "execute": "qom-list", "arguments": { "path": "/machine" } }
{ "execute": "qom-get", "arguments": { "path": "/machine", "property": "type" } }
{ "execute": "qom-list", "arguments": { "path": "/machine/i440fx" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/i440fx", "property": "type" } }
{ "execute": "qom-list", "arguments": { "path": "/machine/i440fx/pci.0" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/i440fx/pci.0", "property": "type" } }
{ "execute": "qom-list", "arguments": { "path": "/machine/i440fx/pci.0/child[3]" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/i440fx/pci.0/child[3]", "property": "type" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/i440fx/pci.0/child[3]", "property": "mac" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/i440fx/pci.0/child[3]", "property": "netdev" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/i440fx/pci.0/child[3]", "property": "legacy-addr" } }

{ "execute": "qom-list", "arguments": { "path": "/machine/peripheral-anon" } }
{ "execute": "qom-list", "arguments": { "path": "/machine/peripheral-anon/device[0]" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/peripheral-anon/device[0]", "property": "type" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/peripheral-anon/device[0]", "property": "mac" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/peripheral-anon/device[0]", "property": "netdev" } }

{ "execute": "qom-get", "arguments": { "path": "/machine/peripheral/nic0", "property": "type" } }
{ "execute": "qom-get", "arguments": { "path": "/machine/peripheral/nic0", "property": "mac" } }

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment