2019-05-29 00:57:20 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-01-18 17:30:29 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
**
|
2009-01-08 06:48:52 +08:00
|
|
|
** Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved.
|
2006-01-18 17:30:29 +08:00
|
|
|
**
|
|
|
|
**
|
|
|
|
*******************************************************************************
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/seq_file.h>
|
2016-09-20 04:44:50 +08:00
|
|
|
#include <linux/init.h>
|
2006-01-18 17:30:29 +08:00
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/debugfs.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
#include "dlm_internal.h"
|
2021-05-22 03:08:47 +08:00
|
|
|
#include "midcomms.h"
|
2007-05-17 03:56:13 +08:00
|
|
|
#include "lock.h"
|
2023-08-02 02:09:40 +08:00
|
|
|
#include "ast.h"
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2006-07-26 02:44:31 +08:00
|
|
|
#define DLM_DEBUG_BUF_LEN 4096
|
|
|
|
static char debug_buf[DLM_DEBUG_BUF_LEN];
|
|
|
|
static struct mutex debug_buf_lock;
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
static struct dentry *dlm_root;
|
2021-05-22 03:08:47 +08:00
|
|
|
static struct dentry *dlm_comms;
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
static char *print_lockmode(int mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case DLM_LOCK_IV:
|
|
|
|
return "--";
|
|
|
|
case DLM_LOCK_NL:
|
|
|
|
return "NL";
|
|
|
|
case DLM_LOCK_CR:
|
|
|
|
return "CR";
|
|
|
|
case DLM_LOCK_CW:
|
|
|
|
return "CW";
|
|
|
|
case DLM_LOCK_PR:
|
|
|
|
return "PR";
|
|
|
|
case DLM_LOCK_PW:
|
|
|
|
return "PW";
|
|
|
|
case DLM_LOCK_EX:
|
|
|
|
return "EX";
|
|
|
|
default:
|
|
|
|
return "??";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
|
|
|
|
struct dlm_rsb *res)
|
2006-01-18 17:30:29 +08:00
|
|
|
{
|
|
|
|
seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode));
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
if (lkb->lkb_status == DLM_LKSTS_CONVERT ||
|
|
|
|
lkb->lkb_status == DLM_LKSTS_WAITING)
|
2006-01-18 17:30:29 +08:00
|
|
|
seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
|
|
|
|
|
|
|
|
if (lkb->lkb_nodeid) {
|
|
|
|
if (lkb->lkb_nodeid != res->res_nodeid)
|
|
|
|
seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
|
|
|
|
lkb->lkb_remid);
|
|
|
|
else
|
|
|
|
seq_printf(s, " Master: %08x", lkb->lkb_remid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lkb->lkb_wait_type)
|
|
|
|
seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
|
|
|
|
|
2017-05-06 14:12:31 +08:00
|
|
|
seq_putc(s, '\n');
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format1(struct dlm_rsb *res, struct seq_file *s)
|
2006-01-18 17:30:29 +08:00
|
|
|
{
|
|
|
|
struct dlm_lkb *lkb;
|
2006-07-26 02:44:31 +08:00
|
|
|
int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list;
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2007-05-29 21:47:04 +08:00
|
|
|
lock_rsb(res);
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length);
|
2009-01-08 06:48:52 +08:00
|
|
|
|
2006-01-18 17:30:29 +08:00
|
|
|
for (i = 0; i < res->res_length; i++) {
|
|
|
|
if (isprint(res->res_name[i]))
|
|
|
|
seq_printf(s, "%c", res->res_name[i]);
|
|
|
|
else
|
|
|
|
seq_printf(s, "%c", '.');
|
|
|
|
}
|
2009-01-08 06:48:52 +08:00
|
|
|
|
2006-01-18 17:30:29 +08:00
|
|
|
if (res->res_nodeid > 0)
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
|
|
|
|
res->res_nodeid);
|
2006-01-18 17:30:29 +08:00
|
|
|
else if (res->res_nodeid == 0)
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_puts(s, "\"\nMaster Copy\n");
|
2006-01-18 17:30:29 +08:00
|
|
|
else if (res->res_nodeid == -1)
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "\"\nLooking up master (lkid %x)\n",
|
|
|
|
res->res_first_lkid);
|
2006-01-18 17:30:29 +08:00
|
|
|
else
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "\"\nInvalid master %d\n", res->res_nodeid);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2006-01-18 17:30:29 +08:00
|
|
|
|
|
|
|
/* Print the LVB: */
|
|
|
|
if (res->res_lvbptr) {
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, "LVB: ");
|
2006-01-18 17:30:29 +08:00
|
|
|
for (i = 0; i < lvblen; i++) {
|
|
|
|
if (i == lvblen / 2)
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, "\n ");
|
2006-01-18 17:30:29 +08:00
|
|
|
seq_printf(s, "%02x ",
|
|
|
|
(unsigned char) res->res_lvbptr[i]);
|
|
|
|
}
|
|
|
|
if (rsb_flag(res, RSB_VALNOTVALID))
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, " (INVALID)");
|
2017-05-06 14:12:31 +08:00
|
|
|
seq_putc(s, '\n');
|
2014-09-30 07:08:23 +08:00
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2006-07-26 02:44:31 +08:00
|
|
|
root_list = !list_empty(&res->res_root_list);
|
|
|
|
recover_list = !list_empty(&res->res_recover_list);
|
|
|
|
|
|
|
|
if (root_list || recover_list) {
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "Recovery: root %d recover %d flags %lx count %d\n",
|
|
|
|
root_list, recover_list,
|
|
|
|
res->res_flags, res->res_recover_locks_count);
|
2006-07-26 02:44:31 +08:00
|
|
|
}
|
|
|
|
|
2006-01-18 17:30:29 +08:00
|
|
|
/* Print the locks attached to this resource */
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, "Granted Queue\n");
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format1_lock(s, lkb, res);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, "Conversion Queue\n");
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format1_lock(s, lkb, res);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, "Waiting Queue\n");
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format1_lock(s, lkb, res);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2006-07-26 02:44:31 +08:00
|
|
|
if (list_empty(&res->res_lookup))
|
|
|
|
goto out;
|
|
|
|
|
2014-06-07 05:38:25 +08:00
|
|
|
seq_puts(s, "Lookup Queue\n");
|
2006-07-26 02:44:31 +08:00
|
|
|
list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) {
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "%08x %s",
|
|
|
|
lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
|
2006-07-26 02:44:31 +08:00
|
|
|
if (lkb->lkb_wait_type)
|
|
|
|
seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
|
2017-05-06 14:12:31 +08:00
|
|
|
seq_putc(s, '\n');
|
2014-09-30 07:08:23 +08:00
|
|
|
if (seq_has_overflowed(s))
|
|
|
|
goto out;
|
2006-07-26 02:44:31 +08:00
|
|
|
}
|
|
|
|
out:
|
2007-05-29 21:47:04 +08:00
|
|
|
unlock_rsb(res);
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
|
|
|
|
struct dlm_rsb *r)
|
2007-05-29 21:47:04 +08:00
|
|
|
{
|
2008-12-10 04:12:21 +08:00
|
|
|
u64 xid = 0;
|
|
|
|
u64 us;
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2023-03-07 04:48:15 +08:00
|
|
|
if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
|
2008-02-07 13:27:04 +08:00
|
|
|
if (lkb->lkb_ua)
|
|
|
|
xid = lkb->lkb_ua->xid;
|
2007-05-29 21:47:04 +08:00
|
|
|
}
|
|
|
|
|
2008-12-10 04:12:21 +08:00
|
|
|
/* microseconds since lkb was added to current queue */
|
|
|
|
us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_timestamp));
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2008-12-10 04:12:21 +08:00
|
|
|
/* id nodeid remid pid xid exflags flags sts grmode rqmode time_us
|
2007-07-06 22:47:08 +08:00
|
|
|
r_nodeid r_len r_name */
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
|
|
|
|
lkb->lkb_id,
|
|
|
|
lkb->lkb_nodeid,
|
|
|
|
lkb->lkb_remid,
|
|
|
|
lkb->lkb_ownpid,
|
|
|
|
(unsigned long long)xid,
|
|
|
|
lkb->lkb_exflags,
|
2023-03-07 04:48:16 +08:00
|
|
|
dlm_iflags_val(lkb),
|
2014-09-30 07:08:23 +08:00
|
|
|
lkb->lkb_status,
|
|
|
|
lkb->lkb_grmode,
|
|
|
|
lkb->lkb_rqmode,
|
|
|
|
(unsigned long long)us,
|
|
|
|
r->res_nodeid,
|
|
|
|
r->res_length,
|
|
|
|
r->res_name);
|
2007-05-29 21:47:04 +08:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format2(struct dlm_rsb *r, struct seq_file *s)
|
2007-05-29 21:47:04 +08:00
|
|
|
{
|
|
|
|
struct dlm_lkb *lkb;
|
|
|
|
|
|
|
|
lock_rsb(r);
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format2_lock(s, lkb, r);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format2_lock(s, lkb, r);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format2_lock(s, lkb, r);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
2008-12-17 04:53:23 +08:00
|
|
|
unlock_rsb(r);
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
|
2009-01-08 06:48:52 +08:00
|
|
|
int rsb_lookup)
|
2008-12-17 04:53:23 +08:00
|
|
|
{
|
|
|
|
u64 xid = 0;
|
|
|
|
|
2023-03-07 04:48:15 +08:00
|
|
|
if (test_bit(DLM_DFL_USER_BIT, &lkb->lkb_dflags)) {
|
2008-12-17 04:53:23 +08:00
|
|
|
if (lkb->lkb_ua)
|
|
|
|
xid = lkb->lkb_ua->xid;
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
|
|
|
|
lkb->lkb_id,
|
|
|
|
lkb->lkb_nodeid,
|
|
|
|
lkb->lkb_remid,
|
|
|
|
lkb->lkb_ownpid,
|
|
|
|
(unsigned long long)xid,
|
|
|
|
lkb->lkb_exflags,
|
2023-03-07 04:48:16 +08:00
|
|
|
dlm_iflags_val(lkb),
|
2014-09-30 07:08:23 +08:00
|
|
|
lkb->lkb_status,
|
|
|
|
lkb->lkb_grmode,
|
|
|
|
lkb->lkb_rqmode,
|
2022-10-28 04:45:21 +08:00
|
|
|
lkb->lkb_last_bast_mode,
|
2014-09-30 07:08:23 +08:00
|
|
|
rsb_lookup,
|
|
|
|
lkb->lkb_wait_type,
|
|
|
|
lkb->lkb_lvbseq,
|
|
|
|
(unsigned long long)ktime_to_ns(lkb->lkb_timestamp),
|
|
|
|
(unsigned long long)ktime_to_ns(lkb->lkb_last_bast_time));
|
2008-12-17 04:53:23 +08:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format3(struct dlm_rsb *r, struct seq_file *s)
|
2008-12-17 04:53:23 +08:00
|
|
|
{
|
|
|
|
struct dlm_lkb *lkb;
|
|
|
|
int i, lvblen = r->res_ls->ls_lvblen;
|
|
|
|
int print_name = 1;
|
|
|
|
|
|
|
|
lock_rsb(r);
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
|
|
|
|
r,
|
|
|
|
r->res_nodeid,
|
|
|
|
r->res_first_lkid,
|
|
|
|
r->res_flags,
|
|
|
|
!list_empty(&r->res_root_list),
|
|
|
|
!list_empty(&r->res_recover_list),
|
|
|
|
r->res_recover_locks_count,
|
|
|
|
r->res_length);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
for (i = 0; i < r->res_length; i++) {
|
|
|
|
if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
|
|
|
|
print_name = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:24 +08:00
|
|
|
seq_puts(s, print_name ? "str " : "hex");
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
for (i = 0; i < r->res_length; i++) {
|
|
|
|
if (print_name)
|
|
|
|
seq_printf(s, "%c", r->res_name[i]);
|
|
|
|
else
|
|
|
|
seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
|
|
|
|
}
|
2017-05-06 14:12:31 +08:00
|
|
|
seq_putc(s, '\n');
|
2014-09-30 07:08:23 +08:00
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
if (!r->res_lvbptr)
|
|
|
|
goto do_locks;
|
|
|
|
|
|
|
|
seq_printf(s, "lvb %u %d", r->res_lvbseq, lvblen);
|
|
|
|
|
|
|
|
for (i = 0; i < lvblen; i++)
|
|
|
|
seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
|
2017-05-06 14:12:31 +08:00
|
|
|
seq_putc(s, '\n');
|
2014-09-30 07:08:23 +08:00
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
do_locks:
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format3_lock(s, lkb, 0);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format3_lock(s, lkb, 0);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format3_lock(s, lkb, 0);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) {
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format3_lock(s, lkb, 1);
|
|
|
|
if (seq_has_overflowed(s))
|
2009-01-08 06:48:52 +08:00
|
|
|
goto out;
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
2009-01-08 06:48:52 +08:00
|
|
|
out:
|
|
|
|
unlock_rsb(r);
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
static void print_format4(struct dlm_rsb *r, struct seq_file *s)
|
2012-05-10 23:18:07 +08:00
|
|
|
{
|
|
|
|
int our_nodeid = dlm_our_nodeid();
|
|
|
|
int print_name = 1;
|
2014-09-30 07:08:23 +08:00
|
|
|
int i;
|
2012-05-10 23:18:07 +08:00
|
|
|
|
|
|
|
lock_rsb(r);
|
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ",
|
|
|
|
r,
|
|
|
|
r->res_nodeid,
|
|
|
|
r->res_master_nodeid,
|
|
|
|
r->res_dir_nodeid,
|
|
|
|
our_nodeid,
|
|
|
|
r->res_toss_time,
|
|
|
|
r->res_flags,
|
|
|
|
r->res_length);
|
2012-05-10 23:18:07 +08:00
|
|
|
|
|
|
|
for (i = 0; i < r->res_length; i++) {
|
|
|
|
if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
|
|
|
|
print_name = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:08:24 +08:00
|
|
|
seq_puts(s, print_name ? "str " : "hex");
|
2012-05-10 23:18:07 +08:00
|
|
|
|
|
|
|
for (i = 0; i < r->res_length; i++) {
|
|
|
|
if (print_name)
|
|
|
|
seq_printf(s, "%c", r->res_name[i]);
|
|
|
|
else
|
|
|
|
seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
|
|
|
|
}
|
2017-05-06 14:12:31 +08:00
|
|
|
seq_putc(s, '\n');
|
2012-05-10 23:18:07 +08:00
|
|
|
unlock_rsb(r);
|
|
|
|
}
|
|
|
|
|
2023-08-02 02:09:40 +08:00
|
|
|
static void print_format5_lock(struct seq_file *s, struct dlm_lkb *lkb)
|
|
|
|
{
|
|
|
|
struct dlm_callback *cb;
|
|
|
|
|
|
|
|
/* lkb_id lkb_flags mode flags sb_status sb_flags */
|
|
|
|
|
|
|
|
spin_lock(&lkb->lkb_cb_lock);
|
|
|
|
list_for_each_entry(cb, &lkb->lkb_callbacks, list) {
|
|
|
|
seq_printf(s, "%x %x %d %x %d %x\n",
|
|
|
|
lkb->lkb_id,
|
|
|
|
dlm_iflags_val(lkb),
|
|
|
|
cb->mode,
|
|
|
|
cb->flags,
|
|
|
|
cb->sb_status,
|
|
|
|
cb->sb_flags);
|
|
|
|
}
|
|
|
|
spin_unlock(&lkb->lkb_cb_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_format5(struct dlm_rsb *r, struct seq_file *s)
|
|
|
|
{
|
|
|
|
struct dlm_lkb *lkb;
|
|
|
|
|
|
|
|
lock_rsb(r);
|
|
|
|
|
|
|
|
list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
|
|
|
|
print_format5_lock(s, lkb);
|
|
|
|
if (seq_has_overflowed(s))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
|
|
|
|
print_format5_lock(s, lkb);
|
|
|
|
if (seq_has_overflowed(s))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
|
|
|
|
print_format5_lock(s, lkb);
|
|
|
|
if (seq_has_overflowed(s))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
unlock_rsb(r);
|
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
struct rsbtbl_iter {
|
|
|
|
struct dlm_rsb *rsb;
|
|
|
|
unsigned bucket;
|
|
|
|
int format;
|
|
|
|
int header;
|
|
|
|
};
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
/*
|
|
|
|
* If the buffer is full, seq_printf can be called again, but it
|
|
|
|
* does nothing. So, the these printing routines periodically check
|
|
|
|
* seq_has_overflowed to avoid wasting too much time trying to print to
|
|
|
|
* a full buffer.
|
|
|
|
*/
|
2009-01-08 06:48:52 +08:00
|
|
|
|
|
|
|
static int table_seq_show(struct seq_file *seq, void *iter_ptr)
|
2006-01-18 17:30:29 +08:00
|
|
|
{
|
2009-01-08 06:48:52 +08:00
|
|
|
struct rsbtbl_iter *ri = iter_ptr;
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2008-12-17 04:53:23 +08:00
|
|
|
switch (ri->format) {
|
|
|
|
case 1:
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format1(ri->rsb, seq);
|
2008-12-17 04:53:23 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2007-05-29 21:47:04 +08:00
|
|
|
if (ri->header) {
|
2014-09-30 07:08:24 +08:00
|
|
|
seq_puts(seq, "id nodeid remid pid xid exflags flags sts grmode rqmode time_ms r_nodeid r_len r_name\n");
|
2007-05-29 21:47:04 +08:00
|
|
|
ri->header = 0;
|
|
|
|
}
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format2(ri->rsb, seq);
|
2008-12-17 04:53:23 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (ri->header) {
|
2023-12-21 03:38:59 +08:00
|
|
|
seq_puts(seq, "rsb ptr nodeid first_lkid flags !root_list_empty !recover_list_empty recover_locks_count len\n");
|
2008-12-17 04:53:23 +08:00
|
|
|
ri->header = 0;
|
|
|
|
}
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format3(ri->rsb, seq);
|
2008-12-17 04:53:23 +08:00
|
|
|
break;
|
2012-05-10 23:18:07 +08:00
|
|
|
case 4:
|
|
|
|
if (ri->header) {
|
2023-12-21 03:38:59 +08:00
|
|
|
seq_puts(seq, "rsb ptr nodeid master_nodeid dir_nodeid our_nodeid toss_time flags len str|hex name\n");
|
2012-05-10 23:18:07 +08:00
|
|
|
ri->header = 0;
|
|
|
|
}
|
2014-09-30 07:08:23 +08:00
|
|
|
print_format4(ri->rsb, seq);
|
2012-05-10 23:18:07 +08:00
|
|
|
break;
|
2023-08-02 02:09:40 +08:00
|
|
|
case 5:
|
|
|
|
if (ri->header) {
|
|
|
|
seq_puts(seq, "lkb_id lkb_flags mode flags sb_status sb_flags\n");
|
|
|
|
ri->header = 0;
|
|
|
|
}
|
|
|
|
print_format5(ri->rsb, seq);
|
|
|
|
break;
|
2007-05-29 21:47:04 +08:00
|
|
|
}
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2014-09-30 07:08:23 +08:00
|
|
|
return 0;
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:43 +08:00
|
|
|
static const struct seq_operations format1_seq_ops;
|
|
|
|
static const struct seq_operations format2_seq_ops;
|
|
|
|
static const struct seq_operations format3_seq_ops;
|
2012-05-10 23:18:07 +08:00
|
|
|
static const struct seq_operations format4_seq_ops;
|
2023-08-02 02:09:40 +08:00
|
|
|
static const struct seq_operations format5_seq_ops;
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
static void *table_seq_start(struct seq_file *seq, loff_t *pos)
|
2006-01-18 17:30:29 +08:00
|
|
|
{
|
2012-05-10 23:18:07 +08:00
|
|
|
struct rb_root *tree;
|
2011-10-27 04:24:55 +08:00
|
|
|
struct rb_node *node;
|
2009-01-08 06:48:52 +08:00
|
|
|
struct dlm_ls *ls = seq->private;
|
|
|
|
struct rsbtbl_iter *ri;
|
|
|
|
struct dlm_rsb *r;
|
|
|
|
loff_t n = *pos;
|
|
|
|
unsigned bucket, entry;
|
2012-05-10 23:18:07 +08:00
|
|
|
int toss = (seq->op == &format4_seq_ops);
|
2006-01-18 17:30:29 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
bucket = n >> 32;
|
|
|
|
entry = n & ((1LL << 32) - 1);
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
if (bucket >= ls->ls_rsbtbl_size)
|
|
|
|
return NULL;
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2017-05-06 14:34:27 +08:00
|
|
|
ri = kzalloc(sizeof(*ri), GFP_NOFS);
|
2007-05-29 21:47:04 +08:00
|
|
|
if (!ri)
|
|
|
|
return NULL;
|
2009-01-08 06:48:52 +08:00
|
|
|
if (n == 0)
|
2007-05-29 21:47:04 +08:00
|
|
|
ri->header = 1;
|
2009-01-08 06:48:52 +08:00
|
|
|
if (seq->op == &format1_seq_ops)
|
|
|
|
ri->format = 1;
|
|
|
|
if (seq->op == &format2_seq_ops)
|
|
|
|
ri->format = 2;
|
|
|
|
if (seq->op == &format3_seq_ops)
|
|
|
|
ri->format = 3;
|
2012-05-10 23:18:07 +08:00
|
|
|
if (seq->op == &format4_seq_ops)
|
|
|
|
ri->format = 4;
|
2023-08-02 02:09:40 +08:00
|
|
|
if (seq->op == &format5_seq_ops)
|
|
|
|
ri->format = 5;
|
2012-05-10 23:18:07 +08:00
|
|
|
|
|
|
|
tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
|
2009-01-08 06:48:52 +08:00
|
|
|
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_lock(&ls->ls_rsbtbl[bucket].lock);
|
2012-05-10 23:18:07 +08:00
|
|
|
if (!RB_EMPTY_ROOT(tree)) {
|
|
|
|
for (node = rb_first(tree); node; node = rb_next(node)) {
|
2011-10-27 04:24:55 +08:00
|
|
|
r = rb_entry(node, struct dlm_rsb, res_hashnode);
|
2009-01-08 06:48:52 +08:00
|
|
|
if (!entry--) {
|
|
|
|
dlm_hold_rsb(r);
|
|
|
|
ri->rsb = r;
|
|
|
|
ri->bucket = bucket;
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
return ri;
|
|
|
|
}
|
|
|
|
}
|
2007-05-29 21:47:04 +08:00
|
|
|
}
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
/*
|
|
|
|
* move to the first rsb in the next non-empty bucket
|
|
|
|
*/
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
/* zero the entry */
|
|
|
|
n &= ~((1LL << 32) - 1);
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
while (1) {
|
|
|
|
bucket++;
|
|
|
|
n += 1LL << 32;
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
if (bucket >= ls->ls_rsbtbl_size) {
|
|
|
|
kfree(ri);
|
2007-05-29 21:47:04 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-10 23:18:07 +08:00
|
|
|
tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
|
2007-05-29 21:47:04 +08:00
|
|
|
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_lock(&ls->ls_rsbtbl[bucket].lock);
|
2012-05-10 23:18:07 +08:00
|
|
|
if (!RB_EMPTY_ROOT(tree)) {
|
|
|
|
node = rb_first(tree);
|
2011-10-27 04:24:55 +08:00
|
|
|
r = rb_entry(node, struct dlm_rsb, res_hashnode);
|
2009-01-08 06:48:52 +08:00
|
|
|
dlm_hold_rsb(r);
|
|
|
|
ri->rsb = r;
|
|
|
|
ri->bucket = bucket;
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
*pos = n;
|
|
|
|
return ri;
|
|
|
|
}
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
}
|
2007-05-29 21:47:04 +08:00
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)
|
2007-05-29 21:47:04 +08:00
|
|
|
{
|
2009-01-08 06:48:52 +08:00
|
|
|
struct dlm_ls *ls = seq->private;
|
|
|
|
struct rsbtbl_iter *ri = iter_ptr;
|
2012-05-10 23:18:07 +08:00
|
|
|
struct rb_root *tree;
|
2011-10-27 04:24:55 +08:00
|
|
|
struct rb_node *next;
|
2009-01-08 06:48:52 +08:00
|
|
|
struct dlm_rsb *r, *rp;
|
|
|
|
loff_t n = *pos;
|
|
|
|
unsigned bucket;
|
2012-05-10 23:18:07 +08:00
|
|
|
int toss = (seq->op == &format4_seq_ops);
|
2009-01-08 06:48:52 +08:00
|
|
|
|
|
|
|
bucket = n >> 32;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* move to the next rsb in the same bucket
|
|
|
|
*/
|
|
|
|
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_lock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
rp = ri->rsb;
|
2011-10-27 04:24:55 +08:00
|
|
|
next = rb_next(&rp->res_hashnode);
|
2009-01-08 06:48:52 +08:00
|
|
|
|
2011-10-27 04:24:55 +08:00
|
|
|
if (next) {
|
|
|
|
r = rb_entry(next, struct dlm_rsb, res_hashnode);
|
2009-01-08 06:48:52 +08:00
|
|
|
dlm_hold_rsb(r);
|
|
|
|
ri->rsb = r;
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
dlm_put_rsb(rp);
|
|
|
|
++*pos;
|
|
|
|
return ri;
|
|
|
|
}
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
dlm_put_rsb(rp);
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
/*
|
|
|
|
* move to the first rsb in the next non-empty bucket
|
|
|
|
*/
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
/* zero the entry */
|
|
|
|
n &= ~((1LL << 32) - 1);
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
while (1) {
|
|
|
|
bucket++;
|
|
|
|
n += 1LL << 32;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
if (bucket >= ls->ls_rsbtbl_size) {
|
|
|
|
kfree(ri);
|
2021-03-02 06:05:08 +08:00
|
|
|
++*pos;
|
2009-01-08 06:48:52 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-10 23:18:07 +08:00
|
|
|
tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_lock(&ls->ls_rsbtbl[bucket].lock);
|
2012-05-10 23:18:07 +08:00
|
|
|
if (!RB_EMPTY_ROOT(tree)) {
|
|
|
|
next = rb_first(tree);
|
2011-10-27 04:24:55 +08:00
|
|
|
r = rb_entry(next, struct dlm_rsb, res_hashnode);
|
2009-01-08 06:48:52 +08:00
|
|
|
dlm_hold_rsb(r);
|
|
|
|
ri->rsb = r;
|
|
|
|
ri->bucket = bucket;
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2009-01-08 06:48:52 +08:00
|
|
|
*pos = n;
|
|
|
|
return ri;
|
|
|
|
}
|
2009-01-08 06:50:41 +08:00
|
|
|
spin_unlock(&ls->ls_rsbtbl[bucket].lock);
|
2008-12-17 04:53:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
static void table_seq_stop(struct seq_file *seq, void *iter_ptr)
|
2008-12-17 04:53:23 +08:00
|
|
|
{
|
2009-01-08 06:48:52 +08:00
|
|
|
struct rsbtbl_iter *ri = iter_ptr;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
if (ri) {
|
|
|
|
dlm_put_rsb(ri->rsb);
|
|
|
|
kfree(ri);
|
2008-12-17 04:53:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:43 +08:00
|
|
|
static const struct seq_operations format1_seq_ops = {
|
2009-01-08 06:48:52 +08:00
|
|
|
.start = table_seq_start,
|
|
|
|
.next = table_seq_next,
|
|
|
|
.stop = table_seq_stop,
|
|
|
|
.show = table_seq_show,
|
2008-12-17 04:53:23 +08:00
|
|
|
};
|
|
|
|
|
2009-09-23 07:43:43 +08:00
|
|
|
static const struct seq_operations format2_seq_ops = {
|
2009-01-08 06:48:52 +08:00
|
|
|
.start = table_seq_start,
|
|
|
|
.next = table_seq_next,
|
|
|
|
.stop = table_seq_stop,
|
|
|
|
.show = table_seq_show,
|
|
|
|
};
|
|
|
|
|
2009-09-23 07:43:43 +08:00
|
|
|
static const struct seq_operations format3_seq_ops = {
|
2009-01-08 06:48:52 +08:00
|
|
|
.start = table_seq_start,
|
|
|
|
.next = table_seq_next,
|
|
|
|
.stop = table_seq_stop,
|
|
|
|
.show = table_seq_show,
|
|
|
|
};
|
|
|
|
|
2012-05-10 23:18:07 +08:00
|
|
|
static const struct seq_operations format4_seq_ops = {
|
|
|
|
.start = table_seq_start,
|
|
|
|
.next = table_seq_next,
|
|
|
|
.stop = table_seq_stop,
|
|
|
|
.show = table_seq_show,
|
|
|
|
};
|
|
|
|
|
2023-08-02 02:09:40 +08:00
|
|
|
static const struct seq_operations format5_seq_ops = {
|
|
|
|
.start = table_seq_start,
|
|
|
|
.next = table_seq_next,
|
|
|
|
.stop = table_seq_stop,
|
|
|
|
.show = table_seq_show,
|
|
|
|
};
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
static const struct file_operations format1_fops;
|
|
|
|
static const struct file_operations format2_fops;
|
|
|
|
static const struct file_operations format3_fops;
|
2012-05-10 23:18:07 +08:00
|
|
|
static const struct file_operations format4_fops;
|
2023-08-02 02:09:40 +08:00
|
|
|
static const struct file_operations format5_fops;
|
2009-01-08 06:48:52 +08:00
|
|
|
|
2016-08-25 17:20:59 +08:00
|
|
|
static int table_open1(struct inode *inode, struct file *file)
|
2008-12-17 04:53:23 +08:00
|
|
|
{
|
|
|
|
struct seq_file *seq;
|
2016-08-25 17:20:59 +08:00
|
|
|
int ret;
|
2009-01-08 06:48:52 +08:00
|
|
|
|
2016-08-25 17:20:59 +08:00
|
|
|
ret = seq_open(file, &format1_seq_ops);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
seq = file->private_data;
|
|
|
|
seq->private = inode->i_private; /* the dlm_ls */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int table_open2(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct seq_file *seq;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = seq_open(file, &format2_seq_ops);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
seq = file->private_data;
|
|
|
|
seq->private = inode->i_private; /* the dlm_ls */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-03 03:17:22 +08:00
|
|
|
static ssize_t table_write2(struct file *file, const char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct seq_file *seq = file->private_data;
|
|
|
|
int n, len, lkb_nodeid, lkb_status, error;
|
2021-11-12 23:08:01 +08:00
|
|
|
char name[DLM_RESNAME_MAXLEN + 1] = {};
|
2021-11-03 03:17:22 +08:00
|
|
|
struct dlm_ls *ls = seq->private;
|
|
|
|
unsigned int lkb_flags;
|
|
|
|
char buf[256] = {};
|
|
|
|
uint32_t lkb_id;
|
|
|
|
|
|
|
|
if (copy_from_user(buf, user_buf,
|
|
|
|
min_t(size_t, sizeof(buf) - 1, count)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
n = sscanf(buf, "%x %" __stringify(DLM_RESNAME_MAXLEN) "s %x %d %d",
|
|
|
|
&lkb_id, name, &lkb_flags, &lkb_nodeid, &lkb_status);
|
|
|
|
if (n != 5)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
len = strnlen(name, DLM_RESNAME_MAXLEN);
|
|
|
|
error = dlm_debug_add_lkb(ls, lkb_id, name, len, lkb_flags,
|
|
|
|
lkb_nodeid, lkb_status);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-08-25 17:20:59 +08:00
|
|
|
static int table_open3(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct seq_file *seq;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = seq_open(file, &format3_seq_ops);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
seq = file->private_data;
|
|
|
|
seq->private = inode->i_private; /* the dlm_ls */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int table_open4(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct seq_file *seq;
|
|
|
|
int ret;
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2023-12-21 03:38:58 +08:00
|
|
|
ret = seq_open(file, &format4_seq_ops);
|
2023-08-02 02:09:40 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
seq = file->private_data;
|
|
|
|
seq->private = inode->i_private; /* the dlm_ls */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int table_open5(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct seq_file *seq;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = seq_open(file, &format5_seq_ops);
|
2008-12-17 04:53:23 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
seq = file->private_data;
|
2009-01-08 06:48:52 +08:00
|
|
|
seq->private = inode->i_private; /* the dlm_ls */
|
2008-12-17 04:53:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-08 06:48:52 +08:00
|
|
|
static const struct file_operations format1_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
2016-08-25 17:20:59 +08:00
|
|
|
.open = table_open1,
|
2009-01-08 06:48:52 +08:00
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = seq_release
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations format2_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
2016-08-25 17:20:59 +08:00
|
|
|
.open = table_open2,
|
2009-01-08 06:48:52 +08:00
|
|
|
.read = seq_read,
|
2021-11-03 03:17:22 +08:00
|
|
|
.write = table_write2,
|
2009-01-08 06:48:52 +08:00
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = seq_release
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations format3_fops = {
|
2008-12-17 04:53:23 +08:00
|
|
|
.owner = THIS_MODULE,
|
2016-08-25 17:20:59 +08:00
|
|
|
.open = table_open3,
|
2008-12-17 04:53:23 +08:00
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = seq_release
|
|
|
|
};
|
|
|
|
|
2012-05-10 23:18:07 +08:00
|
|
|
static const struct file_operations format4_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
2016-08-25 17:20:59 +08:00
|
|
|
.open = table_open4,
|
2012-05-10 23:18:07 +08:00
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = seq_release
|
|
|
|
};
|
|
|
|
|
2023-08-02 02:09:40 +08:00
|
|
|
static const struct file_operations format5_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = table_open5,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = seq_release
|
|
|
|
};
|
|
|
|
|
2006-07-26 02:44:31 +08:00
|
|
|
/*
|
|
|
|
* dump lkb's on the ls_waiters list
|
|
|
|
*/
|
|
|
|
static ssize_t waiters_read(struct file *file, char __user *userbuf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls = file->private_data;
|
|
|
|
struct dlm_lkb *lkb;
|
2006-08-09 00:31:30 +08:00
|
|
|
size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
|
2006-07-26 02:44:31 +08:00
|
|
|
|
|
|
|
mutex_lock(&debug_buf_lock);
|
|
|
|
mutex_lock(&ls->ls_waiters_mutex);
|
|
|
|
memset(debug_buf, 0, sizeof(debug_buf));
|
|
|
|
|
|
|
|
list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
|
2006-08-09 00:31:30 +08:00
|
|
|
ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
|
|
|
|
lkb->lkb_id, lkb->lkb_wait_type,
|
|
|
|
lkb->lkb_nodeid, lkb->lkb_resource->res_name);
|
|
|
|
if (ret >= len - pos)
|
|
|
|
break;
|
|
|
|
pos += ret;
|
2006-07-26 02:44:31 +08:00
|
|
|
}
|
|
|
|
mutex_unlock(&ls->ls_waiters_mutex);
|
|
|
|
|
|
|
|
rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos);
|
|
|
|
mutex_unlock(&debug_buf_lock);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2021-11-03 03:17:23 +08:00
|
|
|
static ssize_t waiters_write(struct file *file, const char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dlm_ls *ls = file->private_data;
|
|
|
|
int mstype, to_nodeid;
|
|
|
|
char buf[128] = {};
|
|
|
|
uint32_t lkb_id;
|
|
|
|
int n, error;
|
|
|
|
|
|
|
|
if (copy_from_user(buf, user_buf,
|
|
|
|
min_t(size_t, sizeof(buf) - 1, count)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
n = sscanf(buf, "%x %d %d", &lkb_id, &mstype, &to_nodeid);
|
|
|
|
if (n != 3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
error = dlm_debug_add_lkb_to_waiters(ls, lkb_id, mstype, to_nodeid);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
static const struct file_operations waiters_fops = {
|
2006-07-26 02:44:31 +08:00
|
|
|
.owner = THIS_MODULE,
|
2012-04-06 05:25:11 +08:00
|
|
|
.open = simple_open,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.read = waiters_read,
|
2021-11-03 03:17:23 +08:00
|
|
|
.write = waiters_write,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = default_llseek,
|
2006-07-26 02:44:31 +08:00
|
|
|
};
|
|
|
|
|
2008-12-17 04:53:23 +08:00
|
|
|
void dlm_delete_debug_file(struct dlm_ls *ls)
|
|
|
|
{
|
2014-08-09 05:23:37 +08:00
|
|
|
debugfs_remove(ls->ls_debug_rsb_dentry);
|
|
|
|
debugfs_remove(ls->ls_debug_waiters_dentry);
|
|
|
|
debugfs_remove(ls->ls_debug_locks_dentry);
|
|
|
|
debugfs_remove(ls->ls_debug_all_dentry);
|
|
|
|
debugfs_remove(ls->ls_debug_toss_dentry);
|
2023-08-02 02:09:40 +08:00
|
|
|
debugfs_remove(ls->ls_debug_queued_asts_dentry);
|
2008-12-17 04:53:23 +08:00
|
|
|
}
|
|
|
|
|
2021-05-22 03:08:47 +08:00
|
|
|
static int dlm_state_show(struct seq_file *file, void *offset)
|
|
|
|
{
|
|
|
|
seq_printf(file, "%s\n", dlm_midcomms_state(file->private));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DEFINE_SHOW_ATTRIBUTE(dlm_state);
|
|
|
|
|
|
|
|
static int dlm_flags_show(struct seq_file *file, void *offset)
|
|
|
|
{
|
|
|
|
seq_printf(file, "%lu\n", dlm_midcomms_flags(file->private));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DEFINE_SHOW_ATTRIBUTE(dlm_flags);
|
|
|
|
|
|
|
|
static int dlm_send_queue_cnt_show(struct seq_file *file, void *offset)
|
|
|
|
{
|
|
|
|
seq_printf(file, "%d\n", dlm_midcomms_send_queue_cnt(file->private));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DEFINE_SHOW_ATTRIBUTE(dlm_send_queue_cnt);
|
|
|
|
|
|
|
|
static int dlm_version_show(struct seq_file *file, void *offset)
|
|
|
|
{
|
|
|
|
seq_printf(file, "0x%08x\n", dlm_midcomms_version(file->private));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DEFINE_SHOW_ATTRIBUTE(dlm_version);
|
|
|
|
|
2021-11-03 03:17:20 +08:00
|
|
|
static ssize_t dlm_rawmsg_write(struct file *fp, const char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (count > PAGE_SIZE || count < sizeof(struct dlm_header))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
buf = kmalloc(PAGE_SIZE, GFP_NOFS);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (copy_from_user(buf, user_buf, count)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dlm_midcomms_rawmsg_send(fp->private_data, buf, count);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
return count;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations dlm_rawmsg_fops = {
|
|
|
|
.open = simple_open,
|
|
|
|
.write = dlm_rawmsg_write,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
};
|
|
|
|
|
2021-05-22 03:08:47 +08:00
|
|
|
void *dlm_create_debug_comms_file(int nodeid, void *data)
|
|
|
|
{
|
|
|
|
struct dentry *d_node;
|
|
|
|
char name[256];
|
|
|
|
|
|
|
|
memset(name, 0, sizeof(name));
|
|
|
|
snprintf(name, 256, "%d", nodeid);
|
|
|
|
|
|
|
|
d_node = debugfs_create_dir(name, dlm_comms);
|
|
|
|
debugfs_create_file("state", 0444, d_node, data, &dlm_state_fops);
|
|
|
|
debugfs_create_file("flags", 0444, d_node, data, &dlm_flags_fops);
|
|
|
|
debugfs_create_file("send_queue_count", 0444, d_node, data,
|
|
|
|
&dlm_send_queue_cnt_fops);
|
|
|
|
debugfs_create_file("version", 0444, d_node, data, &dlm_version_fops);
|
2021-11-03 03:17:20 +08:00
|
|
|
debugfs_create_file("rawmsg", 0200, d_node, data, &dlm_rawmsg_fops);
|
2021-05-22 03:08:47 +08:00
|
|
|
|
|
|
|
return d_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_delete_debug_comms_file(void *ctx)
|
|
|
|
{
|
|
|
|
debugfs_remove(ctx);
|
|
|
|
}
|
|
|
|
|
2019-06-12 23:25:36 +08:00
|
|
|
void dlm_create_debug_file(struct dlm_ls *ls)
|
2006-01-18 17:30:29 +08:00
|
|
|
{
|
fs: dlm: Fix the size of a buffer in dlm_create_debug_file()
8 is not the maximum size of the suffix used when creating debugfs files.
Let the compiler compute the correct size, and only give a hint about the
longest possible string that is used.
When building with W=1, this fixes the following warnings:
fs/dlm/debug_fs.c: In function ‘dlm_create_debug_file’:
fs/dlm/debug_fs.c:1020:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
1020 | snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
| ^
fs/dlm/debug_fs.c:1020:9: note: ‘snprintf’ output between 9 and 73 bytes into a destination of size 72
1020 | snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/dlm/debug_fs.c:1031:50: error: ‘_queued_asts’ directive output may be truncated writing 12 bytes into a region of size between 8 and 72 [-Werror=format-truncation=]
1031 | snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_queued_asts", ls->ls_name);
| ^~~~~~~~~~~~
fs/dlm/debug_fs.c:1031:9: note: ‘snprintf’ output between 13 and 77 bytes into a destination of size 72
1031 | snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_queued_asts", ls->ls_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixes: 541adb0d4d10b ("fs: dlm: debugfs for queued callbacks")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
2023-10-11 06:04:42 +08:00
|
|
|
/* Reserve enough space for the longest file name */
|
|
|
|
char name[DLM_LOCKSPACE_LEN + sizeof("_queued_asts")];
|
2006-07-26 02:44:31 +08:00
|
|
|
|
2008-12-17 04:53:23 +08:00
|
|
|
/* format 1 */
|
|
|
|
|
2006-07-26 02:44:31 +08:00
|
|
|
ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
|
|
|
|
S_IFREG | S_IRUGO,
|
|
|
|
dlm_root,
|
|
|
|
ls,
|
2009-01-08 06:48:52 +08:00
|
|
|
&format1_fops);
|
2006-07-26 02:44:31 +08:00
|
|
|
|
2008-12-17 04:53:23 +08:00
|
|
|
/* format 2 */
|
2006-07-26 02:44:31 +08:00
|
|
|
|
2023-10-11 06:04:41 +08:00
|
|
|
snprintf(name, sizeof(name), "%s_locks", ls->ls_name);
|
2007-07-06 22:47:08 +08:00
|
|
|
|
|
|
|
ls->ls_debug_locks_dentry = debugfs_create_file(name,
|
2021-11-03 03:17:22 +08:00
|
|
|
0644,
|
2007-07-06 22:47:08 +08:00
|
|
|
dlm_root,
|
|
|
|
ls,
|
2009-01-08 06:48:52 +08:00
|
|
|
&format2_fops);
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
/* format 3 */
|
|
|
|
|
2023-10-11 06:04:41 +08:00
|
|
|
snprintf(name, sizeof(name), "%s_all", ls->ls_name);
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
ls->ls_debug_all_dentry = debugfs_create_file(name,
|
|
|
|
S_IFREG | S_IRUGO,
|
|
|
|
dlm_root,
|
|
|
|
ls,
|
2009-01-08 06:48:52 +08:00
|
|
|
&format3_fops);
|
2008-12-17 04:53:23 +08:00
|
|
|
|
2012-05-10 23:18:07 +08:00
|
|
|
/* format 4 */
|
|
|
|
|
2023-10-11 06:04:41 +08:00
|
|
|
snprintf(name, sizeof(name), "%s_toss", ls->ls_name);
|
2012-05-10 23:18:07 +08:00
|
|
|
|
|
|
|
ls->ls_debug_toss_dentry = debugfs_create_file(name,
|
|
|
|
S_IFREG | S_IRUGO,
|
|
|
|
dlm_root,
|
|
|
|
ls,
|
|
|
|
&format4_fops);
|
|
|
|
|
2023-10-11 06:04:41 +08:00
|
|
|
snprintf(name, sizeof(name), "%s_waiters", ls->ls_name);
|
2008-12-17 04:53:23 +08:00
|
|
|
|
|
|
|
ls->ls_debug_waiters_dentry = debugfs_create_file(name,
|
2021-11-03 03:17:23 +08:00
|
|
|
0644,
|
2008-12-17 04:53:23 +08:00
|
|
|
dlm_root,
|
|
|
|
ls,
|
|
|
|
&waiters_fops);
|
2023-08-02 02:09:40 +08:00
|
|
|
|
|
|
|
/* format 5 */
|
|
|
|
|
2023-10-11 06:04:41 +08:00
|
|
|
snprintf(name, sizeof(name), "%s_queued_asts", ls->ls_name);
|
2023-08-02 02:09:40 +08:00
|
|
|
|
|
|
|
ls->ls_debug_queued_asts_dentry = debugfs_create_file(name,
|
|
|
|
0644,
|
|
|
|
dlm_root,
|
|
|
|
ls,
|
|
|
|
&format5_fops);
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 23:25:36 +08:00
|
|
|
void __init dlm_register_debugfs(void)
|
2006-01-18 17:30:29 +08:00
|
|
|
{
|
2006-07-26 02:44:31 +08:00
|
|
|
mutex_init(&debug_buf_lock);
|
2006-01-18 17:30:29 +08:00
|
|
|
dlm_root = debugfs_create_dir("dlm", NULL);
|
2021-05-22 03:08:47 +08:00
|
|
|
dlm_comms = debugfs_create_dir("comms", dlm_root);
|
2006-01-18 17:30:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_unregister_debugfs(void)
|
|
|
|
{
|
|
|
|
debugfs_remove(dlm_root);
|
|
|
|
}
|
|
|
|
|