Whamcloud - gitweb
LU-6245 libcfs: remove tcpip abstraction from libcfs 60/13760/19
authorJames Simmons <uja.ornl@gmail.com>
Fri, 13 Mar 2015 17:11:19 +0000 (13:11 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 25 Mar 2015 14:37:05 +0000 (14:37 +0000)
Since libcfs no longer builds for user land we can
move the tcpip abstraction that exist to the LNET
layer which is the only place that uses it. Also
the migrated code will use native linux kernel
apis directly instead of with wrappers.

Change-Id: Iaa39e4f581f18cfe586feb5bfbf4233a2f2335c7
Signed-off-by: James Simmons <uja.ornl@gmail.com>
Reviewed-on: http://review.whamcloud.com/13760
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Isaac Huang <he.huang@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
28 files changed:
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/linux/Makefile.am
libcfs/include/libcfs/linux/libcfs.h
libcfs/include/libcfs/linux/linux-tcpip.h [deleted file]
libcfs/include/libcfs/user-tcpip.h [deleted file]
libcfs/libcfs/Makefile.in
libcfs/libcfs/hash.c
libcfs/libcfs/linux/Makefile.am
libcfs/libcfs/linux/linux-tcpip.c [deleted file]
lnet/include/lnet/lib-lnet.h
lnet/include/lnet/lib-types.h
lnet/klnds/gnilnd/gnilnd_aries.h
lnet/klnds/o2iblnd/o2iblnd.c
lnet/klnds/o2iblnd/o2iblnd_cb.c
lnet/klnds/socklnd/socklnd.c
lnet/klnds/socklnd/socklnd.h
lnet/klnds/socklnd/socklnd_cb.c
lnet/klnds/socklnd/socklnd_lib.c
lnet/klnds/socklnd/socklnd_proto.c
lnet/lnet/Makefile.in
lnet/lnet/acceptor.c
lnet/lnet/autoMakefile.am
lnet/lnet/config.c
lnet/lnet/lib-socket.c [new file with mode: 0644]
lustre/include/lprocfs_status.h
lustre/llite/llite_internal.h
lustre/ptlrpc/gss/gss_svc_upcall.c

index 11bc80c..d5b179b 100644 (file)
@@ -35,5 +35,4 @@ EXTRA_DIST = \
        user-lock.h \
        user-mem.h \
        user-prim.h \
-       user-tcpip.h \
        user-time.h
index f18f447..39511fe 100644 (file)
@@ -66,7 +66,6 @@
 # include <libcfs/user-prim.h>
 # include <libcfs/user-mem.h>
 # include <libcfs/user-lock.h>
-# include <libcfs/user-tcpip.h>
 # include <libcfs/user-bitops.h>
 #endif /* __KERNEL__ */
 
@@ -138,23 +137,6 @@ static inline int __is_po2(unsigned long long val)
 #  error cfs_for_each_possible_cpu is not supported by kernel!
 #endif
 
-/* libcfs tcpip */
-int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask);
-int libcfs_ipif_enumerate(char ***names);
-void libcfs_ipif_free_enumeration(char **names, int n);
-int libcfs_sock_listen(cfs_socket_t **sockp, __u32 ip, int port, int backlog);
-int libcfs_sock_accept(cfs_socket_t **newsockp, cfs_socket_t *sock);
-void libcfs_sock_abort_accept(cfs_socket_t *sock);
-int libcfs_sock_connect(cfs_socket_t **sockp, int *fatal,
-                        __u32 local_ip, int local_port,
-                        __u32 peer_ip, int peer_port);
-int libcfs_sock_setbuf(cfs_socket_t *socket, int txbufsize, int rxbufsize);
-int libcfs_sock_getbuf(cfs_socket_t *socket, int *txbufsize, int *rxbufsize);
-int libcfs_sock_getaddr(cfs_socket_t *socket, int remote, __u32 *ip, int *port);
-int libcfs_sock_write(cfs_socket_t *sock, void *buffer, int nob, int timeout);
-int libcfs_sock_read(cfs_socket_t *sock, void *buffer, int nob, int timeout);
-void libcfs_sock_release(cfs_socket_t *sock);
-
 /* libcfs watchdogs */
 struct lc_watchdog;
 
index acfb486..240288c 100644 (file)
@@ -1,3 +1,2 @@
 EXTRA_DIST = kp30.h libcfs.h linux-fs.h linux-lock.h linux-mem.h       \
-       linux-prim.h linux-time.h linux-tcpip.h linux-cpu.h             \
-       linux-crypto.h
+       linux-prim.h linux-time.h linux-cpu.h linux-crypto.h
index 8cbe71f..6afd5db 100644 (file)
@@ -53,7 +53,6 @@
 #include <libcfs/linux/linux-prim.h>
 #include <libcfs/linux/linux-lock.h>
 #include <libcfs/linux/linux-fs.h>
-#include <libcfs/linux/linux-tcpip.h>
 #include <libcfs/linux/kp30.h>
 
 #ifdef HAVE_ASM_TYPES_H
diff --git a/libcfs/include/libcfs/linux/linux-tcpip.h b/libcfs/include/libcfs/linux/linux-tcpip.h
deleted file mode 100644 (file)
index bec571a..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * libcfs/include/libcfs/linux/linux-tcpip.h
- *
- * Basic library routines.
- */
-
-#ifndef __LIBCFS_LINUX_CFS_TCP_H__
-#define __LIBCFS_LINUX_CFS_TCP_H__
-
-#ifndef __LIBCFS_LIBCFS_H__
-#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
-#endif
-
-#ifndef __KERNEL__
-#error This include is only for kernel use.
-#endif
-
-#include <net/sock.h>
-
-#ifndef HIPQUAD
-// XXX Should just kill all users
-#if defined(__LITTLE_ENDIAN)
-#define HIPQUAD(addr) \
-        ((unsigned char *)&addr)[3], \
-        ((unsigned char *)&addr)[2], \
-        ((unsigned char *)&addr)[1], \
-        ((unsigned char *)&addr)[0]
-#elif defined(__BIG_ENDIAN)
-#define HIPQUAD NIPQUAD
-#else
-#error "Please fix asm/byteorder.h"
-#endif /* __LITTLE_ENDIAN */
-#endif
-
-typedef struct socket   cfs_socket_t;
-
-#define SOCK_TEST_NOSPACE(so)   test_bit(SOCK_NOSPACE, &(so)->flags)
-
-static inline int
-libcfs_sock_error(struct socket *sock)
-{
-        return sock->sk->sk_err;
-}
-
-static inline int
-libcfs_sock_wmem_queued(struct socket *sock)
-{
-        return sock->sk->sk_wmem_queued;
-}
-#endif
diff --git a/libcfs/include/libcfs/user-tcpip.h b/libcfs/include/libcfs/user-tcpip.h
deleted file mode 100644 (file)
index 9812fb9..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#ifndef __LIBCFS_USER_TCPIP_H__
-#define __LIBCFS_USER_TCPIP_H__
-
-#ifndef __LIBCFS_LIBCFS_H__
-#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
-#endif
-
-#ifndef __KERNEL__
-
-#include <sys/uio.h>
-#include <endian.h>
-
-/*
- * Functions to get network interfaces info
- */
-
-int libcfs_sock_ioctl(int cmd, unsigned long arg);
-int libcfs_ipif_query (char *name, int *up, __u32 *ip);
-void libcfs_ipif_free_enumeration (char **names, int n);
-int libcfs_ipif_enumerate (char ***namesp);
-
-/*
- * Network function used by user-land lnet acceptor
- */
-
-typedef struct cfs_socket {
-        int s_fd;
-} cfs_socket_t;
-
-#define LIBCFS_SOCK2FD(sock) ((sock)->s_fd)
-
-int libcfs_sock_listen(cfs_socket_t **sockp, __u32 ip, int port, int backlog);
-int libcfs_sock_accept(cfs_socket_t **newsockp, cfs_socket_t *sock);
-int libcfs_sock_read(cfs_socket_t *sock, void *buffer, int nob, int timeout);
-int libcfs_sock_write(cfs_socket_t *sock, void *buffer, int nob, int timeout);
-void libcfs_sock_abort_accept(cfs_socket_t *sock);
-void libcfs_sock_release(cfs_socket_t *sock);
-int libcfs_sock_getaddr(cfs_socket_t *sock, int remote, __u32 *ip, int *port);
-
-/*
- * Network functions of common use
- */
-
-int libcfs_socketpair(cfs_socket_t **sockp);
-int libcfs_fcntl_nonblock(cfs_socket_t *sock);
-int libcfs_sock_set_nagle(cfs_socket_t *sock, int nagle);
-int libcfs_sock_set_bufsiz(cfs_socket_t *sock, int bufsiz);
-int libcfs_sock_connect(cfs_socket_t *sock, __u32 ip, __u16 port);
-int libcfs_sock_writev(cfs_socket_t *sock,
-                       const struct iovec *vector, int count);
-int libcfs_sock_readv(cfs_socket_t *sock,
-                      const struct iovec *vector, int count);
-int libcfs_sock_create(cfs_socket_t **sockp, int *fatal,
-                       __u32 local_ip, int local_port);
-
-
-/*
- * Macros for easy printing IP-adresses
- */
-
-#define NIPQUAD(addr) \
-        ((unsigned char *)&addr)[0], \
-        ((unsigned char *)&addr)[1], \
-        ((unsigned char *)&addr)[2], \
-        ((unsigned char *)&addr)[3]
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define HIPQUAD(addr)                \
-        ((unsigned char *)&addr)[3], \
-        ((unsigned char *)&addr)[2], \
-        ((unsigned char *)&addr)[1], \
-        ((unsigned char *)&addr)[0]
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define HIPQUAD NIPQUAD
-#else
-#error "Undefined byteorder??"
-#endif /* __LITTLE_ENDIAN */
-
-#endif /* !__KERNEL__ */
-
-#endif
index 246c773..bb9e551 100644 (file)
@@ -2,8 +2,7 @@ MODULES = libcfs
 
 libcfs-linux-objs := linux-tracefile.o linux-debug.o
 libcfs-linux-objs += linux-prim.o linux-mem.o linux-cpu.o
-libcfs-linux-objs += linux-fs.o linux-tcpip.o
-libcfs-linux-objs += linux-proc.o linux-curproc.o
+libcfs-linux-objs += linux-proc.o linux-curproc.o linux-fs.o
 libcfs-linux-objs += linux-utils.o linux-module.o
 libcfs-linux-objs += linux-crypto.o linux-crypto-adler.o
 @HAVE_CRC32_TRUE@libcfs-linux-objs += linux-crypto-crc32.o
index d76e31f..7684fd6 100644 (file)
  *   Now we support both locked iteration & lockless iteration of hash
  *   table. Also, user can break the iteration by return 1 in callback.
  */
+#include <linux/seq_file.h>
 
 #include <libcfs/libcfs.h>
 
index b355a30..fffb4b3 100644 (file)
@@ -1,6 +1,6 @@
 EXTRA_DIST = linux-debug.c linux-prim.c linux-tracefile.c      \
-       linux-fs.c linux-mem.c linux-proc.c linux-utils.c       \
-       linux-module.c linux-curproc.c linux-tcpip.c            \
-       linux-cpu.c linux-crypto.c linux-crypto-crc32.c linux-crypto-adler.c \
+       linux-fs.c linux-mem.c linux-proc.c linux-utils.c       \
+       linux-module.c linux-curproc.c linux-cpu.c              \
+       linux-crypto.c linux-crypto-crc32.c linux-crypto-adler.c\
        linux-crypto-crc32pclmul.c linux-crypto-crc32c-pclmul.c \
        crc32-pclmul_asm.S crc32c-pcl-intel-asm_64.S inst.h
