libxl: functions to lock / unlock libxl userdata store
authorWei Liu <wei.liu2@citrix.com>
Thu, 4 Sep 2014 22:43:08 +0000 (23:43 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 9 Sep 2014 11:45:10 +0000 (12:45 +0100)
commitd2cd9d4f56c3efd4d9e1b5040dfd7f418635554a
tree070f3e34820697093a795bb73618270b2f06da7e
parent34714e3222eab8cfc0b3a9d5b46b2dfe6dcc7f7f
libxl: functions to lock / unlock libxl userdata store

This lock is used to protect all userdata files related to a particular
domain, which include but are not limited to domain configuration.  A
new "domain-userdata-lock" entry is introduced in libxl registry.

This lock works among different processes and different threads within
the same process.

Locking protocol inspired by Ian Jackson's chiark-utils with-lock-ex. A
file lock is taken with flock(2). If that succeeds that thread fstat the
fd and stat the lock file path. If the device and inode match then the
lock has been successfully acquired. This lock remains acquired until
the lock file gets deleted or released by flock(2). If device and inode
don't match then another thread acquired the lock and deleted the file
in the meantime; lock procedure should restart.

Portability note: this lock utilises flock(2) so a proper implementation
of flock(2) is required -- that is, it should not be implemented with
fcntl(2).

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl.h
tools/libxl/libxl_internal.c
tools/libxl/libxl_internal.h