Whamcloud - gitweb
LU-10391 socklnd: convert ksocknal_add_peer to take sockaddr 08/38408/7
authorMr NeilBrown <neilb@suse.de>
Tue, 28 Jan 2020 01:15:13 +0000 (12:15 +1100)
committerOleg Drokin <green@whamcloud.com>
Tue, 16 Mar 2021 18:16:30 +0000 (18:16 +0000)
ksocknal_add_peer() now takes a 'struct sockaddr' which is currently
always an IPv4 address.  ksocknal_lauch_packet() is the main place
where the nid is converted to an IP address.

Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I194248662798542096e5cc9af985e6c0063a038a
Reviewed-on: https://review.whamcloud.com/38408
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Aurelien Degremont <degremoa@amazon.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/klnds/socklnd/socklnd.c
lnet/klnds/socklnd/socklnd.h
lnet/klnds/socklnd/socklnd_cb.c

index c7f9184..4d3b7a4 100644 (file)
@@ -512,36 +512,33 @@ ksocknal_del_route_locked(struct ksock_route *route)
 }
 
 int
-ksocknal_add_peer(struct lnet_ni *ni, struct lnet_process_id id, __u32 ipaddr,
-                 int port)
+ksocknal_add_peer(struct lnet_ni *ni, struct lnet_process_id id,
+                 struct sockaddr *addr)
 {
        struct list_head *tmp;
        struct ksock_peer_ni *peer_ni;
        struct ksock_peer_ni *peer2;
        struct ksock_route *route;
        struct ksock_route *route2;
-       struct sockaddr_in sa = {.sin_family = AF_INET};
 
-        if (id.nid == LNET_NID_ANY ||
-            id.pid == LNET_PID_ANY)
-                return (-EINVAL);
+       if (id.nid == LNET_NID_ANY ||
+           id.pid == LNET_PID_ANY)
+               return (-EINVAL);
 
        /* Have a brand new peer_ni ready... */
        peer_ni = ksocknal_create_peer(ni, id);
        if (IS_ERR(peer_ni))
                return PTR_ERR(peer_ni);
 
-       sa.sin_addr.s_addr = htonl(ipaddr);
-       sa.sin_port = htons(port);
-       route = ksocknal_create_route((struct sockaddr *)&sa);
-        if (route == NULL) {
-                ksocknal_peer_decref(peer_ni);
-                return (-ENOMEM);
-        }
+       route = ksocknal_create_route(addr);
+       if (route == NULL) {
+               ksocknal_peer_decref(peer_ni);
+               return (-ENOMEM);
+       }
 
        write_lock_bh(&ksocknal_data.ksnd_global_lock);
 
-        /* always called with a ref on ni, so shutdown can't have started */
+       /* always called with a ref on ni, so shutdown can't have started */
        LASSERT(atomic_read(&((struct ksock_net *)ni->ni_data)->ksnn_npeers)
                >= 0);
 
@@ -558,9 +555,7 @@ ksocknal_add_peer(struct lnet_ni *ni, struct lnet_process_id id, __u32 ipaddr,
        list_for_each(tmp, &peer_ni->ksnp_routes) {
                route2 = list_entry(tmp, struct ksock_route, ksnr_list);
 
-               if (route2->ksnr_addr.ss_family == AF_INET &&
-                   ((struct sockaddr_in *)&route2->ksnr_addr)->sin_addr.s_addr
-                   == htonl(ipaddr))
+               if (rpc_cmp_addr(addr, (struct sockaddr *)&route2->ksnr_addr))
                        break;
 
                route2 = NULL;
@@ -934,7 +929,7 @@ static void
 ksocknal_create_routes(struct ksock_peer_ni *peer_ni, int port,
                        __u32 *peer_ipaddrs, int npeer_ipaddrs)
 {
-       struct ksock_route              *newroute = NULL;
+       struct ksock_route      *newroute = NULL;
        rwlock_t                *global_lock = &ksocknal_data.ksnd_global_lock;
        struct lnet_ni *ni = peer_ni->ksnp_ni;
        struct ksock_net                *net = ni->ni_data;
@@ -2223,13 +2218,15 @@ ksocknal_ctl(struct lnet_ni *ni, unsigned int cmd, void *arg)
                 return 0;
         }
 
-        case IOC_LIBCFS_ADD_PEER:
-                id.nid = data->ioc_nid;
-               id.pid = LNET_PID_LUSTRE;
-                return ksocknal_add_peer (ni, id,
-                                          data->ioc_u32[0], /* IP */
-                                          data->ioc_u32[1]); /* port */
+       case IOC_LIBCFS_ADD_PEER: {
+               struct sockaddr_in sa = {.sin_family = AF_INET};
 
+               id.nid = data->ioc_nid;
+               id.pid = LNET_PID_LUSTRE;
+               sa.sin_addr.s_addr = htonl(data->ioc_u32[0]);
+               sa.sin_port = htons(data->ioc_u32[1]);
+               return ksocknal_add_peer(ni, id, (struct sockaddr *)&sa);
+       }
         case IOC_LIBCFS_DEL_PEER:
                 id.nid = data->ioc_nid;
                 id.pid = LNET_PID_ANY;
index caf95bf..9e9aafa 100644 (file)
@@ -575,8 +575,8 @@ int ksocknal_recv(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg,
                   unsigned int offset, unsigned int mlen, unsigned int rlen);
 int ksocknal_accept(struct lnet_ni *ni, struct socket *sock);
 
-int ksocknal_add_peer(struct lnet_ni *ni, struct lnet_process_id id, __u32 ip,
-                     int port);
+int ksocknal_add_peer(struct lnet_ni *ni, struct lnet_process_id id,
+                     struct sockaddr *addr);
 struct ksock_peer_ni *ksocknal_find_peer_locked(struct lnet_ni *ni,
                                           struct lnet_process_id id);
 struct ksock_peer_ni *ksocknal_find_peer(struct lnet_ni *ni,
index 72bf35f..5bcd91a 100644 (file)
@@ -887,6 +887,7 @@ ksocknal_launch_packet(struct lnet_ni *ni, struct ksock_tx *tx,
 {
        struct ksock_peer_ni *peer_ni;
        struct ksock_conn *conn;
+       struct sockaddr_in sa;
        rwlock_t *g_lock;
        int retry;
        int rc;
@@ -934,9 +935,11 @@ ksocknal_launch_packet(struct lnet_ni *ni, struct ksock_tx *tx,
                         return -EHOSTUNREACH;
                 }
 
-                rc = ksocknal_add_peer(ni, id,
-                                       LNET_NIDADDR(id.nid),
-                                       lnet_acceptor_port());
+               memset(&sa, 0, sizeof(sa));
+               sa.sin_family = AF_INET;
+               sa.sin_addr.s_addr = htonl(LNET_NIDADDR(id.nid));
+               sa.sin_port = htons(lnet_acceptor_port());
+               rc = ksocknal_add_peer(ni, id, (struct sockaddr *)&sa);
                 if (rc != 0) {
                         CERROR("Can't add peer_ni %s: %d\n",
                                libcfs_id2str(id), rc);