]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ext4/extents.c
Pull bugfix into test branch
[linux-2.6-omap-h63xx.git] / fs / ext4 / extents.c
index 32526061a17d14e76db4f2d355532b3c2d945d7d..dc2724fa7622b2b1492d0d547425e6dcc1e7e35c 100644 (file)
 #include <asm/uaccess.h>
 
 
-/* this macro combines low and hi parts of phys. blocknr into ext4_fsblk_t */
-static inline ext4_fsblk_t ext_pblock(struct ext4_extent *ex)
+/*
+ * ext_pblock:
+ * combine low and high parts of physical block number into ext4_fsblk_t
+ */
+static ext4_fsblk_t ext_pblock(struct ext4_extent *ex)
 {
        ext4_fsblk_t block;
 
        block = le32_to_cpu(ex->ee_start);
-       if (sizeof(ext4_fsblk_t) > 4)
-               block |= ((ext4_fsblk_t) le16_to_cpu(ex->ee_start_hi) << 31) << 1;
+       block |= ((ext4_fsblk_t) le16_to_cpu(ex->ee_start_hi) << 31) << 1;
        return block;
 }
 
-/* this macro combines low and hi parts of phys. blocknr into ext4_fsblk_t */
-static inline ext4_fsblk_t idx_pblock(struct ext4_extent_idx *ix)
+/*
+ * idx_pblock:
+ * combine low and high parts of a leaf physical block number into ext4_fsblk_t
+ */
+static ext4_fsblk_t idx_pblock(struct ext4_extent_idx *ix)
 {
        ext4_fsblk_t block;
 
        block = le32_to_cpu(ix->ei_leaf);
-       if (sizeof(ext4_fsblk_t) > 4)
-               block |= ((ext4_fsblk_t) le16_to_cpu(ix->ei_leaf_hi) << 31) << 1;
+       block |= ((ext4_fsblk_t) le16_to_cpu(ix->ei_leaf_hi) << 31) << 1;
        return block;
 }
 
-/* the routine stores large phys. blocknr into extent breaking it into parts */
-static inline void ext4_ext_store_pblock(struct ext4_extent *ex, ext4_fsblk_t pb)
+/*
+ * ext4_ext_store_pblock:
+ * stores a large physical block number into an extent struct,
+ * breaking it into parts
+ */
+static void ext4_ext_store_pblock(struct ext4_extent *ex, ext4_fsblk_t pb)
 {
        ex->ee_start = cpu_to_le32((unsigned long) (pb & 0xffffffff));
-       if (sizeof(ext4_fsblk_t) > 4)
-               ex->ee_start_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
+       ex->ee_start_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
 }
 
-/* the routine stores large phys. blocknr into index breaking it into parts */
-static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix, ext4_fsblk_t pb)
+/*
+ * ext4_idx_store_pblock:
+ * stores a large physical block number into an index struct,
+ * breaking it into parts
+ */
+static void ext4_idx_store_pblock(struct ext4_extent_idx *ix, ext4_fsblk_t pb)
 {
        ix->ei_leaf = cpu_to_le32((unsigned long) (pb & 0xffffffff));
-       if (sizeof(ext4_fsblk_t) > 4)
-               ix->ei_leaf_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
+       ix->ei_leaf_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
 }
 
 static int ext4_ext_check_header(const char *function, struct inode *inode,
@@ -176,11 +186,12 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,
                depth = path->p_depth;
 
                /* try to predict block placement */
-               if ((ex = path[depth].p_ext))
+               ex = path[depth].p_ext;
+               if (ex)
                        return ext_pblock(ex)+(block-le32_to_cpu(ex->ee_block));
 
-               /* it looks index is empty
-                * try to find starting from index itself */
+               /* it looks like index is empty;
+                * try to find starting block from index itself */
                if (path[depth].p_bh)
                        return path[depth].p_bh->b_blocknr;
        }
@@ -205,7 +216,7 @@ ext4_ext_new_block(handle_t *handle, struct inode *inode,
        return newblock;
 }
 
-static inline int ext4_ext_space_block(struct inode *inode)
+static int ext4_ext_space_block(struct inode *inode)
 {
        int size;
 
@@ -218,7 +229,7 @@ static inline int ext4_ext_space_block(struct inode *inode)
        return size;
 }
 
-static inline int ext4_ext_space_block_idx(struct inode *inode)
+static int ext4_ext_space_block_idx(struct inode *inode)
 {
        int size;
 
@@ -231,7 +242,7 @@ static inline int ext4_ext_space_block_idx(struct inode *inode)
        return size;
 }
 
-static inline int ext4_ext_space_root(struct inode *inode)
+static int ext4_ext_space_root(struct inode *inode)
 {
        int size;
 
@@ -245,7 +256,7 @@ static inline int ext4_ext_space_root(struct inode *inode)
        return size;
 }
 
