OPEN optimisations and Attribute delegations
Subsystems (2)
[email protected]
maintainerv2 cover OPEN optimisations and Attribute delegations
From: Trond Myklebust <[email protected]>
Now that https://datatracker.ietf.org/doc/draft-ietf-nfsv4-delstid/ is mostly done with the review process, it is time to look at pushing the client implementation that we've been working on upstream.
The following patch series therefore adds support for the NFSv4.2 extension to OP_OPEN to allow the client to request that the server return either an open stateid or a delegation instead of always sending the open stateid whether or not a delegation is returned. This allows us to optimise away CLOSE, and hence makes small or cached file access significantly more efficient.
It also adds support for attribute delegations, which allow the client to manage the atime and mtime, and simply inform the server at file close time what the values should be. This means that most GETATTR operations to retrieve the atime/mtime values while the file is under I/O can be optimised away.
Finally, we also add support for the detection mechanism that allows the client to determine whether or not the server supports the above functionality.
v2:
- Fix issues when compiling without CONFIG_NFS_V4
- Update "NFSv4: Fix up delegated attributes in nfs_setattr" to fix regressions pointed out by Anna Schumaker
- Squash commits "NFSv4: Ask for a delegation or an open stateid in OPEN" and "Return the delegation when deleting the sillyrenamed file" as suggested by Jeff Layton
- Add "NFSv4: Don't send delegation-related share access modes to CLOSE"
Lance Shelton (1):
Return the delegation when deleting sillyrenamed files
Trond Myklebust (18):
NFSv4: Clean up open delegation return structure
NFSv4: Refactor nfs4_opendata_check_deleg()
NFSv4: Add new attribute delegation definitions
NFSv4: Plumb in XDR support for the new delegation-only setattr op
NFSv4: Add CB_GETATTR support for delegated attributes
NFSv4: Add a flags argument to the 'have_delegation' callback
NFSv4: Add support for delegated atime and mtime attributes
NFSv4: Add recovery of attribute delegations
NFSv4: Add a capability for delegated attributes
NFSv4: Enable attribute delegations
NFSv4: Delegreturn must set m/atime when they are delegated
NFSv4: Fix up delegated attributes in nfs_setattr
NFSv4: Don't request atime/mtime/size if they are delegated to us
NFSv4: Add support for the FATTR4_OPEN_ARGUMENTS attribute
NFSv4: Detect support for OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION
NFSv4: Add support for OPEN4_RESULT_NO_OPEN_STATEID
NFSv4: Ask for a delegation or an open stateid in OPEN
NFSv4: Don't send delegation-related share access modes to CLOSE
fs/nfs/callback.h | 5 +- fs/nfs/callback_proc.c | 14 ++- fs/nfs/callback_xdr.c | 39 +++++- fs/nfs/delegation.c | 67 ++++++---- fs/nfs/delegation.h | 45 ++++++- fs/nfs/dir.c | 2 +- fs/nfs/file.c | 4 +- fs/nfs/inode.c | 86 +++++++++++-- fs/nfs/nfs3proc.c | 10 +- fs/nfs/nfs4proc.c | 248 ++++++++++++++++++++++++++++---------- fs/nfs/nfs4xdr.c | 131 +++++++++++++++----- fs/nfs/proc.c | 10 +- fs/nfs/read.c | 3 + fs/nfs/unlink.c | 2 + fs/nfs/write.c | 11 +- include/linux/nfs4.h | 11 ++ include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 45 ++++++- include/uapi/linux/nfs4.h | 4 + 19 files changed, 589 insertions(+), 150 deletions(-)
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 1/19 NFSv4: Clean up open delegation return structure
From: Trond Myklebust <[email protected]>
Instead of having the fields open coded in the struct nfs_openres, add a separate structure for them so that we can reuse that code for the WANT_DELEGATION case.
--- fs/nfs/nfs4proc.c | 30 ++++++++++++++++++------------ fs/nfs/nfs4xdr.c | 38 +++++++++++++++++++------------------- include/linux/nfs_xdr.h | 21 +++++++++++++++++---- 3 files changed, 54 insertions(+), 35 deletions(-)
fs/nfs/nfs4proc.c +18 -12
@@ -1960,6 +1960,13 @@ nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)struct nfs_delegation *delegation;int delegation_flags =0 ; +switch (data->o_res.delegation.open_delegation_type) { +case NFS4_OPEN_DELEGATE_READ : +case NFS4_OPEN_DELEGATE_WRITE : +break ; +default : +return ; + };rcu_read_lock (); delegation =rcu_dereference (NFS_I (state->inode)->delegation);if (delegation)
@@ -1979,19 +1986,19 @@ nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)if ((delegation_flags &1UL <<NFS_DELEGATION_NEED_RECLAIM ) ==0 )nfs_inode_set_delegation (state->inode, data->owner->so_cred, - data->o_res.delegation_type, - &data->o_res.delegation, - data->o_res.pagemod_limit); + data->o_res.delegation.type, + &data->o_res.delegation.stateid, + data->o_res.delegation.pagemod_limit);else nfs_inode_reclaim_delegation (state->inode, data->owner->so_cred, - data->o_res.delegation_type, - &data->o_res.delegation, - data->o_res.pagemod_limit); + data->o_res.delegation.type, + &data->o_res.delegation.stateid, + data->o_res.delegation.pagemod_limit); -if (data->o_res.do_recall) +if (data->o_res.delegation.do_recall)nfs_async_inode_return_delegation (state->inode, - &data->o_res.delegation); + &data->o_res.delegation.stateid); }/*
@@ -2015,8 +2022,7 @@ _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)if (ret)return ERR_PTR (ret); -if (data->o_res.delegation_type !=0 ) -nfs4_opendata_check_deleg (data, state); +nfs4_opendata_check_deleg (data, state);if (!update_open_stateid (state, &data->o_res.stateid,NULL , data->o_arg.fmode))
@@ -2083,7 +2089,7 @@ _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)if (IS_ERR (state)) goto out; -if (data->o_res.delegation_type !=0 ) +if (data->o_res.delegation.type !=0 )nfs4_opendata_check_deleg (data, state);if (!update_open_stateid (state, &data->o_res.stateid,NULL , data->o_arg.fmode)) {
@@ -3111,7 +3117,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,case NFS4_OPEN_CLAIM_DELEGATE_PREV :if (!opendata->rpc_done)break ; -if (opendata->o_res.delegation_type !=0 ) +if (opendata->o_res.delegation.type !=0 ) dir_verifier =nfs_save_change_attribute (dir);nfs_set_verifier (dentry, dir_verifier); }
fs/nfs/nfs4xdr.c +19 -19
@@ -5148,13 +5148,12 @@ static int decode_space_limit(struct xdr_stream *xdr, }static int decode_rw_delegation (struct xdr_stream *xdr, -uint32_t delegation_type, -struct nfs_openres *res) +struct nfs4_open_delegation *res) {__be32 *p;int status; - status =decode_delegation_stateid (xdr, &res->delegation); + status =decode_delegation_stateid (xdr, &res->stateid);if (unlikely (status))return status; p =xdr_inline_decode (xdr,4 );
@@ -5162,52 +5161,53 @@ static int decode_rw_delegation(struct xdr_stream *xdr,return -EIO ; res->do_recall =be32_to_cpup (p); -switch (delegation_type) { +switch (res->open_delegation_type) {case NFS4_OPEN_DELEGATE_READ : - res->delegation_type =FMODE_READ ; + res->type =FMODE_READ ;break ;case NFS4_OPEN_DELEGATE_WRITE : - res->delegation_type =FMODE_WRITE |FMODE_READ ; + res->type =FMODE_WRITE |FMODE_READ ;if (decode_space_limit (xdr, &res->pagemod_limit) <0 )return -EIO ; }return decode_ace (xdr,NULL ); } -static int decode_no_delegation (struct xdr_stream *xdr,struct nfs_openres *res) +static int decode_no_delegation (struct xdr_stream *xdr, +struct nfs4_open_delegation *res) {__be32 *p; -uint32_t why_no_delegation; p =xdr_inline_decode (xdr,4 );if (unlikely (!p))return -EIO ; - why_no_delegation =be32_to_cpup (p); -switch (why_no_delegation) { + res->why_no_delegation =be32_to_cpup (p); +switch (res->why_no_delegation) {case WND4_CONTENTION :case WND4_RESOURCE : -xdr_inline_decode (xdr,4 ); -/* Ignore for now */ + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) +return -EIO ; + res->will_notify =be32_to_cpup (p); }return 0 ; } -static int decode_delegation (struct xdr_stream *xdr,struct nfs_openres *res) +static int decode_delegation (struct xdr_stream *xdr, +struct nfs4_open_delegation *res) {__be32 *p; -uint32_t delegation_type; p =xdr_inline_decode (xdr,4 );if (unlikely (!p))return -EIO ; - delegation_type =be32_to_cpup (p); - res->delegation_type =0 ; -switch (delegation_type) { + res->open_delegation_type =be32_to_cpup (p); +switch (res->open_delegation_type) {case NFS4_OPEN_DELEGATE_NONE :return 0 ;case NFS4_OPEN_DELEGATE_READ :case NFS4_OPEN_DELEGATE_WRITE : -return decode_rw_delegation (xdr, delegation_type, res); +return decode_rw_delegation (xdr, res);case NFS4_OPEN_DELEGATE_NONE_EXT :return decode_no_delegation (xdr, res); }
@@ -5248,7 +5248,7 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)for (; i <NFS4_BITMAP_SIZE ; i++) res->attrset[i] =0 ; -return decode_delegation (xdr, res); +return decode_delegation (xdr, &res->delegation); xdr_error:dprintk ("%s: Bitmap too large! Length = %u\n" , __func__, bmlen);return -EIO ;
include/linux/nfs_xdr.h +17 -4
@@ -449,6 +449,22 @@ struct stateowner_id {__u32 uniquifier; }; +struct nfs4_open_delegation { +__u32 open_delegation_type; +union { +struct { +fmode_t type; +__u32 do_recall; +nfs4_stateid stateid; +unsigned long pagemod_limit; + }; +struct { +__u32 why_no_delegation; +__u32 will_notify; + }; + }; +}; +/* * Arguments to the open call. */
@@ -490,13 +506,10 @@ struct nfs_openres {struct nfs_fattr * f_attr;struct nfs_seqid * seqid;const struct nfs_server *server; -fmode_t delegation_type; -nfs4_stateid delegation; -unsigned long pagemod_limit; -__u32 do_recall;__u32 attrset[NFS4_BITMAP_SIZE ];struct nfs4_string *owner;struct nfs4_string *group_owner; +struct nfs4_open_delegation delegation;__u32 access_request;__u32 access_supported;__u32 access_result;
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 2/19 NFSv4: Refactor nfs4_opendata_check_deleg()
From: Trond Myklebust <[email protected]>
Modify it to no longer depend directly on the struct opendata. This will enable sharing with WANT_DELEGATION.
--- fs/nfs/nfs4proc.c | 66 +++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 36 deletions(-)
fs/nfs/nfs4proc.c +30 -36
@@ -1954,51 +1954,39 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) }static void -nfs4_opendata_check_deleg (struct nfs4_opendata *data,struct nfs4_state *state) +nfs4_process_delegation (struct inode *inode,const struct cred *cred, +enum open_claim_type4 claim, +const struct nfs4_open_delegation *delegation) { -struct nfs_client *clp =NFS_SERVER (state->inode)->nfs_client; -struct nfs_delegation *delegation; -int delegation_flags =0 ; - -switch (data->o_res.delegation.open_delegation_type) { +switch (delegation->open_delegation_type) {case NFS4_OPEN_DELEGATE_READ :case NFS4_OPEN_DELEGATE_WRITE :break ;default :return ; - }; -rcu_read_lock (); - delegation =rcu_dereference (NFS_I (state->inode)->delegation); -if (delegation) - delegation_flags = delegation->flags; -rcu_read_unlock (); -switch (data->o_arg.claim) { -default : -break ; + } +switch (claim) {case NFS4_OPEN_CLAIM_DELEGATE_CUR :case NFS4_OPEN_CLAIM_DELEG_CUR_FH :pr_err_ratelimited ("NFS: Broken NFSv4 server %s is " "returning a delegation for " "OPEN(CLAIM_DELEGATE_CUR)\n" , - clp->cl_hostname); -return ; +NFS_SERVER (inode)->nfs_client->cl_hostname); +break ; +case NFS4_OPEN_CLAIM_PREVIOUS : +nfs_inode_reclaim_delegation (inode, cred, + delegation->type, + &delegation->stateid, + delegation->pagemod_limit); +break ; +default : +nfs_inode_set_delegation (inode, cred, + delegation->type, + &delegation->stateid, + delegation->pagemod_limit); } -if ((delegation_flags &1UL <<NFS_DELEGATION_NEED_RECLAIM ) ==0 ) -nfs_inode_set_delegation (state->inode, - data->owner->so_cred, - data->o_res.delegation.type, - &data->o_res.delegation.stateid, - data->o_res.delegation.pagemod_limit); -else -nfs_inode_reclaim_delegation (state->inode, - data->owner->so_cred, - data->o_res.delegation.type, - &data->o_res.delegation.stateid, - data->o_res.delegation.pagemod_limit); - -if (data->o_res.delegation.do_recall) -nfs_async_inode_return_delegation (state->inode, - &data->o_res.delegation.stateid); +if (delegation->do_recall) +nfs_async_inode_return_delegation (inode, &delegation->stateid); }/*
@@ -2022,7 +2010,10 @@ _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)if (ret)return ERR_PTR (ret); -nfs4_opendata_check_deleg (data, state); +nfs4_process_delegation (state->inode, + data->owner->so_cred, + data->o_arg.claim, + &data->o_res.delegation);if (!update_open_stateid (state, &data->o_res.stateid,NULL , data->o_arg.fmode))
@@ -2089,8 +2080,11 @@ _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)if (IS_ERR (state)) goto out; -if (data->o_res.delegation.type !=0 ) -nfs4_opendata_check_deleg (data, state); +nfs4_process_delegation (state->inode, + data->owner->so_cred, + data->o_arg.claim, + &data->o_res.delegation); +if (!update_open_stateid (state, &data->o_res.stateid,NULL , data->o_arg.fmode)) {nfs4_put_open_state (state);
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 3/19 NFSv4: Add new attribute delegation definitions
From: Trond Myklebust <[email protected]>
Add the attribute delegation XDR definitions from the spec.
--- fs/nfs/nfs4proc.c | 2 +- include/linux/nfs4.h | 9 +++++++++ include/uapi/linux/nfs4.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-)
fs/nfs/nfs4proc.c +1 -1
@@ -3852,7 +3852,7 @@ static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)#define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)#define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) -#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) +#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_TIME_DELEG_MODIFY - 1UL)static int _nfs4_server_capabilities (struct nfs_server *server,struct nfs_fh *fhandle) {
include/linux/nfs4.h +9 -0
@@ -367,6 +367,8 @@ enum open_delegation_type4 {NFS4_OPEN_DELEGATE_READ =1 ,NFS4_OPEN_DELEGATE_WRITE =2 ,NFS4_OPEN_DELEGATE_NONE_EXT =3 ,/* 4.1 */ +NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG =4 , + NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG = 5, }; enum why_no_delegation4 { /* new to v4.1 */
@@ -507,6 +509,11 @@ enum { FATTR4_XATTR_SUPPORT = 82, }; +enum { +FATTR4_TIME_DELEG_ACCESS =84 , +FATTR4_TIME_DELEG_MODIFY =85 , +}; +/* * The following internal definitions enable processing the above * attribute bits within 32-bit word boundaries.
@@ -586,6 +593,8 @@ enum {#define FATTR4_WORD2_SECURITY_LABEL BIT(FATTR4_SEC_LABEL - 64)#define FATTR4_WORD2_MODE_UMASK BIT(FATTR4_MODE_UMASK - 64)#define FATTR4_WORD2_XATTR_SUPPORT BIT(FATTR4_XATTR_SUPPORT - 64) +#define FATTR4_WORD2_TIME_DELEG_ACCESS BIT(FATTR4_TIME_DELEG_ACCESS - 64) +#define FATTR4_WORD2_TIME_DELEG_MODIFY BIT(FATTR4_TIME_DELEG_MODIFY - 64)/* MDS threshold bitmap bits */ #define THRESHOLD_RD (1UL << 0)
include/uapi/linux/nfs4.h +2 -0
@@ -69,6 +69,8 @@#define NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL 0x10000#define NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED 0x20000 +#define NFS4_SHARE_WANT_DELEG_TIMESTAMPS 0x100000 +#define NFS4_CDFC4_FORE 0x1#define NFS4_CDFC4_BACK 0x2#define NFS4_CDFC4_BOTH 0x3
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 4/19 NFSv4: Plumb in XDR support for the new delegation-only setattr op
From: Trond Myklebust <[email protected]>
We want to send the updated atime and mtime as part of the delegreturn compound. Add a special structure to hold those variables.
--- fs/nfs/nfs4proc.c | 25 ++++++++++++++++++++ fs/nfs/nfs4xdr.c | 51 +++++++++++++++++++++++++++++++++++++++++ include/linux/nfs_xdr.h | 10 ++++++++ 3 files changed, 86 insertions(+)
fs/nfs/nfs4proc.c +25 -0
@@ -6575,6 +6575,7 @@ struct nfs4_delegreturndata {u32 roc_barrier;bool roc; } lr; +struct nfs4_delegattr sattr;struct nfs_fattr fattr;int rpc_status;struct inode *inode;
@@ -6599,6 +6600,30 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) &data->res.lr_ret) == -EAGAIN) goto out_restart; +if (data->args.sattr_args && task->tk_status !=0 ) { +switch (data->res.sattr_ret) { +case 0 : + data->args.sattr_args =NULL ; + data->res.sattr_res = false; +break ; +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +case -NFS4ERR_EXPIRED : +case -NFS4ERR_BAD_STATEID : +/* Let the main handler below do stateid recovery */ +break ; +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_delegation_stateid (&data->stateid, + data->inode)) + goto out_restart; + fallthrough; +default : + data->args.sattr_args =NULL ; + data->res.sattr_res = false; + goto out_restart; + } + } +switch (task->tk_status) {case 0 :renew_lease (data->res.server, data->timestamp);
fs/nfs/nfs4xdr.c +51 -0
108 lines not on this page · raw message
include/linux/nfs_xdr.h +10 -0
@@ -622,6 +622,13 @@ struct nfs_release_lockowner_res {struct nfs4_sequence_res seq_res; }; +struct nfs4_delegattr { +struct timespec64 atime; +struct timespec64 mtime; +bool atime_set; +bool mtime_set; +}; +struct nfs4_delegreturnargs {struct nfs4_sequence_args seq_args;const struct nfs_fh *fhandle;
@@ -629,6 +636,7 @@ struct nfs4_delegreturnargs {const u32 *bitmask;u32 bitmask_store[NFS_BITMASK_SZ ];struct nfs4_layoutreturn_args *lr_args; +struct nfs4_delegattr *sattr_args; };struct nfs4_delegreturnres {
@@ -637,6 +645,8 @@ struct nfs4_delegreturnres {struct nfs_server *server;struct nfs4_layoutreturn_res *lr_res;int lr_ret; +bool sattr_res; +int sattr_ret; };/*
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 5/19 NFSv4: Add CB_GETATTR support for delegated attributes
From: Trond Myklebust <[email protected]>
When the client holds an attribute delegation, the server may retrieve all the timestamps through a CB_GETATTR callback.
--- fs/nfs/callback.h | 5 +++-- fs/nfs/callback_proc.c | 14 +++++++++----- fs/nfs/callback_xdr.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 9 deletions(-)
fs/nfs/callback.h +3 -2
@@ -46,14 +46,15 @@ struct cb_compound_hdr_res {struct cb_getattrargs {struct nfs_fh fh; -uint32_t bitmap[2 ]; +uint32_t bitmap[3 ]; };struct cb_getattrres {__be32 status; -uint32_t bitmap[2 ]; +uint32_t bitmap[3 ];uint64_t size;uint64_t change_attr; +struct timespec64 atime;struct timespec64 ctime;struct timespec64 mtime; };
fs/nfs/callback_proc.c +9 -5
@@ -37,7 +37,7 @@ __be32 nfs4_callback_getattr(void *argp, void *resp,if (!cps->clp)/* Always set for v4.0. Set in cb_sequence for v4.1 */ goto out; - res->bitmap[0 ] = res->bitmap[1 ] =0 ; +memset (res->bitmap,0 ,sizeof (res->bitmap)); res->status =htonl (NFS4ERR_BADHANDLE ); dprintk_rcu("NFS: GETATTR callback request from %s\n",
@@ -59,12 +59,16 @@ __be32 nfs4_callback_getattr(void *argp, void *resp, res->change_attr = delegation->change_attr;if (nfs_have_writebacks (inode)) res->change_attr++; + res->atime =inode_get_atime (inode); res->ctime =inode_get_ctime (inode); res->mtime =inode_get_mtime (inode); - res->bitmap[0 ] = (FATTR4_WORD0_CHANGE |FATTR4_WORD0_SIZE ) & - args->bitmap[0 ]; - res->bitmap[1 ] = (FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ) & - args->bitmap[1 ]; + res->bitmap[0 ] = (FATTR4_WORD0_CHANGE |FATTR4_WORD0_SIZE ) & + args->bitmap[0 ]; + res->bitmap[1 ] = (FATTR4_WORD1_TIME_ACCESS | +FATTR4_WORD1_TIME_METADATA | +FATTR4_WORD1_TIME_MODIFY ) & args->bitmap[1 ]; + res->bitmap[2 ] = (FATTR4_WORD2_TIME_DELEG_ACCESS | +FATTR4_WORD2_TIME_DELEG_MODIFY ) & args->bitmap[2 ]; res->status =0 ; out_iput:rcu_read_unlock ();
fs/nfs/callback_xdr.c +37 -2
@@ -25,8 +25,9 @@#define CB_OP_GETATTR_BITMAP_MAXSZ (4 * 4) // bitmap length, 3 bitmaps#define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ CB_OP_GETATTR_BITMAP_MAXSZ + \ -/* change, size, ctime, mtime */ \ - (2 + 2 + 3 + 3) * 4) +/* change, size, atime, ctime, +* mtime, deleg_atime, deleg_mtime */ \ + (2 + 2 + 3 + 3 + 3 + 3 + 3) * 4)#define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ)#if defined(CONFIG_NFS_V4_1 )
@@ -635,6 +636,13 @@ static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec64 *return 0 ; } +static __be32 encode_attr_atime (struct xdr_stream *xdr,const uint32_t *bitmap,const struct timespec64 *time) +{ +if (!(bitmap[1 ] &FATTR4_WORD1_TIME_ACCESS )) +return 0 ; +return encode_attr_time (xdr,time); +} +static __be32 encode_attr_ctime (struct xdr_stream *xdr,const uint32_t *bitmap,const struct timespec64 *time) {if (!(bitmap[1 ] &FATTR4_WORD1_TIME_METADATA ))
@@ -649,6 +657,24 @@ static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap,return encode_attr_time (xdr,time); } +static __be32 encode_attr_delegatime (struct xdr_stream *xdr, +const uint32_t *bitmap, +const struct timespec64 *time) +{ +if (!(bitmap[2 ] &FATTR4_WORD2_TIME_DELEG_ACCESS )) +return 0 ; +return encode_attr_time (xdr,time); +} + +static __be32 encode_attr_delegmtime (struct xdr_stream *xdr, +const uint32_t *bitmap, +const struct timespec64 *time) +{ +if (!(bitmap[2 ] &FATTR4_WORD2_TIME_DELEG_MODIFY )) +return 0 ; +return encode_attr_time (xdr,time); +} +static __be32 encode_compound_hdr_res (struct xdr_stream *xdr,struct cb_compound_hdr_res *hdr) {__be32 status;
@@ -697,12 +723,21 @@ static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr,if (unlikely (status !=0 )) goto out; status =encode_attr_size (xdr, res->bitmap, res->size); +if (unlikely (status !=0 )) + goto out; + status =encode_attr_atime (xdr, res->bitmap, &res->atime);if (unlikely (status !=0 )) goto out; status =encode_attr_ctime (xdr, res->bitmap, &res->ctime);if (unlikely (status !=0 )) goto out; status =encode_attr_mtime (xdr, res->bitmap, &res->mtime); +if (unlikely (status !=0 )) + goto out; + status =encode_attr_delegatime (xdr, res->bitmap, &res->atime); +if (unlikely (status !=0 )) + goto out; + status =encode_attr_delegmtime (xdr, res->bitmap, &res->mtime); *savep =htonl ((unsigned int )((char *)xdr->p - (char *)(savep+1 ))); out:return status;
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 6/19 NFSv4: Add a flags argument to the 'have_delegation' callback
From: Trond Myklebust <[email protected]>
This argument will be used to allow the caller to specify whether or not they need to know that this is an attribute delegation.
--- fs/nfs/delegation.c | 26 +++++++++++++------------- fs/nfs/delegation.h | 16 +++++++++++++--- fs/nfs/dir.c | 2 +- fs/nfs/file.c | 4 ++-- fs/nfs/inode.c | 7 +++---- fs/nfs/nfs3proc.c | 2 +- fs/nfs/nfs4proc.c | 14 +++++++------- fs/nfs/proc.c | 2 +- fs/nfs/write.c | 2 +- include/linux/nfs_xdr.h | 2 +- 10 files changed, 43 insertions(+), 34 deletions(-)
fs/nfs/delegation.c +13 -13
@@ -82,11 +82,10 @@ static void nfs_mark_return_delegation(struct nfs_server *server,set_bit (NFS4CLNT_DELEGRETURN , &server->nfs_client->cl_state); } -static bool -nfs4_is_valid_delegation (const struct nfs_delegation *delegation, -fmode_t flags) +static bool nfs4_is_valid_delegation (const struct nfs_delegation *delegation, +fmode_t type) { -if (delegation !=NULL && (delegation->type & flags) == flags && +if (delegation !=NULL && (delegation->type & type) == type && !test_bit (NFS_DELEGATION_REVOKED , &delegation->flags) && !test_bit (NFS_DELEGATION_RETURNING , &delegation->flags))return true;
@@ -103,16 +102,16 @@ struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode)return NULL ; } -static int -nfs4_do_check_delegation (struct inode *inode,fmode_t flags,bool mark) +static int nfs4_do_check_delegation (struct inode *inode,fmode_t type, +int flags,bool mark) {struct nfs_delegation *delegation;int ret =0 ; - flags &=FMODE_READ |FMODE_WRITE ; + type &=FMODE_READ |FMODE_WRITE ;rcu_read_lock (); delegation =rcu_dereference (NFS_I (inode)->delegation); -if (nfs4_is_valid_delegation (delegation, flags)) { +if (nfs4_is_valid_delegation (delegation, type)) {if (mark)nfs_mark_delegation_referenced (delegation); ret =1 ;
@@ -124,22 +123,23 @@ nfs4_do_check_delegation(struct inode *inode, fmode_t flags, bool mark)* nfs4_have_delegation - check if inode has a delegation, mark it * NFS_DELEGATION_REFERENCED if there is one. * @inode: inode to check -* @flags: delegation types to check for +* @type: delegation types to check for +* @flags: various modifiers * * Returns one if inode has the indicated delegation, otherwise zero. */ -int nfs4_have_delegation (struct inode *inode,fmode_t flags) +int nfs4_have_delegation (struct inode *inode,fmode_t type,int flags) { -return nfs4_do_check_delegation (inode, flags, true); +return nfs4_do_check_delegation (inode, type, flags, true); }/* * nfs4_check_delegation - check if inode has a delegation, do not mark * NFS_DELEGATION_REFERENCED if it has one. */ -int nfs4_check_delegation (struct inode *inode,fmode_t flags) +int nfs4_check_delegation (struct inode *inode,fmode_t type) { -return nfs4_do_check_delegation (inode, flags, false); +return nfs4_do_check_delegation (inode, type,0 , false); }static int nfs_delegation_claim_locks (struct nfs4_state *state,const nfs4_stateid *stateid)
fs/nfs/delegation.h +13 -3
@@ -75,8 +75,8 @@ bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);struct nfs_delegation *nfs4_get_valid_delegation (const struct inode *inode);void nfs_mark_delegation_referenced (struct nfs_delegation *delegation); -int nfs4_have_delegation (struct inode *inode,fmode_t flags); -int nfs4_check_delegation (struct inode *inode,fmode_t flags); +int nfs4_have_delegation (struct inode *inode,fmode_t type,int flags); +int nfs4_check_delegation (struct inode *inode,fmode_t type);bool nfs4_delegation_flush_on_close (const struct inode *inode);void nfs_inode_find_delegation_state_and_recover (struct inode *inode,const nfs4_stateid *stateid);
@@ -84,9 +84,19 @@ int nfs4_inode_make_writeable(struct inode *inode);#endif +static inline int nfs_have_read_or_write_delegation (struct inode *inode) +{ +return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ,0 ); +} + +static inline int nfs_have_write_delegation (struct inode *inode) +{ +return NFS_PROTO (inode)->have_delegation (inode,FMODE_WRITE ,0 ); +} +static inline int nfs_have_delegated_attributes (struct inode *inode) { -return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ); +return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ,0 ); }#endif
fs/nfs/dir.c +1 -1
@@ -1437,7 +1437,7 @@ static void nfs_set_verifier_locked(struct dentry *dentry, unsigned long verf)if (!dir || !nfs_verify_change_attribute (dir, verf))return ; -if (inode &&NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) +if (inode &&NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ,0 ))nfs_set_verifier_delegated (&verf); dentry->d_time = verf; }
fs/nfs/file.c +2 -2
@@ -732,7 +732,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local) } fl->c.flc_type = saved_type; -if (NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) +if (nfs_have_read_or_write_delegation (inode)) goto out_noconflict;if (is_local)
@@ -815,7 +815,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)* This makes locking act as a cache coherency point. */ nfs_sync_mapping (filp->f_mapping); -if (!NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) { +if (!nfs_have_read_or_write_delegation (inode)) {nfs_zap_caches (inode);if (mapping_mapped (filp->f_mapping))nfs_revalidate_mapping (inode, filp->f_mapping);
fs/nfs/inode.c +3 -4
@@ -190,9 +190,8 @@ static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)void nfs_set_cache_invalid (struct inode *inode,unsigned long flags) {struct nfs_inode *nfsi =NFS_I (inode); -bool have_delegation =NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ); -if (have_delegation) { +if (nfs_have_delegated_attributes (inode)) {if (!(flags &NFS_INO_REVAL_FORCED )) flags &= ~(NFS_INO_INVALID_MODE | NFS_INO_INVALID_OTHER |
@@ -1013,7 +1012,7 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)if (!is_sync)return ; inode =d_inode (ctx->dentry); -if (NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) +if (nfs_have_read_or_write_delegation (inode))return ; nfsi =NFS_I (inode);if (inode->i_mapping->nrpages ==0 )
@@ -1483,7 +1482,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fatunsigned long invalid =0 ;struct timespec64 ts; -if (NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) +if (nfs_have_delegated_attributes (inode))return 0 ;if (!(fattr->valid &NFS_ATTR_FATTR_FILEID )) {
fs/nfs/nfs3proc.c +1 -1
@@ -979,7 +979,7 @@ nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)return status; } -static int nfs3_have_delegation (struct inode *inode,fmode_t flags) +static int nfs3_have_delegation (struct inode *inode,fmode_t type,int flags) {return 0 ; }
fs/nfs/nfs4proc.c +7 -7
@@ -293,7 +293,7 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src,unsigned long cache_validity;memcpy (dst, src,NFS4_BITMASK_SZ *sizeof (*dst)); -if (!inode || !nfs4_have_delegation (inode,FMODE_READ )) +if (!inode || !nfs_have_read_or_write_delegation (inode))return ; cache_validity =READ_ONCE (NFS_I (inode)->cache_validity) | flags;
@@ -1264,7 +1264,7 @@ nfs4_update_changeattr_locked(struct inode *inode,if (S_ISDIR (inode->i_mode))nfs_force_lookup_revalidate (inode); -if (!NFS_PROTO (inode)->have_delegation (inode,FMODE_READ )) +if (!nfs_have_delegated_attributes (inode)) cache_validity |=NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL | NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER |
@@ -3700,7 +3700,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)if (calldata->arg.fmode ==0 || calldata->arg.fmode ==FMODE_READ ) {/* Close-to-open cache consistency revalidation */ -if (!nfs4_have_delegation (inode,FMODE_READ )) { +if (!nfs4_have_delegation (inode,FMODE_READ ,0 )) {nfs4_bitmask_set (calldata->arg.bitmask_store, server->cache_consistency_bitmask, inode,0 );
@@ -4638,7 +4638,7 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry };int status =0 ; -if (!nfs4_have_delegation (inode,FMODE_READ )) { +if (!nfs4_have_delegation (inode,FMODE_READ ,0 )) { res.fattr =nfs_alloc_fattr ();if (res.fattr ==NULL )return -ENOMEM ;
@@ -5607,7 +5607,7 @@ bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr)/* Otherwise, request attributes if and only if we don't hold * a delegation */ -return nfs4_have_delegation (hdr->inode,FMODE_READ ) ==0 ; +return nfs4_have_delegation (hdr->inode,FMODE_READ ,0 ) ==0 ; } void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
@@ -7654,10 +7654,10 @@ static int nfs4_add_lease(struct file *file, int arg, struct file_lease **lease,int ret;/* No delegation, no lease */ -if (!nfs4_have_delegation (inode, type)) +if (!nfs4_have_delegation (inode, type,0 ))return -EAGAIN ; ret =generic_setlease (file, arg, lease, priv); -if (ret ||nfs4_have_delegation (inode, type)) +if (ret ||nfs4_have_delegation (inode, type,0 ))return ret;/* We raced with a delegation return */ nfs4_delete_lease (file, priv);
fs/nfs/proc.c +1 -1
@@ -687,7 +687,7 @@ static int nfs_lock_check_bounds(const struct file_lock *fl)return -EINVAL ; } -static int nfs_have_delegation (struct inode *inode,fmode_t flags) +static int nfs_have_delegation (struct inode *inode,fmode_t type,int flags) {return 0 ; }
fs/nfs/write.c +1 -1
@@ -1320,7 +1320,7 @@ static int nfs_can_extend_write(struct file *file, struct folio *folio,return 0 ;if (!nfs_folio_write_uptodate (folio, pagelen))return 0 ; -if (NFS_PROTO (inode)->have_delegation (inode,FMODE_WRITE )) +if (nfs_have_write_delegation (inode))return 1 ;if (!flctx || (list_empty_careful (&flctx->flc_flock) &&list_empty_careful (&flctx->flc_posix)))
include/linux/nfs_xdr.h +1 -1
@@ -1830,7 +1830,7 @@ struct nfs_rpc_ops {int open_flags, struct iattr *iattr, int *); -int (*have_delegation)(struct inode *,fmode_t ); +int (*have_delegation)(struct inode *,fmode_t ,int );struct nfs_client *(*alloc_client) (const struct nfs_client_initdata *);struct nfs_client *(*init_client) (struct nfs_client *,const struct nfs_client_initdata *);
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 7/19 NFSv4: Add support for delegated atime and mtime attributes
From: Trond Myklebust <[email protected]>
Ensure that we update the mtime and atime correctly when we read or write data to the file and when we truncate. Let the server manage ctime on other attribute updates.
--- fs/nfs/delegation.c | 32 ++++++++++++++++++++++----- fs/nfs/delegation.h | 25 +++++++++++++++++++-- fs/nfs/inode.c | 54 +++++++++++++++++++++++++++++++++++++++++---- fs/nfs/nfs4proc.c | 21 ++++++++++-------- fs/nfs/read.c | 3 +++ fs/nfs/write.c | 9 ++++++++ 6 files changed, 124 insertions(+), 20 deletions(-)
fs/nfs/delegation.c +27 -5
@@ -115,6 +115,9 @@ static int nfs4_do_check_delegation(struct inode *inode, fmode_t type,if (mark)nfs_mark_delegation_referenced (delegation); ret =1 ; +if ((flags &NFS_DELEGATION_FLAG_TIME ) && + !test_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags)) + ret =0 ; }rcu_read_unlock ();return ret;
@@ -221,11 +224,12 @@ static int nfs_delegation_claim_opens(struct inode *inode,* @type: delegation type * @stateid: delegation stateid * @pagemod_limit: write delegation "space_limit" +* @deleg_type: raw delegation type * */ void nfs_inode_reclaim_delegation (struct inode *inode,const struct cred *cred,fmode_t type,const nfs4_stateid *stateid, -unsigned long pagemod_limit) +unsigned long pagemod_limit,u32 deleg_type) {struct nfs_delegation *delegation;const struct cred *oldcred =NULL ;
@@ -239,6 +243,14 @@ void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred, delegation->pagemod_limit = pagemod_limit; oldcred = delegation->cred; delegation->cred =get_cred (cred); +switch (deleg_type) { +case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG : +case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG : +set_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags); +break ; +default : +clear_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags); + }clear_bit (NFS_DELEGATION_NEED_RECLAIM , &delegation->flags);if (test_and_clear_bit (NFS_DELEGATION_REVOKED , &delegation->flags))
@@ -250,7 +262,7 @@ void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred, }else {rcu_read_unlock ();nfs_inode_set_delegation (inode, cred, type, stateid, - pagemod_limit); + pagemod_limit, deleg_type); } }
@@ -418,13 +430,13 @@ nfs_update_inplace_delegation(struct nfs_delegation *delegation,* @type: delegation type * @stateid: delegation stateid * @pagemod_limit: write delegation "space_limit" +* @deleg_type: raw delegation type * * Returns zero on success, or a negative errno value. */ int nfs_inode_set_delegation (struct inode *inode,const struct cred *cred, -fmode_t type, -const nfs4_stateid *stateid, -unsigned long pagemod_limit) +fmode_t type,const nfs4_stateid *stateid, +unsigned long pagemod_limit,u32 deleg_type) {struct nfs_server *server =NFS_SERVER (inode);struct nfs_client *clp = server->nfs_client;
@@ -444,6 +456,11 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, delegation->cred =get_cred (cred); delegation->inode = inode; delegation->flags =1 <<NFS_DELEGATION_REFERENCED ; +switch (deleg_type) { +case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG : +case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG : + delegation->flags |=BIT (NFS_DELEGATION_DELEGTIME ); + } delegation->test_gen =0 ;spin_lock_init (&delegation->lock);
@@ -508,6 +525,11 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,atomic_long_inc (&nfs_active_delegations);trace_nfs4_set_delegation (inode, type); + +/* If we hold writebacks and have delegated mtime then update */ +if (deleg_type ==NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG && +nfs_have_writebacks (inode)) +nfs_update_delegated_mtime (inode); out:spin_unlock (&clp->cl_lock);if (delegation !=NULL )
fs/nfs/delegation.h +23 -2
@@ -38,12 +38,15 @@ enum {NFS_DELEGATION_TEST_EXPIRED ,NFS_DELEGATION_INODE_FREEING ,NFS_DELEGATION_RETURN_DELAYED , + NFS_DELEGATION_DELEGTIME, };int nfs_inode_set_delegation (struct inode *inode,const struct cred *cred, -fmode_t type,const nfs4_stateid *stateid,unsigned long pagemod_limit); +fmode_t type,const nfs4_stateid *stateid, +unsigned long pagemod_limit,u32 deleg_type);void nfs_inode_reclaim_delegation (struct inode *inode,const struct cred *cred, -fmode_t type,const nfs4_stateid *stateid,unsigned long pagemod_limit); +fmode_t type,const nfs4_stateid *stateid, +unsigned long pagemod_limit,u32 deleg_type);int nfs4_inode_return_delegation (struct inode *inode);void nfs4_inode_return_delegation_on_close (struct inode *inode);int nfs_async_inode_return_delegation (struct inode *inode,const nfs4_stateid *stateid);
@@ -84,6 +87,12 @@ int nfs4_inode_make_writeable(struct inode *inode);#endif +#define NFS_DELEGATION_FLAG_TIME BIT(1) + +void nfs_update_delegated_atime (struct inode *inode); +void nfs_update_delegated_mtime (struct inode *inode); +void nfs_update_delegated_mtime_locked (struct inode *inode); +static inline int nfs_have_read_or_write_delegation (struct inode *inode) {return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ ,0 );
@@ -99,4 +108,16 @@ static inline int nfs_have_delegated_attributes(struct inode *inode) return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0); } +static inline int nfs_have_delegated_atime (struct inode *inode) +{ +return NFS_PROTO (inode)->have_delegation (inode,FMODE_READ , +NFS_DELEGATION_FLAG_TIME ); +} + +static inline int nfs_have_delegated_mtime (struct inode *inode) +{ +return NFS_PROTO (inode)->have_delegation (inode,FMODE_WRITE , +NFS_DELEGATION_FLAG_TIME ); +} +#endif
fs/nfs/inode.c +50 -4
90 lines not on this page · raw message
fs/nfs/nfs4proc.c +12 -9
@@ -1245,7 +1245,8 @@ nfs4_update_changeattr_locked(struct inode *inode,struct nfs_inode *nfsi =NFS_I (inode);u64 change_attr =inode_peek_iversion_raw (inode); - cache_validity |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ; +if (!nfs_have_delegated_mtime (inode)) + cache_validity |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ;if (S_ISDIR (inode->i_mode)) cache_validity |=NFS_INO_INVALID_DATA ;
@@ -1961,6 +1962,8 @@ nfs4_process_delegation(struct inode *inode, const struct cred *cred,switch (delegation->open_delegation_type) {case NFS4_OPEN_DELEGATE_READ :case NFS4_OPEN_DELEGATE_WRITE : +case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG : +case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG :break ;default :return ;
@@ -1974,16 +1977,16 @@ nfs4_process_delegation(struct inode *inode, const struct cred *cred, NFS_SERVER(inode)->nfs_client->cl_hostname);break ;case NFS4_OPEN_CLAIM_PREVIOUS : -nfs_inode_reclaim_delegation (inode, cred, - delegation->type, - &delegation->stateid, - delegation->pagemod_limit); +nfs_inode_reclaim_delegation (inode, cred, delegation->type, + &delegation->stateid, + delegation->pagemod_limit, + delegation->open_delegation_type);break ;default : -nfs_inode_set_delegation (inode, cred, - delegation->type, - &delegation->stateid, - delegation->pagemod_limit); +nfs_inode_set_delegation (inode, cred, delegation->type, + &delegation->stateid, + delegation->pagemod_limit, + delegation->open_delegation_type); }if (delegation->do_recall)nfs_async_inode_return_delegation (inode, &delegation->stateid);
fs/nfs/read.c +3 -0
@@ -28,6 +28,7 @@#include "fscache.h" #include "pnfs.h" #include "nfstrace.h" +#include "delegation.h" #define NFSDBG_FACILITY NFSDBG_PAGECACHE
@@ -372,6 +373,7 @@ int nfs_read_folio(struct file *file, struct folio *folio) goto out_put;nfs_pageio_complete_read (&pgio); +nfs_update_delegated_atime (inode); ret = pgio.pg_error <0 ? pgio.pg_error :0 ;if (!ret) { ret =folio_wait_locked_killable (folio);
@@ -428,6 +430,7 @@ void nfs_readahead(struct readahead_control *ractl) }nfs_pageio_complete_read (&pgio); +nfs_update_delegated_atime (inode);put_nfs_open_context (ctx); out:
fs/nfs/write.c +9 -0
@@ -289,6 +289,8 @@ static void nfs_grow_file(struct folio *folio, unsigned int offset,NFS_I (inode)->cache_validity &= ~NFS_INO_INVALID_SIZE ;nfs_inc_stats (inode,NFSIOS_EXTENDWRITE ); out: +/* Atomically update timestamps if they are delegated to us. */ +nfs_update_delegated_mtime_locked (inode);spin_unlock (&inode->i_lock);nfs_fscache_invalidate (inode,0 ); }
@@ -1514,6 +1516,13 @@ void nfs_writeback_update_inode(struct nfs_pgio_header *hdr)struct nfs_fattr *fattr = &hdr->fattr;struct inode *inode = hdr->inode; +if (nfs_have_delegated_mtime (inode)) { +spin_lock (&inode->i_lock); +nfs_set_cache_invalid (inode,NFS_INO_INVALID_BLOCKS ); +spin_unlock (&inode->i_lock); +return ; + } +spin_lock (&inode->i_lock);nfs_writeback_check_extend (hdr, fattr);nfs_post_op_update_inode_force_wcc_locked (inode, fattr);
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 8/19 NFSv4: Add recovery of attribute delegations
From: Trond Myklebust <[email protected]>
After a reboot of the NFSv4.2 server, the recovery code needs to specify whether the delegation to be recovered is an attribute delegation or not.
--- fs/nfs/nfs4proc.c | 18 +++++++++++++++--- fs/nfs/nfs4xdr.c | 18 ++++++++---------- include/linux/nfs_xdr.h | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-)
fs/nfs/nfs4proc.c +15 -3
@@ -2225,7 +2225,7 @@ static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state {struct nfs_delegation *delegation;struct nfs4_opendata *opendata; -fmode_t delegation_type =0 ; +u32 delegation_type =NFS4_OPEN_DELEGATE_NONE ;int status; opendata = nfs4_open_recoverdata_alloc(ctx, state,
@@ -2234,8 +2234,20 @@ static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_statereturn PTR_ERR (opendata);rcu_read_lock (); delegation =rcu_dereference (NFS_I (state->inode)->delegation); -if (delegation !=NULL &&test_bit (NFS_DELEGATION_NEED_RECLAIM , &delegation->flags) !=0 ) - delegation_type = delegation->type; +if (delegation !=NULL &&test_bit (NFS_DELEGATION_NEED_RECLAIM , &delegation->flags) !=0 ) { +switch (delegation->type) { +case FMODE_READ : + delegation_type =NFS4_OPEN_DELEGATE_READ ; +if (test_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags)) + delegation_type =NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG ; +break ; +case FMODE_WRITE : +case FMODE_READ |FMODE_WRITE : + delegation_type =NFS4_OPEN_DELEGATE_WRITE ; +if (test_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags)) + delegation_type =NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG ; + } + }rcu_read_unlock (); opendata->o_arg.u.delegation_type = delegation_type; status =nfs4_open_recover (opendata, state);
fs/nfs/nfs4xdr.c +8 -10
@@ -1475,20 +1475,18 @@ static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *a } } -static inline void encode_delegation_type (struct xdr_stream *xdr,fmode_t delegation_type) +static inline void encode_delegation_type (struct xdr_stream *xdr,u32 delegation_type) {__be32 *p; p =reserve_space (xdr,4 );switch (delegation_type) { -case 0 : - *p =cpu_to_be32 (NFS4_OPEN_DELEGATE_NONE ); -break ; -case FMODE_READ : - *p =cpu_to_be32 (NFS4_OPEN_DELEGATE_READ ); -break ; -case FMODE_WRITE |FMODE_READ : - *p =cpu_to_be32 (NFS4_OPEN_DELEGATE_WRITE ); +case NFS4_OPEN_DELEGATE_NONE : +case NFS4_OPEN_DELEGATE_READ : +case NFS4_OPEN_DELEGATE_WRITE : +case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG : +case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG : + *p =cpu_to_be32 (delegation_type);break ;default :BUG ();
@@ -1504,7 +1502,7 @@ static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *encode_string (xdr, name->len, name->name); } -static inline void encode_claim_previous (struct xdr_stream *xdr,fmode_t type) +static inline void encode_claim_previous (struct xdr_stream *xdr,u32 type) {__be32 *p;
include/linux/nfs_xdr.h +1 -1
@@ -484,7 +484,7 @@ struct nfs_openargs {nfs4_verifier verifier;/* EXCLUSIVE */ };nfs4_stateid delegation;/* CLAIM_DELEGATE_CUR */ -fmode_t delegation_type;/* CLAIM_PREVIOUS */ +__u32 delegation_type;/* CLAIM_PREVIOUS */ } u;const struct qstr * name;const struct nfs_server *server;/* Needed for ID mapping */
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 9/19 NFSv4: Add a capability for delegated attributes
From: Trond Myklebust <[email protected]>
Cache whether or not the server may have support for delegated attributes in a capability flag.
--- fs/nfs/nfs4proc.c | 2 ++ include/linux/nfs_fs_sb.h | 1 + 2 files changed, 3 insertions(+)
fs/nfs/nfs4proc.c +2 -0
@@ -3930,6 +3930,8 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f#endif if (res.attr_bitmask[0 ] &FATTR4_WORD0_FS_LOCATIONS ) server->caps |=NFS_CAP_FS_LOCATIONS ; +if (res.attr_bitmask[2 ] &FATTR4_WORD2_TIME_DELEG_MODIFY ) + server->caps |=NFS_CAP_DELEGTIME ;if (!(res.attr_bitmask[0 ] &FATTR4_WORD0_FILEID )) server->fattr_valid &= ~NFS_ATTR_FATTR_FILEID ;if (!(res.attr_bitmask[1 ] &FATTR4_WORD1_MODE ))
include/linux/nfs_fs_sb.h +1 -0
@@ -278,6 +278,7 @@ struct nfs_server {#define NFS_CAP_LGOPEN (1U << 5)#define NFS_CAP_CASE_INSENSITIVE (1U << 6)#define NFS_CAP_CASE_PRESERVING (1U << 7) +#define NFS_CAP_DELEGTIME (1U << 13)#define NFS_CAP_POSIX_LOCK (1U << 14)#define NFS_CAP_UIDGID_NOMAP (1U << 15)#define NFS_CAP_STATEID_NFSV41 (1U << 16)
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 10/19 NFSv4: Enable attribute delegations
From: Trond Myklebust <[email protected]>
If we see that the server supports attribute delegations, then request them by setting the appropriate OPEN arguments.
--- fs/nfs/nfs4proc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/nfs4proc.c +6 -1
@@ -1339,8 +1339,13 @@ nfs4_map_atomic_open_share(struct nfs_server *server,if (!(server->caps &NFS_CAP_ATOMIC_OPEN_V1 )) goto out;/* Want no delegation if we're using O_DIRECT */ -if (openflags &O_DIRECT ) +if (openflags &O_DIRECT ) { res |=NFS4_SHARE_WANT_NO_DELEG ; + goto out; + } +/* res |= NFS4_SHARE_WANT_NO_PREFERENCE; */ +if (server->caps &NFS_CAP_DELEGTIME ) + res |=NFS4_SHARE_WANT_DELEG_TIMESTAMPS ; out:return res; }
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 11/19 NFSv4: Delegreturn must set m/atime when they are delegated
From: Trond Myklebust <[email protected]>
If the atime or mtime attributes were delegated, then we need to propagate their new values back to the server when returning the delegation.
--- fs/nfs/delegation.c | 9 +++++---- fs/nfs/delegation.h | 4 +++- fs/nfs/nfs4proc.c | 27 ++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-)
fs/nfs/delegation.c +5 -4
@@ -266,7 +266,9 @@ void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred, } } -static int nfs_do_return_delegation (struct inode *inode,struct nfs_delegation *delegation,int issync) +static int nfs_do_return_delegation (struct inode *inode, +struct nfs_delegation *delegation, +int issync) {const struct cred *cred;int res =0 ;
@@ -275,9 +277,8 @@ static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *spin_lock (&delegation->lock); cred =get_cred (delegation->cred);spin_unlock (&delegation->lock); - res =nfs4_proc_delegreturn (inode, cred, - &delegation->stateid, - issync); + res =nfs4_proc_delegreturn (inode, cred, &delegation->stateid, + delegation, issync);put_cred (cred); }return res;
fs/nfs/delegation.h +3 -1
@@ -70,7 +70,9 @@ void nfs_test_expired_all_delegations(struct nfs_client *clp);void nfs_reap_expired_delegations (struct nfs_client *clp);/* NFSv4 delegation-related procedures */ -int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred,const nfs4_stateid *stateid,int issync); +int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred, +const nfs4_stateid *stateid, +struct nfs_delegation *delegation,int issync);int nfs4_open_delegation_recall (struct nfs_open_context *ctx,struct nfs4_state *state,const nfs4_stateid *stateid);int nfs4_lock_delegation_recall (struct file_lock *fl,struct nfs4_state *state,const nfs4_stateid *stateid);bool nfs4_copy_delegation_stateid (struct inode *inode,fmode_t flags,nfs4_stateid *dst,const struct cred **cred);
fs/nfs/nfs4proc.c +24 -3
@@ -6739,7 +6739,10 @@ static const struct rpc_call_ops nfs4_delegreturn_ops = { .rpc_release = nfs4_delegreturn_release, }; -static int _nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred,const nfs4_stateid *stateid,int issync) +static int _nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred, +const nfs4_stateid *stateid, +struct nfs_delegation *delegation, +int issync) {struct nfs4_delegreturndata *data;struct nfs_server *server =NFS_SERVER (inode);
@@ -6791,12 +6794,27 @@ static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, } } +if (delegation && +test_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags)) { +if (delegation->type &FMODE_READ ) { + data->sattr.atime =inode_get_atime (inode); + data->sattr.atime_set = true; + } +if (delegation->type &FMODE_WRITE ) { + data->sattr.mtime =inode_get_mtime (inode); + data->sattr.mtime_set = true; + } + data->args.sattr_args = &data->sattr; + data->res.sattr_res = true; + } +if (!data->inode)nfs4_init_sequence (&data->args.seq_args, &data->res.seq_res,1 ,1 );else nfs4_init_sequence (&data->args.seq_args, &data->res.seq_res,1 ,0 ); + task_setup_data.callback_data = data; msg.rpc_argp = &data->args; msg.rpc_resp = &data->res;
@@ -6814,13 +6832,16 @@ static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred,return status; } -int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred,const nfs4_stateid *stateid,int issync) +int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred, +const nfs4_stateid *stateid, +struct nfs_delegation *delegation,int issync) {struct nfs_server *server =NFS_SERVER (inode);struct nfs4_exception exception = { };int err; do { - err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); + err = _nfs4_proc_delegreturn(inode, cred, stateid, + delegation, issync); trace_nfs4_delegreturn(inode, stateid, err); switch (err) { case -NFS4ERR_STALE_STATEID:
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 12/19 NFSv4: Fix up delegated attributes in nfs_setattr
From: Trond Myklebust <[email protected]>
nfs_setattr calls nfs_update_inode() directly, so we have to reset the m/ctime there.
--- fs/nfs/inode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
fs/nfs/inode.c +25 -0
@@ -606,6 +606,28 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) }EXPORT_SYMBOL_GPL (nfs_fhget); +static void +nfs_fattr_fixup_delegated (struct inode *inode,struct nfs_fattr *fattr) +{ +unsigned long cache_validity =NFS_I (inode)->cache_validity; + +if (nfs_have_delegated_mtime (inode)) { +if (!(cache_validity &NFS_INO_INVALID_CTIME )) + fattr->valid &= ~(NFS_ATTR_FATTR_PRECTIME | +NFS_ATTR_FATTR_CTIME ); + +if (!(cache_validity &NFS_INO_INVALID_MTIME )) + fattr->valid &= ~(NFS_ATTR_FATTR_PREMTIME | +NFS_ATTR_FATTR_MTIME ); + +if (!(cache_validity &NFS_INO_INVALID_ATIME )) + fattr->valid &= ~NFS_ATTR_FATTR_ATIME ; + }else if (nfs_have_delegated_atime (inode)) { +if (!(cache_validity &NFS_INO_INVALID_ATIME )) + fattr->valid &= ~NFS_ATTR_FATTR_ATIME ; + } +} +void nfs_update_delegated_atime (struct inode *inode) {spin_lock (&inode->i_lock);
@@ -2164,6 +2186,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)*/ nfsi->read_cache_jiffies = fattr->time_start; +/* Fix up any delegated attributes in the struct nfs_fattr */ +nfs_fattr_fixup_delegated (inode, fattr); + save_cache_validity = nfsi->cache_validity; nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ATIME
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 13/19 NFSv4: Don't request atime/mtime/size if they are delegated to us
From: Trond Myklebust <[email protected]>
If the timestamps and size are delegated to the client, then it is authoritative w.r.t. their values, so we should not be requesting those values from the server.
Note that this allows us to optimise away most GETATTR calls if the only changes to the attributes are the result of read() or write().
--- fs/nfs/nfs4proc.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
fs/nfs/nfs4proc.c +17 -3
@@ -310,6 +310,18 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, dst[1 ] &= ~FATTR4_WORD1_MODE ;if (!(cache_validity &NFS_INO_INVALID_OTHER )) dst[1 ] &= ~(FATTR4_WORD1_OWNER |FATTR4_WORD1_OWNER_GROUP ); + +if (nfs_have_delegated_mtime (inode)) { +if (!(cache_validity &NFS_INO_INVALID_ATIME )) + dst[1 ] &= ~FATTR4_WORD1_TIME_ACCESS ; +if (!(cache_validity &NFS_INO_INVALID_MTIME )) + dst[1 ] &= ~FATTR4_WORD1_TIME_MODIFY ; +if (!(cache_validity &NFS_INO_INVALID_CTIME )) + dst[1 ] &= ~FATTR4_WORD1_TIME_METADATA ; + }else if (nfs_have_delegated_atime (inode)) { +if (!(cache_validity &NFS_INO_INVALID_ATIME )) + dst[1 ] &= ~FATTR4_WORD1_TIME_ACCESS ; + } } static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
@@ -3414,7 +3426,8 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, .inode = inode, .stateid = &arg.stateid, }; -unsigned long adjust_flags =NFS_INO_INVALID_CHANGE ; +unsigned long adjust_flags =NFS_INO_INVALID_CHANGE | +NFS_INO_INVALID_CTIME ;int err;if (sattr->ia_valid & (ATTR_MODE |ATTR_KILL_SUID |ATTR_KILL_SGID ))
@@ -4978,8 +4991,9 @@ static int _nfs4_proc_link(struct inode *inode, struct inode *dir, const struct goto out;nfs4_inode_make_writeable (inode); -nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, res.fattr->label), inode, -NFS_INO_INVALID_CHANGE ); +nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, res.fattr->label), + inode, +NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_CTIME ); status =nfs4_call_sync (server->client, server, &msg, &arg.seq_args, &res.seq_res,1 );if (!status) { nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start,
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 14/19 NFSv4: Add support for the FATTR4_OPEN_ARGUMENTS attribute
From: Trond Myklebust <[email protected]>
Query the server for the OPEN arguments that it supports so that we can figure out which extensions we can use.
--- fs/nfs/nfs4proc.c | 20 ++++++++++++++++++-- fs/nfs/nfs4xdr.c | 24 ++++++++++++++++++++++++ include/linux/nfs4.h | 2 ++ include/linux/nfs_xdr.h | 9 +++++++++ 4 files changed, 53 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +18 -2
@@ -3885,11 +3885,14 @@ static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)#define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)#define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) -#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_TIME_DELEG_MODIFY - 1UL) +#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_OPEN_ARGUMENTS - 1UL)static int _nfs4_server_capabilities (struct nfs_server *server,struct nfs_fh *fhandle) { -u32 bitmask[3 ] = {}, minorversion = server->nfs_client->cl_minorversion; +u32 minorversion = server->nfs_client->cl_minorversion; +u32 bitmask[3 ] = { + [0 ] =FATTR4_WORD0_SUPPORTED_ATTRS , + };struct nfs4_server_caps_arg args = { .fhandle = fhandle, .bitmask = bitmask,
@@ -3915,6 +3918,14 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f status =nfs4_call_sync (server->client, server, &msg, &args.seq_args, &res.seq_res,0 );if (status ==0 ) { + bitmask[0 ] = (FATTR4_WORD0_SUPPORTED_ATTRS | +FATTR4_WORD0_FH_EXPIRE_TYPE | +FATTR4_WORD0_LINK_SUPPORT | +FATTR4_WORD0_SYMLINK_SUPPORT | +FATTR4_WORD0_ACLSUPPORT | +FATTR4_WORD0_CASE_INSENSITIVE | +FATTR4_WORD0_CASE_PRESERVING ) & + res.attr_bitmask[0 ];/* Sanity check the server answers */ switch (minorversion) {case 0 :
@@ -3923,9 +3934,14 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fbreak ;case 1 : res.attr_bitmask[2 ] &=FATTR4_WORD2_NFS41_MASK ; + bitmask[2 ] =FATTR4_WORD2_SUPPATTR_EXCLCREAT & + res.attr_bitmask[2 ];break ;case 2 : res.attr_bitmask[2 ] &=FATTR4_WORD2_NFS42_MASK ; + bitmask[2 ] = (FATTR4_WORD2_SUPPATTR_EXCLCREAT | +FATTR4_WORD2_OPEN_ARGUMENTS ) & + res.attr_bitmask[2 ]; }memcpy (server->attr_bitmask, res.attr_bitmask,sizeof (server->attr_bitmask)); server->caps &= ~(NFS_CAP_ACLS | NFS_CAP_HARDLINKS |
fs/nfs/nfs4xdr.c +24 -0
@@ -4337,6 +4337,28 @@ static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,return 0 ; } +static int decode_attr_open_arguments (struct xdr_stream *xdr,uint32_t *bitmap, +struct nfs4_open_caps *res) +{ +memset (res,0 ,sizeof (*res)); +if (unlikely (bitmap[2 ] & (FATTR4_WORD2_OPEN_ARGUMENTS -1U ))) +return -EIO ; +if (likely (bitmap[2 ] &FATTR4_WORD2_OPEN_ARGUMENTS )) { +if (decode_bitmap4 (xdr, res->oa_share_access,ARRAY_SIZE (res->oa_share_access)) <0 ) +return -EIO ; +if (decode_bitmap4 (xdr, res->oa_share_deny,ARRAY_SIZE (res->oa_share_deny)) <0 ) +return -EIO ; +if (decode_bitmap4 (xdr, res->oa_share_access_want,ARRAY_SIZE (res->oa_share_access_want)) <0 ) +return -EIO ; +if (decode_bitmap4 (xdr, res->oa_open_claim,ARRAY_SIZE (res->oa_open_claim)) <0 ) +return -EIO ; +if (decode_bitmap4 (xdr, res->oa_createmode,ARRAY_SIZE (res->oa_createmode)) <0 ) +return -EIO ; + bitmap[2 ] &= ~FATTR4_WORD2_OPEN_ARGUMENTS ; + } +return 0 ; +} +static int verify_attr_len (struct xdr_stream *xdr,unsigned int savep,uint32_t attrlen) {unsigned int attrwords =XDR_QUADLEN (attrlen);
@@ -4511,6 +4533,8 @@ static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_reif ((status =decode_attr_exclcreat_supported (xdr, bitmap, res->exclcreat_bitmask)) !=0 ) goto xdr_error; +if ((status =decode_attr_open_arguments (xdr, bitmap, &res->open_caps)) !=0 ) + goto xdr_error; status =verify_attr_len (xdr, savep, attrlen); xdr_error:dprintk ("%s: xdr returned %d!\n" , __func__, -status);
include/linux/nfs4.h +2 -0
@@ -512,6 +512,7 @@ enum {enum {FATTR4_TIME_DELEG_ACCESS =84 ,FATTR4_TIME_DELEG_MODIFY =85 , +FATTR4_OPEN_ARGUMENTS =86 , };/*
@@ -595,6 +596,7 @@ enum {#define FATTR4_WORD2_XATTR_SUPPORT BIT(FATTR4_XATTR_SUPPORT - 64)#define FATTR4_WORD2_TIME_DELEG_ACCESS BIT(FATTR4_TIME_DELEG_ACCESS - 64)#define FATTR4_WORD2_TIME_DELEG_MODIFY BIT(FATTR4_TIME_DELEG_MODIFY - 64) +#define FATTR4_WORD2_OPEN_ARGUMENTS BIT(FATTR4_OPEN_ARGUMENTS - 64)/* MDS threshold bitmap bits */ #define THRESHOLD_RD (1UL << 0)
include/linux/nfs_xdr.h +9 -0
@@ -1213,6 +1213,14 @@ struct nfs4_statfs_res {struct nfs_fsstat *fsstat; }; +struct nfs4_open_caps { +u32 oa_share_access[1 ]; +u32 oa_share_deny[1 ]; +u32 oa_share_access_want[1 ]; +u32 oa_open_claim[1 ]; +u32 oa_createmode[1 ]; +}; +struct nfs4_server_caps_arg {struct nfs4_sequence_args seq_args;struct nfs_fh *fhandle;
@@ -1229,6 +1237,7 @@ struct nfs4_server_caps_res {u32 fh_expire_type;u32 case_insensitive;u32 case_preserving; +struct nfs4_open_caps open_caps; };#define NFS4_PATHNAME_MAXCOMPONENTS 512
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 15/19 NFSv4: Detect support for OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION
From: Trond Myklebust <[email protected]>
If the server supports the NFSv4.2 protocol extension to optimise away returning a stateid when it returns a delegation, then we cache that information in another capability flag.
--- fs/nfs/nfs4proc.c | 4 ++++ include/linux/nfs_fs_sb.h | 1 + include/uapi/linux/nfs4.h | 2 ++ 3 files changed, 7 insertions(+)
fs/nfs/nfs4proc.c +4 -0
@@ -3990,6 +3990,10 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f sizeof(server->attr_bitmask)); server->attr_bitmask_nl[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; +if (res.open_caps.oa_share_access_want[0 ] & +NFS4_SHARE_WANT_OPEN_XOR_DELEGATION ) + server->caps |=NFS_CAP_OPEN_XOR ; +memcpy (server->cache_consistency_bitmask, res.attr_bitmask,sizeof (server->cache_consistency_bitmask)); server->cache_consistency_bitmask[0 ] &=FATTR4_WORD0_CHANGE |FATTR4_WORD0_SIZE ; server->cache_consistency_bitmask[1 ] &=FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ;
include/linux/nfs_fs_sb.h +1 -0
@@ -278,6 +278,7 @@ struct nfs_server {#define NFS_CAP_LGOPEN (1U << 5)#define NFS_CAP_CASE_INSENSITIVE (1U << 6)#define NFS_CAP_CASE_PRESERVING (1U << 7) +#define NFS_CAP_OPEN_XOR (1U << 12)#define NFS_CAP_DELEGTIME (1U << 13)#define NFS_CAP_POSIX_LOCK (1U << 14)#define NFS_CAP_UIDGID_NOMAP (1U << 15)
include/uapi/linux/nfs4.h +2 -0
@@ -46,6 +46,7 @@#define NFS4_OPEN_RESULT_CONFIRM 0x0002#define NFS4_OPEN_RESULT_LOCKTYPE_POSIX 0x0004#define NFS4_OPEN_RESULT_PRESERVE_UNLINKED 0x0008 +#define NFS4_OPEN_RESULT_NO_OPEN_STATEID 0x0010#define NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK 0x0020#define NFS4_SHARE_ACCESS_MASK 0x000F
@@ -70,6 +71,7 @@#define NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED 0x20000#define NFS4_SHARE_WANT_DELEG_TIMESTAMPS 0x100000 +#define NFS4_SHARE_WANT_OPEN_XOR_DELEGATION 0x200000#define NFS4_CDFC4_FORE 0x1#define NFS4_CDFC4_BACK 0x2
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 16/19 NFSv4: Add support for OPEN4_RESULT_NO_OPEN_STATEID
From: Trond Myklebust <[email protected]>
If the server returns a delegation stateid only, then don't try to set an open stateid.
--- fs/nfs/nfs4proc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/nfs/nfs4proc.c +12 -4
@@ -2035,8 +2035,11 @@ _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) data->o_arg.claim, &data->o_res.delegation); -if (!update_open_stateid (state, &data->o_res.stateid, -NULL , data->o_arg.fmode)) +if (!(data->o_res.rflags &NFS4_OPEN_RESULT_NO_OPEN_STATEID )) { +if (!update_open_stateid (state, &data->o_res.stateid, +NULL , data->o_arg.fmode)) +return ERR_PTR (-EAGAIN ); + }else if (!update_open_stateid (state,NULL ,NULL , data->o_arg.fmode))return ERR_PTR (-EAGAIN );refcount_inc (&state->count);
@@ -2105,8 +2108,13 @@ _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) data->o_arg.claim, &data->o_res.delegation); -if (!update_open_stateid (state, &data->o_res.stateid, -NULL , data->o_arg.fmode)) { +if (!(data->o_res.rflags &NFS4_OPEN_RESULT_NO_OPEN_STATEID )) { +if (!update_open_stateid (state, &data->o_res.stateid, +NULL , data->o_arg.fmode)) { +nfs4_put_open_state (state); + state =ERR_PTR (-EAGAIN ); + } + }else if (!update_open_stateid (state,NULL ,NULL , data->o_arg.fmode)) {nfs4_put_open_state (state); state =ERR_PTR (-EAGAIN ); }
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 17/19 NFSv4: Ask for a delegation or an open stateid in OPEN
From: Trond Myklebust <[email protected]>
Turn on the optimisation to allow the client to request that the server not return the open stateid when it returns a delegation.
--- fs/nfs/nfs4proc.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfs/nfs4proc.c +2 -0
@@ -1358,6 +1358,8 @@ nfs4_map_atomic_open_share(struct nfs_server *server,/* res |= NFS4_SHARE_WANT_NO_PREFERENCE; */ if (server->caps &NFS_CAP_DELEGTIME ) res |=NFS4_SHARE_WANT_DELEG_TIMESTAMPS ; +if (server->caps &NFS_CAP_OPEN_XOR ) + res |=NFS4_SHARE_WANT_OPEN_XOR_DELEGATION ; out:return res; }
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 18/19 Return the delegation when deleting sillyrenamed files
From: Lance Shelton <[email protected]>
Add a callback to return the delegation in order to allow generic NFS code to return the delegation when appropriate.
--- fs/nfs/nfs3proc.c | 8 ++++++++ fs/nfs/nfs4proc.c | 1 + fs/nfs/proc.c | 8 ++++++++ fs/nfs/unlink.c | 2 ++ include/linux/nfs_xdr.h | 1 + 5 files changed, 20 insertions(+)
fs/nfs/nfs3proc.c +8 -0
@@ -984,6 +984,13 @@ static int nfs3_have_delegation(struct inode *inode, fmode_t type, int flags)return 0 ; } +static int nfs3_return_delegation (struct inode *inode) +{ +if (S_ISREG (inode->i_mode)) +nfs_wb_all (inode); +return 0 ; +} +static const struct inode_operations nfs3_dir_inode_operations = { .create = nfs_create, .atomic_open = nfs_atomic_open_v23,
@@ -1062,6 +1069,7 @@ const struct nfs_rpc_ops nfs_v3_clientops = { .clear_acl_cache = forget_all_cached_acls, .close_context = nfs_close_context, .have_delegation = nfs3_have_delegation, + .return_delegation = nfs3_return_delegation, .alloc_client = nfs_alloc_client, .init_client = nfs_init_client, .free_client = nfs_free_client,
fs/nfs/nfs4proc.c +1 -0
@@ -10871,6 +10871,7 @@ const struct nfs_rpc_ops nfs_v4_clientops = { .close_context = nfs4_close_context, .open_context = nfs4_atomic_open, .have_delegation = nfs4_have_delegation, + .return_delegation = nfs4_inode_return_delegation, .alloc_client = nfs4_alloc_client, .init_client = nfs4_init_client, .free_client = nfs4_free_client,
fs/nfs/proc.c +8 -0
@@ -692,6 +692,13 @@ static int nfs_have_delegation(struct inode *inode, fmode_t type, int flags)return 0 ; } +static int nfs_return_delegation (struct inode *inode) +{ +if (S_ISREG (inode->i_mode)) +nfs_wb_all (inode); +return 0 ; +} +static const struct inode_operations nfs_dir_inode_operations = { .create = nfs_create, .lookup = nfs_lookup,
@@ -757,6 +764,7 @@ const struct nfs_rpc_ops nfs_v2_clientops = { .lock_check_bounds = nfs_lock_check_bounds, .close_context = nfs_close_context, .have_delegation = nfs_have_delegation, + .return_delegation = nfs_return_delegation, .alloc_client = nfs_alloc_client, .init_client = nfs_init_client, .free_client = nfs_free_client,
fs/nfs/unlink.c +2 -0
@@ -232,6 +232,8 @@ nfs_complete_unlink(struct dentry *dentry, struct inode *inode) dentry->d_fsdata =NULL ;spin_unlock (&dentry->d_lock); +NFS_PROTO (inode)->return_delegation (inode); +if (NFS_STALE (inode) || !nfs_call_unlink (dentry, inode, data))nfs_free_unlinkdata (data); }
include/linux/nfs_xdr.h +1 -0
@@ -1840,6 +1840,7 @@ struct nfs_rpc_ops {struct iattr *iattr, int *);int (*have_delegation)(struct inode *,fmode_t ,int ); +int (*return_delegation)(struct inode *);struct nfs_client *(*alloc_client) (const struct nfs_client_initdata *);struct nfs_client *(*init_client) (struct nfs_client *,const struct nfs_client_initdata *);
Signature · 1 line
2.45.2
[email protected]
maintainerPATCH v2 19/19 NFSv4: Don't send delegation-related share access modes to CLOSE
From: Trond Myklebust <[email protected]>
When we set the new share access modes for CLOSE in nfs4_close_prepare(). we should only set a mode of NFS4_SHARE_ACCESS_READ, NFS4_SHARE_ACCESS_WRITE or NFS4_SHARE_ACCESS_BOTH. Currently, we may also be passing in the NFSv4.1 share modes for controlling delegation requests in OPEN, which is wrong.
--- fs/nfs/nfs4proc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
fs/nfs/nfs4proc.c +11 -4
@@ -1333,8 +1333,7 @@ static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) }static u32 -nfs4_map_atomic_open_share (struct nfs_server *server, -fmode_t fmode,int openflags) +nfs4_fmode_to_share_access (fmode_t fmode) {u32 res =0 ;
@@ -1348,6 +1347,15 @@ nfs4_map_atomic_open_share(struct nfs_server *server,case FMODE_READ |FMODE_WRITE : res =NFS4_SHARE_ACCESS_BOTH ; } +return res; +} + +static u32 +nfs4_map_atomic_open_share (struct nfs_server *server, +fmode_t fmode,int openflags) +{ +u32 res =nfs4_fmode_to_share_access (fmode); +if (!(server->caps &NFS_CAP_ATOMIC_OPEN_V1 )) goto out;/* Want no delegation if we're using O_DIRECT */
@@ -3753,8 +3761,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) } calldata->arg.share_access = -nfs4_map_atomic_open_share (NFS_SERVER (inode), - calldata->arg.fmode,0 ); +nfs4_fmode_to_share_access (calldata->arg.fmode);if (calldata->res.fattr ==NULL ) calldata->arg.bitmask =NULL ;
Signature · 1 line
2.45.2
Jeff Layton
maintainerRe: [PATCH v2 11/19] NFSv4: Delegreturn must set m/atime when they are delegated
In reply to [email protected]Quoted 75 lines · On Sun, 2024-06-16 at 21:21 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
If the atime or mtime attributes were delegated, then we need to propagate their new values back to the server when returning the delegation.
Signed-off-by Trond Myklebust <[email protected]>Signed-off-by Lance Shelton <[email protected]>Reviewed-by Jeff Layton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/delegation.c | 9 +++++---- fs/nfs/delegation.h | 4 +++- fs/nfs/nfs4proc.c | 27 ++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-)fs/nfs/delegation.c +5
-4@@ -266,7 +266,9 @@ void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred, } } -static int nfs_do_return_delegation (struct inode *inode,struct nfs_delegation *delegation,int issync) +static int nfs_do_return_delegation (struct inode *inode, +struct nfs_delegation *delegation, +int issync) {const struct cred *cred;int res =0 ;@@ -275,9 +277,8 @@ static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *spin_lock (&delegation->lock); cred =get_cred (delegation->cred);spin_unlock (&delegation->lock); - res =nfs4_proc_delegreturn (inode, cred, - &delegation->stateid, - issync); + res =nfs4_proc_delegreturn (inode, cred, &delegation->stateid, + delegation, issync);put_cred (cred); }return res;fs/nfs/delegation.h +3
-1@@ -70,7 +70,9 @@ void nfs_test_expired_all_delegations(struct nfs_client *clp);void nfs_reap_expired_delegations (struct nfs_client *clp);/* NFSv4 delegation-related procedures */ -int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred,const nfs4_stateid *stateid,int issync); +int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred, +const nfs4_stateid *stateid, +struct nfs_delegation *delegation,int issync);int nfs4_open_delegation_recall (struct nfs_open_context *ctx,struct nfs4_state *state,const nfs4_stateid *stateid);int nfs4_lock_delegation_recall (struct file_lock *fl,struct nfs4_state *state,const nfs4_stateid *stateid);bool nfs4_copy_delegation_stateid (struct inode *inode,fmode_t flags,nfs4_stateid *dst,const struct cred **cred);fs/nfs/nfs4proc.c +4
-1@@ -6739,7 +6739,10 @@ static const struct rpc_call_ops nfs4_delegreturn_ops = { .rpc_release = nfs4_delegreturn_release, }; -static int _nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred,const nfs4_stateid *stateid,int issync) +static int _nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred, +const nfs4_stateid *stateid, +struct nfs_delegation *delegation, +int issync) {struct nfs4_delegreturndata *data;struct nfs_server *server =NFS_SERVER (inode);
fs/nfs/nfs4proc.c static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, · line 6800
Quoted 7 lines
fs/nfs/nfs4proc.c +4
-0@@ -6791,12 +6794,27 @@ static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, } } +if (delegation && +test_bit (NFS_DELEGATION_DELEGTIME , &delegation->flags)) { +if (delegation->type &FMODE_READ ) { + data->sattr.atime =inode_get_atime (inode);
I'm seeing the client try to set bad atimes with newly-created files. To reproduce, I just created a file with vim on an NFS mount and wrote a few bytes to it and then closed it.
The client gets a WRITE_DELEG_ATTRS delegation, and after I close the file it does a SETATTR before the DELEGRETURN for TIME_DELEG_ACCESS and TIME_DELEG_MODIFY. The mtime looks fine, but the atime is ~1500 seconds after the epoch.
pcap is attached.
Cheers,
Quoted 39 lines
fs/nfs/nfs4proc.c +16
-2+ data->sattr.atime_set = true; + } +if (delegation->type &FMODE_WRITE ) { + data->sattr.mtime =inode_get_mtime (inode); + data->sattr.mtime_set = true; + } + data->args.sattr_args = &data->sattr; + data->res.sattr_res = true; + } +if (!data->inode)nfs4_init_sequence (&data->args.seq_args, &data->res.seq_res,1 ,1 );else nfs4_init_sequence (&data->args.seq_args, &data->res.seq_res,1 ,0 ); + task_setup_data.callback_data = data; msg.rpc_argp = &data->args; msg.rpc_resp = &data->res;@@ -6814,13 +6832,16 @@ static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred,return status; } -int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred,const nfs4_stateid *stateid,int issync) +int nfs4_proc_delegreturn (struct inode *inode,const struct cred *cred, +const nfs4_stateid *stateid, +struct nfs_delegation *delegation,int issync) {struct nfs_server *server =NFS_SERVER (inode);struct nfs4_exception exception = { };int err; do { - err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); + err = _nfs4_proc_delegreturn(inode, cred, stateid, + delegation, issync); trace_nfs4_delegreturn(inode, stateid, err); switch (err) { case -NFS4ERR_STALE_STATEID:
Signature · 1 line
Jeff Layton <[email protected]>
[email protected]
maintainerPATCH 1/1 NFS: Fix attribute delegation behaviour on exclusive create
From: Trond Myklebust <[email protected]>
When the client does an exclusive create and the server decides to store the verifier in the timestamps, a SETATTR is subsequently sent to fix up those timestamps. When that is the case, suppress the exceptions for attribute delegations in nfs4_bitmap_copy_adjust().
--- fs/nfs/nfs4proc.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/nfs/nfs4proc.c +4 -0
@@ -3452,6 +3452,10 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, adjust_flags |=NFS_INO_INVALID_MODE ;if (sattr->ia_valid & (ATTR_UID |ATTR_GID )) adjust_flags |=NFS_INO_INVALID_OTHER ; +if (sattr->ia_valid &ATTR_ATIME ) + adjust_flags |=NFS_INO_INVALID_ATIME ; +if (sattr->ia_valid &ATTR_MTIME ) + adjust_flags |=NFS_INO_INVALID_MTIME ; do { nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label),
Signature · 1 line
2.47.0
Re: [PATCH] NFS: Fix attribute delegation behaviour on exclusive create
Quoted 18 lines · On Wed, 2024-10-23 at 09:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
When the client does an exclusive create and the server decides to store the verifier in the timestamps, a SETATTR is subsequently sent to fix up those timestamps. When that is the case, suppress the exceptions for attribute delegations in
nfs4_bitmap_copy_adjust().Fixes 32215c1f893a ("NFSv4: Don't request atime/mtime/size if they are delegated to us")Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4proc.c | 4 ++++ 1 file changed, 4 insertions(+)fs/nfs/nfs4proc.c +0
-0
fs/nfs/nfs4proc.c static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, · line 3461
Quoted 10 lines
fs/nfs/nfs4proc.c +4
-0@@ -3452,6 +3452,10 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, adjust_flags |=NFS_INO_INVALID_MODE ;if (sattr->ia_valid & (ATTR_UID |ATTR_GID )) adjust_flags |=NFS_INO_INVALID_OTHER ; +if (sattr->ia_valid &ATTR_ATIME ) + adjust_flags |=NFS_INO_INVALID_ATIME ; +if (sattr->ia_valid &ATTR_MTIME ) + adjust_flags |=NFS_INO_INVALID_MTIME ; do { nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label),
Hi Trond,
Is it possible to share some numbers of some benchmarks that demonstrate advantages of this patch series? like this many getatts/other ops without patches and this many with?
Quoted 82 lines · On Sun, Jun 16, 2024 at 9:25 PM <[email protected]> wrote:
From: Trond Myklebust <[email protected]>
Now that https://datatracker.ietf.org/doc/draft-ietf-nfsv4-delstid/ is mostly done with the review process, it is time to look at pushing the client implementation that we've been working on upstream.
The following patch series therefore adds support for the NFSv4.2 extension to
OP_OPENto allow the client to request that the server return either an open stateid or a delegation instead of always sending the open stateid whether or not a delegation is returned. This allows us to optimise away CLOSE, and hence makes small or cached file access significantly more efficient.It also adds support for attribute delegations, which allow the client to manage the atime and mtime, and simply inform the server at file close time what the values should be. This means that most GETATTR operations to retrieve the atime/mtime values while the file is under I/O can be optimised away.
Finally, we also add support for the detection mechanism that allows the client to determine whether or not the server supports the above functionality.
v2:
- Fix issues when compiling withoutCONFIG_NFS_V4
- Update "NFSv4: Fix up delegated attributes innfs_setattr" to fix regressions pointed out by Anna Schumaker
- Squash commits "NFSv4: Ask for a delegation or an open stateid in OPEN" and "Return the delegation when deleting the sillyrenamed file" as suggested by Jeff Layton
- Add "NFSv4: Don't send delegation-related share access modes to CLOSE"Lance Shelton (1):
Return the delegation when deleting sillyrenamed filesTrond Myklebust (18):
NFSv4: Clean up open delegation return structure
NFSv4: Refactornfs4_opendata_check_deleg()
NFSv4: Add new attribute delegation definitions
NFSv4: Plumb in XDR support for the new delegation-only setattr op
NFSv4: AddCB_GETATTRsupport for delegated attributes
NFSv4: Add a flags argument to the 'have_delegation' callback
NFSv4: Add support for delegated atime and mtime attributes
NFSv4: Add recovery of attribute delegations
NFSv4: Add a capability for delegated attributes
NFSv4: Enable attribute delegations
NFSv4: Delegreturn must set m/atime when they are delegated
NFSv4: Fix up delegated attributes innfs_setattr
NFSv4: Don't request atime/mtime/size if they are delegated to us
NFSv4: Add support for theFATTR4_OPEN_ARGUMENTSattribute
NFSv4: Detect support forOPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION
NFSv4: Add support forOPEN4_RESULT_NO_OPEN_STATEID
NFSv4: Ask for a delegation or an open stateid in OPEN
NFSv4: Don't send delegation-related share access modes to CLOSEfs/nfs/callback.h | 5 +- fs/nfs/callback_proc.c | 14 ++- fs/nfs/callback_xdr.c | 39 +++++- fs/nfs/delegation.c | 67 ++++++---- fs/nfs/delegation.h | 45 ++++++- fs/nfs/dir.c | 2 +- fs/nfs/file.c | 4 +- fs/nfs/inode.c | 86 +++++++++++-- fs/nfs/nfs3proc.c | 10 +- fs/nfs/nfs4proc.c | 248 ++++++++++++++++++++++++++++---------- fs/nfs/nfs4xdr.c | 131 +++++++++++++++----- fs/nfs/proc.c | 10 +- fs/nfs/read.c | 3 + fs/nfs/unlink.c | 2 + fs/nfs/write.c | 11 +- include/linux/nfs4.h | 11 ++ include/linux/nfs_fs_sb.h | 2 + include/linux/nfs_xdr.h | 45 ++++++- include/uapi/linux/nfs4.h | 4 + 19 files changed, 589 insertions(+), 150 deletions(-)--
2.45.2