aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/dir.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-11-16 21:46:28 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-11-16 21:46:28 -0500
commit1d6636502b23a964f4e5aac5237d1bbb76a9f912 (patch)
treea904be940c83b385be9cdf33fc62041b5c56f7f5 /fs/nfs/dir.c
parentd33fdee4d090076462cfe25473f7139c3204b16e (diff)
parent04e4bd1c67f941d81bff78a3b6b94194f081b7df (diff)
Merge branch 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6
* 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6: nfs: Ignore kmemleak false positive in nfs_readdir_make_qstr SUNRPC: Simplify rpc_alloc_iostats by removing pointless local variable nfs: trivial: remove unused nfs_wait_event macro NFS: readdir shouldn't read beyond the reply returned by the server NFS: Fix a couple of regressions in readdir. Revert "NFSv4: Fall back to ordinary lookup if nfs4_atomic_open() returns EISDIR" Regression: fix mounting NFS when NFSv3 support is not compiled NLM: Fix a regression in lockd
Diffstat (limited to 'fs/nfs/dir.c')
-rw-r--r--fs/nfs/dir.c100
1 files changed, 65 insertions, 35 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 07ac3847e562..662df2a5fad5 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -34,6 +34,7 @@
34#include <linux/mount.h> 34#include <linux/mount.h>
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/kmemleak.h>
37 38
38#include "delegation.h" 39#include "delegation.h"
39#include "iostat.h" 40#include "iostat.h"
@@ -194,9 +195,13 @@ typedef struct {
194static 195static
195struct nfs_cache_array *nfs_readdir_get_array(struct page *page) 196struct nfs_cache_array *nfs_readdir_get_array(struct page *page)
196{ 197{
198 void *ptr;
197 if (page == NULL) 199 if (page == NULL)
198 return ERR_PTR(-EIO); 200 return ERR_PTR(-EIO);
199 return (struct nfs_cache_array *)kmap(page); 201 ptr = kmap(page);
202 if (ptr == NULL)
203 return ERR_PTR(-ENOMEM);
204 return ptr;
200} 205}
201 206
202static 207static
@@ -213,6 +218,9 @@ int nfs_readdir_clear_array(struct page *page, gfp_t mask)
213{ 218{
214 struct nfs_cache_array *array = nfs_readdir_get_array(page); 219 struct nfs_cache_array *array = nfs_readdir_get_array(page);
215 int i; 220 int i;
221
222 if (IS_ERR(array))
223 return PTR_ERR(array);
216 for (i = 0; i < array->size; i++) 224 for (i = 0; i < array->size; i++)
217 kfree(array->array[i].string.name); 225 kfree(array->array[i].string.name);
218 nfs_readdir_release_array(page); 226 nfs_readdir_release_array(page);
@@ -231,6 +239,11 @@ int nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int le
231 string->name = kmemdup(name, len, GFP_KERNEL); 239 string->name = kmemdup(name, len, GFP_KERNEL);
232 if (string->name == NULL) 240 if (string->name == NULL)
233 return -ENOMEM; 241 return -ENOMEM;
242 /*
243 * Avoid a kmemleak false positive. The pointer to the name is stored
244 * in a page cache page which kmemleak does not scan.
245 */
246 kmemleak_not_leak(string->name);
234 string->hash = full_name_hash(name, len); 247 string->hash = full_name_hash(name, len);
235 return 0; 248 return 0;
236} 249}
@@ -244,7 +257,7 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
244 257
245 if (IS_ERR(array)) 258 if (IS_ERR(array))
246 return PTR_ERR(array); 259 return PTR_ERR(array);
247 ret = -EIO; 260 ret = -ENOSPC;
248 if (array->size >= MAX_READDIR_ARRAY) 261 if (array->size >= MAX_READDIR_ARRAY)
249 goto out; 262 goto out;
250 263
@@ -255,9 +268,9 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
255 if (ret) 268 if (ret)
256 goto out; 269 goto out;
257 array->last_cookie = entry->cookie; 270 array->last_cookie = entry->cookie;
271 array->size++;
258 if (entry->eof == 1) 272 if (entry->eof == 1)
259 array->eof_index = array->size; 273 array->eof_index = array->size;
260 array->size++;
261out: 274out:
262 nfs_readdir_release_array(page); 275 nfs_readdir_release_array(page);
263 return ret; 276 return ret;
@@ -272,7 +285,7 @@ int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descri
272 if (diff < 0) 285 if (diff < 0)
273 goto out_eof; 286 goto out_eof;
274 if (diff >= array->size) { 287 if (diff >= array->size) {
275 if (array->eof_index > 0) 288 if (array->eof_index >= 0)
276 goto out_eof; 289 goto out_eof;
277 desc->current_index += array->size; 290 desc->current_index += array->size;
278 return -EAGAIN; 291 return -EAGAIN;
@@ -281,8 +294,6 @@ int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descri
281 index = (unsigned int)diff; 294 index = (unsigned int)diff;
282 *desc->dir_cookie = array->array[index].cookie; 295 *desc->dir_cookie = array->array[index].cookie;
283 desc->cache_entry_index = index; 296 desc->cache_entry_index = index;
284 if (index == array->eof_index)
285 desc->eof = 1;
286 return 0; 297 return 0;
287out_eof: 298out_eof:
288 desc->eof = 1; 299 desc->eof = 1;
@@ -296,17 +307,17 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
296 int status = -EAGAIN; 307 int status = -EAGAIN;
297 308
298 for (i = 0; i < array->size; i++) { 309 for (i = 0; i < array->size; i++) {
299 if (i == array->eof_index) {
300 desc->eof = 1;
301 status = -EBADCOOKIE;
302 }
303 if (array->array[i].cookie == *desc->dir_cookie) { 310 if (array->array[i].cookie == *desc->dir_cookie) {
304 desc->cache_entry_index = i; 311 desc->cache_entry_index = i;
305 status = 0; 312 status = 0;
306 break; 313 goto out;
307 } 314 }
308 } 315 }
309 316 if (i == array->eof_index) {
317 desc->eof = 1;
318 status = -EBADCOOKIE;
319 }
320out:
310 return status; 321 return status;
311} 322}
312 323
@@ -449,7 +460,7 @@ out:
449 460
450/* Perform conversion from xdr to cache array */ 461/* Perform conversion from xdr to cache array */
451static 462static
452void nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, 463int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry,
453 void *xdr_page, struct page *page, unsigned int buflen) 464 void *xdr_page, struct page *page, unsigned int buflen)
454{ 465{
455 struct xdr_stream stream; 466 struct xdr_stream stream;
@@ -471,21 +482,29 @@ void nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *e
471 482
472 do { 483 do {
473 status = xdr_decode(desc, entry, &stream); 484 status = xdr_decode(desc, entry, &stream);
474 if (status != 0) 485 if (status != 0) {
486 if (status == -EAGAIN)
487 status = 0;
475 break; 488 break;
489 }
476 490
477 if (nfs_readdir_add_to_array(entry, page) == -1)
478 break;
479 if (desc->plus == 1) 491 if (desc->plus == 1)
480 nfs_prime_dcache(desc->file->f_path.dentry, entry); 492 nfs_prime_dcache(desc->file->f_path.dentry, entry);
493
494 status = nfs_readdir_add_to_array(entry, page);
495 if (status != 0)
496 break;
481 } while (!entry->eof); 497 } while (!entry->eof);
482 498
483 if (status == -EBADCOOKIE && entry->eof) { 499 if (status == -EBADCOOKIE && entry->eof) {
484 array = nfs_readdir_get_array(page); 500 array = nfs_readdir_get_array(page);
485 array->eof_index = array->size - 1; 501 if (!IS_ERR(array)) {
486 status = 0; 502 array->eof_index = array->size;
487 nfs_readdir_release_array(page); 503 status = 0;
504 nfs_readdir_release_array(page);
505 }
488 } 506 }
507 return status;
489} 508}
490 509
491static 510static
@@ -537,7 +556,7 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
537 struct nfs_entry entry; 556 struct nfs_entry entry;
538 struct file *file = desc->file; 557 struct file *file = desc->file;
539 struct nfs_cache_array *array; 558 struct nfs_cache_array *array;
540 int status = 0; 559 int status = -ENOMEM;
541 unsigned int array_size = ARRAY_SIZE(pages); 560 unsigned int array_size = ARRAY_SIZE(pages);
542 561
543 entry.prev_cookie = 0; 562 entry.prev_cookie = 0;
@@ -549,6 +568,10 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
549 goto out; 568 goto out;
550 569
551 array = nfs_readdir_get_array(page); 570 array = nfs_readdir_get_array(page);
571 if (IS_ERR(array)) {
572 status = PTR_ERR(array);
573 goto out;
574 }
552 memset(array, 0, sizeof(struct nfs_cache_array)); 575 memset(array, 0, sizeof(struct nfs_cache_array));
553 array->eof_index = -1; 576 array->eof_index = -1;
554 577
@@ -556,12 +579,19 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
556 if (!pages_ptr) 579 if (!pages_ptr)
557 goto out_release_array; 580 goto out_release_array;
558 do { 581 do {
582 unsigned int pglen;
559 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode); 583 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode);
560 584
561 if (status < 0) 585 if (status < 0)
562 break; 586 break;
563 nfs_readdir_page_filler(desc, &entry, pages_ptr, page, array_size * PAGE_SIZE); 587 pglen = status;
564 } while (array->eof_index < 0 && array->size < MAX_READDIR_ARRAY); 588 status = nfs_readdir_page_filler(desc, &entry, pages_ptr, page, pglen);
589 if (status < 0) {
590 if (status == -ENOSPC)
591 status = 0;
592 break;
593 }
594 } while (array->eof_index < 0);
565 595
566 nfs_readdir_free_large_page(pages_ptr, pages, array_size); 596 nfs_readdir_free_large_page(pages_ptr, pages, array_size);
567out_release_array: 597out_release_array:
@@ -582,8 +612,10 @@ static
582int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page) 612int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
583{ 613{
584 struct inode *inode = desc->file->f_path.dentry->d_inode; 614 struct inode *inode = desc->file->f_path.dentry->d_inode;
615 int ret;
585 616
586 if (nfs_readdir_xdr_to_array(desc, page, inode) < 0) 617 ret = nfs_readdir_xdr_to_array(desc, page, inode);
618 if (ret < 0)
587 goto error; 619 goto error;
588 SetPageUptodate(page); 620 SetPageUptodate(page);
589 621
@@ -595,7 +627,7 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
595 return 0; 627 return 0;
596 error: 628 error:
597 unlock_page(page); 629 unlock_page(page);
598 return -EIO; 630 return ret;
599} 631}
600 632
601static 633static
@@ -608,12 +640,8 @@ void cache_page_release(nfs_readdir_descriptor_t *desc)
608static 640static
609struct page *get_cache_page(nfs_readdir_descriptor_t *desc) 641struct page *get_cache_page(nfs_readdir_descriptor_t *desc)
610{ 642{
611 struct page *page; 643 return read_cache_page(desc->file->f_path.dentry->d_inode->i_mapping,
612 page = read_cache_page(desc->file->f_path.dentry->d_inode->i_mapping,
613 desc->page_index, (filler_t *)nfs_readdir_filler, desc); 644 desc->page_index, (filler_t *)nfs_readdir_filler, desc);
614 if (IS_ERR(page))
615 desc->eof = 1;
616 return page;
617} 645}
618 646
619/* 647/*
@@ -639,8 +667,10 @@ int find_cache_page(nfs_readdir_descriptor_t *desc)
639static inline 667static inline
640int readdir_search_pagecache(nfs_readdir_descriptor_t *desc) 668int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
641{ 669{
642 int res = -EAGAIN; 670 int res;
643 671
672 if (desc->page_index == 0)
673 desc->current_index = 0;
644 while (1) { 674 while (1) {
645 res = find_cache_page(desc); 675 res = find_cache_page(desc);
646 if (res != -EAGAIN) 676 if (res != -EAGAIN)
@@ -670,6 +700,8 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
670 struct dentry *dentry = NULL; 700 struct dentry *dentry = NULL;
671 701
672 array = nfs_readdir_get_array(desc->page); 702 array = nfs_readdir_get_array(desc->page);
703 if (IS_ERR(array))
704 return PTR_ERR(array);
673 705
674 for (i = desc->cache_entry_index; i < array->size; i++) { 706 for (i = desc->cache_entry_index; i < array->size; i++) {
675 d_type = DT_UNKNOWN; 707 d_type = DT_UNKNOWN;
@@ -685,11 +717,9 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
685 *desc->dir_cookie = array->array[i+1].cookie; 717 *desc->dir_cookie = array->array[i+1].cookie;
686 else 718 else
687 *desc->dir_cookie = array->last_cookie; 719 *desc->dir_cookie = array->last_cookie;
688 if (i == array->eof_index) {
689 desc->eof = 1;
690 break;
691 }
692 } 720 }
721 if (i == array->eof_index)
722 desc->eof = 1;
693 723
694 nfs_readdir_release_array(desc->page); 724 nfs_readdir_release_array(desc->page);
695 cache_page_release(desc); 725 cache_page_release(desc);
@@ -1345,12 +1375,12 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1345 res = NULL; 1375 res = NULL;
1346 goto out; 1376 goto out;
1347 /* This turned out not to be a regular file */ 1377 /* This turned out not to be a regular file */
1348 case -EISDIR:
1349 case -ENOTDIR: 1378 case -ENOTDIR:
1350 goto no_open; 1379 goto no_open;
1351 case -ELOOP: 1380 case -ELOOP:
1352 if (!(nd->intent.open.flags & O_NOFOLLOW)) 1381 if (!(nd->intent.open.flags & O_NOFOLLOW))
1353 goto no_open; 1382 goto no_open;
1383 /* case -EISDIR: */
1354 /* case -EINVAL: */ 1384 /* case -EINVAL: */
1355 default: 1385 default:
1356 res = ERR_CAST(inode); 1386 res = ERR_CAST(inode);