From patchwork Fri Aug 22 09:32:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 4762511 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 21476C0338 for ; Fri, 22 Aug 2014 09:33:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53EF2201BA for ; Fri, 22 Aug 2014 09:33:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 220582018A for ; Fri, 22 Aug 2014 09:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755959AbaHVJdp (ORCPT ); Fri, 22 Aug 2014 05:33:45 -0400 Received: from mail-lb0-f179.google.com ([209.85.217.179]:59792 "EHLO mail-lb0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752114AbaHVJdo (ORCPT ); Fri, 22 Aug 2014 05:33:44 -0400 Received: by mail-lb0-f179.google.com with SMTP id v6so9142268lbi.38 for ; Fri, 22 Aug 2014 02:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ky2oPzdLXx13YM/3Vj9ivlOZtnVy/Wutvc5tGlyNXKs=; b=UKe/1sMJlLShki0Ecud9tQusKyAqfLv5vjWEs9KMj7bW76rALM4tim+BmeEPyPlJbK y5wuzVvjkKhEfHSHCPQS+xABl9xntfCxsT07sZ62oCfgWd2csUTtRGlwu8xtEv1+DW9+ 9tdqpfUfoPxWjrOuMTnSIPiUtaIYYBNRsDuNBfprNdJ7RLTUZGpXR7YDuGirdRlJ1CqR ij7eepTJqzN5VXVuEuhvLgqL0UvFdE5tllaFraoZXiKTp0VirNSTmmVuCnhRlKwjZK1M wx6vhYdUfACwgXX+CfCqklO9lD+p4iXZvqKNmXltWadMCyM8LJCq1uYhvMluqu6FIoUs HKwA== X-Received: by 10.152.87.229 with SMTP id bb5mr3576491lab.75.1408700022758; Fri, 22 Aug 2014 02:33:42 -0700 (PDT) Received: from localhost.localdomain ([85.26.164.242]) by mx.google.com with ESMTPSA id kc1sm20752571lbc.35.2014.08.22.02.33.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Aug 2014 02:33:41 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Subject: [PATCH 1/3] CIFS: Fix directory rename error Date: Fri, 22 Aug 2014 13:32:09 +0400 Message-Id: <1408699931-22515-2-git-send-email-pshilovsky@samba.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1408699931-22515-1-git-send-email-pshilovsky@samba.org> References: <1408699931-22515-1-git-send-email-pshilovsky@samba.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_WEB,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CIFS servers process nlink counts differently for files and directories. In cifs_rename() if we the request fails on the existing target, we try to remove it through cifs_unlink() but this is not what we want to do for directories. As the result the following sequence of commands mkdir {1,2}; mv -T 1 2; rmdir {1,2}; mkdir {1,2}; echo foo > 2/bar and XFS test generic/023 fail with -ENOENT error. That's why the second mkdir reuses the existing inode (target inode of the mv -T command) with S_DEAD flag. Fix this by checking whether the target is directory or not and calling cifs_rmdir() rather than cifs_unlink() for directories. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 949ec90..7899a40 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1720,7 +1720,10 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, unlink_target: /* Try unlinking the target dentry if it's not negative */ if (target_dentry->d_inode && (rc == -EACCES || rc == -EEXIST)) { - tmprc = cifs_unlink(target_dir, target_dentry); + if (d_is_dir(target_dentry)) + tmprc = cifs_rmdir(target_dir, target_dentry); + else + tmprc = cifs_unlink(target_dir, target_dentry); if (tmprc) goto cifs_rename_exit; rc = cifs_do_rename(xid, source_dentry, from_name,