]> err.no Git - linux-2.6/blobdiff - fs/ext3/balloc.c
Pull bugzilla-5653 into release branch
[linux-2.6] / fs / ext3 / balloc.c
index bba4aeb4a708e1198422a8835a2b496f6361328f..77927d6938f61d369e0f64f4bfec1637d2ebd203 100644 (file)
@@ -1011,6 +1011,31 @@ retry:
        goto retry;
 }
 
+static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
+                       struct super_block *sb, int size)
+{
+       struct ext3_reserve_window_node *next_rsv;
+       struct rb_node *next;
+       spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock;
+
+       if (!spin_trylock(rsv_lock))
+               return;
+
+       next = rb_next(&my_rsv->rsv_node);
+
+       if (!next)
+               my_rsv->rsv_end += size;
+       else {
+               next_rsv = list_entry(next, struct ext3_reserve_window_node, rsv_node);
+
+               if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size)
+                       my_rsv->rsv_end += size;
+               else
+                       my_rsv->rsv_end = next_rsv->rsv_start - 1;
+       }
+       spin_unlock(rsv_lock);
+}
+
 /*
  * This is the main function used to allocate a new block and its reservation
  * window.
@@ -1095,6 +1120,8 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
        while (1) {
                if (rsv_is_empty(&my_rsv->rsv_window) || (ret < 0) ||
                        !goal_in_my_reservation(&my_rsv->rsv_window, goal, group, sb)) {
+                       if (my_rsv->rsv_goal_size < *count)
+                               my_rsv->rsv_goal_size = *count;
                        ret = alloc_new_reservation(my_rsv, goal, sb,
                                                        group, bitmap_bh);
                        if (ret < 0)
@@ -1102,7 +1129,10 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
 
                        if (!goal_in_my_reservation(&my_rsv->rsv_window, goal, group, sb))
                                goal = -1;
-               }
+               } else if (goal > 0 && (my_rsv->rsv_end-goal+1) < *count)
+                       try_to_extend_reservation(my_rsv, sb,
+                                       *count-my_rsv->rsv_end + goal - 1);
+
                if ((my_rsv->rsv_start >= group_first_block + EXT3_BLOCKS_PER_GROUP(sb))
                    || (my_rsv->rsv_end < group_first_block))
                        BUG();
@@ -1206,7 +1236,7 @@ int ext3_new_blocks(handle_t *handle, struct inode *inode,
        /*
         * Check quota for allocation of this block.
         */
-       if (DQUOT_ALLOC_BLOCK(inode, 1)) {
+       if (DQUOT_ALLOC_BLOCK(inode, num)) {
                *errp = -EDQUOT;
                return 0;
        }
@@ -1333,13 +1363,15 @@ allocated:
        target_block = ret_block + group_no * EXT3_BLOCKS_PER_GROUP(sb)
                                + le32_to_cpu(es->s_first_data_block);
 
-       if (target_block == le32_to_cpu(gdp->bg_block_bitmap) ||
-           target_block == le32_to_cpu(gdp->bg_inode_bitmap) ||
+       if (in_range(le32_to_cpu(gdp->bg_block_bitmap), target_block, num) ||
+           in_range(le32_to_cpu(gdp->bg_inode_bitmap), target_block, num) ||
            in_range(target_block, le32_to_cpu(gdp->bg_inode_table),
+                     EXT3_SB(sb)->s_itb_per_group) ||
+           in_range(target_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
                      EXT3_SB(sb)->s_itb_per_group))
                ext3_error(sb, "ext3_new_block",
                            "Allocating block in system zone - "
-                           "block = %u", target_block);
+                           "blocks from %u, length %lu", target_block, num);
 
        performed_allocation = 1;
 
@@ -1358,10 +1390,14 @@ allocated:
        jbd_lock_bh_state(bitmap_bh);
        spin_lock(sb_bgl_lock(sbi, group_no));
        if (buffer_jbd(bitmap_bh) && bh2jh(bitmap_bh)->b_committed_data) {
-               if (ext3_test_bit(ret_block,
-                               bh2jh(bitmap_bh)->b_committed_data)) {
-                       printk("%s: block was unexpectedly set in "
-                               "b_committed_data\n", __FUNCTION__);
+               int i;
+
+               for (i = 0; i < num; i++) {
+                       if (ext3_test_bit(ret_block,
+                                       bh2jh(bitmap_bh)->b_committed_data)) {
+                               printk("%s: block was unexpectedly set in "
+                                       "b_committed_data\n", __FUNCTION__);
+                       }
                }
        }
        ext3_debug("found bit %d\n", ret_block);
@@ -1372,7 +1408,7 @@ allocated:
        /* ret_block was blockgroup-relative.  Now it becomes fs-relative */
        ret_block = target_block;
 
-       if (ret_block >= le32_to_cpu(es->s_blocks_count)) {
+       if (ret_block + num - 1 >= le32_to_cpu(es->s_blocks_count)) {
                ext3_error(sb, "ext3_new_block",
                            "block(%d) >= blocks count(%d) - "
                            "block_group = %d, es == %p ", ret_block,
@@ -1390,9 +1426,9 @@ allocated:
 
        spin_lock(sb_bgl_lock(sbi, group_no));
        gdp->bg_free_blocks_count =
-                       cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) - 1);
+                       cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) - num);
        spin_unlock(sb_bgl_lock(sbi, group_no));
-       percpu_counter_mod(&sbi->s_freeblocks_counter, -1);
+       percpu_counter_mod(&sbi->s_freeblocks_counter, -num);
 
        BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
        err = ext3_journal_dirty_metadata(handle, gdp_bh);
@@ -1405,6 +1441,7 @@ allocated:
 
        *errp = 0;
        brelse(bitmap_bh);
+       DQUOT_FREE_BLOCK(inode, *count-num);
        *count = num;
        return ret_block;
 
@@ -1419,7 +1456,7 @@ out:
         * Undo the block allocation
         */
        if (!performed_allocation)
-               DQUOT_FREE_BLOCK(inode, 1);
+               DQUOT_FREE_BLOCK(inode, *count);
        brelse(bitmap_bh);
        return 0;
 }