aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/nfs4state.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/nfs4state.c')
-rw-r--r--fs/nfs/nfs4state.c225
1 files changed, 156 insertions, 69 deletions
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 2ef4fecf3984..e76427e6346f 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -116,6 +116,68 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
116 116
117#if defined(CONFIG_NFS_V4_1) 117#if defined(CONFIG_NFS_V4_1)
118 118
119static int nfs41_setup_state_renewal(struct nfs_client *clp)
120{
121 int status;
122 struct nfs_fsinfo fsinfo;
123
124 status = nfs4_proc_get_lease_time(clp, &fsinfo);
125 if (status == 0) {
126 /* Update lease time and schedule renewal */
127 spin_lock(&clp->cl_lock);
128 clp->cl_lease_time = fsinfo.lease_time * HZ;
129 clp->cl_last_renewal = jiffies;
130 spin_unlock(&clp->cl_lock);
131
132 nfs4_schedule_state_renewal(clp);
133 }
134
135 return status;
136}
137
138static void nfs41_end_drain_session(struct nfs_client *clp,
139 struct nfs4_session *ses)
140{
141 if (test_and_clear_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state))
142 rpc_wake_up(&ses->fc_slot_table.slot_tbl_waitq);
143}
144
145static int nfs41_begin_drain_session(struct nfs_client *clp,
146 struct nfs4_session *ses)
147{
148 struct nfs4_slot_table *tbl = &ses->fc_slot_table;
149
150 spin_lock(&tbl->slot_tbl_lock);
151 set_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state);
152 if (tbl->highest_used_slotid != -1) {
153 INIT_COMPLETION(ses->complete);
154 spin_unlock(&tbl->slot_tbl_lock);
155 return wait_for_completion_interruptible(&ses->complete);
156 }
157 spin_unlock(&tbl->slot_tbl_lock);
158 return 0;
159}
160
161int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
162{
163 int status;
164
165 status = nfs41_begin_drain_session(clp, clp->cl_session);
166 if (status != 0)
167 goto out;
168 status = nfs4_proc_exchange_id(clp, cred);
169 if (status != 0)
170 goto out;
171 status = nfs4_proc_create_session(clp);
172 if (status != 0)
173 goto out;
174 nfs41_end_drain_session(clp, clp->cl_session);
175 nfs41_setup_state_renewal(clp);
176 nfs_mark_client_ready(clp, NFS_CS_READY);
177out:
178 return status;
179}
180
119struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp) 181struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)
120{ 182{
121 struct rpc_cred *cred; 183 struct rpc_cred *cred;
@@ -877,6 +939,10 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
877 case -NFS4ERR_EXPIRED: 939 case -NFS4ERR_EXPIRED:
878 case -NFS4ERR_NO_GRACE: 940 case -NFS4ERR_NO_GRACE:
879 case -NFS4ERR_STALE_CLIENTID: 941 case -NFS4ERR_STALE_CLIENTID:
942 case -NFS4ERR_BADSESSION:
943 case -NFS4ERR_BADSLOT:
944 case -NFS4ERR_BAD_HIGH_SLOT:
945 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
880 goto out; 946 goto out;
881 default: 947 default:
882 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", 948 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n",
@@ -959,6 +1025,10 @@ restart:
959 case -NFS4ERR_NO_GRACE: 1025 case -NFS4ERR_NO_GRACE:
960 nfs4_state_mark_reclaim_nograce(sp->so_client, state); 1026 nfs4_state_mark_reclaim_nograce(sp->so_client, state);
961 case -NFS4ERR_STALE_CLIENTID: 1027 case -NFS4ERR_STALE_CLIENTID:
1028 case -NFS4ERR_BADSESSION:
1029 case -NFS4ERR_BADSLOT:
1030 case -NFS4ERR_BAD_HIGH_SLOT:
1031 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
962 goto out_err; 1032 goto out_err;
963 } 1033 }
964 nfs4_put_open_state(state); 1034 nfs4_put_open_state(state);
@@ -1011,6 +1081,14 @@ static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
1011 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot); 1081 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot);
1012} 1082}
1013 1083
1084static void nfs4_reclaim_complete(struct nfs_client *clp,
1085 const struct nfs4_state_recovery_ops *ops)
1086{
1087 /* Notify the server we're done reclaiming our state */
1088 if (ops->reclaim_complete)
1089 (void)ops->reclaim_complete(clp);
1090}
1091
1014static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp) 1092static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
1015{ 1093{
1016 struct nfs4_state_owner *sp; 1094 struct nfs4_state_owner *sp;
@@ -1020,6 +1098,9 @@ static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
1020 if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) 1098 if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
1021 return; 1099 return;
1022 1100
1101 nfs4_reclaim_complete(clp,
1102 nfs4_reboot_recovery_ops[clp->cl_minorversion]);
1103
1023 for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { 1104 for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
1024 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 1105 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
1025 spin_lock(&sp->so_lock); 1106 spin_lock(&sp->so_lock);
@@ -1046,25 +1127,25 @@ static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
1046 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce); 1127 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
1047} 1128}
1048 1129
1049static void nfs4_state_end_reclaim_nograce(struct nfs_client *clp) 1130static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1050{
1051 clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
1052}
1053
1054static void nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1055{ 1131{
1056 switch (error) { 1132 switch (error) {
1057 case -NFS4ERR_CB_PATH_DOWN: 1133 case -NFS4ERR_CB_PATH_DOWN:
1058 nfs_handle_cb_pathdown(clp); 1134 nfs_handle_cb_pathdown(clp);
1059 break; 1135 return 0;
1136 case -NFS4ERR_NO_GRACE:
1137 nfs4_state_end_reclaim_reboot(clp);
1138 return 0;
1060 case -NFS4ERR_STALE_CLIENTID: 1139 case -NFS4ERR_STALE_CLIENTID:
1061 case -NFS4ERR_LEASE_MOVED: 1140 case -NFS4ERR_LEASE_MOVED:
1062 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1141 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1142 nfs4_state_end_reclaim_reboot(clp);
1063 nfs4_state_start_reclaim_reboot(clp); 1143 nfs4_state_start_reclaim_reboot(clp);
1064 break; 1144 break;
1065 case -NFS4ERR_EXPIRED: 1145 case -NFS4ERR_EXPIRED:
1066 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1146 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1067 nfs4_state_start_reclaim_nograce(clp); 1147 nfs4_state_start_reclaim_nograce(clp);
1148 break;
1068 case -NFS4ERR_BADSESSION: 1149 case -NFS4ERR_BADSESSION:
1069 case -NFS4ERR_BADSLOT: 1150 case -NFS4ERR_BADSLOT:
1070 case -NFS4ERR_BAD_HIGH_SLOT: 1151 case -NFS4ERR_BAD_HIGH_SLOT:
@@ -1072,8 +1153,11 @@ static void nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1072 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: 1153 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1073 case -NFS4ERR_SEQ_FALSE_RETRY: 1154 case -NFS4ERR_SEQ_FALSE_RETRY:
1074 case -NFS4ERR_SEQ_MISORDERED: 1155 case -NFS4ERR_SEQ_MISORDERED:
1075 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 1156 set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1157 /* Zero session reset errors */
1158 return 0;
1076 } 1159 }
1160 return error;
1077} 1161}
1078 1162
1079static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops) 1163static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops)
@@ -1093,8 +1177,7 @@ restart:
1093 if (status < 0) { 1177 if (status < 0) {
1094 set_bit(ops->owner_flag_bit, &sp->so_flags); 1178 set_bit(ops->owner_flag_bit, &sp->so_flags);
1095 nfs4_put_state_owner(sp); 1179 nfs4_put_state_owner(sp);
1096 nfs4_recovery_handle_error(clp, status); 1180 return nfs4_recovery_handle_error(clp, status);
1097 return status;
1098 } 1181 }
1099 nfs4_put_state_owner(sp); 1182 nfs4_put_state_owner(sp);
1100 goto restart; 1183 goto restart;
@@ -1124,8 +1207,7 @@ static int nfs4_check_lease(struct nfs_client *clp)
1124 status = ops->renew_lease(clp, cred); 1207 status = ops->renew_lease(clp, cred);
1125 put_rpccred(cred); 1208 put_rpccred(cred);
1126out: 1209out:
1127 nfs4_recovery_handle_error(clp, status); 1210 return nfs4_recovery_handle_error(clp, status);
1128 return status;
1129} 1211}
1130 1212
1131static int nfs4_reclaim_lease(struct nfs_client *clp) 1213static int nfs4_reclaim_lease(struct nfs_client *clp)
@@ -1151,55 +1233,65 @@ static int nfs4_reclaim_lease(struct nfs_client *clp)
1151} 1233}
1152 1234
1153#ifdef CONFIG_NFS_V4_1 1235#ifdef CONFIG_NFS_V4_1
1154static void nfs4_session_recovery_handle_error(struct nfs_client *clp, int err) 1236void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags)
1155{ 1237{
1156 switch (err) { 1238 if (!flags)
1157 case -NFS4ERR_STALE_CLIENTID: 1239 return;
1240 else if (flags & SEQ4_STATUS_RESTART_RECLAIM_NEEDED) {
1158 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1241 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1159 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 1242 nfs4_state_start_reclaim_reboot(clp);
1160 } 1243 nfs4_schedule_state_recovery(clp);
1244 } else if (flags & (SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED |
1245 SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED |
1246 SEQ4_STATUS_ADMIN_STATE_REVOKED |
1247 SEQ4_STATUS_RECALLABLE_STATE_REVOKED |
1248 SEQ4_STATUS_LEASE_MOVED)) {
1249 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1250 nfs4_state_start_reclaim_nograce(clp);
1251 nfs4_schedule_state_recovery(clp);
1252 } else if (flags & (SEQ4_STATUS_CB_PATH_DOWN |
1253 SEQ4_STATUS_BACKCHANNEL_FAULT |
1254 SEQ4_STATUS_CB_PATH_DOWN_SESSION))
1255 nfs_expire_all_delegations(clp);
1161} 1256}
1162 1257
1163static int nfs4_reset_session(struct nfs_client *clp) 1258static int nfs4_reset_session(struct nfs_client *clp)
1164{ 1259{
1260 struct nfs4_session *ses = clp->cl_session;
1165 int status; 1261 int status;
1166 1262
1263 status = nfs41_begin_drain_session(clp, ses);
1264 if (status != 0)
1265 return status;
1266
1167 status = nfs4_proc_destroy_session(clp->cl_session); 1267 status = nfs4_proc_destroy_session(clp->cl_session);
1168 if (status && status != -NFS4ERR_BADSESSION && 1268 if (status && status != -NFS4ERR_BADSESSION &&
1169 status != -NFS4ERR_DEADSESSION) { 1269 status != -NFS4ERR_DEADSESSION) {
1170 nfs4_session_recovery_handle_error(clp, status); 1270 status = nfs4_recovery_handle_error(clp, status);
1171 goto out; 1271 goto out;
1172 } 1272 }
1173 1273
1174 memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN); 1274 memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN);
1175 status = nfs4_proc_create_session(clp, 1); 1275 status = nfs4_proc_create_session(clp);
1176 if (status) 1276 if (status)
1177 nfs4_session_recovery_handle_error(clp, status); 1277 status = nfs4_recovery_handle_error(clp, status);
1178 /* fall through*/
1179out:
1180 /* Wake up the next rpc task even on error */
1181 rpc_wake_up_next(&clp->cl_session->fc_slot_table.slot_tbl_waitq);
1182 return status;
1183}
1184
1185static int nfs4_initialize_session(struct nfs_client *clp)
1186{
1187 int status;
1188 1278
1189 status = nfs4_proc_create_session(clp, 0); 1279out:
1190 if (!status) { 1280 /*
1191 nfs_mark_client_ready(clp, NFS_CS_READY); 1281 * Let the state manager reestablish state
1192 } else if (status == -NFS4ERR_STALE_CLIENTID) { 1282 * without waking other tasks yet.
1193 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); 1283 */
1194 set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state); 1284 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) {
1195 } else { 1285 /* Wake up the next rpc task */
1196 nfs_mark_client_ready(clp, status); 1286 nfs41_end_drain_session(clp, ses);
1287 if (status == 0)
1288 nfs41_setup_state_renewal(clp);
1197 } 1289 }
1198 return status; 1290 return status;
1199} 1291}
1292
1200#else /* CONFIG_NFS_V4_1 */ 1293#else /* CONFIG_NFS_V4_1 */
1201static int nfs4_reset_session(struct nfs_client *clp) { return 0; } 1294static int nfs4_reset_session(struct nfs_client *clp) { return 0; }
1202static int nfs4_initialize_session(struct nfs_client *clp) { return 0; }
1203#endif /* CONFIG_NFS_V4_1 */ 1295#endif /* CONFIG_NFS_V4_1 */
1204 1296
1205/* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors 1297/* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
@@ -1234,7 +1326,8 @@ static void nfs4_state_manager(struct nfs_client *clp)
1234 status = nfs4_reclaim_lease(clp); 1326 status = nfs4_reclaim_lease(clp);
1235 if (status) { 1327 if (status) {
1236 nfs4_set_lease_expired(clp, status); 1328 nfs4_set_lease_expired(clp, status);
1237 if (status == -EAGAIN) 1329 if (test_bit(NFS4CLNT_LEASE_EXPIRED,
1330 &clp->cl_state))
1238 continue; 1331 continue;
1239 if (clp->cl_cons_state == 1332 if (clp->cl_cons_state ==
1240 NFS_CS_SESSION_INITING) 1333 NFS_CS_SESSION_INITING)
@@ -1242,55 +1335,51 @@ static void nfs4_state_manager(struct nfs_client *clp)
1242 goto out_error; 1335 goto out_error;
1243 } 1336 }
1244 clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); 1337 clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1338 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
1245 } 1339 }
1246 1340
1247 if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) { 1341 if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) {
1248 status = nfs4_check_lease(clp); 1342 status = nfs4_check_lease(clp);
1249 if (status != 0) 1343 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1250 continue; 1344 continue;
1345 if (status < 0 && status != -NFS4ERR_CB_PATH_DOWN)
1346 goto out_error;
1251 } 1347 }
1348
1252 /* Initialize or reset the session */ 1349 /* Initialize or reset the session */
1253 if (test_and_clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state) 1350 if (test_and_clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)
1254 && nfs4_has_session(clp)) { 1351 && nfs4_has_session(clp)) {
1255 if (clp->cl_cons_state == NFS_CS_SESSION_INITING) 1352 status = nfs4_reset_session(clp);
1256 status = nfs4_initialize_session(clp); 1353 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1257 else 1354 continue;
1258 status = nfs4_reset_session(clp); 1355 if (status < 0)
1259 if (status) {
1260 if (status == -NFS4ERR_STALE_CLIENTID)
1261 continue;
1262 goto out_error; 1356 goto out_error;
1263 }
1264 } 1357 }
1358
1265 /* First recover reboot state... */ 1359 /* First recover reboot state... */
1266 if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) { 1360 if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
1267 status = nfs4_do_reclaim(clp, 1361 status = nfs4_do_reclaim(clp,
1268 nfs4_reboot_recovery_ops[clp->cl_minorversion]); 1362 nfs4_reboot_recovery_ops[clp->cl_minorversion]);
1269 if (status == -NFS4ERR_STALE_CLIENTID) 1363 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
1270 continue; 1364 test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
1271 if (test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state))
1272 continue; 1365 continue;
1273 nfs4_state_end_reclaim_reboot(clp); 1366 nfs4_state_end_reclaim_reboot(clp);
1274 continue; 1367 if (test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state))
1368 continue;
1369 if (status < 0)
1370 goto out_error;
1275 } 1371 }
1276 1372
1277 /* Now recover expired state... */ 1373 /* Now recover expired state... */
1278 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) { 1374 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
1279 status = nfs4_do_reclaim(clp, 1375 status = nfs4_do_reclaim(clp,
1280 nfs4_nograce_recovery_ops[clp->cl_minorversion]); 1376 nfs4_nograce_recovery_ops[clp->cl_minorversion]);
1281 if (status < 0) { 1377 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
1282 set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state); 1378 test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) ||
1283 if (status == -NFS4ERR_STALE_CLIENTID) 1379 test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
1284 continue; 1380 continue;
1285 if (status == -NFS4ERR_EXPIRED) 1381 if (status < 0)
1286 continue;
1287 if (test_bit(NFS4CLNT_SESSION_SETUP,
1288 &clp->cl_state))
1289 continue;
1290 goto out_error; 1382 goto out_error;
1291 } else
1292 nfs4_state_end_reclaim_nograce(clp);
1293 continue;
1294 } 1383 }
1295 1384
1296 if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) { 1385 if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) {
@@ -1309,8 +1398,6 @@ static void nfs4_state_manager(struct nfs_client *clp)
1309out_error: 1398out_error:
1310 printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s" 1399 printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s"
1311 " with error %d\n", clp->cl_hostname, -status); 1400 " with error %d\n", clp->cl_hostname, -status);
1312 if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
1313 nfs4_state_end_reclaim_reboot(clp);
1314 nfs4_clear_state_manager_bit(clp); 1401 nfs4_clear_state_manager_bit(clp);
1315} 1402}
1316 1403