@@ -2144,6 +2144,7 @@ static void __free_client(struct kref *k)
2144
2144
kfree (clp -> cl_nii_domain .data );
2145
2145
kfree (clp -> cl_nii_name .data );
2146
2146
idr_destroy (& clp -> cl_stateids );
2147
+ kfree (clp -> cl_ra );
2147
2148
kmem_cache_free (client_slab , clp );
2148
2149
}
2149
2150
@@ -2871,6 +2872,36 @@ static const struct tree_descr client_files[] = {
2871
2872
[3 ] = {"" },
2872
2873
};
2873
2874
2875
+ static int
2876
+ nfsd4_cb_recall_any_done (struct nfsd4_callback * cb ,
2877
+ struct rpc_task * task )
2878
+ {
2879
+ switch (task -> tk_status ) {
2880
+ case - NFS4ERR_DELAY :
2881
+ rpc_delay (task , 2 * HZ );
2882
+ return 0 ;
2883
+ default :
2884
+ return 1 ;
2885
+ }
2886
+ }
2887
+
2888
+ static void
2889
+ nfsd4_cb_recall_any_release (struct nfsd4_callback * cb )
2890
+ {
2891
+ struct nfs4_client * clp = cb -> cb_clp ;
2892
+ struct nfsd_net * nn = net_generic (clp -> net , nfsd_net_id );
2893
+
2894
+ spin_lock (& nn -> client_lock );
2895
+ clear_bit (NFSD4_CLIENT_CB_RECALL_ANY , & clp -> cl_flags );
2896
+ put_client_renew_locked (clp );
2897
+ spin_unlock (& nn -> client_lock );
2898
+ }
2899
+
2900
+ static const struct nfsd4_callback_ops nfsd4_cb_recall_any_ops = {
2901
+ .done = nfsd4_cb_recall_any_done ,
2902
+ .release = nfsd4_cb_recall_any_release ,
2903
+ };
2904
+
2874
2905
static struct nfs4_client * create_client (struct xdr_netobj name ,
2875
2906
struct svc_rqst * rqstp , nfs4_verifier * verf )
2876
2907
{
@@ -2908,6 +2939,14 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
2908
2939
free_client (clp );
2909
2940
return NULL ;
2910
2941
}
2942
+ clp -> cl_ra = kzalloc (sizeof (* clp -> cl_ra ), GFP_KERNEL );
2943
+ if (!clp -> cl_ra ) {
2944
+ free_client (clp );
2945
+ return NULL ;
2946
+ }
2947
+ clp -> cl_ra_time = 0 ;
2948
+ nfsd4_init_cb (& clp -> cl_ra -> ra_cb , clp , & nfsd4_cb_recall_any_ops ,
2949
+ NFSPROC4_CLNT_CB_RECALL_ANY );
2911
2950
return clp ;
2912
2951
}
2913
2952
@@ -4363,14 +4402,16 @@ nfsd4_init_slabs(void)
4363
4402
static unsigned long
4364
4403
nfsd4_state_shrinker_count (struct shrinker * shrink , struct shrink_control * sc )
4365
4404
{
4366
- int cnt ;
4405
+ int count ;
4367
4406
struct nfsd_net * nn = container_of (shrink ,
4368
4407
struct nfsd_net , nfsd_client_shrinker );
4369
4408
4370
- cnt = atomic_read (& nn -> nfsd_courtesy_clients );
4371
- if (cnt > 0 )
4409
+ count = atomic_read (& nn -> nfsd_courtesy_clients );
4410
+ if (!count )
4411
+ count = atomic_long_read (& num_delegations );
4412
+ if (count )
4372
4413
mod_delayed_work (laundry_wq , & nn -> nfsd_shrinker_work , 0 );
4373
- return (unsigned long )cnt ;
4414
+ return (unsigned long )count ;
4374
4415
}
4375
4416
4376
4417
static unsigned long
@@ -6159,6 +6200,44 @@ courtesy_client_reaper(struct nfsd_net *nn)
6159
6200
nfs4_process_client_reaplist (& reaplist );
6160
6201
}
6161
6202
6203
+ static void
6204
+ deleg_reaper (struct nfsd_net * nn )
6205
+ {
6206
+ struct list_head * pos , * next ;
6207
+ struct nfs4_client * clp ;
6208
+ struct list_head cblist ;
6209
+
6210
+ INIT_LIST_HEAD (& cblist );
6211
+ spin_lock (& nn -> client_lock );
6212
+ list_for_each_safe (pos , next , & nn -> client_lru ) {
6213
+ clp = list_entry (pos , struct nfs4_client , cl_lru );
6214
+ if (clp -> cl_state != NFSD4_ACTIVE ||
6215
+ list_empty (& clp -> cl_delegations ) ||
6216
+ atomic_read (& clp -> cl_delegs_in_recall ) ||
6217
+ test_bit (NFSD4_CLIENT_CB_RECALL_ANY , & clp -> cl_flags ) ||
6218
+ (ktime_get_boottime_seconds () -
6219
+ clp -> cl_ra_time < 5 )) {
6220
+ continue ;
6221
+ }
6222
+ list_add (& clp -> cl_ra_cblist , & cblist );
6223
+
6224
+ /* release in nfsd4_cb_recall_any_release */
6225
+ atomic_inc (& clp -> cl_rpc_users );
6226
+ set_bit (NFSD4_CLIENT_CB_RECALL_ANY , & clp -> cl_flags );
6227
+ clp -> cl_ra_time = ktime_get_boottime_seconds ();
6228
+ }
6229
+ spin_unlock (& nn -> client_lock );
6230
+
6231
+ while (!list_empty (& cblist )) {
6232
+ clp = list_first_entry (& cblist , struct nfs4_client ,
6233
+ cl_ra_cblist );
6234
+ list_del_init (& clp -> cl_ra_cblist );
6235
+ clp -> cl_ra -> ra_keep = 0 ;
6236
+ clp -> cl_ra -> ra_bmval [0 ] = BIT (RCA4_TYPE_MASK_RDATA_DLG );
6237
+ nfsd4_run_cb (& clp -> cl_ra -> ra_cb );
6238
+ }
6239
+ }
6240
+
6162
6241
static void
6163
6242
nfsd4_state_shrinker_worker (struct work_struct * work )
6164
6243
{
@@ -6167,6 +6246,7 @@ nfsd4_state_shrinker_worker(struct work_struct *work)
6167
6246
nfsd_shrinker_work );
6168
6247
6169
6248
courtesy_client_reaper (nn );
6249
+ deleg_reaper (nn );
6170
6250
}
6171
6251
6172
6252
static inline __be32 nfs4_check_fh (struct svc_fh * fhp , struct nfs4_stid * stp )
0 commit comments