NFSv4.1: Handle errors in nfs4_bind_conn_to_session
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / nfs / nfs4state.c
index 03fa802..d685fd4 100644 (file)
@@ -256,7 +256,7 @@ int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
                goto out;
        set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
 do_confirm:
-       status = nfs4_proc_create_session(clp);
+       status = nfs4_proc_create_session(clp, cred);
        if (status != 0)
                goto out;
        clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
@@ -1574,26 +1574,62 @@ out:
        return nfs4_recovery_handle_error(clp, status);
 }
 
+/* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
+ * on EXCHANGE_ID for v4.1
+ */
+static int nfs4_handle_reclaim_lease_error(struct nfs_client *clp, int status)
+{
+       switch (status) {
+       case -NFS4ERR_SEQ_MISORDERED:
+               if (test_and_set_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state))
+                       return -ESERVERFAULT;
+               /* Lease confirmation error: retry after purging the lease */
+               ssleep(1);
+       case -NFS4ERR_CLID_INUSE:
+       case -NFS4ERR_STALE_CLIENTID:
+               clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
+               break;
+       case -EACCES:
+               if (clp->cl_machine_cred == NULL)
+                       return -EACCES;
+               /* Handle case where the user hasn't set up machine creds */
+               nfs4_clear_machine_cred(clp);
+       case -NFS4ERR_DELAY:
+       case -ETIMEDOUT:
+       case -EAGAIN:
+               ssleep(1);
+               break;
+
+       case -NFS4ERR_MINOR_VERS_MISMATCH:
+               if (clp->cl_cons_state == NFS_CS_SESSION_INITING)
+                       nfs_mark_client_ready(clp, -EPROTONOSUPPORT);
+               return -EPROTONOSUPPORT;
+       case -EKEYEXPIRED:
+               nfs4_warn_keyexpired(clp->cl_hostname);
+       case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery
+                                * in nfs4_exchange_id */
+       default:
+               return status;
+       }
+       set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
+       return 0;
+}
+
 static int nfs4_reclaim_lease(struct nfs_client *clp)
 {
        struct rpc_cred *cred;
        const struct nfs4_state_recovery_ops *ops =
                clp->cl_mvops->reboot_recovery_ops;
-       int status = -ENOENT;
+       int status;
 
        cred = ops->get_clid_cred(clp);
-       if (cred != NULL) {
-               status = ops->establish_clid(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);
-                       status = -EAGAIN;
-               }
-               if (status == -NFS4ERR_MINOR_VERS_MISMATCH)
-                       status = -EPROTONOSUPPORT;
-       }
-       return status;
+       if (cred == NULL)
+               return -ENOENT;
+       status = ops->establish_clid(clp, cred);
+       put_rpccred(cred);
+       if (status != 0)
+               return nfs4_handle_reclaim_lease_error(clp, status);
+       return 0;
 }
 
 #ifdef CONFIG_NFS_V4_1
@@ -1616,6 +1652,7 @@ static void nfs4_reset_all_state(struct nfs_client *clp)
 {
        if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
                set_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state);
+               clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
                nfs4_state_start_reclaim_nograce(clp);
                nfs4_schedule_state_manager(clp);
        }
@@ -1680,10 +1717,12 @@ void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags)
 
 static int nfs4_reset_session(struct nfs_client *clp)
 {
+       struct rpc_cred *cred;
        int status;
 
        nfs4_begin_drain_session(clp);
-       status = nfs4_proc_destroy_session(clp->cl_session);
+       cred = nfs4_get_exchange_id_cred(clp);
+       status = nfs4_proc_destroy_session(clp->cl_session, cred);
        if (status && status != -NFS4ERR_BADSESSION &&
            status != -NFS4ERR_DEADSESSION) {
                status = nfs4_recovery_handle_error(clp, status);
@@ -1691,7 +1730,7 @@ static int nfs4_reset_session(struct nfs_client *clp)
        }
 
        memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN);
-       status = nfs4_proc_create_session(clp);
+       status = nfs4_proc_create_session(clp, cred);
        if (status) {
                status = nfs4_recovery_handle_error(clp, status);
                goto out;
@@ -1705,6 +1744,8 @@ static int nfs4_reset_session(struct nfs_client *clp)
        if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
                nfs41_setup_state_renewal(clp);
 out:
+       if (cred)
+               put_rpccred(cred);
        return status;
 }
 
@@ -1738,7 +1779,26 @@ static int nfs4_recall_slot(struct nfs_client *clp)
 
 static int nfs4_bind_conn_to_session(struct nfs_client *clp)
 {
-       return nfs4_proc_bind_conn_to_session(clp);
+       struct rpc_cred *cred;
+       int ret;
+
+       nfs4_begin_drain_session(clp);
+       cred = nfs4_get_exchange_id_cred(clp);
+       ret = nfs4_proc_bind_conn_to_session(clp, cred);
+       if (cred)
+               put_rpccred(cred);
+       clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
+       switch (ret) {
+       case 0:
+               break;
+       case -NFS4ERR_DELAY:
+               ssleep(1);
+               set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
+               break;
+       default:
+               return nfs4_recovery_handle_error(clp, ret);
+       }
+       return 0;
 }
 #else /* CONFIG_NFS_V4_1 */
 static int nfs4_reset_session(struct nfs_client *clp) { return 0; }
@@ -1751,32 +1811,6 @@ static int nfs4_bind_conn_to_session(struct nfs_client *clp)
 }
 #endif /* CONFIG_NFS_V4_1 */
 
-/* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
- * on EXCHANGE_ID for v4.1
- */
-static void nfs4_set_lease_expired(struct nfs_client *clp, int status)
-{
-       switch (status) {
-       case -NFS4ERR_CLID_INUSE:
-       case -NFS4ERR_STALE_CLIENTID:
-               clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
-               break;
-       case -NFS4ERR_DELAY:
-       case -ETIMEDOUT:
-       case -EAGAIN:
-               ssleep(1);
-               break;
-
-       case -EKEYEXPIRED:
-               nfs4_warn_keyexpired(clp->cl_hostname);
-       case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery
-                                * in nfs4_exchange_id */
-       default:
-               return;
-       }
-       set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
-}
-
 static void nfs4_state_manager(struct nfs_client *clp)
 {
        int status = 0;
@@ -1784,7 +1818,9 @@ static void nfs4_state_manager(struct nfs_client *clp)
        /* Ensure exclusive access to NFSv4 state */
        do {
                if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
-                       nfs4_reclaim_lease(clp);
+                       status = nfs4_reclaim_lease(clp);
+                       if (status < 0)
+                               goto out_error;
                        clear_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state);
                        set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
                }
@@ -1792,16 +1828,10 @@ static void nfs4_state_manager(struct nfs_client *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) {
-                               nfs4_set_lease_expired(clp, status);
-                               if (test_bit(NFS4CLNT_LEASE_EXPIRED,
-                                                       &clp->cl_state))
-                                       continue;
-                               if (clp->cl_cons_state ==
-                                                       NFS_CS_SESSION_INITING)
-                                       nfs_mark_client_ready(clp, status);
+                       if (status < 0)
                                goto out_error;
-                       }
+                       if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
+                               continue;
                        clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
 
                        if (test_and_clear_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH,
@@ -1838,6 +1868,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
                        status = nfs4_bind_conn_to_session(clp);
                        if (status < 0)
                                goto out_error;
+                       continue;
                }
 
                /* First recover reboot state... */