-static inline int ext4_ext_space_root_idx(struct inode *inode)
+static int ext4_ext_space_root_idx(struct inode *inode)
 {
        int size;
 
@@ -267,10 +278,10 @@ static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path)
        ext_debug("path:");
        for (k = 0; k <= l; k++, path++) {
                if (path->p_idx) {
-                 ext_debug("  %d->"E3FSBLK, le32_to_cpu(path->p_idx->ei_block),
+                 ext_debug("  %d->%llu", le32_to_cpu(path->p_idx->ei_block),
                            idx_pblock(path->p_idx));
                } else if (path->p_ext) {
-                       ext_debug("  %d:%d:"E3FSBLK" ",
+                       ext_debug("  %d:%d:%llu ",
                                  le32_to_cpu(path->p_ext->ee_block),
                                  le16_to_cpu(path->p_ext->ee_len),
                                  ext_pblock(path->p_ext));
@@ -294,7 +305,7 @@ static void ext4_ext_show_leaf(struct inode *inode, struct ext4_ext_path *path)
        ex = EXT_FIRST_EXTENT(eh);
 
        for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ex++) {
-               ext_debug("%d:%d:"E3FSBLK" ", le32_to_cpu(ex->ee_block),
+               ext_debug("%d:%d:%llu ", le32_to_cpu(ex->ee_block),
                          le16_to_cpu(ex->ee_len), ext_pblock(ex));
        }
        ext_debug("\n");
@@ -317,7 +328,8 @@ static void ext4_ext_drop_refs(struct ext4_ext_path *path)
 }
 
 /*
- * binary search for closest index by given block
+ * ext4_ext_binsearch_idx:
+ * binary search for the closest index of the given block
  */
 static void
 ext4_ext_binsearch_idx(struct inode *inode, struct ext4_ext_path *path, int block)
@@ -375,7 +387,8 @@ ext4_ext_binsearch_idx(struct inode *inode, struct ext4_ext_path *path, int bloc
 }
 
 /*
- * binary search for closest extent by given block
+ * ext4_ext_binsearch:
+ * binary search for closest extent of the given block
  */
 static void
 ext4_ext_binsearch(struct inode *inode, struct ext4_ext_path *path, int block)
@@ -388,8 +401,8 @@ ext4_ext_binsearch(struct inode *inode, struct ext4_ext_path *path, int block)
 
        if (eh->eh_entries == 0) {
                /*
-                * this leaf is empty yet:
-                *  we get such a leaf in split/add case
+                * this leaf is empty:
+                * we get such a leaf in split/add case
                 */
                return;
        }
@@ -410,7 +423,7 @@ ext4_ext_binsearch(struct inode *inode, struct ext4_ext_path *path, int block)
        }
 
        path->p_ext = l - 1;
-       ext_debug("  -> %d:"E3FSBLK":%d ",
+       ext_debug("  -> %d:%llu:%d ",
                        le32_to_cpu(path->p_ext->ee_block),
                        ext_pblock(path->p_ext),
                        le16_to_cpu(path->p_ext->ee_len));
@@ -464,13 +477,12 @@ ext4_ext_find_extent(struct inode *inode, int block, struct ext4_ext_path *path)
 
        /* account possible depth increase */
        if (!path) {
-               path = kmalloc(sizeof(struct ext4_ext_path) * (depth + 2),
+               path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 2),
                                GFP_NOFS);
                if (!path)
                        return ERR_PTR(-ENOMEM);
                alloc = 1;
        }
-       memset(path, 0, sizeof(struct ext4_ext_path) * (depth + 1));
        path[0].p_hdr = eh;
 
        /* walk through the tree */
@@ -520,8 +532,9 @@ err:
 }
 
 /*
- * insert new index [logical;ptr] into the block at cupr
- * it check where to insert: before curp or after curp
+ * ext4_ext_insert_index:
+ * insert new index [@logical;@ptr] into the block at @curp;
+ * check where to insert: before @curp or after @curp
  */
 static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
                                struct ext4_ext_path *curp,
@@ -530,7 +543,8 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
        struct ext4_extent_idx *ix;
        int len, err;
 
-       if ((err = ext4_ext_get_access(handle, inode, curp)))
+       err = ext4_ext_get_access(handle, inode, curp);
+       if (err)
                return err;
 
        BUG_ON(logical == le32_to_cpu(curp->p_idx->ei_block));
@@ -574,13 +588,14 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
 }
 
 /*
- * routine inserts new subtree into the path, using free index entry
- * at depth 'at:
- *  - allocates all needed blocks (new leaf and all intermediate index blocks)
- *  - makes decision where to split
- *  - moves remaining extens and index entries (right to the split point)
- *    into the newly allocated blocks
- *  - initialize subtree
+ * ext4_ext_split:
+ * inserts new subtree into the path, using free index entry
+ * at depth @at:
+ * - allocates all needed blocks (new leaf and all intermediate index blocks)
+ * - makes decision where to split
+ * - moves remaining extents and index entries (right to the split point)
+ *   into the newly allocated blocks
+ * - initializes subtree
  */
 static int ext4_ext_split(handle_t *handle, struct inode *inode,
                                struct ext4_ext_path *path,
@@ -598,14 +613,14 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        int err = 0;
 
        /* make decision: where to split? */
-       /* FIXME: now desicion is simplest: at current extent */
+       /* FIXME: now decision is simplest: at current extent */
 
-       /* if current leaf will be splitted, then we should use
+       /* if current leaf will be split, then we should use
         * border from split point */
        BUG_ON(path[depth].p_ext > EXT_MAX_EXTENT(path[depth].p_hdr));
        if (path[depth].p_ext != EXT_MAX_EXTENT(path[depth].p_hdr)) {
                border = path[depth].p_ext[1].ee_block;
-               ext_debug("leaf will be splitted."
+               ext_debug("leaf will be split."
                                " next leaf starts at %d\n",
                                  le32_to_cpu(border));
        } else {
@@ -616,21 +631,20 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        }
 
        /*
-        * if error occurs, then we break processing
-        * and turn filesystem read-only. so, index won't
+        * If error occurs, then we break processing
+        * and mark filesystem read-only. index won't
         * be inserted and tree will be in consistent
-        * state. next mount will repair buffers too
+        * state. Next mount will repair buffers too.
         */
 
        /*
-        * get array to track all allocated blocks
-        * we need this to handle errors and free blocks
-        * upon them
+        * Get array to track all allocated blocks.
+        * We need this to handle errors and free blocks
+        * upon them.
         */
-       ablocks = kmalloc(sizeof(ext4_fsblk_t) * depth, GFP_NOFS);
+       ablocks = kzalloc(sizeof(ext4_fsblk_t) * depth, GFP_NOFS);
        if (!ablocks)
                return -ENOMEM;
-       memset(ablocks, 0, sizeof(ext4_fsblk_t) * depth);
 
        /* allocate all needed blocks */
        ext_debug("allocate %d blocks for indexes/leaf\n", depth - at);
@@ -651,7 +665,8 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        }
        lock_buffer(bh);
 
-       if ((err = ext4_journal_get_create_access(handle, bh)))
+       err = ext4_journal_get_create_access(handle, bh);
+       if (err)
                goto cleanup;
 
        neh = ext_block_hdr(bh);
@@ -661,7 +676,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        neh->eh_depth = 0;
        ex = EXT_FIRST_EXTENT(neh);
 
-       /* move remain of path[depth] to the new leaf */
+       /* move remainder of path[depth] to the new leaf */
        BUG_ON(path[depth].p_hdr->eh_entries != path[depth].p_hdr->eh_max);
        /* start copy from next extent */
        /* TODO: we could do it by single memmove */
@@ -669,7 +684,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        path[depth].p_ext++;
        while (path[depth].p_ext <=
                        EXT_MAX_EXTENT(path[depth].p_hdr)) {
-               ext_debug("move %d:"E3FSBLK":%d in new leaf "E3FSBLK"\n",
+               ext_debug("move %d:%llu:%d in new leaf %llu\n",
                                le32_to_cpu(path[depth].p_ext->ee_block),
                                ext_pblock(path[depth].p_ext),
                                le16_to_cpu(path[depth].p_ext->ee_len),
@@ -688,18 +703,21 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        set_buffer_uptodate(bh);
        unlock_buffer(bh);
 
-       if ((err = ext4_journal_dirty_metadata(handle, bh)))
+       err = ext4_journal_dirty_metadata(handle, bh);
+       if (err)
                goto cleanup;
        brelse(bh);
        bh = NULL;
 
        /* correct old leaf */
        if (m) {
-               if ((err = ext4_ext_get_access(handle, inode, path + depth)))
+               err = ext4_ext_get_access(handle, inode, path + depth);
+               if (err)
                        goto cleanup;
                path[depth].p_hdr->eh_entries =
                     cpu_to_le16(le16_to_cpu(path[depth].p_hdr->eh_entries)-m);
-               if ((err = ext4_ext_dirty(handle, inode, path + depth)))
+               err = ext4_ext_dirty(handle, inode, path + depth);
+               if (err)
                        goto cleanup;
 
        }
@@ -722,7 +740,8 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
                }
                lock_buffer(bh);
 
-               if ((err = ext4_journal_get_create_access(handle, bh)))
+               err = ext4_journal_get_create_access(handle, bh);
+               if (err)
                        goto cleanup;
 
                neh = ext_block_hdr(bh);
@@ -734,7 +753,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
                fidx->ei_block = border;
                ext4_idx_store_pblock(fidx, oldblock);
 
-               ext_debug("int.index at %d (block "E3FSBLK"): %lu -> "E3FSBLK"\n", i,
+               ext_debug("int.index at %d (block %llu): %lu -> %llu\n", i,
                                newblock, (unsigned long) le32_to_cpu(border),
                                oldblock);
                /* copy indexes */
@@ -746,7 +765,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
                BUG_ON(EXT_MAX_INDEX(path[i].p_hdr) !=
                                EXT_LAST_INDEX(path[i].p_hdr));
                while (path[i].p_idx <= EXT_MAX_INDEX(path[i].p_hdr)) {
-                       ext_debug("%d: move %d:%d in new index "E3FSBLK"\n", i,
+                       ext_debug("%d: move %d:%d in new index %llu\n", i,
                                        le32_to_cpu(path[i].p_idx->ei_block),
                                        idx_pblock(path[i].p_idx),
                                        newblock);
@@ -766,7 +785,8 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
                set_buffer_uptodate(bh);
                unlock_buffer(bh);
 
-               if ((err = ext4_journal_dirty_metadata(handle, bh)))
+               err = ext4_journal_dirty_metadata(handle, bh);
+               if (err)
                        goto cleanup;
                brelse(bh);
                bh = NULL;
@@ -786,9 +806,6 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
        }
 
        /* insert new index */
-       if (err)
-               goto cleanup;
-
        err = ext4_ext_insert_index(handle, inode, path + at,
                                    le32_to_cpu(border), newblock);
 
@@ -813,11 +830,12 @@ cleanup:
 }
 
 /*
- * routine implements tree growing procedure:
- *  - allocates new block
- *  - moves top-level data (index block or leaf) into the new block
- *  - initialize new top-level, creating index that points to the
- *    just created block
+ * ext4_ext_grow_indepth:
+ * implements tree growing procedure:
+ * - allocates new block
+ * - moves top-level data (index block or leaf) into the new block
+ * - initializes new top-level, creating index that points to the
+ *   just created block
  */
 static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
                                        struct ext4_ext_path *path,
@@ -842,7 +860,8 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
        }
        lock_buffer(bh);
 
-       if ((err = ext4_journal_get_create_access(handle, bh))) {
+       err = ext4_journal_get_create_access(handle, bh);
+       if (err) {
                unlock_buffer(bh);
                goto out;
        }
@@ -862,11 +881,13 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
        set_buffer_uptodate(bh);
        unlock_buffer(bh);
 
-       if ((err = ext4_journal_dirty_metadata(handle, bh)))
+       err = ext4_journal_dirty_metadata(handle, bh);
+       if (err)
                goto out;
 
        /* create index in new top-level index: num,max,pointer */
-       if ((err = ext4_ext_get_access(handle, inode, curp)))
+       err = ext4_ext_get_access(handle, inode, curp);
+       if (err)
                goto out;
 
        curp->p_hdr->eh_magic = EXT4_EXT_MAGIC;
@@ -879,7 +900,7 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
 
        neh = ext_inode_hdr(inode);
        fidx = EXT_FIRST_INDEX(neh);
-       ext_debug("new root: num %d(%d), lblock %d, ptr "E3FSBLK"\n",
+       ext_debug("new root: num %d(%d), lblock %d, ptr %llu\n",
                  le16_to_cpu(neh->eh_entries), le16_to_cpu(neh->eh_max),
                  le32_to_cpu(fidx->ei_block), idx_pblock(fidx));
 
@@ -892,8 +913,9 @@ out:
 }
 
 /*
- * routine finds empty index and adds new leaf. if no free index found
- * then it requests in-depth growing
+ * ext4_ext_create_new_leaf:
+ * finds empty index and adds new leaf.
+ * if no free index is found, then it requests in-depth growing.
  */
 static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
                                        struct ext4_ext_path *path,
@@ -912,8 +934,8 @@ repeat:
                curp--;
        }
 
-       /* we use already allocated block for index block
-        * so, subsequent data blocks should be contigoues */
+       /* we use already allocated block for index block,
+        * so subsequent data blocks should be contiguous */
        if (EXT_HAS_FREE_INDEX(curp)) {
                /* if we found index with free entry, then use that
                 * entry: create all needed subtree and add new leaf */
@@ -943,12 +965,12 @@ repeat:
                }
 
                /*
-                * only first (depth 0 -> 1) produces free space
-                * in all other cases we have to split growed tree
+                * only first (depth 0 -> 1) produces free space;
+                * in all other cases we have to split the grown tree
                 */
                depth = ext_depth(inode);
                if (path[depth].p_hdr->eh_entries == path[depth].p_hdr->eh_max) {
-                       /* now we need split */
+                       /* now we need to split */
                        goto repeat;
                }
        }
@@ -958,10 +980,11 @@ out:
 }
 
 /*
- * returns allocated block in subsequent extent or EXT_MAX_BLOCK
- * NOTE: it consider block number from index entry as
- * allocated block. thus, index entries have to be consistent
- * with leafs
+ * ext4_ext_next_allocated_block:
+ * returns allocated block in subsequent extent or EXT_MAX_BLOCK.
+ * NOTE: it considers block number from index entry as
+ * allocated block. Thus, index entries have to be consistent
+ * with leaves.
  */
 static unsigned long
 ext4_ext_next_allocated_block(struct ext4_ext_path *path)
@@ -993,10 +1016,11 @@ ext4_ext_next_allocated_block(struct ext4_ext_path *path)
 }
 
 /*
+ * ext4_ext_next_leaf_block:
  * returns first allocated block from next leaf or EXT_MAX_BLOCK
  */
 static unsigned ext4_ext_next_leaf_block(struct inode *inode,
-                                               struct ext4_ext_path *path)
+                                       struct ext4_ext_path *path)
 {
        int depth;
 
@@ -1021,8 +1045,9 @@ static unsigned ext4_ext_next_leaf_block(struct inode *inode,
 }
 
 /*
- * if leaf gets modified and modified extent is first in the leaf
- * then we have to correct all indexes above
+ * ext4_ext_correct_indexes:
+ * if leaf gets modified and modified extent is first in the leaf,
+ * then we have to correct all indexes above.
  * TODO: do we need to correct tree in all cases?
  */
 int ext4_ext_correct_indexes(handle_t *handle, struct inode *inode,
@@ -1050,42 +1075,46 @@ int ext4_ext_correct_indexes(handle_t *handle, struct inode *inode,
        }
 
        /*
-        * TODO: we need correction if border is smaller then current one
+        * TODO: we need correction if border is smaller than current one
         */
        k = depth - 1;
        border = path[depth].p_ext->ee_block;
-       if ((err = ext4_ext_get_access(handle, inode, path + k)))
+       err = ext4_ext_get_access(handle, inode, path + k);
+       if (err)
                return err;
        path[k].p_idx->ei_block = border;
-       if ((err = ext4_ext_dirty(handle, inode, path + k)))
+       err = ext4_ext_dirty(handle, inode, path + k);
+       if (err)
                return err;
 
        while (k--) {
                /* change all left-side indexes */
                if (path[k+1].p_idx != EXT_FIRST_INDEX(path[k+1].p_hdr))
                        break;
-               if ((err = ext4_ext_get_access(handle, inode, path + k)))
+               err = ext4_ext_get_access(handle, inode, path + k);
+               if (err)
                        break;
                path[k].p_idx->ei_block = border;
-               if ((err = ext4_ext_dirty(handle, inode, path + k)))
+               err = ext4_ext_dirty(handle, inode, path + k);
+               if (err)
                        break;
        }
 
        return err;
 }
 
-static int inline
+static int
 ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
                                struct ext4_extent *ex2)
 {
-        if (le32_to_cpu(ex1->ee_block) + le16_to_cpu(ex1->ee_len)
-           != le32_to_cpu(ex2->ee_block))
+       if (le32_to_cpu(ex1->ee_block) + le16_to_cpu(ex1->ee_len) !=
+                       le32_to_cpu(ex2->ee_block))
                return 0;
 
        /*
         * To allow future support for preallocated extents to be added
         * as an RO_COMPAT feature, refuse to merge to extents if
-        * can result in the top bit of ee_len being set
+        * this can result in the top bit of ee_len being set.
         */
        if (le16_to_cpu(ex1->ee_len) + le16_to_cpu(ex2->ee_len) > EXT_MAX_LEN)
                return 0;
@@ -1094,15 +1123,16 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
                return 0;
 #endif
 
-        if (ext_pblock(ex1) + le16_to_cpu(ex1->ee_len) == ext_pblock(ex2))
+       if (ext_pblock(ex1) + le16_to_cpu(ex1->ee_len) == ext_pblock(ex2))
                return 1;
        return 0;
 }
 
 /*
- * this routine tries to merge requsted extent into the existing
- * extent or inserts requested extent as new one into the tree,
- * creating new leaf in no-space case
+ * ext4_ext_insert_extent:
+ * tries to merge requsted extent into the existing extent or
+ * inserts requested extent as new one into the tree,
+ * creating new leaf in the no-space case.
  */
 int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
                                struct ext4_ext_path *path,
