r6040: add helpers to allocate and free the Tx/Rx buffers
[safe/jmp/linux-2.6] / fs / ocfs2 / suballoc.c
index 27f8dc4..72c198a 100644 (file)
@@ -49,7 +49,7 @@
 static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg);
 static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe);
 static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl);
-static int ocfs2_block_group_fill(struct ocfs2_journal_handle *handle,
+static int ocfs2_block_group_fill(handle_t *handle,
                                  struct inode *alloc_inode,
                                  struct buffer_head *bg_bh,
                                  u64 group_blkno,
@@ -69,7 +69,7 @@ static int ocfs2_block_group_search(struct inode *inode,
                                    u16 *bit_off, u16 *bits_found);
 static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
                                     struct ocfs2_alloc_context *ac,
-                                    struct ocfs2_journal_handle *handle,
+                                    handle_t *handle,
                                     u32 bits_wanted,
                                     u32 min_bits,
                                     u16 *bit_off,
@@ -77,20 +77,20 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
                                     u64 *bg_blkno);
 static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
                                         int nr);
-static inline int ocfs2_block_group_set_bits(struct ocfs2_journal_handle *handle,
+static inline int ocfs2_block_group_set_bits(handle_t *handle,
                                             struct inode *alloc_inode,
                                             struct ocfs2_group_desc *bg,
                                             struct buffer_head *group_bh,
                                             unsigned int bit_off,
                                             unsigned int num_bits);
-static inline int ocfs2_block_group_clear_bits(struct ocfs2_journal_handle *handle,
+static inline int ocfs2_block_group_clear_bits(handle_t *handle,
                                               struct inode *alloc_inode,
                                               struct ocfs2_group_desc *bg,
                                               struct buffer_head *group_bh,
                                               unsigned int bit_off,
                                               unsigned int num_bits);
 
-static int ocfs2_relink_block_group(struct ocfs2_journal_handle *handle,
+static int ocfs2_relink_block_group(handle_t *handle,
                                    struct inode *alloc_inode,
                                    struct buffer_head *fe_bh,
                                    struct buffer_head *bg_bh,
@@ -98,19 +98,9 @@ static int ocfs2_relink_block_group(struct ocfs2_journal_handle *handle,
                                    u16 chain);
 static inline int ocfs2_block_group_reasonably_empty(struct ocfs2_group_desc *bg,
                                                     u32 wanted);
-static int ocfs2_free_suballoc_bits(struct ocfs2_journal_handle *handle,
-                                   struct inode *alloc_inode,
-                                   struct buffer_head *alloc_bh,
-                                   unsigned int start_bit,
-                                   u64 bg_blkno,
-                                   unsigned int count);
-static inline u64 ocfs2_which_suballoc_group(u64 block,
-                                            unsigned int bit);
 static inline u32 ocfs2_desc_bitmap_to_cluster_off(struct inode *inode,
                                                   u64 bg_blkno,
                                                   u16 bg_bit_off);
-static inline u64 ocfs2_which_cluster_group(struct inode *inode,
-                                           u32 cluster);
 static inline void ocfs2_block_to_cluster_group(struct inode *inode,
                                                u64 data_blkno,
                                                u64 *bg_blkno,
@@ -122,7 +112,7 @@ void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
 
        if (inode) {
                if (ac->ac_which != OCFS2_AC_USE_LOCAL)
-                       ocfs2_meta_unlock(inode, 1);
+                       ocfs2_inode_unlock(inode, 1);
 
                mutex_unlock(&inode->i_mutex);
 
@@ -139,9 +129,9 @@ static u32 ocfs2_bits_per_group(struct ocfs2_chain_list *cl)
 }
 
 /* somewhat more expensive than our other checks, so use sparingly. */
-static int ocfs2_check_group_descriptor(struct super_block *sb,
-                                       struct ocfs2_dinode *di,
-                                       struct ocfs2_group_desc *gd)
+int ocfs2_check_group_descriptor(struct super_block *sb,
+                                struct ocfs2_dinode *di,
+                                struct ocfs2_group_desc *gd)
 {
        unsigned int max_bits;
 
@@ -196,7 +186,7 @@ static int ocfs2_check_group_descriptor(struct super_block *sb,
        return 0;
 }
 
-static int ocfs2_block_group_fill(struct ocfs2_journal_handle *handle,
+static int ocfs2_block_group_fill(handle_t *handle,
                                  struct inode *alloc_inode,
                                  struct buffer_head *bg_bh,
                                  u64 group_blkno,
@@ -279,7 +269,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
        struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data;
        struct ocfs2_chain_list *cl;
        struct ocfs2_alloc_context *ac = NULL;
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle = NULL;
        u32 bit_off, num_bits;
        u16 alloc_rec;
        u64 bg_blkno;
@@ -302,7 +292,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
 
        credits = ocfs2_calc_group_alloc_credits(osb->sb,
                                                 le16_to_cpu(cl->cl_cpg));
-       handle = ocfs2_start_trans(osb, handle, credits);
+       handle = ocfs2_start_trans(osb, credits);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -381,13 +371,12 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
                                             le32_to_cpu(fe->i_clusters)));
        spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
        i_size_write(alloc_inode, le64_to_cpu(fe->i_size));
-       alloc_inode->i_blocks =
-               ocfs2_align_bytes_to_sectors(i_size_read(alloc_inode));
+       alloc_inode->i_blocks = ocfs2_inode_sector_count(alloc_inode);
 
        status = 0;
 bail:
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
 
        if (ac)
                ocfs2_free_alloc_context(ac);
@@ -421,7 +410,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
 
        mutex_lock(&alloc_inode->i_mutex);
 
-       status = ocfs2_meta_lock(alloc_inode, &bh, 1);
+       status = ocfs2_inode_lock(alloc_inode, &bh, 1);
        if (status < 0) {
                mutex_unlock(&alloc_inode->i_mutex);
                iput(alloc_inode);
@@ -488,7 +477,7 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
        int status;
        u32 slot;
 
-       *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
+       *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
        if (!(*ac)) {
                status = -ENOMEM;
                mlog_errno(status);
@@ -497,13 +486,7 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
 
        (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe);
        (*ac)->ac_which = OCFS2_AC_USE_META;
-
-#ifndef OCFS2_USE_ALL_METADATA_SUBALLOCATORS
-       slot = 0;
-#else
        slot = osb->slot_num;
-#endif
-
        (*ac)->ac_group_search = ocfs2_block_group_search;
 
        status = ocfs2_reserve_suballoc_bits(osb, (*ac),
@@ -530,7 +513,7 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
 {
        int status;
 
-       *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
+       *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
        if (!(*ac)) {
                status = -ENOMEM;
                mlog_errno(status);
@@ -595,7 +578,7 @@ int ocfs2_reserve_clusters(struct ocfs2_super *osb,
 
        mlog_entry_void();
 
-       *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
+       *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
        if (!(*ac)) {
                status = -ENOMEM;
                mlog_errno(status);
@@ -663,7 +646,7 @@ bail:
  * sync-data inodes."
  *
  * Note: OCFS2 already does this differently for metadata vs data
- * allocations, as those bitmaps are seperate and undo access is never
+ * allocations, as those bitmaps are separate and undo access is never
  * called on a metadata group descriptor.
  */
 static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
@@ -747,7 +730,7 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb,
        return status;
 }
 
-static inline int ocfs2_block_group_set_bits(struct ocfs2_journal_handle *handle,
+static inline int ocfs2_block_group_set_bits(handle_t *handle,
                                             struct inode *alloc_inode,
                                             struct ocfs2_group_desc *bg,
                                             struct buffer_head *group_bh,
@@ -818,7 +801,7 @@ static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl)
        return best;
 }
 
-static int ocfs2_relink_block_group(struct ocfs2_journal_handle *handle,
+static int ocfs2_relink_block_group(handle_t *handle,
                                    struct inode *alloc_inode,
                                    struct buffer_head *fe_bh,
                                    struct buffer_head *bg_bh,
@@ -850,9 +833,9 @@ static int ocfs2_relink_block_group(struct ocfs2_journal_handle *handle,
        }
 
        mlog(0, "Suballoc %llu, chain %u, move group %llu to top, prev = %llu\n",
-            (unsigned long long)fe->i_blkno, chain,
-            (unsigned long long)bg->bg_blkno,
-            (unsigned long long)prev_bg->bg_blkno);
+            (unsigned long long)le64_to_cpu(fe->i_blkno), chain,
+            (unsigned long long)le64_to_cpu(bg->bg_blkno),
+            (unsigned long long)le64_to_cpu(prev_bg->bg_blkno));
 
        fe_ptr = le64_to_cpu(fe->id2.i_chain.cl_recs[chain].c_blkno);
        bg_ptr = le64_to_cpu(bg->bg_next_group);
@@ -998,7 +981,7 @@ static int ocfs2_block_group_search(struct inode *inode,
 }
 
 static int ocfs2_alloc_dinode_update_counts(struct inode *inode,
-                                      struct ocfs2_journal_handle *handle,
+                                      handle_t *handle,
                                       struct buffer_head *di_bh,
                                       u32 num_bits,
                                       u16 chain)
@@ -1028,7 +1011,7 @@ out:
 }
 
 static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac,
-                                 struct ocfs2_journal_handle *handle,
+                                 handle_t *handle,
                                  u32 bits_wanted,
                                  u32 min_bits,
                                  u16 *bit_off,
@@ -1088,7 +1071,7 @@ out:
 }
 
 static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
-                             struct ocfs2_journal_handle *handle,
+                             handle_t *handle,
                              u32 bits_wanted,
                              u32 min_bits,
                              u16 *bit_off,
@@ -1163,7 +1146,7 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
        }
 
        mlog(0, "alloc succeeds: we give %u bits from block group %llu\n",
-            tmp_bits, (unsigned long long)bg->bg_blkno);
+            tmp_bits, (unsigned long long)le64_to_cpu(bg->bg_blkno));
 
        *num_bits = tmp_bits;
 
@@ -1228,7 +1211,7 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
        }
 
        mlog(0, "Allocated %u bits from suballocator %llu\n", *num_bits,
-            (unsigned long long)fe->i_blkno);
+            (unsigned long long)le64_to_cpu(fe->i_blkno));
 
        *bg_blkno = le64_to_cpu(bg->bg_blkno);
        *bits_left = le16_to_cpu(bg->bg_free_bits_count);
@@ -1245,7 +1228,7 @@ bail:
 /* will give out up to bits_wanted contiguous bits. */
 static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
                                     struct ocfs2_alloc_context *ac,
-                                    struct ocfs2_journal_handle *handle,
+                                    handle_t *handle,
                                     u32 bits_wanted,
                                     u32 min_bits,
                                     u16 *bit_off,
@@ -1362,7 +1345,7 @@ bail:
 }
 
 int ocfs2_claim_metadata(struct ocfs2_super *osb,
-                        struct ocfs2_journal_handle *handle,
+                        handle_t *handle,
                         struct ocfs2_alloc_context *ac,
                         u32 bits_wanted,
                         u16 *suballoc_bit_start,
@@ -1399,7 +1382,7 @@ bail:
 }
 
 int ocfs2_claim_new_inode(struct ocfs2_super *osb,
-                         struct ocfs2_journal_handle *handle,
+                         handle_t *handle,
                          struct ocfs2_alloc_context *ac,
                          u16 *suballoc_bit,
                          u64 *fe_blkno)
@@ -1458,8 +1441,7 @@ static inline u32 ocfs2_desc_bitmap_to_cluster_off(struct inode *inode,
 
 /* given a cluster offset, calculate which block group it belongs to
  * and return that block offset. */
-static inline u64 ocfs2_which_cluster_group(struct inode *inode,
-                                           u32 cluster)
+u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster)
 {
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        u32 group_no;
@@ -1501,21 +1483,21 @@ static inline void ocfs2_block_to_cluster_group(struct inode *inode,
  * contig. allocation, set to '1' to indicate we can deal with extents
  * of any size.
  */
-int ocfs2_claim_clusters(struct ocfs2_super *osb,
-                        struct ocfs2_journal_handle *handle,
-                        struct ocfs2_alloc_context *ac,
-                        u32 min_clusters,
-                        u32 *cluster_start,
-                        u32 *num_clusters)
+int __ocfs2_claim_clusters(struct ocfs2_super *osb,
+                          handle_t *handle,
+                          struct ocfs2_alloc_context *ac,
+                          u32 min_clusters,
+                          u32 max_clusters,
+                          u32 *cluster_start,
+                          u32 *num_clusters)
 {
        int status;
-       unsigned int bits_wanted = ac->ac_bits_wanted - ac->ac_bits_given;
+       unsigned int bits_wanted = max_clusters;
        u64 bg_blkno = 0;
        u16 bg_bit_off;
 
        mlog_entry_void();
 
-       BUG_ON(!ac);
        BUG_ON(ac->ac_bits_given >= ac->ac_bits_wanted);
 
        BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL
@@ -1534,8 +1516,9 @@ int ocfs2_claim_clusters(struct ocfs2_super *osb,
                if (min_clusters > (osb->bitmap_cpg - 1)) {
                        /* The only paths asking for contiguousness
                         * should know about this already. */
-                       mlog(ML_ERROR, "minimum allocation requested exceeds "
-                                      "group bitmap size!");
+                       mlog(ML_ERROR, "minimum allocation requested %u exceeds "
+                            "group bitmap size %u!\n", min_clusters,
+                            osb->bitmap_cpg);
                        status = -ENOSPC;
                        goto bail;
                }
@@ -1572,7 +1555,20 @@ bail:
        return status;
 }
 
-static inline int ocfs2_block_group_clear_bits(struct ocfs2_journal_handle *handle,
+int ocfs2_claim_clusters(struct ocfs2_super *osb,
+                        handle_t *handle,
+                        struct ocfs2_alloc_context *ac,
+                        u32 min_clusters,
+                        u32 *cluster_start,
+                        u32 *num_clusters)
+{
+       unsigned int bits_wanted = ac->ac_bits_wanted - ac->ac_bits_given;
+
+       return __ocfs2_claim_clusters(osb, handle, ac, min_clusters,
+                                     bits_wanted, cluster_start, num_clusters);
+}
+
+static inline int ocfs2_block_group_clear_bits(handle_t *handle,
                                               struct inode *alloc_inode,
                                               struct ocfs2_group_desc *bg,
                                               struct buffer_head *group_bh,
@@ -1627,12 +1623,12 @@ bail:
 /*
  * expects the suballoc inode to already be locked.
  */
-static int ocfs2_free_suballoc_bits(struct ocfs2_journal_handle *handle,
-                                   struct inode *alloc_inode,
-                                   struct buffer_head *alloc_bh,
-                                   unsigned int start_bit,
-                                   u64 bg_blkno,
-                                   unsigned int count)
+int ocfs2_free_suballoc_bits(handle_t *handle,
+                            struct inode *alloc_inode,
+                            struct buffer_head *alloc_bh,
+                            unsigned int start_bit,
+                            u64 bg_blkno,
+                            unsigned int count)
 {
        int status = 0;
        u32 tmp_used;
@@ -1704,14 +1700,7 @@ bail:
        return status;
 }
 
-static inline u64 ocfs2_which_suballoc_group(u64 block, unsigned int bit)
-{
-       u64 group = block - (u64) bit;
-
-       return group;
-}
-
-int ocfs2_free_dinode(struct ocfs2_journal_handle *handle,
+int ocfs2_free_dinode(handle_t *handle,
                      struct inode *inode_alloc_inode,
                      struct buffer_head *inode_alloc_bh,
                      struct ocfs2_dinode *di)
@@ -1724,20 +1713,7 @@ int ocfs2_free_dinode(struct ocfs2_journal_handle *handle,
                                        inode_alloc_bh, bit, bg_blkno, 1);
 }
 
-int ocfs2_free_extent_block(struct ocfs2_journal_handle *handle,
-                           struct inode *eb_alloc_inode,
-                           struct buffer_head *eb_alloc_bh,
-                           struct ocfs2_extent_block *eb)
-{
-       u64 blk = le64_to_cpu(eb->h_blkno);
-       u16 bit = le16_to_cpu(eb->h_suballoc_bit);
-       u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
-
-       return ocfs2_free_suballoc_bits(handle, eb_alloc_inode, eb_alloc_bh,
-                                       bit, bg_blkno, 1);
-}
-
-int ocfs2_free_clusters(struct ocfs2_journal_handle *handle,
+int ocfs2_free_clusters(handle_t *handle,
                       struct inode *bitmap_inode,
                       struct buffer_head *bitmap_bh,
                       u64 start_blk,