ext4: Use bitops to read/modify EXT4_I(inode)->i_state
[deliverable/linux.git] / fs / ext4 / extents.c
index 7d7b74e9468757a241959fd9903d7e5951ab5843..54616157c0f3766ac8f997b7ce0d59b99abaefc9 100644 (file)
@@ -3076,7 +3076,7 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
                if (io)
                        io->flag = DIO_AIO_UNWRITTEN;
                else
-                       EXT4_I(inode)->i_state |= EXT4_STATE_DIO_UNWRITTEN;
+                       ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
                goto out;
        }
        /* async DIO end_io complete, convert the filled extent to written */
@@ -3132,7 +3132,19 @@ out:
                unmap_underlying_metadata_blocks(inode->i_sb->s_bdev,
                                        newblock + max_blocks,
                                        allocated - max_blocks);
+               allocated = max_blocks;
        }
+
+       /*
+        * If we have done fallocate with the offset that is already
+        * delayed allocated, we would have block reservation
+        * and quota reservation done in the delayed write path.
+        * But fallocate would have already updated quota and block
+        * count for this offset. So cancel these reservation
+        */
+       if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
+               ext4_da_update_reserve_space(inode, allocated, 0);
+
 map_out:
        set_buffer_mapped(bh_result);
 out1:
@@ -3350,8 +3362,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
                        if (io)
                                io->flag = DIO_AIO_UNWRITTEN;
                        else
-                               EXT4_I(inode)->i_state |=
-                                       EXT4_STATE_DIO_UNWRITTEN;;
+                               ext4_set_inode_state(inode,
+                                                    EXT4_STATE_DIO_UNWRITTEN);
                }
        }
        err = ext4_ext_insert_extent(handle, inode, path, &newex, flags);
@@ -3368,8 +3380,17 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
        /* previous routine could use block we allocated */
        newblock = ext_pblock(&newex);
        allocated = ext4_ext_get_actual_len(&newex);
+       if (allocated > max_blocks)
+               allocated = max_blocks;
        set_buffer_new(bh_result);
 
+       /*
+        * Update reserved blocks/metadata blocks after successful
+        * block allocation which had been deferred till now.
+        */
+       if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
+               ext4_da_update_reserve_space(inode, allocated, 1);
+
        /*
         * Cache the extent and update transaction to commit on fdatasync only
         * when it is _not_ an uninitialized extent.
@@ -3582,7 +3603,7 @@ retry:
  * Returns 0 on success.
  */
 int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset,
-                                   loff_t len)
+                                   ssize_t len)
 {
        handle_t *handle;
        ext4_lblk_t block;
@@ -3718,7 +3739,7 @@ static int ext4_xattr_fiemap(struct inode *inode,
        int error = 0;
 
        /* in-inode? */
-       if (EXT4_I(inode)->i_state & EXT4_STATE_XATTR) {
+       if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) {
                struct ext4_iloc iloc;
                int offset;     /* offset of xattr in inode */
 
This page took 0.024836 seconds and 5 git commands to generate.