The file system snapshot pseudo driver.

Uses a hook in spec_strategy() to save data written from a mounted
file system to its block device and a hook in dounmount().

Not enabled by default in any kernel config.

Approved by: Frank van der Linden <fvdl@netbsd.org>
This commit is contained in:
hannken 2003-12-10 11:40:11 +00:00
parent 4949a9ae53
commit fbae381aaa
18 changed files with 2014 additions and 19 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.441 2003/12/05 06:30:18 simonb Exp $
# $NetBSD: mi,v 1.442 2003/12/10 11:40:11 hannken Exp $
. base-sys-root
./altroot base-sys-root
./bin base-sys-root
@ -774,6 +774,7 @@
./usr/sbin/faithd base-router-bin
./usr/sbin/fixmount base-nfsclient-bin
./usr/sbin/fsinfo base-sysutil-bin
./usr/sbin/fssconfig base-sysutil-bin
./usr/sbin/getencstat base-sysutil-bin
./usr/sbin/group base-sysutil-bin
./usr/sbin/groupadd base-sysutil-bin

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.644 2003/12/05 13:49:16 lukem Exp $
# $NetBSD: mi,v 1.645 2003/12/10 11:40:11 hannken Exp $
./usr/bin/addr2line comp-debug-bin
./usr/bin/ar comp-util-bin
./usr/bin/as comp-util-bin
@ -135,6 +135,7 @@
./usr/include/dev/dec/lk201.h comp-c-include
./usr/include/dev/dmover comp-c-include
./usr/include/dev/dmover/dmover_io.h comp-c-include
./usr/include/dev/fssvar.h comp-c-include
./usr/include/dev/hpc comp-c-include
./usr/include/dev/hpc/hpcfbio.h comp-c-include
./usr/include/dev/i2o comp-c-include

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.631 2003/12/05 06:30:18 simonb Exp $
# $NetBSD: mi,v 1.632 2003/12/10 11:40:11 hannken Exp $
./usr/share/info/am-utils.info man-amd-info
./usr/share/info/as.info man-computil-info
./usr/share/info/awk.info man-util-info
@ -676,6 +676,7 @@
./usr/share/man/cat4/fms.0 man-sys-catman
./usr/share/man/cat4/fmv.0 man-sys-catman
./usr/share/man/cat4/fpa.0 man-sys-catman
./usr/share/man/cat4/fss.0 man-sys-catman
./usr/share/man/cat4/fta.0 man-sys-catman
./usr/share/man/cat4/fwiso.0 man-sys-catman
./usr/share/man/cat4/fxp.0 man-sys-catman
@ -1430,6 +1431,7 @@
./usr/share/man/cat8/fsdb.0 man-sysutil-catman
./usr/share/man/cat8/fsinfo.0 man-sysutil-catman
./usr/share/man/cat8/fsirand.0 man-sysutil-catman
./usr/share/man/cat8/fssconfig.0 man-sysutil-catman
./usr/share/man/cat8/ftpd.0 man-netutil-catman
./usr/share/man/cat8/genassym.sh.0 man-sys-catman
./usr/share/man/cat8/getNAME.0 man-man-catman
@ -2429,6 +2431,7 @@
./usr/share/man/man4/fms.4 man-sys-man
./usr/share/man/man4/fmv.4 man-sys-man
./usr/share/man/man4/fpa.4 man-sys-man
./usr/share/man/man4/fss.4 man-sys-man
./usr/share/man/man4/fta.4 man-sys-man
./usr/share/man/man4/fwiso.4 man-sys-man
./usr/share/man/man4/fxp.4 man-sys-man
@ -3184,6 +3187,7 @@
./usr/share/man/man8/fsdb.8 man-sysutil-man
./usr/share/man/man8/fsinfo.8 man-sysutil-man
./usr/share/man/man8/fsirand.8 man-sysutil-man
./usr/share/man/man8/fssconfig.8 man-sysutil-man
./usr/share/man/man8/ftpd.8 man-netutil-man
./usr/share/man/man8/genassym.sh.8 man-sys-man
./usr/share/man/man8/getNAME.8 man-man-man

View File

@ -1,5 +1,5 @@
#!/bin/sh -
# $NetBSD: MAKEDEV.tmpl,v 1.10 2003/11/24 06:31:44 isaki Exp $
# $NetBSD: MAKEDEV.tmpl,v 1.11 2003/12/10 11:40:11 hannken Exp $
#
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
@ -72,6 +72,7 @@
# bmd* Nereid bank memory disks
# ed* IBM PS/2 ESDI disk devices
# fd* "floppy" disk drives (3 1/2", 5 1/4")
# fss* Files system snapshot devices
# gdrom* Dreamcast "gigadisc" CD-ROM drive
# hk* UNIBUS RK06 and RK07
# hp* MASSBUS RM??
@ -316,6 +317,7 @@ all)
makedev std fd pty0
makedev ccd0 ccd1 ccd2 ccd3
makedev cgd0 cgd1 cgd2 cgd3
makedev fss0 fss1 fss2 fss3
makedev md0 md1
makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
makedev vnd0 vnd1 vnd2 vnd3
@ -569,6 +571,14 @@ md*)
makedisk_minimal md ${i#md} %md_blk% %md_chr%
;;
fss*)
name=fss; unit=${i#fss}; blk=%fss_blk%; chr=%fss_chr%
mknod $name$unit b $blk $unit
mknod r$name$unit c $chr $unit
chgrp operator $name$unit r$name$unit
chmod 660 $name$unit r$name$unit
;;
ss*)
case $i in
ss*) name=ss; unit=${i#ss}; chr=%ss_chr%;;

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.303 2003/11/05 02:59:09 uwe Exp $
# $NetBSD: Makefile,v 1.304 2003/12/10 11:40:11 hannken Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
MAN= aac.4 acardide.4 aceride.4 acphy.4 adc.4 adv.4 adw.4 agp.4 \
@ -12,7 +12,7 @@ MAN= aac.4 acardide.4 aceride.4 acphy.4 adc.4 adv.4 adw.4 agp.4 \
ddb.4 de.4 dmoverio.4 dmphy.4 dpt.4 dpti.4 \
drum.4 eap.4 ebus.4 edc.4 elmc.4 emuxki.4 en.4 envsys.4 ep.4 esh.4 \
esis.4 esa.4 esiop.4 esl.4 esm.4 eso.4 exphy.4 \
fd.4 fpa.4 fms.4 fwiso.4 fxp.4 \
fd.4 fpa.4 fms.4 fss.4 fwiso.4 fxp.4 \
gem.4 gentbi.4 glxtphy.4 gpib.4 gre.4 gphyter.4 gsip.4 hme.4 hptide.4 \
icmp.4 icp.4 icsphy.4 idp.4 ifmedia.4 igsfb.4 iha.4 inet.4 \
inphy.4 intersil7170.4 ioasic.4 ioat.4 \

138
share/man/man4/fss.4 Normal file
View File

@ -0,0 +1,138 @@
.\" $NetBSD: fss.4,v 1.1 2003/12/10 11:40:11 hannken Exp $ */
.\"
.\"
.\" Copyright (c) 2003 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.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" 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 10, 2003
.Dt FSS 4
.Os
.Sh NAME
.Nm fss
.Nd file system snapshot device
.Sh SYNOPSIS
.Cd "pseudo-device fss 4"
.Sh DESCRIPTION
The
.Nm
driver provides a read-only interface to the snapshot of a currently
mounted file system.
Reading from a
.Nm
device gives the view of the file system when the snapshot was taken.
It can be configured via
.Xr ioctl 2 .
.Sh IOCTLS
The
.Xr ioctl 2
command codes below are defined in
.Aq Pa sys/dev/fssvar.h .
.Pp
The (third) argument to the
.Xr ioctl 2
should be a pointer to the type indicated.
.Bl -tag -width indent -offset indent
.It Dv FSSIOCSET (struct fss_set)
Configures a
.Nm
device.
.Bd -literal -offset indent
struct fss_set {
char *fss_mount;
char *fss_bstore;
blksize_t fss_csize;
};
.Ed
The struct element
.Va fss_mount
is the mount point of the file system.
The struct element
.Va fss_bstore
is either a regular file or a raw disk device where data overwritten on
the file system will be saved.
The struct element
.Va fss_csize
is the preferred size of this data.
.It Dv FSSIOCGET (struct fss_get)
Gets the status of a
.Nm
device.
.Bd -literal -offset indent
struct fss_get {
char fsg_mount[MNAMELEN];
struct timeval fsg_time;
blksize_t fsg_csize;
blkcnt_t fsg_mount_size;
blkcnt_t fsg_bs_size;
};
.Ed
The struct element
.Va fsg_mount
is the mount point of the file system.
The struct element
.Va fsg_time
is the time this snapshot was taken.
The struct element
.Va fsg_csize
is the current size of data clusters.
The struct element
.Va fsg_mount_size
is the number of clusters of the file system.
The struct element
.Va fsg_bs_size
is the number of clusters written to the backing store.
.It Dv FSSIOCCLR
Unconfigures a
.Nm
device.
.El
.Sh FILES
.Bl -tag -width /dev/rfss? -compact
.It Pa /dev/rfss?
.It Pa /dev/fss?
.El
.Sh SEE ALSO
.Xr fsscontrol 8 ,
.Xr mount 8 ,
.Xr umount 8
.Sh HISTORY
The
.Nm
command appeared in
.Nx 2.0 .
.Sh BUGS
This driver is
.Em experimental .
Be sure you have a backup before you use it.

View File

@ -6,7 +6,7 @@
.\" *** DO NOT EDIT - any changes will be lost!!!
.\" *** ------------------------------------------------------------------
.\"
.\" $NetBSD: MAKEDEV.8,v 1.6 2003/11/24 06:33:17 isaki Exp $
.\" $NetBSD: MAKEDEV.8,v 1.7 2003/12/10 11:40:11 hannken Exp $
.\"
.\" Copyright (c) 2001, 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -42,7 +42,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 23, 2003
.Dd December 10, 2003
.Dt MAKEDEV 8
.Os
.Sh NAME
@ -164,6 +164,9 @@ IBM PS/2 ESDI disk devices, see
``floppy'' disk drives (3 1/2", 5 1/4"), see
.Xr \&amiga/fdc 4 ,
.Xr \&i386/fdc 4
. It Ar fss#
Files system snapshot devices, see
.Xr \&fss 4
. It Ar gdrom#
Dreamcast ``gigadisc'' CD-ROM drive, see
.Xr \&dreamcast/gdrom 4

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.646 2003/12/07 05:30:22 dyoung Exp $
# $NetBSD: files,v 1.647 2003/12/10 11:40:11 hannken Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -985,6 +985,7 @@ defpseudo vnd: disk
defpseudo ccd: disk
defpseudo cgd: disk, des, blowfish, cast128, rijndael
defpseudo md: disk
defpseudo fss: disk
defpseudo pty: tty
defpseudo tb: tty
@ -1086,6 +1087,7 @@ file dev/cgd_crypto.c cgd
file dev/clock_subr.c
file dev/clockctl.c clockctl needs-flag
file dev/dksubr.c cgd
file dev/fss.c fss needs-count
file dev/md.c md needs-count
file dev/midi.c midi | midibus needs-flag
file dev/midisyn.c midisyn

View File

@ -1,4 +1,4 @@
# $NetBSD: majors,v 1.4 2003/10/10 22:46:07 jdolecek Exp $
# $NetBSD: majors,v 1.5 2003/12/10 11:40:11 hannken Exp $
#
# Device majors for Machine-Independent drivers.
#
@ -12,3 +12,4 @@
device-major crypto char 160 opencrypto
device-major pf char 161 pf
device-major vinum char 162 block 162 vinum
device-major fss char 163 block 163 fss

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.17 2003/10/10 06:14:02 grog Exp $
# $NetBSD: Makefile,v 1.18 2003/12/10 11:40:11 hannken Exp $
SUBDIR= apm ata dec dmover hpc i2o ic ieee1394 ir isa ofw \
pci pckbc pcmcia raidframe sbus scsipi sun tc usb vme wscons vinum
@ -6,6 +6,6 @@ SUBDIR= apm ata dec dmover hpc i2o ic ieee1394 ir isa ofw \
INCSDIR= /usr/include/dev
# Only install includes which are used by userland
INCS= ccdvar.h cgdvar.h kttcpio.h md.h vndvar.h
INCS= ccdvar.h cgdvar.h fssvar.h kttcpio.h md.h vndvar.h
.include <bsd.kinc.mk>

1215
sys/dev/fss.c Normal file

File diff suppressed because it is too large Load Diff

163
sys/dev/fssvar.h Normal file
View File

@ -0,0 +1,163 @@
/* $NetBSD: fssvar.h,v 1.1 2003/12/10 11:40:11 hannken Exp $ */
/*-
* Copyright (c) 2003 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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.
*/
#ifndef _SYS_DEV_FSSVAR_H
#define _SYS_DEV_FSSVAR_H
struct fss_set {
char *fss_mount; /* Mount point of file system */
char *fss_bstore; /* Path of backing store */
blksize_t fss_csize; /* Preferred cluster size */
};
struct fss_get {
char fsg_mount[MNAMELEN]; /* Mount point of file system */
struct timeval fsg_time; /* Time this snapshot was taken */
blksize_t fsg_csize; /* Current cluster size */
blkcnt_t fsg_mount_size; /* # clusters on file system */
blkcnt_t fsg_bs_size; /* # clusters on backing store */
};
#define FSSIOCSET _IOW('F', 0, struct fss_set) /* Configure */
#define FSSIOCGET _IOR('F', 1, struct fss_get) /* Status */
#define FSSIOCCLR _IO('F', 2) /* Unconfigure */
#ifdef _KERNEL
#define FSS_CLUSTER_MAX (1<<24) /* Upper bound of clusters. The
sc_copied map uses
FSS_CLUSTER_MAX/NBBY bytes */
typedef enum {
FSS_CACHE_FREE = 0, /* Cache entry is free */
FSS_CACHE_BUSY = 1, /* Cache entry is read from device */
FSS_CACHE_VALID = 2 /* Cache entry contains valid data */
} fss_cache_type;
struct fss_cache {
fss_cache_type fc_type; /* Current state */
struct fss_softc *fc_softc; /* Backlink to our softc */
volatile int fc_xfercount; /* Number of outstanding transfers */
u_int32_t fc_cluster; /* Cluster number of this entry */
caddr_t fc_data; /* Data */
};
struct fss_softc {
int sc_unit; /* Logical unit number */
struct lock sc_lock; /* Get exclusive access to device */
volatile int sc_flags; /* Flags */
#define FSS_ACTIVE 0x01 /* Snapshot is active */
#define FSS_ERROR 0x02 /* I/o error occured */
#define FSS_BS_THREAD 0x04 /* Kernel thread is running */
struct mount *sc_mount; /* Mount point */
char sc_mntname[MNAMELEN]; /* Mount point */
struct timeval sc_time; /* Time this snapshot was taken */
dev_t sc_bdev; /* Underlying block device */
void (*sc_strategy)(struct buf *); /* And its strategy */
struct vnode *sc_bs_vp; /* Our backing store */
int sc_bs_bsize; /* Its bsize */
struct proc *sc_bs_proc; /* Our kernel thread */
u_int32_t sc_clsize; /* Size of cluster */
u_int32_t sc_clcount; /* # clusters in file system */
u_int8_t *sc_copied; /* Map of clusters already copied */
long sc_cllast; /* Bytes in last cluster */
int sc_cowcount; /* Number of cow in progress */
int sc_cache_size; /* Number of entries in sc_cache */
struct fss_cache *sc_cache; /* Cluster cache */
struct bufq_state sc_bufq; /* Transfer queue */
u_int32_t sc_clnext; /* Next free cluster on backing store */
int sc_indir_size; /* # clusters for indirect mapping */
u_int8_t *sc_indir_valid; /* Map of valid indirect clusters */
u_int32_t sc_indir_cur; /* Current indir cluster number */
int sc_indir_dirty; /* Current indir cluster modified */
u_int32_t *sc_indir_data; /* Current indir cluster data */
};
struct fss_softc fss_softc[NFSS];
void fss_copy_on_write(struct fss_softc *, struct buf *);
int fss_umount_hook(struct mount *, int);
/*
* Get this dev's softc if it is a valid device.
* Return a pointer to its softc.
*/
static inline int
fss_dev_to_softc(dev_t dev, struct fss_softc **scp)
{
int unit;
struct fss_softc *sc;
unit = minor(dev);
if (unit < 0 || unit >= NFSS)
return ENODEV;
sc = &fss_softc[unit];
*scp = sc;
return 0;
}
/*
* Check if this buf needs to be copied on write.
* Unroll the loop for small NFSS.
*/
static inline void
fss_cow_hook(struct buf *bp)
{
int i;
if (bp->b_flags & B_READ)
return;
if (NFSS <= 4) {
if (__predict_false(fss_softc[0].sc_bdev == bp->b_dev ||
(NFSS > 1 && fss_softc[1].sc_bdev == bp->b_dev) ||
(NFSS > 2 && fss_softc[2].sc_bdev == bp->b_dev) ||
(NFSS > 3 && fss_softc[3].sc_bdev == bp->b_dev)))
for (i = 0; i < NFSS; i++)
if (fss_softc[i].sc_bdev == bp->b_dev)
fss_copy_on_write(&fss_softc[i], bp);
} else {
for (i = 0; i < NFSS; i++)
if (__predict_false(fss_softc[i].sc_bdev == bp->b_dev))
fss_copy_on_write(&fss_softc[i], bp);
}
}
#endif /* _KERNEL */
#endif /* !_SYS_DEV_FSSVAR_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls.c,v 1.201 2003/11/15 01:19:38 thorpej Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.202 2003/12/10 11:40:12 hannken Exp $ */
/*
* Copyright (c) 1989, 1993
@ -37,11 +37,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.201 2003/11/15 01:19:38 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.202 2003/12/10 11:40:12 hannken Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_43.h"
#include "opt_ktrace.h"
#include "fss.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -66,6 +67,10 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.201 2003/11/15 01:19:38 thorpej E
#include <miscfs/genfs/genfs.h>
#include <miscfs/syncfs/syncfs.h>
#if NFSS > 0
#include <dev/fssvar.h>
#endif
MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount struct");
static int change_dir __P((struct nameidata *, struct proc *));
@ -535,6 +540,9 @@ dounmount(mp, flags, p)
if (mp->mnt_syncer != NULL)
vfs_deallocate_syncvnode(mp);
if (((mp->mnt_flag & MNT_RDONLY) ||
#if NFSS > 0
(error = fss_umount_hook(mp, (flags & MNT_FORCE))) == 0 ||
#endif
(error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p)) == 0) ||
(flags & MNT_FORCE))
error = VFS_UNMOUNT(mp, flags, p);

View File

@ -1,4 +1,4 @@
/* $NetBSD: spec_vnops.c,v 1.74 2003/11/26 11:33:50 pk Exp $ */
/* $NetBSD: spec_vnops.c,v 1.75 2003/12/10 11:40:12 hannken Exp $ */
/*
* Copyright (c) 1989, 1993
@ -32,7 +32,9 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.74 2003/11/26 11:33:50 pk Exp $");
__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.75 2003/12/10 11:40:12 hannken Exp $");
#include "fss.h"
#include <sys/param.h>
#include <sys/proc.h>
@ -54,6 +56,10 @@ __KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.74 2003/11/26 11:33:50 pk Exp $");
#include <miscfs/genfs/genfs.h>
#include <miscfs/specfs/specdev.h>
#if NFSS > 0
#include <dev/fssvar.h>
#endif
/* symbolic sleep message strings for devices */
const char devopn[] = "devopn";
const char devio[] = "devio";
@ -587,8 +593,12 @@ spec_strategy(v)
(LIST_FIRST(&bp->b_dep)) != NULL && bioops.io_start)
(*bioops.io_start)(bp);
bdev = bdevsw_lookup(bp->b_dev);
if (bdev != NULL)
if (bdev != NULL) {
#if NFSS > 0
fss_cow_hook(bp);
#endif
(*bdev->d_strategy)(bp);
}
return (0);
}

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.187 2003/12/07 21:57:22 matt Exp $
# $NetBSD: Makefile,v 1.188 2003/12/10 11:40:12 hannken Exp $
# from: @(#)Makefile 5.20 (Berkeley) 6/12/93
.include <bsd.own.mk>
@ -6,7 +6,7 @@
SUBDIR= ac accton altq amd apm apmd arp bad144 bind bootp catman \
chown chroot chrtbl cnwctl config cron dev_mkdb \
dhcp diskpart dumpfs dumplfs edquota eeprom \
envstat eshconfig etcupdate grfconfig \
envstat eshconfig etcupdate fssconfig grfconfig \
grfinfo gspa hilinfo ifwatchd inetd installboot \
iopctl iostat ipf irdaattach isdn iteconfig \
kgmon lastlogin link lpr mailwrapper makefs \

View File

@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.1 2003/12/10 11:40:12 hannken Exp $
PROG= fssconfig
MAN= fssconfig.8
DPADD+= ${LIBUTIL}
LDADD+= -lutil
.include <bsd.prog.mk>

View File

@ -0,0 +1,166 @@
.\" $NetBSD: fssconfig.8,v 1.1 2003/12/10 11:40:12 hannken Exp $ */
.\"
.\"
.\" Copyright (c) 2003 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.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" 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 10, 2003
.Dt FSSCONFIG 8
.Os
.Sh NAME
.Nm fssconfig
.Nd configure file system snapshot devices
.Sh SYNOPSIS
.Nm
.Op Fl cx
.Ar device
.Ar path
.Ar backup
.Op Ar cluster Op Ar size
.Nm
.Fl u
.Ar device
.Nm
.Fl l Op Fl v
.Op Ar device
.Sh DESCRIPTION
The
.Nm
command configures file system snapshot pseudo disk devices.
It will associate the file system snapshot disk
.Ar device
with a snapshot of
.Ar path
allowing the latter to be accessed as though it were a disk.
Data written through the
.Ar path
will be saved in
.Ar backup
which must not reside on the snapshotted file system.
If
.Ar backup
is a regular file, it will be created with length
.Ar size .
Default size is 10% the size of
.Ar path .
Data is saved to
.Ar backup
in units of
.Ar cluster
bytes.
.Pp
Options indicate an action to be performed:
.Bl -tag -width indent
.It Fl c
Configures the device.
If successful, references to
.Ar device
will access the contents of
.Ar path
at the time the snapshot was taken.
If
.Ar backup
is a directory a temporary file will be created in this directory.
This file will be unlinked on exit.
.It Fl l
List the snapshot devices and indicate which ones are in use.
If a specific
.Ar device
is given, then only that will be described.
.It Fl u
Unconfigures the
.Ar device .
.It Fl v
Be more verbose listing the snapshot devices.
.It Fl x
Unlink
.Ar backup
after the
.Ar device
is configured.
.El
.Pp
If no action option is given,
.Fl c
is assumed.
.Sh FILES
.Bl -tag -width /etc/disktab -compact
.It Pa /dev/rfss?
.It Pa /dev/fss?
.El
.Sh EXAMPLES
.Dl fssconfig fss0 /usr /tmp/back
.Pp
Configures the snapshot device
.Pa fss0
for a snapshot of the
.Pa /usr
file system. Data written through
.Pa /usr
will be backed up in
.Pa /tmp/back .
.Pp
.Dl fssconfig fss1 / /dev/rsd0e 8192
.Pp
Configures the snapshot device
.Pa fss1
for a snapshot of the
.Pa /
file system. Data written through
.Pa /
will be backed up in
.Pa /dev/rsd0e .
The backup will take place in units of 8192 bytes.
.Pp
.Dl fssconfig -u fss0
.Pp
Unconfigures the
.Pa fss0
device.
.Sh SEE ALSO
.Xr opendisk 3 ,
.Xr fss 4 ,
.Xr mount 8 ,
.Xr umount 8
.Sh HISTORY
The
.Nm
command appeared in
.Nx 2.0 .
.Sh BUGS
The
.Xr fss 4
driver is
.Em experimental .
Be sure you have a backup before you use it.

