geom_slice.c revision 107953
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 * $FreeBSD: head/sys/geom/geom_slice.c 107953 2002-12-16 22:33:27Z phk $
3692108Sphk */
3792108Sphk
3892108Sphk
3992108Sphk#include <sys/param.h>
40105540Sphk#include <sys/stdint.h>
4192108Sphk#ifndef _KERNEL
4292108Sphk#include <stdio.h>
4392108Sphk#include <unistd.h>
4492108Sphk#include <stdlib.h>
4592108Sphk#include <signal.h>
4696952Sphk#include <string.h>
4792108Sphk#include <err.h>
4892108Sphk#else
4992108Sphk#include <sys/systm.h>
5092108Sphk#include <sys/kernel.h>
5192108Sphk#include <sys/malloc.h>
5292108Sphk#include <sys/bio.h>
5392108Sphk#include <sys/sysctl.h>
5492108Sphk#include <sys/proc.h>
5592108Sphk#include <sys/kthread.h>
5692108Sphk#include <sys/lock.h>
5792108Sphk#include <sys/mutex.h>
5892108Sphk#endif
5992108Sphk#include <sys/errno.h>
6092108Sphk#include <sys/sbuf.h>
6192108Sphk#include <geom/geom.h>
6292108Sphk#include <geom/geom_slice.h>
6392108Sphk#include <machine/stdarg.h>
6492108Sphk
6593776Sphkstatic g_orphan_t g_slice_orphan;
6693776Sphkstatic g_access_t g_slice_access;
6793776Sphkstatic g_start_t g_slice_start;
6893776Sphk
6995321Sphkstatic struct g_slicer *
7092108Sphkg_slice_init(unsigned nslice, unsigned scsize)
7192108Sphk{
7292108Sphk	struct g_slicer *gsp;
7392108Sphk
7492371Sphk	gsp = g_malloc(sizeof *gsp, M_WAITOK | M_ZERO);
7592371Sphk	gsp->softc = g_malloc(scsize, M_WAITOK | M_ZERO);
76104057Sphk	gsp->slices = g_malloc(nslice * sizeof(struct g_slice),
77104057Sphk	    M_WAITOK | M_ZERO);
7892108Sphk	gsp->nslice = nslice;
7992108Sphk	return (gsp);
8092108Sphk}
8192108Sphk
8293776Sphkstatic int
8392108Sphkg_slice_access(struct g_provider *pp, int dr, int dw, int de)
8492108Sphk{
85107953Sphk	int error;
86107953Sphk	u_int u;
8792108Sphk	struct g_geom *gp;
8892108Sphk	struct g_consumer *cp;
8992108Sphk	struct g_provider *pp2;
9092108Sphk	struct g_slicer *gsp;
9192108Sphk	struct g_slice *gsl, *gsl2;
9292108Sphk
9392108Sphk	gp = pp->geom;
9492108Sphk	cp = LIST_FIRST(&gp->consumer);
9592108Sphk	KASSERT (cp != NULL, ("g_slice_access but no consumer"));
9692108Sphk	gsp = gp->softc;
9792108Sphk	gsl = &gsp->slices[pp->index];
98107953Sphk	for (u = 0; u < gsp->nslice; u++) {
99107953Sphk		gsl2 = &gsp->slices[u];
10092108Sphk		if (gsl2->length == 0)
10192108Sphk			continue;
102107953Sphk		if (u == pp->index)
10392108Sphk			continue;
10492108Sphk		if (gsl->offset + gsl->length <= gsl2->offset)
10592108Sphk			continue;
10692108Sphk		if (gsl2->offset + gsl2->length <= gsl->offset)
10792108Sphk			continue;
10892108Sphk		/* overlap */
10992108Sphk		pp2 = gsl2->provider;
11092108Sphk		if ((pp->acw + dw) > 0 && pp2->ace > 0)
11192108Sphk			return (EPERM);
11292108Sphk		if ((pp->ace + de) > 0 && pp2->acw > 0)
11392108Sphk			return (EPERM);
11492108Sphk	}
11592108Sphk	/* On first open, grab an extra "exclusive" bit */
11692108Sphk	if (cp->acr == 0 && cp->acw == 0 && cp->ace == 0)
11792108Sphk		de++;
11892108Sphk	/* ... and let go of it on last close */
11992108Sphk	if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1)
12092108Sphk		de--;
12192108Sphk	error = g_access_rel(cp, dr, dw, de);
12292108Sphk	return (error);
12392108Sphk}
12492108Sphk
125107522Sphkvoid
126107522Sphkg_slice_finish_hot(struct bio *bp)
127107522Sphk{
128107522Sphk	struct bio *bp2;
129107522Sphk	struct g_geom *gp;
130107522Sphk	struct g_consumer *cp;
131107522Sphk	struct g_slicer *gsp;
132107522Sphk	struct g_slice *gsl;
133107953Sphk	int idx;
134107522Sphk
135107522Sphk	KASSERT(bp->bio_to != NULL, ("NULL bio_to in g_slice_finish_hot(%p)", bp));
136107522Sphk	KASSERT(bp->bio_from != NULL, ("NULL bio_from in g_slice_finish_hot(%p)", bp));
137107522Sphk	gp = bp->bio_to->geom;
138107522Sphk	gsp = gp->softc;
139107522Sphk	cp = LIST_FIRST(&gp->consumer);
140107522Sphk	KASSERT(cp != NULL, ("NULL consumer in g_slice_finish_hot(%p)", bp));
141107953Sphk	idx = bp->bio_to->index;
142107953Sphk	gsl = &gsp->slices[idx];
143107522Sphk
144107522Sphk	bp2 = g_clone_bio(bp);
145107522Sphk	if (bp2 == NULL) {
146107522Sphk		g_io_deliver(bp, ENOMEM);
147107522Sphk		return;
148107522Sphk	}
149107522Sphk	if (bp2->bio_offset + bp2->bio_length > gsl->length)
150107522Sphk		bp2->bio_length = gsl->length - bp2->bio_offset;
151107522Sphk	bp2->bio_done = g_std_done;
152107522Sphk	bp2->bio_offset += gsl->offset;
153107522Sphk	g_io_request(bp2, cp);
154107522Sphk	return;
155107522Sphk}
156107522Sphk
15793776Sphkstatic void
15892108Sphkg_slice_start(struct bio *bp)
15992108Sphk{
16092108Sphk	struct bio *bp2;
16192108Sphk	struct g_provider *pp;
16292108Sphk	struct g_geom *gp;
16392108Sphk	struct g_consumer *cp;
16492108Sphk	struct g_slicer *gsp;
165107522Sphk	struct g_slice *gsl, *gmp;
166107953Sphk	int idx, error;
167107522Sphk	u_int m_index;
16894287Sphk	off_t t;
16992108Sphk
17092108Sphk	pp = bp->bio_to;
17192108Sphk	gp = pp->geom;
17292108Sphk	gsp = gp->softc;
17392108Sphk	cp = LIST_FIRST(&gp->consumer);
174107953Sphk	idx = pp->index;
175107953Sphk	gsl = &gsp->slices[idx];
17692108Sphk	switch(bp->bio_cmd) {
17792108Sphk	case BIO_READ:
17892108Sphk	case BIO_WRITE:
17992108Sphk	case BIO_DELETE:
18092108Sphk		if (bp->bio_offset > gsl->length) {
181104195Sphk			g_io_deliver(bp, EINVAL); /* XXX: EWHAT ? */
18292108Sphk			return;
18392108Sphk		}
184107522Sphk		/*
185107522Sphk		 * Check if we collide with any hot spaces, and call the
186107522Sphk		 * method once if so.
187107522Sphk		 */
188107832Sphk		t = bp->bio_offset + gsl->offset;
189107522Sphk		for (m_index = 0; m_index < gsp->nhot; m_index++) {
190107522Sphk			gmp = &gsp->hot[m_index];
191107832Sphk			if (t >= gmp->offset + gmp->length)
192107522Sphk				continue;
193107832Sphk			if (t + bp->bio_length <= gmp->offset)
194107522Sphk				continue;
195107522Sphk			error = gsp->start(bp);
196107522Sphk			if (error == EJUSTRETURN)
197107522Sphk				return;
198107522Sphk			else if (error) {
199107522Sphk				g_io_deliver(bp, error);
200107522Sphk				return;
201107522Sphk			}
202107522Sphk			break;
203107522Sphk		}
20492108Sphk		bp2 = g_clone_bio(bp);
205104057Sphk		if (bp2 == NULL) {
206104195Sphk			g_io_deliver(bp, ENOMEM);
207104057Sphk			return;
208104057Sphk		}
20992108Sphk		if (bp2->bio_offset + bp2->bio_length > gsl->length)
21092108Sphk			bp2->bio_length = gsl->length - bp2->bio_offset;
21192108Sphk		bp2->bio_done = g_std_done;
21292108Sphk		bp2->bio_offset += gsl->offset;
21392108Sphk		g_io_request(bp2, cp);
21492108Sphk		return;
21592108Sphk	case BIO_GETATTR:
21692108Sphk	case BIO_SETATTR:
21794287Sphk		/* Give the real method a chance to override */
21894287Sphk		if (gsp->start(bp))
21994287Sphk			return;
22094287Sphk		if (!strcmp("GEOM::frontstuff", bp->bio_attribute)) {
22194287Sphk			t = gsp->cfrontstuff;
22294287Sphk			if (gsp->frontstuff > t)
22394287Sphk				t = gsp->frontstuff;
22494287Sphk			t -= gsl->offset;
22594287Sphk			if (t < 0)
22694287Sphk				t = 0;
22794287Sphk			if (t > gsl->length)
22894287Sphk				t = gsl->length;
22998066Sphk			g_handleattr_off_t(bp, "GEOM::frontstuff", t);
23092108Sphk			return;
23194287Sphk		}
23295310Sphk#ifdef _KERNEL
23395038Sphk		if (!strcmp("GEOM::kerneldump", bp->bio_attribute)) {
23495038Sphk			struct g_kerneldump *gkd;
23595038Sphk
23695038Sphk			gkd = (struct g_kerneldump *)bp->bio_data;
237107953Sphk			gkd->offset += gsp->slices[idx].offset;
238107953Sphk			if (gkd->length > gsp->slices[idx].length)
239107953Sphk				gkd->length = gsp->slices[idx].length;
24095038Sphk			/* now, pass it on downwards... */
24195038Sphk		}
24295310Sphk#endif
24392108Sphk		bp2 = g_clone_bio(bp);
244104081Sphk		if (bp2 == NULL) {
245104195Sphk			g_io_deliver(bp, ENOMEM);
246104081Sphk			return;
247104081Sphk		}
24892108Sphk		bp2->bio_done = g_std_done;
24992108Sphk		g_io_request(bp2, cp);
25092108Sphk		break;
25192108Sphk	default:
252104195Sphk		g_io_deliver(bp, EOPNOTSUPP);
25392108Sphk		return;
25492108Sphk	}
25592108Sphk}
25692108Sphk
25792108Sphkvoid
258107953Sphkg_slice_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp)
25992108Sphk{
26092108Sphk	struct g_slicer *gsp;
26192108Sphk
26292108Sphk	gsp = gp->softc;
263106101Sphk	if (indent == NULL) {
264106101Sphk		sbuf_printf(sb, " i %u", pp->index);
265106101Sphk		sbuf_printf(sb, " o %ju",
266106101Sphk		    (uintmax_t)gsp->slices[pp->index].offset);
267106101Sphk		return;
268106101Sphk	}
26995323Sphk	if (gp != NULL && (pp == NULL && cp == NULL)) {
270105540Sphk		sbuf_printf(sb, "%s<frontstuff>%ju</frontstuff>\n",
271105540Sphk		    indent, (intmax_t)gsp->frontstuff);
27294287Sphk	}
27392108Sphk	if (pp != NULL) {
27492108Sphk		sbuf_printf(sb, "%s<index>%u</index>\n", indent, pp->index);
275105540Sphk		sbuf_printf(sb, "%s<length>%ju</length>\n",
276105540Sphk		    indent, (uintmax_t)gsp->slices[pp->index].length);
277105540Sphk		sbuf_printf(sb, "%s<seclength>%ju</seclength>\n", indent,
278105540Sphk		    (uintmax_t)gsp->slices[pp->index].length / 512);
279105540Sphk		sbuf_printf(sb, "%s<offset>%ju</offset>\n", indent,
280105540Sphk		    (uintmax_t)gsp->slices[pp->index].offset);
281105540Sphk		sbuf_printf(sb, "%s<secoffset>%ju</secoffset>\n", indent,
282105540Sphk		    (uintmax_t)gsp->slices[pp->index].offset / 512);
28392108Sphk	}
28492108Sphk}
28592108Sphk
286104064Sphkint
287107953Sphkg_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...)
288104064Sphk{
289104064Sphk	struct g_provider *pp;
290104064Sphk	struct g_slicer *gsp;
291104064Sphk	struct g_slice *gsl;
292104064Sphk	va_list ap;
293104064Sphk	struct sbuf *sb;
294104064Sphk	int error, acc;
295104064Sphk
296104195Sphk	g_trace(G_T_TOPOLOGY, "g_slice_config(%s, %d, %d)",
297107953Sphk	     gp->name, idx, how);
298104064Sphk	g_topology_assert();
299104064Sphk	gsp = gp->softc;
300104064Sphk	error = 0;
301107953Sphk	if (idx >= gsp->nslice)
302104064Sphk		return(EINVAL);
303107953Sphk	gsl = &gsp->slices[idx];
304104064Sphk	pp = gsl->provider;
305104064Sphk	if (pp != NULL)
306104064Sphk		acc = pp->acr + pp->acw + pp->ace;
307104064Sphk	else
308104064Sphk		acc = 0;
309104064Sphk	if (acc != 0 && how != G_SLICE_CONFIG_FORCE) {
310104064Sphk		if (length < gsl->length)
311104064Sphk			return(EBUSY);
312104064Sphk		if (offset != gsl->offset)
313104064Sphk			return(EBUSY);
314104064Sphk	}
315104064Sphk	/* XXX: check offset + length <= MEDIASIZE */
316104064Sphk	if (how == G_SLICE_CONFIG_CHECK)
317104064Sphk		return (0);
318104064Sphk	gsl->length = length;
319104064Sphk	gsl->offset = offset;
320105542Sphk	gsl->sectorsize = sectorsize;
321105957Sphk	if (length == 0) {
322105957Sphk		if (pp == NULL)
323105957Sphk			return (0);
324105957Sphk		if (bootverbose)
325105957Sphk			printf("GEOM: Deconfigure %s\n", pp->name);
326104064Sphk		g_orphan_provider(pp, ENXIO);
327104064Sphk		gsl->provider = NULL;
328104064Sphk		gsp->nprovider--;
329104064Sphk		return (0);
330104064Sphk	}
331105957Sphk	if (pp != NULL) {
332105957Sphk		if (bootverbose)
333105957Sphk			printf("GEOM: Reconfigure %s, start %jd length %jd end %jd\n",
334105957Sphk			    pp->name, (intmax_t)offset, (intmax_t)length,
335105957Sphk			    (intmax_t)(offset + length - 1));
336107116Sphk		pp->mediasize = gsl->length;
337105957Sphk		return (0);
338105957Sphk	}
339104064Sphk	va_start(ap, fmt);
340104064Sphk	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
341104064Sphk	sbuf_vprintf(sb, fmt, ap);
342104064Sphk	sbuf_finish(sb);
343104064Sphk	pp = g_new_providerf(gp, sbuf_data(sb));
344105957Sphk	if (bootverbose)
345105957Sphk		printf("GEOM: Configure %s, start %jd length %jd end %jd\n",
346105957Sphk		    pp->name, (intmax_t)offset, (intmax_t)length,
347105957Sphk		    (intmax_t)(offset + length - 1));
348107953Sphk	pp->index = idx;
349105542Sphk	pp->mediasize = gsl->length;
350105542Sphk	pp->sectorsize = gsl->sectorsize;
351104064Sphk	gsl->provider = pp;
352104064Sphk	gsp->nprovider++;
353104064Sphk	g_error_provider(pp, 0);
354104064Sphk	sbuf_delete(sb);
355104064Sphk	return(0);
356104064Sphk}
357104064Sphk
358107522Sphkint
359107953Sphkg_slice_conf_hot(struct g_geom *gp, u_int idx, off_t offset, off_t length)
360107522Sphk{
361107522Sphk	struct g_slicer *gsp;
362107522Sphk	struct g_slice *gsl, *gsl2;
363107522Sphk
364107522Sphk	g_trace(G_T_TOPOLOGY, "g_slice_conf_hot()");
365107522Sphk	g_topology_assert();
366107522Sphk	gsp = gp->softc;
367107522Sphk	gsl = gsp->hot;
368107953Sphk	if(idx >= gsp->nhot) {
369107953Sphk		gsl2 = g_malloc((idx + 1) * sizeof *gsl2, M_WAITOK | M_ZERO);
370107522Sphk		if (gsp->hot != NULL)
371107522Sphk			bcopy(gsp->hot, gsl2, gsp->nhot * sizeof *gsl2);
372107522Sphk		gsp->hot = gsl2;
373107522Sphk		if (gsp->hot != NULL)
374107522Sphk			g_free(gsl);
375107522Sphk		gsl = gsl2;
376107953Sphk		gsp->nhot = idx + 1;
377107522Sphk	}
378107522Sphk	if (bootverbose)
379107522Sphk		printf("GEOM: Add %s hot[%d] start %jd length %jd end %jd\n",
380107953Sphk		    gp->name, idx, (intmax_t)offset, (intmax_t)length,
381107522Sphk		    (intmax_t)(offset + length - 1));
382107953Sphk	gsl[idx].offset = offset;
383107953Sphk	gsl[idx].length = length;
384107522Sphk	return (0);
385107522Sphk}
386107522Sphk
38792108Sphkstruct g_provider *
388107953Sphkg_slice_addslice(struct g_geom *gp, int idx, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...)
38992108Sphk{
39092108Sphk	struct g_provider *pp;
39192108Sphk	struct g_slicer *gsp;
39292108Sphk	va_list ap;
39392108Sphk	struct sbuf *sb;
39492108Sphk
39592108Sphk	g_trace(G_T_TOPOLOGY, "g_slice_addslice()");
396104064Sphk	g_topology_assert();
39792108Sphk	gsp = gp->softc;
39892108Sphk	va_start(ap, fmt);
39992108Sphk	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
40092108Sphk	sbuf_vprintf(sb, fmt, ap);
40192108Sphk	sbuf_finish(sb);
40292108Sphk	pp = g_new_providerf(gp, sbuf_data(sb));
40392108Sphk
404107953Sphk	pp->index = idx;
405107953Sphk	gsp->slices[idx].length = length;
406107953Sphk	gsp->slices[idx].offset = offset;
407107953Sphk	gsp->slices[idx].provider = pp;
408107953Sphk	gsp->slices[idx].sectorsize = sectorsize;
409107953Sphk	pp->mediasize = gsp->slices[idx].length;
410107953Sphk	pp->sectorsize = gsp->slices[idx].sectorsize;
41192108Sphk	sbuf_delete(sb);
412105957Sphk	if (bootverbose)
413105957Sphk		printf("GEOM: Add %s, start %jd length %jd end %jd\n",
414105957Sphk		    pp->name, (intmax_t)offset, (intmax_t)length,
415105957Sphk		    (intmax_t)(offset + length - 1));
41692108Sphk	return(pp);
41792108Sphk}
41892108Sphk
41992108Sphkstruct g_geom *
420107522Sphkg_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)
42192108Sphk{
42292108Sphk	struct g_geom *gp;
42392108Sphk	struct g_slicer *gsp;
42492108Sphk	struct g_consumer *cp;
42592108Sphk	void **vp;
42694287Sphk	int error, i;
42792108Sphk
42892108Sphk	g_topology_assert();
42992108Sphk	vp = (void **)extrap;
43092108Sphk	gp = g_new_geomf(mp, "%s", pp->name);
43192108Sphk	gsp = g_slice_init(slices, extra);
43292108Sphk	gsp->start = start;
43393776Sphk	gp->access = g_slice_access;
43493776Sphk	gp->orphan = g_slice_orphan;
43592108Sphk	gp->softc = gsp;
43692108Sphk	gp->start = g_slice_start;
43792108Sphk	gp->spoiled = g_std_spoiled;
43892108Sphk	gp->dumpconf = g_slice_dumpconf;
43992108Sphk	cp = g_new_consumer(gp);
440105551Sphk	error = g_attach(cp, pp);
441105551Sphk	if (error == 0)
442105551Sphk		error = g_access_rel(cp, 1, 0, 0);
44392108Sphk	if (error) {
444105551Sphk		if (cp->provider != NULL)
445105551Sphk			g_detach(cp);
44692108Sphk		g_destroy_consumer(cp);
44792371Sphk		g_free(gsp->slices);
44892108Sphk		g_free(gp->softc);
44992108Sphk		g_destroy_geom(gp);
45092108Sphk		return (NULL);
45192108Sphk	}
45294287Sphk	/* Find out if there are any magic bytes on the consumer */
45394287Sphk	i = sizeof gsp->cfrontstuff;
45494287Sphk	error = g_io_getattr("GEOM::frontstuff", cp, &i, &gsp->cfrontstuff);
45594287Sphk	if (error)
45694287Sphk		gsp->cfrontstuff = 0;
45792108Sphk	*vp = gsp->softc;
45892108Sphk	*cpp = cp;
45992108Sphk	return (gp);
46092108Sphk}
46192108Sphk
46293776Sphkstatic void
46393250Sphkg_slice_orphan(struct g_consumer *cp)
46492108Sphk{
46592108Sphk	struct g_geom *gp;
46692108Sphk	struct g_provider *pp;
46792108Sphk	int error;
46892108Sphk
46992108Sphk	g_trace(G_T_TOPOLOGY, "g_slice_orphan(%p/%s)", cp, cp->provider->name);
47092108Sphk	g_topology_assert();
47192108Sphk	KASSERT(cp->provider->error != 0,
47292108Sphk	    ("g_slice_orphan with error == 0"));
47392108Sphk
47492108Sphk	gp = cp->geom;
475107522Sphk	/* XXX: Not good enough we leak the softc and its suballocations */
47692108Sphk	gp->flags |= G_GEOM_WITHER;
47792108Sphk	error = cp->provider->error;
47892108Sphk	LIST_FOREACH(pp, &gp->provider, provider)
47992108Sphk		g_orphan_provider(pp, error);
48092108Sphk	return;
48192108Sphk}
482