You use 'and' in description like this patch have to distinct purposes.
Looks like a candidate for splitting.
Say in first patch you use inroduced functions and thus fix a race. By
the way this could be done in one step with introducing the functions.
In second you refactor prlsdkHandleVmAddedEv
Use prlsdkNewDomain() and prlsdkSetDomainInstance() instead of prlsdkAddDomain()
New algorithm for creating an instance:
In vzDomainDefineXMLFlags() we add new domain to domain list by calling
prlsdkNewDomain()
and only after that we call CreateVm() to create VM.
It means that we "reserve" domain