Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10190222ybi; Wed, 24 Jul 2019 18:01:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPV6lcW6+j4qroWtD2IlrmoufW/L5PLF2pJJ1PL9E6E3iIK93sZjnhiQOiLKLs1qLTlS43 X-Received: by 2002:a17:902:4b:: with SMTP id 69mr87776890pla.89.1564016478338; Wed, 24 Jul 2019 18:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564016478; cv=none; d=google.com; s=arc-20160816; b=NmoTbgi6fSobI+/rw/p+GlQTzffqen3q5Qd6Erh2cI+FGIhqOwv2p79UCys0RHCubD Ml68PjCPlXuuWLutjdVogYVh0VSfAeeXuE5ogyig0pD3jtPHms11fk7ZIbYOft1uSQBl k1ZGz/yYOSQapv8QajwNT0jFW0hnGmBsswidTY10peLwaZyxTN8POLaLgN1xaeJu5nns zDqzm4KkcMGHhqeggQ5BZEqrhsx4Eh07daxXictQgc6So+hCwtN9jAzh2M8CA7FqcVdp qMa1tck9ELsijsZF89hUW63DD/RMKih7w/BCEjFGoxrmxkrsoup2gyUzp6jU75WzP/J8 HqYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/w7ZTgqVpWj4D9C2+q2K+wla9B5BAUOFn472KCBSirw=; b=z2z+ylZnAF5xn5A45hEl8P26dFEmUnND8n6mwTEoDLi04PD8I90oDdpc/8KNKJUnh3 mLzoKigM/qclp1Pu9uOzqFBrFgBTpX5KIoutjGMow0rBhFCFcXLNqkP6j8w74YLdGPtb rienaEbmQwqmV5I1SroK4rwDV3TvsEpNMaf4cCh5oOVDw+8+z9xcr33fPKVzY136iwen y2lLAzhf2Lm7rgFp7Nvs8RIRjIf1ZgGdfFCbENEW6sdUYm3E3cnb96KbYgPZ6i8M37DQ YQmRQhMIZM1BRVrWgDUNdfss6b4w9KyYhbxyaiQTt7wixz6JKTvJWRUip282KEq25ajk pmiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jjXRN4/r"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 19si18032323pfc.239.2019.07.24.18.01.03; Wed, 24 Jul 2019 18:01:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jjXRN4/r"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389292AbfGXTgM (ORCPT + 99 others); Wed, 24 Jul 2019 15:36:12 -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)