VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

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