wl1251: fix a memory leak in probe
[safe/jmp/linux-2.6] / net / sunrpc / xprtsock.c
index bee4154..b7cd8cc 100644 (file)
@@ -81,46 +81,38 @@ static struct ctl_table_header *sunrpc_table_header;
  */
 static ctl_table xs_tunables_table[] = {
        {
-               .ctl_name       = CTL_SLOTTABLE_UDP,
                .procname       = "udp_slot_table_entries",
                .data           = &xprt_udp_slot_table_entries,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_minmax,
-               .strategy       = &sysctl_intvec,
+               .proc_handler   = proc_dointvec_minmax,
                .extra1         = &min_slot_table_size,
                .extra2         = &max_slot_table_size
        },
        {
-               .ctl_name       = CTL_SLOTTABLE_TCP,
                .procname       = "tcp_slot_table_entries",
                .data           = &xprt_tcp_slot_table_entries,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_minmax,
-               .strategy       = &sysctl_intvec,
+               .proc_handler   = proc_dointvec_minmax,
                .extra1         = &min_slot_table_size,
                .extra2         = &max_slot_table_size
        },
        {
-               .ctl_name       = CTL_MIN_RESVPORT,
                .procname       = "min_resvport",
                .data           = &xprt_min_resvport,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_minmax,
-               .strategy       = &sysctl_intvec,
+               .proc_handler   = proc_dointvec_minmax,
                .extra1         = &xprt_min_resvport_limit,
                .extra2         = &xprt_max_resvport_limit
        },
        {
-               .ctl_name       = CTL_MAX_RESVPORT,
                .procname       = "max_resvport",
                .data           = &xprt_max_resvport,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_minmax,
-               .strategy       = &sysctl_intvec,
+               .proc_handler   = proc_dointvec_minmax,
                .extra1         = &xprt_min_resvport_limit,
                .extra2         = &xprt_max_resvport_limit
        },
@@ -129,43 +121,23 @@ static ctl_table xs_tunables_table[] = {
                .data           = &xs_tcp_fin_timeout,
                .maxlen         = sizeof(xs_tcp_fin_timeout),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_jiffies,
-               .strategy       = sysctl_jiffies
-       },
-       {
-               .ctl_name = 0,
+               .proc_handler   = proc_dointvec_jiffies,
        },
+       { },
 };
 
 static ctl_table sunrpc_table[] = {
        {
-               .ctl_name       = CTL_SUNRPC,
                .procname       = "sunrpc",
                .mode           = 0555,
                .child          = xs_tunables_table
        },
-       {
-               .ctl_name = 0,
-       },
+       { },
 };
 
 #endif
 
 /*
- * Time out for an RPC UDP socket connect.  UDP socket connects are
- * synchronous, but we set a timeout anyway in case of resource
- * exhaustion on the local host.
- */
-#define XS_UDP_CONN_TO         (5U * HZ)
-
-/*
- * Wait duration for an RPC TCP connection to be established.  Solaris
- * NFS over TCP uses 60 seconds, for example, which is in line with how
- * long a server takes to reboot.
- */
-#define XS_TCP_CONN_TO         (60U * HZ)
-
-/*
  * Wait duration for a reply from the RPC portmapper.
  */
 #define XS_BIND_TO             (60U * HZ)
@@ -311,12 +283,11 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
        switch (sap->sa_family) {
        case AF_INET:
                sin = xs_addr_in(xprt);
-               (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
-                                       NIPQUAD(sin->sin_addr.s_addr));
+               snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
                break;
        case AF_INET6:
                sin6 = xs_addr_in6(xprt);
-               (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
+               snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
                break;
        default:
                BUG();
@@ -329,10 +300,10 @@ static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
        struct sockaddr *sap = xs_addr(xprt);
        char buf[128];
 
-       (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
+       snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
        xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
 
-       (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
+       snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
        xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
 }
 
@@ -557,14 +528,12 @@ static int xs_udp_send_request(struct rpc_task *task)
                        xdr->len - req->rq_bytes_sent, status);
 
        if (status >= 0) {
-               task->tk_bytes_sent += status;
+               req->rq_xmit_bytes_sent += status;
                if (status >= req->rq_slen)
                        return 0;
                /* Still some bytes left; set up for a retry later. */
                status = -EAGAIN;
        }
-       if (!transport->sock)
-               goto out;
 
        switch (status) {
        case -ENOTSOCK:
@@ -584,7 +553,7 @@ static int xs_udp_send_request(struct rpc_task *task)
                 * prompts ECONNREFUSED. */
                clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
        }
-out:
+
        return status;
 }
 
@@ -655,7 +624,7 @@ static int xs_tcp_send_request(struct rpc_task *task)
                /* If we've sent the entire packet, immediately
                 * reset the count of bytes sent. */
                req->rq_bytes_sent += status;
-               task->tk_bytes_sent += status;
+               req->rq_xmit_bytes_sent += status;
                if (likely(req->rq_bytes_sent >= req->rq_slen)) {
                        req->rq_bytes_sent = 0;
                        return 0;
@@ -666,8 +635,6 @@ static int xs_tcp_send_request(struct rpc_task *task)
                status = -EAGAIN;
                break;
        }
-       if (!transport->sock)
-               goto out;
 
        switch (status) {
        case -ENOTSOCK:
@@ -687,7 +654,7 @@ static int xs_tcp_send_request(struct rpc_task *task)
        case -ENOTCONN:
                clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
        }
-out:
+
        return status;
 }
 
@@ -773,6 +740,7 @@ static void xs_close(struct rpc_xprt *xprt)
        dprintk("RPC:       xs_close xprt %p\n", xprt);
 
        xs_reset_transport(transport);
+       xprt->reestablish_timeout = 0;
 
        smp_mb__before_clear_bit();
        clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
@@ -876,7 +844,6 @@ static void xs_udp_data_ready(struct sock *sk, int len)
        dst_confirm(skb_dst(skb));
 
        xprt_adjust_cwnd(task, copied);
-       xprt_update_rtt(task);
        xprt_complete_rqst(task, copied);
 
  out_unlock:
@@ -1068,8 +1035,6 @@ static inline void xs_tcp_read_common(struct rpc_xprt *xprt,
                if (transport->tcp_flags & TCP_RCV_LAST_FRAG)
                        transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
        }
-
-       return;
 }
 
 /*
@@ -1264,6 +1229,12 @@ static void xs_tcp_data_ready(struct sock *sk, int bytes)
        if (xprt->shutdown)
                goto out;
 
+       /* Any data means we had a useful conversation, so
+        * the we don't need to delay the next reconnect
+        */
+       if (xprt->reestablish_timeout)
+               xprt->reestablish_timeout = 0;
+
        /* We use rd_desc to pass struct xprt to xs_tcp_data_recv */
        rd_desc.arg.data = xprt;
        do {
@@ -1919,6 +1890,11 @@ static void xs_tcp_setup_socket(struct rpc_xprt *xprt,
        case -EALREADY:
                xprt_clear_connecting(xprt);
                return;
+       case -EINVAL:
+               /* Happens, for instance, if the user specified a link
+                * local IPv6 address without a scope-id.
+                */
+               goto out;
        }
 out_eagain:
        status = -EAGAIN;
@@ -2023,10 +1999,7 @@ static void xs_connect(struct rpc_task *task)
        struct rpc_xprt *xprt = task->tk_xprt;
        struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
 
-       if (xprt_test_and_set_connecting(xprt))
-               return;
-
-       if (transport->sock != NULL) {
+       if (transport->sock != NULL && !RPC_IS_SOFTCONN(task)) {
                dprintk("RPC:       xs_connect delayed xprt %p for %lu "
                                "seconds\n",
                                xprt, xprt->reestablish_timeout / HZ);
@@ -2034,6 +2007,8 @@ static void xs_connect(struct rpc_task *task)
                                   &transport->connect_worker,
                                   xprt->reestablish_timeout);
                xprt->reestablish_timeout <<= 1;
+               if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
+                       xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
                if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO)
                        xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO;
        } else {
@@ -2043,16 +2018,6 @@ static void xs_connect(struct rpc_task *task)
        }
 }
 
-static void xs_tcp_connect(struct rpc_task *task)
-{
-       struct rpc_xprt *xprt = task->tk_xprt;
-
-       /* Exit if we need to wait for socket shutdown to complete */
-       if (test_bit(XPRT_CLOSING, &xprt->state))
-               return;
-       xs_connect(task);
-}
-
 /**
  * xs_udp_print_stats - display UDP socket-specifc stats
  * @xprt: rpc_xprt struct containing statistics
@@ -2105,7 +2070,7 @@ static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
  * we allocate pages instead doing a kmalloc like rpc_malloc is because we want
  * to use the server side send routines.
  */
-void *bc_malloc(struct rpc_task *task, size_t size)
+static void *bc_malloc(struct rpc_task *task, size_t size)
 {
        struct page *page;
        struct rpc_buffer *buf;
@@ -2125,7 +2090,7 @@ void *bc_malloc(struct rpc_task *task, size_t size)
 /*
  * Free the space allocated in the bc_alloc routine
  */
-void bc_free(void *buffer)
+static void bc_free(void *buffer)
 {
        struct rpc_buffer *buf;
 
@@ -2215,7 +2180,6 @@ static int bc_send_request(struct rpc_task *task)
 
 static void bc_close(struct rpc_xprt *xprt)
 {
-       return;
 }
 
 /*
@@ -2225,7 +2189,6 @@ static void bc_close(struct rpc_xprt *xprt)
 
 static void bc_destroy(struct rpc_xprt *xprt)
 {
-       return;
 }
 
 static struct rpc_xprt_ops xs_udp_ops = {
@@ -2251,14 +2214,11 @@ static struct rpc_xprt_ops xs_tcp_ops = {
        .release_xprt           = xs_tcp_release_xprt,
        .rpcbind                = rpcb_getport_async,
        .set_port               = xs_set_port,
-       .connect                = xs_tcp_connect,
+       .connect                = xs_connect,
        .buf_alloc              = rpc_malloc,
        .buf_free               = rpc_free,
        .send_request           = xs_tcp_send_request,
        .set_retrans_timeout    = xprt_set_retrans_timeout_def,
-#if defined(CONFIG_NFS_V4_1)
-       .release_request        = bc_release_request,
-#endif /* CONFIG_NFS_V4_1 */
        .close                  = xs_tcp_close,
        .destroy                = xs_destroy,
        .print_stats            = xs_tcp_print_stats,
@@ -2345,7 +2305,6 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
        xprt->max_payload = (1U << 16) - (MAX_HEADER << 3);
 
        xprt->bind_timeout = XS_BIND_TO;
-       xprt->connect_timeout = XS_UDP_CONN_TO;
        xprt->reestablish_timeout = XS_UDP_REEST_TO;
        xprt->idle_timeout = XS_IDLE_DISC_TO;
 
@@ -2420,7 +2379,6 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
        xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
 
        xprt->bind_timeout = XS_BIND_TO;
-       xprt->connect_timeout = XS_TCP_CONN_TO;
        xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
        xprt->idle_timeout = XS_IDLE_DISC_TO;
 
@@ -2480,9 +2438,6 @@ static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
        struct sock_xprt *transport;
        struct svc_sock *bc_sock;
 
-       if (!args->bc_xprt)
-               ERR_PTR(-EINVAL);
-
        xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries);
        if (IS_ERR(xprt))
                return xprt;
@@ -2496,7 +2451,6 @@ static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
        /* backchannel */
        xprt_set_bound(xprt);
        xprt->bind_timeout = 0;
-       xprt->connect_timeout = 0;
        xprt->reestablish_timeout = 0;
        xprt->idle_timeout = 0;