76}; 77 78static g_taste_t g_dev_taste; 79static g_orphan_t g_dev_orphan; 80 81static struct g_class g_dev_class = { 82 "DEV", 83 g_dev_taste, 84 NULL, 85 G_CLASS_INITIALIZER 86}; 87 88int 89g_dev_print(void) 90{ 91 struct g_geom *gp; 92 93 if (LIST_EMPTY(&g_dev_class.geom)) 94 return (0); 95 printf("List of GEOM disk devices:\n "); 96 LIST_FOREACH(gp, &g_dev_class.geom, geom) 97 printf(" %s", gp->name); 98 printf("\n"); 99 return (1); 100} 101 102/* 103 * XXX: This is disgusting and wrong in every way imaginable: The only reason 104 * XXX: we have a clone function is because of the root-mount hack we currently 105 * XXX: employ. An improvment would be to unregister this cloner once we know 106 * XXX: we no longer need it. Ideally, root-fs would be mounted through DEVFS 107 * XXX: eliminating the need for this hack. 108 */ 109static void 110g_dev_clone(void *arg __unused, char *name, int namelen __unused, dev_t *dev) 111{ 112 struct g_geom *gp; 113 114 if (*dev != NODEV) 115 return; 116 117 g_waitidle(); 118 119 /* g_topology_lock(); */ 120 LIST_FOREACH(gp, &g_dev_class.geom, geom) { 121 if (strcmp(gp->name, name)) 122 continue; 123 *dev = gp->softc; 124 g_trace(G_T_TOPOLOGY, "g_dev_clone(%s) = %p", name, *dev); 125 return; 126 } 127 /* g_topology_unlock(); */ 128 return; 129} 130 131static void 132g_dev_register_cloner(void *foo __unused) 133{ 134 static int once; 135 136 /* XXX: why would this happen more than once ?? */ 137 if (!once) { 138 EVENTHANDLER_REGISTER(dev_clone, g_dev_clone, 0, 1000); 139 once++; 140 } 141} 142 143SYSINIT(geomdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,g_dev_register_cloner,NULL); 144 145static struct g_geom * 146g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) 147{ 148 struct g_geom *gp; 149 struct g_consumer *cp; 150 static int unit = GEOM_MINOR_PROVIDERS; 151 int error; 152 dev_t dev; 153 154 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name); 155 g_topology_assert(); 156 LIST_FOREACH(cp, &pp->consumers, consumers) 157 if (cp->geom->class == mp) 158 return (NULL); 159 gp = g_new_geomf(mp, pp->name); 160 gp->orphan = g_dev_orphan; 161 cp = g_new_consumer(gp); 162 error = g_attach(cp, pp); 163 KASSERT(error == 0, 164 ("g_dev_taste(%s) failed to g_attach, err=%d", pp->name, error)); 165 /* 166 * XXX: I'm not 100% sure we can call make_dev(9) without Giant 167 * yet. Once we can, we don't need to drop topology here either. 168 */ 169 g_topology_unlock(); 170 mtx_lock(&Giant); 171 dev = make_dev(&g_dev_cdevsw, unit2minor(unit++), 172 UID_ROOT, GID_OPERATOR, 0640, gp->name); 173 if (pp->flags & G_PF_CANDELETE) 174 dev->si_flags |= SI_CANDELETE; 175 mtx_unlock(&Giant); 176 g_topology_lock(); 177 dev->si_iosize_max = MAXPHYS; 178 dev->si_stripesize = pp->stripesize; 179 dev->si_stripeoffset = pp->stripeoffset; 180 gp->softc = dev; 181 dev->si_drv1 = gp; 182 dev->si_drv2 = cp; 183 return (gp); 184} 185 186static int 187g_dev_open(dev_t dev, int flags, int fmt, struct thread *td) 188{ 189 struct g_geom *gp; 190 struct g_consumer *cp; 191 int error, r, w, e; 192 193 gp = dev->si_drv1; 194 cp = dev->si_drv2; 195 if (gp == NULL || cp == NULL) 196 return(ENXIO); 197 g_trace(G_T_ACCESS, "g_dev_open(%s, %d, %d, %p)", 198 gp->name, flags, fmt, td); 199 DROP_GIANT(); 200 g_topology_lock(); 201 r = flags & FREAD ? 1 : 0; 202 w = flags & FWRITE ? 1 : 0; 203#ifdef notyet 204 e = flags & O_EXCL ? 1 : 0; 205#else 206 e = 0; 207#endif 208 error = g_access_rel(cp, r, w, e); 209 g_topology_unlock(); 210 PICKUP_GIANT(); 211 g_waitidle(); 212 dev->si_bsize_phys = cp->provider->sectorsize; 213 return(error); 214} 215 216static int 217g_dev_close(dev_t dev, int flags, int fmt, struct thread *td) 218{ 219 struct g_geom *gp; 220 struct g_consumer *cp; 221 int error, r, w, e; 222 223 gp = dev->si_drv1; 224 cp = dev->si_drv2; 225 if (gp == NULL || cp == NULL) 226 return(ENXIO); 227 g_trace(G_T_ACCESS, "g_dev_close(%s, %d, %d, %p)", 228 gp->name, flags, fmt, td); 229 DROP_GIANT(); 230 g_topology_lock(); 231 r = flags & FREAD ? -1 : 0; 232 w = flags & FWRITE ? -1 : 0; 233#ifdef notyet 234 e = flags & O_EXCL ? -1 : 0; 235#else 236 e = 0; 237#endif 238 error = g_access_rel(cp, r, w, e); 239 g_topology_unlock(); 240 PICKUP_GIANT(); 241 g_waitidle(); 242 return (error); 243} 244 245static int 246g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) 247{ 248 struct g_geom *gp, *gp2; 249 struct g_consumer *cp; 250 struct g_provider *pp2; 251 struct g_kerneldump kd; 252 int i, error; 253 u_int u; 254 struct g_ioctl *gio; 255 256 gp = dev->si_drv1; 257 cp = dev->si_drv2; 258 pp2 = cp->provider; 259 gp2 = pp2->geom; 260 gio = NULL; 261 262 error = 0; 263 DROP_GIANT(); 264 265 gio = NULL; 266 i = IOCPARM_LEN(cmd); 267 switch (cmd) { 268 case DIOCGSECTORSIZE: 269 *(u_int *)data = cp->provider->sectorsize; 270 if (*(u_int *)data == 0) 271 error = ENOENT; 272 break; 273 case DIOCGMEDIASIZE: 274 *(off_t *)data = cp->provider->mediasize; 275 if (*(off_t *)data == 0) 276 error = ENOENT; 277 break; 278 case DIOCGFWSECTORS: 279 error = g_io_getattr("GEOM::fwsectors", cp, &i, data); 280 if (error == 0 && *(u_int *)data == 0) 281 error = ENOENT; 282 break; 283 case DIOCGFWHEADS: 284 error = g_io_getattr("GEOM::fwheads", cp, &i, data); 285 if (error == 0 && *(u_int *)data == 0) 286 error = ENOENT; 287 break; 288 case DIOCGFRONTSTUFF: 289 error = g_io_getattr("GEOM::frontstuff", cp, &i, data); 290 break; 291 case DIOCSKERNELDUMP: 292 u = *((u_int *)data); 293 if (!u) { 294 set_dumper(NULL); 295 error = 0; 296 break; 297 } 298 kd.offset = 0; 299 kd.length = OFF_MAX; 300 i = sizeof kd; 301 error = g_io_getattr("GEOM::kerneldump", cp, &i, &kd); 302 if (!error) 303 dev->si_flags |= SI_DUMPDEV; 304 break; 305 306 default: 307 gio = g_malloc(sizeof *gio, M_WAITOK | M_ZERO); 308 gio->cmd = cmd; 309 gio->data = data; 310 gio->fflag = fflag; 311 gio->td = td; 312 i = sizeof *gio; 313 /* 314 * We always issue ioctls as getattr since the direction of data 315 * movement in ioctl is no indication of the ioctl being a "set" 316 * or "get" type ioctl or if such simplistic terms even apply 317 */ 318 error = g_io_getattr("GEOM::ioctl", cp, &i, gio); 319 break; 320 } 321 322 PICKUP_GIANT(); 323 if (error == EDIRIOCTL) { 324 KASSERT(gio != NULL, ("NULL gio but EDIRIOCTL")); 325 KASSERT(gio->func != NULL, ("NULL function but EDIRIOCTL")); 326 error = (gio->func)(gio->dev, cmd, data, fflag, td); 327 } 328 g_waitidle(); 329 if (gio != NULL && (error == EOPNOTSUPP || error == ENOIOCTL)) { 330 if (g_debugflags & G_T_TOPOLOGY) { 331 i = IOCGROUP(cmd); 332 printf("IOCTL(0x%lx) \"%s\"", cmd, gp->name); 333 if (i > ' ' && i <= '~') 334 printf(" '%c'", (int)IOCGROUP(cmd)); 335 else 336 printf(" 0x%lx", IOCGROUP(cmd)); 337 printf("/%ld ", cmd & 0xff); 338 if (cmd & IOC_IN) 339 printf("I"); 340 if (cmd & IOC_OUT) 341 printf("O"); 342 printf("(%ld) = ENOIOCTL\n", IOCPARM_LEN(cmd)); 343 } 344 error = ENOTTY; 345 } 346 if (gio != NULL) 347 g_free(gio); 348 return (error); 349} 350 351static void 352g_dev_done(struct bio *bp2) 353{ 354 struct bio *bp; 355 356 bp = bp2->bio_parent; 357 bp->bio_error = bp2->bio_error; 358 if (bp->bio_error != 0) { 359 g_trace(G_T_BIO, "g_dev_done(%p) had error %d", 360 bp2, bp->bio_error); 361 bp->bio_flags |= BIO_ERROR; 362 } else { 363 g_trace(G_T_BIO, "g_dev_done(%p/%p) resid %ld completed %jd", 364 bp2, bp, bp->bio_resid, (intmax_t)bp2->bio_completed); 365 } 366 bp->bio_resid = bp->bio_bcount - bp2->bio_completed; 367 g_destroy_bio(bp2); 368 mtx_lock(&Giant); 369 biodone(bp); 370 mtx_unlock(&Giant); 371} 372 373static void 374g_dev_strategy(struct bio *bp) 375{ 376 struct g_geom *gp; 377 struct g_consumer *cp; 378 struct bio *bp2; 379 dev_t dev; 380 381 KASSERT(bp->bio_cmd == BIO_READ || 382 bp->bio_cmd == BIO_WRITE || 383 bp->bio_cmd == BIO_DELETE, 384 ("Wrong bio_cmd bio=%p cmd=%d", bp, bp->bio_cmd)); 385 dev = bp->bio_dev; 386 gp = dev->si_drv1; 387 cp = dev->si_drv2; 388 bp2 = g_clone_bio(bp); 389 KASSERT(bp2 != NULL, ("XXX: ENOMEM in a bad place")); 390 bp2->bio_offset = (off_t)bp->bio_blkno << DEV_BSHIFT; 391 KASSERT(bp2->bio_offset >= 0, 392 ("Negative bio_offset (%jd) on bio %p", 393 (intmax_t)bp2->bio_offset, bp)); 394 bp2->bio_length = (off_t)bp->bio_bcount; 395 bp2->bio_done = g_dev_done; 396 g_trace(G_T_BIO, 397 "g_dev_strategy(%p/%p) offset %jd length %jd data %p cmd %d", 398 bp, bp2, (intmax_t)bp->bio_offset, (intmax_t)bp2->bio_length, 399 bp2->bio_data, bp2->bio_cmd); 400 g_io_request(bp2, cp); 401} 402 403/* 404 * g_dev_orphan() 405 * 406 * Called from below when the provider orphaned us. It is our responsibility 407 * to get the access counts back to zero, until we do so the stack below will 408 * not unravel. We must clear the kernel-dump settings, if this is the 409 * current dumpdev. We call destroy_dev(9) to send our dev_t the way of 410 * punched cards and if we have non-zero access counts, we call down with 411 * them negated before we detattch and selfdestruct. 412 */ 413 414static void 415g_dev_orphan(struct g_consumer *cp) 416{ 417 struct g_geom *gp; 418 dev_t dev; 419 420 gp = cp->geom; 421 g_trace(G_T_TOPOLOGY, "g_dev_orphan(%p(%s))", cp, gp->name); 422 g_topology_assert(); 423 if (cp->stat->nop != cp->stat->nend) /* XXX ? */ 424 return; 425 dev = gp->softc; 426 if (dev->si_flags & SI_DUMPDEV) 427 set_dumper(NULL); 428 /* XXX: we may need Giant for now */ 429 destroy_dev(dev); 430 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) 431 g_access_rel(cp, -cp->acr, -cp->acw, -cp->ace); 432 g_detach(cp); 433 g_destroy_consumer(cp); 434 g_destroy_geom(gp); 435} 436 437DECLARE_GEOM_CLASS(g_dev_class, g_dev);
| 71}; 72 73static g_taste_t g_dev_taste; 74static g_orphan_t g_dev_orphan; 75 76static struct g_class g_dev_class = { 77 "DEV", 78 g_dev_taste, 79 NULL, 80 G_CLASS_INITIALIZER 81}; 82 83int 84g_dev_print(void) 85{ 86 struct g_geom *gp; 87 88 if (LIST_EMPTY(&g_dev_class.geom)) 89 return (0); 90 printf("List of GEOM disk devices:\n "); 91 LIST_FOREACH(gp, &g_dev_class.geom, geom) 92 printf(" %s", gp->name); 93 printf("\n"); 94 return (1); 95} 96 97/* 98 * XXX: This is disgusting and wrong in every way imaginable: The only reason 99 * XXX: we have a clone function is because of the root-mount hack we currently 100 * XXX: employ. An improvment would be to unregister this cloner once we know 101 * XXX: we no longer need it. Ideally, root-fs would be mounted through DEVFS 102 * XXX: eliminating the need for this hack. 103 */ 104static void 105g_dev_clone(void *arg __unused, char *name, int namelen __unused, dev_t *dev) 106{ 107 struct g_geom *gp; 108 109 if (*dev != NODEV) 110 return; 111 112 g_waitidle(); 113 114 /* g_topology_lock(); */ 115 LIST_FOREACH(gp, &g_dev_class.geom, geom) { 116 if (strcmp(gp->name, name)) 117 continue; 118 *dev = gp->softc; 119 g_trace(G_T_TOPOLOGY, "g_dev_clone(%s) = %p", name, *dev); 120 return; 121 } 122 /* g_topology_unlock(); */ 123 return; 124} 125 126static void 127g_dev_register_cloner(void *foo __unused) 128{ 129 static int once; 130 131 /* XXX: why would this happen more than once ?? */ 132 if (!once) { 133 EVENTHANDLER_REGISTER(dev_clone, g_dev_clone, 0, 1000); 134 once++; 135 } 136} 137 138SYSINIT(geomdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,g_dev_register_cloner,NULL); 139 140static struct g_geom * 141g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) 142{ 143 struct g_geom *gp; 144 struct g_consumer *cp; 145 static int unit = GEOM_MINOR_PROVIDERS; 146 int error; 147 dev_t dev; 148 149 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name); 150 g_topology_assert(); 151 LIST_FOREACH(cp, &pp->consumers, consumers) 152 if (cp->geom->class == mp) 153 return (NULL); 154 gp = g_new_geomf(mp, pp->name); 155 gp->orphan = g_dev_orphan; 156 cp = g_new_consumer(gp); 157 error = g_attach(cp, pp); 158 KASSERT(error == 0, 159 ("g_dev_taste(%s) failed to g_attach, err=%d", pp->name, error)); 160 /* 161 * XXX: I'm not 100% sure we can call make_dev(9) without Giant 162 * yet. Once we can, we don't need to drop topology here either. 163 */ 164 g_topology_unlock(); 165 mtx_lock(&Giant); 166 dev = make_dev(&g_dev_cdevsw, unit2minor(unit++), 167 UID_ROOT, GID_OPERATOR, 0640, gp->name); 168 if (pp->flags & G_PF_CANDELETE) 169 dev->si_flags |= SI_CANDELETE; 170 mtx_unlock(&Giant); 171 g_topology_lock(); 172 dev->si_iosize_max = MAXPHYS; 173 dev->si_stripesize = pp->stripesize; 174 dev->si_stripeoffset = pp->stripeoffset; 175 gp->softc = dev; 176 dev->si_drv1 = gp; 177 dev->si_drv2 = cp; 178 return (gp); 179} 180 181static int 182g_dev_open(dev_t dev, int flags, int fmt, struct thread *td) 183{ 184 struct g_geom *gp; 185 struct g_consumer *cp; 186 int error, r, w, e; 187 188 gp = dev->si_drv1; 189 cp = dev->si_drv2; 190 if (gp == NULL || cp == NULL) 191 return(ENXIO); 192 g_trace(G_T_ACCESS, "g_dev_open(%s, %d, %d, %p)", 193 gp->name, flags, fmt, td); 194 DROP_GIANT(); 195 g_topology_lock(); 196 r = flags & FREAD ? 1 : 0; 197 w = flags & FWRITE ? 1 : 0; 198#ifdef notyet 199 e = flags & O_EXCL ? 1 : 0; 200#else 201 e = 0; 202#endif 203 error = g_access_rel(cp, r, w, e); 204 g_topology_unlock(); 205 PICKUP_GIANT(); 206 g_waitidle(); 207 dev->si_bsize_phys = cp->provider->sectorsize; 208 return(error); 209} 210 211static int 212g_dev_close(dev_t dev, int flags, int fmt, struct thread *td) 213{ 214 struct g_geom *gp; 215 struct g_consumer *cp; 216 int error, r, w, e; 217 218 gp = dev->si_drv1; 219 cp = dev->si_drv2; 220 if (gp == NULL || cp == NULL) 221 return(ENXIO); 222 g_trace(G_T_ACCESS, "g_dev_close(%s, %d, %d, %p)", 223 gp->name, flags, fmt, td); 224 DROP_GIANT(); 225 g_topology_lock(); 226 r = flags & FREAD ? -1 : 0; 227 w = flags & FWRITE ? -1 : 0; 228#ifdef notyet 229 e = flags & O_EXCL ? -1 : 0; 230#else 231 e = 0; 232#endif 233 error = g_access_rel(cp, r, w, e); 234 g_topology_unlock(); 235 PICKUP_GIANT(); 236 g_waitidle(); 237 return (error); 238} 239 240static int 241g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) 242{ 243 struct g_geom *gp, *gp2; 244 struct g_consumer *cp; 245 struct g_provider *pp2; 246 struct g_kerneldump kd; 247 int i, error; 248 u_int u; 249 struct g_ioctl *gio; 250 251 gp = dev->si_drv1; 252 cp = dev->si_drv2; 253 pp2 = cp->provider; 254 gp2 = pp2->geom; 255 gio = NULL; 256 257 error = 0; 258 DROP_GIANT(); 259 260 gio = NULL; 261 i = IOCPARM_LEN(cmd); 262 switch (cmd) { 263 case DIOCGSECTORSIZE: 264 *(u_int *)data = cp->provider->sectorsize; 265 if (*(u_int *)data == 0) 266 error = ENOENT; 267 break; 268 case DIOCGMEDIASIZE: 269 *(off_t *)data = cp->provider->mediasize; 270 if (*(off_t *)data == 0) 271 error = ENOENT; 272 break; 273 case DIOCGFWSECTORS: 274 error = g_io_getattr("GEOM::fwsectors", cp, &i, data); 275 if (error == 0 && *(u_int *)data == 0) 276 error = ENOENT; 277 break; 278 case DIOCGFWHEADS: 279 error = g_io_getattr("GEOM::fwheads", cp, &i, data); 280 if (error == 0 && *(u_int *)data == 0) 281 error = ENOENT; 282 break; 283 case DIOCGFRONTSTUFF: 284 error = g_io_getattr("GEOM::frontstuff", cp, &i, data); 285 break; 286 case DIOCSKERNELDUMP: 287 u = *((u_int *)data); 288 if (!u) { 289 set_dumper(NULL); 290 error = 0; 291 break; 292 } 293 kd.offset = 0; 294 kd.length = OFF_MAX; 295 i = sizeof kd; 296 error = g_io_getattr("GEOM::kerneldump", cp, &i, &kd); 297 if (!error) 298 dev->si_flags |= SI_DUMPDEV; 299 break; 300 301 default: 302 gio = g_malloc(sizeof *gio, M_WAITOK | M_ZERO); 303 gio->cmd = cmd; 304 gio->data = data; 305 gio->fflag = fflag; 306 gio->td = td; 307 i = sizeof *gio; 308 /* 309 * We always issue ioctls as getattr since the direction of data 310 * movement in ioctl is no indication of the ioctl being a "set" 311 * or "get" type ioctl or if such simplistic terms even apply 312 */ 313 error = g_io_getattr("GEOM::ioctl", cp, &i, gio); 314 break; 315 } 316 317 PICKUP_GIANT(); 318 if (error == EDIRIOCTL) { 319 KASSERT(gio != NULL, ("NULL gio but EDIRIOCTL")); 320 KASSERT(gio->func != NULL, ("NULL function but EDIRIOCTL")); 321 error = (gio->func)(gio->dev, cmd, data, fflag, td); 322 } 323 g_waitidle(); 324 if (gio != NULL && (error == EOPNOTSUPP || error == ENOIOCTL)) { 325 if (g_debugflags & G_T_TOPOLOGY) { 326 i = IOCGROUP(cmd); 327 printf("IOCTL(0x%lx) \"%s\"", cmd, gp->name); 328 if (i > ' ' && i <= '~') 329 printf(" '%c'", (int)IOCGROUP(cmd)); 330 else 331 printf(" 0x%lx", IOCGROUP(cmd)); 332 printf("/%ld ", cmd & 0xff); 333 if (cmd & IOC_IN) 334 printf("I"); 335 if (cmd & IOC_OUT) 336 printf("O"); 337 printf("(%ld) = ENOIOCTL\n", IOCPARM_LEN(cmd)); 338 } 339 error = ENOTTY; 340 } 341 if (gio != NULL) 342 g_free(gio); 343 return (error); 344} 345 346static void 347g_dev_done(struct bio *bp2) 348{ 349 struct bio *bp; 350 351 bp = bp2->bio_parent; 352 bp->bio_error = bp2->bio_error; 353 if (bp->bio_error != 0) { 354 g_trace(G_T_BIO, "g_dev_done(%p) had error %d", 355 bp2, bp->bio_error); 356 bp->bio_flags |= BIO_ERROR; 357 } else { 358 g_trace(G_T_BIO, "g_dev_done(%p/%p) resid %ld completed %jd", 359 bp2, bp, bp->bio_resid, (intmax_t)bp2->bio_completed); 360 } 361 bp->bio_resid = bp->bio_bcount - bp2->bio_completed; 362 g_destroy_bio(bp2); 363 mtx_lock(&Giant); 364 biodone(bp); 365 mtx_unlock(&Giant); 366} 367 368static void 369g_dev_strategy(struct bio *bp) 370{ 371 struct g_geom *gp; 372 struct g_consumer *cp; 373 struct bio *bp2; 374 dev_t dev; 375 376 KASSERT(bp->bio_cmd == BIO_READ || 377 bp->bio_cmd == BIO_WRITE || 378 bp->bio_cmd == BIO_DELETE, 379 ("Wrong bio_cmd bio=%p cmd=%d", bp, bp->bio_cmd)); 380 dev = bp->bio_dev; 381 gp = dev->si_drv1; 382 cp = dev->si_drv2; 383 bp2 = g_clone_bio(bp); 384 KASSERT(bp2 != NULL, ("XXX: ENOMEM in a bad place")); 385 bp2->bio_offset = (off_t)bp->bio_blkno << DEV_BSHIFT; 386 KASSERT(bp2->bio_offset >= 0, 387 ("Negative bio_offset (%jd) on bio %p", 388 (intmax_t)bp2->bio_offset, bp)); 389 bp2->bio_length = (off_t)bp->bio_bcount; 390 bp2->bio_done = g_dev_done; 391 g_trace(G_T_BIO, 392 "g_dev_strategy(%p/%p) offset %jd length %jd data %p cmd %d", 393 bp, bp2, (intmax_t)bp->bio_offset, (intmax_t)bp2->bio_length, 394 bp2->bio_data, bp2->bio_cmd); 395 g_io_request(bp2, cp); 396} 397 398/* 399 * g_dev_orphan() 400 * 401 * Called from below when the provider orphaned us. It is our responsibility 402 * to get the access counts back to zero, until we do so the stack below will 403 * not unravel. We must clear the kernel-dump settings, if this is the 404 * current dumpdev. We call destroy_dev(9) to send our dev_t the way of 405 * punched cards and if we have non-zero access counts, we call down with 406 * them negated before we detattch and selfdestruct. 407 */ 408 409static void 410g_dev_orphan(struct g_consumer *cp) 411{ 412 struct g_geom *gp; 413 dev_t dev; 414 415 gp = cp->geom; 416 g_trace(G_T_TOPOLOGY, "g_dev_orphan(%p(%s))", cp, gp->name); 417 g_topology_assert(); 418 if (cp->stat->nop != cp->stat->nend) /* XXX ? */ 419 return; 420 dev = gp->softc; 421 if (dev->si_flags & SI_DUMPDEV) 422 set_dumper(NULL); 423 /* XXX: we may need Giant for now */ 424 destroy_dev(dev); 425 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) 426 g_access_rel(cp, -cp->acr, -cp->acw, -cp->ace); 427 g_detach(cp); 428 g_destroy_consumer(cp); 429 g_destroy_geom(gp); 430} 431 432DECLARE_GEOM_CLASS(g_dev_class, g_dev);
|