Linux Audio

Check our new training course

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