x86[-64]:Remove 'volatile' from atomic_t
[safe/jmp/linux-2.6] / fs / ext4 / balloc.c
index 357e4e5..5d45582 100644 (file)
@@ -14,9 +14,9 @@
 #include <linux/time.h>
 #include <linux/capability.h>
 #include <linux/fs.h>
-#include <linux/jbd.h>
+#include <linux/jbd2.h>
 #include <linux/ext4_fs.h>
-#include <linux/ext4_jbd.h>
+#include <linux/ext4_jbd2.h>
 #include <linux/quotaops.h>
 #include <linux/buffer_head.h>
 
  */
 
 /*
+ * Calculate the block group number and offset, given a block number
+ */
+void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
+               unsigned long *blockgrpp, ext4_grpblk_t *offsetp)
+{
+        struct ext4_super_block *es = EXT4_SB(sb)->s_es;
+       ext4_grpblk_t offset;
+
+        blocknr = blocknr - le32_to_cpu(es->s_first_data_block);
+       offset = do_div(blocknr, EXT4_BLOCKS_PER_GROUP(sb));
+       if (offsetp)
+               *offsetp = offset;
+       if (blockgrpp)
+               *blockgrpp = blocknr;
+
+}
+
+/*
  * The free blocks are managed by bitmaps.  A file system contains several
  * blocks groups.  Each group contains 1 bitmap block for blocks, 1 bitmap
  * block for inodes, N blocks for the inode table and data blocks.
@@ -74,10 +92,12 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
                return NULL;
        }
 
-       desc = (struct ext4_group_desc *) sbi->s_group_desc[group_desc]->b_data;
+       desc = (struct ext4_group_desc *)(
+               (__u8 *)sbi->s_group_desc[group_desc]->b_data +
+               offset * EXT4_DESC_SIZE(sb));
        if (bh)
                *bh = sbi->s_group_desc[group_desc];
-       return desc + offset;
+       return desc;
 }
 
 /**
@@ -99,12 +119,13 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
        desc = ext4_get_group_desc (sb, block_group, NULL);
        if (!desc)
                goto error_out;
-       bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
+       bh = sb_bread(sb, ext4_block_bitmap(sb, desc));
        if (!bh)
                ext4_error (sb, "read_block_bitmap",
                            "Cannot read block bitmap - "
-                           "block_group = %d, block_bitmap = %u",
-                           block_group, le32_to_cpu(desc->bg_block_bitmap));
+                           "block_group = %d, block_bitmap = %llu",
+                           block_group,
+                           ext4_block_bitmap(sb, desc));
 error_out:
        return bh;
 }
@@ -147,7 +168,7 @@ restart:
                rsv = list_entry(n, struct ext4_reserve_window_node, rsv_node);
                if (verbose)
                        printk("reservation window 0x%p "
-                              "start:  %lu, end:  %lu\n",
+                              "start:  %llu, end:  %llu\n",
                               rsv, rsv->rsv_start, rsv->rsv_end);
                if (rsv->rsv_start && rsv->rsv_start >= rsv->rsv_end) {
                        printk("Bad reservation %p (start >= end)\n",
@@ -432,21 +453,18 @@ void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
        es = sbi->s_es;
        if (block < le32_to_cpu(es->s_first_data_block) ||
            block + count < block ||
-           block + count > le32_to_cpu(es->s_blocks_count)) {
+           block + count > ext4_blocks_count(es)) {
                ext4_error (sb, "ext4_free_blocks",
                            "Freeing blocks not in datazone - "
-                           "block = "E3FSBLK", count = %lu", block, count);
+                           "block = %llu, count = %lu", block, count);
                goto error_return;
        }
 
-       ext4_debug ("freeing block(s) %lu-%lu\n", block, block + count - 1);
+       ext4_debug ("freeing block(s) %llu-%llu\n", block, block + count - 1);
 
 do_more:
        overflow = 0;
-       block_group = (block - le32_to_cpu(es->s_first_data_block)) /
-                     EXT4_BLOCKS_PER_GROUP(sb);
-       bit = (block - le32_to_cpu(es->s_first_data_block)) %
-                     EXT4_BLOCKS_PER_GROUP(sb);
+       ext4_get_group_no_and_offset(sb, block, &block_group, &bit);
        /*
         * Check to see if we are freeing blocks across a group
         * boundary.
@@ -463,15 +481,14 @@ do_more:
        if (!desc)
                goto error_return;
 
-       if (in_range (le32_to_cpu(desc->bg_block_bitmap), block, count) ||
-           in_range (le32_to_cpu(desc->bg_inode_bitmap), block, count) ||
-           in_range (block, le32_to_cpu(desc->bg_inode_table),
-                     sbi->s_itb_per_group) ||
-           in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
-                     sbi->s_itb_per_group))
+       if (in_range(ext4_block_bitmap(sb, desc), block, count) ||
+           in_range(ext4_inode_bitmap(sb, desc), block, count) ||
+           in_range(block, ext4_inode_table(sb, desc), sbi->s_itb_per_group) ||
+           in_range(block + count - 1, ext4_inode_table(sb, desc),
+                    sbi->s_itb_per_group))
                ext4_error (sb, "ext4_free_blocks",
                            "Freeing blocks in system zones - "
-                           "Block = "E3FSBLK", count = %lu",
+                           "Block = %llu, count = %lu",
                            block, count);
 
        /*
@@ -526,12 +543,12 @@ do_more:
                 * transaction.
                 *
                 * Ideally we would want to allow that to happen, but to
-                * do so requires making journal_forget() capable of
+                * do so requires making jbd2_journal_forget() capable of
                 * revoking the queued write of a data block, which
                 * implies blocking on the journal lock.  *forget()
                 * cannot block due to truncate races.
                 *
-                * Eventually we can fix this by making journal_forget()
+                * Eventually we can fix this by making jbd2_journal_forget()
                 * return a status indicating whether or not it was able
                 * to revoke the buffer.  On successful revoke, it is
                 * safe not to set the allocation bit in the committed
@@ -555,8 +572,8 @@ do_more:
                                                bit + i, bitmap_bh->b_data)) {
                        jbd_unlock_bh_state(bitmap_bh);
                        ext4_error(sb, __FUNCTION__,
-                               "bit already cleared for block "E3FSBLK,
-                                block + i);
+                                  "bit already cleared for block %llu",
+                                  (ext4_fsblk_t)(block + i));
                        jbd_lock_bh_state(bitmap_bh);
                        BUFFER_TRACE(bitmap_bh, "bit already cleared");
                } else {
@@ -1354,7 +1371,7 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
        ext4_fsblk_t free_blocks, root_blocks;
 
        free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
-       root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
+       root_blocks = ext4_r_blocks_count(sbi->s_es);
        if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
                sbi->s_resuid != current->fsuid &&
                (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
@@ -1382,7 +1399,7 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
 
        jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
 
-       return journal_force_commit_nested(EXT4_SB(sb)->s_journal);
+       return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
 }
 
 /**
@@ -1404,7 +1421,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
 {
        struct buffer_head *bitmap_bh = NULL;
        struct buffer_head *gdp_bh;
-       int group_no;
+       unsigned long group_no;
        int goal_group;
        ext4_grpblk_t grp_target_blk;   /* blockgroup relative goal block */
        ext4_grpblk_t grp_alloc_blk;    /* blockgroup-relative allocated block*/
