Skip to content

Commit 45870d6

Browse files
trondmypdamschuma-ntap
authored andcommitted
NFSv4.1: Test delegation stateids when server declares "some state revoked"
According to RFC5661, if any of the SEQUENCE status bits SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED, SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED, SEQ4_STATUS_ADMIN_STATE_REVOKED, or SEQ4_STATUS_RECALLABLE_STATE_REVOKED are set, then we need to use TEST_STATEID to figure out which stateids have been revoked, so we can acknowledge the loss of state using FREE_STATEID. While we already do this for open and lock state, we have not been doing so for all the delegations. Signed-off-by: Trond Myklebust <[email protected]> Tested-by: Oleg Drokin <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 41020b6 commit 45870d6

File tree

5 files changed

+122
-9
lines changed

5 files changed

+122
-9
lines changed

fs/nfs/delegation.c

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,15 @@ static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
812812
{
813813
struct nfs_delegation *delegation;
814814

815-
list_for_each_entry_rcu(delegation, &server->delegations, super_list)
815+
list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
816+
/*
817+
* If the delegation may have been admin revoked, then we
818+
* cannot reclaim it.
819+
*/
820+
if (test_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags))
821+
continue;
816822
set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
823+
}
817824
}
818825

819826
/**
@@ -877,6 +884,94 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
877884
rcu_read_unlock();
878885
}
879886

887+
static void nfs_mark_test_expired_delegation(struct nfs_server *server,
888+
struct nfs_delegation *delegation)
889+
{
890+
clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
891+
set_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
892+
set_bit(NFS4CLNT_DELEGATION_EXPIRED, &server->nfs_client->cl_state);
893+
}
894+
895+
static void nfs_delegation_mark_test_expired_server(struct nfs_server *server)
896+
{
897+
struct nfs_delegation *delegation;
898+
899+
list_for_each_entry_rcu(delegation, &server->delegations, super_list)
900+
nfs_mark_test_expired_delegation(server, delegation);
901+
}
902+
903+
/**
904+
* nfs_mark_test_expired_all_delegations - mark all delegations for testing
905+
* @clp: nfs_client to process
906+
*
907+
* Iterates through all the delegations associated with this server and
908+
* marks them as needing to be checked for validity.
909+
*/
910+
void nfs_mark_test_expired_all_delegations(struct nfs_client *clp)
911+
{
912+
struct nfs_server *server;
913+
914+
rcu_read_lock();
915+
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
916+
nfs_delegation_mark_test_expired_server(server);
917+
rcu_read_unlock();
918+
}
919+
920+
/**
921+
* nfs_reap_expired_delegations - reap expired delegations
922+
* @clp: nfs_client to process
923+
*
924+
* Iterates through all the delegations associated with this server and
925+
* checks if they have may have been revoked. This function is usually
926+
* expected to be called in cases where the server may have lost its
927+
* lease.
928+
*/
929+
void nfs_reap_expired_delegations(struct nfs_client *clp)
930+
{
931+
const struct nfs4_minor_version_ops *ops = clp->cl_mvops;
932+
struct nfs_delegation *delegation;
933+
struct nfs_server *server;
934+
struct inode *inode;
935+
struct rpc_cred *cred;
936+
nfs4_stateid stateid;
937+
938+
restart:
939+
rcu_read_lock();
940+
list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
941+
list_for_each_entry_rcu(delegation, &server->delegations,
942+
super_list) {
943+
if (test_bit(NFS_DELEGATION_RETURNING,
944+
&delegation->flags))
945+
continue;
946+
if (test_bit(NFS_DELEGATION_TEST_EXPIRED,
947+
&delegation->flags) == 0)
948+
continue;
949+
if (!nfs_sb_active(server->super))
950+
continue;
951+
inode = nfs_delegation_grab_inode(delegation);
952+
if (inode == NULL) {
953+
rcu_read_unlock();
954+
nfs_sb_deactive(server->super);
955+
goto restart;
956+
}
957+
cred = get_rpccred_rcu(delegation->cred);
958+
nfs4_stateid_copy(&stateid, &delegation->stateid);
959+
clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
960+
rcu_read_unlock();
961+
if (cred != NULL &&
962+
ops->test_and_free_expired(server, &stateid, cred) < 0) {
963+
nfs_revoke_delegation(inode, &stateid);
964+
nfs_inode_find_state_and_recover(inode, &stateid);
965+
}
966+
put_rpccred(cred);
967+
iput(inode);
968+
nfs_sb_deactive(server->super);
969+
goto restart;
970+
}
971+
}
972+
rcu_read_unlock();
973+
}
974+
880975
/**
881976
* nfs_delegations_present - check for existence of delegations
882977
* @clp: client state handle

fs/nfs/delegation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum {
3232
NFS_DELEGATION_REFERENCED,
3333
NFS_DELEGATION_RETURNING,
3434
NFS_DELEGATION_REVOKED,
35+
NFS_DELEGATION_TEST_EXPIRED,
3536
};
3637

3738
int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
@@ -52,6 +53,9 @@ void nfs_remove_bad_delegation(struct inode *inode, const nfs4_stateid *stateid)
5253
void nfs_delegation_mark_reclaim(struct nfs_client *clp);
5354
void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
5455

56+
void nfs_mark_test_expired_all_delegations(struct nfs_client *clp);
57+
void nfs_reap_expired_delegations(struct nfs_client *clp);
58+
5559
/* NFSv4 delegation-related procedures */
5660
int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
5761
int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type);

