ocfs2: use all extent block suballocators
[safe/jmp/linux-2.6] / fs / ocfs2 / localalloc.c
index 75f09f1..545f789 100644 (file)
@@ -58,19 +58,18 @@ static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
 static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc);
 
 static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
-                                   struct ocfs2_journal_handle *handle,
+                                   handle_t *handle,
                                    struct ocfs2_dinode *alloc,
                                    struct inode *main_bm_inode,
                                    struct buffer_head *main_bm_bh);
 
 static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
-                                               struct ocfs2_journal_handle *handle,
                                                struct ocfs2_alloc_context **ac,
                                                struct inode **bitmap_inode,
                                                struct buffer_head **bitmap_bh);
 
 static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
-                                       struct ocfs2_journal_handle *handle,
+                                       handle_t *handle,
                                        struct ocfs2_alloc_context *ac);
 
 static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
@@ -196,7 +195,7 @@ bail:
 void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
 {
        int status;
-       struct ocfs2_journal_handle *handle;
+       handle_t *handle;
        struct inode *local_alloc_inode = NULL;
        struct buffer_head *bh = NULL;
        struct buffer_head *main_bm_bh = NULL;
@@ -232,14 +231,14 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
 
        mutex_lock(&main_bm_inode->i_mutex);
 
-       status = ocfs2_meta_lock(main_bm_inode, NULL, &main_bm_bh, 1);
+       status = ocfs2_meta_lock(main_bm_inode, &main_bm_bh, 1);
        if (status < 0) {
                mlog_errno(status);
                goto out_mutex;
        }
 
        /* WINDOW_MOVE_CREDITS is a bit heavy... */
-       handle = ocfs2_start_trans(osb, NULL, OCFS2_WINDOW_MOVE_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS);
        if (IS_ERR(handle)) {
                mlog_errno(PTR_ERR(handle));
                handle = NULL;
@@ -281,7 +280,7 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
                mlog_errno(status);
 
 out_commit:
-       ocfs2_commit_trans(handle);
+       ocfs2_commit_trans(osb, handle);
 
 out_unlock:
        if (main_bm_bh)
@@ -383,7 +382,7 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
                                        struct ocfs2_dinode *alloc)
 {
        int status;
-       struct ocfs2_journal_handle *handle;
+       handle_t *handle;
        struct buffer_head *main_bm_bh = NULL;
        struct inode *main_bm_inode;
 
@@ -400,13 +399,13 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
 
        mutex_lock(&main_bm_inode->i_mutex);
 
-       status = ocfs2_meta_lock(main_bm_inode, NULL, &main_bm_bh, 1);
+       status = ocfs2_meta_lock(main_bm_inode, &main_bm_bh, 1);
        if (status < 0) {
                mlog_errno(status);
                goto out_mutex;
        }
 
-       handle = ocfs2_start_trans(osb, NULL, OCFS2_WINDOW_MOVE_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -415,14 +414,14 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
        }
 
        /* we want the bitmap change to be recorded on disk asap */
-       handle->k_handle->h_sync = 1;
+       handle->h_sync = 1;
 
        status = ocfs2_sync_local_to_main(osb, handle, alloc,
                                          main_bm_inode, main_bm_bh);
        if (status < 0)
                mlog_errno(status);
 
-       ocfs2_commit_trans(handle);
+       ocfs2_commit_trans(osb, handle);
 
 out_unlock:
        ocfs2_meta_unlock(main_bm_inode, 1);
@@ -448,7 +447,6 @@ out:
  * our own in order to shift windows.
  */
 int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
-                                  struct ocfs2_journal_handle *passed_handle,
                                   u32 bits_wanted,
                                   struct ocfs2_alloc_context *ac)
 {
@@ -459,9 +457,7 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
 
        mlog_entry_void();
 
-       BUG_ON(!passed_handle);
        BUG_ON(!ac);
-       BUG_ON(passed_handle->k_handle);
 
        local_alloc_inode =
                ocfs2_get_system_file_inode(osb,
@@ -472,7 +468,8 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
                mlog_errno(status);
                goto bail;
        }
-       ocfs2_handle_add_inode(passed_handle, local_alloc_inode);
+
+       mutex_lock(&local_alloc_inode->i_mutex);
 
        if (osb->local_alloc_state != OCFS2_LA_ENABLED) {
                status = -ENOSPC;
@@ -511,13 +508,13 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
                }
        }
 
-       ac->ac_inode = igrab(local_alloc_inode);
+       ac->ac_inode = local_alloc_inode;
+       ac->ac_which = OCFS2_AC_USE_LOCAL;
        get_bh(osb->local_alloc_bh);
        ac->ac_bh = osb->local_alloc_bh;
-       ac->ac_which = OCFS2_AC_USE_LOCAL;
        status = 0;
 bail:
-       if (local_alloc_inode)
+       if (status < 0 && local_alloc_inode)
                iput(local_alloc_inode);
 
        mlog_exit(status);
@@ -525,7 +522,7 @@ bail:
 }
 
 int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
-                                struct ocfs2_journal_handle *handle,
+                                handle_t *handle,
                                 struct ocfs2_alloc_context *ac,
                                 u32 min_bits,
                                 u32 *bit_off,
@@ -703,7 +700,7 @@ static void ocfs2_verify_zero_bits(unsigned long *bitmap,
  * passed is used for caching.
  */
 static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
-                                   struct ocfs2_journal_handle *handle,
+                                   handle_t *handle,
                                    struct ocfs2_dinode *alloc,
                                    struct inode *main_bm_inode,
                                    struct buffer_head *main_bm_bh)
@@ -774,21 +771,19 @@ bail:
 }
 
 static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
-                                               struct ocfs2_journal_handle *handle,
                                                struct ocfs2_alloc_context **ac,
                                                struct inode **bitmap_inode,
                                                struct buffer_head **bitmap_bh)
 {
        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);
                goto bail;
        }
 
-       (*ac)->ac_handle = handle;
        (*ac)->ac_bits_wanted = ocfs2_local_alloc_window_bits(osb);
 
        status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
@@ -817,7 +812,7 @@ bail:
  * pass it the bitmap lock in lock_bh if you have it.
  */
 static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
-                                       struct ocfs2_journal_handle *handle,
+                                       handle_t *handle,
                                        struct ocfs2_alloc_context *ac)
 {
        int status = 0;
@@ -884,23 +879,15 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
        int status = 0;
        struct buffer_head *main_bm_bh = NULL;
        struct inode *main_bm_inode = NULL;
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle = NULL;
        struct ocfs2_dinode *alloc;
        struct ocfs2_dinode *alloc_copy = NULL;
        struct ocfs2_alloc_context *ac = NULL;
 
        mlog_entry_void();
 
-       handle = ocfs2_alloc_handle(osb);
-       if (!handle) {
-               status = -ENOMEM;
-               mlog_errno(status);
-               goto bail;
-       }
-
        /* This will lock the main bitmap for us. */
        status = ocfs2_local_alloc_reserve_for_window(osb,
-                                                     handle,
                                                      &ac,
                                                      &main_bm_inode,
                                                      &main_bm_bh);
@@ -910,7 +897,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
                goto bail;
        }
 
-       handle = ocfs2_start_trans(osb, handle, OCFS2_WINDOW_MOVE_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -968,7 +955,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
        status = 0;
 bail:
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
 
        if (main_bm_bh)
                brelse(main_bm_bh);