Skip to content

Commit 02e1215

Browse files
Jeff LaytonJ. Bruce Fields
authored andcommitted
nfsd: Avoid taking state_lock while holding inode lock in nfsd_break_one_deleg
state_lock is a heavily contended global lock. We don't want to grab that while simultaneously holding the inode->i_lock. Add a new per-nfs4_file lock that we can use to protect the per-nfs4_file delegation list. Hold that while walking the list in the break_deleg callback and queue the workqueue job for each one. The workqueue job can then take the state_lock and do the list manipulations without the i_lock being held prior to starting the rpc call. Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent e8051c8 commit 02e1215

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

fs/nfsd/nfs4callback.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ void nfsd4_shutdown_callback(struct nfs4_client *clp)
933933
set_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags);
934934
/*
935935
* Note this won't actually result in a null callback;
936-
* instead, nfsd4_do_callback_rpc() will detect the killed
936+
* instead, nfsd4_run_cb_null() will detect the killed
937937
* client, destroy the rpc client, and stop:
938938
*/
939939
do_probe_callback(clp);
@@ -1011,10 +1011,9 @@ static void nfsd4_process_cb_update(struct nfsd4_callback *cb)
10111011
run_nfsd4_cb(cb);
10121012
}
10131013

1014-
void
1015-
nfsd4_do_callback_rpc(struct work_struct *w)
1014+
static void
1015+
nfsd4_run_callback_rpc(struct nfsd4_callback *cb)
10161016
{
1017-
struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback, cb_work);
10181017
struct nfs4_client *clp = cb->cb_clp;
10191018
struct rpc_clnt *clnt;
10201019

@@ -1032,6 +1031,24 @@ nfsd4_do_callback_rpc(struct work_struct *w)
10321031
cb->cb_ops, cb);
10331032
}
10341033

1034+
void
1035+
nfsd4_run_cb_null(struct work_struct *w)
1036+
{
1037+
struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback,
1038+
cb_work);
1039+
nfsd4_run_callback_rpc(cb);
1040+
}
1041+
1042+
void
1043+
nfsd4_run_cb_recall(struct work_struct *w)
1044+
{
1045+
struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback,
1046+
cb_work);
1047+
1048+
nfsd4_prepare_cb_recall(cb->cb_op);
1049+
nfsd4_run_callback_rpc(cb);
1050+
}
1051+
10351052
void nfsd4_cb_recall(struct nfs4_delegation *dp)
10361053
{
10371054
struct nfsd4_callback *cb = &dp->dl_recall;

fs/nfsd/nfs4state.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ static void nfsd4_free_file(struct nfs4_file *f)
254254
static inline void
255255
put_nfs4_file(struct nfs4_file *fi)
256256
{
257+
might_lock(&state_lock);
258+
257259
if (atomic_dec_and_lock(&fi->fi_ref, &state_lock)) {
258260
hlist_del(&fi->fi_hash);
259261
spin_unlock(&state_lock);
@@ -554,6 +556,8 @@ static void block_delegations(struct knfsd_fh *fh)
554556
u32 hash;
555557
struct bloom_pair *bd = &blocked_delegations;
556558

559+
lockdep_assert_held(&state_lock);
560+
557561
hash = arch_fast_hash(&fh->fh_base, fh->fh_size, 0);
558562

559563
__set_bit(hash&255, bd->set[bd->new]);
@@ -592,7 +596,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv
592596
fh_copy_shallow(&dp->dl_fh, &current_fh->fh_handle);
593597
dp->dl_time = 0;
594598
atomic_set(&dp->dl_count, 1);
595-
INIT_WORK(&dp->dl_recall.cb_work, nfsd4_do_callback_rpc);
599+
INIT_WORK(&dp->dl_recall.cb_work, nfsd4_run_cb_recall);
596600
return dp;
597601
}
598602

@@ -640,22 +644,28 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp)
640644
lockdep_assert_held(&state_lock);
641645

642646
dp->dl_stid.sc_type = NFS4_DELEG_STID;
647+
spin_lock(&fp->fi_lock);
643648
list_add(&dp->dl_perfile, &fp->fi_delegations);
649+
spin_unlock(&fp->fi_lock);
644650
list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations);
645651
}
646652

