[Ocfs2-tools-devel] [PATCH 4/5] debugfs: Allows users to print selected fs_locks
Sunil Mushran
sunil.mushran at oracle.com
Wed Oct 8 16:05:46 PDT 2008
dlm_locks allows printing specific locknames. This patch adds the same
functionality to fs_locks.
Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
debugfs.ocfs2/commands.c | 30 +++++++++++++++++++++++++-----
debugfs.ocfs2/dump_fs_locks.c | 26 ++++++++++++++++++++------
debugfs.ocfs2/include/dump_fs_locks.h | 3 ++-
3 files changed, 47 insertions(+), 12 deletions(-)
diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index 4717e4f..b6aa39a 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -1519,21 +1519,41 @@ static void do_fs_locks(char **args)
FILE *out;
int dump_lvbs = 0;
int only_busy = 0;
- int i = 0;
+ int c, argc;
+ struct list_head locklist;
if (check_device_open())
return;
- while (args[++i]) {
- if (!strcmp("-l", args[i]))
+ for (argc = 0; (args[argc]); ++argc);
+ optind = 0;
+
+ while ((c = getopt(argc, args, "lB")) != -1) {
+ switch (c) {
+ case 'l':
dump_lvbs = 1;
- else if (!strcmp("-B", args[i]))
+ break;
+ case 'B':
only_busy = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ init_stringlist(&locklist);
+
+ if (optind < argc) {
+ for ( ; args[optind] && strlen(args[optind]); ++optind)
+ if (add_to_stringlist(args[optind], &locklist))
+ break;
}
out = open_pager(gbls.interactive);
- dump_fs_locks(gbls.fs->uuid_str, out, dump_lvbs, only_busy);
+ dump_fs_locks(gbls.fs->uuid_str, out, dump_lvbs, only_busy, &locklist);
close_pager(out);
+
+ free_stringlist(&locklist);
}
/*
diff --git a/debugfs.ocfs2/dump_fs_locks.c b/debugfs.ocfs2/dump_fs_locks.c
index 1d668dc..2d5d718 100644
--- a/debugfs.ocfs2/dump_fs_locks.c
+++ b/debugfs.ocfs2/dump_fs_locks.c
@@ -275,7 +275,7 @@ out:
/* 0 = eof, > 0 = success, < 0 = error */
static int dump_version_one(FILE *file, FILE *out, int lvbs, int only_busy,
- int *skipped)
+ struct list_head *locklist, int *skipped)
{
char id[OCFS2_LOCK_ID_MAX_LEN + 1];
char lvb[DLM_LVB_LEN];
@@ -327,6 +327,13 @@ static int dump_version_one(FILE *file, FILE *out, int lvbs, int only_busy,
lvb[i] = (char) dummy;
}
+ if (!list_empty(locklist)) {
+ if (!del_from_stringlist(id, locklist)) {
+ ret = 1;
+ goto out;
+ }
+ }
+
if (only_busy) {
if (!(flags & OCFS2_LOCK_BUSY)) {
ret = 1;
@@ -370,7 +377,8 @@ static int end_line(FILE *f)
#define CURRENT_PROTO 2
/* returns 0 on error or end of file */
-static int dump_one_lockres(FILE *file, FILE *out, int lvbs, int only_busy)
+static int dump_one_lockres(FILE *file, FILE *out, int lvbs, int only_busy,
+ struct list_head *locklist)
{
unsigned int version;
int ret;
@@ -386,7 +394,7 @@ static int dump_one_lockres(FILE *file, FILE *out, int lvbs, int only_busy)
return 0;
}
- ret = dump_version_one(file, out, lvbs, only_busy, &skipped);
+ ret = dump_version_one(file, out, lvbs, only_busy, locklist, &skipped);
if (ret <= 0)
return 0;
@@ -408,11 +416,13 @@ static int dump_one_lockres(FILE *file, FILE *out, int lvbs, int only_busy)
return ret;
}
-void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs, int only_busy)
+void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs, int only_busy,
+ struct list_head *locklist)
{
errcode_t ret;
char debugfs_path[PATH_MAX];
FILE *file;
+ int show_select;
ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
if (ret) {
@@ -430,8 +440,12 @@ void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs, int only_busy)
return;
}
- while (dump_one_lockres(file, out, dump_lvbs, only_busy))
- ;
+ show_select = !list_empty(locklist);
+
+ while (dump_one_lockres(file, out, dump_lvbs, only_busy, locklist)) {
+ if (show_select && list_empty(locklist))
+ break;
+ }
fclose(file);
}
diff --git a/debugfs.ocfs2/include/dump_fs_locks.h b/debugfs.ocfs2/include/dump_fs_locks.h
index f218458..f6da59e 100644
--- a/debugfs.ocfs2/include/dump_fs_locks.h
+++ b/debugfs.ocfs2/include/dump_fs_locks.h
@@ -25,6 +25,7 @@
#ifndef _DUMP_FS_LOCKS_H_
#define _DUMP_FS_LOCKS_H_
-void dump_fs_locks(char *uuid, FILE *out, int dump_lvbs, int only_busy);
+void dump_fs_locks(char *uuid, FILE *out, int dump_lvbs, int only_busy,
+ struct list_head *locklist);
#endif /* _DUMP_FS_LOCKS_H_ */
--
1.5.4.3
More information about the Ocfs2-tools-devel
mailing list