Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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 71E8B35C180; Mon, 1 Jun 2026 07:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297312; cv=none; b=Y4bYrAiaIhoUMEVqI35tbdW3OlTvB62N/UlK3YABdrVLhVfWFWI+Qiho4dazg2SsqkbKnq+9pydfG1Sw0XXIyYOTsbm3QRSeLpVNowx9lQxaKlnJ9oynLi1ZVJ5u9toI/gu8mvEDlk9E1DwoW46Jv2VIKRTAPAQ8ua8jgMRX/Pg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297312; c=relaxed/simple; bh=WdEMOzcsDChipQldHx7oLl3JxEQOvDhlD+JF5fLHDDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tAtJNdlFtVkDhxK9kVoHfL6SAGftStWeb2NuKim3EruKXxfq62NCBog0FmGmE5Ds+hciNWwVYHVHO1djEJ0rHBhAnJQyYs+fz1secCGUP/PGXMZe3ON2dZONltm4nOIvg1ZpEy4VvTCYbCOvUrKl+Pd+TDQqdEdpepkvGqpjrfA= 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=rFWwQat0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=V509vnXj; arc=none smtp.client-ip=103.168.172.150 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="rFWwQat0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="V509vnXj" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id B42EBEC01CA; Mon, 1 Jun 2026 03:01:50 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Mon, 01 Jun 2026 03:01:50 -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=1780297310; x=1780383710; bh=KbuELhquSMglCIc7yfH+vCmCpoV49ZOEp1JXA1a2Uxk=; b= rFWwQat0zZU5Nlqu9haVDD6aoQVOc7KdKS4eRw6XRKZkGQWr1hypjCePmG68KHig uTIzbaTTCo/u4wadFBMuibOdsbPjte9xmFcf0mh0PgrnRu/0LXcOeG106L9zzO9E fw5yKeudVT3b4ERKoyqDni1Qlf2powVlQDl5nEvS1SLBFY8+kF6G1/Gym+wLANAR x4+9e6qg6BpqSefA6HFoTZLAMoTbSb6sMBzwUX5nQ4omcffCxkO66Jr9G7yNLGlK 5y/yQyurOu6CImVAkCHKS8n3hf59Cst8Hg+R02KiclyIARZxhi0JAPSKZEOW7AYr Vnm+3WBl5NHQO45Sc0NEyw== 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=1780297310; x=1780383710; bh=K buELhquSMglCIc7yfH+vCmCpoV49ZOEp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J+w X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Jun 2026 03:01:47 -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 10/18] nfsd: in nfsd4_create_file() let VFS report if file was created. Date: Mon, 1 Jun 2026 16:37:58 +1000 Message-ID: <20260601070042.249432-11-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() currently assumes that if a lookup failed but then a create succeeds, then the "create" created the file. With atomic_open this may not be the case - some other actor might have created the file between the lookup and the create. So we move the call to nfsd4_vfs_create() earlier and set ->op_created based on that. Then use "! ->op_created" to trigger nfserr_exist handling. The switch statement is split up into two if() statements. First we check for the possibility of a successful exclusive create and set ->op_create to true if appropriate. Then we check for NFS4_CREATE_UNCHECKED to decide if a pre-existing file means an error or success. This allows us to combine the two fh_compose() calls to one place. With this rearrangement we now repeat the setattr when an exclusive create is repeated. This should be both rare and harmless, and it simplifies the code. Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 75 ++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 3446f9b43bf8..bce64e2061d7 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -337,58 +337,49 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; } - if (d_really_is_positive(child)) { - /* NFSv4 protocol requires change attributes even though - * no change happened. - */ - fh_fill_post_noop(fhp); - - status = fh_compose(resfhp, fhp->fh_export, child, fhp); + if (d_really_is_negative(child)) { + status = nfsd4_vfs_create(fhp, &child, open); if (status != nfs_ok) goto out; + open->op_created = open->op_filp->f_mode & FMODE_CREATED; + } - switch (open->op_createmode) { - case NFS4_CREATE_UNCHECKED: - if (!d_is_reg(child)) - break; + status = fh_compose(resfhp, fhp->fh_export, child, fhp); + if (status != nfs_ok) + goto out; - /* - * In NFSv4, we don't want to truncate the file - * now. This would be wrong if the OPEN fails for - * some other reason. Furthermore, if the size is - * nonzero, we should ignore it according to spec! - */ - open->op_truncate = (iap->ia_valid & ATTR_SIZE) && - !iap->ia_size; - break; - case NFS4_CREATE_GUARDED: - status = nfserr_exist; - break; - case NFS4_CREATE_EXCLUSIVE: - case NFS4_CREATE_EXCLUSIVE4_1: - if (inode_get_mtime_sec(d_inode(child)) == v_mtime && - inode_get_atime_sec(d_inode(child)) == v_atime && - d_inode(child)->i_size == 0) { - open->op_created = true; - goto set_attr; - } - status = nfserr_exist; - break; - } + if (!open->op_created && + nfsd4_create_is_exclusive(open->op_createmode) && + inode_get_mtime_sec(d_inode(child)) == v_mtime && + inode_get_atime_sec(d_inode(child)) == v_atime && + d_inode(child)->i_size == 0) + open->op_created = true; + + if (!open->op_created && + open->op_createmode == NFS4_CREATE_UNCHECKED) { + /* NFSv4 protocol requires change attributes + * even though no change happened. + */ + fh_fill_post_noop(fhp); + + /* + * In NFSv4, we don't want to truncate the file + * now. This would be wrong if the OPEN fails for + * some other reason. Furthermore, if the size is + * nonzero, we should ignore it according to spec! + */ + open->op_truncate = (d_is_reg(child) && + (iap->ia_valid & ATTR_SIZE) && + !iap->ia_size); goto out; } - status = nfsd4_vfs_create(fhp, &child, open); - if (status != nfs_ok) + if (!open->op_created) { + status = nfserr_exist; goto out; - open->op_created = true; + } fh_fill_post_attrs(fhp); - status = fh_compose(resfhp, fhp->fh_export, child, fhp); - if (status != nfs_ok) - goto out; - -set_attr: if (is_create_with_attrs(open)) { status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs); -- 2.50.0.107.gf914562f5916.dirty