Skip to content

Commit 1e33e14

Browse files
neilbrownchucklever
authored andcommitted
nfsd: allow layout state to be admin-revoked.
When there is layout state on a filesystem that is being "unlocked" that is now revoked, which involves closing the nfsd_file and releasing the vfs lease. To avoid races, ->ls_file can now be accessed either: - under ->fi_lock for the state's sc_file or - under rcu_read_lock() if nfsd_file_get() is used. To support this, ->fence_client and nfsd4_cb_layout_fail() now take a second argument being the nfsd_file. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 06efa66 commit 1e33e14

4 files changed

Lines changed: 50 additions & 16 deletions

File tree

fs/nfsd/blocklayout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ nfsd4_scsi_proc_layoutcommit(struct inode *inode,
328328
}
329329

330330
static void
331-
nfsd4_scsi_fence_client(struct nfs4_layout_stateid *ls)
331+
nfsd4_scsi_fence_client(struct nfs4_layout_stateid *ls, struct nfsd_file *file)
332332
{
333333
struct nfs4_client *clp = ls->ls_stid.sc_client;
334-
struct block_device *bdev = ls->ls_file->nf_file->f_path.mnt->mnt_sb->s_bdev;
334+
struct block_device *bdev = file->nf_file->f_path.mnt->mnt_sb->s_bdev;
335335

336336
bdev->bd_disk->fops->pr_ops->pr_preempt(bdev, NFSD_MDS_PR_KEY,
337337
nfsd4_scsi_pr_key(clp), 0, true);

fs/nfsd/nfs4layouts.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ void nfsd4_setup_layout_type(struct svc_export *exp)
152152
#endif
153153
}
154154

155+
void nfsd4_close_layout(struct nfs4_layout_stateid *ls)
156+
{
157+
struct nfsd_file *fl;
158+
159+
spin_lock(&ls->ls_stid.sc_file->fi_lock);
160+
fl = ls->ls_file;
161+
ls->ls_file = NULL;
162+
spin_unlock(&ls->ls_stid.sc_file->fi_lock);
163+
164+
if (fl) {
165+
if (!nfsd4_layout_ops[ls->ls_layout_type]->disable_recalls)
166+
vfs_setlease(fl->nf_file, F_UNLCK, NULL,
167+
(void **)&ls);
168+
nfsd_file_put(fl);
169+
}
170+
}
171+
155172
static void
156173
nfsd4_free_layout_stateid(struct nfs4_stid *stid)
157174
{
@@ -169,9 +186,7 @@ nfsd4_free_layout_stateid(struct nfs4_stid *stid)
169186
list_del_init(&ls->ls_perfile);
170187
spin_unlock(&fp->fi_lock);
171188

172-
if (!nfsd4_layout_ops[ls->ls_layout_type]->disable_recalls)
173-
vfs_setlease(ls->ls_file->nf_file, F_UNLCK, NULL, (void **)&ls);
174-
nfsd_file_put(ls->ls_file);
189+
nfsd4_close_layout(ls);
175190

176191
if (ls->ls_recalled)
177192
atomic_dec(&ls->ls_stid.sc_file->fi_lo_recalls);
@@ -605,7 +620,7 @@ nfsd4_return_all_file_layouts(struct nfs4_client *clp, struct nfs4_file *fp)
605620
}
606621

