Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * dlmast.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * AST and BAST functionality for local and remote nodes
^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) 
^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) static void dlm_update_lvb(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			   struct dlm_lock *lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int dlm_should_cancel_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* Should be called as an ast gets queued to see if the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * lock level will obsolete a pending bast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * For example, if dlm_thread queued a bast for an EX lock that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * was blocking another EX, but before sending the bast the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * lock owner downconverted to NL, the bast is now obsolete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * Only the ast should be sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * This is needed because the lock and convert paths can queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * asts out-of-band (not waiting for dlm_thread) in order to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * allow for LKM_NOQUEUE to get immediate responses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int dlm_should_cancel_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	assert_spin_locked(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	assert_spin_locked(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (lock->ml.highest_blocked == LKM_IVMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	BUG_ON(lock->ml.highest_blocked == LKM_NLMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (lock->bast_pending &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	    list_empty(&lock->bast_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		/* old bast already sent, ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (lock->ml.type == LKM_EXMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		/* EX blocks anything left, any bast still valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	else if (lock->ml.type == LKM_NLMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		/* NL blocks nothing, no reason to send any bast, cancel it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	else if (lock->ml.highest_blocked != LKM_EXMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		/* PR only blocks EX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return 0;
^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) void __dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct dlm_lock_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	BUG_ON(!dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	BUG_ON(!lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	res = lock->lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	assert_spin_locked(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!list_empty(&lock->ast_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		mlog(ML_ERROR, "%s: res %.*s, lock %u:%llu, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		     "AST list not empty, pending %d, newlevel %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		     dlm->name, res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		     lock->ast_pending, lock->ml.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (lock->ast_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		mlog(0, "%s: res %.*s, lock %u:%llu, AST getting flushed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		     dlm->name, res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	/* putting lock on list, add a ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/* check to see if this ast obsoletes the bast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (dlm_should_cancel_bast(dlm, lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		mlog(0, "%s: res %.*s, lock %u:%llu, Cancelling BAST\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		     dlm->name, res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		lock->bast_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		list_del_init(&lock->bast_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		lock->ml.highest_blocked = LKM_IVMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		/* removing lock from list, remove a ref.  guaranteed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		 * this won't be the last ref because of the get above,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		 * so res->spinlock will not be taken here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		/* free up the reserved bast that we are cancelling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		 * guaranteed that this will not be the last reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		 * ast because *both* an ast and a bast were reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		 * to get to this point.  the res->spinlock will not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		 * taken here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		dlm_lockres_release_ast(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	list_add_tail(&lock->ast_list, &dlm->pending_asts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	lock->ast_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	BUG_ON(!dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	BUG_ON(!lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	spin_lock(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	__dlm_queue_ast(dlm, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	spin_unlock(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void __dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct dlm_lock_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	BUG_ON(!dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	BUG_ON(!lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	assert_spin_locked(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	res = lock->lockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	BUG_ON(!list_empty(&lock->bast_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (lock->bast_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		mlog(0, "%s: res %.*s, lock %u:%llu, BAST getting flushed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		     dlm->name, res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* putting lock on list, add a ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	list_add_tail(&lock->bast_list, &dlm->pending_basts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	lock->bast_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	BUG_ON(!dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	BUG_ON(!lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	spin_lock(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	__dlm_queue_bast(dlm, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	spin_unlock(&dlm->ast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void dlm_update_lvb(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			   struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct dlm_lockstatus *lksb = lock->lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	BUG_ON(!lksb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/* only updates if this node masters the lockres */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (res->owner == dlm->node_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		/* check the lksb flags for the direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		if (lksb->flags & DLM_LKSB_GET_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			mlog(0, "getting lvb from lockres for %s node\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				  lock->ml.node == dlm->node_num ? "master" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 				  "remote");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			memcpy(lksb->lvb, res->lvb, DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		/* Do nothing for lvb put requests - they should be done in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  		 * place when the lock is downconverted - otherwise we risk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  		 * racing gets and puts which could result in old lvb data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  		 * being propagated. We leave the put flag set and clear it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  		 * here. In the future we might want to clear it at the time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  		 * the put is actually done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/* reset any lvb flags on the lksb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	lksb->flags &= ~(DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void dlm_do_local_ast(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		      struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	dlm_astlockfunc_t *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	mlog(0, "%s: res %.*s, lock %u:%llu, Local AST\n", dlm->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	     res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	fn = lock->ast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	BUG_ON(lock->ml.node != dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	dlm_update_lvb(dlm, res, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	(*fn)(lock->astdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int dlm_do_remote_ast(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		      struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct dlm_lockstatus *lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int lksbflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	mlog(0, "%s: res %.*s, lock %u:%llu, Remote AST\n", dlm->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	     res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	lksb = lock->lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	BUG_ON(lock->ml.node == dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	lksbflags = lksb->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	dlm_update_lvb(dlm, res, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* lock request came from another node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * go do the ast over there */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	ret = dlm_send_proxy_ast(dlm, res, lock, lksbflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) void dlm_do_local_bast(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		       struct dlm_lock *lock, int blocked_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	dlm_bastlockfunc_t *fn = lock->bast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	BUG_ON(lock->ml.node != dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	mlog(0, "%s: res %.*s, lock %u:%llu, Local BAST, blocked %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	     dlm->name, res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	     blocked_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	(*fn)(lock->astdata, blocked_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int dlm_proxy_ast_handler(struct o2net_msg *msg, u32 len, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			  void **ret_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	unsigned int locklen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct dlm_ctxt *dlm = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct dlm_lock_resource *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct dlm_lock *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct dlm_proxy_ast *past = (struct dlm_proxy_ast *) msg->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct list_head *head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	__be64 cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	u8 node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (!dlm_grab(dlm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		dlm_error(DLM_REJECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return DLM_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	mlog_bug_on_msg(!dlm_domain_fully_joined(dlm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			"Domain %s not fully joined!\n", dlm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	name = past->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	locklen = past->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	cookie = past->cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	flags = be32_to_cpu(past->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	node = past->node_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (locklen > DLM_LOCKID_NAME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		ret = DLM_IVBUFLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		mlog(ML_ERROR, "Invalid name length (%d) in proxy ast "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		     "handler!\n", locklen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if ((flags & (LKM_PUT_LVB|LKM_GET_LVB)) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	     (LKM_PUT_LVB|LKM_GET_LVB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		mlog(ML_ERROR, "Both PUT and GET lvb specified, (0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		     flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		ret = DLM_BADARGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	mlog(0, "lvb: %s\n", flags & LKM_PUT_LVB ? "put lvb" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		  (flags & LKM_GET_LVB ? "get lvb" : "none"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	mlog(0, "type=%d, blocked_type=%d\n", past->type, past->blocked_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (past->type != DLM_AST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	    past->type != DLM_BAST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		mlog(ML_ERROR, "Unknown ast type! %d, cookie=%u:%llu"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		     "name=%.*s, node=%u\n", past->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		     dlm_get_lock_cookie_node(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		     dlm_get_lock_cookie_seq(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		     locklen, name, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		ret = DLM_IVLOCKID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	res = dlm_lookup_lockres(dlm, name, locklen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		mlog(0, "Got %sast for unknown lockres! cookie=%u:%llu, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		     "name=%.*s, node=%u\n", (past->type == DLM_AST ? "" : "b"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		     dlm_get_lock_cookie_node(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		     dlm_get_lock_cookie_seq(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		     locklen, name, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		ret = DLM_IVLOCKID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	/* cannot get a proxy ast message if this node owns it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	BUG_ON(res->owner == dlm->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	mlog(0, "%s: res %.*s\n", dlm->name, res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	     res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (res->state & DLM_LOCK_RES_RECOVERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		mlog(0, "Responding with DLM_RECOVERING!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		ret = DLM_RECOVERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		goto unlock_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (res->state & DLM_LOCK_RES_MIGRATING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		mlog(0, "Responding with DLM_MIGRATING!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		ret = DLM_MIGRATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		goto unlock_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	/* try convert queue for both ast/bast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	head = &res->converting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	list_for_each_entry(lock, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		if (lock->ml.cookie == cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			goto do_ast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	/* if not on convert, try blocked for ast, granted for bast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (past->type == DLM_AST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		head = &res->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		head = &res->granted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	list_for_each_entry(lock, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		/* if lock is found but unlock is pending ignore the bast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if (lock->ml.cookie == cookie) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			if (lock->unlock_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			goto do_ast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		}
^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) 	mlog(0, "Got %sast for unknown lock! cookie=%u:%llu, name=%.*s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	     "node=%u\n", past->type == DLM_AST ? "" : "b",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	     dlm_get_lock_cookie_node(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	     dlm_get_lock_cookie_seq(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	     locklen, name, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	ret = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) unlock_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) do_ast:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	ret = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (past->type == DLM_AST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		/* do not alter lock refcount.  switching lists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		list_move_tail(&lock->list, &res->granted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		mlog(0, "%s: res %.*s, lock %u:%llu, Granted type %d => %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		     dlm->name, res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		     dlm_get_lock_cookie_node(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		     dlm_get_lock_cookie_seq(be64_to_cpu(cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		     lock->ml.type, lock->ml.convert_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		if (lock->ml.convert_type != LKM_IVMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			lock->ml.type = lock->ml.convert_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			lock->ml.convert_type = LKM_IVMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			// should already be there....
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		lock->lksb->status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		/* if we requested the lvb, fetch it into our lksb now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		if (flags & LKM_GET_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			BUG_ON(!(lock->lksb->flags & DLM_LKSB_GET_LVB));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			memcpy(lock->lksb->lvb, past->lvb, DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (past->type == DLM_AST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		dlm_do_local_ast(dlm, res, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		dlm_do_local_bast(dlm, res, lock, past->blocked_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		dlm_lockres_put(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	dlm_put(dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) int dlm_send_proxy_ast_msg(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			   struct dlm_lock *lock, int msg_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			   int blocked_type, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct dlm_proxy_ast past;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct kvec vec[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	size_t veclen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	mlog(0, "%s: res %.*s, to %u, type %d, blocked_type %d\n", dlm->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	     res->lockname.len, res->lockname.name, lock->ml.node, msg_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	     blocked_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	memset(&past, 0, sizeof(struct dlm_proxy_ast));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	past.node_idx = dlm->node_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	past.type = msg_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	past.blocked_type = blocked_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	past.namelen = res->lockname.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	memcpy(past.name, res->lockname.name, past.namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	past.cookie = lock->ml.cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	vec[0].iov_len = sizeof(struct dlm_proxy_ast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	vec[0].iov_base = &past;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (flags & DLM_LKSB_GET_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		be32_add_cpu(&past.flags, LKM_GET_LVB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		vec[1].iov_len = DLM_LVB_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		vec[1].iov_base = lock->lksb->lvb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		veclen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	ret = o2net_send_message_vec(DLM_PROXY_AST_MSG, dlm->key, vec, veclen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 				     lock->ml.node, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		mlog(ML_ERROR, "%s: res %.*s, error %d send AST to node %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		     dlm->name, res->lockname.len, res->lockname.name, ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		     lock->ml.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		if (status == DLM_RECOVERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			mlog(ML_ERROR, "sent AST to node %u, it thinks this "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			     "node is dead!\n", lock->ml.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		} else if (status == DLM_MIGRATING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			mlog(ML_ERROR, "sent AST to node %u, it returned "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			     "DLM_MIGRATING!\n", lock->ml.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		} else if (status != DLM_NORMAL && status != DLM_IVLOCKID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			mlog(ML_ERROR, "AST to node %u returned %d!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			     lock->ml.node, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			/* ignore it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }