-/* -*- 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.
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, Whamcloud, Inc.
+ * Copyright (c) 2012, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
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;
}
-#ifdef HAVE_SOCK_MAP_FD_2ARG
- fd = sock_map_fd(sock,0);
+#if !defined(HAVE_SOCK_ALLOC_FILE) && !defined(HAVE_SOCK_ALLOC_FILE_3ARGS)
+# ifdef HAVE_SOCK_MAP_FD_2ARG
+ fd = sock_map_fd(sock,0);
+# else
+ fd = sock_map_fd(sock);
+# endif
+ 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
- lock_kernel();
- rc = sock_filp->f_op->ioctl(sock_filp->f_dentry->d_inode,
- sock_filp, cmd, arg);
- unlock_kernel();
-#endif
- 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;
}
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(sk_sleep(sock->sk), &wait);
+ add_wait_queue(cfs_sk_sleep(sock->sk), &wait);
rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
if (rc == -EAGAIN) {
rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
}
- remove_wait_queue(sk_sleep(sock->sk), &wait);
+ remove_wait_queue(cfs_sk_sleep(sock->sk), &wait);
set_current_state(TASK_RUNNING);
if (rc != 0)
void
libcfs_sock_abort_accept (struct socket *sock)
{
- wake_up_all(sk_sleep(sock->sk));
+ wake_up_all(cfs_sk_sleep(sock->sk));
}
EXPORT_SYMBOL(libcfs_sock_abort_accept);