@@ -2181,8 +2181,6 @@ int gfs2_setattr_size(struct inode *inode, u64 newsize)
if (ret)
return ret;
- inode_dio_wait(inode);
-
ret = gfs2_rsqa_alloc(ip);
if (ret)
goto out;
@@ -806,7 +806,8 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
if (offset + len > i_size_read(&ip->i_inode))
goto out;
- ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL, 0);
+ ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL,
+ IOMAP_DIO_RWSEM_EXCL);
out:
gfs2_glock_dq(&gh);
@@ -923,7 +924,8 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
return generic_write_sync(iocb, ret);
out_unlock:
- inode_unlock(inode);
+ if (ret != -EIOCBQUEUED)
+ inode_unlock(inode);
return ret;
}
@@ -243,11 +243,8 @@ static void inode_go_sync(struct gfs2_glock *gl)
struct address_space *metamapping = gfs2_glock2aspace(gl);
int error;
- if (isreg) {
- if (test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
- unmap_shared_mapping_range(ip->i_inode.i_mapping, 0, 0);
- inode_dio_wait(&ip->i_inode);
- }
+ if (isreg && test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
+ unmap_shared_mapping_range(ip->i_inode.i_mapping, 0, 0);
if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
goto out;
@@ -440,9 +437,6 @@ static int inode_go_lock(struct gfs2_holder *gh)
return error;
}
- if (gh->gh_state != LM_ST_DEFERRED)
- inode_dio_wait(&ip->i_inode);
-
if ((ip->i_diskflags & GFS2_DIF_TRUNC_IN_PROG) &&
(gl->gl_state == LM_ST_EXCLUSIVE) &&
(gh->gh_state == LM_ST_EXCLUSIVE)) {
Switch gfs from the magic i_dio_count scheme to just hold i_rwsem until the actual I/O has completed to reduce the locking complexity and avoid nasty bugs due to missing inode_dio_wait calls. Note that gfs only uses i_rwsem for direct I/O writes, not for reads so no change to the read behavior. It might also make sense to use the same scheme for the gfs2 internal cluster lock. Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/gfs2/bmap.c | 2 -- fs/gfs2/file.c | 6 ++++-- fs/gfs2/glops.c | 10 ++-------- 3 files changed, 6 insertions(+), 12 deletions(-)