From dd1a1955ecaaa17d4bcba822023d4c78bb10ce6c Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Mon, 9 Apr 2012 15:06:03 +0800 Subject: [PATCH] LU-506 dcache: check lookup_instantiate_filp() return value For new kernels, nd->intent.open.file may not be checked before use, but it may be an error code. To avoid this, return error when the original open in lookup_instantiate_filp() fails. Signed-off-by: Lai Siyao Change-Id: Ibfbc4eef284962302418872b9f1af8dce2f95db5 Reviewed-on: http://review.whamcloud.com/2491 Reviewed-by: Peng Tao Tested-by: Hudson Reviewed-by: Fan Yong Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/llite/dcache.c | 21 ++++++--------------- lustre/llite/namei.c | 38 +++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/lustre/llite/dcache.c b/lustre/llite/dcache.c index 830eca1..45543de 100644 --- a/lustre/llite/dcache.c +++ b/lustre/llite/dcache.c @@ -676,21 +676,12 @@ int ll_revalidate_nd(struct dentry *dentry, struct nameidata *nd) (struct ptlrpc_request *) it->d.lustre.it_data); } else { -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) -/* 2.6.1[456] have a bug in open_namei() that forgets to check - * nd->intent.open.file for error, so we need to return it as lookup's result - * instead */ - struct file *filp; - - nd->intent.open.file->private_data = it; - filp = lookup_instantiate_filp(nd, dentry,NULL); - if (IS_ERR(filp)) { - rc = PTR_ERR(filp); - } -#else - nd->intent.open.file->private_data = it; - (void)lookup_instantiate_filp(nd, dentry,NULL); -#endif + struct file *filp; + + nd->intent.open.file->private_data = it; + filp = lookup_instantiate_filp(nd, dentry,NULL); + if (IS_ERR(filp)) + rc = PTR_ERR(filp); } } if (!rc && (nd->flags & LOOKUP_CREATE) && diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 64bbd87..d5c9fbe 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -669,25 +669,17 @@ static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry, (struct ptlrpc_request *) it->d.lustre.it_data); } else { -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) -/* 2.6.1[456] have a bug in open_namei() that forgets to check - * nd->intent.open.file for error, so we need to return it as lookup's result - * instead */ - struct file *filp; - nd->intent.open.file->private_data = it; - filp =lookup_instantiate_filp(nd,dentry, - NULL); - if (IS_ERR(filp)) { - if (de) - dput(de); - de = (struct dentry *) filp; - } -#else - nd->intent.open.file->private_data = it; - (void)lookup_instantiate_filp(nd,dentry, - NULL); -#endif - + struct file *filp; + + nd->intent.open.file->private_data = it; + filp = lookup_instantiate_filp(nd, + dentry, + NULL); + if (IS_ERR(filp)) { + if (de) + dput(de); + de = (struct dentry *)filp; + } } } else if (it_disposition(it, DISP_OPEN_CREATE)) { // XXX This can only reliably work on assumption @@ -908,8 +900,12 @@ static int ll_create_nd(struct inode *dir, struct dentry *dentry, rc = ll_create_it(dir, dentry, mode, it); if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */ - nd->intent.open.file->private_data = it; - lookup_instantiate_filp(nd, dentry, NULL); + struct file *filp; + + nd->intent.open.file->private_data = it; + filp = lookup_instantiate_filp(nd, dentry, NULL); + if (IS_ERR(filp)) + rc = PTR_ERR(filp); } out: -- 1.8.3.1