Blame SOURCES/bz1063842-3-libgfs2_Add_support_for_new_leaf_hint_fields.patch

903fa7
commit e7b57dae8cfd096514b970d200e1e97648b495a6
903fa7
Author: Andrew Price <anprice@redhat.com>
903fa7
Date:   Thu Feb 6 16:19:02 2014 +0000
903fa7
903fa7
    libgfs2: Add support for new leaf hint fields
903fa7
    
903fa7
    Kernel commit 01bcb0de introduces new gfs2_leaf fields. This patch adds
903fa7
    support for those fields to libgfs2, conditional upon them being
903fa7
    discovered in the configure stage. Includes meta.c changes by Steve
903fa7
    Whitehouse.
903fa7
    
903fa7
    Resolves: rhbz#1063842
903fa7
    
903fa7
    Signed-off-by: Andrew Price <anprice@redhat.com>
903fa7
903fa7
diff --git a/configure.ac b/configure.ac
903fa7
index 628d85e..80310be 100644
903fa7
--- a/configure.ac
903fa7
+++ b/configure.ac
903fa7
@@ -116,12 +116,10 @@ AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h mnt
903fa7
 AC_CHECK_HEADERS([linux/dlmconstants.h linux/limits.h linux/types.h linux/netlink.h linux/fs.h],,
903fa7
 		 [AC_MSG_ERROR([Unable to find all required kernel headers.])])
903fa7
 
