Skip to content

Commit 1ac3629

Browse files
neilbrownchucklever
authored andcommitted
nfsd: prepare for supporting admin-revocation of state
The NFSv4 protocol allows state to be revoked by the admin and has error codes which allow this to be communicated to the client. This patch - introduces a new state-id status SC_STATUS_ADMIN_REVOKED which can be set on open, lock, or delegation state. - reports NFS4ERR_ADMIN_REVOKED when these are accessed - introduces a per-client counter of these states and returns SEQ4_STATUS_ADMIN_STATE_REVOKED when the counter is not zero. Decrements this when freeing any admin-revoked state. - introduces stub code to find all interesting states for a given superblock so they can be revoked via the 'unlock_filesystem' file in /proc/fs/nfsd/ No actual states are handled yet. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 3f29cc8 commit 1ac3629

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

fs/nfsd/nfs4state.c

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,8 @@ nfs4_put_stid(struct nfs4_stid *s)
12101210
return;
12111211
}
12121212
idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
1213+
if (s->sc_status & SC_STATUS_ADMIN_REVOKED)
1214+
atomic_dec(&s->sc_client->cl_admin_revoked);
12131215
nfs4_free_cpntf_statelist(clp->net, s);
12141216
spin_unlock(&clp->cl_lock);
12151217
s->sc_free(s);
@@ -1529,6 +1531,8 @@ static void put_ol_stateid_locked(struct nfs4_ol_stateid *stp,
15291531
}
15301532

15311533
idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
1534+
if (s->sc_status & SC_STATUS_ADMIN_REVOKED)
1535+
atomic_dec(&s->sc_client->cl_admin_revoked);
15321536
list_add(&stp->st_locks, reaplist);
15331537
}
15341538

@@ -1674,6 +1678,68 @@ static void release_openowner(struct nfs4_openowner *oo)
16741678
nfs4_put_stateowner(&oo->oo_owner);
16751679
}
16761680

1681+
static struct nfs4_stid *find_one_sb_stid(struct nfs4_client *clp,
1682+
struct super_block *sb,
1683+
unsigned int sc_types)
1684+
{
1685+
unsigned long id, tmp;
1686+
struct nfs4_stid *stid;
1687+
1688+
spin_lock(&clp->cl_lock);
1689+
idr_for_each_entry_ul(&clp->cl_stateids, stid, tmp, id)
1690+
if ((stid->sc_type & sc_types) &&
1691+
stid->sc_status == 0 &&
1692+
stid->sc_file->fi_inode->i_sb == sb) {
1693+
refcount_inc(&stid->sc_count);
1694+
break;
1695+
}
1696+
spin_unlock(&clp->cl_lock);
1697+
return stid;
1698+
}
1699+
1700+
/**
1701+
* nfsd4_revoke_states - revoke all nfsv4 states associated with given filesystem
1702+
* @net: used to identify instance of nfsd (there is one per net namespace)
1703+
* @sb: super_block used to identify target filesystem
1704+
*
1705+
* All nfs4 states (open, lock, delegation, layout) held by the server instance
1706+
* and associated with a file on the given filesystem will be revoked resulting
1707+
* in any files being closed and so all references from nfsd to the filesystem
1708+
* being released. Thus nfsd will no longer prevent the filesystem from being
1709+
* unmounted.
1710+
*
1711+
* The clients which own the states will subsequently being notified that the
1712+
* states have been "admin-revoked".
1713+
*/
1714+
void nfsd4_revoke_states(struct net *net, struct super_block *sb)
1715+
{
1716+
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1717+
unsigned int idhashval;
1718+
unsigned int sc_types;
1719+
1720+
sc_types = 0;
1721+
1722+
spin_lock(&nn->client_lock);
1723+
for (idhashval = 0; idhashval < CLIENT_HASH_MASK; idhashval++) {
1724+
struct list_head *head = &nn->conf_id_hashtbl[idhashval];
1725+
struct nfs4_client *clp;
1726+
retry:
1727+
list_for_each_entry(clp, head, cl_idhash) {
1728+
struct nfs4_stid *stid = find_one_sb_stid(clp, sb,
1729+
sc_types);
1730+
if (stid) {
1731+
spin_unlock(&nn->client_lock);
1732+
switch (stid->sc_type) {
1733+
}
1734+
nfs4_put_stid(stid);
1735+
spin_lock(&nn->client_lock);
1736+
goto retry;
1737+
}
1738+
}
1739+
}
1740+
spin_unlock(&nn->client_lock);
1741+
}
1742+
16771743
static inline int
16781744
hash_sessionid(struct nfs4_sessionid *sessionid)
16791745
{
@@ -2545,6 +2611,8 @@ static int client_info_show(struct seq_file *m, void *v)
25452611
}
25462612
seq_printf(m, "callback state: %s\n", cb_state2str(clp->cl_cb_state));
25472613
seq_printf(m, "callback address: %pISpc\n", &clp->cl_cb_conn.cb_addr);
2614+
seq_printf(m, "admin-revoked states: %d\n",
2615+
atomic_read(&clp->cl_admin_revoked));
25482616
drop_client(clp);
25492617

