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)  * dlmconvert.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * underlying calls for lock conversion
^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) #include "dlmconvert.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define MLOG_MASK_PREFIX ML_DLM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "../cluster/masklog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /* NOTE: __dlmconvert_master is the only function in here that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * needs a spinlock held on entry (res->spinlock) and it is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * only one that holds a lock on exit (res->spinlock).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * All other functions in here need no locks and drop all of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * the locks that they acquire. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static enum dlm_status __dlmconvert_master(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, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 					   int type, int *call_ast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 					   int *kick_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static enum dlm_status dlm_send_remote_convert_request(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, int flags, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * this is only called directly by dlmlock(), and only when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * local node is the owner of the lockres
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *   caller needs:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *   taken:         takes and drops res->spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *   held on exit:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * returns: see __dlmconvert_master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) enum dlm_status dlmconvert_master(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				  struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				  struct dlm_lock *lock, int flags, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int call_ast = 0, kick_thread = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	enum dlm_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	/* we are not in a network handler, this is fine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	__dlm_wait_on_lockres(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	__dlm_lockres_reserve_ast(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	res->state |= DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	status = __dlmconvert_master(dlm, res, lock, flags, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				     &call_ast, &kick_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	wake_up(&res->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (status != DLM_NORMAL && status != DLM_NOTQUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* either queue the ast or release it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (call_ast)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		dlm_queue_ast(dlm, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		dlm_lockres_release_ast(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (kick_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		dlm_kick_thread(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) /* performs lock conversion at the lockres master site
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *   caller needs:  res->spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *   taken:         takes and drops lock->spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *   held on exit:  res->spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * returns: DLM_NORMAL, DLM_NOTQUEUED, DLM_DENIED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *   call_ast: whether ast should be called for this lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *   kick_thread: whether dlm_kick_thread should be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static enum dlm_status __dlmconvert_master(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					   struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					   struct dlm_lock *lock, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					   int type, int *call_ast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					   int *kick_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	enum dlm_status status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct dlm_lock *tmplock=NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	assert_spin_locked(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	mlog(0, "type=%d, convert_type=%d, new convert_type=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	     lock->ml.type, lock->ml.convert_type, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* already converting? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (lock->ml.convert_type != LKM_IVMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		mlog(ML_ERROR, "attempted to convert a lock with a lock "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		     "conversion pending\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		status = DLM_DENIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		goto unlock_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* must be on grant queue to convert */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!dlm_lock_on_list(&res->granted, lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		mlog(ML_ERROR, "attempted to convert a lock not on grant "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		     "queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		status = DLM_DENIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		goto unlock_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (flags & LKM_VALBLK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		switch (lock->ml.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			case LKM_EXMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				/* EX + LKM_VALBLK + convert == set lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				mlog(0, "will set lvb: converting %s->%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				     dlm_lock_mode_name(lock->ml.type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				     dlm_lock_mode_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				lock->lksb->flags |= DLM_LKSB_PUT_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			case LKM_PRMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			case LKM_NLMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				/* refetch if new level is not NL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				if (type > LKM_NLMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 					mlog(0, "will fetch new value into "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 					     "lvb: converting %s->%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					     dlm_lock_mode_name(lock->ml.type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 					     dlm_lock_mode_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 					lock->lksb->flags |= DLM_LKSB_GET_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 					mlog(0, "will NOT fetch new value "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 					     "into lvb: converting %s->%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 					     dlm_lock_mode_name(lock->ml.type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 					     dlm_lock_mode_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					flags &= ~(LKM_VALBLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* in-place downconvert? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (type <= lock->ml.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		goto grant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/* upconvert from here on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	list_for_each_entry(tmplock, &res->granted, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (tmplock == lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		if (!dlm_lock_compatible(tmplock->ml.type, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			goto switch_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	list_for_each_entry(tmplock, &res->converting, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		if (!dlm_lock_compatible(tmplock->ml.type, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			goto switch_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		/* existing conversion requests take precedence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (!dlm_lock_compatible(tmplock->ml.convert_type, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			goto switch_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	/* fall thru to grant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) grant:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	mlog(0, "res %.*s, granting %s lock\n", res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	     res->lockname.name, dlm_lock_mode_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* immediately grant the new lock type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	lock->lksb->status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (lock->ml.node == dlm->node_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		mlog(0, "doing in-place convert for nonlocal lock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	lock->ml.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (lock->lksb->flags & DLM_LKSB_PUT_LVB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		memcpy(res->lvb, lock->lksb->lvb, DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * Move the lock to the tail because it may be the only lock which has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * an invalid lvb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	list_move_tail(&lock->list, &res->granted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	*call_ast = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	goto unlock_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) switch_queues:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (flags & LKM_NOQUEUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		mlog(0, "failed to convert NOQUEUE lock %.*s from "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		     "%d to %d...\n", res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		     lock->ml.type, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		status = DLM_NOTQUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		goto unlock_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	mlog(0, "res %.*s, queueing...\n", res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	     res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	lock->ml.convert_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	/* do not alter lock refcount.  switching lists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	list_move_tail(&lock->list, &res->converting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) unlock_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (status == DLM_DENIED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		__dlm_print_one_lock_resource(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (status == DLM_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		*kick_thread = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void dlm_revert_pending_convert(struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* do not alter lock refcount.  switching lists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	list_move_tail(&lock->list, &res->granted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	lock->ml.convert_type = LKM_IVMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	lock->lksb->flags &= ~(DLM_LKSB_GET_LVB|DLM_LKSB_PUT_LVB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* messages the master site to do lock conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  *   caller needs:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  *   taken:         takes and drops res->spinlock, uses DLM_LOCK_RES_IN_PROGRESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  *   held on exit:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * returns: DLM_NORMAL, DLM_RECOVERING, status from remote node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) enum dlm_status dlmconvert_remote(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				  struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				  struct dlm_lock *lock, int flags, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	enum dlm_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	mlog(0, "type=%d, convert_type=%d, busy=%d\n", lock->ml.type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	     lock->ml.convert_type, res->state & DLM_LOCK_RES_IN_PROGRESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (res->state & DLM_LOCK_RES_RECOVERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		mlog(0, "bailing out early since res is RECOVERING "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		     "on secondary queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		/* __dlm_print_one_lock_resource(res); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		status = DLM_RECOVERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* will exit this call with spinlock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	__dlm_wait_on_lockres(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (lock->ml.convert_type != LKM_IVMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		__dlm_print_one_lock_resource(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		mlog(ML_ERROR, "converting a remote lock that is already "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		     "converting! (cookie=%u:%llu, conv=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		     lock->ml.convert_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		status = DLM_DENIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		goto bail;
^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) 	if (lock->ml.type == type && lock->ml.convert_type == LKM_IVMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		mlog(0, "last convert request returned DLM_RECOVERING, but "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		     "owner has already queued and sent ast to me. res %.*s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		     "(cookie=%u:%llu, type=%d, conv=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		     res->lockname.len, res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		     dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		     dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		     lock->ml.type, lock->ml.convert_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	res->state |= DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	/* move lock to local convert queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	/* do not alter lock refcount.  switching lists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	list_move_tail(&lock->list, &res->converting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	lock->convert_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	lock->ml.convert_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (flags & LKM_VALBLK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		if (lock->ml.type == LKM_EXMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			flags |= LKM_PUT_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			lock->lksb->flags |= DLM_LKSB_PUT_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			if (lock->ml.convert_type == LKM_NLMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 				flags &= ~LKM_VALBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 				flags |= LKM_GET_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 				lock->lksb->flags |= DLM_LKSB_GET_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	/* no locks held here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * need to wait for a reply as to whether it got queued or not. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	status = dlm_send_remote_convert_request(dlm, res, lock, flags, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	/* if it failed, move it back to granted queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	 * if master returns DLM_NORMAL and then down before sending ast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	 * it may have already been moved to granted queue, reset to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	 * DLM_RECOVERING and retry convert */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (status != DLM_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		if (status != DLM_NOTQUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		dlm_revert_pending_convert(res, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	} else if (!lock->convert_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		mlog(0, "%s: res %.*s, owner died and lock has been moved back "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				"to granted list, retry convert.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				dlm->name, res->lockname.len, res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		status = DLM_RECOVERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	lock->convert_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/* TODO: should this be a wake_one? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/* wake up any IN_PROGRESS waiters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	wake_up(&res->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* sends DLM_CONVERT_LOCK_MSG to master site
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  *   caller needs:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  *   taken:         none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  *   held on exit:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * returns: DLM_NOLOCKMGR, status from remote node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static enum dlm_status dlm_send_remote_convert_request(struct dlm_ctxt *dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 					   struct dlm_lock_resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 					   struct dlm_lock *lock, int flags, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct dlm_convert_lock convert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	int tmpret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	enum dlm_status ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct kvec vec[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	size_t veclen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	mlog(0, "%.*s\n", res->lockname.len, res->lockname.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	memset(&convert, 0, sizeof(struct dlm_convert_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	convert.node_idx = dlm->node_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	convert.requested_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	convert.cookie = lock->ml.cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	convert.namelen = res->lockname.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	convert.flags = cpu_to_be32(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	memcpy(convert.name, res->lockname.name, convert.namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	vec[0].iov_len = sizeof(struct dlm_convert_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	vec[0].iov_base = &convert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (flags & LKM_PUT_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		/* extra data to send if we are updating lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		vec[1].iov_len = DLM_LVB_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		vec[1].iov_base = lock->lksb->lvb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		veclen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	tmpret = o2net_send_message_vec(DLM_CONVERT_LOCK_MSG, dlm->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 					vec, veclen, res->owner, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (tmpret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		// successfully sent and received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		ret = status;  // this is already a dlm_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		if (ret == DLM_RECOVERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			mlog(0, "node %u returned DLM_RECOVERING from convert "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			     "message!\n", res->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		} else if (ret == DLM_MIGRATING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			mlog(0, "node %u returned DLM_MIGRATING from convert "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			     "message!\n", res->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		} else if (ret == DLM_FORWARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			mlog(0, "node %u returned DLM_FORWARD from convert "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			     "message!\n", res->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		} else if (ret != DLM_NORMAL && ret != DLM_NOTQUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			dlm_error(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		mlog(ML_ERROR, "Error %d when sending message %u (key 0x%x) to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		     "node %u\n", tmpret, DLM_CONVERT_LOCK_MSG, dlm->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		     res->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		if (dlm_is_host_down(tmpret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			/* instead of logging the same network error over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			 * and over, sleep here and wait for the heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			 * to notice the node is dead.  times out after 5s. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			dlm_wait_for_node_death(dlm, res->owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 						DLM_NODE_DEATH_WAIT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			ret = DLM_RECOVERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			mlog(0, "node %u died so returning DLM_RECOVERING "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			     "from convert message!\n", res->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			ret = dlm_err_to_dlm_status(tmpret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return ret;
^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) /* handler for DLM_CONVERT_LOCK_MSG on master site
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  *   caller needs:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  *   taken:         takes and drop res->spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  *   held on exit:  none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * returns: DLM_NORMAL, DLM_IVLOCKID, DLM_BADARGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  *          status from __dlmconvert_master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int dlm_convert_lock_handler(struct o2net_msg *msg, u32 len, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			     void **ret_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	struct dlm_ctxt *dlm = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	struct dlm_convert_lock *cnv = (struct dlm_convert_lock *)msg->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct dlm_lock_resource *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct dlm_lock *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct dlm_lock *tmp_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct dlm_lockstatus *lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	enum dlm_status status = DLM_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	int call_ast = 0, kick_thread = 0, ast_reserved = 0, wake = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (!dlm_grab(dlm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		dlm_error(DLM_REJECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		return DLM_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	mlog_bug_on_msg(!dlm_domain_fully_joined(dlm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			"Domain %s not fully joined!\n", dlm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (cnv->namelen > DLM_LOCKID_NAME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		status = DLM_IVBUFLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		dlm_error(status);
^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) 	flags = be32_to_cpu(cnv->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if ((flags & (LKM_PUT_LVB|LKM_GET_LVB)) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	     (LKM_PUT_LVB|LKM_GET_LVB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		mlog(ML_ERROR, "both PUT and GET lvb specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		status = DLM_BADARGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	mlog(0, "lvb: %s\n", flags & LKM_PUT_LVB ? "put lvb" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	     (flags & LKM_GET_LVB ? "get lvb" : "none"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	status = DLM_IVLOCKID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	res = dlm_lookup_lockres(dlm, cnv->name, cnv->namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	status = __dlm_lockres_state_to_status(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	if (status != DLM_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	list_for_each_entry(tmp_lock, &res->granted, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		if (tmp_lock->ml.cookie == cnv->cookie &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		    tmp_lock->ml.node == cnv->node_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			lock = tmp_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			dlm_lock_get(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	if (!lock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		status = DLM_IVLOCKID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		mlog(ML_ERROR, "did not find lock to convert on grant queue! "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			       "cookie=%u:%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		     dlm_get_lock_cookie_node(be64_to_cpu(cnv->cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		     dlm_get_lock_cookie_seq(be64_to_cpu(cnv->cookie)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		dlm_print_one_lock_resource(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	/* found the lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	lksb = lock->lksb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	/* see if caller needed to get/put lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	if (flags & LKM_PUT_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		BUG_ON(lksb->flags & (DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		lksb->flags |= DLM_LKSB_PUT_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		memcpy(&lksb->lvb[0], &cnv->lvb[0], DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	} else if (flags & LKM_GET_LVB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		BUG_ON(lksb->flags & (DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		lksb->flags |= DLM_LKSB_GET_LVB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	status = __dlm_lockres_state_to_status(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (status == DLM_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		__dlm_lockres_reserve_ast(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		ast_reserved = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		res->state |= DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		status = __dlmconvert_master(dlm, res, lock, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 					     cnv->requested_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 					     &call_ast, &kick_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		wake = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (wake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		wake_up(&res->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	if (status != DLM_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		if (status != DLM_NOTQUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			dlm_error(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		lksb->flags &= ~(DLM_LKSB_GET_LVB|DLM_LKSB_PUT_LVB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		dlm_lock_put(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	/* either queue the ast or release it, if reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (call_ast)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		dlm_queue_ast(dlm, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	else if (ast_reserved)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		dlm_lockres_release_ast(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	if (kick_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		dlm_kick_thread(dlm, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		dlm_lockres_put(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	dlm_put(dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }