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