fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / jbd / recovery.c
index 8f19712..11563fe 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * linux/fs/recovery.c
- * 
+ *
  * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
  *
  * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
@@ -10,7 +10,7 @@
  * option, any later version, incorporated herein by reference.
  *
  * Journal recovery routines for the generic filesystem journaling code;
- * part of the ext2fs journaling system.  
+ * part of the ext2fs journaling system.
  */
 
 #ifndef __KERNEL__
@@ -25,9 +25,9 @@
 
 /*
  * Maintain information about the progress of the recovery job, so that
- * the different passes can carry information between them. 
+ * the different passes can carry information between them.
  */
-struct recovery_info 
+struct recovery_info
 {
        tid_t           start_transaction;
        tid_t           end_transaction;
@@ -46,7 +46,7 @@ static int scan_revoke_records(journal_t *, struct buffer_head *,
 #ifdef __KERNEL__
 
 /* Release readahead buffers after use */
-void journal_brelse_array(struct buffer_head *b[], int n)
+static void journal_brelse_array(struct buffer_head *b[], int n)
 {
        while (--n >= 0)
                brelse (b[n]);
@@ -116,7 +116,7 @@ static int do_readahead(journal_t *journal, unsigned int start)
        err = 0;
 
 failed:
-       if (nbufs) 
+       if (nbufs)
                journal_brelse_array(bufs, nbufs);
        return err;
 }
@@ -128,7 +128,7 @@ failed:
  * Read a block from the journal
  */
 
-static int jread(struct buffer_head **bhp, journal_t *journal, 
+static int jread(struct buffer_head **bhp, journal_t *journal,
                 unsigned int offset)
 {
        int err;
@@ -191,10 +191,10 @@ static int count_tags(struct buffer_head *bh, int size)
 
                nr++;
                tagp += sizeof(journal_block_tag_t);
-               if (!(tag->t_flags & htonl(JFS_FLAG_SAME_UUID)))
+               if (!(tag->t_flags & cpu_to_be32(JFS_FLAG_SAME_UUID)))
                        tagp += 16;
 
-               if (tag->t_flags & htonl(JFS_FLAG_LAST_TAG))
+               if (tag->t_flags & cpu_to_be32(JFS_FLAG_LAST_TAG))
                        break;
        }
 
@@ -210,16 +210,16 @@ do {                                                                      \
 } while (0)
 
 /**
- * int journal_recover(journal_t *journal) - recovers a on-disk journal
+ * journal_recover - recovers a on-disk journal
  * @journal: the journal to recover
- * 
+ *
  * The primary function for recovering the log contents when mounting a
- * journaled device.  
+ * journaled device.
  *
  * Recovery is done in three passes.  In the first pass, we look for the
  * end of the log.  In the second, we assemble the list of revoke
  * blocks.  In the third and final pass, we replay any un-revoked blocks
- * in the log.  
+ * in the log.
  */
 int journal_recover(journal_t *journal)
 {
@@ -231,16 +231,16 @@ int journal_recover(journal_t *journal)
        memset(&info, 0, sizeof(info));
        sb = journal->j_superblock;
 
-       /* 
+       /*
         * The journal superblock's s_start field (the current log head)
         * is always zero if, and only if, the journal was cleanly
-        * unmounted.  
+        * unmounted.
         */
 
        if (!sb->s_start) {
                jbd_debug(1, "No recovery required, last transaction %d\n",
-                         ntohl(sb->s_sequence));
-               journal->j_transaction_sequence = ntohl(sb->s_sequence) + 1;
+                         be32_to_cpu(sb->s_sequence));
+               journal->j_transaction_sequence = be32_to_cpu(sb->s_sequence) + 1;
                return 0;
        }
 
@@ -253,7 +253,7 @@ int journal_recover(journal_t *journal)
        jbd_debug(0, "JBD: recovery, exit status %d, "
                  "recovered transactions %u to %u\n",
                  err, info.start_transaction, info.end_transaction);
-       jbd_debug(0, "JBD: Replayed %d and revoked %d/%d blocks\n", 
+       jbd_debug(0, "JBD: Replayed %d and revoked %d/%d blocks\n",
                  info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
 
        /* Restart the log at the next transaction ID, thus invalidating
@@ -266,17 +266,17 @@ int journal_recover(journal_t *journal)
 }
 
 /**
- * int journal_skip_recovery() - Start journal and wipe exiting records 
+ * journal_skip_recovery - Start journal and wipe exiting records
  * @journal: journal to startup
- * 
+ *
  * Locate any valid recovery information from the journal and set up the
  * journal structures in memory to ignore it (presumably because the
- * caller has evidence that it is out of date).  
+ * caller has evidence that it is out of date).
  * This function does'nt appear to be exorted..
  *
  * We perform one pass over the journal to allow us to tell the user how
  * much recovery information is being erased, and to let us initialise
- * the journal transaction sequence numbers to the next unused ID. 
+ * the journal transaction sequence numbers to the next unused ID.
  */
 int journal_skip_recovery(journal_t *journal)
 {
@@ -295,9 +295,9 @@ int journal_skip_recovery(journal_t *journal)
                ++journal->j_transaction_sequence;
        } else {
 #ifdef CONFIG_JBD_DEBUG
-               int dropped = info.end_transaction - ntohl(sb->s_sequence);
+               int dropped = info.end_transaction - be32_to_cpu(sb->s_sequence);
 #endif
-               jbd_debug(0, 
+               jbd_debug(0,
                          "JBD: ignoring %d transaction%s from the journal.\n",
                          dropped, (dropped == 1) ? "" : "s");
                journal->j_transaction_sequence = ++info.end_transaction;
@@ -314,7 +314,7 @@ static int do_one_pass(journal_t *journal,
        unsigned long           next_log_block;
        int                     err, success = 0;
        journal_superblock_t *  sb;
-       journal_header_t *      tmp;
+       journal_header_t *      tmp;
        struct buffer_head *    bh;
        unsigned int            sequence;
        int                     blocktype;
@@ -324,15 +324,15 @@ static int do_one_pass(journal_t *journal,
        MAX_BLOCKS_PER_DESC = ((journal->j_blocksize-sizeof(journal_header_t))
                               / sizeof(journal_block_tag_t));
 
-       /* 
+       /*
         * First thing is to establish what we expect to find in the log
         * (in terms of transaction IDs), and where (in terms of log
-        * block offsets): query the superblock.  
+        * block offsets): query the superblock.
         */
 
        sb = journal->j_superblock;
-       next_commit_ID = ntohl(sb->s_sequence);
-       next_log_block = ntohl(sb->s_start);
+       next_commit_ID = be32_to_cpu(sb->s_sequence);
+       next_log_block = be32_to_cpu(sb->s_start);
 
        first_commit_ID = next_commit_ID;
        if (pass == PASS_SCAN)
@@ -344,7 +344,7 @@ static int do_one_pass(journal_t *journal,
         * Now we walk through the log, transaction by transaction,
         * making sure that each transaction has a commit block in the
         * expected place.  Each complete transaction gets replayed back
-        * into the main filesystem. 
+        * into the main filesystem.
         */
 
        while (1) {
@@ -354,6 +354,8 @@ static int do_one_pass(journal_t *journal,
                struct buffer_head *    obh;
                struct buffer_head *    nbh;
 
+               cond_resched();         /* We're under lock_kernel() */
+
                /* If we already know where to stop the log traversal,
                 * check right now that we haven't gone past the end of
                 * the log. */
@@ -377,22 +379,22 @@ static int do_one_pass(journal_t *journal,
                next_log_block++;
                wrap(journal, next_log_block);
 
-               /* What kind of buffer is it? 
-                * 
+               /* What kind of buffer is it?
+                *
                 * If it is a descriptor block, check that it has the
                 * expected sequence number.  Otherwise, we're all done
                 * here. */
 
                tmp = (journal_header_t *)bh->b_data;
 
-               if (tmp->h_magic != htonl(JFS_MAGIC_NUMBER)) {
+               if (tmp->h_magic != cpu_to_be32(JFS_MAGIC_NUMBER)) {
                        brelse(bh);
                        break;
                }
 
-               blocktype = ntohl(tmp->h_blocktype);
-               sequence = ntohl(tmp->h_sequence);
-               jbd_debug(3, "Found magic %d, sequence %d\n", 
+               blocktype = be32_to_cpu(tmp->h_blocktype);
+               sequence = be32_to_cpu(tmp->h_sequence);
+               jbd_debug(3, "Found magic %d, sequence %d\n",
                          blocktype, sequence);
 
                if (sequence != next_commit_ID) {
@@ -427,7 +429,7 @@ static int do_one_pass(journal_t *journal,
                                unsigned long io_block;
 
                                tag = (journal_block_tag_t *) tagp;
-                               flags = ntohl(tag->t_flags);
+                               flags = be32_to_cpu(tag->t_flags);
 
                                io_block = next_log_block++;
                                wrap(journal, next_log_block);
@@ -436,7 +438,7 @@ static int do_one_pass(journal_t *journal,
                                        /* Recover what we can, but
                                         * report failure at the end. */
                                        success = err;
-                                       printk (KERN_ERR 
+                                       printk (KERN_ERR
                                                "JBD: IO error %d recovering "
                                                "block %ld in log\n",
                                                err, io_block);
@@ -444,13 +446,13 @@ static int do_one_pass(journal_t *journal,
                                        unsigned long blocknr;
 
                                        J_ASSERT(obh != NULL);
-                                       blocknr = ntohl(tag->t_blocknr);
+                                       blocknr = be32_to_cpu(tag->t_blocknr);
 
                                        /* If the block has been
                                         * revoked, then we're all done
                                         * here. */
                                        if (journal_test_revoke
-                                           (journal, blocknr, 
+                                           (journal, blocknr,
                                             next_commit_ID)) {
                                                brelse(obh);
                                                ++info->nr_revoke_hits;
@@ -463,7 +465,7 @@ static int do_one_pass(journal_t *journal,
                                                        blocknr,
                                                        journal->j_blocksize);
                                        if (nbh == NULL) {
-                                               printk(KERN_ERR 
+                                               printk(KERN_ERR
                                                       "JBD: Out of memory "
                                                       "during recovery.\n");
                                                err = -ENOMEM;
@@ -476,8 +478,8 @@ static int do_one_pass(journal_t *journal,
                                        memcpy(nbh->b_data, obh->b_data,
                                                        journal->j_blocksize);
                                        if (flags & JFS_FLAG_ESCAPE) {
-                                               *((unsigned int *)bh->b_data) =
-                                                       htonl(JFS_MAGIC_NUMBER);
+                                               *((__be32 *)bh->b_data) =
+                                               cpu_to_be32(JFS_MAGIC_NUMBER);
                                        }
 
                                        BUFFER_TRACE(nbh, "marking dirty");
@@ -529,12 +531,13 @@ static int do_one_pass(journal_t *journal,
                default:
                        jbd_debug(3, "Unrecognised magic %d, end of scan.\n",
                                  blocktype);
+                       brelse(bh);
                        goto done;
                }
        }
 
  done:
-       /* 
+       /*
         * We broke out of the log scan loop: either we came to the
         * known end of the log or we found an unexpected block in the
         * log.  If the latter happened, then we know that the "current"
@@ -564,7 +567,7 @@ static int do_one_pass(journal_t *journal,
 
 /* Scan a revoke record, marking all blocks mentioned as revoked. */
 
-static int scan_revoke_records(journal_t *journal, struct buffer_head *bh, 
+static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
                               tid_t sequence, struct recovery_info *info)
 {
        journal_revoke_header_t *header;
@@ -572,13 +575,13 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
 
        header = (journal_revoke_header_t *) bh->b_data;
        offset = sizeof(journal_revoke_header_t);
-       max = ntohl(header->r_count);
+       max = be32_to_cpu(header->r_count);
 
        while (offset < max) {
                unsigned long blocknr;
                int err;
 
-               blocknr = ntohl(* ((unsigned int *) (bh->b_data+offset)));
+               blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset)));
                offset += 4;
                err = journal_set_revoke(journal, blocknr, sequence);
                if (err)