// SPDX-License-Identifier: GPL-2.0-or-later /* * userdlm.c * * Code which implements the kernel side of a minimal userspace * interface to our DLM. * * Many of the functions here are pared down versions of dlmglue.c * functions. * * Copyright (C) 2003, 2004 Oracle. All rights reserved.
*/
#define user_log_dlm_error(_func, _stat, _lockres) do { \
mlog(ML_ERROR, "Dlm error %d while calling %s on " \ "resource %.*s\n", _stat, _func, \
_lockres->l_namelen, _lockres->l_name); \
} while (0)
/* WARNING: This function lives in a world where the only three lock * levels are EX, PR, and NL. It *will* have to be adjusted when more
* lock types are added. */ staticinlineint user_highest_compat_lock_level(int level)
{ int new_level = DLM_LOCK_EX;
status = ocfs2_dlm_lock_status(&lockres->l_lksb); if (status) {
mlog(ML_ERROR, "lksb status value of %u on lockres %.*s\n",
status, lockres->l_namelen, lockres->l_name);
spin_unlock(&lockres->l_lock); return;
}
if (status)
mlog(ML_ERROR, "dlm returns status %d\n", status);
spin_lock(&lockres->l_lock); /* The teardown flag gets set early during the unlock process, * so test the cancel flag to make sure that this ast isn't
* for a concurrent cancel. */ if (lockres->l_flags & USER_LOCK_IN_TEARDOWN
&& !(lockres->l_flags & USER_LOCK_IN_CANCEL)) {
lockres->l_level = DLM_LOCK_IV;
} elseif (status == DLM_CANCELGRANT) { /* We tried to cancel a convert request, but it was * already granted. Don't clear the busy flag - the
* ast should've done this already. */
BUG_ON(!(lockres->l_flags & USER_LOCK_IN_CANCEL));
lockres->l_flags &= ~USER_LOCK_IN_CANCEL; goto out_noclear;
} else {
BUG_ON(!(lockres->l_flags & USER_LOCK_IN_CANCEL)); /* Cancel succeeded, we want to re-queue */
lockres->l_requested = DLM_LOCK_IV; /* cancel an * upconvert
* request. */
lockres->l_flags &= ~USER_LOCK_IN_CANCEL; /* we want the unblock thread to look at it again
* now. */ if (lockres->l_flags & USER_LOCK_BLOCKED)
__user_dlm_queue_lockres(lockres);
}
/* notice that we don't clear USER_LOCK_BLOCKED here. If it's
* set, we want user_ast clear it. */
lockres->l_flags &= ~USER_LOCK_QUEUED;
/* It's valid to get here and no longer be blocked - if we get * several basts in a row, we might be queued by the first * one, the unblock thread might run and clear the queued * flag, and finally we might get another bast which re-queues
* us before our ast for the downconvert is called. */ if (!(lockres->l_flags & USER_LOCK_BLOCKED)) {
mlog(ML_BASTS, "lockres %.*s USER_LOCK_BLOCKED\n",
lockres->l_namelen, lockres->l_name);
spin_unlock(&lockres->l_lock); goto drop_ref;
}
status = ocfs2_dlm_unlock(conn, &lockres->l_lksb,
DLM_LKF_CANCEL); if (status)
user_log_dlm_error("ocfs2_dlm_unlock", status, lockres); goto drop_ref;
}
/* If there are still incompat holders, we can exit safely * without worrying about re-queueing this lock as that will
* happen on the last call to user_cluster_unlock. */ if ((lockres->l_blocking == DLM_LOCK_EX)
&& (lockres->l_ex_holders || lockres->l_ro_holders)) {
spin_unlock(&lockres->l_lock);
mlog(ML_BASTS, "lockres %.*s, EX/PR Holders %u,%u\n",
lockres->l_namelen, lockres->l_name,
lockres->l_ex_holders, lockres->l_ro_holders); goto drop_ref;
}
if ((lockres->l_blocking == DLM_LOCK_PR)
&& lockres->l_ex_holders) {
spin_unlock(&lockres->l_lock);
mlog(ML_BASTS, "lockres %.*s, EX Holders %u\n",
lockres->l_namelen, lockres->l_name,
lockres->l_ex_holders); goto drop_ref;
}
/* need lock downconvert request now... */
status = ocfs2_dlm_lock(conn, new_level, &lockres->l_lksb,
DLM_LKF_CONVERT|DLM_LKF_VALBLK,
lockres->l_name,
lockres->l_namelen); if (status) {
user_log_dlm_error("ocfs2_dlm_lock", status, lockres);
user_recover_from_dlm_error(lockres);
}
drop_ref:
user_dlm_drop_inode_ref(lockres);
}
staticinlinevoid user_dlm_inc_holders(struct user_lock_res *lockres, int level)
{ switch(level) { case DLM_LOCK_EX:
lockres->l_ex_holders++; break; case DLM_LOCK_PR:
lockres->l_ro_holders++; break; default:
BUG();
}
}
/* predict what lock level we'll be dropping down to on behalf * of another node, and return true if the currently wanted
* level will be compatible with it. */ staticinlineint
user_may_continue_on_blocked_lock(struct user_lock_res *lockres, int wanted)
{
BUG_ON(!(lockres->l_flags & USER_LOCK_BLOCKED));
int user_dlm_cluster_lock(struct user_lock_res *lockres, int level, int lkm_flags)
{ int status, local_flags; struct ocfs2_cluster_connection *conn =
cluster_connection_from_user_lockres(lockres);
again: if (signal_pending(current)) {
status = -ERESTARTSYS; goto bail;
}
spin_lock(&lockres->l_lock); if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) {
spin_unlock(&lockres->l_lock);
status = -EAGAIN; goto bail;
}
/* We only compare against the currently granted level * here. If the lock is blocked waiting on a downconvert,
* we'll get caught below. */ if ((lockres->l_flags & USER_LOCK_BUSY) &&
(level > lockres->l_level)) { /* is someone sitting in dlm_lock? If so, wait on
* them. */
spin_unlock(&lockres->l_lock);
user_wait_on_busy_lock(lockres); goto again;
}
if ((lockres->l_flags & USER_LOCK_BLOCKED) &&
(!user_may_continue_on_blocked_lock(lockres, level))) { /* is the lock is currently blocked on behalf of
* another node */
spin_unlock(&lockres->l_lock);
user_wait_on_blocked_lock(lockres); goto again;
}
if (level > lockres->l_level) {
local_flags = lkm_flags | DLM_LKF_VALBLK; if (lockres->l_level != DLM_LOCK_IV)
local_flags |= DLM_LKF_CONVERT;
int user_dlm_destroy_lock(struct user_lock_res *lockres)
{ int status = -EBUSY; struct ocfs2_cluster_connection *conn =
cluster_connection_from_user_lockres(lockres);
status = 0; if (!(lockres->l_flags & USER_LOCK_ATTACHED)) { /* * lock is never requested, leave USER_LOCK_IN_TEARDOWN set * to avoid new lock request coming in.
*/
spin_unlock(&lockres->l_lock); goto bail;
}
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.