reiserfs: Use lowercase names of quota functions
[linux-block.git] / fs / reiserfs / bitmap.c
index 2a5dd34649b34eb2c81275c57ef7afdf9a6ec781..f32d1425cc9fe58957906967a4f666009e97397f 100644 (file)
@@ -47,7 +47,9 @@
     test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
 
 static inline void get_bit_address(struct super_block *s,
-                                  b_blocknr_t block, int *bmap_nr, int *offset)
+                                  b_blocknr_t block,
+                                  unsigned int *bmap_nr,
+                                  unsigned int *offset)
 {
        /* It is in the bitmap block number equal to the block
         * number divided by the number of bits in a block. */
@@ -56,10 +58,10 @@ static inline void get_bit_address(struct super_block *s,
        *offset = block & ((s->s_blocksize << 3) - 1);
 }
 
-#ifdef CONFIG_REISERFS_CHECK
 int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
 {
-       int bmap, offset;
+       unsigned int bmap, offset;
+       unsigned int bmap_count = reiserfs_bmap_count(s);
 
        if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
                reiserfs_warning(s,
@@ -75,25 +77,26 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
        if (unlikely(test_bit(REISERFS_OLD_FORMAT,
                              &(REISERFS_SB(s)->s_properties)))) {
                b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
-               if (block >= bmap1 && block <= bmap1 + SB_BMAP_NR(s)) {
+               if (block >= bmap1 &&
+                   block <= bmap1 + bmap_count) {
                        reiserfs_warning(s, "vs: 4019: is_reusable: "
                                         "bitmap block %lu(%u) can't be freed or reused",
-                                        block, SB_BMAP_NR(s));
+                                        block, bmap_count);
                        return 0;
                }
        } else {
                if (offset == 0) {
                        reiserfs_warning(s, "vs: 4020: is_reusable: "
                                         "bitmap block %lu(%u) can't be freed or reused",
-                                        block, SB_BMAP_NR(s));
+                                        block, bmap_count);
                        return 0;
                }
        }
 
-       if (bmap >= SB_BMAP_NR(s)) {
+       if (bmap >= bmap_count) {
                reiserfs_warning(s,
                                 "vs-4030: is_reusable: there is no so many bitmap blocks: "
-                                "block=%lu, bitmap_nr=%d", block, bmap);
+                                "block=%lu, bitmap_nr=%u", block, bmap);
                return 0;
        }
 
@@ -106,12 +109,11 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
 
        return 1;
 }
-#endif                         /* CONFIG_REISERFS_CHECK */
 
 /* searches in journal structures for a given block number (bmap, off). If block
    is found in reiserfs journal it suggests next free block candidate to test. */
-static inline int is_block_in_journal(struct super_block *s, int bmap, int
-                                     off, int *next)
+static inline int is_block_in_journal(struct super_block *s, unsigned int bmap,
+                                     int off, int *next)
 {
        b_blocknr_t tmp;
 
@@ -132,8 +134,8 @@ static inline int is_block_in_journal(struct super_block *s, int bmap, int
 /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap
  * block; */
 static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
-                            int bmap_n, int *beg, int boundary, int min,
-                            int max, int unfm)
+                            unsigned int bmap_n, int *beg, int boundary,
+                            int min, int max, int unfm)
 {
        struct super_block *s = th->t_super;
        struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
@@ -143,8 +145,8 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
 
        BUG_ON(!th->t_trans_id);
 
-       RFALSE(bmap_n >= SB_BMAP_NR(s), "Bitmap %d is out of range (0..%d)",
-              bmap_n, SB_BMAP_NR(s) - 1);
+       RFALSE(bmap_n >= reiserfs_bmap_count(s), "Bitmap %u is out of "
+              "range (0..%u)", bmap_n, reiserfs_bmap_count(s) - 1);
        PROC_INFO_INC(s, scan_bitmap.bmap);
 /* this is unclear and lacks comments, explain how journal bitmaps
    work here for the reader.  Convey a sense of the design here. What
@@ -249,12 +251,12 @@ static int bmap_hash_id(struct super_block *s, u32 id)
        } else {
                hash_in = (char *)(&id);
                hash = keyed_hash(hash_in, 4);
-               bm = hash % SB_BMAP_NR(s);
+               bm = hash % reiserfs_bmap_count(s);
                if (!bm)
                        bm = 1;
        }
        /* this can only be true when SB_BMAP_NR = 1 */
-       if (bm >= SB_BMAP_NR(s))
+       if (bm >= reiserfs_bmap_count(s))
                bm = 0;
        return bm;
 }
@@ -270,10 +272,10 @@ static inline int block_group_used(struct super_block *s, u32 id)
 
        /* If we don't have cached information on this bitmap block, we're
         * going to have to load it later anyway. Loading it here allows us
-        * to make a better decision. This favors long-term performace gain
+        * to make a better decision. This favors long-term performance gain
         * with a better on-disk layout vs. a short term gain of skipping the
         * read and potentially having a bad placement. */
-       if (info->first_zero_hint == 0) {
+       if (info->free_count == UINT_MAX) {
                struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm);
                brelse(bh);
        }
@@ -309,16 +311,16 @@ __le32 reiserfs_choose_packing(struct inode * dir)
  * bitmap and place new blocks there. Returns number of allocated blocks. */
 static int scan_bitmap(struct reiserfs_transaction_handle *th,
                       b_blocknr_t * start, b_blocknr_t finish,
-                      int min, int max, int unfm, unsigned long file_block)
+                      int min, int max, int unfm, sector_t file_block)
 {
        int nr_allocated = 0;
        struct super_block *s = th->t_super;
        /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr
         * - Hans, it is not a block number - Zam. */
 
-       int bm, off;
-       int end_bm, end_off;
-       int off_max = s->s_blocksize << 3;
+       unsigned int bm, off;
+       unsigned int end_bm, end_off;
+       unsigned int off_max = s->s_blocksize << 3;
 
        BUG_ON(!th->t_trans_id);
 
@@ -328,10 +330,10 @@ static int scan_bitmap(struct reiserfs_transaction_handle *th,
 
        get_bit_address(s, *start, &bm, &off);
        get_bit_address(s, finish, &end_bm, &end_off);
-       if (bm > SB_BMAP_NR(s))
+       if (bm > reiserfs_bmap_count(s))
                return 0;
-       if (end_bm > SB_BMAP_NR(s))
-               end_bm = SB_BMAP_NR(s);
+       if (end_bm > reiserfs_bmap_count(s))
+               end_bm = reiserfs_bmap_count(s);
 
        /* When the bitmap is more than 10% free, anyone can allocate.
         * When it's less than 10% free, only files that already use the
@@ -385,7 +387,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
        struct reiserfs_super_block *rs;
        struct buffer_head *sbh, *bmbh;
        struct reiserfs_bitmap_info *apbi;
-       int nr, offset;
+       unsigned int nr, offset;
 
        BUG_ON(!th->t_trans_id);
 
@@ -397,10 +399,12 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
 
        get_bit_address(s, block, &nr, &offset);
 
-       if (nr >= sb_bmap_nr(rs)) {
+       if (nr >= reiserfs_bmap_count(s)) {
                reiserfs_warning(s, "vs-4075: reiserfs_free_block: "
-                                "block %lu is out of range on %s",
-                                block, reiserfs_bdevname(s));
+                                "block %lu is out of range on %s "
+                                "(nr=%u,max=%u)", block,
+                                reiserfs_bdevname(s), nr,
+                                reiserfs_bmap_count(s));
                return;
        }
 
@@ -426,7 +430,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
 
        journal_mark_dirty(th, s, sbh);
        if (for_unformatted)
-               DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
+               vfs_dq_free_block_nodirty(inode, 1);
 }
 
 void reiserfs_free_block(struct reiserfs_transaction_handle *th,
@@ -434,12 +438,19 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th,
                         int for_unformatted)
 {
        struct super_block *s = th->t_super;
-
        BUG_ON(!th->t_trans_id);
 
        RFALSE(!s, "vs-4061: trying to free block on nonexistent device");
-       RFALSE(is_reusable(s, block, 1) == 0,
-              "vs-4071: can not free such block");
+       if (!is_reusable(s, block, 1))
+               return;
+
+       if (block > sb_block_count(REISERFS_SB(s)->s_rs)) {
+               reiserfs_panic(th->t_super, "bitmap-4072",
+                              "Trying to free block outside file system "
+                              "boundaries (%lu > %lu)",
+                              block, sb_block_count(REISERFS_SB(s)->s_rs));
+               return;
+       }
        /* mark it before we clear it, just in case */
        journal_mark_freed(th, s, block);
        _reiserfs_free_block(th, inode, block, for_unformatted);
@@ -449,11 +460,11 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th,
 static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th,
                                         struct inode *inode, b_blocknr_t block)
 {
+       BUG_ON(!th->t_trans_id);
        RFALSE(!th->t_super,
               "vs-4060: trying to free block on nonexistent device");
-       RFALSE(is_reusable(th->t_super, block, 1) == 0,
-              "vs-4070: can not free such block");
-       BUG_ON(!th->t_trans_id);
+       if (!is_reusable(th->t_super, block, 1))
+               return;
        _reiserfs_free_block(th, inode, block, 1);
 }
 
@@ -468,7 +479,7 @@ static void __discard_prealloc(struct reiserfs_transaction_handle *th,
        if (ei->i_prealloc_count < 0)
                reiserfs_warning(th->t_super,
                                 "zam-4001:%s: inode has negative prealloc blocks count.",
-                                __FUNCTION__);
+                                __func__);
 #endif
        while (ei->i_prealloc_count > 0) {
                reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block);
@@ -506,7 +517,7 @@ void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th)
                if (!ei->i_prealloc_count) {
                        reiserfs_warning(th->t_super,
                                         "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.",
-                                        __FUNCTION__);
+                                        __func__);
                }
 #endif
                __discard_prealloc(th, ei);
