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=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 D400DC433DB for ; Mon, 15 Mar 2021 17:09:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 996CA64EB9 for ; Mon, 15 Mar 2021 17:09:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234209AbhCORJY (ORCPT ); Mon, 15 Mar 2021 13:09:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:34570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234184AbhCORIz (ORCPT ); Mon, 15 Mar 2021 13:08:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6A15F61494; Mon, 15 Mar 2021 17:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615828135; bh=NPhL1YlgUxxI25d29OfqBymy6lFh47nfLoh6850iVNI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ZvV5iSI2f2IdhwRH/tvaXHCJhZsrJvO8JozwuWklLCxIS1q3fW2WUwmYw2mDeogKz Yw2h71KkIMkiqfTOiqa9SHZWRYwmkxnyp0zKw9ZMFdmARh/ibC70h4j5+YDVh4Uhcx DmbDOnFYadmdiqjEdlNykh25N1uCNSb4IKnSJ2ZQKfgmHKYw8ZyZoz8Hi5mE21Yrqm 9+Vx6HwadGxLyiP8MY6i3EuTzTAIcSIEGFY8lIZ5HTxcOUUPKlOWW25X+LkqlA8Hkz N1cmxsbpQGamUsyGbOvb7sQGtv2teuXjQE7sFmxF6SvquIZTfJau7bwbKWI+uneMLp HeJ9xsonFspTA== Message-ID: <33555846ce325ceb7b282f359861fbbcf22840ec.camel@kernel.org> Subject: Re: [PATCH v2 10/15] cifs: have ->mkdir() handle race with another client sanely From: Jeff Layton To: Al Viro , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, David Howells , Hans de Goede , Mike Marshall , Joseph Qi , Bob Peterson , Steve French , Richard Weinberger , Dominique Martinet , Arnd Bergmann Date: Mon, 15 Mar 2021 13:08:53 -0400 In-Reply-To: <20210313043824.1283821-10-viro@zeniv.linux.org.uk> References: <20210313043824.1283821-1-viro@zeniv.linux.org.uk> <20210313043824.1283821-10-viro@zeniv.linux.org.uk> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Sat, 2021-03-13 at 04:38 +0000, Al Viro wrote: > if we have mkdir request reported successful *and* simulating lookup > gets us a non-directory (which is possible if another client has > managed to get rmdir and create in between), the sane action is not > to mangle ->i_mode of non-directory inode to S_IFDIR | mode, it's > "report success and return with dentry negative unhashed" - that > way the next lookup will do the right thing. > > Signed-off-by: Al Viro > --- >  fs/cifs/inode.c | 12 +++++++++++- >  1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c > index d46b36d52211..80c487fcf10e 100644 > --- a/fs/cifs/inode.c > +++ b/fs/cifs/inode.c > @@ -1739,6 +1739,16 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, >   if (rc) >   return rc; >   > > + if (!S_ISDIR(inode->i_mode)) { > + /* > + * mkdir succeeded, but another client has managed to remove the > + * sucker and replace it with non-directory. Return success, > + * but don't leave the child in dcache. > + */ > + iput(inode); > + d_drop(dentry); > + return 0; > + } >   /* >   * setting nlink not necessary except in cases where we failed to get it >   * from the server or was set bogus. Also, since this is a brand new > @@ -1790,7 +1800,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, >   } >   } >   d_instantiate(dentry, inode); > - return rc; > + return 0; >  } >   > >  static int Reviewed-by: Jeff Layton