@@ -7726,6 +7726,17 @@ static int direct_iomap_begin(struct inode *inode, loff_t start,
lockstart = start;
lockend = start + len - 1;
+ /*
+ * The generic stuff only does filemap_write_and_wait_range, which
+ * isn't enough if we've written compressed pages to this area, so
+ * we need to flush the dirty pages again to make absolutely sure
+ * that any outstanding dirty pages are on disk.
+ */
+ if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
+ &BTRFS_I(inode)->runtime_flags))
+ filemap_fdatawrite_range(inode->i_mapping, lockstart, lockend);
+
+
if (current->journal_info) {
/*
* Need to pull our outstanding extents and set journal_info to NULL so