#endif /* CONFIG_NFS_V4 */
-static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir, struct rpc_cred *cred)
+static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct rpc_cred *cred)
{
struct nfs_open_dir_context *ctx;
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
if (ctx != NULL) {
ctx->duped = 0;
- ctx->attr_gencount = NFS_I(dir)->attr_gencount;
ctx->dir_cookie = 0;
ctx->dup_cookie = 0;
ctx->cred = get_rpccred(cred);
- return ctx;
- }
- return ERR_PTR(-ENOMEM);
+ } else
+ ctx = ERR_PTR(-ENOMEM);
+ return ctx;
}
static void put_nfs_open_dir_context(struct nfs_open_dir_context *ctx)
cred = rpc_lookup_cred();
if (IS_ERR(cred))
return PTR_ERR(cred);
- ctx = alloc_nfs_open_dir_context(inode, cred);
+ ctx = alloc_nfs_open_dir_context(cred);
if (IS_ERR(ctx)) {
res = PTR_ERR(ctx);
goto out;
{
loff_t diff = desc->file->f_pos - desc->current_index;
unsigned int index;
+ struct nfs_open_dir_context *ctx = desc->file->private_data;
if (diff < 0)
goto out_eof;
index = (unsigned int)diff;
*desc->dir_cookie = array->array[index].cookie;
desc->cache_entry_index = index;
+ ctx->duped = 0;
return 0;
out_eof:
desc->eof = 1;
int i;
loff_t new_pos;
int status = -EAGAIN;
+ struct nfs_open_dir_context *ctx = desc->file->private_data;
for (i = 0; i < array->size; i++) {
if (array->array[i].cookie == *desc->dir_cookie) {
- struct nfs_inode *nfsi = NFS_I(desc->file->f_path.dentry->d_inode);
- struct nfs_open_dir_context *ctx = desc->file->private_data;
-
new_pos = desc->current_index + i;
- if (ctx->attr_gencount != nfsi->attr_gencount
- || (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))) {
- ctx->duped = 0;
- ctx->attr_gencount = nfsi->attr_gencount;
- } else if (new_pos < desc->file->f_pos) {
- if (ctx->duped > 0
- && ctx->dup_cookie == *desc->dir_cookie) {
- if (printk_ratelimit()) {
- pr_notice("NFS: directory %s/%s contains a readdir loop."
- "Please contact your server vendor. "
- "Offending cookie: %llu\n",
- desc->file->f_dentry->d_parent->d_name.name,
- desc->file->f_dentry->d_name.name,
- *desc->dir_cookie);
- }
- status = -ELOOP;
- goto out;
- }
+ if (new_pos < desc->file->f_pos) {
ctx->dup_cookie = *desc->dir_cookie;
- ctx->duped = -1;
+ ctx->duped = 1;
}
desc->file->f_pos = new_pos;
desc->cache_entry_index = i;
if (*desc->dir_cookie == array->last_cookie)
desc->eof = 1;
}
-out:
return status;
}
struct nfs_cache_array *array = NULL;
struct nfs_open_dir_context *ctx = file->private_data;
+ if (ctx->duped != 0 && ctx->dup_cookie == *desc->dir_cookie) {
+ if (printk_ratelimit()) {
+ pr_notice("NFS: directory %s/%s contains a readdir loop. "
+ "Please contact your server vendor. "
+ "Offending cookie: %llu\n",
+ file->f_dentry->d_parent->d_name.name,
+ file->f_dentry->d_name.name,
+ *desc->dir_cookie);
+ }
+ res = -ELOOP;
+ goto out;
+ }
+
array = nfs_readdir_get_array(desc->page);
if (IS_ERR(array)) {
res = PTR_ERR(array);
*desc->dir_cookie = array->array[i+1].cookie;
else
*desc->dir_cookie = array->last_cookie;
- if (ctx->duped != 0)
- ctx->duped = 1;
}
if (array->eof_index >= 0)
desc->eof = 1;
struct page *page = NULL;
int status;
struct inode *inode = desc->file->f_path.dentry->d_inode;
- struct nfs_open_dir_context *ctx = desc->file->private_data;
dfprintk(DIRCACHE, "NFS: uncached_readdir() searching for cookie %Lu\n",
(unsigned long long)*desc->dir_cookie);
desc->page_index = 0;
desc->last_cookie = *desc->dir_cookie;
desc->page = page;
- ctx->duped = 0;
status = nfs_readdir_xdr_to_array(desc, page, inode);
if (status < 0)
struct nfs_fattr *fattr = NULL;
int error;
- if (nd && (nd->flags & LOOKUP_RCU))
+ if (nd->flags & LOOKUP_RCU)
return -ECHILD;
parent = dget_parent(dentry);
}
-/* Ensure that we revalidate inode->i_nlink */
static void nfs_drop_nlink(struct inode *inode)
{
spin_lock(&inode->i_lock);
- /* drop the inode if we're reasonably sure this is the last link */
- if (inode->i_nlink == 1)
- clear_nlink(inode);
- NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
+ if (inode->i_nlink > 0)
+ drop_nlink(inode);
spin_unlock(&inode->i_lock);
}
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
+ drop_nlink(inode);
nfs_complete_unlink(dentry, inode);
- nfs_drop_nlink(inode);
}
iput(inode);
}
res = NULL;
goto out;
/* This turned out not to be a regular file */
- case -EISDIR:
case -ENOTDIR:
goto no_open;
case -ELOOP:
if (!(nd->intent.open.flags & O_NOFOLLOW))
goto no_open;
+ /* case -EISDIR: */
/* case -EINVAL: */
default:
res = ERR_CAST(inode);
struct nfs_open_context *ctx;
int openflags, ret = 0;
- if (nd && (nd->flags & LOOKUP_RCU))
+ if (nd->flags & LOOKUP_RCU)
return -ECHILD;
inode = dentry->d_inode;
if (inode != NULL) {
nfs_inode_return_delegation(inode);
error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
+ /* The VFS may want to delete this inode */
if (error == 0)
nfs_drop_nlink(inode);
+ nfs_mark_for_revalidate(inode);
} else
error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
if (error == -ENOENT)