Re: [RFC 4/5] support >32 bit ext3: sector_t convert in JBD

Mingming Cao <[email protected]>
Newsgroups gmane.comp.file-systems.ext2.devel
Organization IBM LTC
Message-ID <[email protected]>
On Fri, 2006-06-09 at 15:26 +0100, Stephen C. Tweedie wrote:
> Hi,
> 
> On Thu, 2006-06-08 at 13:56 -0700, Mingming Cao wrote:
> 
> > Here is the updated sector_t-jbd patch.
> 
> Do you have an incremental diff against the last one?
> 
> >  /* Borrowed from buffer.c: this is a tried and tested block hash function */
> > -static inline int hash(journal_t *journal, unsigned long block)
> > +static inline int hash(journal_t *journal, sector_t block)
> >  {
> >  	struct jbd_revoke_table_s *table = journal->j_revoke;
> >  	int hash_shift = table->hash_shift;
> > +	int hash = (int)block ^ (int)(block >> 32);
> 
> This is undefined in C if sector_t is 32-bits long.  You need to use
> ((block >> 31) >> 1) or somet
> hing similar.

All, right. Thanks.

The incremental diff against the last(original) one:


 fs/jbd/checkpoint.c      |    2 +-
 fs/jbd/journal.c         |   18 +++++++++---------
 fs/jbd/recovery.c        |   28 ++++++++++++++--------------
 fs/jbd/revoke.c          |   10 ++++++----
 fs/jbd/transaction.c     |    6 +++---
 include/linux/ext3_jbd.h |    2 +-
 include/linux/jbd.h      |   25 ++++++++++++-------------
 7 files changed, 46 insertions(+), 45 deletions(-)

diff -urNp linux-2.6.17-rc6-secjbd.old/fs/jbd/checkpoint.c linux-2.6.17-rc6-secjbd.new/fs/jbd/checkpoint.c
--- linux-2.6.17-rc6-secjbd.old/fs/jbd/checkpoint.c	2006-06-09 08:43:12.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/fs/jbd/checkpoint.c	2006-06-09 08:51:56.000000000 -0700
@@ -396,7 +396,7 @@ int cleanup_journal_tail(journal_t *jour
 {
 	transaction_t * transaction;
 	tid_t		first_tid;
-	sector_t	blocknr, freed;
+	unsigned long	blocknr, freed;
 
 	/* OK, work out the oldest transaction remaining in the log, and
 	 * the log block it starts at. 
diff -urNp linux-2.6.17-rc6-secjbd.old/fs/jbd/journal.c linux-2.6.17-rc6-secjbd.new/fs/jbd/journal.c
--- linux-2.6.17-rc6-secjbd.old/fs/jbd/journal.c	2006-06-09 08:43:12.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/fs/jbd/journal.c	2006-06-09 08:55:55.000000000 -0700
@@ -555,7 +555,7 @@ int log_wait_commit(journal_t *journal, 
 
 int journal_next_log_block(journal_t *journal, sector_t *retp)
 {
-	sector_t blocknr;
+	unsigned long blocknr;
 
 	spin_lock(&journal->j_state_lock);
 	J_ASSERT(journal->j_free > 1);
@@ -576,7 +576,7 @@ int journal_next_log_block(journal_t *jo
  * this is a no-op.  If needed, we can use j_blk_offset - everything is
  * ready.
  */
-int journal_bmap(journal_t *journal, sector_t blocknr,
+int journal_bmap(journal_t *journal, unsigned long blocknr, 
 		 sector_t *retp)
 {
 	int err = 0;
@@ -590,9 +590,9 @@ int journal_bmap(journal_t *journal, sec
 			char b[BDEVNAME_SIZE];
 
 			printk(KERN_ALERT "%s: journal block not found "
-					"at offset %llu on %s\n",
+					"at offset %lu on %s\n",
 				__FUNCTION__,
-				(unsigned long long)blocknr,
+				blocknr,
 				bdevname(journal->j_dev, b));
 			err = -EIO;
 			__journal_abort_soft(journal, err);
@@ -704,7 +704,7 @@ fail:
  */
 journal_t * journal_init_dev(struct block_device *bdev,
 			struct block_device *fs_dev,
-			sector_t start, sector_t len, int blocksize)
+			sector_t start, int len, int blocksize)
 {
 	journal_t *journal = journal_init_common();
 	struct buffer_head *bh;
@@ -818,7 +818,7 @@ static void journal_fail_superblock (jou
 static int journal_reset(journal_t *journal)
 {
 	journal_superblock_t *sb = journal->j_superblock;
-	sector_t first, last;
+	unsigned int first, last;
 
 	first = be32_to_cpu(sb->s_first);
 	last = be32_to_cpu(sb->s_maxlen);
@@ -858,8 +858,8 @@ int journal_create(journal_t *journal)
 	int i, err;
 
 	if (journal->j_maxlen < JFS_MIN_JOURNAL_BLOCKS) {
-		printk (KERN_ERR "Journal length (%lld blocks) too short.\n",
-			(unsigned long long)journal->j_maxlen);
+		printk (KERN_ERR "Journal length (%d blocks) too short.\n",
+			journal->j_maxlen);
 		journal_fail_superblock(journal);
 		return -EINVAL;
 	}
@@ -1328,7 +1328,7 @@ int journal_flush(journal_t *journal)
 {
 	int err = 0;
 	transaction_t *transaction = NULL;
-	sector_t old_tail;
+	unsigned long old_tail;
 
 	spin_lock(&journal->j_state_lock);
 
diff -urNp linux-2.6.17-rc6-secjbd.old/fs/jbd/recovery.c linux-2.6.17-rc6-secjbd.new/fs/jbd/recovery.c
--- linux-2.6.17-rc6-secjbd.old/fs/jbd/recovery.c	2006-06-09 08:43:12.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/fs/jbd/recovery.c	2006-06-09 08:56:38.000000000 -0700
@@ -66,10 +66,10 @@ void journal_brelse_array(struct buffer_
  */
 
 #define MAXBUF 8
-static int do_readahead(journal_t *journal, sector_t start)
+static int do_readahead(journal_t *journal, unsigned int start)
 {
 	int err;
-	sector_t max, nbufs, next;
+	unsigned int max, nbufs, next;
 	sector_t blocknr;
 	struct buffer_head *bh;
 
@@ -89,8 +89,8 @@ static int do_readahead(journal_t *journ
 		err = journal_bmap(journal, next, &blocknr);
 
 		if (err) {
-			printk (KERN_ERR "JBD: bad block at offset %llu\n",
-				(unsigned long long)next);
+			printk (KERN_ERR "JBD: bad block at offset %u\n",
+				next);
 			goto failed;
 		}
 
@@ -129,7 +129,7 @@ failed:
  */
 
 static int jread(struct buffer_head **bhp, journal_t *journal, 
-		 sector_t offset)
+		 unsigned int offset)
 {
 	int err;
 	sector_t blocknr;
@@ -145,8 +145,8 @@ static int jread(struct buffer_head **bh
 	err = journal_bmap(journal, offset, &blocknr);
 
 	if (err) {
-		printk (KERN_ERR "JBD: bad block at offset %llu\n",
-			(unsigned long long)offset);
+		printk (KERN_ERR "JBD: bad block at offset %u\n",
+			offset);
 		return err;
 	}
 
@@ -163,8 +163,8 @@ static int jread(struct buffer_head **bh
 	}
 
 	if (!buffer_uptodate(bh)) {
-		printk (KERN_ERR "JBD: Failed to read block at offset %llu\n",
-			(unsigned long long)offset);
+		printk (KERN_ERR "JBD: Failed to read block at offset %u\n",
+			offset);
 		brelse(bh);
 		return -EIO;
 	}
@@ -311,7 +311,7 @@ static int do_one_pass(journal_t *journa
 			struct recovery_info *info, enum passtype pass)
 {
 	unsigned int		first_commit_ID, next_commit_ID;
-	sector_t		next_log_block;
+	unsigned long		next_log_block;
 	int			err, success = 0;
 	journal_superblock_t *	sb;
 	journal_header_t * 	tmp;
@@ -426,7 +426,7 @@ static int do_one_pass(journal_t *journa
 			tagp = &bh->b_data[sizeof(journal_header_t)];
 			while ((tagp - bh->b_data +sizeof(journal_block_tag_t))
 			       <= journal->j_blocksize) {
-				sector_t io_block;
+				unsigned long io_block;
 
 				tag = (journal_block_tag_t *) tagp;
 				flags = be32_to_cpu(tag->t_flags);
@@ -440,8 +440,8 @@ static int do_one_pass(journal_t *journa
 					success = err;
 					printk (KERN_ERR 
 						"JBD: IO error %d recovering "
-						"block %llu in log\n",
-						err, (unsigned long long)io_block);
+						"block %ld in log\n",
+						err, io_block);
 				} else {
 					sector_t blocknr;
 
@@ -570,7 +570,7 @@ static int scan_revoke_records(journal_t
 			       tid_t sequence, struct recovery_info *info)
 {
 	journal_revoke_header_t *header;
-	sector_t offset, max;
+	int offset, max;
 
 	header = (journal_revoke_header_t *) bh->b_data;
 	offset = sizeof(journal_revoke_header_t);
diff -urNp linux-2.6.17-rc6-secjbd.old/fs/jbd/revoke.c linux-2.6.17-rc6-secjbd.new/fs/jbd/revoke.c
--- linux-2.6.17-rc6-secjbd.old/fs/jbd/revoke.c	2006-06-09 08:43:12.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/fs/jbd/revoke.c	2006-06-09 08:57:18.000000000 -0700
@@ -110,10 +110,11 @@ static inline int hash(journal_t *journa
 {
 	struct jbd_revoke_table_s *table = journal->j_revoke;
 	int hash_shift = table->hash_shift;
+	int hash = (int)block ^ (int)(block >> 31 >> 1);
 
-	return ((block << (hash_shift - 6)) ^
-		(block >> 13) ^
-		(block << (hash_shift - 12))) & (table->hash_size - 1);
+	return ((hash << (hash_shift - 6)) ^
+		(hash >> 13) ^
+		(hash << (hash_shift - 12))) & (table->hash_size - 1);
 }
 
 static int insert_revoke_hash(journal_t *journal, sector_t blocknr,
@@ -394,7 +395,8 @@ int journal_revoke(handle_t *handle, sec
 		}
 	}
 
-	jbd_debug(2, "insert revoke for block %lu, bh_in=%p\n", blocknr, bh_in);
+	jbd_debug(2, "insert revoke for block %llu, bh_in=%p\n",
+		blocknr, bh_in);
 	err = insert_revoke_hash(journal, blocknr,
 				handle->h_transaction->t_tid);
 	BUFFER_TRACE(bh_in, "exit");
diff -urNp linux-2.6.17-rc6-secjbd.old/fs/jbd/transaction.c linux-2.6.17-rc6-secjbd.new/fs/jbd/transaction.c
--- linux-2.6.17-rc6-secjbd.old/fs/jbd/transaction.c	2006-06-09 08:43:12.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/fs/jbd/transaction.c	2006-06-09 08:51:56.000000000 -0700
@@ -1883,10 +1883,10 @@ zap_buffer_unlocked:
  */
 void journal_invalidatepage(journal_t *journal,
 		      struct page *page, 
-		      sector_t offset)
+		      unsigned long offset)
 {
 	struct buffer_head *head, *bh, *next;
-	sector_t curr_off = 0;
+	unsigned int curr_off = 0;
 	int may_free = 1;
 
 	if (!PageLocked(page))
@@ -1900,7 +1900,7 @@ void journal_invalidatepage(journal_t *j
 
 	head = bh = page_buffers(page);
 	do {
-		sector_t next_off = curr_off + bh->b_size;
+		unsigned int next_off = curr_off + bh->b_size;
 		next = bh->b_this_page;
 
 		if (offset <= curr_off) {
diff -urNp linux-2.6.17-rc6-secjbd.old/include/linux/ext3_jbd.h linux-2.6.17-rc6-secjbd.new/include/linux/ext3_jbd.h
--- linux-2.6.17-rc6-secjbd.old/include/linux/ext3_jbd.h	2006-06-09 08:43:12.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/include/linux/ext3_jbd.h	2006-06-09 08:55:55.000000000 -0700
@@ -149,7 +149,7 @@ __ext3_journal_forget(const char *where,
 
 static inline int
 __ext3_journal_revoke(const char *where, handle_t *handle,
-		      sector_t blocknr, struct buffer_head *bh)
+		      ext3_fsblk_t blocknr, struct buffer_head *bh)
 {
 	int err = journal_revoke(handle, blocknr, bh);
 	if (err)
diff -urNp linux-2.6.17-rc6-secjbd.old/include/linux/jbd.h linux-2.6.17-rc6-secjbd.new/include/linux/jbd.h
--- linux-2.6.17-rc6-secjbd.old/include/linux/jbd.h	2006-06-09 08:43:46.000000000 -0700
+++ linux-2.6.17-rc6-secjbd.new/include/linux/jbd.h	2006-06-09 08:55:55.000000000 -0700
@@ -458,7 +458,7 @@ struct transaction_s 
 	/*
 	 * Where in the log does this transaction's commit start? [no locking]
 	 */
-	sector_t	t_log_start;
+	unsigned long		t_log_start;
 
 	/* Number of buffers on the t_buffers list [j_list_lock] */
 	int			t_nr_buffers;
@@ -696,26 +696,26 @@ struct journal_s
 	 * Journal head: identifies the first unused block in the journal.
 	 * [j_state_lock]
 	 */
-	sector_t		j_head;
+	unsigned long		j_head;
 
 	/*
 	 * Journal tail: identifies the oldest still-used block in the journal.
 	 * [j_state_lock]
 	 */
-	sector_t		j_tail;
+	unsigned long		j_tail;
 
 	/*
 	 * Journal free: how many free blocks are there in the journal?
 	 * [j_state_lock]
 	 */
-	sector_t		j_free;
+	unsigned long		j_free;
 
 	/*
 	 * Journal start and end: the block numbers of the first usable block
 	 * and one beyond the last usable block in the journal. [j_state_lock]
 	 */
-	sector_t		j_first;
-	sector_t		j_last;
+	unsigned long		j_first;
+	unsigned long		j_last;
 
 	/*
 	 * Device, blocksize and starting block offset for the location where we
@@ -732,7 +732,7 @@ struct journal_s
 	struct block_device	*j_fs_dev;
 
 	/* Total maximum capacity of the journal region on disk. */
-	sector_t		j_maxlen;
+	unsigned int		j_maxlen;
 
 	/*
 	 * Protects the buffer lists and internal buffer state.
@@ -857,7 +857,7 @@ extern int 
 journal_write_metadata_buffer(transaction_t	  *transaction,
 			      struct journal_head  *jh_in,
 			      struct journal_head **jh_out,
-			      sector_t		   blocknr);
+			      sector_t   blocknr);
 
 /* Transaction locking */
 extern void		__wait_on_journal (journal_t *);
@@ -896,7 +896,7 @@ extern void	 journal_release_buffer (han
 extern int	 journal_forget (handle_t *, struct buffer_head *);
 extern void	 journal_sync_buffer (struct buffer_head *);
 extern void	 journal_invalidatepage(journal_t *,
-				struct page *, sector_t);
+				struct page *, unsigned long);
 extern int	 journal_try_to_free_buffers(journal_t *, struct page *, gfp_t);
 extern int	 journal_stop(handle_t *);
 extern int	 journal_flush (journal_t *);
@@ -905,7 +905,7 @@ extern void	 journal_unlock_updates (jou
 
 extern journal_t * journal_init_dev(struct block_device *bdev,
 				struct block_device *fs_dev,
-				sector_t start, sector_t len, int bsize);
+				sector_t start, int len, int bsize);
 extern journal_t * journal_init_inode (struct inode *);
 extern int	   journal_update_format (journal_t *);
 extern int	   journal_check_used_features 
@@ -926,7 +926,7 @@ extern void	   journal_abort      (journ
 extern int	   journal_errno      (journal_t *);
 extern void	   journal_ack_err    (journal_t *);
 extern int	   journal_clear_err  (journal_t *);
-extern int	   journal_bmap(journal_t *, sector_t, sector_t *);
+extern int	   journal_bmap(journal_t *, unsigned long, sector_t *);
 extern int	   journal_force_commit(journal_t *);
 
 /*
@@ -959,8 +959,7 @@ extern void	   journal_destroy_revoke_ca
 extern int	   journal_init_revoke_caches(void);
 
 extern void	   journal_destroy_revoke(journal_t *);
-extern int	   journal_revoke (handle_t *,
-				sector_t, struct buffer_head *);
+extern int	   journal_revoke (handle_t *, sector_t, struct buffer_head *);
 extern int	   journal_cancel_revoke(handle_t *, struct journal_head *);
 extern void	   journal_write_revoke_records(journal_t *, transaction_t *);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.