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