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)  * dlmdebug.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * debug functionality for the dlm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2004, 2008 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) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "../cluster/heartbeat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "../cluster/nodemanager.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "../cluster/tcp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "dlmapi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "dlmcommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "dlmdomain.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "dlmdebug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define MLOG_MASK_PREFIX ML_DLM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "../cluster/masklog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int stringify_lockname(const char *lockname, int locklen, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 			      int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) void dlm_print_one_lock_resource(struct dlm_lock_resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	__dlm_print_one_lock_resource(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void dlm_print_lockres_refmap(struct dlm_lock_resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	assert_spin_locked(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	printk("  refmap nodes: [ ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	bit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		bit = find_next_bit(res->refmap, O2NM_MAX_NODES, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (bit >= O2NM_MAX_NODES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		printk("%u ", bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		bit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	printk("], inflight=%u\n", res->inflight_locks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static void __dlm_print_lock(struct dlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	printk("    type=%d, conv=%d, node=%u, cookie=%u:%llu, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	       "ref=%u, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	       "pending=(conv=%c,lock=%c,cancel=%c,unlock=%c)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	       lock->ml.type, lock->ml.convert_type, lock->ml.node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	       dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	       dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	       kref_read(&lock->lock_refs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	       (list_empty(&lock->ast_list) ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	       (lock->ast_pending ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	       (list_empty(&lock->bast_list) ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	       (lock->bast_pending ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	       (lock->convert_pending ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	       (lock->lock_pending ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	       (lock->cancel_pending ? 'y' : 'n'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	       (lock->unlock_pending ? 'y' : 'n'));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) void __dlm_print_one_lock_resource(struct dlm_lock_resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct dlm_lock *lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	char buf[DLM_LOCKID_NAME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	assert_spin_locked(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	stringify_lockname(res->lockname.name, res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			   buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	printk("lockres: %s, owner=%u, state=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	       buf, res->owner, res->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	printk("  last used: %lu, refcnt: %u, on purge list: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	       res->last_used, kref_read(&res->refs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	       list_empty(&res->purge) ? "no" : "yes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	printk("  on dirty list: %s, on reco list: %s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	       "migrating pending: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	       list_empty(&res->dirty) ? "no" : "yes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	       list_empty(&res->recovering) ? "no" : "yes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	       res->migration_pending ? "yes" : "no");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	printk("  inflight locks: %d, asts reserved: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	       res->inflight_locks, atomic_read(&res->asts_reserved));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	dlm_print_lockres_refmap(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	printk("  granted queue:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	list_for_each_entry(lock, &res->granted, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		__dlm_print_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	printk("  converting queue:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	list_for_each_entry(lock, &res->converting, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		__dlm_print_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	printk("  blocked queue:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	list_for_each_entry(lock, &res->blocked, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		__dlm_print_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) void dlm_print_one_lock(struct dlm_lock *lockid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	dlm_print_one_lock_resource(lockid->lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) EXPORT_SYMBOL_GPL(dlm_print_one_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static const char *dlm_errnames[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	[DLM_NORMAL] =			"DLM_NORMAL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	[DLM_GRANTED] =			"DLM_GRANTED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	[DLM_DENIED] =			"DLM_DENIED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	[DLM_DENIED_NOLOCKS] =		"DLM_DENIED_NOLOCKS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	[DLM_WORKING] =			"DLM_WORKING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	[DLM_BLOCKED] =			"DLM_BLOCKED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	[DLM_BLOCKED_ORPHAN] =		"DLM_BLOCKED_ORPHAN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	[DLM_DENIED_GRACE_PERIOD] =	"DLM_DENIED_GRACE_PERIOD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	[DLM_SYSERR] =			"DLM_SYSERR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	[DLM_NOSUPPORT] =		"DLM_NOSUPPORT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	[DLM_CANCELGRANT] =		"DLM_CANCELGRANT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	[DLM_IVLOCKID] =		"DLM_IVLOCKID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	[DLM_SYNC] =			"DLM_SYNC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	[DLM_BADTYPE] =			"DLM_BADTYPE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	[DLM_BADRESOURCE] =		"DLM_BADRESOURCE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	[DLM_MAXHANDLES] =		"DLM_MAXHANDLES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	[DLM_NOCLINFO] =		"DLM_NOCLINFO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	[DLM_NOLOCKMGR] =		"DLM_NOLOCKMGR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	[DLM_NOPURGED] =		"DLM_NOPURGED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	[DLM_BADARGS] =			"DLM_BADARGS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	[DLM_VOID] =			"DLM_VOID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	[DLM_NOTQUEUED] =		"DLM_NOTQUEUED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	[DLM_IVBUFLEN] =		"DLM_IVBUFLEN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	[DLM_CVTUNGRANT] =		"DLM_CVTUNGRANT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	[DLM_BADPARAM] =		"DLM_BADPARAM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	[DLM_VALNOTVALID] =		"DLM_VALNOTVALID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	[DLM_REJECTED] =		"DLM_REJECTED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	[DLM_ABORT] =			"DLM_ABORT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	[DLM_CANCEL] =			"DLM_CANCEL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	[DLM_IVRESHANDLE] =		"DLM_IVRESHANDLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	[DLM_DEADLOCK] =		"DLM_DEADLOCK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	[DLM_DENIED_NOASTS] =		"DLM_DENIED_NOASTS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	[DLM_FORWARD] =			"DLM_FORWARD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	[DLM_TIMEOUT] =			"DLM_TIMEOUT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	[DLM_IVGROUPID] =		"DLM_IVGROUPID",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	[DLM_VERS_CONFLICT] =		"DLM_VERS_CONFLICT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	[DLM_BAD_DEVICE_PATH] =		"DLM_BAD_DEVICE_PATH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	[DLM_NO_DEVICE_PERMISSION] =	"DLM_NO_DEVICE_PERMISSION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	[DLM_NO_CONTROL_DEVICE ] =	"DLM_NO_CONTROL_DEVICE ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	[DLM_RECOVERING] =		"DLM_RECOVERING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	[DLM_MIGRATING] =		"DLM_MIGRATING",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	[DLM_MAXSTATS] =		"DLM_MAXSTATS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static const char *dlm_errmsgs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	[DLM_NORMAL] = 			"request in progress",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	[DLM_GRANTED] = 		"request granted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	[DLM_DENIED] = 			"request denied",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	[DLM_DENIED_NOLOCKS] = 		"request denied, out of system resources",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	[DLM_WORKING] = 		"async request in progress",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	[DLM_BLOCKED] = 		"lock request blocked",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	[DLM_BLOCKED_ORPHAN] = 		"lock request blocked by a orphan lock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	[DLM_DENIED_GRACE_PERIOD] = 	"topological change in progress",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	[DLM_SYSERR] = 			"system error",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	[DLM_NOSUPPORT] = 		"unsupported",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	[DLM_CANCELGRANT] = 		"can't cancel convert: already granted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	[DLM_IVLOCKID] = 		"bad lockid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	[DLM_SYNC] = 			"synchronous request granted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	[DLM_BADTYPE] = 		"bad resource type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	[DLM_BADRESOURCE] = 		"bad resource handle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	[DLM_MAXHANDLES] = 		"no more resource handles",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	[DLM_NOCLINFO] = 		"can't contact cluster manager",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	[DLM_NOLOCKMGR] = 		"can't contact lock manager",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	[DLM_NOPURGED] = 		"can't contact purge daemon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	[DLM_BADARGS] = 		"bad api args",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	[DLM_VOID] = 			"no status",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	[DLM_NOTQUEUED] = 		"NOQUEUE was specified and request failed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	[DLM_IVBUFLEN] = 		"invalid resource name length",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	[DLM_CVTUNGRANT] = 		"attempted to convert ungranted lock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	[DLM_BADPARAM] = 		"invalid lock mode specified",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	[DLM_VALNOTVALID] = 		"value block has been invalidated",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	[DLM_REJECTED] = 		"request rejected, unrecognized client",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	[DLM_ABORT] = 			"blocked lock request cancelled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	[DLM_CANCEL] = 			"conversion request cancelled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	[DLM_IVRESHANDLE] = 		"invalid resource handle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	[DLM_DEADLOCK] = 		"deadlock recovery refused this request",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	[DLM_DENIED_NOASTS] = 		"failed to allocate AST",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	[DLM_FORWARD] = 		"request must wait for primary's response",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	[DLM_TIMEOUT] = 		"timeout value for lock has expired",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	[DLM_IVGROUPID] = 		"invalid group specification",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	[DLM_VERS_CONFLICT] = 		"version conflicts prevent request handling",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	[DLM_BAD_DEVICE_PATH] = 	"Locks device does not exist or path wrong",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	[DLM_NO_DEVICE_PERMISSION] = 	"Client has insufficient perms for device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	[DLM_NO_CONTROL_DEVICE] = 	"Cannot set options on opened device ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	[DLM_RECOVERING] = 		"lock resource being recovered",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	[DLM_MIGRATING] = 		"lock resource being migrated",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	[DLM_MAXSTATS] = 		"invalid error number",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) const char *dlm_errmsg(enum dlm_status err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (err >= DLM_MAXSTATS || err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return dlm_errmsgs[DLM_MAXSTATS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return dlm_errmsgs[err];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) EXPORT_SYMBOL_GPL(dlm_errmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) const char *dlm_errname(enum dlm_status err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (err >= DLM_MAXSTATS || err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return dlm_errnames[DLM_MAXSTATS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return dlm_errnames[err];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) EXPORT_SYMBOL_GPL(dlm_errname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* NOTE: This function converts a lockname into a string. It uses knowledge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * of the format of the lockname that should be outside the purview of the dlm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * We are adding only to make dlm debugging slightly easier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static int stringify_lockname(const char *lockname, int locklen, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			      int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	__be64 inode_blkno_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define OCFS2_DENTRY_LOCK_INO_START	18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (*lockname == 'N') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		memcpy((__be64 *)&inode_blkno_be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		       (char *)&lockname[OCFS2_DENTRY_LOCK_INO_START],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		       sizeof(__be64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		out += scnprintf(buf + out, len - out, "%.*s%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 				OCFS2_DENTRY_LOCK_INO_START - 1, lockname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				(unsigned int)be64_to_cpu(inode_blkno_be));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		out += scnprintf(buf + out, len - out, "%.*s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				locklen, lockname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int stringify_nodemap(unsigned long *nodemap, int maxnodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			     char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int i = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		out += scnprintf(buf + out, len - out, "%d ", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return out;
^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) static int dump_mle(struct dlm_master_list_entry *mle, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	char *mle_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (mle->type == DLM_MLE_BLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		mle_type = "BLK";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	else if (mle->type == DLM_MLE_MASTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		mle_type = "MAS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		mle_type = "MIG";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	out += stringify_lockname(mle->mname, mle->mnamelen, buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			"\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			mle_type, mle->master, mle->new_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			!list_empty(&mle->hb_events),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			!!mle->inuse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			kref_read(&mle->mle_refs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	out += scnprintf(buf + out, len - out, "Maybe=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	out += stringify_nodemap(mle->maybe_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	out += scnprintf(buf + out, len - out, "Vote=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	out += stringify_nodemap(mle->vote_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	out += scnprintf(buf + out, len - out, "Response=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	out += stringify_nodemap(mle->response_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	out += scnprintf(buf + out, len - out, "Node=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	out += stringify_nodemap(mle->node_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return out;
^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) void dlm_print_one_mle(struct dlm_master_list_entry *mle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	buf = (char *) get_zeroed_page(GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		dump_mle(mle, buf, PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static struct dentry *dlm_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define DLM_DEBUGFS_DIR				"o2dlm"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #define DLM_DEBUGFS_DLM_STATE			"dlm_state"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) #define DLM_DEBUGFS_LOCKING_STATE		"locking_state"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #define DLM_DEBUGFS_MLE_STATE			"mle_state"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #define DLM_DEBUGFS_PURGE_LIST			"purge_list"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* begin - utils funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int debug_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	free_page((unsigned long)file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static ssize_t debug_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			  size_t nbytes, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				       i_size_read(file->f_mapping->host));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* end - util funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /* begin - purge list funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int debug_purgelist_print(struct dlm_ctxt *dlm, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct dlm_lock_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	unsigned long total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			"Dumping Purgelist for Domain: %s\n", dlm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	spin_lock(&dlm->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	list_for_each_entry(res, &dlm->purge_list, purge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		++total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		if (len - out < 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		out += stringify_lockname(res->lockname.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 					  res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 					  buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		out += scnprintf(buf + out, len - out, "\t%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				(jiffies - res->last_used)/HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	spin_unlock(&dlm->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	out += scnprintf(buf + out, len - out, "Total on list: %lu\n", total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return out;
^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) static int debug_purgelist_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct dlm_ctxt *dlm = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	char *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	buf = (char *) get_zeroed_page(GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	i_size_write(inode, debug_purgelist_print(dlm, buf, PAGE_SIZE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	file->private_data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static const struct file_operations debug_purgelist_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	.open =		debug_purgelist_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	.release =	debug_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	.read =		debug_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* end - purge list funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* begin - debug mle funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static int debug_mle_print(struct dlm_ctxt *dlm, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct dlm_master_list_entry *mle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct hlist_head *bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	int i, out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	unsigned long total = 0, longest = 0, bucket_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			"Dumping MLEs for Domain: %s\n", dlm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	spin_lock(&dlm->master_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	for (i = 0; i < DLM_HASH_BUCKETS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		bucket = dlm_master_hash(dlm, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		hlist_for_each_entry(mle, bucket, master_hash_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			++total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			++bucket_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			if (len - out < 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			out += dump_mle(mle, buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		longest = max(longest, bucket_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		bucket_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	spin_unlock(&dlm->master_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			"Total: %lu, Longest: %lu\n", total, longest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static int debug_mle_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct dlm_ctxt *dlm = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	char *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	buf = (char *) get_zeroed_page(GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	i_size_write(inode, debug_mle_print(dlm, buf, PAGE_SIZE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	file->private_data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static const struct file_operations debug_mle_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	.open =		debug_mle_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	.release =	debug_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	.read =		debug_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /* end - debug mle funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* begin - debug lockres funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static int dump_lock(struct dlm_lock *lock, int list_type, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	int out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #define DEBUG_LOCK_VERSION	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	spin_lock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	out = scnprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		       "%d,%d,%d,%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		       DEBUG_LOCK_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		       list_type, lock->ml.type, lock->ml.convert_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		       lock->ml.node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		       dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		       dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		       !list_empty(&lock->ast_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		       !list_empty(&lock->bast_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		       lock->ast_pending, lock->bast_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		       lock->convert_pending, lock->lock_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		       lock->cancel_pending, lock->unlock_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		       kref_read(&lock->lock_refs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	spin_unlock(&lock->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	struct dlm_lock *lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	out += scnprintf(buf + out, len - out, "NAME:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	out += stringify_lockname(res->lockname.name, res->lockname.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 				  buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #define DEBUG_LRES_VERSION	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			"LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			DEBUG_LRES_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			res->owner, res->state, res->last_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 			!list_empty(&res->purge),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			!list_empty(&res->dirty),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			!list_empty(&res->recovering),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			res->inflight_locks, res->migration_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			atomic_read(&res->asts_reserved),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			kref_read(&res->refs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	/* refmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	out += scnprintf(buf + out, len - out, "RMAP:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	out += stringify_nodemap(res->refmap, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	/* lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	out += scnprintf(buf + out, len - out, "LVBX:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	for (i = 0; i < DLM_LVB_LEN; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 					"%02x", (unsigned char)res->lvb[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	/* granted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	list_for_each_entry(lock, &res->granted, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		out += dump_lock(lock, 0, buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	/* converting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	list_for_each_entry(lock, &res->converting, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		out += dump_lock(lock, 1, buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	/* blocked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	list_for_each_entry(lock, &res->blocked, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		out += dump_lock(lock, 2, buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	struct debug_lockres *dl = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	struct dlm_ctxt *dlm = dl->dl_ctxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	struct dlm_lock_resource *oldres = dl->dl_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	struct dlm_lock_resource *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	struct list_head *track_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	spin_lock(&dlm->track_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	if (oldres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		track_list = &oldres->tracking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		track_list = &dlm->tracking_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		if (list_empty(track_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 			dl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			spin_unlock(&dlm->track_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			goto bail;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	list_for_each_entry(res, track_list, tracking) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		if (&res->tracking == &dlm->tracking_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 			dlm_lockres_get(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	spin_unlock(&dlm->track_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	if (oldres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		dlm_lockres_put(oldres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	dl->dl_res = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		spin_lock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		spin_unlock(&res->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		dl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	/* passed to seq_show */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	return dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static void lockres_seq_stop(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static int lockres_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	struct debug_lockres *dl = (struct debug_lockres *)v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	seq_printf(s, "%s", dl->dl_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	return 0;
^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) static const struct seq_operations debug_lockres_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	.start =	lockres_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	.stop =		lockres_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	.next =		lockres_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	.show =		lockres_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) static int debug_lockres_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	struct dlm_ctxt *dlm = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	struct debug_lockres *dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	dl = __seq_open_private(file, &debug_lockres_ops, sizeof(*dl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	if (!dl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		goto bailfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	dl->dl_len = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	dl->dl_buf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	dlm_grab(dlm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	dl->dl_ctxt = dlm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) bailfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	mlog_errno(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static int debug_lockres_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	struct seq_file *seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	struct debug_lockres *dl = (struct debug_lockres *)seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	if (dl->dl_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		dlm_lockres_put(dl->dl_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	dlm_put(dl->dl_ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	kfree(dl->dl_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	return seq_release_private(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static const struct file_operations debug_lockres_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	.open =		debug_lockres_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	.release =	debug_lockres_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	.read =		seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	.llseek =	seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) /* end - debug lockres funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /* begin - debug state funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	struct dlm_reco_node_data *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	char *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	int cur_mles = 0, tot_mles = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	spin_lock(&dlm->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	switch (dlm->dlm_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	case DLM_CTXT_NEW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		state = "NEW"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	case DLM_CTXT_JOINED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		state = "JOINED"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	case DLM_CTXT_IN_SHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		state = "SHUTDOWN"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	case DLM_CTXT_LEAVING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		state = "LEAVING"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		state = "UNKNOWN"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* Domain: xxxxxxxxxx  Key: 0xdfbac769 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 			"Domain: %s  Key: 0x%08x  Protocol: %d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 			dlm->name, dlm->key, dlm->dlm_locking_proto.pv_major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 			dlm->dlm_locking_proto.pv_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	/* Thread Pid: xxx  Node: xxx  State: xxxxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 			"Thread Pid: %d  Node: %d  State: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 			task_pid_nr(dlm->dlm_thread_task), dlm->node_num, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	/* Number of Joins: xxx  Joining Node: xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 			"Number of Joins: %d  Joining Node: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 			dlm->num_joins, dlm->joining_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	/* Domain Map: xx xx xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	out += scnprintf(buf + out, len - out, "Domain Map: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	/* Exit Domain Map: xx xx xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	out += scnprintf(buf + out, len - out, "Exit Domain Map: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	out += stringify_nodemap(dlm->exit_domain_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	/* Live Map: xx xx xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	out += scnprintf(buf + out, len - out, "Live Map: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	/* Lock Resources: xxx (xxx) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 			"Lock Resources: %d (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 			atomic_read(&dlm->res_cur_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			atomic_read(&dlm->res_tot_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	for (i = 0; i < DLM_MLE_NUM_TYPES; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		tot_mles += atomic_read(&dlm->mle_tot_count[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	for (i = 0; i < DLM_MLE_NUM_TYPES; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		cur_mles += atomic_read(&dlm->mle_cur_count[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	/* MLEs: xxx (xxx) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 			"MLEs: %d (%d)\n", cur_mles, tot_mles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	/*  Blocking: xxx (xxx) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			"  Blocking: %d (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 			atomic_read(&dlm->mle_cur_count[DLM_MLE_BLOCK]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 			atomic_read(&dlm->mle_tot_count[DLM_MLE_BLOCK]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	/*  Mastery: xxx (xxx) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 			"  Mastery: %d (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 			atomic_read(&dlm->mle_cur_count[DLM_MLE_MASTER]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 			atomic_read(&dlm->mle_tot_count[DLM_MLE_MASTER]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	/*  Migration: xxx (xxx) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 			"  Migration: %d (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 			atomic_read(&dlm->mle_cur_count[DLM_MLE_MIGRATION]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 			atomic_read(&dlm->mle_tot_count[DLM_MLE_MIGRATION]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	/* Lists: Dirty=Empty  Purge=InUse  PendingASTs=Empty  ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 			"Lists: Dirty=%s  Purge=%s  PendingASTs=%s  "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 			"PendingBASTs=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 			(list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 			(list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 			(list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 			(list_empty(&dlm->pending_basts) ? "Empty" : "InUse"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	/* Purge Count: xxx  Refs: xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 			"Purge Count: %d  Refs: %d\n", dlm->purge_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 			kref_read(&dlm->dlm_refs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	/* Dead Node: xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 			"Dead Node: %d\n", dlm->reco.dead_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	/* What about DLM_RECO_STATE_FINALIZE? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		state = "ACTIVE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 		state = "INACTIVE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	/* Recovery Pid: xxxx  Master: xxx  State: xxxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	out += scnprintf(buf + out, len - out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 			"Recovery Pid: %d  Master: %d  State: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 			task_pid_nr(dlm->dlm_reco_thread_task),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			dlm->reco.new_master, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	/* Recovery Map: xx xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	out += scnprintf(buf + out, len - out, "Recovery Map: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 				 buf + out, len - out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	out += scnprintf(buf + out, len - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	/* Recovery Node State: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	out += scnprintf(buf + out, len - out, "Recovery Node State:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	list_for_each_entry(node, &dlm->reco.node_data, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		switch (node->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 		case DLM_RECO_NODE_DATA_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 			state = "INIT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 		case DLM_RECO_NODE_DATA_REQUESTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 			state = "REQUESTING";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 		case DLM_RECO_NODE_DATA_DEAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 			state = "DEAD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 		case DLM_RECO_NODE_DATA_RECEIVING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 			state = "RECEIVING";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 		case DLM_RECO_NODE_DATA_REQUESTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 			state = "REQUESTED";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		case DLM_RECO_NODE_DATA_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 			state = "DONE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 		case DLM_RECO_NODE_DATA_FINALIZE_SENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 			state = "FINALIZE-SENT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 			state = "BAD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		out += scnprintf(buf + out, len - out, "\t%u - %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 				node->node_num, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	spin_unlock(&dlm->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) static int debug_state_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	struct dlm_ctxt *dlm = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	char *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	buf = (char *) get_zeroed_page(GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	i_size_write(inode, debug_state_print(dlm, buf, PAGE_SIZE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	file->private_data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) static const struct file_operations debug_state_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	.open =		debug_state_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	.release =	debug_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	.read =		debug_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) /* end  - debug state funcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /* files in subroot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) void dlm_debug_init(struct dlm_ctxt *dlm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	/* for dumping dlm_ctxt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	debugfs_create_file(DLM_DEBUGFS_DLM_STATE, S_IFREG|S_IRUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 			    dlm->dlm_debugfs_subroot, dlm, &debug_state_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	/* for dumping lockres */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE, S_IFREG|S_IRUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 			    dlm->dlm_debugfs_subroot, dlm, &debug_lockres_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	/* for dumping mles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	debugfs_create_file(DLM_DEBUGFS_MLE_STATE, S_IFREG|S_IRUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 			    dlm->dlm_debugfs_subroot, dlm, &debug_mle_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	/* for dumping lockres on the purge list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	debugfs_create_file(DLM_DEBUGFS_PURGE_LIST, S_IFREG|S_IRUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 			    dlm->dlm_debugfs_subroot, dlm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 			    &debug_purgelist_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /* subroot - domain dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) void dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 						      dlm_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	debugfs_remove_recursive(dlm->dlm_debugfs_subroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) /* debugfs root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) void dlm_create_debugfs_root(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 	dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) void dlm_destroy_debugfs_root(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	debugfs_remove(dlm_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) #endif	/* CONFIG_DEBUG_FS */