1 /* $NetBSD: ccd.c,v 1.133 2009/04/04 08:29:39 ad Exp $ */
4 * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe, and by Andrew Doran.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1990, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * the Systems Programming Group of the University of Utah Computer
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * from: Utah $Hdr: cd.c 1.6 90/11/28$
66 * @(#)cd.c 8.2 (Berkeley) 11/16/93
70 * Copyright (c) 1988 University of Utah.
72 * This code is derived from software contributed to Berkeley by
73 * the Systems Programming Group of the University of Utah Computer
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
79 * 1. Redistributions of source code must retain the above copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. All advertising materials mentioning features or use of this software
85 * must display the following acknowledgement:
86 * This product includes software developed by the University of
87 * California, Berkeley and its contributors.
88 * 4. Neither the name of the University nor the names of its contributors
89 * may be used to endorse or promote products derived from this software
90 * without specific prior written permission.
92 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
93 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
95 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
96 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
97 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
98 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
100 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
101 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 * from: Utah $Hdr: cd.c 1.6 90/11/28$
106 * @(#)cd.c 8.2 (Berkeley) 11/16/93
110 * "Concatenated" disk driver.
112 * Notes on concurrency:
114 * => sc_dvlock serializes access to the device nodes, excluding block I/O.
116 * => sc_iolock serializes access to (sc_flags & CCDF_INITED), disk stats,
117 * sc_stop, sc_bufq and b_resid from master buffers.
119 * => a combination of CCDF_INITED, sc_inflight, and sc_iolock is used to
120 * serialize I/O and configuration changes.
122 * => the in-core disk label does not change while the device is open.
124 * On memory consumption: ccd fans out I/O requests and so needs to
125 * allocate memory. If the system is desperately low on memory, we
129 #include <sys/cdefs.h>
130 __KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.133 2009/04/04 08:29:39 ad Exp $");
132 #include <sys/param.h>
133 #include <sys/systm.h>
134 #include <sys/kernel.h>
135 #include <sys/proc.h>
136 #include <sys/errno.h>
138 #include <sys/kmem.h>
139 #include <sys/pool.h>
140 #include <sys/namei.h>
141 #include <sys/stat.h>
142 #include <sys/ioctl.h>
143 #include <sys/disklabel.h>
144 #include <sys/device.h>
145 #include <sys/disk.h>
146 #include <sys/syslog.h>
147 #include <sys/fcntl.h>
148 #include <sys/vnode.h>
149 #include <sys/conf.h>
150 #include <sys/mutex.h>
151 #include <sys/queue.h>
152 #include <sys/kauth.h>
153 #include <sys/kthread.h>
154 #include <sys/bufq.h>
156 #include <dev/ccdvar.h>
157 #include <dev/dkvar.h>
159 #if defined(CCDDEBUG) && !defined(DEBUG)
164 #define CCDB_FOLLOW 0x01
165 #define CCDB_INIT 0x02
167 #define CCDB_LABEL 0x08
168 #define CCDB_VNODE 0x10
172 #define ccdunit(x) DISKUNIT(x)
175 struct buf cb_buf
; /* new I/O buf */
176 struct buf
*cb_obp
; /* ptr. to original I/O buf */
177 struct ccd_softc
*cb_sc
; /* pointer to ccd softc */
178 int cb_comp
; /* target component */
179 SIMPLEQ_ENTRY(ccdbuf
) cb_q
; /* fifo of component buffers */
182 /* component buffer pool */
183 static pool_cache_t ccd_cache
;
185 #define CCD_GETBUF() pool_cache_get(ccd_cache, PR_WAITOK)
186 #define CCD_PUTBUF(cbp) pool_cache_put(ccd_cache, cbp)
188 #define CCDLABELDEV(dev) \
189 (MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART))
191 /* called by main() at boot time */
194 /* called by biodone() at interrupt time */
195 static void ccdiodone(struct buf
*);
197 static void ccdinterleave(struct ccd_softc
*);
198 static int ccdinit(struct ccd_softc
*, char **, struct vnode
**,
200 static struct ccdbuf
*ccdbuffer(struct ccd_softc
*, struct buf
*,
201 daddr_t
, void *, long);
202 static void ccdgetdefaultlabel(struct ccd_softc
*, struct disklabel
*);
203 static void ccdgetdisklabel(dev_t
);
204 static void ccdmakedisklabel(struct ccd_softc
*);
205 static void ccdstart(struct ccd_softc
*);
206 static void ccdthread(void *);
208 static dev_type_open(ccdopen
);
209 static dev_type_close(ccdclose
);
210 static dev_type_read(ccdread
);
211 static dev_type_write(ccdwrite
);
212 static dev_type_ioctl(ccdioctl
);
213 static dev_type_strategy(ccdstrategy
);
214 static dev_type_size(ccdsize
);
216 const struct bdevsw ccd_bdevsw
= {
219 .d_strategy
= ccdstrategy
,
223 .d_flag
= D_DISK
| D_MPSAFE
226 const struct cdevsw ccd_cdevsw
= {
236 .d_kqfilter
= nokqfilter
,
237 .d_flag
= D_DISK
| D_MPSAFE
241 static void printiinfo(struct ccdiinfo
*);
244 /* Publically visible for the benefit of libkvm and ccdconfig(8). */
245 struct ccd_softc
*ccd_softc
;
246 const int ccd_softc_elemsize
= sizeof(struct ccd_softc
);
250 * Called by main() during pseudo-device attachment. All we need
251 * to do is allocate enough space for devices to be configured later.
256 struct ccd_softc
*cs
;
261 panic("ccdattach: count <= 0");
266 ccd_softc
= kmem_zalloc(num
* ccd_softc_elemsize
, KM_SLEEP
);
267 if (ccd_softc
== NULL
) {
268 printf("WARNING: no memory for concatenated disks\n");
273 /* Initialize the component buffer pool. */
274 ccd_cache
= pool_cache_init(sizeof(struct ccdbuf
), 0,
275 0, 0, "ccdbuf", NULL
, IPL_BIO
, NULL
, NULL
, NULL
);
277 /* Initialize per-softc structures. */
278 for (i
= 0; i
< num
; i
++) {
280 snprintf(cs
->sc_xname
, sizeof(cs
->sc_xname
), "ccd%d", i
);
281 mutex_init(&cs
->sc_dvlock
, MUTEX_DEFAULT
, IPL_NONE
);
282 cs
->sc_iolock
= mutex_obj_alloc(MUTEX_DEFAULT
, IPL_NONE
);
283 cv_init(&cs
->sc_stop
, "ccdstop");
284 cv_init(&cs
->sc_push
, "ccdthr");
285 disk_init(&cs
->sc_dkdev
, cs
->sc_xname
, NULL
); /* XXX */
290 ccdinit(struct ccd_softc
*cs
, char **cpaths
, struct vnode
**vpp
,
293 struct ccdcinfo
*ci
= NULL
;
299 struct partinfo dpart
;
300 struct ccdgeom
*ccg
= &cs
->sc_geom
;
302 int error
, path_alloced
;
305 if (ccddebug
& (CCDB_FOLLOW
|CCDB_INIT
))
306 printf("%s: ccdinit\n", cs
->sc_xname
);
309 /* Allocate space for the component info. */
310 cs
->sc_cinfo
= kmem_alloc(cs
->sc_nccdisks
* sizeof(*cs
->sc_cinfo
),
312 tmppath
= kmem_alloc(MAXPATHLEN
, KM_SLEEP
);
317 * Verify that each component piece exists and record
318 * relevant information about it.
322 for (ix
= 0, path_alloced
= 0; ix
< cs
->sc_nccdisks
; ix
++) {
323 ci
= &cs
->sc_cinfo
[ix
];
327 * Copy in the pathname of the component.
329 memset(tmppath
, 0, sizeof(tmppath
)); /* sanity */
330 error
= copyinstr(cpaths
[ix
], tmppath
,
331 MAXPATHLEN
, &ci
->ci_pathlen
);
332 if (ci
->ci_pathlen
== 0)
336 if (ccddebug
& (CCDB_FOLLOW
|CCDB_INIT
))
337 printf("%s: can't copy path, error = %d\n",
338 cs
->sc_xname
, error
);
342 ci
->ci_path
= kmem_alloc(ci
->ci_pathlen
, KM_SLEEP
);
343 memcpy(ci
->ci_path
, tmppath
, ci
->ci_pathlen
);
347 * XXX: Cache the component's dev_t.
349 if ((error
= VOP_GETATTR(vpp
[ix
], &va
, l
->l_cred
)) != 0) {
351 if (ccddebug
& (CCDB_FOLLOW
|CCDB_INIT
))
352 printf("%s: %s: getattr failed %s = %d\n",
353 cs
->sc_xname
, ci
->ci_path
,
358 ci
->ci_dev
= va
.va_rdev
;
361 * Get partition information for the component.
363 error
= VOP_IOCTL(vpp
[ix
], DIOCGPART
, &dpart
,
367 if (ccddebug
& (CCDB_FOLLOW
|CCDB_INIT
))
368 printf("%s: %s: ioctl failed, error = %d\n",
369 cs
->sc_xname
, ci
->ci_path
, error
);
375 * This diagnostic test is disabled (for now?) since not all port supports
376 * on-disk BSD disklabel.
378 #if 0 /* def DIAGNOSTIC */
379 /* Check fstype field of component. */
380 if (dpart
.part
->p_fstype
!= FS_CCD
)
381 printf("%s: WARNING: %s: fstype %d != FS_CCD\n",
382 cs
->sc_xname
, ci
->ci_path
, dpart
.part
->p_fstype
);
386 * Calculate the size, truncating to an interleave
387 * boundary if necessary.
390 ((dpart
.disklab
->d_secsize
> maxsecsize
) ?
391 dpart
.disklab
->d_secsize
: maxsecsize
);
392 size
= dpart
.part
->p_size
;
393 if (cs
->sc_ileave
> 1)
394 size
-= size
% cs
->sc_ileave
;
398 if (ccddebug
& (CCDB_FOLLOW
|CCDB_INIT
))
399 printf("%s: %s: size == 0\n",
400 cs
->sc_xname
, ci
->ci_path
);
406 if (minsize
== 0 || size
< minsize
)
413 * Don't allow the interleave to be smaller than
414 * the biggest component sector.
416 if ((cs
->sc_ileave
> 0) &&
417 (cs
->sc_ileave
< (maxsecsize
/ DEV_BSIZE
))) {
419 if (ccddebug
& (CCDB_FOLLOW
|CCDB_INIT
))
420 printf("%s: interleave must be at least %d\n",
421 cs
->sc_xname
, (maxsecsize
/ DEV_BSIZE
));
428 * If uniform interleave is desired set all sizes to that of
429 * the smallest component.
431 if (cs
->sc_flags
& CCDF_UNIFORM
) {
432 for (ci
= cs
->sc_cinfo
;
433 ci
< &cs
->sc_cinfo
[cs
->sc_nccdisks
]; ci
++)
434 ci
->ci_size
= minsize
;
436 cs
->sc_size
= cs
->sc_nccdisks
* minsize
;
440 * Construct the interleave table.
445 * Create pseudo-geometry based on 1MB cylinders. It's
448 ccg
->ccg_secsize
= DEV_BSIZE
;
449 ccg
->ccg_ntracks
= 1;
450 ccg
->ccg_nsectors
= 1024 * (1024 / ccg
->ccg_secsize
);
451 ccg
->ccg_ncylinders
= cs
->sc_size
/ ccg
->ccg_nsectors
;
454 * Create thread to handle deferred I/O.
457 error
= kthread_create(PRI_BIO
, KTHREAD_MPSAFE
, NULL
, ccdthread
,
458 cs
, &cs
->sc_thread
, "%s", cs
->sc_xname
);
460 printf("ccdinit: can't create thread: %d\n", error
);
465 * Only now that everything is set up can we enable the device.
467 mutex_enter(cs
->sc_iolock
);
468 cs
->sc_flags
|= CCDF_INITED
;
469 mutex_exit(cs
->sc_iolock
);
470 kmem_free(tmppath
, MAXPATHLEN
);
474 for (ix
= 0; ix
< path_alloced
; ix
++) {
475 kmem_free(cs
->sc_cinfo
[ix
].ci_path
,
476 cs
->sc_cinfo
[ix
].ci_pathlen
);
478 kmem_free(cs
->sc_cinfo
, cs
->sc_nccdisks
* sizeof(struct ccdcinfo
));
479 kmem_free(tmppath
, MAXPATHLEN
);
484 ccdinterleave(struct ccd_softc
*cs
)
486 struct ccdcinfo
*ci
, *smallci
;
493 if (ccddebug
& CCDB_INIT
)
494 printf("ccdinterleave(%p): ileave %d\n", cs
, cs
->sc_ileave
);
497 * Allocate an interleave table.
498 * Chances are this is too big, but we don't care.
500 size
= (cs
->sc_nccdisks
+ 1) * sizeof(struct ccdiinfo
);
501 cs
->sc_itable
= kmem_zalloc(size
, KM_SLEEP
);
504 * Trivial case: no interleave (actually interleave of disk size).
505 * Each table entry represents a single component in its entirety.
507 if (cs
->sc_ileave
== 0) {
511 for (ix
= 0; ix
< cs
->sc_nccdisks
; ix
++) {
512 /* Allocate space for ii_index. */
513 ii
->ii_indexsz
= sizeof(int);
514 ii
->ii_index
= kmem_alloc(ii
->ii_indexsz
, KM_SLEEP
);
516 ii
->ii_startblk
= bn
;
518 ii
->ii_index
[0] = ix
;
519 bn
+= cs
->sc_cinfo
[ix
].ci_size
;
524 if (ccddebug
& CCDB_INIT
)
525 printiinfo(cs
->sc_itable
);
531 * The following isn't fast or pretty; it doesn't have to be.
535 for (ii
= cs
->sc_itable
; ; ii
++) {
536 /* Allocate space for ii_index. */
537 ii
->ii_indexsz
= sizeof(int) * cs
->sc_nccdisks
;
538 ii
->ii_index
= kmem_alloc(ii
->ii_indexsz
, KM_SLEEP
);
541 * Locate the smallest of the remaining components
544 for (ci
= cs
->sc_cinfo
;
545 ci
< &cs
->sc_cinfo
[cs
->sc_nccdisks
]; ci
++)
546 if (ci
->ci_size
> size
&&
548 ci
->ci_size
< smallci
->ci_size
))
552 * Nobody left, all done
554 if (smallci
== NULL
) {
560 * Record starting logical block and component offset
562 ii
->ii_startblk
= bn
/ cs
->sc_ileave
;
563 ii
->ii_startoff
= lbn
;
566 * Determine how many disks take part in this interleave
567 * and record their indices.
570 for (ci
= cs
->sc_cinfo
;
571 ci
< &cs
->sc_cinfo
[cs
->sc_nccdisks
]; ci
++)
572 if (ci
->ci_size
>= smallci
->ci_size
)
573 ii
->ii_index
[ix
++] = ci
- cs
->sc_cinfo
;
575 bn
+= ix
* (smallci
->ci_size
- size
);
576 lbn
= smallci
->ci_size
/ cs
->sc_ileave
;
577 size
= smallci
->ci_size
;
580 if (ccddebug
& CCDB_INIT
)
581 printiinfo(cs
->sc_itable
);
587 ccdopen(dev_t dev
, int flags
, int fmt
, struct lwp
*l
)
589 int unit
= ccdunit(dev
);
590 struct ccd_softc
*cs
;
591 struct disklabel
*lp
;
592 int error
= 0, part
, pmask
;
595 if (ccddebug
& CCDB_FOLLOW
)
596 printf("ccdopen(0x%"PRIx64
", 0x%x)\n", dev
, flags
);
600 cs
= &ccd_softc
[unit
];
602 mutex_enter(&cs
->sc_dvlock
);
604 lp
= cs
->sc_dkdev
.dk_label
;
606 part
= DISKPART(dev
);
610 * If we're initialized, check to see if there are any other
611 * open partitions. If not, then it's safe to update
612 * the in-core disklabel. Only read the disklabel if it is
615 if ((cs
->sc_flags
& (CCDF_INITED
|CCDF_VLABEL
)) == CCDF_INITED
&&
616 cs
->sc_dkdev
.dk_openmask
== 0)
617 ccdgetdisklabel(dev
);
619 /* Check that the partition exists. */
620 if (part
!= RAW_PART
) {
621 if (((cs
->sc_flags
& CCDF_INITED
) == 0) ||
622 ((part
>= lp
->d_npartitions
) ||
623 (lp
->d_partitions
[part
].p_fstype
== FS_UNUSED
))) {
629 /* Prevent our unit from being unconfigured while open. */
632 cs
->sc_dkdev
.dk_copenmask
|= pmask
;
636 cs
->sc_dkdev
.dk_bopenmask
|= pmask
;
639 cs
->sc_dkdev
.dk_openmask
=
640 cs
->sc_dkdev
.dk_copenmask
| cs
->sc_dkdev
.dk_bopenmask
;
643 mutex_exit(&cs
->sc_dvlock
);
649 ccdclose(dev_t dev
, int flags
, int fmt
, struct lwp
*l
)
651 int unit
= ccdunit(dev
);
652 struct ccd_softc
*cs
;
656 if (ccddebug
& CCDB_FOLLOW
)
657 printf("ccdclose(0x%"PRIx64
", 0x%x)\n", dev
, flags
);
662 cs
= &ccd_softc
[unit
];
664 mutex_enter(&cs
->sc_dvlock
);
666 part
= DISKPART(dev
);
668 /* ...that much closer to allowing unconfiguration... */
671 cs
->sc_dkdev
.dk_copenmask
&= ~(1 << part
);
675 cs
->sc_dkdev
.dk_bopenmask
&= ~(1 << part
);
678 cs
->sc_dkdev
.dk_openmask
=
679 cs
->sc_dkdev
.dk_copenmask
| cs
->sc_dkdev
.dk_bopenmask
;
681 if (cs
->sc_dkdev
.dk_openmask
== 0) {
682 if ((cs
->sc_flags
& CCDF_KLABEL
) == 0)
683 cs
->sc_flags
&= ~CCDF_VLABEL
;
686 mutex_exit(&cs
->sc_dvlock
);
691 ccdbackoff(struct ccd_softc
*cs
)
694 /* XXX Arbitrary, should be a uvm call. */
695 return uvmexp
.free
< (uvmexp
.freemin
>> 1) &&
696 disk_isbusy(&cs
->sc_dkdev
);
700 ccdthread(void *cookie
)
702 struct ccd_softc
*cs
;
707 if (ccddebug
& CCDB_FOLLOW
)
708 printf("ccdthread: hello\n");
711 mutex_enter(cs
->sc_iolock
);
712 while (__predict_true(!cs
->sc_zap
)) {
713 if (bufq_peek(cs
->sc_bufq
) == NULL
) {
715 cv_wait(&cs
->sc_push
, cs
->sc_iolock
);
718 if (ccdbackoff(cs
)) {
719 /* Wait for memory to become available. */
720 (void)cv_timedwait(&cs
->sc_push
, cs
->sc_iolock
, 1);
724 if (ccddebug
& CCDB_FOLLOW
)
725 printf("ccdthread: dispatching I/O\n");
728 mutex_enter(cs
->sc_iolock
);
730 cs
->sc_thread
= NULL
;
731 mutex_exit(cs
->sc_iolock
);
733 if (ccddebug
& CCDB_FOLLOW
)
734 printf("ccdthread: goodbye\n");
740 ccdstrategy(struct buf
*bp
)
742 int unit
= ccdunit(bp
->b_dev
);
743 struct ccd_softc
*cs
= &ccd_softc
[unit
];
745 /* Must be open or reading label. */
746 KASSERT(cs
->sc_dkdev
.dk_openmask
!= 0 ||
747 (cs
->sc_flags
& CCDF_RLABEL
) != 0);
749 mutex_enter(cs
->sc_iolock
);
750 /* Synchronize with device init/uninit. */
751 if (__predict_false((cs
->sc_flags
& CCDF_INITED
) == 0)) {
752 mutex_exit(cs
->sc_iolock
);
754 if (ccddebug
& CCDB_FOLLOW
)
755 printf("ccdstrategy: unit %d: not inited\n", unit
);
758 bp
->b_resid
= bp
->b_bcount
;
763 /* Defer to thread if system is low on memory. */
764 bufq_put(cs
->sc_bufq
, bp
);
765 if (__predict_false(ccdbackoff(cs
))) {
766 mutex_exit(cs
->sc_iolock
);
768 if (ccddebug
& CCDB_FOLLOW
)
769 printf("ccdstrategy: holding off on I/O\n");
777 ccdstart(struct ccd_softc
*cs
)
781 struct disklabel
*lp
;
789 KASSERT(mutex_owned(cs
->sc_iolock
));
791 disk_busy(&cs
->sc_dkdev
);
792 bp
= bufq_get(cs
->sc_bufq
);
796 if (ccddebug
& CCDB_FOLLOW
)
797 printf("ccdstart(%s, %p)\n", cs
->sc_xname
, bp
);
800 /* If it's a nil transfer, wake up the top half now. */
801 if (bp
->b_bcount
== 0)
804 lp
= cs
->sc_dkdev
.dk_label
;
807 * Do bounds checking and adjust transfer. If there's an
808 * error, the bounds check will flag that for us. Convert
809 * the partition relative block number to an absolute.
812 wlabel
= cs
->sc_flags
& (CCDF_WLABEL
|CCDF_LABELLING
);
813 if (DISKPART(bp
->b_dev
) != RAW_PART
) {
814 if (bounds_check_with_label(&cs
->sc_dkdev
, bp
, wlabel
) <= 0)
816 blkno
+= lp
->d_partitions
[DISKPART(bp
->b_dev
)].p_offset
;
818 mutex_exit(cs
->sc_iolock
);
819 bp
->b_rawblkno
= blkno
;
821 /* Allocate the component buffers and start I/O! */
822 bp
->b_resid
= bp
->b_bcount
;
825 for (bcount
= bp
->b_bcount
; bcount
> 0; bcount
-= rcount
) {
826 cbp
= ccdbuffer(cs
, bp
, bn
, addr
, bcount
);
827 rcount
= cbp
->cb_buf
.b_bcount
;
830 vp
= cbp
->cb_buf
.b_vp
;
831 if ((cbp
->cb_buf
.b_flags
& B_READ
) == 0) {
832 mutex_enter(&vp
->v_interlock
);
834 mutex_exit(&vp
->v_interlock
);
836 (void)VOP_STRATEGY(vp
, &cbp
->cb_buf
);
841 disk_unbusy(&cs
->sc_dkdev
, 0, 0);
842 cv_broadcast(&cs
->sc_stop
);
843 cv_broadcast(&cs
->sc_push
);
844 mutex_exit(cs
->sc_iolock
);
845 bp
->b_resid
= bp
->b_bcount
;
850 * Build a component buffer header.
852 static struct ccdbuf
*
853 ccdbuffer(struct ccd_softc
*cs
, struct buf
*bp
, daddr_t bn
, void *addr
,
863 if (ccddebug
& CCDB_IO
)
864 printf("ccdbuffer(%p, %p, %" PRId64
", %p, %ld)\n",
865 cs
, bp
, bn
, addr
, bcount
);
868 * Determine which component bn falls in.
874 * Serially concatenated
876 if (cs
->sc_ileave
== 0) {
880 for (ccdisk
= 0, ci
= &cs
->sc_cinfo
[ccdisk
];
881 cbn
>= sblk
+ ci
->ci_size
;
882 ccdisk
++, ci
= &cs
->sc_cinfo
[ccdisk
])
893 cboff
= cbn
% cs
->sc_ileave
;
894 cbn
/= cs
->sc_ileave
;
895 for (ii
= cs
->sc_itable
; ii
->ii_ndisk
; ii
++)
896 if (ii
->ii_startblk
> cbn
)
899 off
= cbn
- ii
->ii_startblk
;
900 if (ii
->ii_ndisk
== 1) {
901 ccdisk
= ii
->ii_index
[0];
902 cbn
= ii
->ii_startoff
+ off
;
904 ccdisk
= ii
->ii_index
[off
% ii
->ii_ndisk
];
905 cbn
= ii
->ii_startoff
+ off
/ ii
->ii_ndisk
;
907 cbn
*= cs
->sc_ileave
;
908 ci
= &cs
->sc_cinfo
[ccdisk
];
912 * Fill in the component buf structure.
915 KASSERT(cbp
!= NULL
);
916 buf_init(&cbp
->cb_buf
);
917 cbp
->cb_buf
.b_flags
= bp
->b_flags
;
918 cbp
->cb_buf
.b_oflags
= bp
->b_oflags
;
919 cbp
->cb_buf
.b_cflags
= bp
->b_cflags
;
920 cbp
->cb_buf
.b_iodone
= ccdiodone
;
921 cbp
->cb_buf
.b_proc
= bp
->b_proc
;
922 cbp
->cb_buf
.b_dev
= ci
->ci_dev
;
923 cbp
->cb_buf
.b_blkno
= cbn
+ cboff
;
924 cbp
->cb_buf
.b_data
= addr
;
925 cbp
->cb_buf
.b_vp
= ci
->ci_vp
;
926 cbp
->cb_buf
.b_objlock
= &ci
->ci_vp
->v_interlock
;
927 if (cs
->sc_ileave
== 0)
928 cbc
= dbtob((u_int64_t
)(ci
->ci_size
- cbn
));
930 cbc
= dbtob((u_int64_t
)(cs
->sc_ileave
- cboff
));
931 cbp
->cb_buf
.b_bcount
= cbc
< bcount
? cbc
: bcount
;
934 * context for ccdiodone
938 cbp
->cb_comp
= ccdisk
;
940 BIO_COPYPRIO(&cbp
->cb_buf
, bp
);
943 if (ccddebug
& CCDB_IO
)
944 printf(" dev 0x%"PRIx64
"(u%lu): cbp %p bn %" PRId64
" addr %p"
946 ci
->ci_dev
, (unsigned long) (ci
-cs
->sc_cinfo
), cbp
,
947 cbp
->cb_buf
.b_blkno
, cbp
->cb_buf
.b_data
,
948 cbp
->cb_buf
.b_bcount
);
955 * Called at interrupt time.
956 * Mark the component as done and if all components are done,
957 * take a ccd interrupt.
960 ccdiodone(struct buf
*vbp
)
962 struct ccdbuf
*cbp
= (struct ccdbuf
*) vbp
;
963 struct buf
*bp
= cbp
->cb_obp
;
964 struct ccd_softc
*cs
= cbp
->cb_sc
;
968 if (ccddebug
& CCDB_FOLLOW
)
969 printf("ccdiodone(%p)\n", cbp
);
970 if (ccddebug
& CCDB_IO
) {
971 printf("ccdiodone: bp %p bcount %d resid %d\n",
972 bp
, bp
->b_bcount
, bp
->b_resid
);
973 printf(" dev 0x%"PRIx64
"(u%d), cbp %p bn %" PRId64
" addr %p"
975 cbp
->cb_buf
.b_dev
, cbp
->cb_comp
, cbp
,
976 cbp
->cb_buf
.b_blkno
, cbp
->cb_buf
.b_data
,
977 cbp
->cb_buf
.b_bcount
);
981 if (cbp
->cb_buf
.b_error
!= 0) {
982 bp
->b_error
= cbp
->cb_buf
.b_error
;
983 printf("%s: error %d on component %d\n",
984 cs
->sc_xname
, bp
->b_error
, cbp
->cb_comp
);
986 count
= cbp
->cb_buf
.b_bcount
;
987 buf_destroy(&cbp
->cb_buf
);
991 * If all done, "interrupt".
993 mutex_enter(cs
->sc_iolock
);
994 bp
->b_resid
-= count
;
996 panic("ccdiodone: count");
997 if (bp
->b_resid
== 0) {
999 * Request is done for better or worse, wakeup the top half.
1001 if (bp
->b_error
!= 0)
1002 bp
->b_resid
= bp
->b_bcount
;
1003 disk_unbusy(&cs
->sc_dkdev
, (bp
->b_bcount
- bp
->b_resid
),
1004 (bp
->b_flags
& B_READ
));
1005 if (!disk_isbusy(&cs
->sc_dkdev
)) {
1006 if (bufq_peek(cs
->sc_bufq
) != NULL
) {
1007 cv_broadcast(&cs
->sc_push
);
1009 cv_broadcast(&cs
->sc_stop
);
1011 mutex_exit(cs
->sc_iolock
);
1014 mutex_exit(cs
->sc_iolock
);
1019 ccdread(dev_t dev
, struct uio
*uio
, int flags
)
1021 int unit
= ccdunit(dev
);
1022 struct ccd_softc
*cs
;
1025 if (ccddebug
& CCDB_FOLLOW
)
1026 printf("ccdread(0x%"PRIx64
", %p)\n", dev
, uio
);
1030 cs
= &ccd_softc
[unit
];
1032 /* Unlocked advisory check, ccdstrategy check is synchronous. */
1033 if ((cs
->sc_flags
& CCDF_INITED
) == 0)
1036 return (physio(ccdstrategy
, NULL
, dev
, B_READ
, minphys
, uio
));
1041 ccdwrite(dev_t dev
, struct uio
*uio
, int flags
)
1043 int unit
= ccdunit(dev
);
1044 struct ccd_softc
*cs
;
1047 if (ccddebug
& CCDB_FOLLOW
)
1048 printf("ccdwrite(0x%"PRIx64
", %p)\n", dev
, uio
);
1052 cs
= &ccd_softc
[unit
];
1054 /* Unlocked advisory check, ccdstrategy check is synchronous. */
1055 if ((cs
->sc_flags
& CCDF_INITED
) == 0)
1058 return (physio(ccdstrategy
, NULL
, dev
, B_WRITE
, minphys
, uio
));
1062 ccdioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
1064 int unit
= ccdunit(dev
);
1065 int i
, j
, lookedup
= 0, error
= 0;
1067 struct ccd_softc
*cs
;
1068 struct ccd_ioctl
*ccio
= (struct ccd_ioctl
*)data
;
1072 #ifdef __HAVE_OLD_DISKLABEL
1073 struct disklabel newlabel
;
1078 cs
= &ccd_softc
[unit
];
1079 uc
= kauth_cred_get();
1081 /* Must be open for writes for these commands... */
1087 #ifdef __HAVE_OLD_DISKLABEL
1093 if ((flag
& FWRITE
) == 0)
1097 mutex_enter(&cs
->sc_dvlock
);
1099 /* Must be initialized for these... */
1110 #ifdef __HAVE_OLD_DISKLABEL
1114 case ODIOCGDEFLABEL
:
1116 if ((cs
->sc_flags
& CCDF_INITED
) == 0) {
1124 if (cs
->sc_flags
& CCDF_INITED
) {
1129 /* Validate the flags. */
1130 if ((ccio
->ccio_flags
& CCDF_USERMASK
) != ccio
->ccio_flags
) {
1135 if (ccio
->ccio_ndisks
> CCD_MAXNDISKS
||
1136 ccio
->ccio_ndisks
== 0) {
1141 /* Fill in some important bits. */
1142 cs
->sc_ileave
= ccio
->ccio_ileave
;
1143 cs
->sc_nccdisks
= ccio
->ccio_ndisks
;
1144 cs
->sc_flags
= ccio
->ccio_flags
& CCDF_USERMASK
;
1147 * Allocate space for and copy in the array of
1148 * componet pathnames and device numbers.
1150 cpp
= kmem_alloc(ccio
->ccio_ndisks
* sizeof(*cpp
), KM_SLEEP
);
1151 vpp
= kmem_alloc(ccio
->ccio_ndisks
* sizeof(*vpp
), KM_SLEEP
);
1152 error
= copyin(ccio
->ccio_disks
, cpp
,
1153 ccio
->ccio_ndisks
* sizeof(*cpp
));
1155 kmem_free(vpp
, ccio
->ccio_ndisks
* sizeof(*vpp
));
1156 kmem_free(cpp
, ccio
->ccio_ndisks
* sizeof(*cpp
));
1161 if (ccddebug
& CCDB_INIT
)
1162 for (i
= 0; i
< ccio
->ccio_ndisks
; ++i
)
1163 printf("ccdioctl: component %d: %p\n",
1167 for (i
= 0; i
< ccio
->ccio_ndisks
; ++i
) {
1169 if (ccddebug
& CCDB_INIT
)
1170 printf("ccdioctl: lookedup = %d\n", lookedup
);
1172 if ((error
= dk_lookup(cpp
[i
], l
, &vpp
[i
],
1173 UIO_USERSPACE
)) != 0) {
1174 for (j
= 0; j
< lookedup
; ++j
)
1175 (void)vn_close(vpp
[j
], FREAD
|FWRITE
,
1177 kmem_free(vpp
, ccio
->ccio_ndisks
*
1179 kmem_free(cpp
, ccio
->ccio_ndisks
*
1186 /* Attach the disk. */
1187 disk_attach(&cs
->sc_dkdev
);
1188 bufq_alloc(&cs
->sc_bufq
, "fcfs", 0);
1191 * Initialize the ccd. Fills in the softc for us.
1193 if ((error
= ccdinit(cs
, cpp
, vpp
, l
)) != 0) {
1194 for (j
= 0; j
< lookedup
; ++j
)
1195 (void)vn_close(vpp
[j
], FREAD
|FWRITE
,
1197 kmem_free(vpp
, ccio
->ccio_ndisks
* sizeof(*vpp
));
1198 kmem_free(cpp
, ccio
->ccio_ndisks
* sizeof(*cpp
));
1199 disk_detach(&cs
->sc_dkdev
);
1200 bufq_free(cs
->sc_bufq
);
1204 /* We can free the temporary variables now. */
1205 kmem_free(vpp
, ccio
->ccio_ndisks
* sizeof(*vpp
));
1206 kmem_free(cpp
, ccio
->ccio_ndisks
* sizeof(*cpp
));
1209 * The ccd has been successfully initialized, so
1210 * we can place it into the array. Don't try to
1211 * read the disklabel until the disk has been attached,
1212 * because space for the disklabel is allocated
1215 ccio
->ccio_unit
= unit
;
1216 ccio
->ccio_size
= cs
->sc_size
;
1218 /* Try and read the disklabel. */
1219 ccdgetdisklabel(dev
);
1224 * Don't unconfigure if any other partitions are open
1225 * or if both the character and block flavors of this
1226 * partition are open.
1228 part
= DISKPART(dev
);
1229 pmask
= (1 << part
);
1230 if ((cs
->sc_dkdev
.dk_openmask
& ~pmask
) ||
1231 ((cs
->sc_dkdev
.dk_bopenmask
& pmask
) &&
1232 (cs
->sc_dkdev
.dk_copenmask
& pmask
))) {
1237 /* Stop new I/O, wait for in-flight I/O to complete. */
1238 mutex_enter(cs
->sc_iolock
);
1239 cs
->sc_flags
&= ~(CCDF_INITED
|CCDF_VLABEL
);
1241 while (disk_isbusy(&cs
->sc_dkdev
) ||
1242 bufq_peek(cs
->sc_bufq
) != NULL
||
1243 cs
->sc_thread
!= NULL
) {
1244 cv_broadcast(&cs
->sc_push
);
1245 (void)cv_timedwait(&cs
->sc_stop
, cs
->sc_iolock
, hz
);
1247 mutex_exit(cs
->sc_iolock
);
1250 * Free ccd_softc information and clear entry.
1253 /* Close the components and free their pathnames. */
1254 for (i
= 0; i
< cs
->sc_nccdisks
; ++i
) {
1256 * XXX: this close could potentially fail and
1257 * cause Bad Things. Maybe we need to force
1258 * the close to happen?
1261 if (ccddebug
& CCDB_VNODE
)
1262 vprint("CCDIOCCLR: vnode info",
1263 cs
->sc_cinfo
[i
].ci_vp
);
1265 (void)vn_close(cs
->sc_cinfo
[i
].ci_vp
, FREAD
|FWRITE
,
1267 kmem_free(cs
->sc_cinfo
[i
].ci_path
,
1268 cs
->sc_cinfo
[i
].ci_pathlen
);
1271 /* Free interleave index. */
1272 for (i
= 0; cs
->sc_itable
[i
].ii_ndisk
; ++i
) {
1273 kmem_free(cs
->sc_itable
[i
].ii_index
,
1274 cs
->sc_itable
[i
].ii_indexsz
);
1277 /* Free component info and interleave table. */
1278 kmem_free(cs
->sc_cinfo
, cs
->sc_nccdisks
*
1279 sizeof(struct ccdcinfo
));
1280 kmem_free(cs
->sc_itable
, (cs
->sc_nccdisks
+ 1) *
1281 sizeof(struct ccdiinfo
));
1283 /* Detatch the disk. */
1284 disk_detach(&cs
->sc_dkdev
);
1285 bufq_free(cs
->sc_bufq
);
1289 *(struct disklabel
*)data
= *(cs
->sc_dkdev
.dk_label
);
1292 #ifdef __HAVE_OLD_DISKLABEL
1294 newlabel
= *(cs
->sc_dkdev
.dk_label
);
1295 if (newlabel
.d_npartitions
> OLDMAXPARTITIONS
)
1297 memcpy(data
, &newlabel
, sizeof (struct olddisklabel
));
1302 ((struct partinfo
*)data
)->disklab
= cs
->sc_dkdev
.dk_label
;
1303 ((struct partinfo
*)data
)->part
=
1304 &cs
->sc_dkdev
.dk_label
->d_partitions
[DISKPART(dev
)];
1309 * XXX Do we really need to care about having a writable
1310 * file descriptor here?
1312 if ((flag
& FWRITE
) == 0)
1316 * We pass this call down to all components and report
1317 * the first error we encounter.
1319 for (error
= 0, i
= 0; i
< cs
->sc_nccdisks
; i
++) {
1320 j
= VOP_IOCTL(cs
->sc_cinfo
[i
].ci_vp
, cmd
, data
,
1322 if (j
!= 0 && error
== 0)
1329 #ifdef __HAVE_OLD_DISKLABEL
1334 struct disklabel
*lp
;
1335 #ifdef __HAVE_OLD_DISKLABEL
1336 if (cmd
== ODIOCSDINFO
|| cmd
== ODIOCWDINFO
) {
1337 memset(&newlabel
, 0, sizeof newlabel
);
1338 memcpy(&newlabel
, data
, sizeof (struct olddisklabel
));
1342 lp
= (struct disklabel
*)data
;
1344 cs
->sc_flags
|= CCDF_LABELLING
;
1346 error
= setdisklabel(cs
->sc_dkdev
.dk_label
,
1347 lp
, 0, cs
->sc_dkdev
.dk_cpulabel
);
1349 if (cmd
== DIOCWDINFO
1350 #ifdef __HAVE_OLD_DISKLABEL
1351 || cmd
== ODIOCWDINFO
1354 error
= writedisklabel(CCDLABELDEV(dev
),
1355 ccdstrategy
, cs
->sc_dkdev
.dk_label
,
1356 cs
->sc_dkdev
.dk_cpulabel
);
1359 cs
->sc_flags
&= ~CCDF_LABELLING
;
1364 if (*(int *)data
!= 0)
1365 cs
->sc_flags
|= CCDF_KLABEL
;
1367 cs
->sc_flags
&= ~CCDF_KLABEL
;
1371 if (*(int *)data
!= 0)
1372 cs
->sc_flags
|= CCDF_WLABEL
;
1374 cs
->sc_flags
&= ~CCDF_WLABEL
;
1378 ccdgetdefaultlabel(cs
, (struct disklabel
*)data
);
1381 #ifdef __HAVE_OLD_DISKLABEL
1382 case ODIOCGDEFLABEL
:
1383 ccdgetdefaultlabel(cs
, &newlabel
);
1384 if (newlabel
.d_npartitions
> OLDMAXPARTITIONS
)
1386 memcpy(data
, &newlabel
, sizeof (struct olddisklabel
));
1395 mutex_exit(&cs
->sc_dvlock
);
1402 struct ccd_softc
*cs
;
1403 struct disklabel
*lp
;
1404 int part
, unit
, omask
, size
;
1406 unit
= ccdunit(dev
);
1409 cs
= &ccd_softc
[unit
];
1411 if ((cs
->sc_flags
& CCDF_INITED
) == 0)
1414 part
= DISKPART(dev
);
1415 omask
= cs
->sc_dkdev
.dk_openmask
& (1 << part
);
1416 lp
= cs
->sc_dkdev
.dk_label
;
1418 if (omask
== 0 && ccdopen(dev
, 0, S_IFBLK
, curlwp
))
1421 if (lp
->d_partitions
[part
].p_fstype
!= FS_SWAP
)
1424 size
= lp
->d_partitions
[part
].p_size
*
1425 (lp
->d_secsize
/ DEV_BSIZE
);
1427 if (omask
== 0 && ccdclose(dev
, 0, S_IFBLK
, curlwp
))
1434 ccdgetdefaultlabel(struct ccd_softc
*cs
, struct disklabel
*lp
)
1436 struct ccdgeom
*ccg
= &cs
->sc_geom
;
1438 memset(lp
, 0, sizeof(*lp
));
1440 lp
->d_secperunit
= cs
->sc_size
;
1441 lp
->d_secsize
= ccg
->ccg_secsize
;
1442 lp
->d_nsectors
= ccg
->ccg_nsectors
;
1443 lp
->d_ntracks
= ccg
->ccg_ntracks
;
1444 lp
->d_ncylinders
= ccg
->ccg_ncylinders
;
1445 lp
->d_secpercyl
= lp
->d_ntracks
* lp
->d_nsectors
;
1447 strncpy(lp
->d_typename
, "ccd", sizeof(lp
->d_typename
));
1448 lp
->d_type
= DTYPE_CCD
;
1449 strncpy(lp
->d_packname
, "fictitious", sizeof(lp
->d_packname
));
1451 lp
->d_interleave
= 1;
1454 lp
->d_partitions
[RAW_PART
].p_offset
= 0;
1455 lp
->d_partitions
[RAW_PART
].p_size
= cs
->sc_size
;
1456 lp
->d_partitions
[RAW_PART
].p_fstype
= FS_UNUSED
;
1457 lp
->d_npartitions
= RAW_PART
+ 1;
1459 lp
->d_magic
= DISKMAGIC
;
1460 lp
->d_magic2
= DISKMAGIC
;
1461 lp
->d_checksum
= dkcksum(cs
->sc_dkdev
.dk_label
);
1465 * Read the disklabel from the ccd. If one is not present, fake one
1469 ccdgetdisklabel(dev_t dev
)
1471 int unit
= ccdunit(dev
);
1472 struct ccd_softc
*cs
= &ccd_softc
[unit
];
1473 const char *errstring
;
1474 struct disklabel
*lp
= cs
->sc_dkdev
.dk_label
;
1475 struct cpu_disklabel
*clp
= cs
->sc_dkdev
.dk_cpulabel
;
1477 KASSERT(mutex_owned(&cs
->sc_dvlock
));
1479 memset(clp
, 0, sizeof(*clp
));
1481 ccdgetdefaultlabel(cs
, lp
);
1484 * Call the generic disklabel extraction routine.
1486 cs
->sc_flags
|= CCDF_RLABEL
;
1487 if ((cs
->sc_flags
& CCDF_NOLABEL
) != 0)
1488 errstring
= "CCDF_NOLABEL set; ignoring on-disk label";
1490 errstring
= readdisklabel(CCDLABELDEV(dev
), ccdstrategy
,
1491 cs
->sc_dkdev
.dk_label
, cs
->sc_dkdev
.dk_cpulabel
);
1493 ccdmakedisklabel(cs
);
1496 struct partition
*pp
;
1499 * Sanity check whether the found disklabel is valid.
1501 * This is necessary since total size of ccd may vary
1502 * when an interleave is changed even though exactly
1503 * same componets are used, and old disklabel may used
1506 if (lp
->d_secperunit
!= cs
->sc_size
)
1507 printf("WARNING: %s: "
1508 "total sector size in disklabel (%d) != "
1509 "the size of ccd (%lu)\n", cs
->sc_xname
,
1510 lp
->d_secperunit
, (u_long
)cs
->sc_size
);
1511 for (i
= 0; i
< lp
->d_npartitions
; i
++) {
1512 pp
= &lp
->d_partitions
[i
];
1513 if (pp
->p_offset
+ pp
->p_size
> cs
->sc_size
)
1514 printf("WARNING: %s: end of partition `%c' "
1515 "exceeds the size of ccd (%lu)\n",
1516 cs
->sc_xname
, 'a' + i
, (u_long
)cs
->sc_size
);
1521 /* It's actually extremely common to have unlabeled ccds. */
1522 if (ccddebug
& CCDB_LABEL
)
1523 if (errstring
!= NULL
)
1524 printf("%s: %s\n", cs
->sc_xname
, errstring
);
1527 /* In-core label now valid. */
1528 cs
->sc_flags
= (cs
->sc_flags
| CCDF_VLABEL
) & ~CCDF_RLABEL
;
1532 * Take care of things one might want to take care of in the event
1533 * that a disklabel isn't present.
1536 ccdmakedisklabel(struct ccd_softc
*cs
)
1538 struct disklabel
*lp
= cs
->sc_dkdev
.dk_label
;
1541 * For historical reasons, if there's no disklabel present
1542 * the raw partition must be marked FS_BSDFFS.
1544 lp
->d_partitions
[RAW_PART
].p_fstype
= FS_BSDFFS
;
1546 strncpy(lp
->d_packname
, "default label", sizeof(lp
->d_packname
));
1548 lp
->d_checksum
= dkcksum(lp
);
1553 printiinfo(struct ccdiinfo
*ii
)
1557 for (ix
= 0; ii
->ii_ndisk
; ix
++, ii
++) {
1558 printf(" itab[%d]: #dk %d sblk %" PRId64
" soff %" PRId64
,
1559 ix
, ii
->ii_ndisk
, ii
->ii_startblk
, ii
->ii_startoff
);
1560 for (i
= 0; i
< ii
->ii_ndisk
; i
++)
1561 printf(" %d", ii
->ii_index
[i
]);
1569 #include <sys/module.h>
1571 MODULE(MODULE_CLASS_DRIVER
, ccd
, NULL
);
1574 ccd_modcmd(modcmd_t cmd
, void *arg
)
1576 int bmajor
= -1, cmajor
= -1, error
= 0;
1579 case MODULE_CMD_INIT
:
1582 return devsw_attach("ccd", &ccd_bdevsw
, &bmajor
,
1583 &ccd_cdevsw
, &cmajor
);
1586 case MODULE_CMD_FINI
:
1587 return devsw_detach(&ccd_bdevsw
, &ccd_cdevsw
);
1590 case MODULE_CMD_STAT
: