···11871187 * allocating a new one.11881188 *11891189 * On successful return, the reference to the inode has been transferred11901190- * to the dentry. If %NULL is returned (indicating kmalloc failure),11911191- * the reference on the inode has been released. To make it easier11921192- * to use in export operations a NULL or IS_ERR inode may be passed in11931193- * and will be casted to the corresponding NULL or IS_ERR dentry.11901190+ * to the dentry. In case of an error the reference on the inode is released.11911191+ * To make it easier to use in export operations a %NULL or IS_ERR inode may11921192+ * be passed in and will be the error will be propagate to the return value,11931193+ * with a %NULL @inode replaced by ERR_PTR(-ESTALE).11941194 */11951195struct dentry *d_obtain_alias(struct inode *inode)11961196{11971197 struct dentry *dentry;1198119811991199 if (!inode)12001200- return NULL;12001200+ return ERR_PTR(-ESTALE);12011201 if (IS_ERR(inode))12021202 return ERR_CAST(inode);12031203
···366366 * Try to get any dentry for the given file handle from the filesystem.367367 */368368 result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type);369369- if (!result)370370- result = ERR_PTR(-ESTALE);371369 if (IS_ERR(result))372370 return result;373371···420422421423 target_dir = nop->fh_to_parent(mnt->mnt_sb, fid,422424 fh_len, fileid_type);423423- if (!target_dir)424424- goto err_result;425425 err = PTR_ERR(target_dir);426426 if (IS_ERR(target_dir))427427 goto err_result;
···681681 inode = NULL;682682 }683683 }684684- if (!inode) {685685- /* For now, do nothing686686- * What we could do is:687687- * follow the file starting at fh[4], and record688688- * the ".." entry, and the name of the fh[2] entry.689689- * The follow the ".." file finding the next step up.690690- * This way we build a path to the root of691691- * the tree. If this works, we lookup the path and so692692- * get this inode into the cache.693693- * Finally try the fat_iget lookup again694694- * If that fails, then weare totally out of luck695695- * But all that is for another day696696- */697697- }698698- if (!inode)699699- return ERR_PTR(-ESTALE);700684701701-702702- /* now to find a dentry.703703- * If possible, get a well-connected one685685+ /*686686+ * For now, do nothing if the inode is not found.687687+ *688688+ * What we could do is:689689+ *690690+ * - follow the file starting at fh[4], and record the ".." entry,691691+ * and the name of the fh[2] entry.692692+ * - then follow the ".." file finding the next step up.693693+ *694694+ * This way we build a path to the root of the tree. If this works, we695695+ * lookup the path and so get this inode into the cache. Finally try696696+ * the fat_iget lookup again. If that fails, then we are totally out697697+ * of luck. But all that is for another day704698 */705705- result = d_alloc_anon(inode);706706- if (result == NULL) {707707- iput(inode);708708- return ERR_PTR(-ENOMEM);709709- }710710- result->d_op = sb->s_root->d_op;699699+ result = d_obtain_alias(inode);700700+ if (!IS_ERR(result))701701+ result->d_op = sb->s_root->d_op;711702 return result;712703}713704···745754 }746755 inode = fat_build_inode(sb, de, i_pos);747756 brelse(bh);748748- if (IS_ERR(inode)) {749749- parent = ERR_CAST(inode);750750- goto out;751751- }752752- parent = d_alloc_anon(inode);753753- if (!parent) {754754- iput(inode);755755- parent = ERR_PTR(-ENOMEM);756756- }757757+758758+ parent = d_obtain_alias(inode);757759out:758760 unlock_super(sb);759761
+8-15
fs/fuse/inode.c
···596596 if (inode->i_generation != handle->generation)597597 goto out_iput;598598599599- entry = d_alloc_anon(inode);600600- err = -ENOMEM;601601- if (!entry)602602- goto out_iput;603603-604604- if (get_node_id(inode) != FUSE_ROOT_ID) {599599+ entry = d_obtain_alias(inode);600600+ if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID) {605601 entry->d_op = &fuse_dentry_operations;606602 fuse_invalidate_entry_cache(entry);607603 }···692696 name.name = "..";693697 err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode),694698 &name, &outarg, &inode);695695- if (err && err != -ENOENT)699699+ if (err) {700700+ if (err == -ENOENT)701701+ return ERR_PTR(-ESTALE);696702 return ERR_PTR(err);697697- if (err || !inode)698698- return ERR_PTR(-ESTALE);699699-700700- parent = d_alloc_anon(inode);701701- if (!parent) {702702- iput(inode);703703- return ERR_PTR(-ENOMEM);704703 }705705- if (get_node_id(inode) != FUSE_ROOT_ID) {704704+705705+ parent = d_obtain_alias(inode);706706+ if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID) {706707 parent->d_op = &fuse_dentry_operations;707708 fuse_invalidate_entry_cache(parent);708709 }
+9-24
fs/gfs2/ops_export.c
···130130static struct dentry *gfs2_get_parent(struct dentry *child)131131{132132 struct qstr dotdot;133133- struct inode *inode;134133 struct dentry *dentry;135134136136- gfs2_str2qstr(&dotdot, "..");137137- inode = gfs2_lookupi(child->d_inode, &dotdot, 1);138138-139139- if (!inode)140140- return ERR_PTR(-ENOENT);141135 /*142142- * In case of an error, @inode carries the error value, and we143143- * have to return that as a(n invalid) pointer to dentry.136136+ * XXX(hch): it would be a good idea to keep this around as a137137+ * static variable.144138 */145145- if (IS_ERR(inode))146146- return ERR_CAST(inode);139139+ gfs2_str2qstr(&dotdot, "..");147140148148- dentry = d_alloc_anon(inode);149149- if (!dentry) {150150- iput(inode);151151- return ERR_PTR(-ENOMEM);152152- }153153-154154- dentry->d_op = &gfs2_dops;141141+ dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &dotdot, 1));142142+ if (!IS_ERR(dentry))143143+ dentry->d_op = &gfs2_dops;155144 return dentry;156145}157146···222233 gfs2_glock_dq_uninit(&i_gh);223234224235out_inode:225225- dentry = d_alloc_anon(inode);226226- if (!dentry) {227227- iput(inode);228228- return ERR_PTR(-ENOMEM);229229- }230230-231231- dentry->d_op = &gfs2_dops;236236+ dentry = d_obtain_alias(inode);237237+ if (!IS_ERR(dentry))238238+ dentry->d_op = &gfs2_dops;232239 return dentry;233240234241fail_rgd:
+5-28
fs/isofs/export.c
···2222 __u32 generation)2323{2424 struct inode *inode;2525- struct dentry *result;2525+2626 if (block == 0)2727 return ERR_PTR(-ESTALE);2828 inode = isofs_iget(sb, block, offset);···3232 iput(inode);3333 return ERR_PTR(-ESTALE);3434 }3535- result = d_alloc_anon(inode);3636- if (!result) {3737- iput(inode);3838- return ERR_PTR(-ENOMEM);3939- }4040- return result;3535+ return d_obtain_alias(inode);4136}42374338/* This function is surprisingly simple. The trick is understanding···4651 unsigned long parent_offset = 0;4752 struct inode *child_inode = child->d_inode;4853 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);4949- struct inode *parent_inode = NULL;5054 struct iso_directory_record *de = NULL;5155 struct buffer_head * bh = NULL;5256 struct dentry *rv = NULL;···98104 /* Normalize */99105 isofs_normalize_block_and_offset(de, &parent_block, &parent_offset);100106101101- /* Get the inode. */102102- parent_inode = isofs_iget(child_inode->i_sb,103103- parent_block,104104- parent_offset);105105- if (IS_ERR(parent_inode)) {106106- rv = ERR_CAST(parent_inode);107107- if (rv != ERR_PTR(-ENOMEM))108108- rv = ERR_PTR(-EACCES);109109- goto out;110110- }111111-112112- /* Allocate the dentry. */113113- rv = d_alloc_anon(parent_inode);114114- if (rv == NULL) {115115- rv = ERR_PTR(-ENOMEM);116116- goto out;117117- }118118-107107+ rv = d_obtain_alias(isofs_iget(child_inode->i_sb, parent_block,108108+ parent_offset));119109 out:120120- if (bh) {110110+ if (bh)121111 brelse(bh);122122- }123112 return rv;124113}125114
···107107 * if the dentry tree reaches them; however if the dentry already108108 * exists, we'll pick it up at this point and use it as the root109109 */110110- mntroot = d_alloc_anon(inode);111111- if (!mntroot) {112112- iput(inode);110110+ mntroot = d_obtain_alias(inode);111111+ if (IS_ERR(mntroot)) {113112 dprintk("nfs_get_root: get root dentry failed\n");114114- return ERR_PTR(-ENOMEM);113113+ return mntroot;115114 }116115117116 security_d_instantiate(mntroot, inode);···276277 * if the dentry tree reaches them; however if the dentry already277278 * exists, we'll pick it up at this point and use it as the root278279 */279279- mntroot = d_alloc_anon(inode);280280- if (!mntroot) {281281- iput(inode);280280+ mntroot = d_obtain_alias(inode);281281+ if (IS_ERR(mntroot)) {282282 dprintk("nfs_get_root: get root dentry failed\n");283283- return ERR_PTR(-ENOMEM);283283+ return mntroot;284284 }285285286286 security_d_instantiate(mntroot, inode);
+2-20
fs/ntfs/namei.c
···304304 ntfs_attr_search_ctx *ctx;305305 ATTR_RECORD *attr;306306 FILE_NAME_ATTR *fn;307307- struct inode *parent_vi;308308- struct dentry *parent_dent;309307 unsigned long parent_ino;310308 int err;311309···343345 /* Release the search context and the mft record of the child. */344346 ntfs_attr_put_search_ctx(ctx);345347 unmap_mft_record(ni);346346- /* Get the inode of the parent directory. */347347- parent_vi = ntfs_iget(vi->i_sb, parent_ino);348348- if (IS_ERR(parent_vi) || unlikely(is_bad_inode(parent_vi))) {349349- if (!IS_ERR(parent_vi))350350- iput(parent_vi);351351- ntfs_error(vi->i_sb, "Failed to get parent directory inode "352352- "0x%lx of child inode 0x%lx.", parent_ino,353353- vi->i_ino);354354- return ERR_PTR(-EACCES);355355- }356356- /* Finally get a dentry for the parent directory and return it. */357357- parent_dent = d_alloc_anon(parent_vi);358358- if (unlikely(!parent_dent)) {359359- iput(parent_vi);360360- return ERR_PTR(-ENOMEM);361361- }362362- ntfs_debug("Done for inode 0x%lx.", vi->i_ino);363363- return parent_dent;348348+349349+ return d_obtain_alias(ntfs_iget(vi->i_sb, parent_ino));364350}365351366352static struct inode *ntfs_nfs_get_inode(struct super_block *sb,