Hi Kevin!
28.12.2020 21:03, Kevin Nguetchouang wrote:
Hello everyone, in a class project, i would like to change the backing file of
the current image opened with a particular path file.
I try differents functions i saw in the source code
- bdrv_change_backing_file
- bdrv_open
- bdrv_open_child
but no one work... from segmentation fault error to bdrv_attach_backing passing
through parent->blocking_error, i don't know how to achieve what i want.
--
/Kevin Nguetchouang./
First, you should understand, that there are two different thing in "changing the
backing file":
1. Change backing link in the block nodes graph
2. Change backing file name in the metadata of the image (for example in qcow2
header
For example, look at the bdrv_drop_intermediate() (block.c) function. it's aim
is to drop all nodes in the chain between top and base, and make base to be new
backing file for the top.
Key things in the function:
- bdrv_subtree_drained_begin/end - to pause any io operations during graph
update
- bdrv_replace_node_common() - which actually replace backing child of top node
- c->klass->update_filename() - which will update backing-file in the metadata
of top image
Another example in block/stream.c, in stream_prepare():
- bdrv_set_backing_hd() to change backing child
- bdrv_change_backing_file() to change backing-file in the metadata of top image
(hmm, why don't we have drained begin/end here? why we don't use
bdrv_drop_intermediate()? - just good questions).
Hope, it helps a bit.
--
Best regards,
Vladimir