| From | Sent On | Attachments |
|---|---|---|
| Luoqi Chen | Sep 18, 1998 12:40 pm | |
| Julian Elischer | Sep 18, 1998 2:25 pm | |
| Don Lewis | Sep 18, 1998 8:28 pm | |
| Brian Feldman | Sep 19, 1998 1:41 pm | |
| Don Lewis | Sep 21, 1998 5:51 am | |
| Luoqi Chen | Sep 21, 1998 9:12 am | |
| Luoqi Chen | Sep 21, 1998 9:23 am | |
| Don Lewis | Sep 21, 1998 3:54 pm | |
| Brian Feldman | Sep 21, 1998 4:22 pm | |
| Luoqi Chen | Sep 21, 1998 4:27 pm | |
| Don Lewis | Sep 22, 1998 6:22 am | |
| Luoqi Chen | Sep 22, 1998 9:05 am | |
| Alfred Perlstein | Sep 22, 1998 11:19 am | |
| Kirk McKusick | Sep 22, 1998 1:11 pm | |
| Kirk McKusick | Sep 22, 1998 1:50 pm | |
| Luoqi Chen | Sep 22, 1998 2:39 pm | |
| Luoqi Chen | Sep 22, 1998 3:11 pm | |
| Don Lewis | Sep 22, 1998 5:57 pm | |
| Terry Lambert | Sep 22, 1998 8:04 pm | |
| Terry Lambert | Sep 22, 1998 8:28 pm | |
| Luoqi Chen | Sep 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





