ceph: do not execute direct write in parallel if O_APPEND is specified
authorXiubo Li <xiubli@redhat.com>
Tue, 4 Feb 2020 02:28:25 +0000 (21:28 -0500)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 11 Feb 2020 16:04:04 +0000 (17:04 +0100)
commit8e4473bb50a1796c9c32b244e5dbc5ee24ead937
tree7de41d8d856fcca65497e08059ea660f682295d9
parentbb6d3fb354c5ee8d6bde2d576eb7220ea09862b9
ceph: do not execute direct write in parallel if O_APPEND is specified

In O_APPEND & O_DIRECT mode, the data from different writers will
be possibly overlapping each other since they take the shared lock.

For example, both Writer1 and Writer2 are in O_APPEND and O_DIRECT
mode:

          Writer1                         Writer2

     shared_lock()                   shared_lock()
     getattr(CAP_SIZE)               getattr(CAP_SIZE)
     iocb->ki_pos = EOF              iocb->ki_pos = EOF
     write(data1)
                                     write(data2)
     shared_unlock()                 shared_unlock()

The data2 will overlap the data1 from the same file offset, the
old EOF.

Switch to exclusive lock instead when O_APPEND is specified.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/file.c