fs/nfs/nfs4_fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum nfs4_client_state {
3939
NFS4CLNT_BIND_CONN_TO_SESSION,
4040
NFS4CLNT_MOVED,
4141
NFS4CLNT_LEASE_MOVED,
42+
NFS4CLNT_DELEGATION_EXPIRED,
4243
};
4344

4445
#define NFS4_RENEW_TIMEOUT 0x01
@@ -57,6 +58,8 @@ struct nfs4_minor_version_ops {
5758
struct nfs_fsinfo *);
5859
void (*free_lock_state)(struct nfs_server *,
5960
struct nfs4_lock_state *);
61+
int (*test_and_free_expired)(struct nfs_server *,
62+
nfs4_stateid *, struct rpc_cred *);
6063
struct nfs_seqid *
6164
(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
6265
int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *);

fs/nfs/nfs4proc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,13 @@ static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
24082408
return nfs4_open_expired(sp, state);
24092409
}
24102410

2411+
static int nfs40_test_and_free_expired_stateid(struct nfs_server *server,
2412+
nfs4_stateid *stateid,
2413+
struct rpc_cred *cred)
2414+
{
2415+
return -NFS4ERR_BAD_STATEID;
2416+
}
2417+
24112418
#if defined(CONFIG_NFS_V4_1)
24122419
static int nfs41_test_and_free_expired_stateid(struct nfs_server *server,
24132420
nfs4_stateid *stateid,
@@ -9061,6 +9068,7 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
90619068
.match_stateid = nfs4_match_stateid,
90629069
.find_root_sec = nfs4_find_root_sec,
90639070
.free_lock_state = nfs4_release_lockowner,
9071+
.test_and_free_expired = nfs40_test_and_free_expired_stateid,
90649072
.alloc_seqid = nfs_alloc_seqid,
90659073
.call_sync_ops = &nfs40_call_sync_ops,
90669074
.reboot_recovery_ops = &nfs40_reboot_recovery_ops,
@@ -9088,6 +9096,7 @@ static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
90889096
.match_stateid = nfs41_match_stateid,
90899097
.find_root_sec = nfs41_find_root_sec,
90909098
.free_lock_state = nfs41_free_lock_state,
9099+
.test_and_free_expired = nfs41_test_and_free_expired_stateid,
90919100
.alloc_seqid = nfs_alloc_no_seqid,
90929101
.session_trunk = nfs4_test_session_trunk,
90939102
.call_sync_ops = &nfs41_call_sync_ops,
@@ -9118,6 +9127,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
91189127
.find_root_sec = nfs41_find_root_sec,
91199128
.free_lock_state = nfs41_free_lock_state,
91209129
.call_sync_ops = &nfs41_call_sync_ops,
9130+
.test_and_free_expired = nfs41_test_and_free_expired_stateid,
91219131
.alloc_seqid = nfs_alloc_no_seqid,
91229132
.session_trunk = nfs4_test_session_trunk,
91239133
.reboot_recovery_ops = &nfs41_reboot_recovery_ops,

fs/nfs/nfs4state.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,15 +1656,9 @@ static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
16561656
put_rpccred(cred);
16571657
}
16581658

1659-
static void nfs_delegation_clear_all(struct nfs_client *clp)
1660-
{
1661-
nfs_delegation_mark_reclaim(clp);
1662-
nfs_delegation_reap_unclaimed(clp);
1663-
}
1664-
16651659
static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
16661660
{
1667-
nfs_delegation_clear_all(clp);
1661+
nfs_mark_test_expired_all_delegations(clp);
16681662
nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
16691663
}
16701664

@@ -2195,7 +2189,7 @@ static void nfs41_handle_all_state_revoked(struct nfs_client *clp)
21952189

21962190
static void nfs41_handle_some_state_revoked(struct nfs_client *clp)
21972191
{
2198-
nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
2192+
nfs4_state_start_reclaim_nograce(clp);
21992193
nfs4_schedule_state_manager(clp);
22002194

22012195
dprintk("%s: state revoked on server %s\n", __func__, clp->cl_hostname);
@@ -2420,6 +2414,13 @@ static void nfs4_state_manager(struct nfs_client *clp)
24202414
nfs4_state_end_reclaim_reboot(clp);
24212415
}
24222416

2417+
/* Detect expired delegations... */
2418+
if (test_and_clear_bit(NFS4CLNT_DELEGATION_EXPIRED, &clp->cl_state)) {
2419+
section = "detect expired delegations";
2420+
nfs_reap_expired_delegations(clp);
2421+
continue;
2422+
}
2423+
24232424
/* Now recover expired state... */
24242425
if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
24252426
section = "reclaim nograce";

0 commit comments

Comments
 (0)