cifs: flush before set-info if we have writeable handles
authorRonnie Sahlberg <lsahlber@redhat.com>
Thu, 18 Jul 2019 22:12:11 +0000 (08:12 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Jul 2019 07:12:54 +0000 (09:12 +0200)
commitbe5bc9daadec9ac656d04a8de34a0368607cdff0
treec6f8a4169fe4d0682a6105bf0a38fbf570e3b319
parentc0fcf57679ec80a83c5b752f1e1e96019c81ba4d
cifs: flush before set-info if we have writeable handles

commit aa081859b10c5d8b19f5c525c78883a59d73c2b8 upstream.

Servers can defer destaging any data and updating the mtime until close().
This means that if we do a setinfo to modify the mtime while other handles
are open for write the server may overwrite our setinfo timestamps when
if flushes the file on close() of the writeable handle.

To solve this we add an explicit flush when the mtime is about to
be updated.

This fixes "cp -p" to preserve mtime when copying a file onto an SMB2 share.

CC: Stable <stable@vger.kernel.org>
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/cifs/inode.c