/* Tell us whether we can grant a new lock request. *locking: *callerneeds:res->spinlock *taken:none *heldonexit:none *returns:1ifthelockcanbegranted,0otherwise.
*/ staticint dlm_can_grant_new_lock(struct dlm_lock_resource *res, struct dlm_lock *lock)
{ struct dlm_lock *tmplock;
list_for_each_entry(tmplock, &res->granted, list) { if (!dlm_lock_compatible(tmplock->ml.type, lock->ml.type)) return0;
}
list_for_each_entry(tmplock, &res->converting, list) { if (!dlm_lock_compatible(tmplock->ml.type, lock->ml.type)) return0; if (!dlm_lock_compatible(tmplock->ml.convert_type,
lock->ml.type)) return0;
}
return1;
}
/* performs lock creation at the lockres master site *locking: *callerneeds:none *taken:takesanddropsres->spinlock *heldonexit:none *returns:DLM_NORMAL,DLM_NOTQUEUED
*/ staticenum dlm_status dlmlock_master(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, struct dlm_lock *lock, int flags)
{ int call_ast = 0, kick_thread = 0; enum dlm_status status = DLM_NORMAL;
mlog(0, "type=%d\n", lock->ml.type);
spin_lock(&res->spinlock); /* if called from dlm_create_lock_handler, need to
* ensure it will not sleep in dlm_wait_on_lockres */
status = __dlm_lockres_state_to_status(res); if (status != DLM_NORMAL &&
lock->ml.node != dlm->node_num) { /* erf. state changed after lock was dropped. */
spin_unlock(&res->spinlock);
dlm_error(status); return status;
}
__dlm_wait_on_lockres(res);
__dlm_lockres_reserve_ast(res);
if (dlm_can_grant_new_lock(res, lock)) {
mlog(0, "I can grant this lock right away\n"); /* got it right away */
lock->lksb->status = DLM_NORMAL;
status = DLM_NORMAL;
dlm_lock_get(lock);
list_add_tail(&lock->list, &res->granted);
/* for the recovery lock, we can't allow the ast *tobequeuedsincethedlmthreadisalready *frozen.buttherecoverylockisalwayslocked *withLKM_NOQUEUEsowedonotneedtheastin
* this special case */ if (!dlm_is_recovery_lock(res->lockname.name,
res->lockname.len)) {
kick_thread = 1;
call_ast = 1;
} else {
mlog(0, "%s: returning DLM_NORMAL to " "node %u for reco lock\n", dlm->name,
lock->ml.node);
}
} else { /* for NOQUEUE request, unless we get the
* lock right away, return DLM_NOTQUEUED */ if (flags & LKM_NOQUEUE) {
status = DLM_NOTQUEUED; if (dlm_is_recovery_lock(res->lockname.name,
res->lockname.len)) {
mlog(0, "%s: returning NOTQUEUED to " "node %u for reco lock\n", dlm->name,
lock->ml.node);
}
} else {
status = DLM_NORMAL;
dlm_lock_get(lock);
list_add_tail(&lock->list, &res->blocked);
kick_thread = 1;
}
}
spin_unlock(&res->spinlock);
wake_up(&res->wq);
/* either queue the ast or release it */ if (call_ast)
dlm_queue_ast(dlm, lock); else
dlm_lockres_release_ast(dlm, res);
dlm_lockres_calc_usage(dlm, res); if (kick_thread)
dlm_kick_thread(dlm, res);
return status;
}
void dlm_revert_pending_lock(struct dlm_lock_resource *res, struct dlm_lock *lock)
{ /* remove from local queue if it failed */
list_del_init(&lock->list);
lock->lksb->flags &= ~DLM_LKSB_GET_LVB;
}
/* *locking: *callerneeds:none *taken:takesanddropsres->spinlock *heldonexit:none *returns:DLM_DENIED,DLM_RECOVERING,ornetstatus
*/ staticenum dlm_status dlmlock_remote(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, struct dlm_lock *lock, int flags)
{ enum dlm_status status = DLM_DENIED; int lockres_changed = 1;
/* add lock to local (secondary) queue */
dlm_lock_get(lock);
list_add_tail(&lock->list, &res->blocked);
lock->lock_pending = 1;
spin_unlock(&res->spinlock);
/* spec seems to say that you will get DLM_NORMAL when the lock
* has been queued, meaning we need to wait for a reply here. */
status = dlm_send_remote_lock_request(dlm, res, lock, flags);
spin_lock(&res->spinlock);
res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
lock->lock_pending = 0; if (status != DLM_NORMAL) { if (status == DLM_RECOVERING &&
dlm_is_recovery_lock(res->lockname.name,
res->lockname.len)) { /* recovery lock was mastered by dead node. *weneedtohavecalc_usageshootdownthis
* lockres and completely remaster it. */
mlog(0, "%s: recovery lock was owned by " "dead node %u, remaster it now.\n",
dlm->name, res->owner);
} elseif (status != DLM_NOTQUEUED) { /* *DONOTcallcalc_usage,asthiswouldunhash *theremotelockresbeforeweevergettouse *it.treatasifwenevermadeanychangeto *thelockres.
*/
lockres_changed = 0;
dlm_error(status);
}
dlm_revert_pending_lock(res, lock);
dlm_lock_put(lock);
} elseif (dlm_is_recovery_lock(res->lockname.name,
res->lockname.len)) { /* special case for the $RECOVERY lock. *therewillneverbeanASTdeliveredtoput *thislockonthepropersecondaryqueue
* (granted), so do it manually. */
mlog(0, "%s: $RECOVERY lock for this node (%u) is " "mastered by %u; got lock, manually granting (no ast)\n",
dlm->name, dlm->node_num, res->owner);
list_move_tail(&lock->list, &res->granted);
}
spin_unlock(&res->spinlock);
if (lockres_changed)
dlm_lockres_calc_usage(dlm, res);
wake_up(&res->wq); return status;
}
/* for remote lock creation. *locking: *callerneeds:none,butneedres->state&DLM_LOCK_RES_IN_PROGRESS *taken:none *heldonexit:none *returns:DLM_NOLOCKMGR,ornetstatus
*/ staticenum dlm_status dlm_send_remote_lock_request(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, struct dlm_lock *lock, int flags)
{ struct dlm_create_lock create; int tmpret, status = 0; enum dlm_status ret;
tmpret = o2net_send_message(DLM_CREATE_LOCK_MSG, dlm->key, &create, sizeof(create), res->owner, &status); if (tmpret >= 0) {
ret = status; if (ret == DLM_REJECTED) {
mlog(ML_ERROR, "%s: res %.*s, Stale lockres no longer " "owned by node %u. That node is coming back up " "currently.\n", dlm->name, create.namelen,
create.name, res->owner);
dlm_print_one_lock_resource(res);
BUG();
}
} else {
mlog(ML_ERROR, "%s: res %.*s, Error %d send CREATE LOCK to " "node %u\n", dlm->name, create.namelen, create.name,
tmpret, res->owner); if (dlm_is_host_down(tmpret))
ret = DLM_RECOVERING; else
ret = dlm_err_to_dlm_status(tmpret);
}
/* associate a lock with it's lockres, getting a ref on the lockres */ void dlm_lock_attach_lockres(struct dlm_lock *lock, struct dlm_lock_resource *res)
{
dlm_lockres_get(res);
lock->lockres = res;
}
/* drop ref on lockres, if there is still one associated with lock */ staticvoid dlm_lock_detach_lockres(struct dlm_lock *lock)
{ struct dlm_lock_resource *res;
res = lock->lockres; if (res) {
lock->lockres = NULL;
mlog(0, "removing lock's lockres reference\n");
dlm_lockres_put(res);
}
}
name = create->name;
namelen = create->namelen;
status = DLM_REJECTED; if (!dlm_domain_fully_joined(dlm)) {
mlog(ML_ERROR, "Domain %s not fully joined, but node %u is " "sending a create_lock message for lock %.*s!\n",
dlm->name, create->node_idx, namelen, name);
dlm_error(status); goto leave;
}
status = DLM_IVBUFLEN; if (namelen > DLM_LOCKID_NAME_MAX) {
dlm_error(status); goto leave;
}
status = DLM_SYSERR;
newlock = dlm_new_lock(create->requested_type,
create->node_idx,
be64_to_cpu(create->cookie), NULL); if (!newlock) {
dlm_error(status); goto leave;
}
/* yes this function is a mess. *TODO:cleanthisup.lotsofcommoncodeinthe
* lock and convert paths, especially in the retry blocks */ if (!lksb) {
dlm_error(DLM_BADARGS); return DLM_BADARGS;
}
status = DLM_BADPARAM; if (mode != LKM_EXMODE && mode != LKM_PRMODE && mode != LKM_NLMODE) {
dlm_error(status); goto error;
}
if (flags & ~LKM_VALID_FLAGS) {
dlm_error(status); goto error;
}
if (recovery &&
(!dlm_is_recovery_lock(name, namelen) || convert) ) {
dlm_error(status); goto error;
} if (convert && (flags & LKM_LOCAL)) {
mlog(ML_ERROR, "strange LOCAL convert request!\n"); goto error;
}
if (convert) { /* CONVERT request */
/* if converting, must pass in a valid dlm_lock */
lock = lksb->lockid; if (!lock) {
mlog(ML_ERROR, "NULL lock pointer in convert " "request\n"); goto error;
}
res = lock->lockres; if (!res) {
mlog(ML_ERROR, "NULL lockres pointer in convert " "request\n"); goto error;
}
dlm_lockres_get(res);
if (res->owner == dlm->node_num)
status = dlmconvert_master(dlm, res, lock, flags, mode); else
status = dlmconvert_remote(dlm, res, lock, flags, mode); if (status == DLM_RECOVERING || status == DLM_MIGRATING ||
status == DLM_FORWARD) { /* for now, see how this works without sleeping *andjustretryrightaway.Isuspectthereco *ormigrationwillcompletefastenoughthat
* no waiting will be necessary */
mlog(0, "retrying convert with migration/recovery/" "in-progress\n");
msleep(100); goto retry_convert;
}
} else {
u64 tmpcookie;
/* LOCK request */
status = DLM_BADARGS; if (!name) {
dlm_error(status); goto error;
}
status = DLM_IVBUFLEN; if (namelen > DLM_LOCKID_NAME_MAX || namelen < 1) {
dlm_error(status); goto error;
}
/* find or create the lock resource */
res = dlm_get_lock_resource(dlm, name, namelen, flags); if (!res) {
status = DLM_IVLOCKID;
dlm_error(status); goto error;
}
retry_lock: if (flags & LKM_VALBLK) {
mlog(0, "LKM_VALBLK passed by caller\n");
/* LVB requests for non PR, PW or EX locks are
* ignored. */ if (mode < LKM_PRMODE)
flags &= ~LKM_VALBLK; else {
flags |= LKM_GET_LVB;
lock->lksb->flags |= DLM_LKSB_GET_LVB;
}
}
if (res->owner == dlm->node_num)
status = dlmlock_master(dlm, res, lock, flags); else
status = dlmlock_remote(dlm, res, lock, flags);
if (status == DLM_RECOVERING || status == DLM_MIGRATING ||
status == DLM_FORWARD) {
msleep(100); if (recovery) { if (status != DLM_RECOVERING) goto retry_lock; /* wait to see the node go down, then *dropdownandallowthelockresto
* get cleaned up. need to remaster. */
dlm_wait_for_node_death(dlm, res->owner,
DLM_NODE_DEATH_WAIT_MAX);
} else {
dlm_wait_for_recovery(dlm); goto retry_lock;
}
}
/* Inflight taken in dlm_get_lock_resource() is dropped here */
spin_lock(&res->spinlock);
dlm_lockres_drop_inflight_ref(dlm, res);
spin_unlock(&res->spinlock);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.