@@ -1465,10 +1482,9 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
         * First, test whether the goal block is free.
         */
        if (goal < le32_to_cpu(es->s_first_data_block) ||
-           goal >= le32_to_cpu(es->s_blocks_count))
+           goal >= ext4_blocks_count(es))
                goal = le32_to_cpu(es->s_first_data_block);
-       group_no = (goal - le32_to_cpu(es->s_first_data_block)) /
-                       EXT4_BLOCKS_PER_GROUP(sb);
+       ext4_get_group_no_and_offset(sb, goal, &group_no, &grp_target_blk);
        goal_group = group_no;
 retry_alloc:
        gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
@@ -1485,8 +1501,6 @@ retry_alloc:
                my_rsv = NULL;
 
        if (free_blocks > 0) {
-               grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) %
-                               EXT4_BLOCKS_PER_GROUP(sb));
                bitmap_bh = read_block_bitmap(sb, group_no);
                if (!bitmap_bh)
                        goto io_error;
@@ -1567,15 +1581,15 @@ allocated:
 
        ret_block = grp_alloc_blk + ext4_group_first_block_no(sb, group_no);
 
-       if (in_range(le32_to_cpu(gdp->bg_block_bitmap), ret_block, num) ||
-           in_range(le32_to_cpu(gdp->bg_inode_bitmap), ret_block, num) ||
-           in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
-                     EXT4_SB(sb)->s_itb_per_group) ||
-           in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
-                     EXT4_SB(sb)->s_itb_per_group))
+       if (in_range(ext4_block_bitmap(sb, gdp), ret_block, num) ||
+           in_range(ext4_block_bitmap(sb, gdp), ret_block, num) ||
+           in_range(ret_block, ext4_inode_table(sb, gdp),
+                    EXT4_SB(sb)->s_itb_per_group) ||
+           in_range(ret_block + num - 1, ext4_inode_table(sb, gdp),
+                    EXT4_SB(sb)->s_itb_per_group))
                ext4_error(sb, "ext4_new_block",
                            "Allocating block in system zone - "
-                           "blocks from "E3FSBLK", length %lu",
+                           "blocks from %llu, length %lu",
                             ret_block, num);
 
        performed_allocation = 1;
@@ -1610,11 +1624,11 @@ allocated:
        jbd_unlock_bh_state(bitmap_bh);
 #endif
 
-       if (ret_block + num - 1 >= le32_to_cpu(es->s_blocks_count)) {
+       if (ret_block + num - 1 >= ext4_blocks_count(es)) {
                ext4_error(sb, "ext4_new_block",
-                           "block("E3FSBLK") >= blocks count(%d) - "
-                           "block_group = %d, es == %p ", ret_block,
-                       le32_to_cpu(es->s_blocks_count), group_no, es);
+                           "block(%llu) >= blocks count(%llu) - "
+                           "block_group = %lu, es == %p ", ret_block,
+                       ext4_blocks_count(es), group_no, es);
                goto out;
        }
 
@@ -1711,9 +1725,9 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
                bitmap_count += x;
        }
        brelse(bitmap_bh);
-       printk("ext4_count_free_blocks: stored = "E3FSBLK
-               ", computed = "E3FSBLK", "E3FSBLK"\n",
-              le32_to_cpu(es->s_free_blocks_count),
+       printk("ext4_count_free_blocks: stored = %llu"
+               ", computed = %llu, %llu\n",
+              EXT4_FREE_BLOCKS_COUNT(es),
                desc_count, bitmap_count);
        return bitmap_count;
 #else
@@ -1733,9 +1747,10 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
 static inline int
 block_in_use(ext4_fsblk_t block, struct super_block *sb, unsigned char *map)
 {
-       return ext4_test_bit ((block -
-               le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) %
-                        EXT4_BLOCKS_PER_GROUP(sb), map);
+       ext4_grpblk_t offset;
+
+       ext4_get_group_no_and_offset(sb, block, NULL, &offset);
+       return ext4_test_bit (offset, map);
 }
 
 static inline int test_root(int a, int b)