903fa7
-AC_CHECK_HEADERS([linux/gfs2_ondisk.h],
903fa7
-		 [AC_CHECK_MEMBERS([struct gfs2_sb.sb_uuid],,
903fa7
-			[AC_MSG_ERROR([Unable to find gfs2 uuid support in your headers.
903fa7
-Please update your kernel headers to a more recent version])],
903fa7
-			[#include <linux/gfs2_ondisk.h>])],
903fa7
-		 [AC_MSG_ERROR([Unable to find required kernel headers.])])
903fa7
+AC_CHECK_HEADER([linux/gfs2_ondisk.h], [], [AC_MSG_ERROR([Unable to find linux/gfs2_ondisk.h])])
903fa7
+AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [], [], [[#include <linux/gfs2_ondisk.h>]])
903fa7
+AC_CHECK_MEMBER([struct gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])],
903fa7
+                [], [[#include <linux/gfs2_ondisk.h>]])
903fa7
 
903fa7
 # Checks for typedefs, structures, and compiler characteristics.
903fa7
 AC_C_INLINE
903fa7
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
903fa7
index 27c32a9..328e35c 100644
903fa7
--- a/gfs2/edit/extended.c
903fa7
+++ b/gfs2/edit/extended.c
903fa7
@@ -296,8 +296,18 @@ static void print_inode_type(__be16 de_type)
903fa7
 	}
903fa7
 }
903fa7
 
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+#define LEAF_HINT_FMTS "lf_inode: 0x%"PRIx64", lf_dist: %"PRIu32", " \
903fa7
+                       "lf_nsec: %"PRIu32", lf_sec: %"PRIu64", "
903fa7
+#define LEAF_HINT_FIELDS(lp) lp->lf_inode, lp->lf_dist, lp->lf_nsec, lp->lf_sec,
903fa7
+#else
903fa7
+#define LEAF_HINT_FMTS
903fa7
+#define LEAF_HINT_FIELDS(lp)
903fa7
+#endif
903fa7
+
903fa7
 static int display_leaf(struct iinfo *ind)
903fa7
 {
903fa7
+	struct gfs2_leaf *leaf = &ind->ii[0].lf;
903fa7
 	int start_line, total_dirents = start_row[dmode];
903fa7
 	int d;
903fa7
 
903fa7
@@ -305,11 +315,13 @@ static int display_leaf(struct iinfo *ind)
903fa7
 	if (gfs2_struct_type == GFS2_METATYPE_SB)
903fa7
 		print_gfs2("The superblock has 2 directories");
903fa7
 	else
903fa7
-		print_gfs2("Directory block: lf_depth:%d, lf_entries:%d,"
903fa7
+		print_gfs2("Directory block: lf_depth:%d, lf_entries:%d, "
903fa7
+		           LEAF_HINT_FMTS
903fa7
 			   "fmt:%d next=0x%llx (%d dirents).",
903fa7
-			   ind->ii[0].lf_depth, ind->ii[0].lf_entries,
903fa7
-			   ind->ii[0].lf_dirent_format,
903fa7
-			   ind->ii[0].lf_next,
903fa7
+			   leaf->lf_depth, leaf->lf_entries,
903fa7
+		           LEAF_HINT_FIELDS(leaf)
903fa7
+			   leaf->lf_dirent_format,
903fa7
+			   leaf->lf_next,
903fa7
 			   ind->ii[0].dirents);
903fa7
 
903fa7
 	start_line = line;
903fa7
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
903fa7
index cc0ceb6..cda4dbe 100644
903fa7
--- a/gfs2/edit/gfs2hex.c
903fa7
+++ b/gfs2/edit/gfs2hex.c
903fa7
@@ -341,17 +341,12 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)
903fa7
 {
903fa7
 	int x, i;
903fa7
 	struct gfs2_dirent de;
903fa7
-	struct gfs2_leaf leaf;
903fa7
 	struct gfs2_buffer_head tbh; /* kludge */
903fa7
 
903fa7
 	x = 0;
903fa7
 	memset(indir, 0, sizeof(*indir));
903fa7
 	tbh.b_data = dlebuf;
903fa7
-	gfs2_leaf_in(&leaf, &tbh;;
903fa7
-	indir->ii[0].lf_depth = leaf.lf_depth;
903fa7
-	indir->ii[0].lf_entries = leaf.lf_entries;
903fa7
-	indir->ii[0].lf_dirent_format = leaf.lf_dirent_format;
903fa7
-	indir->ii[0].lf_next = leaf.lf_next;
903fa7
+	gfs2_leaf_in(&indir->ii[0].lf, &tbh;;
903fa7
 	/* Directory Entries: */
903fa7
 	for (i = sizeof(struct gfs2_leaf); i < sbd.bsize;
903fa7
 	     i += de.de_rec_len) {
903fa7
@@ -372,7 +367,7 @@ uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir)
903fa7
 		if (de.de_rec_len <= sizeof(struct gfs2_dirent))
903fa7
 			break;
903fa7
 	}
903fa7
-	return leaf.lf_next;
903fa7
+	return indir->ii[0].lf.lf_next;
903fa7
 }
903fa7
 
903fa7
 static void do_eattr_extended(struct gfs2_buffer_head *ebh)
903fa7
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
903fa7
index 0708445..1738652 100644
903fa7
--- a/gfs2/edit/hexedit.c
903fa7
+++ b/gfs2/edit/hexedit.c
903fa7
@@ -219,7 +219,15 @@ static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield)
903fa7
 	checkprint(strfield, lf, lf_entries);
903fa7
 	checkprint(strfield, lf, lf_dirent_format);
903fa7
 	checkprint(strfield, lf, lf_next);
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	checkprint(strfield, lf, lf_inode);
903fa7
+	checkprint(strfield, lf, lf_dist);
903fa7
+	checkprint(strfield, lf, lf_nsec);
903fa7
+	checkprint(strfield, lf, lf_sec);
903fa7
+	checkprints(strfield, lf, lf_reserved2);
903fa7
+#else
903fa7
 	checkprints(strfield, lf, lf_reserved);
903fa7
+#endif
903fa7
 
903fa7
 	return -1;
903fa7
 }
903fa7
@@ -231,6 +239,12 @@ static int gfs2_leaf_assignval(struct gfs2_leaf *lf, const char *strfield,
903fa7
 	checkassign(strfield, lf, lf_entries, value);
903fa7
 	checkassign(strfield, lf, lf_dirent_format, value);
903fa7
 	checkassign(strfield, lf, lf_next, value);
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	checkassign(strfield, lf, lf_inode, value);
903fa7
+	checkassign(strfield, lf, lf_dist, value);
903fa7
+	checkassign(strfield, lf, lf_nsec, value);
903fa7
+	checkassign(strfield, lf, lf_sec, value);
903fa7
+#endif
903fa7
 
903fa7
 	return -1;
903fa7
 }
903fa7
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
903fa7
index 706909c..ebe3855 100644
903fa7
--- a/gfs2/edit/hexedit.h
903fa7
+++ b/gfs2/edit/hexedit.h
903fa7
@@ -78,10 +78,7 @@ struct indirect_info {
903fa7
 	int height;
903fa7
 	uint64_t block;
903fa7
 	uint32_t dirents;
903fa7
-	uint16_t lf_depth;
903fa7
-	uint16_t lf_entries;
903fa7
-	uint32_t lf_dirent_format;
903fa7
-	uint64_t lf_next;
903fa7
+	struct gfs2_leaf lf;
903fa7
 	struct metapath mp;
903fa7
 	struct gfs2_dirents dirent[64];
903fa7
 };
903fa7
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
903fa7
index b8cef87..59fbde8 100644
903fa7
--- a/gfs2/fsck/metawalk.c
903fa7
+++ b/gfs2/fsck/metawalk.c
903fa7
@@ -657,7 +657,6 @@ static void dir_leaf_reada(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize)
903fa7
 static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
903fa7
 {
903fa7
 	int error = 0;
903fa7
-	struct gfs2_leaf leaf;
903fa7
 	unsigned hsize = (1 << ip->i_di.di_depth);
903fa7
 	uint64_t leaf_no, leaf_next;
903fa7
 	uint64_t first_ok_leaf, orig_di_blocks;
903fa7
@@ -767,6 +766,7 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
903fa7
 
903fa7
 		chained_leaf = 0;
903fa7
 		do {
903fa7
+			struct gfs2_leaf leaf;
903fa7
 			if (fsck_abort) {
903fa7
 				free(tbl);
903fa7
 				posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_NORMAL);
903fa7
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
903fa7
index 4a84687..1790421 100644
903fa7
--- a/gfs2/libgfs2/fs_ops.c
903fa7
+++ b/gfs2/libgfs2/fs_ops.c
903fa7
@@ -1024,6 +1024,9 @@ void dir_split_leaf(struct gfs2_inode *dip, uint32_t start, uint64_t leaf_no,
903fa7
 	oleaf->lf_depth = cpu_to_be16(oleaf->lf_depth);
903fa7
 	nleaf->lf_depth = oleaf->lf_depth;
903fa7
 
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	nleaf->lf_inode = cpu_to_be64(dip->i_di.di_num.no_addr);
903fa7
+#endif
903fa7
 	dip->i_di.di_blocks++;
903fa7
 	bmodified(dip->i_bh);
903fa7
 
903fa7
@@ -1206,7 +1209,9 @@ restart:
903fa7
 				nleaf = (struct gfs2_leaf *)nbh->b_data;
903fa7
 				nleaf->lf_depth = leaf->lf_depth;
903fa7
 				nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
903fa7
-
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+				nleaf->lf_inode = cpu_to_be64(dip->i_di.di_num.no_addr);
903fa7
+#endif
903fa7
 				err = dirent_alloc(dip, nbh, len, &dent);
903fa7
 				if (err)
903fa7
 					return err;
903fa7
@@ -1256,7 +1261,9 @@ static void dir_make_exhash(struct gfs2_inode *dip)
903fa7
 	leaf = (struct gfs2_leaf *)bh->b_data;
903fa7
 	leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
903fa7
 	leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries);
903fa7
-
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	leaf->lf_inode = cpu_to_be64(dip->i_di.di_num.no_addr);
903fa7
+#endif
903fa7
 	buffer_copy_tail(sdp, bh, sizeof(struct gfs2_leaf),
903fa7
 			 dip->i_bh, sizeof(struct gfs2_dinode));
903fa7
 
903fa7
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
903fa7
index 94be823..4305393 100644
903fa7
--- a/gfs2/libgfs2/meta.c
903fa7
+++ b/gfs2/libgfs2/meta.c
903fa7
@@ -317,7 +317,15 @@ F(lf_depth)
903fa7
 F(lf_entries)
903fa7
 F(lf_dirent_format)
903fa7
 F(lf_next)
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+FP(lf_inode, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
903fa7
+F(lf_dist)
903fa7
+F(lf_nsec, .flags = LGFS2_MFF_NSECS)
903fa7
+F(lf_sec, .flags = LGFS2_MFF_SECS)
903fa7
+RF(lf_reserved2)
903fa7
+#else
903fa7
 RF(lf_reserved)
903fa7
+#endif
903fa7
 };
903fa7
 
903fa7
 #undef STRUCT
903fa7
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
903fa7
index 43618bc..dcc537e 100644
903fa7
--- a/gfs2/libgfs2/ondisk.c
903fa7
+++ b/gfs2/libgfs2/ondisk.c
903fa7
@@ -433,8 +433,15 @@ void gfs2_leaf_in(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)
903fa7
 	CPIN_16(lf, str, lf_entries);
903fa7
 	CPIN_32(lf, str, lf_dirent_format);
903fa7
 	CPIN_64(lf, str, lf_next);
903fa7
-
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	CPIN_64(lf, str, lf_inode);
903fa7
+	CPIN_32(lf, str, lf_dist);
903fa7
+	CPIN_32(lf, str, lf_nsec);
903fa7
+	CPIN_64(lf, str, lf_sec);
903fa7
+	CPIN_08(lf, str, lf_reserved2, 40);
903fa7
+#else
903fa7
 	CPIN_08(lf, str, lf_reserved, 32);
903fa7
+#endif
903fa7
 }
903fa7
 
903fa7
 void gfs2_leaf_out(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)
903fa7
@@ -446,8 +453,15 @@ void gfs2_leaf_out(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)
903fa7
 	CPOUT_16(lf, str, lf_entries);
903fa7
 	CPOUT_32(lf, str, lf_dirent_format);
903fa7
 	CPOUT_64(lf, str, lf_next);
903fa7
-
903fa7
-	CPOUT_08(lf, str, lf_reserved, 32);
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	CPOUT_64(lf, str, lf_inode);
903fa7
+	CPOUT_32(lf, str, lf_dist);
903fa7
+	CPOUT_32(lf, str, lf_nsec);
903fa7
+	CPOUT_64(lf, str, lf_sec);
903fa7
+	CPOUT_08(lf, str, lf_reserved2, 40);
903fa7
+#else
903fa7
+	CPOUT_08(lf, str, lf_reserved, 64);
903fa7
+#endif
903fa7
 	bmodified(bh);
903fa7
 }
903fa7
 
903fa7
@@ -458,6 +472,12 @@ void gfs2_leaf_print(struct gfs2_leaf *lf)
903fa7
 	pv(lf, lf_entries, "%u", "0x%x");
903fa7
 	pv(lf, lf_dirent_format, "%u", "0x%x");
903fa7
 	pv(lf, lf_next, "%llu", "0x%llx");
903fa7
+#ifdef GFS2_HAS_LEAF_HINTS
903fa7
+	pv(lf, lf_inode, "%llu", "0x%llx");
903fa7
+	pv(lf, lf_dist, "%u", "0x%x");
903fa7
+	pv(lf, lf_nsec, "%u", "0x%x");
903fa7
+	pv(lf, lf_sec, "%llu", "0x%llx");
903fa7
+#endif
903fa7
 }
903fa7
 
903fa7
 void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf)