Whamcloud - gitweb
LU-13344 lnet: stop using struct timeval
[fs/lustre-release.git] / lnet / lnet / lib-socket.c
index b801b47..a3628da 100644 (file)
 #include <net/sock.h>
 #include <linux/inetdevice.h>
 
+#include <libcfs/linux/linux-time.h>
 #include <libcfs/libcfs.h>
 #include <lnet/lib-lnet.h>
 
-/*
- * kernel 5.1: commit 7f1bc6e95d7840d4305595b3e4025cddda88cee5
- * Y2038 64-bit time.
- *  SO_TIMESTAMP, SO_TIMESTAMPNS and SO_TIMESTAMPING options, the
- *  way they are currently defined, are not y2038 safe.
- *  Subsequent patches in the series add new y2038 safe versions
- *  of these options which provide 64 bit timestamps on all
- *  architectures uniformly.
- *  Hence, rename existing options with OLD tag suffixes.
- *
- * NOTE: When updating to timespec64 change change these to '_NEW'.
- *
- */
-#ifndef SO_SNDTIMEO
-#define SO_SNDTIMEO SO_SNDTIMEO_OLD
-#endif
-
-#ifndef SO_RCVTIMEO
-#define SO_RCVTIMEO SO_RCVTIMEO_OLD
-#endif
-
 int
 lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
 {
-       int             rc;
-       long            jiffies_left = cfs_time_seconds(timeout);
-       unsigned long   then;
-       struct timeval  tv;
+       int rc;
+       long jiffies_left = cfs_time_seconds(timeout);
+       unsigned long then;
 
        LASSERT(nob > 0);
        /* Caller may pass a zero timeout if she thinks the socket buffer is
@@ -87,16 +66,12 @@ lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout)
                };
 
                if (timeout != 0) {
+                       struct sock *sk = sock->sk;
+
                        /* Set send timeout to remaining time */
-                       jiffies_to_timeval(jiffies_left, &tv);
-                       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;
-                       }
+                       lock_sock(sk);
+                       sk->sk_sndtimeo = jiffies_left;
+                       release_sock(sk);
                }
 
                then = jiffies;
@@ -127,10 +102,9 @@ EXPORT_SYMBOL(lnet_sock_write);
 int
 lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
 {
-       int             rc;
-       long            jiffies_left = cfs_time_seconds(timeout);
-       unsigned long   then;
-       struct timeval  tv;
+       int rc;
+       long jiffies_left = cfs_time_seconds(timeout);
+       unsigned long then;
 
        LASSERT(nob > 0);
        LASSERT(jiffies_left > 0);
@@ -143,16 +117,12 @@ lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout)
                struct msghdr msg = {
                        .msg_flags      = 0
                };
+               struct sock *sk = sock->sk;
 
                /* Set receive timeout to remaining time */
-               jiffies_to_timeval(jiffies_left, &tv);
-               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;
-               }
+               lock_sock(sk);
+               sk->sk_rcvtimeo = jiffies_left;
+               release_sock(sk);
 
                then = jiffies;
                rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0);
@@ -376,25 +346,17 @@ lnet_sock_listen(int local_port, int backlog, struct net *ns)
 
 struct socket *
 lnet_sock_connect(int interface, int local_port,
-                 __u32 peer_ip, int peer_port,
+                 struct sockaddr *peeraddr,
                  struct net *ns)
 {
        struct socket *sock;
-       struct sockaddr_in srvaddr;
        int 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);
-
-       sock = lnet_sock_create(interface, (struct sockaddr *)&srvaddr,
-                               local_port, ns);
+       sock = lnet_sock_create(interface, peeraddr, local_port, ns);
        if (IS_ERR(sock))
                return sock;
 
-       rc = kernel_connect(sock, (struct sockaddr *)&srvaddr,
-                           sizeof(srvaddr), 0);
+       rc = kernel_connect(sock, peeraddr, sizeof(struct sockaddr_in), 0);
        if (rc == 0)
                return sock;
 
@@ -404,8 +366,8 @@ lnet_sock_connect(int interface, int local_port,
         * port... */
 
        CDEBUG_LIMIT(rc == -EADDRNOTAVAIL ? D_NET : D_NETERROR,
-                    "Error %d connecting %d -> %pI4h/%d\n", rc,
-                    local_port, &peer_ip, peer_port);
+                    "Error %d connecting %d -> %pISp\n", rc,
+                    local_port, peeraddr);
 
        sock_release(sock);
        return ERR_PTR(rc);