SUNRPC: fewer conditionals in the format_ip_address routines
authorChuck Lever <chuck.lever@oracle.com>
Mon, 7 Jan 2008 23:34:48 +0000 (18:34 -0500)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 30 Jan 2008 07:06:04 +0000 (02:06 -0500)
Clean up: have the set up routines explicitly pass the strings to be used
for the transport name and NETID.  This removes a number of conditionals
and dependencies on rpc_xprt.prot, which is overloaded.

Tighten up type checking on the address_strings array while we're at it.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
include/linux/sunrpc/clnt.h
include/linux/sunrpc/xprt.h
net/sunrpc/clnt.c
net/sunrpc/rpcb_clnt.c
net/sunrpc/xprtsock.c

index 51a338189a2397a7ce12a993f0973e47065f8809..5a13da2573b054ac47e5acc231477818d3fdc05f 100644 (file)
@@ -143,7 +143,7 @@ void                rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
 size_t         rpc_max_payload(struct rpc_clnt *);
 void           rpc_force_rebind(struct rpc_clnt *);
 size_t         rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
-char *         rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
+const char     *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SUNRPC_CLNT_H */
index c3364d88d83ed29c145442139efc4f6e55bd49e9..b3ff9a815e6fe5cf8627335ea9c65f4105115b33 100644 (file)
@@ -183,7 +183,7 @@ struct rpc_xprt {
                                        bklog_u;        /* backlog queue utilization */
        } stat;
 
-       char *                  address_strings[RPC_DISPLAY_MAX];
+       const char              *address_strings[RPC_DISPLAY_MAX];
 };
 
 struct xprt_create {
index a3c00da9ce2156ab57f1134c2d8f93cdb7caeb17..e775ca793249a406ff3a7b2ca7c9642fd1fdd6cd 100644 (file)
@@ -679,7 +679,8 @@ EXPORT_SYMBOL_GPL(rpc_peeraddr);
  * @format: address format
  *
  */
-char *rpc_peeraddr2str(struct rpc_clnt *clnt, enum rpc_display_format_t format)
+const char *rpc_peeraddr2str(struct rpc_clnt *clnt,
+                            enum rpc_display_format_t format)
 {
        struct rpc_xprt *xprt = clnt->cl_xprt;
 
index f494e58910ec0df5d0ea3be1bfbc59437a3230a0..b60fa92321a56122a96c3dfbc54ed1de64351e6b 100644 (file)
@@ -358,7 +358,7 @@ void rpcb_getport_async(struct rpc_task *task)
        map->r_prot = xprt->prot;
        map->r_port = 0;
        map->r_xprt = xprt_get(xprt);
-       map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
+       map->r_netid = (char *)rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
        memcpy(map->r_addr,
               rpc_peeraddr2str(rpcb_clnt, RPC_DISPLAY_UNIVERSAL_ADDR),
               sizeof(map->r_addr));
index 6ba329d339a28f615d7403101334244e9c865cc3..b9b94f49c62029be52e5736365ddfa6544ebe8e4 100644 (file)
@@ -280,7 +280,9 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
        return (struct sockaddr_in6 *) &xprt->addr;
 }
 
-static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt)
+static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt,
+                                         const char *protocol,
+                                         const char *netid)
 {
        struct sockaddr_in *addr = xs_addr_in(xprt);
        char *buf;
@@ -299,21 +301,14 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt)
        }
        xprt->address_strings[RPC_DISPLAY_PORT] = buf;
 
-       buf = kzalloc(8, GFP_KERNEL);
-       if (buf) {
-               if (xprt->prot == IPPROTO_UDP)
-                       snprintf(buf, 8, "udp");
-               else
-                       snprintf(buf, 8, "tcp");
-       }
-       xprt->address_strings[RPC_DISPLAY_PROTO] = buf;
+       xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
 
        buf = kzalloc(48, GFP_KERNEL);
        if (buf) {
                snprintf(buf, 48, "addr="NIPQUAD_FMT" port=%u proto=%s",
                        NIPQUAD(addr->sin_addr.s_addr),
                        ntohs(addr->sin_port),
-                       xprt->prot == IPPROTO_UDP ? "udp" : "tcp");
+                       protocol);
        }
        xprt->address_strings[RPC_DISPLAY_ALL] = buf;
 
@@ -340,12 +335,12 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt)
        }
        xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf;
 
-       xprt->address_strings[RPC_DISPLAY_NETID] =
-               kstrdup(xprt->prot == IPPROTO_UDP ?
-                       RPCBIND_NETID_UDP : RPCBIND_NETID_TCP, GFP_KERNEL);
+       xprt->address_strings[RPC_DISPLAY_NETID] = netid;
 }
 
-static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt)
+static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt,
+                                         const char *protocol,
+                                         const char *netid)
 {
        struct sockaddr_in6 *addr = xs_addr_in6(xprt);
        char *buf;
@@ -364,21 +359,14 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt)
        }
        xprt->address_strings[RPC_DISPLAY_PORT] = buf;
 
-       buf = kzalloc(8, GFP_KERNEL);
-       if (buf) {
-               if (xprt->prot == IPPROTO_UDP)
-                       snprintf(buf, 8, "udp");
-               else
-                       snprintf(buf, 8, "tcp");
-       }
-       xprt->address_strings[RPC_DISPLAY_PROTO] = buf;
+       xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
 
        buf = kzalloc(64, GFP_KERNEL);
        if (buf) {
                snprintf(buf, 64, "addr="NIP6_FMT" port=%u proto=%s",
                                NIP6(addr->sin6_addr),
                                ntohs(addr->sin6_port),
-                               xprt->prot == IPPROTO_UDP ? "udp" : "tcp");
+                               protocol);
        }
        xprt->address_strings[RPC_DISPLAY_ALL] = buf;
 
@@ -405,17 +393,17 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt)
        }
        xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf;
 
-       xprt->address_strings[RPC_DISPLAY_NETID] =
-               kstrdup(xprt->prot == IPPROTO_UDP ?
-                       RPCBIND_NETID_UDP6 : RPCBIND_NETID_TCP6, GFP_KERNEL);
+       xprt->address_strings[RPC_DISPLAY_NETID] = netid;
 }
 
 static void xs_free_peer_addresses(struct rpc_xprt *xprt)
 {
-       int i;
-
-       for (i = 0; i < RPC_DISPLAY_MAX; i++)
-               kfree(xprt->address_strings[i]);
+       kfree(xprt->address_strings[RPC_DISPLAY_ADDR]);
+       kfree(xprt->address_strings[RPC_DISPLAY_PORT]);
+       kfree(xprt->address_strings[RPC_DISPLAY_ALL]);
+       kfree(xprt->address_strings[RPC_DISPLAY_HEX_ADDR]);
+       kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]);
+       kfree(xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR]);
 }
 
 #define XS_SENDMSG_FLAGS       (MSG_DONTWAIT | MSG_NOSIGNAL)
@@ -1939,7 +1927,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
 
                INIT_DELAYED_WORK(&transport->connect_worker,
                                        xs_udp_connect_worker4);
-               xs_format_ipv4_peer_addresses(xprt);
+               xs_format_ipv4_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP);
                break;
        case AF_INET6:
                if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
@@ -1947,7 +1935,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
 
                INIT_DELAYED_WORK(&transport->connect_worker,
                                        xs_udp_connect_worker6);
-               xs_format_ipv6_peer_addresses(xprt);
+               xs_format_ipv6_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6);
                break;
        default:
                kfree(xprt);
@@ -2005,14 +1993,14 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
                        xprt_set_bound(xprt);
 
                INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker4);
-               xs_format_ipv4_peer_addresses(xprt);
+               xs_format_ipv4_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP);
                break;
        case AF_INET6:
                if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
                        xprt_set_bound(xprt);
 
                INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker6);
-               xs_format_ipv6_peer_addresses(xprt);
+               xs_format_ipv6_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6);
                break;
        default:
                kfree(xprt);