X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Flibcfs%2Flinux%2Flinux-tcpip.c;h=de1a63f339054e5a5bb26f68c3ea70f90862c87d;hb=9ed879b12c07d1f4de2fe55f35318ed8cdd8995c;hp=0ac56c636d2f77a60649ec048d11b92a6ac8daa0;hpb=62ef9c949753efb9535fa5b1eb2eb38ec663917f;p=fs%2Flustre-release.git diff --git a/libcfs/libcfs/linux/linux-tcpip.c b/libcfs/libcfs/linux/linux-tcpip.c index 0ac56c6..de1a63f 100644 --- a/libcfs/libcfs/linux/linux-tcpip.c +++ b/libcfs/libcfs/linux/linux-tcpip.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * 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/ @@ -42,20 +42,23 @@ #include #include /* For sys_open & sys_close */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) #include -#else -#include + +#ifndef HAVE_SK_SLEEP +static inline wait_queue_head_t *sk_sleep(struct sock *sk) +{ + return sk->sk_sleep; +} #endif int libcfs_sock_ioctl(int cmd, unsigned long arg) { - mm_segment_t oldmm = get_fs(); - struct socket *sock; - int fd; - int rc; - struct file *sock_filp; + 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) { @@ -63,42 +66,38 @@ libcfs_sock_ioctl(int cmd, unsigned long arg) return rc; } -#ifdef HAVE_SOCK_MAP_FD_2ARG - fd = sock_map_fd(sock,0); +#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 - fd = sock_map_fd(sock); +# 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 (fd < 0) { - rc = fd; - sock_release(sock); - goto out; - } - - sock_filp = fget(fd); if (!sock_filp) { rc = -ENOMEM; - goto out_fd; + sock_release(sock); + goto out; } - set_fs(KERNEL_DS); -#ifdef HAVE_UNLOCKED_IOCTL - if (sock_filp->f_op->unlocked_ioctl) - rc = sock_filp->f_op->unlocked_ioctl(sock_filp, cmd, arg); - else -#endif - { - lock_kernel(); - rc =sock_filp->f_op->ioctl(sock_filp->f_dentry->d_inode, - sock_filp, cmd, arg); - unlock_kernel(); - } - set_fs(oldmm); + 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_fd: - sys_close(fd); out: + if (fd >= 0) + sys_close(fd); + return rc; } @@ -118,7 +117,10 @@ libcfs_ipif_query (char *name, int *up, __u32 *ip, __u32 *mask) CLASSERT (sizeof(ifr.ifr_name) >= IFNAMSIZ); - strcpy(ifr.ifr_name, name); + 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) { @@ -135,7 +137,10 @@ libcfs_ipif_query (char *name, int *up, __u32 *ip, __u32 *mask) *up = 1; - strcpy(ifr.ifr_name, name); + 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); @@ -147,7 +152,10 @@ libcfs_ipif_query (char *name, int *up, __u32 *ip, __u32 *mask) val = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; *ip = ntohl(val); - strcpy(ifr.ifr_name, name); + 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); @@ -182,12 +190,12 @@ libcfs_ipif_enumerate (char ***namesp) nalloc = 16; /* first guess at max interfaces */ toobig = 0; for (;;) { - if (nalloc * sizeof(*ifr) > CFS_PAGE_SIZE) { - toobig = 1; - nalloc = CFS_PAGE_SIZE/sizeof(*ifr); - CWARN("Too many interfaces: only enumerating first %d\n", - nalloc); - } + 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) { @@ -226,8 +234,6 @@ libcfs_ipif_enumerate (char ***namesp) rc = -ENOMEM; goto out1; } - /* NULL out all names[i] */ - memset (names, 0, nfound * sizeof(*names)); for (i = 0; i < nfound; i++) { @@ -292,20 +298,14 @@ libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout) /* Caller may pass a zero timeout if she thinks the socket buffer is * empty enough to take the whole message immediately */ - for (;;) { - struct iovec iov = { - .iov_base = buffer, - .iov_len = nob - }; - struct msghdr msg = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = NULL, - .msg_controllen = 0, - .msg_flags = (timeout == 0) ? MSG_DONTWAIT : 0 - }; + 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 */ @@ -325,11 +325,9 @@ libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout) } } - set_fs (KERNEL_DS); - then = jiffies; - rc = sock_sendmsg (sock, &msg, iov.iov_len); - ticks -= jiffies - then; - set_fs (oldmm); + then = jiffies; + rc = kernel_sendmsg(sock, &msg, &iov, 1, nob); + ticks -= jiffies - then; if (rc == nob) return 0; @@ -366,19 +364,13 @@ libcfs_sock_read (struct socket *sock, void *buffer, int nob, int timeout) LASSERT (ticks > 0); for (;;) { - struct iovec iov = { - .iov_base = buffer, - .iov_len = nob - }; - struct msghdr msg = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = NULL, - .msg_controllen = 0, - .msg_flags = 0 - }; + struct kvec iov = { + .iov_base = buffer, + .iov_len = nob + }; + struct msghdr msg = { + .msg_flags = 0 + }; /* Set receive timeout to remaining time */ tv = (struct timeval) { @@ -395,11 +387,9 @@ libcfs_sock_read (struct socket *sock, void *buffer, int nob, int timeout) return rc; } - set_fs(KERNEL_DS); - then = jiffies; - rc = sock_recvmsg(sock, &msg, iov.iov_len, 0); - ticks -= jiffies - then; - set_fs(oldmm); + then = jiffies; + rc = kernel_recvmsg(sock, &msg, &iov, 1, nob, 0); + ticks -= jiffies - then; if (rc < 0) return rc; @@ -585,22 +575,6 @@ libcfs_sock_listen (struct socket **sockp, EXPORT_SYMBOL(libcfs_sock_listen); -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) -int sock_create_lite(int family, int type, int protocol, struct socket **res) -{ - struct socket *sock; - - sock = sock_alloc(); - if (sock == NULL) - return -ENOMEM; - - sock->type = type; - *res = sock; - - return 0; -} -#endif - int libcfs_sock_accept (struct socket **newsockp, struct socket *sock) { @@ -620,18 +594,18 @@ libcfs_sock_accept (struct socket **newsockp, struct socket *sock) newsock->ops = sock->ops; - set_current_state(TASK_INTERRUPTIBLE); - add_wait_queue(sock->sk->sk_sleep, &wait); + 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); - } + 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(sock->sk->sk_sleep, &wait); - set_current_state(TASK_RUNNING); + remove_wait_queue(sk_sleep(sock->sk), &wait); + set_current_state(TASK_RUNNING); if (rc != 0) goto failed; @@ -649,7 +623,7 @@ EXPORT_SYMBOL(libcfs_sock_accept); void libcfs_sock_abort_accept (struct socket *sock) { - wake_up_all(sock->sk->sk_sleep); + wake_up_all(sk_sleep(sock->sk)); } EXPORT_SYMBOL(libcfs_sock_abort_accept); @@ -683,7 +657,7 @@ libcfs_sock_connect (struct socket **sockp, int *fatal, * port... */ *fatal = !(rc == -EADDRNOTAVAIL); - CDEBUG(*fatal ? D_NETERROR : D_NET, + 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);