Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'nfs-for-7.0-1' of git://git.linux-nfs.org/projects/anna/linux-nfs

Pull NFS client updates from Anna Schumaker:
"New Features:
- Use an LRU list for returning unused delegations
- Introduce a KConfig option to disable NFS v4.0 and make NFS v4.1
the default

Bugfixes:
- NFS/localio:
- Handle short writes by retrying
- Prevent direct reclaim recursion into NFS via nfs_writepages
- Use GFP_NOIO and non-memreclaim workqueue in nfs_local_commit
- Remove -EAGAIN handling in nfs_local_doio()
- pNFS: fix a missing wake up while waiting on NFS_LAYOUT_DRAIN
- fs/nfs: Fix a readdir slow-start regression
- SUNRPC: fix gss_auth kref leak in gss_alloc_msg error path

Other cleanups and improvements:
- A few other NFS/localio cleanups
- Various other delegation handling cleanups from Christoph
- Unify security_inode_listsecurity() calls
- Improvements to NFSv4 lease handling
- Clean up SUNRPC *_debug fields when CONFIG_SUNRPC_DEBUG is not set"

* tag 'nfs-for-7.0-1' of git://git.linux-nfs.org/projects/anna/linux-nfs: (60 commits)
SUNRPC: fix gss_auth kref leak in gss_alloc_msg error path
nfs: nfs4proc: Convert comma to semicolon
SUNRPC: Change list definition method
sunrpc: rpc_debug and others are defined even if CONFIG_SUNRPC_DEBUG unset
NFSv4: limit lease period in nfs4_set_lease_period()
NFSv4: pass lease period in seconds to nfs4_set_lease_period()
nfs: unify security_inode_listsecurity() calls
fs/nfs: Fix readdir slow-start regression
pNFS: fix a missing wake up while waiting on NFS_LAYOUT_DRAIN
NFS: fix delayed delegation return handling
NFS: simplify error handling in nfs_end_delegation_return
NFS: fold nfs_abort_delegation_return into nfs_end_delegation_return
NFS: remove the delegation == NULL check in nfs_end_delegation_return
NFS: use bool for the issync argument to nfs_end_delegation_return
NFS: return void from ->return_delegation
NFS: return void from nfs4_inode_make_writeable
NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4
NFS: Add a way to disable NFS v4.0 via KConfig
NFS: Move sequence slot operations into minorversion operations
NFS: Pass a struct nfs_client to nfs4_init_sequence()
...

