[PATCH] switch all filesystems over to d_obtain_alias

Switch all users of d_alloc_anon to d_obtain_alias.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Christoph Hellwig 2008-08-11 15:49:04 +02:00 committed by Al Viro
parent 4ea3ada295
commit 440037287c
19 changed files with 78 additions and 305 deletions

View file

@ -1187,17 +1187,17 @@ struct dentry * d_alloc_anon(struct inode *inode)
* allocating a new one. * allocating a new one.
* *
* On successful return, the reference to the inode has been transferred * On successful return, the reference to the inode has been transferred
* to the dentry. If %NULL is returned (indicating kmalloc failure), * to the dentry. In case of an error the reference on the inode is released.
* the reference on the inode has been released. To make it easier * To make it easier to use in export operations a %NULL or IS_ERR inode may
* to use in export operations a NULL or IS_ERR inode may be passed in * be passed in and will be the error will be propagate to the return value,
* and will be casted to the corresponding NULL or IS_ERR dentry. * with a %NULL @inode replaced by ERR_PTR(-ESTALE).
*/ */
struct dentry *d_obtain_alias(struct inode *inode) struct dentry *d_obtain_alias(struct inode *inode)
{ {
struct dentry *dentry; struct dentry *dentry;
if (!inode) if (!inode)
return NULL; return ERR_PTR(-ESTALE);
if (IS_ERR(inode)) if (IS_ERR(inode))
return ERR_CAST(inode); return ERR_CAST(inode);

View file

@ -112,35 +112,14 @@ struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
struct dentry *efs_get_parent(struct dentry *child) struct dentry *efs_get_parent(struct dentry *child)
{ {
struct dentry *parent; struct dentry *parent = ERR_PTR(-ENOENT);
struct inode *inode;
efs_ino_t ino; efs_ino_t ino;
long error;
lock_kernel(); lock_kernel();
error = -ENOENT;
ino = efs_find_entry(child->d_inode, "..", 2); ino = efs_find_entry(child->d_inode, "..", 2);
if (!ino) if (ino)
goto fail; parent = d_obtain_alias(efs_iget(child->d_inode->i_sb, ino));
inode = efs_iget(child->d_inode->i_sb, ino);
if (IS_ERR(inode)) {
error = PTR_ERR(inode);
goto fail;
}
error = -ENOMEM;
parent = d_alloc_anon(inode);
if (!parent)
goto fail_iput;
unlock_kernel(); unlock_kernel();
return parent; return parent;
fail_iput:
iput(inode);
fail:
unlock_kernel();
return ERR_PTR(error);
} }

View file

@ -366,8 +366,6 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
* Try to get any dentry for the given file handle from the filesystem. * Try to get any dentry for the given file handle from the filesystem.
*/ */
result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type); result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type);
if (!result)
result = ERR_PTR(-ESTALE);
if (IS_ERR(result)) if (IS_ERR(result))
return result; return result;
@ -422,8 +420,6 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
target_dir = nop->fh_to_parent(mnt->mnt_sb, fid, target_dir = nop->fh_to_parent(mnt->mnt_sb, fid,
fh_len, fileid_type); fh_len, fileid_type);
if (!target_dir)
goto err_result;
err = PTR_ERR(target_dir); err = PTR_ERR(target_dir);
if (IS_ERR(target_dir)) if (IS_ERR(target_dir))
goto err_result; goto err_result;

View file

