Fix a second potential rpc_wakeup race...
[firefly-linux-kernel-4.4.55.git] / net / sunrpc / clnt.c
index 355e7863c0aa57a72bf933682ae2846b8323386a..a323abc7ea85b0c2563f2e664939bc8943cc8dfd 100644 (file)
@@ -60,8 +60,8 @@ static void   call_refreshresult(struct rpc_task *task);
 static void    call_timeout(struct rpc_task *task);
 static void    call_connect(struct rpc_task *task);
 static void    call_connect_status(struct rpc_task *task);
-static u32 *   call_header(struct rpc_task *task);
-static u32 *   call_verify(struct rpc_task *task);
+static __be32 *        call_header(struct rpc_task *task);
+static __be32 *        call_verify(struct rpc_task *task);
 
 
 static int
@@ -161,10 +161,10 @@ static struct rpc_clnt * rpc_new_client(struct rpc_xprt *xprt, char *servname, s
        }
 
        /* save the nodename */
-       clnt->cl_nodelen = strlen(system_utsname.nodename);
+       clnt->cl_nodelen = strlen(utsname()->nodename);
        if (clnt->cl_nodelen > UNX_MAXNODENAME)
                clnt->cl_nodelen = UNX_MAXNODENAME;
-       memcpy(clnt->cl_nodename, system_utsname.nodename, clnt->cl_nodelen);
+       memcpy(clnt->cl_nodename, utsname()->nodename, clnt->cl_nodelen);
        return clnt;
 
 out_no_auth:
@@ -177,7 +177,7 @@ out_no_path:
                kfree(clnt->cl_server);
        kfree(clnt);
 out_err:
-       xprt_destroy(xprt);
+       xprt_put(xprt);
 out_no_xprt:
        return ERR_PTR(err);
 }
@@ -253,14 +253,14 @@ rpc_clone_client(struct rpc_clnt *clnt)
 {
        struct rpc_clnt *new;
 
-       new = kmalloc(sizeof(*new), GFP_KERNEL);
+       new = kmemdup(clnt, sizeof(*new), GFP_KERNEL);
        if (!new)
                goto out_no_clnt;
-       memcpy(new, clnt, sizeof(*new));
        atomic_set(&new->cl_count, 1);
        atomic_set(&new->cl_users, 0);
        new->cl_parent = clnt;
        atomic_inc(&clnt->cl_count);
+       new->cl_xprt = xprt_get(clnt->cl_xprt);
        /* Turn off autobind on clones */
        new->cl_autobind = 0;
        new->cl_oneshot = 0;
@@ -337,15 +337,12 @@ rpc_destroy_client(struct rpc_clnt *clnt)
                rpc_rmdir(clnt->cl_dentry);
                rpc_put_mount();
        }
-       if (clnt->cl_xprt) {
-               xprt_destroy(clnt->cl_xprt);
-               clnt->cl_xprt = NULL;
-       }
        if (clnt->cl_server != clnt->cl_inline_name)
                kfree(clnt->cl_server);
 out_free:
        rpc_free_iostats(clnt->cl_metrics);
        clnt->cl_metrics = NULL;
+       xprt_put(clnt->cl_xprt);
        kfree(clnt);
        return 0;
 }
@@ -469,10 +466,9 @@ int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
 
        BUG_ON(flags & RPC_TASK_ASYNC);
 
-       status = -ENOMEM;
        task = rpc_new_task(clnt, flags, &rpc_default_ops, NULL);
        if (task == NULL)
-               goto out;
+               return -ENOMEM;
 
        /* Mask signals on RPC calls _and_ GSS_AUTH upcalls */
        rpc_task_sigmask(task, &oldset);
@@ -481,15 +477,17 @@ int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
 
        /* Set up the call info struct and execute the task */
        status = task->tk_status;
-       if (status == 0) {
-               atomic_inc(&task->tk_count);
-               status = rpc_execute(task);
-               if (status == 0)
-                       status = task->tk_status;
+       if (status != 0) {
+               rpc_release_task(task);
+               goto out;
        }
-       rpc_restore_sigmask(&oldset);
-       rpc_release_task(task);
+       atomic_inc(&task->tk_count);
+       status = rpc_execute(task);
+       if (status == 0)
+               status = task->tk_status;
+       rpc_put_task(task);
 out:
+       rpc_restore_sigmask(&oldset);
        return status;
 }
 
@@ -784,7 +782,7 @@ call_encode(struct rpc_task *task)
        struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
        unsigned int    bufsiz;
        kxdrproc_t      encode;
-       u32             *p;
+       __be32          *p;
 
        dprintk("RPC: %4d call_encode (status %d)\n", 
                                task->tk_pid, task->tk_status);
@@ -863,15 +861,11 @@ call_bind_status(struct rpc_task *task)
                dprintk("RPC: %4d remote rpcbind: RPC program/version unavailable\n",
                                task->tk_pid);
                rpc_delay(task, 3*HZ);
-               goto retry_bind;
+               goto retry_timeout;
        case -ETIMEDOUT:
                dprintk("RPC: %4d rpcbind request timed out\n",
                                task->tk_pid);
-               if (RPC_IS_SOFT(task)) {
-                       status = -EIO;
-                       break;
-               }
-               goto retry_bind;
+               goto retry_timeout;
        case -EPFNOSUPPORT:
                dprintk("RPC: %4d remote rpcbind service unavailable\n",
                                task->tk_pid);
@@ -884,16 +878,13 @@ call_bind_status(struct rpc_task *task)
                dprintk("RPC: %4d unrecognized rpcbind error (%d)\n",
                                task->tk_pid, -task->tk_status);
                status = -EIO;
-               break;
        }
 
        rpc_exit(task, status);
        return;
 
-retry_bind:
-       task->tk_status = 0;
-       task->tk_action = call_bind;
-       return;
+retry_timeout:
+       task->tk_action = call_timeout;
 }
 
 /*
@@ -941,14 +932,16 @@ call_connect_status(struct rpc_task *task)
 
        switch (status) {
        case -ENOTCONN:
-       case -ETIMEDOUT:
        case -EAGAIN:
                task->tk_action = call_bind;
-               break;
-       default:
-               rpc_exit(task, -EIO);
-               break;
+               if (!RPC_IS_SOFT(task))
+                       return;
+               /* if soft mounted, test if we've timed out */
+       case -ETIMEDOUT:
+               task->tk_action = call_timeout;
+               return;
        }
+       rpc_exit(task, -EIO);
 }
 
 /*
@@ -1057,7 +1050,6 @@ call_status(struct rpc_task *task)
                printk("%s: RPC call returned error %d\n",
                               clnt->cl_protname, -status);
                rpc_exit(task, status);
-               break;
        }
 }
 
@@ -1108,7 +1100,7 @@ call_decode(struct rpc_task *task)
        struct rpc_clnt *clnt = task->tk_client;
        struct rpc_rqst *req = task->tk_rqstp;
        kxdrproc_t      decode = task->tk_msg.rpc_proc->p_decode;
-       u32             *p;
+       __be32          *p;
 
        dprintk("RPC: %4d call_decode (status %d)\n", 
                                task->tk_pid, task->tk_status);
@@ -1125,10 +1117,10 @@ call_decode(struct rpc_task *task)
                        clnt->cl_stats->rpcretrans++;
                        goto out_retry;
                }
-               printk(KERN_WARNING "%s: too small RPC reply size (%d bytes)\n",
+               dprintk("%s: too small RPC reply size (%d bytes)\n",
                        clnt->cl_protname, task->tk_status);
-               rpc_exit(task, -EIO);
-               return;
+               task->tk_action = call_timeout;
+               goto out_retry;
        }
 
        /*
@@ -1205,12 +1197,12 @@ call_refreshresult(struct rpc_task *task)
 /*
  * Call header serialization
  */
-static u32 *
+static __be32 *
 call_header(struct rpc_task *task)
 {
        struct rpc_clnt *clnt = task->tk_client;
        struct rpc_rqst *req = task->tk_rqstp;
-       u32             *p = req->rq_svec[0].iov_base;
+       __be32          *p = req->rq_svec[0].iov_base;
 
        /* FIXME: check buffer size? */
 
@@ -1229,12 +1221,13 @@ call_header(struct rpc_task *task)
 /*
  * Reply header verification
  */
-static u32 *
+static __be32 *
 call_verify(struct rpc_task *task)
 {
        struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
        int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
-       u32     *p = iov->iov_base, n;
+       __be32  *p = iov->iov_base;
+       u32 n;
        int error = -EACCES;
 
        if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) {
@@ -1311,7 +1304,7 @@ call_verify(struct rpc_task *task)
                printk(KERN_WARNING "call_verify: auth check failed\n");
                goto out_garbage;               /* bad verifier, retry */
        }
-       len = p - (u32 *)iov->iov_base - 1;
+       len = p - (__be32 *)iov->iov_base - 1;
        if (len < 0)
                goto out_overflow;
        switch ((n = ntohl(*p++))) {
@@ -1366,12 +1359,12 @@ out_overflow:
        goto out_garbage;
 }
 
-static int rpcproc_encode_null(void *rqstp, u32 *data, void *obj)
+static int rpcproc_encode_null(void *rqstp, __be32 *data, void *obj)
 {
        return 0;
 }
 
-static int rpcproc_decode_null(void *rqstp, u32 *data, void *obj)
+static int rpcproc_decode_null(void *rqstp, __be32 *data, void *obj)
 {
        return 0;
 }