atom feed21 messages in org.freebsd.freebsd-currentRe: Yet another patch to try for soft...
FromSent OnAttachments
Luoqi ChenSep 18, 1998 12:40 pm 
Julian ElischerSep 18, 1998 2:25 pm 
Don LewisSep 18, 1998 8:28 pm 
Brian FeldmanSep 19, 1998 1:41 pm 
Don LewisSep 21, 1998 5:51 am 
Luoqi ChenSep 21, 1998 9:12 am 
Luoqi ChenSep 21, 1998 9:23 am 
Don LewisSep 21, 1998 3:54 pm 
Brian FeldmanSep 21, 1998 4:22 pm 
Luoqi ChenSep 21, 1998 4:27 pm 
Don LewisSep 22, 1998 6:22 am 
Luoqi ChenSep 22, 1998 9:05 am 
Alfred PerlsteinSep 22, 1998 11:19 am 
Kirk McKusickSep 22, 1998 1:11 pm 
Kirk McKusickSep 22, 1998 1:50 pm 
Luoqi ChenSep 22, 1998 2:39 pm 
Luoqi ChenSep 22, 1998 3:11 pm 
Don LewisSep 22, 1998 5:57 pm 
Terry LambertSep 22, 1998 8:04 pm 
Terry LambertSep 22, 1998 8:28 pm 
Luoqi ChenSep 22, 1998 8:59 pm 
Subject:Re: Yet another patch to try for softupdates panic
From:Don Lewis (Don.@tsc.tdk.com)
Date:Sep 22, 1998 6:22:55 am
List:org.freebsd.freebsd-current

On Sep 21, 7:27pm, Luoqi Chen wrote: } Subject: Re: Yet another patch to try for softupdates panic } > It looks like this bogus unlocking could also affect vinvalbuf() which } > expects the vnode to be locked. } > } The unlock is not bogus at all. You have to maintain a strict locking order } to avoid deadlocks. For vnodes, this locking order is the directory tree } itself, i.e., you have to lock the parent first, then the child. So if you } hold the lock on the child and intend to lock the parent, you have to } release the lock on child first, then acquire the lock on the parent, and } then reacquire lock the the child. That's also the reason why you can't have } hardlinks to a directory.

Yes, I read the comments in the code and understand why the locking must be done that way, and I also understand why this new code is needed when a user process calls fsync() for a file that exists on a filesystem using softupdates. What's bogus is that this new code changes the semantics of VOP_FSYNC(). The fact that VOP_FSYNC() may now unlock the vnode for a while then lock it again may break other parts of the kernel that expect the vnode to remain locked across a call VOP_FSYNC(). This change in semantics caused the directory truncation race that your patch fixed, although admittedly this particular call to VOP_FSYNC() was added to support softupdates. For another example, take a look at vinvalbuf(), which has the following code:

/* * Flush out and invalidate all buffers associated with a vnode. * Called with the underlying object locked. */ int vinvalbuf(vp, flags, cred, p, slpflag, slptimeo) [ snip ] if (vp->v_dirtyblkhd.lh_first != NULL) { splx(s); if ((error = VOP_FSYNC(vp, cred, MNT_WAIT, p)) != 0) return (error); s = splbio(); if (vp->v_numoutput > 0 || vp->v_dirtyblkhd.lh_first != NULL) panic("vinvalbuf: dirty bufs"); } splx(s);

It sure looks to me like if VOP_FSYNC() called ffs_fsync(), ffs_fsync() would first write all the dirty buffers and then call softdep_fsync(). Softdep_fsync() would unlock the vnode in order to sync the parent directories, and while the vnode was unlocked, another process could grab the vnode and dirty its buffers. Softdep_fsync() would relock the vnode and return. When VOP_FSYNC() returns, we get a nice panic ...

You could tweak this call to VOP_FSYNC() to get it to avoid the call to softdep_fsync(), but how many other places in the kernel also need to be fixed? It may be better to only call softdep_fsync() from within the fsync() syscall handler. I don't know that any other users of VOP_FSYNC() need to ensure that the parent directories are pushed to disk.

To Unsubscribe: send mail to majo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message