libvirt/po
Daniel P. Berrange eca72d4759 Introduce an internal API for handling file based lockspaces
The previously introduced virFile{Lock,Unlock} APIs provide a
way to acquire/release fcntl() locks on individual files. For
unknown reason though, the POSIX spec says that fcntl() locks
are released when *any* file handle referring to the same path
is closed. In the following sequence

  threadA: fd1 = open("foo")
  threadB: fd2 = open("foo")
  threadA: virFileLock(fd1)
  threadB: virFileLock(fd2)
  threadB: close(fd2)

you'd expect threadA to come out holding a lock on 'foo', and
indeed it does hold a lock for a very short time. Unfortunately
when threadB does close(fd2) this releases the lock associated
with fd1. For the current libvirt use case for virFileLock -
pidfiles - this doesn't matter since the lock is acquired
at startup while single threaded an never released until
exit.

To provide a more generally useful API though, it is necessary
to introduce a slightly higher level abstraction, which is to
be referred to as a "lockspace".  This is to be provided by
a virLockSpacePtr object in src/util/virlockspace.{c,h}. The
core idea is that the lockspace keeps track of what files are
already open+locked. This means that when a 2nd thread comes
along and tries to acquire a lock, it doesn't end up opening
and closing a new FD. The lockspace just checks the current
list of held locks and immediately returns VIR_ERR_RESOURCE_BUSY.

NB, the API as it stands is designed on the basis that the
files being locked are not being otherwise opened and used
by the application code. One approach to using this API is to
acquire locks based on a hash of the filepath.

eg to lock /var/lib/libvirt/images/foo.img the application
might do

   virLockSpacePtr lockspace = virLockSpaceNew("/var/lib/libvirt/imagelocks");
   lockname = md5sum("/var/lib/libvirt/images/foo.img");
   virLockSpaceAcquireLock(lockspace, lockname);

NB, in this example, the caller should ensure that the path
is canonicalized before calculating the checksum.

It is also possible to do locks directly on resources by
using a NULL lockspace directory and then using the file
path as the lock name eg

   virLockSpacePtr lockspace = virLockSpaceNew(NULL);
   virLockSpaceAcquireLock(lockspace, "/var/lib/libvirt/images/foo.img");

This is only safe to do though if no other part of the process
will be opening the files. This will be the case when this
code is used inside the soon-to-be-reposted virlockd daemon

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-10-16 15:45:55 +01:00
..
af.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
am.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ar.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
as.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
be.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
bg.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
bn_IN.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
bn.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
bs.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ca.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
cs.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
cy.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
da.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
de.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
el.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
en_GB.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
es.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
et.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
eu_ES.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
fa.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
fi.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
fr.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
gl.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
gu.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
he.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
hi.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
hr.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
hu.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
hy.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
id.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
is.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
it.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ja.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ka.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
kn.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ko.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ku.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
libvirt.pot Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
lo.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
lt.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
lv.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
mk.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ml.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
mr.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ms.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
my.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
nb.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
nl.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
nn.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
nso.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
or.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
pa.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
pl.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
POTFILES.in Introduce an internal API for handling file based lockspaces 2012-10-16 15:45:55 +01:00
pt_BR.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
pt.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ro.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ru.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
si.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
sk.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
sl.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
sq.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
sr.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
sr@latin.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
sv.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ta.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
te.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
th.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
tr.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
uk.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
ur.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
vi_VN.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
vi.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
zh_CN.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
zh_TW.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00
zu.po Release of libvirt-0.10.2 2012-09-24 12:46:37 +08:00