kernel - Fix filesystem lookup error due to parent directory recyclement race
[dragonfly.git] / sys / sys / ccdvar.h
1 /* $FreeBSD: src/sys/sys/ccdvar.h,v 1.11.2.1 2001/09/11 09:49:54 kris Exp $ */
2 /* $DragonFly: src/sys/sys/ccdvar.h,v 1.7 2007/07/12 00:25:57 dillon Exp $ */
3
4 /*      $NetBSD: ccdvar.h,v 1.7.2.1 1995/10/12 21:30:18 thorpej Exp $   */
5
6 /*
7  * Copyright (c) 1995 Jason R. Thorpe.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed for the NetBSD Project
21  *      by Jason R. Thorpe.
22  * 4. The name of the author may not be used to endorse or promote products
23  *    derived from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37
38 /*
39  * Copyright (c) 1988 University of Utah.
40  * Copyright (c) 1990, 1993
41  *      The Regents of the University of California.  All rights reserved.
42  *
43  * This code is derived from software contributed to Berkeley by
44  * the Systems Programming Group of the University of Utah Computer
45  * Science Department.
46  *
47  * Redistribution and use in source and binary forms, with or without
48  * modification, are permitted provided that the following conditions
49  * are met:
50  * 1. Redistributions of source code must retain the above copyright
51  *    notice, this list of conditions and the following disclaimer.
52  * 2. Redistributions in binary form must reproduce the above copyright
53  *    notice, this list of conditions and the following disclaimer in the
54  *    documentation and/or other materials provided with the distribution.
55  * 3. All advertising materials mentioning features or use of this software
56  *    must display the following acknowledgement:
57  *      This product includes software developed by the University of
58  *      California, Berkeley and its contributors.
59  * 4. Neither the name of the University nor the names of its contributors
60  *    may be used to endorse or promote products derived from this software
61  *    without specific prior written permission.
62  *
63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73  * SUCH DAMAGE.
74  *
75  * from: Utah $Hdr: cdvar.h 1.1 90/07/09$
76  *
77  *      @(#)cdvar.h     8.1 (Berkeley) 6/10/93
78  */
79
80 #ifndef _SYS_CCDVAR_H_
81 #define _SYS_CCDVAR_H_
82
83 /*
84  * Original dynamic configuration support by:
85  *      Jason R. Thorpe <thorpej@nas.nasa.gov>
86  *      Numerical Aerodynamic Simulation Facility
87  *      Mail Stop 258-6
88  *      NASA Ames Research Center
89  *      Moffett Field, CA 94035
90  */
91
92 #ifndef _SYS_TYPES_H_
93 #include <sys/types.h>
94 #endif
95 #ifndef _SYS_CONF_H_
96 #include <sys/conf.h>
97 #endif
98 #ifndef _SYS_DEVICESTAT_H_
99 #include <sys/devicestat.h>
100 #endif
101 #ifndef _SYS_DISK_H_
102 #include <sys/disk.h>
103 #endif
104 #ifndef _SYS_DISKSLICE_H_
105 #include <sys/diskslice.h>
106 #endif
107 #ifndef _SYS_IOCCOM_H_
108 #include <sys/ioccom.h>
109 #endif
110
111 /*
112  * A concatenated disk is described at initialization time by this structure.
113  */
114 struct ccddevice {
115         int             ccd_unit;       /* logical unit of this ccd */
116         int             ccd_interleave; /* interleave (DEV_BSIZE blocks) */
117         int             ccd_flags;      /* misc. information */
118         int             ccd_unused01;   /* disk number */
119         struct vnode    **ccd_vpp;      /* array of component vnodes */
120         char            **ccd_cpp;      /* array of component pathnames */
121         int             ccd_ndev;       /* number of component devices */
122 };
123
124 /*
125  * This structure is used to configure a ccd via ioctl(2).
126  */
127 struct ccd_ioctl {
128         char    **ccio_disks;           /* pointer to component paths */
129         u_int   ccio_ndisks;            /* number of disks to concatenate */
130         int     ccio_ileave;            /* interleave (DEV_BSIZE blocks) */
131         int     ccio_flags;             /* misc. information */
132         int     ccio_unit;              /* unit number: use varies */
133         u_int64_t ccio_size;            /* (returned) size of ccd in sectors */
134 };
135
136 /* ccd_flags */
137 #define CCDF_SWAP       0x01    /* interleave should be dmmax */
138 #define CCDF_UNIFORM    0x02    /* use LCCD of sizes for uniform interleave */
139 #define CCDF_MIRROR     0x04    /* use mirroring */
140 #define CCDF_PARITY     0x08    /* use parity (RAID level 5) */
141
142 /* Mask of user-settable ccd flags. */
143 #define CCDF_USERMASK   (CCDF_SWAP|CCDF_UNIFORM|CCDF_MIRROR|CCDF_PARITY)
144
145 /*
146  * Component info table.
147  * Describes a single component of a concatenated disk.
148  */
149 struct cdev;
150
151 struct ccdcinfo {
152         struct vnode    *ci_vp;                 /* device's vnode */
153         struct cdev     *ci_dev;                /* XXX: device's dev_t */
154         u_int64_t       ci_size;                /* size in sectors */
155         u_int64_t       ci_skip;                /* start skip in sectors */
156         char            *ci_path;               /* path to component */
157         size_t          ci_pathlen;             /* length of component path */
158 };
159
160 /*
161  * Interleave description table.
162  * Computed at boot time to speed irregular-interleave lookups.
163  * The idea is that we interleave in "groups".  First we interleave
164  * evenly over all component disks up to the size of the smallest
165  * component (the first group), then we interleave evenly over all
166  * remaining disks up to the size of the next-smallest (second group),
167  * and so on.
168  *
169  * Each table entry describes the interleave characteristics of one
170  * of these groups.  For example if a concatenated disk consisted of
171  * three components of 5, 3, and 7 DEV_BSIZE blocks interleaved at
172  * DEV_BSIZE (1), the table would have three entries:
173  *
174  *      ndisk   startblk        startoff        dev
175  *      3       0               0               0, 1, 2
176  *      2       9               3               0, 2
177  *      1       13              5               2
178  *      0       -               -               -
179  *
180  * which says that the first nine blocks (0-8) are interleaved over
181  * 3 disks (0, 1, 2) starting at block offset 0 on any component disk,
182  * the next 4 blocks (9-12) are interleaved over 2 disks (0, 2) starting
183  * at component block 3, and the remaining blocks (13-14) are on disk
184  * 2 starting at offset 5.
185  */
186 struct ccdiinfo {
187         int     ii_ndisk;       /* # of disks range is interleaved over */
188         u_int64_t ii_startblk;  /* starting scaled block # for range */
189         u_int64_t ii_startoff;  /* starting component offset (block #) */
190         int     *ii_index;      /* ordered list of components in range */
191 };
192
193 /*
194  * Concatenated disk pseudo-geometry information.
195  */
196 struct ccdgeom {
197         u_int32_t       ccg_secsize;    /* # bytes per sector */
198         u_int32_t       ccg_nsectors;   /* # data sectors per track */
199         u_int32_t       ccg_ntracks;    /* # tracks per cylinder */
200         u_int32_t       ccg_ncylinders; /* # cylinders per unit */
201 };
202
203 /*
204  * A concatenated disk is described after initialization by this structure.
205  */
206 struct ccd_softc {
207         int              sc_unit;               /* logical unit number */
208         int              sc_flags;              /* flags */
209         int              sc_cflags;             /* configuration flags */
210         u_int64_t        sc_size;               /* size of ccd in sectors */
211         int              sc_ileave;             /* interleave */
212         int              sc_maxiosize;          /* maximum I/O size */
213         u_int            sc_nccdisks;           /* number of components */
214 #define CCD_MAXNDISKS    65536
215         struct ccdcinfo  *sc_cinfo;             /* component info */
216         struct ccdiinfo  *sc_itable;            /* interleave table */
217         struct devstat   device_stats;          /* device statistics */
218         struct ccdgeom   sc_geom;               /* pseudo geometry info */
219         struct disk      sc_disk;               /* disk overlay for ccd */
220         struct cdev      *sc_dev;               /* raw ccd device */
221         int              sc_pick;               /* side of mirror picked */
222         off_t            sc_blk[2];             /* mirror localization */
223 };
224
225 /* sc_flags */
226 #define CCDF_INITED     0x01    /* unit has been initialized */
227 #define CCDF_UNUSED02   0x02    /* label area is writable */
228 #define CCDF_UNUSED04   0x04    /* unit is currently being labelled */
229 #define CCDF_WANTED     0x40    /* someone is waiting to obtain a lock */
230 #define CCDF_LOCKED     0x80    /* unit is locked */
231
232 /*
233  * Before you can use a unit, it must be configured with CCDIOCSET.
234  * The configuration persists across opens and closes of the device;
235  * a CCDIOCCLR must be used to reset a configuration.  An attempt to
236  * CCDIOCSET an already active unit will return EBUSY.  Attempts to
237  * CCDIOCCLR an inactive unit will return ENXIO.
238  */
239 #define CCDIOCSET       _IOWR('F', 16, struct ccd_ioctl)   /* enable ccd */
240 #define CCDIOCCLR       _IOW('F', 17, struct ccd_ioctl)    /* disable ccd */
241
242 #endif