Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt...
[cascardo/linux.git] / fs / ext4 / extents.c
index d7ccb7f..c930a01 100644 (file)
@@ -4679,6 +4679,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
        unsigned int credits;
        loff_t epos;
 
+       BUG_ON(!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS));
        map.m_lblk = offset;
        map.m_len = len;
        /*
@@ -4693,13 +4694,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
         * credits to insert 1 extent into extent tree
         */
        credits = ext4_chunk_trans_blocks(inode, len);
-       /*
-        * We can only call ext_depth() on extent based inodes
-        */
-       if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
-               depth = ext_depth(inode);
-       else
-               depth = -1;
+       depth = ext_depth(inode);
 
 retry:
        while (ret >= 0 && len) {
@@ -4966,13 +4961,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 
        trace_ext4_fallocate_enter(inode, offset, len, mode);
        lblk = offset >> blkbits;
-       /*
-        * We can't just convert len to max_blocks because
-        * If blocksize = 4096 offset = 3072 and len = 2048
-        */
-       max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
-               - lblk;
 
+       max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits);
        flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT;
        if (mode & FALLOC_FL_KEEP_SIZE)
                flags |= EXT4_GET_BLOCKS_KEEP_SIZE;
@@ -5035,12 +5025,8 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
        unsigned int credits, blkbits = inode->i_blkbits;
 
        map.m_lblk = offset >> blkbits;
-       /*
-        * We can't just convert len to max_blocks because
-        * If blocksize = 4096 offset = 3072 and len = 2048
-        */
-       max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) -
-                     map.m_lblk);
+       max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits);
+
        /*
         * This is somewhat ugly but the idea is clear: When transaction is
         * reserved, everything goes into it. Otherwise we rather start several
@@ -5734,6 +5720,9 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
                        up_write(&EXT4_I(inode)->i_data_sem);
                        goto out_stop;
                }
+       } else {
+               ext4_ext_drop_refs(path);
+               kfree(path);
        }
 
        ret = ext4_es_remove_extent(inode, offset_lblk,