@ -73,8 +73,6 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
struct dentry *ext2_get_parent(struct dentry *child) struct dentry *ext2_get_parent(struct dentry *child)
{ {
unsigned long ino; unsigned long ino;
struct dentry *parent;
struct inode *inode;
struct dentry dotdot; struct dentry dotdot;
dotdot.d_name.name = ".."; dotdot.d_name.name = "..";
@ -83,16 +81,7 @@ struct dentry *ext2_get_parent(struct dentry *child)
ino = ext2_inode_by_name(child->d_inode, &dotdot); ino = ext2_inode_by_name(child->d_inode, &dotdot);
if (!ino) if (!ino)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
inode = ext2_iget(child->d_inode->i_sb, ino); return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino));
if (IS_ERR(inode))
return ERR_CAST(inode);
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
return parent;
} }
/* /*

View file

@ -1057,8 +1057,6 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
struct dentry *ext3_get_parent(struct dentry *child) struct dentry *ext3_get_parent(struct dentry *child)
{ {
unsigned long ino; unsigned long ino;
struct dentry *parent;
struct inode *inode;
struct dentry dotdot; struct dentry dotdot;
struct ext3_dir_entry_2 * de; struct ext3_dir_entry_2 * de;
struct buffer_head *bh; struct buffer_head *bh;
@ -1068,7 +1066,6 @@ struct dentry *ext3_get_parent(struct dentry *child)
dotdot.d_parent = child; /* confusing, isn't it! */ dotdot.d_parent = child; /* confusing, isn't it! */
bh = ext3_find_entry(&dotdot, &de); bh = ext3_find_entry(&dotdot, &de);
inode = NULL;
if (!bh) if (!bh)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
ino = le32_to_cpu(de->inode); ino = le32_to_cpu(de->inode);
@ -1080,16 +1077,7 @@ struct dentry *ext3_get_parent(struct dentry *child)
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
inode = ext3_iget(child->d_inode->i_sb, ino); return d_obtain_alias(ext3_iget(child->d_inode->i_sb, ino));
if (IS_ERR(inode))
return ERR_CAST(inode);
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
return parent;
} }
#define S_SHIFT 12 #define S_SHIFT 12

View file

@ -1083,16 +1083,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
inode = ext4_iget(child->d_inode->i_sb, ino); return d_obtain_alias(ext4_iget(child->d_inode->i_sb, ino));
if (IS_ERR(inode))
return ERR_CAST(inode);
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
return parent;
} }
#define S_SHIFT 12 #define S_SHIFT 12

View file

@ -681,33 +681,24 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
inode = NULL; inode = NULL;
} }
} }
if (!inode) {
/* For now, do nothing
* What we could do is:
* follow the file starting at fh[4], and record
* the ".." entry, and the name of the fh[2] entry.
* The follow the ".." file finding the next step up.
* This way we build a path to the root of
* the tree. If this works, we lookup the path and so
* get this inode into the cache.
* Finally try the fat_iget lookup again
* If that fails, then weare totally out of luck
* But all that is for another day
*/
}
if (!inode)
return ERR_PTR(-ESTALE);
/*
/* now to find a dentry. * For now, do nothing if the inode is not found.
* If possible, get a well-connected one *
* What we could do is:
*
* - follow the file starting at fh[4], and record the ".." entry,
* and the name of the fh[2] entry.
* - then follow the ".." file finding the next step up.
*
* This way we build a path to the root of the tree. If this works, we
* lookup the path and so get this inode into the cache. Finally try
* the fat_iget lookup again. If that fails, then we are totally out
* of luck. But all that is for another day
*/ */
result = d_alloc_anon(inode); result = d_obtain_alias(inode);
if (result == NULL) { if (!IS_ERR(result))
iput(inode); result->d_op = sb->s_root->d_op;
return ERR_PTR(-ENOMEM);
}
result->d_op = sb->s_root->d_op;
return result; return result;
} }
@ -754,15 +745,8 @@ static struct dentry *fat_get_parent(struct dentry *child)
} }
inode = fat_build_inode(sb, de, i_pos); inode = fat_build_inode(sb, de, i_pos);
brelse(bh); brelse(bh);
if (IS_ERR(inode)) {
parent = ERR_CAST(inode); parent = d_obtain_alias(inode);
goto out;
}
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
out: out:
unlock_super(sb); unlock_super(sb);

View file

@ -596,12 +596,8 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
if (inode->i_generation != handle->generation) if (inode->i_generation != handle->generation)
goto out_iput; goto out_iput;
entry = d_alloc_anon(inode); entry = d_obtain_alias(inode);
err = -ENOMEM; if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID) {
if (!entry)
goto out_iput;
if (get_node_id(inode) != FUSE_ROOT_ID) {
entry->d_op = &fuse_dentry_operations; entry->d_op = &fuse_dentry_operations;
fuse_invalidate_entry_cache(entry); fuse_invalidate_entry_cache(entry);
} }
@ -696,17 +692,14 @@ static struct dentry *fuse_get_parent(struct dentry *child)
name.name = ".."; name.name = "..";
err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode), err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode),
&name, &outarg, &inode); &name, &outarg, &inode);
if (err && err != -ENOENT) if (err) {
if (err == -ENOENT)
return ERR_PTR(-ESTALE);
return ERR_PTR(err); return ERR_PTR(err);
if (err || !inode)
return ERR_PTR(-ESTALE);
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
return ERR_PTR(-ENOMEM);
} }
if (get_node_id(inode) != FUSE_ROOT_ID) {
parent = d_obtain_alias(inode);
if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID) {
parent->d_op = &fuse_dentry_operations; parent->d_op = &fuse_dentry_operations;
fuse_invalidate_entry_cache(parent); fuse_invalidate_entry_cache(parent);
} }

View file

@ -130,28 +130,17 @@ static int gfs2_get_name(struct dentry *parent, char *name,
static struct dentry *gfs2_get_parent(struct dentry *child) static struct dentry *gfs2_get_parent(struct dentry *child)
{ {
struct qstr dotdot; struct qstr dotdot;
struct inode *inode;
struct dentry *dentry; struct dentry *dentry;
gfs2_str2qstr(&dotdot, "..");
inode = gfs2_lookupi(child->d_inode, &dotdot, 1);
if (!inode)
return ERR_PTR(-ENOENT);
/* /*
* In case of an error, @inode carries the error value, and we * XXX(hch): it would be a good idea to keep this around as a
* have to return that as a(n invalid) pointer to dentry. * static variable.
*/ */
if (IS_ERR(inode)) gfs2_str2qstr(&dotdot, "..");
return ERR_CAST(inode);
dentry = d_alloc_anon(inode); dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &dotdot, 1));
if (!dentry) { if (!IS_ERR(dentry))
iput(inode); dentry->d_op = &gfs2_dops;
return ERR_PTR(-ENOMEM);
}
dentry->d_op = &gfs2_dops;
return dentry; return dentry;
} }
@ -233,13 +222,9 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
gfs2_glock_dq_uninit(&i_gh); gfs2_glock_dq_uninit(&i_gh);
out_inode: out_inode:
dentry = d_alloc_anon(inode); dentry = d_obtain_alias(inode);
if (!dentry) { if (!IS_ERR(dentry))
iput(inode); dentry->d_op = &gfs2_dops;
return ERR_PTR(-ENOMEM);
}
dentry->d_op = &gfs2_dops;
return dentry; return dentry;
fail_rgd: fail_rgd:

View file

@ -22,7 +22,7 @@ isofs_export_iget(struct super_block *sb,
__u32 generation) __u32 generation)
{ {
struct inode *inode; struct inode *inode;
struct dentry *result;
if (block == 0) if (block == 0)
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
inode = isofs_iget(sb, block, offset); inode = isofs_iget(sb, block, offset);
@ -32,12 +32,7 @@ isofs_export_iget(struct super_block *sb,
iput(inode); iput(inode);
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
} }
result = d_alloc_anon(inode); return d_obtain_alias(inode);
if (!result) {
iput(inode);
return ERR_PTR(-ENOMEM);
}
return result;
} }
/* This function is surprisingly simple. The trick is understanding /* This function is surprisingly simple. The trick is understanding
@ -51,7 +46,6 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
unsigned long parent_offset = 0; unsigned long parent_offset = 0;
struct inode *child_inode = child->d_inode; struct inode *child_inode = child->d_inode;
struct iso_inode_info *e_child_inode = ISOFS_I(child_inode); struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);
struct inode *parent_inode = NULL;
struct iso_directory_record *de = NULL; struct iso_directory_record *de = NULL;
struct buffer_head * bh = NULL; struct buffer_head * bh = NULL;
struct dentry *rv = NULL; struct dentry *rv = NULL;
@ -104,28 +98,11 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
/* Normalize */ /* Normalize */
isofs_normalize_block_and_offset(de, &parent_block, &parent_offset); isofs_normalize_block_and_offset(de, &parent_block, &parent_offset);
/* Get the inode. */ rv = d_obtain_alias(isofs_iget(child_inode->i_sb, parent_block,
parent_inode = isofs_iget(child_inode->i_sb, parent_offset));
parent_block,
parent_offset);
if (IS_ERR(parent_inode)) {
rv = ERR_CAST(parent_inode);
if (rv != ERR_PTR(-ENOMEM))
rv = ERR_PTR(-EACCES);
goto out;
}
/* Allocate the dentry. */
rv = d_alloc_anon(parent_inode);
if (rv == NULL) {
rv = ERR_PTR(-ENOMEM);
goto out;
}
out: out:
if (bh) { if (bh)
brelse(bh); brelse(bh);
}
return rv; return rv;
} }

View file

@ -1511,25 +1511,12 @@ struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
struct dentry *jfs_get_parent(struct dentry *dentry) struct dentry *jfs_get_parent(struct dentry *dentry)
{ {
struct super_block *sb = dentry->d_inode->i_sb;
struct dentry *parent = ERR_PTR(-ENOENT);
struct inode *inode;
unsigned long parent_ino; unsigned long parent_ino;
parent_ino = parent_ino =
le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot); le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot);
inode = jfs_iget(sb, parent_ino);
if (IS_ERR(inode)) {
parent = ERR_CAST(inode);
} else {
parent = d_alloc_anon(inode);
if (!parent) {
parent = ERR_PTR(-ENOMEM);
iput(inode);
}
}
return parent; return d_obtain_alias(jfs_iget(dentry->d_inode->i_sb, parent_ino));
} }
const struct inode_operations jfs_dir_inode_operations = { const struct inode_operations jfs_dir_inode_operations = {

View file

@ -107,11 +107,10 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
* if the dentry tree reaches them; however if the dentry already * if the dentry tree reaches them; however if the dentry already
* exists, we'll pick it up at this point and use it as the root * exists, we'll pick it up at this point and use it as the root
*/ */
mntroot = d_alloc_anon(inode); mntroot = d_obtain_alias(inode);
if (!mntroot) { if (IS_ERR(mntroot)) {
iput(inode);
dprintk("nfs_get_root: get root dentry failed\n"); dprintk("nfs_get_root: get root dentry failed\n");
return ERR_PTR(-ENOMEM); return mntroot;
} }
security_d_instantiate(mntroot, inode); security_d_instantiate(mntroot, inode);
@ -277,11 +276,10 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
* if the dentry tree reaches them; however if the dentry already * if the dentry tree reaches them; however if the dentry already
* exists, we'll pick it up at this point and use it as the root * exists, we'll pick it up at this point and use it as the root
*/ */
mntroot = d_alloc_anon(inode); mntroot = d_obtain_alias(inode);
if (!mntroot) { if (IS_ERR(mntroot)) {
iput(inode);
dprintk("nfs_get_root: get root dentry failed\n"); dprintk("nfs_get_root: get root dentry failed\n");
return ERR_PTR(-ENOMEM); return mntroot;
} }
security_d_instantiate(mntroot, inode); security_d_instantiate(mntroot, inode);

View file

@ -304,8 +304,6 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
ntfs_attr_search_ctx *ctx; ntfs_attr_search_ctx *ctx;
ATTR_RECORD *attr; ATTR_RECORD *attr;
FILE_NAME_ATTR *fn; FILE_NAME_ATTR *fn;
struct inode *parent_vi;
struct dentry *parent_dent;
unsigned long parent_ino; unsigned long parent_ino;
int err; int err;
@ -345,24 +343,8 @@ try_next:
/* Release the search context and the mft record of the child. */ /* Release the search context and the mft record of the child. */
ntfs_attr_put_search_ctx(ctx); ntfs_attr_put_search_ctx(ctx);
unmap_mft_record(ni); unmap_mft_record(ni);
/* Get the inode of the parent directory. */
parent_vi = ntfs_iget(vi->i_sb, parent_ino); return d_obtain_alias(ntfs_iget(vi->i_sb, parent_ino));
if (IS_ERR(parent_vi) || unlikely(is_bad_inode(parent_vi))) {
if (!IS_ERR(parent_vi))
iput(parent_vi);
ntfs_error(vi->i_sb, "Failed to get parent directory inode "
"0x%lx of child inode 0x%lx.", parent_ino,
vi->i_ino);
return ERR_PTR(-EACCES);
}
/* Finally get a dentry for the parent directory and return it. */
parent_dent = d_alloc_anon(parent_vi);
if (unlikely(!parent_dent)) {
iput(parent_vi);
return ERR_PTR(-ENOMEM);
}
ntfs_debug("Done for inode 0x%lx.", vi->i_ino);
return parent_dent;
} }
static struct inode *ntfs_nfs_get_inode(struct super_block *sb, static struct inode *ntfs_nfs_get_inode(struct super_block *sb,

View file

@ -68,14 +68,9 @@ static struct dentry *ocfs2_get_dentry(struct super_block *sb,
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
} }
result = d_alloc_anon(inode); result = d_obtain_alias(inode);
if (!IS_ERR(result))
if (!result) { result->d_op = &ocfs2_dentry_ops;
iput(inode);
mlog_errno(-ENOMEM);
return ERR_PTR(-ENOMEM);
}
result->d_op = &ocfs2_dentry_ops;
mlog_exit_ptr(result); mlog_exit_ptr(result);
return result; return result;
@ -86,7 +81,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
int status; int status;
u64 blkno; u64 blkno;
struct dentry *parent; struct dentry *parent;
struct inode *inode;
struct inode *dir = child->d_inode; struct inode *dir = child->d_inode;
mlog_entry("(0x%p, '%.*s')\n", child, mlog_entry("(0x%p, '%.*s')\n", child,
@ -109,21 +103,9 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
goto bail_unlock; goto bail_unlock;
} }
inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0); parent = d_obtain_alias(ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0));
if (IS_ERR(inode)) { if (!IS_ERR(parent))
mlog(ML_ERROR, "Unable to create inode %llu\n", parent->d_op = &ocfs2_dentry_ops;
(unsigned long long)blkno);
parent = ERR_PTR(-EACCES);
goto bail_unlock;
}
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
parent->d_op = &ocfs2_dentry_ops;
bail_unlock: bail_unlock:
ocfs2_inode_unlock(dir, 0); ocfs2_inode_unlock(dir, 0);

View file

@ -1522,7 +1522,6 @@ static struct dentry *reiserfs_get_dentry(struct super_block *sb,
{ {
struct cpu_key key; struct cpu_key key;
struct dentry *result;
struct inode *inode; struct inode *inode;
key.on_disk_key.k_objectid = objectid; key.on_disk_key.k_objectid = objectid;
@ -1535,16 +1534,8 @@ static struct dentry *reiserfs_get_dentry(struct super_block *sb,
inode = NULL; inode = NULL;
} }
reiserfs_write_unlock(sb); reiserfs_write_unlock(sb);
if (!inode)
inode = ERR_PTR(-ESTALE); return d_obtain_alias(inode);
if (IS_ERR(inode))
return ERR_CAST(inode);
result = d_alloc_anon(inode);
if (!result) {
iput(inode);
return ERR_PTR(-ENOMEM);
}
return result;
} }
struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid, struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,

View file

@ -383,7 +383,6 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
struct inode *inode = NULL; struct inode *inode = NULL;
struct reiserfs_dir_entry de; struct reiserfs_dir_entry de;
INITIALIZE_PATH(path_to_entry); INITIALIZE_PATH(path_to_entry);
struct dentry *parent;
struct inode *dir = child->d_inode; struct inode *dir = child->d_inode;
if (dir->i_nlink == 0) { if (dir->i_nlink == 0) {
@ -401,15 +400,7 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id)); inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
reiserfs_write_unlock(dir->i_sb); reiserfs_write_unlock(dir->i_sb);
if (!inode || IS_ERR(inode)) { return d_obtain_alias(inode);
return ERR_PTR(-EACCES);
}
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
return parent;
} }
/* add entry to the directory (entry can be hidden). /* add entry to the directory (entry can be hidden).

View file

@ -1243,7 +1243,6 @@ end_rename:
static struct dentry *udf_get_parent(struct dentry *child) static struct dentry *udf_get_parent(struct dentry *child)
{ {
struct dentry *parent;
struct inode *inode = NULL; struct inode *inode = NULL;
struct dentry dotdot; struct dentry dotdot;
struct fileIdentDesc cfi; struct fileIdentDesc cfi;
@ -1266,13 +1265,7 @@ static struct dentry *udf_get_parent(struct dentry *child)
goto out_unlock; goto out_unlock;
unlock_kernel(); unlock_kernel();
parent = d_alloc_anon(inode); return d_obtain_alias(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
return parent;
out_unlock: out_unlock:
unlock_kernel(); unlock_kernel();
return ERR_PTR(-EACCES); return ERR_PTR(-EACCES);
@ -1283,7 +1276,6 @@ static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
u16 partref, __u32 generation) u16 partref, __u32 generation)
{ {
struct inode *inode; struct inode *inode;
struct dentry *result;
kernel_lb_addr loc; kernel_lb_addr loc;
if (block == 0) if (block == 0)
@ -1300,12 +1292,7 @@ static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
iput(inode); iput(inode);
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
} }
result = d_alloc_anon(inode); return d_obtain_alias(inode);
if (!result) {
iput(inode);
return ERR_PTR(-ENOMEM);
}
return result;
} }
static struct dentry *udf_fh_to_dentry(struct super_block *sb, static struct dentry *udf_fh_to_dentry(struct super_block *sb,

View file

@ -148,7 +148,6 @@ xfs_fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
{ {
struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid;
struct inode *inode = NULL; struct inode *inode = NULL;
struct dentry *result;
if (fh_len < xfs_fileid_length(fileid_type)) if (fh_len < xfs_fileid_length(fileid_type))
return NULL; return NULL;
@ -164,16 +163,7 @@ xfs_fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
break; break;
} }
if (!inode) return d_obtain_alias(inode);
return NULL;
if (IS_ERR(inode))
return ERR_CAST(inode);
result = d_alloc_anon(inode);
if (!result) {
iput(inode);
return ERR_PTR(-ENOMEM);
}
return result;
} }
STATIC struct dentry * STATIC struct dentry *
@ -182,7 +172,6 @@ xfs_fs_fh_to_parent(struct super_block *sb, struct fid *fid,
{ {
struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid;
struct inode *inode = NULL; struct inode *inode = NULL;
struct dentry *result;
switch (fileid_type) { switch (fileid_type) {
case FILEID_INO32_GEN_PARENT: case FILEID_INO32_GEN_PARENT:
@ -195,16 +184,7 @@ xfs_fs_fh_to_parent(struct super_block *sb, struct fid *fid,
break; break;
} }
if (!inode) return d_obtain_alias(inode);
return NULL;
if (IS_ERR(inode))
return ERR_CAST(inode);
result = d_alloc_anon(inode);
if (!result) {
iput(inode);
return ERR_PTR(-ENOMEM);
}
return result;
} }
STATIC struct dentry * STATIC struct dentry *
@ -213,18 +193,12 @@ xfs_fs_get_parent(
{ {
int error; int error;
struct xfs_inode *cip; struct xfs_inode *cip;
struct dentry *parent;
error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL); error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL);
if (unlikely(error)) if (unlikely(error))
return ERR_PTR(-error); return ERR_PTR(-error);
parent = d_alloc_anon(VFS_I(cip)); return d_obtain_alias(VFS_I(cip));
if (unlikely(!parent)) {
iput(VFS_I(cip));
return ERR_PTR(-ENOMEM);
}
return parent;
} }
const struct export_operations xfs_export_operations = { const struct export_operations xfs_export_operations = {

View file

@ -311,11 +311,10 @@ xfs_open_by_handle(
return new_fd; return new_fd;
} }
dentry = d_alloc_anon(inode); dentry = d_obtain_alias(inode);
if (dentry == NULL) { if (IS_ERR(dentry)) {
iput(inode);
put_unused_fd(new_fd); put_unused_fd(new_fd);
return -XFS_ERROR(ENOMEM); return PTR_ERR(dentry);
} }
/* Ensure umount returns EBUSY on umounts while this file is open. */ /* Ensure umount returns EBUSY on umounts while this file is open. */