fssvar.h revision 1.1 1 /* $NetBSD: fssvar.h,v 1.1 2003/12/10 11:40:11 hannken Exp $ */
2
3 /*-
4 * Copyright (c) 2003 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 struct fss_set {
43 char *fss_mount; /* Mount point of file system */
44 char *fss_bstore; /* Path of backing store */
45 blksize_t fss_csize; /* Preferred cluster size */
46 };
47
48 struct fss_get {
49 char fsg_mount[MNAMELEN]; /* Mount point of file system */
50 struct timeval fsg_time; /* Time this snapshot was taken */
51 blksize_t fsg_csize; /* Current cluster size */
52 blkcnt_t fsg_mount_size; /* # clusters on file system */
53 blkcnt_t fsg_bs_size; /* # clusters on backing store */
54 };
55
56 #define FSSIOCSET _IOW('F', 0, struct fss_set) /* Configure */
57 #define FSSIOCGET _IOR('F', 1, struct fss_get) /* Status */
58 #define FSSIOCCLR _IO('F', 2) /* Unconfigure */
59
60 #ifdef _KERNEL
61
62 #define FSS_CLUSTER_MAX (1<<24) /* Upper bound of clusters. The
63 sc_copied map uses
64 FSS_CLUSTER_MAX/NBBY bytes */
65 typedef enum {
66 FSS_CACHE_FREE = 0, /* Cache entry is free */
67 FSS_CACHE_BUSY = 1, /* Cache entry is read from device */
68 FSS_CACHE_VALID = 2 /* Cache entry contains valid data */
69 } fss_cache_type;
70
71 struct fss_cache {
72 fss_cache_type fc_type; /* Current state */
73 struct fss_softc *fc_softc; /* Backlink to our softc */
74 volatile int fc_xfercount; /* Number of outstanding transfers */
75 u_int32_t fc_cluster; /* Cluster number of this entry */
76 caddr_t fc_data; /* Data */
77 };
78
79 struct fss_softc {
80 int sc_unit; /* Logical unit number */
81 struct lock sc_lock; /* Get exclusive access to device */
82 volatile int sc_flags; /* Flags */
83 #define FSS_ACTIVE 0x01 /* Snapshot is active */
84 #define FSS_ERROR 0x02 /* I/o error occured */
85 #define FSS_BS_THREAD 0x04 /* Kernel thread is running */
86 struct mount *sc_mount; /* Mount point */
87 char sc_mntname[MNAMELEN]; /* Mount point */
88 struct timeval sc_time; /* Time this snapshot was taken */
89 dev_t sc_bdev; /* Underlying block device */
90 void (*sc_strategy)(struct buf *); /* And its strategy */
91 struct vnode *sc_bs_vp; /* Our backing store */
92 int sc_bs_bsize; /* Its bsize */
93 struct proc *sc_bs_proc; /* Our kernel thread */
94 u_int32_t sc_clsize; /* Size of cluster */
95 u_int32_t sc_clcount; /* # clusters in file system */
96 u_int8_t *sc_copied; /* Map of clusters already copied */
97 long sc_cllast; /* Bytes in last cluster */
98 int sc_cowcount; /* Number of cow in progress */
99 int sc_cache_size; /* Number of entries in sc_cache */
100 struct fss_cache *sc_cache; /* Cluster cache */
101 struct bufq_state sc_bufq; /* Transfer queue */
102 u_int32_t sc_clnext; /* Next free cluster on backing store */
103 int sc_indir_size; /* # clusters for indirect mapping */
104 u_int8_t *sc_indir_valid; /* Map of valid indirect clusters */
105 u_int32_t sc_indir_cur; /* Current indir cluster number */
106 int sc_indir_dirty; /* Current indir cluster modified */
107 u_int32_t *sc_indir_data; /* Current indir cluster data */
108 };
109
110 struct fss_softc fss_softc[NFSS];
111
112 void fss_copy_on_write(struct fss_softc *, struct buf *);
113 int fss_umount_hook(struct mount *, int);
114
115 /*
116 * Get this dev's softc if it is a valid device.
117 * Return a pointer to its softc.
118 */
119 static inline int
120 fss_dev_to_softc(dev_t dev, struct fss_softc **scp)
121 {
122 int unit;
123 struct fss_softc *sc;
124
125 unit = minor(dev);
126 if (unit < 0 || unit >= NFSS)
127 return ENODEV;
128 sc = &fss_softc[unit];
129 *scp = sc;
130
131 return 0;
132 }
133
134 /*
135 * Check if this buf needs to be copied on write.
136 * Unroll the loop for small NFSS.
137 */
138 static inline void
139 fss_cow_hook(struct buf *bp)
140 {
141 int i;
142
143 if (bp->b_flags & B_READ)
144 return;
145
146 if (NFSS <= 4) {
147 if (__predict_false(fss_softc[0].sc_bdev == bp->b_dev ||
148 (NFSS > 1 && fss_softc[1].sc_bdev == bp->b_dev) ||
149 (NFSS > 2 && fss_softc[2].sc_bdev == bp->b_dev) ||
150 (NFSS > 3 && fss_softc[3].sc_bdev == bp->b_dev)))
151 for (i = 0; i < NFSS; i++)
152 if (fss_softc[i].sc_bdev == bp->b_dev)
153 fss_copy_on_write(&fss_softc[i], bp);
154 } else {
155 for (i = 0; i < NFSS; i++)
156 if (__predict_false(fss_softc[i].sc_bdev == bp->b_dev))
157 fss_copy_on_write(&fss_softc[i], bp);
158 }
159 }
160
161 #endif /* _KERNEL */
162
163 #endif /* !_SYS_DEV_FSSVAR_H */
164