@@ -621,7 +632,7 @@ int reiserfs_parse_alloc_options(struct super_block *s, char *options)
                }
 
                reiserfs_warning(s, "zam-4001: %s : unknown option - %s",
-                                __FUNCTION__, this_char);
+                                __func__, this_char);
                return 1;
        }
 
@@ -652,7 +663,7 @@ static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint)
 
 /*
  * Relocation based on dirid, hashing them into a given bitmap block
- * files. Formatted nodes are unaffected, a seperate policy covers them
+ * files. Formatted nodes are unaffected, a separate policy covers them
  */
 static void dirid_groups(reiserfs_blocknr_hint_t * hint)
 {
@@ -677,7 +688,7 @@ static void dirid_groups(reiserfs_blocknr_hint_t * hint)
 
 /*
  * Relocation based on oid, hashing them into a given bitmap block
- * files. Formatted nodes are unaffected, a seperate policy covers them
+ * files. Formatted nodes are unaffected, a separate policy covers them
  */
 static void oid_groups(reiserfs_blocknr_hint_t * hint)
 {
@@ -1044,7 +1055,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
                               amount_needed, hint->inode->i_uid);
 #endif
                quota_ret =
-                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
+                   vfs_dq_alloc_block_nodirty(hint->inode, amount_needed);
                if (quota_ret)  /* Quota exceeded? */
                        return QUOTA_EXCEEDED;
                if (hint->preallocate && hint->prealloc_size) {
@@ -1053,8 +1064,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
                                       "reiserquota: allocating (prealloc) %d blocks id=%u",
                                       hint->prealloc_size, hint->inode->i_uid);
 #endif
-                       quota_ret =
-                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
+                       quota_ret = vfs_dq_prealloc_block_nodirty(hint->inode,
                                                         hint->prealloc_size);
                        if (quota_ret)
                                hint->preallocate = hint->prealloc_size = 0;
@@ -1087,7 +1097,10 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
                                               nr_allocated,
                                               hint->inode->i_uid);
 #endif
