[CRIU] Thread safety of C API

Michal Privoznik mprivozn at redhat.com
Thu Jun 9 01:40:23 PDT 2016


On 09.06.2016 00:56, Tycho Andersen wrote:
> On Wed, Jun 08, 2016 at 03:44:10PM -0700, Andrew Vagin wrote:
>> On Wed, Jun 08, 2016 at 03:14:25PM +0200, Michal Privoznik wrote:
>>> Dear list,
>>>
>>> forgive me if this question has been asked already, but I didn't find
>>> anything about that. Katerina (CCed) and me are working on implementing
>>> migration support for our LXC driver [1] in libvirt [2]. And we wanted
>>> to use the C API, however reading the documentation to that [3] and
>>> checking out the sources we've found that C API is not threat safe. This
>>> is a bummer, since libvirt is multi-threaded app where each thread is
>>> allowed to execute an API over distant VMs (in this case containers) at
>>> the same time. So we are unable to use the C API unless we serialize the
>>> callers wanting to migrate on a mutex. This would, however, have
>>> unfortunate effect on our performance.
>>>
>>> My question here is, are there any plans on making the APIs thread safe?
>>> I don't know what's the policy on changing APIs (for instance in Libvirt
>>> we don't allow that and have to invent a new one for the flawed ones). I
>>> can provide the patches if there's not enough bandwidth, but I'd rather
>>> check with you before devoting my time to it.
>>
>> What do we need to do to make it thread-safe?
> 
> I think if you use the criu_local_* options it is thread safe, isn't
> it? My understanding is that libprotobuf is threadsafe, so as long as
> you're not using the global struct it should be okay.

D'oh! I should have checked the code better before making any fuss.
Sorry guys. Looks like criu_local_* is exactly what we need. Thanks for
the reference!

Michal


More information about the CRIU mailing list