[PATCH 14/34] vfs: nameidata_to_filp(): don't throw away file on error

From: Miklos Szeredi
Date: Thu Apr 05 2012 - 11:02:51 EST


From: Miklos Szeredi <mszeredi@xxxxxxx>

If open fails, don't put the file. This allows it to be reused if open needs to
be retried.

Signed-off-by: Miklos Szeredi <mszeredi@xxxxxxx>
---
fs/open.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 161c15f..0510e58 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -814,10 +814,11 @@ struct file *nameidata_to_filp(struct nameidata *nd)

/* Pick up the filp from the open intent */
filp = nd->intent.open.file;
- nd->intent.open.file = NULL;

/* Has the filesystem initialised the file for us? */
- if (filp->f_path.dentry == NULL) {
+ if (filp->f_path.dentry != NULL) {
+ nd->intent.open.file = NULL;
+ } else {
struct file *res;

path_get(&nd->path);
@@ -826,6 +827,7 @@ struct file *nameidata_to_filp(struct nameidata *nd)
if (!IS_ERR(res)) {
int error;

+ nd->intent.open.file = NULL;
BUG_ON(res != filp);

error = open_check_o_direct(filp);
@@ -834,7 +836,7 @@ struct file *nameidata_to_filp(struct nameidata *nd)
filp = ERR_PTR(error);
}
} else {
- put_filp(filp);
+ /* Allow nd->intent.open.file to be recycled */
filp = res;
}
}
--
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/