aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2010-12-07 12:44:56 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2010-12-07 14:09:02 -0500
commit47c716cbf638a16583441d78be3fc24345eab636 (patch)
treeee06a3e432e9fdc12438423745674442acbbeb0f /fs
parent18fb5fe40ce7f789b5cfc3aa81ff1e6175b0a5be (diff)
NFS: Readdir cleanups
No functional changes, but clarify the code. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfs/dir.c47
1 files changed, 17 insertions, 30 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index ad2fde23446..996dd8989a9 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -271,7 +271,7 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
271 goto out; 271 goto out;
272 array->last_cookie = entry->cookie; 272 array->last_cookie = entry->cookie;
273 array->size++; 273 array->size++;
274 if (entry->eof == 1) 274 if (entry->eof != 0)
275 array->eof_index = array->size; 275 array->eof_index = array->size;
276out: 276out:
277 nfs_readdir_release_array(page); 277 nfs_readdir_release_array(page);
@@ -311,16 +311,14 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
311 for (i = 0; i < array->size; i++) { 311 for (i = 0; i < array->size; i++) {
312 if (array->array[i].cookie == *desc->dir_cookie) { 312 if (array->array[i].cookie == *desc->dir_cookie) {
313 desc->cache_entry_index = i; 313 desc->cache_entry_index = i;
314 status = 0; 314 return 0;
315 goto out;
316 } 315 }
317 } 316 }
318 if (i == array->eof_index) { 317 if (array->eof_index >= 0) {
319 status = -EBADCOOKIE; 318 status = -EBADCOOKIE;
320 if (*desc->dir_cookie == array->last_cookie) 319 if (*desc->dir_cookie == array->last_cookie)
321 desc->eof = 1; 320 desc->eof = 1;
322 } 321 }
323out:
324 return status; 322 return status;
325} 323}
326 324
@@ -328,10 +326,7 @@ static
328int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc) 326int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
329{ 327{
330 struct nfs_cache_array *array; 328 struct nfs_cache_array *array;
331 int status = -EBADCOOKIE; 329 int status;
332
333 if (desc->dir_cookie == NULL)
334 goto out;
335 330
336 array = nfs_readdir_get_array(desc->page); 331 array = nfs_readdir_get_array(desc->page);
337 if (IS_ERR(array)) { 332 if (IS_ERR(array)) {
@@ -344,8 +339,10 @@ int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
344 else 339 else
345 status = nfs_readdir_search_for_cookie(array, desc); 340 status = nfs_readdir_search_for_cookie(array, desc);
346 341
347 if (status == -EAGAIN) 342 if (status == -EAGAIN) {
348 desc->last_cookie = array->last_cookie; 343 desc->last_cookie = array->last_cookie;
344 desc->page_index++;
345 }
349 nfs_readdir_release_array(desc->page); 346 nfs_readdir_release_array(desc->page);
350out: 347out:
351 return status; 348 return status;
@@ -492,7 +489,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
492 489
493 count++; 490 count++;
494 491
495 if (desc->plus == 1) 492 if (desc->plus != 0)
496 nfs_prime_dcache(desc->file->f_path.dentry, entry); 493 nfs_prime_dcache(desc->file->f_path.dentry, entry);
497 494
498 status = nfs_readdir_add_to_array(entry, page); 495 status = nfs_readdir_add_to_array(entry, page);
@@ -500,7 +497,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
500 break; 497 break;
501 } while (!entry->eof); 498 } while (!entry->eof);
502 499
503 if (count == 0 || (status == -EBADCOOKIE && entry->eof == 1)) { 500 if (count == 0 || (status == -EBADCOOKIE && entry->eof != 0)) {
504 array = nfs_readdir_get_array(page); 501 array = nfs_readdir_get_array(page);
505 if (!IS_ERR(array)) { 502 if (!IS_ERR(array)) {
506 array->eof_index = array->size; 503 array->eof_index = array->size;
@@ -664,9 +661,8 @@ int find_cache_page(nfs_readdir_descriptor_t *desc)
664 return PTR_ERR(desc->page); 661 return PTR_ERR(desc->page);
665 662
666 res = nfs_readdir_search_array(desc); 663 res = nfs_readdir_search_array(desc);
667 if (res == 0) 664 if (res != 0)
668 return 0; 665 cache_page_release(desc);
669 cache_page_release(desc);
670 return res; 666 return res;
671} 667}
672 668
@@ -680,20 +676,12 @@ int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
680 desc->current_index = 0; 676 desc->current_index = 0;
681 desc->last_cookie = 0; 677 desc->last_cookie = 0;
682 } 678 }
683 while (1) { 679 do {
684 res = find_cache_page(desc); 680 res = find_cache_page(desc);
685 if (res != -EAGAIN) 681 } while (res == -EAGAIN);
686 break;
687 desc->page_index++;
688 }
689 return res; 682 return res;
690} 683}
691 684
692static inline unsigned int dt_type(struct inode *inode)
693{
694 return (inode->i_mode >> 12) & 15;
695}
696
697/* 685/*
698 * Once we've found the start of the dirent within a page: fill 'er up... 686 * Once we've found the start of the dirent within a page: fill 'er up...
699 */ 687 */
@@ -723,13 +711,12 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
723 break; 711 break;
724 } 712 }
725 file->f_pos++; 713 file->f_pos++;
726 desc->cache_entry_index = i;
727 if (i < (array->size-1)) 714 if (i < (array->size-1))
728 *desc->dir_cookie = array->array[i+1].cookie; 715 *desc->dir_cookie = array->array[i+1].cookie;
729 else 716 else
730 *desc->dir_cookie = array->last_cookie; 717 *desc->dir_cookie = array->last_cookie;
731 } 718 }
732 if (i == array->eof_index) 719 if (array->eof_index >= 0)
733 desc->eof = 1; 720 desc->eof = 1;
734 721
735 nfs_readdir_release_array(desc->page); 722 nfs_readdir_release_array(desc->page);
@@ -798,7 +785,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
798 struct inode *inode = dentry->d_inode; 785 struct inode *inode = dentry->d_inode;
799 nfs_readdir_descriptor_t my_desc, 786 nfs_readdir_descriptor_t my_desc,
800 *desc = &my_desc; 787 *desc = &my_desc;
801 int res = -ENOMEM; 788 int res;
802 789
803 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n", 790 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
804 dentry->d_parent->d_name.name, dentry->d_name.name, 791 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -823,7 +810,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
823 if (res < 0) 810 if (res < 0)
824 goto out; 811 goto out;
825 812
826 while (desc->eof != 1) { 813 do {
827 res = readdir_search_pagecache(desc); 814 res = readdir_search_pagecache(desc);
828 815
829 if (res == -EBADCOOKIE) { 816 if (res == -EBADCOOKIE) {
@@ -851,7 +838,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
851 res = nfs_do_filldir(desc, dirent, filldir); 838 res = nfs_do_filldir(desc, dirent, filldir);
852 if (res < 0) 839 if (res < 0)
853 break; 840 break;
854 } 841 } while (!desc->eof);
855out: 842out:
856 nfs_unblock_sillyrename(dentry); 843 nfs_unblock_sillyrename(dentry);
857 if (res > 0) 844 if (res > 0)