]> git.proxmox.com Git - mirror_qemu.git/commit - block/block-backend.c
block: Leave valid throttle timers when removing a BDS from a backend
authorAlberto Garcia <berto@igalia.com>
Fri, 10 Nov 2017 18:54:47 +0000 (20:54 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Mon, 13 Nov 2017 15:43:49 +0000 (15:43 +0000)
commitc89bcf3af01e7a8834cca5344e098bf879e99999
tree298bffe14a73ad8e7bbb07efeee1b638ca54a713
parent48bf7ea81aa848027bad24f7e7791b503dff727d
block: Leave valid throttle timers when removing a BDS from a backend

If a BlockBackend has I/O limits set then its ThrottleGroupMember
structure uses the AioContext from its attached BlockDriverState.
Those two contexts must be kept in sync manually. This is not
ideal and will be fixed in the future by removing the throttling
configuration from the BlockBackend and storing it in an implicit
filter node instead, but for now we have to live with this.

When you remove the BlockDriverState from the backend then the
throttle timers are destroyed. If a new BlockDriverState is later
inserted then they are created again using the new AioContext.

There are a couple of problems with this:

   a) The code manipulates the timers directly, leaving the
      ThrottleGroupMember.aio_context field in an inconsisent state.

   b) If you remove the I/O limits (e.g by destroying the backend)
      when the timers are gone then throttle_group_unregister_tgm()
      will attempt to destroy them again, crashing QEMU.

While b) could be fixed easily by allowing the timers to be freed
twice, this would result in a situation in which we can no longer
guarantee that a valid ThrottleState has a valid AioContext and
timers.

This patch ensures that the timers and AioContext are always valid
when I/O limits are set, regardless of whether the BlockBackend has a
BlockDriverState inserted or not.

[Fixed "There'a" typo as suggested by Max Reitz <mreitz@redhat.com>
--Stefan]

Reported-by: sochin jiang <sochin.jiang@huawei.com>
Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: e089c66e7c20289b046d782cea4373b765c5bc1d.1510339534.git.berto@igalia.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/block-backend.c