From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2A33C76186 for ; Wed, 24 Jul 2019 19:36:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D0AE22ADA for ; Wed, 24 Jul 2019 19:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996974; bh=JyVWWgTru0+hhOtXI5G3CuzzTpgTucTPxwcbyHaOmug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QsPLrU/kNdTGKiM3pT/rCxDXy6100moFFAJj1oI01RiYVNeAXEHRxpBfSKZWcc93h /04wHta8f/W6sqzGbi/YcN1GI9rQfcxS4unMsC6Tb90z4TiC/OovxixotRo9PCzVdy ssIeX9Y8WWUXtZgKDfzXZJKJ597b1oYVxCMUnTeo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388828AbfGXTgN (ORCPT ); Wed, 24 Jul 2019 15:36:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:35752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389284AbfGXTgK (ORCPT ); Wed, 24 Jul 2019 15:36:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 96E382238C; Wed, 24 Jul 2019 19:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996969; bh=JyVWWgTru0+hhOtXI5G3CuzzTpgTucTPxwcbyHaOmug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjXRN4/rxsEC4O1MAfBqgpKitfcH5814TzVf1cLJrcSoFy1/ATUxgjfgs5P4tDDCW bGig3ucANeU4vhvoQVN5rAqObohH4tqTA2rbRiqh8qmEQzIR+mR0HuAqcvUZwE+A1B HUX4X3YV5TRzVPYFYffKQhVdzYIdklxx5QPwRX6A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ronnie Sahlberg , Pavel Shilovsky , Steve French Subject: [PATCH 5.2 278/413] cifs: flush before set-info if we have writeable handles Date: Wed, 24 Jul 2019 21:19:29 +0200 Message-Id: <20190724191756.193439255@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ronnie Sahlberg 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 Signed-off-by: Ronnie Sahlberg Reviewed-by: Pavel Shilovsky Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/inode.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -2408,6 +2408,8 @@ cifs_setattr_nounix(struct dentry *diren struct inode *inode = d_inode(direntry); struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifsInodeInfo *cifsInode = CIFS_I(inode); + struct cifsFileInfo *wfile; + struct cifs_tcon *tcon; char *full_path = NULL; int rc = -EACCES; __u32 dosattr = 0; @@ -2454,6 +2456,20 @@ cifs_setattr_nounix(struct dentry *diren mapping_set_error(inode->i_mapping, rc); rc = 0; + if (attrs->ia_valid & ATTR_MTIME) { + rc = cifs_get_writable_file(cifsInode, false, &wfile); + if (!rc) { + tcon = tlink_tcon(wfile->tlink); + rc = tcon->ses->server->ops->flush(xid, tcon, &wfile->fid); + cifsFileInfo_put(wfile); + if (rc) + return rc; + } else if (rc != -EBADF) + return rc; + else + rc = 0; + } + if (attrs->ia_valid & ATTR_SIZE) { rc = cifs_set_file_size(inode, attrs, xid, full_path); if (rc != 0)