]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
ext4: add i_data_sem sanity check
authorDmitry Monakhov <dmonakhov@openvz.org>
Mon, 28 Jul 2014 02:28:15 +0000 (22:28 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 28 Jul 2014 02:28:15 +0000 (22:28 -0400)
Each caller of ext4_ext_dirty must hold i_data_sem,
The only exception is migration code, let's make it convenient.

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
fs/ext4/extents.c
fs/ext4/migrate.c

index b30172dd55eb07e0ecd41d5596e8cf71e3e2e6e5..ee93f82630c61f6bd912c17ac8726de0c1a0c46a 100644 (file)
@@ -161,6 +161,8 @@ int __ext4_ext_dirty(const char *where, unsigned int line, handle_t *handle,
                     struct inode *inode, struct ext4_ext_path *path)
 {
        int err;
+
+       WARN_ON(!rwsem_is_locked(&EXT4_I(inode)->i_data_sem));
        if (path->p_bh) {
                ext4_extent_block_csum_set(inode, ext_block_hdr(path->p_bh));
                /* path points to block */
index ec092437d3e0b4c4788e9b49928af80a9e43a1cb..d3567f27bae7071931bcc4b06470caf69d123d7b 100644 (file)
@@ -39,6 +39,8 @@ static int finish_range(handle_t *handle, struct inode *inode,
        newext.ee_block = cpu_to_le32(lb->first_block);
        newext.ee_len   = cpu_to_le16(lb->last_block - lb->first_block + 1);
        ext4_ext_store_pblock(&newext, lb->first_pblock);
+       /* Locking only for convinience since we are operating on temp inode */
+       down_write(&EXT4_I(inode)->i_data_sem);
        path = ext4_ext_find_extent(inode, lb->first_block, NULL, 0);
 
        if (IS_ERR(path)) {
@@ -61,7 +63,9 @@ static int finish_range(handle_t *handle, struct inode *inode,
         */
        if (needed && ext4_handle_has_enough_credits(handle,
                                                EXT4_RESERVE_TRANS_BLOCKS)) {
+               up_write((&EXT4_I(inode)->i_data_sem));
                retval = ext4_journal_restart(handle, needed);
+               down_write((&EXT4_I(inode)->i_data_sem));
                if (retval)
                        goto err_out;
        } else if (needed) {
@@ -70,13 +74,16 @@ static int finish_range(handle_t *handle, struct inode *inode,
                        /*
                         * IF not able to extend the journal restart the journal
                         */
+                       up_write((&EXT4_I(inode)->i_data_sem));
                        retval = ext4_journal_restart(handle, needed);
+                       down_write((&EXT4_I(inode)->i_data_sem));
                        if (retval)
                                goto err_out;
                }
        }
        retval = ext4_ext_insert_extent(handle, inode, path, &newext, 0);
 err_out:
+       up_write((&EXT4_I(inode)->i_data_sem));
        if (path) {
                ext4_ext_drop_refs(path);
                kfree(path);