]> git.ipfire.org Git - thirdparty/libvirt.git/commit
qemu: Fix domain ID numbering race condition
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Nov 2012 12:48:37 +0000 (13:48 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 8 Nov 2012 23:12:38 +0000 (00:12 +0100)
commit02cf57c0d0d2333dceadb7f84b08ec28a35ef540
tree431dbfe169b18c6b3b6ba228494e575d996c7037
parente0c469e58b93f852a72265919703cb6abd3779f8
qemu: Fix domain ID numbering race condition

When the libvirt daemon is restarted it tries to reconnect to running
qemu domains. Since commit d38897a5d4b1880e1998394b2a37bba979bbdff1 the
re-connection code runs in separate threads. In the original
implementation the maximum of domain ID's (that is used as an
initializer for numbering guests created next) while libvirt was
reconnecting to the guest.

With the threaded implementation this opens a possibility for race
conditions with the thread that is autostarting guests. When there's a
guest running with id 1 and the daemon is restarted. The autostart code
is reached first and spawns the first guest that should be autostarted
as id 1. This results into the following unwanted situation:

 # virsh list
   Id    Name                           State
  ----------------------------------------------------
   1     guest1                         running
   1     guest2                         running

This patch extracts the detection code before the re-connection threads
are started so that the maximum id of the guests being reconnected to is
known.

The only semantic change created by this is if the guest with greatest ID
quits before we are able to reconnect it's ID is used anyway as the
greatest one as without this patch the greatest ID of a process we could
successfuly reconnect to would be used.
src/qemu/qemu_driver.c
src/qemu/qemu_process.c