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 110119 2003-01-30 20:34:23Z phk $
| 35 * $FreeBSD: head/sys/geom/geom_disk.c 110230 2003-02-02 11:59:54Z 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 54#include <sys/lock.h> 55#include <sys/mutex.h> 56#include <geom/geom.h> 57 58static g_access_t g_disk_access; 59 60struct g_class g_disk_class = { 61 "DISK", 62 NULL, 63 NULL, 64 G_CLASS_INITIALIZER 65}; 66 67DECLARE_GEOM_CLASS(g_disk_class, g_disk); 68 69static void __inline 70g_disk_lock_giant(struct disk *dp) 71{ 72 if (dp->d_flags & DISKFLAG_NOGIANT) 73 return; 74 mtx_lock(&Giant); 75} 76 77static void __inline 78g_disk_unlock_giant(struct disk *dp) 79{ 80 if (dp->d_flags & DISKFLAG_NOGIANT) 81 return; 82 mtx_unlock(&Giant); 83} 84 85static int 86g_disk_access(struct g_provider *pp, int r, int w, int e) 87{ 88 struct disk *dp; 89 dev_t dev; 90 int error; 91 92 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)", 93 pp->name, r, w, e); 94 g_topology_assert(); 95 r += pp->acr; 96 w += pp->acw; 97 e += pp->ace; 98 dp = pp->geom->softc; 99 dev = dp->d_dev; 100 error = 0; 101 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) { 102 if (dp->d_open != NULL) { 103 g_disk_lock_giant(dp); 104 error = dp->d_open(dev, FREAD | FWRITE, 0, NULL); 105 if (error != 0) 106 printf("Opened disk %s -> %d\n", 107 pp->name, error); 108 g_disk_unlock_giant(dp); 109 } 110 pp->mediasize = dp->d_mediasize; 111 pp->sectorsize = dp->d_sectorsize; 112 dp->d_flags |= DISKFLAG_OPEN; 113 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) { 114 if (dp->d_close != NULL) { 115 g_disk_lock_giant(dp); 116 error = dp->d_close(dev, FREAD | FWRITE, 0, NULL); 117 if (error != 0) 118 printf("Closed disk %s -> %d\n", 119 pp->name, error); 120 g_disk_unlock_giant(dp); 121 } 122 dp->d_flags &= ~DISKFLAG_OPEN; 123 } 124 return (error); 125} 126 127static void 128g_disk_kerneldump(struct bio *bp, struct disk *dp) 129{ 130 int error; 131 struct g_kerneldump *gkd; 132 struct dumperinfo di; 133 struct g_geom *gp; 134 135 gkd = (struct g_kerneldump*)bp->bio_data; 136 gp = bp->bio_to->geom; 137 g_trace(G_T_TOPOLOGY, "g_disk_kernedump(%s, %jd, %jd)", 138 gp->name, (intmax_t)gkd->offset, (intmax_t)gkd->length); 139 di.dumper = dp->d_dump; 140 di.priv = dp->d_dev; 141 di.blocksize = dp->d_sectorsize; 142 di.mediaoffset = gkd->offset; 143 di.mediasize = gkd->length; 144 error = set_dumper(&di); 145 g_io_deliver(bp, error); 146} 147 148static void 149g_disk_done(struct bio *bp) 150{ 151 struct disk *dp; 152
| 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 54#include <sys/lock.h> 55#include <sys/mutex.h> 56#include <geom/geom.h> 57 58static g_access_t g_disk_access; 59 60struct g_class g_disk_class = { 61 "DISK", 62 NULL, 63 NULL, 64 G_CLASS_INITIALIZER 65}; 66 67DECLARE_GEOM_CLASS(g_disk_class, g_disk); 68 69static void __inline 70g_disk_lock_giant(struct disk *dp) 71{ 72 if (dp->d_flags & DISKFLAG_NOGIANT) 73 return; 74 mtx_lock(&Giant); 75} 76 77static void __inline 78g_disk_unlock_giant(struct disk *dp) 79{ 80 if (dp->d_flags & DISKFLAG_NOGIANT) 81 return; 82 mtx_unlock(&Giant); 83} 84 85static int 86g_disk_access(struct g_provider *pp, int r, int w, int e) 87{ 88 struct disk *dp; 89 dev_t dev; 90 int error; 91 92 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)", 93 pp->name, r, w, e); 94 g_topology_assert(); 95 r += pp->acr; 96 w += pp->acw; 97 e += pp->ace; 98 dp = pp->geom->softc; 99 dev = dp->d_dev; 100 error = 0; 101 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) { 102 if (dp->d_open != NULL) { 103 g_disk_lock_giant(dp); 104 error = dp->d_open(dev, FREAD | FWRITE, 0, NULL); 105 if (error != 0) 106 printf("Opened disk %s -> %d\n", 107 pp->name, error); 108 g_disk_unlock_giant(dp); 109 } 110 pp->mediasize = dp->d_mediasize; 111 pp->sectorsize = dp->d_sectorsize; 112 dp->d_flags |= DISKFLAG_OPEN; 113 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) { 114 if (dp->d_close != NULL) { 115 g_disk_lock_giant(dp); 116 error = dp->d_close(dev, FREAD | FWRITE, 0, NULL); 117 if (error != 0) 118 printf("Closed disk %s -> %d\n", 119 pp->name, error); 120 g_disk_unlock_giant(dp); 121 } 122 dp->d_flags &= ~DISKFLAG_OPEN; 123 } 124 return (error); 125} 126 127static void 128g_disk_kerneldump(struct bio *bp, struct disk *dp) 129{ 130 int error; 131 struct g_kerneldump *gkd; 132 struct dumperinfo di; 133 struct g_geom *gp; 134 135 gkd = (struct g_kerneldump*)bp->bio_data; 136 gp = bp->bio_to->geom; 137 g_trace(G_T_TOPOLOGY, "g_disk_kernedump(%s, %jd, %jd)", 138 gp->name, (intmax_t)gkd->offset, (intmax_t)gkd->length); 139 di.dumper = dp->d_dump; 140 di.priv = dp->d_dev; 141 di.blocksize = dp->d_sectorsize; 142 di.mediaoffset = gkd->offset; 143 di.mediasize = gkd->length; 144 error = set_dumper(&di); 145 g_io_deliver(bp, error); 146} 147 148static void 149g_disk_done(struct bio *bp) 150{ 151 struct disk *dp; 152
|
153 dp = bp->bio_caller1;
| 153 dp = bp->bio_disk;
|
154 bp->bio_completed = bp->bio_length - bp->bio_resid; 155 if (!(dp->d_flags & DISKFLAG_NOGIANT)) { 156 DROP_GIANT(); 157 g_std_done(bp); 158 PICKUP_GIANT(); 159 } else { 160 g_std_done(bp); 161 } 162} 163 164static void 165g_disk_start(struct bio *bp) 166{ 167 struct bio *bp2; 168 dev_t dev; 169 struct disk *dp; 170 struct g_ioctl *gio; 171 int error; 172 173 dp = bp->bio_to->geom->softc; 174 dev = dp->d_dev; 175 error = EJUSTRETURN; 176 switch(bp->bio_cmd) { 177 case BIO_DELETE: 178 if (!(dp->d_flags & DISKFLAG_CANDELETE)) { 179 error = 0; 180 break; 181 } 182 /* fall-through */ 183 case BIO_READ: 184 case BIO_WRITE: 185 bp2 = g_clone_bio(bp); 186 bp2->bio_done = g_disk_done; 187 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT; 188 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize; 189 bp2->bio_bcount = bp2->bio_length; 190 bp2->bio_dev = dev;
| 154 bp->bio_completed = bp->bio_length - bp->bio_resid; 155 if (!(dp->d_flags & DISKFLAG_NOGIANT)) { 156 DROP_GIANT(); 157 g_std_done(bp); 158 PICKUP_GIANT(); 159 } else { 160 g_std_done(bp); 161 } 162} 163 164static void 165g_disk_start(struct bio *bp) 166{ 167 struct bio *bp2; 168 dev_t dev; 169 struct disk *dp; 170 struct g_ioctl *gio; 171 int error; 172 173 dp = bp->bio_to->geom->softc; 174 dev = dp->d_dev; 175 error = EJUSTRETURN; 176 switch(bp->bio_cmd) { 177 case BIO_DELETE: 178 if (!(dp->d_flags & DISKFLAG_CANDELETE)) { 179 error = 0; 180 break; 181 } 182 /* fall-through */ 183 case BIO_READ: 184 case BIO_WRITE: 185 bp2 = g_clone_bio(bp); 186 bp2->bio_done = g_disk_done; 187 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT; 188 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize; 189 bp2->bio_bcount = bp2->bio_length; 190 bp2->bio_dev = dev;
|
191 bp2->bio_caller1 = dp;
| 191 bp2->bio_disk = dp;
|
192 g_disk_lock_giant(dp); 193 dp->d_strategy(bp2); 194 g_disk_unlock_giant(dp); 195 break; 196 case BIO_GETATTR: 197 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors)) 198 break; 199 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads)) 200 break; 201 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0)) 202 break; 203 else if (!strcmp(bp->bio_attribute, "GEOM::kerneldump")) 204 g_disk_kerneldump(bp, dp); 205 else if (dp->d_ioctl != NULL && 206 !strcmp(bp->bio_attribute, "GEOM::ioctl") && 207 bp->bio_length == sizeof *gio) { 208 gio = (struct g_ioctl *)bp->bio_data; 209 gio->func = dp->d_ioctl; 210 gio->dev = dp->d_dev; 211 error = EDIRIOCTL; 212 } else 213 error = ENOIOCTL; 214 break; 215 case BIO_SETATTR: 216 if (!strcmp(bp->bio_attribute, "GEOM::ioctl") && 217 bp->bio_length == sizeof *gio) { 218 gio = (struct g_ioctl *)bp->bio_data; 219 gio->func = devsw(dp->d_dev)->d_ioctl; 220 gio->dev = dp->d_dev; 221 error = EDIRIOCTL; 222 } else 223 error = ENOIOCTL; 224 break; 225 default: 226 error = EOPNOTSUPP; 227 break; 228 } 229 if (error != EJUSTRETURN) 230 g_io_deliver(bp, error); 231 return; 232} 233 234static void 235g_disk_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp) 236{ 237 struct disk *dp; 238 239 dp = gp->softc; 240 if (indent == NULL) { 241 sbuf_printf(sb, " hd %u", dp->d_fwheads); 242 sbuf_printf(sb, " sc %u", dp->d_fwsectors); 243 return; 244 } 245 if (pp != NULL) { 246 sbuf_printf(sb, "%s<fwheads>%u</fwheads>\n", 247 indent, dp->d_fwheads); 248 sbuf_printf(sb, "%s<fwsectors>%u</fwsectors>\n", 249 indent, dp->d_fwsectors); 250 } 251} 252 253static void 254g_disk_create(void *arg) 255{ 256 struct g_geom *gp; 257 struct g_provider *pp; 258 dev_t dev; 259 260 g_topology_assert(); 261 dev = arg; 262 gp = g_new_geomf(&g_disk_class, dev->si_name); 263 gp->start = g_disk_start; 264 gp->access = g_disk_access; 265 gp->softc = dev->si_disk; 266 gp->dumpconf = g_disk_dumpconf; 267 dev->si_disk->d_softc = gp; 268 pp = g_new_providerf(gp, "%s", gp->name); 269 pp->mediasize = dev->si_disk->d_mediasize; 270 pp->sectorsize = dev->si_disk->d_sectorsize; 271 g_error_provider(pp, 0); 272 if (bootverbose) 273 printf("GEOM: new disk %s\n", gp->name); 274} 275 276 277 278dev_t 279disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, void * unused __unused) 280{ 281 dev_t dev; 282 283 dev = g_malloc(sizeof *dev, M_ZERO); 284 dp->d_dev = dev; 285 dp->d_flags = flags; 286 dp->d_devsw = cdevsw; 287 dev->si_devsw = cdevsw; 288 if (cdevsw != NULL) { 289 dp->d_open = cdevsw->d_open; 290 dp->d_close = cdevsw->d_close; 291 dp->d_strategy = cdevsw->d_strategy; 292 dp->d_ioctl = cdevsw->d_ioctl; 293 dp->d_dump = (dumper_t *)cdevsw->d_dump; 294 dp->d_name = cdevsw->d_name; 295 } 296 KASSERT(dp->d_strategy != NULL, ("disk_create need d_strategy")); 297 KASSERT(dp->d_name != NULL, ("disk_create need d_name")); 298 KASSERT(*dp->d_name != 0, ("disk_create need d_name")); 299 dev->si_disk = dp; 300 dev->si_udev = 0x10002; /* XXX: Needed ? */ 301 sprintf(dev->si_name, "%s%d", dp->d_name, unit); 302 g_call_me(g_disk_create, dev); 303 return (dev); 304} 305 306void 307disk_destroy(dev_t dev) 308{ 309 struct disk *dp; 310 struct g_geom *gp; 311 312 dp = dev->si_disk; 313 gp = dp->d_softc; 314 g_free(dev); 315 gp->flags |= G_GEOM_WITHER; 316 gp->softc = NULL; 317 g_orphan_provider(LIST_FIRST(&gp->provider), ENXIO); 318} 319 320static void 321g_kern_disks(void *p) 322{ 323 struct sbuf *sb; 324 struct g_geom *gp; 325 char *sp; 326 327 sb = p; 328 sp = ""; 329 g_topology_assert(); 330 LIST_FOREACH(gp, &g_disk_class.geom, geom) { 331 sbuf_printf(sb, "%s%s", sp, gp->name); 332 sp = " "; 333 } 334 sbuf_finish(sb); 335 wakeup(sb); 336} 337 338static int 339sysctl_disks(SYSCTL_HANDLER_ARGS) 340{ 341 int error; 342 struct sbuf *sb; 343 344 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); 345 sbuf_clear(sb); 346 g_call_me(g_kern_disks, sb); 347 do { 348 tsleep(sb, PZERO, "kern.disks", hz); 349 } while(!sbuf_done(sb)); 350 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); 351 sbuf_delete(sb); 352 return error; 353} 354 355SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0, 356 sysctl_disks, "A", "names of available disks"); 357
| 192 g_disk_lock_giant(dp); 193 dp->d_strategy(bp2); 194 g_disk_unlock_giant(dp); 195 break; 196 case BIO_GETATTR: 197 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors)) 198 break; 199 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads)) 200 break; 201 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0)) 202 break; 203 else if (!strcmp(bp->bio_attribute, "GEOM::kerneldump")) 204 g_disk_kerneldump(bp, dp); 205 else if (dp->d_ioctl != NULL && 206 !strcmp(bp->bio_attribute, "GEOM::ioctl") && 207 bp->bio_length == sizeof *gio) { 208 gio = (struct g_ioctl *)bp->bio_data; 209 gio->func = dp->d_ioctl; 210 gio->dev = dp->d_dev; 211 error = EDIRIOCTL; 212 } else 213 error = ENOIOCTL; 214 break; 215 case BIO_SETATTR: 216 if (!strcmp(bp->bio_attribute, "GEOM::ioctl") && 217 bp->bio_length == sizeof *gio) { 218 gio = (struct g_ioctl *)bp->bio_data; 219 gio->func = devsw(dp->d_dev)->d_ioctl; 220 gio->dev = dp->d_dev; 221 error = EDIRIOCTL; 222 } else 223 error = ENOIOCTL; 224 break; 225 default: 226 error = EOPNOTSUPP; 227 break; 228 } 229 if (error != EJUSTRETURN) 230 g_io_deliver(bp, error); 231 return; 232} 233 234static void 235g_disk_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp) 236{ 237 struct disk *dp; 238 239 dp = gp->softc; 240 if (indent == NULL) { 241 sbuf_printf(sb, " hd %u", dp->d_fwheads); 242 sbuf_printf(sb, " sc %u", dp->d_fwsectors); 243 return; 244 } 245 if (pp != NULL) { 246 sbuf_printf(sb, "%s<fwheads>%u</fwheads>\n", 247 indent, dp->d_fwheads); 248 sbuf_printf(sb, "%s<fwsectors>%u</fwsectors>\n", 249 indent, dp->d_fwsectors); 250 } 251} 252 253static void 254g_disk_create(void *arg) 255{ 256 struct g_geom *gp; 257 struct g_provider *pp; 258 dev_t dev; 259 260 g_topology_assert(); 261 dev = arg; 262 gp = g_new_geomf(&g_disk_class, dev->si_name); 263 gp->start = g_disk_start; 264 gp->access = g_disk_access; 265 gp->softc = dev->si_disk; 266 gp->dumpconf = g_disk_dumpconf; 267 dev->si_disk->d_softc = gp; 268 pp = g_new_providerf(gp, "%s", gp->name); 269 pp->mediasize = dev->si_disk->d_mediasize; 270 pp->sectorsize = dev->si_disk->d_sectorsize; 271 g_error_provider(pp, 0); 272 if (bootverbose) 273 printf("GEOM: new disk %s\n", gp->name); 274} 275 276 277 278dev_t 279disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, void * unused __unused) 280{ 281 dev_t dev; 282 283 dev = g_malloc(sizeof *dev, M_ZERO); 284 dp->d_dev = dev; 285 dp->d_flags = flags; 286 dp->d_devsw = cdevsw; 287 dev->si_devsw = cdevsw; 288 if (cdevsw != NULL) { 289 dp->d_open = cdevsw->d_open; 290 dp->d_close = cdevsw->d_close; 291 dp->d_strategy = cdevsw->d_strategy; 292 dp->d_ioctl = cdevsw->d_ioctl; 293 dp->d_dump = (dumper_t *)cdevsw->d_dump; 294 dp->d_name = cdevsw->d_name; 295 } 296 KASSERT(dp->d_strategy != NULL, ("disk_create need d_strategy")); 297 KASSERT(dp->d_name != NULL, ("disk_create need d_name")); 298 KASSERT(*dp->d_name != 0, ("disk_create need d_name")); 299 dev->si_disk = dp; 300 dev->si_udev = 0x10002; /* XXX: Needed ? */ 301 sprintf(dev->si_name, "%s%d", dp->d_name, unit); 302 g_call_me(g_disk_create, dev); 303 return (dev); 304} 305 306void 307disk_destroy(dev_t dev) 308{ 309 struct disk *dp; 310 struct g_geom *gp; 311 312 dp = dev->si_disk; 313 gp = dp->d_softc; 314 g_free(dev); 315 gp->flags |= G_GEOM_WITHER; 316 gp->softc = NULL; 317 g_orphan_provider(LIST_FIRST(&gp->provider), ENXIO); 318} 319 320static void 321g_kern_disks(void *p) 322{ 323 struct sbuf *sb; 324 struct g_geom *gp; 325 char *sp; 326 327 sb = p; 328 sp = ""; 329 g_topology_assert(); 330 LIST_FOREACH(gp, &g_disk_class.geom, geom) { 331 sbuf_printf(sb, "%s%s", sp, gp->name); 332 sp = " "; 333 } 334 sbuf_finish(sb); 335 wakeup(sb); 336} 337 338static int 339sysctl_disks(SYSCTL_HANDLER_ARGS) 340{ 341 int error; 342 struct sbuf *sb; 343 344 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); 345 sbuf_clear(sb); 346 g_call_me(g_kern_disks, sb); 347 do { 348 tsleep(sb, PZERO, "kern.disks", hz); 349 } while(!sbuf_done(sb)); 350 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); 351 sbuf_delete(sb); 352 return error; 353} 354 355SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0, 356 sysctl_disks, "A", "names of available disks"); 357
|