diff --git a/libcfs/libcfs/linux/linux-tcpip.c b/libcfs/libcfs/linux/linux-tcpip.c
deleted file mode 100644 (file)
index 2ad912b..0000000
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, 2014, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-#define DEBUG_SUBSYSTEM S_LNET
-
-#include <libcfs/libcfs.h>
-#include <libcfs/libcfs.h>
-
-#include <linux/if.h>
-#include <linux/in.h>
-#include <linux/file.h>
-/* For sys_open & sys_close */
-#include <linux/syscalls.h>
-
-#ifndef HAVE_SK_SLEEP
-static inline wait_queue_head_t *sk_sleep(struct sock *sk)
-{
-       return sk->sk_sleep;
-}
-#endif
-
-static int
-libcfs_sock_ioctl(int cmd, unsigned long arg)
-{
-       mm_segment_t    oldmm = get_fs();
-       struct socket  *sock;
-       int             fd = -1;
-       int             rc;
-       struct file    *sock_filp;
-
-        rc = sock_create (PF_INET, SOCK_STREAM, 0, &sock);
-        if (rc != 0) {
-                CERROR ("Can't create socket: %d\n", rc);
-                return rc;
-        }
-
-#if !defined(HAVE_SOCK_ALLOC_FILE) && !defined(HAVE_SOCK_ALLOC_FILE_3ARGS)
-       fd = sock_map_fd(sock, 0);
-       if (fd < 0) {
-               rc = fd;
-               sock_release(sock);
-               goto out;
-       }
-       sock_filp = fget(fd);
-#else
-# ifdef HAVE_SOCK_ALLOC_FILE_3ARGS
-       sock_filp = sock_alloc_file(sock, 0, NULL);
-# else
-       sock_filp = sock_alloc_file(sock, 0);
-# endif
-#endif
-        if (!sock_filp) {
-                rc = -ENOMEM;
-               sock_release(sock);
-                goto out;
-        }
-
-       set_fs(KERNEL_DS);
-       if (sock_filp->f_op->unlocked_ioctl)
-               rc = sock_filp->f_op->unlocked_ioctl(sock_filp, cmd, arg);
-       set_fs(oldmm);
-
-        fput(sock_filp);
-
- out:
-       if (fd >= 0)
-               sys_close(fd);
-
-        return rc;
-}
-
-int
-libcfs_ipif_query (char *name, int *up, __u32 *ip, __u32 *mask)
-{
-        struct ifreq   ifr;
-        int            nob;
-        int            rc;
-        __u32          val;
-
-        nob = strnlen(name, IFNAMSIZ);
-        if (nob == IFNAMSIZ) {
-                CERROR("Interface name %s too long\n", name);
-                return -EINVAL;
-        }
-
-        CLASSERT (sizeof(ifr.ifr_name) >= IFNAMSIZ);
-
-       if (strlen(name) > sizeof(ifr.ifr_name)-1)
-               return -E2BIG;
-       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
-
-        rc = libcfs_sock_ioctl(SIOCGIFFLAGS, (unsigned long)&ifr);
-
-        if (rc != 0) {
-                CERROR("Can't get flags for interface %s\n", name);
-                return rc;
-        }
-
-        if ((ifr.ifr_flags & IFF_UP) == 0) {
-                CDEBUG(D_NET, "Interface %s down\n", name);
-                *up = 0;
-                *ip = *mask = 0;
-                return 0;
-        }
-
-        *up = 1;
-
-       if (strlen(name) > sizeof(ifr.ifr_name)-1)
-               return -E2BIG;
-       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
-
-        ifr.ifr_addr.sa_family = AF_INET;
-        rc = libcfs_sock_ioctl(SIOCGIFADDR, (unsigned long)&ifr);
-
-        if (rc != 0) {
-                CERROR("Can't get IP address for interface %s\n", name);
-                return rc;
-        }
-
-        val = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
-        *ip = ntohl(val);
-
-       if (strlen(name) > sizeof(ifr.ifr_name)-1)
-               return -E2BIG;
-       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
-
-        ifr.ifr_addr.sa_family = AF_INET;
-        rc = libcfs_sock_ioctl(SIOCGIFNETMASK, (unsigned long)&ifr);
-
-        if (rc != 0) {
-                CERROR("Can't get netmask for interface %s\n", name);
-                return rc;
-        }
-
-        val = ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr;
-        *mask = ntohl(val);
-
-        return 0;
-}
-
-EXPORT_SYMBOL(libcfs_ipif_query);
-
-int
-libcfs_ipif_enumerate (char ***namesp)
-{
-        /* Allocate and fill in 'names', returning # interfaces/error */
-        char           **names;
-        int             toobig;
-        int             nalloc;
-        int             nfound;
-        struct ifreq   *ifr;
-        struct ifconf   ifc;
-        int             rc;
-        int             nob;
-        int             i;
-
-
-        nalloc = 16;        /* first guess at max interfaces */
-        toobig = 0;
-        for (;;) {
-               if (nalloc * sizeof(*ifr) > PAGE_CACHE_SIZE) {
-                       toobig = 1;
-                       nalloc = PAGE_CACHE_SIZE/sizeof(*ifr);
-                       CWARN("Too many interfaces: only enumerating first %d\n",
-                             nalloc);
-               }
-
-                LIBCFS_ALLOC(ifr, nalloc * sizeof(*ifr));
-                if (ifr == NULL) {
-                        CERROR ("ENOMEM enumerating up to %d interfaces\n", nalloc);
-                        rc = -ENOMEM;
-                        goto out0;
-                }
-
-                ifc.ifc_buf = (char *)ifr;
-                ifc.ifc_len = nalloc * sizeof(*ifr);
-
-                rc = libcfs_sock_ioctl(SIOCGIFCONF, (unsigned long)&ifc);
-
-                if (rc < 0) {
-                        CERROR ("Error %d enumerating interfaces\n", rc);
-                        goto out1;
-                }
-
-                LASSERT (rc == 0);
-
-                nfound = ifc.ifc_len/sizeof(*ifr);
-                LASSERT (nfound <= nalloc);
-
-                if (nfound < nalloc || toobig)
-                        break;
-
-                LIBCFS_FREE(ifr, nalloc * sizeof(*ifr));
-                nalloc *= 2;
-        }
-
-        if (nfound == 0)
-                goto out1;
-
-        LIBCFS_ALLOC(names, nfound * sizeof(*names));
-        if (names == NULL) {
-                rc = -ENOMEM;
-                goto out1;
-        }
-
-        for (i = 0; i < nfound; i++) {
-
-                nob = strnlen (ifr[i].ifr_name, IFNAMSIZ);
-                if (nob == IFNAMSIZ) {
-                        /* no space for terminating NULL */
-                        CERROR("interface name %.*s too long (%d max)\n",
-                               nob, ifr[i].ifr_name, IFNAMSIZ);
-                        rc = -ENAMETOOLONG;
-                        goto out2;
-                }
-
-                LIBCFS_ALLOC(names[i], IFNAMSIZ);
-                if (names[i] == NULL) {
-                        rc = -ENOMEM;
-                        goto out2;
-                }
-
-                memcpy(names[i], ifr[i].ifr_name, nob);
-                names[i][nob] = 0;
-        }
-
-        *namesp = names;
-        rc = nfound;
-
- out2:
-        if (rc < 0)
-                libcfs_ipif_free_enumeration(names, nfound);
- out1:
-        LIBCFS_FREE(ifr, nalloc * sizeof(*ifr));
- out0:
-        return rc;
-}
-
-EXPORT_SYMBOL(libcfs_ipif_enumerate);
-
-void
-libcfs_ipif_free_enumeration (char **names, int n)
-{
-        int      i;
-
-        LASSERT (n > 0);
-
-        for (i = 0; i < n && names[i] != NULL; i++)
-                LIBCFS_FREE(names[i], IFNAMSIZ);
-
-        LIBCFS_FREE(names, n * sizeof(*names));
-}
-
-EXPORT_SYMBOL(libcfs_ipif_free_enumeration);
-
-int
-libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout)
-{
-       int             rc;
-       mm_segment_t    oldmm = get_fs();
-       long            jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
-       unsigned long   then;
-       struct timeval  tv;
-
-       LASSERT(nob > 0);
-       /* Caller may pass a zero timeout if she thinks the socket buffer is
-        * empty enough to take the whole message immediately */
-
-       for (;;) {
-               struct kvec  iov = {
-                       .iov_base = buffer,
-                       .iov_len  = nob
-               };
-               struct msghdr msg = {
-                       .msg_flags      = (timeout == 0) ? MSG_DONTWAIT : 0
-               };
-
-               if (timeout != 0) {
-                       /* Set send timeout to remaining time */
-                       tv = (struct timeval) {
-                               .tv_sec = jiffies_left /
-                                         msecs_to_jiffies(MSEC_PER_SEC),
-                               .tv_usec = ((jiffies_left %
-                                           msecs_to_jiffies(MSEC_PER_SEC)) *
-                                           USEC_PER_SEC) /
-                                           msecs_to_jiffies(MSEC_PER_SEC)
-                       };
-                        set_fs(KERNEL_DS);
-                        rc = sock_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
-                                             (char *)&tv, sizeof(tv));
-                        set_fs(oldmm);
-                        if (rc != 0) {
-                                CERROR("Can't set socket send timeout "
-                                       "%ld.%06d: %d\n",
-                                       (long)tv.tv_sec, (int)tv.tv_usec, rc);
-                                return rc;
-                        }
-                }
-
-               then = jiffies;
-               rc = kernel_sendmsg(sock, &msg, &iov, 1, nob);
-               jiffies_left -= jiffies - then;
-
-                if (rc == nob)
-                        return 0;
-
-                if (rc < 0)
-                        return rc;
-
-                if (rc == 0) {
-                        CERROR ("Unexpected zero rc\n");
-                        return (-ECONNABORTED);
-                }
-
-               if (jiffies_left <= 0)
-                        return -EAGAIN;
-
-                buffer = ((char *)buffer) + rc;
-                nob -= rc;
-        }
-
-        return (0);
-}
-EXPORT_SYMBOL(libcfs_sock_write);
-
-int
-libcfs_sock_read (struct socket *sock, void *buffer, int nob, int timeout)
-{
-       int             rc;
-       mm_segment_t    oldmm = get_fs();
-       long            jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
-       unsigned long   then;
-       struct timeval  tv;
-
-       LASSERT(nob > 0);
-       LASSERT(jiffies_left > 0);
-
-       for (;;) {
-               struct kvec  iov = {
-                       .iov_base = buffer,
-                       .iov_len  = nob
-               };
-               struct msghdr msg = {
-                       .msg_flags      = 0
-               };
-
-               /* Set receive timeout to remaining time */
-               tv = (struct timeval) {
-                       .tv_sec = jiffies_left / msecs_to_jiffies(MSEC_PER_SEC),
-                       .tv_usec = ((jiffies_left %
-                                   msecs_to_jiffies(MSEC_PER_SEC)) *
-                                   USEC_PER_SEC) /
-                                   msecs_to_jiffies(MSEC_PER_SEC)
-               };
-                set_fs(KERNEL_DS);
-                rc = sock_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
-                                     (char *)&tv, sizeof(tv));
-                set_fs(oldmm);
-                if (rc != 0) {
-                        CERROR("Can't set socket recv timeout %ld.%06d: %d\n",
-                               (long)tv.tv_sec, (int)tv.tv_usec, rc);
-                        return rc;
-                }
-
-               then = jiffies;
-               rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0);
-               jiffies_left -= jiffies - then;
-
-                if (rc < 0)
-                        return rc;
-
-                if (rc == 0)
-                        return -ECONNRESET;
-
-                buffer = ((char *)buffer) + rc;
-                nob -= rc;
-
-                if (nob == 0)
-                        return 0;
-
-               if (jiffies_left <= 0)
-                        return -ETIMEDOUT;
-        }
-}
-
-EXPORT_SYMBOL(libcfs_sock_read);
-
-static int
-libcfs_sock_create (struct socket **sockp, int *fatal,
-                    __u32 local_ip, int local_port)
-{
-        struct sockaddr_in  locaddr;
-        struct socket      *sock;
-        int                 rc;
-        int                 option;
-        mm_segment_t        oldmm = get_fs();
-
-        /* All errors are fatal except bind failure if the port is in use */
-        *fatal = 1;
-
-        rc = sock_create (PF_INET, SOCK_STREAM, 0, &sock);
-        *sockp = sock;
-        if (rc != 0) {
-                CERROR ("Can't create socket: %d\n", rc);
-                return (rc);
-        }
-
-        set_fs (KERNEL_DS);
-        option = 1;
-        rc = sock_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-                             (char *)&option, sizeof (option));
-        set_fs (oldmm);
-        if (rc != 0) {
-                CERROR("Can't set SO_REUSEADDR for socket: %d\n", rc);
-                goto failed;
-        }
-
-        if (local_ip != 0 || local_port != 0) {
-                memset(&locaddr, 0, sizeof(locaddr));
-                locaddr.sin_family = AF_INET;
-                locaddr.sin_port = htons(local_port);
-                locaddr.sin_addr.s_addr = (local_ip == 0) ?
-                                          INADDR_ANY : htonl(local_ip);
-
-                rc = sock->ops->bind(sock, (struct sockaddr *)&locaddr,
-                                     sizeof(locaddr));
-                if (rc == -EADDRINUSE) {
-                        CDEBUG(D_NET, "Port %d already in use\n", local_port);
-                        *fatal = 0;
-                        goto failed;
-                }
-                if (rc != 0) {
-                        CERROR("Error trying to bind to port %d: %d\n",
-                               local_port, rc);
-                        goto failed;
-                }
-        }
-
-        return 0;
-
- failed:
-        sock_release(sock);
-        return rc;
-}
-
-int
-libcfs_sock_setbuf (struct socket *sock, int txbufsize, int rxbufsize)
-{
-        mm_segment_t        oldmm = get_fs();
-        int                 option;
-        int                 rc;
-
-        if (txbufsize != 0) {
-                option = txbufsize;
-                set_fs (KERNEL_DS);
-                rc = sock_setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
-                                     (char *)&option, sizeof (option));
-                set_fs (oldmm);
-                if (rc != 0) {
-                        CERROR ("Can't set send buffer %d: %d\n",
-                                option, rc);
-                        return (rc);
-                }
-        }
-
-        if (rxbufsize != 0) {
-                option = rxbufsize;
-                set_fs (KERNEL_DS);
-                rc = sock_setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
-                                      (char *)&option, sizeof (option));
-                set_fs (oldmm);
-                if (rc != 0) {
-                        CERROR ("Can't set receive buffer %d: %d\n",
-                                option, rc);
-                        return (rc);
-                }
-        }
-
-        return 0;
-}
-
-EXPORT_SYMBOL(libcfs_sock_setbuf);
-
-int
-libcfs_sock_getaddr (struct socket *sock, int remote, __u32 *ip, int *port)
-{
-        struct sockaddr_in sin;
-        int                len = sizeof (sin);
-        int                rc;
-
-        rc = sock->ops->getname (sock, (struct sockaddr *)&sin, &len,
-                                 remote ? 2 : 0);
-        if (rc != 0) {
-                CERROR ("Error %d getting sock %s IP/port\n",
-                        rc, remote ? "peer" : "local");
-                return rc;
-        }
-
-        if (ip != NULL)
-                *ip = ntohl (sin.sin_addr.s_addr);
-
-        if (port != NULL)
-                *port = ntohs (sin.sin_port);
-
-        return 0;
-}
-
-EXPORT_SYMBOL(libcfs_sock_getaddr);
-
-int
-libcfs_sock_getbuf (struct socket *sock, int *txbufsize, int *rxbufsize)
-{
-
-        if (txbufsize != NULL) {
-                *txbufsize = sock->sk->sk_sndbuf;
-        }
-
-        if (rxbufsize != NULL) {
-                *rxbufsize = sock->sk->sk_rcvbuf;
-        }
-
-        return 0;
-}
-
-EXPORT_SYMBOL(libcfs_sock_getbuf);
-
-int
-libcfs_sock_listen (struct socket **sockp,
-                    __u32 local_ip, int local_port, int backlog)
-{
-        int      fatal;
-        int      rc;
-
-        rc = libcfs_sock_create(sockp, &fatal, local_ip, local_port);
-        if (rc != 0) {
-                if (!fatal)
-                        CERROR("Can't create socket: port %d already in use\n",
-                               local_port);
-                return rc;
-        }
-
-        rc = (*sockp)->ops->listen(*sockp, backlog);
-        if (rc == 0)
-                return 0;
-
-        CERROR("Can't set listen backlog %d: %d\n", backlog, rc);
-        sock_release(*sockp);
-        return rc;
-}
-
-EXPORT_SYMBOL(libcfs_sock_listen);
-
-int
-libcfs_sock_accept (struct socket **newsockp, struct socket *sock)
-{
-        wait_queue_t   wait;
-        struct socket *newsock;
-        int            rc;
-
-        init_waitqueue_entry(&wait, current);
-
-        /* XXX this should add a ref to sock->ops->owner, if
-         * TCP could be a module */
-        rc = sock_create_lite(PF_PACKET, sock->type, IPPROTO_TCP, &newsock);
-        if (rc) {
-                CERROR("Can't allocate socket\n");
-                return rc;
-        }
-
-        newsock->ops = sock->ops;
-
-       set_current_state(TASK_INTERRUPTIBLE);
-       add_wait_queue(sk_sleep(sock->sk), &wait);
-
-       rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
-       if (rc == -EAGAIN) {
-               /* Nothing ready, so wait for activity */
-               schedule();
-               rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
-       }
-
-       remove_wait_queue(sk_sleep(sock->sk), &wait);
-       set_current_state(TASK_RUNNING);
-
-        if (rc != 0)
-                goto failed;
-
-        *newsockp = newsock;
-        return 0;
-
- failed:
-        sock_release(newsock);
-        return rc;
-}
-
-EXPORT_SYMBOL(libcfs_sock_accept);
-
-void
-libcfs_sock_abort_accept (struct socket *sock)
-{
-       wake_up_all(sk_sleep(sock->sk));
-}
-
-EXPORT_SYMBOL(libcfs_sock_abort_accept);
-
-int
-libcfs_sock_connect (struct socket **sockp, int *fatal,
-                     __u32 local_ip, int local_port,
-                     __u32 peer_ip, int peer_port)
-{
-        struct sockaddr_in  srvaddr;
-        int                 rc;
-
-        rc = libcfs_sock_create(sockp, fatal, local_ip, local_port);
-        if (rc != 0)
-                return rc;
-
-        memset (&srvaddr, 0, sizeof (srvaddr));
-        srvaddr.sin_family = AF_INET;
-        srvaddr.sin_port = htons(peer_port);
-        srvaddr.sin_addr.s_addr = htonl(peer_ip);
-
-        rc = (*sockp)->ops->connect(*sockp,
-                                    (struct sockaddr *)&srvaddr, sizeof(srvaddr),
-                                    0);
-        if (rc == 0)
-                return 0;
-
-        /* EADDRNOTAVAIL probably means we're already connected to the same
-         * peer/port on the same local port on a differently typed
-         * connection.  Let our caller retry with a different local
-         * port... */
-        *fatal = !(rc == -EADDRNOTAVAIL);
-
-        CDEBUG_LIMIT(*fatal ? D_NETERROR : D_NET,
-               "Error %d connecting %u.%u.%u.%u/%d -> %u.%u.%u.%u/%d\n", rc,
-               HIPQUAD(local_ip), local_port, HIPQUAD(peer_ip), peer_port);
-
-        sock_release(*sockp);
-        return rc;
-}
-
-EXPORT_SYMBOL(libcfs_sock_connect);
-
-void
-libcfs_sock_release (struct socket *sock)
-{
-        sock_release(sock);
-}
-
-EXPORT_SYMBOL(libcfs_sock_release);
index db29f2d..4fe3a86 100644 (file)
@@ -694,7 +694,7 @@ void lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd);
 void lnet_register_lnd(lnd_t *lnd);
 void lnet_unregister_lnd(lnd_t *lnd);
 
