提交 297c704a 编写于 作者: J Jiri Denemark

locking: Add support for lock failure action

上级 d236f3fc
......@@ -1502,7 +1502,7 @@ lockdriverdir = $(libdir)/libvirt/lock-driver
lockdriver_LTLIBRARIES = sanlock.la
sanlock_la_SOURCES = $(LOCK_DRIVER_SANLOCK_SOURCES)
sanlock_la_CFLAGS = $(AM_CFLAGS)
sanlock_la_CFLAGS = -I$(top_srcdir)/src/conf $(AM_CFLAGS)
sanlock_la_LDFLAGS = -module -avoid-version
sanlock_la_LIBADD = -lsanlock_client \
../gnulib/lib/libgnu.la
......
......@@ -175,7 +175,8 @@ int virDomainLockProcessStart(virLockManagerPluginPtr plugin,
if (paused)
flags |= VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY;
ret = virLockManagerAcquire(lock, NULL, flags, fd);
ret = virLockManagerAcquire(lock, NULL, flags,
dom->def->onLockFailure, fd);
virLockManagerFree(lock);
......@@ -215,7 +216,7 @@ int virDomainLockProcessResume(virLockManagerPluginPtr plugin,
if (!(lock = virDomainLockManagerNew(plugin, uri, dom, true)))
return -1;
ret = virLockManagerAcquire(lock, state, 0, NULL);
ret = virLockManagerAcquire(lock, state, 0, dom->def->onLockFailure, NULL);
virLockManagerFree(lock);
return ret;
......@@ -258,7 +259,8 @@ int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
if (virDomainLockManagerAddDisk(lock, disk) < 0)
goto cleanup;
if (virLockManagerAcquire(lock, NULL, 0, NULL) < 0)
if (virLockManagerAcquire(lock, NULL, 0,
dom->def->onLockFailure, NULL) < 0)
goto cleanup;
ret = 0;
......@@ -314,7 +316,8 @@ int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
if (virDomainLockManagerAddLease(lock, lease) < 0)
goto cleanup;
if (virLockManagerAcquire(lock, NULL, 0, NULL) < 0)
if (virLockManagerAcquire(lock, NULL, 0,
dom->def->onLockFailure, NULL) < 0)
goto cleanup;
ret = 0;
......
......@@ -23,6 +23,7 @@
# define __VIR_PLUGINS_LOCK_DRIVER_H__
# include "internal.h"
# include "domain_conf.h"
typedef struct _virLockManager virLockManager;
typedef virLockManager *virLockManagerPtr;
......@@ -218,12 +219,13 @@ typedef int (*virLockDriverAddResource)(virLockManagerPtr man,
* @manager: the lock manager context
* @state: the current lock state
* @flags: optional flags, currently unused
* @action: action to take when lock is lost
* @fd: optional return the leaked FD
*
* 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
* time, the PID will be killed off by the lock manager.
* time, the specified action will be taken.
* The optional state contains information about the
* locks previously held for the object.
*
......@@ -237,6 +239,7 @@ typedef int (*virLockDriverAddResource)(virLockManagerPtr man,
typedef int (*virLockDriverAcquire)(virLockManagerPtr man,
const char *state,
unsigned int flags,
virDomainLockFailureAction action,
int *fd);
/**
......
......@@ -69,6 +69,7 @@ static int virLockManagerNopAddResource(virLockManagerPtr lock ATTRIBUTE_UNUSED,
static int virLockManagerNopAcquire(virLockManagerPtr lock ATTRIBUTE_UNUSED,
const char *state ATTRIBUTE_UNUSED,
unsigned int flags_unused ATTRIBUTE_UNUSED,
virDomainLockFailureAction action ATTRIBUTE_UNUSED,
int *fd ATTRIBUTE_UNUSED)
{
return 0;
......
......@@ -686,6 +686,7 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
const char *state,
unsigned int flags,
virDomainLockFailureAction action ATTRIBUTE_UNUSED,
int *fd)
{
virLockManagerSanlockPrivatePtr priv = lock->privateData;
......
......@@ -347,17 +347,18 @@ int virLockManagerAddResource(virLockManagerPtr lock,
int virLockManagerAcquire(virLockManagerPtr lock,
const char *state,
unsigned int flags,
virDomainLockFailureAction action,
int *fd)
{
VIR_DEBUG("lock=%p state='%s' flags=%x fd=%p",
lock, NULLSTR(state), flags, fd);
VIR_DEBUG("lock=%p state='%s' flags=%x action=%d fd=%p",
lock, NULLSTR(state), flags, action, fd);
CHECK_MANAGER(drvAcquire, -1);
if (fd)
*fd = -1;
return lock->driver->drvAcquire(lock, state, flags, fd);
return lock->driver->drvAcquire(lock, state, flags, action, fd);
}
......
......@@ -56,6 +56,7 @@ int virLockManagerAddResource(virLockManagerPtr manager,
int virLockManagerAcquire(virLockManagerPtr manager,
const char *state,
unsigned int flags,
virDomainLockFailureAction action,
int *fd);
int virLockManagerRelease(virLockManagerPtr manager,
char **state,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册