Skip to content
Snippets Groups Projects
nfs4state.c 30 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    	nfs_delegation_reap_unclaimed(clp);
    }
    
    static void nfs_delegation_clear_all(struct nfs_client *clp)
    {
    	nfs_delegation_mark_reclaim(clp);
    	nfs_delegation_reap_unclaimed(clp);
    }
    
    static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
    {
    	nfs_delegation_clear_all(clp);
    	nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
    }
    
    static void nfs4_state_end_reclaim_nograce(struct nfs_client *clp)
    {
    	clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
    }
    
    
    static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	int status = 0;
    
    
    	/* Note: list is protected by exclusive lock on cl->cl_sem */
    	for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
    		struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
    		status = nfs4_reclaim_open_state(sp, ops);
    		if (status < 0)
    			break;
    	}
    	return status;
    }
    
    static int nfs4_check_lease(struct nfs_client *clp)
    {
    	struct rpc_cred *cred;
    	int status = -NFS4ERR_EXPIRED;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    
    	/* Are there any open files on this volume? */
    	cred = nfs4_get_renew_cred(clp);
    	if (cred != NULL) {
    		/* Yes there are: try to renew the old lease */
    		status = nfs4_proc_renew(clp, cred);
    
    		switch (status) {
    			case -NFS4ERR_CB_PATH_DOWN:
    				set_bit(NFS4CLNT_CB_PATH_DOWN, &clp->cl_state);
    				break;
    			case -NFS4ERR_STALE_CLIENTID:
    			case -NFS4ERR_LEASE_MOVED:
    				set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
    				nfs4_state_start_reclaim_reboot(clp);
    				break;
    			case -NFS4ERR_EXPIRED:
    				set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
    				nfs4_state_start_reclaim_nograce(clp);
    		}
    
    
    	/* "reboot" to ensure we clear all state on the server */
    	clp->cl_boot_time = CURRENT_TIME;
    
    	set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
    
    	return status;
    }
    
    static int nfs4_reclaim_lease(struct nfs_client *clp)
    {
    	struct rpc_cred *cred;
    	int status = -ENOENT;
    
    
    	cred = nfs4_get_setclientid_cred(clp);
    
    	if (cred != NULL) {
    		status = nfs4_init_client(clp, cred);
    		put_rpccred(cred);
    
    		/* Handle case where the user hasn't set up machine creds */
    		if (status == -EACCES && cred == clp->cl_machine_cred) {
    			nfs4_clear_machine_cred(clp);
    
    	return status;
    }
    
    static int reclaimer(void *ptr)
    {
    	struct nfs_client *clp = ptr;
    	int status = 0;
    
    	allow_signal(SIGKILL);
    
    	/* Ensure exclusive access to NFSv4 state */
    	down_write(&clp->cl_sem);
    	while (!list_empty(&clp->cl_superblocks)) {
    		status = nfs4_check_lease(clp);
    
    
    		if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) {
    			/* We're going to have to re-establish a clientid */
    			status = nfs4_reclaim_lease(clp);
    			if (status) {
    				set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
    				if (status == -EAGAIN)
    					continue;
    				goto out_error;
    			}
    		}
    
    		/* First recover reboot state... */
    		if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
    			/* Note: list is protected by exclusive lock on cl->cl_sem */
    			status = nfs4_do_reclaim(clp, &nfs4_reboot_recovery_ops);
    			if (status == -NFS4ERR_STALE_CLIENTID) {
    				set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
    
    			}
    			nfs4_state_end_reclaim_reboot(clp);
    			continue;
    
    		/* Now recover expired state... */
    		if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
    			/* Note: list is protected by exclusive lock on cl->cl_sem */
    			status = nfs4_do_reclaim(clp, &nfs4_nograce_recovery_ops);
    			if (status < 0) {
    				set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
    				if (status == -NFS4ERR_STALE_CLIENTID)
    					continue;
    				if (status == -NFS4ERR_EXPIRED)
    					continue;
    				goto out_error;
    			} else
    				nfs4_state_end_reclaim_nograce(clp);
    			continue;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		}
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	}
    out:
    	up_write(&clp->cl_sem);
    
    	if (test_and_clear_bit(NFS4CLNT_CB_PATH_DOWN, &clp->cl_state))
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		nfs_handle_cb_pathdown(clp);
    
    	nfs4_clear_recover_bit(clp);
    
    	nfs_put_client(clp);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	return 0;
    out_error:
    
    	printk(KERN_WARNING "Error: state recovery failed on NFSv4 server %s"
    			" with error %d\n", clp->cl_hostname, -status);
    
    	if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
    		nfs4_state_end_reclaim_reboot(clp);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	goto out;
    }
    
    /*
     * Local variables:
     *  c-basic-offset: 8
     * End:
     */