^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * dlmunlock.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * underlying calls for unlocking locks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2004 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "../cluster/heartbeat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "../cluster/nodemanager.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "../cluster/tcp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "dlmapi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "dlmcommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define MLOG_MASK_PREFIX ML_DLM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "../cluster/masklog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define DLM_UNLOCK_FREE_LOCK 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define DLM_UNLOCK_CALL_AST 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DLM_UNLOCK_REMOVE_LOCK 0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DLM_UNLOCK_REGRANT_LOCK 0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DLM_UNLOCK_CLEAR_CONVERT_TYPE 0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static enum dlm_status dlm_get_cancel_actions(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int *actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static enum dlm_status dlm_get_unlock_actions(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int *actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static enum dlm_status dlm_send_remote_unlock_request(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u8 owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * according to the spec:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * http://opendlm.sourceforge.net/cvsmirror/opendlm/docs/dlmbook_final.pdf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * flags & LKM_CANCEL != 0: must be converting or blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * flags & LKM_CANCEL == 0: must be granted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * So to unlock a converting lock, you must first cancel the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * convert (passing LKM_CANCEL in flags), then call the unlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * again (with no LKM_CANCEL in flags).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * caller needs: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * taken: res->spinlock and lock->spinlock taken and dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * held on exit: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * returns: DLM_NORMAL, DLM_NOLOCKMGR, status from network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * all callers should have taken an extra ref on lock coming in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static enum dlm_status dlmunlock_common(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int flags, int *call_ast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int master_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) enum dlm_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int actions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) u8 owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int recovery_wait = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) mlog(0, "master_node = %d, valblk = %d\n", master_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) flags & LKM_VALBLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (master_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) BUG_ON(res->owner != dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) BUG_ON(res->owner == dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) spin_lock(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* We want to be sure that we're not freeing a lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * that still has AST's pending... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) in_use = !list_empty(&lock->ast_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) spin_unlock(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (in_use && !(flags & LKM_CANCEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) mlog(ML_ERROR, "lockres %.*s: Someone is calling dlmunlock "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) "while waiting for an ast!", res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return DLM_BADPARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (res->state & DLM_LOCK_RES_IN_PROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (master_node && !(flags & LKM_CANCEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) mlog(ML_ERROR, "lockres in progress!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return DLM_FORWARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* ok for this to sleep if not in a network handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) __dlm_wait_on_lockres(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) res->state |= DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (res->state & DLM_LOCK_RES_RECOVERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) status = DLM_RECOVERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (res->state & DLM_LOCK_RES_MIGRATING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) status = DLM_MIGRATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* see above for what the spec says about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * LKM_CANCEL and the lock queue state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (flags & LKM_CANCEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) status = dlm_get_cancel_actions(dlm, res, lock, lksb, &actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) status = dlm_get_unlock_actions(dlm, res, lock, lksb, &actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (status != DLM_NORMAL && (status != DLM_CANCELGRANT || !master_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* By now this has been masked out of cancel requests. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (flags & LKM_VALBLK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* make the final update to the lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (master_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) memcpy(res->lvb, lksb->lvb, DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) flags |= LKM_PUT_LVB; /* let the send function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * handle it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!master_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) owner = res->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* drop locks and send message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (flags & LKM_CANCEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) lock->cancel_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) lock->unlock_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) status = dlm_send_remote_unlock_request(dlm, res, lock, lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) flags, owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* if the master told us the lock was already granted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * let the ast handle all of these actions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (status == DLM_CANCELGRANT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) actions &= ~(DLM_UNLOCK_REMOVE_LOCK|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) DLM_UNLOCK_REGRANT_LOCK|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) DLM_UNLOCK_CLEAR_CONVERT_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) } else if (status == DLM_RECOVERING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) status == DLM_MIGRATING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) status == DLM_FORWARD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) status == DLM_NOLOCKMGR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* must clear the actions because this unlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * is about to be retried. cannot free or do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * any list manipulation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) mlog(0, "%s:%.*s: clearing actions, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) dlm->name, res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) status==DLM_RECOVERING?"recovering":
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) (status==DLM_MIGRATING?"migrating":
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) (status == DLM_FORWARD ? "forward" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) "nolockmanager")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) actions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (flags & LKM_CANCEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) lock->cancel_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!lock->unlock_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) recovery_wait = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) lock->unlock_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* get an extra ref on lock. if we are just switching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * lists here, we dont want the lock to go away. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (actions & DLM_UNLOCK_REMOVE_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) list_del_init(&lock->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (actions & DLM_UNLOCK_REGRANT_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) list_add_tail(&lock->list, &res->granted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (actions & DLM_UNLOCK_CLEAR_CONVERT_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mlog(0, "clearing convert_type at %smaster node\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) master_node ? "" : "non-");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) lock->ml.convert_type = LKM_IVMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* remove the extra ref on lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (!dlm_lock_on_list(&res->converting, lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) BUG_ON(lock->ml.convert_type != LKM_IVMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) BUG_ON(lock->ml.convert_type == LKM_IVMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) wake_up(&res->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (recovery_wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /* Unlock request will directly succeed after owner dies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * and the lock is already removed from grant list. We have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * wait for RECOVERING done or we miss the chance to purge it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * since the removement is much faster than RECOVERING proc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) __dlm_wait_on_lockres_flags(res, DLM_LOCK_RES_RECOVERING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* let the caller's final dlm_lock_put handle the actual kfree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (actions & DLM_UNLOCK_FREE_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* this should always be coupled with list removal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) BUG_ON(!(actions & DLM_UNLOCK_REMOVE_LOCK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) mlog(0, "lock %u:%llu should be gone now! refs=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) kref_read(&lock->lock_refs)-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (actions & DLM_UNLOCK_CALL_AST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) *call_ast = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* if cancel or unlock succeeded, lvb work is done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (status == DLM_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) lksb->flags &= ~(DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) void dlm_commit_pending_unlock(struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* leave DLM_LKSB_PUT_LVB on the lksb so any final
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * update of the lvb will be sent to the new master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) list_del_init(&lock->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) void dlm_commit_pending_cancel(struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) list_move_tail(&lock->list, &res->granted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) lock->ml.convert_type = LKM_IVMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static inline enum dlm_status dlmunlock_master(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int *call_ast)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return dlmunlock_common(dlm, res, lock, lksb, flags, call_ast, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static inline enum dlm_status dlmunlock_remote(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int flags, int *call_ast)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return dlmunlock_common(dlm, res, lock, lksb, flags, call_ast, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * caller needs: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * taken: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * held on exit: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * returns: DLM_NORMAL, DLM_NOLOCKMGR, status from network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static enum dlm_status dlm_send_remote_unlock_request(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) u8 owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct dlm_unlock_lock unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int tmpret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) enum dlm_status ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct kvec vec[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) size_t veclen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) mlog(0, "%.*s\n", res->lockname.len, res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (owner == dlm->node_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* ended up trying to contact ourself. this means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * that the lockres had been remote but became local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * via a migration. just retry it, now as local */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) mlog(0, "%s:%.*s: this node became the master due to a "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) "migration, re-evaluate now\n", dlm->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) res->lockname.len, res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return DLM_FORWARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) memset(&unlock, 0, sizeof(unlock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) unlock.node_idx = dlm->node_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) unlock.flags = cpu_to_be32(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) unlock.cookie = lock->ml.cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) unlock.namelen = res->lockname.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) memcpy(unlock.name, res->lockname.name, unlock.namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) vec[0].iov_len = sizeof(struct dlm_unlock_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) vec[0].iov_base = &unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (flags & LKM_PUT_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* extra data to send if we are updating lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) vec[1].iov_len = DLM_LVB_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) vec[1].iov_base = lock->lksb->lvb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) veclen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) tmpret = o2net_send_message_vec(DLM_UNLOCK_LOCK_MSG, dlm->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) vec, veclen, owner, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (tmpret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) // successfully sent and received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (status == DLM_FORWARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) mlog(0, "master was in-progress. retry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ret = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) mlog(ML_ERROR, "Error %d when sending message %u (key 0x%x) to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) "node %u\n", tmpret, DLM_UNLOCK_LOCK_MSG, dlm->key, owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (dlm_is_host_down(tmpret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* NOTE: this seems strange, but it is what we want.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * when the master goes down during a cancel or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * unlock, the recovery code completes the operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * as if the master had not died, then passes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * updated state to the recovery master. this thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * just needs to finish out the operation and call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * the unlockast. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (dlm_is_node_dead(dlm, owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ret = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ret = DLM_NOLOCKMGR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* something bad. this will BUG in ocfs2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ret = dlm_err_to_dlm_status(tmpret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * caller needs: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * taken: takes and drops res->spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * held on exit: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * returns: DLM_NORMAL, DLM_BADARGS, DLM_IVLOCKID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * return value from dlmunlock_master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) void **ret_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct dlm_ctxt *dlm = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct dlm_unlock_lock *unlock = (struct dlm_unlock_lock *)msg->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct dlm_lock_resource *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct dlm_lock *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) enum dlm_status status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int found = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct dlm_lockstatus *lksb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int ignore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct list_head *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) flags = be32_to_cpu(unlock->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (flags & LKM_GET_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) mlog(ML_ERROR, "bad args! GET_LVB specified on unlock!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return DLM_BADARGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if ((flags & (LKM_PUT_LVB|LKM_CANCEL)) == (LKM_PUT_LVB|LKM_CANCEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) mlog(ML_ERROR, "bad args! cannot modify lvb on a CANCEL "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) "request!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return DLM_BADARGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (unlock->namelen > DLM_LOCKID_NAME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) mlog(ML_ERROR, "Invalid name length in unlock handler!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return DLM_IVBUFLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!dlm_grab(dlm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return DLM_FORWARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) mlog_bug_on_msg(!dlm_domain_fully_joined(dlm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) "Domain %s not fully joined!\n", dlm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mlog(0, "lvb: %s\n", flags & LKM_PUT_LVB ? "put lvb" : "none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) res = dlm_lookup_lockres(dlm, unlock->name, unlock->namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* We assume here that a no lock resource simply means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * it was migrated away and destroyed before the other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * node could detect it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) mlog(0, "returning DLM_FORWARD -- res no longer exists\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) status = DLM_FORWARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) queue=&res->granted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (res->state & DLM_LOCK_RES_RECOVERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) mlog(0, "returning DLM_RECOVERING\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) status = DLM_RECOVERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (res->state & DLM_LOCK_RES_MIGRATING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) mlog(0, "returning DLM_MIGRATING\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) status = DLM_MIGRATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (res->owner != dlm->node_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) mlog(0, "returning DLM_FORWARD -- not master\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) status = DLM_FORWARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) for (i=0; i<3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) list_for_each_entry(lock, queue, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (lock->ml.cookie == unlock->cookie &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) lock->ml.node == unlock->node_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* scan granted -> converting -> blocked queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) queue++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) status = DLM_IVLOCKID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /* lock was found on queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) lksb = lock->lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (flags & (LKM_VALBLK|LKM_PUT_LVB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) lock->ml.type != LKM_EXMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) flags &= ~(LKM_VALBLK|LKM_PUT_LVB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* unlockast only called on originating node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (flags & LKM_PUT_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) lksb->flags |= DLM_LKSB_PUT_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) memcpy(&lksb->lvb[0], &unlock->lvb[0], DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* if this is in-progress, propagate the DLM_FORWARD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * all the way back out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) status = dlmunlock_master(dlm, res, lock, lksb, flags, &ignore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (status == DLM_FORWARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) mlog(0, "lockres is in progress\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (flags & LKM_PUT_LVB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) lksb->flags &= ~DLM_LKSB_PUT_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) dlm_lockres_calc_usage(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) dlm_kick_thread(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) not_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) mlog(ML_ERROR, "failed to find lock to unlock! "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) "cookie=%u:%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) dlm_get_lock_cookie_node(be64_to_cpu(unlock->cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) dlm_get_lock_cookie_seq(be64_to_cpu(unlock->cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) dlm_lockres_put(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) dlm_put(dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static enum dlm_status dlm_get_cancel_actions(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) int *actions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) enum dlm_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (dlm_lock_on_list(&res->blocked, lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /* cancel this outright */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) *actions = (DLM_UNLOCK_CALL_AST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) DLM_UNLOCK_REMOVE_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) } else if (dlm_lock_on_list(&res->converting, lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* cancel the request, put back on granted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) *actions = (DLM_UNLOCK_CALL_AST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) DLM_UNLOCK_REMOVE_LOCK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) DLM_UNLOCK_REGRANT_LOCK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) DLM_UNLOCK_CLEAR_CONVERT_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) } else if (dlm_lock_on_list(&res->granted, lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /* too late, already granted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) status = DLM_CANCELGRANT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) *actions = DLM_UNLOCK_CALL_AST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) mlog(ML_ERROR, "lock to cancel is not on any list!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) status = DLM_IVLOCKID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) *actions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static enum dlm_status dlm_get_unlock_actions(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct dlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) int *actions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) enum dlm_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /* unlock request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (!dlm_lock_on_list(&res->granted, lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) status = DLM_DENIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) *actions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* unlock granted lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) *actions = (DLM_UNLOCK_FREE_LOCK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) DLM_UNLOCK_CALL_AST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) DLM_UNLOCK_REMOVE_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* there seems to be no point in doing this async
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * since (even for the remote case) there is really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * no work to queue up... so just do it and fire the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * unlockast by hand when done... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) enum dlm_status dlmunlock(struct dlm_ctxt *dlm, struct dlm_lockstatus *lksb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) int flags, dlm_astunlockfunc_t *unlockast, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) enum dlm_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct dlm_lock_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct dlm_lock *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) int call_ast, is_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (!lksb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) dlm_error(DLM_BADARGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return DLM_BADARGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (flags & ~(LKM_CANCEL | LKM_VALBLK | LKM_INVVALBLK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) dlm_error(DLM_BADPARAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return DLM_BADPARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if ((flags & (LKM_VALBLK | LKM_CANCEL)) == (LKM_VALBLK | LKM_CANCEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) mlog(0, "VALBLK given with CANCEL: ignoring VALBLK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) flags &= ~LKM_VALBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!lksb->lockid || !lksb->lockid->lockres) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) dlm_error(DLM_BADPARAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) return DLM_BADPARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) lock = lksb->lockid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) BUG_ON(!lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) res = lock->lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) BUG_ON(!res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) dlm_lockres_get(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) call_ast = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /* need to retry up here because owner may have changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) mlog(0, "lock=%p res=%p\n", lock, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) is_master = (res->owner == dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (flags & LKM_VALBLK && lock->ml.type != LKM_EXMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) flags &= ~LKM_VALBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (is_master) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) status = dlmunlock_master(dlm, res, lock, lksb, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) &call_ast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) mlog(0, "done calling dlmunlock_master: returned %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) "call_ast is %d\n", status, call_ast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) status = dlmunlock_remote(dlm, res, lock, lksb, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) &call_ast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) mlog(0, "done calling dlmunlock_remote: returned %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) "call_ast is %d\n", status, call_ast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (status == DLM_RECOVERING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) status == DLM_MIGRATING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) status == DLM_FORWARD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) status == DLM_NOLOCKMGR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) /* We want to go away for a tiny bit to allow recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * / migration to complete on this resource. I don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * know of any wait queue we could sleep on as this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * may be happening on another node. Perhaps the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * proper solution is to queue up requests on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * other end? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) /* do we want to yield(); ?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) mlog(0, "retrying unlock due to pending recovery/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) "migration/in-progress/reconnect\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (call_ast) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) mlog(0, "calling unlockast(%p, %d)\n", data, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (is_master) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* it is possible that there is one last bast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * pending. make sure it is flushed, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * call the unlockast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * not an issue if this is a mastered remotely,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * since this lock has been removed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * lockres queues and cannot be found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) dlm_kick_thread(dlm, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) wait_event(dlm->ast_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) dlm_lock_basts_flushed(dlm, lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) (*unlockast)(data, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (status == DLM_CANCELGRANT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (status == DLM_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) mlog(0, "kicking the thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) dlm_kick_thread(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) dlm_lockres_calc_usage(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) dlm_lockres_put(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) mlog(0, "returning status=%d!\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) EXPORT_SYMBOL_GPL(dlmunlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)