[lxc-devel] [RFC PATCH] lxclock: Replace named sempahore with flock
Serge Hallyn
serge.hallyn at ubuntu.com
Fri May 24 13:23:57 UTC 2013
Quoting Serge Hallyn (serge.hallyn at ubuntu.com):
> The problem: if a task is killed while holding a posix semaphore,
> there appears to be no way to have the semaphore be reliably
> autmoatically released. The only trick which seemed promising
> is to store the pid of the lock holder in some file and have
> later lock seekers check whether that task has died.
>
> Instead of going down that route, this patch switches from a
> named posix semaphore to flock. The advantage is that when
> the task is killed, its fds are closed and locks are automatically
> released.
>
> The disadvantage of flock is that we can't rely on it to exclude
> threads. Therefore c->slock must now always be wrapped inside
> c->privlock.
>
> This patch survived basic testing with the lxcapi_create patchset,
> where now killing lxc-create while it was holding the lock did
> not lock up future api commands.
Two more notes:
1. the new lock doesn't support timeouts like the old one did.
There's no caller which is currently using timeouts, so I will
probably remove timeouts from the private semaphore as well.
2. It doesn't seem necessary to require everyone to understand
the details, so I may abstrace away knowledge of c->privlock
and c->slock behind two helpers. Not sure what good names would
be, maybe c->memlock() and c->disklock() ? c->threadlock()
and c->globallock()? Something to indicate that the first is
to protect the struct lxc_container from simultaneous updates
from other threads, while the latter is to protect the on-disk
container.
-serge
More information about the lxc-devel
mailing list