-int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
+int lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
                  __u32 local_ip, __u32 peer_ip, int peer_port);
 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
                                 __u32 peer_ip, int port);
@@ -704,6 +704,28 @@ int lnet_acceptor_port(void);
 int lnet_acceptor_start(void);
 void lnet_acceptor_stop(void);
 
+#ifndef HAVE_SK_SLEEP
+static inline wait_queue_head_t *sk_sleep(struct sock *sk)
+{
+       return sk->sk_sleep;
+}
+#endif
+
+int lnet_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask);
+int lnet_ipif_enumerate(char ***names);
+void lnet_ipif_free_enumeration(char **names, int n);
+int lnet_sock_setbuf(struct socket *socket, int txbufsize, int rxbufsize);
+int lnet_sock_getbuf(struct socket *socket, int *txbufsize, int *rxbufsize);
+int lnet_sock_getaddr(struct socket *socket, bool remote, __u32 *ip, int *port);
+int lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout);
+int lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout);
+
+int lnet_sock_listen(struct socket **sockp, __u32 ip, int port, int backlog);
+int lnet_sock_accept(struct socket **newsockp, struct socket *sock);
+int lnet_sock_connect(struct socket **sockp, int *fatal,
+                       __u32 local_ip, int local_port,
+                       __u32 peer_ip, int peer_port);
+
 int lnet_peers_start_down(void);
 int lnet_peer_buffer_credits(lnet_ni_t *ni);
 
index 093a8c9..884d473 100644 (file)
@@ -45,6 +45,7 @@
 #ifdef __KERNEL__
 # include <linux/uio.h>
 # include <linux/types.h>
+# include <net/sock.h>
 #else /* !__KERNEL__ */
 # include <sys/types.h>
 #endif /* __KERNEL__ */