607622
static void
608-
nfsd4_cb_layout_fail(struct nfs4_layout_stateid *ls)
623+
nfsd4_cb_layout_fail(struct nfs4_layout_stateid *ls, struct nfsd_file *file)
609624
{
610625
struct nfs4_client *clp = ls->ls_stid.sc_client;
611626
char addr_str[INET6_ADDRSTRLEN];
@@ -627,7 +642,7 @@ nfsd4_cb_layout_fail(struct nfs4_layout_stateid *ls)
627642

628643
argv[0] = (char *)nfsd_recall_failed;
629644
argv[1] = addr_str;
630-
argv[2] = ls->ls_file->nf_file->f_path.mnt->mnt_sb->s_id;
645+
argv[2] = file->nf_file->f_path.mnt->mnt_sb->s_id;
631646
argv[3] = NULL;
632647

633648
error = call_usermodehelper(nfsd_recall_failed, argv, envp,
@@ -657,6 +672,7 @@ nfsd4_cb_layout_done(struct nfsd4_callback *cb, struct rpc_task *task)
657672
struct nfsd_net *nn;
658673
ktime_t now, cutoff;
659674
const struct nfsd4_layout_ops *ops;
675+
struct nfsd_file *fl;
660676

661677
trace_nfsd_cb_layout_done(&ls->ls_stid.sc_stateid, task);
662678
switch (task->tk_status) {
@@ -688,12 +704,17 @@ nfsd4_cb_layout_done(struct nfsd4_callback *cb, struct rpc_task *task)
688704
* Unknown error or non-responding client, we'll need to fence.
689705
*/
690706
trace_nfsd_layout_recall_fail(&ls->ls_stid.sc_stateid);
691-
692-
ops = nfsd4_layout_ops[ls->ls_layout_type];
693-
if (ops->fence_client)
694-
ops->fence_client(ls);
695-
else
696-
nfsd4_cb_layout_fail(ls);
707+
rcu_read_lock();
708+
fl = nfsd_file_get(ls->ls_file);
709+
rcu_read_unlock();
710+
if (fl) {
711+
ops = nfsd4_layout_ops[ls->ls_layout_type];
712+
if (ops->fence_client)
713+
ops->fence_client(ls, fl);
714+
else
715+
nfsd4_cb_layout_fail(ls, fl);
716+
nfsd_file_put(fl);
717+
}
697718
return 1;
698719
case -NFS4ERR_NOMATCHING_LAYOUT:
699720
trace_nfsd_layout_recall_done(&ls->ls_stid.sc_stateid);

fs/nfsd/nfs4state.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)
17211721
unsigned int idhashval;
17221722
unsigned int sc_types;
17231723

1724-
sc_types = SC_TYPE_OPEN | SC_TYPE_LOCK | SC_TYPE_DELEG;
1724+
sc_types = SC_TYPE_OPEN | SC_TYPE_LOCK | SC_TYPE_DELEG | SC_TYPE_LAYOUT;
17251725

17261726
spin_lock(&nn->client_lock);
17271727
for (idhashval = 0; idhashval < CLIENT_HASH_MASK; idhashval++) {
@@ -1734,6 +1734,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)
17341734
if (stid) {
17351735
struct nfs4_ol_stateid *stp;
17361736
struct nfs4_delegation *dp;
1737+
struct nfs4_layout_stateid *ls;
17371738

17381739
spin_unlock(&nn->client_lock);
17391740
switch (stid->sc_type) {
@@ -1789,6 +1790,10 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)
17891790
if (dp)
17901791
revoke_delegation(dp);
17911792
break;
1793+
case SC_TYPE_LAYOUT:
1794+
ls = layoutstateid(stid);
1795+
nfsd4_close_layout(ls);
1796+
break;
17921797
}
17931798
nfs4_put_stid(stid);
17941799
spin_lock(&nn->client_lock);
@@ -2868,20 +2873,22 @@ static int nfs4_show_layout(struct seq_file *s, struct nfs4_stid *st)
28682873
struct nfsd_file *file;
28692874

28702875
ls = container_of(st, struct nfs4_layout_stateid, ls_stid);
2871-
file = ls->ls_file;
28722876

28732877
seq_puts(s, "- ");
28742878
nfs4_show_stateid(s, &st->sc_stateid);
28752879
seq_puts(s, ": { type: layout");
28762880

28772881
/* XXX: What else would be useful? */
28782882

2883+
spin_lock(&ls->ls_stid.sc_file->fi_lock);
2884+
file = ls->ls_file;
28792885
if (file) {
28802886
seq_puts(s, ", ");
28812887
nfs4_show_superblock(s, file);
28822888
seq_puts(s, ", ");
28832889
nfs4_show_fname(s, file);
28842890
}
2891+
spin_unlock(&ls->ls_stid.sc_file->fi_lock);
28852892
if (st->sc_status & SC_STATUS_ADMIN_REVOKED)
28862893
seq_puts(s, ", admin-revoked");
28872894
seq_puts(s, " }\n");

fs/nfsd/pnfs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct nfsd4_layout_ops {
3737
__be32 (*proc_layoutcommit)(struct inode *inode,
3838
struct nfsd4_layoutcommit *lcp);
3939

40-
void (*fence_client)(struct nfs4_layout_stateid *ls);
40+
void (*fence_client)(struct nfs4_layout_stateid *ls,
41+
struct nfsd_file *file);
4142
};
4243

4344
extern const struct nfsd4_layout_ops *nfsd4_layout_ops[];
@@ -72,11 +73,13 @@ void nfsd4_setup_layout_type(struct svc_export *exp);
7273
void nfsd4_return_all_client_layouts(struct nfs4_client *);
7374
void nfsd4_return_all_file_layouts(struct nfs4_client *clp,
7475
struct nfs4_file *fp);
76+
void nfsd4_close_layout(struct nfs4_layout_stateid *ls);
7577
int nfsd4_init_pnfs(void);
7678
void nfsd4_exit_pnfs(void);
7779
#else
7880
struct nfs4_client;
7981
struct nfs4_file;
82+
struct nfs4_layout_stateid;
8083

8184
static inline void nfsd4_setup_layout_type(struct svc_export *exp)
8285
{
@@ -89,6 +92,9 @@ static inline void nfsd4_return_all_file_layouts(struct nfs4_client *clp,
8992
struct nfs4_file *fp)
9093
{
9194
}
95+
static inline void nfsd4_close_layout(struct nfs4_layout_stateid *ls)
96+
{
97+
}
9298
static inline void nfsd4_exit_pnfs(void)
9399
{
94100
}

0 commit comments

Comments
 (0)