2010-09-13 13:02:58 +00:00
|
|
|
/*
|
|
|
|
* lock_driver.h: Defines the lock driver plugin API
|
|
|
|
*
|
2012-12-17 15:03:23 +00:00
|
|
|
* Copyright (C) 2010-2011, 2013 Red Hat, Inc.
|
2010-09-13 13:02:58 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-09-13 13:02:58 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_PLUGINS_LOCK_DRIVER_H__
|
|
|
|
# define __VIR_PLUGINS_LOCK_DRIVER_H__
|
|
|
|
|
|
|
|
# include "internal.h"
|
2012-09-18 11:40:13 +00:00
|
|
|
# include "domain_conf.h"
|
2010-09-13 13:02:58 +00:00
|
|
|
|
|
|
|
typedef struct _virLockManager virLockManager;
|
|
|
|
typedef virLockManager *virLockManagerPtr;
|
|
|
|
|
|
|
|
typedef struct _virLockDriver virLockDriver;
|
|
|
|
typedef virLockDriver *virLockDriverPtr;
|
|
|
|
|
|
|
|
typedef struct _virLockManagerParam virLockManagerParam;
|
|
|
|
typedef virLockManagerParam *virLockManagerParamPtr;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* State passing is used to re-acquire existing leases */
|
|
|
|
VIR_LOCK_MANAGER_USES_STATE = (1 << 0)
|
|
|
|
} virLockManagerFlags;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* The managed object is a virtual guest domain */
|
|
|
|
VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN = 0,
|
|
|
|
} virLockManagerObjectType;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* The resource to be locked is a virtual disk */
|
|
|
|
VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK = 0,
|
|
|
|
/* A lease against an arbitrary resource */
|
|
|
|
VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE = 1,
|
|
|
|
} virLockManagerResourceType;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* The resource is assigned in readonly mode */
|
|
|
|
VIR_LOCK_MANAGER_RESOURCE_READONLY = (1 << 0),
|
|
|
|
/* The resource is assigned in shared, writable mode */
|
|
|
|
VIR_LOCK_MANAGER_RESOURCE_SHARED = (1 << 1),
|
|
|
|
} virLockManagerResourceFlags;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* Don't acquire the resources, just register the object PID */
|
2011-06-02 10:46:56 +00:00
|
|
|
VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY = (1 << 0),
|
|
|
|
/* Prevent further lock/unlock calls from this process */
|
|
|
|
VIR_LOCK_MANAGER_ACQUIRE_RESTRICT = (1 << 1),
|
2010-09-13 13:02:58 +00:00
|
|
|
} virLockManagerAcquireFlags;
|
|
|
|
|
2015-03-06 14:58:55 +00:00
|
|
|
typedef enum {
|
|
|
|
/* virLockManagerNew called for a freshly started domain */
|
|
|
|
VIR_LOCK_MANAGER_NEW_STARTED = (1 << 0),
|
|
|
|
} virLockManagerNewFlags;
|
|
|
|
|
2010-09-13 13:02:58 +00:00
|
|
|
enum {
|
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_STRING,
|
2012-09-17 13:12:53 +00:00
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_CSTRING,
|
2010-09-13 13:02:58 +00:00
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_INT,
|
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_LONG,
|
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_UINT,
|
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_ULONG,
|
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_DOUBLE,
|
|
|
|
VIR_LOCK_MANAGER_PARAM_TYPE_UUID,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _virLockManagerParam {
|
|
|
|
int type;
|
|
|
|
const char *key;
|
|
|
|
union {
|
Convert 'int i' to 'size_t i' in src/locking/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int iv;
|
2010-09-13 13:02:58 +00:00
|
|
|
long long l;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long long ul;
|
|
|
|
double d;
|
|
|
|
char *str;
|
2012-09-17 13:12:53 +00:00
|
|
|
const char *cstr;
|
2010-09-13 13:02:58 +00:00
|
|
|
unsigned char uuid[16];
|
|
|
|
} value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes in major version denote incompatible ABI changes
|
|
|
|
* Changes in minor version denote new compatible API entry points
|
|
|
|
* Changes in micro version denote new compatible flags
|
|
|
|
*/
|
|
|
|
# define VIR_LOCK_MANAGER_VERSION_MAJOR 1
|
|
|
|
# define VIR_LOCK_MANAGER_VERSION_MINOR 0
|
|
|
|
# define VIR_LOCK_MANAGER_VERSION_MICRO 0
|
|
|
|
|
|
|
|
# define VIR_LOCK_MANAGER_VERSION \
|
|
|
|
((VIR_LOCK_MANAGER_VERSION_MAJOR * 1000 * 1000) + \
|
|
|
|
(VIR_LOCK_MANAGER_VERSION_MINOR * 1000) + \
|
|
|
|
(VIR_LOCK_MANAGER_VERSION_MICRO))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverInit:
|
|
|
|
* @version: the libvirt requested plugin ABI version
|
|
|
|
* @flags: the libvirt requested plugin optional extras
|
|
|
|
*
|
|
|
|
* Allow the plugin to validate the libvirt requested
|
|
|
|
* plugin version / flags. This allows the plugin impl
|
|
|
|
* to block its use in versions of libvirtd which are
|
|
|
|
* too old to support key features.
|
|
|
|
*
|
|
|
|
* NB: A plugin may be loaded multiple times, for different
|
|
|
|
* libvirt drivers (eg QEMU, LXC, UML)
|
|
|
|
*
|
|
|
|
* Returns -1 if the requested version/flags were inadequate
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverInit)(unsigned int version,
|
2011-06-13 13:30:26 +00:00
|
|
|
const char *configFile,
|
2010-09-13 13:02:58 +00:00
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverDeinit:
|
|
|
|
*
|
|
|
|
* Called to release any resources prior to the plugin
|
|
|
|
* being unloaded from memory. Returns -1 to prevent
|
|
|
|
* plugin from being unloaded from memory.
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverDeinit)(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockManagerNew:
|
|
|
|
* @man: the lock manager context
|
|
|
|
* @type: the type of process to be supervised
|
|
|
|
* @nparams: number of metadata parameters
|
|
|
|
* @params: extra metadata parameters
|
2015-03-06 14:58:55 +00:00
|
|
|
* @flags: bitwise-OR of virLockManagerNewFlags
|
2010-09-13 13:02:58 +00:00
|
|
|
*
|
|
|
|
* Initialize a new context to supervise a process, usually
|
|
|
|
* a virtual machine. The lock driver implementation can use
|
|
|
|
* the <code>privateData</code> field of <code>man</code>
|
|
|
|
* to store a pointer to any driver specific state.
|
|
|
|
*
|
2015-03-06 14:58:55 +00:00
|
|
|
* If @flags contains VIR_LOCK_MANAGER_NEW_STARTED, this API is called for
|
|
|
|
* a domain that has just been started and may therefore skip some actions.
|
|
|
|
* Specifically, checking whether the domain is registered with a lock
|
|
|
|
* daemon is useless in this case.
|
|
|
|
*
|
2010-09-13 13:02:58 +00:00
|
|
|
* A process of VIR_LOCK_MANAGER_START_DOMAIN will be
|
|
|
|
* given the following parameters
|
|
|
|
*
|
|
|
|
* - id: the domain unique id (unsigned int)
|
|
|
|
* - uuid: the domain uuid (uuid)
|
|
|
|
* - name: the domain name (string)
|
|
|
|
* - pid: process ID to own/owning the lock (unsigned int)
|
2012-09-17 13:36:47 +00:00
|
|
|
* - uri: URI for connecting to the driver the domain belongs to (string)
|
2010-09-13 13:02:58 +00:00
|
|
|
*
|
|
|
|
* Returns 0 if successful initialized a new context, -1 on error
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverNew)(virLockManagerPtr man,
|
|
|
|
unsigned int type,
|
|
|
|
size_t nparams,
|
|
|
|
virLockManagerParamPtr params,
|
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverFree:
|
|
|
|
* @manager: the lock manager context
|
|
|
|
*
|
|
|
|
* Release any resources associated with the lock manager
|
|
|
|
* context private data
|
|
|
|
*/
|
|
|
|
typedef void (*virLockDriverFree)(virLockManagerPtr man);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverAddResource:
|
|
|
|
* @manager: the lock manager context
|
|
|
|
* @type: the resource type virLockManagerResourceType
|
|
|
|
* @name: the resource name
|
|
|
|
* @nparams: number of metadata parameters
|
|
|
|
* @params: extra metadata parameters
|
|
|
|
* @flags: the resource access flags
|
|
|
|
*
|
|
|
|
* Assign a resource to a managed object. This will
|
|
|
|
* only be called prior to the object is being locked
|
2012-12-17 15:03:23 +00:00
|
|
|
* when it is inactive (e.g. to set the initial boot
|
|
|
|
* time disk assignments on a VM).
|
2010-09-13 13:02:58 +00:00
|
|
|
* The format of @name varies according to
|
|
|
|
* the resource @type. A VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK
|
|
|
|
* will have the fully qualified file path, while a resource
|
|
|
|
* of type VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE will have the
|
|
|
|
* unique name of the lease
|
|
|
|
*
|
|
|
|
* A resource of type VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE
|
|
|
|
* will receive at least the following extra parameters
|
|
|
|
*
|
|
|
|
* - 'path': a fully qualified path to the lockspace
|
|
|
|
* - 'lockspace': globally string identifying the lockspace name
|
|
|
|
* - 'offset': byte offset within the lease (unsigned long long)
|
|
|
|
*
|
|
|
|
* If no flags are given, the resource is assumed to be
|
|
|
|
* used in exclusive, read-write mode. Access can be
|
|
|
|
* relaxed to readonly, or shared read-write.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 on failure
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverAddResource)(virLockManagerPtr man,
|
|
|
|
unsigned int type,
|
|
|
|
const char *name,
|
|
|
|
size_t nparams,
|
|
|
|
virLockManagerParamPtr params,
|
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverAcquire:
|
|
|
|
* @manager: the lock manager context
|
|
|
|
* @state: the current lock state
|
|
|
|
* @flags: optional flags, currently unused
|
2012-09-18 11:40:13 +00:00
|
|
|
* @action: action to take when lock is lost
|
2011-06-24 14:14:41 +00:00
|
|
|
* @fd: optional return the leaked FD
|
2010-09-13 13:02:58 +00:00
|
|
|
*
|
|
|
|
* Start managing resources for the object. This
|
|
|
|
* must be called from the PID that represents the
|
|
|
|
* object to be managed. If the lock is lost at any
|
2012-09-18 11:40:13 +00:00
|
|
|
* time, the specified action will be taken.
|
2010-09-13 13:02:58 +00:00
|
|
|
* The optional state contains information about the
|
|
|
|
* locks previously held for the object.
|
|
|
|
*
|
2011-06-24 14:14:41 +00:00
|
|
|
* The file descriptor returned in @fd is one that
|
|
|
|
* is intentionally leaked and should not be closed.
|
|
|
|
* It is returned so that it can be labelled by the
|
|
|
|
* security managers (if required).
|
|
|
|
*
|
2010-09-13 13:02:58 +00:00
|
|
|
* Returns 0 on success, or -1 on failure
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverAcquire)(virLockManagerPtr man,
|
|
|
|
const char *state,
|
2011-06-24 14:14:41 +00:00
|
|
|
unsigned int flags,
|
2012-09-18 11:40:13 +00:00
|
|
|
virDomainLockFailureAction action,
|
2011-06-24 14:14:41 +00:00
|
|
|
int *fd);
|
2010-09-13 13:02:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverRelease:
|
|
|
|
* @manager: the lock manager context
|
|
|
|
* @state: pointer to be filled with lock state
|
|
|
|
* @flags: optional flags
|
|
|
|
*
|
|
|
|
* Inform the lock manager that the supervised process has
|
|
|
|
* been, or can be stopped.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 on failure
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverRelease)(virLockManagerPtr man,
|
|
|
|
char **state,
|
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLockDriverInquire:
|
|
|
|
* @manager: the lock manager context
|
|
|
|
* @state: pointer to be filled with lock state
|
|
|
|
* @flags: optional flags, currently unused
|
|
|
|
*
|
|
|
|
* Retrieve the current lock state. The returned
|
|
|
|
* lock state may be NULL if none is required. The
|
|
|
|
* caller is responsible for freeing the lock
|
|
|
|
* state string when it is no longer required
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 on failure.
|
|
|
|
*/
|
|
|
|
typedef int (*virLockDriverInquire)(virLockManagerPtr man,
|
|
|
|
char **state,
|
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
|
|
|
|
struct _virLockManager {
|
|
|
|
virLockDriverPtr driver;
|
|
|
|
void *privateData;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The plugin must export a static instance of this
|
|
|
|
* driver table, with the name 'virLockDriverImpl'
|
|
|
|
*/
|
|
|
|
struct _virLockDriver {
|
|
|
|
/**
|
|
|
|
* @version: the newest implemented plugin ABI version
|
|
|
|
* @flags: optional flags, currently unused
|
|
|
|
*/
|
|
|
|
unsigned int version;
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
virLockDriverInit drvInit;
|
|
|
|
virLockDriverDeinit drvDeinit;
|
|
|
|
|
|
|
|
virLockDriverNew drvNew;
|
|
|
|
virLockDriverFree drvFree;
|
|
|
|
|
|
|
|
virLockDriverAddResource drvAddResource;
|
|
|
|
|
|
|
|
virLockDriverAcquire drvAcquire;
|
|
|
|
virLockDriverRelease drvRelease;
|
|
|
|
virLockDriverInquire drvInquire;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __VIR_PLUGINS_LOCK_DRIVER_H__ */
|