From patchwork Mon Oct 14 19:26:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13835409 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 0238A1CC171; Mon, 14 Oct 2024 19:27:10 +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=1728934031; cv=none; b=nKlmW290Dmkb7Wpt8TT/qvSIaE2aLrIK/GETAUeuKjYa6vgIFSpSotnDvzobXBGZiNZSul83iMmXVVRm/NbadmpXB1V6a17+gwdTE6p2166CXn9SK6AsUD6EyKRMeRGhR6kar1nUAY1qyHIOvG0C6Q9V1r+2wehmKoZmxsMzMBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728934031; c=relaxed/simple; bh=1cZQdIadKpzmPqf4keXqTpqP8NkguLKE4M/N9rCqvlg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jAAYtRh0fsTzzHgG/peW+n5pxWHimYU1P0XTtfBji1RPRrHOoJTpeQRKuZ+hiU6wU9+YzsDnSYl5mcdMVjuewkL4e0qL6mMmeou57cwqO6MpouPlzfULUbJDhjmZ2lEhWMcHk3DM+CdZZrUi1ekaQqLyhnyncVUC1saj6qHSXj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XhXZSvgg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XhXZSvgg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7667C4CECE; Mon, 14 Oct 2024 19:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728934030; bh=1cZQdIadKpzmPqf4keXqTpqP8NkguLKE4M/N9rCqvlg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XhXZSvggrwkGg3A4+D3o3WOg3znJcWYwHZqbM0/7C3dEkNm/QTvjCOIr0CFjN7vZt ZEn4J14ikLSnkkJ8HfNCMsihYr5mJGwLzSeDrzJwWRfVZB+MLVYOCUC13DBEGnOwGa XjYkbiKSND7468lbS9e2j7jHgnXyZke67KXX6ycNWx29JLPWYCskb7j1gyDPzlQDnV 5WN4X++OBk2iVsLYtPUYIufIFhP48fqAzTAfz6QfWL9YsQDPo2XzG4A+JDAc8zW9Sl OQNq5L1pc7bs2mEnnZAf2THm2tmKaTcBQa3+IcLmBmZWGdTwc1QT27fcuD9oFKECu+ ULlGUxTt4Kyfw== From: Jeff Layton Date: Mon, 14 Oct 2024 15:26:49 -0400 Subject: [PATCH 1/6] nfsd: drop inode parameter from nfsd4_change_attribute() Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-delstid-v1-1-7ce8a2f4dd24@kernel.org> References: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> In-Reply-To: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Jonathan Corbet , Trond Myklebust , Anna Schumaker , Thomas Haynes Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4622; i=jlayton@kernel.org; h=from:subject:message-id; bh=1cZQdIadKpzmPqf4keXqTpqP8NkguLKE4M/N9rCqvlg=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnDXCLT0dAzlFteihjm2O9Qb1MRQu0EYhp03Qak GVxiTscCZqJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZw1wiwAKCRAADmhBGVaC FVu4D/4sziuaQH4/Y/LoEsDPwa3YHhry+1uCPqDnfsQBAaho3IeY9+luxj6a/XqD3ST7cuGpOqC HC7bs4ZLn2FwxOYDAaBs8kFgyHW/G6Axj1k5/HZF4XJjY7yOweZrNXZwMcTfdIKR+0F3OZi9waf P1ZhQO4ElWHky1/4HtaLDqPTU1DFDRXYpD3aUKyyFqlKsX76Tg+0Pa/eec+qwz4ktNv/kaVdCVX pcTPZP65XO24mTCTT8jRPMMnQqX56lVmRPm+4aEckepJl17nEAM17cwQqX7aGxuk/P8TMRR/VFj B0Y6yI2ZzVhBNGQS7+2CPYwHhwVcpP4rpRG7s5CZFQY/CXc2YY/IiIjtxqJLuJSK+gpEpU4jOJF webnnRTvxF7ZrCpJttFWUyFWra3kS38JaSfsDW70uVHzUe6d9Q7Rlh19g5E0M/tctc0dfb4SNGt RYxJFJqowmW6BT3WFLOnB+mlW7m/6SXJ8JxgBT3/js8v6+qQw+yhMUUddTx1gEhDNjf/rZXR7mY y3TgXrq3/CtRawgjy2ug93rTTTGYFd9PvP7bbZo9XyOjZ+yCaIfJhjsKPtzSQabTlE/RgjJ+vfC Hwjy/du/C2KJ5vLnrqwOhaJcWjClzEyrxiMbuxTW0cNVhWPVimXWgFFzEfDtEH7hRtOJXOOowo5 wFFZwzVNp989SrQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Fix up nfs4_delegation_stat() to fetch STATX_MODE, and then drop the inode parameter from nfsd4_change_attribute(), since it's no longer needed. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 5 ++--- fs/nfsd/nfs4xdr.c | 2 +- fs/nfsd/nfsfh.c | 11 ++++------- fs/nfsd/nfsfh.h | 3 +-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index d753926db09eedf629fc3e0938f10b1a6fdb0245..2961a277a79c1f4cdb8c29a7c19abcb3305b61a1 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5953,7 +5953,7 @@ nfs4_delegation_stat(struct nfs4_delegation *dp, struct svc_fh *currentfh, path.dentry = file_dentry(nf->nf_file); rc = vfs_getattr(&path, stat, - (STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE), + (STATX_MODE | STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE), AT_STATX_SYNC_AS_STAT); nfsd_file_put(nf); @@ -6037,8 +6037,7 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, } open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; dp->dl_cb_fattr.ncf_cur_fsize = stat.size; - dp->dl_cb_fattr.ncf_initial_cinfo = - nfsd4_change_attribute(&stat, d_inode(currentfh->fh_dentry)); + dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat); trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); } else { open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 6286ad2afa069f5274ffa352209b7d3c8c577dac..da7ec663da7326ad5c68a9c738b12d09cfcdc65a 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3621,7 +3621,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, args.change_attr = ncf->ncf_initial_cinfo; nfs4_put_stid(&dp->dl_stid); } else { - args.change_attr = nfsd4_change_attribute(&args.stat, d_inode(dentry)); + args.change_attr = nfsd4_change_attribute(&args.stat); } if (err) diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c index 4c5deea0e9535f2b197aa6ca1786d61730d53c44..453b7b52317d538971ce41f7e0492e5ab28b236d 100644 --- a/fs/nfsd/nfsfh.c +++ b/fs/nfsd/nfsfh.c @@ -670,20 +670,18 @@ fh_update(struct svc_fh *fhp) __be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp) { bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE); - struct inode *inode; struct kstat stat; __be32 err; if (fhp->fh_no_wcc || fhp->fh_pre_saved) return nfs_ok; - inode = d_inode(fhp->fh_dentry); err = fh_getattr(fhp, &stat); if (err) return err; if (v4) - fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode); + fhp->fh_pre_change = nfsd4_change_attribute(&stat); fhp->fh_pre_mtime = stat.mtime; fhp->fh_pre_ctime = stat.ctime; @@ -700,7 +698,6 @@ __be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp) __be32 fh_fill_post_attrs(struct svc_fh *fhp) { bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE); - struct inode *inode = d_inode(fhp->fh_dentry); __be32 err; if (fhp->fh_no_wcc) @@ -716,7 +713,7 @@ __be32 fh_fill_post_attrs(struct svc_fh *fhp) fhp->fh_post_saved = true; if (v4) fhp->fh_post_change = - nfsd4_change_attribute(&fhp->fh_post_attr, inode); + nfsd4_change_attribute(&fhp->fh_post_attr); return nfs_ok; } @@ -824,13 +821,13 @@ enum fsid_source fsid_source(const struct svc_fh *fhp) * assume that the new change attr is always logged to stable storage in some * fashion before the results can be seen. */ -u64 nfsd4_change_attribute(const struct kstat *stat, const struct inode *inode) +u64 nfsd4_change_attribute(const struct kstat *stat) { u64 chattr; if (stat->result_mask & STATX_CHANGE_COOKIE) { chattr = stat->change_cookie; - if (S_ISREG(inode->i_mode) && + if (S_ISREG(stat->mode) && !(stat->attributes & STATX_ATTR_CHANGE_MONOTONIC)) { chattr += (u64)stat->ctime.tv_sec << 30; chattr += stat->ctime.tv_nsec; diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h index 5b7394801dc4270dbd5236f3e2f2237130c73dad..876152a91f122f83fb94ffdfb0eedf8fca56a20c 100644 --- a/fs/nfsd/nfsfh.h +++ b/fs/nfsd/nfsfh.h @@ -297,8 +297,7 @@ static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp) fhp->fh_pre_saved = false; } -u64 nfsd4_change_attribute(const struct kstat *stat, - const struct inode *inode); +u64 nfsd4_change_attribute(const struct kstat *stat); __be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp); __be32 fh_fill_post_attrs(struct svc_fh *fhp); __be32 __must_check fh_fill_both_attrs(struct svc_fh *fhp); From patchwork Mon Oct 14 19:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13835410 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 97E021CDFC4; Mon, 14 Oct 2024 19:27:12 +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=1728934032; cv=none; b=jaBGHQx+rRDPjRyBqd2+jZ3sTqxt8ldtmnCyBj6GUXsHSXsd6YwwToPoo5kmJN4DL4la/9Iq61RwxBy5mxljleCgYD+I7beYYxCjEkEqHlOb+mG89pONqMg1AKkHJ8vRdleQsqbUqppd4sdL6FfOrs1lzzYpiXcgzQrDlzgshYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728934032; c=relaxed/simple; bh=TnqJVmuOoQ9p0S5PfTfg0but+wL4NEE0kSJ8v9YBF9k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k/P/x7aUXGMY2XdxvvT3bzInQwUGKuoqRR7y62IY1TJEP+fcjs/kVpSmxItlmA9c+u7zZtpIjBracfEgvCSYUzas6Qkh3dGehAaBN8IUsGegYboi6DBTvKBLao5FmWfd7ICT4QvLJcMqbEpHSwQKVQ50XuC74W17I84RfowTBr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jXt7Qu/B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jXt7Qu/B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13649C4CED0; Mon, 14 Oct 2024 19:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728934032; bh=TnqJVmuOoQ9p0S5PfTfg0but+wL4NEE0kSJ8v9YBF9k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jXt7Qu/B9HTOE7PIk6NDp/QZLYvfvWso8/mekJKHYGEFRVR9WOEDCnwVc3gcNH0i7 EhFcS6t11J3W5i+xZM3QCyA30uzdXRjIM2N7qkKfXd4/5tH8n8rwAnZgCHcl6JnvS2 RlYxEMN6ybVrZMcWbHpgFAFx7fjXNtcQDNdfl+XBU9bjFDClIRKOOIsf51jEFxbhAi qGfKc2cG9kNMqijB9WRMebCOPnk+jQfPae6chi6/B26NwDH0cEVETk/vKEeiaxsoxE csKHRiz/eRabW8MlJtXLRSMFP5n6WecvCGKBnV00iQVWykJgFJahSqsgl0iCidIYFg L1Ir2t4kFlAeA== From: Jeff Layton Date: Mon, 14 Oct 2024 15:26:50 -0400 Subject: [PATCH 2/6] nfsd: switch to autogenerated definitions for open_delegation_type4 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-delstid-v1-2-7ce8a2f4dd24@kernel.org> References: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> In-Reply-To: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Jonathan Corbet , Trond Myklebust , Anna Schumaker , Thomas Haynes Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=12140; i=jlayton@kernel.org; h=from:subject:message-id; bh=TnqJVmuOoQ9p0S5PfTfg0but+wL4NEE0kSJ8v9YBF9k=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnDXCLv/ZszrwV4+TusJlMNWyhZ+8K278Ycjq3W Hk86phGzFOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZw1wiwAKCRAADmhBGVaC Ff93D/4uTlw1mIf92shazTkXVDcuaWOfV7+VJM+ON9u3HVw5ph5CCvlDW8/kkOk2mtk0B9WI0re y0qE2YMGRVt7lxo1bvO9DI7vXufh+xLmf3x0N8r0GC9IEHnnjh8jmnCjhUO/kc5y5OrnuiBwrgt gh2PvSWVr1bLykgw9zD6bk/hHqBG0dVcadDFXiHOOk1uA6I9Yuab35b4foVnB32y1lKKxo2ReAl 1skgjiy4XXpCmQJ6ZqwIwqHOHlFT6N4gI0dscHSCPHdkP3+b3ahgoj8X8iq5TL249iou4eh7vLV /JKAmS124AWAB+JsirSsXebKh5+yQILhUTQ4YMEKHpprpwDDlyYV/1UG5ZbMb9YBhXGL6IZkIvq vZouUrF+Z36vSCltSPWfjcv78EO2ofLhgioznqhc/LxwjfZSrgMqwHmT/PDerVU9VwbdkvHF3kK /LX6P9EzcZVoiMdmRlbHgmNIHBRQOCv/eQYk/7idFmC+PJxCq9t35OPflIqkSqEKN5oT+Nnbd0a gQTVlrflRmTB0BLnSAvEFdy9j8f8YcA6FsGc0eFR0vYWXmxhiZ+VY4CkEHkLx5vZlqFBTMEQC41 rDkgEt03b1WFdcPa3AJ2zo+wyoLPRl4vIpHhPIJ49p0IcITs/cvn4PGokObj9tUwNE8ITgGOU3I w6zBehXdeCRWA7Q== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Rename the enum with the same name in include/linux/nfs4.h, add the proper enum to nfs4_1.x and regenerate the headers and source files. Do a mass rename of all NFS4_OPEN_DELEGATE_* to OPEN_DELEGATE_* in the nfsd directory. Signed-off-by: Jeff Layton --- Documentation/sunrpc/xdr/nfs4_1.x | 9 ++++++++- fs/nfsd/nfs4state.c | 38 ++++++++++++++++++------------------ fs/nfsd/nfs4xdr.c | 8 ++++---- fs/nfsd/nfs4xdr_gen.c | 19 +++++++++++++++++- fs/nfsd/nfs4xdr_gen.h | 2 +- include/linux/nfs4.h | 2 +- include/linux/sunrpc/xdrgen/nfs4_1.h | 13 +++++++++++- 7 files changed, 63 insertions(+), 28 deletions(-) diff --git a/Documentation/sunrpc/xdr/nfs4_1.x b/Documentation/sunrpc/xdr/nfs4_1.x index fc37d1ecba0f40e46c6986df90d07a0e6e6ae9b2..ee9f8f249f1e71dbfc383007a6950ebc4104ed67 100644 --- a/Documentation/sunrpc/xdr/nfs4_1.x +++ b/Documentation/sunrpc/xdr/nfs4_1.x @@ -161,6 +161,13 @@ pragma public fattr4_time_deleg_modify; const FATTR4_TIME_DELEG_ACCESS = 84; const FATTR4_TIME_DELEG_MODIFY = 85; - const OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000; +enum open_delegation_type4 { + OPEN_DELEGATE_NONE = 0, + OPEN_DELEGATE_READ = 1, + OPEN_DELEGATE_WRITE = 2, + OPEN_DELEGATE_NONE_EXT = 3, /* new to v4.1 */ + OPEN_DELEGATE_READ_ATTRS_DELEG = 4, + OPEN_DELEGATE_WRITE_ATTRS_DELEG = 5 +}; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 2961a277a79c1f4cdb8c29a7c19abcb3305b61a1..c8b4c2b9135128f98800bc525563503bff2d2ed2 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2852,7 +2852,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st) seq_puts(s, ": { type: deleg, "); seq_printf(s, "access: %s", - ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w"); + ds->dl_type == OPEN_DELEGATE_READ ? "r" : "w"); /* XXX: lease time, whether it's being recalled. */ @@ -5433,7 +5433,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, static inline __be32 nfs4_check_delegmode(struct nfs4_delegation *dp, int flags) { - if ((flags & WR_STATE) && (dp->dl_type == NFS4_OPEN_DELEGATE_READ)) + if ((flags & WR_STATE) && (dp->dl_type == OPEN_DELEGATE_READ)) return nfserr_openmode; else return nfs_ok; @@ -5675,7 +5675,7 @@ static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp, return NULL; fl->fl_lmops = &nfsd_lease_mng_ops; fl->c.flc_flags = FL_DELEG; - fl->c.flc_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; + fl->c.flc_type = flag == OPEN_DELEGATE_READ ? F_RDLCK : F_WRLCK; fl->c.flc_owner = (fl_owner_t)dp; fl->c.flc_pid = current->tgid; fl->c.flc_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; @@ -5821,7 +5821,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, */ if ((open->op_share_access & NFS4_SHARE_ACCESS_BOTH) == NFS4_SHARE_ACCESS_BOTH) { nf = find_rw_file(fp); - dl_type = NFS4_OPEN_DELEGATE_WRITE; + dl_type = OPEN_DELEGATE_WRITE; } /* @@ -5830,7 +5830,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, */ if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) { nf = find_readable_file(fp); - dl_type = NFS4_OPEN_DELEGATE_READ; + dl_type = OPEN_DELEGATE_READ; } if (!nf) @@ -5919,7 +5919,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status) { - open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; + open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; if (status == -EAGAIN) open->op_why_no_deleg = WND4_CONTENTION; else { @@ -6035,20 +6035,20 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, destroy_delegation(dp); goto out_no_deleg; } - open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; + open->op_delegate_type = OPEN_DELEGATE_WRITE; dp->dl_cb_fattr.ncf_cur_fsize = stat.size; dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat); trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); } else { - open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; + open->op_delegate_type = OPEN_DELEGATE_READ; trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); } nfs4_put_stid(&dp->dl_stid); return; out_no_deleg: - open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE; + open->op_delegate_type = OPEN_DELEGATE_NONE; if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && - open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) { + open->op_delegate_type != OPEN_DELEGATE_NONE) { dprintk("NFSD: WARNING: refusing delegation reclaim\n"); open->op_recall = true; } @@ -6063,17 +6063,17 @@ static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open, struct nfs4_delegation *dp) { if (open->op_deleg_want == NFS4_SHARE_WANT_READ_DELEG && - dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { - open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; + dp->dl_type == OPEN_DELEGATE_WRITE) { + open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; } else if (open->op_deleg_want == NFS4_SHARE_WANT_WRITE_DELEG && - dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { - open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; + dp->dl_type == OPEN_DELEGATE_WRITE) { + open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; } /* Otherwise the client must be confused wanting a delegation * it already has, therefore we don't return - * NFS4_OPEN_DELEGATE_NONE_EXT and reason. + * OPEN_DELEGATE_NONE_EXT and reason. */ } @@ -6082,8 +6082,8 @@ static bool open_xor_delegation(struct nfsd4_open *open) { if (!(open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) return false; - if (open->op_delegate_type != NFS4_OPEN_DELEGATE_READ && - open->op_delegate_type != NFS4_OPEN_DELEGATE_WRITE) + if (open->op_delegate_type != OPEN_DELEGATE_READ && + open->op_delegate_type != OPEN_DELEGATE_WRITE) return false; return true; } @@ -6169,7 +6169,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf if (nfsd4_has_session(&resp->cstate)) { if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { - open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; + open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; open->op_why_no_deleg = WND4_NOT_WANTED; goto nodeleg; } @@ -6196,7 +6196,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf trace_nfsd_open(&stp->st_stid.sc_stateid); out: /* 4.1 client trying to upgrade/downgrade delegation? */ - if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp && + if (open->op_delegate_type == OPEN_DELEGATE_NONE && dp && open->op_deleg_want) nfsd4_deleg_xgrade_none_ext(open, dp); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index da7ec663da7326ad5c68a9c738b12d09cfcdc65a..682fc6a32c8562bbd8531458da9b7ff1de69bcd1 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4292,18 +4292,18 @@ nfsd4_encode_open_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open) if (xdr_stream_encode_u32(xdr, open->op_delegate_type) != XDR_UNIT) return nfserr_resource; switch (open->op_delegate_type) { - case NFS4_OPEN_DELEGATE_NONE: + case OPEN_DELEGATE_NONE: status = nfs_ok; break; - case NFS4_OPEN_DELEGATE_READ: + case OPEN_DELEGATE_READ: /* read */ status = nfsd4_encode_open_read_delegation4(xdr, open); break; - case NFS4_OPEN_DELEGATE_WRITE: + case OPEN_DELEGATE_WRITE: /* write */ status = nfsd4_encode_open_write_delegation4(xdr, open); break; - case NFS4_OPEN_DELEGATE_NONE_EXT: + case OPEN_DELEGATE_NONE_EXT: /* od_whynone */ status = nfsd4_encode_open_none_delegation4(xdr, open); break; diff --git a/fs/nfsd/nfs4xdr_gen.c b/fs/nfsd/nfs4xdr_gen.c index e5d34f9a3147d9d51fb3b9db4c29b048b1083cbf..a0e01f50a28d7f6828f3e6ef02f90b84bf180841 100644 --- a/fs/nfsd/nfs4xdr_gen.c +++ b/fs/nfsd/nfs4xdr_gen.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Generated by xdrgen. Manual edits will be lost. // XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x -// XDR specification modification time: Thu Oct 3 11:30:59 2024 +// XDR specification modification time: Sat Oct 12 08:10:54 2024 #include @@ -135,6 +135,17 @@ xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg return xdrgen_decode_nfstime4(xdr, ptr); }; +static bool __maybe_unused +xdrgen_decode_open_delegation_type4(struct xdr_stream *xdr, open_delegation_type4 *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + *ptr = val; + return true; +} + static bool __maybe_unused xdrgen_encode_int64_t(struct xdr_stream *xdr, const int64_t value) { @@ -237,3 +248,9 @@ xdrgen_encode_fattr4_time_deleg_modify(struct xdr_stream *xdr, const fattr4_time { return xdrgen_encode_nfstime4(xdr, value); }; + +static bool __maybe_unused +xdrgen_encode_open_delegation_type4(struct xdr_stream *xdr, open_delegation_type4 value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} diff --git a/fs/nfsd/nfs4xdr_gen.h b/fs/nfsd/nfs4xdr_gen.h index c4c6a5075b17be3f931e2a20e282e33dc6e10ef1..3fc8bde2b3b5db6f80f17b41e7f5991487cfa959 100644 --- a/fs/nfsd/nfs4xdr_gen.h +++ b/fs/nfsd/nfs4xdr_gen.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ -/* XDR specification modification time: Thu Oct 3 11:30:59 2024 */ +/* XDR specification modification time: Sat Oct 12 08:10:54 2024 */ #ifndef _LINUX_XDRGEN_NFS4_1_DECL_H #define _LINUX_XDRGEN_NFS4_1_DECL_H diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index b907192447755a614289554a01928c1ebb61c3dc..71fbebfa43c7e2bd27708814c7300c506ce64c1b 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -366,7 +366,7 @@ enum limit_by4 { NFS4_LIMIT_BLOCKS = 2 }; -enum open_delegation_type4 { +enum nfs4_open_delegation_type4 { NFS4_OPEN_DELEGATE_NONE = 0, NFS4_OPEN_DELEGATE_READ = 1, NFS4_OPEN_DELEGATE_WRITE = 2, diff --git a/include/linux/sunrpc/xdrgen/nfs4_1.h b/include/linux/sunrpc/xdrgen/nfs4_1.h index 6025ab6b739833aad33567102e216c162003f408..9ca83a4a04cff8ebb5aafa08a24a2db771d6c1ef 100644 --- a/include/linux/sunrpc/xdrgen/nfs4_1.h +++ b/include/linux/sunrpc/xdrgen/nfs4_1.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ -/* XDR specification modification time: Thu Oct 3 11:30:59 2024 */ +/* XDR specification modification time: Sat Oct 12 08:10:54 2024 */ #ifndef _LINUX_XDRGEN_NFS4_1_DEF_H #define _LINUX_XDRGEN_NFS4_1_DEF_H @@ -98,6 +98,16 @@ enum { FATTR4_TIME_DELEG_MODIFY = 85 }; enum { OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000 }; +enum open_delegation_type4 { + OPEN_DELEGATE_NONE = 0, + OPEN_DELEGATE_READ = 1, + OPEN_DELEGATE_WRITE = 2, + OPEN_DELEGATE_NONE_EXT = 3, + OPEN_DELEGATE_READ_ATTRS_DELEG = 4, + OPEN_DELEGATE_WRITE_ATTRS_DELEG = 5, +}; +typedef enum open_delegation_type4 open_delegation_type4; + #define NFS4_int64_t_sz \ (XDR_hyper) #define NFS4_uint32_t_sz \ @@ -120,5 +130,6 @@ enum { OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000 }; (NFS4_nfstime4_sz) #define NFS4_fattr4_time_deleg_modify_sz \ (NFS4_nfstime4_sz) +#define NFS4_open_delegation_type4_sz (XDR_int) #endif /* _LINUX_XDRGEN_NFS4_1_DEF_H */ From patchwork Mon Oct 14 19:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13835411 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 E34621CF2AF; Mon, 14 Oct 2024 19:27:13 +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=1728934034; cv=none; b=IuAB2iJfgzE7TN3aOm4npRmNWQHPibN6iUhHRPvcHYQVN8K0mo9tdTaaGCFeQAbVbe7fcy6H3gvtmHhj86r2VQHTG5uVltP0xwUs24PUrj1ho/3cWQkvTP+kz76mg32URwNUe9QRQgwHkKPkzKeigARb3vd3i9BYNQo9JQfIunY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728934034; c=relaxed/simple; bh=KgABKazkhUlOOAfF3IvLNRQrTCuZpIbnKXg2NqI/6sg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gh1QrQaPb7NBDFa2RNRhF0LJrI7xI7SWroLAYvBlhzKQcSS4vYNmXq0Pd/0YyyLNkMvRtFbgQUoDwgAhrNHfwiT7khcvss8c+XvDktVVhIFI9buTW7RAyc15RjOZwUEZFB5npdN+0vO96wddi/LxxUMIfl9DtTJUlXizCedHbwA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QmcKigP7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QmcKigP7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 643F6C4CECE; Mon, 14 Oct 2024 19:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728934033; bh=KgABKazkhUlOOAfF3IvLNRQrTCuZpIbnKXg2NqI/6sg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QmcKigP7ZiiG950Za3QmuUcJI73JAQws4WkcMWKHoatlAaKXIFVtE/aP1salKKH1w l5iyTtt85lHoXyiRA3O5eXxrwVmh0hNqiRw0AVETOmsjTu6Y3elHBiCrrK6751bIh2 QeQYJM4Pr1PVM25sGTGULeCq3mdYlEfF+C9bZBthOgOEg9odicczq6T79EOPfJGuGb 7fpHb7KOqurhYbENi2zg5oJVfzIQ5Tz3iGHxlLdltnJITrVReipzm6ZvYasTfos5vZ sPGkzMpzgCwAtSI4Ws78EirGVogIxQWsYbVaw0Aqn7hrZp4V06lwJ/8VDFNKy2uZq7 6sFxMU61C4f2w== From: Jeff Layton Date: Mon, 14 Oct 2024 15:26:51 -0400 Subject: [PATCH 3/6] nfsd: rename NFS4_SHARE_WANT_* constants to OPEN4_SHARE_ACCESS_WANT_* Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-delstid-v1-3-7ce8a2f4dd24@kernel.org> References: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> In-Reply-To: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Jonathan Corbet , Trond Myklebust , Anna Schumaker , Thomas Haynes Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8260; i=jlayton@kernel.org; h=from:subject:message-id; bh=KgABKazkhUlOOAfF3IvLNRQrTCuZpIbnKXg2NqI/6sg=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnDXCLqmUXuhGy49NhzA5eTTPg4KigIFKHfFAd7 1ZY8XAWMzSJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZw1wiwAKCRAADmhBGVaC FX1kD/9FszNJEgNxXf4N7/l9F1gdEDprn3cAWfJ2Wv0ALY2ip4pIhAQXlcBMGuGB9AV4cLbsm0a osAawVXQmoxpmExw7tLS5qLitrMmH8yZPWL2UG7Y4m1wgYx+apQWj7r9TxhCw6pXnxIaJK8yRs0 wpBl7vlbBhQtz9ZIAEee80kCK0Dx1iKUtTjefG3PVqqqXQTna9kNxyFlUxxj/+6TsRxi/s/ppJb VFR+poHcWOZsTOC38wEQ80L8fOxV0K9WsC4F6/z+egU0r2YqNc+aUz0SxtXfhElJehFGNfMR1SL /f4tqxwFVmsI1NSFOQNS4AyhnhxsnxOeTRDdFw7YzSGpJ8rq0TiqpactzgtznZH6pn/jqaAB2Y8 nYtudcOyJ5Klbo1tYLciqrsU3wiXENFRVztV/GVT8mnGv2DybirVJ5gUnGCCGhKRUrTNux12+JO K2jJJwT0avTCS8Rz/fi2amcZUUlHjBPAxkhjLopZ/PJGZWGUVLK2kKPjqFjrzS2XLIKQqtpeBnG ejhn5IK7YDV8YZRqIwMVL4DToQERK72FMD714hJXSisA3T9iUCoOjbi8te7CpbzD1++z7DK7VLZ 7n7Gtn+wzCnxHPW9Amb59uvVbOjaIwBm5MqZ6th5aRj3W1n8GMHBse2afwTISNgdasR5PjDMzDG /ZtlJqVPcrIm7fQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add the OPEN4_SHARE_ACCESS_WANT constants from the nfs4.1 and delstid draft into the nfs4_1.x file, and regenerate the headers and source files. Do a mass renaming of NFS4_SHARE_WANT_* to OPEN4_SHARE_ACCESS_WANT_* in the nfsd directory. Signed-off-by: Jeff Layton --- Documentation/sunrpc/xdr/nfs4_1.x | 15 ++++++++++++++- fs/nfsd/nfs4state.c | 16 ++++++++-------- fs/nfsd/nfs4xdr.c | 12 ++++++------ fs/nfsd/nfs4xdr_gen.c | 2 +- fs/nfsd/nfs4xdr_gen.h | 2 +- include/linux/sunrpc/xdrgen/nfs4_1.h | 24 +++++++++++++++++++++--- 6 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Documentation/sunrpc/xdr/nfs4_1.x b/Documentation/sunrpc/xdr/nfs4_1.x index ee9f8f249f1e71dbfc383007a6950ebc4104ed67..ca95150a3a29fc5418991bf2395326bd73645ea8 100644 --- a/Documentation/sunrpc/xdr/nfs4_1.x +++ b/Documentation/sunrpc/xdr/nfs4_1.x @@ -138,7 +138,6 @@ pragma public fattr4_open_arguments; const FATTR4_OPEN_ARGUMENTS = 86; -const OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000; const OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010; @@ -161,7 +160,21 @@ pragma public fattr4_time_deleg_modify; const FATTR4_TIME_DELEG_ACCESS = 84; const FATTR4_TIME_DELEG_MODIFY = 85; + + +/* new flags for share_access field of OPEN4args */ +const OPEN4_SHARE_ACCESS_WANT_DELEG_MASK = 0xFF00; +const OPEN4_SHARE_ACCESS_WANT_NO_PREFERENCE = 0x0000; +const OPEN4_SHARE_ACCESS_WANT_READ_DELEG = 0x0100; +const OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG = 0x0200; +const OPEN4_SHARE_ACCESS_WANT_ANY_DELEG = 0x0300; +const OPEN4_SHARE_ACCESS_WANT_NO_DELEG = 0x0400; +const OPEN4_SHARE_ACCESS_WANT_CANCEL = 0x0500; + +const OPEN4_SHARE_ACCESS_WANT_SIGNAL_DELEG_WHEN_RESRC_AVAIL = 0x10000; +const OPEN4_SHARE_ACCESS_WANT_PUSH_DELEG_WHEN_UNCONTENDED = 0x20000; const OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000; +const OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000; enum open_delegation_type4 { OPEN_DELEGATE_NONE = 0, diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index c8b4c2b9135128f98800bc525563503bff2d2ed2..fe74d8c0c61e76f635a3133a4c71b7fb7b622a48 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5925,14 +5925,14 @@ static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status) else { open->op_why_no_deleg = WND4_RESOURCE; switch (open->op_deleg_want) { - case NFS4_SHARE_WANT_READ_DELEG: - case NFS4_SHARE_WANT_WRITE_DELEG: - case NFS4_SHARE_WANT_ANY_DELEG: + case OPEN4_SHARE_ACCESS_WANT_READ_DELEG: + case OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG: + case OPEN4_SHARE_ACCESS_WANT_ANY_DELEG: break; - case NFS4_SHARE_WANT_CANCEL: + case OPEN4_SHARE_ACCESS_WANT_CANCEL: open->op_why_no_deleg = WND4_CANCELLED; break; - case NFS4_SHARE_WANT_NO_DELEG: + case OPEN4_SHARE_ACCESS_WANT_NO_DELEG: WARN_ON_ONCE(1); } } @@ -6062,11 +6062,11 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open, struct nfs4_delegation *dp) { - if (open->op_deleg_want == NFS4_SHARE_WANT_READ_DELEG && + if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_READ_DELEG && dp->dl_type == OPEN_DELEGATE_WRITE) { open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; - } else if (open->op_deleg_want == NFS4_SHARE_WANT_WRITE_DELEG && + } else if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG && dp->dl_type == OPEN_DELEGATE_WRITE) { open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; @@ -6168,7 +6168,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf mutex_unlock(&stp->st_mutex); if (nfsd4_has_session(&resp->cstate)) { - if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { + if (open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_NO_DELEG) { open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; open->op_why_no_deleg = WND4_NOT_WANTED; goto nodeleg; diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 682fc6a32c8562bbd8531458da9b7ff1de69bcd1..e95f6ba5cc65611b47d5d297584ff6e478d80a1f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -1068,12 +1068,12 @@ static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *sh if (!argp->minorversion) return nfserr_bad_xdr; switch (w & NFS4_SHARE_WANT_TYPE_MASK) { - case NFS4_SHARE_WANT_NO_PREFERENCE: - case NFS4_SHARE_WANT_READ_DELEG: - case NFS4_SHARE_WANT_WRITE_DELEG: - case NFS4_SHARE_WANT_ANY_DELEG: - case NFS4_SHARE_WANT_NO_DELEG: - case NFS4_SHARE_WANT_CANCEL: + case OPEN4_SHARE_ACCESS_WANT_NO_PREFERENCE: + case OPEN4_SHARE_ACCESS_WANT_READ_DELEG: + case OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG: + case OPEN4_SHARE_ACCESS_WANT_ANY_DELEG: + case OPEN4_SHARE_ACCESS_WANT_NO_DELEG: + case OPEN4_SHARE_ACCESS_WANT_CANCEL: break; default: return nfserr_bad_xdr; diff --git a/fs/nfsd/nfs4xdr_gen.c b/fs/nfsd/nfs4xdr_gen.c index a0e01f50a28d7f6828f3e6ef02f90b84bf180841..a17b5d8e60b3579caa2e2a8b40ed757070e1a622 100644 --- a/fs/nfsd/nfs4xdr_gen.c +++ b/fs/nfsd/nfs4xdr_gen.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Generated by xdrgen. Manual edits will be lost. // XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x -// XDR specification modification time: Sat Oct 12 08:10:54 2024 +// XDR specification modification time: Mon Oct 14 09:10:13 2024 #include diff --git a/fs/nfsd/nfs4xdr_gen.h b/fs/nfsd/nfs4xdr_gen.h index 3fc8bde2b3b5db6f80f17b41e7f5991487cfa959..41a0033b72562ee3c1fcdcd4a887ce635385b22b 100644 --- a/fs/nfsd/nfs4xdr_gen.h +++ b/fs/nfsd/nfs4xdr_gen.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ -/* XDR specification modification time: Sat Oct 12 08:10:54 2024 */ +/* XDR specification modification time: Mon Oct 14 09:10:13 2024 */ #ifndef _LINUX_XDRGEN_NFS4_1_DECL_H #define _LINUX_XDRGEN_NFS4_1_DECL_H diff --git a/include/linux/sunrpc/xdrgen/nfs4_1.h b/include/linux/sunrpc/xdrgen/nfs4_1.h index 9ca83a4a04cff8ebb5aafa08a24a2db771d6c1ef..cf21a14aa8850f4b21cd365cb7bc22a02c6097ce 100644 --- a/include/linux/sunrpc/xdrgen/nfs4_1.h +++ b/include/linux/sunrpc/xdrgen/nfs4_1.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ -/* XDR specification modification time: Sat Oct 12 08:10:54 2024 */ +/* XDR specification modification time: Mon Oct 14 09:10:13 2024 */ #ifndef _LINUX_XDRGEN_NFS4_1_DEF_H #define _LINUX_XDRGEN_NFS4_1_DEF_H @@ -84,8 +84,6 @@ typedef struct open_arguments4 fattr4_open_arguments; enum { FATTR4_OPEN_ARGUMENTS = 86 }; -enum { OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000 }; - enum { OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010 }; typedef struct nfstime4 fattr4_time_deleg_access; @@ -96,8 +94,28 @@ enum { FATTR4_TIME_DELEG_ACCESS = 84 }; enum { FATTR4_TIME_DELEG_MODIFY = 85 }; +enum { OPEN4_SHARE_ACCESS_WANT_DELEG_MASK = 0xFF00 }; + +enum { OPEN4_SHARE_ACCESS_WANT_NO_PREFERENCE = 0x0000 }; + +enum { OPEN4_SHARE_ACCESS_WANT_READ_DELEG = 0x0100 }; + +enum { OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG = 0x0200 }; + +enum { OPEN4_SHARE_ACCESS_WANT_ANY_DELEG = 0x0300 }; + +enum { OPEN4_SHARE_ACCESS_WANT_NO_DELEG = 0x0400 }; + +enum { OPEN4_SHARE_ACCESS_WANT_CANCEL = 0x0500 }; + +enum { OPEN4_SHARE_ACCESS_WANT_SIGNAL_DELEG_WHEN_RESRC_AVAIL = 0x10000 }; + +enum { OPEN4_SHARE_ACCESS_WANT_PUSH_DELEG_WHEN_UNCONTENDED = 0x20000 }; + enum { OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000 }; +enum { OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000 }; + enum open_delegation_type4 { OPEN_DELEGATE_NONE = 0, OPEN_DELEGATE_READ = 1, From patchwork Mon Oct 14 19:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13835412 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 3DF8B1CF7DB; Mon, 14 Oct 2024 19:27:14 +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=1728934035; cv=none; b=U94ezQSS2GGVVOOk07xCmN3yJFa+nomah/5n3ktIQU3+Nxl6FSCntcNLJKafITVnSBdwwvSUDItErROi9/cGTTZTZjwRlBn76piGo7f9zzNec4oZ+Nw/eZxw47V8nKmX3iOOexc4k3ik8s0k7wDLyVzRzanvuPw18obCGvC1uB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728934035; c=relaxed/simple; bh=+hRQc9GgFAzsiBo9bvZ+7lG7RTwR60/+HrCAnl4d2hc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pFd9nS4E+73n3i4gcxAgzRZNef7yYCh4Fo9ZG6B/fX+YXqpv+kGCL2QpVz04jHUQd/OV8WvkOpL8TWeO3Zar6vo0ru/Na7e6YetO16VQrFionOJ+RvCejE/8FNAWSzvvYTawCVyF1FFcQSCT1wMhLBzBoys6kPnjiuSBBs5jU3Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XyMGV420; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XyMGV420" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6FCBC4CED2; Mon, 14 Oct 2024 19:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728934034; bh=+hRQc9GgFAzsiBo9bvZ+7lG7RTwR60/+HrCAnl4d2hc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XyMGV420zluBQjLWNJyQCEaxM/Yn1hMs/aMoyGvXvog/17wWGpyof+lNfrMWfr7OW F4QcfMMovwQhIPT33doqBHersdYRArjqH11+ItS/03NYqrOi3HYvhUR+sCa1Z4jryk I8cODYd8xd0yXKED5B7BbQIg1h7d4RsDqgvUaxw1HCTSVLqnmGO4jbpillNEx+WdiS c8ns1pgZz2vZq/G7LeUS83cLcYvM4ER+HSE6Sn7V8TsQbU2a1a0DUfVBv9djQzoJN0 7J3ocRhx4LJa8G4RlYyN+4cqEXxmNKhQ/33LMGQku4pzMEEsffMuDQhWD21JtKLvGL gJzB8uN6LarhQ== From: Jeff Layton Date: Mon, 14 Oct 2024 15:26:52 -0400 Subject: [PATCH 4/6] nfsd: prepare delegation code for handing out *_ATTRS_DELEG delegations Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-delstid-v1-4-7ce8a2f4dd24@kernel.org> References: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> In-Reply-To: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Jonathan Corbet , Trond Myklebust , Anna Schumaker , Thomas Haynes Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6359; i=jlayton@kernel.org; h=from:subject:message-id; bh=+hRQc9GgFAzsiBo9bvZ+7lG7RTwR60/+HrCAnl4d2hc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnDXCLLTppiQWIqY3TUYF7e6oPfkXP6ghaWONuP scItlNaQbqJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZw1wiwAKCRAADmhBGVaC FTAeEACCHWeT98PnyWP/nLiHE1T471Qe1rHX2FEEWx1Q9w3krqSuXV+7fEAHE0LYR4G3OI70Sej dG6eNtKioTx+rxIvLqDim9/H1XpDFTHqcM6lC/myLFdw/9mgCGNbjGyTPwR/ui5TtInZ4pcrj1k ua/gEGqgjltrUOQptmaoQORtNAYg364kMbn/YIgUNWoGAxYNjQAdQajwLifYRqGeEwWNY6bnopO VN7O1+nHSj0hWXnj/mEx77bNt18i0n6AEUOWColf86KutqpVaFM8dOzNEWBnTSZos2Ey6aKQRDY O0w7FoDLPgjWQGQGpjY8k3WvkTxsxmhsH1neK8NBR8lNupetby6qTIe2Rmkl9CIAb89DFdyT9/K bv1WrYARqJcqRJc+N90mweijoJqguiI1uBXE37+ueBcyvOd8fJOi9jHx6UzV7+mWwsCzXyuP9dq KwsXcDPI9MyHOnO/AWtK5CPCtleoD+lTkd98NjgfRMI5bYMfrC2GDlu/pRjXd/51ZOdZvQWgAe5 GoFLxmH7d2ScAe4BWfGWeWxnDRv843R7WQHKLTwzCacWKOUr95kYH4T0BoAaYgbrS3P5iyKu+hG azFJ6uAwlEFy6IuI6nGogZHH8BbDesrxTXUCFdzVWhaAeBfDKas3U7AuBCIUMPfUaZQ/lRxpOHl zgY75K6QFjKjv3A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add some preparatory code to various functions that handle delegation types to allow them to handle the OPEN_DELEGATE_*_ATTRS_DELEG constants. Add helpers for detecting whether it's a read or write deleg, and whether the attributes are delegated. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 50 +++++++++++++++++++++++++++++++++----------------- fs/nfsd/nfs4xdr.c | 2 ++ fs/nfsd/state.h | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index fe74d8c0c61e76f635a3133a4c71b7fb7b622a48..62f9aeb159d0f2ab4d293bf5c0c56ad7b86eb9d6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2838,6 +2838,21 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st) return 0; } +static char *nfs4_show_deleg_type(u32 dl_type) +{ + switch (dl_type) { + case OPEN_DELEGATE_READ: + return "r"; + case OPEN_DELEGATE_WRITE: + return "w"; + case OPEN_DELEGATE_READ_ATTRS_DELEG: + return "ra"; + case OPEN_DELEGATE_WRITE_ATTRS_DELEG: + return "wa"; + } + return "?"; +} + static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st) { struct nfs4_delegation *ds; @@ -2851,8 +2866,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st) nfs4_show_stateid(s, &st->sc_stateid); seq_puts(s, ": { type: deleg, "); - seq_printf(s, "access: %s", - ds->dl_type == OPEN_DELEGATE_READ ? "r" : "w"); + seq_printf(s, "access: %s", nfs4_show_deleg_type(ds->dl_type)); /* XXX: lease time, whether it's being recalled. */ @@ -5433,7 +5447,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, static inline __be32 nfs4_check_delegmode(struct nfs4_delegation *dp, int flags) { - if ((flags & WR_STATE) && (dp->dl_type == OPEN_DELEGATE_READ)) + if ((flags & WR_STATE) && deleg_is_read(dp->dl_type)) return nfserr_openmode; else return nfs_ok; @@ -5665,8 +5679,7 @@ static bool nfsd4_cb_channel_good(struct nfs4_client *clp) return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; } -static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp, - int flag) +static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp) { struct file_lease *fl; @@ -5675,7 +5688,7 @@ static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp, return NULL; fl->fl_lmops = &nfsd_lease_mng_ops; fl->c.flc_flags = FL_DELEG; - fl->c.flc_type = flag == OPEN_DELEGATE_READ ? F_RDLCK : F_WRLCK; + fl->c.flc_type = deleg_is_read(dp->dl_type) ? F_RDLCK : F_WRLCK; fl->c.flc_owner = (fl_owner_t)dp; fl->c.flc_pid = current->tgid; fl->c.flc_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; @@ -5862,7 +5875,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, if (!dp) goto out_delegees; - fl = nfs4_alloc_init_lease(dp, dl_type); + fl = nfs4_alloc_init_lease(dp); if (!fl) goto out_clnt_odstate; @@ -6062,14 +6075,14 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open, struct nfs4_delegation *dp) { - if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_READ_DELEG && - dp->dl_type == OPEN_DELEGATE_WRITE) { - open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; - open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; - } else if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG && - dp->dl_type == OPEN_DELEGATE_WRITE) { - open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; - open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; + if (deleg_is_write(dp->dl_type)) { + if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_READ_DELEG) { + open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; + open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; + } else if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG) { + open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; + open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; + } } /* Otherwise the client must be confused wanting a delegation * it already has, therefore we don't return @@ -6080,11 +6093,14 @@ static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open, /* Are we only returning a delegation stateid? */ static bool open_xor_delegation(struct nfsd4_open *open) { + /* Was one requested? */ if (!(open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) return false; - if (open->op_delegate_type != OPEN_DELEGATE_READ && - open->op_delegate_type != OPEN_DELEGATE_WRITE) + + /* Did we actually get a delegation? */ + if (!deleg_is_read(open->op_delegate_type) && !deleg_is_write(open->op_delegate_type)) return false; + return true; } diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index e95f6ba5cc65611b47d5d297584ff6e478d80a1f..1c9d9349e4447c0078c7de0d533cf6278941679d 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4296,10 +4296,12 @@ nfsd4_encode_open_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open) status = nfs_ok; break; case OPEN_DELEGATE_READ: + case OPEN_DELEGATE_READ_ATTRS_DELEG: /* read */ status = nfsd4_encode_open_read_delegation4(xdr, open); break; case OPEN_DELEGATE_WRITE: + case OPEN_DELEGATE_WRITE_ATTRS_DELEG: /* write */ status = nfsd4_encode_open_write_delegation4(xdr, open); break; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index c7c7ec21e5104761221bd78b31110d902df1dc9b..9d0e844515aa6ea0ec62f2b538ecc2c6a5e34652 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -190,6 +190,22 @@ struct nfs4_delegation { struct nfs4_cb_fattr dl_cb_fattr; }; +static inline bool deleg_is_read(u32 dl_type) +{ + return (dl_type == OPEN_DELEGATE_READ || dl_type == OPEN_DELEGATE_READ_ATTRS_DELEG); +} + +static inline bool deleg_is_write(u32 dl_type) +{ + return (dl_type == OPEN_DELEGATE_WRITE || dl_type == OPEN_DELEGATE_WRITE_ATTRS_DELEG); +} + +static inline bool deleg_attrs_deleg(u32 dl_type) +{ + return dl_type == OPEN_DELEGATE_READ_ATTRS_DELEG || + dl_type == OPEN_DELEGATE_WRITE_ATTRS_DELEG; +} + #define cb_to_delegation(cb) \ container_of(cb, struct nfs4_delegation, dl_recall) From patchwork Mon Oct 14 19:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13835413 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 C79AE1D0E11; Mon, 14 Oct 2024 19:27:16 +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=1728934037; cv=none; b=rg9+uheZ5s2nQjy4XuoWIKmxrdIuzt5FVUqTzuT36jj1+pn5i3NkO4Bt+VOcpZzRkk+SO5tW6/PyVhwLceoeluI96skDrOGY46JpNk9VkgAzQmHHugBSl0L0KPdA1rNBySLWCqo4pjjao3wAVoUPmUafHDBSTCpqAILfzC3Dgzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728934037; c=relaxed/simple; bh=dGisJLqg+eYXaCTTby/7OSGEFV+swIbLcK0osBkVzXI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t7ZyCjXRwPo61pEJaQw8a3rsXdypxHXMPYoChD/MtQIldIlv2Wh7OA7LWy14f9FXVVEC8gSIhfKxiPeO2uTsna+FRTUoDGO/srJtf2TTe7Gca1OeVPcUI/FkEh/+6oHFzjPfkb8Cr6PTfuRR6B13AmQz8m2TNG9UYiUgRxV1upA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t8Sp5YKk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t8Sp5YKk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 132D2C4CEC3; Mon, 14 Oct 2024 19:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728934036; bh=dGisJLqg+eYXaCTTby/7OSGEFV+swIbLcK0osBkVzXI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=t8Sp5YKkz6tJPQ1KIsDf0jqUefEjiALBdmpikZPtxQUkgEvD+x6Tg48HDggYt3Iox khftxO4trS7SH2KjYKWylM8litC/8Ys/fgCAnFAS/uXG2c3dqVJuTQHGwYmfxQVH2f eQCsup0HRFbYOtIIQI1FsBlCa5zcouGvMB5XmQWAUlTt7FuD5KeFKLdqsyMmfj8e7o eo3oow6pediWPD0IfG51IPY/674YjCKD0XBbHaeN5NXrX9Kkt1m9WxpED0OyIGlBy4 yuNIgFpoJCbAzfj7x4C9l/umynzTBmMnRC5x2BSUTN7xHsjEK+WLHd+wutx8pY+CK2 aLZ/2wzaW63Fg== From: Jeff Layton Date: Mon, 14 Oct 2024 15:26:53 -0400 Subject: [PATCH 5/6] nfsd: add support for delegated timestamps Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-delstid-v1-5-7ce8a2f4dd24@kernel.org> References: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> In-Reply-To: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Jonathan Corbet , Trond Myklebust , Anna Schumaker , Thomas Haynes Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=14554; i=jlayton@kernel.org; h=from:subject:message-id; bh=dGisJLqg+eYXaCTTby/7OSGEFV+swIbLcK0osBkVzXI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnDXCLJ4yxG39i7M0cYMbhO/c1gYbvdaslrfTKI +Fk0J+sQWiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZw1wiwAKCRAADmhBGVaC FfqxD/98bfSMTOe2kLj4WruxtgG+Mor+qXiVjWOQPtUFl823Vm8suNZfNA+kyfLzmh5TsUXWMok asJecnzlApGMK1NAuT88NWn5JFiEV9ZZZaJ/9qj68SVFPL1mhTFeOANkZImWO/wnGGhVtands69 SlqvOo/8Cw+yKCszsrfgHuqcNgHIaSXF34ujXU8XMqhPOA86oi5q+2EmPHn4J2nvYnKTui6SLCF 8JOfgkp4zBeBvaPtGrgw72vYaHJFi1HrMVxZnIrj41Yws0SKqKpIcj/CR2FHLcH0EAf3AlfeJyM V3h8c0cfE80lkfhq/RSSjV4r1CTXTH+UmtdIyONCuQfmZDqrZOd9mMpgZIiA/fSLakM7qLxVvQg 9yg1LoRjz6pve2SaGied3EA13NQLdzMyQxBEkcrojkfIHReVDYh7g0GFBDPsXRivhz2OLSDArcS 6u8kv63vf2AX2JrwcdeZNpM8ZEMdW651pDzgH2m/CIXcjRmQ1EopIyPjBZkLwxyUP7Te5teLGEB U8i/e1plJzRSTmqzlmmE+UYBW9nBreuN/hqxW/V9zae8wSjMe+AEClKIiyKvgM2XPHJXkVrhuAD 6RuTWP7/uB+tRkwjWRq51baotMaxH/uEKH08w9PUOGC8N3gzRDkHw6M8e8beU3EK3cztadBoo69 CMk7TUDqezDJGQg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add support for the delegated timestamps on write delegations. This allows the server to proxy timestamps from the delegation holder to other clients that are doing GETATTRs vs. the same inode. When OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS bit is set in the OPEN call, set the dl_type to the *_ATTRS_DELEG flavor of delegation. Add timespec64 fields to nfs4_cb_fattr and decode the timestamps into those. Vet those timestamps according to the delstid spec and update the inode attrs if necessary. Signed-off-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/nfs4callback.c | 42 +++++++++++++++++++-- fs/nfsd/nfs4state.c | 99 +++++++++++++++++++++++++++++++++++++++++++------- fs/nfsd/nfs4xdr.c | 13 ++++++- fs/nfsd/nfsd.h | 2 + fs/nfsd/state.h | 2 + fs/nfsd/xdr4cb.h | 10 +++-- include/linux/time64.h | 5 +++ 7 files changed, 151 insertions(+), 22 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 776838bb83e6b707a4df76326cdc68f32daf1755..08245596289a960eb8b2e78df276544e7d3f4ff8 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -42,6 +42,7 @@ #include "trace.h" #include "xdr4cb.h" #include "xdr4.h" +#include "nfs4xdr_gen.h" #define NFSDDBG_FACILITY NFSDDBG_PROC @@ -93,12 +94,35 @@ static int decode_cb_fattr4(struct xdr_stream *xdr, uint32_t *bitmap, { fattr->ncf_cb_change = 0; fattr->ncf_cb_fsize = 0; + fattr->ncf_cb_atime.tv_sec = 0; + fattr->ncf_cb_atime.tv_nsec = 0; + fattr->ncf_cb_mtime.tv_sec = 0; + fattr->ncf_cb_mtime.tv_nsec = 0; + if (bitmap[0] & FATTR4_WORD0_CHANGE) if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_change) < 0) return -NFSERR_BAD_XDR; if (bitmap[0] & FATTR4_WORD0_SIZE) if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_fsize) < 0) return -NFSERR_BAD_XDR; + if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { + fattr4_time_deleg_access access; + + if (!xdrgen_decode_fattr4_time_deleg_access(xdr, &access)) + return -NFSERR_BAD_XDR; + fattr->ncf_cb_atime.tv_sec = access.seconds; + fattr->ncf_cb_atime.tv_nsec = access.nseconds; + + } + if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + fattr4_time_deleg_modify modify; + + if (!xdrgen_decode_fattr4_time_deleg_modify(xdr, &modify)) + return -NFSERR_BAD_XDR; + fattr->ncf_cb_mtime.tv_sec = modify.seconds; + fattr->ncf_cb_mtime.tv_nsec = modify.nseconds; + + } return 0; } @@ -364,15 +388,21 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr, struct nfs4_delegation *dp = container_of(fattr, struct nfs4_delegation, dl_cb_fattr); struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle; struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; - u32 bmap[1]; + u32 bmap_size = 1; + u32 bmap[3]; bmap[0] = FATTR4_WORD0_SIZE; if (!ncf->ncf_file_modified) bmap[0] |= FATTR4_WORD0_CHANGE; + if (deleg_attrs_deleg(dp->dl_type)) { + bmap[1] = 0; + bmap[2] = FATTR4_WORD2_TIME_DELEG_ACCESS | FATTR4_WORD2_TIME_DELEG_MODIFY; + bmap_size = 3; + } encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR); encode_nfs_fh4(xdr, fh); - encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap)); + encode_bitmap4(xdr, bmap, bmap_size); hdr->nops++; } @@ -597,7 +627,7 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp, struct nfs4_cb_compound_hdr hdr; int status; u32 bitmap[3] = {0}; - u32 attrlen; + u32 attrlen, maxlen; struct nfs4_cb_fattr *ncf = container_of(cb, struct nfs4_cb_fattr, ncf_getattr); @@ -616,7 +646,11 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp, return -NFSERR_BAD_XDR; if (xdr_stream_decode_u32(xdr, &attrlen) < 0) return -NFSERR_BAD_XDR; - if (attrlen > (sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize))) + maxlen = sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize); + if (bitmap[2] != 0) + maxlen += (sizeof(ncf->ncf_cb_mtime.tv_sec) + + sizeof(ncf->ncf_cb_mtime.tv_nsec)) * 2; + if (attrlen > maxlen) return -NFSERR_BAD_XDR; status = decode_cb_fattr4(xdr, bitmap, ncf); return status; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 62f9aeb159d0f2ab4d293bf5c0c56ad7b86eb9d6..2c8d2bb5261ad189c6dfb1c4050c23d8cf061325 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5803,13 +5803,14 @@ static struct nfs4_delegation * nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, struct svc_fh *parent) { - int status = 0; + bool deleg_ts = open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS; struct nfs4_client *clp = stp->st_stid.sc_client; struct nfs4_file *fp = stp->st_stid.sc_file; struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate; struct nfs4_delegation *dp; struct nfsd_file *nf = NULL; struct file_lease *fl; + int status = 0; u32 dl_type; /* @@ -5834,7 +5835,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, */ if ((open->op_share_access & NFS4_SHARE_ACCESS_BOTH) == NFS4_SHARE_ACCESS_BOTH) { nf = find_rw_file(fp); - dl_type = OPEN_DELEGATE_WRITE; + dl_type = deleg_ts ? OPEN_DELEGATE_WRITE_ATTRS_DELEG : OPEN_DELEGATE_WRITE; } /* @@ -5843,7 +5844,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, */ if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) { nf = find_readable_file(fp); - dl_type = OPEN_DELEGATE_READ; + dl_type = deleg_ts ? OPEN_DELEGATE_READ_ATTRS_DELEG : OPEN_DELEGATE_READ; } if (!nf) @@ -6001,13 +6002,14 @@ static void nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, struct svc_fh *currentfh) { - struct nfs4_delegation *dp; + bool deleg_ts = open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS; struct nfs4_openowner *oo = openowner(stp->st_stateowner); struct nfs4_client *clp = stp->st_stid.sc_client; struct svc_fh *parent = NULL; - int cb_up; - int status = 0; + struct nfs4_delegation *dp; struct kstat stat; + int status = 0; + int cb_up; cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); open->op_recall = false; @@ -6048,12 +6050,14 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, destroy_delegation(dp); goto out_no_deleg; } - open->op_delegate_type = OPEN_DELEGATE_WRITE; + open->op_delegate_type = deleg_ts ? OPEN_DELEGATE_WRITE_ATTRS_DELEG : + OPEN_DELEGATE_WRITE; dp->dl_cb_fattr.ncf_cur_fsize = stat.size; dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat); trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); } else { - open->op_delegate_type = OPEN_DELEGATE_READ; + open->op_delegate_type = deleg_ts ? OPEN_DELEGATE_READ_ATTRS_DELEG : + OPEN_DELEGATE_READ; trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); } nfs4_put_stid(&dp->dl_stid); @@ -8887,6 +8891,78 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate, get_stateid(cstate, &u->write.wr_stateid); } +/** + * set_cb_time - vet and set the timespec for a cb_getattr update + * @cb: timestamp from the CB_GETATTR response + * @orig: original timestamp in the inode + * @now: current time + * + * Given a timestamp in a CB_GETATTR response, check it against the + * current timestamp in the inode and the current time. Returns true + * if the inode's timestamp needs to be updated, and false otherwise. + * @cb may also be changed if the timestamp needs to be clamped. + */ +static bool set_cb_time(struct timespec64 *cb, const struct timespec64 *orig, + const struct timespec64 *now) +{ + + /* + * "When the time presented is before the original time, then the + * update is ignored." Also no need to update if there is no change. + */ + if (timespec64_compare(cb, orig) <= 0) + return false; + + /* + * "When the time presented is in the future, the server can either + * clamp the new time to the current time, or it may + * return NFS4ERR_DELAY to the client, allowing it to retry." + */ + if (timespec64_compare(cb, now) > 0) { + /* clamp it */ + *cb = *now; + } + + return true; +} + +static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation *dp) +{ + struct inode *inode = d_inode(dentry); + struct timespec64 now = current_time(inode); + struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; + struct iattr attrs = { }; + int ret; + + if (deleg_attrs_deleg(dp->dl_type)) { + struct timespec64 atime = inode_get_atime(inode); + struct timespec64 mtime = inode_get_mtime(inode); + + attrs.ia_atime = ncf->ncf_cb_atime; + attrs.ia_mtime = ncf->ncf_cb_mtime; + + if (set_cb_time(&attrs.ia_atime, &atime, &now)) + attrs.ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; + + if (set_cb_time(&attrs.ia_mtime, &mtime, &now)) { + attrs.ia_valid |= ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET; + attrs.ia_ctime = attrs.ia_mtime; + } + } else { + attrs.ia_valid |= ATTR_MTIME | ATTR_CTIME; + attrs.ia_mtime = attrs.ia_ctime = now; + } + + if (!attrs.ia_valid) + return 0; + + attrs.ia_valid |= ATTR_DELEG; + inode_lock(inode); + ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL); + inode_unlock(inode); + return ret; +} + /** * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict * @rqstp: RPC transaction context @@ -8913,7 +8989,6 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, struct file_lock_context *ctx; struct nfs4_delegation *dp = NULL; struct file_lease *fl; - struct iattr attrs; struct nfs4_cb_fattr *ncf; struct inode *inode = d_inode(dentry); @@ -8975,11 +9050,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, * not update the file's metadata with the client's * modified size */ - attrs.ia_mtime = attrs.ia_ctime = current_time(inode); - attrs.ia_valid = ATTR_MTIME | ATTR_CTIME | ATTR_DELEG; - inode_lock(inode); - err = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL); - inode_unlock(inode); + err = cb_getattr_update_times(dentry, dp); if (err) { status = nfserrno(err); goto out_status; diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 1c9d9349e4447c0078c7de0d533cf6278941679d..0e9f59f6be015bfa37893973f38fec880ff4c0b1 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3409,6 +3409,7 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr, #define NFSD_OA_SHARE_ACCESS_WANT (BIT(OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) #define NFSD_OA_OPEN_CLAIM (BIT(OPEN_ARGS_OPEN_CLAIM_NULL) | \ @@ -3602,7 +3603,11 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (status) goto out; } - if (attrmask[0] & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) { + if ((attrmask[0] & (FATTR4_WORD0_CHANGE | + FATTR4_WORD0_SIZE)) || + (attrmask[1] & (FATTR4_WORD1_TIME_ACCESS | + FATTR4_WORD1_TIME_MODIFY | + FATTR4_WORD1_TIME_METADATA))) { status = nfsd4_deleg_getattr_conflict(rqstp, dentry, &dp); if (status) goto out; @@ -3617,8 +3622,14 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (ncf->ncf_file_modified) { ++ncf->ncf_initial_cinfo; args.stat.size = ncf->ncf_cur_fsize; + if (!timespec64_is_epoch(&ncf->ncf_cb_mtime)) + args.stat.mtime = ncf->ncf_cb_mtime; } args.change_attr = ncf->ncf_initial_cinfo; + + if (!timespec64_is_epoch(&ncf->ncf_cb_atime)) + args.stat.atime = ncf->ncf_cb_atime; + nfs4_put_stid(&dp->dl_stid); } else { args.change_attr = nfsd4_change_attribute(&args.stat); diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 1955c8e9c4c793728fa75dd136cadc735245483f..004415651295891b3440f52a4c986e3a668a48cb 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -459,6 +459,8 @@ enum { FATTR4_WORD2_MODE_UMASK | \ NFSD4_2_SECURITY_ATTRS | \ FATTR4_WORD2_XATTR_SUPPORT | \ + FATTR4_WORD2_TIME_DELEG_ACCESS | \ + FATTR4_WORD2_TIME_DELEG_MODIFY | \ FATTR4_WORD2_OPEN_ARGUMENTS) extern const u32 nfsd_suppattrs[3][3]; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 9d0e844515aa6ea0ec62f2b538ecc2c6a5e34652..6351e6eca7cc63ccf82a3a081cef39042d52f4e9 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -142,6 +142,8 @@ struct nfs4_cb_fattr { /* from CB_GETATTR reply */ u64 ncf_cb_change; u64 ncf_cb_fsize; + struct timespec64 ncf_cb_mtime; + struct timespec64 ncf_cb_atime; unsigned long ncf_cb_flags; bool ncf_file_modified; diff --git a/fs/nfsd/xdr4cb.h b/fs/nfsd/xdr4cb.h index e8b00309c449fe2667f7d48cda88ec0cff924f93..f1a315cd31b74f73f1d52702ae7b5c93d51ddf82 100644 --- a/fs/nfsd/xdr4cb.h +++ b/fs/nfsd/xdr4cb.h @@ -59,16 +59,20 @@ * 1: CB_GETATTR opcode (32-bit) * N: file_handle * 1: number of entry in attribute array (32-bit) - * 1: entry 0 in attribute array (32-bit) + * 3: entry 0-2 in attribute array (32-bit * 3) */ #define NFS4_enc_cb_getattr_sz (cb_compound_enc_hdr_sz + \ cb_sequence_enc_sz + \ - 1 + enc_nfs4_fh_sz + 1 + 1) + 1 + enc_nfs4_fh_sz + 1 + 3) /* * 4: fattr_bitmap_maxsz * 1: attribute array len * 2: change attr (64-bit) * 2: size (64-bit) + * 2: atime.seconds (64-bit) + * 1: atime.nanoseconds (32-bit) + * 2: mtime.seconds (64-bit) + * 1: mtime.nanoseconds (32-bit) */ #define NFS4_dec_cb_getattr_sz (cb_compound_dec_hdr_sz + \ - cb_sequence_dec_sz + 4 + 1 + 2 + 2 + op_dec_sz) + cb_sequence_dec_sz + 4 + 1 + 2 + 2 + 2 + 1 + 2 + 1 + op_dec_sz) diff --git a/include/linux/time64.h b/include/linux/time64.h index f1bcea8c124a361b6c1e3c98ef915840c22a8413..9934331c7b86b7fb981c7aec0494ac2f5e72977e 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -49,6 +49,11 @@ static inline int timespec64_equal(const struct timespec64 *a, return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); } +static inline bool timespec64_is_epoch(const struct timespec64 *ts) +{ + return ts->tv_sec == 0 && ts->tv_nsec == 0; +} + /* * lhs < rhs: return <0 * lhs == rhs: return 0 From patchwork Mon Oct 14 19:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13835414 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 CA00C1D0E13; Mon, 14 Oct 2024 19:27:17 +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=1728934037; cv=none; b=bTOLCIIOJnt0rwUUFFK/H59iFZdmxmx1efP+WYfJ0xgXpU+EtzQQIanZLa2HFjiC+8xje8feolV0yTnPCMstgtgSys+iXb+HQFdMwKQuLSg0YgxKPVIQEdk4q4JtGo/CuZbILph5d3a5LG8/AZ9Jw05mmHXmlYAWKKVE/0FlVPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728934037; c=relaxed/simple; bh=Gdnp7ZUMKG+dC9gQ7nB03xLfgBQs3H/eiGZRPxyxlv4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k4RBI55lL06mk2TmegsgXtjICs62uy4DBz0oyIYtfP8pwFKiASwY9TQBX5/5xJnyrmX8yDtv9w2ep/IwUzuiPvJaFpY9XWY0Nwn5zz2gHm/v+wCCoAbBK0643d1gb6PJd0QKzECVHdT1MlS4DuCMzsn23LRgkLCLF8nZTWRjzmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TTIq/IoE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TTIq/IoE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6354BC4CED8; Mon, 14 Oct 2024 19:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728934037; bh=Gdnp7ZUMKG+dC9gQ7nB03xLfgBQs3H/eiGZRPxyxlv4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TTIq/IoEOfpGVGAhxjYhnt/e0+XUG2hTf/W8bfbo45pMyLMQNr8AI+MlVFeandNqB yJw49gUBMvh9NndwlOex8xMRM4HNhhwYIemUX/uN5bBCZDDd9omoN4SpzWYv+pf3Gx XE0jUw2K4jmvPeF/t+haYYY/8Xj83T1ejlS8HOQ5LJ5hQ+cgKAVAi21QEFXYPtL1CD 6G9hl+vOIvkoWryAwWRsPSkef1s9lOR9g9Fcu1J/u4zpN/LL0RSUykv8WMa2PpF8DD F0e9mdwPYx7ElFZd789Anj6mR8/aIoP4Bv7NSsMEZtFpZp+SkfngL5rQKpDgIMBsJg bDZGe3PD0DlUQ== From: Jeff Layton Date: Mon, 14 Oct 2024 15:26:54 -0400 Subject: [PATCH 6/6] nfsd: handle delegated timestamps in SETATTR Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-delstid-v1-6-7ce8a2f4dd24@kernel.org> References: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> In-Reply-To: <20241014-delstid-v1-0-7ce8a2f4dd24@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Jonathan Corbet , Trond Myklebust , Anna Schumaker , Thomas Haynes Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3234; i=jlayton@kernel.org; h=from:subject:message-id; bh=Gdnp7ZUMKG+dC9gQ7nB03xLfgBQs3H/eiGZRPxyxlv4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBnDXCMQ4YW+hawOR/CRBgN2k9D36HKXUIq+R0DC O99kx6ZQeWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZw1wjAAKCRAADmhBGVaC FehQD/48f6JodKWRZeE0lWv60hXAxmFYc2SwOnxvCTMXMrxp7ui0xA2VFks7xGAVTo8s/HvR2ZM iGYZL968DJKvX6pugCOINBu8SodvQH0eh0Ky0n1X/irJOQ23wiCEX7kHWrPlfb/gr4LmoA3z449 3TnRlJG1vSG7w3xLIN+AVJOeJeObV2fAVEBUZ+H3snxrD+WgLxXxG/81hJ0qZ7415xUjRJDLVLz NmtijqhHIukAeZvASJ8MakkQfS6vqwAFLEOLft/7MFRgC1PNQXJMNE31HSvlgK/GxYmunGHKNUU mThfGdORC4GUcymIwocvcCWBdLrmkmi77Xu/t/JcHED4XW0raYrt32JyN/ryWrjyaZaaDkUol6E tXX5ZKNx+8sfrX+PWJbTCiAjQKXBAzItkHqdQAzQaOFtAt21JF8Scy8cTlMKaoNfWIXkNnKAZXD JnkxDC4PRDhbZ8yW1702R82BnnxMkT0HxU7ZXRPs2UbsscNkKdq9EwEV85LNK2Sw6BAdvrT3Gur NQlg+IOtuJ4kSZYu5QTON4118A56yRAEl0JZNow9BMTOyLQzffwQ8S3SQlf3X9VW5c6QvyOqSbC BQdX1+e+KSJ0ghisUV6rBZ+vXdFVRu4U8ymeRiIYNl3SYzWiKgFuogENlJkoJB04uv+g63MEcGa nGrDaQm/3GMhtwQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Allow SETATTR to handle delegated timestamps. This patch assumes that only the delegation holder has the ability to set the timestamps in this way, so we allow this only if the SETATTR stateid refers to a *_ATTRS_DELEG delegation. Signed-off-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/nfs4proc.c | 26 +++++++++++++++++++++++--- fs/nfsd/nfs4xdr.c | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index fcce1f2e5454b0f3c4aa4b85fb4a4e24b2dee932..320c4f79662e65848dc824885566d48e696fe97c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1133,18 +1133,38 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, .na_iattr = &setattr->sa_iattr, .na_seclabel = &setattr->sa_label, }; + bool save_no_wcc, deleg_attrs; + struct nfs4_stid *st = NULL; struct inode *inode; __be32 status = nfs_ok; - bool save_no_wcc; int err; - if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { + deleg_attrs = setattr->sa_bmval[2] & (FATTR4_WORD2_TIME_DELEG_ACCESS | + FATTR4_WORD2_TIME_DELEG_MODIFY); + + if (deleg_attrs || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) { status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &setattr->sa_stateid, - WR_STATE, NULL, NULL); + WR_STATE, NULL, &st); if (status) return status; } + + if (deleg_attrs) { + status = nfserr_bad_stateid; + if (st->sc_type & SC_TYPE_DELEG) { + struct nfs4_delegation *dp = delegstateid(st); + + /* Only for *_ATTRS_DELEG flavors */ + if (deleg_attrs_deleg(dp->dl_type)) + status = nfs_ok; + } + } + if (st) + nfs4_put_stid(st); + if (status) + return status; + err = fh_want_write(&cstate->current_fh); if (err) return nfserrno(err); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 0e9f59f6be015bfa37893973f38fec880ff4c0b1..857b39fcdb772585601f760705564968bb0d554c 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -521,6 +521,26 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, *umask = mask & S_IRWXUGO; iattr->ia_valid |= ATTR_MODE; } + if (bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { + fattr4_time_deleg_access access; + + if (!xdrgen_decode_fattr4_time_deleg_access(argp->xdr, &access)) + return nfserr_bad_xdr; + iattr->ia_atime.tv_sec = access.seconds; + iattr->ia_atime.tv_nsec = access.nseconds; + iattr->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET | ATTR_DELEG; + } + if (bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + fattr4_time_deleg_modify modify; + + if (!xdrgen_decode_fattr4_time_deleg_modify(argp->xdr, &modify)) + return nfserr_bad_xdr; + iattr->ia_mtime.tv_sec = modify.seconds; + iattr->ia_mtime.tv_nsec = modify.nseconds; + iattr->ia_ctime.tv_sec = modify.seconds; + iattr->ia_ctime.tv_nsec = modify.seconds; + iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG; + } /* request sanity: did attrlist4 contain the expected number of words? */ if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos)