aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2008-08-11 09:49:04 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2008-10-23 05:13:01 -0400
commit440037287c5ebb07033ab927ca16bb68c291d309 (patch)
treec4be3843ea87a777c2647f471895917005d8068f /fs
parent4ea3ada2955e4519befa98ff55dd62d6dfbd1705 (diff)
[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>
Diffstat (limited to 'fs')
-rw-r--r--fs/dcache.c10
-rw-r--r--fs/efs/namei.c29
-rw-r--r--fs/exportfs/expfs.c4
-rw-r--r--fs/ext2/namei.c13
-rw-r--r--fs/ext3/namei.c14
-rw-r--r--fs/ext4/namei.c11
-rw-r--r--fs/fat/inode.c52
-rw-r--r--fs/fuse/inode.c23
-rw-r--r--fs/gfs2/ops_export.c33
-rw-r--r--fs/isofs/export.c33
-rw-r--r--fs/jfs/namei.c15
-rw-r--r--fs/nfs/getroot.c14
-rw-r--r--fs/ntfs/namei.c22
-rw-r--r--fs/ocfs2/export.c30
-rw-r--r--fs/reiserfs/inode.c13
-rw-r--r--fs/reiserfs/namei.c11
-rw-r--r--fs/udf/namei.c17
-rw-r--r--fs/xfs/linux-2.6/xfs_export.c32
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl.c7
19 files changed, 78 insertions, 305 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 46fc78206782..d45ff7f5ecc2 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1187,17 +1187,17 @@ struct dentry * d_alloc_anon(struct inode *inode)
1187 * allocating a new one. 1187 * allocating a new one.
1188 * 1188 *
1189 * On successful return, the reference to the inode has been transferred 1189 * On successful return, the reference to the inode has been transferred
1190 * to the dentry. If %NULL is returned (indicating kmalloc failure), 1190 * to the dentry. In case of an error the reference on the inode is released.
1191 * the reference on the inode has been released. To make it easier 1191 * To make it easier to use in export operations a %NULL or IS_ERR inode may
1192 * to use in export operations a NULL or IS_ERR inode may be passed in 1192 * be passed in and will be the error will be propagate to the return value,
1193 * and will be casted to the corresponding NULL or IS_ERR dentry. 1193 * with a %NULL @inode replaced by ERR_PTR(-ESTALE).
1194 */ 1194 */
1195struct dentry *d_obtain_alias(struct inode *inode) 1195struct dentry *d_obtain_alias(struct inode *inode)
1196{ 1196{
1197 struct dentry *dentry; 1197 struct dentry *dentry;
1198 1198
1199 if (!inode) 1199 if (!inode)
1200 return NULL; 1200 return ERR_PTR(-ESTALE);
1201 if (IS_ERR(inode)) 1201 if (IS_ERR(inode))
1202 return ERR_CAST(inode); 1202 return ERR_CAST(inode);
1203 1203
diff --git a/fs/efs/namei.c b/fs/efs/namei.c
index 291abb11e20e..c3fb5f9c4a44 100644
--- a/fs/efs/namei.c
+++ b/fs/efs/namei.c
@@ -112,35 +112,14 @@ struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
112 112
113struct dentry *efs_get_parent(struct dentry *child) 113struct dentry *efs_get_parent(struct dentry *child)
114{ 114{
115 struct dentry *parent; 115 struct dentry *parent = ERR_PTR(-ENOENT);
116 struct inode *inode;
117 efs_ino_t ino; 116 efs_ino_t ino;
118 long error;
119 117
120 lock_kernel(); 118 lock_kernel();
121
122 error = -ENOENT;
123 ino = efs_find_entry(child->d_inode, "..", 2); 119 ino = efs_find_entry(child->d_inode, "..", 2);
124 if (!ino) 120 if (ino)
125 goto fail; 121 parent = d_obtain_alias(efs_iget(child->d_inode->i_sb, ino));
126
127 inode = efs_iget(child->d_inode->i_sb, ino);
128 if (IS_ERR(inode)) {
129 error = PTR_ERR(inode);
130 goto fail;
131 }
132
133 error = -ENOMEM;
134 parent = d_alloc_anon(inode);
135 if (!parent)
136 goto fail_iput;
137
138 unlock_kernel(); 122 unlock_kernel();
139 return parent;
140 123
141 fail_iput: 124 return parent;
142 iput(inode);
143 fail:
144 unlock_kernel();
145 return ERR_PTR(error);
146} 125}
diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c
index cc91227d3bb8..7b0f75dcf800 100644
--- a/fs/exportfs/expfs.c
+++ b/fs/exportfs/expfs.c
@@ -366,8 +366,6 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
366 * Try to get any dentry for the given file handle from the filesystem. 366 * Try to get any dentry for the given file handle from the filesystem.
367 */ 367 */
368 result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type); 368 result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type);
369 if (!result)
370 result = ERR_PTR(-ESTALE);
371 if (IS_ERR(result)) 369 if (IS_ERR(result))
372 return result; 370 return result;
373 371
@@ -422,8 +420,6 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
422 420
423 target_dir = nop->fh_to_parent(mnt->mnt_sb, fid, 421 target_dir = nop->fh_to_parent(mnt->mnt_sb, fid,
424 fh_len, fileid_type); 422 fh_len, fileid_type);
425 if (!target_dir)
426 goto err_result;
427 err = PTR_ERR(target_dir); 423 err = PTR_ERR(target_dir);
428 if (IS_ERR(target_dir)) 424 if (IS_ERR(target_dir))
429 goto err_result; 425 goto err_result;
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 80c97fd8c571..a1b328ab1e55 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -73,8 +73,6 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
73struct dentry *ext2_get_parent(struct dentry *child) 73struct dentry *ext2_get_parent(struct dentry *child)
74{ 74{
75 unsigned long ino; 75 unsigned long ino;
76 struct dentry *parent;
77 struct inode *inode;
78 struct dentry dotdot; 76 struct dentry dotdot;
79 77
80 dotdot.d_name.name = ".."; 78 dotdot.d_name.name = "..";
@@ -83,16 +81,7 @@ struct dentry *ext2_get_parent(struct dentry *child)
83 ino = ext2_inode_by_name(child->d_inode, &dotdot); 81 ino = ext2_inode_by_name(child->d_inode, &dotdot);
84 if (!ino) 82 if (!ino)
85 return ERR_PTR(-ENOENT); 83 return ERR_PTR(-ENOENT);
86 inode = ext2_iget(child->d_inode->i_sb, ino); 84 return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino));
87
88 if (IS_ERR(inode))
89 return ERR_CAST(inode);
90 parent = d_alloc_anon(inode);
91 if (!parent) {
92 iput(inode);
93 parent = ERR_PTR(-ENOMEM);
94 }
95 return parent;
96} 85}
97 86
98/* 87/*
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index de13e919cd81..880b54400ac0 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -1057,8 +1057,6 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
1057struct dentry *ext3_get_parent(struct dentry *child) 1057struct dentry *ext3_get_parent(struct dentry *child)
1058{ 1058{
1059 unsigned long ino; 1059 unsigned long ino;
1060 struct dentry *parent;
1061 struct inode *inode;
1062 struct dentry dotdot; 1060 struct dentry dotdot;
1063 struct ext3_dir_entry_2 * de; 1061 struct ext3_dir_entry_2 * de;
1064 struct buffer_head *bh; 1062 struct buffer_head *bh;
@@ -1068,7 +1066,6 @@ struct dentry *ext3_get_parent(struct dentry *child)
1068 dotdot.d_parent = child; /* confusing, isn't it! */ 1066 dotdot.d_parent = child; /* confusing, isn't it! */
1069 1067
1070 bh = ext3_find_entry(&dotdot, &de); 1068 bh = ext3_find_entry(&dotdot, &de);
1071 inode = NULL;
1072 if (!bh) 1069 if (!bh)
1073 return ERR_PTR(-ENOENT); 1070 return ERR_PTR(-ENOENT);
1074 ino = le32_to_cpu(de->inode); 1071 ino = le32_to_cpu(de->inode);
@@ -1080,16 +1077,7 @@ struct dentry *ext3_get_parent(struct dentry *child)
1080 return ERR_PTR(-EIO); 1077 return ERR_PTR(-EIO);
1081 } 1078 }
1082 1079
1083 inode = ext3_iget(child->d_inode->i_sb, ino); 1080 return d_obtain_alias(ext3_iget(child->d_inode->i_sb, ino));
1084 if (IS_ERR(inode))
1085 return ERR_CAST(inode);
1086
1087 parent = d_alloc_anon(inode);
1088 if (!parent) {
1089 iput(inode);
1090 parent = ERR_PTR(-ENOMEM);
1091 }
1092 return parent;
1093} 1081}
1094 1082
1095#define S_SHIFT 12 1083#define S_SHIFT 12
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 92db9e945147..5b93a7d94d42 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1083,16 +1083,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
1083 return ERR_PTR(-EIO); 1083 return ERR_PTR(-EIO);
1084 } 1084 }
1085 1085
1086 inode = ext4_iget(child->d_inode->i_sb, ino); 1086 return d_obtain_alias(ext4_iget(child->d_inode->i_sb, ino));
1087 if (IS_ERR(inode))
1088 return ERR_CAST(inode);
1089
1090 parent = d_alloc_anon(inode);
1091 if (!parent) {
1092 iput(inode);
1093 parent = ERR_PTR(-ENOMEM);
1094 }
1095 return parent;
1096} 1087}
1097 1088
1098#define S_SHIFT 12 1089#define S_SHIFT 12
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index d12cdf2a0406..19eafbe3c379 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -681,33 +681,24 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
681 inode = NULL; 681 inode = NULL;
682 } 682 }
683 } 683 }
684 if (!inode) {
685 /* For now, do nothing
686 * What we could do is:
687 * follow the file starting at fh[4], and record
688 * the ".." entry, and the name of the fh[2] entry.
689 * The follow the ".." file finding the next step up.
690 * This way we build a path to the root of
691 * the tree. If this works, we lookup the path and so
692 * get this inode into the cache.
693 * Finally try the fat_iget lookup again
694 * If that fails, then weare totally out of luck
695 * But all that is for another day
696 */
697 }
698 if (!inode)
699 return ERR_PTR(-ESTALE);
700
701 684
702 /* now to find a dentry. 685 /*
703 * If possible, get a well-connected one 686 * For now, do nothing if the inode is not found.
687 *
688 * What we could do is:
689 *
690 * - follow the file starting at fh[4], and record the ".." entry,
691 * and the name of the fh[2] entry.
692 * - then follow the ".." file finding the next step up.
693 *
694 * This way we build a path to the root of the tree. If this works, we
695 * lookup the path and so get this inode into the cache. Finally try
696 * the fat_iget lookup again. If that fails, then we are totally out
697 * of luck. But all that is for another day
704 */ 698 */
705 result = d_alloc_anon(inode); 699 result = d_obtain_alias(inode);
706 if (result == NULL) { 700 if (!IS_ERR(result))
707 iput(inode); 701 result->d_op = sb->s_root->d_op;
708 return ERR_PTR(-ENOMEM);
709 }
710 result->d_op = sb->s_root->d_op;
711 return result; 702 return result;
712} 703}
713 704
@@ -754,15 +745,8 @@ static struct dentry *fat_get_parent(struct dentry *child)
754 } 745 }
755 inode = fat_build_inode(sb, de, i_pos); 746 inode = fat_build_inode(sb, de, i_pos);
756 brelse(bh); 747 brelse(bh);
757 if (IS_ERR(inode)) { 748
758 parent = ERR_CAST(inode); 749 parent = d_obtain_alias(inode);
759 goto out;
760 }
761 parent = d_alloc_anon(inode);
762 if (!parent) {
763 iput(inode);
764 parent = ERR_PTR(-ENOMEM);
765 }
766out: 750out:
767 unlock_super(sb); 751 unlock_super(sb);
768 752
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 54b1f0e1ef58..2e99f34b4435 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -596,12 +596,8 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
596 if (inode->i_generation != handle->generation) 596 if (inode->i_generation != handle->generation)
597 goto out_iput; 597 goto out_iput;
598 598
599 entry = d_alloc_anon(inode); 599 entry = d_obtain_alias(inode);
600 err = -ENOMEM; 600 if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID) {
601 if (!entry)
602 goto out_iput;
603
604 if (get_node_id(inode) != FUSE_ROOT_ID) {
605 entry->d_op = &fuse_dentry_operations; 601 entry->d_op = &fuse_dentry_operations;
606 fuse_invalidate_entry_cache(entry); 602 fuse_invalidate_entry_cache(entry);
607 } 603 }
@@ -696,17 +692,14 @@ static struct dentry *fuse_get_parent(struct dentry *child)
696 name.name = ".."; 692 name.name = "..";
697 err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode), 693 err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode),
698 &name, &outarg, &inode); 694 &name, &outarg, &inode);
699 if (err && err != -ENOENT) 695 if (err) {
696 if (err == -ENOENT)
697 return ERR_PTR(-ESTALE);
700 return ERR_PTR(err); 698 return ERR_PTR(err);
701 if (err || !inode)
702 return ERR_PTR(-ESTALE);
703
704 parent = d_alloc_anon(inode);
705 if (!parent) {
706 iput(inode);
707 return ERR_PTR(-ENOMEM);
708 } 699 }
709 if (get_node_id(inode) != FUSE_ROOT_ID) { 700
701 parent = d_obtain_alias(inode);
702 if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID) {
710 parent->d_op = &fuse_dentry_operations; 703 parent->d_op = &fuse_dentry_operations;
711 fuse_invalidate_entry_cache(parent); 704 fuse_invalidate_entry_cache(parent);
712 } 705 }
diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c
index 9cda8536530c..bbb8c36403a9 100644
--- a/fs/gfs2/ops_export.c
+++ b/fs/gfs2/ops_export.c
@@ -130,28 +130,17 @@ static int gfs2_get_name(struct dentry *parent, char *name,
130static struct dentry *gfs2_get_parent(struct dentry *child) 130static struct dentry *gfs2_get_parent(struct dentry *child)
131{ 131{
132 struct qstr dotdot; 132 struct qstr dotdot;
133 struct inode *inode;
134 struct dentry *dentry; 133 struct dentry *dentry;
135 134
136 gfs2_str2qstr(&dotdot, "..");
137 inode = gfs2_lookupi(child->d_inode, &dotdot, 1);
138
139 if (!inode)
140 return ERR_PTR(-ENOENT);
141 /* 135 /*
142 * In case of an error, @inode carries the error value, and we 136 * XXX(hch): it would be a good idea to keep this around as a
143 * have to return that as a(n invalid) pointer to dentry. 137 * static variable.
144 */ 138 */
145 if (IS_ERR(inode)) 139 gfs2_str2qstr(&dotdot, "..");
146 return ERR_CAST(inode);
147
148 dentry = d_alloc_anon(inode);
149 if (!dentry) {
150 iput(inode);
151 return ERR_PTR(-ENOMEM);
152 }
153 140
154 dentry->d_op = &gfs2_dops; 141 dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &dotdot, 1));
142 if (!IS_ERR(dentry))
143 dentry->d_op = &gfs2_dops;
155 return dentry; 144 return dentry;
156} 145}
157 146
@@ -233,13 +222,9 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
233 gfs2_glock_dq_uninit(&i_gh); 222 gfs2_glock_dq_uninit(&i_gh);
234 223
235out_inode: 224out_inode:
236 dentry = d_alloc_anon(inode); 225 dentry = d_obtain_alias(inode);
237 if (!dentry) { 226 if (!IS_ERR(dentry))
238 iput(inode); 227 dentry->d_op = &gfs2_dops;
239 return ERR_PTR(-ENOMEM);
240 }
241
242 dentry->d_op = &gfs2_dops;
243 return dentry; 228 return dentry;
244 229
245fail_rgd: 230fail_rgd:
diff --git a/fs/isofs/export.c b/fs/isofs/export.c
index bb219138331a..e81a30593ba9 100644
--- a/fs/isofs/export.c
+++ b/fs/isofs/export.c
@@ -22,7 +22,7 @@ isofs_export_iget(struct super_block *sb,
22 __u32 generation) 22 __u32 generation)
23{ 23{
24 struct inode *inode; 24 struct inode *inode;
25 struct dentry *result; 25
26 if (block == 0) 26 if (block == 0)
27 return ERR_PTR(-ESTALE); 27 return ERR_PTR(-ESTALE);
28 inode = isofs_iget(sb, block, offset); 28 inode = isofs_iget(sb, block, offset);
@@ -32,12 +32,7 @@ isofs_export_iget(struct super_block *sb,
32 iput(inode); 32 iput(inode);
33 return ERR_PTR(-ESTALE); 33 return ERR_PTR(-ESTALE);
34 } 34 }
35 result = d_alloc_anon(inode); 35 return d_obtain_alias(inode);
36 if (!result) {
37 iput(inode);
38 return ERR_PTR(-ENOMEM);
39 }
40 return result;
41} 36}
42 37
43/* This function is surprisingly simple. The trick is understanding 38/* This function is surprisingly simple. The trick is understanding
@@ -51,7 +46,6 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
51 unsigned long parent_offset = 0; 46 unsigned long parent_offset = 0;
52 struct inode *child_inode = child->d_inode; 47 struct inode *child_inode = child->d_inode;
53 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode); 48 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);
54 struct inode *parent_inode = NULL;
55 struct iso_directory_record *de = NULL; 49 struct iso_directory_record *de = NULL;
56 struct buffer_head * bh = NULL; 50 struct buffer_head * bh = NULL;
57 struct dentry *rv = NULL; 51 struct dentry *rv = NULL;
@@ -104,28 +98,11 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
104 /* Normalize */ 98 /* Normalize */
105 isofs_normalize_block_and_offset(de, &parent_block, &parent_offset); 99 isofs_normalize_block_and_offset(de, &parent_block, &parent_offset);
106 100
107 /* Get the inode. */ 101 rv = d_obtain_alias(isofs_iget(child_inode->i_sb, parent_block,
108 parent_inode = isofs_iget(child_inode->i_sb, 102 parent_offset));
109 parent_block,
110 parent_offset);
111 if (IS_ERR(parent_inode)) {
112 rv = ERR_CAST(parent_inode);
113 if (rv != ERR_PTR(-ENOMEM))
114 rv = ERR_PTR(-EACCES);
115 goto out;
116 }
117
118 /* Allocate the dentry. */
119 rv = d_alloc_anon(parent_inode);
120 if (rv == NULL) {
121 rv = ERR_PTR(-ENOMEM);
122 goto out;
123 }
124
125 out: 103 out:
126 if (bh) { 104 if (bh)
127 brelse(bh); 105 brelse(bh);
128 }
129 return rv; 106 return rv;
130} 107}
131 108
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 2aba82386810..e199dde7b83c 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -1511,25 +1511,12 @@ struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
1511 1511
1512struct dentry *jfs_get_parent(struct dentry *dentry) 1512struct dentry *jfs_get_parent(struct dentry *dentry)
1513{ 1513{
1514 struct super_block *sb = dentry->d_inode->i_sb;
1515 struct dentry *parent = ERR_PTR(-ENOENT);
1516 struct inode *inode;
1517 unsigned long parent_ino; 1514 unsigned long parent_ino;
1518 1515
1519 parent_ino = 1516 parent_ino =
1520 le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot); 1517 le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot);
1521 inode = jfs_iget(sb, parent_ino);
1522 if (IS_ERR(inode)) {
1523 parent = ERR_CAST(inode);
1524 } else {
1525 parent = d_alloc_anon(inode);
1526 if (!parent) {
1527 parent = ERR_PTR(-ENOMEM);
1528 iput(inode);
1529 }
1530 }
1531 1518
1532 return parent; 1519 return d_obtain_alias(jfs_iget(dentry->d_inode->i_sb, parent_ino));
1533} 1520}
1534 1521
1535const struct inode_operations jfs_dir_inode_operations = { 1522const struct inode_operations jfs_dir_inode_operations = {
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index fae97196daad..b7c9b2df1f29 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -107,11 +107,10 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
107 * if the dentry tree reaches them; however if the dentry already 107 * if the dentry tree reaches them; however if the dentry already
108 * exists, we'll pick it up at this point and use it as the root 108 * exists, we'll pick it up at this point and use it as the root
109 */ 109 */
110 mntroot = d_alloc_anon(inode); 110 mntroot = d_obtain_alias(inode);
111 if (!mntroot) { 111 if (IS_ERR(mntroot)) {
112 iput(inode);
113 dprintk("nfs_get_root: get root dentry failed\n"); 112 dprintk("nfs_get_root: get root dentry failed\n");
114 return ERR_PTR(-ENOMEM); 113 return mntroot;
115 } 114 }
116 115
117 security_d_instantiate(mntroot, inode); 116 security_d_instantiate(mntroot, inode);
@@ -277,11 +276,10 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
277 * if the dentry tree reaches them; however if the dentry already 276 * if the dentry tree reaches them; however if the dentry already
278 * exists, we'll pick it up at this point and use it as the root 277 * exists, we'll pick it up at this point and use it as the root
279 */ 278 */
280 mntroot = d_alloc_anon(inode); 279 mntroot = d_obtain_alias(inode);
281 if (!mntroot) { 280 if (IS_ERR(mntroot)) {
282 iput(inode);
283 dprintk("nfs_get_root: get root dentry failed\n"); 281 dprintk("nfs_get_root: get root dentry failed\n");
284 return ERR_PTR(-ENOMEM); 282 return mntroot;
285 } 283 }
286 284
287 security_d_instantiate(mntroot, inode); 285 security_d_instantiate(mntroot, inode);
diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
index 9e8a95be7a1e..2ca00153b6ec 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -304,8 +304,6 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
304 ntfs_attr_search_ctx *ctx; 304 ntfs_attr_search_ctx *ctx;
305 ATTR_RECORD *attr; 305 ATTR_RECORD *attr;
306 FILE_NAME_ATTR *fn; 306 FILE_NAME_ATTR *fn;
307 struct inode *parent_vi;
308 struct dentry *parent_dent;
309 unsigned long parent_ino; 307 unsigned long parent_ino;
310 int err; 308 int err;
311 309
@@ -345,24 +343,8 @@ try_next:
345 /* Release the search context and the mft record of the child. */ 343 /* Release the search context and the mft record of the child. */
346 ntfs_attr_put_search_ctx(ctx); 344 ntfs_attr_put_search_ctx(ctx);
347 unmap_mft_record(ni); 345 unmap_mft_record(ni);
348 /* Get the inode of the parent directory. */ 346
349 parent_vi = ntfs_iget(vi->i_sb, parent_ino); 347 return d_obtain_alias(ntfs_iget(vi->i_sb, parent_ino));
350 if (IS_ERR(parent_vi) || unlikely(is_bad_inode(parent_vi))) {
351 if (!IS_ERR(parent_vi))
352 iput(parent_vi);
353 ntfs_error(vi->i_sb, "Failed to get parent directory inode "
354 "0x%lx of child inode 0x%lx.", parent_ino,
355 vi->i_ino);
356 return ERR_PTR(-EACCES);
357 }
358 /* Finally get a dentry for the parent directory and return it. */
359 parent_dent = d_alloc_anon(parent_vi);
360 if (unlikely(!parent_dent)) {
361 iput(parent_vi);
362 return ERR_PTR(-ENOMEM);
363 }
364 ntfs_debug("Done for inode 0x%lx.", vi->i_ino);
365 return parent_dent;
366} 348}
367 349
368static struct inode *ntfs_nfs_get_inode(struct super_block *sb, 350static struct inode *ntfs_nfs_get_inode(struct super_block *sb,
diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c
index 67527cebf214..2f27b332d8b3 100644
--- a/fs/ocfs2/export.c
+++ b/fs/ocfs2/export.c
@@ -68,14 +68,9 @@ static struct dentry *ocfs2_get_dentry(struct super_block *sb,
68 return ERR_PTR(-ESTALE); 68 return ERR_PTR(-ESTALE);
69 } 69 }
70 70
71 result = d_alloc_anon(inode); 71 result = d_obtain_alias(inode);
72 72 if (!IS_ERR(result))
73 if (!result) { 73 result->d_op = &ocfs2_dentry_ops;
74 iput(inode);
75 mlog_errno(-ENOMEM);
76 return ERR_PTR(-ENOMEM);
77 }
78 result->d_op = &ocfs2_dentry_ops;
79 74
80 mlog_exit_ptr(result); 75 mlog_exit_ptr(result);
81 return result; 76 return result;
@@ -86,7 +81,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
86 int status; 81 int status;
87 u64 blkno; 82 u64 blkno;
88 struct dentry *parent; 83 struct dentry *parent;
89 struct inode *inode;
90 struct inode *dir = child->d_inode; 84 struct inode *dir = child->d_inode;
91 85
92 mlog_entry("(0x%p, '%.*s')\n", child, 86 mlog_entry("(0x%p, '%.*s')\n", child,
@@ -109,21 +103,9 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
109 goto bail_unlock; 103 goto bail_unlock;
110 } 104 }
111 105
112 inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0); 106 parent = d_obtain_alias(ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0));
113 if (IS_ERR(inode)) { 107 if (!IS_ERR(parent))
114 mlog(ML_ERROR, "Unable to create inode %llu\n", 108 parent->d_op = &ocfs2_dentry_ops;
115 (unsigned long long)blkno);
116 parent = ERR_PTR(-EACCES);
117 goto bail_unlock;
118 }
119
120 parent = d_alloc_anon(inode);
121 if (!parent) {
122 iput(inode);
123 parent = ERR_PTR(-ENOMEM);
124 }
125
126 parent->d_op = &ocfs2_dentry_ops;
127 109
128bail_unlock: 110bail_unlock:
129 ocfs2_inode_unlock(dir, 0); 111 ocfs2_inode_unlock(dir, 0);
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 5699171212ae..6c4c2c69449f 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -1522,7 +1522,6 @@ static struct dentry *reiserfs_get_dentry(struct super_block *sb,
1522 1522
1523{ 1523{
1524 struct cpu_key key; 1524 struct cpu_key key;
1525 struct dentry *result;
1526 struct inode *inode; 1525 struct inode *inode;
1527 1526
1528 key.on_disk_key.k_objectid = objectid; 1527 key.on_disk_key.k_objectid = objectid;
@@ -1535,16 +1534,8 @@ static struct dentry *reiserfs_get_dentry(struct super_block *sb,
1535 inode = NULL; 1534 inode = NULL;
1536 } 1535 }
1537 reiserfs_write_unlock(sb); 1536 reiserfs_write_unlock(sb);
1538 if (!inode) 1537
1539 inode = ERR_PTR(-ESTALE); 1538 return d_obtain_alias(inode);
1540 if (IS_ERR(inode))
1541 return ERR_CAST(inode);
1542 result = d_alloc_anon(inode);
1543 if (!result) {
1544 iput(inode);
1545 return ERR_PTR(-ENOMEM);
1546 }
1547 return result;
1548} 1539}
1549 1540
1550struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid, 1541struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index c1add28dd45e..f89ebb943f3f 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -383,7 +383,6 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
383 struct inode *inode = NULL; 383 struct inode *inode = NULL;
384 struct reiserfs_dir_entry de; 384 struct reiserfs_dir_entry de;
385 INITIALIZE_PATH(path_to_entry); 385 INITIALIZE_PATH(path_to_entry);
386 struct dentry *parent;
387 struct inode *dir = child->d_inode; 386 struct inode *dir = child->d_inode;
388 387
389 if (dir->i_nlink == 0) { 388 if (dir->i_nlink == 0) {
@@ -401,15 +400,7 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
401 inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id)); 400 inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
402 reiserfs_write_unlock(dir->i_sb); 401 reiserfs_write_unlock(dir->i_sb);
403 402
404 if (!inode || IS_ERR(inode)) { 403 return d_obtain_alias(inode);
405 return ERR_PTR(-EACCES);
406 }
407 parent = d_alloc_anon(inode);
408 if (!parent) {
409 iput(inode);
410 parent = ERR_PTR(-ENOMEM);
411 }
412 return parent;
413} 404}
414 405
415/* add entry to the directory (entry can be hidden). 406/* add entry to the directory (entry can be hidden).
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index d3231947db19..7578fae12d3c 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -1243,7 +1243,6 @@ end_rename:
1243 1243
1244static struct dentry *udf_get_parent(struct dentry *child) 1244static struct dentry *udf_get_parent(struct dentry *child)
1245{ 1245{
1246 struct dentry *parent;
1247 struct inode *inode = NULL; 1246 struct inode *inode = NULL;
1248 struct dentry dotdot; 1247 struct dentry dotdot;
1249 struct fileIdentDesc cfi; 1248 struct fileIdentDesc cfi;
@@ -1266,13 +1265,7 @@ static struct dentry *udf_get_parent(struct dentry *child)
1266 goto out_unlock; 1265 goto out_unlock;
1267 unlock_kernel(); 1266 unlock_kernel();
1268 1267
1269 parent = d_alloc_anon(inode); 1268 return d_obtain_alias(inode);
1270 if (!parent) {
1271 iput(inode);
1272 parent = ERR_PTR(-ENOMEM);
1273 }
1274
1275 return parent;
1276out_unlock: 1269out_unlock:
1277 unlock_kernel(); 1270 unlock_kernel();
1278 return ERR_PTR(-EACCES); 1271 return ERR_PTR(-EACCES);
@@ -1283,7 +1276,6 @@ static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
1283 u16 partref, __u32 generation) 1276 u16 partref, __u32 generation)
1284{ 1277{
1285 struct inode *inode; 1278 struct inode *inode;
1286 struct dentry *result;
1287 kernel_lb_addr loc; 1279 kernel_lb_addr loc;
1288 1280
1289 if (block == 0) 1281 if (block == 0)
@@ -1300,12 +1292,7 @@ static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block,
1300 iput(inode); 1292 iput(inode);
1301 return ERR_PTR(-ESTALE); 1293 return ERR_PTR(-ESTALE);
1302 } 1294 }
1303 result = d_alloc_anon(inode); 1295 return d_obtain_alias(inode);
1304 if (!result) {
1305 iput(inode);
1306 return ERR_PTR(-ENOMEM);
1307 }
1308 return result;
1309} 1296}
1310 1297
1311static struct dentry *udf_fh_to_dentry(struct super_block *sb, 1298static struct dentry *udf_fh_to_dentry(struct super_block *sb,
diff --git a/fs/xfs/linux-2.6/xfs_export.c b/fs/xfs/linux-2.6/xfs_export.c
index 24fd598af846..7f7abec25e14 100644
--- a/fs/xfs/linux-2.6/xfs_export.c
+++ b/fs/xfs/linux-2.6/xfs_export.c
@@ -148,7 +148,6 @@ xfs_fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
148{ 148{
149 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; 149 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid;
150 struct inode *inode = NULL; 150 struct inode *inode = NULL;
151 struct dentry *result;
152 151
153 if (fh_len < xfs_fileid_length(fileid_type)) 152 if (fh_len < xfs_fileid_length(fileid_type))
154 return NULL; 153 return NULL;
@@ -164,16 +163,7 @@ xfs_fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
164 break; 163 break;
165 } 164 }
166 165
167 if (!inode) 166 return d_obtain_alias(inode);
168 return NULL;
169 if (IS_ERR(inode))
170 return ERR_CAST(inode);
171 result = d_alloc_anon(inode);
172 if (!result) {
173 iput(inode);
174 return ERR_PTR(-ENOMEM);
175 }
176 return result;
177} 167}
178 168
179STATIC struct dentry * 169STATIC struct dentry *
@@ -182,7 +172,6 @@ xfs_fs_fh_to_parent(struct super_block *sb, struct fid *fid,
182{ 172{
183 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; 173 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid;
184 struct inode *inode = NULL; 174 struct inode *inode = NULL;
185 struct dentry *result;
186 175
187 switch (fileid_type) { 176 switch (fileid_type) {
188 case FILEID_INO32_GEN_PARENT: 177 case FILEID_INO32_GEN_PARENT:
@@ -195,16 +184,7 @@ xfs_fs_fh_to_parent(struct super_block *sb, struct fid *fid,
195 break; 184 break;
196 } 185 }
197 186
198 if (!inode) 187 return d_obtain_alias(inode);
199 return NULL;
200 if (IS_ERR(inode))
201 return ERR_CAST(inode);
202 result = d_alloc_anon(inode);
203 if (!result) {
204 iput(inode);
205 return ERR_PTR(-ENOMEM);
206 }
207 return result;
208} 188}
209 189
210STATIC struct dentry * 190STATIC struct dentry *
@@ -213,18 +193,12 @@ xfs_fs_get_parent(
213{ 193{
214 int error; 194 int error;
215 struct xfs_inode *cip; 195 struct xfs_inode *cip;
216 struct dentry *parent;
217 196
218 error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL); 197 error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL);
219 if (unlikely(error)) 198 if (unlikely(error))
220 return ERR_PTR(-error); 199 return ERR_PTR(-error);
221 200
222 parent = d_alloc_anon(VFS_I(cip)); 201 return d_obtain_alias(VFS_I(cip));
223 if (unlikely(!parent)) {
224 iput(VFS_I(cip));
225 return ERR_PTR(-ENOMEM);
226 }
227 return parent;
228} 202}
229 203
230const struct export_operations xfs_export_operations = { 204const struct export_operations xfs_export_operations = {
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index 48799ba7e3e6..d3438c72dcaf 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -311,11 +311,10 @@ xfs_open_by_handle(
311 return new_fd; 311 return new_fd;
312 } 312 }
313 313
314 dentry = d_alloc_anon(inode); 314 dentry = d_obtain_alias(inode);
315 if (dentry == NULL) { 315 if (IS_ERR(dentry)) {
316 iput(inode);
317 put_unused_fd(new_fd); 316 put_unused_fd(new_fd);
318 return -XFS_ERROR(ENOMEM); 317 return PTR_ERR(dentry);
319 } 318 }
320 319
321 /* Ensure umount returns EBUSY on umounts while this file is open. */ 320 /* Ensure umount returns EBUSY on umounts while this file is open. */