block-layer: questions on manipulation of internal nodes
Hi everybody,
I am a relatively new user of qemu block layer. I am interested in it mainly because it looks very powerful and general and I am hoping to integrate it on our product and to contribute to it for new usecases.
I have existing use cases where we work with a model of a disk process per VM disk and I am experimenting with qemu and qmp to build something similar.
At the moment I have managed to build a new binary, called qemu-dp (probably should be called qemu-bl for block layer) which is basically starting as a qmp server and accepting qmp block layer commands to operate on disks.
just to give you an example this is the kind of thing I am doing:
EXTERNALLY:/usr/lib64/xen/bin/qemu-img create -f qcow2 -o size=1M /root/a /usr/lib64/xen/bin/qemu-img create -f qcow2 -b /root/a -o size=1M /root/b /usr/lib64/xen/bin/qemu-img create -f qcow2 -b /root/b -o size=1M /root/c /usr/lib64/xen/bin/qemu-img create -f qcow2 -b /root/c -o size=1M /root/d /usr/lib64/xen/bin/qemu-img create -f qcow2 -b /root/d -o size=1M /root/e
let's assume there were some data in every layer....
Than:
USING QMP:
{ "execute": "qmp_capabilities" }
{
"execute": "blockdev-add",
"arguments": {
"driver": "qcow2",
"node-name": "qemu_node",
"discard": "unmap",
"cache": {
"direct": true
},
"file": {
"driver": "file",
"filename": "/root/e"
}
}
}{
"execute": "nbd-server-start",
"arguments": {
"addr": {
"type": "unix",
"data": {
"path": "/tmp/nbd.test1"
}
}
}
}{
"execute": "nbd-server-add",
"arguments": {
"device": "qemu_node",
"writable": true
}
}after this the chain looks like:
a < b < c < d < e < NBD_server
now I make a full copy of b and c which I call b1 and c1 and for example I run externally qemu-img commit c1 -> b1 while qemu-dp has still the chain opened.
I would now like to send a qmp command to tell qemu-dp to hold any IO from the NBD_server and forget about a, b, c and insert b1 as d's child, like this:
a < b1 < d < e < NBD_server
I have tried to implement this qmp command and looked at
qmp_change_backing_file()qmp_x_blockdev_change()
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg02660.html
but did not figure out a way of doing that yet...
I suspect my problem is that I am still very confused about the semantics of the object model in the block layer, the ref counting, the graph manipulation, the monitor etc. etc.
I have tried to have some interactive chats on irc and they have been very useful so far (thanks again stefanha, kwolf, berto, eblake) but maybe a proper email would be a good starting point as stefanha has suggested.
Please if somebody could point me to a bit of code to achieve my example that would be great, otherwise if there is no code for that kind of functionality, it would be good to have a little guide on the sequence of block primiteve I should call and on which node, including refs, locking, drain, caches, reopen etc...
Thanks a lot,
Stefano
Quoted 61 lines · Stefano Panella
Hi everybody,
I am a relatively new user of qemu block layer. I am interested in it mainly because it looks very powerful and general and I am hoping to integrate it on our product and to contribute to it for new usecases.
I have existing use cases where we work with a model of a disk process per VM disk and I am experimenting with qemu and qmp to build something similar.
At the moment I have managed to build a new binary, called qemu-dp (probably should be called qemu-bl for block layer) which is basically starting as a qmp server and accepting qmp block layer commands to operate on disks.
just to give you an example this is the kind of thing I am doing:
EXTERNALLY:
/usr/lib64/xen/bin/qemu-imgcreate -f qcow2 -o size=1M/root/a/usr/lib64/xen/bin/qemu-imgcreate -f qcow2 -b/root/a-o size=1M/root/b/usr/lib64/xen/bin/qemu-imgcreate -f qcow2 -b/root/b-o size=1M/root/c/usr/lib64/xen/bin/qemu-imgcreate -f qcow2 -b/root/c-o size=1M/root/d/usr/lib64/xen/bin/qemu-imgcreate -f qcow2 -b/root/d-o size=1M/root/elet's assume there were some data in every layer....
Than:
USING QMP:
{ "execute": "qmp_capabilities" }{ "execute": "blockdev-add", "arguments": { "driver": "qcow2", "node-name": "qemu_node", "discard": "unmap", "cache": { "direct": true }, "file": { "driver": "file", "filename": "/root/e" } } }{ "execute": "nbd-server-start", "arguments": { "addr": { "type": "unix", "data": { "path": "/tmp/nbd.test1" } } } }{ "execute": "nbd-server-add", "arguments": { "device": "qemu_node", "writable": true } }after this the chain looks like:
Quoted 7 lines
a < b < c < d < e <
NBD_servernow I make a full copy of b and c which I call b1 and c1 and for example I run externally qemu-img commit c1 -> b1 while qemu-dp has still the chain opened.
I would now like to send a qmp command to tell qemu-dp to hold any IO from the
NBD_serverand forget about a, b, c and insert b1 as d's child, like this:a < b1 < d < e <
NBD_server
Holding I/O is done via bdrv_drained_begin/end() and most block-related monitor commands should use it.
Quoted 6 lines
I have tried to implement this qmp command and looked at
qmp_change_backing_file()qmp_x_blockdev_change()
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg02660.html
Quoted 7 lines
but did not figure out a way of doing that yet...
I suspect my problem is that I am still very confused about the semantics of the object model in the block layer, the ref counting, the graph manipulation, the monitor etc. etc.
I have tried to have some interactive chats on irc and they have been very useful so far (thanks again stefanha, kwolf, berto, eblake) but maybe a proper email would be a good starting point as stefanha has suggested.
Please if somebody could point me to a bit of code to achieve my example that would be great, otherwise if there is no code for that kind of functionality, it would be good to have a little guide on the sequence of block primiteve I should call and on which node, including refs, locking, drain, caches, reopen etc...
blockdev-add and related APIs are still under development and incomplete.
Manos' block-insert-node is probably closest to what you need, so I would start there.
I'm not clear enough on what exactly is necessary on top of Manos' patch without doing the work myself, so I'm afraid I can't give a detailed sequence of steps you need to take.
Stefan