Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 52DF629B200 for ; Thu, 2 Jul 2026 01:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782956436; cv=none; b=dQqHZqPvCQmgjf+G4ojl5MhKpMkORL1h9oun2Qn+yytGHO0kOyyFcX5sTyOVRu1SjQwUr7tSHGvNbBsyogbLj01J4jGU3wQf825/dgMEbrRWsMMo27lFcHT6WpgcE/OYSH57vKtexYRY5xoh/lnCJ2F7A2tgfbH2TmrEu6Fa+8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782956436; c=relaxed/simple; bh=D0QOkmYGB4UzI6nkBOds8dJabdx9AmwarUBorTQg5qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qzDHrXo5PnxVPVIk4AoMQewCR23WwcFUzO4wT5ZcE8dP2WxXzMUV4GFaXxWv0Ch24hKyPTVS9j4jTzwcTgKTYc3GPBMV4cUfA8W6205AqsPOr2n03LZKj5l631KW2F3gU6dXgSxW32r+/QfZelC5KNwqV66LgDzSn2jYrKBNmls= 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=m1PmA62x; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bARPj8ac; arc=none smtp.client-ip=103.168.172.155 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="m1PmA62x"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bARPj8ac" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9C773140011B; Wed, 1 Jul 2026 21:40:34 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 01 Jul 2026 21:40:34 -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=1782956434; x=1783042834; bh=8gvq+byj3+5wZS8tUsB8LG5Yy81W1ore8VeYOGwk6EI=; b= m1PmA62xLamt9NYnZhtm7Kte6UMIExm/4IGKoQxg+i+k8dSF+hPb7HRt7Qpj/xlh CMkCwxYf4HTOTarezF4l1I4s+otMpAmJTxJM2bUM2Lv3iZHxEr8nvwiYhBKgupdo 0q7rOqJy+6DqQRVO+H2c2nC3w0o6Ts+kqg/1uZPrDJ+g6uT+/U/02T3VO6fi707D 09vgYNTTK5S9db+R+CKgN/okG5OMaAMXXH7I7p6GWUZXEe2OyIA89O7Teg0oYhl7 XW1qVoDW7HhnIzUYKXmd2w90IwSIjnO7pN0y1BFR8BsuCC8tVhbB6H4UtxGqWXbt dbsKILwqBBPp3DSc4rXDRw== 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=1782956434; x=1783042834; bh=8 gvq+byj3+5wZS8tUsB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LqEambRxZ3Q X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Jul 2026 21:40:32 -0400 (EDT) From: NeilBrown To: Chuck Lever , Jeff Layton Cc: Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH 05/10] nfsd: in nfsd4_create_file() let VFS report if file was created. Date: Thu, 2 Jul 2026 11:34:24 +1000 Message-ID: <20260702014000.3397240-6-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260702014000.3397240-1-neilb@ownmail.net> References: <20260702014000.3397240-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-nfs@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" operation actually 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. Also move the clearing of ATTR_SIZE for a newly created file down to a point where we know we have actually created the file. 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. The above requires changing dentry_create() to reliably set FMODE_CREATED when the file was actually created. Previously it only sets this flag when atomic_open is used. Signed-off-by: NeilBrown --- fs/namei.c | 2 ++ fs/nfsd/nfs4proc.c | 63 ++++++++++++++++++---------------------------- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 5cc9f0f466b8..e0a62198fc60 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -5073,6 +5073,8 @@ struct file *dentry_create(struct path *path, int flags, umode_t mode, error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL); if (!error) error = vfs_open(path, file); + if (!error) + file->f_mode |= FMODE_CREATED; } if (unlikely(error)) return ERR_PTR(error); diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 5b7f0314776f..cbb549ca6567 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -333,22 +333,30 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE); if (status != nfs_ok) 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); + 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; + + 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) { + if (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 @@ -356,41 +364,20 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, * 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: + open->op_truncate = (d_is_reg(child) && + (iap->ia_valid & ATTR_SIZE) && + !iap->ia_size); + } else 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; - } goto out; } - - status = nfsd4_vfs_create(fhp, &child, open); - if (status != nfs_ok) - goto out; - open->op_created = true; + /* file was created */ fh_fill_post_attrs(fhp); - status = fh_compose(resfhp, fhp->fh_export, child, fhp); - if (status != nfs_ok) - goto out; - /* A newly created file already has a file size of zero. */ if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0)) iap->ia_valid &= ~ATTR_SIZE; -set_attr: if (is_create_with_attrs(open)) { status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs); -- 2.50.0.107.gf914562f5916.dirty