Commit 562c72aa authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro

fs: move inode_dio_wait calls into ->setattr

Let filesystems handle waiting for direct I/O requests themselves instead
of doing it beforehand.  This means filesystem-specific locks to prevent
new dio referenes from appearing can be held.  This is important to allow
generalizing i_dio_count to non-DIO_LOCKING filesystems.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 11b80f45
...@@ -232,9 +232,6 @@ int notify_change(struct dentry * dentry, struct iattr * attr) ...@@ -232,9 +232,6 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
if (error) if (error)
return error; return error;
if (ia_valid & ATTR_SIZE)
inode_dio_wait(inode);
if (inode->i_op->setattr) if (inode->i_op->setattr)
error = inode->i_op->setattr(dentry, attr); error = inode->i_op->setattr(dentry, attr);
else else
......
...@@ -1184,6 +1184,8 @@ static int ext2_setsize(struct inode *inode, loff_t newsize) ...@@ -1184,6 +1184,8 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)
if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return -EPERM; return -EPERM;
inode_dio_wait(inode);
if (mapping_is_xip(inode->i_mapping)) if (mapping_is_xip(inode->i_mapping))
error = xip_truncate_page(inode->i_mapping, newsize); error = xip_truncate_page(inode->i_mapping, newsize);
else if (test_opt(inode->i_sb, NOBH)) else if (test_opt(inode->i_sb, NOBH))
......
...@@ -3216,6 +3216,9 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -3216,6 +3216,9 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
ext3_journal_stop(handle); ext3_journal_stop(handle);
} }
if (attr->ia_valid & ATTR_SIZE)
inode_dio_wait(inode);
if (S_ISREG(inode->i_mode) && if (S_ISREG(inode->i_mode) &&
attr->ia_valid & ATTR_SIZE && attr->ia_size < inode->i_size) { attr->ia_valid & ATTR_SIZE && attr->ia_size < inode->i_size) {
handle_t *handle; handle_t *handle;
......
...@@ -5351,6 +5351,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -5351,6 +5351,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
} }
if (attr->ia_valid & ATTR_SIZE) { if (attr->ia_valid & ATTR_SIZE) {
inode_dio_wait(inode);
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
......
...@@ -397,6 +397,8 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -397,6 +397,8 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
* sequence. * sequence.
*/ */
if (attr->ia_valid & ATTR_SIZE) { if (attr->ia_valid & ATTR_SIZE) {
inode_dio_wait(inode);
if (attr->ia_size > inode->i_size) { if (attr->ia_size > inode->i_size) {
error = fat_cont_expand(inode, attr->ia_size); error = fat_cont_expand(inode, attr->ia_size);
if (error || attr->ia_valid == ATTR_SIZE) if (error || attr->ia_valid == ATTR_SIZE)
......
...@@ -1224,6 +1224,8 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize) ...@@ -1224,6 +1224,8 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize)
if (ret) if (ret)
return ret; return ret;
inode_dio_wait(inode);
oldsize = inode->i_size; oldsize = inode->i_size;
if (newsize >= oldsize) if (newsize >= oldsize)
return do_grow(inode, newsize); return do_grow(inode, newsize);
......
...@@ -615,6 +615,8 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr) ...@@ -615,6 +615,8 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)
if ((attr->ia_valid & ATTR_SIZE) && if ((attr->ia_valid & ATTR_SIZE) &&
attr->ia_size != i_size_read(inode)) { attr->ia_size != i_size_read(inode)) {
inode_dio_wait(inode);
error = vmtruncate(inode, attr->ia_size); error = vmtruncate(inode, attr->ia_size);
if (error) if (error)
return error; return error;
......
...@@ -296,6 +296,8 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -296,6 +296,8 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
if ((attr->ia_valid & ATTR_SIZE) && if ((attr->ia_valid & ATTR_SIZE) &&
attr->ia_size != i_size_read(inode)) { attr->ia_size != i_size_read(inode)) {
inode_dio_wait(inode);
error = vmtruncate(inode, attr->ia_size); error = vmtruncate(inode, attr->ia_size);
if (error) if (error)
return error; return error;
......
...@@ -110,6 +110,8 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -110,6 +110,8 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
if ((iattr->ia_valid & ATTR_SIZE) && if ((iattr->ia_valid & ATTR_SIZE) &&
iattr->ia_size != i_size_read(inode)) { iattr->ia_size != i_size_read(inode)) {
inode_dio_wait(inode);
rc = vmtruncate(inode, iattr->ia_size); rc = vmtruncate(inode, iattr->ia_size);
if (rc) if (rc)
return rc; return rc;
......
...@@ -778,6 +778,8 @@ int nilfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -778,6 +778,8 @@ int nilfs_setattr(struct dentry *dentry, struct iattr *iattr)
if ((iattr->ia_valid & ATTR_SIZE) && if ((iattr->ia_valid & ATTR_SIZE) &&
iattr->ia_size != i_size_read(inode)) { iattr->ia_size != i_size_read(inode)) {
inode_dio_wait(inode);
err = vmtruncate(inode, iattr->ia_size); err = vmtruncate(inode, iattr->ia_size);
if (unlikely(err)) if (unlikely(err))
goto out_err; goto out_err;
......
...@@ -1142,6 +1142,8 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -1142,6 +1142,8 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
if (status) if (status)
goto bail_unlock; goto bail_unlock;
inode_dio_wait(inode);
if (i_size_read(inode) > attr->ia_size) { if (i_size_read(inode) > attr->ia_size) {
if (ocfs2_should_order_data(inode)) { if (ocfs2_should_order_data(inode)) {
status = ocfs2_begin_ordered_truncate(inode, status = ocfs2_begin_ordered_truncate(inode,
......
...@@ -3114,6 +3114,9 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -3114,6 +3114,9 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
error = -EFBIG; error = -EFBIG;
goto out; goto out;
} }
inode_dio_wait(inode);
/* fill in hole pointers in the expanding truncate case. */ /* fill in hole pointers in the expanding truncate case. */
if (attr->ia_size > inode->i_size) { if (attr->ia_size > inode->i_size) {
error = generic_cont_expand_simple(inode, attr->ia_size); error = generic_cont_expand_simple(inode, attr->ia_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment