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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Mar 2020 15:43:38 +0000 (16:43 +0100)
commitb520f78ba4286e9ac82ffdf45ec55112058e7891
tree9d9abb579d5713335c2c061c4fd6f615f31e3dca
parent3b0a0bd12963f0aa92195e674c139860098d631c
ceph: do not execute direct write in parallel if O_APPEND is specified

[ Upstream commit 8e4473bb50a1796c9c32b244e5dbc5ee24ead937 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ceph/file.c