geom_subr.c revision 114495
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_subr.c 114495 2003-05-02 06:15:27Z phk $
36 */
37
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/devicestat.h>
42#include <sys/kernel.h>
43#include <sys/malloc.h>
44#include <sys/bio.h>
45#include <sys/sysctl.h>
46#include <sys/proc.h>
47#include <sys/kthread.h>
48#include <sys/lock.h>
49#include <sys/mutex.h>
50#include <sys/errno.h>
51#include <sys/sbuf.h>
52#include <geom/geom.h>
53#include <geom/geom_int.h>
54#include <machine/stdarg.h>
55
56struct class_list_head g_classes = LIST_HEAD_INITIALIZER(g_classes);
57static struct g_tailq_head geoms = TAILQ_HEAD_INITIALIZER(geoms);
58static int g_nproviders;
59char *g_wait_event, *g_wait_up, *g_wait_down, *g_wait_sim;
60
61static int g_ignition;
62
63
64/*
65 * This event offers a new class a chance to taste all preexisting providers.
66 */
67static void
68g_new_class_event(void *arg, int flag)
69{
70	struct g_class *mp2, *mp;
71	struct g_geom *gp;
72	struct g_provider *pp;
73
74	g_topology_assert();
75	if (flag == EV_CANCEL)
76		return;
77	if (g_shutdown)
78		return;
79	mp2 = arg;
80	if (mp2->taste == NULL)
81		return;
82	LIST_FOREACH(mp, &g_classes, class) {
83		if (mp2 == mp)
84			continue;
85		LIST_FOREACH(gp, &mp->geom, geom) {
86			LIST_FOREACH(pp, &gp->provider, provider) {
87				mp2->taste(mp2, pp, 0);
88				g_topology_assert();
89			}
90		}
91	}
92}
93
94void
95g_add_class(struct g_class *mp)
96{
97
98	if (!g_ignition) {
99		g_ignition++;
100		g_init();
101	}
102	mp->protect = 0x020016600;
103	g_topology_lock();
104	g_trace(G_T_TOPOLOGY, "g_add_class(%s)", mp->name);
105	LIST_INIT(&mp->geom);
106	LIST_INSERT_HEAD(&g_classes, mp, class);
107	if (g_nproviders > 0 && mp->taste != NULL)
108		g_post_event(g_new_class_event, mp, M_WAITOK, mp, NULL);
109	g_topology_unlock();
110}
111
112struct g_geom *
113g_new_geomf(struct g_class *mp, const char *fmt, ...)
114{
115	struct g_geom *gp;
116	va_list ap;
117	struct sbuf *sb;
118
119	g_topology_assert();
120	va_start(ap, fmt);
121	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
122	sbuf_vprintf(sb, fmt, ap);
123	sbuf_finish(sb);
124	gp = g_malloc(sizeof *gp, M_WAITOK | M_ZERO);
125	gp->protect = 0x020016601;
126	gp->name = g_malloc(sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
127	gp->class = mp;
128	gp->rank = 1;
129	LIST_INIT(&gp->consumer);
130	LIST_INIT(&gp->provider);
131	LIST_INSERT_HEAD(&mp->geom, gp, geom);
132	TAILQ_INSERT_HEAD(&geoms, gp, geoms);
133	strcpy(gp->name, sbuf_data(sb));
134	sbuf_delete(sb);
135	return (gp);
136}
137
138void
139g_destroy_geom(struct g_geom *gp)
140{
141
142	g_trace(G_T_TOPOLOGY, "g_destroy_geom(%p(%s))", gp, gp->name);
143	g_topology_assert();
144	KASSERT(LIST_EMPTY(&gp->consumer),
145	    ("g_destroy_geom(%s) with consumer(s) [%p]",
146	    gp->name, LIST_FIRST(&gp->consumer)));
147	KASSERT(LIST_EMPTY(&gp->provider),
148	    ("g_destroy_geom(%s) with provider(s) [%p]",
149	    gp->name, LIST_FIRST(&gp->consumer)));
150	g_cancel_event(gp);
151	LIST_REMOVE(gp, geom);
152	TAILQ_REMOVE(&geoms, gp, geoms);
153	g_free(gp->name);
154	g_free(gp);
155}
156
157/*
158 * This function is called (repeatedly) until has withered away.
159 */
160void
161g_wither_geom(struct g_geom *gp, int error)
162{
163	struct g_provider *pp, *pp2;
164	struct g_consumer *cp, *cp2;
165	static int once_is_enough;
166
167	if (once_is_enough)
168		return;
169	once_is_enough = 1;
170	g_trace(G_T_TOPOLOGY, "g_wither_geom(%p(%s))", gp, gp->name);
171	g_topology_assert();
172	if (!(gp->flags & G_GEOM_WITHER)) {
173		gp->flags |= G_GEOM_WITHER;
174		LIST_FOREACH(pp, &gp->provider, provider)
175			g_orphan_provider(pp, error);
176	}
177	for (pp = LIST_FIRST(&gp->provider); pp != NULL; pp = pp2) {
178		pp2 = LIST_NEXT(pp, provider);
179		if (!LIST_EMPTY(&pp->consumers))
180			continue;
181		g_destroy_provider(pp);
182	}
183	for (cp = LIST_FIRST(&gp->consumer); cp != NULL; cp = cp2) {
184		cp2 = LIST_NEXT(cp, consumer);
185		if (cp->acr || cp->acw || cp->ace)
186			continue;
187		g_detach(cp);
188		g_destroy_consumer(cp);
189	}
190	if (LIST_EMPTY(&gp->provider) && LIST_EMPTY(&gp->consumer))
191		g_destroy_geom(gp);
192	once_is_enough = 0;
193}
194
195struct g_consumer *
196g_new_consumer(struct g_geom *gp)
197{
198	struct g_consumer *cp;
199
200	g_topology_assert();
201	KASSERT(gp->orphan != NULL,
202	    ("g_new_consumer on geom(%s) (class %s) without orphan",
203	    gp->name, gp->class->name));
204
205	cp = g_malloc(sizeof *cp, M_WAITOK | M_ZERO);
206	cp->protect = 0x020016602;
207	cp->geom = gp;
208	cp->stat = devstat_new_entry(cp, -1, 0, DEVSTAT_ALL_SUPPORTED,
209	    DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
210	LIST_INSERT_HEAD(&gp->consumer, cp, consumer);
211	return(cp);
212}
213
214void
215g_destroy_consumer(struct g_consumer *cp)
216{
217	struct g_geom *gp;
218
219	g_trace(G_T_TOPOLOGY, "g_destroy_consumer(%p)", cp);
220	g_topology_assert();
221	KASSERT (cp->provider == NULL, ("g_destroy_consumer but attached"));
222	KASSERT (cp->acr == 0, ("g_destroy_consumer with acr"));
223	KASSERT (cp->acw == 0, ("g_destroy_consumer with acw"));
224	KASSERT (cp->ace == 0, ("g_destroy_consumer with ace"));
225	g_cancel_event(cp);
226	gp = cp->geom;
227	LIST_REMOVE(cp, consumer);
228	devstat_remove_entry(cp->stat);
229	g_free(cp);
230	if (gp->flags & G_GEOM_WITHER)
231		g_wither_geom(gp, 0);
232}
233
234static void
235g_new_provider_event(void *arg, int flag)
236{
237	struct g_class *mp;
238	struct g_provider *pp;
239	struct g_consumer *cp;
240	int i;
241
242	g_topology_assert();
243	if (flag == EV_CANCEL)
244		return;
245	if (g_shutdown)
246		return;
247	pp = arg;
248	LIST_FOREACH(mp, &g_classes, class) {
249		if (mp->taste == NULL)
250			continue;
251		i = 1;
252		LIST_FOREACH(cp, &pp->consumers, consumers)
253			if (cp->geom->class == mp)
254				i = 0;
255		if (!i)
256			continue;
257		mp->taste(mp, pp, 0);
258		g_topology_assert();
259	}
260}
261
262
263struct g_provider *
264g_new_providerf(struct g_geom *gp, const char *fmt, ...)
265{
266	struct g_provider *pp;
267	struct sbuf *sb;
268	va_list ap;
269
270	g_topology_assert();
271	va_start(ap, fmt);
272	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
273	sbuf_vprintf(sb, fmt, ap);
274	sbuf_finish(sb);
275	pp = g_malloc(sizeof *pp + sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
276	pp->protect = 0x020016603;
277	pp->name = (char *)(pp + 1);
278	strcpy(pp->name, sbuf_data(sb));
279	sbuf_delete(sb);
280	LIST_INIT(&pp->consumers);
281	pp->error = ENXIO;
282	pp->geom = gp;
283	pp->stat = devstat_new_entry(pp, -1, 0, DEVSTAT_ALL_SUPPORTED,
284	    DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
285	LIST_INSERT_HEAD(&gp->provider, pp, provider);
286	g_nproviders++;
287	g_post_event(g_new_provider_event, pp, M_WAITOK, pp, NULL);
288	return (pp);
289}
290
291void
292g_error_provider(struct g_provider *pp, int error)
293{
294
295	pp->error = error;
296}
297
298
299void
300g_destroy_provider(struct g_provider *pp)
301{
302	struct g_geom *gp;
303
304	g_topology_assert();
305	KASSERT(LIST_EMPTY(&pp->consumers),
306	    ("g_destroy_provider but attached"));
307	KASSERT (pp->acr == 0, ("g_destroy_provider with acr"));
308	KASSERT (pp->acw == 0, ("g_destroy_provider with acw"));
309	KASSERT (pp->acw == 0, ("g_destroy_provider with ace"));
310	g_cancel_event(pp);
311	g_nproviders--;
312	LIST_REMOVE(pp, provider);
313	gp = pp->geom;
314	devstat_remove_entry(pp->stat);
315	g_free(pp);
316	if ((gp->flags & G_GEOM_WITHER))
317		g_wither_geom(gp, 0);
318}
319
320/*
321 * We keep the "geoms" list sorted by topological order (== increasing
322 * numerical rank) at all times.
323 * When an attach is done, the attaching geoms rank is invalidated
324 * and it is moved to the tail of the list.
325 * All geoms later in the sequence has their ranks reevaluated in
326 * sequence.  If we cannot assign rank to a geom because it's
327 * prerequisites do not have rank, we move that element to the tail
328 * of the sequence with invalid rank as well.
329 * At some point we encounter our original geom and if we stil fail
330 * to assign it a rank, there must be a loop and we fail back to
331 * g_attach() which detach again and calls redo_rank again
332 * to fix up the damage.
333 * It would be much simpler code wise to do it recursively, but we
334 * can't risk that on the kernel stack.
335 */
336
337static int
338redo_rank(struct g_geom *gp)
339{
340	struct g_consumer *cp;
341	struct g_geom *gp1, *gp2;
342	int n, m;
343
344	g_topology_assert();
345
346	/* Invalidate this geoms rank and move it to the tail */
347	gp1 = TAILQ_NEXT(gp, geoms);
348	if (gp1 != NULL) {
349		gp->rank = 0;
350		TAILQ_REMOVE(&geoms, gp, geoms);
351		TAILQ_INSERT_TAIL(&geoms, gp, geoms);
352	} else {
353		gp1 = gp;
354	}
355
356	/* re-rank the rest of the sequence */
357	for (; gp1 != NULL; gp1 = gp2) {
358		gp1->rank = 0;
359		m = 1;
360		LIST_FOREACH(cp, &gp1->consumer, consumer) {
361			if (cp->provider == NULL)
362				continue;
363			n = cp->provider->geom->rank;
364			if (n == 0) {
365				m = 0;
366				break;
367			} else if (n >= m)
368				m = n + 1;
369		}
370		gp1->rank = m;
371		gp2 = TAILQ_NEXT(gp1, geoms);
372
373		/* got a rank, moving on */
374		if (m != 0)
375			continue;
376
377		/* no rank to original geom means loop */
378		if (gp == gp1)
379			return (ELOOP);
380
381		/* no rank, put it at the end move on */
382		TAILQ_REMOVE(&geoms, gp1, geoms);
383		TAILQ_INSERT_TAIL(&geoms, gp1, geoms);
384	}
385	return (0);
386}
387
388int
389g_attach(struct g_consumer *cp, struct g_provider *pp)
390{
391	int error;
392
393	g_topology_assert();
394	KASSERT(cp->provider == NULL, ("attach but attached"));
395	cp->provider = pp;
396	LIST_INSERT_HEAD(&pp->consumers, cp, consumers);
397	error = redo_rank(cp->geom);
398	if (error) {
399		LIST_REMOVE(cp, consumers);
400		cp->provider = NULL;
401		redo_rank(cp->geom);
402	}
403	return (error);
404}
405
406void
407g_detach(struct g_consumer *cp)
408{
409	struct g_provider *pp;
410
411	g_trace(G_T_TOPOLOGY, "g_detach(%p)", cp);
412	KASSERT(cp != (void*)0xd0d0d0d0, ("ARGH!"));
413	g_topology_assert();
414	KASSERT(cp->provider != NULL, ("detach but not attached"));
415	KASSERT(cp->acr == 0, ("detach but nonzero acr"));
416	KASSERT(cp->acw == 0, ("detach but nonzero acw"));
417	KASSERT(cp->ace == 0, ("detach but nonzero ace"));
418	KASSERT(cp->nstart == cp->nend,
419	    ("detach with active requests"));
420	pp = cp->provider;
421	LIST_REMOVE(cp, consumers);
422	cp->provider = NULL;
423	if (pp->geom->flags & G_GEOM_WITHER)
424		g_wither_geom(pp->geom, 0);
425	redo_rank(cp->geom);
426}
427
428
429/*
430 * g_access_abs()
431 *
432 * Access-check with absolute new values:  Just fall through
433 * and use the relative version.
434 */
435int
436g_access_abs(struct g_consumer *cp, int acr, int acw, int ace)
437{
438
439	g_topology_assert();
440	return(g_access_rel(cp,
441		acr - cp->acr,
442		acw - cp->acw,
443		ace - cp->ace));
444}
445
446/*
447 * g_access_rel()
448 *
449 * Access-check with delta values.  The question asked is "can provider
450 * "cp" change the access counters by the relative amounts dc[rwe] ?"
451 */
452
453int
454g_access_rel(struct g_consumer *cp, int dcr, int dcw, int dce)
455{
456	struct g_provider *pp;
457	int pr,pw,pe;
458	int error;
459
460	pp = cp->provider;
461
462	g_trace(G_T_ACCESS, "g_access_rel(%p(%s), %d, %d, %d)",
463	    cp, pp->name, dcr, dcw, dce);
464
465	g_topology_assert();
466	KASSERT(cp->provider != NULL, ("access but not attached"));
467	KASSERT(cp->acr + dcr >= 0, ("access resulting in negative acr"));
468	KASSERT(cp->acw + dcw >= 0, ("access resulting in negative acw"));
469	KASSERT(cp->ace + dce >= 0, ("access resulting in negative ace"));
470	KASSERT(pp->geom->access != NULL, ("NULL geom->access"));
471
472	/*
473	 * If our class cares about being spoiled, and we have been, we
474	 * are probably just ahead of the event telling us that.  Fail
475	 * now rather than having to unravel this later.
476	 */
477	if (cp->geom->spoiled != NULL && cp->spoiled) {
478		KASSERT(dcr <= 0, ("spoiled but dcr = %d", dcr));
479		KASSERT(dcw <= 0, ("spoiled but dce = %d", dcw));
480		KASSERT(dce <= 0, ("spoiled but dcw = %d", dce));
481	}
482
483	/*
484	 * Figure out what counts the provider would have had, if this
485	 * consumer had (r0w0e0) at this time.
486	 */
487	pr = pp->acr - cp->acr;
488	pw = pp->acw - cp->acw;
489	pe = pp->ace - cp->ace;
490
491	g_trace(G_T_ACCESS,
492    "open delta:[r%dw%de%d] old:[r%dw%de%d] provider:[r%dw%de%d] %p(%s)",
493	    dcr, dcw, dce,
494	    cp->acr, cp->acw, cp->ace,
495	    pp->acr, pp->acw, pp->ace,
496	    pp, pp->name);
497
498	/* If foot-shooting is enabled, any open on rank#1 is OK */
499	if ((g_debugflags & 16) && pp->geom->rank == 1)
500		;
501	/* If we try exclusive but already write: fail */
502	else if (dce > 0 && pw > 0)
503		return (EPERM);
504	/* If we try write but already exclusive: fail */
505	else if (dcw > 0 && pe > 0)
506		return (EPERM);
507	/* If we try to open more but provider is error'ed: fail */
508	else if ((dcr > 0 || dcw > 0 || dce > 0) && pp->error != 0)
509		return (pp->error);
510
511	/* Ok then... */
512
513	error = pp->geom->access(pp, dcr, dcw, dce);
514	if (!error) {
515		/*
516		 * If we open first write, spoil any partner consumers.
517		 * If we close last write, trigger re-taste.
518		 */
519		if (pp->acw == 0 && dcw != 0)
520			g_spoil(pp, cp);
521		else if (pp->acw != 0 && pp->acw == -dcw &&
522		    !(pp->geom->flags & G_GEOM_WITHER))
523			g_post_event(g_new_provider_event, pp, M_WAITOK,
524			    pp, NULL);
525
526		pp->acr += dcr;
527		pp->acw += dcw;
528		pp->ace += dce;
529		cp->acr += dcr;
530		cp->acw += dcw;
531		cp->ace += dce;
532	}
533	return (error);
534}
535
536int
537g_handleattr_int(struct bio *bp, const char *attribute, int val)
538{
539
540	return (g_handleattr(bp, attribute, &val, sizeof val));
541}
542
543int
544g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val)
545{
546
547	return (g_handleattr(bp, attribute, &val, sizeof val));
548}
549
550int
551g_handleattr(struct bio *bp, const char *attribute, void *val, int len)
552{
553	int error;
554
555	if (strcmp(bp->bio_attribute, attribute))
556		return (0);
557	if (bp->bio_length != len) {
558		printf("bio_length %jd len %d -> EFAULT\n",
559		    (intmax_t)bp->bio_length, len);
560		error = EFAULT;
561	} else {
562		error = 0;
563		bcopy(val, bp->bio_data, len);
564		bp->bio_completed = len;
565	}
566	g_io_deliver(bp, error);
567	return (1);
568}
569
570int
571g_std_access(struct g_provider *pp __unused,
572	int dr __unused, int dw __unused, int de __unused)
573{
574
575        return (0);
576}
577
578void
579g_std_done(struct bio *bp)
580{
581	struct bio *bp2;
582
583	bp2 = bp->bio_parent;
584	if (bp2->bio_error == 0)
585		bp2->bio_error = bp->bio_error;
586	bp2->bio_completed += bp->bio_completed;
587	g_destroy_bio(bp);
588	bp2->bio_inbed++;
589	if (bp2->bio_children == bp2->bio_inbed)
590		g_io_deliver(bp2, bp2->bio_error);
591}
592
593/* XXX: maybe this is only g_slice_spoiled */
594
595void
596g_std_spoiled(struct g_consumer *cp)
597{
598	struct g_geom *gp;
599	struct g_provider *pp;
600
601	g_trace(G_T_TOPOLOGY, "g_std_spoiled(%p)", cp);
602	g_topology_assert();
603	g_detach(cp);
604	gp = cp->geom;
605	LIST_FOREACH(pp, &gp->provider, provider)
606		g_orphan_provider(pp, ENXIO);
607	g_destroy_consumer(cp);
608	if (LIST_EMPTY(&gp->provider) && LIST_EMPTY(&gp->consumer))
609		g_destroy_geom(gp);
610	else
611		gp->flags |= G_GEOM_WITHER;
612}
613
614/*
615 * Spoiling happens when a provider is opened for writing, but consumers
616 * which are configured by in-band data are attached (slicers for instance).
617 * Since the write might potentially change the in-band data, such consumers
618 * need to re-evaluate their existence after the writing session closes.
619 * We do this by (offering to) tear them down when the open for write happens
620 * in return for a re-taste when it closes again.
621 * Together with the fact that such consumers grab an 'e' bit whenever they
622 * are open, regardless of mode, this ends up DTRT.
623 */
624
625static void
626g_spoil_event(void *arg, int flag)
627{
628	struct g_provider *pp;
629	struct g_consumer *cp, *cp2;
630
631	g_topology_assert();
632	if (flag == EV_CANCEL)
633		return;
634	pp = arg;
635	for (cp = LIST_FIRST(&pp->consumers); cp != NULL; cp = cp2) {
636		cp2 = LIST_NEXT(cp, consumers);
637		if (!cp->spoiled)
638			continue;
639		cp->spoiled = 0;
640		if (cp->geom->spoiled == NULL)
641			continue;
642		cp->geom->spoiled(cp);
643		g_topology_assert();
644	}
645}
646
647void
648g_spoil(struct g_provider *pp, struct g_consumer *cp)
649{
650	struct g_consumer *cp2;
651
652	g_topology_assert();
653
654	LIST_FOREACH(cp2, &pp->consumers, consumers) {
655		if (cp2 == cp)
656			continue;
657/*
658		KASSERT(cp2->acr == 0, ("spoiling cp->acr = %d", cp2->acr));
659		KASSERT(cp2->acw == 0, ("spoiling cp->acw = %d", cp2->acw));
660*/
661		KASSERT(cp2->ace == 0, ("spoiling cp->ace = %d", cp2->ace));
662		cp2->spoiled++;
663	}
664	g_post_event(g_spoil_event, pp, M_WAITOK, pp, NULL);
665}
666
667int
668g_getattr__(const char *attr, struct g_consumer *cp, void *var, int len)
669{
670	int error, i;
671
672	i = len;
673	error = g_io_getattr(attr, cp, &i, var);
674	if (error)
675		return (error);
676	if (i != len)
677		return (EINVAL);
678	return (0);
679}
680
681/*
682 * Check if the given pointer is a live object
683 */
684
685void
686g_sanity(void *ptr)
687{
688	struct g_class *mp;
689	struct g_geom *gp;
690	struct g_consumer *cp;
691	struct g_provider *pp;
692
693	if (!(g_debugflags & 0x8))
694		return;
695	LIST_FOREACH(mp, &g_classes, class) {
696		KASSERT(mp != ptr, ("Ptr is live class"));
697		KASSERT(mp->protect == 0x20016600,
698		    ("corrupt class %p %x", mp, mp->protect));
699		LIST_FOREACH(gp, &mp->geom, geom) {
700			KASSERT(gp != ptr, ("Ptr is live geom"));
701			KASSERT(gp->protect == 0x20016601,
702			    ("corrupt geom, %p %x", gp, gp->protect));
703			KASSERT(gp->name != ptr, ("Ptr is live geom's name"));
704			LIST_FOREACH(cp, &gp->consumer, consumer) {
705				KASSERT(cp != ptr, ("Ptr is live consumer"));
706				KASSERT(cp->protect == 0x20016602,
707				    ("corrupt consumer %p %x",
708				    cp, cp->protect));
709			}
710			LIST_FOREACH(pp, &gp->provider, provider) {
711				KASSERT(pp != ptr, ("Ptr is live provider"));
712				KASSERT(pp->protect == 0x20016603,
713				    ("corrupt provider %p %x",
714				    pp, pp->protect));
715			}
716		}
717	}
718}
719
720