hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/nfsd/nfs4state.c
....@@ -507,15 +507,26 @@
507507 return ret;
508508 }
509509
510
-static struct nfsd_file *find_deleg_file(struct nfs4_file *f)
510
+static struct nfsd_file *find_any_file_locked(struct nfs4_file *f)
511511 {
512
- struct nfsd_file *ret = NULL;
512
+ lockdep_assert_held(&f->fi_lock);
513513
514
- spin_lock(&f->fi_lock);
514
+ if (f->fi_fds[O_RDWR])
515
+ return f->fi_fds[O_RDWR];
516
+ if (f->fi_fds[O_WRONLY])
517
+ return f->fi_fds[O_WRONLY];
518
+ if (f->fi_fds[O_RDONLY])
519
+ return f->fi_fds[O_RDONLY];
520
+ return NULL;
521
+}
522
+
523
+static struct nfsd_file *find_deleg_file_locked(struct nfs4_file *f)
524
+{
525
+ lockdep_assert_held(&f->fi_lock);
526
+
515527 if (f->fi_deleg_file)
516
- ret = nfsd_file_get(f->fi_deleg_file);
517
- spin_unlock(&f->fi_lock);
518
- return ret;
528
+ return f->fi_deleg_file;
529
+ return NULL;
519530 }
520531
521532 static atomic_long_t num_delegations;
....@@ -1134,9 +1145,9 @@
11341145 WARN_ON(!list_empty(&dp->dl_recall_lru));
11351146
11361147 if (clp->cl_minorversion) {
1148
+ spin_lock(&clp->cl_lock);
11371149 dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID;
11381150 refcount_inc(&dp->dl_stid.sc_count);
1139
- spin_lock(&clp->cl_lock);
11401151 list_add(&dp->dl_recall_lru, &clp->cl_revoked);
11411152 spin_unlock(&clp->cl_lock);
11421153 }
....@@ -2462,9 +2473,11 @@
24622473 ols = openlockstateid(st);
24632474 oo = ols->st_stateowner;
24642475 nf = st->sc_file;
2465
- file = find_any_file(nf);
2476
+
2477
+ spin_lock(&nf->fi_lock);
2478
+ file = find_any_file_locked(nf);
24662479 if (!file)
2467
- return 0;
2480
+ goto out;
24682481
24692482 seq_printf(s, "- ");
24702483 nfs4_show_stateid(s, &st->sc_stateid);
....@@ -2486,8 +2499,8 @@
24862499 seq_printf(s, ", ");
24872500 nfs4_show_owner(s, oo);
24882501 seq_printf(s, " }\n");
2489
- nfsd_file_put(file);
2490
-
2502
+out:
2503
+ spin_unlock(&nf->fi_lock);
24912504 return 0;
24922505 }
24932506
....@@ -2501,9 +2514,10 @@
25012514 ols = openlockstateid(st);
25022515 oo = ols->st_stateowner;
25032516 nf = st->sc_file;
2504
- file = find_any_file(nf);
2517
+ spin_lock(&nf->fi_lock);
2518
+ file = find_any_file_locked(nf);
25052519 if (!file)
2506
- return 0;
2520
+ goto out;
25072521
25082522 seq_printf(s, "- ");
25092523 nfs4_show_stateid(s, &st->sc_stateid);
....@@ -2523,8 +2537,8 @@
25232537 seq_printf(s, ", ");
25242538 nfs4_show_owner(s, oo);
25252539 seq_printf(s, " }\n");
2526
- nfsd_file_put(file);
2527
-
2540
+out:
2541
+ spin_unlock(&nf->fi_lock);
25282542 return 0;
25292543 }
25302544
....@@ -2536,9 +2550,10 @@
25362550
25372551 ds = delegstateid(st);
25382552 nf = st->sc_file;
2539
- file = find_deleg_file(nf);
2553
+ spin_lock(&nf->fi_lock);
2554
+ file = find_deleg_file_locked(nf);
25402555 if (!file)
2541
- return 0;
2556
+ goto out;
25422557
25432558 seq_printf(s, "- ");
25442559 nfs4_show_stateid(s, &st->sc_stateid);
....@@ -2554,8 +2569,8 @@
25542569 seq_printf(s, ", ");
25552570 nfs4_show_fname(s, file);
25562571 seq_printf(s, " }\n");
2557
- nfsd_file_put(file);
2558
-
2572
+out:
2573
+ spin_unlock(&nf->fi_lock);
25592574 return 0;
25602575 }
25612576
....@@ -5641,8 +5656,6 @@
56415656 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
56425657 CLOSE_STATEID(stateid))
56435658 return status;
5644
- if (!same_clid(&stateid->si_opaque.so_clid, &cl->cl_clientid))
5645
- return status;
56465659 spin_lock(&cl->cl_lock);
56475660 s = find_stateid_locked(cl, stateid);
56485661 if (!s)
....@@ -7379,14 +7392,9 @@
73797392 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
73807393 int ret;
73817394
7382
- ret = get_nfsdfs(net);
7395
+ ret = nfs4_state_create_net(net);
73837396 if (ret)
73847397 return ret;
7385
- ret = nfs4_state_create_net(net);
7386
- if (ret) {
7387
- mntput(nn->nfsd_mnt);
7388
- return ret;
7389
- }
73907398 locks_start_grace(net, &nn->nfsd4_manager);
73917399 nfsd4_client_tracking_init(net);
73927400 if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0)
....@@ -7456,7 +7464,6 @@
74567464
74577465 nfsd4_client_tracking_exit(net);
74587466 nfs4_state_destroy_net(net);
7459
- mntput(nn->nfsd_mnt);
74607467 }
74617468
74627469 void