NFS: Ensure we check all allocation return values in new readdir code
Also some clean ups. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
parent
82f2e5472e
commit
4a201d6e3f
1 changed files with 37 additions and 24 deletions
61
fs/nfs/dir.c
61
fs/nfs/dir.c
|
@ -225,33 +225,42 @@ int nfs_readdir_clear_array(struct page *page, gfp_t mask)
|
||||||
* nfs_clear_readdir_array()
|
* nfs_clear_readdir_array()
|
||||||
*/
|
*/
|
||||||
static
|
static
|
||||||
void nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int len)
|
int nfs_readdir_make_qstr(struct qstr *string, const char *name, unsigned int len)
|
||||||
{
|
{
|
||||||
string->len = len;
|
string->len = len;
|
||||||
string->name = kmemdup(name, len, GFP_KERNEL);
|
string->name = kmemdup(name, len, GFP_KERNEL);
|
||||||
string->hash = full_name_hash(string->name, string->len);
|
if (string->name == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
string->hash = full_name_hash(name, len);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
|
int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)
|
||||||
{
|
{
|
||||||
struct nfs_cache_array *array = nfs_readdir_get_array(page);
|
struct nfs_cache_array *array = nfs_readdir_get_array(page);
|
||||||
|
struct nfs_cache_array_entry *cache_entry;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (IS_ERR(array))
|
if (IS_ERR(array))
|
||||||
return PTR_ERR(array);
|
return PTR_ERR(array);
|
||||||
if (array->size >= MAX_READDIR_ARRAY) {
|
ret = -EIO;
|
||||||
nfs_readdir_release_array(page);
|
if (array->size >= MAX_READDIR_ARRAY)
|
||||||
return -EIO;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
array->array[array->size].cookie = entry->prev_cookie;
|
cache_entry = &array->array[array->size];
|
||||||
|
cache_entry->cookie = entry->prev_cookie;
|
||||||
|
cache_entry->ino = entry->ino;
|
||||||
|
ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
array->last_cookie = entry->cookie;
|
array->last_cookie = entry->cookie;
|
||||||
array->array[array->size].ino = entry->ino;
|
|
||||||
nfs_readdir_make_qstr(&array->array[array->size].string, entry->name, entry->len);
|
|
||||||
if (entry->eof == 1)
|
if (entry->eof == 1)
|
||||||
array->eof_index = array->size;
|
array->eof_index = array->size;
|
||||||
array->size++;
|
array->size++;
|
||||||
|
out:
|
||||||
nfs_readdir_release_array(page);
|
nfs_readdir_release_array(page);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -388,21 +397,24 @@ different:
|
||||||
static
|
static
|
||||||
void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
|
void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
|
||||||
{
|
{
|
||||||
struct qstr filename;
|
struct qstr filename = {
|
||||||
struct dentry *dentry = NULL;
|
.len = entry->len,
|
||||||
struct dentry *alias = NULL;
|
.name = entry->name,
|
||||||
|
};
|
||||||
|
struct dentry *dentry;
|
||||||
|
struct dentry *alias;
|
||||||
struct inode *dir = parent->d_inode;
|
struct inode *dir = parent->d_inode;
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
|
|
||||||
nfs_readdir_make_qstr(&filename, entry->name, entry->len);
|
if (filename.name[0] == '.') {
|
||||||
if (filename.len == 1 && filename.name[0] == '.')
|
if (filename.len == 1)
|
||||||
dentry = dget(parent);
|
return;
|
||||||
else if (filename.len == 2 && filename.name[0] == '.'
|
if (filename.len == 2 && filename.name[1] == '.')
|
||||||
&& filename.name[1] == '.')
|
return;
|
||||||
dentry = dget_parent(parent);
|
}
|
||||||
else
|
filename.hash = full_name_hash(filename.name, filename.len);
|
||||||
dentry = d_lookup(parent, &filename);
|
|
||||||
|
|
||||||
|
dentry = d_lookup(parent, &filename);
|
||||||
if (dentry != NULL) {
|
if (dentry != NULL) {
|
||||||
if (nfs_same_file(dentry, entry)) {
|
if (nfs_same_file(dentry, entry)) {
|
||||||
nfs_refresh_inode(dentry->d_inode, entry->fattr);
|
nfs_refresh_inode(dentry->d_inode, entry->fattr);
|
||||||
|
@ -414,6 +426,9 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
dentry = d_alloc(parent, &filename);
|
dentry = d_alloc(parent, &filename);
|
||||||
|
if (dentry == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
dentry->d_op = NFS_PROTO(dir)->dentry_ops;
|
dentry->d_op = NFS_PROTO(dir)->dentry_ops;
|
||||||
inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr);
|
inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr);
|
||||||
if (IS_ERR(inode))
|
if (IS_ERR(inode))
|
||||||
|
@ -430,8 +445,6 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
kfree(filename.name);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform conversion from xdr to cache array */
|
/* Perform conversion from xdr to cache array */
|
||||||
|
@ -508,7 +521,7 @@ void *nfs_readdir_large_page(struct page **pages, unsigned int npages)
|
||||||
pages[i] = page;
|
pages[i] = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = vm_map_ram(pages, NFS_MAX_READDIR_PAGES, 0, PAGE_KERNEL);
|
ptr = vm_map_ram(pages, npages, 0, PAGE_KERNEL);
|
||||||
if (!IS_ERR_OR_NULL(ptr))
|
if (!IS_ERR_OR_NULL(ptr))
|
||||||
return ptr;
|
return ptr;
|
||||||
out_freepages:
|
out_freepages:
|
||||||
|
|
Loading…
Add table
Reference in a new issue