From 701322d0e64a6530e6263aaf8e852e6171c65de5 Mon Sep 17 00:00:00 2001 From: tappro Date: Mon, 16 May 2005 18:33:01 +0000 Subject: [PATCH] b=5881, 6274 r=alex -fix bug with setting i_ino (thanks alex) -fix issue with non-freed dentry after error -cleanup smfs_do_lookup() code --- lustre/smfs/dir.c | 56 +++++++++++++++++++++++++++++------------------------ lustre/smfs/inode.c | 19 ++++++++++-------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/lustre/smfs/dir.c b/lustre/smfs/dir.c index 3d01e5a..6be2ddd 100644 --- a/lustre/smfs/dir.c +++ b/lustre/smfs/dir.c @@ -166,15 +166,15 @@ do_rehash: } static int smfs_do_lookup (struct inode * dir, - struct dentry * dentry, - struct nameidata *nd, - struct inode **inode, int * flags) + struct dentry * dentry, + struct nameidata *nd, + struct inode **inode) { struct inode *cache_dir = I2CI(dir); struct inode *parent = I2CI(dentry->d_parent->d_inode); struct dentry *cache_dentry = NULL; struct dentry *cache_parent = NULL; - struct dentry *rdentry = NULL; + struct dentry *rdentry = NULL, *tmp = NULL; int rc = 0; struct hook_msg msg = { .dentry = dentry, @@ -191,35 +191,43 @@ static int smfs_do_lookup (struct inode * dir, /* preparing artificial backing fs dentries. */ cache_parent = pre_smfs_dentry(NULL, parent, dentry->d_parent); cache_dentry = pre_smfs_dentry(cache_parent, NULL, dentry); - if (!cache_dentry || !cache_parent) - RETURN(-ENOMEM); + if (!cache_dentry || !cache_parent) { + rc = -ENOMEM; + goto exit; + } SMFS_PRE_HOOK(dir, HOOK_LOOKUP, &msg); /* perform lookup in backing fs. */ rdentry = cache_dir->i_op->lookup(cache_dir, cache_dentry, nd); if (rdentry) { - if (IS_ERR(rdentry)) + if (IS_ERR(rdentry)) { rc = PTR_ERR(rdentry); - } else { - rdentry = dget(cache_dentry); - } + rdentry = NULL; + } + else { + tmp = rdentry; + //copy fields if DCACHE_CROSS_REF + smfs_update_dentry(dentry, tmp); + } + } else + tmp = cache_dentry; - if (!rc && rdentry->d_inode) { - *inode = smfs_get_inode(dir->i_sb, rdentry->d_inode->i_ino, - dir, 0); - if (!(*inode)) { + SMFS_POST_HOOK(dir, HOOK_LOOKUP, &msg, rc); + + if (tmp && tmp->d_inode) { + *inode = smfs_get_inode(dir->i_sb, tmp->d_inode->i_ino, + dir, 0); + if (!(*inode)) rc = -ENOENT; - } } - - SMFS_POST_HOOK(dir, HOOK_LOOKUP, &msg, rc); - if (!rc) { - smfs_update_dentry(dentry, rdentry); - *flags = rdentry->d_flags; + if (rdentry) { + LASSERT(atomic_read(&rdentry->d_count) > 0); dput(rdentry); } + +exit: post_smfs_dentry(cache_dentry); post_smfs_dentry(cache_parent); @@ -232,11 +240,10 @@ static struct dentry * smfs_iopen_lookup(struct inode * dir, { struct dentry * alternate = NULL; struct inode *inode = NULL; - int flags = 0; int rc = 0; ENTRY; - rc = smfs_do_lookup(dir, dentry, nd, &inode, &flags); + rc = smfs_do_lookup(dir, dentry, nd, &inode); if (rc) RETURN(ERR_PTR(rc)); @@ -278,15 +285,14 @@ static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry, { struct dentry * rdentry = NULL; struct inode * inode = NULL; - int flags = 0; int rc; - rc = smfs_do_lookup(dir, dentry, nd, &inode, &flags); + rc = smfs_do_lookup(dir, dentry, nd, &inode); if (rc) RETURN(ERR_PTR(rc)); //lmv stuff. Special dentry that has no inode. - if (flags & DCACHE_CROSS_REF) { + if (dentry->d_flags & DCACHE_CROSS_REF) { d_add(dentry, NULL); RETURN(NULL); } diff --git a/lustre/smfs/inode.c b/lustre/smfs/inode.c index 857a9e6..f31852d 100644 --- a/lustre/smfs/inode.c +++ b/lustre/smfs/inode.c @@ -48,7 +48,7 @@ static void smfs_init_inode_info(struct inode *inode, void *opaque) /* getting backing fs inode. */ LASSERT(sargs); - ino = sargs ? sargs->s_ino : inode->i_ino; + ino = inode->i_ino; cache_inode = iget(S2CSB(inode->i_sb), ino); OBD_ALLOC(inode->u.generic_ip, @@ -68,11 +68,10 @@ static void smfs_init_inode_info(struct inode *inode, void *opaque) inode->i_op = &smfs_iopen_iops; inode->i_fop = &smfs_iopen_fops; } - if (sargs) { - struct inode *dir = sargs->s_inode; - if (dir) - I2SMI(inode)->smi_flags = I2SMI(dir)->smi_flags; - } + //inherit parent inode flags + if (sargs->s_inode) + I2SMI(inode)->smi_flags = I2SMI(sargs->s_inode)->smi_flags; + } else LBUG(); } @@ -139,6 +138,10 @@ static int smfs_test_inode(struct inode *inode, void *opaque) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) int smfs_set_inode(struct inode *inode, void *opaque) { + struct smfs_iget_args *sargs = opaque; + + inode->i_ino = sargs->s_ino; + return 0; } @@ -155,11 +158,11 @@ static struct inode *smfs_iget(struct super_block *sb, ino_t hash, smfs_init_inode_info(inode, (void*)sargs); unlock_new_inode(inode); } - //inode->i_ino = hash; + CDEBUG(D_INODE, "inode: %lu/%u(%p) index %d " "ino %d\n", inode->i_ino, inode->i_generation, inode, sargs->s_index, sargs->s_ino); - inode->i_ino = hash; + } return inode; } -- 1.8.3.1