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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) **  Copyright (C) 2005-2009 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "dlm_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "lock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DLM_DEBUG_BUF_LEN 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static char debug_buf[DLM_DEBUG_BUF_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static struct mutex debug_buf_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct dentry *dlm_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static char *print_lockmode(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	case DLM_LOCK_IV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		return "--";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	case DLM_LOCK_NL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return "NL";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	case DLM_LOCK_CR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		return "CR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	case DLM_LOCK_CW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return "CW";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	case DLM_LOCK_PR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return "PR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	case DLM_LOCK_PW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return "PW";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	case DLM_LOCK_EX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return "EX";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return "??";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			       struct dlm_rsb *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (lkb->lkb_status == DLM_LKSTS_CONVERT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	    lkb->lkb_status == DLM_LKSTS_WAITING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (lkb->lkb_nodeid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		if (lkb->lkb_nodeid != res->res_nodeid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 				   lkb->lkb_remid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			seq_printf(s, " Master:     %08x", lkb->lkb_remid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (lkb->lkb_wait_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static void print_format1(struct dlm_rsb *res, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct dlm_lkb *lkb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	lock_rsb(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	for (i = 0; i < res->res_length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		if (isprint(res->res_name[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			seq_printf(s, "%c", res->res_name[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			seq_printf(s, "%c", '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (res->res_nodeid > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			   res->res_nodeid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	else if (res->res_nodeid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		seq_puts(s, "\"\nMaster Copy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	else if (res->res_nodeid == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		seq_printf(s, "\"\nLooking up master (lkid %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			   res->res_first_lkid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		seq_printf(s, "\"\nInvalid master %d\n", res->res_nodeid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* Print the LVB: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (res->res_lvbptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		seq_puts(s, "LVB: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		for (i = 0; i < lvblen; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			if (i == lvblen / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				seq_puts(s, "\n     ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			seq_printf(s, "%02x ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				   (unsigned char) res->res_lvbptr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (rsb_flag(res, RSB_VALNOTVALID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			seq_puts(s, " (INVALID)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			goto out;
^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) 	root_list = !list_empty(&res->res_root_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	recover_list = !list_empty(&res->res_recover_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (root_list || recover_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		seq_printf(s, "Recovery: root %d recover %d flags %lx count %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			   root_list, recover_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			   res->res_flags, res->res_recover_locks_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* Print the locks attached to this resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	seq_puts(s, "Granted Queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		print_format1_lock(s, lkb, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	seq_puts(s, "Conversion Queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		print_format1_lock(s, lkb, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	seq_puts(s, "Waiting Queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		print_format1_lock(s, lkb, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (list_empty(&res->res_lookup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	seq_puts(s, "Lookup Queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		seq_printf(s, "%08x %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			   lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (lkb->lkb_wait_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	unlock_rsb(res);
^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) static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			       struct dlm_rsb *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	u64 xid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	u64 us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (lkb->lkb_flags & DLM_IFL_USER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (lkb->lkb_ua)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			xid = lkb->lkb_ua->xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	/* microseconds since lkb was added to current queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_timestamp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* id nodeid remid pid xid exflags flags sts grmode rqmode time_us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	   r_nodeid r_len r_name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		   lkb->lkb_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		   lkb->lkb_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		   lkb->lkb_remid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		   lkb->lkb_ownpid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		   (unsigned long long)xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		   lkb->lkb_exflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		   lkb->lkb_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		   lkb->lkb_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		   lkb->lkb_grmode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		   lkb->lkb_rqmode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		   (unsigned long long)us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		   r->res_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		   r->res_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		   r->res_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void print_format2(struct dlm_rsb *r, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct dlm_lkb *lkb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	lock_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		print_format2_lock(s, lkb, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		print_format2_lock(s, lkb, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		print_format2_lock(s, lkb, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	unlock_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			      int rsb_lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	u64 xid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (lkb->lkb_flags & DLM_IFL_USER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		if (lkb->lkb_ua)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			xid = lkb->lkb_ua->xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		   lkb->lkb_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		   lkb->lkb_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		   lkb->lkb_remid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		   lkb->lkb_ownpid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		   (unsigned long long)xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		   lkb->lkb_exflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		   lkb->lkb_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		   lkb->lkb_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		   lkb->lkb_grmode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		   lkb->lkb_rqmode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		   lkb->lkb_last_bast.mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		   rsb_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		   lkb->lkb_wait_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		   lkb->lkb_lvbseq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		   (unsigned long long)ktime_to_ns(lkb->lkb_timestamp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		   (unsigned long long)ktime_to_ns(lkb->lkb_last_bast_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static void print_format3(struct dlm_rsb *r, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct dlm_lkb *lkb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	int i, lvblen = r->res_ls->ls_lvblen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	int print_name = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	lock_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		   r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		   r->res_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		   r->res_first_lkid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		   r->res_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		   !list_empty(&r->res_root_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		   !list_empty(&r->res_recover_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		   r->res_recover_locks_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		   r->res_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	for (i = 0; i < r->res_length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			print_name = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	seq_puts(s, print_name ? "str " : "hex");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	for (i = 0; i < r->res_length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		if (print_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			seq_printf(s, "%c", r->res_name[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (!r->res_lvbptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		goto do_locks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	seq_printf(s, "lvb %u %d", r->res_lvbseq, lvblen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	for (i = 0; i < lvblen; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  do_locks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		print_format3_lock(s, lkb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		print_format3_lock(s, lkb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		print_format3_lock(s, lkb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		print_format3_lock(s, lkb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (seq_has_overflowed(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	unlock_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static void print_format4(struct dlm_rsb *r, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	int our_nodeid = dlm_our_nodeid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	int print_name = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	lock_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		   r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		   r->res_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		   r->res_master_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		   r->res_dir_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		   our_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		   r->res_toss_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		   r->res_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		   r->res_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	for (i = 0; i < r->res_length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			print_name = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	seq_puts(s, print_name ? "str " : "hex");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	for (i = 0; i < r->res_length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		if (print_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			seq_printf(s, "%c", r->res_name[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	seq_putc(s, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	unlock_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct rsbtbl_iter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct dlm_rsb *rsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	unsigned bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	int format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	int header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * If the buffer is full, seq_printf can be called again, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * does nothing.  So, the these printing routines periodically check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  * seq_has_overflowed to avoid wasting too much time trying to print to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * a full buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int table_seq_show(struct seq_file *seq, void *iter_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct rsbtbl_iter *ri = iter_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	switch (ri->format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		print_format1(ri->rsb, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		if (ri->header) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			seq_puts(seq, "id nodeid remid pid xid exflags flags sts grmode rqmode time_ms r_nodeid r_len r_name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			ri->header = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		print_format2(ri->rsb, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		if (ri->header) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			seq_puts(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			ri->header = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		print_format3(ri->rsb, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (ri->header) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			seq_puts(seq, "version 4 rsb 2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			ri->header = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		print_format4(ri->rsb, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static const struct seq_operations format1_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static const struct seq_operations format2_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static const struct seq_operations format3_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static const struct seq_operations format4_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void *table_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	struct rb_root *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	struct dlm_ls *ls = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	struct rsbtbl_iter *ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	struct dlm_rsb *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	loff_t n = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	unsigned bucket, entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	int toss = (seq->op == &format4_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	bucket = n >> 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	entry = n & ((1LL << 32) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (bucket >= ls->ls_rsbtbl_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	ri = kzalloc(sizeof(*ri), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (!ri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		ri->header = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (seq->op == &format1_seq_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		ri->format = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (seq->op == &format2_seq_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		ri->format = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (seq->op == &format3_seq_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		ri->format = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (seq->op == &format4_seq_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		ri->format = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	spin_lock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (!RB_EMPTY_ROOT(tree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		for (node = rb_first(tree); node; node = rb_next(node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			r = rb_entry(node, struct dlm_rsb, res_hashnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			if (!entry--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 				dlm_hold_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 				ri->rsb = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 				ri->bucket = bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 				spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				return ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	 * move to the first rsb in the next non-empty bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* zero the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	n &= ~((1LL << 32) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		bucket++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		n += 1LL << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		if (bucket >= ls->ls_rsbtbl_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			kfree(ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		spin_lock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		if (!RB_EMPTY_ROOT(tree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			node = rb_first(tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			r = rb_entry(node, struct dlm_rsb, res_hashnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			dlm_hold_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			ri->rsb = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			ri->bucket = bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			*pos = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			return ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	struct dlm_ls *ls = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	struct rsbtbl_iter *ri = iter_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	struct rb_root *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	struct rb_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	struct dlm_rsb *r, *rp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	loff_t n = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	unsigned bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	int toss = (seq->op == &format4_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	bucket = n >> 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	 * move to the next rsb in the same bucket
^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(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	rp = ri->rsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	next = rb_next(&rp->res_hashnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	if (next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		r = rb_entry(next, struct dlm_rsb, res_hashnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		dlm_hold_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		ri->rsb = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		dlm_put_rsb(rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		return ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	dlm_put_rsb(rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	 * move to the first rsb in the next non-empty bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	/* zero the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	n &= ~((1LL << 32) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		bucket++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		n += 1LL << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		if (bucket >= ls->ls_rsbtbl_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			kfree(ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		spin_lock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		if (!RB_EMPTY_ROOT(tree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			next = rb_first(tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			r = rb_entry(next, struct dlm_rsb, res_hashnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 			dlm_hold_rsb(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 			ri->rsb = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			ri->bucket = bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 			*pos = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			return ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		spin_unlock(&ls->ls_rsbtbl[bucket].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static void table_seq_stop(struct seq_file *seq, void *iter_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	struct rsbtbl_iter *ri = iter_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	if (ri) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		dlm_put_rsb(ri->rsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		kfree(ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static const struct seq_operations format1_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	.start = table_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	.next  = table_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	.stop  = table_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	.show  = table_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static const struct seq_operations format2_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	.start = table_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	.next  = table_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	.stop  = table_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	.show  = table_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static const struct seq_operations format3_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	.start = table_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	.next  = table_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	.stop  = table_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	.show  = table_seq_show,
^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 const struct seq_operations format4_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	.start = table_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	.next  = table_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	.stop  = table_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	.show  = table_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static const struct file_operations format1_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static const struct file_operations format2_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static const struct file_operations format3_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static const struct file_operations format4_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static int table_open1(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	ret = seq_open(file, &format1_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	seq->private = inode->i_private; /* the dlm_ls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static int table_open2(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	ret = seq_open(file, &format2_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	seq->private = inode->i_private; /* the dlm_ls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static int table_open3(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	ret = seq_open(file, &format3_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	seq->private = inode->i_private; /* the dlm_ls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static int table_open4(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	ret = seq_open(file, &format4_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	seq->private = inode->i_private; /* the dlm_ls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static const struct file_operations format1_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	.open    = table_open1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	.read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	.llseek  = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	.release = seq_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static const struct file_operations format2_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	.open    = table_open2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	.read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	.llseek  = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	.release = seq_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static const struct file_operations format3_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	.open    = table_open3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	.read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	.llseek  = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	.release = seq_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static const struct file_operations format4_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	.open    = table_open4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	.read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	.llseek  = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	.release = seq_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)  * dump lkb's on the ls_waiters list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static ssize_t waiters_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 			    size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	struct dlm_ls *ls = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	struct dlm_lkb *lkb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	mutex_lock(&debug_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	mutex_lock(&ls->ls_waiters_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	memset(debug_buf, 0, sizeof(debug_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			       lkb->lkb_id, lkb->lkb_wait_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 			       lkb->lkb_nodeid, lkb->lkb_resource->res_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		if (ret >= len - pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		pos += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	mutex_unlock(&ls->ls_waiters_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	mutex_unlock(&debug_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static const struct file_operations waiters_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	.open    = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	.read    = waiters_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	.llseek  = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) void dlm_delete_debug_file(struct dlm_ls *ls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	debugfs_remove(ls->ls_debug_rsb_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	debugfs_remove(ls->ls_debug_waiters_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	debugfs_remove(ls->ls_debug_locks_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	debugfs_remove(ls->ls_debug_all_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	debugfs_remove(ls->ls_debug_toss_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) void dlm_create_debug_file(struct dlm_ls *ls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	char name[DLM_LOCKSPACE_LEN + 8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	/* format 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 						      S_IFREG | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 						      dlm_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 						      ls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 						      &format1_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	/* format 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	memset(name, 0, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_locks", ls->ls_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	ls->ls_debug_locks_dentry = debugfs_create_file(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 							S_IFREG | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 							dlm_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 							ls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 							&format2_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	/* format 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	memset(name, 0, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_all", ls->ls_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	ls->ls_debug_all_dentry = debugfs_create_file(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 						      S_IFREG | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 						      dlm_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 						      ls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 						      &format3_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	/* format 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	memset(name, 0, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_toss", ls->ls_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 	ls->ls_debug_toss_dentry = debugfs_create_file(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 						       S_IFREG | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 						       dlm_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 						       ls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 						       &format4_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	memset(name, 0, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	ls->ls_debug_waiters_dentry = debugfs_create_file(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 							  S_IFREG | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 							  dlm_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 							  ls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 							  &waiters_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) void __init dlm_register_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	mutex_init(&debug_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	dlm_root = debugfs_create_dir("dlm", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) void dlm_unregister_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	debugfs_remove(dlm_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)