-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
*
- * Copyright (C) 2005 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * This file is part of Lustre, http://www.lustre.org.
+ * 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.
*
- * Lustre is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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).
*
- * Lustre 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 for more details.
+ * 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
*
- * You should have received a copy of the GNU General Public License
- * along with Lustre; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.
*/
#define DEBUG_SUBSYSTEM S_LNET
#include <linux/in.h>
#include <linux/file.h>
/* For sys_open & sys_close */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
#include <linux/syscalls.h>
-#else
-#include <linux/fs.h>
+
+#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) {
return rc;
}
- fd = sock_map_fd(sock);
- if (fd < 0) {
- rc = fd;
- sock_release(sock);
- goto out;
- }
-
- sock_filp = fget(fd);
+#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;
- 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;
}
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) {
*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);
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);
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) {
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)
{
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;
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);
* 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);