1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/* $NetBSD: fssvar.h,v 1.2 2004/01/11 19:05:27 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 up to
FSS_CLUSTER_MAX/NBBY bytes */
#define FSS_LOCK(sc, s) \
do { \
(s) = splbio(); \
simple_lock(&(sc)->sc_slock); \
} while (/*CONSTCOND*/0)
#define FSS_UNLOCK(sc, s) \
do { \
simple_unlock(&(sc)->sc_slock); \
splx((s)); \
} while (/*CONSTCOND*/0)
/* Device to softc, NULL on error */
#define FSS_DEV_TO_SOFTC(dev) \
(minor((dev)) < 0 || minor((dev)) >= NFSS ? NULL : \
&fss_softc[minor((dev))])
/* Check if still valid */
#define FSS_ISVALID(sc) \
(((sc)->sc_flags & (FSS_ACTIVE|FSS_ERROR)) == FSS_ACTIVE)
/* Offset to cluster */
#define FSS_BTOCL(sc, off) \
((off) >> (sc)->sc_clshift)
/* Cluster to offset */
#define FSS_CLTOB(sc, cl) \
((off_t)(cl) << (sc)->sc_clshift)
/* Offset from start of cluster */
#define FSS_CLOFF(sc, off) \
((off) & (sc)->sc_clmask)
/* Size of cluster */
#define FSS_CLSIZE(sc) \
(1 << (sc)->sc_clshift)
/* Offset to backing store block */
#define FSS_BTOFSB(sc, off) \
((off) >> (sc)->sc_bs_bshift)
/* Backing store block to offset */
#define FSS_FSBTOB(sc, blk) \
((off_t)(blk) << (sc)->sc_bs_bshift)
/* Offset from start of backing store block */
#define FSS_FSBOFF(sc, off) \
((off) & (sc)->sc_bs_bmask)
/* Size of backing store block */
#define FSS_FSBSIZE(sc) \
(1 << (sc)->sc_bs_bshift)
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 simplelock sc_slock; /* Protect this softc */
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 */
#define FSS_EXCL 0x08 /* Exclusive access granted */
#define FSS_BS_ALLOC 0x10 /* Allocate backing store */
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 */
off_t sc_bs_size; /* Its size in bytes */
int sc_bs_bshift; /* Shift of backing store block */
u_int32_t sc_bs_bmask; /* Mask of backing store block */
struct proc *sc_bs_proc; /* Our kernel thread */
int sc_clshift; /* Shift of cluster size */
u_int32_t sc_clmask; /* Mask of cluster size */
u_int32_t sc_clcount; /* # clusters in file system */
u_int8_t *sc_copied; /* Map of clusters already copied */
long sc_clresid; /* 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);
/*
* 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 */
|