]> git.ipfire.org Git - thirdparty/libvirt.git/commit
qemu_capabilities: Rework domain caps cache
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 24 Jan 2020 09:43:29 +0000 (10:43 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 24 Jan 2020 13:48:44 +0000 (14:48 +0100)
commitc76009313f8068c848cad6cb517daf42e6716bb9
tree4c5a7c75ff16a2fdc38f94296855eb37f49c5dff
parentcc361a34c53210d682dbc5f2d506b4a23b71e399
qemu_capabilities: Rework domain caps cache

Since v5.6.0-48-g270583ed98 we try to cache domain capabilities,
i.e. store filled virDomainCaps in a hash table in virQEMUCaps
for future use. However, there's a race condition in the way it's
implemented. We use virQEMUCapsGetDomainCapsCache() to obtain the
pointer to the hash table, then we search the hash table for
cached data and if none is found the domcaps is constructed and
put into the table. Problem is that this is all done without any
locking, so if there are two threads trying to do the same, one
will succeed and the other will fail inserting the data into the
table.

Also, the API looks a bit fishy - obtaining pointer to the hash
table is dangerous.

The solution is to use a mutex that guards the whole operation
with the hash table. Then, the API can be changes to return
virDomainCapsPtr directly.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1791790

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_conf.c