aboutsummaryrefslogtreecommitdiff
blob: a8797a05b60cf405ab71682b3493a3b4f063be45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
From 18036cc8a9ddc00c269b9b3b7ea25529a0a25e9b Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Wed, 13 Feb 2013 02:45:16 -0500
Subject: [PATCH 02/11] LU-2800 libcfs: use sock_alloc_file instead of
 sock_map_fd

v2.6.27 added a second argument to sock_map_fd. Earlier versions are
out of scope and we can remove the test for the number of arguments.

Commit 56b31d1c (v3.7) made sock_map_fd() static and exported
sock_alloc_file() instead. For our purposes, we didn't want to expose
the file in the descriptor table anyway.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Change-Id: I4e12da8c102b5d682db9658187330ae601b00a21
---
 libcfs/autoconf/lustre-libcfs.m4  | 18 ++++++++++--------
 libcfs/libcfs/linux/linux-tcpip.c | 17 ++++++++++++-----
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4
index 312542d..380fd5b 100644
--- a/libcfs/autoconf/lustre-libcfs.m4
+++ b/libcfs/autoconf/lustre-libcfs.m4
@@ -500,18 +500,19 @@ LB_LINUX_TRY_COMPILE([
 ])
 
 # 2.6.27 have second argument to sock_map_fd
-AC_DEFUN([LIBCFS_SOCK_MAP_FD_2ARG],
-[AC_MSG_CHECKING([sock_map_fd have second argument])
+# 3.7 (56b31d1c) un-exported sock_map_fd in favor of sock_alloc_file
+AC_DEFUN([LIBCFS_SOCK_ALLOC_FILE],
+[AC_MSG_CHECKING([sock_alloc_file is exported])
 LB_LINUX_TRY_COMPILE([
 	#include <linux/net.h>
 ],[
-        sock_map_fd(NULL, 0);
+	sock_alloc_file(NULL, 0, NULL);
 ],[
-        AC_MSG_RESULT(yes)
-        AC_DEFINE(HAVE_SOCK_MAP_FD_2ARG, 1,
-                  [sock_map_fd have second argument])
+	AC_MSG_RESULT(yes)
+	AC_DEFINE(HAVE_SOCK_ALLOC_FILE, 1,
+		  [sock_alloc_file is exported])
 ],[
-        AC_MSG_RESULT(NO)
+	AC_MSG_RESULT(NO)
 ])
 ])
 
@@ -834,7 +835,6 @@ LIBCFS_CPU_TOPOLOGY
 LIBCFS_STRUCT_SHASH_ALG
 # 2.6.30
 LIBCFS_FUNC_UNSHARE_FS_STRUCT
-LIBCFS_SOCK_MAP_FD_2ARG
 # 2.6.31
 LIBCFS_HAVE_SET_MEMS_ALLOWED
 # 2.6.32
@@ -850,6 +850,8 @@ LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
 LC_SK_SLEEP
 # 2.6.40 fc15
 LC_SHRINK_CONTROL
+# 3.7
+LIBCFS_SOCK_ALLOC_FILE
 ])
 
 #
diff --git a/libcfs/libcfs/linux/linux-tcpip.c b/libcfs/libcfs/linux/linux-tcpip.c
index 0a31b55..b83ed84 100644
--- a/libcfs/libcfs/linux/linux-tcpip.c
+++ b/libcfs/libcfs/linux/linux-tcpip.c
@@ -49,7 +49,9 @@ libcfs_sock_ioctl(int cmd, unsigned long arg)
 {
         mm_segment_t   oldmm = get_fs();
         struct socket  *sock;
+#ifndef HAVE_SOCK_ALLOC_FILE
         int             fd;
+#endif
         int             rc;
         struct file     *sock_filp;
 
@@ -59,11 +61,8 @@ libcfs_sock_ioctl(int cmd, unsigned long arg)
                 return rc;
         }
 
-#ifdef HAVE_SOCK_MAP_FD_2ARG
+#ifndef HAVE_SOCK_ALLOC_FILE
         fd = sock_map_fd(sock,0);
-#else
-        fd = sock_map_fd(sock);
-#endif
         if (fd < 0) {
                 rc = fd;
                 sock_release(sock);
@@ -75,7 +74,13 @@ libcfs_sock_ioctl(int cmd, unsigned long arg)
                 rc = -ENOMEM;
                 goto out_fd;
         }
-
+#else
+	sock_filp = sock_alloc_file(sock, 0, NULL);
+	if (IS_ERR(sock_filp)) {
+		rc = PTR_ERR(sock_filp);
+		goto out;
+	}
+#endif
 	set_fs(KERNEL_DS);
 	if (sock_filp->f_op->unlocked_ioctl)
 		rc = sock_filp->f_op->unlocked_ioctl(sock_filp, cmd, arg);
@@ -83,8 +88,10 @@ libcfs_sock_ioctl(int cmd, unsigned long arg)
 
         fput(sock_filp);
 
+#ifndef HAVE_SOCK_ALLOC_FILE
  out_fd:
         sys_close(fd);
+#endif
  out:
         return rc;
 }
-- 
1.8.1.5