From mboxrd@z Thu Jan 1 00:00:00 1970 From: rpeterso@sourceware.org Date: 13 Nov 2007 17:22:07 -0000 Subject: [Cluster-devel] cluster/gfs2/edit gfs2hex.c hexedit.c hexedit.h Message-ID: <20071113172207.19228.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: rpeterso at sourceware.org 2007-11-13 17:22:06 Modified files: gfs2/edit : gfs2hex.c hexedit.c hexedit.h Log message: Fixed printing of gfs1 journals. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/edit/gfs2hex.c.diff?cvsroot=cluster&r1=1.12&r2=1.13 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/edit/hexedit.c.diff?cvsroot=cluster&r1=1.24&r2=1.25 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/edit/hexedit.h.diff?cvsroot=cluster&r1=1.13&r2=1.14 --- cluster/gfs2/edit/gfs2hex.c 2007/07/30 15:31:23 1.12 +++ cluster/gfs2/edit/gfs2hex.c 2007/11/13 17:22:06 1.13 @@ -463,6 +463,7 @@ struct gfs2_meta_header mh; struct gfs2_rgrp rg; struct gfs2_leaf lf; + struct gfs_log_header lh1; struct gfs2_log_header lh; struct gfs2_log_descriptor ld; @@ -525,8 +526,13 @@ case GFS2_METATYPE_LH: print_gfs2("Log Header:"); eol(0); - gfs2_log_header_in(&lh, buf); - gfs2_log_header_print(&lh); + if (gfs1) { + gfs_log_header_in(&lh1, buf); + gfs_log_header_print(&lh1); + } else { + gfs2_log_header_in(&lh, buf); + gfs2_log_header_print(&lh); + } break; case GFS2_METATYPE_LD: --- cluster/gfs2/edit/hexedit.c 2007/11/08 18:10:09 1.24 +++ cluster/gfs2/edit/hexedit.c 2007/11/13 17:22:06 1.25 @@ -1247,6 +1247,8 @@ parse_rindex(tmp_inode, TRUE); brelse(tmp_bh, not_updated); } + else if (display_indirect(indirect, indirect_blocks, 0, 0) == 0) + return -1; else if (block_is_rglist()) { tmp_bh = bread(&sbd, masterblock("rindex")); tmp_inode = inode_get(&sbd, tmp_bh); @@ -1277,8 +1279,6 @@ print_quota(tmp_inode); brelse(tmp_bh, not_updated); } - else if (display_indirect(indirect, indirect_blocks, 0, 0) == 0) - return -1; return 0; } @@ -1977,6 +1977,42 @@ }/* interactive_mode */ /* ------------------------------------------------------------------------ */ +/* gfs_log_header_in - read in a gfs1-style log header */ +/* ------------------------------------------------------------------------ */ +void gfs_log_header_in(struct gfs_log_header *head, char *buf) +{ + struct gfs_log_header *str = (struct gfs_log_header *) buf; + + gfs2_meta_header_in(&head->lh_header, buf); + + head->lh_flags = be32_to_cpu(str->lh_flags); + head->lh_pad = be32_to_cpu(str->lh_pad); + + head->lh_first = be64_to_cpu(str->lh_first); + head->lh_sequence = be64_to_cpu(str->lh_sequence); + + head->lh_tail = be64_to_cpu(str->lh_tail); + head->lh_last_dump = be64_to_cpu(str->lh_last_dump); + + memcpy(head->lh_reserved, str->lh_reserved, 64); +} + + +/* ------------------------------------------------------------------------ */ +/* gfs_log_header_print - print a gfs1-style log header */ +/* ------------------------------------------------------------------------ */ +void gfs_log_header_print(struct gfs_log_header *lh) +{ + gfs2_meta_header_print(&lh->lh_header); + pv(lh, lh_flags, "%u", "0x%.8X"); + pv(lh, lh_pad, "%u", "%x"); + pv(lh, lh_first, "%llu", "%llx"); + pv(lh, lh_sequence, "%llu", "%llx"); + pv(lh, lh_tail, "%llu", "%llx"); + pv(lh, lh_last_dump, "%llu", "%llx"); +} + +/* ------------------------------------------------------------------------ */ /* dump_journal - dump a journal file's contents. */ /* ------------------------------------------------------------------------ */ void dump_journal(const char *journal) @@ -2045,19 +2081,34 @@ uint64_t *b; struct gfs2_log_descriptor ld; int i = 0, ltndx; - const char *logtypestr[4] = { - "Metadata", "Revoke", "Jdata", "Unknown"}; + uint32_t logtypes[2][6] = { + {GFS2_LOG_DESC_METADATA, + GFS2_LOG_DESC_REVOKE, + GFS2_LOG_DESC_JDATA, + 0, 0, 0}, + {GFS_LOG_DESC_METADATA, + GFS_LOG_DESC_IUL, + GFS_LOG_DESC_IDA, + GFS_LOG_DESC_Q, + GFS_LOG_DESC_LAST, + 0}}; + const char *logtypestr[2][6] = { + {"Metadata", "Revoke", "Jdata", + "Unknown", "Unknown", "Unknown"}, + {"Metadata", "Unlinked inode", "Dealloc inode", + "Quota", "Final Entry", "Unknown"}}; print_gfs2("Block #%4llx: Log descriptor, ", jb / (gfs1 ? 1 : bufsize)); gfs2_log_descriptor_in(&ld, jbuf); print_gfs2("type %d ", ld.ld_type); - if (ld.ld_type >= GFS2_LOG_DESC_METADATA && - ld.ld_type <= GFS2_LOG_DESC_JDATA) - ltndx = ld.ld_type - GFS2_LOG_DESC_METADATA; - else - ltndx = 3; - print_gfs2("(%s) ", logtypestr[ltndx]); + + for (ltndx = 0;; ltndx++) { + if (ld.ld_type == logtypes[gfs1][ltndx] || + logtypes[gfs1][ltndx] == 0) + break; + } + print_gfs2("(%s) ", logtypestr[gfs1][ltndx]); print_gfs2("len:%u, data1: %u", ld.ld_length, ld.ld_data1); eol(0); @@ -2085,11 +2136,22 @@ eol(0); } else if (get_block_type(jbuf) == GFS2_METATYPE_LH) { struct gfs2_log_header lh; + struct gfs_log_header lh1; - gfs2_log_header_in(&lh, jbuf); - print_gfs2("Block #%4llx: Log header: Seq = 0x%x, tail = 0x%x, blk = 0x%x", - jb / (gfs1 ? 1 : bufsize), - lh.lh_sequence, lh.lh_tail, lh.lh_blkno); + if (gfs1) { + gfs_log_header_in(&lh1, jbuf); + print_gfs2("Block #%4llx: Log header: Seq" + "= 0x%x, first = 0x%x tail = " + "0x%x, last = 0x%x", + jb, lh1.lh_sequence, lh1.lh_first, + lh1.lh_tail, lh1.lh_last_dump); + } else { + gfs2_log_header_in(&lh, jbuf); + print_gfs2("Block #%4llx: Log header: Seq" + "= 0x%x, tail = 0x%x, blk = 0x%x", + jb / bufsize, lh.lh_sequence, + lh.lh_tail, lh.lh_blkno); + } eol(0); } } --- cluster/gfs2/edit/hexedit.h 2007/11/13 17:03:39 1.13 +++ cluster/gfs2/edit/hexedit.h 2007/11/13 17:22:06 1.14 @@ -57,6 +57,13 @@ #define GFS_FILE_FIFO (101) /* fifo/pipe */ #define GFS_FILE_SOCK (102) /* socket */ +/* GFS 1 journal block types: */ +#define GFS_LOG_DESC_METADATA (300) /* metadata */ +#define GFS_LOG_DESC_IUL (400) /* unlinked inode */ +#define GFS_LOG_DESC_IDA (401) /* de-allocated inode */ +#define GFS_LOG_DESC_Q (402) /* quota */ +#define GFS_LOG_DESC_LAST (500) /* final in a logged transaction */ + EXTERN char *prog_name; EXTERN uint64_t block INIT(0); EXTERN int blockhist INIT(0); @@ -103,12 +110,39 @@ char ji_reserved[64]; }; +struct gfs_log_descriptor { + struct gfs2_meta_header ld_header; + + uint32_t ld_type; /* GFS_LOG_DESC_... Type of this log chunk */ + uint32_t ld_length; /* Number of buffers in this chunk */ + uint32_t ld_data1; /* descriptor-specific field */ + uint32_t ld_data2; /* descriptor-specific field */ + char ld_reserved[64]; +}; + +struct gfs_log_header { + struct gfs2_meta_header lh_header; + + uint32_t lh_flags; /* GFS_LOG_HEAD_... */ + uint32_t lh_pad; + + uint64_t lh_first; /* Block number of first header in this trans */ + uint64_t lh_sequence; /* Sequence number of this transaction */ + + uint64_t lh_tail; /* Block number of log tail */ + uint64_t lh_last_dump; /* Block number of last dump */ + + char lh_reserved[64]; +}; + EXTERN int block_is_jindex(void); EXTERN int block_is_inum_file(void); EXTERN int block_is_statfs_file(void); EXTERN int block_is_quota_file(void); EXTERN int display_block_type(const char *lpBuffer, int from_restore); EXTERN void gfs_jindex_in(struct gfs_jindex *jindex, char *buf); +EXTERN void gfs_log_header_in(struct gfs_log_header *head, char *buf); +EXTERN void gfs_log_header_print(struct gfs_log_header *lh); struct gfs2_dirents { uint64_t block; @@ -177,16 +211,6 @@ char sb_reserved[96]; }; -struct gfs_log_descriptor { - struct gfs2_meta_header ld_header; - - uint32_t ld_type; /* GFS_LOG_DESC_... Type of this log chunk */ - uint32_t ld_length; /* Number of buffers in this chunk */ - uint32_t ld_data1; /* descriptor-specific field */ - uint32_t ld_data2; /* descriptor-specific field */ - char ld_reserved[64]; -}; - EXTERN struct blkstack_info blockstack[BLOCK_STACK_SIZE]; EXTERN struct iinfo *indirect; /* more than the most indirect pointers possible for any given 4K block */