xref: /netbsd/sys/dev/fssvar.h (revision d3d92310)
1 /*	$NetBSD: fssvar.h,v 1.32 2019/02/20 10:03:25 hannken 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/ioccom.h>
36 
37 #define FSS_UNCONFIG_ON_CLOSE	0x01	/* Unconfigure on last close */
38 #define FSS_UNLINK_ON_CREATE	0x02	/* Unlink backing store on create */
39 
40 struct fss_set {
41 	char		*fss_mount;	/* Mount point of file system */
42 	char		*fss_bstore;	/* Path of backing store */
43 	blksize_t	fss_csize;	/* Preferred cluster size */
44 	int		fss_flags;	/* Initial flags */
45 };
46 
47 struct fss_get {
48 	char		fsg_mount[MNAMELEN]; /* Mount point of file system */
49 	struct timeval	fsg_time;	/* Time this snapshot was taken */
50 	blksize_t	fsg_csize;	/* Current cluster size */
51 	blkcnt_t	fsg_mount_size;	/* # clusters on file system */
52 	blkcnt_t	fsg_bs_size;	/* # clusters on backing store */
53 };
54 
55 #define FSSIOCSET	_IOW('F', 5, struct fss_set)	/* Configure */
56 #define FSSIOCGET	_IOR('F', 1, struct fss_get)	/* Status */
57 #define FSSIOCCLR	_IO('F', 2)			/* Unconfigure */
58 #define FSSIOFSET	_IOW('F', 3, int)		/* Set flags */
59 #define FSSIOFGET	_IOR('F', 4, int)		/* Get flags */
60 #ifdef _KERNEL
61 #include <compat/sys/time_types.h>
62 
63 struct fss_set50 {
64 	char		*fss_mount;	/* Mount point of file system */
65 	char		*fss_bstore;	/* Path of backing store */
66 	blksize_t	fss_csize;	/* Preferred cluster size */
67 };
68 
69 struct fss_get50 {
70 	char		fsg_mount[MNAMELEN]; /* Mount point of file system */
71 	struct timeval50 fsg_time;	/* Time this snapshot was taken */
72 	blksize_t	fsg_csize;	/* Current cluster size */
73 	blkcnt_t	fsg_mount_size;	/* # clusters on file system */
74 	blkcnt_t	fsg_bs_size;	/* # clusters on backing store */
75 };
76 
77 #define FSSIOCSET50	_IOW('F', 0, struct fss_set50)	/* Old configure */
78 #define FSSIOCGET50	_IOR('F', 1, struct fss_get50)	/* Old Status */
79 
80 #include <sys/bufq.h>
81 
82 #define FSS_CLUSTER_MAX	(1<<24)		/* Upper bound of clusters. The
83 					   sc_copied map uses up to
84 					   FSS_CLUSTER_MAX/NBBY bytes */
85 
86 /* Offset to cluster */
87 #define FSS_BTOCL(sc, off) \
88 	((off) >> (sc)->sc_clshift)
89 
90 /* Cluster to offset */
91 #define FSS_CLTOB(sc, cl) \
92 	((off_t)(cl) << (sc)->sc_clshift)
93 
94 /* Offset from start of cluster */
95 #define FSS_CLOFF(sc, off) \
96 	((off) & (sc)->sc_clmask)
97 
98 /* Size of cluster */
99 #define FSS_CLSIZE(sc) \
100 	(1 << (sc)->sc_clshift)
101 
102 /* Offset to backing store block */
103 #define FSS_BTOFSB(sc, off) \
104 	((off) >> (sc)->sc_bs_bshift)
105 
106 /* Backing store block to offset */
107 #define FSS_FSBTOB(sc, blk) \
108 	((off_t)(blk) << (sc)->sc_bs_bshift)
109 
110 /* Offset from start of backing store block */
111 #define FSS_FSBOFF(sc, off) \
112 	((off) & (sc)->sc_bs_bmask)
113 
114 /* Size of backing store block */
115 #define FSS_FSBSIZE(sc) \
116 	(1 << (sc)->sc_bs_bshift)
117 
118 typedef enum {
119 	FSS_READ,
120 	FSS_WRITE
121 } fss_io_type;
122 
123 typedef enum {
124 	FSS_CACHE_FREE	= 0,		/* Cache entry is free */
125 	FSS_CACHE_BUSY	= 1,		/* Cache entry is read from device */
126 	FSS_CACHE_VALID	= 2		/* Cache entry contains valid data */
127 } fss_cache_type;
128 
129 struct fss_cache {
130 	fss_cache_type	fc_type;	/* Current state */
131 	u_int32_t	fc_cluster;	/* Cluster number of this entry */
132 	kcondvar_t	fc_state_cv;	/* Signals state change from busy */
133 	void *		fc_data;	/* Data */
134 };
135 
136 typedef enum {
137 	FSS_IDLE,			/* Device is unconfigured */
138 	FSS_CREATING,			/* Device is currently configuring */
139 	FSS_ACTIVE,			/* Device is configured */
140 	FSS_DESTROYING			/* Device is currently unconfiguring */
141 } fss_state_t;
142 
143 struct fss_softc {
144 	device_t	sc_dev;		/* Self */
145 	kmutex_t	sc_slock;	/* Protect this softc */
146 	kcondvar_t	sc_work_cv;	/* Signals work for the kernel thread */
147 	kcondvar_t	sc_cache_cv;	/* Signals free cache slot */
148 	fss_state_t	sc_state;	/* Current state */
149 	volatile int	sc_flags;	/* Flags */
150 #define FSS_ERROR	0x01		/* Device had errors. */
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 disk	*sc_dkdev;	/* Generic disk device info */
157 	struct mount	*sc_mount;	/* Mount point */
158 	char		sc_mntname[MNAMELEN]; /* Mount point */
159 	struct timeval	sc_time;	/* Time this snapshot was taken */
160 	dev_t		sc_bdev;	/* Underlying block device */
161 	struct vnode	*sc_bs_vp;	/* Our backing store */
162 	int		sc_bs_bshift;	/* Shift of backing store block */
163 	u_int32_t	sc_bs_bmask;	/* Mask of backing store block */
164 	struct lwp	*sc_bs_lwp;	/* Our kernel thread */
165 	int		sc_clshift;	/* Shift of cluster size */
166 	u_int32_t	sc_clmask;	/* Mask of cluster size */
167 	u_int32_t	sc_clcount;	/* # clusters in file system */
168 	u_int8_t	*sc_copied;	/* Map of clusters already copied */
169 	long		sc_clresid;	/* Bytes in last cluster */
170 	int		sc_cache_size;	/* Number of entries in sc_cache */
171 	struct fss_cache *sc_cache;	/* Cluster cache */
172 	struct bufq_state *sc_bufq;	/* Transfer queue */
173 	u_int32_t	sc_clnext;	/* Next free cluster on backing store */
174 	int		sc_indir_size;	/* # clusters for indirect mapping */
175 	u_int8_t	*sc_indir_valid; /* Map of valid indirect clusters */
176 	u_int32_t	sc_indir_cur;	/* Current indir cluster number */
177 	int		sc_indir_dirty;	/* Current indir cluster modified */
178 	u_int32_t	*sc_indir_data;	/* Current indir cluster data */
179 };
180 
181 #endif /* _KERNEL */
182 
183 #endif /* !_SYS_DEV_FSSVAR_H */
184