Home | History | Annotate | Line # | Download | only in dev
fssvar.h revision 1.14
      1 /*	$NetBSD: fssvar.h,v 1.14 2007/02/15 15:40:51 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Juergen Hannken-Illjes.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _SYS_DEV_FSSVAR_H
     40 #define _SYS_DEV_FSSVAR_H
     41 
     42 #define FSS_UNCONFIG_ON_CLOSE	0x01	/* Unconfigure on last close */
     43 
     44 struct fss_set {
     45 	char		*fss_mount;	/* Mount point of file system */
     46 	char		*fss_bstore;	/* Path of backing store */
     47 	blksize_t	fss_csize;	/* Preferred cluster size */
     48 };
     49 
     50 struct fss_get {
     51 	char		fsg_mount[MNAMELEN]; /* Mount point of file system */
     52 	struct timeval	fsg_time;	/* Time this snapshot was taken */
     53 	blksize_t	fsg_csize;	/* Current cluster size */
     54 	blkcnt_t	fsg_mount_size;	/* # clusters on file system */
     55 	blkcnt_t	fsg_bs_size;	/* # clusters on backing store */
     56 };
     57 
     58 #define FSSIOCSET	_IOW('F', 0, struct fss_set)	/* Configure */
     59 #define FSSIOCGET	_IOR('F', 1, struct fss_get)	/* Status */
     60 #define FSSIOCCLR	_IO('F', 2)			/* Unconfigure */
     61 #define FSSIOFSET	_IOW('F', 3, int)		/* Set flags */
     62 #define FSSIOFGET	_IOR('F', 4, int)		/* Get flags */
     63 
     64 #ifdef _KERNEL
     65 
     66 #include <sys/bufq.h>
     67 
     68 #define FSS_CLUSTER_MAX	(1<<24)		/* Upper bound of clusters. The
     69 					   sc_copied map uses up to
     70 					   FSS_CLUSTER_MAX/NBBY bytes */
     71 
     72 #define FSS_LOCK(sc, s) \
     73 	do { \
     74 		(s) = splbio(); \
     75 		simple_lock(&(sc)->sc_slock); \
     76 	} while (/*CONSTCOND*/0)
     77 
     78 #define FSS_UNLOCK(sc, s) \
     79 	do { \
     80 		simple_unlock(&(sc)->sc_slock); \
     81 		splx((s)); \
     82 	} while (/*CONSTCOND*/0)
     83 
     84 /* Device to softc, NULL on error */
     85 #define FSS_DEV_TO_SOFTC(dev) \
     86 	(minor((dev)) < 0 || minor((dev)) >= NFSS ? NULL : \
     87 	    &fss_softc[minor((dev))])
     88 
     89 /* Check if still valid */
     90 #define FSS_ISVALID(sc) \
     91 	(((sc)->sc_flags & (FSS_ACTIVE|FSS_ERROR)) == FSS_ACTIVE)
     92 
     93 /* Offset to cluster */
     94 #define FSS_BTOCL(sc, off) \
     95 	((off) >> (sc)->sc_clshift)
     96 
     97 /* Cluster to offset */
     98 #define FSS_CLTOB(sc, cl) \
     99 	((off_t)(cl) << (sc)->sc_clshift)
    100 
    101 /* Offset from start of cluster */
    102 #define FSS_CLOFF(sc, off) \
    103 	((off) & (sc)->sc_clmask)
    104 
    105 /* Size of cluster */
    106 #define FSS_CLSIZE(sc) \
    107 	(1 << (sc)->sc_clshift)
    108 
    109 /* Offset to backing store block */
    110 #define FSS_BTOFSB(sc, off) \
    111 	((off) >> (sc)->sc_bs_bshift)
    112 
    113 /* Backing store block to offset */
    114 #define FSS_FSBTOB(sc, blk) \
    115 	((off_t)(blk) << (sc)->sc_bs_bshift)
    116 
    117 /* Offset from start of backing store block */
    118 #define FSS_FSBOFF(sc, off) \
    119 	((off) & (sc)->sc_bs_bmask)
    120 
    121 /* Size of backing store block */
    122 #define FSS_FSBSIZE(sc) \
    123 	(1 << (sc)->sc_bs_bshift)
    124 
    125 typedef enum {
    126 	FSS_READ,
    127 	FSS_WRITE
    128 } fss_io_type;
    129 
    130 typedef enum {
    131 	FSS_CACHE_FREE	= 0,		/* Cache entry is free */
    132 	FSS_CACHE_BUSY	= 1,		/* Cache entry is read from device */
    133 	FSS_CACHE_VALID	= 2		/* Cache entry contains valid data */
    134 } fss_cache_type;
    135 
    136 struct fss_cache {
    137 	fss_cache_type	fc_type;	/* Current state */
    138 	struct fss_softc *fc_softc;	/* Backlink to our softc */
    139 	volatile int	fc_xfercount;	/* Number of outstanding transfers */
    140 	u_int32_t	fc_cluster;	/* Cluster number of this entry */
    141 	caddr_t		fc_data;	/* Data */
    142 };
    143 
    144 struct fss_softc {
    145 	int		sc_unit;	/* Logical unit number */
    146 	struct simplelock sc_slock;	/* Protect this softc */
    147 	kmutex_t	sc_lock;	/* Sleep lock for fss_ioctl */
    148 	volatile int	sc_flags;	/* Flags */
    149 #define FSS_ACTIVE	0x01		/* Snapshot is active */
    150 #define FSS_ERROR	0x02		/* I/O error occurred */
    151 #define FSS_BS_THREAD	0x04		/* Kernel thread is running */
    152 #define FSS_PERSISTENT	0x20		/* File system internal snapshot */
    153 #define FSS_CDEV_OPEN	0x40		/* character device open */
    154 #define FSS_BDEV_OPEN	0x80		/* block device open */
    155 	int		sc_uflags;	/* User visible flags */
    156 	struct mount	*sc_mount;	/* Mount point */
    157 	char		sc_mntname[MNAMELEN]; /* Mount point */
    158 	struct timeval	sc_time;	/* Time this snapshot was taken */
    159 	dev_t		sc_bdev;	/* Underlying block device */
    160 	struct vnode	*sc_mount_vp;	/* Underlying spec vnode */
    161 	struct vnode	*sc_bs_vp;	/* Our backing store */
    162 	off_t		sc_bs_size;	/* Its size in bytes */
    163 	int		sc_bs_bshift;	/* Shift of backing store block */
    164 	u_int32_t	sc_bs_bmask;	/* Mask of backing store block */
    165 	struct proc	*sc_bs_proc;	/* Our kernel thread */
    166 	int		sc_clshift;	/* Shift of cluster size */
    167 	u_int32_t	sc_clmask;	/* Mask of cluster size */
    168 	u_int32_t	sc_clcount;	/* # clusters in file system */
    169 	u_int8_t	*sc_copied;	/* Map of clusters already copied */
    170 	long		sc_clresid;	/* Bytes in last cluster */
    171 	int		sc_cache_size;	/* Number of entries in sc_cache */
    172 	struct fss_cache *sc_cache;	/* Cluster cache */
    173 	struct bufq_state *sc_bufq;	/* Transfer queue */
    174 	u_int32_t	sc_clnext;	/* Next free cluster on backing store */
    175 	int		sc_indir_size;	/* # clusters for indirect mapping */
    176 	u_int8_t	*sc_indir_valid; /* Map of valid indirect clusters */
    177 	u_int32_t	sc_indir_cur;	/* Current indir cluster number */
    178 	int		sc_indir_dirty;	/* Current indir cluster modified */
    179 	u_int32_t	*sc_indir_data;	/* Current indir cluster data */
    180 };
    181 
    182 int fss_umount_hook(struct mount *, int);
    183 
    184 #endif /* _KERNEL */
    185 
    186 #endif /* !_SYS_DEV_FSSVAR_H */
    187