From patchwork Mon Aug 5 22:46:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 11077843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AA0D1850 for ; Mon, 5 Aug 2019 22:46:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58CB528970 for ; Mon, 5 Aug 2019 22:46:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CEFB28988; Mon, 5 Aug 2019 22:46:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F409A28984 for ; Mon, 5 Aug 2019 22:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730037AbfHEWqw (ORCPT ); Mon, 5 Aug 2019 18:46:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53850 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729999AbfHEWqw (ORCPT ); Mon, 5 Aug 2019 18:46:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 484AB30A699D; Mon, 5 Aug 2019 22:46:52 +0000 (UTC) Received: from test1135.test.redhat.com (vpn2-54-55.bne.redhat.com [10.64.54.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id D14A510016E8; Mon, 5 Aug 2019 22:46:51 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French , Ronnie Sahlberg Subject: [PATCH] cifs: do not attempt unlink-and-retry-rename for SMB2+ mounts Date: Tue, 6 Aug 2019 08:46:39 +1000 Message-Id: <20190805224639.2322-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 05 Aug 2019 22:46:52 +0000 (UTC) Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Normally in smb you can not rename ontop of a destination that is held open except in SMB1 where this is allowed IFF the delete-on-close flag is also set. This special case is not supported in SMB2 so should not attempt the unlink-and-try-again since the rename will still fail but we now also delete the destination file. Signed-off-by: Ronnie Sahlberg --- fs/cifs/inode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 56ca4b8ccaba..fdea45267a39 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1777,6 +1777,7 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, FILE_UNIX_BASIC_INFO *info_buf_target; unsigned int xid; int rc, tmprc; + struct TCP_Server_Info *server; if (flags & ~RENAME_NOREPLACE) return -EINVAL; @@ -1786,6 +1787,7 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, if (IS_ERR(tlink)) return PTR_ERR(tlink); tcon = tlink_tcon(tlink); + server = tcon->ses->server; xid = get_xid(); @@ -1809,6 +1811,14 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, to_name); /* + * Do not attempt unlink-then-try-rename-again for SMB2+. + * Renaming ontop of an existing open file IF the delete-on-close + * flag is set is only supported for SMB1. + */ + if (rc == -EACCES && server->vals->protocol_id != 0) + goto cifs_rename_exit; + + /* * No-replace is the natural behavior for CIFS, so skip unlink hacks. */ if (flags & RENAME_NOREPLACE)