| .. | .. | 
|---|
| 49 | 49 | #include <linux/workqueue.h> | 
|---|
| 50 | 50 | #include <linux/bitops.h> | 
|---|
| 51 | 51 | #include <linux/jiffies.h> | 
|---|
|  | 52 | +#include <linux/sched/mm.h> | 
|---|
| 52 | 53 |  | 
|---|
| 53 | 54 | #include <linux/sunrpc/clnt.h> | 
|---|
| 54 | 55 |  | 
|---|
| .. | .. | 
|---|
| 60 | 61 | #include "nfs4session.h" | 
|---|
| 61 | 62 | #include "pnfs.h" | 
|---|
| 62 | 63 | #include "netns.h" | 
|---|
|  | 64 | +#include "nfs4trace.h" | 
|---|
| 63 | 65 |  | 
|---|
| 64 | 66 | #define NFSDBG_FACILITY		NFSDBG_STATE | 
|---|
| 65 | 67 |  | 
|---|
| 66 | 68 | #define OPENOWNER_POOL_SIZE	8 | 
|---|
|  | 69 | + | 
|---|
|  | 70 | +static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp); | 
|---|
| 67 | 71 |  | 
|---|
| 68 | 72 | const nfs4_stateid zero_stateid = { | 
|---|
| 69 | 73 | { .data = { 0 } }, | 
|---|
| .. | .. | 
|---|
| 87 | 91 |  | 
|---|
| 88 | 92 | static DEFINE_MUTEX(nfs_clid_init_mutex); | 
|---|
| 89 | 93 |  | 
|---|
| 90 |  | -int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) | 
|---|
|  | 94 | +static int nfs4_setup_state_renewal(struct nfs_client *clp) | 
|---|
|  | 95 | +{ | 
|---|
|  | 96 | +	int status; | 
|---|
|  | 97 | +	struct nfs_fsinfo fsinfo; | 
|---|
|  | 98 | + | 
|---|
|  | 99 | +	if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) { | 
|---|
|  | 100 | +		nfs4_schedule_state_renewal(clp); | 
|---|
|  | 101 | +		return 0; | 
|---|
|  | 102 | +	} | 
|---|
|  | 103 | + | 
|---|
|  | 104 | +	status = nfs4_proc_get_lease_time(clp, &fsinfo); | 
|---|
|  | 105 | +	if (status == 0) { | 
|---|
|  | 106 | +		nfs4_set_lease_period(clp, fsinfo.lease_time * HZ); | 
|---|
|  | 107 | +		nfs4_schedule_state_renewal(clp); | 
|---|
|  | 108 | +	} | 
|---|
|  | 109 | + | 
|---|
|  | 110 | +	return status; | 
|---|
|  | 111 | +} | 
|---|
|  | 112 | + | 
|---|
|  | 113 | +int nfs4_init_clientid(struct nfs_client *clp, const struct cred *cred) | 
|---|
| 91 | 114 | { | 
|---|
| 92 | 115 | struct nfs4_setclientid_res clid = { | 
|---|
| 93 | 116 | .clientid = clp->cl_clientid, | 
|---|
| .. | .. | 
|---|
| 114 | 137 | if (status != 0) | 
|---|
| 115 | 138 | goto out; | 
|---|
| 116 | 139 | clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); | 
|---|
| 117 |  | -	nfs4_schedule_state_renewal(clp); | 
|---|
|  | 140 | +	nfs4_setup_state_renewal(clp); | 
|---|
| 118 | 141 | out: | 
|---|
| 119 | 142 | return status; | 
|---|
| 120 | 143 | } | 
|---|
| .. | .. | 
|---|
| 134 | 157 | */ | 
|---|
| 135 | 158 | int nfs40_discover_server_trunking(struct nfs_client *clp, | 
|---|
| 136 | 159 | struct nfs_client **result, | 
|---|
| 137 |  | -				   struct rpc_cred *cred) | 
|---|
|  | 160 | +				   const struct cred *cred) | 
|---|
| 138 | 161 | { | 
|---|
| 139 | 162 | struct nfs4_setclientid_res clid = { | 
|---|
| 140 | 163 | .clientid = clp->cl_clientid, | 
|---|
| .. | .. | 
|---|
| 168 | 191 | return status; | 
|---|
| 169 | 192 | } | 
|---|
| 170 | 193 |  | 
|---|
| 171 |  | -struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp) | 
|---|
|  | 194 | +const struct cred *nfs4_get_machine_cred(struct nfs_client *clp) | 
|---|
| 172 | 195 | { | 
|---|
| 173 |  | -	struct rpc_cred *cred = NULL; | 
|---|
| 174 |  | - | 
|---|
| 175 |  | -	if (clp->cl_machine_cred != NULL) | 
|---|
| 176 |  | -		cred = get_rpccred(clp->cl_machine_cred); | 
|---|
| 177 |  | -	return cred; | 
|---|
|  | 196 | +	return get_cred(rpc_machine_cred()); | 
|---|
| 178 | 197 | } | 
|---|
| 179 | 198 |  | 
|---|
| 180 | 199 | static void nfs4_root_machine_cred(struct nfs_client *clp) | 
|---|
| 181 | 200 | { | 
|---|
| 182 |  | -	struct rpc_cred *cred, *new; | 
|---|
| 183 | 201 |  | 
|---|
| 184 |  | -	new = rpc_lookup_machine_cred(NULL); | 
|---|
| 185 |  | -	spin_lock(&clp->cl_lock); | 
|---|
| 186 |  | -	cred = clp->cl_machine_cred; | 
|---|
| 187 |  | -	clp->cl_machine_cred = new; | 
|---|
| 188 |  | -	spin_unlock(&clp->cl_lock); | 
|---|
| 189 |  | -	if (cred != NULL) | 
|---|
| 190 |  | -		put_rpccred(cred); | 
|---|
|  | 202 | +	/* Force root creds instead of machine */ | 
|---|
|  | 203 | +	clp->cl_principal = NULL; | 
|---|
|  | 204 | +	clp->cl_rpcclient->cl_principal = NULL; | 
|---|
| 191 | 205 | } | 
|---|
| 192 | 206 |  | 
|---|
| 193 |  | -static struct rpc_cred * | 
|---|
|  | 207 | +static const struct cred * | 
|---|
| 194 | 208 | nfs4_get_renew_cred_server_locked(struct nfs_server *server) | 
|---|
| 195 | 209 | { | 
|---|
| 196 |  | -	struct rpc_cred *cred = NULL; | 
|---|
|  | 210 | +	const struct cred *cred = NULL; | 
|---|
| 197 | 211 | struct nfs4_state_owner *sp; | 
|---|
| 198 | 212 | struct rb_node *pos; | 
|---|
| 199 | 213 |  | 
|---|
| .. | .. | 
|---|
| 203 | 217 | sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); | 
|---|
| 204 | 218 | if (list_empty(&sp->so_states)) | 
|---|
| 205 | 219 | continue; | 
|---|
| 206 |  | -		cred = get_rpccred(sp->so_cred); | 
|---|
|  | 220 | +		cred = get_cred(sp->so_cred); | 
|---|
| 207 | 221 | break; | 
|---|
| 208 | 222 | } | 
|---|
| 209 | 223 | return cred; | 
|---|
| 210 | 224 | } | 
|---|
| 211 | 225 |  | 
|---|
| 212 | 226 | /** | 
|---|
| 213 |  | - * nfs4_get_renew_cred_locked - Acquire credential for a renew operation | 
|---|
|  | 227 | + * nfs4_get_renew_cred - Acquire credential for a renew operation | 
|---|
| 214 | 228 | * @clp: client state handle | 
|---|
| 215 | 229 | * | 
|---|
| 216 | 230 | * Returns an rpc_cred with reference count bumped, or NULL. | 
|---|
| 217 | 231 | * Caller must hold clp->cl_lock. | 
|---|
| 218 | 232 | */ | 
|---|
| 219 |  | -struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) | 
|---|
|  | 233 | +const struct cred *nfs4_get_renew_cred(struct nfs_client *clp) | 
|---|
| 220 | 234 | { | 
|---|
| 221 |  | -	struct rpc_cred *cred = NULL; | 
|---|
|  | 235 | +	const struct cred *cred = NULL; | 
|---|
| 222 | 236 | struct nfs_server *server; | 
|---|
| 223 | 237 |  | 
|---|
| 224 | 238 | /* Use machine credentials if available */ | 
|---|
| 225 |  | -	cred = nfs4_get_machine_cred_locked(clp); | 
|---|
|  | 239 | +	cred = nfs4_get_machine_cred(clp); | 
|---|
| 226 | 240 | if (cred != NULL) | 
|---|
| 227 | 241 | goto out; | 
|---|
| 228 | 242 |  | 
|---|
|  | 243 | +	spin_lock(&clp->cl_lock); | 
|---|
| 229 | 244 | rcu_read_lock(); | 
|---|
| 230 | 245 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { | 
|---|
| 231 | 246 | cred = nfs4_get_renew_cred_server_locked(server); | 
|---|
| .. | .. | 
|---|
| 233 | 248 | break; | 
|---|
| 234 | 249 | } | 
|---|
| 235 | 250 | rcu_read_unlock(); | 
|---|
|  | 251 | +	spin_unlock(&clp->cl_lock); | 
|---|
| 236 | 252 |  | 
|---|
| 237 | 253 | out: | 
|---|
| 238 | 254 | return cred; | 
|---|
| .. | .. | 
|---|
| 293 | 309 |  | 
|---|
| 294 | 310 | #if defined(CONFIG_NFS_V4_1) | 
|---|
| 295 | 311 |  | 
|---|
| 296 |  | -static int nfs41_setup_state_renewal(struct nfs_client *clp) | 
|---|
| 297 |  | -{ | 
|---|
| 298 |  | -	int status; | 
|---|
| 299 |  | -	struct nfs_fsinfo fsinfo; | 
|---|
| 300 |  | -	unsigned long now; | 
|---|
| 301 |  | - | 
|---|
| 302 |  | -	if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) { | 
|---|
| 303 |  | -		nfs4_schedule_state_renewal(clp); | 
|---|
| 304 |  | -		return 0; | 
|---|
| 305 |  | -	} | 
|---|
| 306 |  | - | 
|---|
| 307 |  | -	now = jiffies; | 
|---|
| 308 |  | -	status = nfs4_proc_get_lease_time(clp, &fsinfo); | 
|---|
| 309 |  | -	if (status == 0) { | 
|---|
| 310 |  | -		nfs4_set_lease_period(clp, fsinfo.lease_time * HZ, now); | 
|---|
| 311 |  | -		nfs4_schedule_state_renewal(clp); | 
|---|
| 312 |  | -	} | 
|---|
| 313 |  | - | 
|---|
| 314 |  | -	return status; | 
|---|
| 315 |  | -} | 
|---|
| 316 |  | - | 
|---|
| 317 | 312 | static void nfs41_finish_session_reset(struct nfs_client *clp) | 
|---|
| 318 | 313 | { | 
|---|
| 319 | 314 | clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); | 
|---|
| 320 | 315 | clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); | 
|---|
| 321 | 316 | /* create_session negotiated new slot table */ | 
|---|
| 322 | 317 | clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); | 
|---|
| 323 |  | -	nfs41_setup_state_renewal(clp); | 
|---|
|  | 318 | +	nfs4_setup_state_renewal(clp); | 
|---|
| 324 | 319 | } | 
|---|
| 325 | 320 |  | 
|---|
| 326 |  | -int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) | 
|---|
|  | 321 | +int nfs41_init_clientid(struct nfs_client *clp, const struct cred *cred) | 
|---|
| 327 | 322 | { | 
|---|
| 328 | 323 | int status; | 
|---|
| 329 | 324 |  | 
|---|
| .. | .. | 
|---|
| 337 | 332 | status = nfs4_proc_create_session(clp, cred); | 
|---|
| 338 | 333 | if (status != 0) | 
|---|
| 339 | 334 | goto out; | 
|---|
|  | 335 | +	if (!(clp->cl_exchange_flags & EXCHGID4_FLAG_CONFIRMED_R)) | 
|---|
|  | 336 | +		nfs4_state_start_reclaim_reboot(clp); | 
|---|
| 340 | 337 | nfs41_finish_session_reset(clp); | 
|---|
| 341 | 338 | nfs_mark_client_ready(clp, NFS_CS_READY); | 
|---|
| 342 | 339 | out: | 
|---|
| .. | .. | 
|---|
| 358 | 355 | */ | 
|---|
| 359 | 356 | int nfs41_discover_server_trunking(struct nfs_client *clp, | 
|---|
| 360 | 357 | struct nfs_client **result, | 
|---|
| 361 |  | -				   struct rpc_cred *cred) | 
|---|
|  | 358 | +				   const struct cred *cred) | 
|---|
| 362 | 359 | { | 
|---|
| 363 | 360 | int status; | 
|---|
| 364 | 361 |  | 
|---|
| .. | .. | 
|---|
| 396 | 393 | * nfs4_get_clid_cred - Acquire credential for a setclientid operation | 
|---|
| 397 | 394 | * @clp: client state handle | 
|---|
| 398 | 395 | * | 
|---|
| 399 |  | - * Returns an rpc_cred with reference count bumped, or NULL. | 
|---|
|  | 396 | + * Returns a cred with reference count bumped, or NULL. | 
|---|
| 400 | 397 | */ | 
|---|
| 401 |  | -struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp) | 
|---|
|  | 398 | +const struct cred *nfs4_get_clid_cred(struct nfs_client *clp) | 
|---|
| 402 | 399 | { | 
|---|
| 403 |  | -	struct rpc_cred *cred; | 
|---|
|  | 400 | +	const struct cred *cred; | 
|---|
| 404 | 401 |  | 
|---|
| 405 |  | -	spin_lock(&clp->cl_lock); | 
|---|
| 406 |  | -	cred = nfs4_get_machine_cred_locked(clp); | 
|---|
| 407 |  | -	spin_unlock(&clp->cl_lock); | 
|---|
|  | 402 | +	cred = nfs4_get_machine_cred(clp); | 
|---|
| 408 | 403 | return cred; | 
|---|
| 409 | 404 | } | 
|---|
| 410 | 405 |  | 
|---|
| 411 | 406 | static struct nfs4_state_owner * | 
|---|
| 412 |  | -nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred) | 
|---|
|  | 407 | +nfs4_find_state_owner_locked(struct nfs_server *server, const struct cred *cred) | 
|---|
| 413 | 408 | { | 
|---|
| 414 | 409 | struct rb_node **p = &server->state_owners.rb_node, | 
|---|
| 415 | 410 | *parent = NULL; | 
|---|
| 416 | 411 | struct nfs4_state_owner *sp; | 
|---|
|  | 412 | +	int cmp; | 
|---|
| 417 | 413 |  | 
|---|
| 418 | 414 | while (*p != NULL) { | 
|---|
| 419 | 415 | parent = *p; | 
|---|
| 420 | 416 | sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); | 
|---|
|  | 417 | +		cmp = cred_fscmp(cred, sp->so_cred); | 
|---|
| 421 | 418 |  | 
|---|
| 422 |  | -		if (cred < sp->so_cred) | 
|---|
|  | 419 | +		if (cmp < 0) | 
|---|
| 423 | 420 | p = &parent->rb_left; | 
|---|
| 424 |  | -		else if (cred > sp->so_cred) | 
|---|
|  | 421 | +		else if (cmp > 0) | 
|---|
| 425 | 422 | p = &parent->rb_right; | 
|---|
| 426 | 423 | else { | 
|---|
| 427 | 424 | if (!list_empty(&sp->so_lru)) | 
|---|
| .. | .. | 
|---|
| 440 | 437 | struct rb_node **p = &server->state_owners.rb_node, | 
|---|
| 441 | 438 | *parent = NULL; | 
|---|
| 442 | 439 | struct nfs4_state_owner *sp; | 
|---|
|  | 440 | +	int cmp; | 
|---|
| 443 | 441 |  | 
|---|
| 444 | 442 | while (*p != NULL) { | 
|---|
| 445 | 443 | parent = *p; | 
|---|
| 446 | 444 | sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); | 
|---|
|  | 445 | +		cmp = cred_fscmp(new->so_cred, sp->so_cred); | 
|---|
| 447 | 446 |  | 
|---|
| 448 |  | -		if (new->so_cred < sp->so_cred) | 
|---|
|  | 447 | +		if (cmp < 0) | 
|---|
| 449 | 448 | p = &parent->rb_left; | 
|---|
| 450 |  | -		else if (new->so_cred > sp->so_cred) | 
|---|
|  | 449 | +		else if (cmp > 0) | 
|---|
| 451 | 450 | p = &parent->rb_right; | 
|---|
| 452 | 451 | else { | 
|---|
| 453 | 452 | if (!list_empty(&sp->so_lru)) | 
|---|
| .. | .. | 
|---|
| 494 | 493 | */ | 
|---|
| 495 | 494 | static struct nfs4_state_owner * | 
|---|
| 496 | 495 | nfs4_alloc_state_owner(struct nfs_server *server, | 
|---|
| 497 |  | -		struct rpc_cred *cred, | 
|---|
|  | 496 | +		const struct cred *cred, | 
|---|
| 498 | 497 | gfp_t gfp_flags) | 
|---|
| 499 | 498 | { | 
|---|
| 500 | 499 | struct nfs4_state_owner *sp; | 
|---|
| .. | .. | 
|---|
| 509 | 508 | return NULL; | 
|---|
| 510 | 509 | } | 
|---|
| 511 | 510 | sp->so_server = server; | 
|---|
| 512 |  | -	sp->so_cred = get_rpccred(cred); | 
|---|
|  | 511 | +	sp->so_cred = get_cred(cred); | 
|---|
| 513 | 512 | spin_lock_init(&sp->so_lock); | 
|---|
| 514 | 513 | INIT_LIST_HEAD(&sp->so_states); | 
|---|
| 515 | 514 | nfs4_init_seqid_counter(&sp->so_seqid); | 
|---|
| 516 | 515 | atomic_set(&sp->so_count, 1); | 
|---|
| 517 | 516 | INIT_LIST_HEAD(&sp->so_lru); | 
|---|
| 518 |  | -	seqlock_init(&sp->so_reclaim_seqlock); | 
|---|
|  | 517 | +	seqcount_spinlock_init(&sp->so_reclaim_seqcount, &sp->so_lock); | 
|---|
| 519 | 518 | mutex_init(&sp->so_delegreturn_mutex); | 
|---|
| 520 | 519 | return sp; | 
|---|
| 521 | 520 | } | 
|---|
| .. | .. | 
|---|
| 538 | 537 | static void nfs4_free_state_owner(struct nfs4_state_owner *sp) | 
|---|
| 539 | 538 | { | 
|---|
| 540 | 539 | nfs4_destroy_seqid_counter(&sp->so_seqid); | 
|---|
| 541 |  | -	put_rpccred(sp->so_cred); | 
|---|
|  | 540 | +	put_cred(sp->so_cred); | 
|---|
| 542 | 541 | ida_simple_remove(&sp->so_server->openowner_id, sp->so_seqid.owner_id); | 
|---|
| 543 | 542 | kfree(sp); | 
|---|
| 544 | 543 | } | 
|---|
| .. | .. | 
|---|
| 572 | 571 | * nfs4_get_state_owner - Look up a state owner given a credential | 
|---|
| 573 | 572 | * @server: nfs_server to search | 
|---|
| 574 | 573 | * @cred: RPC credential to match | 
|---|
|  | 574 | + * @gfp_flags: allocation mode | 
|---|
| 575 | 575 | * | 
|---|
| 576 | 576 | * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. | 
|---|
| 577 | 577 | */ | 
|---|
| 578 | 578 | struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, | 
|---|
| 579 |  | -					      struct rpc_cred *cred, | 
|---|
|  | 579 | +					      const struct cred *cred, | 
|---|
| 580 | 580 | gfp_t gfp_flags) | 
|---|
| 581 | 581 | { | 
|---|
| 582 | 582 | struct nfs_client *clp = server->nfs_client; | 
|---|
| .. | .. | 
|---|
| 674 | 674 | state = kzalloc(sizeof(*state), GFP_NOFS); | 
|---|
| 675 | 675 | if (!state) | 
|---|
| 676 | 676 | return NULL; | 
|---|
| 677 |  | -	atomic_set(&state->count, 1); | 
|---|
|  | 677 | +	refcount_set(&state->count, 1); | 
|---|
| 678 | 678 | INIT_LIST_HEAD(&state->lock_states); | 
|---|
| 679 | 679 | spin_lock_init(&state->state_lock); | 
|---|
| 680 | 680 | seqlock_init(&state->seqlock); | 
|---|
| .. | .. | 
|---|
| 703 | 703 | struct nfs_inode *nfsi = NFS_I(inode); | 
|---|
| 704 | 704 | struct nfs4_state *state; | 
|---|
| 705 | 705 |  | 
|---|
| 706 |  | -	list_for_each_entry(state, &nfsi->open_states, inode_states) { | 
|---|
|  | 706 | +	list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) { | 
|---|
| 707 | 707 | if (state->owner != owner) | 
|---|
| 708 | 708 | continue; | 
|---|
| 709 | 709 | if (!nfs4_valid_open_stateid(state)) | 
|---|
| 710 | 710 | continue; | 
|---|
| 711 |  | -		if (atomic_inc_not_zero(&state->count)) | 
|---|
|  | 711 | +		if (refcount_inc_not_zero(&state->count)) | 
|---|
| 712 | 712 | return state; | 
|---|
| 713 | 713 | } | 
|---|
| 714 | 714 | return NULL; | 
|---|
| .. | .. | 
|---|
| 717 | 717 | static void | 
|---|
| 718 | 718 | nfs4_free_open_state(struct nfs4_state *state) | 
|---|
| 719 | 719 | { | 
|---|
| 720 |  | -	kfree(state); | 
|---|
|  | 720 | +	kfree_rcu(state, rcu_head); | 
|---|
| 721 | 721 | } | 
|---|
| 722 | 722 |  | 
|---|
| 723 | 723 | struct nfs4_state * | 
|---|
| .. | .. | 
|---|
| 726 | 726 | struct nfs4_state *state, *new; | 
|---|
| 727 | 727 | struct nfs_inode *nfsi = NFS_I(inode); | 
|---|
| 728 | 728 |  | 
|---|
| 729 |  | -	spin_lock(&inode->i_lock); | 
|---|
|  | 729 | +	rcu_read_lock(); | 
|---|
| 730 | 730 | state = __nfs4_find_state_byowner(inode, owner); | 
|---|
| 731 |  | -	spin_unlock(&inode->i_lock); | 
|---|
|  | 731 | +	rcu_read_unlock(); | 
|---|
| 732 | 732 | if (state) | 
|---|
| 733 | 733 | goto out; | 
|---|
| 734 | 734 | new = nfs4_alloc_open_state(); | 
|---|
| .. | .. | 
|---|
| 739 | 739 | state = new; | 
|---|
| 740 | 740 | state->owner = owner; | 
|---|
| 741 | 741 | atomic_inc(&owner->so_count); | 
|---|
| 742 |  | -		list_add(&state->inode_states, &nfsi->open_states); | 
|---|
| 743 | 742 | ihold(inode); | 
|---|
| 744 | 743 | state->inode = inode; | 
|---|
|  | 744 | +		list_add_rcu(&state->inode_states, &nfsi->open_states); | 
|---|
| 745 | 745 | spin_unlock(&inode->i_lock); | 
|---|
| 746 | 746 | /* Note: The reclaim code dictates that we add stateless | 
|---|
| 747 | 747 | * and read-only stateids to the end of the list */ | 
|---|
| .. | .. | 
|---|
| 762 | 762 | struct inode *inode = state->inode; | 
|---|
| 763 | 763 | struct nfs4_state_owner *owner = state->owner; | 
|---|
| 764 | 764 |  | 
|---|
| 765 |  | -	if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) | 
|---|
|  | 765 | +	if (!refcount_dec_and_lock(&state->count, &owner->so_lock)) | 
|---|
| 766 | 766 | return; | 
|---|
| 767 | 767 | spin_lock(&inode->i_lock); | 
|---|
| 768 |  | -	list_del(&state->inode_states); | 
|---|
|  | 768 | +	list_del_rcu(&state->inode_states); | 
|---|
| 769 | 769 | list_del(&state->open_states); | 
|---|
| 770 | 770 | spin_unlock(&inode->i_lock); | 
|---|
| 771 | 771 | spin_unlock(&owner->so_lock); | 
|---|
|  | 772 | +	nfs4_inode_return_delegation_on_close(inode); | 
|---|
| 772 | 773 | iput(inode); | 
|---|
| 773 | 774 | nfs4_free_open_state(state); | 
|---|
| 774 | 775 | nfs4_put_state_owner(owner); | 
|---|
| .. | .. | 
|---|
| 1019 | 1020 | return ret; | 
|---|
| 1020 | 1021 | } | 
|---|
| 1021 | 1022 |  | 
|---|
| 1022 |  | -bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) | 
|---|
| 1023 |  | -{ | 
|---|
| 1024 |  | -	bool ret; | 
|---|
| 1025 |  | -	int seq; | 
|---|
| 1026 |  | - | 
|---|
| 1027 |  | -	do { | 
|---|
| 1028 |  | -		ret = false; | 
|---|
| 1029 |  | -		seq = read_seqbegin(&state->seqlock); | 
|---|
| 1030 |  | -		if (nfs4_state_match_open_stateid_other(state, dst)) { | 
|---|
| 1031 |  | -			dst->seqid = state->open_stateid.seqid; | 
|---|
| 1032 |  | -			ret = true; | 
|---|
| 1033 |  | -		} | 
|---|
| 1034 |  | -	} while (read_seqretry(&state->seqlock, seq)); | 
|---|
| 1035 |  | -	return ret; | 
|---|
| 1036 |  | -} | 
|---|
| 1037 |  | - | 
|---|
| 1038 | 1023 | bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) | 
|---|
| 1039 | 1024 | { | 
|---|
| 1040 | 1025 | bool ret; | 
|---|
| .. | .. | 
|---|
| 1060 | 1045 | */ | 
|---|
| 1061 | 1046 | int nfs4_select_rw_stateid(struct nfs4_state *state, | 
|---|
| 1062 | 1047 | fmode_t fmode, const struct nfs_lock_context *l_ctx, | 
|---|
| 1063 |  | -		nfs4_stateid *dst, struct rpc_cred **cred) | 
|---|
|  | 1048 | +		nfs4_stateid *dst, const struct cred **cred) | 
|---|
| 1064 | 1049 | { | 
|---|
| 1065 | 1050 | int ret; | 
|---|
| 1066 | 1051 |  | 
|---|
| .. | .. | 
|---|
| 1083 | 1068 | * choose to use. | 
|---|
| 1084 | 1069 | */ | 
|---|
| 1085 | 1070 | goto out; | 
|---|
| 1086 |  | -	nfs4_copy_open_stateid(dst, state); | 
|---|
| 1087 |  | -	ret = 0; | 
|---|
|  | 1071 | +	ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN; | 
|---|
| 1088 | 1072 | out: | 
|---|
| 1089 | 1073 | if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) | 
|---|
| 1090 | 1074 | dst->seqid = 0; | 
|---|
| .. | .. | 
|---|
| 1155 | 1139 | case -NFS4ERR_MOVED: | 
|---|
| 1156 | 1140 | /* Non-seqid mutating errors */ | 
|---|
| 1157 | 1141 | return; | 
|---|
| 1158 |  | -	}; | 
|---|
|  | 1142 | +	} | 
|---|
| 1159 | 1143 | /* | 
|---|
| 1160 | 1144 | * Note: no locking needed as we are guaranteed to be first | 
|---|
| 1161 | 1145 | * on the sequence list | 
|---|
| .. | .. | 
|---|
| 1228 | 1212 | { | 
|---|
| 1229 | 1213 | struct task_struct *task; | 
|---|
| 1230 | 1214 | char buf[INET6_ADDRSTRLEN + sizeof("-manager") + 1]; | 
|---|
|  | 1215 | +	struct rpc_clnt *clnt = clp->cl_rpcclient; | 
|---|
|  | 1216 | +	bool swapon = false; | 
|---|
| 1231 | 1217 |  | 
|---|
| 1232 | 1218 | set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); | 
|---|
|  | 1219 | + | 
|---|
|  | 1220 | +	if (atomic_read(&clnt->cl_swapper)) { | 
|---|
|  | 1221 | +		swapon = !test_and_set_bit(NFS4CLNT_MANAGER_AVAILABLE, | 
|---|
|  | 1222 | +					   &clp->cl_state); | 
|---|
|  | 1223 | +		if (!swapon) { | 
|---|
|  | 1224 | +			wake_up_var(&clp->cl_state); | 
|---|
|  | 1225 | +			return; | 
|---|
|  | 1226 | +		} | 
|---|
|  | 1227 | +	} | 
|---|
|  | 1228 | + | 
|---|
| 1233 | 1229 | if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) | 
|---|
| 1234 | 1230 | return; | 
|---|
|  | 1231 | + | 
|---|
| 1235 | 1232 | __module_get(THIS_MODULE); | 
|---|
| 1236 | 1233 | refcount_inc(&clp->cl_count); | 
|---|
| 1237 | 1234 |  | 
|---|
| .. | .. | 
|---|
| 1246 | 1243 | if (IS_ERR(task)) { | 
|---|
| 1247 | 1244 | printk(KERN_ERR "%s: kthread_run: %ld\n", | 
|---|
| 1248 | 1245 | __func__, PTR_ERR(task)); | 
|---|
|  | 1246 | +		if (!nfs_client_init_is_complete(clp)) | 
|---|
|  | 1247 | +			nfs_mark_client_ready(clp, PTR_ERR(task)); | 
|---|
|  | 1248 | +		if (swapon) | 
|---|
|  | 1249 | +			clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); | 
|---|
| 1249 | 1250 | nfs4_clear_state_manager_bit(clp); | 
|---|
| 1250 | 1251 | nfs_put_client(clp); | 
|---|
| 1251 | 1252 | module_put(THIS_MODULE); | 
|---|
| .. | .. | 
|---|
| 1428 | 1429 | list_for_each_entry(pos, &state->lock_states, ls_locks) { | 
|---|
| 1429 | 1430 | if (!test_bit(NFS_LOCK_INITIALIZED, &pos->ls_flags)) | 
|---|
| 1430 | 1431 | continue; | 
|---|
| 1431 |  | -		if (nfs4_stateid_match_other(&pos->ls_stateid, stateid)) | 
|---|
|  | 1432 | +		if (nfs4_stateid_match_or_older(&pos->ls_stateid, stateid)) | 
|---|
| 1432 | 1433 | return pos; | 
|---|
| 1433 | 1434 | } | 
|---|
| 1434 | 1435 | return NULL; | 
|---|
| .. | .. | 
|---|
| 1457 | 1458 | struct nfs4_state *state; | 
|---|
| 1458 | 1459 | bool found = false; | 
|---|
| 1459 | 1460 |  | 
|---|
| 1460 |  | -	spin_lock(&inode->i_lock); | 
|---|
| 1461 |  | -	list_for_each_entry(ctx, &nfsi->open_files, list) { | 
|---|
|  | 1461 | +	rcu_read_lock(); | 
|---|
|  | 1462 | +	list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { | 
|---|
| 1462 | 1463 | state = ctx->state; | 
|---|
| 1463 | 1464 | if (state == NULL) | 
|---|
| 1464 | 1465 | continue; | 
|---|
| 1465 |  | -		if (nfs4_stateid_match_other(&state->stateid, stateid) && | 
|---|
|  | 1466 | +		if (nfs4_stateid_match_or_older(&state->stateid, stateid) && | 
|---|
| 1466 | 1467 | nfs4_state_mark_reclaim_nograce(clp, state)) { | 
|---|
| 1467 | 1468 | found = true; | 
|---|
| 1468 | 1469 | continue; | 
|---|
| 1469 | 1470 | } | 
|---|
| 1470 |  | -		if (nfs4_stateid_match_other(&state->open_stateid, stateid) && | 
|---|
|  | 1471 | +		if (test_bit(NFS_OPEN_STATE, &state->flags) && | 
|---|
|  | 1472 | +		    nfs4_stateid_match_or_older(&state->open_stateid, stateid) && | 
|---|
| 1471 | 1473 | nfs4_state_mark_reclaim_nograce(clp, state)) { | 
|---|
| 1472 | 1474 | found = true; | 
|---|
| 1473 | 1475 | continue; | 
|---|
| .. | .. | 
|---|
| 1476 | 1478 | nfs4_state_mark_reclaim_nograce(clp, state)) | 
|---|
| 1477 | 1479 | found = true; | 
|---|
| 1478 | 1480 | } | 
|---|
| 1479 |  | -	spin_unlock(&inode->i_lock); | 
|---|
|  | 1481 | +	rcu_read_unlock(); | 
|---|
| 1480 | 1482 |  | 
|---|
| 1481 | 1483 | nfs_inode_find_delegation_state_and_recover(inode, stateid); | 
|---|
| 1482 | 1484 | if (found) | 
|---|
| 1483 | 1485 | nfs4_schedule_state_manager(clp); | 
|---|
| 1484 | 1486 | } | 
|---|
| 1485 | 1487 |  | 
|---|
| 1486 |  | -static void nfs4_state_mark_open_context_bad(struct nfs4_state *state) | 
|---|
|  | 1488 | +static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err) | 
|---|
| 1487 | 1489 | { | 
|---|
| 1488 | 1490 | struct inode *inode = state->inode; | 
|---|
| 1489 | 1491 | struct nfs_inode *nfsi = NFS_I(inode); | 
|---|
| 1490 | 1492 | struct nfs_open_context *ctx; | 
|---|
| 1491 | 1493 |  | 
|---|
| 1492 |  | -	spin_lock(&inode->i_lock); | 
|---|
| 1493 |  | -	list_for_each_entry(ctx, &nfsi->open_files, list) { | 
|---|
|  | 1494 | +	rcu_read_lock(); | 
|---|
|  | 1495 | +	list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { | 
|---|
| 1494 | 1496 | if (ctx->state != state) | 
|---|
| 1495 | 1497 | continue; | 
|---|
| 1496 | 1498 | set_bit(NFS_CONTEXT_BAD, &ctx->flags); | 
|---|
|  | 1499 | +		pr_warn("NFSv4: state recovery failed for open file %pd2, " | 
|---|
|  | 1500 | +				"error = %d\n", ctx->dentry, err); | 
|---|
| 1497 | 1501 | } | 
|---|
| 1498 |  | -	spin_unlock(&inode->i_lock); | 
|---|
|  | 1502 | +	rcu_read_unlock(); | 
|---|
| 1499 | 1503 | } | 
|---|
| 1500 | 1504 |  | 
|---|
| 1501 | 1505 | static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) | 
|---|
| 1502 | 1506 | { | 
|---|
| 1503 | 1507 | set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); | 
|---|
| 1504 |  | -	nfs4_state_mark_open_context_bad(state); | 
|---|
|  | 1508 | +	nfs4_state_mark_open_context_bad(state, error); | 
|---|
| 1505 | 1509 | } | 
|---|
| 1506 | 1510 |  | 
|---|
| 1507 | 1511 |  | 
|---|
| .. | .. | 
|---|
| 1532 | 1536 | switch (status) { | 
|---|
| 1533 | 1537 | case 0: | 
|---|
| 1534 | 1538 | break; | 
|---|
|  | 1539 | +		case -ETIMEDOUT: | 
|---|
| 1535 | 1540 | case -ESTALE: | 
|---|
| 1536 | 1541 | case -NFS4ERR_ADMIN_REVOKED: | 
|---|
| 1537 | 1542 | case -NFS4ERR_STALE_STATEID: | 
|---|
| .. | .. | 
|---|
| 1547 | 1552 | default: | 
|---|
| 1548 | 1553 | pr_err("NFS: %s: unhandled error %d\n", | 
|---|
| 1549 | 1554 | __func__, status); | 
|---|
| 1550 |  | -			/* Fall through */ | 
|---|
|  | 1555 | +			fallthrough; | 
|---|
| 1551 | 1556 | case -ENOMEM: | 
|---|
| 1552 | 1557 | case -NFS4ERR_DENIED: | 
|---|
| 1553 | 1558 | case -NFS4ERR_RECLAIM_BAD: | 
|---|
| .. | .. | 
|---|
| 1569 | 1574 | return status; | 
|---|
| 1570 | 1575 | } | 
|---|
| 1571 | 1576 |  | 
|---|
|  | 1577 | +#ifdef CONFIG_NFS_V4_2 | 
|---|
|  | 1578 | +static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|---|
|  | 1579 | +{ | 
|---|
|  | 1580 | +	struct nfs4_copy_state *copy; | 
|---|
|  | 1581 | + | 
|---|
|  | 1582 | +	if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) && | 
|---|
|  | 1583 | +		!test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags)) | 
|---|
|  | 1584 | +		return; | 
|---|
|  | 1585 | + | 
|---|
|  | 1586 | +	spin_lock(&sp->so_server->nfs_client->cl_lock); | 
|---|
|  | 1587 | +	list_for_each_entry(copy, &sp->so_server->ss_copies, copies) { | 
|---|
|  | 1588 | +		if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) && | 
|---|
|  | 1589 | +				!nfs4_stateid_match_other(&state->stateid, | 
|---|
|  | 1590 | +				©->parent_dst_state->stateid))) | 
|---|
|  | 1591 | +				continue; | 
|---|
|  | 1592 | +		copy->flags = 1; | 
|---|
|  | 1593 | +		if (test_and_clear_bit(NFS_CLNT_DST_SSC_COPY_STATE, | 
|---|
|  | 1594 | +				&state->flags)) { | 
|---|
|  | 1595 | +			clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags); | 
|---|
|  | 1596 | +			complete(©->completion); | 
|---|
|  | 1597 | +		} | 
|---|
|  | 1598 | +	} | 
|---|
|  | 1599 | +	list_for_each_entry(copy, &sp->so_server->ss_copies, src_copies) { | 
|---|
|  | 1600 | +		if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) && | 
|---|
|  | 1601 | +				!nfs4_stateid_match_other(&state->stateid, | 
|---|
|  | 1602 | +				©->parent_src_state->stateid))) | 
|---|
|  | 1603 | +				continue; | 
|---|
|  | 1604 | +		copy->flags = 1; | 
|---|
|  | 1605 | +		if (test_and_clear_bit(NFS_CLNT_DST_SSC_COPY_STATE, | 
|---|
|  | 1606 | +				&state->flags)) | 
|---|
|  | 1607 | +			complete(©->completion); | 
|---|
|  | 1608 | +	} | 
|---|
|  | 1609 | +	spin_unlock(&sp->so_server->nfs_client->cl_lock); | 
|---|
|  | 1610 | +} | 
|---|
|  | 1611 | +#else /* !CONFIG_NFS_V4_2 */ | 
|---|
|  | 1612 | +static inline void nfs42_complete_copies(struct nfs4_state_owner *sp, | 
|---|
|  | 1613 | +					 struct nfs4_state *state) | 
|---|
|  | 1614 | +{ | 
|---|
|  | 1615 | +} | 
|---|
|  | 1616 | +#endif /* CONFIG_NFS_V4_2 */ | 
|---|
|  | 1617 | + | 
|---|
|  | 1618 | +static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state, | 
|---|
|  | 1619 | +				     const struct nfs4_state_recovery_ops *ops) | 
|---|
|  | 1620 | +{ | 
|---|
|  | 1621 | +	struct nfs4_lock_state *lock; | 
|---|
|  | 1622 | +	int status; | 
|---|
|  | 1623 | + | 
|---|
|  | 1624 | +	status = ops->recover_open(sp, state); | 
|---|
|  | 1625 | +	if (status < 0) | 
|---|
|  | 1626 | +		return status; | 
|---|
|  | 1627 | + | 
|---|
|  | 1628 | +	status = nfs4_reclaim_locks(state, ops); | 
|---|
|  | 1629 | +	if (status < 0) | 
|---|
|  | 1630 | +		return status; | 
|---|
|  | 1631 | + | 
|---|
|  | 1632 | +	if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 
|---|
|  | 1633 | +		spin_lock(&state->state_lock); | 
|---|
|  | 1634 | +		list_for_each_entry(lock, &state->lock_states, ls_locks) { | 
|---|
|  | 1635 | +			trace_nfs4_state_lock_reclaim(state, lock); | 
|---|
|  | 1636 | +			if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags)) | 
|---|
|  | 1637 | +				pr_warn_ratelimited("NFS: %s: Lock reclaim failed!\n", __func__); | 
|---|
|  | 1638 | +		} | 
|---|
|  | 1639 | +		spin_unlock(&state->state_lock); | 
|---|
|  | 1640 | +	} | 
|---|
|  | 1641 | + | 
|---|
|  | 1642 | +	nfs42_complete_copies(sp, state); | 
|---|
|  | 1643 | +	clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); | 
|---|
|  | 1644 | +	return status; | 
|---|
|  | 1645 | +} | 
|---|
|  | 1646 | + | 
|---|
| 1572 | 1647 | static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops) | 
|---|
| 1573 | 1648 | { | 
|---|
| 1574 | 1649 | struct nfs4_state *state; | 
|---|
| 1575 |  | -	struct nfs4_lock_state *lock; | 
|---|
|  | 1650 | +	unsigned int loop = 0; | 
|---|
| 1576 | 1651 | int status = 0; | 
|---|
|  | 1652 | +#ifdef CONFIG_NFS_V4_2 | 
|---|
|  | 1653 | +	bool found_ssc_copy_state = false; | 
|---|
|  | 1654 | +#endif /* CONFIG_NFS_V4_2 */ | 
|---|
| 1577 | 1655 |  | 
|---|
| 1578 | 1656 | /* Note: we rely on the sp->so_states list being ordered | 
|---|
| 1579 | 1657 | * so that we always reclaim open(O_RDWR) and/or open(O_WRITE) | 
|---|
| .. | .. | 
|---|
| 1583 | 1661 | * recovering after a network partition or a reboot from a | 
|---|
| 1584 | 1662 | * server that doesn't support a grace period. | 
|---|
| 1585 | 1663 | */ | 
|---|
| 1586 |  | -#ifdef CONFIG_PREEMPT_RT_FULL | 
|---|
| 1587 |  | -	write_seqlock(&sp->so_reclaim_seqlock); | 
|---|
| 1588 |  | -#else | 
|---|
| 1589 |  | -	write_seqcount_begin(&sp->so_reclaim_seqlock.seqcount); | 
|---|
| 1590 |  | -#endif | 
|---|
| 1591 | 1664 | spin_lock(&sp->so_lock); | 
|---|
|  | 1665 | +	raw_write_seqcount_begin(&sp->so_reclaim_seqcount); | 
|---|
| 1592 | 1666 | restart: | 
|---|
| 1593 | 1667 | list_for_each_entry(state, &sp->so_states, open_states) { | 
|---|
| 1594 | 1668 | if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) | 
|---|
| .. | .. | 
|---|
| 1597 | 1671 | continue; | 
|---|
| 1598 | 1672 | if (state->state == 0) | 
|---|
| 1599 | 1673 | continue; | 
|---|
| 1600 |  | -		atomic_inc(&state->count); | 
|---|
| 1601 |  | -		spin_unlock(&sp->so_lock); | 
|---|
| 1602 |  | -		status = ops->recover_open(sp, state); | 
|---|
| 1603 |  | -		if (status >= 0) { | 
|---|
| 1604 |  | -			status = nfs4_reclaim_locks(state, ops); | 
|---|
| 1605 |  | -			if (status >= 0) { | 
|---|
| 1606 |  | -				if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 
|---|
| 1607 |  | -					spin_lock(&state->state_lock); | 
|---|
| 1608 |  | -					list_for_each_entry(lock, &state->lock_states, ls_locks) { | 
|---|
| 1609 |  | -						if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags)) | 
|---|
| 1610 |  | -							pr_warn_ratelimited("NFS: " | 
|---|
| 1611 |  | -									    "%s: Lock reclaim " | 
|---|
| 1612 |  | -									    "failed!\n", __func__); | 
|---|
| 1613 |  | -					} | 
|---|
| 1614 |  | -					spin_unlock(&state->state_lock); | 
|---|
| 1615 |  | -				} | 
|---|
| 1616 |  | -				clear_bit(NFS_STATE_RECLAIM_NOGRACE, | 
|---|
| 1617 |  | -					&state->flags); | 
|---|
| 1618 | 1674 | #ifdef CONFIG_NFS_V4_2 | 
|---|
| 1619 |  | -				if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) { | 
|---|
| 1620 |  | -					struct nfs4_copy_state *copy; | 
|---|
| 1621 |  | - | 
|---|
| 1622 |  | -					spin_lock(&sp->so_server->nfs_client->cl_lock); | 
|---|
| 1623 |  | -					list_for_each_entry(copy, &sp->so_server->ss_copies, copies) { | 
|---|
| 1624 |  | -						if (memcmp(&state->stateid.other, ©->parent_state->stateid.other, NFS4_STATEID_SIZE)) | 
|---|
| 1625 |  | -							continue; | 
|---|
| 1626 |  | -						copy->flags = 1; | 
|---|
| 1627 |  | -						complete(©->completion); | 
|---|
| 1628 |  | -						printk("AGLO: server rebooted waking up the copy\n"); | 
|---|
| 1629 |  | -						break; | 
|---|
| 1630 |  | -					} | 
|---|
| 1631 |  | -					spin_unlock(&sp->so_server->nfs_client->cl_lock); | 
|---|
| 1632 |  | -				} | 
|---|
| 1633 |  | -#endif /* CONFIG_NFS_V4_2 */ | 
|---|
| 1634 |  | -				nfs4_put_open_state(state); | 
|---|
| 1635 |  | -				spin_lock(&sp->so_lock); | 
|---|
| 1636 |  | -				goto restart; | 
|---|
| 1637 |  | -			} | 
|---|
|  | 1675 | +		if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) { | 
|---|
|  | 1676 | +			nfs4_state_mark_recovery_failed(state, -EIO); | 
|---|
|  | 1677 | +			found_ssc_copy_state = true; | 
|---|
|  | 1678 | +			continue; | 
|---|
| 1638 | 1679 | } | 
|---|
|  | 1680 | +#endif /* CONFIG_NFS_V4_2 */ | 
|---|
|  | 1681 | +		refcount_inc(&state->count); | 
|---|
|  | 1682 | +		spin_unlock(&sp->so_lock); | 
|---|
|  | 1683 | +		status = __nfs4_reclaim_open_state(sp, state, ops); | 
|---|
|  | 1684 | + | 
|---|
| 1639 | 1685 | switch (status) { | 
|---|
| 1640 |  | -			default: | 
|---|
| 1641 |  | -				printk(KERN_ERR "NFS: %s: unhandled error %d\n", | 
|---|
| 1642 |  | -					__func__, status); | 
|---|
| 1643 |  | -				/* Fall through */ | 
|---|
| 1644 |  | -			case -ENOENT: | 
|---|
| 1645 |  | -			case -ENOMEM: | 
|---|
| 1646 |  | -			case -EACCES: | 
|---|
| 1647 |  | -			case -EROFS: | 
|---|
| 1648 |  | -			case -EIO: | 
|---|
| 1649 |  | -			case -ESTALE: | 
|---|
| 1650 |  | -				/* Open state on this file cannot be recovered */ | 
|---|
| 1651 |  | -				nfs4_state_mark_recovery_failed(state, status); | 
|---|
|  | 1686 | +		default: | 
|---|
|  | 1687 | +			if (status >= 0) { | 
|---|
|  | 1688 | +				loop = 0; | 
|---|
| 1652 | 1689 | break; | 
|---|
| 1653 |  | -			case -EAGAIN: | 
|---|
| 1654 |  | -				ssleep(1); | 
|---|
| 1655 |  | -				/* Fall through */ | 
|---|
| 1656 |  | -			case -NFS4ERR_ADMIN_REVOKED: | 
|---|
| 1657 |  | -			case -NFS4ERR_STALE_STATEID: | 
|---|
| 1658 |  | -			case -NFS4ERR_OLD_STATEID: | 
|---|
| 1659 |  | -			case -NFS4ERR_BAD_STATEID: | 
|---|
| 1660 |  | -			case -NFS4ERR_RECLAIM_BAD: | 
|---|
| 1661 |  | -			case -NFS4ERR_RECLAIM_CONFLICT: | 
|---|
| 1662 |  | -				nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); | 
|---|
|  | 1690 | +			} | 
|---|
|  | 1691 | +			printk(KERN_ERR "NFS: %s: unhandled error %d\n", __func__, status); | 
|---|
|  | 1692 | +			fallthrough; | 
|---|
|  | 1693 | +		case -ENOENT: | 
|---|
|  | 1694 | +		case -ENOMEM: | 
|---|
|  | 1695 | +		case -EACCES: | 
|---|
|  | 1696 | +		case -EROFS: | 
|---|
|  | 1697 | +		case -EIO: | 
|---|
|  | 1698 | +		case -ESTALE: | 
|---|
|  | 1699 | +			/* Open state on this file cannot be recovered */ | 
|---|
|  | 1700 | +			nfs4_state_mark_recovery_failed(state, status); | 
|---|
|  | 1701 | +			break; | 
|---|
|  | 1702 | +		case -EAGAIN: | 
|---|
|  | 1703 | +			ssleep(1); | 
|---|
|  | 1704 | +			if (loop++ < 10) { | 
|---|
|  | 1705 | +				set_bit(ops->state_flag_bit, &state->flags); | 
|---|
| 1663 | 1706 | break; | 
|---|
| 1664 |  | -			case -NFS4ERR_EXPIRED: | 
|---|
| 1665 |  | -			case -NFS4ERR_NO_GRACE: | 
|---|
| 1666 |  | -				nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); | 
|---|
| 1667 |  | -			case -NFS4ERR_STALE_CLIENTID: | 
|---|
| 1668 |  | -			case -NFS4ERR_BADSESSION: | 
|---|
| 1669 |  | -			case -NFS4ERR_BADSLOT: | 
|---|
| 1670 |  | -			case -NFS4ERR_BAD_HIGH_SLOT: | 
|---|
| 1671 |  | -			case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|---|
| 1672 |  | -				goto out_err; | 
|---|
|  | 1707 | +			} | 
|---|
|  | 1708 | +			fallthrough; | 
|---|
|  | 1709 | +		case -NFS4ERR_ADMIN_REVOKED: | 
|---|
|  | 1710 | +		case -NFS4ERR_STALE_STATEID: | 
|---|
|  | 1711 | +		case -NFS4ERR_OLD_STATEID: | 
|---|
|  | 1712 | +		case -NFS4ERR_BAD_STATEID: | 
|---|
|  | 1713 | +		case -NFS4ERR_RECLAIM_BAD: | 
|---|
|  | 1714 | +		case -NFS4ERR_RECLAIM_CONFLICT: | 
|---|
|  | 1715 | +			nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); | 
|---|
|  | 1716 | +			break; | 
|---|
|  | 1717 | +		case -NFS4ERR_EXPIRED: | 
|---|
|  | 1718 | +		case -NFS4ERR_NO_GRACE: | 
|---|
|  | 1719 | +			nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); | 
|---|
|  | 1720 | +			fallthrough; | 
|---|
|  | 1721 | +		case -NFS4ERR_STALE_CLIENTID: | 
|---|
|  | 1722 | +		case -NFS4ERR_BADSESSION: | 
|---|
|  | 1723 | +		case -NFS4ERR_BADSLOT: | 
|---|
|  | 1724 | +		case -NFS4ERR_BAD_HIGH_SLOT: | 
|---|
|  | 1725 | +		case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|---|
|  | 1726 | +		case -ETIMEDOUT: | 
|---|
|  | 1727 | +			goto out_err; | 
|---|
| 1673 | 1728 | } | 
|---|
| 1674 | 1729 | nfs4_put_open_state(state); | 
|---|
| 1675 | 1730 | spin_lock(&sp->so_lock); | 
|---|
| 1676 | 1731 | goto restart; | 
|---|
| 1677 | 1732 | } | 
|---|
|  | 1733 | +	raw_write_seqcount_end(&sp->so_reclaim_seqcount); | 
|---|
| 1678 | 1734 | spin_unlock(&sp->so_lock); | 
|---|
| 1679 |  | -#ifdef CONFIG_PREEMPT_RT_FULL | 
|---|
| 1680 |  | -	write_sequnlock(&sp->so_reclaim_seqlock); | 
|---|
| 1681 |  | -#else | 
|---|
| 1682 |  | -	write_seqcount_end(&sp->so_reclaim_seqlock.seqcount); | 
|---|
| 1683 |  | -#endif | 
|---|
|  | 1735 | +#ifdef CONFIG_NFS_V4_2 | 
|---|
|  | 1736 | +	if (found_ssc_copy_state) | 
|---|
|  | 1737 | +		return -EIO; | 
|---|
|  | 1738 | +#endif /* CONFIG_NFS_V4_2 */ | 
|---|
| 1684 | 1739 | return 0; | 
|---|
| 1685 | 1740 | out_err: | 
|---|
| 1686 | 1741 | nfs4_put_open_state(state); | 
|---|
| 1687 |  | -#ifdef CONFIG_PREEMPT_RT_FULL | 
|---|
| 1688 |  | -	write_sequnlock(&sp->so_reclaim_seqlock); | 
|---|
| 1689 |  | -#else | 
|---|
| 1690 |  | -	write_seqcount_end(&sp->so_reclaim_seqlock.seqcount); | 
|---|
| 1691 |  | -#endif | 
|---|
|  | 1742 | +	spin_lock(&sp->so_lock); | 
|---|
|  | 1743 | +	raw_write_seqcount_end(&sp->so_reclaim_seqcount); | 
|---|
|  | 1744 | +	spin_unlock(&sp->so_lock); | 
|---|
| 1692 | 1745 | return status; | 
|---|
| 1693 | 1746 | } | 
|---|
| 1694 | 1747 |  | 
|---|
| .. | .. | 
|---|
| 1745 | 1798 |  | 
|---|
| 1746 | 1799 | static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp) | 
|---|
| 1747 | 1800 | { | 
|---|
|  | 1801 | +	set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state); | 
|---|
| 1748 | 1802 | /* Mark all delegations for reclaim */ | 
|---|
| 1749 | 1803 | nfs_delegation_mark_reclaim(clp); | 
|---|
| 1750 | 1804 | nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot); | 
|---|
| .. | .. | 
|---|
| 1752 | 1806 |  | 
|---|
| 1753 | 1807 | static int nfs4_reclaim_complete(struct nfs_client *clp, | 
|---|
| 1754 | 1808 | const struct nfs4_state_recovery_ops *ops, | 
|---|
| 1755 |  | -				 struct rpc_cred *cred) | 
|---|
|  | 1809 | +				 const struct cred *cred) | 
|---|
| 1756 | 1810 | { | 
|---|
| 1757 | 1811 | /* Notify the server we're done reclaiming our state */ | 
|---|
| 1758 | 1812 | if (ops->reclaim_complete) | 
|---|
| .. | .. | 
|---|
| 1803 | 1857 | static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp) | 
|---|
| 1804 | 1858 | { | 
|---|
| 1805 | 1859 | const struct nfs4_state_recovery_ops *ops; | 
|---|
| 1806 |  | -	struct rpc_cred *cred; | 
|---|
|  | 1860 | +	const struct cred *cred; | 
|---|
| 1807 | 1861 | int err; | 
|---|
| 1808 | 1862 |  | 
|---|
| 1809 | 1863 | if (!nfs4_state_clear_reclaim_reboot(clp)) | 
|---|
| .. | .. | 
|---|
| 1811 | 1865 | ops = clp->cl_mvops->reboot_recovery_ops; | 
|---|
| 1812 | 1866 | cred = nfs4_get_clid_cred(clp); | 
|---|
| 1813 | 1867 | err = nfs4_reclaim_complete(clp, ops, cred); | 
|---|
| 1814 |  | -	put_rpccred(cred); | 
|---|
|  | 1868 | +	put_cred(cred); | 
|---|
| 1815 | 1869 | if (err == -NFS4ERR_CONN_NOT_BOUND_TO_SESSION) | 
|---|
| 1816 | 1870 | set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state); | 
|---|
| 1817 | 1871 | } | 
|---|
| .. | .. | 
|---|
| 1825 | 1879 | static int nfs4_recovery_handle_error(struct nfs_client *clp, int error) | 
|---|
| 1826 | 1880 | { | 
|---|
| 1827 | 1881 | switch (error) { | 
|---|
| 1828 |  | -		case 0: | 
|---|
| 1829 |  | -			break; | 
|---|
| 1830 |  | -		case -NFS4ERR_CB_PATH_DOWN: | 
|---|
| 1831 |  | -			nfs40_handle_cb_pathdown(clp); | 
|---|
| 1832 |  | -			break; | 
|---|
| 1833 |  | -		case -NFS4ERR_NO_GRACE: | 
|---|
| 1834 |  | -			nfs4_state_end_reclaim_reboot(clp); | 
|---|
| 1835 |  | -			break; | 
|---|
| 1836 |  | -		case -NFS4ERR_STALE_CLIENTID: | 
|---|
| 1837 |  | -			set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | 
|---|
| 1838 |  | -			nfs4_state_start_reclaim_reboot(clp); | 
|---|
| 1839 |  | -			break; | 
|---|
| 1840 |  | -		case -NFS4ERR_EXPIRED: | 
|---|
| 1841 |  | -			set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | 
|---|
| 1842 |  | -			nfs4_state_start_reclaim_nograce(clp); | 
|---|
| 1843 |  | -			break; | 
|---|
| 1844 |  | -		case -NFS4ERR_BADSESSION: | 
|---|
| 1845 |  | -		case -NFS4ERR_BADSLOT: | 
|---|
| 1846 |  | -		case -NFS4ERR_BAD_HIGH_SLOT: | 
|---|
| 1847 |  | -		case -NFS4ERR_DEADSESSION: | 
|---|
| 1848 |  | -		case -NFS4ERR_SEQ_FALSE_RETRY: | 
|---|
| 1849 |  | -		case -NFS4ERR_SEQ_MISORDERED: | 
|---|
| 1850 |  | -			set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); | 
|---|
| 1851 |  | -			/* Zero session reset errors */ | 
|---|
| 1852 |  | -			break; | 
|---|
| 1853 |  | -		case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|---|
| 1854 |  | -			set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); | 
|---|
| 1855 |  | -			break; | 
|---|
| 1856 |  | -		default: | 
|---|
| 1857 |  | -			dprintk("%s: failed to handle error %d for server %s\n", | 
|---|
| 1858 |  | -					__func__, error, clp->cl_hostname); | 
|---|
| 1859 |  | -			return error; | 
|---|
|  | 1882 | +	case 0: | 
|---|
|  | 1883 | +		break; | 
|---|
|  | 1884 | +	case -NFS4ERR_CB_PATH_DOWN: | 
|---|
|  | 1885 | +		nfs40_handle_cb_pathdown(clp); | 
|---|
|  | 1886 | +		break; | 
|---|
|  | 1887 | +	case -NFS4ERR_NO_GRACE: | 
|---|
|  | 1888 | +		nfs4_state_end_reclaim_reboot(clp); | 
|---|
|  | 1889 | +		break; | 
|---|
|  | 1890 | +	case -NFS4ERR_STALE_CLIENTID: | 
|---|
|  | 1891 | +		set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | 
|---|
|  | 1892 | +		nfs4_state_start_reclaim_reboot(clp); | 
|---|
|  | 1893 | +		break; | 
|---|
|  | 1894 | +	case -NFS4ERR_EXPIRED: | 
|---|
|  | 1895 | +		set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | 
|---|
|  | 1896 | +		nfs4_state_start_reclaim_nograce(clp); | 
|---|
|  | 1897 | +		break; | 
|---|
|  | 1898 | +	case -NFS4ERR_BADSESSION: | 
|---|
|  | 1899 | +	case -NFS4ERR_BADSLOT: | 
|---|
|  | 1900 | +	case -NFS4ERR_BAD_HIGH_SLOT: | 
|---|
|  | 1901 | +	case -NFS4ERR_DEADSESSION: | 
|---|
|  | 1902 | +	case -NFS4ERR_SEQ_FALSE_RETRY: | 
|---|
|  | 1903 | +	case -NFS4ERR_SEQ_MISORDERED: | 
|---|
|  | 1904 | +		set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); | 
|---|
|  | 1905 | +		/* Zero session reset errors */ | 
|---|
|  | 1906 | +		break; | 
|---|
|  | 1907 | +	case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|---|
|  | 1908 | +		set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); | 
|---|
|  | 1909 | +		break; | 
|---|
|  | 1910 | +	default: | 
|---|
|  | 1911 | +		dprintk("%s: failed to handle error %d for server %s\n", | 
|---|
|  | 1912 | +				__func__, error, clp->cl_hostname); | 
|---|
|  | 1913 | +		return error; | 
|---|
| 1860 | 1914 | } | 
|---|
| 1861 | 1915 | dprintk("%s: handled error %d for server %s\n", __func__, error, | 
|---|
| 1862 | 1916 | clp->cl_hostname); | 
|---|
| .. | .. | 
|---|
| 1909 | 1963 |  | 
|---|
| 1910 | 1964 | static int nfs4_check_lease(struct nfs_client *clp) | 
|---|
| 1911 | 1965 | { | 
|---|
| 1912 |  | -	struct rpc_cred *cred; | 
|---|
|  | 1966 | +	const struct cred *cred; | 
|---|
| 1913 | 1967 | const struct nfs4_state_maintenance_ops *ops = | 
|---|
| 1914 | 1968 | clp->cl_mvops->state_renewal_ops; | 
|---|
| 1915 | 1969 | int status; | 
|---|
| .. | .. | 
|---|
| 1917 | 1971 | /* Is the client already known to have an expired lease? */ | 
|---|
| 1918 | 1972 | if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) | 
|---|
| 1919 | 1973 | return 0; | 
|---|
| 1920 |  | -	spin_lock(&clp->cl_lock); | 
|---|
| 1921 |  | -	cred = ops->get_state_renewal_cred_locked(clp); | 
|---|
| 1922 |  | -	spin_unlock(&clp->cl_lock); | 
|---|
|  | 1974 | +	cred = ops->get_state_renewal_cred(clp); | 
|---|
| 1923 | 1975 | if (cred == NULL) { | 
|---|
| 1924 | 1976 | cred = nfs4_get_clid_cred(clp); | 
|---|
| 1925 | 1977 | status = -ENOKEY; | 
|---|
| .. | .. | 
|---|
| 1927 | 1979 | goto out; | 
|---|
| 1928 | 1980 | } | 
|---|
| 1929 | 1981 | status = ops->renew_lease(clp, cred); | 
|---|
| 1930 |  | -	put_rpccred(cred); | 
|---|
|  | 1982 | +	put_cred(cred); | 
|---|
| 1931 | 1983 | if (status == -ETIMEDOUT) { | 
|---|
| 1932 | 1984 | set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); | 
|---|
| 1933 | 1985 | return 0; | 
|---|
| .. | .. | 
|---|
| 1961 | 2013 | return -EPERM; | 
|---|
| 1962 | 2014 | case -EACCES: | 
|---|
| 1963 | 2015 | case -NFS4ERR_DELAY: | 
|---|
| 1964 |  | -	case -ETIMEDOUT: | 
|---|
| 1965 | 2016 | case -EAGAIN: | 
|---|
| 1966 | 2017 | ssleep(1); | 
|---|
| 1967 | 2018 | break; | 
|---|
| .. | .. | 
|---|
| 1987 | 2038 |  | 
|---|
| 1988 | 2039 | static int nfs4_establish_lease(struct nfs_client *clp) | 
|---|
| 1989 | 2040 | { | 
|---|
| 1990 |  | -	struct rpc_cred *cred; | 
|---|
|  | 2041 | +	const struct cred *cred; | 
|---|
| 1991 | 2042 | const struct nfs4_state_recovery_ops *ops = | 
|---|
| 1992 | 2043 | clp->cl_mvops->reboot_recovery_ops; | 
|---|
| 1993 | 2044 | int status; | 
|---|
| .. | .. | 
|---|
| 1999 | 2050 | if (cred == NULL) | 
|---|
| 2000 | 2051 | return -ENOENT; | 
|---|
| 2001 | 2052 | status = ops->establish_clid(clp, cred); | 
|---|
| 2002 |  | -	put_rpccred(cred); | 
|---|
|  | 2053 | +	put_cred(cred); | 
|---|
| 2003 | 2054 | if (status != 0) | 
|---|
| 2004 | 2055 | return status; | 
|---|
| 2005 | 2056 | pnfs_destroy_all_layouts(clp); | 
|---|
| .. | .. | 
|---|
| 2046 | 2097 | * | 
|---|
| 2047 | 2098 | * Returns zero or a negative NFS4ERR status code. | 
|---|
| 2048 | 2099 | */ | 
|---|
| 2049 |  | -static int nfs4_try_migration(struct nfs_server *server, struct rpc_cred *cred) | 
|---|
|  | 2100 | +static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred) | 
|---|
| 2050 | 2101 | { | 
|---|
| 2051 | 2102 | struct nfs_client *clp = server->nfs_client; | 
|---|
| 2052 | 2103 | struct nfs4_fs_locations *locations = NULL; | 
|---|
| .. | .. | 
|---|
| 2086 | 2137 | } | 
|---|
| 2087 | 2138 |  | 
|---|
| 2088 | 2139 | status = nfs4_begin_drain_session(clp); | 
|---|
| 2089 |  | -	if (status != 0) | 
|---|
| 2090 |  | -		return status; | 
|---|
|  | 2140 | +	if (status != 0) { | 
|---|
|  | 2141 | +		result = status; | 
|---|
|  | 2142 | +		goto out; | 
|---|
|  | 2143 | +	} | 
|---|
| 2091 | 2144 |  | 
|---|
| 2092 | 2145 | status = nfs4_replace_transport(server, locations); | 
|---|
| 2093 | 2146 | if (status != 0) { | 
|---|
| .. | .. | 
|---|
| 2119 | 2172 | const struct nfs4_state_maintenance_ops *ops = | 
|---|
| 2120 | 2173 | clp->cl_mvops->state_renewal_ops; | 
|---|
| 2121 | 2174 | struct nfs_server *server; | 
|---|
| 2122 |  | -	struct rpc_cred *cred; | 
|---|
|  | 2175 | +	const struct cred *cred; | 
|---|
| 2123 | 2176 |  | 
|---|
| 2124 | 2177 | dprintk("%s: migration reported on \"%s\"\n", __func__, | 
|---|
| 2125 | 2178 | clp->cl_hostname); | 
|---|
| 2126 | 2179 |  | 
|---|
| 2127 |  | -	spin_lock(&clp->cl_lock); | 
|---|
| 2128 |  | -	cred = ops->get_state_renewal_cred_locked(clp); | 
|---|
| 2129 |  | -	spin_unlock(&clp->cl_lock); | 
|---|
|  | 2180 | +	cred = ops->get_state_renewal_cred(clp); | 
|---|
| 2130 | 2181 | if (cred == NULL) | 
|---|
| 2131 | 2182 | return -NFS4ERR_NOENT; | 
|---|
| 2132 | 2183 |  | 
|---|
| .. | .. | 
|---|
| 2147 | 2198 | rcu_read_unlock(); | 
|---|
| 2148 | 2199 | status = nfs4_try_migration(server, cred); | 
|---|
| 2149 | 2200 | if (status < 0) { | 
|---|
| 2150 |  | -			put_rpccred(cred); | 
|---|
|  | 2201 | +			put_cred(cred); | 
|---|
| 2151 | 2202 | return status; | 
|---|
| 2152 | 2203 | } | 
|---|
| 2153 | 2204 | goto restart; | 
|---|
| 2154 | 2205 | } | 
|---|
| 2155 | 2206 | rcu_read_unlock(); | 
|---|
| 2156 |  | -	put_rpccred(cred); | 
|---|
|  | 2207 | +	put_cred(cred); | 
|---|
| 2157 | 2208 | return 0; | 
|---|
| 2158 | 2209 | } | 
|---|
| 2159 | 2210 |  | 
|---|
| .. | .. | 
|---|
| 2167 | 2218 | const struct nfs4_state_maintenance_ops *ops = | 
|---|
| 2168 | 2219 | clp->cl_mvops->state_renewal_ops; | 
|---|
| 2169 | 2220 | struct nfs_server *server; | 
|---|
| 2170 |  | -	struct rpc_cred *cred; | 
|---|
|  | 2221 | +	const struct cred *cred; | 
|---|
| 2171 | 2222 |  | 
|---|
| 2172 | 2223 | dprintk("%s: lease moved reported on \"%s\"\n", __func__, | 
|---|
| 2173 | 2224 | clp->cl_hostname); | 
|---|
| 2174 | 2225 |  | 
|---|
| 2175 |  | -	spin_lock(&clp->cl_lock); | 
|---|
| 2176 |  | -	cred = ops->get_state_renewal_cred_locked(clp); | 
|---|
| 2177 |  | -	spin_unlock(&clp->cl_lock); | 
|---|
|  | 2226 | +	cred = ops->get_state_renewal_cred(clp); | 
|---|
| 2178 | 2227 | if (cred == NULL) | 
|---|
| 2179 | 2228 | return -NFS4ERR_NOENT; | 
|---|
| 2180 | 2229 |  | 
|---|
| .. | .. | 
|---|
| 2202 | 2251 | rcu_read_unlock(); | 
|---|
| 2203 | 2252 |  | 
|---|
| 2204 | 2253 | out: | 
|---|
| 2205 |  | -	put_rpccred(cred); | 
|---|
|  | 2254 | +	put_cred(cred); | 
|---|
| 2206 | 2255 | return 0; | 
|---|
| 2207 | 2256 | } | 
|---|
| 2208 | 2257 |  | 
|---|
| .. | .. | 
|---|
| 2225 | 2274 | const struct nfs4_state_recovery_ops *ops = | 
|---|
| 2226 | 2275 | clp->cl_mvops->reboot_recovery_ops; | 
|---|
| 2227 | 2276 | struct rpc_clnt *clnt; | 
|---|
| 2228 |  | -	struct rpc_cred *cred; | 
|---|
|  | 2277 | +	const struct cred *cred; | 
|---|
| 2229 | 2278 | int i, status; | 
|---|
| 2230 | 2279 |  | 
|---|
| 2231 | 2280 | dprintk("NFS: %s: testing '%s'\n", __func__, clp->cl_hostname); | 
|---|
| .. | .. | 
|---|
| 2241 | 2290 | goto out_unlock; | 
|---|
| 2242 | 2291 |  | 
|---|
| 2243 | 2292 | status = ops->detect_trunking(clp, result, cred); | 
|---|
| 2244 |  | -	put_rpccred(cred); | 
|---|
|  | 2293 | +	put_cred(cred); | 
|---|
| 2245 | 2294 | switch (status) { | 
|---|
| 2246 | 2295 | case 0: | 
|---|
| 2247 | 2296 | case -EINTR: | 
|---|
| .. | .. | 
|---|
| 2250 | 2299 | case -ETIMEDOUT: | 
|---|
| 2251 | 2300 | if (clnt->cl_softrtry) | 
|---|
| 2252 | 2301 | break; | 
|---|
| 2253 |  | -		/* Fall through */ | 
|---|
|  | 2302 | +		fallthrough; | 
|---|
| 2254 | 2303 | case -NFS4ERR_DELAY: | 
|---|
| 2255 | 2304 | case -EAGAIN: | 
|---|
| 2256 | 2305 | ssleep(1); | 
|---|
| 2257 |  | -		/* Fall through */ | 
|---|
|  | 2306 | +		fallthrough; | 
|---|
| 2258 | 2307 | case -NFS4ERR_STALE_CLIENTID: | 
|---|
| 2259 | 2308 | dprintk("NFS: %s after status %d, retrying\n", | 
|---|
| 2260 | 2309 | __func__, status); | 
|---|
| .. | .. | 
|---|
| 2266 | 2315 | } | 
|---|
| 2267 | 2316 | if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX) | 
|---|
| 2268 | 2317 | break; | 
|---|
| 2269 |  | -		/* Fall through */ | 
|---|
|  | 2318 | +		fallthrough; | 
|---|
| 2270 | 2319 | case -NFS4ERR_CLID_INUSE: | 
|---|
| 2271 | 2320 | case -NFS4ERR_WRONGSEC: | 
|---|
| 2272 | 2321 | /* No point in retrying if we already used RPC_AUTH_UNIX */ | 
|---|
| .. | .. | 
|---|
| 2372 | 2421 | { | 
|---|
| 2373 | 2422 | /* FIXME: For now, we destroy all layouts. */ | 
|---|
| 2374 | 2423 | pnfs_destroy_all_layouts(clp); | 
|---|
| 2375 |  | -	/* FIXME: For now, we test all delegations+open state+locks. */ | 
|---|
| 2376 |  | -	nfs41_handle_some_state_revoked(clp); | 
|---|
|  | 2424 | +	nfs_test_expired_all_delegations(clp); | 
|---|
| 2377 | 2425 | dprintk("%s: Recallable state revoked on server %s!\n", __func__, | 
|---|
| 2378 | 2426 | clp->cl_hostname); | 
|---|
| 2379 | 2427 | } | 
|---|
| .. | .. | 
|---|
| 2432 | 2480 |  | 
|---|
| 2433 | 2481 | static int nfs4_reset_session(struct nfs_client *clp) | 
|---|
| 2434 | 2482 | { | 
|---|
| 2435 |  | -	struct rpc_cred *cred; | 
|---|
|  | 2483 | +	const struct cred *cred; | 
|---|
| 2436 | 2484 | int status; | 
|---|
| 2437 | 2485 |  | 
|---|
| 2438 | 2486 | if (!nfs4_has_session(clp)) | 
|---|
| .. | .. | 
|---|
| 2470 | 2518 | dprintk("%s: session reset was successful for server %s!\n", | 
|---|
| 2471 | 2519 | __func__, clp->cl_hostname); | 
|---|
| 2472 | 2520 | out: | 
|---|
| 2473 |  | -	if (cred) | 
|---|
| 2474 |  | -		put_rpccred(cred); | 
|---|
|  | 2521 | +	put_cred(cred); | 
|---|
| 2475 | 2522 | return status; | 
|---|
| 2476 | 2523 | } | 
|---|
| 2477 | 2524 |  | 
|---|
| 2478 | 2525 | static int nfs4_bind_conn_to_session(struct nfs_client *clp) | 
|---|
| 2479 | 2526 | { | 
|---|
| 2480 |  | -	struct rpc_cred *cred; | 
|---|
|  | 2527 | +	const struct cred *cred; | 
|---|
| 2481 | 2528 | int ret; | 
|---|
| 2482 | 2529 |  | 
|---|
| 2483 | 2530 | if (!nfs4_has_session(clp)) | 
|---|
| .. | .. | 
|---|
| 2487 | 2534 | return ret; | 
|---|
| 2488 | 2535 | cred = nfs4_get_clid_cred(clp); | 
|---|
| 2489 | 2536 | ret = nfs4_proc_bind_conn_to_session(clp, cred); | 
|---|
| 2490 |  | -	if (cred) | 
|---|
| 2491 |  | -		put_rpccred(cred); | 
|---|
|  | 2537 | +	put_cred(cred); | 
|---|
| 2492 | 2538 | clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); | 
|---|
| 2493 | 2539 | switch (ret) { | 
|---|
| 2494 | 2540 | case 0: | 
|---|
| .. | .. | 
|---|
| 2504 | 2550 | } | 
|---|
| 2505 | 2551 | return 0; | 
|---|
| 2506 | 2552 | } | 
|---|
|  | 2553 | + | 
|---|
|  | 2554 | +static void nfs4_layoutreturn_any_run(struct nfs_client *clp) | 
|---|
|  | 2555 | +{ | 
|---|
|  | 2556 | +	int iomode = 0; | 
|---|
|  | 2557 | + | 
|---|
|  | 2558 | +	if (test_and_clear_bit(NFS4CLNT_RECALL_ANY_LAYOUT_READ, &clp->cl_state)) | 
|---|
|  | 2559 | +		iomode += IOMODE_READ; | 
|---|
|  | 2560 | +	if (test_and_clear_bit(NFS4CLNT_RECALL_ANY_LAYOUT_RW, &clp->cl_state)) | 
|---|
|  | 2561 | +		iomode += IOMODE_RW; | 
|---|
|  | 2562 | +	/* Note: IOMODE_READ + IOMODE_RW == IOMODE_ANY */ | 
|---|
|  | 2563 | +	if (iomode) { | 
|---|
|  | 2564 | +		pnfs_layout_return_unused_byclid(clp, iomode); | 
|---|
|  | 2565 | +		set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); | 
|---|
|  | 2566 | +	} | 
|---|
|  | 2567 | +} | 
|---|
| 2507 | 2568 | #else /* CONFIG_NFS_V4_1 */ | 
|---|
| 2508 | 2569 | static int nfs4_reset_session(struct nfs_client *clp) { return 0; } | 
|---|
| 2509 | 2570 |  | 
|---|
| .. | .. | 
|---|
| 2511 | 2572 | { | 
|---|
| 2512 | 2573 | return 0; | 
|---|
| 2513 | 2574 | } | 
|---|
|  | 2575 | + | 
|---|
|  | 2576 | +static void nfs4_layoutreturn_any_run(struct nfs_client *clp) | 
|---|
|  | 2577 | +{ | 
|---|
|  | 2578 | +} | 
|---|
| 2514 | 2579 | #endif /* CONFIG_NFS_V4_1 */ | 
|---|
| 2515 | 2580 |  | 
|---|
| 2516 | 2581 | static void nfs4_state_manager(struct nfs_client *clp) | 
|---|
| 2517 | 2582 | { | 
|---|
|  | 2583 | +	unsigned int memflags; | 
|---|
| 2518 | 2584 | int status = 0; | 
|---|
| 2519 | 2585 | const char *section = "", *section_sep = ""; | 
|---|
| 2520 | 2586 |  | 
|---|
|  | 2587 | +	/* | 
|---|
|  | 2588 | +	 * State recovery can deadlock if the direct reclaim code tries | 
|---|
|  | 2589 | +	 * start NFS writeback. So ensure memory allocations are all | 
|---|
|  | 2590 | +	 * GFP_NOFS. | 
|---|
|  | 2591 | +	 */ | 
|---|
|  | 2592 | +	memflags = memalloc_nofs_save(); | 
|---|
|  | 2593 | + | 
|---|
| 2521 | 2594 | /* Ensure exclusive access to NFSv4 state */ | 
|---|
| 2522 | 2595 | do { | 
|---|
|  | 2596 | +		trace_nfs4_state_mgr(clp); | 
|---|
| 2523 | 2597 | clear_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); | 
|---|
| 2524 | 2598 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { | 
|---|
| 2525 | 2599 | section = "purge state"; | 
|---|
| .. | .. | 
|---|
| 2590 | 2664 | if (status < 0) | 
|---|
| 2591 | 2665 | goto out_error; | 
|---|
| 2592 | 2666 | nfs4_state_end_reclaim_reboot(clp); | 
|---|
|  | 2667 | +			continue; | 
|---|
| 2593 | 2668 | } | 
|---|
| 2594 | 2669 |  | 
|---|
| 2595 | 2670 | /* Detect expired delegations... */ | 
|---|
| .. | .. | 
|---|
| 2600 | 2675 | } | 
|---|
| 2601 | 2676 |  | 
|---|
| 2602 | 2677 | /* Now recover expired state... */ | 
|---|
| 2603 |  | -		if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) { | 
|---|
|  | 2678 | +		if (test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) { | 
|---|
| 2604 | 2679 | section = "reclaim nograce"; | 
|---|
| 2605 | 2680 | status = nfs4_do_reclaim(clp, | 
|---|
| 2606 | 2681 | clp->cl_mvops->nograce_recovery_ops); | 
|---|
| .. | .. | 
|---|
| 2608 | 2683 | continue; | 
|---|
| 2609 | 2684 | if (status < 0) | 
|---|
| 2610 | 2685 | goto out_error; | 
|---|
|  | 2686 | +			clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state); | 
|---|
| 2611 | 2687 | } | 
|---|
| 2612 | 2688 |  | 
|---|
|  | 2689 | +		memalloc_nofs_restore(memflags); | 
|---|
| 2613 | 2690 | nfs4_end_drain_session(clp); | 
|---|
| 2614 | 2691 | nfs4_clear_state_manager_bit(clp); | 
|---|
| 2615 | 2692 |  | 
|---|
| 2616 |  | -		if (!test_and_set_bit(NFS4CLNT_DELEGRETURN_RUNNING, &clp->cl_state)) { | 
|---|
|  | 2693 | +		if (test_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state) && | 
|---|
|  | 2694 | +		    !test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, | 
|---|
|  | 2695 | +				      &clp->cl_state)) { | 
|---|
|  | 2696 | +			memflags = memalloc_nofs_save(); | 
|---|
|  | 2697 | +			continue; | 
|---|
|  | 2698 | +		} | 
|---|
|  | 2699 | + | 
|---|
|  | 2700 | +		if (!test_and_set_bit(NFS4CLNT_RECALL_RUNNING, &clp->cl_state)) { | 
|---|
| 2617 | 2701 | if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) { | 
|---|
| 2618 | 2702 | nfs_client_return_marked_delegations(clp); | 
|---|
| 2619 | 2703 | set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); | 
|---|
| 2620 | 2704 | } | 
|---|
| 2621 |  | -			clear_bit(NFS4CLNT_DELEGRETURN_RUNNING, &clp->cl_state); | 
|---|
|  | 2705 | +			nfs4_layoutreturn_any_run(clp); | 
|---|
|  | 2706 | +			clear_bit(NFS4CLNT_RECALL_RUNNING, &clp->cl_state); | 
|---|
| 2622 | 2707 | } | 
|---|
| 2623 | 2708 |  | 
|---|
| 2624 |  | -		/* Did we race with an attempt to give us more work? */ | 
|---|
| 2625 |  | -		if (!test_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state)) | 
|---|
| 2626 |  | -			return; | 
|---|
| 2627 |  | -		if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) | 
|---|
| 2628 |  | -			return; | 
|---|
|  | 2709 | +		return; | 
|---|
|  | 2710 | + | 
|---|
| 2629 | 2711 | } while (refcount_read(&clp->cl_count) > 1 && !signalled()); | 
|---|
| 2630 | 2712 | goto out_drain; | 
|---|
| 2631 | 2713 |  | 
|---|
| 2632 | 2714 | out_error: | 
|---|
| 2633 | 2715 | if (strlen(section)) | 
|---|
| 2634 | 2716 | section_sep = ": "; | 
|---|
|  | 2717 | +	trace_nfs4_state_mgr_failed(clp, section, status); | 
|---|
| 2635 | 2718 | pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s" | 
|---|
| 2636 | 2719 | " with error %d\n", section_sep, section, | 
|---|
| 2637 | 2720 | clp->cl_hostname, -status); | 
|---|
| 2638 | 2721 | ssleep(1); | 
|---|
| 2639 | 2722 | out_drain: | 
|---|
|  | 2723 | +	memalloc_nofs_restore(memflags); | 
|---|
| 2640 | 2724 | nfs4_end_drain_session(clp); | 
|---|
| 2641 | 2725 | nfs4_clear_state_manager_bit(clp); | 
|---|
| 2642 | 2726 | } | 
|---|
| .. | .. | 
|---|
| 2644 | 2728 | static int nfs4_run_state_manager(void *ptr) | 
|---|
| 2645 | 2729 | { | 
|---|
| 2646 | 2730 | struct nfs_client *clp = ptr; | 
|---|
|  | 2731 | +	struct rpc_clnt *cl = clp->cl_rpcclient; | 
|---|
|  | 2732 | + | 
|---|
|  | 2733 | +	while (cl != cl->cl_parent) | 
|---|
|  | 2734 | +		cl = cl->cl_parent; | 
|---|
| 2647 | 2735 |  | 
|---|
| 2648 | 2736 | allow_signal(SIGKILL); | 
|---|
|  | 2737 | +again: | 
|---|
| 2649 | 2738 | nfs4_state_manager(clp); | 
|---|
|  | 2739 | + | 
|---|
|  | 2740 | +	if (test_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state) && | 
|---|
|  | 2741 | +	    !test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state)) { | 
|---|
|  | 2742 | +		wait_var_event_interruptible(&clp->cl_state, | 
|---|
|  | 2743 | +					     test_bit(NFS4CLNT_RUN_MANAGER, | 
|---|
|  | 2744 | +						      &clp->cl_state)); | 
|---|
|  | 2745 | +		if (!atomic_read(&cl->cl_swapper)) | 
|---|
|  | 2746 | +			clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); | 
|---|
|  | 2747 | +		if (refcount_read(&clp->cl_count) > 1 && !signalled() && | 
|---|
|  | 2748 | +		    !test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state)) | 
|---|
|  | 2749 | +			goto again; | 
|---|
|  | 2750 | +		/* Either no longer a swapper, or were signalled */ | 
|---|
|  | 2751 | +		clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); | 
|---|
|  | 2752 | +	} | 
|---|
|  | 2753 | + | 
|---|
|  | 2754 | +	if (refcount_read(&clp->cl_count) > 1 && !signalled() && | 
|---|
|  | 2755 | +	    test_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state) && | 
|---|
|  | 2756 | +	    !test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state)) | 
|---|
|  | 2757 | +		goto again; | 
|---|
|  | 2758 | + | 
|---|
| 2650 | 2759 | nfs_put_client(clp); | 
|---|
| 2651 | 2760 | module_put_and_exit(0); | 
|---|
| 2652 | 2761 | return 0; | 
|---|