Subject: Re: Proposal: File system suspension - prerequisite for snapshots
To: None <tech-kern@netbsd.org>
From: Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
List: tech-kern
Date: 08/14/2003 10:31:48
On Wed, Aug 13, 2003 at 02:42:33PM -0700, Bill Studenmund wrote:
> On Wed, 13 Aug 2003, Juergen Hannken-Illjes wrote:
> 
> > On Wed, Aug 13, 2003 at 12:02:01PM -0700, Bill Studenmund wrote:
> > > On Tue, 12 Aug 2003, Juergen Hannken-Illjes wrote:
> > >
> > > > restart:
> > > > 	prepare_a_write_operation
> > > > 	if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
> > > > 		abort_current_preparation
> > > > 		if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
> > > > 			return (error);
> > > > 		goto restart;
> > > > 	}
> > > > 	do_the_write_operation
> > > > 	vn_finished_write(mp);
> > > >
> > > > Doing it this way guarantees that no operation sleeps with locked vnodes.
> > >
> > > Note: don't you end up calling vn_start_write() _after_ you've been told
> > > it's ok to start? :-) If you _want_ that to be part of the interface, we
> > > need to document it. For one, it prevents a simple reference counting
> > > mechanism to determine if writes are in progress.
> >
> > vn_start_write(..., V_NOWAIT) will return zero on success.  If the result
> > is non-zero it means it's NOT ok to start.  So we have to abort and wait
> > until it is ok (the second vn_start_write(..., V_XSLEEP | PCATCH)) and
> > restart the syscall.
> 
> Yes, but you will fall through the vn_start_write() AGAIN. _THAT_ is the
> second call. :-)
> 
> i.e. it will be:
> 
> vn_start_write(..., V_NOWAIT) == error
> vn_start_write(..., V_XSLEEP | PCATCH) == no error
> vn_start_write(..., V_NOWAIT) == no error I assume <- second success call

I still don't see the problem:

	Case 1: Filesystem is not suspended

	vn_start_write(..., V_NOWAIT) succeeds, the gate is open, we do the
	write and close the gate (vn_finished_write())

	Case 2: Filesystem is suspended

	vn_start_write(..., V_NOWAIT) fails, gate is still closed.
	vn_start_write(..., V_XSLEEP | PCATCH) sleeps until the filesystem is
	resumed. The gate is still closed.  The complete system call is
	restarted (goto restart)

The do_the_write_operation is only reached if the filesystem is not suspended.

The flags to vn_start_write are:

	V_NOWAIT	Don't block, return EWOULDBLOCK
	V_XSLEEP	Block, but don't open the gate
-- 
Juergen Hannken-Illjes - hannken@eis.cs.tu-bs.de - TU Braunschweig (Germany)