|
@@ -4191,6 +4191,39 @@ int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static void ext4_wait_dax_page(struct ext4_inode_info *ei, bool *did_unlock)
|
|
|
+{
|
|
|
+ *did_unlock = true;
|
|
|
+ up_write(&ei->i_mmap_sem);
|
|
|
+ schedule();
|
|
|
+ down_write(&ei->i_mmap_sem);
|
|
|
+}
|
|
|
+
|
|
|
+int ext4_break_layouts(struct inode *inode)
|
|
|
+{
|
|
|
+ struct ext4_inode_info *ei = EXT4_I(inode);
|
|
|
+ struct page *page;
|
|
|
+ bool retry;
|
|
|
+ int error;
|
|
|
+
|
|
|
+ if (WARN_ON_ONCE(!rwsem_is_locked(&ei->i_mmap_sem)))
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
+ do {
|
|
|
+ retry = false;
|
|
|
+ page = dax_layout_busy_page(inode->i_mapping);
|
|
|
+ if (!page)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ error = ___wait_var_event(&page->_refcount,
|
|
|
+ atomic_read(&page->_refcount) == 1,
|
|
|
+ TASK_INTERRUPTIBLE, 0, 0,
|
|
|
+ ext4_wait_dax_page(ei, &retry));
|
|
|
+ } while (error == 0 && retry);
|
|
|
+
|
|
|
+ return error;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* ext4_punch_hole: punches a hole in a file by releasing the blocks
|
|
|
* associated with the given offset and length
|
|
@@ -4264,6 +4297,11 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
|
|
|
* page cache.
|
|
|
*/
|
|
|
down_write(&EXT4_I(inode)->i_mmap_sem);
|
|
|
+
|
|
|
+ ret = ext4_break_layouts(inode);
|
|
|
+ if (ret)
|
|
|
+ goto out_dio;
|
|
|
+
|
|
|
first_block_offset = round_up(offset, sb->s_blocksize);
|
|
|
last_block_offset = round_down((offset + length), sb->s_blocksize) - 1;
|
|
|
|
|
@@ -5553,6 +5591,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
ext4_wait_for_tail_page_commit(inode);
|
|
|
}
|
|
|
down_write(&EXT4_I(inode)->i_mmap_sem);
|
|
|
+
|
|
|
+ rc = ext4_break_layouts(inode);
|
|
|
+ if (rc) {
|
|
|
+ up_write(&EXT4_I(inode)->i_mmap_sem);
|
|
|
+ error = rc;
|
|
|
+ goto err_out;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* Truncate pagecache after we've waited for commit
|
|
|
* in data=journal mode to make pages freeable.
|