Subject: Re: nfs crash
To: Matt Fredette <fredette@theory.lcs.mit.edu>
From: Chuck Silvers <chuq@chuq.com>
List: current-users
Date: 02/08/2002 04:42:21
hi,

I'm not sure why this change would be necessary, since we initialize
np->n_wcred in nfs_open() when the file is being opened with write access.
how can we get modified pages in the cache if the file has never
been opened with write access?  do you know how the file that is having
the problem was modified?  whatever path created the dirty pages in the
page cache should also initialize np->n_wcred.

the problem with initializing the write creds in nfs_flush() is that
the creds we have available at that point don't necessarily have
write access to the file on the server, and doing the flush with the
wrong creds could end up just throwing the data away.

-Chuck


On Thu, Feb 07, 2002 at 07:29:17PM -0500, Matt Fredette wrote:
> 
> > kernel: page fault trap, code=0
> > Stopped in pid 28575 (postgres) at nfs_request+0x1d1: movl 0xc(%ecx),%edx
> > db> t
> > nfs_request+0x1d1
> > nfs_writerpc+0xb8e
> > nfs_doio+0x957
> > nfs_strategy+0x98
> > VOP_STRATEGY+0x34
> > genfs_gop_write+0x3da
> > genfs_putpages+0xa77
> > VOP_PUTPAGES+0x59
> > nfs_flush+0x31
> > nfs_fsync+0x35
> > VOP_FSYNC+0x65
> > nfs_sync+0xac
> > sys_sync+0x8e
> > syscall_plain+0xd5
> 
> When working on the hp700 port, I would see a stack trace pretty
> similar to this in a panic I'd get while trying to halt the machine.
> Poking around it looked to me like credentials weren't getting 
> passed through to everywhere they're needed; this patch to nfs_flush() 
> in nfs/nfs_vnops.c made my problem go away.
> 
> I am completely not an expert on the NFS or filesystem code, and I 
> still haven't 100% ruled out compiler bugs as the source of my problem.
> Hopefully someone in the know can tell me if I really fixed a bug 
> or not. :)
> 
> [snip]
> Index: nfs_vnops.c
> ===================================================================
> RCS file: /cvsroot/syssrc/sys/nfs/nfs_vnops.c,v
> retrieving revision 1.148
> diff -u -r1.148 nfs_vnops.c
> --- nfs_vnops.c	2001/12/15 00:32:49	1.148
> +++ nfs_vnops.c	2002/02/08 00:17:15
> @@ -2883,6 +2883,18 @@
>  	UVMHIST_FUNC("nfs_flush"); UVMHIST_CALLED(ubchist);
>  
>  	simple_lock(&vp->v_interlock);
> +
> +	/*
> +	 * update the cached write creds for this node.
> +	 */
> +	if (cred != NOCRED) {
> +		if (np->n_wcred) {
> +			crfree(np->n_wcred);
> +		}
> +		np->n_wcred = cred;
> +		crhold(cred);
> +	}
> +
>  	error = VOP_PUTPAGES(vp, 0, 0, flushflags);
>  	if (np->n_flag & NWRITEERR) {
>  		error = np->n_error;
> [snip]
> 
> -- 
> Matt Fredette