]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ext4/inode.c
ext4: Make ext4_get_blocks_wrap take the truncate_mutex early.
[linux-2.6-omap-h63xx.git] / fs / ext4 / inode.c
index eaace1373ccb11cda8e113662ad0375b91e3832f..71c7ad0c6723abdc2601889fa68666ae0cf0cbda 100644 (file)
@@ -243,13 +243,6 @@ static inline void add_chain(Indirect *p, struct buffer_head *bh, __le32 *v)
        p->bh = bh;
 }
 
-static int verify_chain(Indirect *from, Indirect *to)
-{
-       while (from <= to && from->key == *from->p)
-               from++;
-       return (from > to);
-}
-
 /**
  *     ext4_block_to_path - parse the block number into array of offsets
  *     @inode: inode in question (we are only interested in its superblock)
@@ -348,10 +341,11 @@ static int ext4_block_to_path(struct inode *inode,
  *             (pointer to last triple returned, *@err == 0)
  *     or when it gets an IO error reading an indirect block
  *             (ditto, *@err == -EIO)
- *     or when it notices that chain had been changed while it was reading
- *             (ditto, *@err == -EAGAIN)
  *     or when it reads all @depth-1 indirect blocks successfully and finds
  *     the whole chain, all way to the data (returns %NULL, *err == 0).
+ *
+ *      Need to be called with
+ *      mutex_lock(&EXT4_I(inode)->truncate_mutex)
  */
 static Indirect *ext4_get_branch(struct inode *inode, int depth,
                                 ext4_lblk_t  *offsets,
@@ -370,9 +364,6 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
                bh = sb_bread(sb, le32_to_cpu(p->key));
                if (!bh)
                        goto failure;
-               /* Reader: pointers */
-               if (!verify_chain(chain, p))
-                       goto changed;
                add_chain(++p, bh, (__le32*)bh->b_data + *++offsets);
                /* Reader: end */
                if (!p->key)
@@ -380,10 +371,6 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
        }
        return NULL;
 
-changed:
-       brelse(bh);
-       *err = -EAGAIN;
-       goto no_block;
 failure:
        *err = -EIO;
 no_block:
@@ -787,6 +774,10 @@ err_out:
  * return > 0, # of blocks mapped or allocated.
  * return = 0, if plain lookup failed.
  * return < 0, error case.
+ *
+ *
+ * Need to be called with
+ * mutex_lock(&EXT4_I(inode)->truncate_mutex)
  */
 int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
                ext4_lblk_t iblock, unsigned long maxblocks,
@@ -825,18 +816,6 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
                while (count < maxblocks && count <= blocks_to_boundary) {
                        ext4_fsblk_t blk;
 
-                       if (!verify_chain(chain, partial)) {
-                               /*
-                                * Indirect block might be removed by
-                                * truncate while we were reading it.
-                                * Handling of that case: forget what we've
-                                * got now. Flag the err as EAGAIN, so it
-                                * will reread.
-                                */
-                               err = -EAGAIN;
-                               count = 0;
-                               break;
-                       }
                        blk = le32_to_cpu(*(chain[depth-1].p + count));
 
                        if (blk == first_block + count)
@@ -844,44 +823,13 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
                        else
                                break;
                }
-               if (err != -EAGAIN)
-                       goto got_it;
+               goto got_it;
        }
 
        /* Next simple case - plain lookup or failed read of indirect block */
        if (!create || err == -EIO)
                goto cleanup;
 
-       mutex_lock(&ei->truncate_mutex);
-
-       /*
-        * If the indirect block is missing while we are reading
-        * the chain(ext4_get_branch() returns -EAGAIN err), or
-        * if the chain has been changed after we grab the semaphore,
-        * (either because another process truncated this branch, or
-        * another get_block allocated this branch) re-grab the chain to see if
-        * the request block has been allocated or not.
-        *
-        * Since we already block the truncate/other get_block
-        * at this point, we will have the current copy of the chain when we
-        * splice the branch into the tree.
-        */
-       if (err == -EAGAIN || !verify_chain(chain, partial)) {
-               while (partial > chain) {
-                       brelse(partial->bh);
-                       partial--;
-               }
-               partial = ext4_get_branch(inode, depth, offsets, chain, &err);
-               if (!partial) {
-                       count++;
-                       mutex_unlock(&ei->truncate_mutex);
-                       if (err)
-                               goto cleanup;
-                       clear_buffer_new(bh_result);
-                       goto got_it;
-               }
-       }
-
        /*
         * Okay, we need to do block allocation.  Lazily initialize the block
         * allocation info here if necessary
@@ -923,7 +871,6 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
        */
        if (!err && extend_disksize && inode->i_size > ei->i_disksize)
                ei->i_disksize = inode->i_size;
-       mutex_unlock(&ei->truncate_mutex);
        if (err)
                goto cleanup;