View File

@ -0,0 +1,265 @@
/* $NetBSD: fssconfig.c,v 1.1 2003/12/10 11:40:12 hannken Exp $ */
/*-
* Copyright (c) 2003 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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.
*/
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <util.h>
#include <dev/fssvar.h>
int vflag = 0;
int xflag = 0;
int mkfile(int, off_t);
void config(int, char **);
void unconfig(int, char **);
void list(int, char **);
void usage(void);
int
main(int argc, char **argv)
{
int ch;
void (*action)(int, char **);
action = config;
while ((ch = getopt(argc, argv, "cluvx")) != -1) {
switch (ch) {
case 'c':
action = config;
break;
case 'l':
action = list;
break;
case 'u':
action = unconfig;
break;
case 'v':
vflag++;
break;
case 'x':
xflag++;
break;
default:
case '?':
usage();
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;
(*action)(argc, argv);
exit(0);
}
int
mkfile(int fd, off_t size)
{
char buf[64*1024];
ssize_t l;
memset(buf, 0, sizeof(buf));
while (size > 0) {
if ((l = write(fd, buf, sizeof(buf))) < 0)
return -1;
size -= l;
}
return 0;
}
void
config(int argc, char **argv)
{
int fd, isreg, istmp;
char full[64], path[MAXPATHLEN];
off_t bssize;
struct stat sbuf;
struct statfs fsbuf;
struct fss_set fss;
if (argc < 3)
usage();
istmp = 0;
if (statfs(argv[1], &fsbuf) != 0)
err(1, "statfs %s", argv[1]);
fss.fss_mount = argv[1];
fss.fss_bstore = argv[2];
if (argc > 3)
fss.fss_csize = strsuftoll("cluster size", argv[3], 0, INT_MAX);
else
fss.fss_csize = 0;
if (argc > 4)
bssize = strsuftoll("bs size", argv[4], 0, LLONG_MAX);
else
bssize = (off_t)fsbuf.f_blocks*fsbuf.f_bsize/10;
/*
* Create the backing store. If it is a directory, create a temporary
* file and set the unlink flag.
*/
if ((fd = open(fss.fss_bstore, O_CREAT|O_TRUNC|O_WRONLY, 0600)) < 0) {
if (errno != EISDIR)
err(1, "create: %s", fss.fss_bstore);
snprintf(path, sizeof(path), "%s/XXXXXXXXXX", fss.fss_bstore);
if ((fd = mkstemp(path)) < 0)
err(1, "mkstemp: %s", path);
fss.fss_bstore = path;
istmp = 1;
}
if (fstat(fd, &sbuf) < 0)
err(1, "stat: %s", fss.fss_bstore);
isreg = S_ISREG(sbuf.st_mode);
if (isreg && mkfile(fd, bssize) < 0)
err(1, "write %s", fss.fss_bstore);
close(fd);
if ((fd = opendisk(argv[0], O_RDWR, full, sizeof(full), 0)) < 0) {
if (istmp)
unlink(fss.fss_bstore);
err(1, "open: %s", argv[0]);
}
if (ioctl(fd, FSSIOCSET, &fss) < 0) {
if (istmp)
unlink(fss.fss_bstore);
err(1, "%s: FSSIOCSET", full);
}
if ((xflag || istmp) && isreg && unlink(fss.fss_bstore) < 0)
err(1, "unlink: %s", fss.fss_bstore);
}
void
unconfig(int argc, char **argv)
{
int fd;
char full[64];
if (argc != 1)
usage();
if ((fd = opendisk(argv[0], O_RDWR, full, sizeof(full), 0)) < 0)
err(1, "open: %s", argv[0]);
if (ioctl(fd, FSSIOCCLR) < 0)
err(1, "%s: FSSIOCCLR", full);
}
void
list(int argc, char **argv)
{
int n, fd;
char *dev, path[64], full[64];
char clbuf[5], bsbuf[5], tmbuf[64];
time_t t;
struct fss_get fsg;
if (argc > 1)
usage();
if (argc > 0)
dev = argv[0];
else
dev = path;
for (n = 0; ; n++) {
if (argc == 0)
snprintf(path, sizeof(path), "fss%d", n);
if ((fd = opendisk(dev, O_RDONLY, full, sizeof(full), 0)) < 0) {
if (argc == 0 && (errno == ENOENT || errno == ENXIO))
break;
err(1, "open: %s", dev);
}
if (ioctl(fd, FSSIOCGET, &fsg) < 0) {
if (errno == ENXIO)
printf("%s: not in use\n", dev);
else
err(1, "%s: FSSIOCGET", full);
} else if (vflag) {
humanize_number(clbuf, sizeof(clbuf),
(int64_t)fsg.fsg_csize,
"", HN_AUTOSCALE, HN_B|HN_NOSPACE);
humanize_number(bsbuf, sizeof(bsbuf),
(int64_t)fsg.fsg_bs_size*fsg.fsg_csize,
"", HN_AUTOSCALE, HN_B|HN_NOSPACE);
t = fsg.fsg_time.tv_sec;
strftime(tmbuf, sizeof(tmbuf), "%F %T", localtime(&t));
printf("%s: %s, taken %s, %" PRId64 " clusters of %s"
", %s backup\n", dev, fsg.fsg_mount, tmbuf,
fsg.fsg_mount_size, clbuf, bsbuf);
} else
printf("%s: %s\n", dev, fsg.fsg_mount);
close(fd);
if (argc > 0)
break;
}
}
void
usage(void)
{
fprintf(stderr, "%s",
"usage: fssconfig [-cx] device path backup [cluster [size]]\n"
" fssconfig -u device\n"
" fssconfig -l [-v] [device]\n");
exit(1);
}