Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On Fri, Oct 06, 2017 at 02:59:55PM +0200, Max Reitz wrote: On 2017-10-04 23:04, Manos Pitsidianakis wrote: On Wed, Oct 04, 2017 at 08:09:24PM +0200, Max Reitz wrote: On 2017-10-04 19:05, Manos Pitsidianakis wrote: On Wed, Oct 04, 2017 at 02:49:27PM +0200, Max Reitz wrote: On 2017-08-15 09:45, Manos Pitsidianakis wrote: block-insert-node and its pair command block-remove-node provide runtime insertion and removal of filter nodes. block-insert-node takes a (parent, child) and (node, child) pair of edges and unrefs the (parent, child) BdrvChild relationship and creates a new (parent, node) child with the same BdrvChildRole. This is a different approach than x-blockdev-change which uses the driver methods bdrv_add_child() and bdrv_del_child(), Why? :-) Can't we reuse x-blockdev-change? As far as I'm concerned, this was one of its roles, and at least I don't want to have both x-blockdev-change and these new commands. I think it would be a good idea just to change bdrv_add_child() and bdrv_del_child(): If the driver has a bdrv_{add,del}_child() callback, invoke that. If it doesn't, then just attach the child. Of course, it may turn out that x-blockdev-change is lacking something (e.g. a way to specify as what kind of child a new node is to be attached). Then we should either extend it so that it covers what it's lacking, or replace it completely by these new commands. In the latter case, however, they would need to cover the existing use case which is reconfiguring the quorum driver. (And that would mean it would have to invoke bdrv_add_child()/bdrv_del_child() when the driver has them.) Max I think the two use cases are this: a) Adding/removing a replication child to an existing quorum node b) Insert a filter between two existing nodes. For me both are the same: Adding/removing nodes into/from the graph. The difference is how those children are added (or removed, but it's the same in reverse): In case of quorum, you can simply attach a new child because it supports a variable number of children. Another case where this would work are all block drivers which support backing files (you can freely attach/detach those). Doesn't blockdev-snapshot-sync cover this? (I may be missing something). Not really, because it doesn't add a new child. But it's still a good point, because your block-insert-node command would make it obsolete, actually. blockdev-snapshot literally is a special-cased block-insert-node. And blockdev-snapshot-sync then is qemu-img create + blockdev-add + blockdev-snapshot. Now that we're on this topic, quorum might be a good candidate for *_reopen when and if it lands on QMP: Reconfiguring the children could be done by reopening the BDS with new options. Hmmm... I guess that would work, too. But intuitively, that seems a bit heavy-weight to me In this series, it's not about adding or removing new children, but instead "injecting" them into an edge: An existing child is replaced, but it now serves as some child of the new one. (I guess writing too much trying to get my point across, sorry...) The gist is that for me it's not so much about "quorum" or "filter nodes". It's about adding a new child to a node vs. replacing an existing one. These are not directly compatible semantically, but as you said x-blockdev-change can perform b) if bdrv_add_child()/bdrv_del_child() are not implemented. Wouldn't that be unnecessary overloading? Yes, I think it would be. :-) So say we have these two trees in our graph: [ Parent BDS -> Child BDS ] [ Filter BDS -> Child BDS ] So here's what you can do with x-blockdev-change (in theory; in practice it can only do that for quorum): - Remove a child, so [ Parent BDS -> Child BDS ] is split into two trees [ Parent BDS ] and [ Child BDS ] - Add a child, so we can merge [ Parent BDS ] and [ Filter BDS -> Child BDS ] into [ Parent BDS -> Filter BDS -> Child BDS ] Yes, of course this would have to be done in one transaction. Would it? If you want to put Filter BDS into the chain, you can just create [ Filter BDS ] without any child, and then use a single x-blockdev-change invocation to inject it. The only thing that's necessary is that the filter BDS would have to be able to handle having no child. Yeah that was what I had in mind. [...] So after I've written all of this, I feel like the new insert-node and remove-node commands are exactly what x-blockdev-change should do when asked to replace a node. The only difference is that x-blockdev-change would allow you to replace any node with anything, without the constraints that block-insert-node and block-remove-node exact. (And node replacement with x-blockdev-change would work by specifying all three parameters.) Not sure if that makes sense, I hope it does. :-) Hm, I can't think of a way to fit that into x-blockdev-change *and* keep the bdrv_add_child/bdrv_del_child functionality into consideration (since we'd have to keep both). This
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On 2017-10-04 23:04, Manos Pitsidianakis wrote: > On Wed, Oct 04, 2017 at 08:09:24PM +0200, Max Reitz wrote: >> On 2017-10-04 19:05, Manos Pitsidianakis wrote: >>> On Wed, Oct 04, 2017 at 02:49:27PM +0200, Max Reitz wrote: On 2017-08-15 09:45, Manos Pitsidianakis wrote: > block-insert-node and its pair command block-remove-node provide > runtime > insertion and removal of filter nodes. > > block-insert-node takes a (parent, child) and (node, child) pair of > edges and unrefs the (parent, child) BdrvChild relationship and > creates > a new (parent, node) child with the same BdrvChildRole. > > This is a different approach than x-blockdev-change which uses the > driver > methods bdrv_add_child() and bdrv_del_child(), Why? :-) Can't we reuse x-blockdev-change? As far as I'm concerned, this was one of its roles, and at least I don't want to have both x-blockdev-change and these new commands. I think it would be a good idea just to change bdrv_add_child() and bdrv_del_child(): If the driver has a bdrv_{add,del}_child() callback, invoke that. If it doesn't, then just attach the child. Of course, it may turn out that x-blockdev-change is lacking something (e.g. a way to specify as what kind of child a new node is to be attached). Then we should either extend it so that it covers what it's lacking, or replace it completely by these new commands. In the latter case, however, they would need to cover the existing use case which is reconfiguring the quorum driver. (And that would mean it would have to invoke bdrv_add_child()/bdrv_del_child() when the driver has them.) Max >>> >>> I think the two use cases are this: >>> >>> a) Adding/removing a replication child to an existing quorum node >>> b) Insert a filter between two existing nodes. >> >> For me both are the same: Adding/removing nodes into/from the graph. >> >> The difference is how those children are added (or removed, but it's the >> same in reverse): In case of quorum, you can simply attach a new child >> because it supports a variable number of children. Another case where >> this would work are all block drivers which support backing files (you >> can freely attach/detach those). > > Doesn't blockdev-snapshot-sync cover this? (I may be missing something). Not really, because it doesn't add a new child. But it's still a good point, because your block-insert-node command would make it obsolete, actually. blockdev-snapshot literally is a special-cased block-insert-node. And blockdev-snapshot-sync then is qemu-img create + blockdev-add + blockdev-snapshot. > Now that we're on this topic, quorum might be a good candidate for > *_reopen when and if it lands on QMP: Reconfiguring the children could > be done by reopening the BDS with new options. Hmmm... I guess that would work, too. But intuitively, that seems a bit heavy-weight to me >> In this series, it's not about adding or removing new children, but >> instead "injecting" them into an edge: An existing child is replaced, >> but it now serves as some child of the new one. >> >> (I guess writing too much trying to get my point across, sorry...) >> >> The gist is that for me it's not so much about "quorum" or "filter >> nodes". It's about adding a new child to a node vs. replacing an >> existing one. >> >>> These are not directly compatible semantically, but as you said >>> x-blockdev-change can perform b) if bdrv_add_child()/bdrv_del_child() >>> are not implemented. Wouldn't that be unnecessary overloading? >> >> Yes, I think it would be. :-) >> >> So say we have these two trees in our graph: >> >> [ Parent BDS -> Child BDS ] >> [ Filter BDS -> Child BDS ] >> >> So here's what you can do with x-blockdev-change (in theory; in practice >> it can only do that for quorum): >> - Remove a child, so >> [ Parent BDS -> Child BDS ] >> is split into two trees >> [ Parent BDS ] and >> [ Child BDS ] >> - Add a child, so we can merge >> [ Parent BDS ] and >> [ Filter BDS -> Child BDS ] >> into >> [ Parent BDS -> Filter BDS -> Child BDS ] >> > > Yes, of course this would have to be done in one transaction. Would it? If you want to put Filter BDS into the chain, you can just create [ Filter BDS ] without any child, and then use a single x-blockdev-change invocation to inject it. The only thing that's necessary is that the filter BDS would have to be able to handle having no child. [...] >> So after I've written all of this, I feel like the new insert-node and >> remove-node commands are exactly what x-blockdev-change should do when >> asked to replace a node. The only difference is that x-blockdev-change >> would allow you to replace any node with anything, without the >> constraints that block-insert-node and block-remove-node exact. >> >> (And node replacement with x-blockdev-change would work by specifying >> all three
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On Wed, Oct 04, 2017 at 08:09:24PM +0200, Max Reitz wrote: On 2017-10-04 19:05, Manos Pitsidianakis wrote: On Wed, Oct 04, 2017 at 02:49:27PM +0200, Max Reitz wrote: On 2017-08-15 09:45, Manos Pitsidianakis wrote: block-insert-node and its pair command block-remove-node provide runtime insertion and removal of filter nodes. block-insert-node takes a (parent, child) and (node, child) pair of edges and unrefs the (parent, child) BdrvChild relationship and creates a new (parent, node) child with the same BdrvChildRole. This is a different approach than x-blockdev-change which uses the driver methods bdrv_add_child() and bdrv_del_child(), Why? :-) Can't we reuse x-blockdev-change? As far as I'm concerned, this was one of its roles, and at least I don't want to have both x-blockdev-change and these new commands. I think it would be a good idea just to change bdrv_add_child() and bdrv_del_child(): If the driver has a bdrv_{add,del}_child() callback, invoke that. If it doesn't, then just attach the child. Of course, it may turn out that x-blockdev-change is lacking something (e.g. a way to specify as what kind of child a new node is to be attached). Then we should either extend it so that it covers what it's lacking, or replace it completely by these new commands. In the latter case, however, they would need to cover the existing use case which is reconfiguring the quorum driver. (And that would mean it would have to invoke bdrv_add_child()/bdrv_del_child() when the driver has them.) Max I think the two use cases are this: a) Adding/removing a replication child to an existing quorum node b) Insert a filter between two existing nodes. For me both are the same: Adding/removing nodes into/from the graph. The difference is how those children are added (or removed, but it's the same in reverse): In case of quorum, you can simply attach a new child because it supports a variable number of children. Another case where this would work are all block drivers which support backing files (you can freely attach/detach those). Doesn't blockdev-snapshot-sync cover this? (I may be missing something). Now that we're on this topic, quorum might be a good candidate for *_reopen when and if it lands on QMP: Reconfiguring the children could be done by reopening the BDS with new options. In this series, it's not about adding or removing new children, but instead "injecting" them into an edge: An existing child is replaced, but it now serves as some child of the new one. (I guess writing too much trying to get my point across, sorry...) The gist is that for me it's not so much about "quorum" or "filter nodes". It's about adding a new child to a node vs. replacing an existing one. These are not directly compatible semantically, but as you said x-blockdev-change can perform b) if bdrv_add_child()/bdrv_del_child() are not implemented. Wouldn't that be unnecessary overloading? Yes, I think it would be. :-) So say we have these two trees in our graph: [ Parent BDS -> Child BDS ] [ Filter BDS -> Child BDS ] So here's what you can do with x-blockdev-change (in theory; in practice it can only do that for quorum): - Remove a child, so [ Parent BDS -> Child BDS ] is split into two trees [ Parent BDS ] and [ Child BDS ] - Add a child, so we can merge [ Parent BDS ] and [ Filter BDS -> Child BDS ] into [ Parent BDS -> Filter BDS -> Child BDS ] Yes, of course this would have to be done in one transaction. However, this is only possible with quorum because usually block drivers don't support detaching children. And here's what you can do with your commands (from what I can see): - Replace a child (you call it insertion, but it really is just replacement of an existing child with the constraint that both nodes involved must have the same child): [ Parent BDS -> Child BDS ] [ Filter BDS -> Child BDS ] to [ Parent BDS -> Filter BDS -> Child BDS ] - Replace a child (you call it removal, but it really is just replacement of a child with its child): [ Parent BDS -> Filter BDS -> Child BDS ] to [ Parent BDS -> Child BDS ] This works on all BDSs because you don't change the number of children. The interesting thing of course is that the "change" command can actually add and remove children; where as the "insert" and "remove" commands can only replace children. So that's already a bit funny (one command does two things; two commands do one thing). That is true, but the replacing is more in terms of inserting and removing a node in a BDS chain. And then of course you can simply modify x-blockdev-change so it can do the same thing block-insert-node and block-remove-node can do: It just needs another mode which can be used to replace a child (and its description already states that it is supposed to be usable for that at some point in the future). So after I've written all of this, I feel like the new insert-node and remove-node commands are exactly what
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On 2017-10-04 19:05, Manos Pitsidianakis wrote: > On Wed, Oct 04, 2017 at 02:49:27PM +0200, Max Reitz wrote: >> On 2017-08-15 09:45, Manos Pitsidianakis wrote: >>> block-insert-node and its pair command block-remove-node provide runtime >>> insertion and removal of filter nodes. >>> >>> block-insert-node takes a (parent, child) and (node, child) pair of >>> edges and unrefs the (parent, child) BdrvChild relationship and creates >>> a new (parent, node) child with the same BdrvChildRole. >>> >>> This is a different approach than x-blockdev-change which uses the >>> driver >>> methods bdrv_add_child() and bdrv_del_child(), >> >> Why? :-) >> >> Can't we reuse x-blockdev-change? As far as I'm concerned, this was one >> of its roles, and at least I don't want to have both x-blockdev-change >> and these new commands. >> >> I think it would be a good idea just to change bdrv_add_child() and >> bdrv_del_child(): If the driver has a bdrv_{add,del}_child() callback, >> invoke that. If it doesn't, then just attach the child. >> >> Of course, it may turn out that x-blockdev-change is lacking something >> (e.g. a way to specify as what kind of child a new node is to be >> attached). Then we should either extend it so that it covers what it's >> lacking, or replace it completely by these new commands. In the latter >> case, however, they would need to cover the existing use case which is >> reconfiguring the quorum driver. (And that would mean it would have to >> invoke bdrv_add_child()/bdrv_del_child() when the driver has them.) >> >> Max >> > > I think the two use cases are this: > > a) Adding/removing a replication child to an existing quorum node > b) Insert a filter between two existing nodes. For me both are the same: Adding/removing nodes into/from the graph. The difference is how those children are added (or removed, but it's the same in reverse): In case of quorum, you can simply attach a new child because it supports a variable number of children. Another case where this would work are all block drivers which support backing files (you can freely attach/detach those). In this series, it's not about adding or removing new children, but instead "injecting" them into an edge: An existing child is replaced, but it now serves as some child of the new one. (I guess writing too much trying to get my point across, sorry...) The gist is that for me it's not so much about "quorum" or "filter nodes". It's about adding a new child to a node vs. replacing an existing one. > These are not directly compatible semantically, but as you said > x-blockdev-change can perform b) if bdrv_add_child()/bdrv_del_child() > are not implemented. Wouldn't that be unnecessary overloading? Yes, I think it would be. :-) So say we have these two trees in our graph: [ Parent BDS -> Child BDS ] [ Filter BDS -> Child BDS ] So here's what you can do with x-blockdev-change (in theory; in practice it can only do that for quorum): - Remove a child, so [ Parent BDS -> Child BDS ] is split into two trees [ Parent BDS ] and [ Child BDS ] - Add a child, so we can merge [ Parent BDS ] and [ Filter BDS -> Child BDS ] into [ Parent BDS -> Filter BDS -> Child BDS ] However, this is only possible with quorum because usually block drivers don't support detaching children. And here's what you can do with your commands (from what I can see): - Replace a child (you call it insertion, but it really is just replacement of an existing child with the constraint that both nodes involved must have the same child): [ Parent BDS -> Child BDS ] [ Filter BDS -> Child BDS ] to [ Parent BDS -> Filter BDS -> Child BDS ] - Replace a child (you call it removal, but it really is just replacement of a child with its child): [ Parent BDS -> Filter BDS -> Child BDS ] to [ Parent BDS -> Child BDS ] This works on all BDSs because you don't change the number of children. The interesting thing of course is that the "change" command can actually add and remove children; where as the "insert" and "remove" commands can only replace children. So that's already a bit funny (one command does two things; two commands do one thing). And then of course you can simply modify x-blockdev-change so it can do the same thing block-insert-node and block-remove-node can do: It just needs another mode which can be used to replace a child (and its description already states that it is supposed to be usable for that at some point in the future). So after I've written all of this, I feel like the new insert-node and remove-node commands are exactly what x-blockdev-change should do when asked to replace a node. The only difference is that x-blockdev-change would allow you to replace any node with anything, without the constraints that block-insert-node and block-remove-node exact. (And node replacement with x-blockdev-change would work by specifying all three parameters.) Not sure if that makes sense, I hope it does.
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On Wed, Oct 04, 2017 at 02:49:27PM +0200, Max Reitz wrote: On 2017-08-15 09:45, Manos Pitsidianakis wrote: block-insert-node and its pair command block-remove-node provide runtime insertion and removal of filter nodes. block-insert-node takes a (parent, child) and (node, child) pair of edges and unrefs the (parent, child) BdrvChild relationship and creates a new (parent, node) child with the same BdrvChildRole. This is a different approach than x-blockdev-change which uses the driver methods bdrv_add_child() and bdrv_del_child(), Why? :-) Can't we reuse x-blockdev-change? As far as I'm concerned, this was one of its roles, and at least I don't want to have both x-blockdev-change and these new commands. I think it would be a good idea just to change bdrv_add_child() and bdrv_del_child(): If the driver has a bdrv_{add,del}_child() callback, invoke that. If it doesn't, then just attach the child. Of course, it may turn out that x-blockdev-change is lacking something (e.g. a way to specify as what kind of child a new node is to be attached). Then we should either extend it so that it covers what it's lacking, or replace it completely by these new commands. In the latter case, however, they would need to cover the existing use case which is reconfiguring the quorum driver. (And that would mean it would have to invoke bdrv_add_child()/bdrv_del_child() when the driver has them.) Max I think the two use cases are this: a) Adding/removing a replication child to an existing quorum node b) Insert a filter between two existing nodes. These are not directly compatible semantically, but as you said x-blockdev-change can perform b) if bdrv_add_child()/bdrv_del_child() are not implemented. Wouldn't that be unnecessary overloading? signature.asc Description: PGP signature
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
Am 04.10.2017 um 14:23 hat Manos Pitsidianakis geschrieben: > > > diff --git a/block.c b/block.c > > > index 81bd51b670..f874aabbfb 100644 > > > --- a/block.c > > > +++ b/block.c > > > +/* insert 'node' as child bs of 'parent' node */ > > > +if (check_node_edge(parent, child, errp)) { > > > +return; > > > +} > > > +parent_bs = bdrv_find_node(parent); > > > +c = bdrv_find_child(parent_bs, child); > > > +role = c->role; > > > +assert(role == _file || role == _backing); > > > + > > > +bdrv_ref(node_bs); > > > + > > > +bdrv_drained_begin(parent_bs); > > > +bdrv_unref_child(parent_bs, c); > > > +if (role == _file) { > > > +parent_bs->file = bdrv_attach_child(parent_bs, node_bs, "file", > > > +_file, errp); > > > +if (!parent_bs->file) { > > > +parent_bs->file = bdrv_attach_child(parent_bs, child_bs, > > > "file", > > > +_file, > > > _abort); > > > +goto out; > > > +} > > > +} else if (role == _backing) { > > > +parent_bs->backing = bdrv_attach_child(parent_bs, node_bs, > > > "backing", > > > + _backing, errp); > > > +if (!parent_bs->backing) { > > > +parent_bs->backing = bdrv_attach_child(parent_bs, child_bs, > > > + "backing", > > > _backing, > > > + _abort); > > > +goto out; > > > +} > > > +} > > > > I would prefer if we could find a solution to avoid requiring a specific > > role. I'm not even sure that your assertion above is correct; can you > > explain why c couldn't have any other role? > > > > Instead of bdrv_unref_child/bdrv_attach_child, could we just change > > where the child points to using bdrv_replace_child()? Then > > bdrv_replace_child() uses bdrv_set_perm() and co. When I tried it at first I > got errors like "Conflicts with use by ** as 'backing', which does not > allow 'write' on disk". Presumably the permissions do not need to change but > can we do bdrv_set_perm without bdrv_check_perm? Which child is conflicting with which other child? Is c conflicting with itself or something? If unref_child/attach_child works without any other action in between, there is no reason why replace_child shouldn't work, too. Maybe this is a bug in bdrv_ > > parent_bs->file and parent_bs->backing (or whatever other variable > > contains the BdrvChild pointer) can stay unchanged and just keep > > working. > > > > > +bdrv_refresh_filename(parent_bs); > > > +bdrv_refresh_limits(parent_bs, NULL); > > > + > > > +out: > > > +bdrv_drained_end(parent_bs); > > > +} > > > > > diff --git a/blockdev.c b/blockdev.c > > > index 8e2fc6e64c..5195ec1b61 100644 > > > --- a/blockdev.c > > > +++ b/blockdev.c > > > @@ -4238,3 +4238,47 @@ QemuOptsList qemu_drive_opts = { > > > { /* end of list */ } > > > }, > > > }; > > > + > > > +void qmp_block_insert_node(const char *parent, const char *child, > > > + const char *node, Error **errp) > > > +{ > > > +BlockDriverState *bs = bdrv_find_node(node); > > > +if (!bs) { > > > +error_setg(errp, "Node '%s' not found", node); > > > +return; > > > +} > > > +if (!bs->monitor_list.tqe_prev) { > > > +error_setg(errp, "Node '%s' is not owned by the monitor", > > > + bs->node_name); > > > +return; > > > +} > > > +if (!bs->drv->is_filter) { > > > +error_setg(errp, "Block format '%s' used by node '%s' does not > > > support" > > > + "insertion", bs->drv->format_name, bs->node_name); > > > +return; > > > +} > > > + > > > +bdrv_insert_node(parent, child, node, errp); > > > +} > > > > Do we need to acquire an AioContext lock somewhere? > > the *_child() functions call drained_begin/end which I think might cover > this case? I don't think it's enough when you don't own the AioContext lock. Kevin signature.asc Description: PGP signature
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On 2017-08-15 09:45, Manos Pitsidianakis wrote: > block-insert-node and its pair command block-remove-node provide runtime > insertion and removal of filter nodes. > > block-insert-node takes a (parent, child) and (node, child) pair of > edges and unrefs the (parent, child) BdrvChild relationship and creates > a new (parent, node) child with the same BdrvChildRole. > > This is a different approach than x-blockdev-change which uses the driver > methods bdrv_add_child() and bdrv_del_child(), Why? :-) Can't we reuse x-blockdev-change? As far as I'm concerned, this was one of its roles, and at least I don't want to have both x-blockdev-change and these new commands. I think it would be a good idea just to change bdrv_add_child() and bdrv_del_child(): If the driver has a bdrv_{add,del}_child() callback, invoke that. If it doesn't, then just attach the child. Of course, it may turn out that x-blockdev-change is lacking something (e.g. a way to specify as what kind of child a new node is to be attached). Then we should either extend it so that it covers what it's lacking, or replace it completely by these new commands. In the latter case, however, they would need to cover the existing use case which is reconfiguring the quorum driver. (And that would mean it would have to invoke bdrv_add_child()/bdrv_del_child() when the driver has them.) Max signature.asc Description: OpenPGP digital signature
Re: [Qemu-block] [PATCH RFC] block: add block-insert-node QMP command
On Fri, Sep 29, 2017 at 07:52:35PM +0200, Kevin Wolf wrote: Am 15.08.2017 um 09:45 hat Manos Pitsidianakis geschrieben: block-insert-node and its pair command block-remove-node provide runtime insertion and removal of filter nodes. block-insert-node takes a (parent, child) and (node, child) pair of edges and unrefs the (parent, child) BdrvChild relationship and creates a new (parent, node) child with the same BdrvChildRole. This is a different approach than x-blockdev-change which uses the driver methods bdrv_add_child() and bdrv_del_child(), Signed-off-by: Manos Pitsidianakisdiff --git a/qapi/block-core.json b/qapi/block-core.json index 4d6ba1baef..16e19cb648 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3947,3 +3947,63 @@ 'data' : { 'parent': 'str', '*child': 'str', '*node': 'str' } } + +## +# @block-insert-node: +# +# Insert a filter node between a specific edge in the block driver state graph. +# @parent: the name of the parent node or device +# @node:the name of the node to insert under parent +# @child: the name of the child of both node and parent +# +# Example: +# Insert and remove a throttle filter on top of a device chain, between the +# device 'ide0-hd0' and node 'node-A' +# +# -> {'execute': 'object-add', +# "arguments": { +# "qom-type": "throttle-group", +# "id": "group0", +# "props" : { "limits": { "iops-total": 300 } } +# } +#} +# <- { 'return': {} } +# -> {'execute': 'blockdev-add', +# 'arguments': { +# 'driver': 'throttle', +# 'node-name': 'throttle0', +# 'throttle-group': 'group0', +# 'file': 'node-A' +# } +#} +# <- { 'return': {} } +# -> { 'execute': 'block-insert-node', +# 'arguments': { 'parent': 'ide0-hd0', 'child': 'node-A', 'node': 'throttle0' } +#} +# <- { 'return': {} } +# -> { 'execute': 'block-remove-node', +# 'arguments': { 'parent': 'ide0-hd0', 'child': 'node-A', 'node': 'throttle0' } +#} +# <- { 'return': {} } +# -> { 'execute': 'blockdev-del', +# 'arguments': { 'node-name': 'throttle0' } +#} +# <- { 'return': {} } +# +## +{ 'command': 'block-insert-node', + 'data': { 'parent': 'str', + 'child': 'str', + 'node': 'str'} } I would suggest a change to the meaning of @child: Instead of using the node-name of the child BDS, I would use the name of the BdrvChild that represents the link. The reason for this is that the node-name could be ambiguous, if you have two edges between the same two nodes. The only use of the node-name of the child that I can remember was for checking that the graph still looks like what the user expects. But I think we came to the conclusion that there are no race conditions to check for if we have manual block job deletion instead of automatic completion which can involve surprise changes to the graph. So probably we don't need the node-name even for this. +## +# @block-remove-node: +# +# Remove a filter node between two other nodes in the block driver state graph. +# @parent: the name of the parent node or device +# @node:the name of the node to remove from parent +# @child: the name of the child of node which will go under parent +## +{ 'command': 'block-remove-node', + 'data': { 'parent': 'str', + 'child': 'str', + 'node': 'str'} } Same thing here. diff --git a/block.c b/block.c index 81bd51b670..f874aabbfb 100644 --- a/block.c +++ b/block.c +/* insert 'node' as child bs of 'parent' node */ +if (check_node_edge(parent, child, errp)) { +return; +} +parent_bs = bdrv_find_node(parent); +c = bdrv_find_child(parent_bs, child); +role = c->role; +assert(role == _file || role == _backing); + +bdrv_ref(node_bs); + +bdrv_drained_begin(parent_bs); +bdrv_unref_child(parent_bs, c); +if (role == _file) { +parent_bs->file = bdrv_attach_child(parent_bs, node_bs, "file", +_file, errp); +if (!parent_bs->file) { +parent_bs->file = bdrv_attach_child(parent_bs, child_bs, "file", +_file, _abort); +goto out; +} +} else if (role == _backing) { +parent_bs->backing = bdrv_attach_child(parent_bs, node_bs, "backing", + _backing, errp); +if (!parent_bs->backing) { +parent_bs->backing = bdrv_attach_child(parent_bs, child_bs, + "backing", _backing, + _abort); +goto out; +} +} I would prefer if we could find a solution to avoid requiring a specific role. I'm not even sure that your assertion above is correct; can you explain why c couldn't have any other role? Instead of bdrv_unref_child/bdrv_attach_child, could we just