geom_slice.c revision 131568
192108Sphk/*- 292108Sphk * Copyright (c) 2002 Poul-Henning Kamp 392108Sphk * Copyright (c) 2002 Networks Associates Technology, Inc. 492108Sphk * All rights reserved. 592108Sphk * 692108Sphk * This software was developed for the FreeBSD Project by Poul-Henning Kamp 792108Sphk * and NAI Labs, the Security Research Division of Network Associates, Inc. 892108Sphk * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 992108Sphk * DARPA CHATS research program. 1092108Sphk * 1192108Sphk * Redistribution and use in source and binary forms, with or without 1292108Sphk * modification, are permitted provided that the following conditions 1392108Sphk * are met: 1492108Sphk * 1. Redistributions of source code must retain the above copyright 1592108Sphk * notice, this list of conditions and the following disclaimer. 1692108Sphk * 2. Redistributions in binary form must reproduce the above copyright 1792108Sphk * notice, this list of conditions and the following disclaimer in the 1892108Sphk * documentation and/or other materials provided with the distribution. 1992108Sphk * 3. The names of the authors may not be used to endorse or promote 2092108Sphk * products derived from this software without specific prior written 2192108Sphk * permission. 2292108Sphk * 2392108Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2492108Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2592108Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2692108Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2792108Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2892108Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2992108Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3092108Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3192108Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3292108Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3392108Sphk * SUCH DAMAGE. 3492108Sphk */ 3592108Sphk 36116196Sobrien#include <sys/cdefs.h> 37116196Sobrien__FBSDID("$FreeBSD: head/sys/geom/geom_slice.c 131568 2004-07-04 13:44:48Z phk $"); 3892108Sphk 3992108Sphk#include <sys/param.h> 4092108Sphk#include <sys/systm.h> 4192108Sphk#include <sys/kernel.h> 4292108Sphk#include <sys/malloc.h> 4392108Sphk#include <sys/bio.h> 4492108Sphk#include <sys/sysctl.h> 4592108Sphk#include <sys/proc.h> 4692108Sphk#include <sys/kthread.h> 4792108Sphk#include <sys/lock.h> 4892108Sphk#include <sys/mutex.h> 4992108Sphk#include <sys/errno.h> 5092108Sphk#include <sys/sbuf.h> 5192108Sphk#include <geom/geom.h> 5292108Sphk#include <geom/geom_slice.h> 5392108Sphk#include <machine/stdarg.h> 5492108Sphk 5593776Sphkstatic g_orphan_t g_slice_orphan; 5693776Sphkstatic g_access_t g_slice_access; 5793776Sphkstatic g_start_t g_slice_start; 5893776Sphk 5995321Sphkstatic struct g_slicer * 60114493Sphkg_slice_alloc(unsigned nslice, unsigned scsize) 6192108Sphk{ 6292108Sphk struct g_slicer *gsp; 6392108Sphk 64111119Simp gsp = g_malloc(sizeof *gsp, M_WAITOK | M_ZERO); 65131046Spjd if (scsize > 0) 66131046Spjd gsp->softc = g_malloc(scsize, M_WAITOK | M_ZERO); 67131046Spjd else 68131046Spjd gsp->softc = NULL; 69104057Sphk gsp->slices = g_malloc(nslice * sizeof(struct g_slice), 70111119Simp M_WAITOK | M_ZERO); 7192108Sphk gsp->nslice = nslice; 7292108Sphk return (gsp); 7392108Sphk} 7492108Sphk 75114493Sphkstatic void 76114493Sphkg_slice_free(struct g_slicer *gsp) 77114493Sphk{ 78114493Sphk 79114493Sphk g_free(gsp->slices); 80114493Sphk if (gsp->hotspot != NULL) 81114493Sphk g_free(gsp->hotspot); 82131408Spjd if (gsp->softc != NULL) 83131408Spjd g_free(gsp->softc); 84114493Sphk g_free(gsp); 85114493Sphk} 86114493Sphk 8793776Sphkstatic int 8892108Sphkg_slice_access(struct g_provider *pp, int dr, int dw, int de) 8992108Sphk{ 90107953Sphk int error; 91107953Sphk u_int u; 9292108Sphk struct g_geom *gp; 9392108Sphk struct g_consumer *cp; 9492108Sphk struct g_provider *pp2; 9592108Sphk struct g_slicer *gsp; 9692108Sphk struct g_slice *gsl, *gsl2; 9792108Sphk 9892108Sphk gp = pp->geom; 9992108Sphk cp = LIST_FIRST(&gp->consumer); 10092108Sphk KASSERT (cp != NULL, ("g_slice_access but no consumer")); 10192108Sphk gsp = gp->softc; 102131568Sphk if (dr > 0 || dw > 0 || de > 0) { 103131568Sphk gsl = &gsp->slices[pp->index]; 104131568Sphk for (u = 0; u < gsp->nslice; u++) { 105131568Sphk gsl2 = &gsp->slices[u]; 106131568Sphk if (gsl2->length == 0) 107131568Sphk continue; 108131568Sphk if (u == pp->index) 109131568Sphk continue; 110131568Sphk if (gsl->offset + gsl->length <= gsl2->offset) 111131568Sphk continue; 112131568Sphk if (gsl2->offset + gsl2->length <= gsl->offset) 113131568Sphk continue; 114131568Sphk /* overlap */ 115131568Sphk pp2 = gsl2->provider; 116131568Sphk if ((pp->acw + dw) > 0 && pp2->ace > 0) 117131568Sphk return (EPERM); 118131568Sphk if ((pp->ace + de) > 0 && pp2->acw > 0) 119131568Sphk return (EPERM); 120131568Sphk } 12192108Sphk } 12292108Sphk /* On first open, grab an extra "exclusive" bit */ 12392108Sphk if (cp->acr == 0 && cp->acw == 0 && cp->ace == 0) 12492108Sphk de++; 12592108Sphk /* ... and let go of it on last close */ 12692108Sphk if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1) 12792108Sphk de--; 128125755Sphk error = g_access(cp, dr, dw, de); 12992108Sphk return (error); 13092108Sphk} 13192108Sphk 132113713Sphk/* 133113713Sphk * XXX: It should be possible to specify here if we should finish all of the 134113713Sphk * XXX: bio, or only the non-hot bits. This would get messy if there were 135113713Sphk * XXX: two hot spots in the same bio, so for now we simply finish off the 136113713Sphk * XXX: entire bio. Modifying hot data on the way to disk is frowned on 137113713Sphk * XXX: so making that considerably harder is not a bad idea anyway. 138113713Sphk */ 139107522Sphkvoid 140107522Sphkg_slice_finish_hot(struct bio *bp) 141107522Sphk{ 142107522Sphk struct bio *bp2; 143107522Sphk struct g_geom *gp; 144107522Sphk struct g_consumer *cp; 145107522Sphk struct g_slicer *gsp; 146107522Sphk struct g_slice *gsl; 147107953Sphk int idx; 148107522Sphk 149113713Sphk KASSERT(bp->bio_to != NULL, 150113713Sphk ("NULL bio_to in g_slice_finish_hot(%p)", bp)); 151113713Sphk KASSERT(bp->bio_from != NULL, 152113713Sphk ("NULL bio_from in g_slice_finish_hot(%p)", bp)); 153107522Sphk gp = bp->bio_to->geom; 154107522Sphk gsp = gp->softc; 155107522Sphk cp = LIST_FIRST(&gp->consumer); 156107522Sphk KASSERT(cp != NULL, ("NULL consumer in g_slice_finish_hot(%p)", bp)); 157107953Sphk idx = bp->bio_to->index; 158107953Sphk gsl = &gsp->slices[idx]; 159107522Sphk 160107522Sphk bp2 = g_clone_bio(bp); 161107522Sphk if (bp2 == NULL) { 162107522Sphk g_io_deliver(bp, ENOMEM); 163107522Sphk return; 164107522Sphk } 165107522Sphk if (bp2->bio_offset + bp2->bio_length > gsl->length) 166107522Sphk bp2->bio_length = gsl->length - bp2->bio_offset; 167107522Sphk bp2->bio_done = g_std_done; 168107522Sphk bp2->bio_offset += gsl->offset; 169107522Sphk g_io_request(bp2, cp); 170107522Sphk return; 171107522Sphk} 172107522Sphk 17393776Sphkstatic void 17492108Sphkg_slice_start(struct bio *bp) 17592108Sphk{ 17692108Sphk struct bio *bp2; 17792108Sphk struct g_provider *pp; 17892108Sphk struct g_geom *gp; 17992108Sphk struct g_consumer *cp; 18092108Sphk struct g_slicer *gsp; 181113712Sphk struct g_slice *gsl; 182113713Sphk struct g_slice_hot *ghp; 183107953Sphk int idx, error; 184107522Sphk u_int m_index; 18594287Sphk off_t t; 18692108Sphk 18792108Sphk pp = bp->bio_to; 18892108Sphk gp = pp->geom; 18992108Sphk gsp = gp->softc; 19092108Sphk cp = LIST_FIRST(&gp->consumer); 191107953Sphk idx = pp->index; 192107953Sphk gsl = &gsp->slices[idx]; 19392108Sphk switch(bp->bio_cmd) { 19492108Sphk case BIO_READ: 19592108Sphk case BIO_WRITE: 19692108Sphk case BIO_DELETE: 19792108Sphk if (bp->bio_offset > gsl->length) { 198104195Sphk g_io_deliver(bp, EINVAL); /* XXX: EWHAT ? */ 19992108Sphk return; 20092108Sphk } 201107522Sphk /* 202107522Sphk * Check if we collide with any hot spaces, and call the 203107522Sphk * method once if so. 204107522Sphk */ 205107832Sphk t = bp->bio_offset + gsl->offset; 206113712Sphk for (m_index = 0; m_index < gsp->nhotspot; m_index++) { 207113713Sphk ghp = &gsp->hotspot[m_index]; 208113713Sphk if (t >= ghp->offset + ghp->length) 209107522Sphk continue; 210113713Sphk if (t + bp->bio_length <= ghp->offset) 211107522Sphk continue; 212113713Sphk switch(bp->bio_cmd) { 213113713Sphk case BIO_READ: idx = ghp->ract; break; 214113713Sphk case BIO_WRITE: idx = ghp->wact; break; 215113713Sphk case BIO_DELETE: idx = ghp->dact; break; 216113713Sphk } 217113713Sphk switch(idx) { 218113713Sphk case G_SLICE_HOT_ALLOW: 219113713Sphk /* Fall out and continue normal processing */ 220113713Sphk continue; 221113713Sphk case G_SLICE_HOT_DENY: 222113713Sphk g_io_deliver(bp, EROFS); 223107522Sphk return; 224113713Sphk case G_SLICE_HOT_START: 225113713Sphk error = gsp->start(bp); 226113713Sphk if (error && error != EJUSTRETURN) 227113713Sphk g_io_deliver(bp, error); 228107522Sphk return; 229113713Sphk case G_SLICE_HOT_CALL: 230113937Sphk error = g_post_event(gsp->hot, bp, M_NOWAIT, 231113937Sphk gp, NULL); 232113713Sphk if (error) 233113713Sphk g_io_deliver(bp, error); 234113713Sphk return; 235107522Sphk } 236107522Sphk break; 237107522Sphk } 23892108Sphk bp2 = g_clone_bio(bp); 239104057Sphk if (bp2 == NULL) { 240104195Sphk g_io_deliver(bp, ENOMEM); 241104057Sphk return; 242104057Sphk } 24392108Sphk if (bp2->bio_offset + bp2->bio_length > gsl->length) 24492108Sphk bp2->bio_length = gsl->length - bp2->bio_offset; 24592108Sphk bp2->bio_done = g_std_done; 24692108Sphk bp2->bio_offset += gsl->offset; 24792108Sphk g_io_request(bp2, cp); 24892108Sphk return; 24992108Sphk case BIO_GETATTR: 25094287Sphk /* Give the real method a chance to override */ 251113878Sphk if (gsp->start != NULL && gsp->start(bp)) 25294287Sphk return; 25395038Sphk if (!strcmp("GEOM::kerneldump", bp->bio_attribute)) { 25495038Sphk struct g_kerneldump *gkd; 25595038Sphk 25695038Sphk gkd = (struct g_kerneldump *)bp->bio_data; 257107953Sphk gkd->offset += gsp->slices[idx].offset; 258107953Sphk if (gkd->length > gsp->slices[idx].length) 259107953Sphk gkd->length = gsp->slices[idx].length; 26095038Sphk /* now, pass it on downwards... */ 26195038Sphk } 26292108Sphk bp2 = g_clone_bio(bp); 263104081Sphk if (bp2 == NULL) { 264104195Sphk g_io_deliver(bp, ENOMEM); 265104081Sphk return; 266104081Sphk } 26792108Sphk bp2->bio_done = g_std_done; 26892108Sphk g_io_request(bp2, cp); 26992108Sphk break; 27092108Sphk default: 271104195Sphk g_io_deliver(bp, EOPNOTSUPP); 27292108Sphk return; 27392108Sphk } 27492108Sphk} 27592108Sphk 27692108Sphkvoid 277107953Sphkg_slice_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp) 27892108Sphk{ 27992108Sphk struct g_slicer *gsp; 28092108Sphk 28192108Sphk gsp = gp->softc; 282106101Sphk if (indent == NULL) { 283106101Sphk sbuf_printf(sb, " i %u", pp->index); 284106101Sphk sbuf_printf(sb, " o %ju", 285106101Sphk (uintmax_t)gsp->slices[pp->index].offset); 286106101Sphk return; 287106101Sphk } 28892108Sphk if (pp != NULL) { 28992108Sphk sbuf_printf(sb, "%s<index>%u</index>\n", indent, pp->index); 290105540Sphk sbuf_printf(sb, "%s<length>%ju</length>\n", 291105540Sphk indent, (uintmax_t)gsp->slices[pp->index].length); 292105540Sphk sbuf_printf(sb, "%s<seclength>%ju</seclength>\n", indent, 293105540Sphk (uintmax_t)gsp->slices[pp->index].length / 512); 294105540Sphk sbuf_printf(sb, "%s<offset>%ju</offset>\n", indent, 295105540Sphk (uintmax_t)gsp->slices[pp->index].offset); 296105540Sphk sbuf_printf(sb, "%s<secoffset>%ju</secoffset>\n", indent, 297105540Sphk (uintmax_t)gsp->slices[pp->index].offset / 512); 29892108Sphk } 29992108Sphk} 30092108Sphk 301104064Sphkint 302107953Sphkg_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...) 303104064Sphk{ 304110710Sphk struct g_provider *pp, *pp2; 305104064Sphk struct g_slicer *gsp; 306104064Sphk struct g_slice *gsl; 307104064Sphk va_list ap; 308104064Sphk struct sbuf *sb; 309115506Sphk int acc; 310104064Sphk 311104195Sphk g_trace(G_T_TOPOLOGY, "g_slice_config(%s, %d, %d)", 312107953Sphk gp->name, idx, how); 313104064Sphk g_topology_assert(); 314104064Sphk gsp = gp->softc; 315107953Sphk if (idx >= gsp->nslice) 316104064Sphk return(EINVAL); 317107953Sphk gsl = &gsp->slices[idx]; 318104064Sphk pp = gsl->provider; 319104064Sphk if (pp != NULL) 320104064Sphk acc = pp->acr + pp->acw + pp->ace; 321104064Sphk else 322104064Sphk acc = 0; 323104064Sphk if (acc != 0 && how != G_SLICE_CONFIG_FORCE) { 324104064Sphk if (length < gsl->length) 325104064Sphk return(EBUSY); 326104064Sphk if (offset != gsl->offset) 327104064Sphk return(EBUSY); 328104064Sphk } 329104064Sphk /* XXX: check offset + length <= MEDIASIZE */ 330104064Sphk if (how == G_SLICE_CONFIG_CHECK) 331104064Sphk return (0); 332104064Sphk gsl->length = length; 333104064Sphk gsl->offset = offset; 334105542Sphk gsl->sectorsize = sectorsize; 335105957Sphk if (length == 0) { 336105957Sphk if (pp == NULL) 337105957Sphk return (0); 338105957Sphk if (bootverbose) 339105957Sphk printf("GEOM: Deconfigure %s\n", pp->name); 340104064Sphk g_orphan_provider(pp, ENXIO); 341104064Sphk gsl->provider = NULL; 342104064Sphk gsp->nprovider--; 343104064Sphk return (0); 344104064Sphk } 345105957Sphk if (pp != NULL) { 346105957Sphk if (bootverbose) 347105957Sphk printf("GEOM: Reconfigure %s, start %jd length %jd end %jd\n", 348105957Sphk pp->name, (intmax_t)offset, (intmax_t)length, 349105957Sphk (intmax_t)(offset + length - 1)); 350107116Sphk pp->mediasize = gsl->length; 351105957Sphk return (0); 352105957Sphk } 353115949Sphk sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); 354104064Sphk va_start(ap, fmt); 355104064Sphk sbuf_vprintf(sb, fmt, ap); 356115949Sphk va_end(ap); 357104064Sphk sbuf_finish(sb); 358104064Sphk pp = g_new_providerf(gp, sbuf_data(sb)); 359110710Sphk pp2 = LIST_FIRST(&gp->consumer)->provider; 360110710Sphk pp->flags = pp2->flags & G_PF_CANDELETE; 361110713Sphk if (pp2->stripesize > 0) { 362110713Sphk pp->stripesize = pp2->stripesize; 363110713Sphk pp->stripeoffset = (pp2->stripeoffset + offset) % pp->stripesize; 364110713Sphk } 365105957Sphk if (bootverbose) 366105957Sphk printf("GEOM: Configure %s, start %jd length %jd end %jd\n", 367105957Sphk pp->name, (intmax_t)offset, (intmax_t)length, 368105957Sphk (intmax_t)(offset + length - 1)); 369107953Sphk pp->index = idx; 370105542Sphk pp->mediasize = gsl->length; 371105542Sphk pp->sectorsize = gsl->sectorsize; 372104064Sphk gsl->provider = pp; 373104064Sphk gsp->nprovider++; 374104064Sphk g_error_provider(pp, 0); 375104064Sphk sbuf_delete(sb); 376104064Sphk return(0); 377104064Sphk} 378104064Sphk 379113713Sphk/* 380113713Sphk * Configure "hotspots". A hotspot is a piece of the parent device which 381113713Sphk * this particular slicer cares about for some reason. Typically because 382113713Sphk * it contains meta-data used to configure the slicer. 383113713Sphk * A hotspot is identified by its index number. The offset and length are 384113713Sphk * relative to the parent device, and the three "?act" fields specify 385113713Sphk * what action to take on BIO_READ, BIO_DELETE and BIO_WRITE. 386113713Sphk * 387113713Sphk * XXX: There may be a race relative to g_slice_start() here, if an existing 388113713Sphk * XXX: hotspot is changed wile I/O is happening. Should this become a problem 389113713Sphk * XXX: we can protect the hotspot stuff with a mutex. 390113713Sphk */ 391113713Sphk 392107522Sphkint 393113713Sphkg_slice_conf_hot(struct g_geom *gp, u_int idx, off_t offset, off_t length, int ract, int dact, int wact) 394107522Sphk{ 395107522Sphk struct g_slicer *gsp; 396113712Sphk struct g_slice_hot *gsl, *gsl2; 397107522Sphk 398113713Sphk g_trace(G_T_TOPOLOGY, "g_slice_conf_hot(%s, idx: %d, off: %jd, len: %jd)", 399113713Sphk gp->name, idx, (intmax_t)offset, (intmax_t)length); 400107522Sphk g_topology_assert(); 401107522Sphk gsp = gp->softc; 402113712Sphk gsl = gsp->hotspot; 403113712Sphk if(idx >= gsp->nhotspot) { 404111119Simp gsl2 = g_malloc((idx + 1) * sizeof *gsl2, M_WAITOK | M_ZERO); 405113712Sphk if (gsp->hotspot != NULL) 406113712Sphk bcopy(gsp->hotspot, gsl2, gsp->nhotspot * sizeof *gsl2); 407113712Sphk gsp->hotspot = gsl2; 408113712Sphk if (gsp->hotspot != NULL) 409107522Sphk g_free(gsl); 410107522Sphk gsl = gsl2; 411113712Sphk gsp->nhotspot = idx + 1; 412107522Sphk } 413107953Sphk gsl[idx].offset = offset; 414107953Sphk gsl[idx].length = length; 415113878Sphk KASSERT(!((ract | dact | wact) & G_SLICE_HOT_START) 416113878Sphk || gsp->start != NULL, ("G_SLICE_HOT_START but no slice->start")); 417113878Sphk /* XXX: check that we _have_ a start function if HOT_START specified */ 418113713Sphk gsl[idx].ract = ract; 419113713Sphk gsl[idx].dact = dact; 420113713Sphk gsl[idx].wact = wact; 421107522Sphk return (0); 422107522Sphk} 423107522Sphk 424114504Sphkvoid 425114504Sphkg_slice_spoiled(struct g_consumer *cp) 426114504Sphk{ 427114504Sphk struct g_geom *gp; 428114504Sphk struct g_slicer *gsp; 429114504Sphk 430114504Sphk g_topology_assert(); 431114504Sphk gp = cp->geom; 432114504Sphk g_trace(G_T_TOPOLOGY, "g_slice_spoiled(%p/%s)", cp, gp->name); 433114504Sphk gsp = gp->softc; 434114504Sphk gp->softc = NULL; 435114504Sphk g_slice_free(gsp); 436114504Sphk g_wither_geom(gp, ENXIO); 437114504Sphk} 438114504Sphk 439115506Sphkint 440115506Sphkg_slice_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp) 441115506Sphk{ 442115506Sphk 443115506Sphk g_slice_spoiled(LIST_FIRST(&gp->consumer)); 444115506Sphk return (0); 445115506Sphk} 446115506Sphk 44792108Sphkstruct g_geom * 448107522Sphkg_slice_new(struct g_class *mp, u_int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start) 44992108Sphk{ 45092108Sphk struct g_geom *gp; 45192108Sphk struct g_slicer *gsp; 45292108Sphk struct g_consumer *cp; 45392108Sphk void **vp; 454113390Sphk int error; 45592108Sphk 45692108Sphk g_topology_assert(); 45792108Sphk vp = (void **)extrap; 45892108Sphk gp = g_new_geomf(mp, "%s", pp->name); 459114493Sphk gsp = g_slice_alloc(slices, extra); 46092108Sphk gsp->start = start; 46193776Sphk gp->access = g_slice_access; 46293776Sphk gp->orphan = g_slice_orphan; 46392108Sphk gp->softc = gsp; 46492108Sphk gp->start = g_slice_start; 465114504Sphk gp->spoiled = g_slice_spoiled; 46692108Sphk gp->dumpconf = g_slice_dumpconf; 467115506Sphk if (gp->class->destroy_geom == NULL) 468115506Sphk gp->class->destroy_geom = g_slice_destroy_geom; 46992108Sphk cp = g_new_consumer(gp); 470105551Sphk error = g_attach(cp, pp); 471105551Sphk if (error == 0) 472125755Sphk error = g_access(cp, 1, 0, 0); 47392108Sphk if (error) { 474114504Sphk g_wither_geom(gp, ENXIO); 47592108Sphk return (NULL); 47692108Sphk } 477131046Spjd if (extrap != NULL) 478131046Spjd *vp = gsp->softc; 47992108Sphk *cpp = cp; 48092108Sphk return (gp); 48192108Sphk} 48292108Sphk 48393776Sphkstatic void 48493250Sphkg_slice_orphan(struct g_consumer *cp) 48592108Sphk{ 48692108Sphk 48792108Sphk g_trace(G_T_TOPOLOGY, "g_slice_orphan(%p/%s)", cp, cp->provider->name); 48892108Sphk g_topology_assert(); 48992108Sphk KASSERT(cp->provider->error != 0, 49092108Sphk ("g_slice_orphan with error == 0")); 49192108Sphk 492107522Sphk /* XXX: Not good enough we leak the softc and its suballocations */ 493114504Sphk g_slice_free(cp->geom->softc); 494114504Sphk g_wither_geom(cp->geom, cp->provider->error); 49592108Sphk} 496