+1374 -1558
+13 -13
fs/nfs/Kconfig
··· 78 78 tristate "NFS client support for NFS version 4" 79 79 depends on NFS_FS 80 80 select KEYS 81 + select SUNRPC_BACKCHANNEL 81 82 help 82 - This option enables support for version 4 of the NFS protocol 83 - (RFC 3530) in the kernel's NFS client. 83 + This option enables support for version 4.1 of the NFS protocol 84 + (RFC 5661) in the kernel's NFS client. 84 85 85 86 To mount NFS servers using NFSv4, you also need to install user 86 87 space programs which can be found in the Linux nfs-utils package, ··· 97 96 help 98 97 This option enables swapon to work on files located on NFS mounts. 99 98 100 - config NFS_V4_1 101 - bool "NFS client support for NFSv4.1" 99 + config NFS_V4_0 100 + bool "NFS client support for NFSv4.0" 102 101 depends on NFS_V4 103 - select SUNRPC_BACKCHANNEL 104 102 help 105 - This option enables support for minor version 1 of the NFSv4 protocol 106 - (RFC 5661) in the kernel's NFS client. 103 + This option enables support for minor version 0 of the NFSv4 protocol 104 + (RFC 3530) in the kernel's NFS client. 107 105 108 106 If unsure, say N. 109 107 110 108 config NFS_V4_2 111 109 bool "NFS client support for NFSv4.2" 112 - depends on NFS_V4_1 110 + depends on NFS_V4 113 111 help 114 112 This option enables support for minor version 2 of the NFSv4 protocol 115 113 in the kernel's NFS client. ··· 117 117 118 118 config PNFS_FILE_LAYOUT 119 119 tristate 120 - depends on NFS_V4_1 120 + depends on NFS_V4 121 121 default NFS_V4 122 122 123 123 config PNFS_BLOCK 124 124 tristate 125 - depends on NFS_V4_1 && BLK_DEV_DM 125 + depends on NFS_V4 && BLK_DEV_DM 126 126 default NFS_V4 127 127 128 128 config PNFS_FLEXFILE_LAYOUT 129 129 tristate 130 - depends on NFS_V4_1 130 + depends on NFS_V4 131 131 default NFS_V4 132 132 133 133 config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN 134 134 string "NFSv4.1 Implementation ID Domain" 135 - depends on NFS_V4_1 135 + depends on NFS_V4 136 136 default "kernel.org" 137 137 help 138 138 This option defines the domain portion of the implementation ID that ··· 144 144 145 145 config NFS_V4_1_MIGRATION 146 146 bool "NFSv4.1 client support for migration" 147 - depends on NFS_V4_1 147 + depends on NFS_V4 148 148 default n 149 149 help 150 150 This option makes the NFS client advertise to NFSv4.1 servers that
+2 -2
fs/nfs/Makefile
··· 27 27 nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o \ 28 28 delegation.o nfs4idmap.o callback.o callback_xdr.o callback_proc.o \ 29 29 nfs4namespace.o nfs4getroot.o nfs4client.o nfs4session.o \ 30 - dns_resolve.o nfs4trace.o 30 + dns_resolve.o nfs4trace.o pnfs.o pnfs_dev.o pnfs_nfs.o 31 31 nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o 32 32 nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o 33 - nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o pnfs_nfs.o 33 + nfsv4-$(CONFIG_NFS_V4_0) += nfs40client.o nfs40proc.o 34 34 nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o nfs42xattr.o 35 35 36 36 obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/
+1 -12
fs/nfs/callback.c
··· 87 87 return 0; 88 88 } 89 89 90 - #if defined(CONFIG_NFS_V4_1) 91 90 static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt, 92 91 struct svc_serv *serv) 93 92 { ··· 97 98 */ 98 99 xprt->bc_serv = serv; 99 100 } 100 - #else 101 - static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt, 102 - struct svc_serv *serv) 103 - { 104 - } 105 - #endif /* CONFIG_NFS_V4_1 */ 106 101 107 102 static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt, 108 103 struct svc_serv *serv) ··· 150 157 } 151 158 152 159 ret = 0; 153 - if (!IS_ENABLED(CONFIG_NFS_V4_1) || minorversion == 0) 160 + if (minorversion == 0) 154 161 ret = nfs4_callback_up_net(serv, net); 155 162 else if (xprt->ops->bc_setup) 156 163 set_bc_enabled(serv); ··· 191 198 cb_info->users); 192 199 193 200 threadfn = nfs4_callback_svc; 194 - #if !defined(CONFIG_NFS_V4_1) 195 - if (minorversion) 196 - return ERR_PTR(-ENOTSUPP); 197 - #endif 198 201 serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, 199 202 threadfn); 200 203 if (!serv) {
-3
fs/nfs/callback.h
··· 65 65 uint32_t truncate; 66 66 }; 67 67 68 - #if defined(CONFIG_NFS_V4_1) 69 - 70 68 struct referring_call { 71 69 uint32_t rc_sequenceid; 72 70 uint32_t rc_slotid; ··· 166 168 167 169 extern __be32 nfs4_callback_notify_lock(void *argp, void *resp, 168 170 struct cb_process_state *cps); 169 - #endif /* CONFIG_NFS_V4_1 */ 170 171 #ifdef CONFIG_NFS_V4_2 171 172 struct cb_offloadargs { 172 173 struct nfs_fh coa_fh;
+9 -7
fs/nfs/callback_proc.c
··· 51 51 -ntohl(res->status)); 52 52 goto out; 53 53 } 54 - rcu_read_lock(); 54 + 55 55 delegation = nfs4_get_valid_delegation(inode); 56 - if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0) 56 + if (!delegation) 57 57 goto out_iput; 58 - res->size = i_size_read(inode); 58 + if ((delegation->type & FMODE_WRITE) == 0) { 59 + nfs_put_delegation(delegation); 60 + goto out_iput; 61 + } 59 62 res->change_attr = delegation->change_attr; 63 + nfs_put_delegation(delegation); 64 + 65 + res->size = i_size_read(inode); 60 66 if (nfs_have_writebacks(inode)) 61 67 res->change_attr++; 62 68 res->atime = inode_get_atime(inode); ··· 77 71 FATTR4_WORD2_TIME_DELEG_MODIFY) & args->bitmap[2]; 78 72 res->status = 0; 79 73 out_iput: 80 - rcu_read_unlock(); 81 74 trace_nfs4_cb_getattr(cps->clp, &args->fh, inode, -ntohl(res->status)); 82 75 nfs_iput_and_deactive(inode); 83 76 out: ··· 125 120 dprintk("%s: exit with status = %d\n", __func__, ntohl(res)); 126 121 return res; 127 122 } 128 - 129 - #if defined(CONFIG_NFS_V4_1) 130 123 131 124 /* 132 125 * Lookup a layout inode by stateid ··· 696 693 697 694 return htonl(NFS4_OK); 698 695 } 699 - #endif /* CONFIG_NFS_V4_1 */ 700 696 #ifdef CONFIG_NFS_V4_2 701 697 static void nfs4_copy_cb_args(struct nfs4_copy_state *cp_state, 702 698 struct cb_offloadargs *args)
-21
fs/nfs/callback_xdr.c
··· 30 30 (2 + 2 + 3 + 3 + 3 + 3 + 3) * 4) 31 31 #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 32 32 33 - #if defined(CONFIG_NFS_V4_1) 34 33 #define CB_OP_LAYOUTRECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 35 34 #define CB_OP_DEVICENOTIFY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 36 35 #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ ··· 38 39 #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 39 40 #define CB_OP_RECALLSLOT_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 40 41 #define CB_OP_NOTIFY_LOCK_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 41 - #endif /* CONFIG_NFS_V4_1 */ 42 42 #ifdef CONFIG_NFS_V4_2 43 43 #define CB_OP_OFFLOAD_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) 44 44 #endif /* CONFIG_NFS_V4_2 */ ··· 203 205 return decode_fh(xdr, &args->fh); 204 206 } 205 207 206 - #if defined(CONFIG_NFS_V4_1) 207 208 static __be32 decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 208 209 { 209 210 stateid->type = NFS4_LAYOUT_STATEID_TYPE; ··· 518 521 return decode_lockowner(xdr, args); 519 522 } 520 523 521 - #endif /* CONFIG_NFS_V4_1 */ 522 524 #ifdef CONFIG_NFS_V4_2 523 525 static __be32 decode_write_response(struct xdr_stream *xdr, 524 526 struct cb_offloadargs *args) ··· 743 747 return status; 744 748 } 745 749 746 - #if defined(CONFIG_NFS_V4_1) 747 - 748 750 static __be32 encode_sessionid(struct xdr_stream *xdr, 749 751 const struct nfs4_sessionid *sid) 750 752 { ··· 839 845 cps->slot = NULL; 840 846 } 841 847 } 842 - 843 - #else /* CONFIG_NFS_V4_1 */ 844 - 845 - static __be32 846 - preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) 847 - { 848 - return htonl(NFS4ERR_MINOR_VERS_MISMATCH); 849 - } 850 - 851 - static void nfs4_cb_free_slot(struct cb_process_state *cps) 852 - { 853 - } 854 - #endif /* CONFIG_NFS_V4_1 */ 855 848 856 849 #ifdef CONFIG_NFS_V4_2 857 850 static __be32 ··· 1032 1051 .decode_args = decode_recall_args, 1033 1052 .res_maxsize = CB_OP_RECALL_RES_MAXSZ, 1034 1053 }, 1035 - #if defined(CONFIG_NFS_V4_1) 1036 1054 [OP_CB_LAYOUTRECALL] = { 1037 1055 .process_op = nfs4_callback_layoutrecall, 1038 1056 .decode_args = decode_layoutrecall_args, ··· 1063 1083 .decode_args = decode_notify_lock_args, 1064 1084 .res_maxsize = CB_OP_NOTIFY_LOCK_RES_MAXSZ, 1065 1085 }, 1066 - #endif /* CONFIG_NFS_V4_1 */ 1067 1086 #ifdef CONFIG_NFS_V4_2 1068 1087 [OP_CB_OFFLOAD] = { 1069 1088 .process_op = nfs4_callback_offload,
+7 -5
fs/nfs/client.c
··· 1060 1060 INIT_LIST_HEAD(&server->client_link); 1061 1061 INIT_LIST_HEAD(&server->master_link); 1062 1062 INIT_LIST_HEAD(&server->delegations); 1063 + spin_lock_init(&server->delegations_lock); 1064 + INIT_LIST_HEAD(&server->delegations_return); 1065 + INIT_LIST_HEAD(&server->delegations_lru); 1066 + INIT_LIST_HEAD(&server->delegations_delayed); 1063 1067 INIT_LIST_HEAD(&server->layouts); 1064 1068 INIT_LIST_HEAD(&server->state_owners_lru); 1065 1069 INIT_LIST_HEAD(&server->ss_copies); ··· 1267 1263 INIT_LIST_HEAD(&nn->nfs_volume_list); 1268 1264 #if IS_ENABLED(CONFIG_NFS_V4) 1269 1265 idr_init(&nn->cb_ident_idr); 1270 - #endif 1271 - #if IS_ENABLED(CONFIG_NFS_V4_1) 1272 1266 INIT_LIST_HEAD(&nn->nfs4_data_server_cache); 1273 1267 spin_lock_init(&nn->nfs4_data_server_lock); 1274 - #endif 1268 + #endif /* CONFIG_NFS_V4 */ 1275 1269 spin_lock_init(&nn->nfs_client_lock); 1276 1270 nn->boot_time = ktime_get_real(); 1277 1271 memset(&nn->rpcstats, 0, sizeof(nn->rpcstats)); ··· 1286 1284 nfs_cleanup_cb_ident_idr(net); 1287 1285 WARN_ON_ONCE(!list_empty(&nn->nfs_client_list)); 1288 1286 WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list)); 1289 - #if IS_ENABLED(CONFIG_NFS_V4_1) 1287 + #if IS_ENABLED(CONFIG_NFS_V4) 1290 1288 WARN_ON_ONCE(!list_empty(&nn->nfs4_data_server_cache)); 1291 - #endif 1289 + #endif /* CONFIG_NFS_V4 */ 1292 1290 } 1293 1291 1294 1292 #ifdef CONFIG_PROC_FS
+299 -305
fs/nfs/delegation.c
··· 52 52 static void nfs_mark_delegation_revoked(struct nfs_server *server, 53 53 struct nfs_delegation *delegation) 54 54 { 55 - if (!test_and_set_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { 56 - delegation->stateid.type = NFS4_INVALID_STATEID_TYPE; 57 - atomic_long_dec(&server->nr_active_delegations); 58 - if (!test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) 59 - nfs_clear_verifier_delegated(delegation->inode); 55 + bool put_ref = false; 56 + 57 + if (test_and_set_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) 58 + return; 59 + 60 + delegation->stateid.type = NFS4_INVALID_STATEID_TYPE; 61 + atomic_long_dec(&server->nr_active_delegations); 62 + if (!test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) 63 + nfs_clear_verifier_delegated(delegation->inode); 64 + 65 + spin_lock(&server->delegations_lock); 66 + if (!list_empty(&delegation->entry)) { 67 + list_del_init(&delegation->entry); 68 + put_ref = true; 60 69 } 70 + spin_unlock(&server->delegations_lock); 71 + 72 + if (put_ref) 73 + nfs_put_delegation(delegation); 61 74 } 62 75 63 - static struct nfs_delegation *nfs_get_delegation(struct nfs_delegation *delegation) 64 - { 65 - refcount_inc(&delegation->refcount); 66 - return delegation; 67 - } 68 - 69 - static void nfs_put_delegation(struct nfs_delegation *delegation) 76 + void nfs_put_delegation(struct nfs_delegation *delegation) 70 77 { 71 78 if (refcount_dec_and_test(&delegation->refcount)) 72 79 __nfs_free_delegation(delegation); 73 - } 74 - 75 - static void nfs_free_delegation(struct nfs_server *server, 76 - struct nfs_delegation *delegation) 77 - { 78 - nfs_mark_delegation_revoked(server, delegation); 79 - nfs_put_delegation(delegation); 80 80 } 81 81 82 82 /** ··· 92 92 static void nfs_mark_return_delegation(struct nfs_server *server, 93 93 struct nfs_delegation *delegation) 94 94 { 95 - set_bit(NFS_DELEGATION_RETURN, &delegation->flags); 96 - set_bit(NFS4SERV_DELEGRETURN, &server->delegation_flags); 95 + spin_lock(&server->delegations_lock); 96 + if (list_empty(&delegation->entry)) 97 + refcount_inc(&delegation->refcount); 98 + list_move_tail(&delegation->entry, &server->delegations_return); 99 + spin_unlock(&server->delegations_lock); 100 + 97 101 set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); 98 102 } 99 103 ··· 115 111 { 116 112 struct nfs_delegation *delegation; 117 113 114 + rcu_read_lock(); 118 115 delegation = rcu_dereference(NFS_I(inode)->delegation); 119 - if (nfs4_is_valid_delegation(delegation, 0)) 120 - return delegation; 121 - return NULL; 116 + if (!nfs4_is_valid_delegation(delegation, 0) || 117 + !refcount_inc_not_zero(&delegation->refcount)) 118 + delegation = NULL; 119 + rcu_read_unlock(); 120 + 121 + return delegation; 122 122 } 123 123 124 124 static int nfs4_do_check_delegation(struct inode *inode, fmode_t type, ··· 316 308 spin_lock(&delegation->lock); 317 309 if (delegation->inode != NULL) 318 310 inode = igrab(delegation->inode); 319 - if (!inode) 320 - set_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags); 321 311 spin_unlock(&delegation->lock); 322 312 return inode; 323 - } 324 - 325 - static struct nfs_delegation * 326 - nfs_start_delegation_return_locked(struct nfs_inode *nfsi) 327 - { 328 - struct nfs_delegation *ret = NULL; 329 - struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation); 330 - 331 - if (delegation == NULL) 332 - goto out; 333 - spin_lock(&delegation->lock); 334 - if (delegation->inode && 335 - !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) { 336 - clear_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags); 337 - /* Refcount matched in nfs_end_delegation_return() */ 338 - ret = nfs_get_delegation(delegation); 339 - } 340 - spin_unlock(&delegation->lock); 341 - if (ret) 342 - nfs_clear_verifier_delegated(&nfsi->vfs_inode); 343 - out: 344 - return ret; 345 313 } 346 314 347 315 static struct nfs_delegation * 348 316 nfs_start_delegation_return(struct nfs_inode *nfsi) 349 317 { 350 318 struct nfs_delegation *delegation; 319 + bool return_now = false; 351 320 352 321 rcu_read_lock(); 353 - delegation = nfs_start_delegation_return_locked(nfsi); 322 + delegation = rcu_dereference(nfsi->delegation); 323 + if (!delegation || !refcount_inc_not_zero(&delegation->refcount)) { 324 + rcu_read_unlock(); 325 + return NULL; 326 + } 354 327 rcu_read_unlock(); 328 + 329 + spin_lock(&delegation->lock); 330 + if (delegation->inode && 331 + !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) 332 + return_now = true; 333 + spin_unlock(&delegation->lock); 334 + 335 + if (!return_now) { 336 + nfs_put_delegation(delegation); 337 + return NULL; 338 + } 339 + nfs_clear_verifier_delegated(&nfsi->vfs_inode); 355 340 return delegation; 356 341 } 357 342 358 - static void nfs_abort_delegation_return(struct nfs_delegation *delegation, 359 - struct nfs_server *server, int err) 360 - { 361 - spin_lock(&delegation->lock); 362 - clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags); 363 - if (err == -EAGAIN) { 364 - set_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags); 365 - set_bit(NFS4SERV_DELEGRETURN_DELAYED, 366 - &server->delegation_flags); 367 - set_bit(NFS4CLNT_DELEGRETURN_DELAYED, 368 - &server->nfs_client->cl_state); 369 - } 370 - spin_unlock(&delegation->lock); 371 - } 372 - 373 - static struct nfs_delegation * 374 - nfs_detach_delegation_locked(struct nfs_inode *nfsi, 343 + static bool 344 + nfs_detach_delegations_locked(struct nfs_inode *nfsi, 375 345 struct nfs_delegation *delegation, 376 346 struct nfs_client *clp) 377 347 { 378 - struct nfs_delegation *deleg_cur = 379 - rcu_dereference_protected(nfsi->delegation, 380 - lockdep_is_held(&clp->cl_lock)); 348 + lockdep_assert_held(&clp->cl_lock); 381 349 382 350 trace_nfs4_detach_delegation(&nfsi->vfs_inode, delegation->type); 383 - 384 - if (deleg_cur == NULL || delegation != deleg_cur) 385 - return NULL; 386 351 387 352 spin_lock(&delegation->lock); 388 353 if (!delegation->inode) { 389 354 spin_unlock(&delegation->lock); 390 - return NULL; 355 + return false; 391 356 } 392 357 hlist_del_init_rcu(&delegation->hash); 393 358 list_del_rcu(&delegation->super_list); ··· 368 387 rcu_assign_pointer(nfsi->delegation, NULL); 369 388 spin_unlock(&delegation->lock); 370 389 clear_bit(NFS_INO_REQ_DIR_DELEG, &nfsi->flags); 371 - return delegation; 390 + return true; 372 391 } 373 392 374 - static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi, 393 + static bool nfs_detach_delegation(struct nfs_inode *nfsi, 375 394 struct nfs_delegation *delegation, 376 395 struct nfs_server *server) 377 396 { 378 397 struct nfs_client *clp = server->nfs_client; 398 + struct nfs_delegation *deleg_cur; 399 + bool ret = false; 379 400 380 401 spin_lock(&clp->cl_lock); 381 - delegation = nfs_detach_delegation_locked(nfsi, delegation, clp); 402 + deleg_cur = rcu_dereference_protected(nfsi->delegation, 403 + lockdep_is_held(&clp->cl_lock)); 404 + if (delegation == deleg_cur) 405 + ret = nfs_detach_delegations_locked(nfsi, delegation, clp); 382 406 spin_unlock(&clp->cl_lock); 383 - return delegation; 384 - } 385 - 386 - static struct nfs_delegation * 387 - nfs_inode_detach_delegation(struct inode *inode) 388 - { 389 - struct nfs_inode *nfsi = NFS_I(inode); 390 - struct nfs_server *server = NFS_SERVER(inode); 391 - struct nfs_delegation *delegation; 392 - 393 - rcu_read_lock(); 394 - delegation = rcu_dereference(nfsi->delegation); 395 - if (delegation != NULL) 396 - delegation = nfs_detach_delegation(nfsi, delegation, server); 397 - rcu_read_unlock(); 398 - return delegation; 407 + return ret; 399 408 } 400 409 401 410 static void ··· 453 482 delegation->cred = get_cred(cred); 454 483 delegation->inode = inode; 455 484 delegation->flags = 1<<NFS_DELEGATION_REFERENCED; 485 + INIT_LIST_HEAD(&delegation->entry); 456 486 switch (deleg_type) { 457 487 case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG: 458 488 case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG: ··· 496 524 &old_delegation->flags)) 497 525 goto out; 498 526 } 499 - freeme = nfs_detach_delegation_locked(nfsi, old_delegation, clp); 500 - if (freeme == NULL) 527 + if (!nfs_detach_delegations_locked(nfsi, old_delegation, clp)) 501 528 goto out; 529 + freeme = old_delegation; 502 530 add_new: 503 531 /* 504 532 * If we didn't revalidate the change attribute before setting ··· 536 564 __nfs_free_delegation(delegation); 537 565 if (freeme != NULL) { 538 566 nfs_do_return_delegation(inode, freeme, 0); 539 - nfs_free_delegation(server, freeme); 567 + nfs_mark_delegation_revoked(server, freeme); 568 + nfs_put_delegation(freeme); 540 569 } 541 570 return status; 542 571 } 543 572 544 573 /* 545 - * Basic procedure for returning a delegation to the server 574 + * Basic procedure for returning a delegation to the server. 575 + * If @issync is set, wait until state recovery has finished. Otherwise 576 + * return -EAGAIN to the caller if we need more time. 546 577 */ 547 - static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync) 578 + static int nfs_end_delegation_return(struct inode *inode, 579 + struct nfs_delegation *delegation, bool issync) 548 580 { 549 581 struct nfs_server *server = NFS_SERVER(inode); 550 582 unsigned int mode = O_WRONLY | O_RDWR; 551 583 int err = 0; 552 - 553 - if (delegation == NULL) 554 - return 0; 555 584 556 585 /* Directory delegations don't require any state recovery */ 557 586 if (!S_ISREG(inode->i_mode)) ··· 568 595 break; 569 596 err = nfs_delegation_claim_opens(inode, &delegation->stateid, 570 597 delegation->type); 571 - if (!issync || err != -EAGAIN) 598 + if (!err) 572 599 break; 600 + if (err != -EAGAIN) 601 + goto abort; 602 + if (!issync) 603 + goto delay; 604 + 573 605 /* 574 606 * Guard against state recovery 575 607 */ 576 608 err = nfs4_wait_clnt_recover(server->nfs_client); 577 609 } 578 610 579 - if (err) { 580 - nfs_abort_delegation_return(delegation, server, err); 581 - goto out; 582 - } 583 - 584 611 out_return: 585 - err = nfs_do_return_delegation(inode, delegation, issync); 586 - out: 587 - /* Refcount matched in nfs_start_delegation_return_locked() */ 588 - nfs_put_delegation(delegation); 612 + return nfs_do_return_delegation(inode, delegation, issync); 613 + delay: 614 + spin_lock(&server->delegations_lock); 615 + if (list_empty(&delegation->entry)) 616 + refcount_inc(&delegation->refcount); 617 + list_move_tail(&delegation->entry, &server->delegations_return); 618 + spin_unlock(&server->delegations_lock); 619 + set_bit(NFS4CLNT_DELEGRETURN_DELAYED, &server->nfs_client->cl_state); 620 + abort: 621 + clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags); 589 622 return err; 590 623 } 591 624 592 - static bool nfs_delegation_need_return(struct nfs_delegation *delegation) 625 + static int nfs_return_one_delegation(struct nfs_server *server) 593 626 { 594 - bool ret = false; 627 + struct nfs_delegation *delegation; 628 + struct inode *inode; 629 + int err = 0; 595 630 596 - trace_nfs_delegation_need_return(delegation); 631 + spin_lock(&server->delegations_lock); 632 + delegation = list_first_entry_or_null(&server->delegations_return, 633 + struct nfs_delegation, entry); 634 + if (!delegation) { 635 + spin_unlock(&server->delegations_lock); 636 + return 0; /* no more delegations */ 637 + } 638 + list_del_init(&delegation->entry); 639 + spin_unlock(&server->delegations_lock); 597 640 598 - if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) 599 - ret = true; 600 - if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags) || 601 - test_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags) || 602 - test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) 603 - ret = false; 641 + spin_lock(&delegation->lock); 642 + inode = delegation->inode; 643 + if (!inode || !igrab(inode)) { 644 + spin_unlock(&delegation->lock); 645 + goto out_put_delegation; 646 + } 647 + if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || 648 + test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) { 649 + spin_unlock(&delegation->lock); 650 + goto out_put_inode; 651 + } 652 + spin_unlock(&delegation->lock); 604 653 605 - return ret; 654 + nfs_clear_verifier_delegated(inode); 655 + 656 + err = nfs_end_delegation_return(inode, delegation, false); 657 + 658 + out_put_inode: 659 + iput(inode); 660 + out_put_delegation: 661 + nfs_put_delegation(delegation); 662 + if (err) 663 + return err; 664 + return 1; /* keep going */ 606 665 } 607 666 608 667 static int nfs_server_return_marked_delegations(struct nfs_server *server, 609 668 void __always_unused *data) 610 669 { 611 - struct nfs_delegation *delegation; 612 - struct nfs_delegation *prev; 613 - struct inode *inode; 614 - struct inode *place_holder = NULL; 615 - struct nfs_delegation *place_holder_deleg = NULL; 616 - int err = 0; 670 + int err; 617 671 618 - if (!test_and_clear_bit(NFS4SERV_DELEGRETURN, 619 - &server->delegation_flags)) 620 - return 0; 621 - restart: 622 - /* 623 - * To avoid quadratic looping we hold a reference 624 - * to an inode place_holder. Each time we restart, we 625 - * list delegation in the server from the delegations 626 - * of that inode. 627 - * prev is an RCU-protected pointer to a delegation which 628 - * wasn't marked for return and might be a good choice for 629 - * the next place_holder. 630 - */ 631 - prev = NULL; 632 - delegation = NULL; 633 - rcu_read_lock(); 634 - if (place_holder) 635 - delegation = rcu_dereference(NFS_I(place_holder)->delegation); 636 - if (!delegation || delegation != place_holder_deleg) 637 - delegation = list_entry_rcu(server->delegations.next, 638 - struct nfs_delegation, super_list); 639 - list_for_each_entry_from_rcu(delegation, &server->delegations, super_list) { 640 - struct inode *to_put = NULL; 641 - 642 - if (test_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags)) 643 - continue; 644 - if (!nfs_delegation_need_return(delegation)) { 645 - if (nfs4_is_valid_delegation(delegation, 0)) 646 - prev = delegation; 647 - continue; 648 - } 649 - inode = nfs_delegation_grab_inode(delegation); 650 - if (inode == NULL) 651 - continue; 652 - 653 - if (prev) { 654 - struct inode *tmp = nfs_delegation_grab_inode(prev); 655 - if (tmp) { 656 - to_put = place_holder; 657 - place_holder = tmp; 658 - place_holder_deleg = prev; 659 - } 660 - } 661 - 662 - delegation = nfs_start_delegation_return_locked(NFS_I(inode)); 663 - rcu_read_unlock(); 664 - 665 - iput(to_put); 666 - 667 - err = nfs_end_delegation_return(inode, delegation, 0); 668 - iput(inode); 672 + while ((err = nfs_return_one_delegation(server)) > 0) 669 673 cond_resched(); 670 - if (!err) 671 - goto restart; 672 - set_bit(NFS4SERV_DELEGRETURN, &server->delegation_flags); 673 - set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); 674 - goto out; 675 - } 676 - rcu_read_unlock(); 677 - out: 678 - iput(place_holder); 679 674 return err; 675 + } 676 + 677 + static inline bool nfs_delegations_over_limit(struct nfs_server *server) 678 + { 679 + return !list_empty_careful(&server->delegations_lru) && 680 + atomic_long_read(&server->nr_active_delegations) > 681 + nfs_delegation_watermark; 682 + } 683 + 684 + static void nfs_delegations_return_from_lru(struct nfs_server *server) 685 + { 686 + struct nfs_delegation *d, *n; 687 + unsigned int pass = 0; 688 + bool moved = false; 689 + 690 + retry: 691 + spin_lock(&server->delegations_lock); 692 + list_for_each_entry_safe(d, n, &server->delegations_lru, entry) { 693 + if (!nfs_delegations_over_limit(server)) 694 + break; 695 + if (pass == 0 && test_bit(NFS_DELEGATION_REFERENCED, &d->flags)) 696 + continue; 697 + list_move_tail(&d->entry, &server->delegations_return); 698 + moved = true; 699 + } 700 + spin_unlock(&server->delegations_lock); 701 + 702 + /* 703 + * If we are still over the limit, try to reclaim referenced delegations 704 + * as well. 705 + */ 706 + if (pass == 0 && nfs_delegations_over_limit(server)) { 707 + pass++; 708 + goto retry; 709 + } 710 + 711 + if (moved) { 712 + set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); 713 + nfs4_schedule_state_manager(server->nfs_client); 714 + } 715 + } 716 + 717 + static void nfs_delegation_add_lru(struct nfs_server *server, 718 + struct nfs_delegation *delegation) 719 + { 720 + spin_lock(&server->delegations_lock); 721 + if (list_empty(&delegation->entry)) { 722 + list_add_tail(&delegation->entry, &server->delegations_lru); 723 + refcount_inc(&delegation->refcount); 724 + } 725 + spin_unlock(&server->delegations_lock); 726 + 727 + if (nfs_delegations_over_limit(server)) 728 + nfs_delegations_return_from_lru(server); 680 729 } 681 730 682 731 static bool nfs_server_clear_delayed_delegations(struct nfs_server *server) 683 732 { 684 - struct nfs_delegation *d; 685 733 bool ret = false; 686 734 687 - if (!test_and_clear_bit(NFS4SERV_DELEGRETURN_DELAYED, 688 - &server->delegation_flags)) 689 - goto out; 690 - list_for_each_entry_rcu (d, &server->delegations, super_list) { 691 - if (!test_bit(NFS_DELEGATION_RETURN_DELAYED, &d->flags)) 692 - continue; 693 - nfs_mark_return_delegation(server, d); 694 - clear_bit(NFS_DELEGATION_RETURN_DELAYED, &d->flags); 735 + if (list_empty_careful(&server->delegations_delayed)) 736 + return false; 737 + 738 + spin_lock(&server->delegations_lock); 739 + if (!list_empty(&server->delegations_delayed)) { 740 + list_splice_tail_init(&server->delegations_delayed, 741 + &server->delegations_return); 695 742 ret = true; 696 743 } 697 - out: 744 + spin_unlock(&server->delegations_lock); 745 + 698 746 return ret; 699 747 } 700 748 ··· 725 731 bool ret = false; 726 732 727 733 if (!test_and_clear_bit(NFS4CLNT_DELEGRETURN_DELAYED, &clp->cl_state)) 728 - goto out; 734 + return false; 735 + 729 736 rcu_read_lock(); 730 737 list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { 731 738 if (nfs_server_clear_delayed_delegations(server)) 732 739 ret = true; 733 740 } 734 741 rcu_read_unlock(); 735 - out: 742 + 743 + if (ret) 744 + set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); 736 745 return ret; 737 746 } 738 747 ··· 771 774 */ 772 775 void nfs_inode_evict_delegation(struct inode *inode) 773 776 { 777 + struct nfs_inode *nfsi = NFS_I(inode); 778 + struct nfs_server *server = NFS_SERVER(inode); 774 779 struct nfs_delegation *delegation; 775 780 776 - delegation = nfs_inode_detach_delegation(inode); 777 - if (delegation != NULL) { 778 - set_bit(NFS_DELEGATION_RETURNING, &delegation->flags); 779 - set_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags); 780 - nfs_do_return_delegation(inode, delegation, 1); 781 - nfs_free_delegation(NFS_SERVER(inode), delegation); 782 - } 781 + rcu_read_lock(); 782 + delegation = rcu_dereference(nfsi->delegation); 783 + if (delegation && !nfs_detach_delegation(nfsi, delegation, server)) 784 + delegation = NULL; 785 + rcu_read_unlock(); 786 + 787 + if (!delegation) 788 + return; 789 + 790 + set_bit(NFS_DELEGATION_RETURNING, &delegation->flags); 791 + nfs_do_return_delegation(inode, delegation, 1); 792 + nfs_mark_delegation_revoked(server, delegation); 793 + nfs_put_delegation(delegation); 783 794 } 784 795 785 796 /** ··· 800 795 * 801 796 * Returns zero on success, or a negative errno value. 802 797 */ 803 - int nfs4_inode_return_delegation(struct inode *inode) 798 + void nfs4_inode_return_delegation(struct inode *inode) 804 799 { 805 800 struct nfs_inode *nfsi = NFS_I(inode); 806 801 struct nfs_delegation *delegation; 807 802 808 803 delegation = nfs_start_delegation_return(nfsi); 809 - if (delegation != NULL) { 810 - /* Synchronous recall of any application leases */ 811 - break_lease(inode, O_WRONLY | O_RDWR); 812 - if (S_ISREG(inode->i_mode)) 813 - nfs_wb_all(inode); 814 - return nfs_end_delegation_return(inode, delegation, 1); 815 - } 816 - return 0; 804 + if (!delegation) 805 + return; 806 + 807 + /* Synchronous recall of any application leases */ 808 + break_lease(inode, O_WRONLY | O_RDWR); 809 + if (S_ISREG(inode->i_mode)) 810 + nfs_wb_all(inode); 811 + nfs_end_delegation_return(inode, delegation, true); 812 + nfs_put_delegation(delegation); 817 813 } 818 814 819 815 /** ··· 828 822 void nfs4_inode_set_return_delegation_on_close(struct inode *inode) 829 823 { 830 824 struct nfs_delegation *delegation; 831 - struct nfs_delegation *ret = NULL; 825 + bool return_now = false; 832 826 833 827 if (!inode) 834 828 return; 835 - rcu_read_lock(); 829 + 836 830 delegation = nfs4_get_valid_delegation(inode); 837 831 if (!delegation) 838 - goto out; 832 + return; 833 + 839 834 spin_lock(&delegation->lock); 840 835 if (!delegation->inode) 841 836 goto out_unlock; 842 837 if (list_empty(&NFS_I(inode)->open_files) && 843 - !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) { 844 - /* Refcount matched in nfs_end_delegation_return() */ 845 - ret = nfs_get_delegation(delegation); 846 - } else 838 + !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) 839 + return_now = true; 840 + else 847 841 set_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags); 848 842 out_unlock: 849 843 spin_unlock(&delegation->lock); 850 - if (ret) 844 + if (return_now) { 851 845 nfs_clear_verifier_delegated(inode); 852 - out: 853 - rcu_read_unlock(); 854 - nfs_end_delegation_return(inode, ret, 0); 846 + nfs_end_delegation_return(inode, delegation, false); 847 + } 848 + nfs_put_delegation(delegation); 855 849 } 856 850 857 851 /** ··· 863 857 */ 864 858 void nfs4_inode_return_delegation_on_close(struct inode *inode) 865 859 { 860 + struct nfs_server *server = NFS_SERVER(inode); 866 861 struct nfs_delegation *delegation; 867 - struct nfs_delegation *ret = NULL; 862 + bool return_now = false; 868 863 869 - if (!inode) 870 - return; 871 - rcu_read_lock(); 872 864 delegation = nfs4_get_valid_delegation(inode); 873 865 if (!delegation) 874 - goto out; 875 - if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) || 876 - atomic_long_read(&NFS_SERVER(inode)->nr_active_delegations) >= 877 - nfs_delegation_watermark) { 866 + return; 867 + 868 + if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) { 878 869 spin_lock(&delegation->lock); 879 870 if (delegation->inode && 880 871 list_empty(&NFS_I(inode)->open_files) && 881 872 !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) { 882 873 clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags); 883 - /* Refcount matched in nfs_end_delegation_return() */ 884 - ret = nfs_get_delegation(delegation); 874 + return_now = true; 885 875 } 886 876 spin_unlock(&delegation->lock); 887 - if (ret) 888 - nfs_clear_verifier_delegated(inode); 889 877 } 890 - out: 891 - rcu_read_unlock(); 892 - nfs_end_delegation_return(inode, ret, 0); 878 + 879 + if (return_now) { 880 + nfs_clear_verifier_delegated(inode); 881 + nfs_end_delegation_return(inode, delegation, false); 882 + } else { 883 + nfs_delegation_add_lru(server, delegation); 884 + } 885 + nfs_put_delegation(delegation); 893 886 } 894 887 895 888 /** ··· 896 891 * @inode: pointer to inode 897 892 * 898 893 * Make the inode writeable by returning the delegation if necessary 899 - * 900 - * Returns zero on success, or a negative errno value. 901 894 */ 902 - int nfs4_inode_make_writeable(struct inode *inode) 895 + void nfs4_inode_make_writeable(struct inode *inode) 903 896 { 904 897 struct nfs_delegation *delegation; 905 898 906 - rcu_read_lock(); 907 899 delegation = nfs4_get_valid_delegation(inode); 908 - if (delegation == NULL || 909 - (nfs4_has_session(NFS_SERVER(inode)->nfs_client) && 910 - (delegation->type & FMODE_WRITE))) { 911 - rcu_read_unlock(); 912 - return 0; 913 - } 914 - rcu_read_unlock(); 915 - return nfs4_inode_return_delegation(inode); 900 + if (!delegation) 901 + return; 902 + 903 + if (!nfs4_has_session(NFS_SERVER(inode)->nfs_client) || 904 + !(delegation->type & FMODE_WRITE)) 905 + nfs4_inode_return_delegation(inode); 906 + nfs_put_delegation(delegation); 916 907 } 917 908 918 909 static void ··· 917 916 { 918 917 struct inode *inode; 919 918 920 - if (test_bit(NFS_DELEGATION_RETURN, &delegation->flags) || 919 + if (!list_empty_careful(&server->delegations_return) || 921 920 test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) 922 921 return; 923 922 spin_lock(&delegation->lock); ··· 944 943 return ret; 945 944 } 946 945 947 - static void nfs_client_mark_return_all_delegations(struct nfs_client *clp) 948 - { 949 - struct nfs_server *server; 950 - 951 - rcu_read_lock(); 952 - list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) 953 - nfs_server_mark_return_all_delegations(server); 954 - rcu_read_unlock(); 955 - } 956 - 957 946 static void nfs_delegation_run_state_manager(struct nfs_client *clp) 958 947 { 959 948 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) ··· 957 966 */ 958 967 void nfs_expire_all_delegations(struct nfs_client *clp) 959 968 { 960 - nfs_client_mark_return_all_delegations(clp); 969 + struct nfs_server *server; 970 + 971 + rcu_read_lock(); 972 + list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) 973 + nfs_server_mark_return_all_delegations(server); 974 + rcu_read_unlock(); 975 + 961 976 nfs_delegation_run_state_manager(clp); 962 977 } 963 978 ··· 1003 1006 } 1004 1007 } 1005 1008 1006 - static void nfs_client_mark_return_unused_delegation_types(struct nfs_client *clp, 1007 - fmode_t flags) 1009 + void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags) 1008 1010 { 1009 1011 struct nfs_server *server; 1010 1012 ··· 1011 1015 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) 1012 1016 nfs_mark_return_unused_delegation_types(server, flags); 1013 1017 rcu_read_unlock(); 1018 + 1019 + nfs_delegation_run_state_manager(clp); 1014 1020 } 1015 1021 1016 1022 static void nfs_revoke_delegation(struct inode *inode, ··· 1109 1111 } 1110 1112 EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation); 1111 1113 1112 - /** 1113 - * nfs_expire_unused_delegation_types 1114 - * @clp: client to process 1115 - * @flags: delegation types to expire 1116 - * 1117 - */ 1118 - void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags) 1114 + static bool nfs_mark_return_unreferenced_delegations(struct nfs_server *server) 1119 1115 { 1120 - nfs_client_mark_return_unused_delegation_types(clp, flags); 1121 - nfs_delegation_run_state_manager(clp); 1122 - } 1116 + struct nfs_delegation *d, *n; 1117 + bool marked = false; 1123 1118 1124 - static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server) 1125 - { 1126 - struct nfs_delegation *delegation; 1127 - 1128 - list_for_each_entry_rcu(delegation, &server->delegations, super_list) { 1129 - if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags)) 1119 + spin_lock(&server->delegations_lock); 1120 + list_for_each_entry_safe(d, n, &server->delegations_lru, entry) { 1121 + if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &d->flags)) 1130 1122 continue; 1131 - nfs_mark_return_if_closed_delegation(server, delegation); 1123 + list_move_tail(&d->entry, &server->delegations_return); 1124 + marked = true; 1132 1125 } 1126 + spin_unlock(&server->delegations_lock); 1127 + 1128 + return marked; 1133 1129 } 1134 1130 1135 1131 /** ··· 1134 1142 void nfs_expire_unreferenced_delegations(struct nfs_client *clp) 1135 1143 { 1136 1144 struct nfs_server *server; 1145 + bool marked = false; 1137 1146 1138 1147 rcu_read_lock(); 1139 1148 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) 1140 - nfs_mark_return_unreferenced_delegations(server); 1149 + marked |= nfs_mark_return_unreferenced_delegations(server); 1141 1150 rcu_read_unlock(); 1142 1151 1143 - nfs_delegation_run_state_manager(clp); 1152 + if (marked) { 1153 + set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); 1154 + nfs4_schedule_state_manager(clp); 1155 + } 1144 1156 } 1145 1157 1146 1158 /** ··· 1161 1165 struct nfs_client *clp = server->nfs_client; 1162 1166 struct nfs_delegation *delegation; 1163 1167 1164 - rcu_read_lock(); 1165 1168 delegation = nfs4_get_valid_delegation(inode); 1166 - if (delegation == NULL) 1167 - goto out_enoent; 1169 + if (!delegation) 1170 + return -ENOENT; 1171 + 1168 1172 if (stateid != NULL && 1169 - !clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) 1170 - goto out_enoent; 1173 + !clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) { 1174 + nfs_put_delegation(delegation); 1175 + return -ENOENT; 1176 + } 1177 + 1171 1178 nfs_mark_return_delegation(server, delegation); 1172 - rcu_read_unlock(); 1179 + nfs_put_delegation(delegation); 1173 1180 1174 1181 /* If there are any application leases or delegations, recall them */ 1175 1182 break_lease(inode, O_WRONLY | O_RDWR | O_NONBLOCK); 1176 1183 1177 1184 nfs_delegation_run_state_manager(clp); 1178 1185 return 0; 1179 - out_enoent: 1180 - rcu_read_unlock(); 1181 - return -ENOENT; 1182 1186 } 1183 1187 1184 1188 static struct inode * ··· 1278 1282 restart: 1279 1283 rcu_read_lock(); 1280 1284 list_for_each_entry_rcu(delegation, &server->delegations, super_list) { 1281 - if (test_bit(NFS_DELEGATION_INODE_FREEING, 1282 - &delegation->flags) || 1283 - test_bit(NFS_DELEGATION_RETURNING, 1285 + if (test_bit(NFS_DELEGATION_RETURNING, 1284 1286 &delegation->flags) || 1285 1287 test_bit(NFS_DELEGATION_NEED_RECLAIM, 1286 1288 &delegation->flags) == 0) ··· 1286 1292 inode = nfs_delegation_grab_inode(delegation); 1287 1293 if (inode == NULL) 1288 1294 continue; 1289 - delegation = nfs_start_delegation_return_locked(NFS_I(inode)); 1295 + delegation = nfs_start_delegation_return(NFS_I(inode)); 1290 1296 rcu_read_unlock(); 1291 1297 if (delegation != NULL) { 1292 1298 if (nfs_detach_delegation(NFS_I(inode), delegation, 1293 - server) != NULL) 1294 - nfs_free_delegation(server, delegation); 1295 - /* Match nfs_start_delegation_return_locked */ 1299 + server)) { 1300 + nfs_mark_delegation_revoked(server, delegation); 1301 + nfs_put_delegation(delegation); 1302 + } 1303 + /* Match nfs_start_delegation_return */ 1296 1304 nfs_put_delegation(delegation); 1297 1305 } 1298 1306 iput(inode); ··· 1415 1419 restart: 1416 1420 rcu_read_lock(); 1417 1421 list_for_each_entry_rcu(delegation, &server->delegations, super_list) { 1418 - if (test_bit(NFS_DELEGATION_INODE_FREEING, 1419 - &delegation->flags) || 1420 - test_bit(NFS_DELEGATION_RETURNING, 1422 + if (test_bit(NFS_DELEGATION_RETURNING, 1421 1423 &delegation->flags) || 1422 1424 test_bit(NFS_DELEGATION_TEST_EXPIRED, 1423 1425 &delegation->flags) == 0 || ··· 1498 1504 1499 1505 rcu_read_lock(); 1500 1506 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) 1501 - if (!list_empty(&server->delegations)) { 1507 + if (atomic_long_read(&server->nr_active_delegations) > 0) { 1502 1508 ret = 1; 1503 1509 break; 1504 1510 }
+4 -5
fs/nfs/delegation.h
··· 26 26 unsigned long flags; 27 27 refcount_t refcount; 28 28 spinlock_t lock; 29 + struct list_head entry; 29 30 struct rcu_head rcu; 30 31 }; 31 32 32 33 enum { 33 34 NFS_DELEGATION_NEED_RECLAIM = 0, 34 - NFS_DELEGATION_RETURN, 35 35 NFS_DELEGATION_RETURN_IF_CLOSED, 36 36 NFS_DELEGATION_REFERENCED, 37 37 NFS_DELEGATION_RETURNING, 38 38 NFS_DELEGATION_REVOKED, 39 39 NFS_DELEGATION_TEST_EXPIRED, 40 - NFS_DELEGATION_INODE_FREEING, 41 - NFS_DELEGATION_RETURN_DELAYED, 42 40 NFS_DELEGATION_DELEGTIME, 43 41 }; 44 42 ··· 46 48 void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred, 47 49 fmode_t type, const nfs4_stateid *stateid, 48 50 unsigned long pagemod_limit, u32 deleg_type); 49 - int nfs4_inode_return_delegation(struct inode *inode); 51 + void nfs4_inode_return_delegation(struct inode *inode); 50 52 void nfs4_inode_return_delegation_on_close(struct inode *inode); 51 53 void nfs4_inode_set_return_delegation_on_close(struct inode *inode); 52 54 int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid); ··· 79 81 bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode); 80 82 81 83 struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode); 84 + void nfs_put_delegation(struct nfs_delegation *delegation); 82 85 void nfs_mark_delegation_referenced(struct nfs_delegation *delegation); 83 86 int nfs4_have_delegation(struct inode *inode, fmode_t type, int flags); 84 87 int nfs4_check_delegation(struct inode *inode, fmode_t type); 85 88 bool nfs4_delegation_flush_on_close(const struct inode *inode); 86 89 void nfs_inode_find_delegation_state_and_recover(struct inode *inode, 87 90 const nfs4_stateid *stateid); 88 - int nfs4_inode_make_writeable(struct inode *inode); 91 + void nfs4_inode_make_writeable(struct inode *inode); 89 92 90 93 #endif 91 94
+2 -2
fs/nfs/dir.c
··· 72 72 .free_folio = nfs_readdir_clear_array, 73 73 }; 74 74 75 - #define NFS_INIT_DTSIZE PAGE_SIZE 75 + #define NFS_INIT_DTSIZE SZ_64K 76 76 77 77 static struct nfs_open_dir_context * 78 78 alloc_nfs_open_dir_context(struct inode *dir) ··· 83 83 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); 84 84 if (ctx != NULL) { 85 85 ctx->attr_gencount = nfsi->attr_gencount; 86 - ctx->dtsize = NFS_INIT_DTSIZE; 86 + ctx->dtsize = min(NFS_SERVER(dir)->dtsize, NFS_INIT_DTSIZE); 87 87 spin_lock(&dir->i_lock); 88 88 if (list_empty(&nfsi->open_files) && 89 89 (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
+2 -1
fs/nfs/fs_context.c
··· 806 806 ctx->mount_server.version = result.uint_32; 807 807 break; 808 808 case Opt_minorversion: 809 - if (result.uint_32 > NFS4_MAX_MINOR_VERSION) 809 + if (result.uint_32 < NFS4_MIN_MINOR_VERSION || 810 + result.uint_32 > NFS4_MAX_MINOR_VERSION) 810 811 goto out_of_bounds; 811 812 ctx->minorversion = result.uint_32; 812 813 break;
+4 -11
fs/nfs/internal.h
··· 334 334 #if IS_ENABLED(CONFIG_NFS_V4) 335 335 extern int nfs4_decode_dirent(struct xdr_stream *, 336 336 struct nfs_entry *, bool); 337 - #endif 338 - #ifdef CONFIG_NFS_V4_1 339 337 extern const u32 nfs41_maxread_overhead; 340 338 extern const u32 nfs41_maxwrite_overhead; 341 339 extern const u32 nfs41_maxgetdevinfo_overhead; 342 - #endif 343 340 344 341 /* nfs4proc.c */ 345 - #if IS_ENABLED(CONFIG_NFS_V4) 346 342 extern const struct rpc_procinfo nfs4_procedures[]; 347 - #endif 343 + #endif /* CONFIG_NFS_V4 */ 348 344 349 345 #ifdef CONFIG_NFS_V4_SECURITY_LABEL 350 346 extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags); ··· 635 639 int nfs_filemap_write_and_wait_range(struct address_space *mapping, 636 640 loff_t lstart, loff_t lend); 637 641 638 - #ifdef CONFIG_NFS_V4_1 642 + #ifdef CONFIG_NFS_V4 639 643 static inline void 640 644 pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets, 641 645 unsigned int nbuckets) ··· 656 660 array->nbuckets); 657 661 rcu_read_unlock(); 658 662 } 659 - #else 663 + #else /* CONFIG_NFS_V4 */ 660 664 static inline 661 665 void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo) 662 666 { 663 667 } 664 - #endif 668 + #endif /* CONFIG_NFS_V4 */ 665 669 666 670 #ifdef CONFIG_MIGRATION 667 671 int nfs_migrate_folio(struct address_space *, struct folio *dst, ··· 735 739 /* nfs4proc.c */ 736 740 extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, 737 741 const struct nfs_client_initdata *); 738 - extern int nfs40_walk_client_list(struct nfs_client *clp, 739 - struct nfs_client **result, 740 - const struct cred *cred); 741 742 extern int nfs41_walk_client_list(struct nfs_client *clp, 742 743 struct nfs_client **result, 743 744 const struct cred *cred);
+82 -44
fs/nfs/localio.c
··· 58 58 static bool localio_enabled __read_mostly = true; 59 59 module_param(localio_enabled, bool, 0644); 60 60 61 + static void nfs_local_do_read(struct nfs_local_kiocb *iocb, 62 + const struct rpc_call_ops *call_ops); 63 + static void nfs_local_do_write(struct nfs_local_kiocb *iocb, 64 + const struct rpc_call_ops *call_ops); 65 + 61 66 static inline bool nfs_client_is_local(const struct nfs_client *clp) 62 67 { 63 68 return !!rcu_access_pointer(clp->cl_uuid.net); ··· 291 286 } 292 287 EXPORT_SYMBOL_GPL(nfs_local_open_fh); 293 288 289 + /* 290 + * Ensure all page cache allocations are done from GFP_NOFS context to 291 + * prevent direct reclaim recursion back into NFS via nfs_writepages. 292 + */ 293 + static void 294 + nfs_local_mapping_set_gfp_nofs_context(struct address_space *m) 295 + { 296 + gfp_t gfp_mask = mapping_gfp_mask(m); 297 + 298 + mapping_set_gfp_mask(m, (gfp_mask & ~(__GFP_FS))); 299 + } 300 + 294 301 static void 295 302 nfs_local_iocb_free(struct nfs_local_kiocb *iocb) 296 303 { ··· 327 310 return NULL; 328 311 } 329 312 313 + nfs_local_mapping_set_gfp_nofs_context(file->f_mapping); 330 314 init_sync_kiocb(&iocb->kiocb, file); 331 315 332 316 iocb->hdr = hdr; ··· 530 512 hdr->task.tk_start = ktime_get(); 531 513 } 532 514 533 - static bool 534 - nfs_local_pgio_done(struct nfs_local_kiocb *iocb, long status, bool force) 515 + static bool nfs_local_pgio_done(struct nfs_local_kiocb *iocb, long status) 535 516 { 536 517 struct nfs_pgio_header *hdr = iocb->hdr; 537 518 ··· 545 528 hdr->task.tk_status = status; 546 529 } 547 530 548 - if (force) 549 - return true; 550 - 551 531 BUG_ON(atomic_read(&iocb->n_iters) <= 0); 552 532 return atomic_dec_and_test(&iocb->n_iters); 553 533 } ··· 556 542 nfs_local_iocb_free(iocb); 557 543 } 558 544 559 - static void 560 - nfs_local_pgio_release(struct nfs_local_kiocb *iocb) 545 + static void nfs_local_pgio_restart(struct nfs_local_kiocb *iocb, 546 + struct nfs_pgio_header *hdr) 547 + { 548 + int status = 0; 549 + 550 + iocb->kiocb.ki_pos = hdr->args.offset; 551 + iocb->kiocb.ki_flags &= ~(IOCB_DSYNC | IOCB_SYNC | IOCB_DIRECT); 552 + iocb->kiocb.ki_complete = NULL; 553 + iocb->aio_complete_work = NULL; 554 + iocb->end_iter_index = -1; 555 + 556 + switch (hdr->rw_mode) { 557 + case FMODE_READ: 558 + nfs_local_iters_init(iocb, ITER_DEST); 559 + nfs_local_do_read(iocb, hdr->task.tk_ops); 560 + break; 561 + case FMODE_WRITE: 562 + nfs_local_iters_init(iocb, ITER_SOURCE); 563 + nfs_local_do_write(iocb, hdr->task.tk_ops); 564 + break; 565 + default: 566 + status = -EOPNOTSUPP; 567 + } 568 + 569 + if (unlikely(status != 0)) { 570 + nfs_local_iocb_release(iocb); 571 + hdr->task.tk_status = status; 572 + nfs_local_hdr_release(hdr, hdr->task.tk_ops); 573 + } 574 + } 575 + 576 + static void nfs_local_pgio_release(struct nfs_local_kiocb *iocb) 561 577 { 562 578 struct nfs_pgio_header *hdr = iocb->hdr; 579 + struct rpc_task *task = &hdr->task; 563 580 564 - nfs_local_iocb_release(iocb); 565 - nfs_local_hdr_release(hdr, hdr->task.tk_ops); 581 + task->tk_action = NULL; 582 + task->tk_ops->rpc_call_done(task, hdr); 583 + 584 + if (task->tk_action == NULL) { 585 + nfs_local_iocb_release(iocb); 586 + task->tk_ops->rpc_release(hdr); 587 + } else 588 + nfs_local_pgio_restart(iocb, hdr); 566 589 } 567 590 568 591 /* ··· 660 609 container_of(kiocb, struct nfs_local_kiocb, kiocb); 661 610 662 611 /* AIO completion of DIO read should always be last to complete */ 663 - if (unlikely(!nfs_local_pgio_done(iocb, ret, false))) 612 + if (unlikely(!nfs_local_pgio_done(iocb, ret))) 664 613 return; 665 614 666 615 nfs_local_pgio_aio_complete(iocb); /* Calls nfs_local_read_aio_complete_work */ ··· 692 641 if (status == -EIOCBQUEUED) 693 642 continue; 694 643 /* Break on completion, errors, or short reads */ 695 - if (nfs_local_pgio_done(iocb, status, false) || status < 0 || 644 + if (nfs_local_pgio_done(iocb, status) || status < 0 || 696 645 (size_t)status < iov_iter_count(&iocb->iters[i])) { 697 646 nfs_local_read_iocb_done(iocb); 698 647 break; ··· 700 649 } 701 650 } 702 651 703 - static int 704 - nfs_local_do_read(struct nfs_local_kiocb *iocb, 705 - const struct rpc_call_ops *call_ops) 652 + static void nfs_local_do_read(struct nfs_local_kiocb *iocb, 653 + const struct rpc_call_ops *call_ops) 706 654 { 707 655 struct nfs_pgio_header *hdr = iocb->hdr; 708 656 ··· 713 663 714 664 INIT_WORK(&iocb->work, nfs_local_call_read); 715 665 queue_work(nfslocaliod_workqueue, &iocb->work); 716 - 717 - return 0; 718 666 } 719 667 720 668 static void ··· 821 773 pr_info_ratelimited("nfs: Unexpected direct I/O write alignment failure\n"); 822 774 } 823 775 824 - /* Handle short writes as if they are ENOSPC */ 825 - status = hdr->res.count; 826 - if (status > 0 && status < hdr->args.count) { 827 - hdr->mds_offset += status; 828 - hdr->args.offset += status; 829 - hdr->args.pgbase += status; 830 - hdr->args.count -= status; 831 - nfs_set_pgio_error(hdr, -ENOSPC, hdr->args.offset); 832 - status = -ENOSPC; 833 - /* record -ENOSPC in terms of nfs_local_pgio_done */ 834 - (void) nfs_local_pgio_done(iocb, status, true); 835 - } 836 - if (hdr->task.tk_status < 0) 776 + if (status < 0) 837 777 nfs_reset_boot_verifier(hdr->inode); 838 778 } 839 779 ··· 846 810 container_of(kiocb, struct nfs_local_kiocb, kiocb); 847 811 848 812 /* AIO completion of DIO write should always be last to complete */ 849 - if (unlikely(!nfs_local_pgio_done(iocb, ret, false))) 813 + if (unlikely(!nfs_local_pgio_done(iocb, ret))) 850 814 return; 851 815 852 816 nfs_local_pgio_aio_complete(iocb); /* Calls nfs_local_write_aio_complete_work */ ··· 882 846 if (status == -EIOCBQUEUED) 883 847 continue; 884 848 /* Break on completion, errors, or short writes */ 885 - if (nfs_local_pgio_done(iocb, status, false) || status < 0 || 849 + if (nfs_local_pgio_done(iocb, status) || status < 0 || 886 850 (size_t)status < iov_iter_count(&iocb->iters[i])) { 887 851 nfs_local_write_iocb_done(iocb); 888 852 break; ··· 893 857 current->flags = old_flags; 894 858 } 895 859 896 - static int 897 - nfs_local_do_write(struct nfs_local_kiocb *iocb, 898 - const struct rpc_call_ops *call_ops) 860 + static void nfs_local_do_write(struct nfs_local_kiocb *iocb, 861 + const struct rpc_call_ops *call_ops) 899 862 { 900 863 struct nfs_pgio_header *hdr = iocb->hdr; 901 864 ··· 918 883 919 884 INIT_WORK(&iocb->work, nfs_local_call_write); 920 885 queue_work(nfslocaliod_workqueue, &iocb->work); 921 - 922 - return 0; 923 886 } 924 887 925 888 static struct nfs_local_kiocb * ··· 967 934 968 935 switch (hdr->rw_mode) { 969 936 case FMODE_READ: 970 - status = nfs_local_do_read(iocb, call_ops); 937 + nfs_local_do_read(iocb, call_ops); 971 938 break; 972 939 case FMODE_WRITE: 973 - status = nfs_local_do_write(iocb, call_ops); 940 + nfs_local_do_write(iocb, call_ops); 974 941 break; 975 942 default: 976 943 dprintk("%s: invalid mode: %d\n", __func__, ··· 978 945 status = -EOPNOTSUPP; 979 946 } 980 947 981 - if (status != 0) { 982 - if (status == -EAGAIN) 983 - nfs_localio_disable_client(clp); 948 + if (unlikely(status != 0)) { 984 949 nfs_local_iocb_release(iocb); 985 950 hdr->task.tk_status = status; 986 951 nfs_local_hdr_release(hdr, call_ops); ··· 1004 973 if (end < start) 1005 974 end = LLONG_MAX; 1006 975 } 976 + 977 + nfs_local_mapping_set_gfp_nofs_context(filp->f_mapping); 1007 978 1008 979 dprintk("%s: commit %llu - %llu\n", __func__, start, end); 1009 980 return vfs_fsync_range(filp, start, end, 0); ··· 1048 1015 static void 1049 1016 nfs_local_fsync_work(struct work_struct *work) 1050 1017 { 1018 + unsigned long old_flags = current->flags; 1051 1019 struct nfs_local_fsync_ctx *ctx; 1052 1020 int status; 1053 1021 1054 1022 ctx = container_of(work, struct nfs_local_fsync_ctx, work); 1023 + 1024 + current->flags |= PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO; 1055 1025 1056 1026 status = nfs_local_run_commit(nfs_to->nfsd_file_file(ctx->localio), 1057 1027 ctx->data); ··· 1062 1026 if (ctx->done != NULL) 1063 1027 complete(ctx->done); 1064 1028 nfs_local_fsync_ctx_free(ctx); 1029 + 1030 + current->flags = old_flags; 1065 1031 } 1066 1032 1067 1033 static struct nfs_local_fsync_ctx * ··· 1087 1049 { 1088 1050 struct nfs_local_fsync_ctx *ctx; 1089 1051 1090 - ctx = nfs_local_fsync_ctx_alloc(data, localio, GFP_KERNEL); 1052 + ctx = nfs_local_fsync_ctx_alloc(data, localio, GFP_NOIO); 1091 1053 if (!ctx) { 1092 1054 nfs_local_commit_done(data, -ENOMEM); 1093 1055 nfs_local_release_commit_data(localio, data, call_ops); ··· 1099 1061 if (how & FLUSH_SYNC) { 1100 1062 DECLARE_COMPLETION_ONSTACK(done); 1101 1063 ctx->done = &done; 1102 - queue_work(nfsiod_workqueue, &ctx->work); 1064 + queue_work(nfslocaliod_workqueue, &ctx->work); 1103 1065 wait_for_completion(&done); 1104 1066 } else 1105 - queue_work(nfsiod_workqueue, &ctx->work); 1067 + queue_work(nfslocaliod_workqueue, &ctx->work); 1106 1068 1107 1069 return 0; 1108 1070 }
+1 -3
fs/nfs/netns.h
··· 31 31 unsigned short nfs_callback_tcpport; 32 32 unsigned short nfs_callback_tcpport6; 33 33 int cb_users[NFS4_MAX_MINOR_VERSION + 1]; 34 - #endif /* CONFIG_NFS_V4 */ 35 - #if IS_ENABLED(CONFIG_NFS_V4_1) 36 34 struct list_head nfs4_data_server_cache; 37 35 spinlock_t nfs4_data_server_lock; 38 - #endif /* CONFIG_NFS_V4_1 */ 36 + #endif /* CONFIG_NFS_V4 */ 39 37 struct nfs_netns_client *nfs_client; 40 38 spinlock_t nfs_client_lock; 41 39 ktime_t boot_time;
+1 -2
fs/nfs/nfs3proc.c
··· 1027 1027 return 0; 1028 1028 } 1029 1029 1030 - static int nfs3_return_delegation(struct inode *inode) 1030 + static void nfs3_return_delegation(struct inode *inode) 1031 1031 { 1032 1032 if (S_ISREG(inode->i_mode)) 1033 1033 nfs_wb_all(inode); 1034 - return 0; 1035 1034 } 1036 1035 1037 1036 static const struct inode_operations nfs3_dir_inode_operations = {
+19
fs/nfs/nfs40.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __LINUX_FS_NFS_NFS4_0_H 3 + #define __LINUX_FS_NFS_NFS4_0_H 4 + 5 + 6 + /* nfs40client.c */ 7 + void nfs40_shutdown_client(struct nfs_client *); 8 + int nfs40_init_client(struct nfs_client *); 9 + void nfs40_handle_cb_pathdown(struct nfs_client *clp); 10 + 11 + /* nfs40proc.c */ 12 + extern const struct nfs4_minor_version_ops nfs_v4_0_minor_ops; 13 + 14 + /* nfs40state.c */ 15 + int nfs40_discover_server_trunking(struct nfs_client *clp, 16 + struct nfs_client **result, 17 + const struct cred *cred); 18 + 19 + #endif /* __LINUX_FS_NFS_NFS4_0_H */
+245
fs/nfs/nfs40client.c
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <linux/nfs_fs.h> 3 + #include "nfs4_fs.h" 4 + #include "nfs4session.h" 5 + #include "callback.h" 6 + #include "delegation.h" 7 + #include "internal.h" 8 + #include "netns.h" 9 + #include "nfs40.h" 10 + 11 + #define NFSDBG_FACILITY NFSDBG_CLIENT 12 + 13 + /* 14 + * SETCLIENTID just did a callback update with the callback ident in 15 + * "drop," but server trunking discovery claims "drop" and "keep" are 16 + * actually the same server. Swap the callback IDs so that "keep" 17 + * will continue to use the callback ident the server now knows about, 18 + * and so that "keep"'s original callback ident is destroyed when 19 + * "drop" is freed. 20 + */ 21 + static void nfs4_swap_callback_idents(struct nfs_client *keep, 22 + struct nfs_client *drop) 23 + { 24 + struct nfs_net *nn = net_generic(keep->cl_net, nfs_net_id); 25 + unsigned int save = keep->cl_cb_ident; 26 + 27 + if (keep->cl_cb_ident == drop->cl_cb_ident) 28 + return; 29 + 30 + dprintk("%s: keeping callback ident %u and dropping ident %u\n", 31 + __func__, keep->cl_cb_ident, drop->cl_cb_ident); 32 + 33 + spin_lock(&nn->nfs_client_lock); 34 + 35 + idr_replace(&nn->cb_ident_idr, keep, drop->cl_cb_ident); 36 + keep->cl_cb_ident = drop->cl_cb_ident; 37 + 38 + idr_replace(&nn->cb_ident_idr, drop, save); 39 + drop->cl_cb_ident = save; 40 + 41 + spin_unlock(&nn->nfs_client_lock); 42 + } 43 + 44 + static bool nfs4_same_verifier(nfs4_verifier *v1, nfs4_verifier *v2) 45 + { 46 + return memcmp(v1->data, v2->data, sizeof(v1->data)) == 0; 47 + } 48 + 49 + void nfs40_shutdown_client(struct nfs_client *clp) 50 + { 51 + if (clp->cl_slot_tbl) { 52 + nfs4_shutdown_slot_table(clp->cl_slot_tbl); 53 + kfree(clp->cl_slot_tbl); 54 + } 55 + } 56 + 57 + /** 58 + * nfs40_init_client - nfs_client initialization tasks for NFSv4.0 59 + * @clp: nfs_client to initialize 60 + * 61 + * Returns zero on success, or a negative errno if some error occurred. 62 + */ 63 + int nfs40_init_client(struct nfs_client *clp) 64 + { 65 + struct nfs4_slot_table *tbl; 66 + int ret; 67 + 68 + tbl = kzalloc(sizeof(*tbl), GFP_NOFS); 69 + if (tbl == NULL) 70 + return -ENOMEM; 71 + 72 + ret = nfs4_setup_slot_table(tbl, NFS4_MAX_SLOT_TABLE, 73 + "NFSv4.0 transport Slot table"); 74 + if (ret) { 75 + nfs4_shutdown_slot_table(tbl); 76 + kfree(tbl); 77 + return ret; 78 + } 79 + 80 + clp->cl_slot_tbl = tbl; 81 + return 0; 82 + } 83 + 84 + /* 85 + * nfs40_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN 86 + * @clp: client to process 87 + * 88 + * Set the NFS4CLNT_LEASE_EXPIRED state in order to force a 89 + * resend of the SETCLIENTID and hence re-establish the 90 + * callback channel. Then return all existing delegations. 91 + */ 92 + void nfs40_handle_cb_pathdown(struct nfs_client *clp) 93 + { 94 + set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 95 + nfs_expire_all_delegations(clp); 96 + dprintk("%s: handling CB_PATHDOWN recovery for server %s\n", __func__, 97 + clp->cl_hostname); 98 + } 99 + 100 + void nfs4_schedule_path_down_recovery(struct nfs_client *clp) 101 + { 102 + nfs40_handle_cb_pathdown(clp); 103 + nfs4_schedule_state_manager(clp); 104 + } 105 + 106 + /** 107 + * nfs40_walk_client_list - Find server that recognizes a client ID 108 + * 109 + * @new: nfs_client with client ID to test 110 + * @result: OUT: found nfs_client, or new 111 + * @cred: credential to use for trunking test 112 + * 113 + * Returns zero, a negative errno, or a negative NFS4ERR status. 114 + * If zero is returned, an nfs_client pointer is planted in "result." 115 + * 116 + * NB: nfs40_walk_client_list() relies on the new nfs_client being 117 + * the last nfs_client on the list. 118 + */ 119 + static int nfs40_walk_client_list(struct nfs_client *new, 120 + struct nfs_client **result, 121 + const struct cred *cred) 122 + { 123 + struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id); 124 + struct nfs_client *pos, *prev = NULL; 125 + struct nfs4_setclientid_res clid = { 126 + .clientid = new->cl_clientid, 127 + .confirm = new->cl_confirm, 128 + }; 129 + int status = -NFS4ERR_STALE_CLIENTID; 130 + 131 + spin_lock(&nn->nfs_client_lock); 132 + list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) { 133 + 134 + if (pos == new) 135 + goto found; 136 + 137 + status = nfs4_match_client(pos, new, &prev, nn); 138 + if (status < 0) 139 + goto out_unlock; 140 + if (status != 0) 141 + continue; 142 + /* 143 + * We just sent a new SETCLIENTID, which should have 144 + * caused the server to return a new cl_confirm. So if 145 + * cl_confirm is the same, then this is a different 146 + * server that just returned the same cl_confirm by 147 + * coincidence: 148 + */ 149 + if ((new != pos) && nfs4_same_verifier(&pos->cl_confirm, 150 + &new->cl_confirm)) 151 + continue; 152 + /* 153 + * But if the cl_confirm's are different, then the only 154 + * way that a SETCLIENTID_CONFIRM to pos can succeed is 155 + * if new and pos point to the same server: 156 + */ 157 + found: 158 + refcount_inc(&pos->cl_count); 159 + spin_unlock(&nn->nfs_client_lock); 160 + 161 + nfs_put_client(prev); 162 + prev = pos; 163 + 164 + status = nfs4_proc_setclientid_confirm(pos, &clid, cred); 165 + switch (status) { 166 + case -NFS4ERR_STALE_CLIENTID: 167 + break; 168 + case 0: 169 + nfs4_swap_callback_idents(pos, new); 170 + pos->cl_confirm = new->cl_confirm; 171 + nfs_mark_client_ready(pos, NFS_CS_READY); 172 + 173 + prev = NULL; 174 + *result = pos; 175 + goto out; 176 + case -ERESTARTSYS: 177 + case -ETIMEDOUT: 178 + /* The callback path may have been inadvertently 179 + * changed. Schedule recovery! 180 + */ 181 + nfs4_schedule_path_down_recovery(pos); 182 + goto out; 183 + default: 184 + goto out; 185 + } 186 + 187 + spin_lock(&nn->nfs_client_lock); 188 + } 189 + out_unlock: 190 + spin_unlock(&nn->nfs_client_lock); 191 + 192 + /* No match found. The server lost our clientid */ 193 + out: 194 + nfs_put_client(prev); 195 + return status; 196 + } 197 + 198 + /** 199 + * nfs40_discover_server_trunking - Detect server IP address trunking (mv0) 200 + * 201 + * @clp: nfs_client under test 202 + * @result: OUT: found nfs_client, or clp 203 + * @cred: credential to use for trunking test 204 + * 205 + * Returns zero, a negative errno, or a negative NFS4ERR status. 206 + * If zero is returned, an nfs_client pointer is planted in 207 + * "result". 208 + * 209 + * Note: The returned client may not yet be marked ready. 210 + */ 211 + int nfs40_discover_server_trunking(struct nfs_client *clp, 212 + struct nfs_client **result, 213 + const struct cred *cred) 214 + { 215 + struct nfs4_setclientid_res clid = { 216 + .clientid = clp->cl_clientid, 217 + .confirm = clp->cl_confirm, 218 + }; 219 + struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 220 + unsigned short port; 221 + int status; 222 + 223 + port = nn->nfs_callback_tcpport; 224 + if (clp->cl_addr.ss_family == AF_INET6) 225 + port = nn->nfs_callback_tcpport6; 226 + 227 + status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred, &clid); 228 + if (status != 0) 229 + goto out; 230 + clp->cl_clientid = clid.clientid; 231 + clp->cl_confirm = clid.confirm; 232 + 233 + status = nfs40_walk_client_list(clp, result, cred); 234 + if (status == 0) { 235 + /* Sustain the lease, even if it's empty. If the clientid4 236 + * goes stale it's of no use for trunking discovery. */ 237 + nfs4_schedule_state_renewal(*result); 238 + 239 + /* If the client state need to recover, do it. */ 240 + if (clp->cl_state) 241 + nfs4_schedule_state_manager(clp); 242 + } 243 + out: 244 + return status; 245 + }
+395
fs/nfs/nfs40proc.c
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <linux/nfs4.h> 3 + #include <linux/nfs.h> 4 + #include <linux/sunrpc/sched.h> 5 + #include <linux/nfs_fs.h> 6 + #include "internal.h" 7 + #include "nfs4_fs.h" 8 + #include "nfs40.h" 9 + #include "nfs4session.h" 10 + #include "nfs4trace.h" 11 + 12 + static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) 13 + { 14 + struct nfs4_call_sync_data *data = calldata; 15 + nfs4_setup_sequence(data->seq_server->nfs_client, 16 + data->seq_args, data->seq_res, task); 17 + } 18 + 19 + static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) 20 + { 21 + struct nfs4_call_sync_data *data = calldata; 22 + nfs4_sequence_done(task, data->seq_res); 23 + } 24 + 25 + static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) 26 + { 27 + struct nfs4_slot *slot = res->sr_slot; 28 + struct nfs4_slot_table *tbl; 29 + 30 + tbl = slot->table; 31 + spin_lock(&tbl->slot_tbl_lock); 32 + if (!nfs41_wake_and_assign_slot(tbl, slot)) 33 + nfs4_free_slot(tbl, slot); 34 + spin_unlock(&tbl->slot_tbl_lock); 35 + 36 + res->sr_slot = NULL; 37 + } 38 + 39 + static int nfs40_sequence_done(struct rpc_task *task, 40 + struct nfs4_sequence_res *res) 41 + { 42 + if (res->sr_slot != NULL) 43 + nfs40_sequence_free_slot(res); 44 + return 1; 45 + } 46 + 47 + static void nfs40_clear_delegation_stateid(struct nfs4_state *state) 48 + { 49 + if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) 50 + nfs_finish_clear_delegation_stateid(state, NULL); 51 + } 52 + 53 + static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) 54 + { 55 + /* NFSv4.0 doesn't allow for delegation recovery on open expire */ 56 + nfs40_clear_delegation_stateid(state); 57 + nfs_state_clear_open_state_flags(state); 58 + return nfs4_open_expired(sp, state); 59 + } 60 + 61 + struct nfs4_renewdata { 62 + struct nfs_client *client; 63 + unsigned long timestamp; 64 + }; 65 + 66 + /* 67 + * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special 68 + * standalone procedure for queueing an asynchronous RENEW. 69 + */ 70 + static void nfs4_renew_release(void *calldata) 71 + { 72 + struct nfs4_renewdata *data = calldata; 73 + struct nfs_client *clp = data->client; 74 + 75 + if (refcount_read(&clp->cl_count) > 1) 76 + nfs4_schedule_state_renewal(clp); 77 + nfs_put_client(clp); 78 + kfree(data); 79 + } 80 + 81 + static void nfs4_renew_done(struct rpc_task *task, void *calldata) 82 + { 83 + struct nfs4_renewdata *data = calldata; 84 + struct nfs_client *clp = data->client; 85 + unsigned long timestamp = data->timestamp; 86 + 87 + trace_nfs4_renew_async(clp, task->tk_status); 88 + switch (task->tk_status) { 89 + case 0: 90 + break; 91 + case -NFS4ERR_LEASE_MOVED: 92 + nfs4_schedule_lease_moved_recovery(clp); 93 + break; 94 + default: 95 + /* Unless we're shutting down, schedule state recovery! */ 96 + if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) 97 + return; 98 + if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { 99 + nfs4_schedule_lease_recovery(clp); 100 + return; 101 + } 102 + nfs4_schedule_path_down_recovery(clp); 103 + } 104 + do_renew_lease(clp, timestamp); 105 + } 106 + 107 + static const struct rpc_call_ops nfs4_renew_ops = { 108 + .rpc_call_done = nfs4_renew_done, 109 + .rpc_release = nfs4_renew_release, 110 + }; 111 + 112 + static int nfs4_proc_async_renew(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) 113 + { 114 + struct rpc_message msg = { 115 + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], 116 + .rpc_argp = clp, 117 + .rpc_cred = cred, 118 + }; 119 + struct nfs4_renewdata *data; 120 + 121 + if (renew_flags == 0) 122 + return 0; 123 + if (!refcount_inc_not_zero(&clp->cl_count)) 124 + return -EIO; 125 + data = kmalloc(sizeof(*data), GFP_NOFS); 126 + if (data == NULL) { 127 + nfs_put_client(clp); 128 + return -ENOMEM; 129 + } 130 + data->client = clp; 131 + data->timestamp = jiffies; 132 + return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, 133 + &nfs4_renew_ops, data); 134 + } 135 + 136 + static int nfs4_proc_renew(struct nfs_client *clp, const struct cred *cred) 137 + { 138 + struct rpc_message msg = { 139 + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], 140 + .rpc_argp = clp, 141 + .rpc_cred = cred, 142 + }; 143 + unsigned long now = jiffies; 144 + int status; 145 + 146 + status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 147 + if (status < 0) 148 + return status; 149 + do_renew_lease(clp, now); 150 + return 0; 151 + } 152 + 153 + static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, 154 + nfs4_stateid *stateid, 155 + const struct cred *cred) 156 + { 157 + return -NFS4ERR_BAD_STATEID; 158 + } 159 + 160 + /* 161 + * This operation also signals the server that this client is 162 + * performing migration recovery. The server can stop returning 163 + * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is 164 + * appended to this compound to identify the client ID which is 165 + * performing recovery. 166 + */ 167 + static int _nfs40_proc_get_locations(struct nfs_server *server, 168 + struct nfs_fh *fhandle, 169 + struct nfs4_fs_locations *locations, 170 + struct page *page, const struct cred *cred) 171 + { 172 + struct rpc_clnt *clnt = server->client; 173 + struct nfs_client *clp = server->nfs_client; 174 + u32 bitmask[2] = { 175 + [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, 176 + }; 177 + struct nfs4_fs_locations_arg args = { 178 + .clientid = clp->cl_clientid, 179 + .fh = fhandle, 180 + .page = page, 181 + .bitmask = bitmask, 182 + .migration = 1, /* skip LOOKUP */ 183 + .renew = 1, /* append RENEW */ 184 + }; 185 + struct nfs4_fs_locations_res res = { 186 + .fs_locations = locations, 187 + .migration = 1, 188 + .renew = 1, 189 + }; 190 + struct rpc_message msg = { 191 + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], 192 + .rpc_argp = &args, 193 + .rpc_resp = &res, 194 + .rpc_cred = cred, 195 + }; 196 + unsigned long now = jiffies; 197 + int status; 198 + 199 + nfs_fattr_init(locations->fattr); 200 + locations->server = server; 201 + locations->nlocations = 0; 202 + 203 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 1); 204 + status = nfs4_call_sync_sequence(clnt, server, &msg, 205 + &args.seq_args, &res.seq_res); 206 + if (status) 207 + return status; 208 + 209 + renew_lease(server, now); 210 + return 0; 211 + } 212 + 213 + /* 214 + * This operation also signals the server that this client is 215 + * performing "lease moved" recovery. The server can stop 216 + * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation 217 + * is appended to this compound to identify the client ID which is 218 + * performing recovery. 219 + */ 220 + static int _nfs40_proc_fsid_present(struct inode *inode, const struct cred *cred) 221 + { 222 + struct nfs_server *server = NFS_SERVER(inode); 223 + struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 224 + struct rpc_clnt *clnt = server->client; 225 + struct nfs4_fsid_present_arg args = { 226 + .fh = NFS_FH(inode), 227 + .clientid = clp->cl_clientid, 228 + .renew = 1, /* append RENEW */ 229 + }; 230 + struct nfs4_fsid_present_res res = { 231 + .renew = 1, 232 + }; 233 + struct rpc_message msg = { 234 + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], 235 + .rpc_argp = &args, 236 + .rpc_resp = &res, 237 + .rpc_cred = cred, 238 + }; 239 + unsigned long now = jiffies; 240 + int status; 241 + 242 + res.fh = nfs_alloc_fhandle(); 243 + if (res.fh == NULL) 244 + return -ENOMEM; 245 + 246 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 1); 247 + status = nfs4_call_sync_sequence(clnt, server, &msg, 248 + &args.seq_args, &res.seq_res); 249 + nfs_free_fhandle(res.fh); 250 + if (status) 251 + return status; 252 + 253 + do_renew_lease(clp, now); 254 + return 0; 255 + } 256 + 257 + struct nfs_release_lockowner_data { 258 + struct nfs4_lock_state *lsp; 259 + struct nfs_server *server; 260 + struct nfs_release_lockowner_args args; 261 + struct nfs_release_lockowner_res res; 262 + unsigned long timestamp; 263 + }; 264 + 265 + static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) 266 + { 267 + struct nfs_release_lockowner_data *data = calldata; 268 + struct nfs_server *server = data->server; 269 + nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, 270 + &data->res.seq_res, task); 271 + data->args.lock_owner.clientid = server->nfs_client->cl_clientid; 272 + data->timestamp = jiffies; 273 + } 274 + 275 + static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) 276 + { 277 + struct nfs_release_lockowner_data *data = calldata; 278 + struct nfs_server *server = data->server; 279 + 280 + nfs40_sequence_done(task, &data->res.seq_res); 281 + 282 + switch (task->tk_status) { 283 + case 0: 284 + renew_lease(server, data->timestamp); 285 + break; 286 + case -NFS4ERR_STALE_CLIENTID: 287 + case -NFS4ERR_EXPIRED: 288 + nfs4_schedule_lease_recovery(server->nfs_client); 289 + break; 290 + case -NFS4ERR_LEASE_MOVED: 291 + case -NFS4ERR_DELAY: 292 + if (nfs4_async_handle_error(task, server, 293 + NULL, NULL) == -EAGAIN) 294 + rpc_restart_call_prepare(task); 295 + } 296 + } 297 + 298 + static void nfs4_release_lockowner_release(void *calldata) 299 + { 300 + struct nfs_release_lockowner_data *data = calldata; 301 + nfs4_free_lock_state(data->server, data->lsp); 302 + kfree(calldata); 303 + } 304 + 305 + static const struct rpc_call_ops nfs4_release_lockowner_ops = { 306 + .rpc_call_prepare = nfs4_release_lockowner_prepare, 307 + .rpc_call_done = nfs4_release_lockowner_done, 308 + .rpc_release = nfs4_release_lockowner_release, 309 + }; 310 + 311 + static void 312 + nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) 313 + { 314 + struct nfs_release_lockowner_data *data; 315 + struct nfs_client *clp = server->nfs_client; 316 + struct rpc_message msg = { 317 + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], 318 + }; 319 + 320 + if (clp->cl_mvops->minor_version != 0) 321 + return; 322 + 323 + data = kmalloc(sizeof(*data), GFP_KERNEL); 324 + if (!data) 325 + return; 326 + data->lsp = lsp; 327 + data->server = server; 328 + data->args.lock_owner.clientid = clp->cl_clientid; 329 + data->args.lock_owner.id = lsp->ls_seqid.owner_id; 330 + data->args.lock_owner.s_dev = server->s_dev; 331 + 332 + msg.rpc_argp = &data->args; 333 + msg.rpc_resp = &data->res; 334 + nfs4_init_sequence(clp, &data->args.seq_args, &data->res.seq_res, 0, 0); 335 + rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); 336 + } 337 + 338 + static const struct rpc_call_ops nfs40_call_sync_ops = { 339 + .rpc_call_prepare = nfs40_call_sync_prepare, 340 + .rpc_call_done = nfs40_call_sync_done, 341 + }; 342 + 343 + static const struct nfs4_sequence_slot_ops nfs40_sequence_slot_ops = { 344 + .process = nfs40_sequence_done, 345 + .done = nfs40_sequence_done, 346 + .free_slot = nfs40_sequence_free_slot, 347 + }; 348 + 349 + static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { 350 + .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 351 + .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 352 + .recover_open = nfs4_open_reclaim, 353 + .recover_lock = nfs4_lock_reclaim, 354 + .establish_clid = nfs4_init_clientid, 355 + .detect_trunking = nfs40_discover_server_trunking, 356 + }; 357 + 358 + static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { 359 + .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 360 + .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 361 + .recover_open = nfs40_open_expired, 362 + .recover_lock = nfs4_lock_expired, 363 + .establish_clid = nfs4_init_clientid, 364 + }; 365 + 366 + static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { 367 + .sched_state_renewal = nfs4_proc_async_renew, 368 + .get_state_renewal_cred = nfs4_get_renew_cred, 369 + .renew_lease = nfs4_proc_renew, 370 + }; 371 + 372 + static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { 373 + .get_locations = _nfs40_proc_get_locations, 374 + .fsid_present = _nfs40_proc_fsid_present, 375 + }; 376 + 377 + const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { 378 + .minor_version = 0, 379 + .init_caps = NFS_CAP_READDIRPLUS 380 + | NFS_CAP_ATOMIC_OPEN 381 + | NFS_CAP_POSIX_LOCK, 382 + .init_client = nfs40_init_client, 383 + .shutdown_client = nfs40_shutdown_client, 384 + .match_stateid = nfs4_match_stateid, 385 + .find_root_sec = nfs4_find_root_sec, 386 + .free_lock_state = nfs4_release_lockowner, 387 + .test_and_free_expired = nfs40_test_and_free_expired_stateid, 388 + .alloc_seqid = nfs_alloc_seqid, 389 + .call_sync_ops = &nfs40_call_sync_ops, 390 + .sequence_slot_ops = &nfs40_sequence_slot_ops, 391 + .reboot_recovery_ops = &nfs40_reboot_recovery_ops, 392 + .nograce_recovery_ops = &nfs40_nograce_recovery_ops, 393 + .state_renewal_ops = &nfs40_state_renewal_ops, 394 + .mig_recovery_ops = &nfs40_mig_recovery_ops, 395 + };
+8 -5
fs/nfs/nfs42proc.c
··· 670 670 msg.rpc_argp = &data->args; 671 671 msg.rpc_resp = &data->res; 672 672 task_setup_data.callback_data = data; 673 - nfs4_init_sequence(&data->args.osa_seq_args, &data->res.osr_seq_res, 674 - 1, 0); 673 + nfs4_init_sequence(dst_server->nfs_client, &data->args.osa_seq_args, 674 + &data->res.osr_seq_res, 1, 0); 675 675 task = rpc_run_task(&task_setup_data); 676 676 if (IS_ERR(task)) 677 677 return PTR_ERR(task); ··· 1072 1072 nfs42_layoutstat_release(data); 1073 1073 return -EAGAIN; 1074 1074 } 1075 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); 1075 + nfs4_init_sequence(server->nfs_client, &data->args.seq_args, 1076 + &data->res.seq_res, 0, 0); 1076 1077 task = rpc_run_task(&task_setup); 1077 1078 if (IS_ERR(task)) 1078 1079 return PTR_ERR(task); ··· 1211 1210 const struct nfs42_layout_error *errors, size_t n) 1212 1211 { 1213 1212 struct inode *inode = lseg->pls_layout->plh_inode; 1213 + struct nfs_server *server = NFS_SERVER(inode); 1214 1214 struct nfs42_layouterror_data *data; 1215 1215 struct rpc_task *task; 1216 1216 struct rpc_message msg = { ··· 1239 1237 msg.rpc_argp = &data->args; 1240 1238 msg.rpc_resp = &data->res; 1241 1239 task_setup.callback_data = data; 1242 - task_setup.rpc_client = NFS_SERVER(inode)->client; 1243 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); 1240 + task_setup.rpc_client = server->client; 1241 + nfs4_init_sequence(server->nfs_client, &data->args.seq_args, 1242 + &data->res.seq_res, 0, 0); 1244 1243 task = rpc_run_task(&task_setup); 1245 1244 if (IS_ERR(task)) 1246 1245 return PTR_ERR(task);
+46 -40
fs/nfs/nfs4_fs.h
··· 10 10 #ifndef __LINUX_FS_NFS_NFS4_FS_H 11 11 #define __LINUX_FS_NFS_NFS4_FS_H 12 12 13 + #if defined(CONFIG_NFS_V4_0) 14 + #define NFS4_MIN_MINOR_VERSION 0 15 + #else 16 + #define NFS4_MIN_MINOR_VERSION 1 17 + #endif 18 + 13 19 #if defined(CONFIG_NFS_V4_2) 14 20 #define NFS4_MAX_MINOR_VERSION 2 15 - #elif defined(CONFIG_NFS_V4_1) 16 - #define NFS4_MAX_MINOR_VERSION 1 17 21 #else 18 - #define NFS4_MAX_MINOR_VERSION 0 22 + #define NFS4_MAX_MINOR_VERSION 1 19 23 #endif 20 24 21 25 #if IS_ENABLED(CONFIG_NFS_V4) ··· 77 73 void (*session_trunk)(struct rpc_clnt *clnt, 78 74 struct rpc_xprt *xprt, void *data); 79 75 const struct rpc_call_ops *call_sync_ops; 76 + const struct nfs4_sequence_slot_ops *sequence_slot_ops; 80 77 const struct nfs4_state_recovery_ops *reboot_recovery_ops; 81 78 const struct nfs4_state_recovery_ops *nograce_recovery_ops; 82 79 const struct nfs4_state_maintenance_ops *state_renewal_ops; ··· 261 256 const struct cred *cred; 262 257 }; 263 258 259 + struct nfs4_sequence_slot_ops { 260 + int (*process)(struct rpc_task *, struct nfs4_sequence_res *); 261 + int (*done)(struct rpc_task *, struct nfs4_sequence_res *); 262 + void (*free_slot)(struct nfs4_sequence_res *); 263 + }; 264 + 264 265 struct nfs4_state_maintenance_ops { 265 266 int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned); 266 267 const struct cred * (*get_state_renewal_cred)(struct nfs_client *); ··· 288 277 /* fs_context.c */ 289 278 extern struct file_system_type nfs4_fs_type; 290 279 280 + /* nfs4client.c */ 281 + struct nfs_net; 282 + int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new, 283 + struct nfs_client **prev, struct nfs_net *nn); 284 + 291 285 /* nfs4namespace.c */ 292 286 struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, 293 287 const struct qstr *); ··· 302 286 size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr_storage *ss, 303 287 size_t salen, struct net *net, int port); 304 288 /* nfs4proc.c */ 289 + struct nfs4_call_sync_data { 290 + const struct nfs_server *seq_server; 291 + struct nfs4_sequence_args *seq_args; 292 + struct nfs4_sequence_res *seq_res; 293 + }; 294 + 305 295 extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *); 306 296 extern int nfs4_async_handle_error(struct rpc_task *task, 307 297 struct nfs_server *server, ··· 315 293 extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *, 316 294 struct rpc_message *, struct nfs4_sequence_args *, 317 295 struct nfs4_sequence_res *, int); 318 - extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int); 296 + extern int nfs4_call_sync_sequence(struct rpc_clnt *clnt, 297 + struct nfs_server *server, 298 + struct rpc_message *msg, 299 + struct nfs4_sequence_args *args, 300 + struct nfs4_sequence_res *res); 301 + extern void nfs4_init_sequence(struct nfs_client *clp, struct nfs4_sequence_args *, 302 + struct nfs4_sequence_res *, int, int); 319 303 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *); 320 304 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *); 305 + extern void renew_lease(const struct nfs_server *server, unsigned long timestamp); 321 306 extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, 322 307 struct nfs_fattr *, bool); 323 308 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred); ··· 368 339 unsigned long cache_validity); 369 340 extern int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, 370 341 struct page **pages); 342 + extern int nfs4_open_reclaim(struct nfs4_state_owner *, struct nfs4_state *); 343 + extern int nfs4_open_expired(struct nfs4_state_owner *, struct nfs4_state *); 344 + extern int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request); 345 + extern int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request); 346 + extern void nfs_state_clear_delegation(struct nfs4_state *state); 347 + extern void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, 348 + const nfs4_stateid *stateid); 349 + extern void nfs_state_clear_open_state_flags(struct nfs4_state *state); 350 + extern void do_renew_lease(struct nfs_client *clp, unsigned long timestamp); 351 + extern bool nfs4_match_stateid(const nfs4_stateid *s1, const nfs4_stateid *s2); 352 + extern int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, 353 + struct nfs_fattr *fattr); 371 354 372 - #if defined(CONFIG_NFS_V4_1) 373 355 extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *); 374 356 extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *); 375 357 extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *); ··· 458 418 !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags)) 459 419 hdr->args.stable = NFS_FILE_SYNC; 460 420 } 461 - #else /* CONFIG_NFS_v4_1 */ 462 - static inline bool 463 - is_ds_only_client(struct nfs_client *clp) 464 - { 465 - return false; 466 - } 467 - 468 - static inline bool 469 - is_ds_client(struct nfs_client *clp) 470 - { 471 - return false; 472 - } 473 - 474 - static inline void 475 - nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags, 476 - struct rpc_clnt **clntp, struct rpc_message *msg) 477 - { 478 - } 479 - 480 - static inline void 481 - nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp, 482 - struct rpc_message *msg, struct nfs_pgio_header *hdr) 483 - { 484 - } 485 - #endif /* CONFIG_NFS_V4_1 */ 486 421 487 422 extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[]; 488 423 ··· 467 452 extern const u32 nfs4_fsinfo_bitmap[3]; 468 453 extern const u32 nfs4_fs_locations_bitmap[3]; 469 454 470 - void nfs40_shutdown_client(struct nfs_client *); 471 455 void nfs41_shutdown_client(struct nfs_client *); 472 - int nfs40_init_client(struct nfs_client *); 473 456 int nfs41_init_client(struct nfs_client *); 474 457 void nfs4_free_client(struct nfs_client *); 475 458 ··· 477 464 extern void nfs4_schedule_state_renewal(struct nfs_client *); 478 465 extern void nfs4_kill_renewd(struct nfs_client *); 479 466 extern void nfs4_renew_state(struct work_struct *); 480 - extern void nfs4_set_lease_period(struct nfs_client *clp, unsigned long lease); 481 - 467 + extern void nfs4_set_lease_period(struct nfs_client *clp, u32 period); 482 468 483 469 /* nfs4state.c */ 484 470 extern const nfs4_stateid current_stateid; ··· 489 477 struct nfs_client **); 490 478 int nfs40_discover_server_trunking(struct nfs_client *clp, 491 479 struct nfs_client **, const struct cred *); 492 - #if defined(CONFIG_NFS_V4_1) 493 480 int nfs41_discover_server_trunking(struct nfs_client *clp, 494 481 struct nfs_client **, const struct cred *); 495 482 extern void nfs4_schedule_session_recovery(struct nfs4_session *, int); 496 483 extern void nfs41_notify_server(struct nfs_client *); 497 484 bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1, 498 485 struct nfs41_server_owner *o2); 499 - #else 500 - static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err) 501 - { 502 - } 503 - #endif /* CONFIG_NFS_V4_1 */ 504 486 505 487 extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t); 506 488 extern void nfs4_put_state_owner(struct nfs4_state_owner *);
+4 -189
fs/nfs/nfs4client.c
··· 44 44 return ret < 0 ? ret : 0; 45 45 } 46 46 47 - #ifdef CONFIG_NFS_V4_1 48 47 /* 49 48 * Per auth flavor data server rpc clients 50 49 */ ··· 186 187 } 187 188 188 189 } 189 - #endif /* CONFIG_NFS_V4_1 */ 190 - 191 - void nfs40_shutdown_client(struct nfs_client *clp) 192 - { 193 - if (clp->cl_slot_tbl) { 194 - nfs4_shutdown_slot_table(clp->cl_slot_tbl); 195 - kfree(clp->cl_slot_tbl); 196 - } 197 - } 198 190 199 191 struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) 200 192 { ··· 201 211 if (err) 202 212 goto error; 203 213 204 - if (cl_init->minorversion > NFS4_MAX_MINOR_VERSION) { 214 + if (cl_init->minorversion < NFS4_MIN_MINOR_VERSION || 215 + cl_init->minorversion > NFS4_MAX_MINOR_VERSION) { 205 216 err = -EINVAL; 206 217 goto error; 207 218 } ··· 215 224 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; 216 225 clp->cl_mig_gen = 1; 217 226 clp->cl_last_renewal = jiffies; 218 - #if IS_ENABLED(CONFIG_NFS_V4_1) 219 227 init_waitqueue_head(&clp->cl_lock_waitq); 220 - #endif 221 228 INIT_LIST_HEAD(&clp->pending_cb_stateids); 222 229 223 230 if (cl_init->minorversion != 0) ··· 329 340 } 330 341 331 342 /** 332 - * nfs40_init_client - nfs_client initialization tasks for NFSv4.0 333 - * @clp: nfs_client to initialize 334 - * 335 - * Returns zero on success, or a negative errno if some error occurred. 336 - */ 337 - int nfs40_init_client(struct nfs_client *clp) 338 - { 339 - struct nfs4_slot_table *tbl; 340 - int ret; 341 - 342 - tbl = kzalloc(sizeof(*tbl), GFP_NOFS); 343 - if (tbl == NULL) 344 - return -ENOMEM; 345 - 346 - ret = nfs4_setup_slot_table(tbl, NFS4_MAX_SLOT_TABLE, 347 - "NFSv4.0 transport Slot table"); 348 - if (ret) { 349 - nfs4_shutdown_slot_table(tbl); 350 - kfree(tbl); 351 - return ret; 352 - } 353 - 354 - clp->cl_slot_tbl = tbl; 355 - return 0; 356 - } 357 - 358 - #if defined(CONFIG_NFS_V4_1) 359 - 360 - /** 361 343 * nfs41_init_client - nfs_client initialization tasks for NFSv4.1+ 362 344 * @clp: nfs_client to initialize 363 345 * ··· 358 398 nfs_mark_client_ready(clp, NFS_CS_SESSION_INITING); 359 399 return 0; 360 400 } 361 - 362 - #endif /* CONFIG_NFS_V4_1 */ 363 401 364 402 /* 365 403 * Initialize the minor version specific parts of an NFS4 client record ··· 448 490 return ERR_PTR(error); 449 491 } 450 492 451 - /* 452 - * SETCLIENTID just did a callback update with the callback ident in 453 - * "drop," but server trunking discovery claims "drop" and "keep" are 454 - * actually the same server. Swap the callback IDs so that "keep" 455 - * will continue to use the callback ident the server now knows about, 456 - * and so that "keep"'s original callback ident is destroyed when 457 - * "drop" is freed. 458 - */ 459 - static void nfs4_swap_callback_idents(struct nfs_client *keep, 460 - struct nfs_client *drop) 461 - { 462 - struct nfs_net *nn = net_generic(keep->cl_net, nfs_net_id); 463 - unsigned int save = keep->cl_cb_ident; 464 - 465 - if (keep->cl_cb_ident == drop->cl_cb_ident) 466 - return; 467 - 468 - dprintk("%s: keeping callback ident %u and dropping ident %u\n", 469 - __func__, keep->cl_cb_ident, drop->cl_cb_ident); 470 - 471 - spin_lock(&nn->nfs_client_lock); 472 - 473 - idr_replace(&nn->cb_ident_idr, keep, drop->cl_cb_ident); 474 - keep->cl_cb_ident = drop->cl_cb_ident; 475 - 476 - idr_replace(&nn->cb_ident_idr, drop, save); 477 - drop->cl_cb_ident = save; 478 - 479 - spin_unlock(&nn->nfs_client_lock); 480 - } 481 - 482 493 static bool nfs4_match_client_owner_id(const struct nfs_client *clp1, 483 494 const struct nfs_client *clp2) 484 495 { ··· 456 529 return strcmp(clp1->cl_owner_id, clp2->cl_owner_id) == 0; 457 530 } 458 531 459 - static bool nfs4_same_verifier(nfs4_verifier *v1, nfs4_verifier *v2) 460 - { 461 - return memcmp(v1->data, v2->data, sizeof(v1->data)) == 0; 462 - } 463 - 464 - static int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new, 465 - struct nfs_client **prev, struct nfs_net *nn) 532 + int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new, 533 + struct nfs_client **prev, struct nfs_net *nn) 466 534 { 467 535 int status; 468 536 ··· 500 578 return 0; 501 579 } 502 580 503 - /** 504 - * nfs40_walk_client_list - Find server that recognizes a client ID 505 - * 506 - * @new: nfs_client with client ID to test 507 - * @result: OUT: found nfs_client, or new 508 - * @cred: credential to use for trunking test 509 - * 510 - * Returns zero, a negative errno, or a negative NFS4ERR status. 511 - * If zero is returned, an nfs_client pointer is planted in "result." 512 - * 513 - * NB: nfs40_walk_client_list() relies on the new nfs_client being 514 - * the last nfs_client on the list. 515 - */ 516 - int nfs40_walk_client_list(struct nfs_client *new, 517 - struct nfs_client **result, 518 - const struct cred *cred) 519 - { 520 - struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id); 521 - struct nfs_client *pos, *prev = NULL; 522 - struct nfs4_setclientid_res clid = { 523 - .clientid = new->cl_clientid, 524 - .confirm = new->cl_confirm, 525 - }; 526 - int status = -NFS4ERR_STALE_CLIENTID; 527 - 528 - spin_lock(&nn->nfs_client_lock); 529 - list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) { 530 - 531 - if (pos == new) 532 - goto found; 533 - 534 - status = nfs4_match_client(pos, new, &prev, nn); 535 - if (status < 0) 536 - goto out_unlock; 537 - if (status != 0) 538 - continue; 539 - /* 540 - * We just sent a new SETCLIENTID, which should have 541 - * caused the server to return a new cl_confirm. So if 542 - * cl_confirm is the same, then this is a different 543 - * server that just returned the same cl_confirm by 544 - * coincidence: 545 - */ 546 - if ((new != pos) && nfs4_same_verifier(&pos->cl_confirm, 547 - &new->cl_confirm)) 548 - continue; 549 - /* 550 - * But if the cl_confirm's are different, then the only 551 - * way that a SETCLIENTID_CONFIRM to pos can succeed is 552 - * if new and pos point to the same server: 553 - */ 554 - found: 555 - refcount_inc(&pos->cl_count); 556 - spin_unlock(&nn->nfs_client_lock); 557 - 558 - nfs_put_client(prev); 559 - prev = pos; 560 - 561 - status = nfs4_proc_setclientid_confirm(pos, &clid, cred); 562 - switch (status) { 563 - case -NFS4ERR_STALE_CLIENTID: 564 - break; 565 - case 0: 566 - nfs4_swap_callback_idents(pos, new); 567 - pos->cl_confirm = new->cl_confirm; 568 - nfs_mark_client_ready(pos, NFS_CS_READY); 569 - 570 - prev = NULL; 571 - *result = pos; 572 - goto out; 573 - case -ERESTARTSYS: 574 - case -ETIMEDOUT: 575 - /* The callback path may have been inadvertently 576 - * changed. Schedule recovery! 577 - */ 578 - nfs4_schedule_path_down_recovery(pos); 579 - goto out; 580 - default: 581 - goto out; 582 - } 583 - 584 - spin_lock(&nn->nfs_client_lock); 585 - } 586 - out_unlock: 587 - spin_unlock(&nn->nfs_client_lock); 588 - 589 - /* No match found. The server lost our clientid */ 590 - out: 591 - nfs_put_client(prev); 592 - return status; 593 - } 594 - 595 - #ifdef CONFIG_NFS_V4_1 596 581 /* 597 582 * Returns true if the server major ids match 598 583 */ ··· 628 799 nfs_put_client(prev); 629 800 return status; 630 801 } 631 - #endif /* CONFIG_NFS_V4_1 */ 632 802 633 803 static void nfs4_destroy_server(struct nfs_server *server) 634 804 { ··· 659 831 return clp; 660 832 } 661 833 662 - #if defined(CONFIG_NFS_V4_1) 663 834 /* Common match routine for v4.0 and v4.1 callback services */ 664 835 static bool nfs4_cb_match_client(const struct sockaddr *addr, 665 836 struct nfs_client *clp, u32 minorversion) ··· 715 888 spin_unlock(&nn->nfs_client_lock); 716 889 return NULL; 717 890 } 718 - 719 - #else /* CONFIG_NFS_V4_1 */ 720 - 721 - struct nfs_client * 722 - nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, 723 - struct nfs4_sessionid *sid, u32 minorversion) 724 - { 725 - return NULL; 726 - } 727 - #endif /* CONFIG_NFS_V4_1 */ 728 891 729 892 /* 730 893 * Set up an NFS4 client ··· 857 1040 */ 858 1041 static void nfs4_session_limit_rwsize(struct nfs_server *server) 859 1042 { 860 - #ifdef CONFIG_NFS_V4_1 861 1043 struct nfs4_session *sess; 862 1044 u32 server_resp_sz; 863 1045 u32 server_rqst_sz; ··· 873 1057 server->rsize = server_resp_sz; 874 1058 if (server->wsize > server_rqst_sz) 875 1059 server->wsize = server_rqst_sz; 876 - #endif /* CONFIG_NFS_V4_1 */ 877 1060 } 878 1061 879 1062 /*
+160 -606
fs/nfs/nfs4proc.c
··· 67 67 #include "nfs4idmap.h" 68 68 #include "nfs4session.h" 69 69 #include "fscache.h" 70 + #include "nfs40.h" 70 71 #include "nfs42.h" 71 72 72 73 #include "nfs4trace.h" ··· 99 98 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, 100 99 struct nfs_fattr *fattr, struct iattr *sattr, 101 100 struct nfs_open_context *ctx, struct nfs4_label *ilabel); 102 - #ifdef CONFIG_NFS_V4_1 103 101 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, 104 102 const struct cred *cred, 105 103 struct nfs4_slot *slot, ··· 107 107 const struct cred *); 108 108 static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, 109 109 const struct cred *, bool); 110 - #endif 111 110 112 111 #ifdef CONFIG_NFS_V4_SECURITY_LABEL 113 112 static inline struct nfs4_label * ··· 567 568 case -NFS4ERR_LEASE_MOVED: 568 569 nfs4_schedule_lease_moved_recovery(clp); 569 570 goto wait_on_recovery; 570 - #if defined(CONFIG_NFS_V4_1) 571 571 case -NFS4ERR_BADSESSION: 572 572 case -NFS4ERR_BADSLOT: 573 573 case -NFS4ERR_BAD_HIGH_SLOT: ··· 576 578 case -NFS4ERR_SEQ_MISORDERED: 577 579 /* Handled in nfs41_sequence_process() */ 578 580 goto wait_on_recovery; 579 - #endif /* defined(CONFIG_NFS_V4_1) */ 580 581 case -NFS4ERR_FILE_OPEN: 581 582 if (exception->timeout > HZ) { 582 583 /* We have retried a decent amount, time to ··· 750 753 return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); 751 754 } 752 755 753 - static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) 756 + void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) 754 757 { 755 758 spin_lock(&clp->cl_lock); 756 759 if (time_before(clp->cl_last_renewal,timestamp)) ··· 758 761 spin_unlock(&clp->cl_lock); 759 762 } 760 763 761 - static void renew_lease(const struct nfs_server *server, unsigned long timestamp) 764 + void renew_lease(const struct nfs_server *server, unsigned long timestamp) 762 765 { 763 766 struct nfs_client *clp = server->nfs_client; 764 767 ··· 766 769 do_renew_lease(clp, timestamp); 767 770 } 768 771 769 - struct nfs4_call_sync_data { 770 - const struct nfs_server *seq_server; 771 - struct nfs4_sequence_args *seq_args; 772 - struct nfs4_sequence_res *seq_res; 773 - }; 774 - 775 - void nfs4_init_sequence(struct nfs4_sequence_args *args, 772 + void nfs4_init_sequence(struct nfs_client *clp, 773 + struct nfs4_sequence_args *args, 776 774 struct nfs4_sequence_res *res, int cache_reply, 777 775 int privileged) 778 776 { ··· 776 784 args->sa_privileged = privileged; 777 785 778 786 res->sr_slot = NULL; 787 + res->sr_slot_ops = clp->cl_mvops->sequence_slot_ops; 779 788 } 780 - 781 - static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) 782 - { 783 - struct nfs4_slot *slot = res->sr_slot; 784 - struct nfs4_slot_table *tbl; 785 - 786 - tbl = slot->table; 787 - spin_lock(&tbl->slot_tbl_lock); 788 - if (!nfs41_wake_and_assign_slot(tbl, slot)) 789 - nfs4_free_slot(tbl, slot); 790 - spin_unlock(&tbl->slot_tbl_lock); 791 - 792 - res->sr_slot = NULL; 793 - } 794 - 795 - static int nfs40_sequence_done(struct rpc_task *task, 796 - struct nfs4_sequence_res *res) 797 - { 798 - if (res->sr_slot != NULL) 799 - nfs40_sequence_free_slot(res); 800 - return 1; 801 - } 802 - 803 - #if defined(CONFIG_NFS_V4_1) 804 789 805 790 static void nfs41_release_slot(struct nfs4_slot *slot) 806 791 { ··· 993 1024 } 994 1025 EXPORT_SYMBOL_GPL(nfs41_sequence_done); 995 1026 996 - static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) 997 - { 998 - if (res->sr_slot == NULL) 999 - return 1; 1000 - if (res->sr_slot->table->session != NULL) 1001 - return nfs41_sequence_process(task, res); 1002 - return nfs40_sequence_done(task, res); 1003 - } 1004 - 1005 - static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) 1006 - { 1007 - if (res->sr_slot != NULL) { 1008 - if (res->sr_slot->table->session != NULL) 1009 - nfs41_sequence_free_slot(res); 1010 - else 1011 - nfs40_sequence_free_slot(res); 1012 - } 1013 - } 1014 - 1015 - int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) 1016 - { 1017 - if (res->sr_slot == NULL) 1018 - return 1; 1019 - if (!res->sr_slot->table->session) 1020 - return nfs40_sequence_done(task, res); 1021 - return nfs41_sequence_done(task, res); 1022 - } 1023 - EXPORT_SYMBOL_GPL(nfs4_sequence_done); 1024 - 1025 1027 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) 1026 1028 { 1027 1029 struct nfs4_call_sync_data *data = calldata; ··· 1015 1075 .rpc_call_done = nfs41_call_sync_done, 1016 1076 }; 1017 1077 1018 - #else /* !CONFIG_NFS_V4_1 */ 1019 - 1020 - static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) 1021 - { 1022 - return nfs40_sequence_done(task, res); 1023 - } 1024 - 1025 - static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) 1026 - { 1027 - if (res->sr_slot != NULL) 1028 - nfs40_sequence_free_slot(res); 1029 - } 1030 - 1031 - int nfs4_sequence_done(struct rpc_task *task, 1032 - struct nfs4_sequence_res *res) 1033 - { 1034 - return nfs40_sequence_done(task, res); 1035 - } 1036 - EXPORT_SYMBOL_GPL(nfs4_sequence_done); 1037 - 1038 - #endif /* !CONFIG_NFS_V4_1 */ 1039 1078 1040 1079 static void nfs41_sequence_res_init(struct nfs4_sequence_res *res) 1041 1080 { ··· 1035 1116 1036 1117 res->sr_slot = slot; 1037 1118 } 1119 + 1120 + static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) 1121 + { 1122 + if (res->sr_slot != NULL) 1123 + res->sr_slot_ops->free_slot(res); 1124 + } 1125 + 1126 + static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) 1127 + { 1128 + if (res->sr_slot == NULL) 1129 + return 1; 1130 + return res->sr_slot_ops->process(task, res); 1131 + } 1132 + 1133 + int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) 1134 + { 1135 + if (res->sr_slot == NULL) 1136 + return 1; 1137 + return res->sr_slot_ops->done(task, res); 1138 + } 1139 + EXPORT_SYMBOL_GPL(nfs4_sequence_done); 1140 + 1038 1141 1039 1142 int nfs4_setup_sequence(struct nfs_client *client, 1040 1143 struct nfs4_sequence_args *args, ··· 1115 1174 } 1116 1175 EXPORT_SYMBOL_GPL(nfs4_setup_sequence); 1117 1176 1118 - static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) 1119 - { 1120 - struct nfs4_call_sync_data *data = calldata; 1121 - nfs4_setup_sequence(data->seq_server->nfs_client, 1122 - data->seq_args, data->seq_res, task); 1123 - } 1124 - 1125 - static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) 1126 - { 1127 - struct nfs4_call_sync_data *data = calldata; 1128 - nfs4_sequence_done(task, data->seq_res); 1129 - } 1130 - 1131 - static const struct rpc_call_ops nfs40_call_sync_ops = { 1132 - .rpc_call_prepare = nfs40_call_sync_prepare, 1133 - .rpc_call_done = nfs40_call_sync_done, 1134 - }; 1135 - 1136 1177 static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) 1137 1178 { 1138 1179 int ret; ··· 1153 1230 return nfs4_call_sync_custom(&task_setup); 1154 1231 } 1155 1232 1156 - static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, 1157 - struct nfs_server *server, 1158 - struct rpc_message *msg, 1159 - struct nfs4_sequence_args *args, 1160 - struct nfs4_sequence_res *res) 1233 + int nfs4_call_sync_sequence(struct rpc_clnt *clnt, 1234 + struct nfs_server *server, 1235 + struct rpc_message *msg, 1236 + struct nfs4_sequence_args *args, 1237 + struct nfs4_sequence_res *res) 1161 1238 { 1162 1239 unsigned short task_flags = 0; 1163 1240 ··· 1174 1251 struct nfs4_sequence_res *res, 1175 1252 int cache_reply) 1176 1253 { 1177 - nfs4_init_sequence(args, res, cache_reply, 0); 1254 + nfs4_init_sequence(server->nfs_client, args, res, cache_reply, 0); 1178 1255 return nfs4_call_sync_sequence(clnt, server, msg, args, res); 1179 1256 } 1180 1257 ··· 1532 1609 return ret; 1533 1610 } 1534 1611 1535 - static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, 1536 - enum open_claim_type4 claim) 1612 + static bool can_open_delegated(const struct inode *inode, fmode_t fmode, 1613 + enum open_claim_type4 claim, nfs4_stateid *stateid) 1537 1614 { 1538 - if (delegation == NULL) 1539 - return 0; 1615 + struct nfs_delegation *delegation; 1616 + bool ret = false; 1617 + 1618 + delegation = nfs4_get_valid_delegation(inode); 1619 + if (!delegation) 1620 + return false; 1540 1621 if ((delegation->type & fmode) != fmode) 1541 - return 0; 1622 + goto out_put_delegation; 1623 + 1542 1624 switch (claim) { 1543 - case NFS4_OPEN_CLAIM_NULL: 1544 - case NFS4_OPEN_CLAIM_FH: 1545 - break; 1546 1625 case NFS4_OPEN_CLAIM_PREVIOUS: 1547 - if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) 1626 + if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) 1548 1627 break; 1549 1628 fallthrough; 1629 + case NFS4_OPEN_CLAIM_NULL: 1630 + case NFS4_OPEN_CLAIM_FH: 1631 + nfs_mark_delegation_referenced(delegation); 1632 + /* Save the delegation stateid */ 1633 + if (stateid) 1634 + nfs4_stateid_copy(stateid, &delegation->stateid); 1635 + ret = true; 1636 + break; 1550 1637 default: 1551 - return 0; 1638 + break; 1552 1639 } 1553 - nfs_mark_delegation_referenced(delegation); 1554 - return 1; 1640 + 1641 + out_put_delegation: 1642 + nfs_put_delegation(delegation); 1643 + return ret; 1555 1644 } 1556 1645 1557 1646 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) ··· 1581 1646 nfs4_state_set_mode_locked(state, state->state | fmode); 1582 1647 } 1583 1648 1584 - #ifdef CONFIG_NFS_V4_1 1585 1649 static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) 1586 1650 { 1587 1651 if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) ··· 1591 1657 return true; 1592 1658 return false; 1593 1659 } 1594 - #endif /* CONFIG_NFS_V4_1 */ 1595 1660 1596 1661 static void nfs_state_log_update_open_stateid(struct nfs4_state *state) 1597 1662 { ··· 1792 1859 write_sequnlock(&state->seqlock); 1793 1860 } 1794 1861 1795 - static void nfs_state_clear_open_state_flags(struct nfs4_state *state) 1862 + void nfs_state_clear_open_state_flags(struct nfs4_state *state) 1796 1863 { 1797 1864 clear_bit(NFS_O_RDWR_STATE, &state->flags); 1798 1865 clear_bit(NFS_O_WRONLY_STATE, &state->flags); ··· 1814 1881 write_sequnlock(&state->seqlock); 1815 1882 } 1816 1883 1817 - static void nfs_state_clear_delegation(struct nfs4_state *state) 1884 + void nfs_state_clear_delegation(struct nfs4_state *state) 1818 1885 { 1819 1886 write_seqlock(&state->seqlock); 1820 1887 nfs4_stateid_copy(&state->stateid, &state->open_stateid); ··· 1829 1896 { 1830 1897 struct nfs_server *server = NFS_SERVER(state->inode); 1831 1898 struct nfs_client *clp = server->nfs_client; 1832 - struct nfs_inode *nfsi = NFS_I(state->inode); 1833 1899 struct nfs_delegation *deleg_cur; 1834 1900 nfs4_stateid freeme = { }; 1835 1901 int ret = 0; 1836 1902 1837 1903 fmode &= (FMODE_READ|FMODE_WRITE); 1838 1904 1839 - rcu_read_lock(); 1840 1905 spin_lock(&state->owner->so_lock); 1841 1906 if (open_stateid != NULL) { 1907 + rcu_read_lock(); 1842 1908 nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); 1909 + rcu_read_unlock(); 1843 1910 ret = 1; 1844 1911 } 1845 1912 ··· 1848 1915 goto no_delegation; 1849 1916 1850 1917 spin_lock(&deleg_cur->lock); 1851 - if (rcu_dereference(nfsi->delegation) != deleg_cur || 1918 + if (!deleg_cur->inode || 1852 1919 test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || 1853 1920 (deleg_cur->type & fmode) != fmode) 1854 1921 goto no_delegation_unlock; ··· 1863 1930 ret = 1; 1864 1931 no_delegation_unlock: 1865 1932 spin_unlock(&deleg_cur->lock); 1933 + nfs_put_delegation(deleg_cur); 1866 1934 no_delegation: 1867 1935 if (ret) 1868 1936 update_open_stateflags(state, fmode); 1869 1937 spin_unlock(&state->owner->so_lock); 1870 - rcu_read_unlock(); 1871 1938 1872 1939 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) 1873 1940 nfs4_schedule_state_manager(clp); ··· 1901 1968 struct nfs_delegation *delegation; 1902 1969 1903 1970 fmode &= FMODE_READ|FMODE_WRITE; 1904 - rcu_read_lock(); 1905 1971 delegation = nfs4_get_valid_delegation(inode); 1906 - if (delegation == NULL || (delegation->type & fmode) == fmode) { 1907 - rcu_read_unlock(); 1972 + if (!delegation) 1908 1973 return; 1909 - } 1910 - rcu_read_unlock(); 1911 - nfs4_inode_return_delegation(inode); 1974 + if ((delegation->type & fmode) != fmode) 1975 + nfs4_inode_return_delegation(inode); 1976 + nfs_put_delegation(delegation); 1912 1977 } 1913 1978 1914 1979 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) 1915 1980 { 1916 1981 struct nfs4_state *state = opendata->state; 1917 - struct nfs_delegation *delegation; 1918 1982 int open_mode = opendata->o_arg.open_flags; 1919 1983 fmode_t fmode = opendata->o_arg.fmode; 1920 1984 enum open_claim_type4 claim = opendata->o_arg.claim; ··· 1926 1996 goto out_return_state; 1927 1997 } 1928 1998 spin_unlock(&state->owner->so_lock); 1929 - rcu_read_lock(); 1930 - delegation = nfs4_get_valid_delegation(state->inode); 1931 - if (!can_open_delegated(delegation, fmode, claim)) { 1932 - rcu_read_unlock(); 1999 + 2000 + if (!can_open_delegated(state->inode, fmode, claim, &stateid)) 1933 2001 break; 1934 - } 1935 - /* Save the delegation */ 1936 - nfs4_stateid_copy(&stateid, &delegation->stateid); 1937 - rcu_read_unlock(); 2002 + 1938 2003 nfs_release_seqid(opendata->o_arg.seqid); 1939 2004 if (!opendata->is_recover) { 1940 2005 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); ··· 2275 2350 return err; 2276 2351 } 2277 2352 2278 - static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) 2353 + int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) 2279 2354 { 2280 2355 struct nfs_open_context *ctx; 2281 2356 int ret; ··· 2390 2465 { 2391 2466 struct nfs4_opendata *data = calldata; 2392 2467 2393 - nfs40_sequence_done(task, &data->c_res.seq_res); 2468 + data->c_res.seq_res.sr_slot_ops->done(task, &data->c_res.seq_res); 2394 2469 2395 2470 data->rpc_status = task->tk_status; 2396 2471 if (data->rpc_status == 0) { ··· 2448 2523 }; 2449 2524 int status; 2450 2525 2451 - nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, 2452 - data->is_recover); 2526 + nfs4_init_sequence(server->nfs_client, &data->c_arg.seq_args, 2527 + &data->c_res.seq_res, 1, data->is_recover); 2453 2528 kref_get(&data->kref); 2454 2529 data->rpc_done = false; 2455 2530 data->rpc_status = 0; ··· 2481 2556 * a delegation instead. 2482 2557 */ 2483 2558 if (data->state != NULL) { 2484 - struct nfs_delegation *delegation; 2485 - 2486 2559 if (can_open_cached(data->state, data->o_arg.fmode, 2487 2560 data->o_arg.open_flags, claim)) 2488 2561 goto out_no_action; 2489 - rcu_read_lock(); 2490 - delegation = nfs4_get_valid_delegation(data->state->inode); 2491 - if (can_open_delegated(delegation, data->o_arg.fmode, claim)) 2492 - goto unlock_no_action; 2493 - rcu_read_unlock(); 2562 + if (can_open_delegated(data->state->inode, data->o_arg.fmode, 2563 + claim, NULL)) { 2564 + trace_nfs4_cached_open(data->state); 2565 + goto out_no_action; 2566 + } 2494 2567 } 2495 2568 /* Update client id. */ 2496 2569 data->o_arg.clientid = clp->cl_clientid; ··· 2524 2601 data->o_arg.createmode = NFS4_CREATE_GUARDED; 2525 2602 } 2526 2603 return; 2527 - unlock_no_action: 2528 - trace_nfs4_cached_open(data->state); 2529 - rcu_read_unlock(); 2604 + 2530 2605 out_no_action: 2531 2606 task->tk_action = NULL; 2532 2607 out_wait: ··· 2596 2675 { 2597 2676 struct inode *dir = d_inode(data->dir); 2598 2677 struct nfs_server *server = NFS_SERVER(dir); 2678 + struct nfs_client *clp = server->nfs_client; 2599 2679 struct nfs_openargs *o_arg = &data->o_arg; 2600 2680 struct nfs_openres *o_res = &data->o_res; 2601 2681 struct rpc_task *task; ··· 2625 2703 data->cancelled = false; 2626 2704 data->is_recover = false; 2627 2705 if (!ctx) { 2628 - nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 1); 2706 + nfs4_init_sequence(clp, &o_arg->seq_args, &o_res->seq_res, 1, 1); 2629 2707 data->is_recover = true; 2630 2708 task_setup_data.flags |= RPC_TASK_TIMEOUT; 2631 2709 } else { 2632 - nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 0); 2710 + nfs4_init_sequence(clp, &o_arg->seq_args, &o_res->seq_res, 1, 0); 2633 2711 pnfs_lgopen_prepare(data, ctx); 2634 2712 } 2635 2713 task = rpc_run_task(&task_setup_data); ··· 2807 2885 return err; 2808 2886 } 2809 2887 2810 - static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) 2888 + int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) 2811 2889 { 2812 2890 struct nfs_open_context *ctx; 2813 2891 int ret; ··· 2820 2898 return ret; 2821 2899 } 2822 2900 2823 - static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, 2901 + void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, 2824 2902 const nfs4_stateid *stateid) 2825 2903 { 2826 2904 nfs_remove_bad_delegation(state->inode, stateid); 2827 2905 nfs_state_clear_delegation(state); 2828 2906 } 2829 2907 2830 - static void nfs40_clear_delegation_stateid(struct nfs4_state *state) 2831 - { 2832 - if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) 2833 - nfs_finish_clear_delegation_stateid(state, NULL); 2834 - } 2835 - 2836 - static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) 2837 - { 2838 - /* NFSv4.0 doesn't allow for delegation recovery on open expire */ 2839 - nfs40_clear_delegation_stateid(state); 2840 - nfs_state_clear_open_state_flags(state); 2841 - return nfs4_open_expired(sp, state); 2842 - } 2843 - 2844 - static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, 2845 - nfs4_stateid *stateid, const struct cred *cred) 2846 - { 2847 - return -NFS4ERR_BAD_STATEID; 2848 - } 2849 - 2850 - #if defined(CONFIG_NFS_V4_1) 2851 2908 static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, 2852 2909 nfs4_stateid *stateid, const struct cred *cred) 2853 2910 { ··· 3011 3110 status = nfs4_open_expired(sp, state); 3012 3111 return status; 3013 3112 } 3014 - #endif 3015 3113 3016 3114 /* 3017 3115 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* ··· 3750 3850 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) 3751 3851 { 3752 3852 struct nfs_server *server = NFS_SERVER(state->inode); 3853 + struct nfs_client *clp = server->nfs_client; 3753 3854 struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); 3754 3855 struct nfs4_closedata *calldata; 3755 3856 struct nfs4_state_owner *sp = state->owner; ··· 3771 3870 if (nfs_server_capable(state->inode, NFS_CAP_MOVEABLE)) 3772 3871 task_setup_data.flags |= RPC_TASK_MOVEABLE; 3773 3872 3774 - nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, 3873 + nfs4_state_protect(clp, NFS_SP4_MACH_CRED_CLEANUP, 3775 3874 &task_setup_data.rpc_client, &msg); 3776 3875 3777 3876 calldata = kzalloc(sizeof(*calldata), gfp_mask); 3778 3877 if (calldata == NULL) 3779 3878 goto out; 3780 - nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1, 0); 3879 + nfs4_init_sequence(clp, &calldata->arg.seq_args, 3880 + &calldata->res.seq_res, 1, 0); 3781 3881 calldata->inode = state->inode; 3782 3882 calldata->state = state; 3783 3883 calldata->arg.fh = NFS_FH(state->inode); 3784 3884 if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) 3785 3885 goto out_free_calldata; 3786 3886 /* Serialization for the sequence id */ 3787 - alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; 3887 + alloc_seqid = clp->cl_mvops->alloc_seqid; 3788 3888 calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); 3789 3889 if (IS_ERR(calldata->arg.seqid)) 3790 3890 goto out_free_calldata; ··· 4228 4326 * Returns zero on success, or a negative NFS4ERR value, or a 4229 4327 * negative errno value. 4230 4328 */ 4231 - static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, 4329 + int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, 4232 4330 struct nfs_fattr *fattr) 4233 4331 { 4234 4332 /* Per 3530bis 15.33.5 */ ··· 4372 4470 return status; 4373 4471 } 4374 4472 4375 - #if IS_ENABLED(CONFIG_NFS_V4_1) 4376 4473 static bool should_request_dir_deleg(struct inode *inode) 4377 4474 { 4378 4475 if (!directory_delegations) ··· 4388 4487 return false; 4389 4488 return true; 4390 4489 } 4391 - #else 4392 - static bool should_request_dir_deleg(struct inode *inode) 4393 - { 4394 - return false; 4395 - } 4396 - #endif /* CONFIG_NFS_V4_1 */ 4397 4490 4398 4491 static void nfs4_call_getattr_prepare(struct rpc_task *task, void *calldata) 4399 4492 { ··· 4436 4541 .callback_ops = &nfs4_call_getattr_ops, 4437 4542 .callback_data = &data, 4438 4543 }; 4544 + struct nfs_client *clp = server->nfs_client; 4439 4545 struct nfs4_gdd_res gdd_res; 4440 4546 int status; 4441 4547 4442 - if (nfs4_has_session(server->nfs_client)) 4548 + if (nfs4_has_session(clp)) 4443 4549 task_setup.flags = RPC_TASK_MOVEABLE; 4444 4550 4445 4551 /* Is this is an attribute revalidation, subject to softreval? */ ··· 4453 4557 4454 4558 nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), inode, 0); 4455 4559 nfs_fattr_init(fattr); 4456 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); 4560 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 0); 4457 4561 4458 4562 status = nfs4_call_sync_custom(&task_setup); 4459 4563 ··· 4594 4698 nfs_fattr_init(fattr); 4595 4699 4596 4700 dprintk("NFS call lookup %pd2\n", dentry); 4597 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); 4701 + nfs4_init_sequence(server->nfs_client, &args.seq_args, &res.seq_res, 0, 0); 4598 4702 status = nfs4_do_call_sync(clnt, server, &msg, 4599 4703 &args.seq_args, &res.seq_res, task_flags); 4600 4704 dprintk("NFS reply lookup: %d\n", status); ··· 4712 4816 args.bitmask = nfs4_bitmask(server, fattr->label); 4713 4817 4714 4818 nfs_fattr_init(fattr); 4715 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); 4819 + nfs4_init_sequence(server->nfs_client, &args.seq_args, &res.seq_res, 0, 0); 4716 4820 4717 4821 dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); 4718 4822 status = nfs4_do_call_sync(clnt, server, &msg, &args.seq_args, ··· 4957 5061 { 4958 5062 struct nfs_removeargs *args = msg->rpc_argp; 4959 5063 struct nfs_removeres *res = msg->rpc_resp; 5064 + struct nfs_server *server = NFS_SB(dentry->d_sb); 4960 5065 4961 - res->server = NFS_SB(dentry->d_sb); 5066 + res->server = server; 4962 5067 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; 4963 - nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); 5068 + nfs4_init_sequence(server->nfs_client, &args->seq_args, 5069 + &res->seq_res, 1, 0); 4964 5070 4965 5071 nfs_fattr_init(res->dir_attr); 4966 5072 nfs_request_directory_delegation(d_inode(dentry->d_parent)); ··· 5003 5105 struct dentry *new_dentry, 5004 5106 struct inode *same_parent) 5005 5107 { 5108 + struct nfs_server *server = NFS_SB(old_dentry->d_sb); 5006 5109 struct nfs_renameargs *arg = msg->rpc_argp; 5007 5110 struct nfs_renameres *res = msg->rpc_resp; 5008 5111 struct inode *old_inode = d_inode(old_dentry); ··· 5016 5117 if (same_parent) 5017 5118 nfs_request_directory_delegation(same_parent); 5018 5119 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; 5019 - res->server = NFS_SB(old_dentry->d_sb); 5020 - nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); 5120 + res->server = server; 5121 + nfs4_init_sequence(server->nfs_client, &arg->seq_args, 5122 + &res->seq_res, 1, 0); 5021 5123 } 5022 5124 5023 5125 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) ··· 5487 5587 err = _nfs4_do_fsinfo(server, fhandle, fsinfo); 5488 5588 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); 5489 5589 if (err == 0) { 5490 - nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); 5590 + nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time); 5491 5591 break; 5492 5592 } 5493 5593 err = nfs4_handle_exception(server, err, &exception); ··· 5686 5786 hdr->pgio_done_cb = nfs4_read_done_cb; 5687 5787 if (!nfs42_read_plus_support(hdr, msg)) 5688 5788 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; 5689 - nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); 5789 + nfs4_init_sequence(NFS_SERVER(hdr->inode)->nfs_client, 5790 + &hdr->args.seq_args, &hdr->res.seq_res, 0, 0); 5690 5791 } 5691 5792 5692 5793 static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, ··· 5829 5928 hdr->timestamp = jiffies; 5830 5929 5831 5930 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; 5832 - nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); 5931 + nfs4_init_sequence(server->nfs_client, &hdr->args.seq_args, 5932 + &hdr->res.seq_res, 0, 0); 5833 5933 nfs4_state_protect_write(hdr->ds_clp ? hdr->ds_clp : server->nfs_client, clnt, msg, hdr); 5834 5934 } 5835 5935 ··· 5871 5969 data->commit_done_cb = nfs4_commit_done_cb; 5872 5970 data->res.server = server; 5873 5971 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; 5874 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); 5972 + nfs4_init_sequence(server->nfs_client, &data->args.seq_args, 5973 + &data->res.seq_res, 1, 0); 5875 5974 nfs4_state_protect(data->ds_clp ? data->ds_clp : server->nfs_client, 5876 5975 NFS_SP4_MACH_CRED_COMMIT, clnt, msg); 5877 5976 } ··· 5909 6006 } while (exception.retry); 5910 6007 5911 6008 return status; 5912 - } 5913 - 5914 - struct nfs4_renewdata { 5915 - struct nfs_client *client; 5916 - unsigned long timestamp; 5917 - }; 5918 - 5919 - /* 5920 - * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special 5921 - * standalone procedure for queueing an asynchronous RENEW. 5922 - */ 5923 - static void nfs4_renew_release(void *calldata) 5924 - { 5925 - struct nfs4_renewdata *data = calldata; 5926 - struct nfs_client *clp = data->client; 5927 - 5928 - if (refcount_read(&clp->cl_count) > 1) 5929 - nfs4_schedule_state_renewal(clp); 5930 - nfs_put_client(clp); 5931 - kfree(data); 5932 - } 5933 - 5934 - static void nfs4_renew_done(struct rpc_task *task, void *calldata) 5935 - { 5936 - struct nfs4_renewdata *data = calldata; 5937 - struct nfs_client *clp = data->client; 5938 - unsigned long timestamp = data->timestamp; 5939 - 5940 - trace_nfs4_renew_async(clp, task->tk_status); 5941 - switch (task->tk_status) { 5942 - case 0: 5943 - break; 5944 - case -NFS4ERR_LEASE_MOVED: 5945 - nfs4_schedule_lease_moved_recovery(clp); 5946 - break; 5947 - default: 5948 - /* Unless we're shutting down, schedule state recovery! */ 5949 - if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) 5950 - return; 5951 - if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { 5952 - nfs4_schedule_lease_recovery(clp); 5953 - return; 5954 - } 5955 - nfs4_schedule_path_down_recovery(clp); 5956 - } 5957 - do_renew_lease(clp, timestamp); 5958 - } 5959 - 5960 - static const struct rpc_call_ops nfs4_renew_ops = { 5961 - .rpc_call_done = nfs4_renew_done, 5962 - .rpc_release = nfs4_renew_release, 5963 - }; 5964 - 5965 - static int nfs4_proc_async_renew(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) 5966 - { 5967 - struct rpc_message msg = { 5968 - .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], 5969 - .rpc_argp = clp, 5970 - .rpc_cred = cred, 5971 - }; 5972 - struct nfs4_renewdata *data; 5973 - 5974 - if (renew_flags == 0) 5975 - return 0; 5976 - if (!refcount_inc_not_zero(&clp->cl_count)) 5977 - return -EIO; 5978 - data = kmalloc(sizeof(*data), GFP_NOFS); 5979 - if (data == NULL) { 5980 - nfs_put_client(clp); 5981 - return -ENOMEM; 5982 - } 5983 - data->client = clp; 5984 - data->timestamp = jiffies; 5985 - return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, 5986 - &nfs4_renew_ops, data); 5987 - } 5988 - 5989 - static int nfs4_proc_renew(struct nfs_client *clp, const struct cred *cred) 5990 - { 5991 - struct rpc_message msg = { 5992 - .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], 5993 - .rpc_argp = clp, 5994 - .rpc_cred = cred, 5995 - }; 5996 - unsigned long now = jiffies; 5997 - int status; 5998 - 5999 - status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 6000 - if (status < 0) 6001 - return status; 6002 - do_renew_lease(clp, now); 6003 - return 0; 6004 6009 } 6005 6010 6006 6011 static bool nfs4_server_supports_acls(const struct nfs_server *server, ··· 6868 7057 data->res.sattr_res = true; 6869 7058 } 6870 7059 6871 - if (!data->inode) 6872 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 6873 - 1); 6874 - else 6875 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 6876 - 0); 7060 + nfs4_init_sequence(server->nfs_client, &data->args.seq_args, 7061 + &data->res.seq_res, 1, !data->inode ? 1 : 0); 6877 7062 6878 7063 task_setup_data.callback_data = data; 6879 7064 msg.rpc_argp = &data->args; ··· 7148 7341 struct nfs_seqid *seqid) 7149 7342 { 7150 7343 struct nfs4_unlockdata *data; 7344 + struct nfs_client *clp = NFS_SERVER(lsp->ls_state->inode)->nfs_client; 7151 7345 struct rpc_message msg = { 7152 7346 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], 7153 7347 .rpc_cred = ctx->cred, ··· 7164 7356 if (nfs_server_capable(lsp->ls_state->inode, NFS_CAP_MOVEABLE)) 7165 7357 task_setup_data.flags |= RPC_TASK_MOVEABLE; 7166 7358 7167 - nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, 7168 - NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); 7359 + nfs4_state_protect(clp, NFS_SP4_MACH_CRED_CLEANUP, 7360 + &task_setup_data.rpc_client, &msg); 7169 7361 7170 7362 /* Ensure this is an unlock - when canceling a lock, the 7171 7363 * canceled lock is passed in, and it won't be an unlock. ··· 7180 7372 return ERR_PTR(-ENOMEM); 7181 7373 } 7182 7374 7183 - nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, 0); 7375 + nfs4_init_sequence(clp, &data->arg.seq_args, &data->res.seq_res, 1, 0); 7184 7376 msg.rpc_argp = &data->arg; 7185 7377 msg.rpc_resp = &data->res; 7186 7378 task_setup_data.callback_data = data; ··· 7430 7622 { 7431 7623 struct nfs4_lockdata *data; 7432 7624 struct rpc_task *task; 7625 + struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; 7433 7626 struct rpc_message msg = { 7434 7627 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], 7435 7628 .rpc_cred = state->owner->so_cred, ··· 7454 7645 return -ENOMEM; 7455 7646 if (IS_SETLKW(cmd)) 7456 7647 data->arg.block = 1; 7457 - nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, 7648 + nfs4_init_sequence(clp, &data->arg.seq_args, &data->res.seq_res, 1, 7458 7649 recovery_type > NFS_LOCK_NEW); 7459 7650 msg.rpc_argp = &data->arg; 7460 7651 msg.rpc_resp = &data->res; ··· 7481 7672 return ret; 7482 7673 } 7483 7674 7484 - static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) 7675 + int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) 7485 7676 { 7486 7677 struct nfs_server *server = NFS_SERVER(state->inode); 7487 7678 struct nfs4_exception exception = { ··· 7501 7692 return err; 7502 7693 } 7503 7694 7504 - static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) 7695 + int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) 7505 7696 { 7506 7697 struct nfs_server *server = NFS_SERVER(state->inode); 7507 7698 struct nfs4_exception exception = { ··· 7533 7724 return err; 7534 7725 } 7535 7726 7536 - #if defined(CONFIG_NFS_V4_1) 7537 7727 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) 7538 7728 { 7539 7729 struct nfs4_lock_state *lsp; ··· 7547 7739 return 0; 7548 7740 return nfs4_lock_expired(state, request); 7549 7741 } 7550 - #endif 7551 7742 7552 7743 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) 7553 7744 { ··· 7620 7813 return status; 7621 7814 } 7622 7815 7623 - #ifdef CONFIG_NFS_V4_1 7624 7816 struct nfs4_lock_waiter { 7625 7817 struct inode *inode; 7626 7818 struct nfs_lowner owner; ··· 7687 7881 7688 7882 return status; 7689 7883 } 7690 - #else /* !CONFIG_NFS_V4_1 */ 7691 - static inline int 7692 - nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) 7693 - { 7694 - return nfs4_retry_setlk_simple(state, cmd, request); 7695 - } 7696 - #endif 7697 7884 7698 7885 static int 7699 7886 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) ··· 7796 7997 return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); 7797 7998 } 7798 7999 7799 - struct nfs_release_lockowner_data { 7800 - struct nfs4_lock_state *lsp; 7801 - struct nfs_server *server; 7802 - struct nfs_release_lockowner_args args; 7803 - struct nfs_release_lockowner_res res; 7804 - unsigned long timestamp; 7805 - }; 7806 - 7807 - static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) 7808 - { 7809 - struct nfs_release_lockowner_data *data = calldata; 7810 - struct nfs_server *server = data->server; 7811 - nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, 7812 - &data->res.seq_res, task); 7813 - data->args.lock_owner.clientid = server->nfs_client->cl_clientid; 7814 - data->timestamp = jiffies; 7815 - } 7816 - 7817 - static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) 7818 - { 7819 - struct nfs_release_lockowner_data *data = calldata; 7820 - struct nfs_server *server = data->server; 7821 - 7822 - nfs40_sequence_done(task, &data->res.seq_res); 7823 - 7824 - switch (task->tk_status) { 7825 - case 0: 7826 - renew_lease(server, data->timestamp); 7827 - break; 7828 - case -NFS4ERR_STALE_CLIENTID: 7829 - case -NFS4ERR_EXPIRED: 7830 - nfs4_schedule_lease_recovery(server->nfs_client); 7831 - break; 7832 - case -NFS4ERR_LEASE_MOVED: 7833 - case -NFS4ERR_DELAY: 7834 - if (nfs4_async_handle_error(task, server, 7835 - NULL, NULL) == -EAGAIN) 7836 - rpc_restart_call_prepare(task); 7837 - } 7838 - } 7839 - 7840 - static void nfs4_release_lockowner_release(void *calldata) 7841 - { 7842 - struct nfs_release_lockowner_data *data = calldata; 7843 - nfs4_free_lock_state(data->server, data->lsp); 7844 - kfree(calldata); 7845 - } 7846 - 7847 - static const struct rpc_call_ops nfs4_release_lockowner_ops = { 7848 - .rpc_call_prepare = nfs4_release_lockowner_prepare, 7849 - .rpc_call_done = nfs4_release_lockowner_done, 7850 - .rpc_release = nfs4_release_lockowner_release, 7851 - }; 7852 - 7853 - static void 7854 - nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) 7855 - { 7856 - struct nfs_release_lockowner_data *data; 7857 - struct rpc_message msg = { 7858 - .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], 7859 - }; 7860 - 7861 - if (server->nfs_client->cl_mvops->minor_version != 0) 7862 - return; 7863 - 7864 - data = kmalloc(sizeof(*data), GFP_KERNEL); 7865 - if (!data) 7866 - return; 7867 - data->lsp = lsp; 7868 - data->server = server; 7869 - data->args.lock_owner.clientid = server->nfs_client->cl_clientid; 7870 - data->args.lock_owner.id = lsp->ls_seqid.owner_id; 7871 - data->args.lock_owner.s_dev = server->s_dev; 7872 - 7873 - msg.rpc_argp = &data->args; 7874 - msg.rpc_resp = &data->res; 7875 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); 7876 - rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); 7877 - } 7878 - 7879 8000 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" 7880 8001 7881 8002 static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, ··· 7819 8100 return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_ACL); 7820 8101 } 7821 8102 7822 - #if defined(CONFIG_NFS_V4_1) 7823 8103 #define XATTR_NAME_NFSV4_DACL "system.nfs4_dacl" 7824 8104 7825 8105 static int nfs4_xattr_set_nfs4_dacl(const struct xattr_handler *handler, ··· 7864 8146 { 7865 8147 return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_SACL); 7866 8148 } 7867 - 7868 - #endif 7869 8149 7870 8150 #ifdef CONFIG_NFS_V4_SECURITY_LABEL 7871 8151 ··· 8105 8389 8106 8390 /* 8107 8391 * This operation also signals the server that this client is 8108 - * performing migration recovery. The server can stop returning 8109 - * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is 8110 - * appended to this compound to identify the client ID which is 8111 - * performing recovery. 8112 - */ 8113 - static int _nfs40_proc_get_locations(struct nfs_server *server, 8114 - struct nfs_fh *fhandle, 8115 - struct nfs4_fs_locations *locations, 8116 - struct page *page, const struct cred *cred) 8117 - { 8118 - struct rpc_clnt *clnt = server->client; 8119 - u32 bitmask[2] = { 8120 - [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, 8121 - }; 8122 - struct nfs4_fs_locations_arg args = { 8123 - .clientid = server->nfs_client->cl_clientid, 8124 - .fh = fhandle, 8125 - .page = page, 8126 - .bitmask = bitmask, 8127 - .migration = 1, /* skip LOOKUP */ 8128 - .renew = 1, /* append RENEW */ 8129 - }; 8130 - struct nfs4_fs_locations_res res = { 8131 - .fs_locations = locations, 8132 - .migration = 1, 8133 - .renew = 1, 8134 - }; 8135 - struct rpc_message msg = { 8136 - .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], 8137 - .rpc_argp = &args, 8138 - .rpc_resp = &res, 8139 - .rpc_cred = cred, 8140 - }; 8141 - unsigned long now = jiffies; 8142 - int status; 8143 - 8144 - nfs_fattr_init(locations->fattr); 8145 - locations->server = server; 8146 - locations->nlocations = 0; 8147 - 8148 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); 8149 - status = nfs4_call_sync_sequence(clnt, server, &msg, 8150 - &args.seq_args, &res.seq_res); 8151 - if (status) 8152 - return status; 8153 - 8154 - renew_lease(server, now); 8155 - return 0; 8156 - } 8157 - 8158 - #ifdef CONFIG_NFS_V4_1 8159 - 8160 - /* 8161 - * This operation also signals the server that this client is 8162 8392 * performing migration recovery. The server can stop asserting 8163 8393 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID 8164 8394 * performing this operation is identified in the SEQUENCE ··· 8119 8457 struct page *page, const struct cred *cred) 8120 8458 { 8121 8459 struct rpc_clnt *clnt = server->client; 8460 + struct nfs_client *clp = server->nfs_client; 8122 8461 u32 bitmask[2] = { 8123 8462 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, 8124 8463 }; ··· 8147 8484 struct rpc_task_setup task_setup_data = { 8148 8485 .rpc_client = clnt, 8149 8486 .rpc_message = &msg, 8150 - .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, 8487 + .callback_ops = clp->cl_mvops->call_sync_ops, 8151 8488 .callback_data = &data, 8152 8489 .flags = RPC_TASK_NO_ROUND_ROBIN, 8153 8490 }; ··· 8157 8494 locations->server = server; 8158 8495 locations->nlocations = 0; 8159 8496 8160 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); 8497 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 1); 8161 8498 status = nfs4_call_sync_custom(&task_setup_data); 8162 8499 if (status == NFS4_OK && 8163 8500 res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) 8164 8501 status = -NFS4ERR_LEASE_MOVED; 8165 8502 return status; 8166 8503 } 8167 - 8168 - #endif /* CONFIG_NFS_V4_1 */ 8169 8504 8170 8505 /** 8171 8506 * nfs4_proc_get_locations - discover locations for a migrated FSID ··· 8214 8553 8215 8554 /* 8216 8555 * This operation also signals the server that this client is 8217 - * performing "lease moved" recovery. The server can stop 8218 - * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation 8219 - * is appended to this compound to identify the client ID which is 8220 - * performing recovery. 8221 - */ 8222 - static int _nfs40_proc_fsid_present(struct inode *inode, const struct cred *cred) 8223 - { 8224 - struct nfs_server *server = NFS_SERVER(inode); 8225 - struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 8226 - struct rpc_clnt *clnt = server->client; 8227 - struct nfs4_fsid_present_arg args = { 8228 - .fh = NFS_FH(inode), 8229 - .clientid = clp->cl_clientid, 8230 - .renew = 1, /* append RENEW */ 8231 - }; 8232 - struct nfs4_fsid_present_res res = { 8233 - .renew = 1, 8234 - }; 8235 - struct rpc_message msg = { 8236 - .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], 8237 - .rpc_argp = &args, 8238 - .rpc_resp = &res, 8239 - .rpc_cred = cred, 8240 - }; 8241 - unsigned long now = jiffies; 8242 - int status; 8243 - 8244 - res.fh = nfs_alloc_fhandle(); 8245 - if (res.fh == NULL) 8246 - return -ENOMEM; 8247 - 8248 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); 8249 - status = nfs4_call_sync_sequence(clnt, server, &msg, 8250 - &args.seq_args, &res.seq_res); 8251 - nfs_free_fhandle(res.fh); 8252 - if (status) 8253 - return status; 8254 - 8255 - do_renew_lease(clp, now); 8256 - return 0; 8257 - } 8258 - 8259 - #ifdef CONFIG_NFS_V4_1 8260 - 8261 - /* 8262 - * This operation also signals the server that this client is 8263 8556 * performing "lease moved" recovery. The server can stop asserting 8264 8557 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing 8265 8558 * this operation is identified in the SEQUENCE operation in this ··· 8240 8625 if (res.fh == NULL) 8241 8626 return -ENOMEM; 8242 8627 8243 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); 8628 + nfs4_init_sequence(server->nfs_client, &args.seq_args, &res.seq_res, 0, 1); 8244 8629 status = nfs4_call_sync_sequence(clnt, server, &msg, 8245 8630 &args.seq_args, &res.seq_res); 8246 8631 nfs_free_fhandle(res.fh); ··· 8249 8634 status = -NFS4ERR_LEASE_MOVED; 8250 8635 return status; 8251 8636 } 8252 - 8253 - #endif /* CONFIG_NFS_V4_1 */ 8254 8637 8255 8638 /** 8256 8639 * nfs4_proc_fsid_present - Is this FSID present or absent on server? ··· 8339 8726 dprintk("NFS call secinfo %s\n", name->name); 8340 8727 8341 8728 nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); 8342 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); 8729 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 0); 8343 8730 status = nfs4_call_sync_custom(&task_setup); 8344 8731 8345 8732 dprintk("NFS reply secinfo: %d\n", status); ··· 8378 8765 return err; 8379 8766 } 8380 8767 8381 - #ifdef CONFIG_NFS_V4_1 8382 8768 /* 8383 8769 * Check the exchange flags returned by the server for invalid flags, having 8384 8770 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or ··· 8990 9378 return ret; 8991 9379 } 8992 9380 8993 - #endif /* CONFIG_NFS_V4_1 */ 8994 - 8995 9381 struct nfs4_get_lease_time_data { 8996 9382 struct nfs4_get_lease_time_args *args; 8997 9383 struct nfs4_get_lease_time_res *res; ··· 9062 9452 .flags = RPC_TASK_TIMEOUT, 9063 9453 }; 9064 9454 9065 - nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); 9455 + nfs4_init_sequence(clp, &args.la_seq_args, &res.lr_seq_res, 0, 1); 9066 9456 return nfs4_call_sync_custom(&task_setup); 9067 9457 } 9068 - 9069 - #ifdef CONFIG_NFS_V4_1 9070 9458 9071 9459 /* 9072 9460 * Initialize the values to be used by the client in CREATE_SESSION ··· 9399 9791 calldata = kzalloc(sizeof(*calldata), GFP_KERNEL); 9400 9792 if (calldata == NULL) 9401 9793 goto out_put_clp; 9402 - nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); 9794 + nfs4_init_sequence(clp, &calldata->args, &calldata->res, 0, is_privileged); 9403 9795 nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); 9404 9796 msg.rpc_argp = &calldata->args; 9405 9797 msg.rpc_resp = &calldata->res; ··· 9549 9941 calldata->clp = clp; 9550 9942 calldata->arg.one_fs = 0; 9551 9943 9552 - nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0, 1); 9944 + nfs4_init_sequence(clp, &calldata->arg.seq_args, &calldata->res.seq_res, 0, 1); 9553 9945 msg.rpc_argp = &calldata->arg; 9554 9946 msg.rpc_resp = &calldata->res; 9555 9947 task_setup_data.callback_data = calldata; ··· 9713 10105 struct pnfs_layout_segment *lseg = NULL; 9714 10106 int status = 0; 9715 10107 9716 - nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0, 0); 10108 + nfs4_init_sequence(server->nfs_client, &lgp->args.seq_args, 10109 + &lgp->res.seq_res, 0, 0); 9717 10110 exception->retry = 0; 9718 10111 9719 10112 task = rpc_run_task(&task_setup_data); ··· 9849 10240 9850 10241 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, unsigned int flags) 9851 10242 { 10243 + struct nfs_client *clp = NFS_SERVER(lrp->args.inode)->nfs_client; 9852 10244 struct rpc_task *task; 9853 10245 struct rpc_message msg = { 9854 10246 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], ··· 9866 10256 }; 9867 10257 int status = 0; 9868 10258 9869 - nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, 9870 - NFS_SP4_MACH_CRED_PNFS_CLEANUP, 9871 - &task_setup_data.rpc_client, &msg); 10259 + nfs4_state_protect(clp, NFS_SP4_MACH_CRED_PNFS_CLEANUP, 10260 + &task_setup_data.rpc_client, &msg); 9872 10261 9873 10262 lrp->inode = nfs_igrab_and_active(lrp->args.inode); 9874 10263 if (flags & PNFS_FL_LAYOUTRETURN_ASYNC) { ··· 9879 10270 } 9880 10271 if (!lrp->inode) 9881 10272 flags |= PNFS_FL_LAYOUTRETURN_PRIVILEGED; 9882 - if (flags & PNFS_FL_LAYOUTRETURN_PRIVILEGED) 9883 - nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, 9884 - 1); 9885 - else 9886 - nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1, 9887 - 0); 10273 + 10274 + nfs4_init_sequence(clp, &lrp->args.seq_args, &lrp->res.seq_res, 1, 10275 + flags & PNFS_FL_LAYOUTRETURN_PRIVILEGED ? 1 : 0); 9888 10276 task = rpc_run_task(&task_setup_data); 9889 10277 if (IS_ERR(task)) 9890 10278 return PTR_ERR(task); ··· 10031 10425 } 10032 10426 task_setup_data.flags = RPC_TASK_ASYNC; 10033 10427 } 10034 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, 0); 10428 + nfs4_init_sequence(NFS_SERVER(data->args.inode)->nfs_client, 10429 + &data->args.seq_args, &data->res.seq_res, 1, 0); 10035 10430 task = rpc_run_task(&task_setup_data); 10036 10431 if (IS_ERR(task)) 10037 10432 return PTR_ERR(task); ··· 10053 10446 struct nfs4_secinfo_flavors *flavors, 10054 10447 bool use_integrity) 10055 10448 { 10449 + struct nfs_client *clp = server->nfs_client; 10056 10450 struct nfs41_secinfo_no_name_args args = { 10057 10451 .style = SECINFO_STYLE_CURRENT_FH, 10058 10452 }; ··· 10073 10465 struct rpc_task_setup task_setup = { 10074 10466 .rpc_client = server->client, 10075 10467 .rpc_message = &msg, 10076 - .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, 10468 + .callback_ops = clp->cl_mvops->call_sync_ops, 10077 10469 .callback_data = &data, 10078 10470 .flags = RPC_TASK_NO_ROUND_ROBIN, 10079 10471 }; ··· 10081 10473 int status; 10082 10474 10083 10475 if (use_integrity) { 10084 - task_setup.rpc_client = server->nfs_client->cl_rpcclient; 10476 + task_setup.rpc_client = clp->cl_rpcclient; 10085 10477 10086 - cred = nfs4_get_clid_cred(server->nfs_client); 10478 + cred = nfs4_get_clid_cred(clp); 10087 10479 msg.rpc_cred = cred; 10088 10480 } 10089 10481 10090 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); 10482 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 0); 10091 10483 status = nfs4_call_sync_custom(&task_setup); 10092 10484 dprintk("<-- %s status=%d\n", __func__, status); 10093 10485 ··· 10219 10611 .rpc_cred = cred, 10220 10612 }; 10221 10613 struct rpc_clnt *rpc_client = server->client; 10614 + struct nfs_client *clp = server->nfs_client; 10222 10615 10223 - nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, 10224 - &rpc_client, &msg); 10616 + nfs4_state_protect(clp, NFS_SP4_MACH_CRED_STATEID, &rpc_client, &msg); 10225 10617 10226 10618 dprintk("NFS call test_stateid %p\n", stateid); 10227 - nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); 10619 + nfs4_init_sequence(clp, &args.seq_args, &res.seq_res, 0, 1); 10228 10620 status = nfs4_call_sync_sequence(rpc_client, server, &msg, 10229 10621 &args.seq_args, &res.seq_res); 10230 10622 if (status != NFS_OK) { ··· 10354 10746 if (!refcount_inc_not_zero(&clp->cl_count)) 10355 10747 return -EIO; 10356 10748 10357 - nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, 10749 + nfs4_state_protect(clp, NFS_SP4_MACH_CRED_STATEID, 10358 10750 &task_setup.rpc_client, &msg); 10359 10751 10360 10752 dprintk("NFS call free_stateid %p\n", stateid); ··· 10368 10760 10369 10761 msg.rpc_argp = &data->args; 10370 10762 msg.rpc_resp = &data->res; 10371 - nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1, privileged); 10763 + nfs4_init_sequence(clp, &data->args.seq_args, &data->res.seq_res, 1, 10764 + privileged); 10372 10765 task = rpc_run_task(&task_setup); 10373 10766 if (IS_ERR(task)) 10374 10767 return PTR_ERR(task); ··· 10404 10795 return s1->seqid == 0 || s2->seqid == 0; 10405 10796 } 10406 10797 10407 - #endif /* CONFIG_NFS_V4_1 */ 10408 - 10409 - static bool nfs4_match_stateid(const nfs4_stateid *s1, 10798 + bool nfs4_match_stateid(const nfs4_stateid *s1, 10410 10799 const nfs4_stateid *s2) 10411 10800 { 10412 10801 trace_nfs4_match_stateid(s1, s2); ··· 10413 10806 } 10414 10807 10415 10808 10416 - static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { 10417 - .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 10418 - .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 10419 - .recover_open = nfs4_open_reclaim, 10420 - .recover_lock = nfs4_lock_reclaim, 10421 - .establish_clid = nfs4_init_clientid, 10422 - .detect_trunking = nfs40_discover_server_trunking, 10809 + static const struct nfs4_sequence_slot_ops nfs41_sequence_slot_ops = { 10810 + .process = nfs41_sequence_process, 10811 + .done = nfs41_sequence_done, 10812 + .free_slot = nfs41_sequence_free_slot, 10423 10813 }; 10424 10814 10425 - #if defined(CONFIG_NFS_V4_1) 10426 10815 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { 10427 10816 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 10428 10817 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, ··· 10428 10825 .reclaim_complete = nfs41_proc_reclaim_complete, 10429 10826 .detect_trunking = nfs41_discover_server_trunking, 10430 10827 }; 10431 - #endif /* CONFIG_NFS_V4_1 */ 10432 10828 10433 - static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { 10434 - .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 10435 - .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 10436 - .recover_open = nfs40_open_expired, 10437 - .recover_lock = nfs4_lock_expired, 10438 - .establish_clid = nfs4_init_clientid, 10439 - }; 10440 - 10441 - #if defined(CONFIG_NFS_V4_1) 10442 10829 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { 10443 10830 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 10444 10831 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, ··· 10436 10843 .recover_lock = nfs41_lock_expired, 10437 10844 .establish_clid = nfs41_init_clientid, 10438 10845 }; 10439 - #endif /* CONFIG_NFS_V4_1 */ 10440 10846 10441 - static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { 10442 - .sched_state_renewal = nfs4_proc_async_renew, 10443 - .get_state_renewal_cred = nfs4_get_renew_cred, 10444 - .renew_lease = nfs4_proc_renew, 10445 - }; 10446 - 10447 - #if defined(CONFIG_NFS_V4_1) 10448 10847 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { 10449 10848 .sched_state_renewal = nfs41_proc_async_sequence, 10450 10849 .get_state_renewal_cred = nfs4_get_machine_cred, 10451 10850 .renew_lease = nfs4_proc_sequence, 10452 10851 }; 10453 - #endif 10454 10852 10455 - static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { 10456 - .get_locations = _nfs40_proc_get_locations, 10457 - .fsid_present = _nfs40_proc_fsid_present, 10458 - }; 10459 - 10460 - #if defined(CONFIG_NFS_V4_1) 10461 10853 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { 10462 10854 .get_locations = _nfs41_proc_get_locations, 10463 10855 .fsid_present = _nfs41_proc_fsid_present, 10464 10856 }; 10465 - #endif /* CONFIG_NFS_V4_1 */ 10466 10857 10467 - static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { 10468 - .minor_version = 0, 10469 - .init_caps = NFS_CAP_READDIRPLUS 10470 - | NFS_CAP_ATOMIC_OPEN 10471 - | NFS_CAP_POSIX_LOCK, 10472 - .init_client = nfs40_init_client, 10473 - .shutdown_client = nfs40_shutdown_client, 10474 - .match_stateid = nfs4_match_stateid, 10475 - .find_root_sec = nfs4_find_root_sec, 10476 - .free_lock_state = nfs4_release_lockowner, 10477 - .test_and_free_expired = nfs40_test_and_free_expired_stateid, 10478 - .alloc_seqid = nfs_alloc_seqid, 10479 - .call_sync_ops = &nfs40_call_sync_ops, 10480 - .reboot_recovery_ops = &nfs40_reboot_recovery_ops, 10481 - .nograce_recovery_ops = &nfs40_nograce_recovery_ops, 10482 - .state_renewal_ops = &nfs40_state_renewal_ops, 10483 - .mig_recovery_ops = &nfs40_mig_recovery_ops, 10484 - }; 10485 - 10486 - #if defined(CONFIG_NFS_V4_1) 10487 10858 static struct nfs_seqid * 10488 10859 nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) 10489 10860 { ··· 10473 10916 .alloc_seqid = nfs_alloc_no_seqid, 10474 10917 .session_trunk = nfs4_test_session_trunk, 10475 10918 .call_sync_ops = &nfs41_call_sync_ops, 10919 + .sequence_slot_ops = &nfs41_sequence_slot_ops, 10476 10920 .reboot_recovery_ops = &nfs41_reboot_recovery_ops, 10477 10921 .nograce_recovery_ops = &nfs41_nograce_recovery_ops, 10478 10922 .state_renewal_ops = &nfs41_state_renewal_ops, 10479 10923 .mig_recovery_ops = &nfs41_mig_recovery_ops, 10480 10924 }; 10481 - #endif 10482 10925 10483 10926 #if defined(CONFIG_NFS_V4_2) 10484 10927 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { ··· 10509 10952 .find_root_sec = nfs41_find_root_sec, 10510 10953 .free_lock_state = nfs41_free_lock_state, 10511 10954 .call_sync_ops = &nfs41_call_sync_ops, 10955 + .sequence_slot_ops = &nfs41_sequence_slot_ops, 10512 10956 .test_and_free_expired = nfs41_test_and_free_expired_stateid, 10513 10957 .alloc_seqid = nfs_alloc_no_seqid, 10514 10958 .session_trunk = nfs4_test_session_trunk, ··· 10521 10963 #endif 10522 10964 10523 10965 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { 10966 + #if defined(CONFIG_NFS_V4_0) 10524 10967 [0] = &nfs_v4_0_minor_ops, 10525 - #if defined(CONFIG_NFS_V4_1) 10968 + #endif /* CONFIG_NFS_V4_0 */ 10526 10969 [1] = &nfs_v4_1_minor_ops, 10527 - #endif 10528 10970 #if defined(CONFIG_NFS_V4_2) 10529 10971 [2] = &nfs_v4_2_minor_ops, 10530 10972 #endif ··· 10692 11134 .set = nfs4_xattr_set_nfs4_acl, 10693 11135 }; 10694 11136 10695 - #if defined(CONFIG_NFS_V4_1) 10696 11137 static const struct xattr_handler nfs4_xattr_nfs4_dacl_handler = { 10697 11138 .name = XATTR_NAME_NFSV4_DACL, 10698 11139 .list = nfs4_xattr_list_nfs4_dacl, ··· 10705 11148 .get = nfs4_xattr_get_nfs4_sacl, 10706 11149 .set = nfs4_xattr_set_nfs4_sacl, 10707 11150 }; 10708 - #endif 10709 11151 10710 11152 #ifdef CONFIG_NFS_V4_2 10711 11153 static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { ··· 10716 11160 10717 11161 const struct xattr_handler * const nfs4_xattr_handlers[] = { 10718 11162 &nfs4_xattr_nfs4_acl_handler, 10719 - #if defined(CONFIG_NFS_V4_1) 10720 11163 &nfs4_xattr_nfs4_dacl_handler, 10721 11164 &nfs4_xattr_nfs4_sacl_handler, 10722 - #endif 10723 11165 #ifdef CONFIG_NFS_V4_SECURITY_LABEL 10724 11166 &nfs4_xattr_nfs4_label_handler, 10725 11167 #endif
+12 -3
fs/nfs/nfs4renewd.c
··· 133 133 cancel_delayed_work_sync(&clp->cl_renewd); 134 134 } 135 135 136 + #define MAX_LEASE_PERIOD (60 * 60) /* 1 hour */ 137 + 136 138 /** 137 139 * nfs4_set_lease_period - Sets the lease period on a nfs_client 138 140 * 139 141 * @clp: pointer to nfs_client 140 - * @lease: new value for lease period 142 + * @period: new value for lease period (in seconds) 141 143 */ 142 - void nfs4_set_lease_period(struct nfs_client *clp, 143 - unsigned long lease) 144 + void nfs4_set_lease_period(struct nfs_client *clp, u32 period) 144 145 { 146 + unsigned long lease; 147 + 148 + /* Limit the lease period */ 149 + if (period < MAX_LEASE_PERIOD) 150 + lease = period * HZ; 151 + else 152 + lease = MAX_LEASE_PERIOD * HZ; 153 + 145 154 spin_lock(&clp->cl_lock); 146 155 clp->cl_lease_time = lease; 147 156 spin_unlock(&clp->cl_lock);
-4
fs/nfs/nfs4session.c
··· 408 408 } 409 409 } 410 410 411 - #if defined(CONFIG_NFS_V4_1) 412 - 413 411 static void nfs41_set_max_slotid_locked(struct nfs4_slot_table *tbl, 414 412 u32 target_highest_slotid) 415 413 { ··· 651 653 return 0; 652 654 } 653 655 EXPORT_SYMBOL_GPL(nfs4_init_ds_session); 654 - 655 - #endif /* defined(CONFIG_NFS_V4_1) */
-23
fs/nfs/nfs4session.h
··· 111 111 return clp->cl_session; 112 112 } 113 113 114 - #if defined(CONFIG_NFS_V4_1) 115 114 extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl, 116 115 u32 target_highest_slotid); 117 116 extern void nfs41_update_target_slotid(struct nfs4_slot_table *tbl, ··· 153 154 */ 154 155 #define nfs_session_id_hash(sess_id) \ 155 156 (~crc32_le(0xFFFFFFFF, &(sess_id)->data[0], sizeof((sess_id)->data))) 156 - #else /* defined(CONFIG_NFS_V4_1) */ 157 157 158 - static inline int nfs4_init_session(struct nfs_client *clp) 159 - { 160 - return 0; 161 - } 162 - 163 - /* 164 - * Determine if sessions are in use. 165 - */ 166 - static inline int nfs4_has_session(const struct nfs_client *clp) 167 - { 168 - return 0; 169 - } 170 - 171 - static inline int nfs4_has_persistent_session(const struct nfs_client *clp) 172 - { 173 - return 0; 174 - } 175 - 176 - #define nfs_session_id_hash(session) (0) 177 - 178 - #endif /* defined(CONFIG_NFS_V4_1) */ 179 158 #endif /* IS_ENABLED(CONFIG_NFS_V4) */ 180 159 #endif /* __LINUX_FS_NFS_NFS4SESSION_H */
+4 -89
fs/nfs/nfs4state.c
··· 54 54 #include <linux/sunrpc/clnt.h> 55 55 56 56 #include "nfs4_fs.h" 57 + #include "nfs40.h" 57 58 #include "callback.h" 58 59 #include "delegation.h" 59 60 #include "internal.h" ··· 104 103 105 104 status = nfs4_proc_get_lease_time(clp, &fsinfo); 106 105 if (status == 0) { 107 - nfs4_set_lease_period(clp, fsinfo.lease_time * HZ); 106 + nfs4_set_lease_period(clp, fsinfo.lease_time); 108 107 nfs4_schedule_state_renewal(clp); 109 108 } 110 109 ··· 139 138 goto out; 140 139 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); 141 140 nfs4_setup_state_renewal(clp); 142 - out: 143 - return status; 144 - } 145 - 146 - /** 147 - * nfs40_discover_server_trunking - Detect server IP address trunking (mv0) 148 - * 149 - * @clp: nfs_client under test 150 - * @result: OUT: found nfs_client, or clp 151 - * @cred: credential to use for trunking test 152 - * 153 - * Returns zero, a negative errno, or a negative NFS4ERR status. 154 - * If zero is returned, an nfs_client pointer is planted in 155 - * "result". 156 - * 157 - * Note: The returned client may not yet be marked ready. 158 - */ 159 - int nfs40_discover_server_trunking(struct nfs_client *clp, 160 - struct nfs_client **result, 161 - const struct cred *cred) 162 - { 163 - struct nfs4_setclientid_res clid = { 164 - .clientid = clp->cl_clientid, 165 - .confirm = clp->cl_confirm, 166 - }; 167 - struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); 168 - unsigned short port; 169 - int status; 170 - 171 - port = nn->nfs_callback_tcpport; 172 - if (clp->cl_addr.ss_family == AF_INET6) 173 - port = nn->nfs_callback_tcpport6; 174 - 175 - status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred, &clid); 176 - if (status != 0) 177 - goto out; 178 - clp->cl_clientid = clid.clientid; 179 - clp->cl_confirm = clid.confirm; 180 - 181 - status = nfs40_walk_client_list(clp, result, cred); 182 - if (status == 0) { 183 - /* Sustain the lease, even if it's empty. If the clientid4 184 - * goes stale it's of no use for trunking discovery. */ 185 - nfs4_schedule_state_renewal(*result); 186 - 187 - /* If the client state need to recover, do it. */ 188 - if (clp->cl_state) 189 - nfs4_schedule_state_manager(clp); 190 - } 191 141 out: 192 142 return status; 193 143 } ··· 259 307 return nfs4_drain_slot_tbl(&ses->fc_slot_table); 260 308 } 261 309 262 - #if defined(CONFIG_NFS_V4_1) 263 - 264 310 static void nfs41_finish_session_reset(struct nfs_client *clp) 265 311 { 266 312 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); ··· 336 386 nfs_put_client(clp); 337 387 return status; 338 388 } 339 - 340 - #endif /* CONFIG_NFS_V4_1 */ 341 389 342 390 /** 343 391 * nfs4_get_clid_cred - Acquire credential for a setclientid operation ··· 1291 1343 return ret; 1292 1344 } 1293 1345 1294 - /* 1295 - * nfs40_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN 1296 - * @clp: client to process 1297 - * 1298 - * Set the NFS4CLNT_LEASE_EXPIRED state in order to force a 1299 - * resend of the SETCLIENTID and hence re-establish the 1300 - * callback channel. Then return all existing delegations. 1301 - */ 1302 - static void nfs40_handle_cb_pathdown(struct nfs_client *clp) 1303 - { 1304 - set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1305 - nfs_expire_all_delegations(clp); 1306 - dprintk("%s: handling CB_PATHDOWN recovery for server %s\n", __func__, 1307 - clp->cl_hostname); 1308 - } 1309 - 1310 - void nfs4_schedule_path_down_recovery(struct nfs_client *clp) 1311 - { 1312 - nfs40_handle_cb_pathdown(clp); 1313 - nfs4_schedule_state_manager(clp); 1314 - } 1315 - 1316 1346 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) 1317 1347 { 1318 1348 ··· 1800 1874 switch (error) { 1801 1875 case 0: 1802 1876 break; 1877 + #if IS_ENABLED(CONFIG_NFS_V4_0) 1803 1878 case -NFS4ERR_CB_PATH_DOWN: 1804 1879 nfs40_handle_cb_pathdown(clp); 1805 1880 break; 1881 + #endif /* CONFIG_NFS_V4_0 */ 1806 1882 case -NFS4ERR_NO_GRACE: 1807 1883 nfs4_state_end_reclaim_reboot(clp); 1808 1884 break; ··· 2306 2378 return status; 2307 2379 } 2308 2380 2309 - #ifdef CONFIG_NFS_V4_1 2310 2381 void nfs4_schedule_session_recovery(struct nfs4_session *session, int err) 2311 2382 { 2312 2383 struct nfs_client *clp = session->clp; ··· 2512 2585 set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); 2513 2586 } 2514 2587 } 2515 - #else /* CONFIG_NFS_V4_1 */ 2516 - static int nfs4_reset_session(struct nfs_client *clp) { return 0; } 2517 - 2518 - static int nfs4_bind_conn_to_session(struct nfs_client *clp) 2519 - { 2520 - return 0; 2521 - } 2522 - 2523 - static void nfs4_layoutreturn_any_run(struct nfs_client *clp) 2524 - { 2525 - } 2526 - #endif /* CONFIG_NFS_V4_1 */ 2527 2588 2528 2589 static void nfs4_state_manager(struct nfs_client *clp) 2529 2590 {
-2
fs/nfs/nfs4trace.c
··· 14 14 #define CREATE_TRACE_POINTS 15 15 #include "nfs4trace.h" 16 16 17 - #ifdef CONFIG_NFS_V4_1 18 17 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs4_pnfs_read); 19 18 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs4_pnfs_write); 20 19 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs4_pnfs_commit_ds); ··· 38 39 EXPORT_TRACEPOINT_SYMBOL_GPL(bl_pr_key_unreg_err); 39 40 40 41 EXPORT_TRACEPOINT_SYMBOL_GPL(fl_getdevinfo); 41 - #endif
+1 -20
fs/nfs/nfs4trace.h
··· 71 71 DEFINE_NFS4_CLIENTID_EVENT(nfs4_setclientid_confirm); 72 72 DEFINE_NFS4_CLIENTID_EVENT(nfs4_renew); 73 73 DEFINE_NFS4_CLIENTID_EVENT(nfs4_renew_async); 74 - #ifdef CONFIG_NFS_V4_1 75 74 DEFINE_NFS4_CLIENTID_EVENT(nfs4_exchange_id); 76 75 DEFINE_NFS4_CLIENTID_EVENT(nfs4_create_session); 77 76 DEFINE_NFS4_CLIENTID_EVENT(nfs4_destroy_session); ··· 300 301 __entry->status 301 302 ) 302 303 ); 303 - 304 - #endif /* CONFIG_NFS_V4_1 */ 305 304 306 305 TRACE_EVENT(nfs4_setup_sequence, 307 306 TP_PROTO( ··· 987 990 #define show_delegation_flags(flags) \ 988 991 __print_flags(flags, "|", \ 989 992 { BIT(NFS_DELEGATION_NEED_RECLAIM), "NEED_RECLAIM" }, \ 990 - { BIT(NFS_DELEGATION_RETURN), "RETURN" }, \ 991 993 { BIT(NFS_DELEGATION_RETURN_IF_CLOSED), "RETURN_IF_CLOSED" }, \ 992 994 { BIT(NFS_DELEGATION_REFERENCED), "REFERENCED" }, \ 993 995 { BIT(NFS_DELEGATION_RETURNING), "RETURNING" }, \ 994 996 { BIT(NFS_DELEGATION_REVOKED), "REVOKED" }, \ 995 - { BIT(NFS_DELEGATION_TEST_EXPIRED), "TEST_EXPIRED" }, \ 996 - { BIT(NFS_DELEGATION_INODE_FREEING), "INODE_FREEING" }, \ 997 - { BIT(NFS_DELEGATION_RETURN_DELAYED), "RETURN_DELAYED" }) 997 + { BIT(NFS_DELEGATION_TEST_EXPIRED), "TEST_EXPIRED" }) 998 998 999 999 DECLARE_EVENT_CLASS(nfs4_delegation_event, 1000 1000 TP_PROTO( ··· 1064 1070 ) 1065 1071 ); 1066 1072 1067 - #ifdef CONFIG_NFS_V4_1 1068 1073 DECLARE_EVENT_CLASS(nfs4_test_stateid_event, 1069 1074 TP_PROTO( 1070 1075 const struct nfs4_state *state, ··· 1118 1125 DEFINE_NFS4_TEST_STATEID_EVENT(nfs4_test_delegation_stateid); 1119 1126 DEFINE_NFS4_TEST_STATEID_EVENT(nfs4_test_open_stateid); 1120 1127 DEFINE_NFS4_TEST_STATEID_EVENT(nfs4_test_lock_stateid); 1121 - #endif /* CONFIG_NFS_V4_1 */ 1122 1128 1123 1129 DECLARE_EVENT_CLASS(nfs4_lookup_event, 1124 1130 TP_PROTO( ··· 1620 1628 DEFINE_NFS4_IDMAP_EVENT(nfs4_map_uid_to_name); 1621 1629 DEFINE_NFS4_IDMAP_EVENT(nfs4_map_gid_to_group); 1622 1630 1623 - #ifdef CONFIG_NFS_V4_1 1624 1631 #define NFS4_LSEG_LAYOUT_STATEID_HASH(lseg) \ 1625 1632 (lseg ? nfs_stateid_hash(&lseg->pls_layout->plh_stateid) : 0) 1626 - #else 1627 - #define NFS4_LSEG_LAYOUT_STATEID_HASH(lseg) (0) 1628 - #endif 1629 1633 1630 1634 DECLARE_EVENT_CLASS(nfs4_read_event, 1631 1635 TP_PROTO( ··· 1693 1705 ), \ 1694 1706 TP_ARGS(hdr, error)) 1695 1707 DEFINE_NFS4_READ_EVENT(nfs4_read); 1696 - #ifdef CONFIG_NFS_V4_1 1697 1708 DEFINE_NFS4_READ_EVENT(nfs4_pnfs_read); 1698 - #endif /* CONFIG_NFS_V4_1 */ 1699 1709 1700 1710 DECLARE_EVENT_CLASS(nfs4_write_event, 1701 1711 TP_PROTO( ··· 1766 1780 ), \ 1767 1781 TP_ARGS(hdr, error)) 1768 1782 DEFINE_NFS4_WRITE_EVENT(nfs4_write); 1769 - #ifdef CONFIG_NFS_V4_1 1770 1783 DEFINE_NFS4_WRITE_EVENT(nfs4_pnfs_write); 1771 - #endif /* CONFIG_NFS_V4_1 */ 1772 1784 1773 1785 DECLARE_EVENT_CLASS(nfs4_commit_event, 1774 1786 TP_PROTO( ··· 1826 1842 ), \ 1827 1843 TP_ARGS(data, error)) 1828 1844 DEFINE_NFS4_COMMIT_EVENT(nfs4_commit); 1829 - #ifdef CONFIG_NFS_V4_1 1830 1845 DEFINE_NFS4_COMMIT_EVENT(nfs4_pnfs_commit_ds); 1831 1846 1832 1847 TRACE_EVENT(nfs4_layoutget, ··· 2858 2875 2859 2876 DEFINE_NFS4_INODE_EVENT(nfs4_listxattr); 2860 2877 #endif /* CONFIG_NFS_V4_2 */ 2861 - 2862 - #endif /* CONFIG_NFS_V4_1 */ 2863 2878 2864 2879 #endif /* _TRACE_NFS4_H */ 2865 2880
+21 -88
fs/nfs/nfs4xdr.c
··· 308 308 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz) 309 309 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4)) 310 310 311 - #if defined(CONFIG_NFS_V4_1) 312 311 #define NFS4_MAX_MACHINE_NAME_LEN (64) 313 312 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 314 313 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) ··· 454 455 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \ 455 456 XDR_QUADLEN(NFS4_STATEID_SIZE)) 456 457 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz) 457 - #else /* CONFIG_NFS_V4_1 */ 458 - #define encode_sequence_maxsz 0 459 - #define decode_sequence_maxsz 0 460 - #define encode_get_dir_deleg_maxsz 0 461 - #define decode_get_dir_deleg_maxsz 0 462 - #define encode_layoutreturn_maxsz 0 463 - #define decode_layoutreturn_maxsz 0 464 - #define encode_layoutget_maxsz 0 465 - #define decode_layoutget_maxsz 0 466 - #endif /* CONFIG_NFS_V4_1 */ 467 458 468 459 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ 469 460 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */ ··· 827 838 decode_putfh_maxsz + \ 828 839 decode_getfh_maxsz + \ 829 840 decode_renew_maxsz) 830 - #if defined(CONFIG_NFS_V4_1) 831 841 #define NFS4_enc_bind_conn_to_session_sz \ 832 842 (compound_encode_hdr_maxsz + \ 833 843 encode_bind_conn_to_session_maxsz) ··· 859 871 #define NFS4_dec_sequence_sz \ 860 872 (compound_decode_hdr_maxsz + \ 861 873 decode_sequence_maxsz) 862 - #endif 863 874 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \ 864 875 encode_sequence_maxsz + \ 865 876 encode_putrootfh_maxsz + \ ··· 867 880 decode_sequence_maxsz + \ 868 881 decode_putrootfh_maxsz + \ 869 882 decode_fsinfo_maxsz) 870 - #if defined(CONFIG_NFS_V4_1) 871 883 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \ 872 884 encode_sequence_maxsz + \ 873 885 encode_reclaim_complete_maxsz) ··· 944 958 decode_sequence_maxsz) * 945 959 XDR_UNIT); 946 960 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); 947 - #endif /* CONFIG_NFS_V4_1 */ 948 961 949 962 static const umode_t nfs_type2fmt[] = { 950 963 [NF4BAD] = 0, ··· 1384 1399 xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1385 1400 } 1386 1401 1402 + #if defined(CONFIG_NFS_V4_0) 1387 1403 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1388 1404 { 1389 1405 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr); 1390 1406 encode_lockowner(xdr, lowner); 1391 1407 } 1408 + #endif /* CONFIG_NFS_V4_0 */ 1392 1409 1393 1410 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1394 1411 { ··· 1819 1832 encode_string(xdr, name->len, name->name); 1820 1833 } 1821 1834 1822 - #if defined(CONFIG_NFS_V4_1) 1823 1835 /* NFSv4.1 operations */ 1824 1836 static void encode_bind_conn_to_session(struct xdr_stream *xdr, 1825 1837 const struct nfs41_bind_conn_to_session_args *args, ··· 1970 1984 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr); 1971 1985 encode_uint32(xdr, args->one_fs); 1972 1986 } 1973 - #endif /* CONFIG_NFS_V4_1 */ 1974 1987 1975 1988 static void encode_sequence(struct xdr_stream *xdr, 1976 1989 const struct nfs4_sequence_args *args, 1977 1990 struct compound_hdr *hdr) 1978 1991 { 1979 - #if defined(CONFIG_NFS_V4_1) 1980 1992 struct nfs4_session *session; 1981 1993 struct nfs4_slot_table *tp; 1982 1994 struct nfs4_slot *slot = args->sa_slot; ··· 2005 2021 *p++ = cpu_to_be32(slot->slot_nr); 2006 2022 *p++ = cpu_to_be32(tp->highest_used_slotid); 2007 2023 *p = cpu_to_be32(args->sa_cache_this); 2008 - #endif /* CONFIG_NFS_V4_1 */ 2009 2024 } 2010 2025 2011 - #ifdef CONFIG_NFS_V4_1 2012 2026 static void 2013 2027 encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) 2014 2028 { ··· 2168 2186 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr); 2169 2187 encode_nfs4_stateid(xdr, &args->stateid); 2170 2188 } 2171 - #else 2172 - static inline void 2173 - encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) 2174 - { 2175 - } 2176 - 2177 - static inline void 2178 - encode_layoutreturn(struct xdr_stream *xdr, 2179 - const struct nfs4_layoutreturn_args *args, 2180 - struct compound_hdr *hdr) 2181 - { 2182 - } 2183 - 2184 - static void 2185 - encode_layoutget(struct xdr_stream *xdr, 2186 - const struct nfs4_layoutget_args *args, 2187 - struct compound_hdr *hdr) 2188 - { 2189 - } 2190 - #endif /* CONFIG_NFS_V4_1 */ 2191 2189 2192 2190 /* 2193 2191 * END OF "GENERIC" ENCODE ROUTINES. ··· 2175 2213 2176 2214 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 2177 2215 { 2178 - #if defined(CONFIG_NFS_V4_1) 2179 2216 struct nfs4_session *session = args->sa_slot->table->session; 2180 2217 if (session) 2181 2218 return session->clp->cl_mvops->minor_version; 2182 - #endif /* CONFIG_NFS_V4_1 */ 2183 2219 return 0; 2184 2220 } 2185 2221 ··· 2543 2583 encode_nops(&hdr); 2544 2584 } 2545 2585 2586 + #if defined(CONFIG_NFS_V4_0) 2546 2587 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, 2547 2588 struct xdr_stream *xdr, 2548 2589 const void *data) ··· 2557 2596 encode_release_lockowner(xdr, &args->lock_owner, &hdr); 2558 2597 encode_nops(&hdr); 2559 2598 } 2599 + #endif /* CONFIG_NFS_V4_0 */ 2560 2600 2561 2601 /* 2562 2602 * Encode a READLINK request ··· 2787 2825 /* 2788 2826 * a RENEW request 2789 2827 */ 2828 + #if defined(CONFIG_NFS_V4_0) 2790 2829 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, 2791 2830 const void *data) 2792 2831 ··· 2801 2838 encode_renew(xdr, clp->cl_clientid, &hdr); 2802 2839 encode_nops(&hdr); 2803 2840 } 2841 + #endif /* CONFIG_NFS_V4_0 */ 2804 2842 2805 2843 /* 2806 2844 * a SETCLIENTID request ··· 2935 2971 encode_nops(&hdr); 2936 2972 } 2937 2973 2938 - #if defined(CONFIG_NFS_V4_1) 2939 2974 /* 2940 2975 * BIND_CONN_TO_SESSION request 2941 2976 */ ··· 3036 3073 encode_nops(&hdr); 3037 3074 } 3038 3075 3039 - #endif 3040 - 3041 3076 /* 3042 3077 * a GET_LEASE_TIME request 3043 3078 */ ··· 3055 3094 encode_fsinfo(xdr, lease_bitmap, &hdr); 3056 3095 encode_nops(&hdr); 3057 3096 } 3058 - 3059 - #ifdef CONFIG_NFS_V4_1 3060 3097 3061 3098 /* 3062 3099 * a RECLAIM_COMPLETE request ··· 3218 3259 encode_free_stateid(xdr, args, &hdr); 3219 3260 encode_nops(&hdr); 3220 3261 } 3221 - #endif /* CONFIG_NFS_V4_1 */ 3222 3262 3223 3263 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) 3224 3264 { ··· 5182 5224 return status; 5183 5225 } 5184 5226 5227 + #if defined(CONFIG_NFS_V4_0) 5185 5228 static int decode_release_lockowner(struct xdr_stream *xdr) 5186 5229 { 5187 5230 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER); 5188 5231 } 5232 + #endif /* CONFIG_NFS_V4_0 */ 5189 5233 5190 5234 static int decode_lookup(struct xdr_stream *xdr) 5191 5235 { ··· 5716 5756 return decode_secinfo_common(xdr, res); 5717 5757 } 5718 5758 5719 - #if defined(CONFIG_NFS_V4_1) 5720 5759 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res) 5721 5760 { 5722 5761 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME); ··· 5927 5968 { 5928 5969 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE); 5929 5970 } 5930 - #endif /* CONFIG_NFS_V4_1 */ 5931 5971 5932 5972 static int decode_sequence(struct xdr_stream *xdr, 5933 5973 struct nfs4_sequence_res *res, 5934 5974 struct rpc_rqst *rqstp) 5935 5975 { 5936 - #if defined(CONFIG_NFS_V4_1) 5937 5976 struct nfs4_session *session; 5938 5977 struct nfs4_sessionid id; 5939 5978 u32 dummy; ··· 5991 6034 out_overflow: 5992 6035 status = -EIO; 5993 6036 goto out_err; 5994 - #else /* CONFIG_NFS_V4_1 */ 5995 - return 0; 5996 - #endif /* CONFIG_NFS_V4_1 */ 5997 6037 } 5998 6038 5999 - #if defined(CONFIG_NFS_V4_1) 6000 6039 static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 6001 6040 { 6002 6041 stateid->type = NFS4_LAYOUT_STATEID_TYPE; ··· 6255 6302 res->status = decode_op_hdr(xdr, OP_FREE_STATEID); 6256 6303 return res->status; 6257 6304 } 6258 - #else 6259 - static int decode_get_dir_delegation(struct xdr_stream *xdr, 6260 - struct nfs4_getattr_res *res) 6261 - { 6262 - return 0; 6263 - } 6264 - 6265 - static inline 6266 - int decode_layoutreturn(struct xdr_stream *xdr, 6267 - struct nfs4_layoutreturn_res *res) 6268 - { 6269 - return 0; 6270 - } 6271 - 6272 - static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, 6273 - struct nfs4_layoutget_res *res) 6274 - { 6275 - return 0; 6276 - } 6277 - 6278 - #endif /* CONFIG_NFS_V4_1 */ 6279 6305 6280 6306 /* 6281 6307 * END OF "GENERIC" DECODE ROUTINES. ··· 6862 6930 return status; 6863 6931 } 6864 6932 6933 + #if defined(CONFIG_NFS_V4_0) 6865 6934 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, 6866 6935 struct xdr_stream *xdr, void *dummy) 6867 6936 { ··· 6874 6941 status = decode_release_lockowner(xdr); 6875 6942 return status; 6876 6943 } 6944 + #endif /* CONFIG_NFS_V4_0 */ 6877 6945 6878 6946 /* 6879 6947 * Decode READLINK response ··· 7096 7162 /* 7097 7163 * Decode RENEW response 7098 7164 */ 7165 + #if defined(CONFIG_NFS_V4_0) 7099 7166 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, 7100 7167 void *__unused) 7101 7168 { ··· 7108 7173 status = decode_renew(xdr); 7109 7174 return status; 7110 7175 } 7176 + #endif /* CONFIG_NFS_V4_0 */ 7111 7177 7112 7178 /* 7113 7179 * Decode SETCLIENTID response ··· 7283 7347 return status; 7284 7348 } 7285 7349 7286 - #if defined(CONFIG_NFS_V4_1) 7287 7350 /* 7288 7351 * Decode BIND_CONN_TO_SESSION response 7289 7352 */ ··· 7379 7444 return status; 7380 7445 } 7381 7446 7382 - #endif 7383 - 7384 7447 /* 7385 7448 * Decode GET_LEASE_TIME response 7386 7449 */ ··· 7399 7466 status = decode_fsinfo(xdr, res->lr_fsinfo); 7400 7467 return status; 7401 7468 } 7402 - 7403 - #ifdef CONFIG_NFS_V4_1 7404 7469 7405 7470 /* 7406 7471 * Decode RECLAIM_COMPLETE response ··· 7587 7656 out: 7588 7657 return status; 7589 7658 } 7590 - #endif /* CONFIG_NFS_V4_1 */ 7591 7659 7592 7660 /** 7593 7661 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in ··· 7684 7754 .p_name = #proc, \ 7685 7755 } 7686 7756 7687 - #if defined(CONFIG_NFS_V4_1) 7688 - #define PROC41(proc, argtype, restype) \ 7757 + #if defined(CONFIG_NFS_V4_0) 7758 + #define PROC40(proc, argtype, restype) \ 7689 7759 PROC(proc, argtype, restype) 7690 7760 #else 7691 - #define PROC41(proc, argtype, restype) \ 7761 + #define PROC40(proc, argtype, restype) \ 7692 7762 STUB(proc) 7693 - #endif 7763 + #endif /* CONFIG_NFS_V4_0 */ 7764 + 7765 + #define PROC41(proc, argtype, restype) \ 7766 + PROC(proc, argtype, restype) 7694 7767 7695 7768 #if defined(CONFIG_NFS_V4_2) 7696 7769 #define PROC42(proc, argtype, restype) \ ··· 7714 7781 PROC(CLOSE, enc_close, dec_close), 7715 7782 PROC(SETATTR, enc_setattr, dec_setattr), 7716 7783 PROC(FSINFO, enc_fsinfo, dec_fsinfo), 7717 - PROC(RENEW, enc_renew, dec_renew), 7784 + PROC40(RENEW, enc_renew, dec_renew), 7718 7785 PROC(SETCLIENTID, enc_setclientid, dec_setclientid), 7719 7786 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), 7720 7787 PROC(LOCK, enc_lock, dec_lock), ··· 7738 7805 PROC(GETACL, enc_getacl, dec_getacl), 7739 7806 PROC(SETACL, enc_setacl, dec_setacl), 7740 7807 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), 7741 - PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 7808 + PROC40(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), 7742 7809 PROC(SECINFO, enc_secinfo, dec_secinfo), 7743 7810 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present), 7744 7811 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
+2 -1
fs/nfs/pnfs.c
··· 463 463 }; 464 464 struct pnfs_layout_segment *lseg, *next; 465 465 466 - set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags); 466 + if (test_and_set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) 467 + return !list_empty(&lo->plh_segs); 467 468 clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(lo->plh_inode)->flags); 468 469 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) 469 470 pnfs_clear_lseg_state(lseg, lseg_list);
+3 -3
fs/nfs/pnfs.h
··· 84 84 PNFS_TRY_AGAIN = 2, 85 85 }; 86 86 87 - #ifdef CONFIG_NFS_V4_1 87 + #if IS_ENABLED(CONFIG_NFS_V4) 88 88 89 89 #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4" 90 90 ··· 704 704 } 705 705 706 706 #endif /* NFS_DEBUG */ 707 - #else /* CONFIG_NFS_V4_1 */ 707 + #else /* CONFIG_NFS_V4 */ 708 708 709 709 static inline bool nfs_have_layout(struct inode *inode) 710 710 { ··· 913 913 return false; 914 914 } 915 915 916 - #endif /* CONFIG_NFS_V4_1 */ 916 + #endif /* CONFIG_NFS_V4 */ 917 917 918 918 #if IS_ENABLED(CONFIG_NFS_V4_2) 919 919 int pnfs_report_layoutstat(struct inode *inode, gfp_t gfp_flags);
+1 -2
fs/nfs/proc.c
··· 697 697 return 0; 698 698 } 699 699 700 - static int nfs_return_delegation(struct inode *inode) 700 + static void nfs_return_delegation(struct inode *inode) 701 701 { 702 702 if (S_ISREG(inode->i_mode)) 703 703 nfs_wb_all(inode); 704 - return 0; 705 704 } 706 705 707 706 static const struct inode_operations nfs_dir_inode_operations = {
+2 -2
fs/nfs/read.c
··· 68 68 struct nfs_server *server = NFS_SERVER(inode); 69 69 const struct nfs_pageio_ops *pg_ops = &nfs_pgio_rw_ops; 70 70 71 - #ifdef CONFIG_NFS_V4_1 71 + #if IS_ENABLED(CONFIG_NFS_V4) 72 72 if (server->pnfs_curr_ld && !force_mds) 73 73 pg_ops = server->pnfs_curr_ld->pg_read_ops; 74 - #endif 74 + #endif /* CONFIG_NFS_V4 */ 75 75 nfs_pageio_init(pgio, inode, pg_ops, compl_ops, &nfs_rw_read_ops, 76 76 server->rsize, 0); 77 77 }
+6 -24
fs/nfs/super.c
··· 212 212 } 213 213 EXPORT_SYMBOL_GPL(nfs_sb_deactive); 214 214 215 - static int __nfs_list_for_each_server(struct list_head *head, 216 - int (*fn)(struct nfs_server *, void *), 217 - void *data) 215 + int nfs_client_for_each_server(struct nfs_client *clp, 216 + int (*fn)(struct nfs_server *server, void *data), void *data) 218 217 { 219 218 struct nfs_server *server, *last = NULL; 220 219 int ret = 0; 221 220 222 221 rcu_read_lock(); 223 - list_for_each_entry_rcu(server, head, client_link) { 222 + list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { 224 223 if (!(server->super && nfs_sb_active(server->super))) 225 224 continue; 226 225 rcu_read_unlock(); ··· 237 238 if (last) 238 239 nfs_sb_deactive(last->super); 239 240 return ret; 240 - } 241 - 242 - int nfs_client_for_each_server(struct nfs_client *clp, 243 - int (*fn)(struct nfs_server *, void *), 244 - void *data) 245 - { 246 - return __nfs_list_for_each_server(&clp->cl_superblocks, fn, data); 247 241 } 248 242 EXPORT_SYMBOL_GPL(nfs_client_for_each_server); 249 243 ··· 589 597 seq_printf(m, ",lease_expired=%ld", 590 598 time_after(expire, jiffies) ? 0 : (jiffies - expire) / HZ); 591 599 } 592 - #ifdef CONFIG_NFS_V4_1 600 + 593 601 static void show_sessions(struct seq_file *m, struct nfs_server *server) 594 602 { 595 603 if (nfs4_has_session(server->nfs_client)) 596 604 seq_puts(m, ",sessions"); 597 605 } 598 - #else 599 - static void show_sessions(struct seq_file *m, struct nfs_server *server) {} 600 - #endif 601 - #endif 602 606 603 - #ifdef CONFIG_NFS_V4_1 604 607 static void show_pnfs(struct seq_file *m, struct nfs_server *server) 605 608 { 606 609 seq_printf(m, ",pnfs="); ··· 615 628 impl_id->date.seconds, impl_id->date.nseconds); 616 629 } 617 630 } 618 - #else 619 - #if IS_ENABLED(CONFIG_NFS_V4) 620 - static void show_pnfs(struct seq_file *m, struct nfs_server *server) 621 - { 622 - } 623 - #endif 631 + #else /* CONFIG_NFS_V4 */ 624 632 static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss) 625 633 { 626 634 } 627 - #endif 635 + #endif /* CONFIG_NFS_V4 */ 628 636 629 637 int nfs_show_devname(struct seq_file *m, struct dentry *root) 630 638 {
+5 -5
fs/nfs/sysfs.c
··· 293 293 294 294 static struct kobj_attribute nfs_sysfs_attr_shutdown = __ATTR_RW(shutdown); 295 295 296 - #if IS_ENABLED(CONFIG_NFS_V4_1) 296 + #if IS_ENABLED(CONFIG_NFS_V4) 297 297 static ssize_t 298 298 implid_domain_show(struct kobject *kobj, struct kobj_attribute *attr, 299 299 char *buf) ··· 323 323 324 324 static struct kobj_attribute nfs_sysfs_attr_implid_name = __ATTR_RO(implid_name); 325 325 326 - #endif /* IS_ENABLED(CONFIG_NFS_V4_1) */ 326 + #endif /* IS_ENABLED(CONFIG_NFS_V4) */ 327 327 328 328 #define RPC_CLIENT_NAME_SIZE 64 329 329 ··· 362 362 .child_ns_type = nfs_netns_object_child_ns_type, 363 363 }; 364 364 365 - #if IS_ENABLED(CONFIG_NFS_V4_1) 365 + #if IS_ENABLED(CONFIG_NFS_V4) 366 366 static void nfs_sysfs_add_nfsv41_server(struct nfs_server *server) 367 367 { 368 368 int ret; ··· 382 382 pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n", 383 383 server->s_sysfs_id, ret); 384 384 } 385 - #else /* CONFIG_NFS_V4_1 */ 385 + #else /* CONFIG_NFS_V4 */ 386 386 static inline void nfs_sysfs_add_nfsv41_server(struct nfs_server *server) 387 387 { 388 388 } 389 - #endif /* CONFIG_NFS_V4_1 */ 389 + #endif /* CONFIG_NFS_V4 */ 390 390 391 391 #if IS_ENABLED(CONFIG_NFS_LOCALIO) 392 392
+1 -1
fs/nfs/write.c
··· 1402 1402 struct nfs_server *server = NFS_SERVER(inode); 1403 1403 const struct nfs_pageio_ops *pg_ops = &nfs_pgio_rw_ops; 1404 1404 1405 - #ifdef CONFIG_NFS_V4_1 1405 + #if IS_ENABLED(CONFIG_NFS_V4) 1406 1406 if (server->pnfs_curr_ld && !force_mds) 1407 1407 pg_ops = server->pnfs_curr_ld->pg_write_ops; 1408 1408 #endif
+5 -5
include/linux/nfs_fs_sb.h
··· 115 115 #define NFS_SP4_MACH_CRED_WRITE 5 /* WRITE */ 116 116 #define NFS_SP4_MACH_CRED_COMMIT 6 /* COMMIT */ 117 117 #define NFS_SP4_MACH_CRED_PNFS_CLEANUP 7 /* LAYOUTRETURN */ 118 - #if IS_ENABLED(CONFIG_NFS_V4_1) 119 118 wait_queue_head_t cl_lock_waitq; 120 - #endif /* CONFIG_NFS_V4_1 */ 121 119 #endif /* CONFIG_NFS_V4 */ 122 120 123 121 /* Our own IP address, as a null-terminated string. ··· 257 259 struct list_head state_owners_lru; 258 260 struct list_head layouts; 259 261 struct list_head delegations; 262 + spinlock_t delegations_lock; 263 + struct list_head delegations_return; 264 + struct list_head delegations_lru; 265 + struct list_head delegations_delayed; 260 266 atomic_long_t nr_active_delegations; 261 267 unsigned int delegation_hash_mask; 262 268 struct hlist_head *delegation_hash_table; ··· 268 266 struct list_head ss_src_copies; 269 267 270 268 unsigned long delegation_flags; 271 - #define NFS4SERV_DELEGRETURN (1) 272 - #define NFS4SERV_DELEGATION_EXPIRED (2) 273 - #define NFS4SERV_DELEGRETURN_DELAYED (3) 269 + #define NFS4SERV_DELEGATION_EXPIRED (1) 274 270 unsigned long delegation_gen; 275 271 unsigned long mig_gen; 276 272 unsigned long mig_status;
+3 -6
include/linux/nfs_xdr.h
··· 209 209 }; 210 210 211 211 struct nfs4_sequence_res { 212 + const struct nfs4_sequence_slot_ops *sr_slot_ops; 212 213 struct nfs4_slot *sr_slot; /* slot used to send request */ 213 214 unsigned long sr_timestamp; 214 215 int sr_status; /* sequence operation status */ ··· 1324 1323 unsigned char renew:1; 1325 1324 }; 1326 1325 1327 - #endif /* CONFIG_NFS_V4 */ 1328 - 1329 - #ifdef CONFIG_NFS_V4_1 1330 - 1331 1326 struct pnfs_commit_bucket { 1332 1327 struct list_head written; 1333 1328 struct list_head committing; ··· 1463 1466 struct pnfs_ds_commit_info { 1464 1467 }; 1465 1468 1466 - #endif /* CONFIG_NFS_V4_1 */ 1469 + #endif /* CONFIG_NFS_V4 */ 1467 1470 1468 1471 #ifdef CONFIG_NFS_V4_2 1469 1472 struct nfs42_falloc_args { ··· 1846 1849 struct iattr *iattr, 1847 1850 int *); 1848 1851 int (*have_delegation)(struct inode *, fmode_t, int); 1849 - int (*return_delegation)(struct inode *); 1852 + void (*return_delegation)(struct inode *); 1850 1853 struct nfs_client *(*alloc_client) (const struct nfs_client_initdata *); 1851 1854 struct nfs_client *(*init_client) (struct nfs_client *, 1852 1855 const struct nfs_client_initdata *);
-2
include/linux/sunrpc/debug.h
··· 14 14 /* 15 15 * Debugging macros etc 16 16 */ 17 - #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 18 17 extern unsigned int rpc_debug; 19 18 extern unsigned int nfs_debug; 20 19 extern unsigned int nfsd_debug; 21 20 extern unsigned int nlm_debug; 22 - #endif 23 21 24 22 #define dprintk(fmt, ...) \ 25 23 dfprintk(FACILITY, fmt, ##__VA_ARGS__)
+3
net/sunrpc/auth_gss/auth_gss.c
··· 39 39 static const struct rpc_credops gss_credops; 40 40 static const struct rpc_credops gss_nullops; 41 41 42 + static void gss_free_callback(struct kref *kref); 43 + 42 44 #define GSS_RETRY_EXPIRED 5 43 45 static unsigned int gss_expired_cred_retry_delay = GSS_RETRY_EXPIRED; 44 46 ··· 553 551 } 554 552 return gss_msg; 555 553 err_put_pipe_version: 554 + kref_put(&gss_auth->kref, gss_free_callback); 556 555 put_pipe_version(gss_auth->net); 557 556 err_free_msg: 558 557 kfree(gss_msg);
+1 -2
net/sunrpc/backchannel_rqst.c
··· 147 147 int xprt_setup_bc(struct rpc_xprt *xprt, unsigned int min_reqs) 148 148 { 149 149 struct rpc_rqst *req; 150 - struct list_head tmp_list; 150 + LIST_HEAD(tmp_list); 151 151 int i; 152 152 153 153 dprintk("RPC: setup backchannel transport\n"); ··· 163 163 * lock is held on the rpc_xprt struct. It also makes cleanup 164 164 * easier in case of memory allocation errors. 165 165 */ 166 - INIT_LIST_HEAD(&tmp_list); 167 166 for (i = 0; i < min_reqs; i++) { 168 167 /* Pre-allocate one backchannel rpc_rqst */ 169 168 req = xprt_alloc_bc_req(xprt);