647653
/* Called under the state lock. */
648654
static void
649655
unhash_delegation(struct nfs4_delegation *dp)
650656
{
657+
struct nfs4_file *fp = dp->dl_file;
658+
651659
spin_lock(&state_lock);
652660
list_del_init(&dp->dl_perclnt);
653-
list_del_init(&dp->dl_perfile);
654661
list_del_init(&dp->dl_recall_lru);
662+
spin_lock(&fp->fi_lock);
663+
list_del_init(&dp->dl_perfile);
664+
spin_unlock(&fp->fi_lock);
655665
spin_unlock(&state_lock);
656-
if (dp->dl_file) {
657-
nfs4_put_deleg_lease(dp->dl_file);
658-
put_nfs4_file(dp->dl_file);
666+
if (fp) {
667+
nfs4_put_deleg_lease(fp);
668+
put_nfs4_file(fp);
659669
dp->dl_file = NULL;
660670
}
661671
}
@@ -1677,7 +1687,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
16771687
spin_unlock(&nn->client_lock);
16781688
return NULL;
16791689
}
1680-
INIT_WORK(&clp->cl_cb_null.cb_work, nfsd4_do_callback_rpc);
1690+
INIT_WORK(&clp->cl_cb_null.cb_work, nfsd4_run_cb_null);
16811691
clp->cl_time = get_seconds();
16821692
clear_bit(0, &clp->cl_cb_slot_busy);
16831693
copy_verf(clp, verf);
@@ -3079,30 +3089,38 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
30793089
return ret;
30803090
}
30813091

3082-
static void nfsd_break_one_deleg(struct nfs4_delegation *dp)
3092+
void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp)
30833093
{
30843094
struct nfs4_client *clp = dp->dl_stid.sc_client;
30853095
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
30863096

3087-
lockdep_assert_held(&state_lock);
3088-
/* We're assuming the state code never drops its reference
3089-
* without first removing the lease. Since we're in this lease
3090-
* callback (and since the lease code is serialized by the kernel
3091-
* lock) we know the server hasn't removed the lease yet, we know
3092-
* it's safe to take a reference: */
3093-
atomic_inc(&dp->dl_count);
3094-
3097+
/*
3098+
* We can't do this in nfsd_break_deleg_cb because it is
3099+
* already holding inode->i_lock
3100+
*/
3101+
spin_lock(&state_lock);
3102+
block_delegations(&dp->dl_fh);
30953103
/*
30963104
* If the dl_time != 0, then we know that it has already been
30973105
* queued for a lease break. Don't queue it again.
30983106
*/
30993107
if (dp->dl_time == 0) {
3100-
list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru);
31013108
dp->dl_time = get_seconds();
3109+
list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru);
31023110
}
3111+
spin_unlock(&state_lock);
3112+
}
31033113

3104-
block_delegations(&dp->dl_fh);
3105-
3114+
static void nfsd_break_one_deleg(struct nfs4_delegation *dp)
3115+
{
3116+
/*
3117+
* We're assuming the state code never drops its reference
3118+
* without first removing the lease. Since we're in this lease
3119+
* callback (and since the lease code is serialized by the kernel
3120+
* lock) we know the server hasn't removed the lease yet, we know
3121+
* it's safe to take a reference.
3122+
*/
3123+
atomic_inc(&dp->dl_count);
31063124
nfsd4_cb_recall(dp);
31073125
}
31083126

@@ -3127,11 +3145,11 @@ static void nfsd_break_deleg_cb(struct file_lock *fl)
31273145
*/
31283146
fl->fl_break_time = 0;
31293147

3130-
spin_lock(&state_lock);
31313148
fp->fi_had_conflict = true;
3149+
spin_lock(&fp->fi_lock);
31323150
list_for_each_entry(dp, &fp->fi_delegations, dl_perfile)
31333151
nfsd_break_one_deleg(dp);
3134-
spin_unlock(&state_lock);
3152+
spin_unlock(&fp->fi_lock);
31353153
}
31363154

31373155
static

fs/nfsd/state.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,16 @@ extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(const char *recdir,
436436
extern __be32 nfs4_check_open_reclaim(clientid_t *clid,
437437
struct nfsd4_compound_state *cstate, struct nfsd_net *nn);
438438
extern int set_callback_cred(void);
439-
void nfsd4_do_callback_rpc(struct work_struct *w);
439+
void nfsd4_run_cb_null(struct work_struct *w);
440+
void nfsd4_run_cb_recall(struct work_struct *w);
440441
extern void nfsd4_probe_callback(struct nfs4_client *clp);
441442
extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
442443
extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
443444
extern void nfsd4_cb_recall(struct nfs4_delegation *dp);
444445
extern int nfsd4_create_callback_queue(void);
445446
extern void nfsd4_destroy_callback_queue(void);
446447
extern void nfsd4_shutdown_callback(struct nfs4_client *);
448+
extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
447449
extern void nfs4_put_delegation(struct nfs4_delegation *dp);
448450
extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(const char *name,
449451
struct nfsd_net *nn);

0 commit comments

Comments
 (0)