aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/callback.c1
-rw-r--r--fs/nfs/delegation.c1
-rw-r--r--fs/nfs/dir.c162
-rw-r--r--fs/nfs/direct.c2
-rw-r--r--fs/nfs/internal.h9
-rw-r--r--fs/nfs/nfs2xdr.c8
-rw-r--r--fs/nfs/nfs3xdr.c8
-rw-r--r--fs/nfs/nfs4proc.c4
-rw-r--r--fs/nfs/nfs4xdr.c8
-rw-r--r--fs/nfs/super.c9
10 files changed, 133 insertions, 79 deletions
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index aeec017fe814..93a8b3bd69e3 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -9,7 +9,6 @@
9#include <linux/completion.h> 9#include <linux/completion.h>
10#include <linux/ip.h> 10#include <linux/ip.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/smp_lock.h>
13#include <linux/sunrpc/svc.h> 12#include <linux/sunrpc/svc.h>
14#include <linux/sunrpc/svcsock.h> 13#include <linux/sunrpc/svcsock.h>
15#include <linux/nfs_fs.h> 14#include <linux/nfs_fs.h>
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 232a7eead33a..1fd62fc49be3 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -11,7 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/smp_lock.h>
15#include <linux/spinlock.h> 14#include <linux/spinlock.h>
16 15
17#include <linux/nfs4.h> 16#include <linux/nfs4.h>
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 07ac3847e562..f0a384e2ae63 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"
@@ -161,6 +162,7 @@ struct nfs_cache_array_entry {
161 u64 cookie; 162 u64 cookie;
162 u64 ino; 163 u64 ino;
163 struct qstr string; 164 struct qstr string;
165 unsigned char d_type;
164}; 166};
165 167
166struct nfs_cache_array { 168struct nfs_cache_array {
@@ -170,8 +172,6 @@ struct nfs_cache_array {
170 struct nfs_cache_array_entry array[0]; 172 struct nfs_cache_array_entry array[0];
171}; 173};
172 174
173#define MAX_READDIR_ARRAY ((PAGE_SIZE - sizeof(struct nfs_cache_array)) / sizeof(struct nfs_cache_array_entry))
174
175typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); 175typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
176typedef struct { 176typedef struct {
177 struct file *file; 177 struct file *file;
@@ -194,9 +194,13 @@ typedef struct {
194static 194static
195struct nfs_cache_array *nfs_readdir_get_array(struct page *page) 195struct nfs_cache_array *nfs_readdir_get_array(struct page *page)
196{ 196{
197 void *ptr;
197 if (page == NULL) 198 if (page == NULL)
198 return ERR_PTR(-EIO); 199 return ERR_PTR(-EIO);
199 return (struct nfs_cache_array *)kmap(page); 200 ptr = kmap(page);
201 if (ptr == NULL)
202 return ERR_PTR(-ENOMEM);
203 return ptr;
200} 204}
201 205
202static 206static
@@ -213,6 +217,9 @@ int nfs_readdir_clear_array(struct page *page, gfp_t mask)
213{ 217{
214 struct nfs_cache_array *array = nfs_readdir_get_array(page); 218 struct nfs_cache_array *array = nfs_readdir_get_array(page);
215 int i; 219 int i;
220
221 if (IS_ERR(array))
222 return PTR_ERR(array);
216 for (i = 0; i < array->size; i++) 223 for (i = 0; i < array->size; i++)
217 kfree(array->array[i].string.name); 224 kfree(array->array[i].string.name);
218 nfs_readdir_release_array(page); 225 nfs_readdir_release_array(page);
@@ -231,6 +238,11 @@ int nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int le
231 string->name = kmemdup(name, len, GFP_KERNEL); 238 string->name = kmemdup(name, len, GFP_KERNEL);
232 if (string->name == NULL) 239 if (string->name == NULL)
233 return -ENOMEM; 240 return -ENOMEM;
241 /*
242 * Avoid a kmemleak false positive. The pointer to the name is stored
243 * in a page cache page which kmemleak does not scan.
244 */
245 kmemleak_not_leak(string->name);
234 string->hash = full_name_hash(name, len); 246 string->hash = full_name_hash(name, len);
235 return 0; 247 return 0;
236} 248}
@@ -244,20 +256,24 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
244 256
245 if (IS_ERR(array)) 257 if (IS_ERR(array))
246 return PTR_ERR(array); 258 return PTR_ERR(array);
247 ret = -EIO;
248 if (array->size >= MAX_READDIR_ARRAY)
249 goto out;
250 259
251 cache_entry = &array->array[array->size]; 260 cache_entry = &array->array[array->size];
261
262 /* Check that this entry lies within the page bounds */
263 ret = -ENOSPC;
264 if ((char *)&cache_entry[1] - (char *)page_address(page) > PAGE_SIZE)
265 goto out;
266
252 cache_entry->cookie = entry->prev_cookie; 267 cache_entry->cookie = entry->prev_cookie;
253 cache_entry->ino = entry->ino; 268 cache_entry->ino = entry->ino;
269 cache_entry->d_type = entry->d_type;
254 ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len); 270 ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len);
255 if (ret) 271 if (ret)
256 goto out; 272 goto out;
257 array->last_cookie = entry->cookie; 273 array->last_cookie = entry->cookie;
274 array->size++;
258 if (entry->eof == 1) 275 if (entry->eof == 1)
259 array->eof_index = array->size; 276 array->eof_index = array->size;
260 array->size++;
261out: 277out:
262 nfs_readdir_release_array(page); 278 nfs_readdir_release_array(page);
263 return ret; 279 return ret;
@@ -272,7 +288,7 @@ int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descri
272 if (diff < 0) 288 if (diff < 0)
273 goto out_eof; 289 goto out_eof;
274 if (diff >= array->size) { 290 if (diff >= array->size) {
275 if (array->eof_index > 0) 291 if (array->eof_index >= 0)
276 goto out_eof; 292 goto out_eof;
277 desc->current_index += array->size; 293 desc->current_index += array->size;
278 return -EAGAIN; 294 return -EAGAIN;
@@ -281,8 +297,6 @@ int nfs_readdir_search_for_pos(struct nfs_cache_array *array, nfs_readdir_descri
281 index = (unsigned int)diff; 297 index = (unsigned int)diff;
282 *desc->dir_cookie = array->array[index].cookie; 298 *desc->dir_cookie = array->array[index].cookie;
283 desc->cache_entry_index = index; 299 desc->cache_entry_index = index;
284 if (index == array->eof_index)
285 desc->eof = 1;
286 return 0; 300 return 0;
287out_eof: 301out_eof:
288 desc->eof = 1; 302 desc->eof = 1;
@@ -296,17 +310,17 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
296 int status = -EAGAIN; 310 int status = -EAGAIN;
297 311
298 for (i = 0; i < array->size; i++) { 312 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) { 313 if (array->array[i].cookie == *desc->dir_cookie) {
304 desc->cache_entry_index = i; 314 desc->cache_entry_index = i;
305 status = 0; 315 status = 0;
306 break; 316 goto out;
307 } 317 }
308 } 318 }
309 319 if (i == array->eof_index) {
320 desc->eof = 1;
321 status = -EBADCOOKIE;
322 }
323out:
310 return status; 324 return status;
311} 325}
312 326
@@ -381,13 +395,9 @@ int xdr_decode(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, struct x
381static 395static
382int nfs_same_file(struct dentry *dentry, struct nfs_entry *entry) 396int nfs_same_file(struct dentry *dentry, struct nfs_entry *entry)
383{ 397{
384 struct nfs_inode *node;
385 if (dentry->d_inode == NULL) 398 if (dentry->d_inode == NULL)
386 goto different; 399 goto different;
387 node = NFS_I(dentry->d_inode); 400 if (nfs_compare_fh(entry->fh, NFS_FH(dentry->d_inode)) != 0)
388 if (node->fh.size != entry->fh->size)
389 goto different;
390 if (strncmp(node->fh.data, entry->fh->data, node->fh.size) != 0)
391 goto different; 401 goto different;
392 return 1; 402 return 1;
393different: 403different:
@@ -449,14 +459,15 @@ out:
449 459
450/* Perform conversion from xdr to cache array */ 460/* Perform conversion from xdr to cache array */
451static 461static
452void nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, 462int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry,
453 void *xdr_page, struct page *page, unsigned int buflen) 463 void *xdr_page, struct page *page, unsigned int buflen)
454{ 464{
455 struct xdr_stream stream; 465 struct xdr_stream stream;
456 struct xdr_buf buf; 466 struct xdr_buf buf;
457 __be32 *ptr = xdr_page; 467 __be32 *ptr = xdr_page;
458 int status;
459 struct nfs_cache_array *array; 468 struct nfs_cache_array *array;
469 unsigned int count = 0;
470 int status;
460 471
461 buf.head->iov_base = xdr_page; 472 buf.head->iov_base = xdr_page;
462 buf.head->iov_len = buflen; 473 buf.head->iov_len = buflen;
@@ -471,21 +482,32 @@ 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 }
490
491 count++;
476 492
477 if (nfs_readdir_add_to_array(entry, page) == -1)
478 break;
479 if (desc->plus == 1) 493 if (desc->plus == 1)
480 nfs_prime_dcache(desc->file->f_path.dentry, entry); 494 nfs_prime_dcache(desc->file->f_path.dentry, entry);
495
496 status = nfs_readdir_add_to_array(entry, page);
497 if (status != 0)
498 break;
481 } while (!entry->eof); 499 } while (!entry->eof);
482 500
483 if (status == -EBADCOOKIE && entry->eof) { 501 if (count == 0 || (status == -EBADCOOKIE && entry->eof == 1)) {
484 array = nfs_readdir_get_array(page); 502 array = nfs_readdir_get_array(page);
485 array->eof_index = array->size - 1; 503 if (!IS_ERR(array)) {
486 status = 0; 504 array->eof_index = array->size;
487 nfs_readdir_release_array(page); 505 status = 0;
506 nfs_readdir_release_array(page);
507 } else
508 status = PTR_ERR(array);
488 } 509 }
510 return status;
489} 511}
490 512
491static 513static
@@ -537,7 +559,7 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
537 struct nfs_entry entry; 559 struct nfs_entry entry;
538 struct file *file = desc->file; 560 struct file *file = desc->file;
539 struct nfs_cache_array *array; 561 struct nfs_cache_array *array;
540 int status = 0; 562 int status = -ENOMEM;
541 unsigned int array_size = ARRAY_SIZE(pages); 563 unsigned int array_size = ARRAY_SIZE(pages);
542 564
543 entry.prev_cookie = 0; 565 entry.prev_cookie = 0;
@@ -549,6 +571,10 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
549 goto out; 571 goto out;
550 572
551 array = nfs_readdir_get_array(page); 573 array = nfs_readdir_get_array(page);
574 if (IS_ERR(array)) {
575 status = PTR_ERR(array);
576 goto out;
577 }
552 memset(array, 0, sizeof(struct nfs_cache_array)); 578 memset(array, 0, sizeof(struct nfs_cache_array));
553 array->eof_index = -1; 579 array->eof_index = -1;
554 580
@@ -556,12 +582,19 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,
556 if (!pages_ptr) 582 if (!pages_ptr)
557 goto out_release_array; 583 goto out_release_array;
558 do { 584 do {
585 unsigned int pglen;
559 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode); 586 status = nfs_readdir_xdr_filler(pages, desc, &entry, file, inode);
560 587
561 if (status < 0) 588 if (status < 0)
562 break; 589 break;
563 nfs_readdir_page_filler(desc, &entry, pages_ptr, page, array_size * PAGE_SIZE); 590 pglen = status;
564 } while (array->eof_index < 0 && array->size < MAX_READDIR_ARRAY); 591 status = nfs_readdir_page_filler(desc, &entry, pages_ptr, page, pglen);
592 if (status < 0) {
593 if (status == -ENOSPC)
594 status = 0;
595 break;
596 }
597 } while (array->eof_index < 0);
565 598
566 nfs_readdir_free_large_page(pages_ptr, pages, array_size); 599 nfs_readdir_free_large_page(pages_ptr, pages, array_size);
567out_release_array: 600out_release_array:
@@ -582,8 +615,10 @@ static
582int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page) 615int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
583{ 616{
584 struct inode *inode = desc->file->f_path.dentry->d_inode; 617 struct inode *inode = desc->file->f_path.dentry->d_inode;
618 int ret;
585 619
586 if (nfs_readdir_xdr_to_array(desc, page, inode) < 0) 620 ret = nfs_readdir_xdr_to_array(desc, page, inode);
621 if (ret < 0)
587 goto error; 622 goto error;
588 SetPageUptodate(page); 623 SetPageUptodate(page);
589 624
@@ -595,7 +630,7 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page)
595 return 0; 630 return 0;
596 error: 631 error:
597 unlock_page(page); 632 unlock_page(page);
598 return -EIO; 633 return ret;
599} 634}
600 635
601static 636static
@@ -608,12 +643,8 @@ void cache_page_release(nfs_readdir_descriptor_t *desc)
608static 643static
609struct page *get_cache_page(nfs_readdir_descriptor_t *desc) 644struct page *get_cache_page(nfs_readdir_descriptor_t *desc)
610{ 645{
611 struct page *page; 646 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); 647 desc->page_index, (filler_t *)nfs_readdir_filler, desc);
614 if (IS_ERR(page))
615 desc->eof = 1;
616 return page;
617} 648}
618 649
619/* 650/*
@@ -639,8 +670,10 @@ int find_cache_page(nfs_readdir_descriptor_t *desc)
639static inline 670static inline
640int readdir_search_pagecache(nfs_readdir_descriptor_t *desc) 671int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
641{ 672{
642 int res = -EAGAIN; 673 int res;
643 674
675 if (desc->page_index == 0)
676 desc->current_index = 0;
644 while (1) { 677 while (1) {
645 res = find_cache_page(desc); 678 res = find_cache_page(desc);
646 if (res != -EAGAIN) 679 if (res != -EAGAIN)
@@ -666,35 +699,36 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
666 int i = 0; 699 int i = 0;
667 int res = 0; 700 int res = 0;
668 struct nfs_cache_array *array = NULL; 701 struct nfs_cache_array *array = NULL;
669 unsigned int d_type = DT_UNKNOWN;
670 struct dentry *dentry = NULL;
671 702
672 array = nfs_readdir_get_array(desc->page); 703 array = nfs_readdir_get_array(desc->page);
704 if (IS_ERR(array)) {
705 res = PTR_ERR(array);
706 goto out;
707 }
673 708
674 for (i = desc->cache_entry_index; i < array->size; i++) { 709 for (i = desc->cache_entry_index; i < array->size; i++) {
675 d_type = DT_UNKNOWN; 710 struct nfs_cache_array_entry *ent;
676 711
677 res = filldir(dirent, array->array[i].string.name, 712 ent = &array->array[i];
678 array->array[i].string.len, file->f_pos, 713 if (filldir(dirent, ent->string.name, ent->string.len,
679 nfs_compat_user_ino64(array->array[i].ino), d_type); 714 file->f_pos, nfs_compat_user_ino64(ent->ino),
680 if (res < 0) 715 ent->d_type) < 0) {
716 desc->eof = 1;
681 break; 717 break;
718 }
682 file->f_pos++; 719 file->f_pos++;
683 desc->cache_entry_index = i; 720 desc->cache_entry_index = i;
684 if (i < (array->size-1)) 721 if (i < (array->size-1))
685 *desc->dir_cookie = array->array[i+1].cookie; 722 *desc->dir_cookie = array->array[i+1].cookie;
686 else 723 else
687 *desc->dir_cookie = array->last_cookie; 724 *desc->dir_cookie = array->last_cookie;
688 if (i == array->eof_index) {
689 desc->eof = 1;
690 break;
691 }
692 } 725 }
726 if (i == array->eof_index)
727 desc->eof = 1;
693 728
694 nfs_readdir_release_array(desc->page); 729 nfs_readdir_release_array(desc->page);
730out:
695 cache_page_release(desc); 731 cache_page_release(desc);
696 if (dentry != NULL)
697 dput(dentry);
698 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %Lu; returning = %d\n", 732 dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %Lu; returning = %d\n",
699 (unsigned long long)*desc->dir_cookie, res); 733 (unsigned long long)*desc->dir_cookie, res);
700 return res; 734 return res;
@@ -729,13 +763,13 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
729 goto out; 763 goto out;
730 } 764 }
731 765
732 if (nfs_readdir_xdr_to_array(desc, page, inode) == -1) {
733 status = -EIO;
734 goto out_release;
735 }
736
737 desc->page_index = 0; 766 desc->page_index = 0;
738 desc->page = page; 767 desc->page = page;
768
769 status = nfs_readdir_xdr_to_array(desc, page, inode);
770 if (status < 0)
771 goto out_release;
772
739 status = nfs_do_filldir(desc, dirent, filldir); 773 status = nfs_do_filldir(desc, dirent, filldir);
740 774
741 out: 775 out:
@@ -786,14 +820,14 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
786 res = readdir_search_pagecache(desc); 820 res = readdir_search_pagecache(desc);
787 821
788 if (res == -EBADCOOKIE) { 822 if (res == -EBADCOOKIE) {
823 res = 0;
789 /* This means either end of directory */ 824 /* This means either end of directory */
790 if (*desc->dir_cookie && desc->eof == 0) { 825 if (*desc->dir_cookie && desc->eof == 0) {
791 /* Or that the server has 'lost' a cookie */ 826 /* Or that the server has 'lost' a cookie */
792 res = uncached_readdir(desc, dirent, filldir); 827 res = uncached_readdir(desc, dirent, filldir);
793 if (res >= 0) 828 if (res == 0)
794 continue; 829 continue;
795 } 830 }
796 res = 0;
797 break; 831 break;
798 } 832 }
799 if (res == -ETOOSMALL && desc->plus) { 833 if (res == -ETOOSMALL && desc->plus) {
@@ -808,10 +842,8 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
808 break; 842 break;
809 843
810 res = nfs_do_filldir(desc, dirent, filldir); 844 res = nfs_do_filldir(desc, dirent, filldir);
811 if (res < 0) { 845 if (res < 0)
812 res = 0;
813 break; 846 break;
814 }
815 } 847 }
816out: 848out:
817 nfs_unblock_sillyrename(dentry); 849 nfs_unblock_sillyrename(dentry);
@@ -1345,12 +1377,12 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1345 res = NULL; 1377 res = NULL;
1346 goto out; 1378 goto out;
1347 /* This turned out not to be a regular file */ 1379 /* This turned out not to be a regular file */
1348 case -EISDIR:
1349 case -ENOTDIR: 1380 case -ENOTDIR:
1350 goto no_open; 1381 goto no_open;
1351 case -ELOOP: 1382 case -ELOOP:
1352 if (!(nd->intent.open.flags & O_NOFOLLOW)) 1383 if (!(nd->intent.open.flags & O_NOFOLLOW))
1353 goto no_open; 1384 goto no_open;
1385 /* case -EISDIR: */
1354 /* case -EINVAL: */ 1386 /* case -EINVAL: */
1355 default: 1387 default:
1356 res = ERR_CAST(inode); 1388 res = ERR_CAST(inode);
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 84d3c8b90206..e6ace0d93c71 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -867,7 +867,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
867 goto out; 867 goto out;
868 nfs_alloc_commit_data(dreq); 868 nfs_alloc_commit_data(dreq);
869 869
870 if (dreq->commit_data == NULL || count < wsize) 870 if (dreq->commit_data == NULL || count <= wsize)
871 sync = NFS_FILE_SYNC; 871 sync = NFS_FILE_SYNC;
872 872
873 dreq->inode = inode; 873 dreq->inode = inode;
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index db08ff3ff454..e6356b750b77 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -362,6 +362,15 @@ unsigned int nfs_page_length(struct page *page)
362} 362}
363 363
364/* 364/*
365 * Convert a umode to a dirent->d_type
366 */
367static inline
368unsigned char nfs_umode_to_dtype(umode_t mode)
369{
370 return (mode >> 12) & 15;
371}
372
373/*
365 * Determine the number of pages in an array of length 'len' and 374 * Determine the number of pages in an array of length 'len' and
366 * with a base offset of 'base' 375 * with a base offset of 'base'
367 */ 376 */
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index e6bf45710cc7..5914a1911c95 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -423,7 +423,7 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
423 struct page **page; 423 struct page **page;
424 size_t hdrlen; 424 size_t hdrlen;
425 unsigned int pglen, recvd; 425 unsigned int pglen, recvd;
426 int status, nr = 0; 426 int status;
427 427
428 if ((status = ntohl(*p++))) 428 if ((status = ntohl(*p++)))
429 return nfs_stat_to_errno(status); 429 return nfs_stat_to_errno(status);
@@ -443,7 +443,7 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
443 if (pglen > recvd) 443 if (pglen > recvd)
444 pglen = recvd; 444 pglen = recvd;
445 page = rcvbuf->pages; 445 page = rcvbuf->pages;
446 return nr; 446 return pglen;
447} 447}
448 448
449static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 449static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
@@ -485,6 +485,8 @@ nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_se
485 entry->prev_cookie = entry->cookie; 485 entry->prev_cookie = entry->cookie;
486 entry->cookie = ntohl(*p++); 486 entry->cookie = ntohl(*p++);
487 487
488 entry->d_type = DT_UNKNOWN;
489
488 p = xdr_inline_peek(xdr, 8); 490 p = xdr_inline_peek(xdr, 8);
489 if (p != NULL) 491 if (p != NULL)
490 entry->eof = !p[0] && p[1]; 492 entry->eof = !p[0] && p[1];
@@ -495,7 +497,7 @@ nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_se
495 497
496out_overflow: 498out_overflow:
497 print_overflow_msg(__func__, xdr); 499 print_overflow_msg(__func__, xdr);
498 return ERR_PTR(-EIO); 500 return ERR_PTR(-EAGAIN);
499} 501}
500 502
501/* 503/*
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index d9a5e832c257..f6cc60f06dac 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -555,7 +555,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
555 struct page **page; 555 struct page **page;
556 size_t hdrlen; 556 size_t hdrlen;
557 u32 recvd, pglen; 557 u32 recvd, pglen;
558 int status, nr = 0; 558 int status;
559 559
560 status = ntohl(*p++); 560 status = ntohl(*p++);
561 /* Decode post_op_attrs */ 561 /* Decode post_op_attrs */
@@ -586,7 +586,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
586 pglen = recvd; 586 pglen = recvd;
587 page = rcvbuf->pages; 587 page = rcvbuf->pages;
588 588
589 return nr; 589 return pglen;
590} 590}
591 591
592__be32 * 592__be32 *
@@ -622,11 +622,13 @@ nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_s
622 entry->prev_cookie = entry->cookie; 622 entry->prev_cookie = entry->cookie;
623 p = xdr_decode_hyper(p, &entry->cookie); 623 p = xdr_decode_hyper(p, &entry->cookie);
624 624
625 entry->d_type = DT_UNKNOWN;
625 if (plus) { 626 if (plus) {
626 entry->fattr->valid = 0; 627 entry->fattr->valid = 0;
627 p = xdr_decode_post_op_attr_stream(xdr, entry->fattr); 628 p = xdr_decode_post_op_attr_stream(xdr, entry->fattr);
628 if (IS_ERR(p)) 629 if (IS_ERR(p))
629 goto out_overflow_exit; 630 goto out_overflow_exit;
631 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
630 /* In fact, a post_op_fh3: */ 632 /* In fact, a post_op_fh3: */
631 p = xdr_inline_decode(xdr, 4); 633 p = xdr_inline_decode(xdr, 4);
632 if (unlikely(!p)) 634 if (unlikely(!p))
@@ -656,7 +658,7 @@ nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_s
656out_overflow: 658out_overflow:
657 print_overflow_msg(__func__, xdr); 659 print_overflow_msg(__func__, xdr);
658out_overflow_exit: 660out_overflow_exit:
659 return ERR_PTR(-EIO); 661 return ERR_PTR(-EAGAIN);
660} 662}
661 663
662/* 664/*
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 0f24cdf2cb13..6a653ffd8e4e 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2852,8 +2852,10 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2852 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); 2852 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2853 res.pgbase = args.pgbase; 2853 res.pgbase = args.pgbase;
2854 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); 2854 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2855 if (status == 0) 2855 if (status >= 0) {
2856 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); 2856 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2857 status += args.pgbase;
2858 }
2857 2859
2858 nfs_invalidate_atime(dir); 2860 nfs_invalidate_atime(dir);
2859 2861
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index f313c4cce7e4..9f1826b012e6 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -4518,7 +4518,7 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
4518 xdr_read_pages(xdr, pglen); 4518 xdr_read_pages(xdr, pglen);
4519 4519
4520 4520
4521 return 0; 4521 return pglen;
4522} 4522}
4523 4523
4524static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req) 4524static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
@@ -6208,6 +6208,10 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6208 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) 6208 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6209 entry->ino = entry->fattr->fileid; 6209 entry->ino = entry->fattr->fileid;
6210 6210
6211 entry->d_type = DT_UNKNOWN;
6212 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6213 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6214
6211 if (verify_attr_len(xdr, p, len) < 0) 6215 if (verify_attr_len(xdr, p, len) < 0)
6212 goto out_overflow; 6216 goto out_overflow;
6213 6217
@@ -6221,7 +6225,7 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6221 6225
6222out_overflow: 6226out_overflow:
6223 print_overflow_msg(__func__, xdr); 6227 print_overflow_msg(__func__, xdr);
6224 return ERR_PTR(-EIO); 6228 return ERR_PTR(-EAGAIN);
6225} 6229}
6226 6230
6227/* 6231/*
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 0a42e8f4adcb..3c045044fca2 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -39,7 +39,6 @@
39#include <linux/nfs_mount.h> 39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h> 40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h> 41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h> 42#include <linux/seq_file.h>
44#include <linux/mount.h> 43#include <linux/mount.h>
45#include <linux/mnt_namespace.h> 44#include <linux/mnt_namespace.h>
@@ -67,6 +66,12 @@
67 66
68#define NFSDBG_FACILITY NFSDBG_VFS 67#define NFSDBG_FACILITY NFSDBG_VFS
69 68
69#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
70enum { 75enum {
71 /* Mount options that take no arguments */ 76 /* Mount options that take no arguments */
72 Opt_soft, Opt_hard, 77 Opt_soft, Opt_hard,
@@ -2277,7 +2282,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,
2277 }; 2282 };
2278 int error = -ENOMEM; 2283 int error = -ENOMEM;
2279 2284
2280 data = nfs_alloc_parsed_mount_data(3); 2285 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
2281 mntfh = nfs_alloc_fhandle(); 2286 mntfh = nfs_alloc_fhandle();
2282 if (data == NULL || mntfh == NULL) 2287 if (data == NULL || mntfh == NULL)
2283 goto out_free_fh; 2288 goto out_free_fh;