25502618
return 0;
@@ -4058,6 +4126,8 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
40584126
}
40594127
if (!list_empty(&clp->cl_revoked))
40604128
seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
4129+
if (atomic_read(&clp->cl_admin_revoked))
4130+
seq->status_flags |= SEQ4_STATUS_ADMIN_STATE_REVOKED;
40614131
trace_nfsd_seq4_status(rqstp, seq);
40624132
out_no_session:
40634133
if (conn)
@@ -4547,7 +4617,9 @@ nfsd4_verify_open_stid(struct nfs4_stid *s)
45474617
{
45484618
__be32 ret = nfs_ok;
45494619

4550-
if (s->sc_status & SC_STATUS_REVOKED)
4620+
if (s->sc_status & SC_STATUS_ADMIN_REVOKED)
4621+
ret = nfserr_admin_revoked;
4622+
else if (s->sc_status & SC_STATUS_REVOKED)
45514623
ret = nfserr_deleg_revoked;
45524624
else if (s->sc_status & SC_STATUS_CLOSED)
45534625
ret = nfserr_bad_stateid;
@@ -5136,6 +5208,11 @@ nfs4_check_deleg(struct nfs4_client *cl, struct nfsd4_open *open,
51365208
deleg = find_deleg_stateid(cl, &open->op_delegate_stateid);
51375209
if (deleg == NULL)
51385210
goto out;
5211+
if (deleg->dl_stid.sc_status & SC_STATUS_ADMIN_REVOKED) {
5212+
nfs4_put_stid(&deleg->dl_stid);
5213+
status = nfserr_admin_revoked;
5214+
goto out;
5215+
}
51395216
if (deleg->dl_stid.sc_status & SC_STATUS_REVOKED) {
51405217
nfs4_put_stid(&deleg->dl_stid);
51415218
status = nfserr_deleg_revoked;
@@ -6443,6 +6520,8 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
64436520
*/
64446521
statusmask |= SC_STATUS_REVOKED;
64456522

6523+
statusmask |= SC_STATUS_ADMIN_REVOKED;
6524+
64466525
if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
64476526
CLOSE_STATEID(stateid))
64486527
return nfserr_bad_stateid;
@@ -6461,6 +6540,10 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
64616540
nfs4_put_stid(stid);
64626541
return nfserr_deleg_revoked;
64636542
}
6543+
if (stid->sc_status & SC_STATUS_ADMIN_REVOKED) {
6544+
nfs4_put_stid(stid);
6545+
return nfserr_admin_revoked;
6546+
}
64646547
*s = stid;
64656548
return nfs_ok;
64666549
}

fs/nfsd/nfsctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
281281
* 3. Is that directory the root of an exported file system?
282282
*/
283283
error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb);
284+
nfsd4_revoke_states(netns(file), path.dentry->d_sb);
284285

285286
path_put(&path);
286287
return error;

fs/nfsd/nfsd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ void nfsd_lockd_shutdown(void);
275275
#define nfserr_no_grace cpu_to_be32(NFSERR_NO_GRACE)
276276
#define nfserr_reclaim_bad cpu_to_be32(NFSERR_RECLAIM_BAD)
277277
#define nfserr_badname cpu_to_be32(NFSERR_BADNAME)
278+
#define nfserr_admin_revoked cpu_to_be32(NFS4ERR_ADMIN_REVOKED)
278279
#define nfserr_cb_path_down cpu_to_be32(NFSERR_CB_PATH_DOWN)
279280
#define nfserr_locked cpu_to_be32(NFSERR_LOCKED)
280281
#define nfserr_wrongsec cpu_to_be32(NFSERR_WRONGSEC)

fs/nfsd/state.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct nfs4_stid {
112112
#define SC_STATUS_CLOSED BIT(0)
113113
/* For a deleg stateid kept around only to process free_stateid's: */
114114
#define SC_STATUS_REVOKED BIT(1)
115+
#define SC_STATUS_ADMIN_REVOKED BIT(2)
115116
unsigned short sc_status;
116117

117118
struct list_head sc_cp_list;
@@ -367,6 +368,7 @@ struct nfs4_client {
367368
clientid_t cl_clientid; /* generated by server */
368369
nfs4_verifier cl_confirm; /* generated by server */
369370
u32 cl_minorversion;
371+
atomic_t cl_admin_revoked; /* count of admin-revoked states */
370372
/* NFSv4.1 client implementation id: */
371373
struct xdr_netobj cl_nii_domain;
372374
struct xdr_netobj cl_nii_name;
@@ -730,6 +732,14 @@ static inline void get_nfs4_file(struct nfs4_file *fi)
730732
}
731733
struct nfsd_file *find_any_file(struct nfs4_file *f);
732734

735+
#ifdef CONFIG_NFSD_V4
736+
void nfsd4_revoke_states(struct net *net, struct super_block *sb);
737+
#else
738+
static inline void nfsd4_revoke_states(struct net *net, struct super_block *sb)
739+
{
740+
}
741+
#endif
742+
733743
/* grace period management */
734744
void nfsd4_end_grace(struct nfsd_net *nn);
735745

fs/nfsd/trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ DEFINE_STATESEQID_EVENT(open_confirm);
653653
#define show_stid_status(x) \
654654
__print_flags(x, "|", \
655655
{ SC_STATUS_CLOSED, "CLOSED" }, \
656-
{ SC_STATUS_REVOKED, "REVOKED" }) \
656+
{ SC_STATUS_REVOKED, "REVOKED" }, \
657+
{ SC_STATUS_ADMIN_REVOKED, "ADMIN_REVOKED" })
657658

658659
DECLARE_EVENT_CLASS(nfsd_stid_class,
659660
TP_PROTO(

0 commit comments

Comments
 (0)