From mboxrd@z Thu Jan 1 00:00:00 1970 From: lhh@sourceware.org Date: 16 Jun 2006 19:54:58 -0000 Subject: [Cluster-devel] cluster/magma-plugins dumb/dumb.c gulm/gulm-lo ... Message-ID: <20060616195458.25753.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Branch: RHEL4 Changes by: lhh at sourceware.org 2006-06-16 19:54:57 Modified files: magma-plugins/dumb: dumb.c magma-plugins/gulm: gulm-lock.c gulm.c magma-plugins/sm: sm.c Log message: Allow support for NULL locks in sm module. Set errno accordingly on gulm/dumb modules (#193128) Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/magma-plugins/dumb/dumb.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.2&r2=1.2.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/magma-plugins/gulm/gulm-lock.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.5.2.3&r2=1.5.2.4 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/magma-plugins/gulm/gulm.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.6.2.6&r2=1.6.2.7 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/magma-plugins/sm/sm.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.9.2.8&r2=1.9.2.9 --- cluster/magma-plugins/dumb/Attic/dumb.c 2004/06/29 20:25:49 1.2 +++ cluster/magma-plugins/dumb/Attic/dumb.c 2006/06/16 19:54:56 1.2.2.1 @@ -35,7 +35,7 @@ #include #include -#define MODULE_DESCRIPTION "Dumb Plugin v1.1" +#define MODULE_DESCRIPTION "Dumb Plugin v1.1.1" #define MODULE_AUTHOR "Lon Hohberger" #define DUMB_LOCK_PATH "/tmp/magma-dumb" @@ -158,6 +158,12 @@ //printf("DUMB: %s called\n", __FUNCTION__); + if ((flags & CLK_EX) == 0) { + /* NULL lock not supported */ + errno = EINVAL; + return -1; + } + fdp = malloc(sizeof(int)); if (!fdp) return -1; --- cluster/magma-plugins/gulm/Attic/gulm-lock.c 2006/01/27 20:55:06 1.5.2.3 +++ cluster/magma-plugins/gulm/Attic/gulm-lock.c 2006/06/16 19:54:57 1.5.2.4 @@ -269,13 +269,14 @@ *lockpp = NULL; - if (flags & CLK_EX) { + if ((flags & CLK_EX) == CLK_EX) { state = lg_lock_state_Exclusive; } else if (flags & CLK_READ) { state = lg_lock_state_Shared; } else if (flags & CLK_WRITE) { state = lg_lock_state_Exclusive; } else { + /* NULL Locks not supported on GULM */ errno = EINVAL; return -1; } --- cluster/magma-plugins/gulm/Attic/gulm.c 2006/01/24 19:30:44 1.6.2.6 +++ cluster/magma-plugins/gulm/Attic/gulm.c 2006/06/16 19:54:57 1.6.2.7 @@ -34,7 +34,7 @@ #include #include -#define MODULE_DESCRIPTION "GuLM Plugin v1.0.4" +#define MODULE_DESCRIPTION "GuLM Plugin v1.0.5" #define MODULE_AUTHOR "Lon Hohberger" --- cluster/magma-plugins/sm/Attic/sm.c 2006/05/15 16:59:11 1.9.2.8 +++ cluster/magma-plugins/sm/Attic/sm.c 2006/06/16 19:54:57 1.9.2.9 @@ -35,7 +35,7 @@ #include #include -#define MODULE_DESCRIPTION "CMAN/SM Plugin v1.1.6" +#define MODULE_DESCRIPTION "CMAN/SM Plugin v1.1.7.1" #define MODULE_AUTHOR "Lon Hohberger" #define DLM_LS_NAME "Magma" @@ -47,6 +47,7 @@ /* Internal */ static inline int _dlm_release_lockspace(sm_priv_t *p); +static inline int _dlm_unlock(sm_priv_t *p, struct dlm_lksb *lksb); /* @@ -560,24 +561,13 @@ { int ret; - /* - * per pjc: create/open lockspace when first lock is taken - */ - ret = dlm_ls_lock(p->ls, mode, lksb, options, resource, - strlen(resource), 0, ast_function, lksb, - NULL, NULL); - - if (ret < 0) { -#if 0 - if (errno == ENOENT) { - /* This should not happen if we have a lock - ref open in the LS ! */A - assert(0); - } -#endif + /* Ok, we have the NL lock. Now convert it. */ + ret = dlm_ls_lock(p->ls, mode, lksb, options, + resource, strlen(resource), 0, ast_function, + lksb, NULL, NULL); + if (ret < 0) return -1; - } if ((ret = (wait_for_dlm_event(p->ls) < 0))) { fprintf(stderr, "wait_for_dlm_event: %d / %d\n", @@ -585,6 +575,7 @@ return -1; } + /* Got the lock ! */ return 0; } @@ -760,42 +751,64 @@ p = (sm_priv_t *)self->cp_private.p_data; assert(p); - *lockpp = NULL; - if (flags & CLK_EX) { + + if ((flags & CLK_EX) == CLK_EX) { mode = LKM_EXMODE; } else if (flags & CLK_READ) { mode = LKM_PRMODE; } else if (flags & CLK_WRITE) { mode = LKM_PWMODE; - } else { - errno = EINVAL; - return -1; + } else if ((flags & CLK_EX) == 0){ + mode = LKM_NLMODE; } if (flags & CLK_NOWAIT) options = LKF_NOQUEUE; + if (flags & CLK_CONVERT) + flags &= ~CLK_HOLDER; /* CLK_HOLDER mutually exclusive with + CLK_CONVERT */ /* Allocate our lock structure. */ sz = (sizeof(*lksb) > sizeof(uint64_t) ? sizeof(*lksb) : sizeof(uint64_t)); - lksb = malloc(sz); - assert(lksb); - memset(lksb, 0, sz); - - while(!p->ls) { + while(!p->ls) _dlm_acquire_lockspace(p, DLM_LS_NAME); - } assert(p->ls); + /* If we've got a non-zero pointer and we're being called with + the CLK_CONVERT flag, then assume it's a previous lksb with + a held lock. */ + if ((flags & CLK_CONVERT) && *lockpp) { + lksb = (struct lksb *)*lockpp; + options |= LKF_CONVERT; + } else { + lksb = malloc(sz); + assert(lksb); + memset(lksb, 0, sz); + } + + /* Take the real lock, or at least, try to. */ ret = _dlm_lock(p, mode, lksb, options, resource); - switch(lksb->sb_status) { - case 0: - *lockpp = (void *)lksb; - return 0; + /* Got the lock? */ + if (ret == 0) { + if (lksb->sb_status == 0) { + *lockpp = (void *)lksb; + return 0; + } + + /* Flip errno so we only have one switch statement */ + errno = lksb->sb_status; + } + + switch(errno) { case EAGAIN: - if ((flags & CLK_HOLDER) && + if (flags & CLK_CONVERT) { + *lockpp = (void *)lksb; + /* Nothing special here */ + /* Lock is busy */ + } else if ((flags & CLK_HOLDER) && (_get_holder(resource, p, mode, &holder) == 0)) { memset(lksb, 0, sz); *((uint64_t *)lksb) = holder; @@ -806,7 +819,7 @@ errno = EAGAIN; return -1; default: - fprintf(stderr, "_dlm_lock: %d / %d\n", ret, lksb->sb_status); + fprintf(stderr, "_dlm_lock: %d / %d\n", ret, errno); ret = lksb->sb_status; free(lksb); errno = ret;