All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Ma <tao.ma@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH] debugfs.ocfs2: Allow dumping dlm locks from a file
Date: Fri, 05 Dec 2008 14:56:28 +0800	[thread overview]
Message-ID: <4938D09C.10306@oracle.com> (raw)
In-Reply-To: <20081205061450.GJ8791@wotan.suse.de>

Signed-off-by: Tao Ma <tao.ma@oracle.com>

Mark Fasheh wrote:
> This way we can review locking state even if all a customer provides us is
> the contents of /sys/kernel/debug/o2dlm/locking_state.
> 
> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
> ---
>  debugfs.ocfs2/commands.c               |   36 ++++++++++++++++++++++-------
>  debugfs.ocfs2/dump_dlm_locks.c         |   38 ++++++++++++++++++++-----------
>  debugfs.ocfs2/include/dump_dlm_locks.h |    2 +-
>  3 files changed, 52 insertions(+), 24 deletions(-)
> 
> diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
> index 0e46151..06b6c98 100644
> --- a/debugfs.ocfs2/commands.c
> +++ b/debugfs.ocfs2/commands.c
> @@ -831,7 +831,7 @@ static void do_help (char **args)
>  	printf ("controld dump\t\t\tObtain information from ocfs2_controld\n");
>  	printf ("curdev\t\t\t\t\tShow current device\n");
>  	printf ("decode <lockname#> ...\t\t\tDecode block#(s) from the lockname(s)\n");
> -	printf ("dlm_locks [-l] lockname\t\t\tShow live dlm locking state\n");
> +	printf ("dlm_locks [-f <file>] [-l] lockname\t\t\tShow live dlm locking state\n");
>  	printf ("dump [-p] <filespec> <outfile>\t\tDumps file to outfile on a mounted fs\n");
>  	printf ("encode <filespec>\t\t\tShow lock name\n");
>  	printf ("extent <block#>\t\t\t\tShow extent block\n");
> @@ -1485,26 +1485,44 @@ static void do_dlm_locks(char **args)
>  	int dump_lvbs = 0;
>  	int i;
>  	struct list_head locklist;
> -
> -	if (check_device_open())
> -		return;
> +	char *path = NULL, *uuid_str = NULL;
> +	int c, argc;
>  
>  	init_stringlist(&locklist);
>  
> -	i = 1;
> -	if (args[i] && strlen(args[i])) {
> -		if (!strcmp("-l", args[i])) {
> +	for (argc = 0; (args[argc]); ++argc);
> +	optind = 0;
> +
> +	while ((c = getopt(argc, args, "lf:")) != -1) {
> +		switch (c) {
> +		case 'l':
>  			dump_lvbs = 1;
> -			i++;
> +			break;
> +		case 'f':
> +			path = optarg;
> +			break;
> +		default:
> +			break;
>  		}
> +	}
> +	if ((path == NULL)) {
> +		/* Only error for a missing device if we're asked to
> +		 * read from a live file system. */
> +		if (check_device_open())
> +			return;
> +
> +		uuid_str = gbls.fs->uuid_str;
> +	}
>  
> +	i = optind;
> +	if (args[i] && strlen(args[i])) {
>  		for ( ; args[i] && strlen(args[i]); ++i)
>  			if (add_to_stringlist(args[i], &locklist))
>  				break;
>  	}
>  
>  	out = open_pager(gbls.interactive);
> -	dump_dlm_locks(gbls.fs->uuid_str, out, dump_lvbs, &locklist);
> +	dump_dlm_locks(uuid_str, out, path, dump_lvbs, &locklist);
>  	close_pager(out);
>  
>  	free_stringlist(&locklist);
> diff --git a/debugfs.ocfs2/dump_dlm_locks.c b/debugfs.ocfs2/dump_dlm_locks.c
> index b946821..6344ff1 100644
> --- a/debugfs.ocfs2/dump_dlm_locks.c
> +++ b/debugfs.ocfs2/dump_dlm_locks.c
> @@ -411,7 +411,7 @@ static int get_next_dlm_lockname(FILE *file, char *name, int len)
>  	return 0;
>  }
>  
> -void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
> +void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
>  		    struct list_head *locklist)
>  {
>  	errcode_t ret;
> @@ -421,20 +421,30 @@ void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
>  	struct lockres res;
>  	int show_all_locks = 0;
>  
> -	ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
> -	if (ret) {
> -		fprintf(stderr, "Could not locate debugfs file system. "
> -			"Perhaps it is not mounted?\n");
> -		return;
> -	}
> +	if (path == NULL) {
> +		ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
> +		if (ret) {
> +			fprintf(stderr, "Could not locate debugfs file system. "
> +				"Perhaps it is not mounted?\n");
> +			return;
> +		}
>  
> -	ret = open_debugfs_file(debugfs_path, "o2dlm", uuid, "locking_state",
> -				&file);
> -	if (ret) {
> -		fprintf(stderr, "Could not open debug state for \"%s\".\n"
> -			"Perhaps that OCFS2 file system is not mounted?\n",
> -			uuid);
> -		return;
> +		ret = open_debugfs_file(debugfs_path, "o2dlm", uuid,
> +					"locking_state", &file);
> +		if (ret) {
> +			fprintf(stderr,
> +				"Could not open debug state for \"%s\".\n"
> +				"Perhaps that OCFS2 file system is not mounted?\n",
> +				uuid);
> +			return;
> +		}
> +	} else {
> +		file = fopen(path, "r");
> +		if (!file) {
> +			fprintf(stderr, "Could not open file at \"%s\"\n",
> +				path);
> +			return;
> +		}
>  	}
>  
>  	show_all_locks = list_empty(locklist);
> diff --git a/debugfs.ocfs2/include/dump_dlm_locks.h b/debugfs.ocfs2/include/dump_dlm_locks.h
> index 2cbb72a..7bc35ba 100644
> --- a/debugfs.ocfs2/include/dump_dlm_locks.h
> +++ b/debugfs.ocfs2/include/dump_dlm_locks.h
> @@ -74,7 +74,7 @@ struct lock {
>  	struct list_head list;
>  };
>  
> -void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
> +void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
>  		    struct list_head *locklist);
>  
>  #endif		/* _DUMP_DLM_LOCKS_H_ */

  reply	other threads:[~2008-12-05  6:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-05  6:14 [Ocfs2-devel] [PATCH] debugfs.ocfs2: Allow dumping dlm locks from a file Mark Fasheh
2008-12-05  6:56 ` Tao Ma [this message]
2008-12-26 22:39 ` Mark Fasheh
2008-12-26 23:04   ` Sunil Mushran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4938D09C.10306@oracle.com \
    --to=tao.ma@oracle.com \
    --cc=ocfs2-devel@oss.oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.