diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fcntl.c | 9 | ||||
-rw-r--r-- | fs/file.c | 34 | ||||
-rw-r--r-- | fs/open.c | 8 |
3 files changed, 22 insertions, 29 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c index dc4a7007f4e7..03c789560fb8 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
@@ -73,8 +73,8 @@ repeat: | |||
73 | * orig_start..fdt->next_fd | 73 | * orig_start..fdt->next_fd |
74 | */ | 74 | */ |
75 | start = orig_start; | 75 | start = orig_start; |
76 | if (start < fdt->next_fd) | 76 | if (start < files->next_fd) |
77 | start = fdt->next_fd; | 77 | start = files->next_fd; |
78 | 78 | ||
79 | newfd = start; | 79 | newfd = start; |
80 | if (start < fdt->max_fdset) { | 80 | if (start < fdt->max_fdset) { |
@@ -102,9 +102,8 @@ repeat: | |||
102 | * we reacquire the fdtable pointer and use it while holding | 102 | * we reacquire the fdtable pointer and use it while holding |
103 | * the lock, no one can free it during that time. | 103 | * the lock, no one can free it during that time. |
104 | */ | 104 | */ |
105 | fdt = files_fdtable(files); | 105 | if (start <= files->next_fd) |
106 | if (start <= fdt->next_fd) | 106 | files->next_fd = newfd + 1; |
107 | fdt->next_fd = newfd + 1; | ||
108 | 107 | ||
109 | error = newfd; | 108 | error = newfd; |
110 | 109 | ||
@@ -125,7 +125,8 @@ static void free_fdtable_rcu(struct rcu_head *rcu) | |||
125 | kmem_cache_free(files_cachep, fdt->free_files); | 125 | kmem_cache_free(files_cachep, fdt->free_files); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (fdt->max_fdset <= __FD_SETSIZE && fdt->max_fds <= NR_OPEN_DEFAULT) { | 128 | if (fdt->max_fdset <= EMBEDDED_FD_SET_SIZE && |
129 | fdt->max_fds <= NR_OPEN_DEFAULT) { | ||
129 | /* | 130 | /* |
130 | * The fdtable was embedded | 131 | * The fdtable was embedded |
131 | */ | 132 | */ |
@@ -155,8 +156,9 @@ static void free_fdtable_rcu(struct rcu_head *rcu) | |||
155 | 156 | ||
156 | void free_fdtable(struct fdtable *fdt) | 157 | void free_fdtable(struct fdtable *fdt) |
157 | { | 158 | { |
158 | if (fdt->free_files || fdt->max_fdset > __FD_SETSIZE || | 159 | if (fdt->free_files || |
159 | fdt->max_fds > NR_OPEN_DEFAULT) | 160 | fdt->max_fdset > EMBEDDED_FD_SET_SIZE || |
161 | fdt->max_fds > NR_OPEN_DEFAULT) | ||
160 | call_rcu(&fdt->rcu, free_fdtable_rcu); | 162 | call_rcu(&fdt->rcu, free_fdtable_rcu); |
161 | } | 163 | } |
162 | 164 | ||
@@ -199,7 +201,6 @@ static void copy_fdtable(struct fdtable *nfdt, struct fdtable *fdt) | |||
199 | (nfdt->max_fds - fdt->max_fds) * | 201 | (nfdt->max_fds - fdt->max_fds) * |
200 | sizeof(struct file *)); | 202 | sizeof(struct file *)); |
201 | } | 203 | } |
202 | nfdt->next_fd = fdt->next_fd; | ||
203 | } | 204 | } |
204 | 205 | ||
205 | /* | 206 | /* |
@@ -220,11 +221,9 @@ fd_set * alloc_fdset(int num) | |||
220 | 221 | ||
221 | void free_fdset(fd_set *array, int num) | 222 | void free_fdset(fd_set *array, int num) |
222 | { | 223 | { |
223 | int size = num / 8; | 224 | if (num <= EMBEDDED_FD_SET_SIZE) /* Don't free an embedded fdset */ |
224 | |||
225 | if (num <= __FD_SETSIZE) /* Don't free an embedded fdset */ | ||
226 | return; | 225 | return; |
227 | else if (size <= PAGE_SIZE) | 226 | else if (num <= 8 * PAGE_SIZE) |
228 | kfree(array); | 227 | kfree(array); |
229 | else | 228 | else |
230 | vfree(array); | 229 | vfree(array); |
@@ -237,22 +236,17 @@ static struct fdtable *alloc_fdtable(int nr) | |||
237 | fd_set *new_openset = NULL, *new_execset = NULL; | 236 | fd_set *new_openset = NULL, *new_execset = NULL; |
238 | struct file **new_fds; | 237 | struct file **new_fds; |
239 | 238 | ||
240 | fdt = kmalloc(sizeof(*fdt), GFP_KERNEL); | 239 | fdt = kzalloc(sizeof(*fdt), GFP_KERNEL); |
241 | if (!fdt) | 240 | if (!fdt) |
242 | goto out; | 241 | goto out; |
243 | memset(fdt, 0, sizeof(*fdt)); | ||
244 | 242 | ||
245 | nfds = __FD_SETSIZE; | 243 | nfds = 8 * L1_CACHE_BYTES; |
246 | /* Expand to the max in easy steps */ | 244 | /* Expand to the max in easy steps */ |
247 | do { | 245 | while (nfds <= nr) { |
248 | if (nfds < (PAGE_SIZE * 8)) | 246 | nfds = nfds * 2; |
249 | nfds = PAGE_SIZE * 8; | 247 | if (nfds > NR_OPEN) |
250 | else { | 248 | nfds = NR_OPEN; |
251 | nfds = nfds * 2; | 249 | } |
252 | if (nfds > NR_OPEN) | ||
253 | nfds = NR_OPEN; | ||
254 | } | ||
255 | } while (nfds <= nr); | ||
256 | 250 | ||
257 | new_openset = alloc_fdset(nfds); | 251 | new_openset = alloc_fdset(nfds); |
258 | new_execset = alloc_fdset(nfds); | 252 | new_execset = alloc_fdset(nfds); |
@@ -973,7 +973,7 @@ repeat: | |||
973 | fdt = files_fdtable(files); | 973 | fdt = files_fdtable(files); |
974 | fd = find_next_zero_bit(fdt->open_fds->fds_bits, | 974 | fd = find_next_zero_bit(fdt->open_fds->fds_bits, |
975 | fdt->max_fdset, | 975 | fdt->max_fdset, |
976 | fdt->next_fd); | 976 | files->next_fd); |
977 | 977 | ||
978 | /* | 978 | /* |
979 | * N.B. For clone tasks sharing a files structure, this test | 979 | * N.B. For clone tasks sharing a files structure, this test |
@@ -998,7 +998,7 @@ repeat: | |||
998 | 998 | ||
999 | FD_SET(fd, fdt->open_fds); | 999 | FD_SET(fd, fdt->open_fds); |
1000 | FD_CLR(fd, fdt->close_on_exec); | 1000 | FD_CLR(fd, fdt->close_on_exec); |
1001 | fdt->next_fd = fd + 1; | 1001 | files->next_fd = fd + 1; |
1002 | #if 1 | 1002 | #if 1 |
1003 | /* Sanity check */ | 1003 | /* Sanity check */ |
1004 | if (fdt->fd[fd] != NULL) { | 1004 | if (fdt->fd[fd] != NULL) { |
@@ -1019,8 +1019,8 @@ static void __put_unused_fd(struct files_struct *files, unsigned int fd) | |||
1019 | { | 1019 | { |
1020 | struct fdtable *fdt = files_fdtable(files); | 1020 | struct fdtable *fdt = files_fdtable(files); |
1021 | __FD_CLR(fd, fdt->open_fds); | 1021 | __FD_CLR(fd, fdt->open_fds); |
1022 | if (fd < fdt->next_fd) | 1022 | if (fd < files->next_fd) |
1023 | fdt->next_fd = fd; | 1023 | files->next_fd = fd; |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | void fastcall put_unused_fd(unsigned int fd) | 1026 | void fastcall put_unused_fd(unsigned int fd) |