1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 9 * DARPA CHATS research program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The names of the authors may not be used to endorse or promote 20 * products derived from this software without specific prior written 21 * permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 *
| 1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 9 * DARPA CHATS research program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The names of the authors may not be used to endorse or promote 20 * products derived from this software without specific prior written 21 * permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 *
|
35 * $FreeBSD: head/sys/geom/geom_disk.c 111220 2003-02-21 19:00:48Z phk $
| 35 * $FreeBSD: head/sys/geom/geom_disk.c 111668 2003-02-28 10:02:02Z phk $
|
36 */ 37 38#include "opt_geom.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/sysctl.h> 44#include <sys/bio.h> 45#include <sys/conf.h> 46#include <sys/disk.h> 47#include <sys/fcntl.h> 48#include <sys/malloc.h> 49#include <sys/sysctl.h> 50#include <sys/stdint.h> 51#include <machine/md_var.h> 52 53#include <sys/lock.h> 54#include <sys/mutex.h> 55#include <geom/geom.h> 56 57static struct mtx g_disk_done_mtx; 58 59static g_access_t g_disk_access; 60 61struct g_class g_disk_class = { 62 "DISK", 63 NULL, 64 NULL, 65 G_CLASS_INITIALIZER 66}; 67 68static void 69g_disk_init(void) 70{ 71 mtx_unlock(&Giant); 72 g_add_class(&g_disk_class); 73 mtx_init(&g_disk_done_mtx, "g_disk_done", MTX_DEF, 0); 74 mtx_lock(&Giant); 75} 76 77DECLARE_GEOM_CLASS_INIT(g_disk_class, g_disk, g_disk_init); 78 79static void __inline 80g_disk_lock_giant(struct disk *dp) 81{ 82 if (dp->d_flags & DISKFLAG_NOGIANT) 83 return; 84 mtx_lock(&Giant); 85} 86 87static void __inline 88g_disk_unlock_giant(struct disk *dp) 89{ 90 if (dp->d_flags & DISKFLAG_NOGIANT) 91 return; 92 mtx_unlock(&Giant); 93} 94 95static int 96g_disk_access(struct g_provider *pp, int r, int w, int e) 97{ 98 struct disk *dp;
| 36 */ 37 38#include "opt_geom.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/sysctl.h> 44#include <sys/bio.h> 45#include <sys/conf.h> 46#include <sys/disk.h> 47#include <sys/fcntl.h> 48#include <sys/malloc.h> 49#include <sys/sysctl.h> 50#include <sys/stdint.h> 51#include <machine/md_var.h> 52 53#include <sys/lock.h> 54#include <sys/mutex.h> 55#include <geom/geom.h> 56 57static struct mtx g_disk_done_mtx; 58 59static g_access_t g_disk_access; 60 61struct g_class g_disk_class = { 62 "DISK", 63 NULL, 64 NULL, 65 G_CLASS_INITIALIZER 66}; 67 68static void 69g_disk_init(void) 70{ 71 mtx_unlock(&Giant); 72 g_add_class(&g_disk_class); 73 mtx_init(&g_disk_done_mtx, "g_disk_done", MTX_DEF, 0); 74 mtx_lock(&Giant); 75} 76 77DECLARE_GEOM_CLASS_INIT(g_disk_class, g_disk, g_disk_init); 78 79static void __inline 80g_disk_lock_giant(struct disk *dp) 81{ 82 if (dp->d_flags & DISKFLAG_NOGIANT) 83 return; 84 mtx_lock(&Giant); 85} 86 87static void __inline 88g_disk_unlock_giant(struct disk *dp) 89{ 90 if (dp->d_flags & DISKFLAG_NOGIANT) 91 return; 92 mtx_unlock(&Giant); 93} 94 95static int 96g_disk_access(struct g_provider *pp, int r, int w, int e) 97{ 98 struct disk *dp;
|
99 dev_t dev;
| |
100 int error; 101 102 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)", 103 pp->name, r, w, e); 104 g_topology_assert(); 105 r += pp->acr; 106 w += pp->acw; 107 e += pp->ace; 108 dp = pp->geom->softc;
| 99 int error; 100 101 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)", 102 pp->name, r, w, e); 103 g_topology_assert(); 104 r += pp->acr; 105 w += pp->acw; 106 e += pp->ace; 107 dp = pp->geom->softc;
|
109 dev = dp->d_dev;
| |
110 error = 0; 111 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
| 108 error = 0; 109 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
|
112 if (dp->d_open != NULL || dp->d_copen != NULL) {
| 110 if (dp->d_open != NULL) {
|
113 g_disk_lock_giant(dp);
| 111 g_disk_lock_giant(dp);
|
114 if (dp->d_open != NULL) 115 error = dp->d_open(dp); 116 else 117 error = dp->d_copen(dev, FREAD|FWRITE, 0, NULL);
| 112 error = dp->d_open(dp);
|
118 if (error != 0) 119 printf("Opened disk %s -> %d\n", 120 pp->name, error); 121 g_disk_unlock_giant(dp); 122 } 123 pp->mediasize = dp->d_mediasize; 124 pp->sectorsize = dp->d_sectorsize; 125 dp->d_flags |= DISKFLAG_OPEN;
| 113 if (error != 0) 114 printf("Opened disk %s -> %d\n", 115 pp->name, error); 116 g_disk_unlock_giant(dp); 117 } 118 pp->mediasize = dp->d_mediasize; 119 pp->sectorsize = dp->d_sectorsize; 120 dp->d_flags |= DISKFLAG_OPEN;
|
126 if (dp->d_maxsize == 0 && dp->d_dev->si_iosize_max != 0) 127 dp->d_maxsize = dp->d_dev->si_iosize_max;
| |
128 if (dp->d_maxsize == 0) { 129 printf("WARNING: Disk drive %s%d has no d_maxsize\n", 130 dp->d_name, dp->d_unit); 131 dp->d_maxsize = DFLTPHYS; 132 } 133 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
| 121 if (dp->d_maxsize == 0) { 122 printf("WARNING: Disk drive %s%d has no d_maxsize\n", 123 dp->d_name, dp->d_unit); 124 dp->d_maxsize = DFLTPHYS; 125 } 126 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
|
134 if (dp->d_close != NULL || dp->d_cclose != NULL) {
| 127 if (dp->d_close != NULL) {
|
135 g_disk_lock_giant(dp);
| 128 g_disk_lock_giant(dp);
|
136 if (dp->d_close != NULL) 137 error = dp->d_close(dp); 138 else 139 error = dp->d_cclose(dev, FREAD|FWRITE, 0, NULL);
| 129 error = dp->d_close(dp);
|
140 if (error != 0) 141 printf("Closed disk %s -> %d\n", 142 pp->name, error); 143 g_disk_unlock_giant(dp); 144 } 145 dp->d_flags &= ~DISKFLAG_OPEN; 146 } 147 return (error); 148} 149 150static void 151g_disk_kerneldump(struct bio *bp, struct disk *dp) 152{ 153 int error; 154 struct g_kerneldump *gkd; 155 struct dumperinfo di; 156 struct g_geom *gp; 157 158 gkd = (struct g_kerneldump*)bp->bio_data; 159 gp = bp->bio_to->geom; 160 g_trace(G_T_TOPOLOGY, "g_disk_kernedump(%s, %jd, %jd)", 161 gp->name, (intmax_t)gkd->offset, (intmax_t)gkd->length); 162 di.dumper = dp->d_dump; 163 di.priv = dp; 164 di.blocksize = dp->d_sectorsize; 165 di.mediaoffset = gkd->offset; 166 di.mediasize = gkd->length; 167 error = set_dumper(&di); 168 g_io_deliver(bp, error); 169} 170 171static void 172g_disk_done(struct bio *bp) 173{ 174 175 /* See "notes" for why we need a mutex here */ 176 /* XXX: will witness accept a mix of Giant/unGiant drivers here ? */ 177 mtx_lock(&g_disk_done_mtx); 178 bp->bio_completed = bp->bio_length - bp->bio_resid; 179 g_std_done(bp); 180 mtx_unlock(&g_disk_done_mtx); 181} 182 183static void 184g_disk_start(struct bio *bp) 185{ 186 struct bio *bp2, *bp3;
| 130 if (error != 0) 131 printf("Closed disk %s -> %d\n", 132 pp->name, error); 133 g_disk_unlock_giant(dp); 134 } 135 dp->d_flags &= ~DISKFLAG_OPEN; 136 } 137 return (error); 138} 139 140static void 141g_disk_kerneldump(struct bio *bp, struct disk *dp) 142{ 143 int error; 144 struct g_kerneldump *gkd; 145 struct dumperinfo di; 146 struct g_geom *gp; 147 148 gkd = (struct g_kerneldump*)bp->bio_data; 149 gp = bp->bio_to->geom; 150 g_trace(G_T_TOPOLOGY, "g_disk_kernedump(%s, %jd, %jd)", 151 gp->name, (intmax_t)gkd->offset, (intmax_t)gkd->length); 152 di.dumper = dp->d_dump; 153 di.priv = dp; 154 di.blocksize = dp->d_sectorsize; 155 di.mediaoffset = gkd->offset; 156 di.mediasize = gkd->length; 157 error = set_dumper(&di); 158 g_io_deliver(bp, error); 159} 160 161static void 162g_disk_done(struct bio *bp) 163{ 164 165 /* See "notes" for why we need a mutex here */ 166 /* XXX: will witness accept a mix of Giant/unGiant drivers here ? */ 167 mtx_lock(&g_disk_done_mtx); 168 bp->bio_completed = bp->bio_length - bp->bio_resid; 169 g_std_done(bp); 170 mtx_unlock(&g_disk_done_mtx); 171} 172 173static void 174g_disk_start(struct bio *bp) 175{ 176 struct bio *bp2, *bp3;
|
187 dev_t dev;
| |
188 struct disk *dp; 189 struct g_ioctl *gio; 190 int error; 191 off_t off; 192 193 dp = bp->bio_to->geom->softc;
| 177 struct disk *dp; 178 struct g_ioctl *gio; 179 int error; 180 off_t off; 181 182 dp = bp->bio_to->geom->softc;
|
194 dev = dp->d_dev;
| |
195 error = EJUSTRETURN; 196 switch(bp->bio_cmd) { 197 case BIO_DELETE: 198 if (!(dp->d_flags & DISKFLAG_CANDELETE)) { 199 error = 0; 200 break; 201 } 202 /* fall-through */ 203 case BIO_READ: 204 case BIO_WRITE: 205 off = 0; 206 bp3 = NULL; 207 bp2 = g_clone_bio(bp); 208 if (bp2 == NULL) { 209 error = ENOMEM; 210 break; 211 } 212 do { 213 bp2->bio_offset += off; 214 bp2->bio_length -= off; 215 bp2->bio_data += off; 216 if (bp2->bio_length > dp->d_maxsize) { 217 /* 218 * XXX: If we have a stripesize we should really 219 * use it here. 220 */ 221 bp2->bio_length = dp->d_maxsize; 222 off += dp->d_maxsize; 223 /* 224 * To avoid a race, we need to grab the next bio 225 * before we schedule this one. See "notes". 226 */ 227 bp3 = g_clone_bio(bp); 228 if (bp3 == NULL) 229 bp->bio_error = ENOMEM; 230 } 231 bp2->bio_done = g_disk_done; 232 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT; 233 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize; 234 bp2->bio_bcount = bp2->bio_length;
| 183 error = EJUSTRETURN; 184 switch(bp->bio_cmd) { 185 case BIO_DELETE: 186 if (!(dp->d_flags & DISKFLAG_CANDELETE)) { 187 error = 0; 188 break; 189 } 190 /* fall-through */ 191 case BIO_READ: 192 case BIO_WRITE: 193 off = 0; 194 bp3 = NULL; 195 bp2 = g_clone_bio(bp); 196 if (bp2 == NULL) { 197 error = ENOMEM; 198 break; 199 } 200 do { 201 bp2->bio_offset += off; 202 bp2->bio_length -= off; 203 bp2->bio_data += off; 204 if (bp2->bio_length > dp->d_maxsize) { 205 /* 206 * XXX: If we have a stripesize we should really 207 * use it here. 208 */ 209 bp2->bio_length = dp->d_maxsize; 210 off += dp->d_maxsize; 211 /* 212 * To avoid a race, we need to grab the next bio 213 * before we schedule this one. See "notes". 214 */ 215 bp3 = g_clone_bio(bp); 216 if (bp3 == NULL) 217 bp->bio_error = ENOMEM; 218 } 219 bp2->bio_done = g_disk_done; 220 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT; 221 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize; 222 bp2->bio_bcount = bp2->bio_length;
|
235 bp2->bio_dev = dev;
| |
236 bp2->bio_disk = dp; 237 g_disk_lock_giant(dp); 238 dp->d_strategy(bp2); 239 g_disk_unlock_giant(dp); 240 bp2 = bp3; 241 bp3 = NULL; 242 } while (bp2 != NULL); 243 break; 244 case BIO_GETATTR: 245 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors)) 246 break; 247 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads)) 248 break; 249 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0)) 250 break; 251 else if (!strcmp(bp->bio_attribute, "GEOM::kerneldump")) 252 g_disk_kerneldump(bp, dp);
| 223 bp2->bio_disk = dp; 224 g_disk_lock_giant(dp); 225 dp->d_strategy(bp2); 226 g_disk_unlock_giant(dp); 227 bp2 = bp3; 228 bp3 = NULL; 229 } while (bp2 != NULL); 230 break; 231 case BIO_GETATTR: 232 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors)) 233 break; 234 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads)) 235 break; 236 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0)) 237 break; 238 else if (!strcmp(bp->bio_attribute, "GEOM::kerneldump")) 239 g_disk_kerneldump(bp, dp);
|
253 else if ((dp->d_ioctl != NULL || dp->d_cioctl != NULL) &&
| 240 else if ((dp->d_ioctl != NULL) &&
|
254 !strcmp(bp->bio_attribute, "GEOM::ioctl") && 255 bp->bio_length == sizeof *gio) { 256 gio = (struct g_ioctl *)bp->bio_data;
| 241 !strcmp(bp->bio_attribute, "GEOM::ioctl") && 242 bp->bio_length == sizeof *gio) { 243 gio = (struct g_ioctl *)bp->bio_data;
|
257 if (dp->d_ioctl != NULL) { 258 gio->func = (d_ioctl_t *)(dp->d_ioctl); 259 gio->dev = dp; 260 } else { 261 gio->func = dp->d_cioctl; 262 gio->dev = dp->d_dev; 263 }
| 244 gio->dev = dp; 245 gio->func = (d_ioctl_t *)(dp->d_ioctl);
|
264 error = EDIRIOCTL; 265 } else 266 error = ENOIOCTL; 267 break; 268 case BIO_SETATTR:
| 246 error = EDIRIOCTL; 247 } else 248 error = ENOIOCTL; 249 break; 250 case BIO_SETATTR:
|
269 if (!strcmp(bp->bio_attribute, "GEOM::ioctl") && 270 bp->bio_length == sizeof *gio) { 271 gio = (struct g_ioctl *)bp->bio_data; 272 gio->func = devsw(dp->d_dev)->d_ioctl; 273 gio->dev = dp->d_dev; 274 error = EDIRIOCTL; 275 } else 276 error = ENOIOCTL;
| 251 error = ENOIOCTL;
|
277 break; 278 default: 279 error = EOPNOTSUPP; 280 break; 281 } 282 if (error != EJUSTRETURN) 283 g_io_deliver(bp, error); 284 return; 285} 286 287static void 288g_disk_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp) 289{ 290 struct disk *dp; 291 292 dp = gp->softc; 293 if (indent == NULL) { 294 sbuf_printf(sb, " hd %u", dp->d_fwheads); 295 sbuf_printf(sb, " sc %u", dp->d_fwsectors); 296 return; 297 } 298 if (pp != NULL) { 299 sbuf_printf(sb, "%s<fwheads>%u</fwheads>\n", 300 indent, dp->d_fwheads); 301 sbuf_printf(sb, "%s<fwsectors>%u</fwsectors>\n", 302 indent, dp->d_fwsectors); 303 } 304} 305 306static void 307g_disk_create(void *arg) 308{ 309 struct g_geom *gp; 310 struct g_provider *pp; 311 struct disk *dp; 312 313 g_topology_assert(); 314 dp = arg; 315 gp = g_new_geomf(&g_disk_class, "%s%d", dp->d_name, dp->d_unit); 316 gp->start = g_disk_start; 317 gp->access = g_disk_access; 318 gp->softc = dp; 319 gp->dumpconf = g_disk_dumpconf; 320 dp->d_geom = gp; 321 pp = g_new_providerf(gp, "%s", gp->name); 322 pp->mediasize = dp->d_mediasize; 323 pp->sectorsize = dp->d_sectorsize; 324 if (dp->d_flags & DISKFLAG_CANDELETE) 325 pp->flags |= G_PF_CANDELETE; 326 pp->stripeoffset = dp->d_stripeoffset; 327 pp->stripesize = dp->d_stripesize; 328 g_error_provider(pp, 0); 329 if (bootverbose) 330 printf("GEOM: new disk %s\n", gp->name); 331} 332 333 334
| 252 break; 253 default: 254 error = EOPNOTSUPP; 255 break; 256 } 257 if (error != EJUSTRETURN) 258 g_io_deliver(bp, error); 259 return; 260} 261 262static void 263g_disk_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp) 264{ 265 struct disk *dp; 266 267 dp = gp->softc; 268 if (indent == NULL) { 269 sbuf_printf(sb, " hd %u", dp->d_fwheads); 270 sbuf_printf(sb, " sc %u", dp->d_fwsectors); 271 return; 272 } 273 if (pp != NULL) { 274 sbuf_printf(sb, "%s<fwheads>%u</fwheads>\n", 275 indent, dp->d_fwheads); 276 sbuf_printf(sb, "%s<fwsectors>%u</fwsectors>\n", 277 indent, dp->d_fwsectors); 278 } 279} 280 281static void 282g_disk_create(void *arg) 283{ 284 struct g_geom *gp; 285 struct g_provider *pp; 286 struct disk *dp; 287 288 g_topology_assert(); 289 dp = arg; 290 gp = g_new_geomf(&g_disk_class, "%s%d", dp->d_name, dp->d_unit); 291 gp->start = g_disk_start; 292 gp->access = g_disk_access; 293 gp->softc = dp; 294 gp->dumpconf = g_disk_dumpconf; 295 dp->d_geom = gp; 296 pp = g_new_providerf(gp, "%s", gp->name); 297 pp->mediasize = dp->d_mediasize; 298 pp->sectorsize = dp->d_sectorsize; 299 if (dp->d_flags & DISKFLAG_CANDELETE) 300 pp->flags |= G_PF_CANDELETE; 301 pp->stripeoffset = dp->d_stripeoffset; 302 pp->stripesize = dp->d_stripesize; 303 g_error_provider(pp, 0); 304 if (bootverbose) 305 printf("GEOM: new disk %s\n", gp->name); 306} 307 308 309
|
335dev_t 336disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, void * unused __unused)
| 310void 311disk_create(int unit, struct disk *dp, int flags, void *unused __unused, void * unused2 __unused)
|
337{
| 312{
|
338 dev_t dev;
| |
339
| 313
|
340 dev = g_malloc(sizeof *dev, M_WAITOK | M_ZERO);
| |
341 dp->d_unit = unit;
| 314 dp->d_unit = unit;
|
342 dp->d_dev = dev;
| |
343 dp->d_flags = flags;
| 315 dp->d_flags = flags;
|
344 dp->d_devsw = cdevsw; 345 dev->si_devsw = cdevsw; 346 if (cdevsw != NULL) { 347 dp->d_copen = cdevsw->d_open; 348 dp->d_cclose = cdevsw->d_close; 349 dp->d_cioctl = cdevsw->d_ioctl; 350 dp->d_strategy = cdevsw->d_strategy; 351 dp->d_dump = cdevsw->d_dump; 352 dp->d_name = cdevsw->d_name; 353 }
| |
354 KASSERT(dp->d_strategy != NULL, ("disk_create need d_strategy")); 355 KASSERT(dp->d_name != NULL, ("disk_create need d_name")); 356 KASSERT(*dp->d_name != 0, ("disk_create need d_name")); 357 KASSERT(strlen(dp->d_name) < SPECNAMELEN - 4, ("disk name too long"));
| 316 KASSERT(dp->d_strategy != NULL, ("disk_create need d_strategy")); 317 KASSERT(dp->d_name != NULL, ("disk_create need d_name")); 318 KASSERT(*dp->d_name != 0, ("disk_create need d_name")); 319 KASSERT(strlen(dp->d_name) < SPECNAMELEN - 4, ("disk name too long"));
|
358 dev->si_disk = dp; 359 dev->si_udev = 0x10002; /* XXX: Needed ? */ 360 dev->si_name = dev->__si_namebuf; 361 sprintf(dev->si_name, "%s%d", dp->d_name, unit);
| |
362 g_call_me(g_disk_create, dp);
| 320 g_call_me(g_disk_create, dp);
|
363 return (dev);
| |
364} 365 366void 367disk_destroy(struct disk *dp) 368{ 369 struct g_geom *gp; 370 371 gp = dp->d_geom;
| 321} 322 323void 324disk_destroy(struct disk *dp) 325{ 326 struct g_geom *gp; 327 328 gp = dp->d_geom;
|
372 g_free(dp->d_dev);
| |
373 gp->flags |= G_GEOM_WITHER; 374 gp->softc = NULL; 375 g_orphan_provider(LIST_FIRST(&gp->provider), ENXIO); 376} 377 378static void 379g_kern_disks(void *p) 380{ 381 struct sbuf *sb; 382 struct g_geom *gp; 383 char *sp; 384 385 sb = p; 386 sp = ""; 387 g_topology_assert(); 388 LIST_FOREACH(gp, &g_disk_class.geom, geom) { 389 sbuf_printf(sb, "%s%s", sp, gp->name); 390 sp = " "; 391 } 392 sbuf_finish(sb); 393 wakeup(sb); 394} 395 396static int 397sysctl_disks(SYSCTL_HANDLER_ARGS) 398{ 399 int error; 400 struct sbuf *sb; 401 402 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); 403 sbuf_clear(sb); 404 g_call_me(g_kern_disks, sb); 405 do { 406 tsleep(sb, PZERO, "kern.disks", hz); 407 } while(!sbuf_done(sb)); 408 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); 409 sbuf_delete(sb); 410 return error; 411} 412 413SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0, 414 sysctl_disks, "A", "names of available disks"); 415
| 329 gp->flags |= G_GEOM_WITHER; 330 gp->softc = NULL; 331 g_orphan_provider(LIST_FIRST(&gp->provider), ENXIO); 332} 333 334static void 335g_kern_disks(void *p) 336{ 337 struct sbuf *sb; 338 struct g_geom *gp; 339 char *sp; 340 341 sb = p; 342 sp = ""; 343 g_topology_assert(); 344 LIST_FOREACH(gp, &g_disk_class.geom, geom) { 345 sbuf_printf(sb, "%s%s", sp, gp->name); 346 sp = " "; 347 } 348 sbuf_finish(sb); 349 wakeup(sb); 350} 351 352static int 353sysctl_disks(SYSCTL_HANDLER_ARGS) 354{ 355 int error; 356 struct sbuf *sb; 357 358 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); 359 sbuf_clear(sb); 360 g_call_me(g_kern_disks, sb); 361 do { 362 tsleep(sb, PZERO, "kern.disks", hz); 363 } while(!sbuf_done(sb)); 364 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); 365 sbuf_delete(sb); 366 return error; 367} 368 369SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0, 370 sysctl_disks, "A", "names of available disks"); 371
|