[BACK]Return to fstrans.9 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / man / man9

File: [cvs.NetBSD.org] / src / share / man / man9 / fstrans.9 (download)

Revision 1.12, Wed Apr 30 13:10:58 2008 UTC (15 years, 11 months ago) by martin
Branch: MAIN
CVS Tags: yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, mjf-devfs2-base, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-base2, hpcarm-cleanup-nbase
Branch point for: jym-xensuspend
Changes since 1.11: +1 -8 lines

Convert TNF licenses to new 2 clause variant

.\"     $NetBSD: fstrans.9,v 1.12 2008/04/30 13:10:58 martin Exp $
.\"
.\" Copyright (c) 2007 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Juergen Hannken-Illjes.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 2, 2007
.Dt FSTRANS 9
.Os
.Sh NAME
.Nm fstrans ,
.Nm fstrans_setstate ,
.Nm fstrans_getstate ,
.Nm fstrans_start ,
.Nm fstrans_start_nowait ,
.Nm fstrans_done ,
.Nm fstrans_is_owner ,
.Nm fscow_establish ,
.Nm fscow_disestablish ,
.Nm fscow_run
.Nd file system suspension helper subsystem
.Sh SYNOPSIS
.In sys/mount.h
.In sys/fstrans.h
.Ft int
.Fn fstrans_setstate "struct mount *mp" "enum fstrans_state new_state"
.Ft "enum fstrans_state"
.Fn fstrans_getstate "struct mount *mp"
.Ft void
.Fn fstrans_start "struct mount *mp" "enum fstrans_lock_type lock_type"
.Ft int
.Fn fstrans_start_nowait "struct mount *mp" "enum fstrans_lock_type lock_type"
.Ft void
.Fn fstrans_done "struct mount *mp"
.Ft int
.Fn fstrans_is_owner "struct mount *mp"
.Ft int
.Fn fscow_establish "struct mount *mp" \
"int (*func)(void *, struct buf *, bool)" "void *cookie"
.Ft int
.Fn fscow_disestablish "struct mount *mp" \
"int (*func)(void *, struct buf *, bool)" "void *cookie"
.Ft int
.Fn fscow_run "struct buf *bp" "bool data_valid"
.Sh DESCRIPTION
The
.Nm
subsystem is a set of operations to assist file system suspension.
These operations must not be used outside of file systems.
.Pp
File systems supporting this subsystem must set the flag
.Dv IMNT_HAS_TRANS
in
.Dv "mnt_iflag" .
.Pp
File systems are always in one of these states:
.Bl -tag -offset indent -width FSTRANS_SUSPENDING -compact
.It Dv FSTRANS_NORMAL
normal operations.
.It Dv FSTRANS_SUSPENDING
preparing a suspension.
.It Dv FSTRANS_SUSPENDED
suspended.
.El
This state is represented by
.Vt "enum fstrans_state" .
.Bl -tag -width compact
.It Fn fstrans_getstate "mp"
returns the current state of the file system
.Fa mp .
.Pp
.It Fn fstrans_setstate "mp" "new_state"
changes the state of the file system
.Fa mp
to
.Fa new_state .
.El
.Pp
All file system operations use a
.Em "fstrans lock" .
This lock is recursive.
A thread already owning a lock will always get another lock.
The lock has two variants:
.Bl -tag -offset indent -width FSTRANS_SHARED -compact
.It Dv FSTRANS_SHARED
this lock will be granted if the file system is in state
.Dv FSTRANS_NORMAL .
.It Dv FSTRANS_LAZY
this lock will be granted if the file system is in state
.Dv FSTRANS_NORMAL
or
.Dv FSTRANS_SUSPENDING .
It needs special care because operations using this variant will not block
while the file system prepares suspension.
.El
The lock variant is represented by
.Vt "enum fstrans_lock_type" .
.Bl -tag -width compact
.It Fn fstrans_start "mp" "lock_type"
sets a lock of type
.Fa lock_type
on the file system
.Fa mp .
.It Fn fstrans_start_nowait "mp" "lock_type"
will not wait for a state change of the file system when attempting to
aquire the lock.
The thread may still sleep while attempting to aquire the lock.
.It Fn fstrans_done "mp"
releases a lock on the file system
.Fa mp .
.It Fn fstrans_is_owner "mp"
returns
.Dv true
if this thread is currently suspending the file system
.Fa mp .
.It Fn fscow_establish "mp" "func" "cookie"
Establish a copy-on-write callback for the file system
.Fa mp .
.Fa func
will be called for every buffer written through this file system.
.It Fn fscow_disestablish "mp" "func" "cookie"
Disestablish a copy-on-write callback registered with
.Fn fscow_establish .
.It Fn fscow_run "bp" "data_valid"
Run all copy-on-write callbacks established for the file system this buffer
belongs to.
If
.Fa data_valid
is
.Dv true
the buffer data has not yet been modified.
.El
.Sh RETURN VALUES
The functions
.Fn fstrans_setstate
and
.Fn fstrans_start_nowait
return zero on success and an error value on failure.
.Sh EXAMPLES
The following is an example of a file system suspend operation.
.Bd -literal
int
xxx_suspendctl(struct mount *mp, int cmd)
{
	int error;

	switch (cmd) {
	case SUSPEND_SUSPEND:
		error = fstrans_setstate(mp, FSTRANS_SUSPENDING);
		if (error != 0)
			return error;

		/* Sync file system state to disk. */

		return fstrans_setstate(mp, FSTRANS_SUSPENDED);

	case SUSPEND_RESUME:
		return fstrans_setstate(mp, FSTRANS_NORMAL);

	default:
		return EINVAL;
	}
}
.Ed
.Pp
This is an example of a file system operation.
.Bd -literal
int
xxx_create(void *v)
{
	struct vop_create_args *ap = v;
	struct mount *mp = ap-\*[Gt]a_dvp-\*[Gt]v_mount;
	int error;

	if ((error = fstrans_start(mp, FSTRANS_SHARED)) != 0)
		return error;

	/* Actually create the node. */

	fstrans_done(mp);

	return 0;
}
.Ed
.Sh SEE ALSO
.Xr vfs_resume 9 ,
.Xr vfs_suspend 9
.Sh CODE REFERENCES
The actual code implementing this subsystem can be found in the file
.Pa sys/kern/vfs_trans.c .
.Sh HISTORY
The
.Nm
subsystem appeared in
.Nx 5.0 .
.Sh AUTHORS
The
.Nm
subsystem was written by
.if t .An J\(:urgen Hannken-Illjes
.if n .An Juergen Hannken-Illjes
.Aq hannken@NetBSD.org .