geom_subr.c revision 192797
1254721Semaste/*-
2254721Semaste * Copyright (c) 2002 Poul-Henning Kamp
3254721Semaste * Copyright (c) 2002 Networks Associates Technology, Inc.
4254721Semaste * All rights reserved.
5254721Semaste *
6254721Semaste * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7254721Semaste * and NAI Labs, the Security Research Division of Network Associates, Inc.
8254721Semaste * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9254721Semaste * DARPA CHATS research program.
10254721Semaste *
11254721Semaste * Redistribution and use in source and binary forms, with or without
12254721Semaste * modification, are permitted provided that the following conditions
13254721Semaste * are met:
14254721Semaste * 1. Redistributions of source code must retain the above copyright
15254721Semaste *    notice, this list of conditions and the following disclaimer.
16254721Semaste * 2. Redistributions in binary form must reproduce the above copyright
17254721Semaste *    notice, this list of conditions and the following disclaimer in the
18254721Semaste *    documentation and/or other materials provided with the distribution.
19254721Semaste * 3. The names of the authors may not be used to endorse or promote
20254721Semaste *    products derived from this software without specific prior written
21254721Semaste *    permission.
22254721Semaste *
23254721Semaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26254721Semaste * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32254721Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33254721Semaste * SUCH DAMAGE.
34254721Semaste */
35254721Semaste
36254721Semaste#include <sys/cdefs.h>
37254721Semaste__FBSDID("$FreeBSD: head/sys/geom/geom_subr.c 192797 2009-05-26 07:29:17Z lulf $");
38254721Semaste
39254721Semaste#include "opt_ddb.h"
40254721Semaste
41254721Semaste#include <sys/param.h>
42254721Semaste#include <sys/systm.h>
43254721Semaste#include <sys/devicestat.h>
44254721Semaste#include <sys/kernel.h>
45254721Semaste#include <sys/malloc.h>
46254721Semaste#include <sys/bio.h>
47254721Semaste#include <sys/sysctl.h>
48254721Semaste#include <sys/proc.h>
49254721Semaste#include <sys/kthread.h>
50254721Semaste#include <sys/lock.h>
51254721Semaste#include <sys/mutex.h>
52254721Semaste#include <sys/errno.h>
53254721Semaste#include <sys/sbuf.h>
54254721Semaste#include <geom/geom.h>
55254721Semaste#include <geom/geom_int.h>
56254721Semaste#include <machine/stdarg.h>
57254721Semaste
58254721Semaste#ifdef DDB
59254721Semaste#include <ddb/ddb.h>
60254721Semaste#endif
61254721Semaste
62254721Semastestruct class_list_head g_classes = LIST_HEAD_INITIALIZER(g_classes);
63254721Semastestatic struct g_tailq_head geoms = TAILQ_HEAD_INITIALIZER(geoms);
64254721Semastechar *g_wait_event, *g_wait_up, *g_wait_down, *g_wait_sim;
65254721Semaste
66254721Semastestruct g_hh00 {
67254721Semaste	struct g_class	*mp;
68254721Semaste	int		error;
69254721Semaste	int		post;
70254721Semaste};
71254721Semaste
72254721Semaste/*
73254721Semaste * This event offers a new class a chance to taste all preexisting providers.
74254721Semaste */
75254721Semastestatic void
76254721Semasteg_load_class(void *arg, int flag)
77254721Semaste{
78254721Semaste	struct g_hh00 *hh;
79254721Semaste	struct g_class *mp2, *mp;
80254721Semaste	struct g_geom *gp;
81254721Semaste	struct g_provider *pp;
82254721Semaste
83254721Semaste	g_topology_assert();
84254721Semaste	if (flag == EV_CANCEL)	/* XXX: can't happen ? */
85254721Semaste		return;
86254721Semaste	if (g_shutdown)
87254721Semaste		return;
88254721Semaste
89254721Semaste	hh = arg;
90254721Semaste	mp = hh->mp;
91254721Semaste	hh->error = 0;
92254721Semaste	if (hh->post) {
93254721Semaste		g_free(hh);
94254721Semaste		hh = NULL;
95254721Semaste	}
96254721Semaste	g_trace(G_T_TOPOLOGY, "g_load_class(%s)", mp->name);
97254721Semaste	KASSERT(mp->name != NULL && *mp->name != '\0',
98254721Semaste	    ("GEOM class has no name"));
99254721Semaste	LIST_FOREACH(mp2, &g_classes, class) {
100254721Semaste		if (mp2 == mp) {
101254721Semaste			printf("The GEOM class %s is already loaded.\n",
102254721Semaste			    mp2->name);
103254721Semaste			if (hh != NULL)
104254721Semaste				hh->error = EEXIST;
105254721Semaste			return;
106254721Semaste		} else if (strcmp(mp2->name, mp->name) == 0) {
107254721Semaste			printf("A GEOM class %s is already loaded.\n",
108254721Semaste			    mp2->name);
109254721Semaste			if (hh != NULL)
110254721Semaste				hh->error = EEXIST;
111254721Semaste			return;
112254721Semaste		}
113254721Semaste	}
114254721Semaste
115254721Semaste	LIST_INIT(&mp->geom);
116254721Semaste	LIST_INSERT_HEAD(&g_classes, mp, class);
117254721Semaste	if (mp->init != NULL)
118254721Semaste		mp->init(mp);
119254721Semaste	if (mp->taste == NULL)
120254721Semaste		return;
121254721Semaste	LIST_FOREACH(mp2, &g_classes, class) {
122254721Semaste		if (mp == mp2)
123254721Semaste			continue;
124254721Semaste		LIST_FOREACH(gp, &mp2->geom, geom) {
125254721Semaste			LIST_FOREACH(pp, &gp->provider, provider) {
126254721Semaste				mp->taste(mp, pp, 0);
127254721Semaste				g_topology_assert();
128254721Semaste			}
129254721Semaste		}
130254721Semaste	}
131254721Semaste}
132254721Semaste
133254721Semastestatic void
134254721Semasteg_unload_class(void *arg, int flag)
135254721Semaste{
136254721Semaste	struct g_hh00 *hh;
137254721Semaste	struct g_class *mp;
138254721Semaste	struct g_geom *gp;
139254721Semaste	struct g_provider *pp;
140254721Semaste	struct g_consumer *cp;
141254721Semaste	int error;
142254721Semaste
143254721Semaste	g_topology_assert();
144254721Semaste	hh = arg;
145254721Semaste	mp = hh->mp;
146254721Semaste	G_VALID_CLASS(mp);
147254721Semaste	g_trace(G_T_TOPOLOGY, "g_unload_class(%s)", mp->name);
148254721Semaste
149254721Semaste	/*
150254721Semaste	 * We allow unloading if we have no geoms, or a class
151254721Semaste	 * method we can use to get rid of them.
152254721Semaste	 */
153254721Semaste	if (!LIST_EMPTY(&mp->geom) && mp->destroy_geom == NULL) {
154254721Semaste		hh->error = EOPNOTSUPP;
155254721Semaste		return;
156254721Semaste	}
157254721Semaste
158254721Semaste	/* We refuse to unload if anything is open */
159254721Semaste	LIST_FOREACH(gp, &mp->geom, geom) {
160254721Semaste		LIST_FOREACH(pp, &gp->provider, provider)
161254721Semaste			if (pp->acr || pp->acw || pp->ace) {
162254721Semaste				hh->error = EBUSY;
163254721Semaste				return;
164254721Semaste			}
165254721Semaste		LIST_FOREACH(cp, &gp->consumer, consumer)
166254721Semaste			if (cp->acr || cp->acw || cp->ace) {
167				hh->error = EBUSY;
168				return;
169			}
170	}
171
172	/* Bar new entries */
173	mp->taste = NULL;
174	mp->config = NULL;
175
176	error = 0;
177	for (;;) {
178		gp = LIST_FIRST(&mp->geom);
179		if (gp == NULL)
180			break;
181		error = mp->destroy_geom(NULL, mp, gp);
182		if (error != 0)
183			break;
184	}
185	if (error == 0) {
186		if (mp->fini != NULL)
187			mp->fini(mp);
188		LIST_REMOVE(mp, class);
189	}
190	hh->error = error;
191	return;
192}
193
194int
195g_modevent(module_t mod, int type, void *data)
196{
197	struct g_hh00 *hh;
198	int error;
199	static int g_ignition;
200	struct g_class *mp;
201
202	mp = data;
203	if (mp->version != G_VERSION) {
204		printf("GEOM class %s has Wrong version %x\n",
205		    mp->name, mp->version);
206		return (EINVAL);
207	}
208	if (!g_ignition) {
209		g_ignition++;
210		g_init();
211	}
212	hh = g_malloc(sizeof *hh, M_WAITOK | M_ZERO);
213	hh->mp = data;
214	error = EOPNOTSUPP;
215	switch (type) {
216	case MOD_LOAD:
217		g_trace(G_T_TOPOLOGY, "g_modevent(%s, LOAD)", hh->mp->name);
218		/*
219		 * Once the system is not cold, MOD_LOAD calls will be
220		 * from the userland and the g_event thread will be able
221		 * to acknowledge their completion.
222		 */
223		if (cold) {
224			hh->post = 1;
225			error = g_post_event(g_load_class, hh, M_WAITOK, NULL);
226		} else {
227			error = g_waitfor_event(g_load_class, hh, M_WAITOK,
228			    NULL);
229			if (error == 0)
230				error = hh->error;
231			g_free(hh);
232		}
233		break;
234	case MOD_UNLOAD:
235		g_trace(G_T_TOPOLOGY, "g_modevent(%s, UNLOAD)", hh->mp->name);
236		error = g_waitfor_event(g_unload_class, hh, M_WAITOK, NULL);
237		if (error == 0)
238			error = hh->error;
239		if (error == 0) {
240			KASSERT(LIST_EMPTY(&hh->mp->geom),
241			    ("Unloaded class (%s) still has geom", hh->mp->name));
242		}
243		g_free(hh);
244		break;
245	default:
246		g_free(hh);
247		break;
248	}
249	return (error);
250}
251
252static void
253g_retaste_event(void *arg, int flag)
254{
255	struct g_class *cp, *mp;
256	struct g_geom *gp, *gp2;
257	struct g_hh00 *hh;
258	struct g_provider *pp;
259
260	g_topology_assert();
261	if (flag == EV_CANCEL)  /* XXX: can't happen ? */
262		return;
263	if (g_shutdown)
264		return;
265
266	hh = arg;
267	mp = hh->mp;
268	hh->error = 0;
269	if (hh->post) {
270		g_free(hh);
271		hh = NULL;
272	}
273	g_trace(G_T_TOPOLOGY, "g_retaste(%s)", mp->name);
274
275	LIST_FOREACH(cp, &g_classes, class) {
276		LIST_FOREACH(gp, &cp->geom, geom) {
277			LIST_FOREACH(pp, &gp->provider, provider) {
278				if (pp->acr || pp->acw || pp->ace)
279					continue;
280				LIST_FOREACH(gp2, &mp->geom, geom) {
281					if (!strcmp(pp->name, gp2->name))
282						break;
283				}
284				if (gp2 != NULL)
285					g_wither_geom(gp2, ENXIO);
286				mp->taste(mp, pp, 0);
287				g_topology_assert();
288			}
289		}
290	}
291}
292
293int
294g_retaste(struct g_class *mp)
295{
296	struct g_hh00 *hh;
297	int error;
298
299	if (mp->taste == NULL)
300		return (EINVAL);
301
302	hh = g_malloc(sizeof *hh, M_WAITOK | M_ZERO);
303	hh->mp = mp;
304
305	if (cold) {
306		hh->post = 1;
307		error = g_post_event(g_retaste_event, hh, M_WAITOK, NULL);
308	} else {
309		error = g_waitfor_event(g_retaste_event, hh, M_WAITOK, NULL);
310		if (error == 0)
311			error = hh->error;
312		g_free(hh);
313	}
314
315	return (error);
316}
317
318struct g_geom *
319g_new_geomf(struct g_class *mp, const char *fmt, ...)
320{
321	struct g_geom *gp;
322	va_list ap;
323	struct sbuf *sb;
324
325	g_topology_assert();
326	G_VALID_CLASS(mp);
327	sb = sbuf_new_auto();
328	va_start(ap, fmt);
329	sbuf_vprintf(sb, fmt, ap);
330	va_end(ap);
331	sbuf_finish(sb);
332	gp = g_malloc(sizeof *gp, M_WAITOK | M_ZERO);
333	gp->name = g_malloc(sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
334	gp->class = mp;
335	gp->rank = 1;
336	LIST_INIT(&gp->consumer);
337	LIST_INIT(&gp->provider);
338	LIST_INSERT_HEAD(&mp->geom, gp, geom);
339	TAILQ_INSERT_HEAD(&geoms, gp, geoms);
340	strcpy(gp->name, sbuf_data(sb));
341	sbuf_delete(sb);
342	/* Fill in defaults from class */
343	gp->start = mp->start;
344	gp->spoiled = mp->spoiled;
345	gp->dumpconf = mp->dumpconf;
346	gp->access = mp->access;
347	gp->orphan = mp->orphan;
348	gp->ioctl = mp->ioctl;
349	return (gp);
350}
351
352void
353g_destroy_geom(struct g_geom *gp)
354{
355
356	g_topology_assert();
357	G_VALID_GEOM(gp);
358	g_trace(G_T_TOPOLOGY, "g_destroy_geom(%p(%s))", gp, gp->name);
359	KASSERT(LIST_EMPTY(&gp->consumer),
360	    ("g_destroy_geom(%s) with consumer(s) [%p]",
361	    gp->name, LIST_FIRST(&gp->consumer)));
362	KASSERT(LIST_EMPTY(&gp->provider),
363	    ("g_destroy_geom(%s) with provider(s) [%p]",
364	    gp->name, LIST_FIRST(&gp->provider)));
365	g_cancel_event(gp);
366	LIST_REMOVE(gp, geom);
367	TAILQ_REMOVE(&geoms, gp, geoms);
368	g_free(gp->name);
369	g_free(gp);
370}
371
372/*
373 * This function is called (repeatedly) until the geom has withered away.
374 */
375void
376g_wither_geom(struct g_geom *gp, int error)
377{
378	struct g_provider *pp;
379
380	g_topology_assert();
381	G_VALID_GEOM(gp);
382	g_trace(G_T_TOPOLOGY, "g_wither_geom(%p(%s))", gp, gp->name);
383	if (!(gp->flags & G_GEOM_WITHER)) {
384		gp->flags |= G_GEOM_WITHER;
385		LIST_FOREACH(pp, &gp->provider, provider)
386			if (!(pp->flags & G_PF_ORPHAN))
387				g_orphan_provider(pp, error);
388	}
389	g_do_wither();
390}
391
392/*
393 * Convenience function to destroy a particular provider.
394 */
395void
396g_wither_provider(struct g_provider *pp, int error)
397{
398
399	pp->flags |= G_PF_WITHER;
400	if (!(pp->flags & G_PF_ORPHAN))
401		g_orphan_provider(pp, error);
402}
403
404/*
405 * This function is called (repeatedly) until the has withered away.
406 */
407void
408g_wither_geom_close(struct g_geom *gp, int error)
409{
410	struct g_consumer *cp;
411
412	g_topology_assert();
413	G_VALID_GEOM(gp);
414	g_trace(G_T_TOPOLOGY, "g_wither_geom_close(%p(%s))", gp, gp->name);
415	LIST_FOREACH(cp, &gp->consumer, consumer)
416		if (cp->acr || cp->acw || cp->ace)
417			g_access(cp, -cp->acr, -cp->acw, -cp->ace);
418	g_wither_geom(gp, error);
419}
420
421/*
422 * This function is called (repeatedly) until we cant wash away more
423 * withered bits at present.  Return value contains two bits.  Bit 0
424 * set means "withering stuff we can't wash now", bit 1 means "call
425 * me again, there may be stuff I didn't get the first time around.
426 */
427int
428g_wither_washer()
429{
430	struct g_class *mp;
431	struct g_geom *gp, *gp2;
432	struct g_provider *pp, *pp2;
433	struct g_consumer *cp, *cp2;
434	int result;
435
436	result = 0;
437	g_topology_assert();
438	LIST_FOREACH(mp, &g_classes, class) {
439		LIST_FOREACH_SAFE(gp, &mp->geom, geom, gp2) {
440			LIST_FOREACH_SAFE(pp, &gp->provider, provider, pp2) {
441				if (!(pp->flags & G_PF_WITHER))
442					continue;
443				if (LIST_EMPTY(&pp->consumers))
444					g_destroy_provider(pp);
445				else
446					result |= 1;
447			}
448			if (!(gp->flags & G_GEOM_WITHER))
449				continue;
450			LIST_FOREACH_SAFE(pp, &gp->provider, provider, pp2) {
451				if (LIST_EMPTY(&pp->consumers))
452					g_destroy_provider(pp);
453				else
454					result |= 1;
455			}
456			LIST_FOREACH_SAFE(cp, &gp->consumer, consumer, cp2) {
457				if (cp->acr || cp->acw || cp->ace) {
458					result |= 1;
459					continue;
460				}
461				if (cp->provider != NULL)
462					g_detach(cp);
463				g_destroy_consumer(cp);
464				result |= 2;
465			}
466			if (LIST_EMPTY(&gp->provider) &&
467			    LIST_EMPTY(&gp->consumer))
468				g_destroy_geom(gp);
469			else
470				result |= 1;
471		}
472	}
473	return (result);
474}
475
476struct g_consumer *
477g_new_consumer(struct g_geom *gp)
478{
479	struct g_consumer *cp;
480
481	g_topology_assert();
482	G_VALID_GEOM(gp);
483	KASSERT(!(gp->flags & G_GEOM_WITHER),
484	    ("g_new_consumer on WITHERing geom(%s) (class %s)",
485	    gp->name, gp->class->name));
486	KASSERT(gp->orphan != NULL,
487	    ("g_new_consumer on geom(%s) (class %s) without orphan",
488	    gp->name, gp->class->name));
489
490	cp = g_malloc(sizeof *cp, M_WAITOK | M_ZERO);
491	cp->geom = gp;
492	cp->stat = devstat_new_entry(cp, -1, 0, DEVSTAT_ALL_SUPPORTED,
493	    DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
494	LIST_INSERT_HEAD(&gp->consumer, cp, consumer);
495	return(cp);
496}
497
498void
499g_destroy_consumer(struct g_consumer *cp)
500{
501	struct g_geom *gp;
502
503	g_topology_assert();
504	G_VALID_CONSUMER(cp);
505	g_trace(G_T_TOPOLOGY, "g_destroy_consumer(%p)", cp);
506	KASSERT (cp->provider == NULL, ("g_destroy_consumer but attached"));
507	KASSERT (cp->acr == 0, ("g_destroy_consumer with acr"));
508	KASSERT (cp->acw == 0, ("g_destroy_consumer with acw"));
509	KASSERT (cp->ace == 0, ("g_destroy_consumer with ace"));
510	g_cancel_event(cp);
511	gp = cp->geom;
512	LIST_REMOVE(cp, consumer);
513	devstat_remove_entry(cp->stat);
514	g_free(cp);
515	if (gp->flags & G_GEOM_WITHER)
516		g_do_wither();
517}
518
519static void
520g_new_provider_event(void *arg, int flag)
521{
522	struct g_class *mp;
523	struct g_provider *pp;
524	struct g_consumer *cp;
525	int i;
526
527	g_topology_assert();
528	if (flag == EV_CANCEL)
529		return;
530	if (g_shutdown)
531		return;
532	pp = arg;
533	G_VALID_PROVIDER(pp);
534	KASSERT(!(pp->flags & G_PF_WITHER),
535	    ("g_new_provider_event but withered"));
536	LIST_FOREACH(mp, &g_classes, class) {
537		if (mp->taste == NULL)
538			continue;
539		i = 1;
540		LIST_FOREACH(cp, &pp->consumers, consumers)
541			if (cp->geom->class == mp)
542				i = 0;
543		if (!i)
544			continue;
545		mp->taste(mp, pp, 0);
546		g_topology_assert();
547	}
548}
549
550
551struct g_provider *
552g_new_providerf(struct g_geom *gp, const char *fmt, ...)
553{
554	struct g_provider *pp;
555	struct sbuf *sb;
556	va_list ap;
557
558	g_topology_assert();
559	G_VALID_GEOM(gp);
560	KASSERT(gp->access != NULL,
561	    ("new provider on geom(%s) without ->access (class %s)",
562	    gp->name, gp->class->name));
563	KASSERT(gp->start != NULL,
564	    ("new provider on geom(%s) without ->start (class %s)",
565	    gp->name, gp->class->name));
566	KASSERT(!(gp->flags & G_GEOM_WITHER),
567	    ("new provider on WITHERing geom(%s) (class %s)",
568	    gp->name, gp->class->name));
569	sb = sbuf_new_auto();
570	va_start(ap, fmt);
571	sbuf_vprintf(sb, fmt, ap);
572	va_end(ap);
573	sbuf_finish(sb);
574	pp = g_malloc(sizeof *pp + sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
575	pp->name = (char *)(pp + 1);
576	strcpy(pp->name, sbuf_data(sb));
577	sbuf_delete(sb);
578	LIST_INIT(&pp->consumers);
579	pp->error = ENXIO;
580	pp->geom = gp;
581	pp->stat = devstat_new_entry(pp, -1, 0, DEVSTAT_ALL_SUPPORTED,
582	    DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
583	LIST_INSERT_HEAD(&gp->provider, pp, provider);
584	g_post_event(g_new_provider_event, pp, M_WAITOK, pp, gp, NULL);
585	return (pp);
586}
587
588void
589g_error_provider(struct g_provider *pp, int error)
590{
591
592	/* G_VALID_PROVIDER(pp);  We may not have g_topology */
593	pp->error = error;
594}
595
596struct g_provider *
597g_provider_by_name(char const *arg)
598{
599	struct g_class *cp;
600	struct g_geom *gp;
601	struct g_provider *pp;
602
603	LIST_FOREACH(cp, &g_classes, class) {
604		LIST_FOREACH(gp, &cp->geom, geom) {
605			LIST_FOREACH(pp, &gp->provider, provider) {
606				if (!strcmp(arg, pp->name))
607					return (pp);
608			}
609		}
610	}
611	return (NULL);
612}
613
614void
615g_destroy_provider(struct g_provider *pp)
616{
617	struct g_geom *gp;
618
619	g_topology_assert();
620	G_VALID_PROVIDER(pp);
621	KASSERT(LIST_EMPTY(&pp->consumers),
622	    ("g_destroy_provider but attached"));
623	KASSERT (pp->acr == 0, ("g_destroy_provider with acr"));
624	KASSERT (pp->acw == 0, ("g_destroy_provider with acw"));
625	KASSERT (pp->ace == 0, ("g_destroy_provider with ace"));
626	g_cancel_event(pp);
627	LIST_REMOVE(pp, provider);
628	gp = pp->geom;
629	devstat_remove_entry(pp->stat);
630	g_free(pp);
631	if ((gp->flags & G_GEOM_WITHER))
632		g_do_wither();
633}
634
635/*
636 * We keep the "geoms" list sorted by topological order (== increasing
637 * numerical rank) at all times.
638 * When an attach is done, the attaching geoms rank is invalidated
639 * and it is moved to the tail of the list.
640 * All geoms later in the sequence has their ranks reevaluated in
641 * sequence.  If we cannot assign rank to a geom because it's
642 * prerequisites do not have rank, we move that element to the tail
643 * of the sequence with invalid rank as well.
644 * At some point we encounter our original geom and if we stil fail
645 * to assign it a rank, there must be a loop and we fail back to
646 * g_attach() which detach again and calls redo_rank again
647 * to fix up the damage.
648 * It would be much simpler code wise to do it recursively, but we
649 * can't risk that on the kernel stack.
650 */
651
652static int
653redo_rank(struct g_geom *gp)
654{
655	struct g_consumer *cp;
656	struct g_geom *gp1, *gp2;
657	int n, m;
658
659	g_topology_assert();
660	G_VALID_GEOM(gp);
661
662	/* Invalidate this geoms rank and move it to the tail */
663	gp1 = TAILQ_NEXT(gp, geoms);
664	if (gp1 != NULL) {
665		gp->rank = 0;
666		TAILQ_REMOVE(&geoms, gp, geoms);
667		TAILQ_INSERT_TAIL(&geoms, gp, geoms);
668	} else {
669		gp1 = gp;
670	}
671
672	/* re-rank the rest of the sequence */
673	for (; gp1 != NULL; gp1 = gp2) {
674		gp1->rank = 0;
675		m = 1;
676		LIST_FOREACH(cp, &gp1->consumer, consumer) {
677			if (cp->provider == NULL)
678				continue;
679			n = cp->provider->geom->rank;
680			if (n == 0) {
681				m = 0;
682				break;
683			} else if (n >= m)
684				m = n + 1;
685		}
686		gp1->rank = m;
687		gp2 = TAILQ_NEXT(gp1, geoms);
688
689		/* got a rank, moving on */
690		if (m != 0)
691			continue;
692
693		/* no rank to original geom means loop */
694		if (gp == gp1)
695			return (ELOOP);
696
697		/* no rank, put it at the end move on */
698		TAILQ_REMOVE(&geoms, gp1, geoms);
699		TAILQ_INSERT_TAIL(&geoms, gp1, geoms);
700	}
701	return (0);
702}
703
704int
705g_attach(struct g_consumer *cp, struct g_provider *pp)
706{
707	int error;
708
709	g_topology_assert();
710	G_VALID_CONSUMER(cp);
711	G_VALID_PROVIDER(pp);
712	KASSERT(cp->provider == NULL, ("attach but attached"));
713	cp->provider = pp;
714	LIST_INSERT_HEAD(&pp->consumers, cp, consumers);
715	error = redo_rank(cp->geom);
716	if (error) {
717		LIST_REMOVE(cp, consumers);
718		cp->provider = NULL;
719		redo_rank(cp->geom);
720	}
721	return (error);
722}
723
724void
725g_detach(struct g_consumer *cp)
726{
727	struct g_provider *pp;
728
729	g_topology_assert();
730	G_VALID_CONSUMER(cp);
731	g_trace(G_T_TOPOLOGY, "g_detach(%p)", cp);
732	KASSERT(cp->provider != NULL, ("detach but not attached"));
733	KASSERT(cp->acr == 0, ("detach but nonzero acr"));
734	KASSERT(cp->acw == 0, ("detach but nonzero acw"));
735	KASSERT(cp->ace == 0, ("detach but nonzero ace"));
736	KASSERT(cp->nstart == cp->nend,
737	    ("detach with active requests"));
738	pp = cp->provider;
739	LIST_REMOVE(cp, consumers);
740	cp->provider = NULL;
741	if (pp->geom->flags & G_GEOM_WITHER)
742		g_do_wither();
743	else if (pp->flags & G_PF_WITHER)
744		g_do_wither();
745	redo_rank(cp->geom);
746}
747
748/*
749 * g_access()
750 *
751 * Access-check with delta values.  The question asked is "can provider
752 * "cp" change the access counters by the relative amounts dc[rwe] ?"
753 */
754
755int
756g_access(struct g_consumer *cp, int dcr, int dcw, int dce)
757{
758	struct g_provider *pp;
759	int pr,pw,pe;
760	int error;
761
762	g_topology_assert();
763	G_VALID_CONSUMER(cp);
764	pp = cp->provider;
765	KASSERT(pp != NULL, ("access but not attached"));
766	G_VALID_PROVIDER(pp);
767
768	g_trace(G_T_ACCESS, "g_access(%p(%s), %d, %d, %d)",
769	    cp, pp->name, dcr, dcw, dce);
770
771	KASSERT(cp->acr + dcr >= 0, ("access resulting in negative acr"));
772	KASSERT(cp->acw + dcw >= 0, ("access resulting in negative acw"));
773	KASSERT(cp->ace + dce >= 0, ("access resulting in negative ace"));
774	KASSERT(dcr != 0 || dcw != 0 || dce != 0, ("NOP access request"));
775	KASSERT(pp->geom->access != NULL, ("NULL geom->access"));
776
777	/*
778	 * If our class cares about being spoiled, and we have been, we
779	 * are probably just ahead of the event telling us that.  Fail
780	 * now rather than having to unravel this later.
781	 */
782	if (cp->geom->spoiled != NULL && cp->spoiled &&
783	    (dcr > 0 || dcw > 0 || dce > 0))
784		return (ENXIO);
785
786	/*
787	 * Figure out what counts the provider would have had, if this
788	 * consumer had (r0w0e0) at this time.
789	 */
790	pr = pp->acr - cp->acr;
791	pw = pp->acw - cp->acw;
792	pe = pp->ace - cp->ace;
793
794	g_trace(G_T_ACCESS,
795    "open delta:[r%dw%de%d] old:[r%dw%de%d] provider:[r%dw%de%d] %p(%s)",
796	    dcr, dcw, dce,
797	    cp->acr, cp->acw, cp->ace,
798	    pp->acr, pp->acw, pp->ace,
799	    pp, pp->name);
800
801	/* If foot-shooting is enabled, any open on rank#1 is OK */
802	if ((g_debugflags & 16) && pp->geom->rank == 1)
803		;
804	/* If we try exclusive but already write: fail */
805	else if (dce > 0 && pw > 0)
806		return (EPERM);
807	/* If we try write but already exclusive: fail */
808	else if (dcw > 0 && pe > 0)
809		return (EPERM);
810	/* If we try to open more but provider is error'ed: fail */
811	else if ((dcr > 0 || dcw > 0 || dce > 0) && pp->error != 0)
812		return (pp->error);
813
814	/* Ok then... */
815
816	error = pp->geom->access(pp, dcr, dcw, dce);
817	KASSERT(dcr > 0 || dcw > 0 || dce > 0 || error == 0,
818	    ("Geom provider %s::%s failed closing ->access()",
819	    pp->geom->class->name, pp->name));
820	if (!error) {
821		/*
822		 * If we open first write, spoil any partner consumers.
823		 * If we close last write and provider is not errored,
824		 * trigger re-taste.
825		 */
826		if (pp->acw == 0 && dcw != 0)
827			g_spoil(pp, cp);
828		else if (pp->acw != 0 && pp->acw == -dcw && pp->error == 0 &&
829		    !(pp->geom->flags & G_GEOM_WITHER))
830			g_post_event(g_new_provider_event, pp, M_WAITOK,
831			    pp, NULL);
832
833		pp->acr += dcr;
834		pp->acw += dcw;
835		pp->ace += dce;
836		cp->acr += dcr;
837		cp->acw += dcw;
838		cp->ace += dce;
839		if (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)
840			KASSERT(pp->sectorsize > 0,
841			    ("Provider %s lacks sectorsize", pp->name));
842	}
843	return (error);
844}
845
846int
847g_handleattr_int(struct bio *bp, const char *attribute, int val)
848{
849
850	return (g_handleattr(bp, attribute, &val, sizeof val));
851}
852
853int
854g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val)
855{
856
857	return (g_handleattr(bp, attribute, &val, sizeof val));
858}
859
860int
861g_handleattr_str(struct bio *bp, const char *attribute, const char *str)
862{
863
864	return (g_handleattr(bp, attribute, str, 0));
865}
866
867int
868g_handleattr(struct bio *bp, const char *attribute, const void *val, int len)
869{
870	int error = 0;
871
872	if (strcmp(bp->bio_attribute, attribute))
873		return (0);
874	if (len == 0) {
875		bzero(bp->bio_data, bp->bio_length);
876		if (strlcpy(bp->bio_data, val, bp->bio_length) >=
877		    bp->bio_length) {
878			printf("%s: %s bio_length %jd len %zu -> EFAULT\n",
879			    __func__, bp->bio_to->name,
880			    (intmax_t)bp->bio_length, strlen(val));
881			error = EFAULT;
882		}
883	} else if (bp->bio_length == len) {
884		bcopy(val, bp->bio_data, len);
885	} else {
886		printf("%s: %s bio_length %jd len %d -> EFAULT\n", __func__,
887		    bp->bio_to->name, (intmax_t)bp->bio_length, len);
888		error = EFAULT;
889	}
890	if (error == 0)
891		bp->bio_completed = bp->bio_length;
892	g_io_deliver(bp, error);
893	return (1);
894}
895
896int
897g_std_access(struct g_provider *pp,
898	int dr __unused, int dw __unused, int de __unused)
899{
900
901	g_topology_assert();
902	G_VALID_PROVIDER(pp);
903        return (0);
904}
905
906void
907g_std_done(struct bio *bp)
908{
909	struct bio *bp2;
910
911	bp2 = bp->bio_parent;
912	if (bp2->bio_error == 0)
913		bp2->bio_error = bp->bio_error;
914	bp2->bio_completed += bp->bio_completed;
915	g_destroy_bio(bp);
916	bp2->bio_inbed++;
917	if (bp2->bio_children == bp2->bio_inbed)
918		g_io_deliver(bp2, bp2->bio_error);
919}
920
921/* XXX: maybe this is only g_slice_spoiled */
922
923void
924g_std_spoiled(struct g_consumer *cp)
925{
926	struct g_geom *gp;
927	struct g_provider *pp;
928
929	g_topology_assert();
930	G_VALID_CONSUMER(cp);
931	g_trace(G_T_TOPOLOGY, "g_std_spoiled(%p)", cp);
932	g_detach(cp);
933	gp = cp->geom;
934	LIST_FOREACH(pp, &gp->provider, provider)
935		g_orphan_provider(pp, ENXIO);
936	g_destroy_consumer(cp);
937	if (LIST_EMPTY(&gp->provider) && LIST_EMPTY(&gp->consumer))
938		g_destroy_geom(gp);
939	else
940		gp->flags |= G_GEOM_WITHER;
941}
942
943/*
944 * Spoiling happens when a provider is opened for writing, but consumers
945 * which are configured by in-band data are attached (slicers for instance).
946 * Since the write might potentially change the in-band data, such consumers
947 * need to re-evaluate their existence after the writing session closes.
948 * We do this by (offering to) tear them down when the open for write happens
949 * in return for a re-taste when it closes again.
950 * Together with the fact that such consumers grab an 'e' bit whenever they
951 * are open, regardless of mode, this ends up DTRT.
952 */
953
954static void
955g_spoil_event(void *arg, int flag)
956{
957	struct g_provider *pp;
958	struct g_consumer *cp, *cp2;
959
960	g_topology_assert();
961	if (flag == EV_CANCEL)
962		return;
963	pp = arg;
964	G_VALID_PROVIDER(pp);
965	for (cp = LIST_FIRST(&pp->consumers); cp != NULL; cp = cp2) {
966		cp2 = LIST_NEXT(cp, consumers);
967		if (!cp->spoiled)
968			continue;
969		cp->spoiled = 0;
970		if (cp->geom->spoiled == NULL)
971			continue;
972		cp->geom->spoiled(cp);
973		g_topology_assert();
974	}
975}
976
977void
978g_spoil(struct g_provider *pp, struct g_consumer *cp)
979{
980	struct g_consumer *cp2;
981
982	g_topology_assert();
983	G_VALID_PROVIDER(pp);
984	G_VALID_CONSUMER(cp);
985
986	LIST_FOREACH(cp2, &pp->consumers, consumers) {
987		if (cp2 == cp)
988			continue;
989/*
990		KASSERT(cp2->acr == 0, ("spoiling cp->acr = %d", cp2->acr));
991		KASSERT(cp2->acw == 0, ("spoiling cp->acw = %d", cp2->acw));
992*/
993		KASSERT(cp2->ace == 0, ("spoiling cp->ace = %d", cp2->ace));
994		cp2->spoiled++;
995	}
996	g_post_event(g_spoil_event, pp, M_WAITOK, pp, NULL);
997}
998
999int
1000g_getattr__(const char *attr, struct g_consumer *cp, void *var, int len)
1001{
1002	int error, i;
1003
1004	i = len;
1005	error = g_io_getattr(attr, cp, &i, var);
1006	if (error)
1007		return (error);
1008	if (i != len)
1009		return (EINVAL);
1010	return (0);
1011}
1012
1013#if defined(DIAGNOSTIC) || defined(DDB)
1014/*
1015 * This function walks (topologically unsafely) the mesh and return a
1016 * non-zero integer if it finds the argument pointer is an object.
1017 * The return value indicates which type of object it is belived to be.
1018 * If topology is not locked, this function is potentially dangerous,
1019 * but since it is for debugging purposes and can be useful for instance
1020 * from DDB, we do not assert topology lock is held.
1021 */
1022int
1023g_valid_obj(void const *ptr)
1024{
1025	struct g_class *mp;
1026	struct g_geom *gp;
1027	struct g_consumer *cp;
1028	struct g_provider *pp;
1029
1030	LIST_FOREACH(mp, &g_classes, class) {
1031		if (ptr == mp)
1032			return (1);
1033		LIST_FOREACH(gp, &mp->geom, geom) {
1034			if (ptr == gp)
1035				return (2);
1036			LIST_FOREACH(cp, &gp->consumer, consumer)
1037				if (ptr == cp)
1038					return (3);
1039			LIST_FOREACH(pp, &gp->provider, provider)
1040				if (ptr == pp)
1041					return (4);
1042		}
1043	}
1044	return(0);
1045}
1046#endif
1047
1048#ifdef DDB
1049
1050#define	gprintf(...)	do {						\
1051	printf("%*s", indent, "");					\
1052	printf(__VA_ARGS__);						\
1053} while (0)
1054#define	gprintln(...)	do {						\
1055	gprintf(__VA_ARGS__);						\
1056	printf("\n");							\
1057} while (0)
1058
1059#define	ADDFLAG(obj, flag, sflag)	do {				\
1060	if ((obj)->flags & (flag)) {					\
1061		if (comma)						\
1062			strlcat(str, ",", size);			\
1063		strlcat(str, (sflag), size);				\
1064		comma = 1;						\
1065	}								\
1066} while (0)
1067
1068static char *
1069provider_flags_to_string(struct g_provider *pp, char *str, size_t size)
1070{
1071	int comma = 0;
1072
1073	bzero(str, size);
1074	if (pp->flags == 0) {
1075		strlcpy(str, "NONE", size);
1076		return (str);
1077	}
1078	ADDFLAG(pp, G_PF_CANDELETE, "G_PF_CANDELETE");
1079	ADDFLAG(pp, G_PF_WITHER, "G_PF_WITHER");
1080	ADDFLAG(pp, G_PF_ORPHAN, "G_PF_ORPHAN");
1081	return (str);
1082}
1083
1084static char *
1085geom_flags_to_string(struct g_geom *gp, char *str, size_t size)
1086{
1087	int comma = 0;
1088
1089	bzero(str, size);
1090	if (gp->flags == 0) {
1091		strlcpy(str, "NONE", size);
1092		return (str);
1093	}
1094	ADDFLAG(gp, G_GEOM_WITHER, "G_GEOM_WITHER");
1095	return (str);
1096}
1097static void
1098db_show_geom_consumer(int indent, struct g_consumer *cp)
1099{
1100
1101	if (indent == 0) {
1102		gprintln("consumer: %p", cp);
1103		gprintln("  class:    %s (%p)", cp->geom->class->name,
1104		    cp->geom->class);
1105		gprintln("  geom:     %s (%p)", cp->geom->name, cp->geom);
1106		if (cp->provider == NULL)
1107			gprintln("  provider: none");
1108		else {
1109			gprintln("  provider: %s (%p)", cp->provider->name,
1110			    cp->provider);
1111		}
1112		gprintln("  access:   r%dw%de%d", cp->acr, cp->acw, cp->ace);
1113		gprintln("  spoiled:  %d", cp->spoiled);
1114		gprintln("  nstart:   %u", cp->nstart);
1115		gprintln("  nend:     %u", cp->nend);
1116	} else {
1117		gprintf("consumer: %p (%s), access=r%dw%de%d", cp,
1118		    cp->provider != NULL ? cp->provider->name : "none",
1119		    cp->acr, cp->acw, cp->ace);
1120		if (cp->spoiled)
1121			printf(", spoiled=%d", cp->spoiled);
1122		printf("\n");
1123	}
1124}
1125
1126static void
1127db_show_geom_provider(int indent, struct g_provider *pp)
1128{
1129	struct g_consumer *cp;
1130	char flags[64];
1131
1132	if (indent == 0) {
1133		gprintln("provider: %s (%p)", pp->name, pp);
1134		gprintln("  class:        %s (%p)", pp->geom->class->name,
1135		    pp->geom->class);
1136		gprintln("  geom:         %s (%p)", pp->geom->name, pp->geom);
1137		gprintln("  mediasize:    %jd", (intmax_t)pp->mediasize);
1138		gprintln("  sectorsize:   %u", pp->sectorsize);
1139		gprintln("  stripesize:   %u", pp->stripesize);
1140		gprintln("  stripeoffset: %u", pp->stripeoffset);
1141		gprintln("  access:       r%dw%de%d", pp->acr, pp->acw,
1142		    pp->ace);
1143		gprintln("  flags:        %s (0x%04x)",
1144		    provider_flags_to_string(pp, flags, sizeof(flags)),
1145		    pp->flags);
1146		gprintln("  error:        %d", pp->error);
1147		gprintln("  nstart:       %u", pp->nstart);
1148		gprintln("  nend:         %u", pp->nend);
1149		if (LIST_EMPTY(&pp->consumers))
1150			gprintln("  consumers:    none");
1151	} else {
1152		gprintf("provider: %s (%p), access=r%dw%de%d",
1153		    pp->name, pp, pp->acr, pp->acw, pp->ace);
1154		if (pp->flags != 0) {
1155			printf(", flags=%s (0x%04x)",
1156			    provider_flags_to_string(pp, flags, sizeof(flags)),
1157			    pp->flags);
1158		}
1159		printf("\n");
1160	}
1161	if (!LIST_EMPTY(&pp->consumers)) {
1162		LIST_FOREACH(cp, &pp->consumers, consumers) {
1163			db_show_geom_consumer(indent + 2, cp);
1164			if (db_pager_quit)
1165				break;
1166		}
1167	}
1168}
1169
1170static void
1171db_show_geom_geom(int indent, struct g_geom *gp)
1172{
1173	struct g_provider *pp;
1174	struct g_consumer *cp;
1175	char flags[64];
1176
1177	if (indent == 0) {
1178		gprintln("geom: %s (%p)", gp->name, gp);
1179		gprintln("  class:     %s (%p)", gp->class->name, gp->class);
1180		gprintln("  flags:     %s (0x%04x)",
1181		    geom_flags_to_string(gp, flags, sizeof(flags)), gp->flags);
1182		gprintln("  rank:      %d", gp->rank);
1183		if (LIST_EMPTY(&gp->provider))
1184			gprintln("  providers: none");
1185		if (LIST_EMPTY(&gp->consumer))
1186			gprintln("  consumers: none");
1187	} else {
1188		gprintf("geom: %s (%p), rank=%d", gp->name, gp, gp->rank);
1189		if (gp->flags != 0) {
1190			printf(", flags=%s (0x%04x)",
1191			    geom_flags_to_string(gp, flags, sizeof(flags)),
1192			    gp->flags);
1193		}
1194		printf("\n");
1195	}
1196	if (!LIST_EMPTY(&gp->provider)) {
1197		LIST_FOREACH(pp, &gp->provider, provider) {
1198			db_show_geom_provider(indent + 2, pp);
1199			if (db_pager_quit)
1200				break;
1201		}
1202	}
1203	if (!LIST_EMPTY(&gp->consumer)) {
1204		LIST_FOREACH(cp, &gp->consumer, consumer) {
1205			db_show_geom_consumer(indent + 2, cp);
1206			if (db_pager_quit)
1207				break;
1208		}
1209	}
1210}
1211
1212static void
1213db_show_geom_class(struct g_class *mp)
1214{
1215	struct g_geom *gp;
1216
1217	printf("class: %s (%p)\n", mp->name, mp);
1218	LIST_FOREACH(gp, &mp->geom, geom) {
1219		db_show_geom_geom(2, gp);
1220		if (db_pager_quit)
1221			break;
1222	}
1223}
1224
1225/*
1226 * Print the GEOM topology or the given object.
1227 */
1228DB_SHOW_COMMAND(geom, db_show_geom)
1229{
1230	struct g_class *mp;
1231
1232	if (!have_addr) {
1233		/* No address given, print the entire topology. */
1234		LIST_FOREACH(mp, &g_classes, class) {
1235			db_show_geom_class(mp);
1236			printf("\n");
1237			if (db_pager_quit)
1238				break;
1239		}
1240	} else {
1241		switch (g_valid_obj((void *)addr)) {
1242		case 1:
1243			db_show_geom_class((struct g_class *)addr);
1244			break;
1245		case 2:
1246			db_show_geom_geom(0, (struct g_geom *)addr);
1247			break;
1248		case 3:
1249			db_show_geom_consumer(0, (struct g_consumer *)addr);
1250			break;
1251		case 4:
1252			db_show_geom_provider(0, (struct g_provider *)addr);
1253			break;
1254		default:
1255			printf("Not a GEOM object.\n");
1256			break;
1257		}
1258	}
1259}
1260
1261static void
1262db_print_bio_cmd(struct bio *bp)
1263{
1264	printf("  cmd: ");
1265	switch (bp->bio_cmd) {
1266	case BIO_READ: printf("BIO_READ"); break;
1267	case BIO_WRITE: printf("BIO_WRITE"); break;
1268	case BIO_DELETE: printf("BIO_DELETE"); break;
1269	case BIO_GETATTR: printf("BIO_GETATTR"); break;
1270	case BIO_FLUSH: printf("BIO_FLUSH"); break;
1271	case BIO_CMD0: printf("BIO_CMD0"); break;
1272	case BIO_CMD1: printf("BIO_CMD1"); break;
1273	case BIO_CMD2: printf("BIO_CMD2"); break;
1274	default: printf("UNKNOWN"); break;
1275	}
1276	printf("\n");
1277}
1278
1279static void
1280db_print_bio_flags(struct bio *bp)
1281{
1282	int comma;
1283
1284	comma = 0;
1285	printf("  flags: ");
1286	if (bp->bio_flags & BIO_ERROR) {
1287		printf("BIO_ERROR");
1288		comma = 1;
1289	}
1290	if (bp->bio_flags & BIO_DONE) {
1291		printf("%sBIO_ERROR", (comma ? ", " : ""));
1292		comma = 1;
1293	}
1294	if (bp->bio_flags & BIO_ONQUEUE)
1295		printf("%sBIO_ONQUEUE", (comma ? ", " : ""));
1296	printf("\n");
1297}
1298
1299/*
1300 * Print useful information in a BIO
1301 */
1302DB_SHOW_COMMAND(bio, db_show_bio)
1303{
1304	struct bio *bp;
1305
1306	if (have_addr) {
1307		bp = (struct bio *)addr;
1308		printf("BIO %p\n", bp);
1309		db_print_bio_cmd(bp);
1310		db_print_bio_flags(bp);
1311		printf("  cflags: 0x%hhx\n", bp->bio_cflags);
1312		printf("  pflags: 0x%hhx\n", bp->bio_pflags);
1313		printf("  offset: %lld\n", bp->bio_offset);
1314		printf("  length: %lld\n", bp->bio_length);
1315		printf("  bcount: %ld\n", bp->bio_bcount);
1316		printf("  resid: %ld\n", bp->bio_resid);
1317		printf("  completed: %lld\n", bp->bio_completed);
1318		printf("  children: %u\n", bp->bio_children);
1319		printf("  inbed: %u\n", bp->bio_inbed);
1320		printf("  error: %d\n", bp->bio_error);
1321		printf("  parent: %p\n", bp->bio_parent);
1322		printf("  driver1: %p\n", bp->bio_driver1);
1323		printf("  driver2: %p\n", bp->bio_driver2);
1324		printf("  caller1: %p\n", bp->bio_caller1);
1325		printf("  caller2: %p\n", bp->bio_caller2);
1326		printf("  bio_from: %p\n", bp->bio_from);
1327		printf("  bio_to: %p\n", bp->bio_to);
1328	}
1329}
1330
1331#undef	gprintf
1332#undef	gprintln
1333#undef	ADDFLAG
1334
1335#endif	/* DDB */
1336