Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Evergreen:11.4
lvm2
clvmd-openais-use-dlm.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File clvmd-openais-use-dlm.diff of Package lvm2
Index: LVM2.2.02.67/daemons/clvmd/Makefile.in =================================================================== --- LVM2.2.02.67.orig/daemons/clvmd/Makefile.in 2010-04-09 23:42:48.000000000 +0200 +++ LVM2.2.02.67/daemons/clvmd/Makefile.in 2010-09-09 13:52:33.857385191 +0200 @@ -58,7 +58,7 @@ endif ifneq (,$(findstring openais,, "@CLVMD@,")) SOURCES += clvmd-openais.c - LMLIBS += $(CONFDB_LIBS) $(CPG_LIBS) $(SALCK_LIBS) + LMLIBS += $(CONFDB_LIBS) -ldlm $(CPG_LIBS) CFLAGS += $(CONFDB_CFLAGS) $(CPG_CFLAGS) $(SALCK_CFLAGS) DEFS += -DUSE_OPENAIS endif Index: LVM2.2.02.67/daemons/clvmd/clvm.h =================================================================== --- LVM2.2.02.67.orig/daemons/clvmd/clvm.h 2010-09-09 13:52:32.000000000 +0200 +++ LVM2.2.02.67/daemons/clvmd/clvm.h 2010-09-09 13:53:02.258385366 +0200 @@ -83,6 +83,7 @@ static const char CLVMD_SOCKNAME[] = "\0 /* Locking flags - these match the ones * in dlm.h */ +#ifndef LKF_NOQUEUE #define LKF_NOQUEUE (0x00000001) #define LKF_CANCEL (0x00000002) #define LKF_CONVERT (0x00000004) @@ -97,3 +98,5 @@ static const char CLVMD_SOCKNAME[] = "\0 #define LKF_NOQUEUEBAST (0x00000800) #define LKF_HEADQUE (0x00001000) #define LKF_NOORDER (0x00002000) + +#endif Index: LVM2.2.02.67/daemons/clvmd/clvmd-openais.c =================================================================== --- LVM2.2.02.67.orig/daemons/clvmd/clvmd-openais.c 2009-09-15 14:51:28.000000000 +0200 +++ LVM2.2.02.67/daemons/clvmd/clvmd-openais.c 2010-09-09 13:52:33.858385280 +0200 @@ -44,9 +44,9 @@ #include <syslog.h> #include <assert.h> #include <libdevmapper.h> +#include <libdlm.h> #include <openais/saAis.h> -#include <openais/saLck.h> #include <corosync/corotypes.h> #include <corosync/cpg.h> @@ -61,6 +61,8 @@ /* Timeout value for several openais calls */ #define TIMEOUT 10 +#define LOCKSPACE_NAME "clvmd" + static void openais_cpg_deliver_callback (cpg_handle_t handle, const struct cpg_name *groupName, uint32_t nodeid, @@ -78,9 +80,6 @@ static void _cluster_closedown(void); /* Hash list of nodes in the cluster */ static struct dm_hash_table *node_hash; -/* For associating lock IDs & resource handles */ -static struct dm_hash_table *lock_hash; - /* Number of active nodes */ static int num_nodes; static unsigned int our_nodeid; @@ -89,9 +88,15 @@ static struct local_client *cluster_clie /* OpenAIS handles */ static cpg_handle_t cpg_handle; -static SaLckHandleT lck_handle; static struct cpg_name cpg_group_name; +static dlm_lshandle_t *lockspace; + +struct lock_wait { + pthread_cond_t cond; + pthread_mutex_t mutex; + struct dlm_lksb lksb; +}; /* Openais callback structs */ cpg_callbacks_t openais_cpg_callbacks = { @@ -105,13 +110,6 @@ struct node_info int nodeid; }; -struct lock_info -{ - SaLckResourceHandleT res_handle; - SaLckLockIdT lock_id; - SaNameT lock_name; -}; - /* Set errno to something approximating the right value and return 0 or -1 */ static int ais_to_errno(SaAisErrorT err) { @@ -321,22 +319,11 @@ static void openais_cpg_confchg_callback num_nodes = member_list_entries; } -static int lck_dispatch(struct local_client *client, char *buf, int len, - const char *csid, struct local_client **new_client) -{ - *new_client = NULL; - saLckDispatch(lck_handle, SA_DISPATCH_ONE); - return 1; -} - static int _init_cluster(void) { SaAisErrorT err; - SaVersionT ver = { 'B', 1, 1 }; - int select_fd; node_hash = dm_hash_create(100); - lock_hash = dm_hash_create(10); err = cpg_initialize(&cpg_handle, &openais_cpg_callbacks); @@ -347,16 +334,19 @@ static int _init_cluster(void) return ais_to_errno(err); } - err = saLckInitialize(&lck_handle, - NULL, - &ver); - if (err != SA_AIS_OK) { - cpg_initialize(&cpg_handle, &openais_cpg_callbacks); - syslog(LOG_ERR, "Cannot initialise OpenAIS lock service: %d", - err); - DEBUGLOG("Cannot initialise OpenAIS lock service: %d\n\n", err); - return ais_to_errno(err); + /* Create a lockspace for LV & VG locks to live in */ + lockspace = dlm_create_lockspace(LOCKSPACE_NAME, 0600); + if (!lockspace) { + if (errno == EEXIST) { + lockspace = dlm_open_lockspace(LOCKSPACE_NAME); + } + if (!lockspace) { + syslog(LOG_ERR, "Unable to create lockspace for CLVM: %m"); + return -1; + } } + dlm_ls_pthread_init(lockspace); + DEBUGLOG("DLM initialisation complete\n"); /* Connect to the clvmd group */ strcpy((char *)cpg_group_name.value, "clvmd"); @@ -364,7 +354,7 @@ static int _init_cluster(void) err = cpg_join(cpg_handle, &cpg_group_name); if (err != SA_AIS_OK) { cpg_finalize(cpg_handle); - saLckFinalize(lck_handle); + dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 0); syslog(LOG_ERR, "Cannot join clvmd process group"); DEBUGLOG("Cannot join clvmd process group: %d\n", err); return ais_to_errno(err); @@ -374,15 +364,12 @@ static int _init_cluster(void) &our_nodeid); if (err != SA_AIS_OK) { cpg_finalize(cpg_handle); - saLckFinalize(lck_handle); + dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 0); syslog(LOG_ERR, "Cannot get local node id\n"); return ais_to_errno(err); } DEBUGLOG("Our local node id is %d\n", our_nodeid); - saLckSelectionObjectGet(lck_handle, (SaSelectionObjectT *)&select_fd); - add_internal_client(select_fd, lck_dispatch); - DEBUGLOG("Connected to OpenAIS\n"); return 0; @@ -393,7 +380,7 @@ static void _cluster_closedown(void) DEBUGLOG("cluster_closedown\n"); destroy_lvhash(); - saLckFinalize(lck_handle); + dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 0); cpg_finalize(cpg_handle); } @@ -484,156 +471,69 @@ static int _cluster_do_node_callback(str return somedown; } -/* Real locking */ -static int _lock_resource(char *resource, int mode, int flags, int *lockid) +static int _sync_lock(const char *resource, int mode, int flags, int *lockid) { - struct lock_info *linfo; - SaLckResourceHandleT res_handle; - SaAisErrorT err; - SaLckLockIdT lock_id; - SaLckLockStatusT lockStatus; - - /* This needs to be converted from DLM/LVM2 value for OpenAIS LCK */ - if (flags & LCK_NONBLOCK) flags = SA_LCK_LOCK_NO_QUEUE; - - linfo = malloc(sizeof(struct lock_info)); - if (!linfo) - return -1; + struct dlm_lksb lksb; + int err; DEBUGLOG("lock_resource '%s', flags=%d, mode=%d\n", resource, flags, mode); - linfo->lock_name.length = strlen(resource)+1; - strcpy((char *)linfo->lock_name.value, resource); - - err = saLckResourceOpen(lck_handle, &linfo->lock_name, - SA_LCK_RESOURCE_CREATE, TIMEOUT, &res_handle); - if (err != SA_AIS_OK) - { - DEBUGLOG("ResourceOpen returned %d\n", err); - free(linfo); - return ais_to_errno(err); - } + if (flags & LKF_CONVERT) + lksb.sb_lkid = *lockid; - err = saLckResourceLock( - res_handle, - &lock_id, + err = dlm_ls_lock_wait(lockspace, mode, + &lksb, flags, + resource, + strlen(resource), 0, - SA_TIME_END, - &lockStatus); - if (err != SA_AIS_OK && lockStatus != SA_LCK_LOCK_GRANTED) + NULL, NULL, NULL); + + if (err != 0) { - free(linfo); - saLckResourceClose(res_handle); - return ais_to_errno(err); + DEBUGLOG("dlm_ls_lock returned %d\n", errno); + return err; + } + errno = lksb.sb_status; + if (lksb.sb_status != 0) + { + DEBUGLOG("dlm_ls_lock returns lksb.sb_status %d\n", lksb.sb_status); + return -1; } - - /* Wait for it to complete */ - - DEBUGLOG("lock_resource returning %d, lock_id=%llx\n", err, - lock_id); - linfo->lock_id = lock_id; - linfo->res_handle = res_handle; + DEBUGLOG("lock_resource returning %d, lock_id=%x\n", err, lksb.sb_lkid); - dm_hash_insert(lock_hash, resource, linfo); + *lockid = lksb.sb_lkid; - return ais_to_errno(err); + return 0; } - -static int _unlock_resource(char *resource, int lockid) +static int _sync_unlock(const char *resource, int lockid) { - SaAisErrorT err; - struct lock_info *linfo; + struct dlm_lksb lksb; + int err; - DEBUGLOG("unlock_resource %s\n", resource); - linfo = dm_hash_lookup(lock_hash, resource); - if (!linfo) - return 0; + DEBUGLOG("unlock_resource: %s lockid: %x\n", resource, lockid); + lksb.sb_lkid = lockid; - DEBUGLOG("unlock_resource: lockid: %llx\n", linfo->lock_id); - err = saLckResourceUnlock(linfo->lock_id, SA_TIME_END); - if (err != SA_AIS_OK) + err = dlm_ls_unlock_wait(lockspace, + lockid, + 0, + &lksb); + if (err != 0) { DEBUGLOG("Unlock returned %d\n", err); - return ais_to_errno(err); + return err; } - - /* Release the resource */ - dm_hash_remove(lock_hash, resource); - saLckResourceClose(linfo->res_handle); - free(linfo); - - return ais_to_errno(err); -} - -static int _sync_lock(const char *resource, int mode, int flags, int *lockid) -{ - int status; - char lock1[strlen(resource)+3]; - char lock2[strlen(resource)+3]; - - snprintf(lock1, sizeof(lock1), "%s-1", resource); - snprintf(lock2, sizeof(lock2), "%s-2", resource); - - switch (mode) + errno = lksb.sb_status; + if (lksb.sb_status != EUNLOCK) { - case LCK_EXCL: - status = _lock_resource(lock1, SA_LCK_EX_LOCK_MODE, flags, lockid); - if (status) - goto out; - - /* If we can't get this lock too then bail out */ - status = _lock_resource(lock2, SA_LCK_EX_LOCK_MODE, LCK_NONBLOCK, - lockid); - if (status == SA_LCK_LOCK_NOT_QUEUED) - { - _unlock_resource(lock1, *lockid); - status = -1; - errno = EAGAIN; - } - break; - - case LCK_PREAD: - case LCK_READ: - status = _lock_resource(lock1, SA_LCK_PR_LOCK_MODE, flags, lockid); - if (status) - goto out; - _unlock_resource(lock2, *lockid); - break; - - case LCK_WRITE: - status = _lock_resource(lock2, SA_LCK_EX_LOCK_MODE, flags, lockid); - if (status) - goto out; - _unlock_resource(lock1, *lockid); - break; - - default: - status = -1; - errno = EINVAL; - break; + DEBUGLOG("dlm_ls_unlock_wait returns lksb.sb_status: %x\n", lksb.sb_status); + return -1; } -out: - *lockid = mode; - return status; -} - -static int _sync_unlock(const char *resource, int lockid) -{ - int status = 0; - char lock1[strlen(resource)+3]; - char lock2[strlen(resource)+3]; - - snprintf(lock1, sizeof(lock1), "%s-1", resource); - snprintf(lock2, sizeof(lock2), "%s-2", resource); - - _unlock_resource(lock1, lockid); - _unlock_resource(lock2, lockid); + return 0; - return status; } /* We are always quorate ! */
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor