ext4: Fix special handling of journalled data from extent zeroing
[linux-2.6-microblaze.git] / fs / ext4 / extents.c
index 0b622ae..e79c767 100644 (file)
@@ -4526,13 +4526,6 @@ static long ext4_zero_range(struct file *file, loff_t offset,
 
        trace_ext4_zero_range(inode, offset, len, mode);
 
-       /* Call ext4_force_commit to flush all data in case of data=journal. */
-       if (ext4_should_journal_data(inode)) {
-               ret = ext4_force_commit(inode->i_sb);
-               if (ret)
-                       return ret;
-       }
-
        /*
         * Round up offset. This is not fallocate, we need to zero out
         * blocks, so convert interior block aligned part of the range to
@@ -4616,6 +4609,20 @@ static long ext4_zero_range(struct file *file, loff_t offset,
                        filemap_invalidate_unlock(mapping);
                        goto out_mutex;
                }
+
+               /*
+                * For journalled data we need to write (and checkpoint) pages
+                * before discarding page cache to avoid inconsitent data on
+                * disk in case of crash before zeroing trans is committed.
+                */
+               if (ext4_should_journal_data(inode)) {
+                       ret = filemap_write_and_wait_range(mapping, start, end);
+                       if (ret) {
+                               filemap_invalidate_unlock(mapping);
+                               goto out_mutex;
+                       }
+               }
+
                /* Now release the pages and zero block aligned part of pages */
                truncate_pagecache_range(inode, start, end - 1);
                inode->i_mtime = inode->i_ctime = current_time(inode);