@@ -303,6 +304,7 @@ typedef struct {
 #define LNET_COOKIE_MASK       ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
 
 struct lnet_ni;                                  /* forward ref */
+struct socket;
 
 typedef struct lnet_lnd
 {
@@ -361,7 +363,7 @@ typedef struct lnet_lnd
         void (*lnd_query)(struct lnet_ni *ni, lnet_nid_t peer, cfs_time_t *when);
 
         /* accept a new connection */
-        int (*lnd_accept)(struct lnet_ni *ni, cfs_socket_t *sock);
+       int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
 } lnd_t;
 
 #define LNET_NI_STATUS_UP      0x15aac0de
index 81a58ff..72ca834 100644 (file)
@@ -24,8 +24,8 @@
 #ifndef _GNILND_ARIES_H
 #define _GNILND_ARIES_H
 
-/* for libcfs_ipif_query */
-#include <libcfs/libcfs.h>
+/* for lnet_ipif_query */
+#include <lnet/lib-lnet.h>
 
 #ifndef _GNILND_HSS_OPS_H
 # error "must include gnilnd_hss_ops.h first"
@@ -105,7 +105,7 @@ kgnilnd_setup_nic_translation(__u32 device_id)
 
        LCONSOLE_INFO("using Aries SIM IP info for RCA translation\n");
 
-       rc = libcfs_ipif_query(if_name, &up, &ipaddr, &netmask);
+       rc = lnet_ipif_query(if_name, &up, &ipaddr, &netmask);
        if (rc != 0) {
                CERROR ("can't get IP interface for %s: %d\n", if_name, rc);
                return rc;
index 135f5ef..8849b99 100644 (file)
@@ -2570,8 +2570,8 @@ kiblnd_dev_need_failover(kib_dev_t *dev)
         rc = rdma_resolve_addr(cmid, (struct sockaddr *)&srcaddr,
                                (struct sockaddr *)&dstaddr, 1);
        if (rc != 0 || cmid->device == NULL) {
-               CERROR("Failed to bind %s:%u.%u.%u.%u to device(%p): %d\n",
-                      dev->ibd_ifname, HIPQUAD(dev->ibd_ifip),
+               CERROR("Failed to bind %s:%pI4h to device(%p): %d\n",
+                      dev->ibd_ifname, &dev->ibd_ifip,
                       cmid->device, rc);
                 rdma_destroy_id(cmid);
                 return rc;
@@ -2643,8 +2643,8 @@ kiblnd_dev_failover(kib_dev_t *dev)
         /* Bind to failover device or port */
         rc = rdma_bind_addr(cmid, (struct sockaddr *)&addr);
        if (rc != 0 || cmid->device == NULL) {
-               CERROR("Failed to bind %s:%u.%u.%u.%u to device(%p): %d\n",
-                      dev->ibd_ifname, HIPQUAD(dev->ibd_ifip),
+               CERROR("Failed to bind %s:%pI4h to device(%p): %d\n",
+                      dev->ibd_ifname, &dev->ibd_ifip,
                       cmid->device, rc);
                 rdma_destroy_id(cmid);
                 goto out;
@@ -2750,7 +2750,7 @@ kiblnd_create_dev(char *ifname)
         int                up;
         int                rc;
 
-        rc = libcfs_ipif_query(ifname, &up, &ip, &netmask);
+       rc = lnet_ipif_query(ifname, &up, &ip, &netmask);
         if (rc != 0) {
                 CERROR("Can't query IPoIB interface %s: %d\n",
                        ifname, rc);
index cb7ee4e..41a4ca5 100644 (file)
@@ -1342,9 +1342,9 @@ kiblnd_connect_peer (kib_peer_t *peer)
         }
 
         LASSERT (cmid->device != NULL);
-        CDEBUG(D_NET, "%s: connection bound to %s:%u.%u.%u.%u:%s\n",
+       CDEBUG(D_NET, "%s: connection bound to %s:%pI4h:%s\n",
                libcfs_nid2str(peer->ibp_nid), dev->ibd_ifname,
-               HIPQUAD(dev->ibd_ifip), cmid->device->name);
+              &dev->ibd_ifip, cmid->device->name);
 
         return;
 
@@ -2201,7 +2201,7 @@ kiblnd_reject(struct rdma_cm_id *cmid, kib_rej_t *rej)
 }
 
 static int
-kiblnd_passive_connect (struct rdma_cm_id *cmid, void *priv, int priv_nob)
+kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
 {
        rwlock_t                *g_lock = &kiblnd_data.kib_global_lock;
         kib_msg_t             *reqmsg = priv;
@@ -2233,9 +2233,9 @@ kiblnd_passive_connect (struct rdma_cm_id *cmid, void *priv, int priv_nob)
         peer_addr = (struct sockaddr_in *)&(cmid->route.addr.dst_addr);
         if (*kiblnd_tunables.kib_require_priv_port &&
             ntohs(peer_addr->sin_port) >= PROT_SOCK) {
-                __u32 ip = ntohl(peer_addr->sin_addr.s_addr);
-                CERROR("Peer's port (%u.%u.%u.%u:%hu) is not privileged\n",
-                       HIPQUAD(ip), ntohs(peer_addr->sin_port));
+               __u32 ip = ntohl(peer_addr->sin_addr.s_addr);
+               CERROR("Peer's port (%pI4h:%hu) is not privileged\n",
+                      &ip, ntohs(peer_addr->sin_port));
                 goto failed;
         }
 
@@ -2279,11 +2279,11 @@ kiblnd_passive_connect (struct rdma_cm_id *cmid, void *priv, int priv_nob)
         if (ni == NULL ||                         /* no matching net */
             ni->ni_nid != reqmsg->ibm_dstnid ||   /* right NET, wrong NID! */
             net->ibn_dev != ibdev) {              /* wrong device */
-                CERROR("Can't accept %s on %s (%s:%d:%u.%u.%u.%u): "
+               CERROR("Can't accept %s on %s (%s:%d:%pI4h): "
                        "bad dst nid %s\n", libcfs_nid2str(nid),
                        ni == NULL ? "NA" : libcfs_nid2str(ni->ni_nid),
                        ibdev->ibd_ifname, ibdev->ibd_nnets,
-                       HIPQUAD(ibdev->ibd_ifip),
+                       &ibdev->ibd_ifip,
                        libcfs_nid2str(reqmsg->ibm_dstnid));
 
                 goto failed;
index 04f79cc..02601e6 100644 (file)
@@ -323,27 +323,26 @@ out:
 static void
 ksocknal_associate_route_conn_locked(ksock_route_t *route, ksock_conn_t *conn)
 {
-        ksock_peer_t      *peer = route->ksnr_peer;
-        int                type = conn->ksnc_type;
-        ksock_interface_t *iface;
+       ksock_peer_t      *peer = route->ksnr_peer;
+       int                type = conn->ksnc_type;
+       ksock_interface_t *iface;
 
-        conn->ksnc_route = route;
-        ksocknal_route_addref(route);
+       conn->ksnc_route = route;
+       ksocknal_route_addref(route);
 
-        if (route->ksnr_myipaddr != conn->ksnc_myipaddr) {
-                if (route->ksnr_myipaddr == 0) {
-                        /* route wasn't bound locally yet (the initial route) */
-                        CDEBUG(D_NET, "Binding %s %u.%u.%u.%u to %u.%u.%u.%u\n",
-                               libcfs_id2str(peer->ksnp_id),
-                               HIPQUAD(route->ksnr_ipaddr),
-                               HIPQUAD(conn->ksnc_myipaddr));
-                } else {
-                        CDEBUG(D_NET, "Rebinding %s %u.%u.%u.%u from "
-                               "%u.%u.%u.%u to %u.%u.%u.%u\n",
-                               libcfs_id2str(peer->ksnp_id),
-                               HIPQUAD(route->ksnr_ipaddr),
-                               HIPQUAD(route->ksnr_myipaddr),
-                               HIPQUAD(conn->ksnc_myipaddr));
+       if (route->ksnr_myipaddr != conn->ksnc_myipaddr) {
+               if (route->ksnr_myipaddr == 0) {
+                       /* route wasn't bound locally yet (the initial route) */
+                       CDEBUG(D_NET, "Binding %s %pI4h to %pI4h\n",
+                              libcfs_id2str(peer->ksnp_id),
+                              &route->ksnr_ipaddr,
+                              &conn->ksnc_myipaddr);
+               } else {
+                       CDEBUG(D_NET, "Rebinding %s %pI4h from %pI4h "
+                              "to %pI4h\n", libcfs_id2str(peer->ksnp_id),
+                              &route->ksnr_ipaddr,
+                              &route->ksnr_myipaddr,
+                              &conn->ksnc_myipaddr);
 
                         iface = ksocknal_ip2iface(route->ksnr_peer->ksnp_ni,
                                                   route->ksnr_myipaddr);
@@ -383,9 +382,9 @@ ksocknal_add_route_locked (ksock_peer_t *peer, ksock_route_t *route)
                route2 = list_entry(tmp, ksock_route_t, ksnr_list);
 
                if (route2->ksnr_ipaddr == route->ksnr_ipaddr) {
-                       CERROR("Duplicate route %s %u.%u.%u.%u\n",
+                       CERROR("Duplicate route %s %pI4h\n",
                               libcfs_id2str(peer->ksnp_id),
-                              HIPQUAD(route->ksnr_ipaddr));
+                              &route->ksnr_ipaddr);
                        LBUG();
                }
        }
@@ -972,23 +971,22 @@ ksocknal_create_routes(ksock_peer_t *peer, int port,
 }
 
 int
-ksocknal_accept (lnet_ni_t *ni, cfs_socket_t *sock)
+ksocknal_accept(lnet_ni_t *ni, struct socket *sock)
 {
-        ksock_connreq_t    *cr;
-        int                 rc;
-        __u32               peer_ip;
-        int                 peer_port;
-
-        rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
-        LASSERT (rc == 0);                      /* we succeeded before */
-
-        LIBCFS_ALLOC(cr, sizeof(*cr));
-        if (cr == NULL) {
-                LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from "
-                                   "%u.%u.%u.%u: memory exhausted\n",
-                                   HIPQUAD(peer_ip));
-                return -ENOMEM;
-        }
+       ksock_connreq_t *cr;
+       int              rc;
+       __u32            peer_ip;
+       int              peer_port;
+
+       rc = lnet_sock_getaddr(sock, true, &peer_ip, &peer_port);
+       LASSERT(rc == 0);               /* we succeeded before */
+
+       LIBCFS_ALLOC(cr, sizeof(*cr));
+       if (cr == NULL) {
+               LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from "
+                                  "%pI4h: memory exhausted\n", &peer_ip);
+               return -ENOMEM;
+       }
 
        lnet_ni_addref(ni);
        cr->ksncr_ni   = ni;
@@ -1016,8 +1014,8 @@ ksocknal_connecting (ksock_peer_t *peer, __u32 ipaddr)
 }
 
 int
-ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
-                      cfs_socket_t *sock, int type)
+ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
+                    struct socket *sock, int type)
 {
        rwlock_t                *global_lock = &ksocknal_data.ksnd_global_lock;
        struct list_head        zombies = LIST_HEAD_INIT(zombies);
@@ -1238,10 +1236,10 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
          * code below probably isn't going to work. */
         if (active &&
             route->ksnr_ipaddr != conn->ksnc_ipaddr) {
-                CERROR("Route %s %u.%u.%u.%u connected to %u.%u.%u.%u\n",
+               CERROR("Route %s %pI4h connected to %pI4h\n",
                        libcfs_id2str(peer->ksnp_id),
-                       HIPQUAD(route->ksnr_ipaddr),
-                       HIPQUAD(conn->ksnc_ipaddr));
+                      &route->ksnr_ipaddr,
+                      &conn->ksnc_ipaddr);
         }
 
        /* Search for a route corresponding to the new connection and
@@ -1269,7 +1267,7 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
 
        conn->ksnc_tx_last_post = cfs_time_current();
        /* Set the deadline for the outgoing HELLO to drain */
-       conn->ksnc_tx_bufnob = libcfs_sock_wmem_queued(sock);
+       conn->ksnc_tx_bufnob = sock->sk->sk_wmem_queued;
        conn->ksnc_tx_deadline = cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
        smp_mb();   /* order with adding to peer's conn list */
 
@@ -1300,10 +1298,10 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
          *        socket callbacks.
          */
 
-       CDEBUG(D_NET, "New conn %s p %d.x %u.%u.%u.%u -> %u.%u.%u.%u/%d"
-              " incarnation:"LPD64" sched[%d:%d]\n",
+       CDEBUG(D_NET, "New conn %s p %d.x %pI4h -> %pI4h/%d"
+              " incarnation:%lld sched[%d:%d]\n",
               libcfs_id2str(peerid), conn->ksnc_proto->pro_version,
-              HIPQUAD(conn->ksnc_myipaddr), HIPQUAD(conn->ksnc_ipaddr),
+              &conn->ksnc_myipaddr, &conn->ksnc_ipaddr,
               conn->ksnc_port, incarnation, cpt,
               (int)(sched - &sched->kss_info->ksi_scheds[0]));
 
@@ -1398,11 +1396,11 @@ failed_2:
                 LIBCFS_FREE(hello, offsetof(ksock_hello_msg_t,
                                             kshm_ips[LNET_MAX_INTERFACES]));
 
-        LIBCFS_FREE (conn, sizeof(*conn));
+       LIBCFS_FREE(conn, sizeof(*conn));
 
- failed_0:
-        libcfs_sock_release(sock);
-        return rc;
+failed_0:
+       sock_release(sock);
+       return rc;
 }
 
 void
@@ -1652,11 +1650,11 @@ ksocknal_destroy_conn (ksock_conn_t *conn)
         case SOCKNAL_RX_LNET_PAYLOAD:
                 last_rcv = conn->ksnc_rx_deadline -
                            cfs_time_seconds(*ksocknal_tunables.ksnd_timeout);
-                CERROR("Completing partial receive from %s[%d]"
-                       ", ip %d.%d.%d.%d:%d, with error, wanted: %d, left: %d, "
+               CERROR("Completing partial receive from %s[%d], "
+                      "ip %pI4h:%d, with error, wanted: %d, left: %d, "
                        "last alive is %ld secs ago\n",
                        libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type,
-                       HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port,
+                      &conn->ksnc_ipaddr, conn->ksnc_port,
                        conn->ksnc_rx_nob_wanted, conn->ksnc_rx_nob_left,
                        cfs_duration_sec(cfs_time_sub(cfs_time_current(),
                                         last_rcv)));
@@ -1665,26 +1663,26 @@ ksocknal_destroy_conn (ksock_conn_t *conn)
                 break;
         case SOCKNAL_RX_LNET_HEADER:
                 if (conn->ksnc_rx_started)
-                        CERROR("Incomplete receive of lnet header from %s"
-                               ", ip %d.%d.%d.%d:%d, with error, protocol: %d.x.\n",
+                       CERROR("Incomplete receive of lnet header from %s, "
+                              "ip %pI4h:%d, with error, protocol: %d.x.\n",
                                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                               HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port,
+                              &conn->ksnc_ipaddr, conn->ksnc_port,
                                conn->ksnc_proto->pro_version);
                 break;
         case SOCKNAL_RX_KSM_HEADER:
                 if (conn->ksnc_rx_started)
-                        CERROR("Incomplete receive of ksock message from %s"
-                               ", ip %d.%d.%d.%d:%d, with error, protocol: %d.x.\n",
+                       CERROR("Incomplete receive of ksock message from %s, "
+                              "ip %pI4h:%d, with error, protocol: %d.x.\n",
                                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                               HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port,
+                              &conn->ksnc_ipaddr, conn->ksnc_port,
                                conn->ksnc_proto->pro_version);
                 break;
         case SOCKNAL_RX_SLOP:
                 if (conn->ksnc_rx_started)
-                        CERROR("Incomplete receive of slops from %s"
-                               ", ip %d.%d.%d.%d:%d, with error\n",
+                       CERROR("Incomplete receive of slops from %s, "
+                              "ip %pI4h:%d, with error\n",
                                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                               HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
+                              &conn->ksnc_ipaddr, conn->ksnc_port);
                break;
         default:
                 LBUG ();
@@ -1821,7 +1819,7 @@ ksocknal_query (lnet_ni_t *ni, lnet_nid_t nid, cfs_time_t *when)
 
                list_for_each(tmp, &peer->ksnp_conns) {
                        conn = list_entry(tmp, ksock_conn_t, ksnc_list);
-                        bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+                       bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
 
                         if (bufnob < conn->ksnc_tx_bufnob) {
                                 /* something got ACKed */
@@ -2617,7 +2615,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
         int         rc;
         int         n;
 
-        n = libcfs_ipif_enumerate(&names);
+       n = lnet_ipif_enumerate(&names);
         if (n <= 0) {
                 CERROR("Can't enumerate interfaces: %d\n", n);
                 return n;
@@ -2631,7 +2629,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
                 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
                         continue;
 
-                rc = libcfs_ipif_query(names[i], &up, &ip, &mask);
+               rc = lnet_ipif_query(names[i], &up, &ip, &mask);
                 if (rc != 0) {
                         CWARN("Can't get interface %s info: %d\n",
                               names[i], rc);
@@ -2657,7 +2655,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
                 j++;
         }
 
-        libcfs_ipif_free_enumeration(names, n);
+       lnet_ipif_free_enumeration(names, n);
 
         if (j == 0)
                 CERROR("Can't find any usable interfaces\n");
@@ -2819,8 +2817,7 @@ ksocknal_startup (lnet_ni_t *ni)
                         if (ni->ni_interfaces[i] == NULL)
                                 break;
 
-                        rc = libcfs_ipif_query(
-                                ni->ni_interfaces[i], &up,
+                       rc = lnet_ipif_query(ni->ni_interfaces[i], &up,
                                 &net->ksnn_interfaces[i].ksni_ipaddr,
                                 &net->ksnn_interfaces[i].ksni_netmask);
 
index 8abbddf..3ced60f 100644 (file)
@@ -322,7 +322,7 @@ typedef struct ksock_conn
        struct ksock_peer  *ksnc_peer;          /* owning peer */
        struct ksock_route *ksnc_route;         /* owning route */
        struct list_head    ksnc_list;          /* stash on peer's conn list */
-       cfs_socket_t       *ksnc_sock;          /* actual socket */
+       struct socket       *ksnc_sock;         /* actual socket */
        void                *ksnc_saved_data_ready; /* socket's original data_ready() callback */
        void                *ksnc_saved_write_space; /* socket's original write_space() callback */
        atomic_t            ksnc_conn_refcount; /* conn refcount */
@@ -437,7 +437,7 @@ typedef struct ksock_connreq
        /* chosen NI */
        lnet_ni_t               *ksncr_ni;
        /* accepted socket */
-       cfs_socket_t            *ksncr_sock;
+       struct socket           *ksncr_sock;
 } ksock_connreq_t;
 
 extern ksock_nal_data_t ksocknal_data;
@@ -548,7 +548,7 @@ ksocknal_connsock_decref (ksock_conn_t *conn)
        LASSERT (atomic_read(&conn->ksnc_sock_refcount) > 0);
        if (atomic_dec_and_test(&conn->ksnc_sock_refcount)) {
                LASSERT (conn->ksnc_closing);
-               libcfs_sock_release(conn->ksnc_sock);
+               sock_release(conn->ksnc_sock);
                conn->ksnc_sock = NULL;
                ksocknal_finalize_zcreq(conn);
        }
@@ -614,14 +614,14 @@ int ksocknal_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
                   int delayed, unsigned int niov, 
                   struct iovec *iov, lnet_kiov_t *kiov,
                   unsigned int offset, unsigned int mlen, unsigned int rlen);
-int ksocknal_accept(lnet_ni_t *ni, cfs_socket_t *sock);
+int ksocknal_accept(lnet_ni_t *ni, struct socket *sock);
 
 extern int ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip, int port);
 extern ksock_peer_t *ksocknal_find_peer_locked (lnet_ni_t *ni, lnet_process_id_t id);
 extern ksock_peer_t *ksocknal_find_peer (lnet_ni_t *ni, lnet_process_id_t id);
 extern void ksocknal_peer_failed (ksock_peer_t *peer);
 extern int ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
-                                 cfs_socket_t *sock, int type);
+                                struct socket *sock, int type);
 extern void ksocknal_close_conn_locked (ksock_conn_t *conn, int why);
 extern void ksocknal_terminate_conn (ksock_conn_t *conn);
 extern void ksocknal_destroy_conn (ksock_conn_t *conn);
@@ -661,19 +661,20 @@ extern void ksocknal_read_callback(ksock_conn_t *conn);
 extern void ksocknal_write_callback(ksock_conn_t *conn);
 
 extern int ksocknal_lib_zc_capable(ksock_conn_t *conn);
-extern void ksocknal_lib_save_callback(cfs_socket_t *sock, ksock_conn_t *conn);
-extern void ksocknal_lib_set_callback(cfs_socket_t *sock,  ksock_conn_t *conn);
-extern void ksocknal_lib_reset_callback(cfs_socket_t *sock, ksock_conn_t *conn);
-extern void ksocknal_lib_push_conn (ksock_conn_t *conn);
-extern int ksocknal_lib_get_conn_addrs (ksock_conn_t *conn);
-extern int ksocknal_lib_setup_sock (cfs_socket_t *so);
-extern int ksocknal_lib_send_iov (ksock_conn_t *conn, ksock_tx_t *tx);
-extern int ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx);
-extern void ksocknal_lib_eager_ack (ksock_conn_t *conn);
-extern int ksocknal_lib_recv_iov (ksock_conn_t *conn);
-extern int ksocknal_lib_recv_kiov (ksock_conn_t *conn);
-extern int ksocknal_lib_get_conn_tunables (ksock_conn_t *conn, int *txmem, 
-                                           int *rxmem, int *nagle);
+extern void ksocknal_lib_save_callback(struct socket *sock, ksock_conn_t *conn);
+extern void ksocknal_lib_set_callback(struct socket *sock,  ksock_conn_t *conn);
+extern void ksocknal_lib_reset_callback(struct socket *sock,
+                                       ksock_conn_t *conn);
+extern void ksocknal_lib_push_conn(ksock_conn_t *conn);
+extern int ksocknal_lib_get_conn_addrs(ksock_conn_t *conn);
+extern int ksocknal_lib_setup_sock(struct socket *so);
+extern int ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx);
+extern int ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx);
+extern void ksocknal_lib_eager_ack(ksock_conn_t *conn);
+extern int ksocknal_lib_recv_iov(ksock_conn_t *conn);
+extern int ksocknal_lib_recv_kiov(ksock_conn_t *conn);
+extern int ksocknal_lib_get_conn_tunables(ksock_conn_t *conn, int *txmem,
+                                         int *rxmem, int *nagle);
 
 extern int ksocknal_tunables_init(void);
 extern void ksocknal_tunables_fini(void);
index e7f0e06..d1538fc 100644 (file)
@@ -211,7 +211,7 @@ ksocknal_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
                         rc = ksocknal_send_kiov (conn, tx);
                 }
 
-                bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+               bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
                 if (rc > 0)                     /* sent something? */
                         conn->ksnc_tx_bufnob += rc; /* account it */
 
@@ -553,22 +553,20 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
         if (!conn->ksnc_closing) {
                 switch (rc) {
                 case -ECONNRESET:
-                        LCONSOLE_WARN("Host %u.%u.%u.%u reset our connection "
+                       LCONSOLE_WARN("Host %pI4h reset our connection "
                                       "while we were sending data; it may have "
                                       "rebooted.\n",
-                                      HIPQUAD(conn->ksnc_ipaddr));
+                                     &conn->ksnc_ipaddr);
                         break;
                 default:
                         LCONSOLE_WARN("There was an unexpected network error "
-                                      "while writing to %u.%u.%u.%u: %d.\n",
-                                      HIPQUAD(conn->ksnc_ipaddr), rc);
+                                     "while writing to %pI4h: %d.\n",
+                                     &conn->ksnc_ipaddr, rc);
                         break;
                 }
-                CDEBUG(D_NET, "[%p] Error %d on write to %s"
-                       " ip %d.%d.%d.%d:%d\n", conn, rc,
-                       libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                       HIPQUAD(conn->ksnc_ipaddr),
-                       conn->ksnc_port);
+               CDEBUG(D_NET, "[%p] Error %d on write to %s ip %pI4h:%d\n",
+                      conn, rc, libcfs_id2str(conn->ksnc_peer->ksnp_id),
+                      &conn->ksnc_ipaddr, conn->ksnc_port);
         }
 
         if (tx->tx_zc_checked)
@@ -632,7 +630,7 @@ ksocknal_find_conn_locked(ksock_peer_t *peer, ksock_tx_t *tx, int nonblk)
        list_for_each(tmp, &peer->ksnp_conns) {
                ksock_conn_t *c  = list_entry(tmp, ksock_conn_t, ksnc_list);
                int           nob = atomic_read(&c->ksnc_tx_nob) +
-                                    libcfs_sock_wmem_queued(c->ksnc_sock);
+                                       c->ksnc_sock->sk->sk_wmem_queued;
                 int           rc;
 
                 LASSERT (!c->ksnc_closing);
@@ -700,10 +698,9 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
          * ksnc_sock... */
         LASSERT(!conn->ksnc_closing);
 
-       CDEBUG(D_NET, "Sending to %s ip %d.%d.%d.%d:%d\n",
+       CDEBUG(D_NET, "Sending to %s ip %pI4h:%d\n",
               libcfs_id2str(conn->ksnc_peer->ksnp_id),
-              HIPQUAD(conn->ksnc_ipaddr),
-              conn->ksnc_port);
+              &conn->ksnc_ipaddr, conn->ksnc_port);
 
         ksocknal_tx_prep(conn, tx);
 
@@ -724,7 +721,7 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
                                                KSOCK_MSG_NOOP,
                 tx->tx_nob, tx->tx_niov, tx->tx_nkiov);
 
-        bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+       bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
        spin_lock_bh(&sched->kss_lock);
 
        if (list_empty(&conn->ksnc_tx_queue) && bufnob == 0) {
@@ -797,9 +794,9 @@ ksocknal_find_connectable_route_locked (ksock_peer_t *peer)
                 if (!(route->ksnr_retry_interval == 0 || /* first attempt */
                       cfs_time_aftereq(now, route->ksnr_timeout))) {
                         CDEBUG(D_NET,
-                               "Too soon to retry route %u.%u.%u.%u "
+                              "Too soon to retry route %pI4h "
                                "(cnted %d, interval %ld, %ld secs later)\n",
-                               HIPQUAD(route->ksnr_ipaddr),
+                              &route->ksnr_ipaddr,
                                route->ksnr_connected,
                                route->ksnr_retry_interval,
                                cfs_duration_sec(route->ksnr_timeout - now));
@@ -1126,22 +1123,23 @@ ksocknal_process_receive (ksock_conn_t *conn)
         if (conn->ksnc_rx_nob_wanted != 0) {
                 rc = ksocknal_receive(conn);
 
-                if (rc <= 0) {
-                        LASSERT (rc != -EAGAIN);
+               if (rc <= 0) {
+                       lnet_process_id_t ksnp_id = conn->ksnc_peer->ksnp_id;
 
-                        if (rc == 0)
-                                CDEBUG (D_NET, "[%p] EOF from %s"
-                                        " ip %d.%d.%d.%d:%d\n", conn,
-                                        libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
-                                        conn->ksnc_port);
-                        else if (!conn->ksnc_closing)
-                                CERROR ("[%p] Error %d on read from %s"
-                                        " ip %d.%d.%d.%d:%d\n",
-                                        conn, rc,
-                                        libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                       LASSERT(rc != -EAGAIN);
+
+                       if (rc == 0)
+                               CDEBUG(D_NET, "[%p] EOF from %s "
+                                      "ip %pI4h:%d\n", conn,
+                                       libcfs_id2str(ksnp_id),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
+                       else if (!conn->ksnc_closing)
+                               CERROR("[%p] Error %d on read from %s "
+                                      "ip %pI4h:%d\n", conn, rc,
+                                      libcfs_id2str(ksnp_id),
+                                      &conn->ksnc_ipaddr,
+                                      conn->ksnc_port);
 
                         /* it's not an error if conn is being closed */
                         ksocknal_close_conn_and_siblings (conn,
@@ -1702,7 +1700,7 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
          *        EALREADY   lost connection race
          *        EPROTO     protocol version mismatch
          */
-        cfs_socket_t        *sock = conn->ksnc_sock;
+       struct socket        *sock = conn->ksnc_sock;
         int                  active = (conn->ksnc_proto != NULL);
         int                  timeout;
         int                  proto_match;
@@ -1710,16 +1708,17 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         ksock_proto_t       *proto;
         lnet_process_id_t    recv_id;
 
-        /* socket type set on active connections - not set on passive */
-        LASSERT (!active == !(conn->ksnc_type != SOCKLND_CONN_NONE));
+       /* socket type set on active connections - not set on passive */
+       LASSERT(!active == !(conn->ksnc_type != SOCKLND_CONN_NONE));
 
-        timeout = active ? *ksocknal_tunables.ksnd_timeout :
-                            lnet_acceptor_timeout();
+       timeout = active ? *ksocknal_tunables.ksnd_timeout :
+                           lnet_acceptor_timeout();
 
-        rc = libcfs_sock_read(sock, &hello->kshm_magic, sizeof (hello->kshm_magic), timeout);
+       rc = lnet_sock_read(sock, &hello->kshm_magic,
+                           sizeof(hello->kshm_magic), timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading HELLO from %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Error %d reading HELLO from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
                 LASSERT (rc < 0);
                 return rc;
         }
@@ -1729,18 +1728,17 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
             hello->kshm_magic != le32_to_cpu (LNET_PROTO_TCP_MAGIC)) {
                 /* Unexpected magic! */
                 CERROR ("Bad magic(1) %#08x (%#08x expected) from "
-                        "%u.%u.%u.%u\n", __cpu_to_le32 (hello->kshm_magic),
-                        LNET_PROTO_TCP_MAGIC,
-                        HIPQUAD(conn->ksnc_ipaddr));
+                       "%pI4h\n", __cpu_to_le32 (hello->kshm_magic),
+                       LNET_PROTO_TCP_MAGIC, &conn->ksnc_ipaddr);
                 return -EPROTO;
         }
 
-        rc = libcfs_sock_read(sock, &hello->kshm_version,
-                              sizeof(hello->kshm_version), timeout);
+       rc = lnet_sock_read(sock, &hello->kshm_version,
+                           sizeof(hello->kshm_version), timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading HELLO from %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
-                LASSERT (rc < 0);
+               CERROR("Error %d reading HELLO from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
+               LASSERT(rc < 0);
                 return rc;
         }
 
@@ -1759,10 +1757,8 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
                         ksocknal_send_hello(ni, conn, ni->ni_nid, hello);
                 }
 
-                CERROR ("Unknown protocol version (%d.x expected)"
-                        " from %u.%u.%u.%u\n",
-                        conn->ksnc_proto->pro_version,
-                        HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Unknown protocol version (%d.x expected) from %pI4h\n",
+                      conn->ksnc_proto->pro_version, &conn->ksnc_ipaddr);
 
                 return -EPROTO;
         }
@@ -1773,8 +1769,8 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         /* receive the rest of hello message anyway */
         rc = conn->ksnc_proto->pro_recv_hello(conn, hello, timeout);
         if (rc != 0) {
-                CERROR("Error %d reading or checking hello from from %u.%u.%u.%u\n",
-                       rc, HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Error %d reading or checking hello from from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
                 LASSERT (rc < 0);
                 return rc;
         }
@@ -1783,7 +1779,7 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
 
         if (hello->kshm_src_nid == LNET_NID_ANY) {
                 CERROR("Expecting a HELLO hdr with a NID, but got LNET_NID_ANY"
-                       "from %u.%u.%u.%u\n", HIPQUAD(conn->ksnc_ipaddr));
+                      "from %pI4h\n", &conn->ksnc_ipaddr);
                 return -EPROTO;
         }
 
@@ -1800,26 +1796,25 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         if (!active) {
                 *peerid = recv_id;
 
-                /* peer determines type */
-                conn->ksnc_type = ksocknal_invert_type(hello->kshm_ctype);
-                if (conn->ksnc_type == SOCKLND_CONN_NONE) {
-                        CERROR ("Unexpected type %d from %s ip %u.%u.%u.%u\n",
-                                hello->kshm_ctype, libcfs_id2str(*peerid),
-                                HIPQUAD(conn->ksnc_ipaddr));
-                        return -EPROTO;
-                }
-
-                return 0;
-        }
+               /* peer determines type */
+               conn->ksnc_type = ksocknal_invert_type(hello->kshm_ctype);
+               if (conn->ksnc_type == SOCKLND_CONN_NONE) {
+                       CERROR("Unexpected type %d from %s ip %pI4h\n",
+                              hello->kshm_ctype, libcfs_id2str(*peerid),
+                              &conn->ksnc_ipaddr);
+                       return -EPROTO;
+               }
+               return 0;
+       }
 
         if (peerid->pid != recv_id.pid ||
             peerid->nid != recv_id.nid) {
                 LCONSOLE_ERROR_MSG(0x130, "Connected successfully to %s on host"
-                                   " %u.%u.%u.%u, but they claimed they were "
+                                  " %pI4h, but they claimed they were "
                                    "%s; please check your Lustre "
                                    "configuration.\n",
                                    libcfs_id2str(*peerid),
-                                   HIPQUAD(conn->ksnc_ipaddr),
+                                  &conn->ksnc_ipaddr,
                                    libcfs_id2str(recv_id));
                 return -EPROTO;
         }
@@ -1829,15 +1824,14 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
                 return proto_match ? EALREADY : EPROTO;
         }
 
-        if (ksocknal_invert_type(hello->kshm_ctype) != conn->ksnc_type) {
-                CERROR ("Mismatched types: me %d, %s ip %u.%u.%u.%u %d\n",
-                       conn->ksnc_type, libcfs_id2str(*peerid),
-                        HIPQUAD(conn->ksnc_ipaddr),
-                        hello->kshm_ctype);
-                return -EPROTO;
-        }
-
-        return 0;
+       if (ksocknal_invert_type(hello->kshm_ctype) != conn->ksnc_type) {
+               CERROR("Mismatched types: me %d, %s ip %pI4h %d\n",
+                      conn->ksnc_type, libcfs_id2str(*peerid),
+                      &conn->ksnc_ipaddr,
+                      hello->kshm_ctype);
+               return -EPROTO;
+       }
+       return 0;
 }
 
 static int
@@ -1847,7 +1841,7 @@ ksocknal_connect (ksock_route_t *route)
         ksock_peer_t     *peer = route->ksnr_peer;
         int               type;
         int               wanted;
-        cfs_socket_t     *sock;
+       struct socket     *sock;
         cfs_time_t        deadline;
         int               retry_later = 0;
         int               rc = 0;
@@ -2204,8 +2198,8 @@ ksocknal_connd (void *arg)
                                 /* consecutive retry */
                                 if (cons_retry++ > SOCKNAL_INSANITY_RECONN) {
                                         CWARN("massive consecutive "
-                                              "re-connecting to %u.%u.%u.%u\n",
-                                              HIPQUAD(route->ksnr_ipaddr));
+                                             "re-connecting to %pI4h\n",
+                                             &route->ksnr_ipaddr);
                                         cons_retry = 0;
                                 }
                         } else {
@@ -2261,33 +2255,33 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                 /* Don't need the {get,put}connsock dance to deref ksnc_sock */
                 LASSERT (!conn->ksnc_closing);
 
-                error = libcfs_sock_error(conn->ksnc_sock);
+               error = conn->ksnc_sock->sk->sk_err;
                 if (error != 0) {
                         ksocknal_conn_addref(conn);
 
                         switch (error) {
                         case ECONNRESET:
                                 CNETERR("A connection with %s "
-                                        "(%u.%u.%u.%u:%d) was reset; "
+                                       "(%pI4h:%d) was reset; "
                                         "it may have rebooted.\n",
                                         libcfs_id2str(peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
                                 break;
                         case ETIMEDOUT:
                                 CNETERR("A connection with %s "
-                                        "(%u.%u.%u.%u:%d) timed out; the "
+                                       "(%pI4h:%d) timed out; the "
                                         "network or node may be down.\n",
                                         libcfs_id2str(peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
                                 break;
                         default:
                                 CNETERR("An unexpected network error %d "
                                         "occurred with %s "
-                                        "(%u.%u.%u.%u:%d\n", error,
+                                       "(%pI4h:%d\n", error,
                                         libcfs_id2str(peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
                                 break;
                         }
@@ -2300,10 +2294,10 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                                      conn->ksnc_rx_deadline)) {
                         /* Timed out incomplete incoming message */
                         ksocknal_conn_addref(conn);
-                        CNETERR("Timeout receiving from %s (%u.%u.%u.%u:%d), "
+                       CNETERR("Timeout receiving from %s (%pI4h:%d), "
                                 "state %d wanted %d left %d\n",
                                 libcfs_id2str(peer->ksnp_id),
-                                HIPQUAD(conn->ksnc_ipaddr),
+                               &conn->ksnc_ipaddr,
                                 conn->ksnc_port,
                                 conn->ksnc_rx_state,
                                 conn->ksnc_rx_nob_wanted,
@@ -2312,17 +2306,16 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                 }
 
                if ((!list_empty(&conn->ksnc_tx_queue) ||
-                     libcfs_sock_wmem_queued(conn->ksnc_sock) != 0) &&
+                    conn->ksnc_sock->sk->sk_wmem_queued != 0) &&
                     cfs_time_aftereq(cfs_time_current(),
                                      conn->ksnc_tx_deadline)) {
                         /* Timed out messages queued for sending or
                          * buffered in the socket's send buffer */
                         ksocknal_conn_addref(conn);
-                        CNETERR("Timeout sending data to %s (%u.%u.%u.%u:%d) "
+                       CNETERR("Timeout sending data to %s (%pI4h:%d) "
                                 "the network or that node may be down.\n",
                                 libcfs_id2str(peer->ksnp_id),
-                                HIPQUAD(conn->ksnc_ipaddr),
-                                conn->ksnc_port);
+                               &conn->ksnc_ipaddr, conn->ksnc_port);
                         return (conn);
                 }
         }
@@ -2511,7 +2504,7 @@ ksocknal_check_peer_timeouts (int idx)
                        "resid: %d, wmem: %d\n",
                        n, libcfs_nid2str(peer->ksnp_id.nid), tx,
                        cfs_duration_sec(cfs_time_current() - deadline),
-                       resid, libcfs_sock_wmem_queued(conn->ksnc_sock));
+                      resid, conn->ksnc_sock->sk->sk_wmem_queued);
 
                 ksocknal_close_conn_and_siblings (conn, -ETIMEDOUT);
                 ksocknal_conn_decref(conn);
index a5f63f0..e17f475 100644 (file)
@@ -345,7 +345,7 @@ ksocknal_lib_tunables_fini ()
 int
 ksocknal_lib_get_conn_addrs (ksock_conn_t *conn)
 {
-        int rc = libcfs_sock_getaddr(conn->ksnc_sock, 1,
+       int rc = lnet_sock_getaddr(conn->ksnc_sock, true,
                                      &conn->ksnc_ipaddr,
                                      &conn->ksnc_port);
 
@@ -357,7 +357,7 @@ ksocknal_lib_get_conn_addrs (ksock_conn_t *conn)
                 return rc;
         }
 
-        rc = libcfs_sock_getaddr(conn->ksnc_sock, 0,
+       rc = lnet_sock_getaddr(conn->ksnc_sock, false,
                                  &conn->ksnc_myipaddr, NULL);
         if (rc != 0) {
                 CERROR ("Error %d getting sock local IP\n", rc);
@@ -747,7 +747,7 @@ ksocknal_lib_get_conn_tunables (ksock_conn_t *conn, int *txmem, int *rxmem, int
                 return (-ESHUTDOWN);
         }
 
-        rc = libcfs_sock_getbuf(sock, txmem, rxmem);
+       rc = lnet_sock_getbuf(sock, txmem, rxmem);
         if (rc == 0) {
                 len = sizeof(*nagle);
                 set_fs(KERNEL_DS);
@@ -818,9 +818,9 @@ ksocknal_lib_setup_sock (struct socket *sock)
                 }
         }
 
-        rc = libcfs_sock_setbuf(sock,
-                                *ksocknal_tunables.ksnd_tx_buffer_size,
-                                *ksocknal_tunables.ksnd_rx_buffer_size);
+       rc = lnet_sock_setbuf(sock,
+                             *ksocknal_tunables.ksnd_tx_buffer_size,
+                             *ksocknal_tunables.ksnd_rx_buffer_size);
         if (rc != 0) {
                 CERROR ("Can't set buffer tx %d, rx %d buffers: %d\n",
                         *ksocknal_tunables.ksnd_tx_buffer_size,
@@ -1075,7 +1075,7 @@ ksocknal_lib_memory_pressure(ksock_conn_t *conn)
        sched = conn->ksnc_scheduler;
        spin_lock_bh(&sched->kss_lock);
 
-        if (!SOCK_TEST_NOSPACE(conn->ksnc_sock) &&
+       if (!test_bit(SOCK_NOSPACE, &conn->ksnc_sock->flags) &&
             !conn->ksnc_tx_ready) {
                 /* SOCK_NOSPACE is set when the socket fills
                  * and cleared in the write_space callback
index 9bfb61a..f4a7d77 100644 (file)
@@ -451,7 +451,7 @@ ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
 static int
 ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
 {
-        cfs_socket_t        *sock = conn->ksnc_sock;
+       struct socket        *sock = conn->ksnc_sock;
         lnet_hdr_t          *hdr;
         lnet_magicversion_t *hmv;
         int                  rc;
@@ -494,11 +494,10 @@ ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
         hdr->msg.hello.type = cpu_to_le32 (hello->kshm_ctype);
         hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
 
-        rc = libcfs_sock_write(sock, hdr, sizeof(*hdr),lnet_acceptor_timeout());
-
+       rc = lnet_sock_write(sock, hdr, sizeof(*hdr), lnet_acceptor_timeout());
         if (rc != 0) {
-                CNETERR("Error %d sending HELLO hdr to %u.%u.%u.%u/%d\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
+               CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
+                       rc, &conn->ksnc_ipaddr, conn->ksnc_port);
                 goto out;
         }
 
@@ -509,13 +508,13 @@ ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
                 hello->kshm_ips[i] = __cpu_to_le32 (hello->kshm_ips[i]);
         }
 
-        rc = libcfs_sock_write(sock, hello->kshm_ips,
+       rc = lnet_sock_write(sock, hello->kshm_ips,
                                hello->kshm_nips * sizeof(__u32),
                                lnet_acceptor_timeout());
         if (rc != 0) {
                 CNETERR("Error %d sending HELLO payload (%d)"
-                        " to %u.%u.%u.%u/%d\n", rc, hello->kshm_nips,
-                        HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
+                       " to %pI4h/%d\n", rc, hello->kshm_nips,
+                       &conn->ksnc_ipaddr, conn->ksnc_port);
         }
 out:
         LIBCFS_FREE(hdr, sizeof(*hdr));
@@ -526,7 +525,7 @@ out:
 static int
 ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
 {
-        cfs_socket_t   *sock = conn->ksnc_sock;
+       struct socket   *sock = conn->ksnc_sock;
         int             rc;
 
         hello->kshm_magic   = LNET_PROTO_MAGIC;
@@ -542,25 +541,25 @@ ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
                 LNET_UNLOCK();
         }
 
-        rc = libcfs_sock_write(sock, hello, offsetof(ksock_hello_msg_t, kshm_ips),
+       rc = lnet_sock_write(sock, hello, offsetof(ksock_hello_msg_t, kshm_ips),
                                lnet_acceptor_timeout());
 
         if (rc != 0) {
-                CNETERR("Error %d sending HELLO hdr to %u.%u.%u.%u/%d\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
+               CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
+                       rc, &conn->ksnc_ipaddr, conn->ksnc_port);
                 return rc;
         }
 
         if (hello->kshm_nips == 0)
                 return 0;
 
-        rc = libcfs_sock_write(sock, hello->kshm_ips,
+       rc = lnet_sock_write(sock, hello->kshm_ips,
                                hello->kshm_nips * sizeof(__u32),
                                lnet_acceptor_timeout());
         if (rc != 0) {
                 CNETERR("Error %d sending HELLO payload (%d)"
-                        " to %u.%u.%u.%u/%d\n", rc, hello->kshm_nips,
-                        HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
+                       " to %pI4h/%d\n", rc, hello->kshm_nips,
+                       &conn->ksnc_ipaddr, conn->ksnc_port);
         }
 
         return rc;
@@ -569,7 +568,7 @@ ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
 static int
 ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
 {
-        cfs_socket_t        *sock = conn->ksnc_sock;
+       struct socket        *sock = conn->ksnc_sock;
         lnet_hdr_t          *hdr;
         int                  rc;
         int                  i;
@@ -580,22 +579,22 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
                 return -ENOMEM;
         }
 
-        rc = libcfs_sock_read(sock, &hdr->src_nid,
-                              sizeof (*hdr) - offsetof (lnet_hdr_t, src_nid),
-                              timeout);
-        if (rc != 0) {
-                CERROR ("Error %d reading rest of HELLO hdr from %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
-                LASSERT (rc < 0 && rc != -EALREADY);
-                goto out;
-        }
+       rc = lnet_sock_read(sock, &hdr->src_nid,
+                             sizeof(*hdr) - offsetof(lnet_hdr_t, src_nid),
+                             timeout);
+       if (rc != 0) {
+               CERROR("Error %d reading rest of HELLO hdr from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
+               LASSERT(rc < 0 && rc != -EALREADY);
+               goto out;
+       }
 
         /* ...and check we got what we expected */
         if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
                 CERROR ("Expecting a HELLO hdr,"
-                        " but got type %d from %u.%u.%u.%u\n",
+                       " but got type %d from %pI4h\n",
                         le32_to_cpu (hdr->type),
-                        HIPQUAD(conn->ksnc_ipaddr));
+                       &conn->ksnc_ipaddr);
                 rc = -EPROTO;
                 goto out;
         }
@@ -608,8 +607,8 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
                                          sizeof (__u32);
 
         if (hello->kshm_nips > LNET_MAX_INTERFACES) {
-                CERROR("Bad nips %d from ip %u.%u.%u.%u\n",
-                       hello->kshm_nips, HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Bad nips %d from ip %pI4h\n",
+                      hello->kshm_nips, &conn->ksnc_ipaddr);
                 rc = -EPROTO;
                 goto out;
         }
@@ -617,12 +616,12 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
         if (hello->kshm_nips == 0)
                 goto out;
 
-        rc = libcfs_sock_read(sock, hello->kshm_ips,
+       rc = lnet_sock_read(sock, hello->kshm_ips,
                               hello->kshm_nips * sizeof(__u32), timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading IPs from ip %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
-                LASSERT (rc < 0 && rc != -EALREADY);
+               CERROR("Error %d reading IPs from ip %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
+               LASSERT(rc < 0 && rc != -EALREADY);
                 goto out;
         }
 
@@ -630,8 +629,8 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
                 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
 
                 if (hello->kshm_ips[i] == 0) {
-                        CERROR("Zero IP[%d] from ip %u.%u.%u.%u\n",
-                               i, HIPQUAD(conn->ksnc_ipaddr));
+                       CERROR("Zero IP[%d] from ip %pI4h\n",
+                              i, &conn->ksnc_ipaddr);
                         rc = -EPROTO;
                         break;
                 }
@@ -643,9 +642,10 @@ out:
 }
 
 static int
-ksocknal_recv_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeout)
+ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello,
+                      int timeout)
 {
-        cfs_socket_t      *sock = conn->ksnc_sock;
+       struct socket     *sock = conn->ksnc_sock;
         int                rc;
         int                i;
 
@@ -654,14 +654,14 @@ ksocknal_recv_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeou
         else
                 conn->ksnc_flip = 1;
 
-        rc = libcfs_sock_read(sock, &hello->kshm_src_nid,
+       rc = lnet_sock_read(sock, &hello->kshm_src_nid,
                               offsetof(ksock_hello_msg_t, kshm_ips) -
                                        offsetof(ksock_hello_msg_t, kshm_src_nid),
                               timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading HELLO from %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
-                LASSERT (rc < 0 && rc != -EALREADY);
+               CERROR("Error %d reading HELLO from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
+               LASSERT(rc < 0 && rc != -EALREADY);
                 return rc;
         }
 
@@ -677,20 +677,20 @@ ksocknal_recv_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeou
         }
 
         if (hello->kshm_nips > LNET_MAX_INTERFACES) {
-                CERROR("Bad nips %d from ip %u.%u.%u.%u\n",
-                       hello->kshm_nips, HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Bad nips %d from ip %pI4h\n",
+                      hello->kshm_nips, &conn->ksnc_ipaddr);
                 return -EPROTO;
         }
 
         if (hello->kshm_nips == 0)
                 return 0;
 
-        rc = libcfs_sock_read(sock, hello->kshm_ips,
-                              hello->kshm_nips * sizeof(__u32), timeout);
+       rc = lnet_sock_read(sock, hello->kshm_ips,
+                           hello->kshm_nips * sizeof(__u32), timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading IPs from ip %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
-                LASSERT (rc < 0 && rc != -EALREADY);
+               CERROR("Error %d reading IPs from ip %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
+               LASSERT(rc < 0 && rc != -EALREADY);
                 return rc;
         }
 
@@ -699,8 +699,8 @@ ksocknal_recv_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeou
                         __swab32s(&hello->kshm_ips[i]);
 
                 if (hello->kshm_ips[i] == 0) {
-                        CERROR("Zero IP[%d] from ip %u.%u.%u.%u\n",
-                               i, HIPQUAD(conn->ksnc_ipaddr));
+                       CERROR("Zero IP[%d] from ip %pI4h\n",
+                              i, &conn->ksnc_ipaddr);
                         return -EPROTO;
                 }
         }
index a1f7168..2e6736a 100644 (file)
@@ -2,7 +2,7 @@ MODULES := lnet
 
 lnet-objs := api-ni.o config.o
 lnet-objs += lib-me.o lib-msg.o lib-eq.o lib-md.o lib-ptl.o
-lnet-objs += lib-move.o module.o lo.o
+lnet-objs += lib-socket.o lib-move.o module.o lo.o
 lnet-objs += router.o router_proc.o acceptor.o peer.o net_fault.o
 
 default: all
index f706c6b..b6d85ef 100644 (file)
@@ -43,7 +43,7 @@ static int   accept_timeout = 5;
 
 static struct {
        int                     pta_shutdown;
-       cfs_socket_t            *pta_sock;
+       struct socket           *pta_sock;
        struct completion       pta_signal;
 } lnet_acceptor_state = {
        .pta_shutdown = 1
@@ -101,63 +101,60 @@ lnet_connect_console_error (int rc, lnet_nid_t peer_nid,
         switch (rc) {
         /* "normal" errors */
         case -ECONNREFUSED:
-                CNETERR("Connection to %s at host %u.%u.%u.%u on port %d was "
+               CNETERR("Connection to %s at host %pI4h on port %d was "
                         "refused: check that Lustre is running on that node.\n",
-                        libcfs_nid2str(peer_nid),
-                        HIPQUAD(peer_ip), peer_port);
+                       libcfs_nid2str(peer_nid), &peer_ip, peer_port);
                 break;
         case -EHOSTUNREACH:
         case -ENETUNREACH:
-                CNETERR("Connection to %s at host %u.%u.%u.%u "
+               CNETERR("Connection to %s at host %pI4h "
                         "was unreachable: the network or that node may "
                         "be down, or Lustre may be misconfigured.\n",
-                        libcfs_nid2str(peer_nid), HIPQUAD(peer_ip));
+                       libcfs_nid2str(peer_nid), &peer_ip);
                 break;
         case -ETIMEDOUT:
-                CNETERR("Connection to %s at host %u.%u.%u.%u on "
+               CNETERR("Connection to %s at host %pI4h on "
                         "port %d took too long: that node may be hung "
                         "or experiencing high load.\n",
-                        libcfs_nid2str(peer_nid),
-                        HIPQUAD(peer_ip), peer_port);
+                       libcfs_nid2str(peer_nid), &peer_ip, peer_port);
                 break;
         case -ECONNRESET:
-                LCONSOLE_ERROR_MSG(0x11b, "Connection to %s at host %u.%u.%u.%u"
+               LCONSOLE_ERROR_MSG(0x11b, "Connection to %s at host %pI4h"
                                    " on port %d was reset: "
                                    "is it running a compatible version of "
                                    "Lustre and is %s one of its NIDs?\n",
-                                   libcfs_nid2str(peer_nid),
-                                   HIPQUAD(peer_ip), peer_port,
-                                   libcfs_nid2str(peer_nid));
+                                  libcfs_nid2str(peer_nid), &peer_ip,
+                                  peer_port, libcfs_nid2str(peer_nid));
                 break;
         case -EPROTO:
                 LCONSOLE_ERROR_MSG(0x11c, "Protocol error connecting to %s at "
-                                   "host %u.%u.%u.%u on port %d: is it running "
+                                  "host %pI4h on port %d: is it running "
                                    "a compatible version of Lustre?\n",
-                                   libcfs_nid2str(peer_nid),
-                                   HIPQUAD(peer_ip), peer_port);
+                                  libcfs_nid2str(peer_nid), &peer_ip,
+                                  peer_port);
                 break;
         case -EADDRINUSE:
                 LCONSOLE_ERROR_MSG(0x11d, "No privileged ports available to "
-                                   "connect to %s at host %u.%u.%u.%u on port "
+                                  "connect to %s at host %pI4h on port "
                                    "%d\n", libcfs_nid2str(peer_nid),
-                                   HIPQUAD(peer_ip), peer_port);
+                                  &peer_ip, peer_port);
                 break;
         default:
                 LCONSOLE_ERROR_MSG(0x11e, "Unexpected error %d connecting to %s"
-                                   " at host %u.%u.%u.%u on port %d\n", rc,
+                                  " at host %pI4h on port %d\n", rc,
                                    libcfs_nid2str(peer_nid),
-                                   HIPQUAD(peer_ip), peer_port);
+                                  &peer_ip, peer_port);
                 break;
         }
 }
 EXPORT_SYMBOL(lnet_connect_console_error);
 
 int
-lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
+lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
             __u32 local_ip, __u32 peer_ip, int peer_port)
 {
         lnet_acceptor_connreq_t cr;
-        cfs_socket_t           *sock;
+       struct socket           *sock;
         int                     rc;
         int                     port;
         int                     fatal;
@@ -169,7 +166,7 @@ lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
              --port) {
                 /* Iterate through reserved ports. */
 
-                rc = libcfs_sock_connect(&sock, &fatal,
+               rc = lnet_sock_connect(&sock, &fatal,
                                          local_ip, port,
                                          peer_ip, peer_port);
                 if (rc != 0) {
@@ -198,7 +195,7 @@ lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
                        lnet_net_unlock(LNET_LOCK_EX);
                 }
 
-                rc = libcfs_sock_write(sock, &cr, sizeof(cr),
+               rc = lnet_sock_write(sock, &cr, sizeof(cr),
                                        accept_timeout);
                 if (rc != 0)
                         goto failed_sock;
@@ -210,16 +207,16 @@ lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
         rc = -EADDRINUSE;
         goto failed;
 
- failed_sock:
-        libcfs_sock_release(sock);
- failed:
-        lnet_connect_console_error(rc, peer_nid, peer_ip, peer_port);
-        return rc;
+failed_sock:
+       sock_release(sock);
+failed:
+       lnet_connect_console_error(rc, peer_nid, peer_ip, peer_port);
+       return rc;
 }
 EXPORT_SYMBOL(lnet_connect);
 
 static int
-lnet_accept(cfs_socket_t *sock, __u32 magic)
+lnet_accept(struct socket *sock, __u32 magic)
 {
         lnet_acceptor_connreq_t cr;
         __u32                   peer_ip;
@@ -231,7 +228,7 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
 
         LASSERT (sizeof(cr) <= 16);             /* not too big for the stack */
 
-        rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
+       rc = lnet_sock_getaddr(sock, true, &peer_ip, &peer_port);
         LASSERT (rc == 0);                      /* we succeeded before */
 
         if (!lnet_accept_magic(magic, LNET_PROTO_ACCEPTOR_MAGIC)) {
@@ -245,13 +242,13 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
                         memset (&cr, 0, sizeof(cr));
                         cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC;
                         cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
-                        rc = libcfs_sock_write(sock, &cr, sizeof(cr),
+                       rc = lnet_sock_write(sock, &cr, sizeof(cr),
                                                accept_timeout);
 
                         if (rc != 0)
                                 CERROR("Error sending magic+version in response"
-                                       "to LNET magic from %u.%u.%u.%u: %d\n",
-                                       HIPQUAD(peer_ip), rc);
+                                      "to LNET magic from %pI4h: %d\n",
+                                      &peer_ip, rc);
                         return -EPROTO;
                 }
 
@@ -262,20 +259,20 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
                 else
                         str = "unrecognised";
 
-                LCONSOLE_ERROR_MSG(0x11f, "Refusing connection from %u.%u.%u.%u"
+               LCONSOLE_ERROR_MSG(0x11f, "Refusing connection from %pI4h"
                                    " magic %08x: %s acceptor protocol\n",
-                                   HIPQUAD(peer_ip), magic, str);
+                                  &peer_ip, magic, str);
                 return -EPROTO;
         }
 
         flip = (magic != LNET_PROTO_ACCEPTOR_MAGIC);
 
-        rc = libcfs_sock_read(sock, &cr.acr_version,
+       rc = lnet_sock_read(sock, &cr.acr_version,
                               sizeof(cr.acr_version),
                               accept_timeout);
         if (rc != 0) {
                 CERROR("Error %d reading connection request version from "
-                       "%u.%u.%u.%u\n", rc, HIPQUAD(peer_ip));
+                      "%pI4h\n", rc, &peer_ip);
                 return -EIO;
         }
 
@@ -293,23 +290,23 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
                 cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC;
                 cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
 
-                rc = libcfs_sock_write(sock, &cr, sizeof(cr),
+               rc = lnet_sock_write(sock, &cr, sizeof(cr),
                                        accept_timeout);
 
                 if (rc != 0)
                         CERROR("Error sending magic+version in response"
-                               "to version %d from %u.%u.%u.%u: %d\n",
-                               peer_version, HIPQUAD(peer_ip), rc);
+                              "to version %d from %pI4h: %d\n",
+                              peer_version, &peer_ip, rc);
                 return -EPROTO;
         }
 
-        rc = libcfs_sock_read(sock, &cr.acr_nid,
+       rc = lnet_sock_read(sock, &cr.acr_nid,
                               sizeof(cr) -
                               offsetof(lnet_acceptor_connreq_t, acr_nid),
                               accept_timeout);
         if (rc != 0) {
                 CERROR("Error %d reading connection request from "
-                       "%u.%u.%u.%u\n", rc, HIPQUAD(peer_ip));
+                      "%pI4h\n", rc, &peer_ip);
                 return -EIO;
         }
 
@@ -321,23 +318,23 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
             ni->ni_nid != cr.acr_nid) { /* right NET, wrong NID! */
                 if (ni != NULL)
                         lnet_ni_decref(ni);
-                LCONSOLE_ERROR_MSG(0x120, "Refusing connection from %u.%u.%u.%u"
-                                   " for %s: No matching NI\n",
-                                   HIPQUAD(peer_ip), libcfs_nid2str(cr.acr_nid));
+               LCONSOLE_ERROR_MSG(0x120, "Refusing connection from %pI4h "
+                                  "for %s: No matching NI\n",
+                                  &peer_ip, libcfs_nid2str(cr.acr_nid));
                 return -EPERM;
         }
 
         if (ni->ni_lnd->lnd_accept == NULL) {
                 /* This catches a request for the loopback LND */
                 lnet_ni_decref(ni);
-                LCONSOLE_ERROR_MSG(0x121, "Refusing connection from %u.%u.%u.%u"
-                                  " for %s: NI doesn not accept IP connections\n",
-                                  HIPQUAD(peer_ip), libcfs_nid2str(cr.acr_nid));
+               LCONSOLE_ERROR_MSG(0x121, "Refusing connection from %pI4h "
+                                 "for %s: NI doesn not accept IP connections\n",
+                                 &peer_ip, libcfs_nid2str(cr.acr_nid));
                 return -EPERM;
         }
 
-        CDEBUG(D_NET, "Accept %s from %u.%u.%u.%u\n",
-               libcfs_nid2str(cr.acr_nid), HIPQUAD(peer_ip));
+       CDEBUG(D_NET, "Accept %s from %pI4h\n",
+              libcfs_nid2str(cr.acr_nid), &peer_ip);
 
         rc = ni->ni_lnd->lnd_accept(ni, sock);
 
@@ -348,7 +345,7 @@ lnet_accept(cfs_socket_t *sock, __u32 magic)
 static int
 lnet_acceptor(void *arg)
 {
-        cfs_socket_t  *newsock;
+       struct socket  *newsock;
         int            rc;
         __u32          magic;
         __u32          peer_ip;
@@ -359,7 +356,7 @@ lnet_acceptor(void *arg)
 
         cfs_block_allsigs();
 
-        rc = libcfs_sock_listen(&lnet_acceptor_state.pta_sock,
+       rc = lnet_sock_listen(&lnet_acceptor_state.pta_sock,
                                 0, accept_port, accept_backlog);
         if (rc != 0) {
                 if (rc == -EADDRINUSE)
@@ -385,7 +382,7 @@ lnet_acceptor(void *arg)
 
         while (!lnet_acceptor_state.pta_shutdown) {
 
-                rc = libcfs_sock_accept(&newsock, lnet_acceptor_state.pta_sock);
+               rc = lnet_sock_accept(&newsock, lnet_acceptor_state.pta_sock);
                 if (rc != 0) {
                         if (rc != -EAGAIN) {
                                 CWARN("Accept error %d: pausing...\n", rc);
@@ -394,30 +391,29 @@ lnet_acceptor(void *arg)
                         continue;
                 }
 
-                /* maybe we're waken up with libcfs_sock_abort_accept() */
-                if (lnet_acceptor_state.pta_shutdown) {
-                        libcfs_sock_release(newsock);
-                        break;
-                }
+               /* maybe we're waken up with lnet_sock_abort_accept() */
+               if (lnet_acceptor_state.pta_shutdown) {
+                       sock_release(newsock);
+                       break;
+               }
 
-                rc = libcfs_sock_getaddr(newsock, 1, &peer_ip, &peer_port);
+               rc = lnet_sock_getaddr(newsock, true, &peer_ip, &peer_port);
                 if (rc != 0) {
                         CERROR("Can't determine new connection's address\n");
                         goto failed;
                 }
 
                 if (secure && peer_port > LNET_ACCEPTOR_MAX_RESERVED_PORT) {
-                        CERROR("Refusing connection from %u.%u.%u.%u: "
-                               "insecure port %d\n",
-                               HIPQUAD(peer_ip), peer_port);
+                       CERROR("Refusing connection from %pI4h: "
+                              "insecure port %d\n", &peer_ip, peer_port);
                         goto failed;
                 }
 
-                rc = libcfs_sock_read(newsock, &magic, sizeof(magic),
+               rc = lnet_sock_read(newsock, &magic, sizeof(magic),
                                       accept_timeout);
                 if (rc != 0) {
                         CERROR("Error %d reading connection request from "
-                               "%u.%u.%u.%u\n", rc, HIPQUAD(peer_ip));
+                              "%pI4h\n", rc, &peer_ip);
                         goto failed;
                 }
 
@@ -427,14 +423,14 @@ lnet_acceptor(void *arg)
 
                 continue;
 
-        failed:
-                libcfs_sock_release(newsock);
-        }
+failed:
+               sock_release(newsock);
+       }
 
-        libcfs_sock_release(lnet_acceptor_state.pta_sock);
-        lnet_acceptor_state.pta_sock = NULL;
+       sock_release(lnet_acceptor_state.pta_sock);
+       lnet_acceptor_state.pta_sock = NULL;
 
-        CDEBUG(D_NET, "Acceptor stopping\n");
+       CDEBUG(D_NET, "Acceptor stopping\n");
 
        /* unblock lnet_acceptor_stop() */
        complete(&lnet_acceptor_state.pta_signal);
@@ -519,7 +515,7 @@ lnet_acceptor_stop(void)
                return;
 
        lnet_acceptor_state.pta_shutdown = 1;
-       libcfs_sock_abort_accept(lnet_acceptor_state.pta_sock);
+       wake_up_all(sk_sleep(lnet_acceptor_state.pta_sock->sk));
 
        /* block until acceptor signals exit */
        wait_for_completion(&lnet_acceptor_state.pta_signal);
index 424c660..9956886 100644 (file)
@@ -1,17 +1,9 @@
 my_sources =    api-ni.c config.c \
-               lib-me.c lib-msg.c lib-eq.c \
+               lib-me.c lib-msg.c lib-eq.c lib-socket.c \
                lib-md.c lib-ptl.c lib-move.c lo.c \
                router.c router_proc.c \
                acceptor.c peer.c net_fault.c
 
-
-if LIBLUSTRE
-noinst_LIBRARIES= liblnet.a
-liblnet_a_SOURCES= $(my_sources)
-liblnet_a_CPPFLAGS = $(LLCPPFLAGS)
-liblnet_a_CFLAGS = $(LLCFLAGS)
-endif
-
 if MODULES
 
 if LINUX
index a40f17b..d8a70f1 100644 (file)
@@ -1153,7 +1153,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
         __u32     *ipaddrs2;
         int        nip;
         char     **ifnames;
-        int        nif = libcfs_ipif_enumerate(&ifnames);
+       int        nif = lnet_ipif_enumerate(&ifnames);
         int        i;
         int        rc;
 
@@ -1163,7 +1163,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
         LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
         if (ipaddrs == NULL) {
                 CERROR("Can't allocate ipaddrs[%d]\n", nif);
-                libcfs_ipif_free_enumeration(ifnames, nif);
+               lnet_ipif_free_enumeration(ifnames, nif);
                 return -ENOMEM;
         }
 
@@ -1171,7 +1171,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                 if (!strcmp(ifnames[i], "lo"))
                         continue;
 
-                rc = libcfs_ipif_query(ifnames[i], &up,
+               rc = lnet_ipif_query(ifnames[i], &up,
                                        &ipaddrs[nip], &netmask);
                 if (rc != 0) {
                         CWARN("Can't query interface %s: %d\n",
@@ -1188,7 +1188,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                 nip++;
         }
 
-        libcfs_ipif_free_enumeration(ifnames, nif);
+       lnet_ipif_free_enumeration(ifnames, nif);
 
         if (nip == nif) {
                 *ipaddrsp = ipaddrs;
diff --git a/lnet/lnet/lib-socket.c b/lnet/lnet/lib-socket.c
new file mode 100644 (file)
index 0000000..80ca9a7
--- /dev/null
@@ -0,0 +1,632 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+#define DEBUG_SUBSYSTEM S_LNET
+
+#include <linux/if.h>
+#include <linux/in.h>
+#include <linux/net.h>
+#include <linux/file.h>
+#include <linux/pagemap.h>
+/* For sys_open & sys_close */
+#include <linux/syscalls.h>
+#include <net/sock.h>
+
+#include <libcfs/libcfs.h>
+#include <lnet/lib-lnet.h>
+
+static int
+kernel_sock_unlocked_ioctl(struct file *filp, int cmd, unsigned long arg)
+{
+       mm_segment_t oldfs = get_fs();
+       int err;
+
+       set_fs(KERNEL_DS);
+       err = filp->f_op->unlocked_ioctl(filp, cmd, arg);
+       set_fs(oldfs);
+
+       return err;
+}
+
+static int
+lnet_sock_ioctl(int cmd, unsigned long arg)
+{
+       struct file    *sock_filp;
+       struct socket  *sock;
+       int             fd = -1;
+       int             rc;
+
+       rc = sock_create(PF_INET, SOCK_STREAM, 0, &sock);
+       if (rc != 0) {
+               CERROR("Can't create socket: %d\n", rc);
+               return rc;
+       }
+
+#if !defined(HAVE_SOCK_ALLOC_FILE) && !defined(HAVE_SOCK_ALLOC_FILE_3ARGS)
+       fd = sock_map_fd(sock, 0);
+       if (fd < 0) {
+               rc = fd;
+               sock_release(sock);
+               goto out;
+       }
+       sock_filp = fget(fd);
+#else
+# ifdef HAVE_SOCK_ALLOC_FILE_3ARGS
+       sock_filp = sock_alloc_file(sock, 0, NULL);
+# else
+       sock_filp = sock_alloc_file(sock, 0);
+# endif
+#endif
+       if (!sock_filp) {
+               rc = -ENOMEM;
+               sock_release(sock);
+               goto out;
+       }
+
+       rc = kernel_sock_unlocked_ioctl(sock_filp, cmd, arg);
+
+       fput(sock_filp);
+out:
+       if (fd >= 0)
+               sys_close(fd);
+       return rc;
+}
+
+int
+lnet_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask)
+{
+       struct ifreq    ifr;
+       int             nob;
+       int             rc;
+       __u32           val;
+
+       nob = strnlen(name, IFNAMSIZ);
+       if (nob == IFNAMSIZ) {
+               CERROR("Interface name %s too long\n", name);
+               return -EINVAL;
+       }
+
+       CLASSERT(sizeof(ifr.ifr_name) >= IFNAMSIZ);
+
+       if (strlen(name) > sizeof(ifr.ifr_name)-1)
+               return -E2BIG;
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+       rc = lnet_sock_ioctl(SIOCGIFFLAGS, (unsigned long)&ifr);
+       if (rc != 0) {
+               CERROR("Can't get flags for interface %s\n", name);
+               return rc;
+       }
+
+       if ((ifr.ifr_flags & IFF_UP) == 0) {
+               CDEBUG(D_NET, "Interface %s down\n", name);
+               *up = 0;
+               *ip = *mask = 0;
+               return 0;
+       }
+       *up = 1;
+
+       if (strlen(name) > sizeof(ifr.ifr_name)-1)
+               return -E2BIG;
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+       ifr.ifr_addr.sa_family = AF_INET;
+       rc = lnet_sock_ioctl(SIOCGIFADDR, (unsigned long)&ifr);
+
+       if (rc != 0) {
+               CERROR("Can't get IP address for interface %s\n", name);
+               return rc;
+       }
+
+       val = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
+       *ip = ntohl(val);
+
+       if (strlen(name) > sizeof(ifr.ifr_name)-1)
+               return -E2BIG;
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+       ifr.ifr_addr.sa_family = AF_INET;
+       rc = lnet_sock_ioctl(SIOCGIFNETMASK, (unsigned long)&ifr);
+       if (rc != 0) {
+               CERROR("Can't get netmask for interface %s\n", name);
+               return rc;
+       }
+
+       val = ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr;
+       *mask = ntohl(val);
+
+       return 0;
+}
+EXPORT_SYMBOL(lnet_ipif_query);
+
+void
+lnet_ipif_free_enumeration(char **names, int n)
+{
+       int     i;
+
+       LASSERT(n > 0);
+
+       for (i = 0; i < n && names[i] != NULL; i++)
+               LIBCFS_FREE(names[i], IFNAMSIZ);
+
+       LIBCFS_FREE(names, n * sizeof(*names));
+}
+EXPORT_SYMBOL(lnet_ipif_free_enumeration);
+
+int
+lnet_ipif_enumerate(char ***namesp)
+{
+       /* Allocate and fill in 'names', returning # interfaces/error */
+       char          **names;
+       int             toobig;
+       int             nalloc;
+       int             nfound;
+       struct ifreq   *ifr;
+       struct ifconf   ifc;
+       int             rc;
+       int             nob;
+       int             i;
+
+       nalloc = 16;    /* first guess at max interfaces */
+       toobig = 0;
+       for (;;) {
+               if (nalloc * sizeof(*ifr) > PAGE_CACHE_SIZE) {
+                       toobig = 1;
+                       nalloc = PAGE_CACHE_SIZE/sizeof(*ifr);
+                       CWARN("Too many interfaces: only enumerating "
+                             "first %d\n", nalloc);
+               }
+
+               LIBCFS_ALLOC(ifr, nalloc * sizeof(*ifr));
+               if (ifr == NULL) {
+                       CERROR("ENOMEM enumerating up to %d interfaces\n",
+                              nalloc);
+                       rc = -ENOMEM;
+                       goto out0;
+               }
+
+               ifc.ifc_buf = (char *)ifr;
+               ifc.ifc_len = nalloc * sizeof(*ifr);
+
+               rc = lnet_sock_ioctl(SIOCGIFCONF, (unsigned long)&ifc);
+               if (rc < 0) {
+                       CERROR("Error %d enumerating interfaces\n", rc);
+                       goto out1;
+               }
+
+               LASSERT(rc == 0);
+
+               nfound = ifc.ifc_len/sizeof(*ifr);
+               LASSERT(nfound <= nalloc);
+
+               if (nfound < nalloc || toobig)
+                       break;
+
+               LIBCFS_FREE(ifr, nalloc * sizeof(*ifr));
+               nalloc *= 2;
+       }
+
+       if (nfound == 0)
+               goto out1;
+
+       LIBCFS_ALLOC(names, nfound * sizeof(*names));
+       if (names == NULL) {
+               rc = -ENOMEM;
+               goto out1;
+       }
+
+       for (i = 0; i < nfound; i++) {
+               nob = strnlen(ifr[i].ifr_name, IFNAMSIZ);
+               if (nob == IFNAMSIZ) {
+                       /* no space for terminating NULL */
+                       CERROR("interface name %.*s too long (%d max)\n",
+                              nob, ifr[i].ifr_name, IFNAMSIZ);
+                       rc = -ENAMETOOLONG;
+                       goto out2;
+               }
+
+               LIBCFS_ALLOC(names[i], IFNAMSIZ);
+               if (names[i] == NULL) {
+                       rc = -ENOMEM;
+                       goto out2;
+               }
+
+               memcpy(names[i], ifr[i].ifr_name, nob);
+               names[i][nob] = 0;
+       }
+
+       *namesp = names;
+       rc = nfound;
+
+ out2:
+       if (rc < 0)
+               lnet_ipif_free_enumeration(names, nfound);
+ out1:
+       LIBCFS_FREE(ifr, nalloc * sizeof(*ifr));
+ out0:
+       return rc;
+}
+EXPORT_SYMBOL(lnet_ipif_enumerate);
+
+int
+lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
+{
+       int             rc;
+       long            jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
+       unsigned long   then;
+       struct timeval  tv;
+
+       LASSERT(nob > 0);
+       /* Caller may pass a zero timeout if she thinks the socket buffer is
+        * empty enough to take the whole message immediately */
+
+       for (;;) {
+               struct kvec  iov = {
+                       .iov_base = buffer,
+                       .iov_len  = nob
+               };
+               struct msghdr msg = {
+                       .msg_flags      = (timeout == 0) ? MSG_DONTWAIT : 0
+               };
+
+               if (timeout != 0) {
+                       /* Set send timeout to remaining time */
+                       tv = (struct timeval) {
+                               .tv_sec = jiffies_left /
+                                         msecs_to_jiffies(MSEC_PER_SEC),
+                               .tv_usec = ((jiffies_left %
+                                            msecs_to_jiffies(MSEC_PER_SEC)) *
+                                            USEC_PER_SEC) /
+                                            msecs_to_jiffies(MSEC_PER_SEC)
+                       };
+
+                       rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
+                                              (char *)&tv, sizeof(tv));
+                       if (rc != 0) {
+                               CERROR("Can't set socket send timeout "
+                                      "%ld.%06d: %d\n",
+                                      (long)tv.tv_sec, (int)tv.tv_usec, rc);
+                               return rc;
+                       }
+               }
+
+               then = jiffies;
+               rc = kernel_sendmsg(sock, &msg, &iov, 1, nob);
+               jiffies_left -= jiffies - then;
+
+               if (rc == nob)
+                       return 0;
+
+               if (rc < 0)
+                       return rc;
+
+               if (rc == 0) {
+                       CERROR("Unexpected zero rc\n");
+                       return -ECONNABORTED;
+               }
+
+               if (jiffies_left <= 0)
+                       return -EAGAIN;
+
+               buffer = ((char *)buffer) + rc;
+               nob -= rc;
+       }
+       return 0;
+}
+EXPORT_SYMBOL(lnet_sock_write);
+
+int
+lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
+{
+       int             rc;
+       long            jiffies_left = timeout * msecs_to_jiffies(MSEC_PER_SEC);
+       unsigned long   then;
+       struct timeval  tv;
+
+       LASSERT(nob > 0);
+       LASSERT(jiffies_left > 0);
+
+       for (;;) {
+               struct kvec  iov = {
+                       .iov_base = buffer,
+                       .iov_len  = nob
+               };
+               struct msghdr msg = {
+                       .msg_flags      = 0
+               };
+
+               /* Set receive timeout to remaining time */
+               tv = (struct timeval) {
+                       .tv_sec = jiffies_left / msecs_to_jiffies(MSEC_PER_SEC),
+                       .tv_usec = ((jiffies_left %
+                                       msecs_to_jiffies(MSEC_PER_SEC)) *
+                                       USEC_PER_SEC) /
+                                       msecs_to_jiffies(MSEC_PER_SEC)
+               };
+               rc = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
+                                      (char *)&tv, sizeof(tv));
+               if (rc != 0) {
+                       CERROR("Can't set socket recv timeout %ld.%06d: %d\n",
+                              (long)tv.tv_sec, (int)tv.tv_usec, rc);
+                       return rc;
+               }
+
+               then = jiffies;
+               rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0);
+               jiffies_left -= jiffies - then;
+
+               if (rc < 0)
+                       return rc;
+
+               if (rc == 0)
+                       return -ECONNRESET;
+
+               buffer = ((char *)buffer) + rc;
+               nob -= rc;
+
+               if (nob == 0)
+                       return 0;
+
+               if (jiffies_left <= 0)
+                       return -ETIMEDOUT;
+       }
+}
+EXPORT_SYMBOL(lnet_sock_read);
+
+static int
+lnet_sock_create(struct socket **sockp, int *fatal,
+                __u32 local_ip, int local_port)
+{
+       struct sockaddr_in  locaddr;
+       struct socket      *sock;
+       int                 rc;
+       int                 option;
+
+       /* All errors are fatal except bind failure if the port is in use */
+       *fatal = 1;
+
+       rc = sock_create(PF_INET, SOCK_STREAM, 0, &sock);
+       *sockp = sock;
+       if (rc != 0) {
+               CERROR("Can't create socket: %d\n", rc);
+               return rc;
+       }
+
+       option = 1;
+       rc = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+                              (char *)&option, sizeof(option));
+       if (rc != 0) {
+               CERROR("Can't set SO_REUSEADDR for socket: %d\n", rc);
+               goto failed;
+       }
+
+       if (local_ip != 0 || local_port != 0) {
+               memset(&locaddr, 0, sizeof(locaddr));
+               locaddr.sin_family = AF_INET;
+               locaddr.sin_port = htons(local_port);
+               locaddr.sin_addr.s_addr = (local_ip == 0) ?
+                                         INADDR_ANY : htonl(local_ip);
+
+               rc = kernel_bind(sock, (struct sockaddr *)&locaddr,
+                                sizeof(locaddr));
+               if (rc == -EADDRINUSE) {
+                       CDEBUG(D_NET, "Port %d already in use\n", local_port);
+                       *fatal = 0;
+                       goto failed;
+               }
+               if (rc != 0) {
+                       CERROR("Error trying to bind to port %d: %d\n",
+                              local_port, rc);
+                       goto failed;
+               }
+       }
+       return 0;
+
+failed:
+       sock_release(sock);
+       return rc;
+}
+
+int
+lnet_sock_setbuf(struct socket *sock, int txbufsize, int rxbufsize)
+{
+       int                 option;
+       int                 rc;
+
+       if (txbufsize != 0) {
+               option = txbufsize;
+               rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
+                                      (char *)&option, sizeof(option));
+               if (rc != 0) {
+                       CERROR("Can't set send buffer %d: %d\n",
+                               option, rc);
+                       return rc;
+               }
+       }
+
+       if (rxbufsize != 0) {
+               option = rxbufsize;
+               rc = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
+                                      (char *)&option, sizeof(option));
+               if (rc != 0) {
+                       CERROR("Can't set receive buffer %d: %d\n",
+                               option, rc);
+                       return rc;
+               }
+       }
+       return 0;
+}
+EXPORT_SYMBOL(lnet_sock_setbuf);
+
+int
+lnet_sock_getaddr(struct socket *sock, bool remote, __u32 *ip, int *port)
+{
+       struct sockaddr_in sin;
+       int                len = sizeof(sin);
+       int                rc;
+
+       if (remote)
+               rc = kernel_getpeername(sock, (struct sockaddr *)&sin, &len);
+       else
+               rc = kernel_getsockname(sock, (struct sockaddr *)&sin, &len);
+       if (rc != 0) {
+               CERROR("Error %d getting sock %s IP/port\n",
+                       rc, remote ? "peer" : "local");
+               return rc;
+       }
+
+       if (ip != NULL)
+               *ip = ntohl(sin.sin_addr.s_addr);
+
+       if (port != NULL)
+               *port = ntohs(sin.sin_port);
+
+       return 0;
+}
+EXPORT_SYMBOL(lnet_sock_getaddr);
+
+int
+lnet_sock_getbuf(struct socket *sock, int *txbufsize, int *rxbufsize)
+{
+       if (txbufsize != NULL)
+               *txbufsize = sock->sk->sk_sndbuf;
+
+       if (rxbufsize != NULL)
+               *rxbufsize = sock->sk->sk_rcvbuf;
+
+       return 0;
+}
+EXPORT_SYMBOL(lnet_sock_getbuf);
+
+int
+lnet_sock_listen(struct socket **sockp,
+                  __u32 local_ip, int local_port, int backlog)
+{
+       int      fatal;
+       int      rc;
+
+       rc = lnet_sock_create(sockp, &fatal, local_ip, local_port);
+       if (rc != 0) {
+               if (!fatal)
+                       CERROR("Can't create socket: port %d already in use\n",
+                              local_port);
+               return rc;
+       }
+
+       rc = kernel_listen(*sockp, backlog);
+       if (rc == 0)
+               return 0;
+
+       CERROR("Can't set listen backlog %d: %d\n", backlog, rc);
+       sock_release(*sockp);
+       return rc;
+}
+
+int
+lnet_sock_accept(struct socket **newsockp, struct socket *sock)
+{
+       wait_queue_t   wait;
+       struct socket *newsock;
+       int            rc;
+
+       init_waitqueue_entry(&wait, current);
+
+       /* XXX this should add a ref to sock->ops->owner, if
+        * TCP could be a module */
+       rc = sock_create_lite(PF_PACKET, sock->type, IPPROTO_TCP, &newsock);
+       if (rc) {
+               CERROR("Can't allocate socket\n");
+               return rc;
+       }
+
+       newsock->ops = sock->ops;
+       add_wait_queue(sk_sleep(sock->sk), &wait);
+
+       rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
+       if (rc == -EAGAIN) {
+               /* Nothing ready, so wait for activity */
+               schedule();
+               rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
+       }
+
+       remove_wait_queue(sk_sleep(sock->sk), &wait);
+       set_current_state(TASK_RUNNING);
+
+       if (rc != 0)
+               goto failed;
+
+       *newsockp = newsock;
+       return 0;
+
+failed:
+       sock_release(newsock);
+       return rc;
+}
+
+int
+lnet_sock_connect(struct socket **sockp, int *fatal,
+                 __u32 local_ip, int local_port,
+                 __u32 peer_ip, int peer_port)
+{
+       struct sockaddr_in  srvaddr;
+       int                 rc;
+
+       rc = lnet_sock_create(sockp, fatal, local_ip, local_port);
+       if (rc != 0)
+               return rc;
+
+       memset(&srvaddr, 0, sizeof(srvaddr));
+       srvaddr.sin_family = AF_INET;
+       srvaddr.sin_port = htons(peer_port);
+       srvaddr.sin_addr.s_addr = htonl(peer_ip);
+
+       rc = kernel_connect(*sockp, (struct sockaddr *)&srvaddr,
+                           sizeof(srvaddr), 0);
+       if (rc == 0)
+               return 0;
+
+       /* EADDRNOTAVAIL probably means we're already connected to the same
+        * peer/port on the same local port on a differently typed
+        * connection.  Let our caller retry with a different local
+        * port... */
+       *fatal = !(rc == -EADDRNOTAVAIL);
+
+       CDEBUG_LIMIT(*fatal ? D_NETERROR : D_NET,
+              "Error %d connecting %pI4h/%d -> %pI4h/%d\n", rc,
+              &local_ip, local_port, &peer_ip, peer_port);
+
+       sock_release(*sockp);
+       return rc;
+}
index b9d5dec..8d47825 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/proc_fs.h>
 #include <linux/rwsem.h>
 #include <linux/spinlock.h>
+#include <linux/seq_file.h>
 
 #include <lustre/lustre_idl.h>
 
index 83b26e3..9ada5b1 100644 (file)
@@ -48,6 +48,7 @@
 #include <lustre_mdc.h>
 #include <lustre_intent.h>
 #include <linux/compat.h>
+#include <linux/aio.h>
 
 #include "vvp_internal.h"
 #include "range_lock.h"
index 9fa1622..b7f9b23 100644 (file)
@@ -55,6 +55,7 @@
 #include <linux/hash.h>
 #include <linux/mutex.h>
 #include <linux/sunrpc/cache.h>
+#include <net/sock.h>
 
 #include <obd.h>
 #include <obd_class.h>