[Ocfs2-tools-devel] [PATCH 2/3] debugfs: Add option to limit fs_locks to dump only busy locks
Tao Ma
tao.ma at oracle.com
Thu May 8 23:45:14 PDT 2008
Signed-off-by: Tao Ma <tao.ma at oracle.com>
Sunil Mushran wrote:
> This patch enhances the fs_locks command in debugfs.ocfs2 to limit
> the output to only the busy locks. This is useful in debugging hangs
> in a cluster operation as it allows the user to limit the dump to
> only the locks that could be relevant to the issue.
>
> Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
> ---
> debugfs.ocfs2/commands.c | 14 ++++++++++----
> debugfs.ocfs2/dump_fs_locks.c | 28 ++++++++++++++++++++--------
> debugfs.ocfs2/include/dump_fs_locks.h | 4 ++--
> 3 files changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
> index cdab387..c06442c 100644
> --- a/debugfs.ocfs2/commands.c
> +++ b/debugfs.ocfs2/commands.c
> @@ -801,7 +801,7 @@ static void do_help (char **args)
> printf ("encode <filespec>\t\t\tShow lock name\n");
> printf ("extent <block#>\t\t\t\tShow extent block\n");
> printf ("findpath <block#>\t\t\tList one pathname of the inode/lockname\n");
> - printf ("fs_locks [-l]\t\t\t\tShow live fs locking state\n");
> + printf ("fs_locks [-l] [-B]\t\t\tShow live fs locking state\n");
> printf ("group <block#>\t\t\t\tShow chain group\n");
> printf ("hb\t\t\t\t\tShows the used heartbeat blocks\n");
> printf ("help, ?\t\t\t\t\tThis information\n");
> @@ -1469,15 +1469,21 @@ static void do_fs_locks(char **args)
> {
> FILE *out;
> int dump_lvbs = 0;
> + int only_busy = 0;
> + int i = 0;
>
> if (check_device_open())
> return;
>
> - if (args[1] && !strcmp("-l", args[1]))
> - dump_lvbs = 1;
> + while (args[++i]) {
> + if (!strcmp("-l", args[i]))
> + dump_lvbs = 1;
> + else if (!strcmp("-B", args[i]))
> + only_busy = 1;
> + }
>
> out = open_pager(gbls.interactive);
> - dump_fs_locks(gbls.fs->uuid_str, out, dump_lvbs);
> + dump_fs_locks(gbls.fs->uuid_str, out, dump_lvbs, only_busy);
> close_pager(out);
> }
>
> diff --git a/debugfs.ocfs2/dump_fs_locks.c b/debugfs.ocfs2/dump_fs_locks.c
> index 74423eb..c9f5a74 100644
> --- a/debugfs.ocfs2/dump_fs_locks.c
> +++ b/debugfs.ocfs2/dump_fs_locks.c
> @@ -5,7 +5,7 @@
> *
> * Interface with the kernel and dump current fs locking state
> *
> - * Copyright (C) 2005 Oracle. All rights reserved.
> + * Copyright (C) 2005, 2008 Oracle. All rights reserved.
> *
> * This program is free software; you can redistribute it and/or
> * modify it under the terms of the GNU General Public
> @@ -21,9 +21,8 @@
> * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> * Boston, MA 021110-1307, USA.
> *
> - * This code is a port of e2fsprogs/lib/ext2fs/dir_iterate.c
> - * Copyright (C) 1993, 1994, 1994, 1995, 1996, 1997 Theodore Ts'o.
> */
> +
> #define _XOPEN_SOURCE 600 /* Triggers XOPEN2K in features.h */
> #define _LARGEFILE64_SOURCE
>
> @@ -226,7 +225,8 @@ static void dump_meta_lvb(const char *raw_lvb, FILE *out)
> }
>
> /* 0 = eof, > 0 = success, < 0 = error */
> -static int dump_version_one(FILE *file, FILE *out, int lvbs)
> +static int dump_version_one(FILE *file, FILE *out, int lvbs, int only_busy,
> + int *skipped)
> {
> char id[OCFS2_LOCK_ID_MAX_LEN + 1];
> char lvb[DLM_LVB_LEN];
> @@ -235,6 +235,8 @@ static int dump_version_one(FILE *file, FILE *out, int lvbs)
> unsigned int action, unlock_action, ro, ex, dummy;
> const char *format;
>
> + *skipped = 1;
> +
> ret = fscanf(file, "%s\t"
> "%d\t"
> "0x%lx\t"
> @@ -276,6 +278,13 @@ static int dump_version_one(FILE *file, FILE *out, int lvbs)
> lvb[i] = (char) dummy;
> }
>
> + if (only_busy) {
> + if (!(flags & OCFS2_LOCK_BUSY)) {
> + ret = 1;
> + goto out;
> + }
> + }
> +
> fprintf(out, "Lockres: %s Mode: %s\nFlags:", id, level_str(level));
> print_flags(flags, out);
> fprintf(out, "\nRO Holders: %u EX Holders: %u\n", ro, ex);
> @@ -291,6 +300,8 @@ static int dump_version_one(FILE *file, FILE *out, int lvbs)
> }
> fprintf(out, "\n");
>
> + *skipped = 0;
> +
> ret = 1;
> out:
> return ret;
> @@ -311,10 +322,11 @@ static int end_line(FILE *f)
>
> #define CURRENT_PROTO 1
> /* returns 0 on error or end of file */
> -static int dump_one_lockres(FILE *file, FILE *out, int lvbs)
> +static int dump_one_lockres(FILE *file, FILE *out, int lvbs, int only_busy)
> {
> unsigned int version;
> int ret;
> + int skipped = 0;
>
> ret = fscanf(file, "%x\t", &version);
> if (ret != 1)
> @@ -326,7 +338,7 @@ static int dump_one_lockres(FILE *file, FILE *out, int lvbs)
> return 0;
> }
>
> - ret = dump_version_one(file, out, lvbs);
> + ret = dump_version_one(file, out, lvbs, only_busy, &skipped);
> if (ret <= 0)
> return 0;
>
> @@ -398,7 +410,7 @@ out:
> #define DEBUGFS_PATH SYSFS_BASE "debug"
> #define DEBUGFS_ALTERNATE_PATH "/debug"
>
> -void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs)
> +void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs, int only_busy)
> {
> errcode_t ret;
> int err;
> @@ -425,7 +437,7 @@ void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs)
> return;
> }
>
> - while (dump_one_lockres(file, out, dump_lvbs))
> + while (dump_one_lockres(file, out, dump_lvbs, only_busy))
> ;
>
> fclose(file);
> diff --git a/debugfs.ocfs2/include/dump_fs_locks.h b/debugfs.ocfs2/include/dump_fs_locks.h
> index 420a6d1..f218458 100644
> --- a/debugfs.ocfs2/include/dump_fs_locks.h
> +++ b/debugfs.ocfs2/include/dump_fs_locks.h
> @@ -3,7 +3,7 @@
> *
> * Function prototypes, macros, etc. for related 'C' files
> *
> - * Copyright (C) 2005 Oracle. All rights reserved.
> + * Copyright (C) 2005, 2008 Oracle. All rights reserved.
> *
> * This program is free software; you can redistribute it and/or
> * modify it under the terms of the GNU General Public
> @@ -25,6 +25,6 @@
> #ifndef _DUMP_FS_LOCKS_H_
> #define _DUMP_FS_LOCKS_H_
>
> -void dump_fs_locks(char *uuid, FILE *out, int dump_lvbs);
> +void dump_fs_locks(char *uuid, FILE *out, int dump_lvbs, int only_busy);
>
> #endif /* _DUMP_FS_LOCKS_H_ */
More information about the Ocfs2-tools-devel
mailing list