aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@primarydata.com>2016-09-22 13:38:59 -0400
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2016-09-27 14:33:44 -0400
commit45870d6909d5a1f702d2a3781d8fc831301d13c8 (patch)
tree9343039cc514fcd1b462a0d633292ffb82256c06 /fs/nfs
parent41020b671aa553f31e766fd1e9d38598eba72bd6 (diff)
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 <trond.myklebust@primarydata.com> Tested-by: Oleg Drokin <green@linuxhacker.ru> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/delegation.c97
-rw-r--r--fs/nfs/delegation.h4
-rw-r--r--fs/nfs/nfs4_fs.h3
-rw-r--r--fs/nfs/nfs4proc.c10
-rw-r--r--fs/nfs/nfs4state.c17
5 files changed, 122 insertions, 9 deletions
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index e5212e5c73d2..dfb300901f7e 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -812,8 +812,15 @@ static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
812{ 812{
813 struct nfs_delegation *delegation; 813 struct nfs_delegation *delegation;
814 814
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;
816 set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); 822 set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
823 }
817} 824}
818 825
819/** 826/**
@@ -877,6 +884,94 @@ restart:
877 rcu_read_unlock(); 884 rcu_read_unlock();
878} 885}
879 886
887static 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
895static 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 */
910void 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 */
929void 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
938restart:
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
880/** 975/**
881 * nfs_delegations_present - check for existence of delegations 976 * nfs_delegations_present - check for existence of delegations
882 * @clp: client state handle 977 * @clp: client state handle
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index d40827af5913..1442e3b1521d 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -32,6 +32,7 @@ enum {
32 NFS_DELEGATION_REFERENCED, 32 NFS_DELEGATION_REFERENCED,
33 NFS_DELEGATION_RETURNING, 33 NFS_DELEGATION_RETURNING,
34 NFS_DELEGATION_REVOKED, 34 NFS_DELEGATION_REVOKED,
35 NFS_DELEGATION_TEST_EXPIRED,
35}; 36};
36 37
37int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); 38int 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)
52void nfs_delegation_mark_reclaim(struct nfs_client *clp); 53void nfs_delegation_mark_reclaim(struct nfs_client *clp);
53void nfs_delegation_reap_unclaimed(struct nfs_client *clp); 54void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
54 55
56void nfs_mark_test_expired_all_delegations(struct nfs_client *clp);
57void nfs_reap_expired_delegations(struct nfs_client *clp);
58
55/* NFSv4 delegation-related procedures */ 59/* NFSv4 delegation-related procedures */
56int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync); 60int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
57int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type); 61int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type);
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 2d1889de69fb..9b3a82abab07 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -39,6 +39,7 @@ enum nfs4_client_state {
39 NFS4CLNT_BIND_CONN_TO_SESSION, 39 NFS4CLNT_BIND_CONN_TO_SESSION,
40 NFS4CLNT_MOVED, 40 NFS4CLNT_MOVED,
41 NFS4CLNT_LEASE_MOVED, 41 NFS4CLNT_LEASE_MOVED,
42 NFS4CLNT_DELEGATION_EXPIRED,
42}; 43};
43 44
44#define NFS4_RENEW_TIMEOUT 0x01 45#define NFS4_RENEW_TIMEOUT 0x01
@@ -57,6 +58,8 @@ struct nfs4_minor_version_ops {
57 struct nfs_fsinfo *); 58 struct nfs_fsinfo *);
58 void (*free_lock_state)(struct nfs_server *, 59 void (*free_lock_state)(struct nfs_server *,
59 struct nfs4_lock_state *); 60 struct nfs4_lock_state *);
61 int (*test_and_free_expired)(struct nfs_server *,
62 nfs4_stateid *, struct rpc_cred *);
60 struct nfs_seqid * 63 struct nfs_seqid *
61 (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); 64 (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
62 int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *); 65 int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 4cc86001220a..083786aad83c 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2408,6 +2408,13 @@ static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
2408 return nfs4_open_expired(sp, state); 2408 return nfs4_open_expired(sp, state);
2409} 2409}
2410 2410
2411static 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
2411#if defined(CONFIG_NFS_V4_1) 2418#if defined(CONFIG_NFS_V4_1)
2412static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, 2419static int nfs41_test_and_free_expired_stateid(struct nfs_server *server,
2413 nfs4_stateid *stateid, 2420 nfs4_stateid *stateid,
@@ -9061,6 +9068,7 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
9061 .match_stateid = nfs4_match_stateid, 9068 .match_stateid = nfs4_match_stateid,
9062 .find_root_sec = nfs4_find_root_sec, 9069 .find_root_sec = nfs4_find_root_sec,
9063 .free_lock_state = nfs4_release_lockowner, 9070 .free_lock_state = nfs4_release_lockowner,
9071 .test_and_free_expired = nfs40_test_and_free_expired_stateid,
9064 .alloc_seqid = nfs_alloc_seqid, 9072 .alloc_seqid = nfs_alloc_seqid,
9065 .call_sync_ops = &nfs40_call_sync_ops, 9073 .call_sync_ops = &nfs40_call_sync_ops,
9066 .reboot_recovery_ops = &nfs40_reboot_recovery_ops, 9074 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
@@ -9088,6 +9096,7 @@ static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
9088 .match_stateid = nfs41_match_stateid, 9096 .match_stateid = nfs41_match_stateid,
9089 .find_root_sec = nfs41_find_root_sec, 9097 .find_root_sec = nfs41_find_root_sec,
9090 .free_lock_state = nfs41_free_lock_state, 9098 .free_lock_state = nfs41_free_lock_state,
9099 .test_and_free_expired = nfs41_test_and_free_expired_stateid,
9091 .alloc_seqid = nfs_alloc_no_seqid, 9100 .alloc_seqid = nfs_alloc_no_seqid,
9092 .session_trunk = nfs4_test_session_trunk, 9101 .session_trunk = nfs4_test_session_trunk,
9093 .call_sync_ops = &nfs41_call_sync_ops, 9102 .call_sync_ops = &nfs41_call_sync_ops,
@@ -9118,6 +9127,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
9118 .find_root_sec = nfs41_find_root_sec, 9127 .find_root_sec = nfs41_find_root_sec,
9119 .free_lock_state = nfs41_free_lock_state, 9128 .free_lock_state = nfs41_free_lock_state,
9120 .call_sync_ops = &nfs41_call_sync_ops, 9129 .call_sync_ops = &nfs41_call_sync_ops,
9130 .test_and_free_expired = nfs41_test_and_free_expired_stateid,
9121 .alloc_seqid = nfs_alloc_no_seqid, 9131 .alloc_seqid = nfs_alloc_no_seqid,
9122 .session_trunk = nfs4_test_session_trunk, 9132 .session_trunk = nfs4_test_session_trunk,
9123 .reboot_recovery_ops = &nfs41_reboot_recovery_ops, 9133 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 9801b5bb5fac..63da0411e2af 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1656,15 +1656,9 @@ static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
1656 put_rpccred(cred); 1656 put_rpccred(cred);
1657} 1657}
1658 1658
1659static void nfs_delegation_clear_all(struct nfs_client *clp)
1660{
1661 nfs_delegation_mark_reclaim(clp);
1662 nfs_delegation_reap_unclaimed(clp);
1663}
1664
1665static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp) 1659static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
1666{ 1660{
1667 nfs_delegation_clear_all(clp); 1661 nfs_mark_test_expired_all_delegations(clp);
1668 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce); 1662 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
1669} 1663}
1670 1664
@@ -2195,7 +2189,7 @@ static void nfs41_handle_all_state_revoked(struct nfs_client *clp)
2195 2189
2196static void nfs41_handle_some_state_revoked(struct nfs_client *clp) 2190static void nfs41_handle_some_state_revoked(struct nfs_client *clp)
2197{ 2191{
2198 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce); 2192 nfs4_state_start_reclaim_nograce(clp);
2199 nfs4_schedule_state_manager(clp); 2193 nfs4_schedule_state_manager(clp);
2200 2194
2201 dprintk("%s: state revoked on server %s\n", __func__, clp->cl_hostname); 2195 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)
2420 nfs4_state_end_reclaim_reboot(clp); 2414 nfs4_state_end_reclaim_reboot(clp);
2421 } 2415 }
2422 2416
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
2423 /* Now recover expired state... */ 2424 /* Now recover expired state... */
2424 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) { 2425 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
2425 section = "reclaim nograce"; 2426 section = "reclaim nograce";