[Ocfs2-tools-devel] [PATCH] debugfs.ocfs2: Use a proper enum when dumping blocks in the journal.

Sunil Mushran sunil.mushran at oracle.com
Fri Jan 9 16:55:48 PST 2009


Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>


Joel Becker wrote:
> In the 'logdump' command, we detect the type of a block before dumping
> it.  However, we pass around literal integer values - silly, no?  Let's
> put together a proper enum.  This makes expanding it easier, too.
>
> Signed-off-by: Joel Becker <joel.becker at oracle.com>
> ---
>  debugfs.ocfs2/dump.c            |   13 ++++++++-----
>  debugfs.ocfs2/include/dump.h    |   26 ++++++++++++++------------
>  debugfs.ocfs2/include/journal.h |    1 -
>  debugfs.ocfs2/journal.c         |   20 ++++++++++++--------
>  4 files changed, 34 insertions(+), 26 deletions(-)
>
> diff --git a/debugfs.ocfs2/dump.c b/debugfs.ocfs2/dump.c
> index 43ff43e..c29f580 100644
> --- a/debugfs.ocfs2/dump.c
> +++ b/debugfs.ocfs2/dump.c
> @@ -1,4 +1,6 @@
> -/*
> +/* -*- mode: c; c-basic-offset: 8; -*-
> + * vim: noexpandtab sw=8 ts=8 sts=0:
> + *
>   * dump.c
>   *
>   * dumps ocfs2 structures
> @@ -640,21 +642,22 @@ void dump_jbd_block (FILE *out, journal_superblock_t *jsb,
>   * dump_jbd_metadata()
>   *
>   */
> -void dump_jbd_metadata (FILE *out, int type, char *buf, uint64_t blknum)
> +void dump_jbd_metadata (FILE *out, enum dump_block_type type, char *buf,
> +			uint64_t blknum)
>  {
>  	fprintf (out, "\tBlock %"PRIu64": ", blknum);
>  	switch (type) {
> -	case 1:
> +	case DUMP_BLOCK_INODE:
>  		fprintf(out, "Inode\n");
>  		dump_inode (out, (struct ocfs2_dinode *)buf);
>  		fprintf (out, "\n");
>  		break;
> -	case 2:
> +	case DUMP_BLOCK_EXTENT_BLOCK:
>  		fprintf(out, "Extent\n");
>  		dump_extent_block (out, (struct ocfs2_extent_block *)buf);
>  		fprintf (out, "\n");
>  		break;
> -	case 3:
> +	case DUMP_BLOCK_GROUP_DESCRIPTOR:
>  		fprintf(out, "Group\n");
>  		dump_group_descriptor (out, (struct ocfs2_group_desc *)buf, 0);
>  		fprintf (out, "\n");
> diff --git a/debugfs.ocfs2/include/dump.h b/debugfs.ocfs2/include/dump.h
> index ecb070a..db49dfb 100644
> --- a/debugfs.ocfs2/include/dump.h
> +++ b/debugfs.ocfs2/include/dump.h
> @@ -1,31 +1,32 @@
> -/*
> +/* -*- mode: c; c-basic-offset: 8; -*-
> + * vim: noexpandtab sw=8 ts=8 sts=0:
> + *
>   * dump.h
>   *
>   * Function prototypes, macros, etc. for related 'C' files
>   *
> - * Copyright (C) 2004 Oracle.  All rights reserved.
> + * Copyright (C) 2004,2009 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
> - * License as published by the Free Software Foundation; either
> - * version 2 of the License, or (at your option) any later version.
> + * License version 2 as published by the Free Software Foundation.
>   * 
>   * This program is distributed in the hope that it will be useful,
>   * but WITHOUT ANY WARRANTY; without even the implied warranty of
>   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>   * General Public License for more details.
> - * 
> - * You should have received a copy of the GNU General Public
> - * License along with this program; if not, write to the
> - * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> - * Boston, MA 021110-1307, USA.
> - *
> - * Authors: Sunil Mushran
>   */
>  
>  #ifndef __DUMP_H__
>  #define __DUMP_H__
>  
> +enum dump_block_type {
> +	DUMP_BLOCK_UNKNOWN,
> +	DUMP_BLOCK_INODE,
> +	DUMP_BLOCK_EXTENT_BLOCK,
> +	DUMP_BLOCK_GROUP_DESCRIPTOR,
> +};
> +
>  typedef struct _list_dir_opts {
>  	ocfs2_filesys *fs;
>  	FILE *out;
> @@ -54,7 +55,8 @@ void dump_jbd_header (FILE *out, journal_header_t *header);
>  void dump_jbd_superblock (FILE *out, journal_superblock_t *jsb);
>  void dump_jbd_block (FILE *out, journal_superblock_t *jsb,
>  		     journal_header_t *header, uint64_t blknum);
> -void dump_jbd_metadata (FILE *out, int type, char *buf, uint64_t blknum);
> +void dump_jbd_metadata (FILE *out, enum dump_block_type type, char *buf,
> +			uint64_t blknum);
>  void dump_jbd_unknown (FILE *out, uint64_t start, uint64_t end);
>  void dump_slots (FILE *out, struct ocfs2_slot_map_extended *se,
>                   struct ocfs2_slot_map *sm, int num_slots);
> diff --git a/debugfs.ocfs2/include/journal.h b/debugfs.ocfs2/include/journal.h
> index 3825bbe..4c7e5e4 100644
> --- a/debugfs.ocfs2/include/journal.h
> +++ b/debugfs.ocfs2/include/journal.h
> @@ -27,6 +27,5 @@
>  #define _JOURNAL_H_
>  
>  errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out);
> -int detect_block (char *buf);
>  
>  #endif		/* _JOURNAL_H_ */
> diff --git a/debugfs.ocfs2/journal.c b/debugfs.ocfs2/journal.c
> index bcebaeb..4b447fd 100644
> --- a/debugfs.ocfs2/journal.c
> +++ b/debugfs.ocfs2/journal.c
> @@ -1,4 +1,6 @@
> -/*
> +/* -*- mode: c; c-basic-offset: 8; -*-
> + * vim: noexpandtab sw=8 ts=8 sts=0:
> + *
>   * journal.c
>   *
>   * reads the journal file
> @@ -27,12 +29,14 @@
>  
>  extern dbgfs_gbls gbls;
>  
> +static enum dump_block_type detect_block (char *buf);
> +
>  static void scan_journal(FILE *out, journal_superblock_t *jsb, char *buf,
>  			 int len, uint64_t *blocknum, uint64_t *last_unknown)
>  {
>  	char *block;
>  	char *p;
> -	int type;
> +	enum dump_block_type type;
>  	journal_header_t *header;
>  
>  	p = buf;
> @@ -48,7 +52,7 @@ static void scan_journal(FILE *out, journal_superblock_t *jsb, char *buf,
>  			dump_jbd_block(out, jsb, header, *blocknum);
>  		} else {
>  			type = detect_block(block);
> -			if (type < 0) {
> +			if (type == DUMP_BLOCK_UNKNOWN) {
>  				if (*last_unknown == 0)
>  					*last_unknown = *blocknum;
>  			} else {
> @@ -157,31 +161,31 @@ bail:
>   * detect_block()
>   *
>   */
> -int detect_block (char *buf)
> +static enum dump_block_type detect_block (char *buf)
>  {
>  	struct ocfs2_dinode *inode;
>  	struct ocfs2_extent_block *extent;
>  	struct ocfs2_group_desc *group;
> -	int ret = -1;
> +	enum dump_block_type ret = DUMP_BLOCK_UNKNOWN;
>  
>  	inode = (struct ocfs2_dinode *)buf;
>  	if (!memcmp(inode->i_signature, OCFS2_INODE_SIGNATURE,
>  		    sizeof(OCFS2_INODE_SIGNATURE))) {
> -		ret = 1;
> +		ret = DUMP_BLOCK_INODE;
>  		goto bail;
>  	}
>  
>  	extent = (struct ocfs2_extent_block *)buf;
>  	if (!memcmp(extent->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE,
>  		    sizeof(OCFS2_EXTENT_BLOCK_SIGNATURE))) {
> -		ret = 2;
> +		ret = DUMP_BLOCK_EXTENT_BLOCK;
>  		goto bail;
>  	}
>  
>  	group = (struct ocfs2_group_desc *)buf;
>  	if (!memcmp(group->bg_signature, OCFS2_GROUP_DESC_SIGNATURE,
>  		    sizeof(OCFS2_GROUP_DESC_SIGNATURE))) {
> -		ret = 3;
> +		ret = DUMP_BLOCK_GROUP_DESCRIPTOR;
>  		goto bail;
>  	}
>  
>   




More information about the Ocfs2-tools-devel mailing list