ceph: do not direct write executes in parallel if O_APPEND is set
RFC PATCH 1/1 ceph: do not direct write executes in parallel if O_APPEND is set
From: Xiubo Li <[email protected]>
In O_APPEND & O_DIRECT mode, the data from different writers will be possiblly overlapping each other. Just use the exclusive clock instead in O_APPEND & O_DIRECT mode.
Signed-off-by Xiubo Li <[email protected]>
--- fs/ceph/file.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
fs/ceph/file.c +11 -6
@@ -1443,6 +1443,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)struct ceph_cap_flush *prealloc_cf;ssize_t count, written =0 ;int err, want, got; +bool direct_lock = false;loff_t pos;loff_t limit =max (i_size_read (inode), fsc->max_file_size);
@@ -1453,8 +1454,11 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)if (!prealloc_cf)return -ENOMEM ; +if ((iocb->ki_flags & (IOCB_DIRECT |IOCB_APPEND )) ==IOCB_DIRECT ) + direct_lock = true; + retry_snap: -if (iocb->ki_flags &IOCB_DIRECT ) +if (direct_lock)ceph_start_io_direct (inode);else ceph_start_io_write (inode);
@@ -1544,14 +1548,15 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)/* we might need to revert back to that point */ data = *from; -if (iocb->ki_flags &IOCB_DIRECT ) { +if (iocb->ki_flags &IOCB_DIRECT ) written =ceph_direct_read_write (iocb, &data, snapc, &prealloc_cf); -ceph_end_io_direct (inode); - }else { +else written =ceph_sync_write (iocb, &data, pos, snapc); +if (direct_lock) +ceph_end_io_direct (inode); +else ceph_end_io_write (inode); - }if (written >0 )iov_iter_advance (from, written);ceph_put_snap_context (snapc);
@@ -1602,7 +1607,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) goto out_unlocked; out: -if (iocb->ki_flags &IOCB_DIRECT ) +if (direct_lock)ceph_end_io_direct (inode);else ceph_end_io_write (inode);
Signature · 1 line
2.21.0
Quoted 5 lines · On Fri, Jan 31, 2020 at 08:36:19AM -0500, [email protected] wrote:
From: Xiubo Li <[email protected]>
In
O_APPEND&O_DIRECTmode, the data from different writers will be possiblly overlapping each other. Just use the exclusive clock instead inO_APPEND&O_DIRECTmode.
s/clock/lock/
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · On Fri, Jan 31, 2020 at 08:36:19AM -0500, [email protected] wrote:
From: Xiubo Li <[email protected]>
In
O_APPEND&O_DIRECTmode, the data from different writers will be possiblly overlapping each other. Just use the exclusive clock instead inO_APPEND&O_DIRECTmode.s/clock/lock/
Will fix it :-)
Thanks.
BRs