-                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
+                               /* Free not allocated blocks */
+                               vfs_dq_free_block_nodirty(hint->inode,
+                                       amount_needed + hint->prealloc_size -
+                                       nr_allocated);
                        }
                        while (nr_allocated--)
                                reiserfs_free_block(hint->th, hint->inode,
@@ -1118,7 +1131,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
                               REISERFS_I(hint->inode)->i_prealloc_count,
                               hint->inode->i_uid);
 #endif
-               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
+               vfs_dq_free_block_nodirty(hint->inode, amount_needed +
                                         hint->prealloc_size - nr_allocated -
                                         REISERFS_I(hint->inode)->
                                         i_prealloc_count);
@@ -1207,27 +1220,22 @@ void reiserfs_cache_bitmap_metadata(struct super_block *sb,
 {
        unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size);
 
-       info->first_zero_hint = 1 << (sb->s_blocksize_bits + 3);
+       /* The first bit must ALWAYS be 1 */
+       BUG_ON(!reiserfs_test_le_bit(0, (unsigned long *)bh->b_data));
+
+       info->free_count = 0;
 
        while (--cur >= (unsigned long *)bh->b_data) {
-               int base = ((char *)cur - bh->b_data) << 3;
+               int i;
 
                /* 0 and ~0 are special, we can optimize for them */
-               if (*cur == 0) {
-                       info->first_zero_hint = base;
+               if (*cur == 0)
                        info->free_count += BITS_PER_LONG;
-               } else if (*cur != ~0L) {       /* A mix, investigate */
-                       int b;
-                       for (b = BITS_PER_LONG - 1; b >= 0; b--) {
-                               if (!reiserfs_test_le_bit(b, cur)) {
-                                       info->first_zero_hint = base + b;
+               else if (*cur != ~0L)   /* A mix, investigate */
+                       for (i = BITS_PER_LONG - 1; i >= 0; i--)
+                               if (!reiserfs_test_le_bit(i, cur))
                                        info->free_count++;
-                               }
-                       }
-               }
        }
-       /* The first bit must ALWAYS be 1 */
-       BUG_ON(info->first_zero_hint == 0);
 }
 
 struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
