Skip to contentSkip to conversation

64bit jbd2 core changes

PATCH In review Mingming Cao 1 participant 1 message Aug 10, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 6/9 64bit jbd2 core changes

Here is the patch to JBD to handle 64 bit block numbers, originally from Zach Brown. This patch is useful only after adding support for 64-bit block numbers in the filesystem.

---

 linux-2.6.18-rc4-ming/fs/jbd2/commit.c     |   17 ++++++++---
 linux-2.6.18-rc4-ming/fs/jbd2/journal.c    |   11 +++++++
 linux-2.6.18-rc4-ming/fs/jbd2/recovery.c   |   43 ++++++++++++++++++++---------
 linux-2.6.18-rc4-ming/fs/jbd2/revoke.c     |   14 +++++++--
 linux-2.6.18-rc4-ming/include/linux/jbd2.h |   14 ++++++++-
 5 files changed, 77 insertions(+), 22 deletions(-)
fs/jbd2/commit.c renamed from fs/jbd2/commit.c~64bit_jbd2_core +13 -4
diff -puN fs/jbd2/commit.c~64bit_jbd2_core fs/jbd2/commit.c
@@ -160,6 +160,14 @@ static int journal_write_commit_record(j
 	return (ret == -EIO);
 }
 
+static inline void write_tag_block(int tag_bytes, journal_block_tag_t *tag,
+				   sector_t block)
+{
+	tag->t_blocknr = cpu_to_be32(block & (u32)~0);
+	if (tag_bytes > JBD_TAG_SIZE32)
+		tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
+}
+
 /*
  * jbd2_journal_commit_transaction
  *
@@ -182,6 +190,7 @@ void jbd2_journal_commit_transaction(jou
 	int first_tag = 0;
 	int tag_flag;
 	int i;
+	int tag_bytes = journal_tag_bytes(journal);
 
 	/*
 	 * First job: lock down the current transaction and wait for
@@ -553,10 +562,10 @@ write_out_data:
 			tag_flag |= JBD2_FLAG_SAME_UUID;
 
 		tag = (journal_block_tag_t *) tagp;
-		tag->t_blocknr = cpu_to_be32(jh2bh(jh)->b_blocknr);
+		write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr);
 		tag->t_flags = cpu_to_be32(tag_flag);
-		tagp += sizeof(journal_block_tag_t);
-		space_left -= sizeof(journal_block_tag_t);
+		tagp += tag_bytes;
+		space_left -= tag_bytes;
 
 		if (first_tag) {
 			memcpy (tagp, journal->j_uuid, 16);
@@ -570,7 +579,7 @@ write_out_data:
 
 		if (bufs == journal->j_wbufsize ||
 		    commit_transaction->t_buffers == NULL ||
-		    space_left < sizeof(journal_block_tag_t) + 16) {
+		    space_left < tag_bytes + 16) {
 
 			jbd_debug(4, "JBD: Submit %d IOs\n", bufs);
 
fs/jbd2/journal.c renamed from fs/jbd2/journal.c~64bit_jbd2_core +11 -0
diff -puN fs/jbd2/journal.c~64bit_jbd2_core fs/jbd2/journal.c
@@ -1603,6 +1603,17 @@ int jbd2_journal_blocks_per_page(struct 
 }
 
 /*
+ * helper functions to deal with 32 or 64bit block numbers.
+ */
+size_t journal_tag_bytes(journal_t *journal)
+{
+	if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
+		return JBD_TAG_SIZE64;
+	else
+		return JBD_TAG_SIZE32;
+}
+
+/*
  * Simple support for retrying memory allocations.  Introduced to help to
  * debug different VM deadlock avoidance strategies.
  */
fs/jbd2/recovery.c renamed from fs/jbd2/recovery.c~64bit_jbd2_core +30 -13

112 lines not on this page · raw message

fs/jbd2/revoke.c renamed from fs/jbd2/revoke.c~64bit_jbd2_core +11 -3
diff -puN fs/jbd2/revoke.c~64bit_jbd2_core fs/jbd2/revoke.c
@@ -584,9 +584,17 @@ static void write_one_revoke_record(jour
 		*descriptorp = descriptor;
 	}
 
-	* ((__be32 *)(&jh2bh(descriptor)->b_data[offset])) =
-		cpu_to_be32(record->blocknr);
-	offset += 4;
+	if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) {
+		* ((__be64 *)(&jh2bh(descriptor)->b_data[offset])) =
+			cpu_to_be64(record->blocknr);
+		offset += 8;
+
+	} else {
+		* ((__be32 *)(&jh2bh(descriptor)->b_data[offset])) =
+			cpu_to_be32(record->blocknr);
+		offset += 4;
+	}
+
 	*offsetp = offset;
 }
 
include/linux/jbd2.h renamed from include/linux/jbd2.h~64bit_jbd2_core +12 -2
diff -puN include/linux/jbd2.h~64bit_jbd2_core include/linux/jbd2.h
@@ -147,14 +147,21 @@ typedef struct journal_header_s
 
 
 /*
- * The block tag: used to describe a single buffer in the journal
+ * The block tag: used to describe a single buffer in the journal.
+ * t_blocknr_high is only used if INCOMPAT_64BIT is set, so this
+ * raw struct shouldn't be used for pointer math or sizeof() - use
+ * journal_tag_bytes(journal) instead to compute this.
  */
 typedef struct journal_block_tag_s
 {
 	__be32		t_blocknr;	/* The on-disk block number */
 	__be32		t_flags;	/* See below */
+	__be32		t_blocknr_high; /* most-significant high 32bits. */
 } journal_block_tag_t;
 
+#define JBD_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high))
+#define JBD_TAG_SIZE64 (sizeof(journal_block_tag_t))
+
 /*
  * The revoke descriptor: used on disk to describe a series of blocks to
  * be revoked from the log
@@ -232,11 +239,13 @@ typedef struct journal_superblock_s
 	 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
 
 #define JBD2_FEATURE_INCOMPAT_REVOKE	0x00000001
+#define JBD2_FEATURE_INCOMPAT_64BIT	0x00000002
 
 /* Features known to this kernel version: */
 #define JBD2_KNOWN_COMPAT_FEATURES	0
 #define JBD2_KNOWN_ROCOMPAT_FEATURES	0
-#define JBD2_KNOWN_INCOMPAT_FEATURES	JBD2_FEATURE_INCOMPAT_REVOKE
+#define JBD2_KNOWN_INCOMPAT_FEATURES	(JBD2_FEATURE_INCOMPAT_REVOKE | \
+					 JBD2_FEATURE_INCOMPAT_64BIT)
 
 #ifdef __KERNEL__
 
@@ -1050,6 +1059,7 @@ static inline int tid_geq(tid_t x, tid_t
 }
 
 extern int jbd2_journal_blocks_per_page(struct inode *inode);
+extern size_t journal_tag_bytes(journal_t *journal);
 
 /*
  * Return the minimum number of blocks which must be free in the journal

_