[Ocfs2-tools-devel] [PATCH] debugfs.ocfs2: Allow dumping fs locks from a file

Sunil Mushran sunil.mushran at oracle.com
Wed Nov 19 14:57:39 PST 2008


Signed-off-by: Sunil Mushran <sunil.mushran at 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/ocfs2/locking_state.
>
> Signed-off-by: Mark Fasheh <mfasheh at suse.com>
> ---
>  debugfs.ocfs2/commands.c              |   22 +++++++++++++-----
>  debugfs.ocfs2/dump_fs_locks.c         |   39 ++++++++++++++++++++------------
>  debugfs.ocfs2/include/dump_fs_locks.h |    4 +-
>  3 files changed, 42 insertions(+), 23 deletions(-)
>
> diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
> index b6aa39a..0e46151 100644
> --- a/debugfs.ocfs2/commands.c
> +++ b/debugfs.ocfs2/commands.c
> @@ -836,7 +836,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] [-B]\t\t\tShow live fs locking state\n");
> +	printf ("fs_locks [-f <file>] [-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");
> @@ -1521,14 +1521,12 @@ static void do_fs_locks(char **args)
>  	int only_busy = 0;
>  	int c, argc;
>  	struct list_head locklist;
> -
> -	if (check_device_open())
> -		return;
> +	char *path = NULL, *uuid_str = NULL;
>  
>  	for (argc = 0; (args[argc]); ++argc);
>  	optind = 0;
>  
> -	while ((c = getopt(argc, args, "lB")) != -1) {
> +	while ((c = getopt(argc, args, "lBf:")) != -1) {
>  		switch (c) {
>  		case 'l':
>  			dump_lvbs = 1;
> @@ -1536,10 +1534,21 @@ static void do_fs_locks(char **args)
>  		case 'B':
>  			only_busy = 1;
>  			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;
> +	}
>  
>  	init_stringlist(&locklist);
>  
> @@ -1550,7 +1559,8 @@ static void do_fs_locks(char **args)
>  	}
>  
>  	out = open_pager(gbls.interactive);
> -	dump_fs_locks(gbls.fs->uuid_str, out, dump_lvbs, only_busy, &locklist);
> +	dump_fs_locks(uuid_str, out, path, 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 2d5d718..1d4a56e 100644
> --- a/debugfs.ocfs2/dump_fs_locks.c
> +++ b/debugfs.ocfs2/dump_fs_locks.c
> @@ -416,28 +416,37 @@ 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,
> -		   struct list_head *locklist)
> +void dump_fs_locks(char *uuid_str, FILE *out, char *path, 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) {
> -		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, "ocfs2", uuid_str,
> -				"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_str);
> -		return;
> +		ret = open_debugfs_file(debugfs_path, "ocfs2", uuid_str,
> +					"locking_state", &file);
> +		if (ret) {
> +			fprintf(stderr, "Could not open debug state for "
> +				"\"%s\".\nPerhaps that OCFS2 file system is "
> +				"not mounted?\n", uuid_str);
> +			return;
> +		}
> +	} else {
> +		file = fopen(path, "r");
> +		if (!file) {
> +			fprintf(stderr, "Could not open file at \"%s\"\n",
> +				path);
> +			return;
> +		}
>  	}
>  
>  	show_select = !list_empty(locklist);
> diff --git a/debugfs.ocfs2/include/dump_fs_locks.h b/debugfs.ocfs2/include/dump_fs_locks.h
> index f6da59e..9445c31 100644
> --- a/debugfs.ocfs2/include/dump_fs_locks.h
> +++ b/debugfs.ocfs2/include/dump_fs_locks.h
> @@ -25,7 +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,
> -		   struct list_head *locklist);
> +void dump_fs_locks(char *uuid_str, FILE *out, char *path, int dump_lvbs,
> +		   int only_busy, struct list_head *locklist);
>  
>  #endif		/* _DUMP_FS_LOCKS_H_ */
>   




More information about the Ocfs2-tools-devel mailing list