@@ -1248,7 +1256,7 @@ struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
        bh = sb_bread(sb, block);
        if (bh == NULL)
                reiserfs_warning(sb, "sh-2029: %s: bitmap block (#%u) "
-                                "reading failed", __FUNCTION__, block);
+                                "reading failed", __func__, block);
        else {
                if (buffer_locked(bh)) {
                        PROC_INFO_INC(sb, scan_bitmap.wait);
@@ -1257,7 +1265,7 @@ struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
                BUG_ON(!buffer_uptodate(bh));
                BUG_ON(atomic_read(&bh->b_count) == 0);
 
-               if (info->first_zero_hint == 0)
+               if (info->free_count == UINT_MAX)
                        reiserfs_cache_bitmap_metadata(sb, bh, info);
        }
 
@@ -1267,12 +1275,13 @@ struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
 int reiserfs_init_bitmap_cache(struct super_block *sb)
 {
        struct reiserfs_bitmap_info *bitmap;
+       unsigned int bmap_nr = reiserfs_bmap_count(sb);
 
-       bitmap = vmalloc(sizeof (*bitmap) * SB_BMAP_NR(sb));
+       bitmap = vmalloc(sizeof(*bitmap) * bmap_nr);
        if (bitmap == NULL)
                return -ENOMEM;
 
-       memset(bitmap, 0, sizeof (*bitmap) * SB_BMAP_NR(sb));
+       memset(bitmap, 0xff, sizeof(*bitmap) * bmap_nr);
 
        SB_AP_BITMAP(sb) = bitmap;