Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp921772lqb; Fri, 15 Mar 2024 09:56:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVefrW0op7LzsvtUFV4Zp+CmLSzNtxQ3WONLE3vGurel6q2pmV5kWM4v+pI2ITj9vLUUyMm7kGMCOJ2sweikWK9AZk5eIgQ8+rf6NRCcw== X-Google-Smtp-Source: AGHT+IGe3k1WR97LO3fpj/YyMD/c4Ky36hEk+fmL3BW+oSb7Dj7rEdv34GPVTm0DkQFMdhRvDTuL X-Received: by 2002:ac8:7f8e:0:b0:430:9740:ef2a with SMTP id z14-20020ac87f8e000000b004309740ef2amr5603967qtj.6.1710521818082; Fri, 15 Mar 2024 09:56:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710521818; cv=pass; d=google.com; s=arc-20160816; b=JlhYsCLYDPw7GD9tbwl2Wcg39Zlt99GFlVpwlJWkrZk+D9wVqvwlts5U3CsDaz46C7 rF3lKXIKRMfy4kG09BEEpZD7wH/q7JbmJLC4cqKsKKEtDNTOwfTWTukSYtvojpCDSOBa WX2SHZNCNZqwn61gg+BSCy0ELNAwgZTAv7Hojy4P/OHlgTQl2SmudTFkUhyW43+dr9dB na8M81Seo25St9rf1ZppEujf+ueBO+dI6aEuMBvyCbGfSDIw42twaRvvarVs+hQSFgiL rmFJVPWKrxeRY/rn7lmj18EBMf54bSTDlClALhMtsACY0Pm5GUnBM0x7YYTyJcMjS1uk f6Pw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=ai5f1WJYjacCggYkjaX7bX6lCQFV/7y7NshbV/3cmgA=; fh=KQw6j1pwA9+2sEyzfdoIxUQ6vRmj5Vja7hcK1IN4mbM=; b=x/nnEcKwGHxDks0gWcSlrNs9xXjrqeeUCbRBaQobayYYVJnf01a/EpodHIV4i6Rr9j A1X9/nMxTJrVUZkT2yQWGEahx89BTQ2JwKi9mCwou160+39NfPYyxOTAhwQQyIFcu6BB ryaY8L+lrIKqKC9UgqqEbxltSwnrUB3+f5dz0vKYdpt1lFwvBXOOMtkg2SxPhxBTL6t8 wc4YomNDDtEsfuYKSDRgM4DOr4y8iupu4v5ja5s7B9bM/xprpR/1e09FnVWKYkhakolv O3y772/vLbLtqOdhpK8gSsJD48XdLENyaa0mpBvmk1IBPoLhva5AB3NHQSZL1bdRBMlW Nk+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=taAB791R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2315-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2315-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s12-20020ac85ccc000000b0043095cd72f1si3922329qta.5.2024.03.15.09.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 09:56:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2315-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=taAB791R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2315-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2315-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B5CD31C219A0 for ; Fri, 15 Mar 2024 16:56:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF221548FF; Fri, 15 Mar 2024 16:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="taAB791R" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A00FC56758; Fri, 15 Mar 2024 16:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521606; cv=none; b=oXe6FOA+/6KN8+NzhlKriSic6Ll6pWyVfA8LQ25aWsKZUvu8fX/Uc/C5DollD0XChhUeypIjyF3F1IclT22rukC5mjRPsBNvWzmFxeDyEOX4+BnLkCUdto+BYXWIzTnkHfr6xW5Tpf+O/BaAqFv61yh36TjrA7f9uT/3sHH6WM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521606; c=relaxed/simple; bh=pNsngRzgw8CEGDxcLrFjYZpk10rAX7yWtKnMHw2YxwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rp3VRwMdQeFdnfyjTjWZvR95zX6q6YAMUGP32jcFClo5yQQFYuzx+BjNMjJhBA7rcoh6Tj4vd4R/ZBsADpQpZyJnuKu+BBnr5VNYMy1/bAjKf8wnYofjg2ov42+aJRTZ/QPXxbNmbxedU0U7z51COuViCHhPhowpELgQXg7Zhb0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=taAB791R; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43AAFC43601; Fri, 15 Mar 2024 16:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521606; bh=pNsngRzgw8CEGDxcLrFjYZpk10rAX7yWtKnMHw2YxwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=taAB791R5Xdjx0ThiJdW+vqwgJ+WDVR5BELTZ9zupxXhg6Bkc+GotPp+PPLOTQcu5 Jl+RUQuAa54BcCD2IPeyBKB4+YjtyvJakN+R0EPtGatqoH2m1z9BKDxOC7+jDu1AVr 5wAHTvNaSTobg7b+42t2SuGZf6gzP+0ECNT3uckB/km51Bf+p/AqMIxHor+ZqGVOie uE2sAYylN8qtVz353c51w4I1wQfgrCYiIUElTUwLCI6VYiDWVoduUiqPTxiIewjmxe lMUgWA5r9AQGmYaz28YEQc4VSoHUfoclXASRCXM+O4n7QOQ94Qeym91b6PlmMj5nJA G6dSWDl0MILcQ== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:57 -0400 Subject: [PATCH RFC 06/24] vfs: break parent dir delegations in open(..., O_CREAT) codepath Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240315-dir-deleg-v1-6-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2943; i=jlayton@kernel.org; h=from:subject:message-id; bh=pNsngRzgw8CEGDxcLrFjYZpk10rAX7yWtKnMHw2YxwE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HztCX4vyElQrHztHrMIhenbB3r+5vTs620Ft ibHnhreb96JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FeVWD/9HXrfF8C9gMMmlb/yPm/eZKZ+0UHcF/vvMd2O+2tMmSMQqO0lAD0BNjn+q02XGoga3GXJ y2q3eR+ez9xLCEVoICGz7rJXG9laxCleebaQk8p9mroi2ULPwIzkqb6HDx5dChIahfT9dtUneOO WiXzmgW+fBPkXHL5Bzrl3aKL32BeV6r7HOeX2AqPZC8li35Kl9zlvfpKbu0mRn+44K6hWamilLo vCuAOJTrnxuvPv3gxdTJW4ly5A5l/Bcn2SE1Ah0EEcQysluzy183G34X9taw7eDIpa1QJ5pmqaY tuDw0A4BEpk20WymMN92EtfdTJ/FM2c+gdg3tQxOsSdmxSzljb15j0YqfzTm9UJWc/wjriBIETe ll4FDW16YLwAxN167qoEBhbd+Kg/EAIlePcFD3YpFcU7Zjr5W/cOu0HKYaipxFiGOoN8Y11zMMo mohdx5hBYkcmqcYgHIgIqjFOSNNudIEdhkKZpZJP7jxPkHJZCa9MlqpbVwp+uX9NPaV9N9Y3bGU hqN7nf3kPGs9t6ZZGbPLCRW+nsyzgD24cGBsrXCWktlbYU/i8DWAsd3JxTBuVlT07rDUcidJefA Q0yElVrkmg3clEvHNQGaei1uVg1aps5SAgp5rVHf642TFdxajBoAtlbqzQXUvE74OHkpzrGsHrl b6afdnHiFZjlC1w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a delegated_inode parameter to lookup_open and have it break the delegation. Then, open_last_lookups can wait for the delegation break and retry the call to lookup_open once it's done. Signed-off-by: Jeff Layton --- fs/namei.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index f00d8d708001..88598a62ec64 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3404,7 +3404,7 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, */ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, const struct open_flags *op, - bool got_write) + bool got_write, struct inode **delegated_inode) { struct mnt_idmap *idmap; struct dentry *dir = nd->path.dentry; @@ -3490,6 +3490,11 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, /* Negative dentry, just create the file */ if (!dentry->d_inode && (open_flag & O_CREAT)) { + /* but break the directory lease first! */ + error = try_break_deleg(dir_inode, delegated_inode); + if (error) + goto out_dput; + file->f_mode |= FMODE_CREATED; audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE); if (!dir_inode->i_op->create) { @@ -3517,6 +3522,7 @@ static const char *open_last_lookups(struct nameidata *nd, struct file *file, const struct open_flags *op) { struct dentry *dir = nd->path.dentry; + struct inode *delegated_inode = NULL; int open_flag = op->open_flag; bool got_write = false; struct dentry *dentry; @@ -3553,7 +3559,7 @@ static const char *open_last_lookups(struct nameidata *nd, if (unlikely(nd->last.name[nd->last.len])) return ERR_PTR(-EISDIR); } - +retry: if (open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) { got_write = !mnt_want_write(nd->path.mnt); /* @@ -3566,7 +3572,7 @@ static const char *open_last_lookups(struct nameidata *nd, inode_lock(dir->d_inode); else inode_lock_shared(dir->d_inode); - dentry = lookup_open(nd, file, op, got_write); + dentry = lookup_open(nd, file, op, got_write, &delegated_inode); if (!IS_ERR(dentry) && (file->f_mode & FMODE_CREATED)) fsnotify_create(dir->d_inode, dentry); if (open_flag & O_CREAT) @@ -3577,8 +3583,16 @@ static const char *open_last_lookups(struct nameidata *nd, if (got_write) mnt_drop_write(nd->path.mnt); - if (IS_ERR(dentry)) + if (IS_ERR(dentry)) { + if (delegated_inode) { + int error = break_deleg_wait(&delegated_inode); + + if (!error) + goto retry; + return ERR_PTR(error); + } return ERR_CAST(dentry); + } if (file->f_mode & (FMODE_OPENED | FMODE_CREATED)) { dput(nd->path.dentry); -- 2.44.0