Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (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 72F4C37FF5B; Mon, 1 Jun 2026 07:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297338; cv=none; b=tLl6IvCd61u1pGa2iTMZSdQioOSPLV/cHfj5k0HB3GGE5hT5P8dmEgqSjzfSl0n9qL99fslrquwe1co6MNyaV+ON7RzalRbkPwpV94ZwhT/u5NjRO6TX6pWjYCnwwrz5USPEK7tRQ9pvCLV2jniBH7LEVAGQin9Jxzd36/gE+RI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297338; c=relaxed/simple; bh=bRDe8QjFtxKdu4VN6X2niSuyuif68JQKaQSz2rM3IAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y5cD+7O7XPTXNWskzem4sZOubYhBeJt/FiPHw8I7iHuafQr9CiTpUolwyEscoucjeNNgtZ6k0qi69arPwWlfTjQjTLnn9P/aA8NHamsCtrLRNQeamLj9rikOsySaukPumGPHphjvtRBwdse/1XJx4gbpdjtdQreil3q+bNJgRkw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=laRi+zB8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=A2cuOuua; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b="laRi+zB8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="A2cuOuua" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id C65341400065; Mon, 1 Jun 2026 03:02:16 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Mon, 01 Jun 2026 03:02:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm1; t=1780297336; x=1780383736; bh=sQH7s7MHHWSH1VATRKuLSiOI/pSMRfhZy1jIH52dETA=; b= laRi+zB8bRoUAH3UslPsrIhbYgofRpM8UUBH00KQje21mwPFp1eqGiLjAy1fD7tU Cb4bm04NTQcOXZxiryhcbmDQP9JTwF9eXm2WI1NQBT5VrDWbXVTV9qIQkT79y1El SwYXoKEU+KNAEVgzaGXgcMnGGBo2z0c+caNvXRArX8gAlPwLjxd5+3feZw7CcAQq 39LRbD+4o/UJ+8XU8hYxv+t99g7a39PL/TS6Y2rOUPz6D9i2NcVYScFNSoKF8B10 R5Wa+Xc0UPu7wZV6cntjxNAEPy715IUi48UAPalw5sDxAhvunc/b5KRWWbx9NNSb qaRfXaifuIJg9kP9arpLaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1780297336; x=1780383736; bh=s QH7s7MHHWSH1VATRKuLSiOI/pSMRfhZy1jIH52dETA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w X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Jun 2026 03:02:13 -0400 (EDT) From: NeilBrown To: Christian Brauner , Alexander Viro , Chuck Lever , Jeff Layton Cc: Jan Kara , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, "Jori Koolstra" , Benjamin Coddington , "Mateusz Guzik" Subject: [PATCH 15/18] nfsd: reduce want-write range in nfsd4_create_file( Date: Mon, 1 Jun 2026 16:38:03 +1000 Message-ID: <20260601070042.249432-16-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260601070042.249432-1-neilb@ownmail.net> References: <20260601070042.249432-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown nfsd4_create_file() needs write access to the mount for two purposes: 1/ to create/open the file. 2/ to set attributes on the newly created file. Normally a file being created would be open for write, and once we have an active open we have the write access needed for a setattr. However if a file were created but opened read-only then the setattr wouldn't necessarily have write access to the mount. Currently this is all handled by holding the write access across the open and the setattr. A subsequent patch will necessarily change how write access is gained for the open. So we reduce the range for the first want_write, and add another one only if setattr is needed on a read-only open. Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 03eb93f696f9..5bd19e5d9e34 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -310,7 +310,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, &QSTR_LEN(open->op_fname, open->op_fnamelen)); if (IS_ERR(child)) { status = nfserrno(PTR_ERR(child)); - goto out; + goto out_write; } path.dentry = child; @@ -323,12 +323,13 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, end_creating(child); status = nfserrno(PTR_ERR(open->op_filp)); open->op_filp = NULL; - goto out; + goto out_write; } open->op_created = open->op_filp->f_mode & FMODE_CREATED; } end_creating(child); + fh_drop_write(fhp); status = fh_compose(resfhp, fhp->fh_export, child, fhp); if (status != nfs_ok) @@ -367,7 +368,22 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, fh_fill_post_attrs(fhp); if (is_create_with_attrs(open)) { - status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs); + if (((oflags & O_ACCMODE) == O_RDONLY)) { + /* We will need write access to set the attrs, + * but a successful open won't provide that. + */ + int host_err = fh_want_write(fhp); + if (host_err) { + status = nfserrno(host_err); + } else { + status = nfsd_create_setattr(rqstp, fhp, + resfhp, &attrs); + fh_drop_write(fhp); + } + } else { + status = nfsd_create_setattr(rqstp, fhp, + resfhp, &attrs); + } if (attrs.na_labelerr) open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; @@ -380,8 +396,11 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, } out: nfsd_attrs_free(&attrs); - fh_drop_write(fhp); return status; + +out_write: + fh_drop_write(fhp); + goto out; } /** -- 2.50.0.107.gf914562f5916.dirty