From 64430c06457edaa383e3a1d6b105c15a6ed30f61 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Fri, 13 Apr 2012 12:55:45 -0600 Subject: [PATCH] debugfs: dump "fid" and "lma" xattrs on inode stat Print out the Lustre "fid" and "lma" contents for stat, if present, to simplify debugging. Signed-off-by: Andreas Dilger --- debugfs/Makefile.in | 3 ++- debugfs/debugfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/ext2fs/lfsck.h | 11 ++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in index 7e71c3f..5009b5c 100644 --- a/debugfs/Makefile.in +++ b/debugfs/Makefile.in @@ -29,6 +29,7 @@ SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \ $(srcdir)/htree.c $(srcdir)/unused.c ${srcdir}/../misc/e2freefrag.c \ $(srcdir)/filefrag.c +@LFSCK_CMT@LUSTRE_INC=-I @LUSTRE@/lustre/include -I @LUSTRE@/include -I @LUSTRE@/libcfs/include -Wall LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \ $(LIBUUID) DEPLIBS= $(LIBEXT2FS) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \ @@ -36,7 +37,7 @@ DEPLIBS= $(LIBEXT2FS) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \ .c.o: $(E) " CC $<" - $(Q) $(CC) -c $(ALL_CFLAGS) $< -o $@ + $(Q) $(CC) -c $(ALL_CFLAGS) $(LUSTRE_INC) $< -o $@ all:: $(PROGS) $(MANPAGES) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 36243f6..5b715f9 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -512,9 +512,47 @@ static void dump_xattr_string(FILE *out, const char *str, int len) fprintf(out, "%02x ", (unsigned char)str[i]); } +#ifdef HAVE_LFSCK +#include "ext2fs/lfsck.h" + +static void print_fidstr(FILE *out, ext2_ino_t inode_num, void *data, int len) +{ + struct filter_fid *ff = data; + struct lu_fid parent_fid = ff->ff_parent; + int stripe; + + if (len < sizeof(*ff)) { + fprintf(stderr, "%s: error: fid for inode %u smaller than " + "expected (%d bytes).\n", + debug_prog_name, inode_num, len); + return; + } + lfsck_swab_fid(&parent_fid); + stripe = parent_fid.f_ver; /* stripe is stored in f_ver */ + parent_fid.f_ver = 0; + fprintf(out, " fid: objid=%llu seq=%llu parent="DFID" stripe=%u\n", + ext2fs_le64_to_cpu(ff->ff_objid), + ext2fs_le64_to_cpu(ff->ff_seq), PFID(&parent_fid), stripe); +} + +static void print_lmastr(FILE *out, ext2_ino_t inode_num, void *data, int len) +{ + struct lustre_mdt_attrs *lma = data; + + if (len < sizeof(*lma)) { + fprintf(stderr, "%s: error: lma for inode %u smaller than " + "expected (%d bytes).\n", + debug_prog_name, inode_num, len); + return; + } + lfsck_swab_fid(&lma->lma_self_fid); + fprintf(out, " lma: fid="DFID"\n", PFID(&lma->lma_self_fid)); +} +#endif /* HAVE_LFSCK */ + static void internal_dump_inode_extra(FILE *out, const char *prefix EXT2FS_ATTR((unused)), - ext2_ino_t inode_num EXT2FS_ATTR((unused)), + ext2_ino_t inode_num, struct ext2_inode_large *inode) { struct ext2_ext_attr_entry *entry; @@ -566,6 +604,24 @@ static void internal_dump_inode_extra(FILE *out, start + entry->e_value_offs, entry->e_value_size); fprintf(out, "\" (%u)\n", entry->e_value_size); +#ifdef HAVE_LFSCK + /* Special decoding for Lustre filter-fid */ + if ((entry->e_name_index == EXT2_ATTR_INDEX_TRUSTED || + entry->e_name_index == EXT2_ATTR_INDEX_LUSTRE) && + !strncmp(EXT2_EXT_ATTR_NAME(entry), + "fid", entry->e_name_len)) + print_fidstr(out, inode_num, + start + entry->e_value_offs, + entry->e_value_size); + /* Special decoding for Lustre lma */ + if ((entry->e_name_index == EXT2_ATTR_INDEX_TRUSTED || + entry->e_name_index == EXT2_ATTR_INDEX_LUSTRE) && + !strncmp(EXT2_EXT_ATTR_NAME(entry), + "lma", entry->e_name_len)) + print_lmastr(out, inode_num, + start + entry->e_value_offs, + entry->e_value_size); +#endif entry = next; } } diff --git a/lib/ext2fs/lfsck.h b/lib/ext2fs/lfsck.h index a29f1e9..12ec50b 100644 --- a/lib/ext2fs/lfsck.h +++ b/lib/ext2fs/lfsck.h @@ -42,6 +42,8 @@ #ifndef IDENTITY_DOWNCALL_MAGIC #define l_object_seq l_object_gr /* for lov_ost_data_v1 */ #define lmm_object_seq lmm_object_gr /* for lov_mds_md_v1/3 */ +#define ff_seq ff_group /* for filter_fid */ +#define ff_parent (struct lu_fid *)ff_fid /* for filter_fid */ #endif /* IDENTITY_DOWNCALL_MAGIC */ /* Unfortunately, neither the 1.8 or 2.x lustre_idl.h file is suitable @@ -66,8 +68,16 @@ struct lu_fid { }; #endif +static inline void lfsck_swab_fid(struct lu_fid *fid) +{ + fid->f_seq = ext2fs_le64_to_cpu(fid->f_seq); + fid->f_oid = ext2fs_le32_to_cpu(fid->f_oid); + fid->f_ver = ext2fs_le32_to_cpu(fid->f_ver); +} + #define OBD_CONNECT_FID 0x40000000ULL +#ifndef LMA_INCOMPAT_SUPP struct lustre_mdt_attrs { __u32 lma_compat; __u32 lma_incompat; @@ -78,6 +88,7 @@ struct lustre_mdt_attrs { __u64 lma_som_blocks; __u64 lma_som_mountid; }; +#endif struct ost_id { __u64 oi_id; -- 1.8.3.1