Whamcloud - gitweb
LU-8300 e2fsck: print out FID with dirent inode number
authorAndreas Dilger <andreas.dilger@intel.com>
Sat, 18 Jun 2016 10:50:41 +0000 (04:50 -0600)
committerLi Dongyang <dongyangli@ddn.com>
Wed, 15 Aug 2018 02:09:04 +0000 (12:09 +1000)
When printing out the dirent inode number in e2fsck, also print
out the FID, if available, for reference in the future if needed.

   Entry 'lustre.conf' in /ROOT/etc/yum/protected.d (50132) has
   deleted/unused inode=1964 fid=[0x200000401:0x844:0x0].  Clear? yes

This can be useful if LFSCK is able to rebuild the MDT layout from
the OST object xattrs, but the filename isn't stored on the OST.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Change-Id: Id0ec22c47d83f16c392e93328d2869e7a53ebbe5
Reviewed-on: https://review.whamcloud.com/20866
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Artem Blagodarenko <c17828@cray.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
e2fsck/message.c

index 727f71d..eca280a 100644 (file)
@@ -99,6 +99,7 @@
 
 #include "e2fsck.h"
 #include "problem.h"
+#include "ext2fs/lfsck.h"
 
 #ifdef __GNUC__
 #define _INLINE_ __inline__
@@ -348,6 +349,33 @@ static _INLINE_ void expand_inode_expression(FILE *f, ext2_filsys fs, char ch,
        }
 }
 
+const struct lu_fid *get_dirent_fid(struct ext2_dir_entry *dirent)
+{
+       unsigned char *data = (unsigned char *)dirent->name +
+                             (dirent->name_len & EXT2_NAME_LEN) + 1;
+       __u8 file_type = dirent->name_len >> 8;
+       struct lu_fid *fid = NULL;
+       __u8 dirdata_mask;
+
+       for (dirdata_mask = EXT2_FT_MASK + 1;
+            dirdata_mask != 0; dirdata_mask <<= 1) {
+               int dlen;
+
+               if ((dirdata_mask & file_type) == 0)
+                       continue;
+
+               dlen = data[0];
+               if (dirdata_mask == EXT2_DIRENT_LUFID) {
+                       fid = (struct lu_fid *)(data + 1);
+                       fid_be_to_cpu(fid, fid);
+                       break;
+               }
+               data += dlen;
+       }
+
+       return fid;
+}
+
 /*
  * This function expands '%dX' expressions
  */
@@ -363,9 +391,17 @@ static _INLINE_ void expand_dirent_expression(FILE *f, ext2_filsys fs, char ch,
        dirent = ctx->dirent;
 
        switch (ch) {
-       case 'i':
+       case 'i': {
+               const struct lu_fid *fid;
+
                fprintf(f, "%u", dirent->inode);
+
+               fid = get_dirent_fid(dirent);
+               if (fid != NULL)
+                       fprintf(f, " fid="DFID, PFID(fid));
+
                break;
+       }
        case 'n':
                len = ext2fs_dirent_name_len(dirent);
                if ((ext2fs_get_rec_len(fs, dirent, &rec_len) == 0) &&