Re: [RFC][PATCH 5/5] make open_namei() return a filp

From: Christoph Hellwig
Date: Thu Sep 27 2007 - 14:55:51 EST


On Thu, Sep 27, 2007 at 11:52:15AM -0700, Dave Hansen wrote:
> If open_namei() succeeds, there is potentially a mnt_want_write()
> that needs to get balanced. If the caller doesn't create a
> 'struct file' and eventually __fput() it, or manually drop the
> write count on an error, we have a bug.
>
> Forcing open_namei() to return a filp fixes this. Any caller
> getting a 'struct file' back must consider that filp instantiated
> and fput() it normally. The callers no longer have to worry about
> ever manually releasing a mnt write count.

> diff -puN fs/open.c~make-open_namei-return-a-filp fs/open.c
> --- lxc/fs/open.c~make-open_namei-return-a-filp 2007-09-27 11:51:34.000000000 -0700
> +++ lxc-dave/fs/open.c 2007-09-27 11:51:34.000000000 -0700
> @@ -846,11 +846,7 @@ static struct file *do_filp_open(int dfd
> int error;
> struct nameidata nd;
>
> - error = open_namei(dfd, filename, flags, mode, &nd);
> - if (!error)
> - return nameidata_to_filp(&nd, flags);
> -
> - return ERR_PTR(error);
> + return open_namei(dfd, filename, flags, mode, &nd);

Error is unused now, and it's also rather silly to allocate the
nd here when it's only used inside open_namei. So I'd suggest
killing do_filp_open, and maybe filp_open aswell while you're at
it.
-
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/