open() and ESTALE error

Andrey Alekseyev uitm at blackflag.ru
Thu Jun 19 07:27:08 PDT 2003


Corrections:
- the patch is against STABLE
- I know the second lookup will fail if the *current* directory itself
is stale :)

> Could anyone please be so kind to comment this issue?

In particular, I'd like to know if I need NDINIT before entering vn_open()
again, as there are several comments throughout the code about "struct nd"
not being safe after namei() and lookup().  However, the patch seems to
work well without NDINIT. Another thing that interests me, is if any vnode
leakage is possible with re-entering vn_open() for the second time. It
seems to me that not (as the nd.ni_vp is vput()'d inside vn_open() in case
of any error after a successful lookup with namei()).

> --- kern/vfs_syscalls.c.orig	Thu Jun 19 13:22:50 2003
> +++ kern/vfs_syscalls.c	Thu Jun 19 13:29:11 2003
> @@ -1008,6 +1008,7 @@
>  	int type, indx, error;
>  	struct flock lf;
>  	struct nameidata nd;
> +	int stale = 0;
>  
>  	oflags = SCARG(uap, flags);
>  	if ((oflags & O_ACCMODE) == O_ACCMODE)
> @@ -1025,8 +1026,15 @@
>  	 * the descriptor while we are blocked in vn_open()
>  	 */
>  	fhold(fp);
> +again:
>  	error = vn_open(&nd, flags, cmode);
>  	if (error) {
> +		/*
> +		 * if the underlying filesystem returns ESTALE
> +		 * we must have used a cached file handle.
> +		 */
> +		if (error == ESTALE && stale++ == 0)
> +			goto again;
>  		/*
>  		 * release our own reference
>  		 */


More information about the freebsd-hackers mailing list