1. Write the command's and type(s) specification in the QAPI schema file
(qapi-schema.json in the root source directory)
{ 'command': 'block_rebase', 'data': { 'device': 'str', 'file': 'str' } }
Currently, I only support rebase from qcow2 to qcow2.
edit qmp-commands.hx
{
.name = "block_rebase",
.args_type = "device:s,file:s",
.mhandler.cmd_new = qmp_marshal_input_block_rebase,
},
SQMP
block_rebase
------------
Rebase a block image while a guest is running.
Arguments:
- "device": the device's ID, must be unique (json-string)
- "file": new backing file path
Example:
-> { "execute": "block_rebase", "arguments": { "device": "ide-0", "file": "/storage/new_base.img" } }
<- { "return": {} }
cf) device name can be identified by { "execute": "query-block" }
QMP test by hand
qemu [...] -qmp tcp:localhost:4444,server,nowait
QMP client
$ telnet localhost 4444
{ "execute": "qmp_capabilities" }
{ "execute": "query-block" }
... after query-block, you can find "device" name
...
{ "execute": "block_rebase", "arguments": { "device": "ide0-hd0", "file": "/storage/new_base.img" } }