LXC
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Functions
lxclock.h File Reference
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <semaphore.h>
#include <string.h>
#include <time.h>
Include dependency graph for lxclock.h:

Go to the source code of this file.

Data Structures

struct  lxc_lock
 

Macros

#define LXC_LOCK_ANON_SEM   1
 
#define LXC_LOCK_FLOCK   2
 

Functions

struct lxc_locklxc_newlock (const char *lxcpath, const char *name)
 Create a new (unlocked) lock. More...
 
int lxclock (struct lxc_lock *lock, int timeout)
 Take an existing lock. More...
 
int lxcunlock (struct lxc_lock *lock)
 Unlock specified lock previously locked using lxclock(). More...
 
void lxc_putlock (struct lxc_lock *lock)
 Free a lock created by lxc_newlock(). More...
 
void process_lock (void)
 Lock the current process.
 
void process_unlock (void)
 Unlock the current process.
 
int container_mem_lock (struct lxc_container *c)
 Lock the containers memory. More...
 
void container_mem_unlock (struct lxc_container *c)
 Unlock the containers memory. More...
 
int container_disk_lock (struct lxc_container *c)
 Lock the containers disk data. More...
 
void container_disk_unlock (struct lxc_container *c)
 Unlock the containers disk data. More...
 

Detailed Description

liblxcapi

Copyright © 2012 Serge Hallyn serge.nosp@m..hal.nosp@m.lyn@u.nosp@m.bunt.nosp@m.u.com. Copyright © 2012 Canonical Ltd.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Macro Definition Documentation

#define LXC_LOCK_ANON_SEM   1

Anonymous semaphore lock

#define LXC_LOCK_FLOCK   2

flock(2) lock

Function Documentation

int container_disk_lock ( struct lxc_container c)

Lock the containers disk data.

Parameters
cContainer.
Returns
0 on success, or an lxclock() error return values on error.
void container_disk_unlock ( struct lxc_container c)

Unlock the containers disk data.

Parameters
cContainer.
int container_mem_lock ( struct lxc_container c)

Lock the containers memory.

Parameters
cContainer.
Returns
As for lxclock().
void container_mem_unlock ( struct lxc_container c)

Unlock the containers memory.

Parameters
cContainer.
struct lxc_lock* lxc_newlock ( const char *  lxcpath,
const char *  name 
)

Create a new (unlocked) lock.

Parameters
lxcpathlxcpath lock should relate to.
nameName for lock.
Returns
Newly-allocated lxclock on success, NULL on failure.
Note
If name is not given, create an unnamed semaphore (used to protect against racing threads).
Note that an unnamed sem was malloced by us and needs to be freed.
void lxc_putlock ( struct lxc_lock lock)

Free a lock created by lxc_newlock().

Parameters
lockLock.
int lxclock ( struct lxc_lock lock,
int  timeout 
)

Take an existing lock.

Parameters
lockLock to operate on.
timeoutSeconds to wait to take lock (0 signifies an indefinite wait).
Returns
0 if lock obtained, -2 on failure to set timeout, or -1 on any other error (errno will be set by sem_wait(3) or fcntl(2)).
Note
timeout is (currently?) only supported for privlock, not for slock. Since currently there is not a single use of the timeout (except in the test case) I may remove the support for it in sem as well.
int lxcunlock ( struct lxc_lock lock)

Unlock specified lock previously locked using lxclock().

Parameters
locklxc_lock.
Returns
0 on success, -2 if provided lock was not already held, otherwise -1 with errno saved from fcntl(2) or sem_post function.