| @@ -1,1889 +1,1889 @@ | | | @@ -1,1889 +1,1889 @@ |
1 | /* $NetBSD: ccd.c,v 1.185 2020/10/06 18:45:23 mlelstv Exp $ */ | | 1 | /* $NetBSD: ccd.c,v 1.186 2022/02/11 23:20:09 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jason R. Thorpe, and by Andrew Doran. | | 8 | * by Jason R. Thorpe, and by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 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 | | 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 | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 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 | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 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 | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Copyright (c) 1988 University of Utah. | | 33 | * Copyright (c) 1988 University of Utah. |
34 | * Copyright (c) 1990, 1993 | | 34 | * Copyright (c) 1990, 1993 |
35 | * The Regents of the University of California. All rights reserved. | | 35 | * The Regents of the University of California. All rights reserved. |
36 | * | | 36 | * |
37 | * This code is derived from software contributed to Berkeley by | | 37 | * This code is derived from software contributed to Berkeley by |
38 | * the Systems Programming Group of the University of Utah Computer | | 38 | * the Systems Programming Group of the University of Utah Computer |
39 | * Science Department. | | 39 | * Science Department. |
40 | * | | 40 | * |
41 | * Redistribution and use in source and binary forms, with or without | | 41 | * Redistribution and use in source and binary forms, with or without |
42 | * modification, are permitted provided that the following conditions | | 42 | * modification, are permitted provided that the following conditions |
43 | * are met: | | 43 | * are met: |
44 | * 1. Redistributions of source code must retain the above copyright | | 44 | * 1. Redistributions of source code must retain the above copyright |
45 | * notice, this list of conditions and the following disclaimer. | | 45 | * notice, this list of conditions and the following disclaimer. |
46 | * 2. Redistributions in binary form must reproduce the above copyright | | 46 | * 2. Redistributions in binary form must reproduce the above copyright |
47 | * notice, this list of conditions and the following disclaimer in the | | 47 | * notice, this list of conditions and the following disclaimer in the |
48 | * documentation and/or other materials provided with the distribution. | | 48 | * documentation and/or other materials provided with the distribution. |
49 | * 3. Neither the name of the University nor the names of its contributors | | 49 | * 3. Neither the name of the University nor the names of its contributors |
50 | * may be used to endorse or promote products derived from this software | | 50 | * may be used to endorse or promote products derived from this software |
51 | * without specific prior written permission. | | 51 | * without specific prior written permission. |
52 | * | | 52 | * |
53 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 53 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
63 | * SUCH DAMAGE. | | 63 | * SUCH DAMAGE. |
64 | * | | 64 | * |
65 | * from: Utah $Hdr: cd.c 1.6 90/11/28$ | | 65 | * from: Utah $Hdr: cd.c 1.6 90/11/28$ |
66 | * | | 66 | * |
67 | * @(#)cd.c 8.2 (Berkeley) 11/16/93 | | 67 | * @(#)cd.c 8.2 (Berkeley) 11/16/93 |
68 | */ | | 68 | */ |
69 | | | 69 | |
70 | /* | | 70 | /* |
71 | * "Concatenated" disk driver. | | 71 | * "Concatenated" disk driver. |
72 | * | | 72 | * |
73 | * Notes on concurrency: | | 73 | * Notes on concurrency: |
74 | * | | 74 | * |
75 | * => sc_dvlock serializes access to the device nodes, excluding block I/O. | | 75 | * => sc_dvlock serializes access to the device nodes, excluding block I/O. |
76 | * | | 76 | * |
77 | * => sc_iolock serializes access to (sc_flags & CCDF_INITED), disk stats, | | 77 | * => sc_iolock serializes access to (sc_flags & CCDF_INITED), disk stats, |
78 | * sc_stop, sc_bufq and b_resid from master buffers. | | 78 | * sc_stop, sc_bufq and b_resid from master buffers. |
79 | * | | 79 | * |
80 | * => a combination of CCDF_INITED, sc_inflight, and sc_iolock is used to | | 80 | * => a combination of CCDF_INITED, sc_inflight, and sc_iolock is used to |
81 | * serialize I/O and configuration changes. | | 81 | * serialize I/O and configuration changes. |
82 | * | | 82 | * |
83 | * => the in-core disk label does not change while the device is open. | | 83 | * => the in-core disk label does not change while the device is open. |
84 | * | | 84 | * |
85 | * On memory consumption: ccd fans out I/O requests and so needs to | | 85 | * On memory consumption: ccd fans out I/O requests and so needs to |
86 | * allocate memory. If the system is desperately low on memory, we | | 86 | * allocate memory. If the system is desperately low on memory, we |
87 | * single thread I/O. | | 87 | * single thread I/O. |
88 | */ | | 88 | */ |
89 | | | 89 | |
90 | #include <sys/cdefs.h> | | 90 | #include <sys/cdefs.h> |
91 | __KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.185 2020/10/06 18:45:23 mlelstv Exp $"); | | 91 | __KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.186 2022/02/11 23:20:09 riastradh Exp $"); |
92 | | | 92 | |
93 | #include <sys/param.h> | | 93 | #include <sys/param.h> |
94 | #include <sys/systm.h> | | 94 | #include <sys/systm.h> |
95 | #include <sys/kernel.h> | | 95 | #include <sys/kernel.h> |
96 | #include <sys/proc.h> | | 96 | #include <sys/proc.h> |
97 | #include <sys/errno.h> | | 97 | #include <sys/errno.h> |
98 | #include <sys/buf.h> | | 98 | #include <sys/buf.h> |
99 | #include <sys/kmem.h> | | 99 | #include <sys/kmem.h> |
100 | #include <sys/pool.h> | | 100 | #include <sys/pool.h> |
101 | #include <sys/module.h> | | 101 | #include <sys/module.h> |
102 | #include <sys/namei.h> | | 102 | #include <sys/namei.h> |
103 | #include <sys/stat.h> | | 103 | #include <sys/stat.h> |
104 | #include <sys/ioctl.h> | | 104 | #include <sys/ioctl.h> |
105 | #include <sys/disklabel.h> | | 105 | #include <sys/disklabel.h> |
106 | #include <sys/device.h> | | 106 | #include <sys/device.h> |
107 | #include <sys/disk.h> | | 107 | #include <sys/disk.h> |
108 | #include <sys/syslog.h> | | 108 | #include <sys/syslog.h> |
109 | #include <sys/fcntl.h> | | 109 | #include <sys/fcntl.h> |
110 | #include <sys/vnode.h> | | 110 | #include <sys/vnode.h> |
111 | #include <sys/conf.h> | | 111 | #include <sys/conf.h> |
112 | #include <sys/mutex.h> | | 112 | #include <sys/mutex.h> |
113 | #include <sys/queue.h> | | 113 | #include <sys/queue.h> |
114 | #include <sys/kauth.h> | | 114 | #include <sys/kauth.h> |
115 | #include <sys/kthread.h> | | 115 | #include <sys/kthread.h> |
116 | #include <sys/bufq.h> | | 116 | #include <sys/bufq.h> |
117 | #include <sys/sysctl.h> | | 117 | #include <sys/sysctl.h> |
118 | #include <sys/compat_stub.h> | | 118 | #include <sys/compat_stub.h> |
119 | | | 119 | |
120 | #include <uvm/uvm_extern.h> | | 120 | #include <uvm/uvm_extern.h> |
121 | | | 121 | |
122 | #include <dev/ccdvar.h> | | 122 | #include <dev/ccdvar.h> |
123 | #include <dev/dkvar.h> | | 123 | #include <dev/dkvar.h> |
124 | | | 124 | |
125 | #include <miscfs/specfs/specdev.h> /* for v_rdev */ | | 125 | #include <miscfs/specfs/specdev.h> /* for v_rdev */ |
126 | | | 126 | |
127 | #include "ioconf.h" | | 127 | #include "ioconf.h" |
128 | | | 128 | |
129 | #if defined(CCDDEBUG) && !defined(DEBUG) | | 129 | #if defined(CCDDEBUG) && !defined(DEBUG) |
130 | #define DEBUG | | 130 | #define DEBUG |
131 | #endif | | 131 | #endif |
132 | | | 132 | |
133 | #ifdef DEBUG | | 133 | #ifdef DEBUG |
134 | #define CCDB_FOLLOW 0x01 | | 134 | #define CCDB_FOLLOW 0x01 |
135 | #define CCDB_INIT 0x02 | | 135 | #define CCDB_INIT 0x02 |
136 | #define CCDB_IO 0x04 | | 136 | #define CCDB_IO 0x04 |
137 | #define CCDB_LABEL 0x08 | | 137 | #define CCDB_LABEL 0x08 |
138 | #define CCDB_VNODE 0x10 | | 138 | #define CCDB_VNODE 0x10 |
139 | int ccddebug = 0x00; | | 139 | int ccddebug = 0x00; |
140 | #endif | | 140 | #endif |
141 | | | 141 | |
142 | #define ccdunit(x) DISKUNIT(x) | | 142 | #define ccdunit(x) DISKUNIT(x) |
143 | | | 143 | |
144 | struct ccdbuf { | | 144 | struct ccdbuf { |
145 | struct buf cb_buf; /* new I/O buf */ | | 145 | struct buf cb_buf; /* new I/O buf */ |
146 | struct buf *cb_obp; /* ptr. to original I/O buf */ | | 146 | struct buf *cb_obp; /* ptr. to original I/O buf */ |
147 | struct ccd_softc *cb_sc; /* pointer to ccd softc */ | | 147 | struct ccd_softc *cb_sc; /* pointer to ccd softc */ |
148 | int cb_comp; /* target component */ | | 148 | int cb_comp; /* target component */ |
149 | SIMPLEQ_ENTRY(ccdbuf) cb_q; /* fifo of component buffers */ | | 149 | SIMPLEQ_ENTRY(ccdbuf) cb_q; /* fifo of component buffers */ |
150 | }; | | 150 | }; |
151 | | | 151 | |
152 | /* component buffer pool */ | | 152 | /* component buffer pool */ |
153 | static pool_cache_t ccd_cache; | | 153 | static pool_cache_t ccd_cache; |
154 | | | 154 | |
155 | #define CCD_GETBUF() pool_cache_get(ccd_cache, PR_WAITOK) | | 155 | #define CCD_GETBUF() pool_cache_get(ccd_cache, PR_WAITOK) |
156 | #define CCD_PUTBUF(cbp) pool_cache_put(ccd_cache, cbp) | | 156 | #define CCD_PUTBUF(cbp) pool_cache_put(ccd_cache, cbp) |
157 | | | 157 | |
158 | #define CCDLABELDEV(dev) \ | | 158 | #define CCDLABELDEV(dev) \ |
159 | (MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART)) | | 159 | (MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART)) |
160 | | | 160 | |
161 | /* called by main() at boot time */ | | 161 | /* called by main() at boot time */ |
162 | void ccddetach(void); | | 162 | void ccddetach(void); |
163 | | | 163 | |
164 | /* called by biodone() at interrupt time */ | | 164 | /* called by biodone() at interrupt time */ |
165 | static void ccdiodone(struct buf *); | | 165 | static void ccdiodone(struct buf *); |
166 | | | 166 | |
167 | static void ccdinterleave(struct ccd_softc *); | | 167 | static void ccdinterleave(struct ccd_softc *); |
168 | static int ccdinit(struct ccd_softc *, char **, struct vnode **, | | 168 | static int ccdinit(struct ccd_softc *, char **, struct vnode **, |
169 | struct lwp *); | | 169 | struct lwp *); |
170 | static struct ccdbuf *ccdbuffer(struct ccd_softc *, struct buf *, | | 170 | static struct ccdbuf *ccdbuffer(struct ccd_softc *, struct buf *, |
171 | daddr_t, void *, long); | | 171 | daddr_t, void *, long); |
172 | static void ccdgetdefaultlabel(struct ccd_softc *, struct disklabel *); | | 172 | static void ccdgetdefaultlabel(struct ccd_softc *, struct disklabel *); |
173 | static void ccdgetdisklabel(dev_t); | | 173 | static void ccdgetdisklabel(dev_t); |
174 | static void ccdmakedisklabel(struct ccd_softc *); | | 174 | static void ccdmakedisklabel(struct ccd_softc *); |
175 | static void ccdstart(struct ccd_softc *); | | 175 | static void ccdstart(struct ccd_softc *); |
176 | static void ccdthread(void *); | | 176 | static void ccdthread(void *); |
177 | | | 177 | |
178 | static dev_type_open(ccdopen); | | 178 | static dev_type_open(ccdopen); |
179 | static dev_type_close(ccdclose); | | 179 | static dev_type_close(ccdclose); |
180 | static dev_type_read(ccdread); | | 180 | static dev_type_read(ccdread); |
181 | static dev_type_write(ccdwrite); | | 181 | static dev_type_write(ccdwrite); |
182 | static dev_type_ioctl(ccdioctl); | | 182 | static dev_type_ioctl(ccdioctl); |
183 | static dev_type_strategy(ccdstrategy); | | 183 | static dev_type_strategy(ccdstrategy); |
184 | static dev_type_size(ccdsize); | | 184 | static dev_type_size(ccdsize); |
185 | | | 185 | |
186 | const struct bdevsw ccd_bdevsw = { | | 186 | const struct bdevsw ccd_bdevsw = { |
187 | .d_open = ccdopen, | | 187 | .d_open = ccdopen, |
188 | .d_close = ccdclose, | | 188 | .d_close = ccdclose, |
189 | .d_strategy = ccdstrategy, | | 189 | .d_strategy = ccdstrategy, |
190 | .d_ioctl = ccdioctl, | | 190 | .d_ioctl = ccdioctl, |
191 | .d_dump = nodump, | | 191 | .d_dump = nodump, |
192 | .d_psize = ccdsize, | | 192 | .d_psize = ccdsize, |
193 | .d_discard = nodiscard, | | 193 | .d_discard = nodiscard, |
194 | .d_flag = D_DISK | D_MPSAFE | | 194 | .d_flag = D_DISK | D_MPSAFE |
195 | }; | | 195 | }; |
196 | | | 196 | |
197 | const struct cdevsw ccd_cdevsw = { | | 197 | const struct cdevsw ccd_cdevsw = { |
198 | .d_open = ccdopen, | | 198 | .d_open = ccdopen, |
199 | .d_close = ccdclose, | | 199 | .d_close = ccdclose, |
200 | .d_read = ccdread, | | 200 | .d_read = ccdread, |
201 | .d_write = ccdwrite, | | 201 | .d_write = ccdwrite, |
202 | .d_ioctl = ccdioctl, | | 202 | .d_ioctl = ccdioctl, |
203 | .d_stop = nostop, | | 203 | .d_stop = nostop, |
204 | .d_tty = notty, | | 204 | .d_tty = notty, |
205 | .d_poll = nopoll, | | 205 | .d_poll = nopoll, |
206 | .d_mmap = nommap, | | 206 | .d_mmap = nommap, |
207 | .d_kqfilter = nokqfilter, | | 207 | .d_kqfilter = nokqfilter, |
208 | .d_discard = nodiscard, | | 208 | .d_discard = nodiscard, |
209 | .d_flag = D_DISK | D_MPSAFE | | 209 | .d_flag = D_DISK | D_MPSAFE |
210 | }; | | 210 | }; |
211 | | | 211 | |
212 | static const struct dkdriver ccddkdriver = { | | 212 | static const struct dkdriver ccddkdriver = { |
213 | .d_strategy = ccdstrategy, | | 213 | .d_strategy = ccdstrategy, |
214 | .d_minphys = minphys | | 214 | .d_minphys = minphys |
215 | }; | | 215 | }; |
216 | | | 216 | |
217 | #ifdef DEBUG | | 217 | #ifdef DEBUG |
218 | static void printiinfo(struct ccdiinfo *); | | 218 | static void printiinfo(struct ccdiinfo *); |
219 | #endif | | 219 | #endif |
220 | | | 220 | |
221 | static LIST_HEAD(, ccd_softc) ccds = LIST_HEAD_INITIALIZER(ccds); | | 221 | static LIST_HEAD(, ccd_softc) ccds = LIST_HEAD_INITIALIZER(ccds); |
222 | static kmutex_t ccd_lock; | | 222 | static kmutex_t ccd_lock; |
223 | | | 223 | |
224 | SYSCTL_SETUP_PROTO(sysctl_kern_ccd_setup); | | 224 | SYSCTL_SETUP_PROTO(sysctl_kern_ccd_setup); |
225 | | | 225 | |
226 | static struct ccd_softc * | | 226 | static struct ccd_softc * |
227 | ccdcreate(int unit) { | | 227 | ccdcreate(int unit) { |
228 | struct ccd_softc *sc = kmem_zalloc(sizeof(*sc), KM_SLEEP); | | 228 | struct ccd_softc *sc = kmem_zalloc(sizeof(*sc), KM_SLEEP); |
229 | | | 229 | |
230 | /* Initialize per-softc structures. */ | | 230 | /* Initialize per-softc structures. */ |
231 | snprintf(sc->sc_xname, sizeof(sc->sc_xname), "ccd%d", unit); | | 231 | snprintf(sc->sc_xname, sizeof(sc->sc_xname), "ccd%d", unit); |
232 | sc->sc_unit = unit; | | 232 | sc->sc_unit = unit; |
233 | mutex_init(&sc->sc_dvlock, MUTEX_DEFAULT, IPL_NONE); | | 233 | mutex_init(&sc->sc_dvlock, MUTEX_DEFAULT, IPL_NONE); |
234 | sc->sc_iolock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); | | 234 | sc->sc_iolock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); |
235 | cv_init(&sc->sc_stop, "ccdstop"); | | 235 | cv_init(&sc->sc_stop, "ccdstop"); |
236 | cv_init(&sc->sc_push, "ccdthr"); | | 236 | cv_init(&sc->sc_push, "ccdthr"); |
237 | disk_init(&sc->sc_dkdev, sc->sc_xname, &ccddkdriver); | | 237 | disk_init(&sc->sc_dkdev, sc->sc_xname, &ccddkdriver); |
238 | return sc; | | 238 | return sc; |
239 | } | | 239 | } |
240 | | | 240 | |
241 | static void | | 241 | static void |
242 | ccddestroy(struct ccd_softc *sc) { | | 242 | ccddestroy(struct ccd_softc *sc) { |
243 | mutex_obj_free(sc->sc_iolock); | | 243 | mutex_obj_free(sc->sc_iolock); |
244 | mutex_exit(&sc->sc_dvlock); | | 244 | mutex_exit(&sc->sc_dvlock); |
245 | mutex_destroy(&sc->sc_dvlock); | | 245 | mutex_destroy(&sc->sc_dvlock); |
246 | cv_destroy(&sc->sc_stop); | | 246 | cv_destroy(&sc->sc_stop); |
247 | cv_destroy(&sc->sc_push); | | 247 | cv_destroy(&sc->sc_push); |
248 | disk_destroy(&sc->sc_dkdev); | | 248 | disk_destroy(&sc->sc_dkdev); |
249 | kmem_free(sc, sizeof(*sc)); | | 249 | kmem_free(sc, sizeof(*sc)); |
250 | } | | 250 | } |
251 | | | 251 | |
252 | static struct ccd_softc * | | 252 | static struct ccd_softc * |
253 | ccdget(int unit, int make) { | | 253 | ccdget(int unit, int make) { |
254 | struct ccd_softc *sc; | | 254 | struct ccd_softc *sc; |
255 | if (unit < 0) { | | 255 | if (unit < 0) { |
256 | #ifdef DIAGNOSTIC | | 256 | #ifdef DIAGNOSTIC |
257 | panic("%s: unit %d!", __func__, unit); | | 257 | panic("%s: unit %d!", __func__, unit); |
258 | #endif | | 258 | #endif |
259 | return NULL; | | 259 | return NULL; |
260 | } | | 260 | } |
261 | mutex_enter(&ccd_lock); | | 261 | mutex_enter(&ccd_lock); |
262 | LIST_FOREACH(sc, &ccds, sc_link) { | | 262 | LIST_FOREACH(sc, &ccds, sc_link) { |
263 | if (sc->sc_unit == unit) { | | 263 | if (sc->sc_unit == unit) { |
264 | mutex_exit(&ccd_lock); | | 264 | mutex_exit(&ccd_lock); |
265 | return sc; | | 265 | return sc; |
266 | } | | 266 | } |
267 | } | | 267 | } |
268 | mutex_exit(&ccd_lock); | | 268 | mutex_exit(&ccd_lock); |
269 | if (!make) | | 269 | if (!make) |
270 | return NULL; | | 270 | return NULL; |
271 | if ((sc = ccdcreate(unit)) == NULL) | | 271 | if ((sc = ccdcreate(unit)) == NULL) |
272 | return NULL; | | 272 | return NULL; |
273 | mutex_enter(&ccd_lock); | | 273 | mutex_enter(&ccd_lock); |
274 | LIST_INSERT_HEAD(&ccds, sc, sc_link); | | 274 | LIST_INSERT_HEAD(&ccds, sc, sc_link); |
275 | mutex_exit(&ccd_lock); | | 275 | mutex_exit(&ccd_lock); |
276 | return sc; | | 276 | return sc; |
277 | } | | 277 | } |
278 | | | 278 | |
279 | static void | | 279 | static void |
280 | ccdput(struct ccd_softc *sc) { | | 280 | ccdput(struct ccd_softc *sc) { |
281 | mutex_enter(&ccd_lock); | | 281 | mutex_enter(&ccd_lock); |
282 | LIST_REMOVE(sc, sc_link); | | 282 | LIST_REMOVE(sc, sc_link); |
283 | mutex_exit(&ccd_lock); | | 283 | mutex_exit(&ccd_lock); |
284 | ccddestroy(sc); | | 284 | ccddestroy(sc); |
285 | } | | 285 | } |
286 | | | 286 | |
287 | /* | | 287 | /* |
288 | * Called by main() during pseudo-device attachment. All we need | | 288 | * Called by main() during pseudo-device attachment. All we need |
289 | * to do is allocate enough space for devices to be configured later. | | 289 | * to do is allocate enough space for devices to be configured later. |
290 | */ | | 290 | */ |
291 | void | | 291 | void |
292 | ccdattach(int num) | | 292 | ccdattach(int num) |
293 | { | | 293 | { |
294 | mutex_init(&ccd_lock, MUTEX_DEFAULT, IPL_NONE); | | 294 | mutex_init(&ccd_lock, MUTEX_DEFAULT, IPL_NONE); |
295 | | | 295 | |
296 | /* Initialize the component buffer pool. */ | | 296 | /* Initialize the component buffer pool. */ |
297 | ccd_cache = pool_cache_init(sizeof(struct ccdbuf), 0, | | 297 | ccd_cache = pool_cache_init(sizeof(struct ccdbuf), 0, |
298 | 0, 0, "ccdbuf", NULL, IPL_BIO, NULL, NULL, NULL); | | 298 | 0, 0, "ccdbuf", NULL, IPL_BIO, NULL, NULL, NULL); |
299 | } | | 299 | } |
300 | | | 300 | |
301 | void | | 301 | void |
302 | ccddetach(void) | | 302 | ccddetach(void) |
303 | { | | 303 | { |
304 | pool_cache_destroy(ccd_cache); | | 304 | pool_cache_destroy(ccd_cache); |
305 | mutex_destroy(&ccd_lock); | | 305 | mutex_destroy(&ccd_lock); |
306 | } | | 306 | } |
307 | | | 307 | |
308 | static int | | 308 | static int |
309 | ccdinit(struct ccd_softc *cs, char **cpaths, struct vnode **vpp, | | 309 | ccdinit(struct ccd_softc *cs, char **cpaths, struct vnode **vpp, |
310 | struct lwp *l) | | 310 | struct lwp *l) |
311 | { | | 311 | { |
312 | struct ccdcinfo *ci = NULL; | | 312 | struct ccdcinfo *ci = NULL; |
313 | int ix; | | 313 | int ix; |
314 | struct ccdgeom *ccg = &cs->sc_geom; | | 314 | struct ccdgeom *ccg = &cs->sc_geom; |
315 | char *tmppath; | | 315 | char *tmppath; |
316 | int error, path_alloced; | | 316 | int error, path_alloced; |
317 | uint64_t psize, minsize; | | 317 | uint64_t psize, minsize; |
318 | unsigned secsize, maxsecsize; | | 318 | unsigned secsize, maxsecsize; |
319 | struct disk_geom *dg; | | 319 | struct disk_geom *dg; |
320 | | | 320 | |
321 | #ifdef DEBUG | | 321 | #ifdef DEBUG |
322 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) | | 322 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) |
323 | printf("%s: ccdinit\n", cs->sc_xname); | | 323 | printf("%s: ccdinit\n", cs->sc_xname); |
324 | #endif | | 324 | #endif |
325 | | | 325 | |
326 | /* Allocate space for the component info. */ | | 326 | /* Allocate space for the component info. */ |
327 | cs->sc_cinfo = kmem_alloc(cs->sc_nccdisks * sizeof(*cs->sc_cinfo), | | 327 | cs->sc_cinfo = kmem_alloc(cs->sc_nccdisks * sizeof(*cs->sc_cinfo), |
328 | KM_SLEEP); | | 328 | KM_SLEEP); |
329 | tmppath = kmem_alloc(MAXPATHLEN, KM_SLEEP); | | 329 | tmppath = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
330 | | | 330 | |
331 | cs->sc_size = 0; | | 331 | cs->sc_size = 0; |
332 | | | 332 | |
333 | /* | | 333 | /* |
334 | * Verify that each component piece exists and record | | 334 | * Verify that each component piece exists and record |
335 | * relevant information about it. | | 335 | * relevant information about it. |
336 | */ | | 336 | */ |
337 | maxsecsize = 0; | | 337 | maxsecsize = 0; |
338 | minsize = 0; | | 338 | minsize = 0; |
339 | for (ix = 0, path_alloced = 0; ix < cs->sc_nccdisks; ix++) { | | 339 | for (ix = 0, path_alloced = 0; ix < cs->sc_nccdisks; ix++) { |
340 | ci = &cs->sc_cinfo[ix]; | | 340 | ci = &cs->sc_cinfo[ix]; |
341 | ci->ci_vp = vpp[ix]; | | 341 | ci->ci_vp = vpp[ix]; |
342 | | | 342 | |
343 | /* | | 343 | /* |
344 | * Copy in the pathname of the component. | | 344 | * Copy in the pathname of the component. |
345 | */ | | 345 | */ |
346 | memset(tmppath, 0, MAXPATHLEN); /* sanity */ | | 346 | memset(tmppath, 0, MAXPATHLEN); /* sanity */ |
347 | error = copyinstr(cpaths[ix], tmppath, | | 347 | error = copyinstr(cpaths[ix], tmppath, |
348 | MAXPATHLEN, &ci->ci_pathlen); | | 348 | MAXPATHLEN, &ci->ci_pathlen); |
349 | if (ci->ci_pathlen == 0) | | 349 | if (ci->ci_pathlen == 0) |
350 | error = EINVAL; | | 350 | error = EINVAL; |
351 | if (error) { | | 351 | if (error) { |
352 | #ifdef DEBUG | | 352 | #ifdef DEBUG |
353 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) | | 353 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) |
354 | printf("%s: can't copy path, error = %d\n", | | 354 | printf("%s: can't copy path, error = %d\n", |
355 | cs->sc_xname, error); | | 355 | cs->sc_xname, error); |
356 | #endif | | 356 | #endif |
357 | goto out; | | 357 | goto out; |
358 | } | | 358 | } |
359 | ci->ci_path = kmem_alloc(ci->ci_pathlen, KM_SLEEP); | | 359 | ci->ci_path = kmem_alloc(ci->ci_pathlen, KM_SLEEP); |
360 | memcpy(ci->ci_path, tmppath, ci->ci_pathlen); | | 360 | memcpy(ci->ci_path, tmppath, ci->ci_pathlen); |
361 | path_alloced++; | | 361 | path_alloced++; |
362 | | | 362 | |
363 | /* | | 363 | /* |
364 | * XXX: Cache the component's dev_t. | | 364 | * XXX: Cache the component's dev_t. |
365 | */ | | 365 | */ |
366 | ci->ci_dev = vpp[ix]->v_rdev; | | 366 | ci->ci_dev = vpp[ix]->v_rdev; |
367 | | | 367 | |
368 | /* | | 368 | /* |
369 | * Get partition information for the component. | | 369 | * Get partition information for the component. |
370 | */ | | 370 | */ |
371 | error = getdisksize(vpp[ix], &psize, &secsize); | | 371 | error = getdisksize(vpp[ix], &psize, &secsize); |
372 | if (error) { | | 372 | if (error) { |
373 | #ifdef DEBUG | | 373 | #ifdef DEBUG |
374 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) | | 374 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) |
375 | printf("%s: %s: disksize failed, error = %d\n", | | 375 | printf("%s: %s: disksize failed, error = %d\n", |
376 | cs->sc_xname, ci->ci_path, error); | | 376 | cs->sc_xname, ci->ci_path, error); |
377 | #endif | | 377 | #endif |
378 | goto out; | | 378 | goto out; |
379 | } | | 379 | } |
380 | | | 380 | |
381 | /* | | 381 | /* |
382 | * Calculate the size, truncating to an interleave | | 382 | * Calculate the size, truncating to an interleave |
383 | * boundary if necessary. | | 383 | * boundary if necessary. |
384 | */ | | 384 | */ |
385 | maxsecsize = secsize > maxsecsize ? secsize : maxsecsize; | | 385 | maxsecsize = secsize > maxsecsize ? secsize : maxsecsize; |
386 | if (cs->sc_ileave > 1) | | 386 | if (cs->sc_ileave > 1) |
387 | psize -= psize % cs->sc_ileave; | | 387 | psize -= psize % cs->sc_ileave; |
388 | | | 388 | |
389 | if (psize == 0) { | | 389 | if (psize == 0) { |
390 | #ifdef DEBUG | | 390 | #ifdef DEBUG |
391 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) | | 391 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) |
392 | printf("%s: %s: size == 0\n", | | 392 | printf("%s: %s: size == 0\n", |
393 | cs->sc_xname, ci->ci_path); | | 393 | cs->sc_xname, ci->ci_path); |
394 | #endif | | 394 | #endif |
395 | error = ENODEV; | | 395 | error = ENODEV; |
396 | goto out; | | 396 | goto out; |
397 | } | | 397 | } |
398 | | | 398 | |
399 | if (minsize == 0 || psize < minsize) | | 399 | if (minsize == 0 || psize < minsize) |
400 | minsize = psize; | | 400 | minsize = psize; |
401 | ci->ci_size = psize; | | 401 | ci->ci_size = psize; |
402 | cs->sc_size += psize; | | 402 | cs->sc_size += psize; |
403 | } | | 403 | } |
404 | | | 404 | |
405 | /* | | 405 | /* |
406 | * Don't allow the interleave to be smaller than | | 406 | * Don't allow the interleave to be smaller than |
407 | * the biggest component sector. | | 407 | * the biggest component sector. |
408 | */ | | 408 | */ |
409 | if ((cs->sc_ileave > 0) && | | 409 | if ((cs->sc_ileave > 0) && |
410 | (cs->sc_ileave < (maxsecsize / DEV_BSIZE))) { | | 410 | (cs->sc_ileave < (maxsecsize / DEV_BSIZE))) { |
411 | #ifdef DEBUG | | 411 | #ifdef DEBUG |
412 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) | | 412 | if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) |
413 | printf("%s: interleave must be at least %d\n", | | 413 | printf("%s: interleave must be at least %d\n", |
414 | cs->sc_xname, (maxsecsize / DEV_BSIZE)); | | 414 | cs->sc_xname, (maxsecsize / DEV_BSIZE)); |
415 | #endif | | 415 | #endif |
416 | error = EINVAL; | | 416 | error = EINVAL; |
417 | goto out; | | 417 | goto out; |
418 | } | | 418 | } |
419 | | | 419 | |
420 | /* | | 420 | /* |
421 | * If uniform interleave is desired set all sizes to that of | | 421 | * If uniform interleave is desired set all sizes to that of |
422 | * the smallest component. | | 422 | * the smallest component. |
423 | */ | | 423 | */ |
424 | if (cs->sc_flags & CCDF_UNIFORM) { | | 424 | if (cs->sc_flags & CCDF_UNIFORM) { |
425 | for (ci = cs->sc_cinfo; | | 425 | for (ci = cs->sc_cinfo; |
426 | ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) | | 426 | ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) |
427 | ci->ci_size = minsize; | | 427 | ci->ci_size = minsize; |
428 | | | 428 | |
429 | cs->sc_size = cs->sc_nccdisks * minsize; | | 429 | cs->sc_size = cs->sc_nccdisks * minsize; |
430 | } | | 430 | } |
431 | | | 431 | |
432 | /* | | 432 | /* |
433 | * Construct the interleave table. | | 433 | * Construct the interleave table. |
434 | */ | | 434 | */ |
435 | ccdinterleave(cs); | | 435 | ccdinterleave(cs); |
436 | | | 436 | |
437 | /* | | 437 | /* |
438 | * Create pseudo-geometry based on 1MB cylinders. It's | | 438 | * Create pseudo-geometry based on 1MB cylinders. It's |
439 | * pretty close. | | 439 | * pretty close. |
440 | */ | | 440 | */ |
441 | ccg->ccg_secsize = DEV_BSIZE; | | 441 | ccg->ccg_secsize = DEV_BSIZE; |
442 | ccg->ccg_ntracks = 1; | | 442 | ccg->ccg_ntracks = 1; |
443 | ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize); | | 443 | ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize); |
444 | ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors; | | 444 | ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors; |
445 | | | 445 | |
446 | dg = &cs->sc_dkdev.dk_geom; | | 446 | dg = &cs->sc_dkdev.dk_geom; |
447 | memset(dg, 0, sizeof(*dg)); | | 447 | memset(dg, 0, sizeof(*dg)); |
448 | dg->dg_secperunit = cs->sc_size; | | 448 | dg->dg_secperunit = cs->sc_size; |
449 | dg->dg_secsize = ccg->ccg_secsize; | | 449 | dg->dg_secsize = ccg->ccg_secsize; |
450 | dg->dg_nsectors = ccg->ccg_nsectors; | | 450 | dg->dg_nsectors = ccg->ccg_nsectors; |
451 | dg->dg_ntracks = ccg->ccg_ntracks; | | 451 | dg->dg_ntracks = ccg->ccg_ntracks; |
452 | dg->dg_ncylinders = ccg->ccg_ncylinders; | | 452 | dg->dg_ncylinders = ccg->ccg_ncylinders; |
453 | | | 453 | |
454 | if (cs->sc_ileave > 0) | | 454 | if (cs->sc_ileave > 0) |
455 | aprint_normal("%s: Interleaving %d component%s " | | 455 | aprint_normal("%s: Interleaving %d component%s " |
456 | "(%d block interleave)\n", cs->sc_xname, | | 456 | "(%d block interleave)\n", cs->sc_xname, |
457 | cs->sc_nccdisks, (cs->sc_nccdisks != 0 ? "s" : ""), | | 457 | cs->sc_nccdisks, (cs->sc_nccdisks != 0 ? "s" : ""), |
458 | cs->sc_ileave); | | 458 | cs->sc_ileave); |
459 | else | | 459 | else |
460 | aprint_normal("%s: Concatenating %d component%s\n", | | 460 | aprint_normal("%s: Concatenating %d component%s\n", |
461 | cs->sc_xname, | | 461 | cs->sc_xname, |
462 | cs->sc_nccdisks, (cs->sc_nccdisks != 0 ? "s" : "")); | | 462 | cs->sc_nccdisks, (cs->sc_nccdisks != 0 ? "s" : "")); |
463 | for (ix = 0; ix < cs->sc_nccdisks; ix++) { | | 463 | for (ix = 0; ix < cs->sc_nccdisks; ix++) { |
464 | ci = &cs->sc_cinfo[ix]; | | 464 | ci = &cs->sc_cinfo[ix]; |
465 | aprint_normal("%s: %s (%ju blocks)\n", cs->sc_xname, | | 465 | aprint_normal("%s: %s (%ju blocks)\n", cs->sc_xname, |
466 | ci->ci_path, (uintmax_t)ci->ci_size); | | 466 | ci->ci_path, (uintmax_t)ci->ci_size); |
467 | } | | 467 | } |
468 | aprint_normal("%s: total %ju blocks\n", cs->sc_xname, cs->sc_size); | | 468 | aprint_normal("%s: total %ju blocks\n", cs->sc_xname, cs->sc_size); |
469 | | | 469 | |
470 | /* | | 470 | /* |
471 | * Create thread to handle deferred I/O. | | 471 | * Create thread to handle deferred I/O. |
472 | */ | | 472 | */ |
473 | cs->sc_zap = false; | | 473 | cs->sc_zap = false; |
474 | error = kthread_create(PRI_BIO, KTHREAD_MPSAFE, NULL, ccdthread, | | 474 | error = kthread_create(PRI_BIO, KTHREAD_MPSAFE, NULL, ccdthread, |
475 | cs, &cs->sc_thread, "%s", cs->sc_xname); | | 475 | cs, &cs->sc_thread, "%s", cs->sc_xname); |
476 | if (error) { | | 476 | if (error) { |
477 | printf("ccdinit: can't create thread: %d\n", error); | | 477 | printf("ccdinit: can't create thread: %d\n", error); |
478 | goto out; | | 478 | goto out; |
479 | } | | 479 | } |
480 | | | 480 | |
481 | /* | | 481 | /* |
482 | * Only now that everything is set up can we enable the device. | | 482 | * Only now that everything is set up can we enable the device. |
483 | */ | | 483 | */ |
484 | mutex_enter(cs->sc_iolock); | | 484 | mutex_enter(cs->sc_iolock); |
485 | cs->sc_flags |= CCDF_INITED; | | 485 | cs->sc_flags |= CCDF_INITED; |
486 | mutex_exit(cs->sc_iolock); | | 486 | mutex_exit(cs->sc_iolock); |
487 | kmem_free(tmppath, MAXPATHLEN); | | 487 | kmem_free(tmppath, MAXPATHLEN); |
488 | return (0); | | 488 | return (0); |
489 | | | 489 | |
490 | out: | | 490 | out: |
491 | for (ix = 0; ix < path_alloced; ix++) { | | 491 | for (ix = 0; ix < path_alloced; ix++) { |
492 | kmem_free(cs->sc_cinfo[ix].ci_path, | | 492 | kmem_free(cs->sc_cinfo[ix].ci_path, |
493 | cs->sc_cinfo[ix].ci_pathlen); | | 493 | cs->sc_cinfo[ix].ci_pathlen); |
494 | } | | 494 | } |
495 | kmem_free(cs->sc_cinfo, cs->sc_nccdisks * sizeof(struct ccdcinfo)); | | 495 | kmem_free(cs->sc_cinfo, cs->sc_nccdisks * sizeof(struct ccdcinfo)); |
496 | kmem_free(tmppath, MAXPATHLEN); | | 496 | kmem_free(tmppath, MAXPATHLEN); |
497 | return (error); | | 497 | return (error); |
498 | } | | 498 | } |
499 | | | 499 | |
500 | static void | | 500 | static void |
501 | ccdinterleave(struct ccd_softc *cs) | | 501 | ccdinterleave(struct ccd_softc *cs) |
502 | { | | 502 | { |
503 | struct ccdcinfo *ci, *smallci; | | 503 | struct ccdcinfo *ci, *smallci; |
504 | struct ccdiinfo *ii; | | 504 | struct ccdiinfo *ii; |
505 | daddr_t bn, lbn; | | 505 | daddr_t bn, lbn; |
506 | int ix; | | 506 | int ix; |
507 | u_long size; | | 507 | u_long size; |
508 | | | 508 | |
509 | #ifdef DEBUG | | 509 | #ifdef DEBUG |
510 | if (ccddebug & CCDB_INIT) | | 510 | if (ccddebug & CCDB_INIT) |
511 | printf("ccdinterleave(%p): ileave %d\n", cs, cs->sc_ileave); | | 511 | printf("ccdinterleave(%p): ileave %d\n", cs, cs->sc_ileave); |
512 | #endif | | 512 | #endif |
513 | /* | | 513 | /* |
514 | * Allocate an interleave table. | | 514 | * Allocate an interleave table. |
515 | * Chances are this is too big, but we don't care. | | 515 | * Chances are this is too big, but we don't care. |
516 | */ | | 516 | */ |
517 | size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo); | | 517 | size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo); |
518 | cs->sc_itable = kmem_zalloc(size, KM_SLEEP); | | 518 | cs->sc_itable = kmem_zalloc(size, KM_SLEEP); |
519 | | | 519 | |
520 | /* | | 520 | /* |
521 | * Trivial case: no interleave (actually interleave of disk size). | | 521 | * Trivial case: no interleave (actually interleave of disk size). |
522 | * Each table entry represents a single component in its entirety. | | 522 | * Each table entry represents a single component in its entirety. |
523 | */ | | 523 | */ |
524 | if (cs->sc_ileave == 0) { | | 524 | if (cs->sc_ileave == 0) { |
525 | bn = 0; | | 525 | bn = 0; |
526 | ii = cs->sc_itable; | | 526 | ii = cs->sc_itable; |
527 | | | 527 | |
528 | for (ix = 0; ix < cs->sc_nccdisks; ix++) { | | 528 | for (ix = 0; ix < cs->sc_nccdisks; ix++) { |
529 | /* Allocate space for ii_index. */ | | 529 | /* Allocate space for ii_index. */ |
530 | ii->ii_indexsz = sizeof(int); | | 530 | ii->ii_indexsz = sizeof(int); |
531 | ii->ii_index = kmem_alloc(ii->ii_indexsz, KM_SLEEP); | | 531 | ii->ii_index = kmem_alloc(ii->ii_indexsz, KM_SLEEP); |
532 | ii->ii_ndisk = 1; | | 532 | ii->ii_ndisk = 1; |
533 | ii->ii_startblk = bn; | | 533 | ii->ii_startblk = bn; |
534 | ii->ii_startoff = 0; | | 534 | ii->ii_startoff = 0; |
535 | ii->ii_index[0] = ix; | | 535 | ii->ii_index[0] = ix; |
536 | bn += cs->sc_cinfo[ix].ci_size; | | 536 | bn += cs->sc_cinfo[ix].ci_size; |
537 | ii++; | | 537 | ii++; |
538 | } | | 538 | } |
539 | ii->ii_ndisk = 0; | | 539 | ii->ii_ndisk = 0; |
540 | #ifdef DEBUG | | 540 | #ifdef DEBUG |
541 | if (ccddebug & CCDB_INIT) | | 541 | if (ccddebug & CCDB_INIT) |
542 | printiinfo(cs->sc_itable); | | 542 | printiinfo(cs->sc_itable); |
543 | #endif | | 543 | #endif |
544 | return; | | 544 | return; |
545 | } | | 545 | } |
546 | | | 546 | |
547 | /* | | 547 | /* |
548 | * The following isn't fast or pretty; it doesn't have to be. | | 548 | * The following isn't fast or pretty; it doesn't have to be. |
549 | */ | | 549 | */ |
550 | size = 0; | | 550 | size = 0; |
551 | bn = lbn = 0; | | 551 | bn = lbn = 0; |
552 | for (ii = cs->sc_itable; ; ii++) { | | 552 | for (ii = cs->sc_itable; ; ii++) { |
553 | /* Allocate space for ii_index. */ | | 553 | /* Allocate space for ii_index. */ |
554 | ii->ii_indexsz = sizeof(int) * cs->sc_nccdisks; | | 554 | ii->ii_indexsz = sizeof(int) * cs->sc_nccdisks; |
555 | ii->ii_index = kmem_alloc(ii->ii_indexsz, KM_SLEEP); | | 555 | ii->ii_index = kmem_alloc(ii->ii_indexsz, KM_SLEEP); |
556 | | | 556 | |
557 | /* | | 557 | /* |
558 | * Locate the smallest of the remaining components | | 558 | * Locate the smallest of the remaining components |
559 | */ | | 559 | */ |
560 | smallci = NULL; | | 560 | smallci = NULL; |
561 | for (ci = cs->sc_cinfo; | | 561 | for (ci = cs->sc_cinfo; |
562 | ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) | | 562 | ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) |
563 | if (ci->ci_size > size && | | 563 | if (ci->ci_size > size && |
564 | (smallci == NULL || | | 564 | (smallci == NULL || |
565 | ci->ci_size < smallci->ci_size)) | | 565 | ci->ci_size < smallci->ci_size)) |
566 | smallci = ci; | | 566 | smallci = ci; |
567 | | | 567 | |
568 | /* | | 568 | /* |
569 | * Nobody left, all done | | 569 | * Nobody left, all done |
570 | */ | | 570 | */ |
571 | if (smallci == NULL) { | | 571 | if (smallci == NULL) { |
572 | ii->ii_ndisk = 0; | | 572 | ii->ii_ndisk = 0; |
573 | break; | | 573 | break; |
574 | } | | 574 | } |
575 | | | 575 | |
576 | /* | | 576 | /* |
577 | * Record starting logical block and component offset | | 577 | * Record starting logical block and component offset |
578 | */ | | 578 | */ |
579 | ii->ii_startblk = bn / cs->sc_ileave; | | 579 | ii->ii_startblk = bn / cs->sc_ileave; |
580 | ii->ii_startoff = lbn; | | 580 | ii->ii_startoff = lbn; |
581 | | | 581 | |
582 | /* | | 582 | /* |
583 | * Determine how many disks take part in this interleave | | 583 | * Determine how many disks take part in this interleave |
584 | * and record their indices. | | 584 | * and record their indices. |
585 | */ | | 585 | */ |
586 | ix = 0; | | 586 | ix = 0; |
587 | for (ci = cs->sc_cinfo; | | 587 | for (ci = cs->sc_cinfo; |
588 | ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) | | 588 | ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) |
589 | if (ci->ci_size >= smallci->ci_size) | | 589 | if (ci->ci_size >= smallci->ci_size) |
590 | ii->ii_index[ix++] = ci - cs->sc_cinfo; | | 590 | ii->ii_index[ix++] = ci - cs->sc_cinfo; |
591 | ii->ii_ndisk = ix; | | 591 | ii->ii_ndisk = ix; |
592 | bn += ix * (smallci->ci_size - size); | | 592 | bn += ix * (smallci->ci_size - size); |
593 | lbn = smallci->ci_size / cs->sc_ileave; | | 593 | lbn = smallci->ci_size / cs->sc_ileave; |
594 | size = smallci->ci_size; | | 594 | size = smallci->ci_size; |
595 | } | | 595 | } |
596 | #ifdef DEBUG | | 596 | #ifdef DEBUG |
597 | if (ccddebug & CCDB_INIT) | | 597 | if (ccddebug & CCDB_INIT) |
598 | printiinfo(cs->sc_itable); | | 598 | printiinfo(cs->sc_itable); |
599 | #endif | | 599 | #endif |
600 | } | | 600 | } |
601 | | | 601 | |
602 | /* ARGSUSED */ | | 602 | /* ARGSUSED */ |
603 | static int | | 603 | static int |
604 | ccdopen(dev_t dev, int flags, int fmt, struct lwp *l) | | 604 | ccdopen(dev_t dev, int flags, int fmt, struct lwp *l) |
605 | { | | 605 | { |
606 | int unit = ccdunit(dev); | | 606 | int unit = ccdunit(dev); |
607 | struct ccd_softc *cs; | | 607 | struct ccd_softc *cs; |
608 | struct disklabel *lp; | | 608 | struct disklabel *lp; |
609 | int error = 0, part, pmask; | | 609 | int error = 0, part, pmask; |
610 | | | 610 | |
611 | #ifdef DEBUG | | 611 | #ifdef DEBUG |
612 | if (ccddebug & CCDB_FOLLOW) | | 612 | if (ccddebug & CCDB_FOLLOW) |
613 | printf("ccdopen(0x%"PRIx64", 0x%x)\n", dev, flags); | | 613 | printf("ccdopen(0x%"PRIx64", 0x%x)\n", dev, flags); |
614 | #endif | | 614 | #endif |
615 | if ((cs = ccdget(unit, 1)) == NULL) | | 615 | if ((cs = ccdget(unit, 1)) == NULL) |
616 | return ENXIO; | | 616 | return ENXIO; |
617 | | | 617 | |
618 | mutex_enter(&cs->sc_dvlock); | | 618 | mutex_enter(&cs->sc_dvlock); |
619 | | | 619 | |
620 | lp = cs->sc_dkdev.dk_label; | | 620 | lp = cs->sc_dkdev.dk_label; |
621 | | | 621 | |
622 | part = DISKPART(dev); | | 622 | part = DISKPART(dev); |
623 | pmask = (1 << part); | | 623 | pmask = (1 << part); |
624 | | | 624 | |
625 | /* | | 625 | /* |
626 | * If we're initialized, check to see if there are any other | | 626 | * If we're initialized, check to see if there are any other |
627 | * open partitions. If not, then it's safe to update | | 627 | * open partitions. If not, then it's safe to update |
628 | * the in-core disklabel. Only read the disklabel if it is | | 628 | * the in-core disklabel. Only read the disklabel if it is |
629 | * not already valid. | | 629 | * not already valid. |
630 | */ | | 630 | */ |
631 | if ((cs->sc_flags & (CCDF_INITED|CCDF_VLABEL)) == CCDF_INITED && | | 631 | if ((cs->sc_flags & (CCDF_INITED|CCDF_VLABEL)) == CCDF_INITED && |
632 | cs->sc_dkdev.dk_openmask == 0) | | 632 | cs->sc_dkdev.dk_openmask == 0) |
633 | ccdgetdisklabel(dev); | | 633 | ccdgetdisklabel(dev); |
634 | | | 634 | |
635 | /* Check that the partition exists. */ | | 635 | /* Check that the partition exists. */ |
636 | if (part != RAW_PART) { | | 636 | if (part != RAW_PART) { |
637 | if (((cs->sc_flags & CCDF_INITED) == 0) || | | 637 | if (((cs->sc_flags & CCDF_INITED) == 0) || |
638 | ((part >= lp->d_npartitions) || | | 638 | ((part >= lp->d_npartitions) || |
639 | (lp->d_partitions[part].p_fstype == FS_UNUSED))) { | | 639 | (lp->d_partitions[part].p_fstype == FS_UNUSED))) { |
640 | error = ENXIO; | | 640 | error = ENXIO; |
641 | goto done; | | 641 | goto done; |
642 | } | | 642 | } |
643 | } | | 643 | } |
644 | | | 644 | |
645 | /* Prevent our unit from being unconfigured while open. */ | | 645 | /* Prevent our unit from being unconfigured while open. */ |
646 | switch (fmt) { | | 646 | switch (fmt) { |
647 | case S_IFCHR: | | 647 | case S_IFCHR: |
648 | cs->sc_dkdev.dk_copenmask |= pmask; | | 648 | cs->sc_dkdev.dk_copenmask |= pmask; |
649 | break; | | 649 | break; |
650 | | | 650 | |
651 | case S_IFBLK: | | 651 | case S_IFBLK: |
652 | cs->sc_dkdev.dk_bopenmask |= pmask; | | 652 | cs->sc_dkdev.dk_bopenmask |= pmask; |
653 | break; | | 653 | break; |
654 | } | | 654 | } |
655 | cs->sc_dkdev.dk_openmask = | | 655 | cs->sc_dkdev.dk_openmask = |
656 | cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; | | 656 | cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; |
657 | | | 657 | |
658 | done: | | 658 | done: |
659 | mutex_exit(&cs->sc_dvlock); | | 659 | mutex_exit(&cs->sc_dvlock); |
660 | return (error); | | 660 | return (error); |
661 | } | | 661 | } |
662 | | | 662 | |
663 | /* ARGSUSED */ | | 663 | /* ARGSUSED */ |
664 | static int | | 664 | static int |
665 | ccdclose(dev_t dev, int flags, int fmt, struct lwp *l) | | 665 | ccdclose(dev_t dev, int flags, int fmt, struct lwp *l) |
666 | { | | 666 | { |
667 | int unit = ccdunit(dev); | | 667 | int unit = ccdunit(dev); |
668 | struct ccd_softc *cs; | | 668 | struct ccd_softc *cs; |
669 | int part; | | 669 | int part; |
670 | | | 670 | |
671 | #ifdef DEBUG | | 671 | #ifdef DEBUG |
672 | if (ccddebug & CCDB_FOLLOW) | | 672 | if (ccddebug & CCDB_FOLLOW) |
673 | printf("ccdclose(0x%"PRIx64", 0x%x)\n", dev, flags); | | 673 | printf("ccdclose(0x%"PRIx64", 0x%x)\n", dev, flags); |
674 | #endif | | 674 | #endif |
675 | | | 675 | |
676 | if ((cs = ccdget(unit, 0)) == NULL) | | 676 | if ((cs = ccdget(unit, 0)) == NULL) |
677 | return ENXIO; | | 677 | return ENXIO; |
678 | | | 678 | |
679 | mutex_enter(&cs->sc_dvlock); | | 679 | mutex_enter(&cs->sc_dvlock); |
680 | | | 680 | |
681 | part = DISKPART(dev); | | 681 | part = DISKPART(dev); |
682 | | | 682 | |
683 | /* ...that much closer to allowing unconfiguration... */ | | 683 | /* ...that much closer to allowing unconfiguration... */ |
684 | switch (fmt) { | | 684 | switch (fmt) { |
685 | case S_IFCHR: | | 685 | case S_IFCHR: |
686 | cs->sc_dkdev.dk_copenmask &= ~(1 << part); | | 686 | cs->sc_dkdev.dk_copenmask &= ~(1 << part); |
687 | break; | | 687 | break; |
688 | | | 688 | |
689 | case S_IFBLK: | | 689 | case S_IFBLK: |
690 | cs->sc_dkdev.dk_bopenmask &= ~(1 << part); | | 690 | cs->sc_dkdev.dk_bopenmask &= ~(1 << part); |
691 | break; | | 691 | break; |
692 | } | | 692 | } |
693 | cs->sc_dkdev.dk_openmask = | | 693 | cs->sc_dkdev.dk_openmask = |
694 | cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; | | 694 | cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; |
695 | | | 695 | |
696 | if (cs->sc_dkdev.dk_openmask == 0) { | | 696 | if (cs->sc_dkdev.dk_openmask == 0) { |
697 | if ((cs->sc_flags & CCDF_KLABEL) == 0) | | 697 | if ((cs->sc_flags & CCDF_KLABEL) == 0) |
698 | cs->sc_flags &= ~CCDF_VLABEL; | | 698 | cs->sc_flags &= ~CCDF_VLABEL; |
699 | } | | 699 | } |
700 | | | 700 | |
701 | mutex_exit(&cs->sc_dvlock); | | 701 | mutex_exit(&cs->sc_dvlock); |
702 | return (0); | | 702 | return (0); |
703 | } | | 703 | } |
704 | | | 704 | |
705 | static bool | | 705 | static bool |
706 | ccdbackoff(struct ccd_softc *cs) | | 706 | ccdbackoff(struct ccd_softc *cs) |
707 | { | | 707 | { |
708 | | | 708 | |
709 | /* XXX Arbitrary, should be a uvm call. */ | | 709 | /* XXX Arbitrary, should be a uvm call. */ |
710 | return uvm_availmem(true) < (uvmexp.freemin >> 1) && | | 710 | return uvm_availmem(true) < (uvmexp.freemin >> 1) && |
711 | disk_isbusy(&cs->sc_dkdev); | | 711 | disk_isbusy(&cs->sc_dkdev); |
712 | } | | 712 | } |
713 | | | 713 | |
714 | static void | | 714 | static void |
715 | ccdthread(void *cookie) | | 715 | ccdthread(void *cookie) |
716 | { | | 716 | { |
717 | struct ccd_softc *cs; | | 717 | struct ccd_softc *cs; |
718 | | | 718 | |
719 | cs = cookie; | | 719 | cs = cookie; |
720 | | | 720 | |
721 | #ifdef DEBUG | | 721 | #ifdef DEBUG |
722 | if (ccddebug & CCDB_FOLLOW) | | 722 | if (ccddebug & CCDB_FOLLOW) |
723 | printf("ccdthread: hello\n"); | | 723 | printf("ccdthread: hello\n"); |
724 | #endif | | 724 | #endif |
725 | | | 725 | |
726 | mutex_enter(cs->sc_iolock); | | 726 | mutex_enter(cs->sc_iolock); |
727 | while (__predict_true(!cs->sc_zap)) { | | 727 | while (__predict_true(!cs->sc_zap)) { |
728 | if (bufq_peek(cs->sc_bufq) == NULL) { | | 728 | if (bufq_peek(cs->sc_bufq) == NULL) { |
729 | /* Nothing to do. */ | | 729 | /* Nothing to do. */ |
730 | cv_wait(&cs->sc_push, cs->sc_iolock); | | 730 | cv_wait(&cs->sc_push, cs->sc_iolock); |
731 | continue; | | 731 | continue; |
732 | } | | 732 | } |
733 | if (ccdbackoff(cs)) { | | 733 | if (ccdbackoff(cs)) { |
734 | /* Wait for memory to become available. */ | | 734 | /* Wait for memory to become available. */ |
735 | (void)cv_timedwait(&cs->sc_push, cs->sc_iolock, 1); | | 735 | (void)cv_timedwait(&cs->sc_push, cs->sc_iolock, 1); |
736 | continue; | | 736 | continue; |
737 | } | | 737 | } |
738 | #ifdef DEBUG | | 738 | #ifdef DEBUG |
739 | if (ccddebug & CCDB_FOLLOW) | | 739 | if (ccddebug & CCDB_FOLLOW) |
740 | printf("ccdthread: dispatching I/O\n"); | | 740 | printf("ccdthread: dispatching I/O\n"); |
741 | #endif | | 741 | #endif |
742 | ccdstart(cs); | | 742 | ccdstart(cs); |
743 | mutex_enter(cs->sc_iolock); | | 743 | mutex_enter(cs->sc_iolock); |
744 | } | | 744 | } |
745 | cs->sc_thread = NULL; | | 745 | cs->sc_thread = NULL; |
746 | mutex_exit(cs->sc_iolock); | | 746 | mutex_exit(cs->sc_iolock); |
747 | #ifdef DEBUG | | 747 | #ifdef DEBUG |
748 | if (ccddebug & CCDB_FOLLOW) | | 748 | if (ccddebug & CCDB_FOLLOW) |
749 | printf("ccdthread: goodbye\n"); | | 749 | printf("ccdthread: goodbye\n"); |
750 | #endif | | 750 | #endif |
751 | kthread_exit(0); | | 751 | kthread_exit(0); |
752 | } | | 752 | } |
753 | | | 753 | |
754 | static void | | 754 | static void |
755 | ccdstrategy(struct buf *bp) | | 755 | ccdstrategy(struct buf *bp) |
756 | { | | 756 | { |
757 | int unit = ccdunit(bp->b_dev); | | 757 | int unit = ccdunit(bp->b_dev); |
758 | struct ccd_softc *cs; | | 758 | struct ccd_softc *cs; |
759 | if ((cs = ccdget(unit, 0)) == NULL) | | 759 | if ((cs = ccdget(unit, 0)) == NULL) |
760 | return; | | 760 | return; |
761 | | | 761 | |
762 | /* Must be open or reading label. */ | | 762 | /* Must be open or reading label. */ |
763 | KASSERT(cs->sc_dkdev.dk_openmask != 0 || | | 763 | KASSERT(cs->sc_dkdev.dk_openmask != 0 || |
764 | (cs->sc_flags & CCDF_RLABEL) != 0); | | 764 | (cs->sc_flags & CCDF_RLABEL) != 0); |
765 | | | 765 | |
766 | mutex_enter(cs->sc_iolock); | | 766 | mutex_enter(cs->sc_iolock); |
767 | /* Synchronize with device init/uninit. */ | | 767 | /* Synchronize with device init/uninit. */ |
768 | if (__predict_false((cs->sc_flags & CCDF_INITED) == 0)) { | | 768 | if (__predict_false((cs->sc_flags & CCDF_INITED) == 0)) { |
769 | mutex_exit(cs->sc_iolock); | | 769 | mutex_exit(cs->sc_iolock); |
770 | #ifdef DEBUG | | 770 | #ifdef DEBUG |
771 | if (ccddebug & CCDB_FOLLOW) | | 771 | if (ccddebug & CCDB_FOLLOW) |
772 | printf("ccdstrategy: unit %d: not inited\n", unit); | | 772 | printf("ccdstrategy: unit %d: not inited\n", unit); |
773 | #endif | | 773 | #endif |
774 | bp->b_error = ENXIO; | | 774 | bp->b_error = ENXIO; |
775 | bp->b_resid = bp->b_bcount; | | 775 | bp->b_resid = bp->b_bcount; |
776 | biodone(bp); | | 776 | biodone(bp); |
777 | return; | | 777 | return; |
778 | } | | 778 | } |
779 | | | 779 | |
780 | /* Defer to thread if system is low on memory. */ | | 780 | /* Defer to thread if system is low on memory. */ |
781 | bufq_put(cs->sc_bufq, bp); | | 781 | bufq_put(cs->sc_bufq, bp); |
782 | if (__predict_false(ccdbackoff(cs))) { | | 782 | if (__predict_false(ccdbackoff(cs))) { |
783 | mutex_exit(cs->sc_iolock); | | 783 | mutex_exit(cs->sc_iolock); |
784 | #ifdef DEBUG | | 784 | #ifdef DEBUG |
785 | if (ccddebug & CCDB_FOLLOW) | | 785 | if (ccddebug & CCDB_FOLLOW) |
786 | printf("ccdstrategy: holding off on I/O\n"); | | 786 | printf("ccdstrategy: holding off on I/O\n"); |
787 | #endif | | 787 | #endif |
788 | return; | | 788 | return; |
789 | } | | 789 | } |
790 | ccdstart(cs); | | 790 | ccdstart(cs); |
791 | } | | 791 | } |
792 | | | 792 | |
793 | static void | | 793 | static void |
794 | ccdstart(struct ccd_softc *cs) | | 794 | ccdstart(struct ccd_softc *cs) |
795 | { | | 795 | { |
796 | daddr_t blkno; | | 796 | daddr_t blkno; |
797 | int wlabel; | | 797 | int wlabel; |
798 | struct disklabel *lp; | | 798 | struct disklabel *lp; |
799 | long bcount, rcount; | | 799 | long bcount, rcount; |
800 | struct ccdbuf *cbp; | | 800 | struct ccdbuf *cbp; |
801 | char *addr; | | 801 | char *addr; |
802 | daddr_t bn; | | 802 | daddr_t bn; |
803 | vnode_t *vp; | | 803 | vnode_t *vp; |
804 | buf_t *bp; | | 804 | buf_t *bp; |
805 | | | 805 | |
806 | KASSERT(mutex_owned(cs->sc_iolock)); | | 806 | KASSERT(mutex_owned(cs->sc_iolock)); |
807 | | | 807 | |
808 | bp = bufq_get(cs->sc_bufq); | | 808 | bp = bufq_get(cs->sc_bufq); |
809 | KASSERT(bp != NULL); | | 809 | KASSERT(bp != NULL); |
810 | | | 810 | |
811 | disk_busy(&cs->sc_dkdev); | | 811 | disk_busy(&cs->sc_dkdev); |
812 | | | 812 | |
813 | #ifdef DEBUG | | 813 | #ifdef DEBUG |
814 | if (ccddebug & CCDB_FOLLOW) | | 814 | if (ccddebug & CCDB_FOLLOW) |
815 | printf("ccdstart(%s, %p)\n", cs->sc_xname, bp); | | 815 | printf("ccdstart(%s, %p)\n", cs->sc_xname, bp); |
816 | #endif | | 816 | #endif |
817 | | | 817 | |
818 | /* If it's a nil transfer, wake up the top half now. */ | | 818 | /* If it's a nil transfer, wake up the top half now. */ |
819 | if (bp->b_bcount == 0) | | 819 | if (bp->b_bcount == 0) |
820 | goto done; | | 820 | goto done; |
821 | | | 821 | |
822 | lp = cs->sc_dkdev.dk_label; | | 822 | lp = cs->sc_dkdev.dk_label; |
823 | | | 823 | |
824 | /* | | 824 | /* |
825 | * Do bounds checking and adjust transfer. If there's an | | 825 | * Do bounds checking and adjust transfer. If there's an |
826 | * error, the bounds check will flag that for us. Convert | | 826 | * error, the bounds check will flag that for us. Convert |
827 | * the partition relative block number to an absolute. | | 827 | * the partition relative block number to an absolute. |
828 | */ | | 828 | */ |
829 | blkno = bp->b_blkno; | | 829 | blkno = bp->b_blkno; |
830 | wlabel = cs->sc_flags & (CCDF_WLABEL|CCDF_LABELLING); | | 830 | wlabel = cs->sc_flags & (CCDF_WLABEL|CCDF_LABELLING); |
831 | if (DISKPART(bp->b_dev) != RAW_PART) { | | 831 | if (DISKPART(bp->b_dev) != RAW_PART) { |
832 | if (bounds_check_with_label(&cs->sc_dkdev, bp, wlabel) <= 0) | | 832 | if (bounds_check_with_label(&cs->sc_dkdev, bp, wlabel) <= 0) |
833 | goto done; | | 833 | goto done; |
834 | blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset; | | 834 | blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset; |
835 | } | | 835 | } |
836 | mutex_exit(cs->sc_iolock); | | 836 | mutex_exit(cs->sc_iolock); |
837 | bp->b_rawblkno = blkno; | | 837 | bp->b_rawblkno = blkno; |
838 | | | 838 | |
839 | /* Allocate the component buffers and start I/O! */ | | 839 | /* Allocate the component buffers and start I/O! */ |
840 | bp->b_resid = bp->b_bcount; | | 840 | bp->b_resid = bp->b_bcount; |
841 | bn = bp->b_rawblkno; | | 841 | bn = bp->b_rawblkno; |
842 | addr = bp->b_data; | | 842 | addr = bp->b_data; |
843 | for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) { | | 843 | for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) { |
844 | cbp = ccdbuffer(cs, bp, bn, addr, bcount); | | 844 | cbp = ccdbuffer(cs, bp, bn, addr, bcount); |
845 | rcount = cbp->cb_buf.b_bcount; | | 845 | rcount = cbp->cb_buf.b_bcount; |
846 | bn += btodb(rcount); | | 846 | bn += btodb(rcount); |
847 | addr += rcount; | | 847 | addr += rcount; |
848 | vp = cbp->cb_buf.b_vp; | | 848 | vp = cbp->cb_buf.b_vp; |
849 | if ((cbp->cb_buf.b_flags & B_READ) == 0) { | | 849 | if ((cbp->cb_buf.b_flags & B_READ) == 0) { |
850 | mutex_enter(vp->v_interlock); | | 850 | mutex_enter(vp->v_interlock); |
851 | vp->v_numoutput++; | | 851 | vp->v_numoutput++; |
852 | mutex_exit(vp->v_interlock); | | 852 | mutex_exit(vp->v_interlock); |
853 | } | | 853 | } |
854 | (void)VOP_STRATEGY(vp, &cbp->cb_buf); | | 854 | (void)VOP_STRATEGY(vp, &cbp->cb_buf); |
855 | } | | 855 | } |
856 | return; | | 856 | return; |
857 | | | 857 | |
858 | done: | | 858 | done: |
859 | disk_unbusy(&cs->sc_dkdev, 0, 0); | | 859 | disk_unbusy(&cs->sc_dkdev, 0, 0); |
860 | cv_broadcast(&cs->sc_stop); | | 860 | cv_broadcast(&cs->sc_stop); |
861 | cv_broadcast(&cs->sc_push); | | 861 | cv_broadcast(&cs->sc_push); |
862 | mutex_exit(cs->sc_iolock); | | 862 | mutex_exit(cs->sc_iolock); |
863 | bp->b_resid = bp->b_bcount; | | 863 | bp->b_resid = bp->b_bcount; |
864 | biodone(bp); | | 864 | biodone(bp); |
865 | } | | 865 | } |
866 | | | 866 | |
867 | /* | | 867 | /* |
868 | * Build a component buffer header. | | 868 | * Build a component buffer header. |
869 | */ | | 869 | */ |
870 | static struct ccdbuf * | | 870 | static struct ccdbuf * |
871 | ccdbuffer(struct ccd_softc *cs, struct buf *bp, daddr_t bn, void *addr, | | 871 | ccdbuffer(struct ccd_softc *cs, struct buf *bp, daddr_t bn, void *addr, |
872 | long bcount) | | 872 | long bcount) |
873 | { | | 873 | { |
874 | struct ccdcinfo *ci; | | 874 | struct ccdcinfo *ci; |
875 | struct ccdbuf *cbp; | | 875 | struct ccdbuf *cbp; |
876 | daddr_t cbn, cboff; | | 876 | daddr_t cbn, cboff; |
877 | u_int64_t cbc; | | 877 | u_int64_t cbc; |
878 | int ccdisk; | | 878 | int ccdisk; |
879 | | | 879 | |
880 | #ifdef DEBUG | | 880 | #ifdef DEBUG |
881 | if (ccddebug & CCDB_IO) | | 881 | if (ccddebug & CCDB_IO) |
882 | printf("ccdbuffer(%p, %p, %" PRId64 ", %p, %ld)\n", | | 882 | printf("ccdbuffer(%p, %p, %" PRId64 ", %p, %ld)\n", |
883 | cs, bp, bn, addr, bcount); | | 883 | cs, bp, bn, addr, bcount); |
884 | #endif | | 884 | #endif |
885 | /* | | 885 | /* |
886 | * Determine which component bn falls in. | | 886 | * Determine which component bn falls in. |
887 | */ | | 887 | */ |
888 | cbn = bn; | | 888 | cbn = bn; |
889 | cboff = 0; | | 889 | cboff = 0; |
890 | | | 890 | |
891 | /* | | 891 | /* |
892 | * Serially concatenated | | 892 | * Serially concatenated |
893 | */ | | 893 | */ |
894 | if (cs->sc_ileave == 0) { | | 894 | if (cs->sc_ileave == 0) { |
895 | daddr_t sblk; | | 895 | daddr_t sblk; |
896 | | | 896 | |
897 | sblk = 0; | | 897 | sblk = 0; |
898 | for (ccdisk = 0, ci = &cs->sc_cinfo[ccdisk]; | | 898 | for (ccdisk = 0, ci = &cs->sc_cinfo[ccdisk]; |
899 | cbn >= sblk + ci->ci_size; | | 899 | cbn >= sblk + ci->ci_size; |
900 | ccdisk++, ci = &cs->sc_cinfo[ccdisk]) | | 900 | ccdisk++, ci = &cs->sc_cinfo[ccdisk]) |
901 | sblk += ci->ci_size; | | 901 | sblk += ci->ci_size; |
902 | cbn -= sblk; | | 902 | cbn -= sblk; |
903 | } | | 903 | } |
904 | /* | | 904 | /* |
905 | * Interleaved | | 905 | * Interleaved |
906 | */ | | 906 | */ |
907 | else { | | 907 | else { |
908 | struct ccdiinfo *ii; | | 908 | struct ccdiinfo *ii; |
909 | int off; | | 909 | int off; |
910 | | | 910 | |
911 | cboff = cbn % cs->sc_ileave; | | 911 | cboff = cbn % cs->sc_ileave; |
912 | cbn /= cs->sc_ileave; | | 912 | cbn /= cs->sc_ileave; |
913 | for (ii = cs->sc_itable; ii->ii_ndisk; ii++) | | 913 | for (ii = cs->sc_itable; ii->ii_ndisk; ii++) |
914 | if (ii->ii_startblk > cbn) | | 914 | if (ii->ii_startblk > cbn) |
915 | break; | | 915 | break; |
916 | ii--; | | 916 | ii--; |
917 | off = cbn - ii->ii_startblk; | | 917 | off = cbn - ii->ii_startblk; |
918 | if (ii->ii_ndisk == 1) { | | 918 | if (ii->ii_ndisk == 1) { |
919 | ccdisk = ii->ii_index[0]; | | 919 | ccdisk = ii->ii_index[0]; |
920 | cbn = ii->ii_startoff + off; | | 920 | cbn = ii->ii_startoff + off; |
921 | } else { | | 921 | } else { |
922 | ccdisk = ii->ii_index[off % ii->ii_ndisk]; | | 922 | ccdisk = ii->ii_index[off % ii->ii_ndisk]; |
923 | cbn = ii->ii_startoff + off / ii->ii_ndisk; | | 923 | cbn = ii->ii_startoff + off / ii->ii_ndisk; |
924 | } | | 924 | } |
925 | cbn *= cs->sc_ileave; | | 925 | cbn *= cs->sc_ileave; |
926 | ci = &cs->sc_cinfo[ccdisk]; | | 926 | ci = &cs->sc_cinfo[ccdisk]; |
927 | } | | 927 | } |
928 | | | 928 | |
929 | /* | | 929 | /* |
930 | * Fill in the component buf structure. | | 930 | * Fill in the component buf structure. |
931 | */ | | 931 | */ |
932 | cbp = CCD_GETBUF(); | | 932 | cbp = CCD_GETBUF(); |
933 | KASSERT(cbp != NULL); | | 933 | KASSERT(cbp != NULL); |
934 | buf_init(&cbp->cb_buf); | | 934 | buf_init(&cbp->cb_buf); |
935 | cbp->cb_buf.b_flags = bp->b_flags; | | 935 | cbp->cb_buf.b_flags = bp->b_flags; |
936 | cbp->cb_buf.b_oflags = bp->b_oflags; | | 936 | cbp->cb_buf.b_oflags = bp->b_oflags; |
937 | cbp->cb_buf.b_cflags = bp->b_cflags; | | 937 | cbp->cb_buf.b_cflags = bp->b_cflags; |
938 | cbp->cb_buf.b_iodone = ccdiodone; | | 938 | cbp->cb_buf.b_iodone = ccdiodone; |
939 | cbp->cb_buf.b_proc = bp->b_proc; | | 939 | cbp->cb_buf.b_proc = bp->b_proc; |
940 | cbp->cb_buf.b_dev = ci->ci_dev; | | 940 | cbp->cb_buf.b_dev = ci->ci_dev; |
941 | cbp->cb_buf.b_blkno = cbn + cboff; | | 941 | cbp->cb_buf.b_blkno = cbn + cboff; |
942 | cbp->cb_buf.b_data = addr; | | 942 | cbp->cb_buf.b_data = addr; |
943 | cbp->cb_buf.b_vp = ci->ci_vp; | | 943 | cbp->cb_buf.b_vp = ci->ci_vp; |
944 | cbp->cb_buf.b_objlock = ci->ci_vp->v_interlock; | | 944 | cbp->cb_buf.b_objlock = ci->ci_vp->v_interlock; |
945 | if (cs->sc_ileave == 0) | | 945 | if (cs->sc_ileave == 0) |
946 | cbc = dbtob((u_int64_t)(ci->ci_size - cbn)); | | 946 | cbc = dbtob((u_int64_t)(ci->ci_size - cbn)); |
947 | else | | 947 | else |
948 | cbc = dbtob((u_int64_t)(cs->sc_ileave - cboff)); | | 948 | cbc = dbtob((u_int64_t)(cs->sc_ileave - cboff)); |
949 | cbp->cb_buf.b_bcount = cbc < bcount ? cbc : bcount; | | 949 | cbp->cb_buf.b_bcount = cbc < bcount ? cbc : bcount; |
950 | | | 950 | |
951 | /* | | 951 | /* |
952 | * context for ccdiodone | | 952 | * context for ccdiodone |
953 | */ | | 953 | */ |
954 | cbp->cb_obp = bp; | | 954 | cbp->cb_obp = bp; |
955 | cbp->cb_sc = cs; | | 955 | cbp->cb_sc = cs; |
956 | cbp->cb_comp = ccdisk; | | 956 | cbp->cb_comp = ccdisk; |
957 | | | 957 | |
958 | BIO_COPYPRIO(&cbp->cb_buf, bp); | | 958 | BIO_COPYPRIO(&cbp->cb_buf, bp); |
959 | | | 959 | |
960 | #ifdef DEBUG | | 960 | #ifdef DEBUG |
961 | if (ccddebug & CCDB_IO) | | 961 | if (ccddebug & CCDB_IO) |
962 | printf(" dev 0x%"PRIx64"(u%lu): cbp %p bn %" PRId64 " addr %p" | | 962 | printf(" dev 0x%"PRIx64"(u%lu): cbp %p bn %" PRId64 " addr %p" |
963 | " bcnt %d\n", | | 963 | " bcnt %d\n", |
964 | ci->ci_dev, (unsigned long) (ci-cs->sc_cinfo), cbp, | | 964 | ci->ci_dev, (unsigned long) (ci-cs->sc_cinfo), cbp, |
965 | cbp->cb_buf.b_blkno, cbp->cb_buf.b_data, | | 965 | cbp->cb_buf.b_blkno, cbp->cb_buf.b_data, |
966 | cbp->cb_buf.b_bcount); | | 966 | cbp->cb_buf.b_bcount); |
967 | #endif | | 967 | #endif |
968 | | | 968 | |
969 | return (cbp); | | 969 | return (cbp); |
970 | } | | 970 | } |
971 | | | 971 | |
972 | /* | | 972 | /* |
973 | * Called at interrupt time. | | 973 | * Called at interrupt time. |
974 | * Mark the component as done and if all components are done, | | 974 | * Mark the component as done and if all components are done, |
975 | * take a ccd interrupt. | | 975 | * take a ccd interrupt. |
976 | */ | | 976 | */ |
977 | static void | | 977 | static void |
978 | ccdiodone(struct buf *vbp) | | 978 | ccdiodone(struct buf *vbp) |
979 | { | | 979 | { |
980 | struct ccdbuf *cbp = (struct ccdbuf *) vbp; | | 980 | struct ccdbuf *cbp = (struct ccdbuf *) vbp; |
981 | struct buf *bp = cbp->cb_obp; | | 981 | struct buf *bp = cbp->cb_obp; |
982 | struct ccd_softc *cs = cbp->cb_sc; | | 982 | struct ccd_softc *cs = cbp->cb_sc; |
983 | int count; | | 983 | int count; |
984 | | | 984 | |
985 | #ifdef DEBUG | | 985 | #ifdef DEBUG |
986 | if (ccddebug & CCDB_FOLLOW) | | 986 | if (ccddebug & CCDB_FOLLOW) |
987 | printf("ccdiodone(%p)\n", cbp); | | 987 | printf("ccdiodone(%p)\n", cbp); |
988 | if (ccddebug & CCDB_IO) { | | 988 | if (ccddebug & CCDB_IO) { |
989 | printf("ccdiodone: bp %p bcount %d resid %d\n", | | 989 | printf("ccdiodone: bp %p bcount %d resid %d\n", |
990 | bp, bp->b_bcount, bp->b_resid); | | 990 | bp, bp->b_bcount, bp->b_resid); |
991 | printf(" dev 0x%"PRIx64"(u%d), cbp %p bn %" PRId64 " addr %p" | | 991 | printf(" dev 0x%"PRIx64"(u%d), cbp %p bn %" PRId64 " addr %p" |
992 | " bcnt %d\n", | | 992 | " bcnt %d\n", |
993 | cbp->cb_buf.b_dev, cbp->cb_comp, cbp, | | 993 | cbp->cb_buf.b_dev, cbp->cb_comp, cbp, |
994 | cbp->cb_buf.b_blkno, cbp->cb_buf.b_data, | | 994 | cbp->cb_buf.b_blkno, cbp->cb_buf.b_data, |
995 | cbp->cb_buf.b_bcount); | | 995 | cbp->cb_buf.b_bcount); |
996 | } | | 996 | } |
997 | #endif | | 997 | #endif |
998 | | | 998 | |
999 | if (cbp->cb_buf.b_error != 0) { | | 999 | if (cbp->cb_buf.b_error != 0) { |
1000 | bp->b_error = cbp->cb_buf.b_error; | | 1000 | bp->b_error = cbp->cb_buf.b_error; |
1001 | printf("%s: error %d on component %d\n", | | 1001 | printf("%s: error %d on component %d\n", |
1002 | cs->sc_xname, bp->b_error, cbp->cb_comp); | | 1002 | cs->sc_xname, bp->b_error, cbp->cb_comp); |
1003 | } | | 1003 | } |
1004 | count = cbp->cb_buf.b_bcount; | | 1004 | count = cbp->cb_buf.b_bcount; |
1005 | buf_destroy(&cbp->cb_buf); | | 1005 | buf_destroy(&cbp->cb_buf); |
1006 | CCD_PUTBUF(cbp); | | 1006 | CCD_PUTBUF(cbp); |
1007 | | | 1007 | |
1008 | /* | | 1008 | /* |
1009 | * If all done, "interrupt". | | 1009 | * If all done, "interrupt". |
1010 | */ | | 1010 | */ |
1011 | mutex_enter(cs->sc_iolock); | | 1011 | mutex_enter(cs->sc_iolock); |
1012 | bp->b_resid -= count; | | 1012 | bp->b_resid -= count; |
1013 | if (bp->b_resid < 0) | | 1013 | if (bp->b_resid < 0) |
1014 | panic("ccdiodone: count"); | | 1014 | panic("ccdiodone: count"); |
1015 | if (bp->b_resid == 0) { | | 1015 | if (bp->b_resid == 0) { |
1016 | /* | | 1016 | /* |
1017 | * Request is done for better or worse, wakeup the top half. | | 1017 | * Request is done for better or worse, wakeup the top half. |
1018 | */ | | 1018 | */ |
1019 | if (bp->b_error != 0) | | 1019 | if (bp->b_error != 0) |
1020 | bp->b_resid = bp->b_bcount; | | 1020 | bp->b_resid = bp->b_bcount; |
1021 | disk_unbusy(&cs->sc_dkdev, (bp->b_bcount - bp->b_resid), | | 1021 | disk_unbusy(&cs->sc_dkdev, (bp->b_bcount - bp->b_resid), |
1022 | (bp->b_flags & B_READ)); | | 1022 | (bp->b_flags & B_READ)); |
1023 | if (!disk_isbusy(&cs->sc_dkdev)) { | | 1023 | if (!disk_isbusy(&cs->sc_dkdev)) { |
1024 | if (bufq_peek(cs->sc_bufq) != NULL) { | | 1024 | if (bufq_peek(cs->sc_bufq) != NULL) { |
1025 | cv_broadcast(&cs->sc_push); | | 1025 | cv_broadcast(&cs->sc_push); |
1026 | } | | 1026 | } |
1027 | cv_broadcast(&cs->sc_stop); | | 1027 | cv_broadcast(&cs->sc_stop); |
1028 | } | | 1028 | } |
1029 | mutex_exit(cs->sc_iolock); | | 1029 | mutex_exit(cs->sc_iolock); |
1030 | biodone(bp); | | 1030 | biodone(bp); |
1031 | } else | | 1031 | } else |
1032 | mutex_exit(cs->sc_iolock); | | 1032 | mutex_exit(cs->sc_iolock); |
1033 | } | | 1033 | } |
1034 | | | 1034 | |
1035 | /* ARGSUSED */ | | 1035 | /* ARGSUSED */ |
1036 | static int | | 1036 | static int |
1037 | ccdread(dev_t dev, struct uio *uio, int flags) | | 1037 | ccdread(dev_t dev, struct uio *uio, int flags) |
1038 | { | | 1038 | { |
1039 | int unit = ccdunit(dev); | | 1039 | int unit = ccdunit(dev); |
1040 | struct ccd_softc *cs; | | 1040 | struct ccd_softc *cs; |
1041 | | | 1041 | |
1042 | #ifdef DEBUG | | 1042 | #ifdef DEBUG |
1043 | if (ccddebug & CCDB_FOLLOW) | | 1043 | if (ccddebug & CCDB_FOLLOW) |
1044 | printf("ccdread(0x%"PRIx64", %p)\n", dev, uio); | | 1044 | printf("ccdread(0x%"PRIx64", %p)\n", dev, uio); |
1045 | #endif | | 1045 | #endif |
1046 | if ((cs = ccdget(unit, 0)) == NULL) | | 1046 | if ((cs = ccdget(unit, 0)) == NULL) |
1047 | return 0; | | 1047 | return 0; |
1048 | | | 1048 | |
1049 | /* Unlocked advisory check, ccdstrategy check is synchronous. */ | | 1049 | /* Unlocked advisory check, ccdstrategy check is synchronous. */ |
1050 | if ((cs->sc_flags & CCDF_INITED) == 0) | | 1050 | if ((cs->sc_flags & CCDF_INITED) == 0) |
1051 | return (ENXIO); | | 1051 | return (ENXIO); |
1052 | | | 1052 | |
1053 | return (physio(ccdstrategy, NULL, dev, B_READ, minphys, uio)); | | 1053 | return (physio(ccdstrategy, NULL, dev, B_READ, minphys, uio)); |
1054 | } | | 1054 | } |
1055 | | | 1055 | |
1056 | /* ARGSUSED */ | | 1056 | /* ARGSUSED */ |
1057 | static int | | 1057 | static int |
1058 | ccdwrite(dev_t dev, struct uio *uio, int flags) | | 1058 | ccdwrite(dev_t dev, struct uio *uio, int flags) |
1059 | { | | 1059 | { |
1060 | int unit = ccdunit(dev); | | 1060 | int unit = ccdunit(dev); |
1061 | struct ccd_softc *cs; | | 1061 | struct ccd_softc *cs; |
1062 | | | 1062 | |
1063 | #ifdef DEBUG | | 1063 | #ifdef DEBUG |
1064 | if (ccddebug & CCDB_FOLLOW) | | 1064 | if (ccddebug & CCDB_FOLLOW) |
1065 | printf("ccdwrite(0x%"PRIx64", %p)\n", dev, uio); | | 1065 | printf("ccdwrite(0x%"PRIx64", %p)\n", dev, uio); |
1066 | #endif | | 1066 | #endif |
1067 | if ((cs = ccdget(unit, 0)) == NULL) | | 1067 | if ((cs = ccdget(unit, 0)) == NULL) |
1068 | return ENOENT; | | 1068 | return ENOENT; |
1069 | | | 1069 | |
1070 | /* Unlocked advisory check, ccdstrategy check is synchronous. */ | | 1070 | /* Unlocked advisory check, ccdstrategy check is synchronous. */ |
1071 | if ((cs->sc_flags & CCDF_INITED) == 0) | | 1071 | if ((cs->sc_flags & CCDF_INITED) == 0) |
1072 | return (ENXIO); | | 1072 | return (ENXIO); |
1073 | | | 1073 | |
1074 | return (physio(ccdstrategy, NULL, dev, B_WRITE, minphys, uio)); | | 1074 | return (physio(ccdstrategy, NULL, dev, B_WRITE, minphys, uio)); |
1075 | } | | 1075 | } |
1076 | | | 1076 | |
1077 | int (*compat_ccd_ioctl_60)(dev_t, u_long, void *, int, struct lwp *, | | 1077 | int (*compat_ccd_ioctl_60)(dev_t, u_long, void *, int, struct lwp *, |
1078 | int (*)(dev_t, u_long, void *, int, struct lwp *)) = (void *)enosys; | | 1078 | int (*)(dev_t, u_long, void *, int, struct lwp *)) = (void *)enosys; |
1079 | | | 1079 | |
1080 | static int | | 1080 | static int |
1081 | ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) | | 1081 | ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) |
1082 | { | | 1082 | { |
1083 | int unit = ccdunit(dev); | | 1083 | int unit = ccdunit(dev); |
1084 | int i, j, lookedup = 0, error = 0; | | 1084 | int i, j, lookedup = 0, error = 0; |
1085 | int part, pmask, make, hook; | | 1085 | int part, pmask, make, hook; |
1086 | struct ccd_softc *cs; | | 1086 | struct ccd_softc *cs; |
1087 | struct ccd_ioctl *ccio = (struct ccd_ioctl *)data; | | 1087 | struct ccd_ioctl *ccio = (struct ccd_ioctl *)data; |
1088 | kauth_cred_t uc; | | 1088 | kauth_cred_t uc; |
1089 | char **cpp; | | 1089 | char **cpp; |
1090 | struct pathbuf *pb; | | 1090 | struct pathbuf *pb; |
1091 | struct vnode **vpp; | | 1091 | struct vnode **vpp; |
1092 | #ifdef __HAVE_OLD_DISKLABEL | | 1092 | #ifdef __HAVE_OLD_DISKLABEL |
1093 | struct disklabel newlabel; | | 1093 | struct disklabel newlabel; |
1094 | #endif | | 1094 | #endif |
1095 | | | 1095 | |
1096 | switch (cmd) { | | 1096 | switch (cmd) { |
1097 | case CCDIOCSET: | | 1097 | case CCDIOCSET: |
1098 | make = 1; | | 1098 | make = 1; |
1099 | break; | | 1099 | break; |
1100 | default: | | 1100 | default: |
1101 | MODULE_HOOK_CALL(ccd_ioctl_60_hook, | | 1101 | MODULE_HOOK_CALL(ccd_ioctl_60_hook, |
1102 | (0, cmd, NULL, 0, NULL, NULL), | | 1102 | (0, cmd, NULL, 0, NULL, NULL), |
1103 | enosys(), hook); | | 1103 | enosys(), hook); |
1104 | if (hook == 0) | | 1104 | if (hook == 0) |
1105 | make = 1; | | 1105 | make = 1; |
1106 | else | | 1106 | else |
1107 | make = 0; | | 1107 | make = 0; |
1108 | break; | | 1108 | break; |
1109 | } | | 1109 | } |
1110 | | | 1110 | |
1111 | if ((cs = ccdget(unit, make)) == NULL) | | 1111 | if ((cs = ccdget(unit, make)) == NULL) |
1112 | return ENOENT; | | 1112 | return ENOENT; |
1113 | uc = kauth_cred_get(); | | 1113 | uc = kauth_cred_get(); |
1114 | | | 1114 | |
1115 | MODULE_HOOK_CALL(ccd_ioctl_60_hook, | | 1115 | MODULE_HOOK_CALL(ccd_ioctl_60_hook, |
1116 | (dev, cmd, data, flag, l, ccdioctl), | | 1116 | (dev, cmd, data, flag, l, ccdioctl), |
1117 | enosys(), error); | | 1117 | enosys(), error); |
1118 | if (error != ENOSYS) | | 1118 | if (error != ENOSYS) |
1119 | return error; | | 1119 | return error; |
1120 | | | 1120 | |
1121 | /* Must be open for writes for these commands... */ | | 1121 | /* Must be open for writes for these commands... */ |
1122 | switch (cmd) { | | 1122 | switch (cmd) { |
1123 | case CCDIOCSET: | | 1123 | case CCDIOCSET: |
1124 | case CCDIOCCLR: | | 1124 | case CCDIOCCLR: |
1125 | case DIOCSDINFO: | | 1125 | case DIOCSDINFO: |
1126 | case DIOCWDINFO: | | 1126 | case DIOCWDINFO: |
1127 | case DIOCCACHESYNC: | | 1127 | case DIOCCACHESYNC: |
1128 | case DIOCAWEDGE: | | 1128 | case DIOCAWEDGE: |
1129 | case DIOCDWEDGE: | | 1129 | case DIOCDWEDGE: |
1130 | case DIOCRMWEDGES: | | 1130 | case DIOCRMWEDGES: |
1131 | case DIOCMWEDGES: | | 1131 | case DIOCMWEDGES: |
1132 | #ifdef __HAVE_OLD_DISKLABEL | | 1132 | #ifdef __HAVE_OLD_DISKLABEL |
1133 | case ODIOCSDINFO: | | 1133 | case ODIOCSDINFO: |
1134 | case ODIOCWDINFO: | | 1134 | case ODIOCWDINFO: |
1135 | #endif | | 1135 | #endif |
1136 | case DIOCKLABEL: | | 1136 | case DIOCKLABEL: |
1137 | case DIOCWLABEL: | | 1137 | case DIOCWLABEL: |
1138 | if ((flag & FWRITE) == 0) | | 1138 | if ((flag & FWRITE) == 0) |
1139 | return (EBADF); | | 1139 | return (EBADF); |
1140 | } | | 1140 | } |
1141 | | | 1141 | |
1142 | /* Must be initialized for these... */ | | 1142 | /* Must be initialized for these... */ |
1143 | switch (cmd) { | | 1143 | switch (cmd) { |
1144 | case CCDIOCCLR: | | 1144 | case CCDIOCCLR: |
1145 | case DIOCGDINFO: | | 1145 | case DIOCGDINFO: |
1146 | case DIOCGSTRATEGY: | | 1146 | case DIOCGSTRATEGY: |
1147 | case DIOCGCACHE: | | 1147 | case DIOCGCACHE: |
1148 | case DIOCCACHESYNC: | | 1148 | case DIOCCACHESYNC: |
1149 | case DIOCAWEDGE: | | 1149 | case DIOCAWEDGE: |
1150 | case DIOCDWEDGE: | | 1150 | case DIOCDWEDGE: |
1151 | case DIOCLWEDGES: | | 1151 | case DIOCLWEDGES: |
1152 | case DIOCMWEDGES: | | 1152 | case DIOCMWEDGES: |
1153 | case DIOCSDINFO: | | 1153 | case DIOCSDINFO: |
1154 | case DIOCWDINFO: | | 1154 | case DIOCWDINFO: |
1155 | case DIOCGPARTINFO: | | 1155 | case DIOCGPARTINFO: |
1156 | case DIOCWLABEL: | | 1156 | case DIOCWLABEL: |
1157 | case DIOCKLABEL: | | 1157 | case DIOCKLABEL: |
1158 | case DIOCGDEFLABEL: | | 1158 | case DIOCGDEFLABEL: |
1159 | #ifdef __HAVE_OLD_DISKLABEL | | 1159 | #ifdef __HAVE_OLD_DISKLABEL |
1160 | case ODIOCGDINFO: | | 1160 | case ODIOCGDINFO: |
1161 | case ODIOCSDINFO: | | 1161 | case ODIOCSDINFO: |
1162 | case ODIOCWDINFO: | | 1162 | case ODIOCWDINFO: |
1163 | case ODIOCGDEFLABEL: | | 1163 | case ODIOCGDEFLABEL: |
1164 | #endif | | 1164 | #endif |
1165 | if ((cs->sc_flags & CCDF_INITED) == 0) | | 1165 | if ((cs->sc_flags & CCDF_INITED) == 0) |
1166 | return ENXIO; | | 1166 | return ENXIO; |
1167 | } | | 1167 | } |
1168 | | | 1168 | |
1169 | error = disk_ioctl(&cs->sc_dkdev, dev, cmd, data, flag, l); | | 1169 | error = disk_ioctl(&cs->sc_dkdev, dev, cmd, data, flag, l); |
1170 | if (error != EPASSTHROUGH) | | 1170 | if (error != EPASSTHROUGH) |
1171 | return error; | | 1171 | return error; |
1172 | | | 1172 | |
1173 | switch (cmd) { | | 1173 | switch (cmd) { |
1174 | case DIOCGSTRATEGY: | | 1174 | case DIOCGSTRATEGY: |
1175 | { | | 1175 | { |
1176 | struct disk_strategy *dks = (void *)data; | | 1176 | struct disk_strategy *dks = (void *)data; |
1177 | | | 1177 | |
1178 | mutex_enter(cs->sc_iolock); | | 1178 | mutex_enter(cs->sc_iolock); |
1179 | if (cs->sc_bufq != NULL) | | 1179 | if (cs->sc_bufq != NULL) |
1180 | strlcpy(dks->dks_name, | | 1180 | strlcpy(dks->dks_name, |
1181 | bufq_getstrategyname(cs->sc_bufq), | | 1181 | bufq_getstrategyname(cs->sc_bufq), |
1182 | sizeof(dks->dks_name)); | | 1182 | sizeof(dks->dks_name)); |
1183 | else | | 1183 | else |
1184 | error = EINVAL; | | 1184 | error = EINVAL; |
1185 | mutex_exit(cs->sc_iolock); | | 1185 | mutex_exit(cs->sc_iolock); |
1186 | dks->dks_paramlen = 0; | | 1186 | dks->dks_paramlen = 0; |
1187 | break; | | 1187 | break; |
1188 | } | | 1188 | } |
1189 | | | 1189 | |
1190 | case DIOCWDINFO: | | 1190 | case DIOCWDINFO: |
1191 | case DIOCSDINFO: | | 1191 | case DIOCSDINFO: |
1192 | #ifdef __HAVE_OLD_DISKLABEL | | 1192 | #ifdef __HAVE_OLD_DISKLABEL |
1193 | case ODIOCWDINFO: | | 1193 | case ODIOCWDINFO: |
1194 | case ODIOCSDINFO: | | 1194 | case ODIOCSDINFO: |
1195 | #endif | | 1195 | #endif |
1196 | { | | 1196 | { |
1197 | struct disklabel *lp; | | 1197 | struct disklabel *lp; |
1198 | #ifdef __HAVE_OLD_DISKLABEL | | 1198 | #ifdef __HAVE_OLD_DISKLABEL |
1199 | if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) { | | 1199 | if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) { |
1200 | memset(&newlabel, 0, sizeof newlabel); | | 1200 | memset(&newlabel, 0, sizeof newlabel); |
1201 | memcpy(&newlabel, data, sizeof (struct olddisklabel)); | | 1201 | memcpy(&newlabel, data, sizeof (struct olddisklabel)); |
1202 | lp = &newlabel; | | 1202 | lp = &newlabel; |
1203 | } else | | 1203 | } else |
1204 | #endif | | 1204 | #endif |
1205 | lp = (struct disklabel *)data; | | 1205 | lp = (struct disklabel *)data; |
1206 | | | 1206 | |
1207 | cs->sc_flags |= CCDF_LABELLING; | | 1207 | cs->sc_flags |= CCDF_LABELLING; |
1208 | | | 1208 | |
1209 | error = setdisklabel(cs->sc_dkdev.dk_label, | | 1209 | error = setdisklabel(cs->sc_dkdev.dk_label, |
1210 | lp, 0, cs->sc_dkdev.dk_cpulabel); | | 1210 | lp, 0, cs->sc_dkdev.dk_cpulabel); |
1211 | if (error == 0) { | | 1211 | if (error == 0) { |
1212 | if (cmd == DIOCWDINFO | | 1212 | if (cmd == DIOCWDINFO |
1213 | #ifdef __HAVE_OLD_DISKLABEL | | 1213 | #ifdef __HAVE_OLD_DISKLABEL |
1214 | || cmd == ODIOCWDINFO | | 1214 | || cmd == ODIOCWDINFO |
1215 | #endif | | 1215 | #endif |
1216 | ) | | 1216 | ) |
1217 | error = writedisklabel(CCDLABELDEV(dev), | | 1217 | error = writedisklabel(CCDLABELDEV(dev), |
1218 | ccdstrategy, cs->sc_dkdev.dk_label, | | 1218 | ccdstrategy, cs->sc_dkdev.dk_label, |
1219 | cs->sc_dkdev.dk_cpulabel); | | 1219 | cs->sc_dkdev.dk_cpulabel); |
1220 | } | | 1220 | } |
1221 | | | 1221 | |
1222 | cs->sc_flags &= ~CCDF_LABELLING; | | 1222 | cs->sc_flags &= ~CCDF_LABELLING; |
1223 | break; | | 1223 | break; |
1224 | } | | 1224 | } |
1225 | | | 1225 | |
1226 | case DIOCKLABEL: | | 1226 | case DIOCKLABEL: |
1227 | if (*(int *)data != 0) | | 1227 | if (*(int *)data != 0) |
1228 | cs->sc_flags |= CCDF_KLABEL; | | 1228 | cs->sc_flags |= CCDF_KLABEL; |
1229 | else | | 1229 | else |
1230 | cs->sc_flags &= ~CCDF_KLABEL; | | 1230 | cs->sc_flags &= ~CCDF_KLABEL; |
1231 | break; | | 1231 | break; |
1232 | | | 1232 | |
1233 | case DIOCWLABEL: | | 1233 | case DIOCWLABEL: |
1234 | if (*(int *)data != 0) | | 1234 | if (*(int *)data != 0) |
1235 | cs->sc_flags |= CCDF_WLABEL; | | 1235 | cs->sc_flags |= CCDF_WLABEL; |
1236 | else | | 1236 | else |
1237 | cs->sc_flags &= ~CCDF_WLABEL; | | 1237 | cs->sc_flags &= ~CCDF_WLABEL; |
1238 | break; | | 1238 | break; |
1239 | | | 1239 | |
1240 | case DIOCGDEFLABEL: | | 1240 | case DIOCGDEFLABEL: |
1241 | ccdgetdefaultlabel(cs, (struct disklabel *)data); | | 1241 | ccdgetdefaultlabel(cs, (struct disklabel *)data); |
1242 | break; | | 1242 | break; |
1243 | | | 1243 | |
1244 | #ifdef __HAVE_OLD_DISKLABEL | | 1244 | #ifdef __HAVE_OLD_DISKLABEL |
1245 | case ODIOCGDEFLABEL: | | 1245 | case ODIOCGDEFLABEL: |
1246 | ccdgetdefaultlabel(cs, &newlabel); | | 1246 | ccdgetdefaultlabel(cs, &newlabel); |
1247 | if (newlabel.d_npartitions > OLDMAXPARTITIONS) | | 1247 | if (newlabel.d_npartitions > OLDMAXPARTITIONS) |
1248 | return ENOTTY; | | 1248 | return ENOTTY; |
1249 | memcpy(data, &newlabel, sizeof (struct olddisklabel)); | | 1249 | memcpy(data, &newlabel, sizeof (struct olddisklabel)); |
1250 | break; | | 1250 | break; |
1251 | #endif | | 1251 | #endif |
1252 | default: | | 1252 | default: |
1253 | error = ENOTTY; | | 1253 | error = ENOTTY; |
1254 | break; | | 1254 | break; |
1255 | } | | 1255 | } |
1256 | | | 1256 | |
1257 | if (error != ENOTTY) | | 1257 | if (error != ENOTTY) |
1258 | return error; | | 1258 | return error; |
1259 | | | 1259 | |
1260 | mutex_enter(&cs->sc_dvlock); | | 1260 | mutex_enter(&cs->sc_dvlock); |
1261 | | | 1261 | |
1262 | error = 0; | | 1262 | error = 0; |
1263 | switch (cmd) { | | 1263 | switch (cmd) { |
1264 | case CCDIOCSET: | | 1264 | case CCDIOCSET: |
1265 | if (cs->sc_flags & CCDF_INITED) { | | 1265 | if (cs->sc_flags & CCDF_INITED) { |
1266 | error = EBUSY; | | 1266 | error = EBUSY; |
1267 | goto out; | | 1267 | goto out; |
1268 | } | | 1268 | } |
1269 | | | 1269 | |
1270 | /* Validate the flags. */ | | 1270 | /* Validate the flags. */ |
1271 | if ((ccio->ccio_flags & CCDF_USERMASK) != ccio->ccio_flags) { | | 1271 | if ((ccio->ccio_flags & CCDF_USERMASK) != ccio->ccio_flags) { |
1272 | error = EINVAL; | | 1272 | error = EINVAL; |
1273 | goto out; | | 1273 | goto out; |
1274 | } | | 1274 | } |
1275 | | | 1275 | |
1276 | if (ccio->ccio_ndisks > CCD_MAXNDISKS || | | 1276 | if (ccio->ccio_ndisks > CCD_MAXNDISKS || |
1277 | ccio->ccio_ndisks == 0) { | | 1277 | ccio->ccio_ndisks == 0) { |
1278 | error = EINVAL; | | 1278 | error = EINVAL; |
1279 | goto out; | | 1279 | goto out; |
1280 | } | | 1280 | } |
1281 | | | 1281 | |
1282 | /* Fill in some important bits. */ | | 1282 | /* Fill in some important bits. */ |
1283 | cs->sc_ileave = ccio->ccio_ileave; | | 1283 | cs->sc_ileave = ccio->ccio_ileave; |
1284 | cs->sc_nccdisks = ccio->ccio_ndisks; | | 1284 | cs->sc_nccdisks = ccio->ccio_ndisks; |
1285 | cs->sc_flags = ccio->ccio_flags & CCDF_USERMASK; | | 1285 | cs->sc_flags = ccio->ccio_flags & CCDF_USERMASK; |
1286 | | | 1286 | |
1287 | /* | | 1287 | /* |
1288 | * Allocate space for and copy in the array of | | 1288 | * Allocate space for and copy in the array of |
1289 | * component pathnames and device numbers. | | 1289 | * component pathnames and device numbers. |
1290 | */ | | 1290 | */ |
1291 | cpp = kmem_alloc(ccio->ccio_ndisks * sizeof(*cpp), KM_SLEEP); | | 1291 | cpp = kmem_alloc(ccio->ccio_ndisks * sizeof(*cpp), KM_SLEEP); |
1292 | vpp = kmem_alloc(ccio->ccio_ndisks * sizeof(*vpp), KM_SLEEP); | | 1292 | vpp = kmem_alloc(ccio->ccio_ndisks * sizeof(*vpp), KM_SLEEP); |
1293 | error = copyin(ccio->ccio_disks, cpp, | | 1293 | error = copyin(ccio->ccio_disks, cpp, |
1294 | ccio->ccio_ndisks * sizeof(*cpp)); | | 1294 | ccio->ccio_ndisks * sizeof(*cpp)); |
1295 | if (error) { | | 1295 | if (error) { |
1296 | kmem_free(vpp, ccio->ccio_ndisks * sizeof(*vpp)); | | 1296 | kmem_free(vpp, ccio->ccio_ndisks * sizeof(*vpp)); |
1297 | kmem_free(cpp, ccio->ccio_ndisks * sizeof(*cpp)); | | 1297 | kmem_free(cpp, ccio->ccio_ndisks * sizeof(*cpp)); |
1298 | goto out; | | 1298 | goto out; |
1299 | } | | 1299 | } |
1300 | | | 1300 | |
1301 | #ifdef DEBUG | | 1301 | #ifdef DEBUG |
1302 | if (ccddebug & CCDB_INIT) | | 1302 | if (ccddebug & CCDB_INIT) |
1303 | for (i = 0; i < ccio->ccio_ndisks; ++i) | | 1303 | for (i = 0; i < ccio->ccio_ndisks; ++i) |
1304 | printf("ccdioctl: component %d: %p\n", | | 1304 | printf("ccdioctl: component %d: %p\n", |
1305 | i, cpp[i]); | | 1305 | i, cpp[i]); |
1306 | #endif | | 1306 | #endif |
1307 | | | 1307 | |
1308 | for (i = 0; i < ccio->ccio_ndisks; ++i) { | | 1308 | for (i = 0; i < ccio->ccio_ndisks; ++i) { |
1309 | #ifdef DEBUG | | 1309 | #ifdef DEBUG |
1310 | if (ccddebug & CCDB_INIT) | | 1310 | if (ccddebug & CCDB_INIT) |
1311 | printf("ccdioctl: lookedup = %d\n", lookedup); | | 1311 | printf("ccdioctl: lookedup = %d\n", lookedup); |
1312 | #endif | | 1312 | #endif |
1313 | error = pathbuf_copyin(cpp[i], &pb); | | 1313 | error = pathbuf_copyin(cpp[i], &pb); |
1314 | if (error == 0) { | | 1314 | if (error == 0) { |
1315 | error = vn_bdev_openpath(pb, &vpp[i], l); | | 1315 | error = vn_bdev_openpath(pb, &vpp[i], l); |
1316 | } | | 1316 | } |
1317 | pathbuf_destroy(pb); | | 1317 | pathbuf_destroy(pb); |
1318 | if (error != 0) { | | 1318 | if (error != 0) { |
1319 | for (j = 0; j < lookedup; ++j) | | 1319 | for (j = 0; j < lookedup; ++j) |
1320 | (void)vn_close(vpp[j], FREAD|FWRITE, | | 1320 | (void)vn_close(vpp[j], FREAD|FWRITE, |
1321 | uc); | | 1321 | uc); |
1322 | kmem_free(vpp, ccio->ccio_ndisks * | | 1322 | kmem_free(vpp, ccio->ccio_ndisks * |
1323 | sizeof(*vpp)); | | 1323 | sizeof(*vpp)); |
1324 | kmem_free(cpp, ccio->ccio_ndisks * | | 1324 | kmem_free(cpp, ccio->ccio_ndisks * |
1325 | sizeof(*cpp)); | | 1325 | sizeof(*cpp)); |
1326 | | | 1326 | |
1327 | /* | | 1327 | /* |
1328 | * No component data is allocated, | | 1328 | * No component data is allocated, |
1329 | * nothing is to be freed. | | 1329 | * nothing is to be freed. |
1330 | */ | | 1330 | */ |
1331 | cs->sc_nccdisks = 0; | | 1331 | cs->sc_nccdisks = 0; |
1332 | goto out; | | 1332 | goto out; |
1333 | } | | 1333 | } |
1334 | ++lookedup; | | 1334 | ++lookedup; |
1335 | } | | 1335 | } |
1336 | | | 1336 | |
1337 | /* Attach the disk. */ | | 1337 | /* Attach the disk. */ |
1338 | disk_attach(&cs->sc_dkdev); | | 1338 | disk_attach(&cs->sc_dkdev); |
1339 | bufq_alloc(&cs->sc_bufq, "fcfs", 0); | | 1339 | bufq_alloc(&cs->sc_bufq, "fcfs", 0); |
1340 | | | 1340 | |
1341 | /* | | 1341 | /* |
1342 | * Initialize the ccd. Fills in the softc for us. | | 1342 | * Initialize the ccd. Fills in the softc for us. |
1343 | */ | | 1343 | */ |
1344 | if ((error = ccdinit(cs, cpp, vpp, l)) != 0) { | | 1344 | if ((error = ccdinit(cs, cpp, vpp, l)) != 0) { |
1345 | for (j = 0; j < lookedup; ++j) | | 1345 | for (j = 0; j < lookedup; ++j) |
1346 | (void)vn_close(vpp[j], FREAD|FWRITE, | | 1346 | (void)vn_close(vpp[j], FREAD|FWRITE, |
1347 | uc); | | 1347 | uc); |
1348 | kmem_free(vpp, ccio->ccio_ndisks * sizeof(*vpp)); | | 1348 | kmem_free(vpp, ccio->ccio_ndisks * sizeof(*vpp)); |
1349 | kmem_free(cpp, ccio->ccio_ndisks * sizeof(*cpp)); | | 1349 | kmem_free(cpp, ccio->ccio_ndisks * sizeof(*cpp)); |
1350 | disk_detach(&cs->sc_dkdev); | | 1350 | disk_detach(&cs->sc_dkdev); |
1351 | mutex_exit(&cs->sc_dvlock); | | 1351 | mutex_exit(&cs->sc_dvlock); |
1352 | bufq_free(cs->sc_bufq); | | 1352 | bufq_free(cs->sc_bufq); |
1353 | return error; | | 1353 | return error; |
1354 | } | | 1354 | } |
1355 | | | 1355 | |
1356 | /* We can free the temporary variables now. */ | | 1356 | /* We can free the temporary variables now. */ |
1357 | kmem_free(vpp, ccio->ccio_ndisks * sizeof(*vpp)); | | 1357 | kmem_free(vpp, ccio->ccio_ndisks * sizeof(*vpp)); |
1358 | kmem_free(cpp, ccio->ccio_ndisks * sizeof(*cpp)); | | 1358 | kmem_free(cpp, ccio->ccio_ndisks * sizeof(*cpp)); |
1359 | | | 1359 | |
1360 | /* | | 1360 | /* |
1361 | * The ccd has been successfully initialized, so | | 1361 | * The ccd has been successfully initialized, so |
1362 | * we can place it into the array. Don't try to | | 1362 | * we can place it into the array. Don't try to |
1363 | * read the disklabel until the disk has been attached, | | 1363 | * read the disklabel until the disk has been attached, |
1364 | * because space for the disklabel is allocated | | 1364 | * because space for the disklabel is allocated |
1365 | * in disk_attach(); | | 1365 | * in disk_attach(); |
1366 | */ | | 1366 | */ |
1367 | ccio->ccio_unit = unit; | | 1367 | ccio->ccio_unit = unit; |
1368 | ccio->ccio_size = cs->sc_size; | | 1368 | ccio->ccio_size = cs->sc_size; |
1369 | | | 1369 | |
1370 | /* Try and read the disklabel. */ | | 1370 | /* Try and read the disklabel. */ |
1371 | ccdgetdisklabel(dev); | | 1371 | ccdgetdisklabel(dev); |
1372 | disk_set_info(NULL, &cs->sc_dkdev, NULL); | | 1372 | disk_set_info(NULL, &cs->sc_dkdev, NULL); |
1373 | | | 1373 | |
1374 | /* discover wedges */ | | 1374 | /* discover wedges */ |
1375 | mutex_exit(&cs->sc_dvlock); | | 1375 | mutex_exit(&cs->sc_dvlock); |
1376 | dkwedge_discover(&cs->sc_dkdev); | | 1376 | dkwedge_discover(&cs->sc_dkdev); |
1377 | return 0; | | 1377 | return 0; |
1378 | | | 1378 | |
1379 | case CCDIOCCLR: | | 1379 | case CCDIOCCLR: |
1380 | /* | | 1380 | /* |
1381 | * Don't unconfigure if any other partitions are open | | 1381 | * Don't unconfigure if any other partitions are open |
1382 | * or if both the character and block flavors of this | | 1382 | * or if both the character and block flavors of this |
1383 | * partition are open. | | 1383 | * partition are open. |
1384 | */ | | 1384 | */ |
1385 | part = DISKPART(dev); | | 1385 | part = DISKPART(dev); |
1386 | pmask = (1 << part); | | 1386 | pmask = (1 << part); |
1387 | if ((cs->sc_dkdev.dk_openmask & ~pmask) || | | 1387 | if ((cs->sc_dkdev.dk_openmask & ~pmask) || |
1388 | ((cs->sc_dkdev.dk_bopenmask & pmask) && | | 1388 | ((cs->sc_dkdev.dk_bopenmask & pmask) && |
1389 | (cs->sc_dkdev.dk_copenmask & pmask))) { | | 1389 | (cs->sc_dkdev.dk_copenmask & pmask))) { |
1390 | error = EBUSY; | | 1390 | error = EBUSY; |
1391 | goto out; | | 1391 | goto out; |
1392 | } | | 1392 | } |
1393 | | | 1393 | |
1394 | /* Delete all of our wedges. */ | | 1394 | /* Delete all of our wedges. */ |
1395 | dkwedge_delall(&cs->sc_dkdev); | | 1395 | dkwedge_delall(&cs->sc_dkdev); |
1396 | | | 1396 | |
1397 | /* Stop new I/O, wait for in-flight I/O to complete. */ | | 1397 | /* Stop new I/O, wait for in-flight I/O to complete. */ |
1398 | mutex_enter(cs->sc_iolock); | | 1398 | mutex_enter(cs->sc_iolock); |
1399 | cs->sc_flags &= ~(CCDF_INITED|CCDF_VLABEL); | | 1399 | cs->sc_flags &= ~(CCDF_INITED|CCDF_VLABEL); |
1400 | cs->sc_zap = true; | | 1400 | cs->sc_zap = true; |
1401 | while (disk_isbusy(&cs->sc_dkdev) || | | 1401 | while (disk_isbusy(&cs->sc_dkdev) || |
1402 | bufq_peek(cs->sc_bufq) != NULL || | | 1402 | bufq_peek(cs->sc_bufq) != NULL || |
1403 | cs->sc_thread != NULL) { | | 1403 | cs->sc_thread != NULL) { |
1404 | cv_broadcast(&cs->sc_push); | | 1404 | cv_broadcast(&cs->sc_push); |
1405 | (void)cv_timedwait(&cs->sc_stop, cs->sc_iolock, hz); | | 1405 | (void)cv_timedwait(&cs->sc_stop, cs->sc_iolock, hz); |
1406 | } | | 1406 | } |
1407 | mutex_exit(cs->sc_iolock); | | 1407 | mutex_exit(cs->sc_iolock); |
1408 | | | 1408 | |
1409 | /* | | 1409 | /* |
1410 | * Free ccd_softc information and clear entry. | | 1410 | * Free ccd_softc information and clear entry. |
1411 | */ | | 1411 | */ |
1412 | | | 1412 | |
1413 | /* Close the components and free their pathnames. */ | | 1413 | /* Close the components and free their pathnames. */ |
1414 | for (i = 0; i < cs->sc_nccdisks; ++i) { | | 1414 | for (i = 0; i < cs->sc_nccdisks; ++i) { |
1415 | /* | | 1415 | /* |
1416 | * XXX: this close could potentially fail and | | 1416 | * XXX: this close could potentially fail and |
1417 | * cause Bad Things. Maybe we need to force | | 1417 | * cause Bad Things. Maybe we need to force |
1418 | * the close to happen? | | 1418 | * the close to happen? |
1419 | */ | | 1419 | */ |
1420 | #ifdef DEBUG | | 1420 | #ifdef DEBUG |
1421 | if (ccddebug & CCDB_VNODE) | | 1421 | if (ccddebug & CCDB_VNODE) |
1422 | vprint("CCDIOCCLR: vnode info", | | 1422 | vprint("CCDIOCCLR: vnode info", |
1423 | cs->sc_cinfo[i].ci_vp); | | 1423 | cs->sc_cinfo[i].ci_vp); |
1424 | #endif | | 1424 | #endif |
1425 | (void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE, | | 1425 | (void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE, |
1426 | uc); | | 1426 | uc); |
1427 | kmem_free(cs->sc_cinfo[i].ci_path, | | 1427 | kmem_free(cs->sc_cinfo[i].ci_path, |
1428 | cs->sc_cinfo[i].ci_pathlen); | | 1428 | cs->sc_cinfo[i].ci_pathlen); |
1429 | } | | 1429 | } |
1430 | | | 1430 | |
1431 | if (cs->sc_nccdisks != 0) { | | 1431 | if (cs->sc_nccdisks != 0) { |
1432 | /* Free interleave index. */ | | 1432 | /* Free interleave index. */ |
1433 | for (i = 0; cs->sc_itable[i].ii_ndisk; ++i) { | | 1433 | for (i = 0; cs->sc_itable[i].ii_ndisk; ++i) { |
1434 | kmem_free(cs->sc_itable[i].ii_index, | | 1434 | kmem_free(cs->sc_itable[i].ii_index, |
1435 | cs->sc_itable[i].ii_indexsz); | | 1435 | cs->sc_itable[i].ii_indexsz); |
1436 | } | | 1436 | } |
1437 | /* Free component info and interleave table. */ | | 1437 | /* Free component info and interleave table. */ |
1438 | kmem_free(cs->sc_cinfo, cs->sc_nccdisks * | | 1438 | kmem_free(cs->sc_cinfo, cs->sc_nccdisks * |
1439 | sizeof(struct ccdcinfo)); | | 1439 | sizeof(struct ccdcinfo)); |
1440 | kmem_free(cs->sc_itable, (cs->sc_nccdisks + 1) * | | 1440 | kmem_free(cs->sc_itable, (cs->sc_nccdisks + 1) * |
1441 | sizeof(struct ccdiinfo)); | | 1441 | sizeof(struct ccdiinfo)); |
1442 | } | | 1442 | } |
1443 | | | 1443 | |
1444 | aprint_normal("%s: detached\n", cs->sc_xname); | | 1444 | aprint_normal("%s: detached\n", cs->sc_xname); |
1445 | | | 1445 | |
1446 | /* Detach the disk. */ | | 1446 | /* Detach the disk. */ |
1447 | disk_detach(&cs->sc_dkdev); | | 1447 | disk_detach(&cs->sc_dkdev); |
1448 | bufq_free(cs->sc_bufq); | | 1448 | bufq_free(cs->sc_bufq); |
1449 | | | 1449 | |
1450 | /* also releases dv_lock */ | | 1450 | /* also releases sc_dvlock */ |
1451 | ccdput(cs); | | 1451 | ccdput(cs); |
1452 | | | 1452 | |
1453 | /* Don't break, otherwise cs is read again. */ | | 1453 | /* Don't break, otherwise cs is read again. */ |
1454 | return 0; | | 1454 | return 0; |
1455 | | | 1455 | |
1456 | case DIOCGCACHE: | | 1456 | case DIOCGCACHE: |
1457 | { | | 1457 | { |
1458 | int dkcache = 0; | | 1458 | int dkcache = 0; |
1459 | | | 1459 | |
1460 | /* | | 1460 | /* |
1461 | * We pass this call down to all components and report | | 1461 | * We pass this call down to all components and report |
1462 | * intersection of the flags returned by the components. | | 1462 | * intersection of the flags returned by the components. |
1463 | * If any errors out, we return error. CCD components | | 1463 | * If any errors out, we return error. CCD components |
1464 | * can not change unless the device is unconfigured, so | | 1464 | * can not change unless the device is unconfigured, so |
1465 | * device feature flags will remain static. RCE/WCE can change | | 1465 | * device feature flags will remain static. RCE/WCE can change |
1466 | * of course, if set directly on underlying device. | | 1466 | * of course, if set directly on underlying device. |
1467 | */ | | 1467 | */ |
1468 | for (error = 0, i = 0; i < cs->sc_nccdisks; i++) { | | 1468 | for (error = 0, i = 0; i < cs->sc_nccdisks; i++) { |
1469 | error = VOP_IOCTL(cs->sc_cinfo[i].ci_vp, cmd, &j, | | 1469 | error = VOP_IOCTL(cs->sc_cinfo[i].ci_vp, cmd, &j, |
1470 | flag, uc); | | 1470 | flag, uc); |
1471 | if (error) | | 1471 | if (error) |
1472 | break; | | 1472 | break; |
1473 | | | 1473 | |
1474 | if (i == 0) | | 1474 | if (i == 0) |
1475 | dkcache = j; | | 1475 | dkcache = j; |
1476 | else | | 1476 | else |
1477 | dkcache = DKCACHE_COMBINE(dkcache, j); | | 1477 | dkcache = DKCACHE_COMBINE(dkcache, j); |
1478 | } | | 1478 | } |
1479 | | | 1479 | |
1480 | *((int *)data) = dkcache; | | 1480 | *((int *)data) = dkcache; |
1481 | break; | | 1481 | break; |
1482 | } | | 1482 | } |
1483 | | | 1483 | |
1484 | case DIOCCACHESYNC: | | 1484 | case DIOCCACHESYNC: |
1485 | /* | | 1485 | /* |
1486 | * We pass this call down to all components and report | | 1486 | * We pass this call down to all components and report |
1487 | * the first error we encounter. | | 1487 | * the first error we encounter. |
1488 | */ | | 1488 | */ |
1489 | for (error = 0, i = 0; i < cs->sc_nccdisks; i++) { | | 1489 | for (error = 0, i = 0; i < cs->sc_nccdisks; i++) { |
1490 | j = VOP_IOCTL(cs->sc_cinfo[i].ci_vp, cmd, data, | | 1490 | j = VOP_IOCTL(cs->sc_cinfo[i].ci_vp, cmd, data, |
1491 | flag, uc); | | 1491 | flag, uc); |
1492 | if (j != 0 && error == 0) | | 1492 | if (j != 0 && error == 0) |
1493 | error = j; | | 1493 | error = j; |
1494 | } | | 1494 | } |
1495 | break; | | 1495 | break; |
1496 | | | 1496 | |
1497 | default: | | 1497 | default: |
1498 | error = ENOTTY; | | 1498 | error = ENOTTY; |
1499 | break; | | 1499 | break; |
1500 | } | | 1500 | } |
1501 | | | 1501 | |
1502 | out: | | 1502 | out: |
1503 | mutex_exit(&cs->sc_dvlock); | | 1503 | mutex_exit(&cs->sc_dvlock); |
1504 | return (error); | | 1504 | return (error); |
1505 | } | | 1505 | } |
1506 | | | 1506 | |
1507 | static int | | 1507 | static int |
1508 | ccdsize(dev_t dev) | | 1508 | ccdsize(dev_t dev) |
1509 | { | | 1509 | { |
1510 | struct ccd_softc *cs; | | 1510 | struct ccd_softc *cs; |
1511 | struct disklabel *lp; | | 1511 | struct disklabel *lp; |
1512 | int part, unit, omask, size; | | 1512 | int part, unit, omask, size; |
1513 | | | 1513 | |
1514 | unit = ccdunit(dev); | | 1514 | unit = ccdunit(dev); |
1515 | if ((cs = ccdget(unit, 0)) == NULL) | | 1515 | if ((cs = ccdget(unit, 0)) == NULL) |
1516 | return -1; | | 1516 | return -1; |
1517 | | | 1517 | |
1518 | if ((cs->sc_flags & CCDF_INITED) == 0) | | 1518 | if ((cs->sc_flags & CCDF_INITED) == 0) |
1519 | return (-1); | | 1519 | return (-1); |
1520 | | | 1520 | |
1521 | part = DISKPART(dev); | | 1521 | part = DISKPART(dev); |
1522 | omask = cs->sc_dkdev.dk_openmask & (1 << part); | | 1522 | omask = cs->sc_dkdev.dk_openmask & (1 << part); |
1523 | lp = cs->sc_dkdev.dk_label; | | 1523 | lp = cs->sc_dkdev.dk_label; |
1524 | | | 1524 | |
1525 | if (omask == 0 && ccdopen(dev, 0, S_IFBLK, curlwp)) | | 1525 | if (omask == 0 && ccdopen(dev, 0, S_IFBLK, curlwp)) |
1526 | return (-1); | | 1526 | return (-1); |
1527 | | | 1527 | |
1528 | if (lp->d_partitions[part].p_fstype != FS_SWAP) | | 1528 | if (lp->d_partitions[part].p_fstype != FS_SWAP) |
1529 | size = -1; | | 1529 | size = -1; |
1530 | else | | 1530 | else |
1531 | size = lp->d_partitions[part].p_size * | | 1531 | size = lp->d_partitions[part].p_size * |
1532 | (lp->d_secsize / DEV_BSIZE); | | 1532 | (lp->d_secsize / DEV_BSIZE); |
1533 | | | 1533 | |
1534 | if (omask == 0 && ccdclose(dev, 0, S_IFBLK, curlwp)) | | 1534 | if (omask == 0 && ccdclose(dev, 0, S_IFBLK, curlwp)) |
1535 | return (-1); | | 1535 | return (-1); |
1536 | | | 1536 | |
1537 | return (size); | | 1537 | return (size); |
1538 | } | | 1538 | } |
1539 | | | 1539 | |
1540 | static void | | 1540 | static void |
1541 | ccdgetdefaultlabel(struct ccd_softc *cs, struct disklabel *lp) | | 1541 | ccdgetdefaultlabel(struct ccd_softc *cs, struct disklabel *lp) |
1542 | { | | 1542 | { |
1543 | struct ccdgeom *ccg = &cs->sc_geom; | | 1543 | struct ccdgeom *ccg = &cs->sc_geom; |
1544 | | | 1544 | |
1545 | memset(lp, 0, sizeof(*lp)); | | 1545 | memset(lp, 0, sizeof(*lp)); |
1546 | | | 1546 | |
1547 | if (cs->sc_size > UINT32_MAX) | | 1547 | if (cs->sc_size > UINT32_MAX) |
1548 | lp->d_secperunit = UINT32_MAX; | | 1548 | lp->d_secperunit = UINT32_MAX; |
1549 | else | | 1549 | else |
1550 | lp->d_secperunit = cs->sc_size; | | 1550 | lp->d_secperunit = cs->sc_size; |
1551 | lp->d_secsize = ccg->ccg_secsize; | | 1551 | lp->d_secsize = ccg->ccg_secsize; |
1552 | lp->d_nsectors = ccg->ccg_nsectors; | | 1552 | lp->d_nsectors = ccg->ccg_nsectors; |
1553 | lp->d_ntracks = ccg->ccg_ntracks; | | 1553 | lp->d_ntracks = ccg->ccg_ntracks; |
1554 | lp->d_ncylinders = ccg->ccg_ncylinders; | | 1554 | lp->d_ncylinders = ccg->ccg_ncylinders; |
1555 | lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; | | 1555 | lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; |
1556 | | | 1556 | |
1557 | strncpy(lp->d_typename, "ccd", sizeof(lp->d_typename)); | | 1557 | strncpy(lp->d_typename, "ccd", sizeof(lp->d_typename)); |
1558 | lp->d_type = DKTYPE_CCD; | | 1558 | lp->d_type = DKTYPE_CCD; |
1559 | strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); | | 1559 | strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); |
1560 | lp->d_rpm = 3600; | | 1560 | lp->d_rpm = 3600; |
1561 | lp->d_interleave = 1; | | 1561 | lp->d_interleave = 1; |
1562 | lp->d_flags = 0; | | 1562 | lp->d_flags = 0; |
1563 | | | 1563 | |
1564 | lp->d_partitions[RAW_PART].p_offset = 0; | | 1564 | lp->d_partitions[RAW_PART].p_offset = 0; |
1565 | lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; | | 1565 | lp->d_partitions[RAW_PART].p_size = lp->d_secperunit; |
1566 | lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; | | 1566 | lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; |
1567 | lp->d_npartitions = RAW_PART + 1; | | 1567 | lp->d_npartitions = RAW_PART + 1; |
1568 | | | 1568 | |
1569 | lp->d_magic = DISKMAGIC; | | 1569 | lp->d_magic = DISKMAGIC; |
1570 | lp->d_magic2 = DISKMAGIC; | | 1570 | lp->d_magic2 = DISKMAGIC; |
1571 | lp->d_checksum = dkcksum(cs->sc_dkdev.dk_label); | | 1571 | lp->d_checksum = dkcksum(cs->sc_dkdev.dk_label); |
1572 | } | | 1572 | } |
1573 | | | 1573 | |
1574 | /* | | 1574 | /* |
1575 | * Read the disklabel from the ccd. If one is not present, fake one | | 1575 | * Read the disklabel from the ccd. If one is not present, fake one |
1576 | * up. | | 1576 | * up. |
1577 | */ | | 1577 | */ |
1578 | static void | | 1578 | static void |
1579 | ccdgetdisklabel(dev_t dev) | | 1579 | ccdgetdisklabel(dev_t dev) |
1580 | { | | 1580 | { |
1581 | int unit = ccdunit(dev); | | 1581 | int unit = ccdunit(dev); |
1582 | struct ccd_softc *cs; | | 1582 | struct ccd_softc *cs; |
1583 | const char *errstring; | | 1583 | const char *errstring; |
1584 | struct disklabel *lp; | | 1584 | struct disklabel *lp; |
1585 | struct cpu_disklabel *clp; | | 1585 | struct cpu_disklabel *clp; |
1586 | | | 1586 | |
1587 | if ((cs = ccdget(unit, 0)) == NULL) | | 1587 | if ((cs = ccdget(unit, 0)) == NULL) |
1588 | return; | | 1588 | return; |
1589 | lp = cs->sc_dkdev.dk_label; | | 1589 | lp = cs->sc_dkdev.dk_label; |
1590 | clp = cs->sc_dkdev.dk_cpulabel; | | 1590 | clp = cs->sc_dkdev.dk_cpulabel; |
1591 | KASSERT(mutex_owned(&cs->sc_dvlock)); | | 1591 | KASSERT(mutex_owned(&cs->sc_dvlock)); |
1592 | | | 1592 | |
1593 | memset(clp, 0, sizeof(*clp)); | | 1593 | memset(clp, 0, sizeof(*clp)); |
1594 | | | 1594 | |
1595 | ccdgetdefaultlabel(cs, lp); | | 1595 | ccdgetdefaultlabel(cs, lp); |
1596 | | | 1596 | |
1597 | /* | | 1597 | /* |
1598 | * Call the generic disklabel extraction routine. | | 1598 | * Call the generic disklabel extraction routine. |
1599 | */ | | 1599 | */ |
1600 | cs->sc_flags |= CCDF_RLABEL; | | 1600 | cs->sc_flags |= CCDF_RLABEL; |
1601 | if ((cs->sc_flags & CCDF_NOLABEL) != 0) | | 1601 | if ((cs->sc_flags & CCDF_NOLABEL) != 0) |
1602 | errstring = "CCDF_NOLABEL set; ignoring on-disk label"; | | 1602 | errstring = "CCDF_NOLABEL set; ignoring on-disk label"; |
1603 | else | | 1603 | else |
1604 | errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy, | | 1604 | errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy, |
1605 | cs->sc_dkdev.dk_label, cs->sc_dkdev.dk_cpulabel); | | 1605 | cs->sc_dkdev.dk_label, cs->sc_dkdev.dk_cpulabel); |
1606 | if (errstring) | | 1606 | if (errstring) |
1607 | ccdmakedisklabel(cs); | | 1607 | ccdmakedisklabel(cs); |
1608 | else { | | 1608 | else { |
1609 | int i; | | 1609 | int i; |
1610 | struct partition *pp; | | 1610 | struct partition *pp; |
1611 | | | 1611 | |
1612 | /* | | 1612 | /* |
1613 | * Sanity check whether the found disklabel is valid. | | 1613 | * Sanity check whether the found disklabel is valid. |
1614 | * | | 1614 | * |
1615 | * This is necessary since total size of ccd may vary | | 1615 | * This is necessary since total size of ccd may vary |
1616 | * when an interleave is changed even though exactly | | 1616 | * when an interleave is changed even though exactly |
1617 | * same componets are used, and old disklabel may used | | 1617 | * same componets are used, and old disklabel may used |
1618 | * if that is found. | | 1618 | * if that is found. |
1619 | */ | | 1619 | */ |
1620 | if (lp->d_secperunit < UINT32_MAX ? | | 1620 | if (lp->d_secperunit < UINT32_MAX ? |
1621 | lp->d_secperunit != cs->sc_size : | | 1621 | lp->d_secperunit != cs->sc_size : |
1622 | lp->d_secperunit > cs->sc_size) | | 1622 | lp->d_secperunit > cs->sc_size) |
1623 | printf("WARNING: %s: " | | 1623 | printf("WARNING: %s: " |
1624 | "total sector size in disklabel (%ju) != " | | 1624 | "total sector size in disklabel (%ju) != " |
1625 | "the size of ccd (%ju)\n", cs->sc_xname, | | 1625 | "the size of ccd (%ju)\n", cs->sc_xname, |
1626 | (uintmax_t)lp->d_secperunit, | | 1626 | (uintmax_t)lp->d_secperunit, |
1627 | (uintmax_t)cs->sc_size); | | 1627 | (uintmax_t)cs->sc_size); |
1628 | for (i = 0; i < lp->d_npartitions; i++) { | | 1628 | for (i = 0; i < lp->d_npartitions; i++) { |
1629 | pp = &lp->d_partitions[i]; | | 1629 | pp = &lp->d_partitions[i]; |
1630 | if (pp->p_offset + pp->p_size > cs->sc_size) | | 1630 | if (pp->p_offset + pp->p_size > cs->sc_size) |
1631 | printf("WARNING: %s: end of partition `%c' " | | 1631 | printf("WARNING: %s: end of partition `%c' " |
1632 | "exceeds the size of ccd (%ju)\n", | | 1632 | "exceeds the size of ccd (%ju)\n", |
1633 | cs->sc_xname, 'a' + i, (uintmax_t)cs->sc_size); | | 1633 | cs->sc_xname, 'a' + i, (uintmax_t)cs->sc_size); |
1634 | } | | 1634 | } |
1635 | } | | 1635 | } |
1636 | | | 1636 | |
1637 | #ifdef DEBUG | | 1637 | #ifdef DEBUG |
1638 | /* It's actually extremely common to have unlabeled ccds. */ | | 1638 | /* It's actually extremely common to have unlabeled ccds. */ |
1639 | if (ccddebug & CCDB_LABEL) | | 1639 | if (ccddebug & CCDB_LABEL) |
1640 | if (errstring != NULL) | | 1640 | if (errstring != NULL) |
1641 | printf("%s: %s\n", cs->sc_xname, errstring); | | 1641 | printf("%s: %s\n", cs->sc_xname, errstring); |
1642 | #endif | | 1642 | #endif |
1643 | | | 1643 | |
1644 | /* In-core label now valid. */ | | 1644 | /* In-core label now valid. */ |
1645 | cs->sc_flags = (cs->sc_flags | CCDF_VLABEL) & ~CCDF_RLABEL; | | 1645 | cs->sc_flags = (cs->sc_flags | CCDF_VLABEL) & ~CCDF_RLABEL; |
1646 | } | | 1646 | } |
1647 | | | 1647 | |
1648 | /* | | 1648 | /* |
1649 | * Take care of things one might want to take care of in the event | | 1649 | * Take care of things one might want to take care of in the event |
1650 | * that a disklabel isn't present. | | 1650 | * that a disklabel isn't present. |
1651 | */ | | 1651 | */ |
1652 | static void | | 1652 | static void |
1653 | ccdmakedisklabel(struct ccd_softc *cs) | | 1653 | ccdmakedisklabel(struct ccd_softc *cs) |
1654 | { | | 1654 | { |
1655 | struct disklabel *lp = cs->sc_dkdev.dk_label; | | 1655 | struct disklabel *lp = cs->sc_dkdev.dk_label; |
1656 | | | 1656 | |
1657 | /* | | 1657 | /* |
1658 | * For historical reasons, if there's no disklabel present | | 1658 | * For historical reasons, if there's no disklabel present |
1659 | * the raw partition must be marked FS_BSDFFS. | | 1659 | * the raw partition must be marked FS_BSDFFS. |
1660 | */ | | 1660 | */ |
1661 | lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS; | | 1661 | lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS; |
1662 | | | 1662 | |
1663 | strncpy(lp->d_packname, "default label", sizeof(lp->d_packname)); | | 1663 | strncpy(lp->d_packname, "default label", sizeof(lp->d_packname)); |
1664 | | | 1664 | |
1665 | lp->d_checksum = dkcksum(lp); | | 1665 | lp->d_checksum = dkcksum(lp); |
1666 | } | | 1666 | } |
1667 | | | 1667 | |
1668 | #ifdef DEBUG | | 1668 | #ifdef DEBUG |
1669 | static void | | 1669 | static void |
1670 | printiinfo(struct ccdiinfo *ii) | | 1670 | printiinfo(struct ccdiinfo *ii) |
1671 | { | | 1671 | { |
1672 | int ix, i; | | 1672 | int ix, i; |
1673 | | | 1673 | |
1674 | for (ix = 0; ii->ii_ndisk; ix++, ii++) { | | 1674 | for (ix = 0; ii->ii_ndisk; ix++, ii++) { |
1675 | printf(" itab[%d]: #dk %d sblk %" PRId64 " soff %" PRId64, | | 1675 | printf(" itab[%d]: #dk %d sblk %" PRId64 " soff %" PRId64, |
1676 | ix, ii->ii_ndisk, ii->ii_startblk, ii->ii_startoff); | | 1676 | ix, ii->ii_ndisk, ii->ii_startblk, ii->ii_startoff); |
1677 | for (i = 0; i < ii->ii_ndisk; i++) | | 1677 | for (i = 0; i < ii->ii_ndisk; i++) |
1678 | printf(" %d", ii->ii_index[i]); | | 1678 | printf(" %d", ii->ii_index[i]); |
1679 | printf("\n"); | | 1679 | printf("\n"); |
1680 | } | | 1680 | } |
1681 | } | | 1681 | } |
1682 | #endif | | 1682 | #endif |
1683 | | | 1683 | |
1684 | MODULE(MODULE_CLASS_DRIVER, ccd, "dk_subr,bufq_fcfs"); | | 1684 | MODULE(MODULE_CLASS_DRIVER, ccd, "dk_subr,bufq_fcfs"); |
1685 | | | 1685 | |
1686 | static int | | 1686 | static int |
1687 | ccd_modcmd(modcmd_t cmd, void *arg) | | 1687 | ccd_modcmd(modcmd_t cmd, void *arg) |
1688 | { | | 1688 | { |
1689 | int error = 0; | | 1689 | int error = 0; |
1690 | #ifdef _MODULE | | 1690 | #ifdef _MODULE |
1691 | int bmajor = -1, cmajor = -1; | | 1691 | int bmajor = -1, cmajor = -1; |
1692 | #endif | | 1692 | #endif |
1693 | | | 1693 | |
1694 | | | 1694 | |
1695 | switch (cmd) { | | 1695 | switch (cmd) { |
1696 | case MODULE_CMD_INIT: | | 1696 | case MODULE_CMD_INIT: |
1697 | #ifdef _MODULE | | 1697 | #ifdef _MODULE |
1698 | ccdattach(0); | | 1698 | ccdattach(0); |
1699 | | | 1699 | |
1700 | error = devsw_attach("ccd", &ccd_bdevsw, &bmajor, | | 1700 | error = devsw_attach("ccd", &ccd_bdevsw, &bmajor, |
1701 | &ccd_cdevsw, &cmajor); | | 1701 | &ccd_cdevsw, &cmajor); |
1702 | #endif | | 1702 | #endif |
1703 | break; | | 1703 | break; |
1704 | | | 1704 | |
1705 | case MODULE_CMD_FINI: | | 1705 | case MODULE_CMD_FINI: |
1706 | #ifdef _MODULE | | 1706 | #ifdef _MODULE |
1707 | mutex_enter(&ccd_lock); | | 1707 | mutex_enter(&ccd_lock); |
1708 | if (!LIST_EMPTY(&ccds)) { | | 1708 | if (!LIST_EMPTY(&ccds)) { |
1709 | mutex_exit(&ccd_lock); | | 1709 | mutex_exit(&ccd_lock); |
1710 | error = EBUSY; | | 1710 | error = EBUSY; |
1711 | } else { | | 1711 | } else { |
1712 | mutex_exit(&ccd_lock); | | 1712 | mutex_exit(&ccd_lock); |
1713 | error = devsw_detach(&ccd_bdevsw, &ccd_cdevsw); | | 1713 | error = devsw_detach(&ccd_bdevsw, &ccd_cdevsw); |
1714 | ccddetach(); | | 1714 | ccddetach(); |
1715 | } | | 1715 | } |
1716 | #endif | | 1716 | #endif |
1717 | break; | | 1717 | break; |
1718 | | | 1718 | |
1719 | case MODULE_CMD_STAT: | | 1719 | case MODULE_CMD_STAT: |
1720 | return ENOTTY; | | 1720 | return ENOTTY; |
1721 | | | 1721 | |
1722 | default: | | 1722 | default: |
1723 | return ENOTTY; | | 1723 | return ENOTTY; |
1724 | } | | 1724 | } |
1725 | | | 1725 | |
1726 | return error; | | 1726 | return error; |
1727 | } | | 1727 | } |
1728 | | | 1728 | |
1729 | static int | | 1729 | static int |
1730 | ccd_units_sysctl(SYSCTLFN_ARGS) | | 1730 | ccd_units_sysctl(SYSCTLFN_ARGS) |
1731 | { | | 1731 | { |
1732 | struct sysctlnode node; | | 1732 | struct sysctlnode node; |
1733 | struct ccd_softc *sc; | | 1733 | struct ccd_softc *sc; |
1734 | int error, i, nccd, *units; | | 1734 | int error, i, nccd, *units; |
1735 | size_t size; | | 1735 | size_t size; |
1736 | | | 1736 | |
1737 | nccd = 0; | | 1737 | nccd = 0; |
1738 | mutex_enter(&ccd_lock); | | 1738 | mutex_enter(&ccd_lock); |
1739 | LIST_FOREACH(sc, &ccds, sc_link) | | 1739 | LIST_FOREACH(sc, &ccds, sc_link) |
1740 | nccd++; | | 1740 | nccd++; |
1741 | mutex_exit(&ccd_lock); | | 1741 | mutex_exit(&ccd_lock); |
1742 | | | 1742 | |
1743 | if (nccd != 0) { | | 1743 | if (nccd != 0) { |
1744 | size = nccd * sizeof(*units); | | 1744 | size = nccd * sizeof(*units); |
1745 | units = kmem_zalloc(size, KM_SLEEP); | | 1745 | units = kmem_zalloc(size, KM_SLEEP); |
1746 | i = 0; | | 1746 | i = 0; |
1747 | mutex_enter(&ccd_lock); | | 1747 | mutex_enter(&ccd_lock); |
1748 | LIST_FOREACH(sc, &ccds, sc_link) { | | 1748 | LIST_FOREACH(sc, &ccds, sc_link) { |
1749 | if (i >= nccd) | | 1749 | if (i >= nccd) |
1750 | break; | | 1750 | break; |
1751 | units[i] = sc->sc_unit; | | 1751 | units[i] = sc->sc_unit; |
1752 | } | | 1752 | } |
1753 | mutex_exit(&ccd_lock); | | 1753 | mutex_exit(&ccd_lock); |
1754 | } else { | | 1754 | } else { |
1755 | units = NULL; | | 1755 | units = NULL; |
1756 | size = 0; | | 1756 | size = 0; |
1757 | } | | 1757 | } |
1758 | | | 1758 | |
1759 | node = *rnode; | | 1759 | node = *rnode; |
1760 | node.sysctl_data = units; | | 1760 | node.sysctl_data = units; |
1761 | node.sysctl_size = size; | | 1761 | node.sysctl_size = size; |
1762 | | | 1762 | |
1763 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | | 1763 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); |
1764 | if (units) | | 1764 | if (units) |
1765 | kmem_free(units, size); | | 1765 | kmem_free(units, size); |
1766 | return error; | | 1766 | return error; |
1767 | } | | 1767 | } |
1768 | | | 1768 | |
1769 | static int | | 1769 | static int |
1770 | ccd_info_sysctl(SYSCTLFN_ARGS) | | 1770 | ccd_info_sysctl(SYSCTLFN_ARGS) |
1771 | { | | 1771 | { |
1772 | struct sysctlnode node; | | 1772 | struct sysctlnode node; |
1773 | struct ccddiskinfo ccd; | | 1773 | struct ccddiskinfo ccd; |
1774 | struct ccd_softc *sc; | | 1774 | struct ccd_softc *sc; |
1775 | int unit; | | 1775 | int unit; |
1776 | | | 1776 | |
1777 | if (newp == NULL || newlen != sizeof(int)) | | 1777 | if (newp == NULL || newlen != sizeof(int)) |
1778 | return EINVAL; | | 1778 | return EINVAL; |
1779 | | | 1779 | |
1780 | unit = *(const int *)newp; | | 1780 | unit = *(const int *)newp; |
1781 | newp = NULL; | | 1781 | newp = NULL; |
1782 | newlen = 0; | | 1782 | newlen = 0; |
1783 | ccd.ccd_ndisks = ~0; | | 1783 | ccd.ccd_ndisks = ~0; |
1784 | mutex_enter(&ccd_lock); | | 1784 | mutex_enter(&ccd_lock); |
1785 | LIST_FOREACH(sc, &ccds, sc_link) { | | 1785 | LIST_FOREACH(sc, &ccds, sc_link) { |
1786 | if (sc->sc_unit == unit) { | | 1786 | if (sc->sc_unit == unit) { |
1787 | ccd.ccd_ileave = sc->sc_ileave; | | 1787 | ccd.ccd_ileave = sc->sc_ileave; |
1788 | ccd.ccd_size = sc->sc_size; | | 1788 | ccd.ccd_size = sc->sc_size; |
1789 | ccd.ccd_ndisks = sc->sc_nccdisks; | | 1789 | ccd.ccd_ndisks = sc->sc_nccdisks; |
1790 | ccd.ccd_flags = sc->sc_flags; | | 1790 | ccd.ccd_flags = sc->sc_flags; |
1791 | break; | | 1791 | break; |
1792 | } | | 1792 | } |
1793 | } | | 1793 | } |
1794 | mutex_exit(&ccd_lock); | | 1794 | mutex_exit(&ccd_lock); |
1795 | | | 1795 | |
1796 | if (ccd.ccd_ndisks == ~0) | | 1796 | if (ccd.ccd_ndisks == ~0) |
1797 | return ENOENT; | | 1797 | return ENOENT; |
1798 | | | 1798 | |
1799 | node = *rnode; | | 1799 | node = *rnode; |
1800 | node.sysctl_data = &ccd; | | 1800 | node.sysctl_data = &ccd; |
1801 | node.sysctl_size = sizeof(ccd); | | 1801 | node.sysctl_size = sizeof(ccd); |
1802 | | | 1802 | |
1803 | return sysctl_lookup(SYSCTLFN_CALL(&node)); | | 1803 | return sysctl_lookup(SYSCTLFN_CALL(&node)); |
1804 | } | | 1804 | } |
1805 | | | 1805 | |
1806 | static int | | 1806 | static int |
1807 | ccd_components_sysctl(SYSCTLFN_ARGS) | | 1807 | ccd_components_sysctl(SYSCTLFN_ARGS) |
1808 | { | | 1808 | { |
1809 | struct sysctlnode node; | | 1809 | struct sysctlnode node; |
1810 | int error, unit; | | 1810 | int error, unit; |
1811 | size_t size; | | 1811 | size_t size; |
1812 | char *names, *p, *ep; | | 1812 | char *names, *p, *ep; |
1813 | struct ccd_softc *sc; | | 1813 | struct ccd_softc *sc; |
1814 | | | 1814 | |
1815 | if (newp == NULL || newlen != sizeof(int)) | | 1815 | if (newp == NULL || newlen != sizeof(int)) |
1816 | return EINVAL; | | 1816 | return EINVAL; |
1817 | | | 1817 | |
1818 | size = 0; | | 1818 | size = 0; |
1819 | unit = *(const int *)newp; | | 1819 | unit = *(const int *)newp; |
1820 | newp = NULL; | | 1820 | newp = NULL; |
1821 | newlen = 0; | | 1821 | newlen = 0; |
1822 | mutex_enter(&ccd_lock); | | 1822 | mutex_enter(&ccd_lock); |
1823 | LIST_FOREACH(sc, &ccds, sc_link) | | 1823 | LIST_FOREACH(sc, &ccds, sc_link) |
1824 | if (sc->sc_unit == unit) { | | 1824 | if (sc->sc_unit == unit) { |
1825 | for (size_t i = 0; i < sc->sc_nccdisks; i++) | | 1825 | for (size_t i = 0; i < sc->sc_nccdisks; i++) |
1826 | size += strlen(sc->sc_cinfo[i].ci_path) + 1; | | 1826 | size += strlen(sc->sc_cinfo[i].ci_path) + 1; |
1827 | break; | | 1827 | break; |
1828 | } | | 1828 | } |
1829 | mutex_exit(&ccd_lock); | | 1829 | mutex_exit(&ccd_lock); |
1830 | | | 1830 | |
1831 | if (size == 0) | | 1831 | if (size == 0) |
1832 | return ENOENT; | | 1832 | return ENOENT; |
1833 | names = kmem_zalloc(size, KM_SLEEP); | | 1833 | names = kmem_zalloc(size, KM_SLEEP); |
1834 | p = names; | | 1834 | p = names; |
1835 | ep = names + size; | | 1835 | ep = names + size; |
1836 | mutex_enter(&ccd_lock); | | 1836 | mutex_enter(&ccd_lock); |
1837 | LIST_FOREACH(sc, &ccds, sc_link) | | 1837 | LIST_FOREACH(sc, &ccds, sc_link) |
1838 | if (sc->sc_unit == unit) { | | 1838 | if (sc->sc_unit == unit) { |
1839 | for (size_t i = 0; i < sc->sc_nccdisks; i++) { | | 1839 | for (size_t i = 0; i < sc->sc_nccdisks; i++) { |
1840 | char *d = sc->sc_cinfo[i].ci_path; | | 1840 | char *d = sc->sc_cinfo[i].ci_path; |
1841 | while (p < ep && (*p++ = *d++) != '\0') | | 1841 | while (p < ep && (*p++ = *d++) != '\0') |
1842 | continue; | | 1842 | continue; |
1843 | } | | 1843 | } |
1844 | break; | | 1844 | break; |
1845 | } | | 1845 | } |
1846 | mutex_exit(&ccd_lock); | | 1846 | mutex_exit(&ccd_lock); |
1847 | | | 1847 | |
1848 | node = *rnode; | | 1848 | node = *rnode; |
1849 | node.sysctl_data = names; | | 1849 | node.sysctl_data = names; |
1850 | node.sysctl_size = ep - names; | | 1850 | node.sysctl_size = ep - names; |
1851 | | | 1851 | |
1852 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | | 1852 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); |
1853 | kmem_free(names, size); | | 1853 | kmem_free(names, size); |
1854 | return error; | | 1854 | return error; |
1855 | } | | 1855 | } |
1856 | | | 1856 | |
1857 | SYSCTL_SETUP(sysctl_kern_ccd_setup, "sysctl kern.ccd subtree setup") | | 1857 | SYSCTL_SETUP(sysctl_kern_ccd_setup, "sysctl kern.ccd subtree setup") |
1858 | { | | 1858 | { |
1859 | const struct sysctlnode *node = NULL; | | 1859 | const struct sysctlnode *node = NULL; |
1860 | | | 1860 | |
1861 | sysctl_createv(clog, 0, NULL, &node, | | 1861 | sysctl_createv(clog, 0, NULL, &node, |
1862 | CTLFLAG_PERMANENT, | | 1862 | CTLFLAG_PERMANENT, |
1863 | CTLTYPE_NODE, "ccd", | | 1863 | CTLTYPE_NODE, "ccd", |
1864 | SYSCTL_DESCR("ConCatenated Disk state"), | | 1864 | SYSCTL_DESCR("ConCatenated Disk state"), |
1865 | NULL, 0, NULL, 0, | | 1865 | NULL, 0, NULL, 0, |
1866 | CTL_KERN, CTL_CREATE, CTL_EOL); | | 1866 | CTL_KERN, CTL_CREATE, CTL_EOL); |
1867 | | | 1867 | |
1868 | if (node == NULL) | | 1868 | if (node == NULL) |
1869 | return; | | 1869 | return; |
1870 | | | 1870 | |
1871 | sysctl_createv(clog, 0, &node, NULL, | | 1871 | sysctl_createv(clog, 0, &node, NULL, |
1872 | CTLFLAG_PERMANENT | CTLFLAG_READONLY, | | 1872 | CTLFLAG_PERMANENT | CTLFLAG_READONLY, |
1873 | CTLTYPE_STRUCT, "units", | | 1873 | CTLTYPE_STRUCT, "units", |
1874 | SYSCTL_DESCR("List of ccd unit numbers"), | | 1874 | SYSCTL_DESCR("List of ccd unit numbers"), |
1875 | ccd_units_sysctl, 0, NULL, 0, | | 1875 | ccd_units_sysctl, 0, NULL, 0, |
1876 | CTL_CREATE, CTL_EOL); | | 1876 | CTL_CREATE, CTL_EOL); |
1877 | sysctl_createv(clog, 0, &node, NULL, | | 1877 | sysctl_createv(clog, 0, &node, NULL, |
1878 | CTLFLAG_PERMANENT | CTLFLAG_READWRITE, | | 1878 | CTLFLAG_PERMANENT | CTLFLAG_READWRITE, |
1879 | CTLTYPE_STRUCT, "info", | | 1879 | CTLTYPE_STRUCT, "info", |
1880 | SYSCTL_DESCR("Information about a CCD unit"), | | 1880 | SYSCTL_DESCR("Information about a CCD unit"), |
1881 | ccd_info_sysctl, 0, NULL, 0, | | 1881 | ccd_info_sysctl, 0, NULL, 0, |
1882 | CTL_CREATE, CTL_EOL); | | 1882 | CTL_CREATE, CTL_EOL); |
1883 | sysctl_createv(clog, 0, &node, NULL, | | 1883 | sysctl_createv(clog, 0, &node, NULL, |
1884 | CTLFLAG_PERMANENT | CTLFLAG_READWRITE, | | 1884 | CTLFLAG_PERMANENT | CTLFLAG_READWRITE, |
1885 | CTLTYPE_STRUCT, "components", | | 1885 | CTLTYPE_STRUCT, "components", |
1886 | SYSCTL_DESCR("Information about CCD components"), | | 1886 | SYSCTL_DESCR("Information about CCD components"), |
1887 | ccd_components_sysctl, 0, NULL, 0, | | 1887 | ccd_components_sysctl, 0, NULL, 0, |
1888 | CTL_CREATE, CTL_EOL); | | 1888 | CTL_CREATE, CTL_EOL); |
1889 | } | | 1889 | } |