Whamcloud - gitweb
b=21671 Eliminate a warning for the ldiskfs module
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-mballoc-extra-checks-rhel5.patch
index b8cdada..45e95bb 100644 (file)
@@ -1,7 +1,17 @@
-Index: linux-2.6.18.i686/fs/ext4/mballoc.c
-===================================================================
---- linux-2.6.18.i686.orig/fs/ext4/mballoc.c
-+++ linux-2.6.18.i686/fs/ext4/mballoc.c
+diff -rupN linux-2.6.18-128.1.6_1//fs/ext4/mballoc.c linux-2.6.18-128.1.6_2//fs/ext4/mballoc.c
+--- linux-2.6.18-128.1.6_1//fs/ext4/mballoc.c
++++ linux-2.6.18-128.1.6_2//fs/ext4/mballoc.c
+@@ -360,8 +360,8 @@ static void ext4_mb_mark_free_simple(str
+ static struct kmem_cache *ext4_pspace_cachep;
+ static struct kmem_cache *ext4_ac_cachep;
+ static struct kmem_cache *ext4_free_ext_cachep;
+-static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
+-                                      ext4_group_t group);
++static int ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
++                                      ext4_group_t group);
+ static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap,
+                                                ext4_group_t group);
 @@ -660,7 +660,7 @@ static void ext4_mb_mark_free_simple(str
        }
  }
