]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ocfs2/localalloc.c
[PATCH] ocfs2: le*_add_cpu conversion
[linux-2.6-omap-h63xx.git] / fs / ocfs2 / localalloc.c
index 545f7892cdf39b645888e12fa8614598dbb86bfb..ab83fd5624294561541dba9663f128336f296116 100644 (file)
@@ -75,18 +75,12 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
 static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
                                          struct inode *local_alloc_inode);
 
-/*
- * Determine how large our local alloc window should be, in bits.
- *
- * These values (and the behavior in ocfs2_alloc_should_use_local) have
- * been chosen so that most allocations, including new block groups go
- * through local alloc.
- */
 static inline int ocfs2_local_alloc_window_bits(struct ocfs2_super *osb)
 {
-       BUG_ON(osb->s_clustersize_bits < 12);
+       BUG_ON(osb->s_clustersize_bits > 20);
 
-       return 2048 >> (osb->s_clustersize_bits - 12);
+       /* Size local alloc windows by the megabyte */
+       return osb->local_alloc_size << (20 - osb->s_clustersize_bits);
 }
 
 /*
@@ -96,18 +90,23 @@ static inline int ocfs2_local_alloc_window_bits(struct ocfs2_super *osb)
 int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits)
 {
        int la_bits = ocfs2_local_alloc_window_bits(osb);
+       int ret = 0;
 
        if (osb->local_alloc_state != OCFS2_LA_ENABLED)
-               return 0;
+               goto bail;
 
        /* la_bits should be at least twice the size (in clusters) of
         * a new block group. We want to be sure block group
         * allocations go through the local alloc, so allow an
         * allocation to take up to half the bitmap. */
        if (bits > (la_bits / 2))
-               return 0;
+               goto bail;
 
-       return 1;
+       ret = 1;
+bail:
+       mlog(0, "state=%d, bits=%llu, la_bits=%d, ret=%d\n",
+            osb->local_alloc_state, (unsigned long long)bits, la_bits, ret);
+       return ret;
 }
 
 int ocfs2_load_local_alloc(struct ocfs2_super *osb)
@@ -121,6 +120,16 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb)
 
        mlog_entry_void();
 
+       if (osb->local_alloc_size == 0)
+               goto bail;
+
+       if (ocfs2_local_alloc_window_bits(osb) >= osb->bitmap_cpg) {
+               mlog(ML_NOTICE, "Requested local alloc window %d is larger "
+                    "than max possible %u. Using defaults.\n",
+                    ocfs2_local_alloc_window_bits(osb), (osb->bitmap_cpg - 1));
+               osb->local_alloc_size = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
+       }
+
        /* read the alloc off disk */
        inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE,
                                            osb->slot_num);
@@ -181,6 +190,9 @@ bail:
        if (inode)
                iput(inode);
 
+       mlog(0, "Local alloc window bits = %d\n",
+            ocfs2_local_alloc_window_bits(osb));
+
        mlog_exit(status);
        return status;
 }
@@ -231,7 +243,7 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
 
        mutex_lock(&main_bm_inode->i_mutex);
 
-       status = ocfs2_meta_lock(main_bm_inode, &main_bm_bh, 1);
+       status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
        if (status < 0) {
                mlog_errno(status);
                goto out_mutex;
@@ -286,7 +298,7 @@ out_unlock:
        if (main_bm_bh)
                brelse(main_bm_bh);
 
-       ocfs2_meta_unlock(main_bm_inode, 1);
+       ocfs2_inode_unlock(main_bm_inode, 1);
 
 out_mutex:
        mutex_unlock(&main_bm_inode->i_mutex);
@@ -399,7 +411,7 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
 
        mutex_lock(&main_bm_inode->i_mutex);
 
-       status = ocfs2_meta_lock(main_bm_inode, &main_bm_bh, 1);
+       status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
        if (status < 0) {
                mlog_errno(status);
                goto out_mutex;
@@ -424,7 +436,7 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
        ocfs2_commit_trans(osb, handle);
 
 out_unlock:
-       ocfs2_meta_unlock(main_bm_inode, 1);
+       ocfs2_inode_unlock(main_bm_inode, 1);
 
 out_mutex:
        mutex_unlock(&main_bm_inode->i_mutex);
@@ -484,6 +496,7 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
 
        alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
 
+#ifdef OCFS2_DEBUG_FS
        if (le32_to_cpu(alloc->id1.bitmap1.i_used) !=
            ocfs2_local_alloc_count_bits(alloc)) {
                ocfs2_error(osb->sb, "local alloc inode %llu says it has "
@@ -494,6 +507,7 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
                status = -EIO;
                goto bail;
        }
+#endif
 
        free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) -
                le32_to_cpu(alloc->id1.bitmap1.i_used);
@@ -514,8 +528,13 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
        ac->ac_bh = osb->local_alloc_bh;
        status = 0;
 bail:
-       if (status < 0 && local_alloc_inode)
+       if (status < 0 && local_alloc_inode) {
+               mutex_unlock(&local_alloc_inode->i_mutex);
                iput(local_alloc_inode);
+       }
+
+       mlog(0, "bits=%d, slot=%d, ret=%d\n", bits_wanted, osb->slot_num,
+            status);
 
        mlog_exit(status);
        return status;
@@ -524,13 +543,12 @@ bail:
 int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
                                 handle_t *handle,
                                 struct ocfs2_alloc_context *ac,
-                                u32 min_bits,
+                                u32 bits_wanted,
                                 u32 *bit_off,
                                 u32 *num_bits)
 {
        int status, start;
        struct inode *local_alloc_inode;
-       u32 bits_wanted;
        void *bitmap;
        struct ocfs2_dinode *alloc;
        struct ocfs2_local_alloc *la;
@@ -538,7 +556,6 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
        mlog_entry_void();
        BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL);
 
-       bits_wanted = ac->ac_bits_wanted - ac->ac_bits_given;
        local_alloc_inode = ac->ac_inode;
        alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
        la = OCFS2_LOCAL_ALLOC(alloc);
@@ -568,8 +585,7 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
        while(bits_wanted--)
                ocfs2_set_bit(start++, bitmap);
 
-       alloc->id1.bitmap1.i_used = cpu_to_le32(*num_bits +
-                               le32_to_cpu(alloc->id1.bitmap1.i_used));
+       le32_add_cpu(&alloc->id1.bitmap1.i_used, *num_bits);
 
        status = ocfs2_journal_dirty(handle, osb->local_alloc_bh);
        if (status < 0) {
@@ -712,9 +728,8 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
        void *bitmap;
        struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc);
 
-       mlog_entry("total = %u, COUNT = %u, used = %u\n",
+       mlog_entry("total = %u, used = %u\n",
                   le32_to_cpu(alloc->id1.bitmap1.i_total),
-                  ocfs2_local_alloc_count_bits(alloc),
                   le32_to_cpu(alloc->id1.bitmap1.i_used));
 
        if (!alloc->id1.bitmap1.i_total) {