@@ -1121,11 +1151,12 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
 
        /* try to insert block into found extent and return */
        if (ex && ext4_can_extents_be_merged(inode, ex, newext)) {
-               ext_debug("append %d block to %d:%d (from "E3FSBLK")\n",
+               ext_debug("append %d block to %d:%d (from %llu)\n",
                                le16_to_cpu(newext->ee_len),
                                le32_to_cpu(ex->ee_block),
                                le16_to_cpu(ex->ee_len), ext_pblock(ex));
-               if ((err = ext4_ext_get_access(handle, inode, path + depth)))
+               err = ext4_ext_get_access(handle, inode, path + depth);
+               if (err)
                        return err;
                ex->ee_len = cpu_to_le16(le16_to_cpu(ex->ee_len)
                                         + le16_to_cpu(newext->ee_len));
@@ -1163,8 +1194,8 @@ repeat:
        }
 
        /*
-        * there is no free space in found leaf
-        * we're gonna add new leaf in the tree
+        * There is no free space in the found leaf.
+        * We're gonna add a new leaf in the tree.
         */
        err = ext4_ext_create_new_leaf(handle, inode, path, newext);
        if (err)
@@ -1175,12 +1206,13 @@ repeat:
 has_space:
        nearex = path[depth].p_ext;
 
-       if ((err = ext4_ext_get_access(handle, inode, path + depth)))
+       err = ext4_ext_get_access(handle, inode, path + depth);
+       if (err)
                goto cleanup;
 
        if (!nearex) {
                /* there is no extent in this leaf, create first one */
-               ext_debug("first extent in the leaf: %d:"E3FSBLK":%d\n",
+               ext_debug("first extent in the leaf: %d:%llu:%d\n",
                                le32_to_cpu(newext->ee_block),
                                ext_pblock(newext),
                                le16_to_cpu(newext->ee_len));
@@ -1192,7 +1224,7 @@ has_space:
                        len = EXT_MAX_EXTENT(eh) - nearex;
                        len = (len - 1) * sizeof(struct ext4_extent);
                        len = len < 0 ? 0 : len;
-                       ext_debug("insert %d:"E3FSBLK":%d after: nearest 0x%p, "
+                       ext_debug("insert %d:%llu:%d after: nearest 0x%p, "
                                        "move %d from 0x%p to 0x%p\n",
                                        le32_to_cpu(newext->ee_block),
                                        ext_pblock(newext),
@@ -1205,7 +1237,7 @@ has_space:
                BUG_ON(newext->ee_block == nearex->ee_block);
                len = (EXT_MAX_EXTENT(eh) - nearex) * sizeof(struct ext4_extent);
                len = len < 0 ? 0 : len;
-               ext_debug("insert %d:"E3FSBLK":%d before: nearest 0x%p, "
+               ext_debug("insert %d:%llu:%d before: nearest 0x%p, "
                                "move %d from 0x%p to 0x%p\n",
                                le32_to_cpu(newext->ee_block),
                                ext_pblock(newext),
@@ -1363,7 +1395,7 @@ int ext4_ext_walk_space(struct inode *inode, unsigned long block,
        return err;
 }
 
-static inline void
+static void
 ext4_ext_put_in_cache(struct inode *inode, __u32 block,
                        __u32 len, __u32 start, int type)
 {
@@ -1377,10 +1409,11 @@ ext4_ext_put_in_cache(struct inode *inode, __u32 block,
 }
 
 /*
- * this routine calculate boundaries of the gap requested block fits into
+ * ext4_ext_put_gap_in_cache:
+ * calculate boundaries of the gap that the requested block fits into
  * and cache this gap
  */
-static inline void
+static void
 ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path,
                                unsigned long block)
 {
@@ -1421,7 +1454,7 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path,
        ext4_ext_put_in_cache(inode, lblock, len, 0, EXT4_EXT_CACHE_GAP);
 }
 
-static inline int
+static int
 ext4_ext_in_cache(struct inode *inode, unsigned long block,
                        struct ext4_extent *ex)
 {
@@ -1439,7 +1472,7 @@ ext4_ext_in_cache(struct inode *inode, unsigned long block,
                ex->ee_block = cpu_to_le32(cex->ec_block);
                ext4_ext_store_pblock(ex, cex->ec_start);
                ex->ee_len = cpu_to_le16(cex->ec_len);
-               ext_debug("%lu cached by %lu:%lu:"E3FSBLK"\n",
+               ext_debug("%lu cached by %lu:%lu:%llu\n",
                                (unsigned long) block,
                                (unsigned long) cex->ec_block,
                                (unsigned long) cex->ec_len,
@@ -1452,9 +1485,10 @@ ext4_ext_in_cache(struct inode *inode, unsigned long block,
 }
 
 /*
- * routine removes index from the index block
- * it's used in truncate case only. thus all requests are for
- * last index in the block only
+ * ext4_ext_rm_idx:
+ * removes index from the index block.
+ * It's used in truncate case only, thus all requests are for
+ * last index in the block only.
  */
 int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
                        struct ext4_ext_path *path)
@@ -1467,12 +1501,14 @@ int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
        path--;
        leaf = idx_pblock(path->p_idx);
        BUG_ON(path->p_hdr->eh_entries == 0);
-       if ((err = ext4_ext_get_access(handle, inode, path)))
+       err = ext4_ext_get_access(handle, inode, path);
+       if (err)
                return err;
        path->p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(path->p_hdr->eh_entries)-1);
-       if ((err = ext4_ext_dirty(handle, inode, path)))
+       err = ext4_ext_dirty(handle, inode, path);
+       if (err)
                return err;
-       ext_debug("index is empty, remove it, free block "E3FSBLK"\n", leaf);
+       ext_debug("index is empty, remove it, free block %llu\n", leaf);
        bh = sb_find_get_block(inode->i_sb, leaf);
        ext4_forget(handle, 1, inode, bh, leaf);
        ext4_free_blocks(handle, inode, leaf, 1);
@@ -1480,13 +1516,14 @@ int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
 }
 
 /*
- * This routine returns max. credits extent tree can consume.
+ * ext4_ext_calc_credits_for_insert:
+ * This routine returns max. credits that the extent tree can consume.
  * It should be OK for low-performance paths like ->writepage()
- * To allow many writing process to fit a single transaction,
- * caller should calculate credits under truncate_mutex and
- * pass actual path.
+ * To allow many writing processes to fit into a single transaction,
+ * the caller should calculate credits under truncate_mutex and
+ * pass the actual path.
  */
-int inline ext4_ext_calc_credits_for_insert(struct inode *inode,
+int ext4_ext_calc_credits_for_insert(struct inode *inode,
                                                struct ext4_ext_path *path)
 {
        int depth, needed;
@@ -1500,9 +1537,9 @@ int inline ext4_ext_calc_credits_for_insert(struct inode *inode,
        }
 
        /*
-        * given 32bit logical block (4294967296 blocks), max. tree
+        * given 32-bit logical block (4294967296 blocks), max. tree
         * can be 4 levels in depth -- 4 * 340^4 == 53453440000.
-        * let's also add one more level for imbalance.
+        * Let's also add one more level for imbalance.
         */
        depth = 5;
 
@@ -1510,17 +1547,18 @@ int inline ext4_ext_calc_credits_for_insert(struct inode *inode,
        needed = 2;
 
        /*
-        * tree can be full, so it'd need to grow in depth:
-        * allocation + old root + new root
+        * tree can be full, so it would need to grow in depth:
+        * we need one credit to modify old root, credits for
+        * new root will be added in split accounting
         */
-       needed += 2 + 1 + 1;
+       needed += 1;
 
        /*
-        * Index split can happen, we'd need:
+        * Index split can happen, we would need:
         *    allocate intermediate indexes (bitmap + group)
         *  + change two blocks at each level, but root (already included)
         */
-       needed = (depth * 2) + (depth * 2);
+       needed += (depth * 2) + (depth * 2);
 
        /* any allocation modifies superblock */
        needed += 1;
@@ -1558,7 +1596,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
                ext4_fsblk_t start;
                num = le32_to_cpu(ex->ee_block) + le16_to_cpu(ex->ee_len) - from;
                start = ext_pblock(ex) + le16_to_cpu(ex->ee_len) - num;
-               ext_debug("free last %lu blocks starting "E3FSBLK"\n", num, start);
+               ext_debug("free last %lu blocks starting %llu\n", num, start);
                for (i = 0; i < num; i++) {
                        bh = sb_find_get_block(inode->i_sb, start + i);
                        ext4_forget(handle, 0, inode, bh, start + i);
@@ -1634,7 +1672,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
                        BUG_ON(b != ex_ee_block + ex_ee_len - 1);
                }
 
-               /* at present, extent can't cross block group */
+               /* at present, extent can't cross block group: */
                /* leaf + bitmap + group desc + sb + inode */
                credits = 5;
                if (ex == EXT_FIRST_EXTENT(eh)) {
@@ -1660,7 +1698,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
                        goto out;
 
                if (num == 0) {
-                       /* this extent is removed entirely mark slot unused */
+                       /* this extent is removed; mark slot entirely unused */
                        ext4_ext_store_pblock(ex, 0);
                        eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries)-1);
                }
@@ -1672,7 +1710,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
                if (err)
                        goto out;
 
-               ext_debug("new extent: %u:%u:"E3FSBLK"\n", block, num,
+               ext_debug("new extent: %u:%u:%llu\n", block, num,
                                ext_pblock(ex));
                ex--;
                ex_ee_block = le32_to_cpu(ex->ee_block);
@@ -1692,9 +1730,10 @@ out:
 }
 
 /*
- * returns 1 if current index have to be freed (even partial)
+ * ext4_ext_more_to_rm:
+ * returns 1 if current index has to be freed (even partial)
  */
-static int inline
+static int
 ext4_ext_more_to_rm(struct ext4_ext_path *path)
 {
        BUG_ON(path->p_idx == NULL);
@@ -1703,7 +1742,7 @@ ext4_ext_more_to_rm(struct ext4_ext_path *path)
                return 0;
 
        /*
-        * if truncate on deeper level happened it it wasn't partial
+        * if truncate on deeper level happened, it wasn't partial,
         * so we have to consider current index for truncation
         */
        if (le16_to_cpu(path->p_hdr->eh_entries) == path->p_block)
@@ -1729,15 +1768,14 @@ int ext4_ext_remove_space(struct inode *inode, unsigned long start)
        ext4_ext_invalidate_cache(inode);
 
        /*
-        * we start scanning from right side freeing all the blocks
-        * after i_size and walking into the deep
+        * We start scanning from right side, freeing all the blocks
+        * after i_size and walking into the tree depth-wise.
         */
-       path = kmalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_KERNEL);
+       path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_KERNEL);
        if (path == NULL) {
                ext4_journal_stop(handle);
                return -ENOMEM;
        }
-       memset(path, 0, sizeof(struct ext4_ext_path) * (depth + 1));
        path[0].p_hdr = ext_inode_hdr(inode);
        if (ext4_ext_check_header(__FUNCTION__, inode, path[0].p_hdr)) {
                err = -EIO;
@@ -1749,7 +1787,7 @@ int ext4_ext_remove_space(struct inode *inode, unsigned long start)
                if (i == depth) {
                        /* this is leaf block */
                        err = ext4_ext_rm_leaf(handle, inode, path, start);
-                       /* root level have p_bh == NULL, brelse() eats this */
+                       /* root level has p_bh == NULL, brelse() eats this */
                        brelse(path[i].p_bh);
                        path[i].p_bh = NULL;
                        i--;
@@ -1772,14 +1810,14 @@ int ext4_ext_remove_space(struct inode *inode, unsigned long start)
                BUG_ON(path[i].p_hdr->eh_magic != EXT4_EXT_MAGIC);
 
                if (!path[i].p_idx) {
-                       /* this level hasn't touched yet */
+                       /* this level hasn't been touched yet */
                        path[i].p_idx = EXT_LAST_INDEX(path[i].p_hdr);
                        path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries)+1;
                        ext_debug("init index ptr: hdr 0x%p, num %d\n",
                                  path[i].p_hdr,
                                  le16_to_cpu(path[i].p_hdr->eh_entries));
                } else {
-                       /* we've already was here, see at next index */
+                       /* we were already here, see at next index */
                        path[i].p_idx--;
                }
 
@@ -1788,7 +1826,7 @@ int ext4_ext_remove_space(struct inode *inode, unsigned long start)
                                path[i].p_idx);
                if (ext4_ext_more_to_rm(path + i)) {
                        /* go to the next level */
-                       ext_debug("move to level %d (block "E3FSBLK")\n",
+                       ext_debug("move to level %d (block %llu)\n",
                                  i + 1, idx_pblock(path[i].p_idx));
                        memset(path + i + 1, 0, sizeof(*path));
                        path[i+1].p_bh =
@@ -1799,19 +1837,19 @@ int ext4_ext_remove_space(struct inode *inode, unsigned long start)
                                break;
                        }
 
-                       /* put actual number of indexes to know is this
-                        * number got changed at the next iteration */
+                       /* save actual number of indexes since this
+                        * number is changed at the next iteration */
                        path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries);
                        i++;
                } else {
-                       /* we finish processing this index, go up */
+                       /* we finished processing this index, go up */
                        if (path[i].p_hdr->eh_entries == 0 && i > 0) {
-                               /* index is empty, remove it
+                               /* index is empty, remove it;
                                 * handle must be already prepared by the
                                 * truncatei_leaf() */
                                err = ext4_ext_rm_idx(handle, inode, path + i);
                        }
-                       /* root level have p_bh == NULL, brelse() eats this */
+                       /* root level has p_bh == NULL, brelse() eats this */
                        brelse(path[i].p_bh);
                        path[i].p_bh = NULL;
                        i--;
@@ -1822,8 +1860,8 @@ int ext4_ext_remove_space(struct inode *inode, unsigned long start)
        /* TODO: flexible tree reduction should be here */
        if (path->p_hdr->eh_entries == 0) {
                /*
-                * truncate to zero freed all the tree
-                * so, we need to correct eh_depth
+                * truncate to zero freed all the tree,
+                * so we need to correct eh_depth
                 */
                err = ext4_ext_get_access(handle, inode, path);
                if (err == 0) {
@@ -1908,11 +1946,12 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
        mutex_lock(&EXT4_I(inode)->truncate_mutex);
 
        /* check in cache */
-       if ((goal = ext4_ext_in_cache(inode, iblock, &newex))) {
+       goal = ext4_ext_in_cache(inode, iblock, &newex);
+       if (goal) {
                if (goal == EXT4_EXT_CACHE_GAP) {
                        if (!create) {
                                /* block isn't allocated yet and
-                                * user don't want to allocate it */
+                                * user doesn't want to allocate it */
                                goto out2;
                        }
                        /* we should allocate requested block */
@@ -1921,7 +1960,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
                        newblock = iblock
                                   - le32_to_cpu(newex.ee_block)
                                   + ext_pblock(&newex);
-                       /* number of remain blocks in the extent */
+                       /* number of remaining blocks in the extent */
                        allocated = le16_to_cpu(newex.ee_len) -
                                        (iblock - le32_to_cpu(newex.ee_block));
                        goto out;
@@ -1941,13 +1980,14 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
        depth = ext_depth(inode);
 
        /*
-        * consistent leaf must not be empty
-        * this situations is possible, though, _during_ tree modification
+        * consistent leaf must not be empty;
+        * this situation is possible, though, _during_ tree modification;
         * this is why assert can't be put in ext4_ext_find_extent()
         */
        BUG_ON(path[depth].p_ext == NULL && depth != 0);
 
-       if ((ex = path[depth].p_ext)) {
+       ex = path[depth].p_ext;
+       if (ex) {
                unsigned long ee_block = le32_to_cpu(ex->ee_block);
                ext4_fsblk_t ee_start = ext_pblock(ex);
                unsigned short ee_len  = le16_to_cpu(ex->ee_len);
@@ -1960,12 +2000,12 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
                 */
                if (ee_len > EXT_MAX_LEN)
                        goto out2;
-               /* if found exent covers block, simple return it */
+               /* if found extent covers block, simply return it */
                if (iblock >= ee_block && iblock < ee_block + ee_len) {
                        newblock = iblock - ee_block + ee_start;
-                       /* number of remain blocks in the extent */
+                       /* number of remaining blocks in the extent */
                        allocated = ee_len - (iblock - ee_block);
-                       ext_debug("%d fit into %lu:%d -> "E3FSBLK"\n", (int) iblock,
+                       ext_debug("%d fit into %lu:%d -> %llu\n", (int) iblock,
                                        ee_block, ee_len, newblock);
                        ext4_ext_put_in_cache(inode, ee_block, ee_len,
                                                ee_start, EXT4_EXT_CACHE_EXTENT);
@@ -1974,18 +2014,19 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
        }
 
        /*
-        * requested block isn't allocated yet
+        * requested block isn't allocated yet;
         * we couldn't try to create block if create flag is zero
         */
        if (!create) {
-               /* put just found gap into cache to speedup subsequest reqs */
+               /* put just found gap into cache to speed up
+                * subsequent requests */
                ext4_ext_put_gap_in_cache(inode, path, iblock);
                goto out2;
        }
        /*
-         * Okay, we need to do block allocation.  Lazily initialize the block
-         * allocation info here if necessary
-        */
+        * Okay, we need to do block allocation.  Lazily initialize the block
+        * allocation info here if necessary.
+        */
        if (S_ISREG(inode->i_mode) && (!EXT4_I(inode)->i_block_alloc_info))
                ext4_init_block_alloc_info(inode);
 
@@ -1995,7 +2036,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
        newblock = ext4_new_blocks(handle, inode, goal, &allocated, &err);
        if (!newblock)
                goto out2;
-       ext_debug("allocate new block: goal "E3FSBLK", found "E3FSBLK"/%lu\n",
+       ext_debug("allocate new block: goal %llu, found %llu/%lu\n",
                        goal, newblock, allocated);
 
        /* try to insert new extent into found leaf and return */
@@ -2062,9 +2103,9 @@ void ext4_ext_truncate(struct inode * inode, struct page *page)
        ext4_ext_invalidate_cache(inode);
 
        /*
-        * TODO: optimization is possible here
-        * probably we need not scaning at all,
-        * because page truncation is enough
+        * TODO: optimization is possible here.
+        * Probably we need not scan at all,
+        * because page truncation is enough.
         */
        if (ext4_orphan_add(handle, inode))
                goto out_stop;
@@ -2078,13 +2119,13 @@ void ext4_ext_truncate(struct inode * inode, struct page *page)
        err = ext4_ext_remove_space(inode, last_block);
 
        /* In a multi-transaction truncate, we only make the final
-        * transaction synchronous */
+        * transaction synchronous. */
        if (IS_SYNC(inode))
                handle->h_sync = 1;
 
 out_stop:
        /*
-        * If this was a simple ftruncate(), and the file will remain alive
+        * If this was a simple ftruncate() and the file will remain alive,
         * then we need to clear up the orphan record which we created above.
         * However, if this was a real unlink then we were called by
         * ext4_delete_inode(), and we allow that function to clean up the
@@ -2098,7 +2139,8 @@ out_stop:
 }
 
 /*
- * this routine calculate max number of blocks we could modify
+ * ext4_ext_writepage_trans_blocks:
+ * calculate max number of blocks we could modify
  * in order to allocate new block for an inode
  */
 int ext4_ext_writepage_trans_blocks(struct inode *inode, int num)
@@ -2107,7 +2149,7 @@ int ext4_ext_writepage_trans_blocks(struct inode *inode, int num)
 
        needed = ext4_ext_calc_credits_for_insert(inode, NULL);
 
-       /* caller want to allocate num blocks, but note it includes sb */
+       /* caller wants to allocate num blocks, but note it includes sb */
        needed = needed * num - (num - 1);
 
 #ifdef CONFIG_QUOTA