@@ -15,8 +25,8 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        grp->bb_fragments = fragments;
  
        if (free != grp->bb_free) {
--              ext4_error(sb, __func__,
--                      "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n",
+-              ext4_grp_locked_error(sb, group,  __func__,
+-                      "EXT4-fs: group %u: %u blocks in bitmap, %u in gd",
 -                      group, free, grp->bb_free);
 -              /*
 -               * If we intent to continue, we consider group descritor
@@ -27,8 +37,8 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
 +              gdp = ext4_get_group_desc (sb, group, NULL);
 +              ext4_error(sb, __FUNCTION__,
 +                      "group %lu: %u blocks in bitmap, %u in bb, "
-+                      "%u in gd, %lu pa's\n", group, free, grp->bb_free,
-+                      le16_to_cpu(gdp->bg_free_blocks_count),
++                      "%u in gd, %lu pa's\n", (long unsigned int)group,
++                      free, grp->bb_free, ext4_free_blks_count(sb, gdp),
 +                      grp->bb_prealloc_nr);
 +              return -EIO;
        }
@@ -44,32 +54,32 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
  
  /* The buddy information is attached the buddy cache inode
 @@ -814,7 +816,7 @@ static int ext4_mb_init_cache(struct pag
-       err = 0;
        first_block = page->index * blocks_per_page;
+       /* init the page  */
+       memset(page_address(page), 0xff, PAGE_CACHE_SIZE);
 -      for (i = 0; i < blocks_per_page; i++) {
 +      for (i = 0; i < blocks_per_page && err == 0; i++) {
                int group;
                struct ext4_group_info *grinfo;
  
 @@ -848,7 +850,7 @@ static int ext4_mb_init_cache(struct pag
-                       /*
                         * incore got set to the group block bitmap below
                         */
+                       ext4_lock_group(sb, group);
 -                      ext4_mb_generate_buddy(sb, data, incore, group);
 +                      err = ext4_mb_generate_buddy(sb, data, incore, group);
+                       ext4_unlock_group(sb, group);
                        incore = NULL;
                } else {
-                       /* this is block of bitmap */
 @@ -861,7 +863,7 @@ static int ext4_mb_init_cache(struct pag
                        memcpy(data, bitmap, blocksize);
  
                        /* mark all preallocated blks used in in-core bitmap */
 -                      ext4_mb_generate_from_pa(sb, data, group);
 +                      err = ext4_mb_generate_from_pa(sb, data, group);
+                       ext4_mb_generate_from_freelist(sb, data, group);
                        ext4_unlock_group(sb, group);
  
-                       /* set incore so that the buddy information can be
 @@ -870,6 +872,7 @@ static int ext4_mb_init_cache(struct pag
                        incore = data;
                }
@@ -94,7 +104,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
  {
        struct super_block *sb = seq->private;
 +      struct ext4_group_desc *gdp;
-       long group = (long) v;
+       ext4_group_t group = (ext4_group_t) ((unsigned long) v);
        int i;
        int err;
 +      int free = 0;
@@ -121,17 +131,17 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
 +
 +      gdp = ext4_get_group_desc(sb, group, NULL);
 +      if (gdp != NULL)
-+              free = le16_to_cpu(gdp->bg_free_blocks_count);
++              free = ext4_free_blks_count(sb, gdp);
 +
        ext4_lock_group(sb, group);
        memcpy(&sg, ext4_get_group_info(sb, group), i);
        ext4_unlock_group(sb, group);
        ext4_mb_release_desc(&e4b);
  
--      seq_printf(seq, "#%-5lu: %-5u %-5u %-5u [", group, sg.info.bb_free,
+-      seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
 -                      sg.info.bb_fragments, sg.info.bb_first_free);
-+      seq_printf(seq, "#%-5lu: %-5u %-5u %-5u %-5u %-5lu [", group,
-+                      sg.info.bb_free, free,
++      seq_printf(seq, "#%-5lu: %-5u %-5u %-5u %-5u %-5lu [",
++                      (long unsigned int)group, sg.info.bb_free, free,
 +                      sg.info.bb_fragments, sg.info.bb_first_free,
 +                      sg.info.bb_prealloc_nr);
        for (i = 0; i <= 13; i++)
@@ -145,13 +155,14 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        if (ac->ac_op == EXT4_MB_HISTORY_ALLOC) {
                if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
                                ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
-@@ -3531,22 +3547,66 @@ ext4_mb_use_preallocated(struct ext4_all
+@@ -3539,22 +3555,67 @@ ext4_mb_use_preallocated(struct ext4_all
  }
  
  /*
 + * check free blocks in bitmap match free block in group descriptor
 + * do this before taking preallocated blocks into account to be able
-+ * to detect on-disk corruptions
++ * to detect on-disk corruptions. The group lock should be hold by the
++ * caller.
 + */
 +int ext4_mb_check_ondisk_bitmap(struct super_block *sb, void *bitmap,
 +                              struct ext4_group_desc *gdp, int group)
@@ -163,7 +174,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
 +
 +      while (i < max) {
 +              first = i;
-+              i = find_next_bit(bitmap, max, i);
++              i = mb_find_next_bit(bitmap, max, i);
 +              if (i > max)
 +                      i = max;
 +              free += i - first;
@@ -171,10 +182,10 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
 +                      i = mb_find_next_zero_bit(bitmap, max, i);
 +      }
 +
-+      if (free != le16_to_cpu(gdp->bg_free_blocks_count)) {
++      if (free != ext4_free_blks_count(sb, gdp)) {
 +              ext4_error(sb, __FUNCTION__, "on-disk bitmap for group %d"
 +                      "corrupted: %u blocks free in bitmap, %u - in gd\n",
-+                      group, free, le16_to_cpu(gdp->bg_free_blocks_count));
++                      group, free, ext4_free_blks_count(sb, gdp));
 +              return -EIO;
 +      }
 +      return 0;
@@ -213,7 +224,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        /* all form of preallocation discards first load group,
         * so the only competing code is preallocation use.
         * we don't need any locking here
-@@ -3562,15 +3622,24 @@ static void ext4_mb_generate_from_pa(str
+@@ -3570,15 +3631,24 @@ static void ext4_mb_generate_from_pa(str
                                             &groupnr, &start);
                len = pa->pa_len;
                spin_unlock(&pa->pa_lock);
@@ -234,12 +245,12 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
 +                         count, grp->bb_prealloc_nr, skip);
 +              return -EIO;
 +      }
-       mb_debug("prellocated %u for group %lu\n", preallocated, group);
+       mb_debug("prellocated %u for group %u\n", preallocated, group);
 +      return 0;
  }
  
  static void ext4_mb_pa_callback(struct rcu_head *head)
-@@ -3621,6 +3690,7 @@ static void ext4_mb_put_pa(struct ext4_a
+@@ -3629,6 +3699,7 @@ static void ext4_mb_put_pa(struct ext4_a
         */
        ext4_lock_group(sb, grp);
        list_del(&pa->pa_group_list);
@@ -247,7 +258,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        ext4_unlock_group(sb, grp);
  
        spin_lock(pa->pa_obj_lock);
-@@ -3709,6 +3779,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
+@@ -3717,6 +3788,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
  
        ext4_lock_group(sb, ac->ac_b_ex.fe_group);
        list_add(&pa->pa_group_list, &grp->bb_prealloc_list);
@@ -255,7 +266,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
  
        spin_lock(pa->pa_obj_lock);
-@@ -3768,6 +3839,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
+@@ -3776,6 +3848,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
  
        ext4_lock_group(sb, ac->ac_b_ex.fe_group);
        list_add(&pa->pa_group_list, &grp->bb_prealloc_list);
@@ -263,7 +274,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
  
        /*
-@@ -3820,6 +3892,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
+@@ -3828,6 +3901,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
                ac->ac_sb = sb;
                ac->ac_inode = pa->pa_inode;
                ac->ac_op = EXT4_MB_HISTORY_DISCARD;
@@ -271,7 +282,7 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
        }
  
        while (bit < end) {
-@@ -3964,6 +4037,8 @@ repeat:
+@@ -3972,6 +4046,8 @@ repeat:
  
                spin_unlock(&pa->pa_lock);
  
@@ -280,16 +291,16 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
                list_del(&pa->pa_group_list);
                list_add(&pa->u.pa_tmp_list, &list);
        }
-@@ -4099,7 +4174,7 @@ repeat:
+@@ -4107,7 +4183,7 @@ repeat:
                if (err) {
                        ext4_error(sb, __func__, "Error in loading buddy "
-                                       "information for %lu\n", group);
+                                       "information for %u", group);
 -                      continue;
 +                      return;
                }
  
                bitmap_bh = ext4_read_block_bitmap(sb, group);
-@@ -4111,6 +4186,8 @@ repeat:
+@@ -4119,6 +4195,8 @@ repeat:
                }
  
                ext4_lock_group(sb, group);
@@ -298,18 +309,29 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.c
                list_del(&pa->pa_group_list);
                ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac);
                ext4_unlock_group(sb, group);
-Index: linux-2.6.18.i686/fs/ext4/mballoc.h
-===================================================================
---- linux-2.6.18.i686.orig/fs/ext4/mballoc.h
-+++ linux-2.6.18.i686/fs/ext4/mballoc.h
+@@ -4394,6 +4472,7 @@ ext4_mb_discard_lg_preallocations(struct
+               }
+               ext4_lock_group(sb, group);
+               list_del(&pa->pa_group_list);
++              ext4_get_group_info(sb, group)->bb_prealloc_nr--;
+               ext4_mb_release_group_pa(&e4b, pa, ac);
+               ext4_unlock_group(sb, group);
+diff -rupN linux-2.6.18-128.1.6/fs/ext4/ext4.h
+--- linux-2.6.18-128.1.6.orig/fs/ext4/ext4.h
++++ linux-2.6.18-128.1.6/fs/ext4/ext4.h
 @@ -119,6 +119,7 @@ struct ext4_group_info {
-       unsigned short  bb_free;
-       unsigned short  bb_fragments;
-       struct          list_head bb_prealloc_list;
+       unsigned short  bb_free;
+       unsigned short  bb_fragments;
+       struct          list_head bb_prealloc_list;
 +      unsigned long   bb_prealloc_nr;
  #ifdef DOUBLE_CHECK
        void            *bb_bitmap;
  #endif
+Index: linux-2.6.18-128.1.6/fs/ext4/mballoc.h
+===================================================================
+--- linux-2.6.18-128.1.6.orig/fs/ext4/mballoc.h
++++ linux-2.6.18-128.1.6/fs/ext4/mballoc.h
 @@ -228,7 +229,7 @@ struct ext4_mb_history {
        __u16 tail;     /* what tail broke some buddy */
        __u16 buddy;    /* buddy the tail ^^^ broke */
@@ -319,12 +341,3 @@ Index: linux-2.6.18.i686/fs/ext4/mballoc.h
        __u8 op:4;
        __u8 merged:1;
  };
-@@ -259,7 +260,7 @@ static void ext4_mb_store_history(struct
- struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t);
--static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
-+static int ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
-                                       ext4_group_t group);
- static void ext4_mb_poll_new_transaction(struct super_block *, handle_t *);
- static void ext4_mb_free_committed_blocks(struct super_block *);