Commit 47c716cb authored by Trond Myklebust's avatar Trond Myklebust

NFS: Readdir cleanups

No functional changes, but clarify the code.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 18fb5fe4
...@@ -271,7 +271,7 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page) ...@@ -271,7 +271,7 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
goto out; goto out;
array->last_cookie = entry->cookie; array->last_cookie = entry->cookie;
array->size++; array->size++;
if (entry->eof == 1) if (entry->eof != 0)
array->eof_index = array->size; array->eof_index = array->size;
out: out:
nfs_readdir_release_array(page); nfs_readdir_release_array(page);
...@@ -311,16 +311,14 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des ...@@ -311,16 +311,14 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
for (i = 0; i < array->size; i++) { for (i = 0; i < array->size; i++) {
if (array->array[i].cookie == *desc->dir_cookie) { if (array->array[i].cookie == *desc->dir_cookie) {
desc->cache_entry_index = i; desc->cache_entry_index = i;
status = 0; return 0;
goto out;
} }
} }
if (i == array->eof_index) { if (array->eof_index >= 0) {
status = -EBADCOOKIE; status = -EBADCOOKIE;
if (*desc->dir_cookie == array->last_cookie) if (*desc->dir_cookie == array->last_cookie)
desc->eof = 1; desc->eof = 1;
} }
out:
return status; return status;
} }
...@@ -328,10 +326,7 @@ static ...@@ -328,10 +326,7 @@ static
int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc) int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
{ {
struct nfs_cache_array *array; struct nfs_cache_array *array;
int status = -EBADCOOKIE; int status;
if (desc->dir_cookie == NULL)
goto out;
array = nfs_readdir_get_array(desc->page); array = nfs_readdir_get_array(desc->page);
if (IS_ERR(array)) { if (IS_ERR(array)) {
...@@ -344,8 +339,10 @@ int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc) ...@@ -344,8 +339,10 @@ int nfs_readdir_search_array(nfs_readdir_descriptor_t *desc)
else else
status = nfs_readdir_search_for_cookie(array, desc); status = nfs_readdir_search_for_cookie(array, desc);
if (status == -EAGAIN) if (status == -EAGAIN) {
desc->last_cookie = array->last_cookie; desc->last_cookie = array->last_cookie;
desc->page_index++;
}
nfs_readdir_release_array(desc->page); nfs_readdir_release_array(desc->page);
out: out:
return status; return status;
...@@ -492,7 +489,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en ...@@ -492,7 +489,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
count++; count++;
if (desc->plus == 1) if (desc->plus != 0)
nfs_prime_dcache(desc->file->f_path.dentry, entry); nfs_prime_dcache(desc->file->f_path.dentry, entry);
status = nfs_readdir_add_to_array(entry, page); 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,7 +497,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
break; break;
} while (!entry->eof); } while (!entry->eof);
if (count == 0 || (status == -EBADCOOKIE && entry->eof == 1)) { if (count == 0 || (status == -EBADCOOKIE && entry->eof != 0)) {
array = nfs_readdir_get_array(page); array = nfs_readdir_get_array(page);
if (!IS_ERR(array)) { if (!IS_ERR(array)) {
array->eof_index = array->size; array->eof_index = array->size;
...@@ -664,8 +661,7 @@ int find_cache_page(nfs_readdir_descriptor_t *desc) ...@@ -664,8 +661,7 @@ int find_cache_page(nfs_readdir_descriptor_t *desc)
return PTR_ERR(desc->page); return PTR_ERR(desc->page);
res = nfs_readdir_search_array(desc); res = nfs_readdir_search_array(desc);
if (res == 0) if (res != 0)
return 0;
cache_page_release(desc); cache_page_release(desc);
return res; return res;
} }
...@@ -680,20 +676,12 @@ int readdir_search_pagecache(nfs_readdir_descriptor_t *desc) ...@@ -680,20 +676,12 @@ int readdir_search_pagecache(nfs_readdir_descriptor_t *desc)
desc->current_index = 0; desc->current_index = 0;
desc->last_cookie = 0; desc->last_cookie = 0;
} }
while (1) { do {
res = find_cache_page(desc); res = find_cache_page(desc);
if (res != -EAGAIN) } while (res == -EAGAIN);
break;
desc->page_index++;
}
return res; return res;
} }
static inline unsigned int dt_type(struct inode *inode)
{
return (inode->i_mode >> 12) & 15;
}
/* /*
* Once we've found the start of the dirent within a page: fill 'er up... * Once we've found the start of the dirent within a page: fill 'er up...
*/ */
...@@ -723,13 +711,12 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent, ...@@ -723,13 +711,12 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc, void *dirent,
break; break;
} }
file->f_pos++; file->f_pos++;
desc->cache_entry_index = i;
if (i < (array->size-1)) if (i < (array->size-1))
*desc->dir_cookie = array->array[i+1].cookie; *desc->dir_cookie = array->array[i+1].cookie;
else else
*desc->dir_cookie = array->last_cookie; *desc->dir_cookie = array->last_cookie;
} }
if (i == array->eof_index) if (array->eof_index >= 0)
desc->eof = 1; desc->eof = 1;
nfs_readdir_release_array(desc->page); nfs_readdir_release_array(desc->page);
...@@ -798,7 +785,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -798,7 +785,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
nfs_readdir_descriptor_t my_desc, nfs_readdir_descriptor_t my_desc,
*desc = &my_desc; *desc = &my_desc;
int res = -ENOMEM; int res;
dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n", dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
dentry->d_parent->d_name.name, dentry->d_name.name, 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,7 +810,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (res < 0) if (res < 0)
goto out; goto out;
while (desc->eof != 1) { do {
res = readdir_search_pagecache(desc); res = readdir_search_pagecache(desc);
if (res == -EBADCOOKIE) { if (res == -EBADCOOKIE) {
...@@ -851,7 +838,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -851,7 +838,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
res = nfs_do_filldir(desc, dirent, filldir); res = nfs_do_filldir(desc, dirent, filldir);
if (res < 0) if (res < 0)
break; break;
} } while (!desc->eof);
out: out:
nfs_unblock_sillyrename(dentry); nfs_unblock_sillyrename(dentry);
if (res > 0) if (res > 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment