2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * Copyright (c) 2013 The FreeBSD Foundation
7 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
8 * and NAI Labs, the Security Research Division of Network Associates, Inc.
9 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
10 * DARPA CHATS research program.
12 * Portions of this software were developed by Konstantin Belousov
13 * under sponsorship from the FreeBSD Foundation.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. The names of the authors may not be used to endorse or promote
24 * products derived from this software without specific prior written
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
50 #include <sys/stack.h>
51 #include <sys/sysctl.h>
54 #include <sys/errno.h>
55 #include <geom/geom.h>
56 #include <geom/geom_int.h>
57 #include <sys/devicestat.h>
61 #include <vm/vm_param.h>
62 #include <vm/vm_kern.h>
63 #include <vm/vm_page.h>
64 #include <vm/vm_object.h>
65 #include <vm/vm_extern.h>
66 #include <vm/vm_map.h>
68 static struct g_bioq g_bio_run_down;
69 static struct g_bioq g_bio_run_up;
70 static struct g_bioq g_bio_run_task;
73 static uma_zone_t biozone;
76 * The head of the list of classifiers used in g_io_request.
77 * Use g_register_classifier() and g_unregister_classifier()
78 * to add/remove entries to the list.
79 * Classifiers are invoked in registration order.
81 static TAILQ_HEAD(g_classifier_tailq, g_classifier_hook)
82 g_classifier_tailq = TAILQ_HEAD_INITIALIZER(g_classifier_tailq);
84 #include <machine/atomic.h>
87 g_bioq_lock(struct g_bioq *bq)
90 mtx_lock(&bq->bio_queue_lock);
94 g_bioq_unlock(struct g_bioq *bq)
97 mtx_unlock(&bq->bio_queue_lock);
102 g_bioq_destroy(struct g_bioq *bq)
105 mtx_destroy(&bq->bio_queue_lock);
110 g_bioq_init(struct g_bioq *bq)
113 TAILQ_INIT(&bq->bio_queue);
114 mtx_init(&bq->bio_queue_lock, "bio queue", NULL, MTX_DEF);
118 g_bioq_first(struct g_bioq *bq)
122 bp = TAILQ_FIRST(&bq->bio_queue);
124 KASSERT((bp->bio_flags & BIO_ONQUEUE),
125 ("Bio not on queue bp=%p target %p", bp, bq));
126 bp->bio_flags &= ~BIO_ONQUEUE;
127 TAILQ_REMOVE(&bq->bio_queue, bp, bio_queue);
128 bq->bio_queue_length--;
138 bp = uma_zalloc(biozone, M_NOWAIT | M_ZERO);
140 if ((KTR_COMPILE & KTR_GEOM) && (ktr_mask & KTR_GEOM)) {
143 CTR1(KTR_GEOM, "g_new_bio(): %p", bp);
145 CTRSTACK(KTR_GEOM, &st, 3, 0);
156 bp = uma_zalloc(biozone, M_WAITOK | M_ZERO);
158 if ((KTR_COMPILE & KTR_GEOM) && (ktr_mask & KTR_GEOM)) {
161 CTR1(KTR_GEOM, "g_alloc_bio(): %p", bp);
163 CTRSTACK(KTR_GEOM, &st, 3, 0);
170 g_destroy_bio(struct bio *bp)
173 if ((KTR_COMPILE & KTR_GEOM) && (ktr_mask & KTR_GEOM)) {
176 CTR1(KTR_GEOM, "g_destroy_bio(): %p", bp);
178 CTRSTACK(KTR_GEOM, &st, 3, 0);
181 uma_zfree(biozone, bp);
185 g_clone_bio(struct bio *bp)
189 bp2 = uma_zalloc(biozone, M_NOWAIT | M_ZERO);
191 bp2->bio_parent = bp;
192 bp2->bio_cmd = bp->bio_cmd;
194 * BIO_ORDERED flag may be used by disk drivers to enforce
195 * ordering restrictions, so this flag needs to be cloned.
196 * BIO_UNMAPPED should be inherited, to properly indicate
197 * which way the buffer is passed.
198 * Other bio flags are not suitable for cloning.
200 bp2->bio_flags = bp->bio_flags & (BIO_ORDERED | BIO_UNMAPPED);
201 bp2->bio_length = bp->bio_length;
202 bp2->bio_offset = bp->bio_offset;
203 bp2->bio_data = bp->bio_data;
204 bp2->bio_ma = bp->bio_ma;
205 bp2->bio_ma_n = bp->bio_ma_n;
206 bp2->bio_ma_offset = bp->bio_ma_offset;
207 bp2->bio_attribute = bp->bio_attribute;
208 /* Inherit classification info from the parent */
209 bp2->bio_classifier1 = bp->bio_classifier1;
210 bp2->bio_classifier2 = bp->bio_classifier2;
214 if ((KTR_COMPILE & KTR_GEOM) && (ktr_mask & KTR_GEOM)) {
217 CTR2(KTR_GEOM, "g_clone_bio(%p): %p", bp, bp2);
219 CTRSTACK(KTR_GEOM, &st, 3, 0);
226 g_duplicate_bio(struct bio *bp)
230 bp2 = uma_zalloc(biozone, M_WAITOK | M_ZERO);
231 bp2->bio_flags = bp->bio_flags & BIO_UNMAPPED;
232 bp2->bio_parent = bp;
233 bp2->bio_cmd = bp->bio_cmd;
234 bp2->bio_length = bp->bio_length;
235 bp2->bio_offset = bp->bio_offset;
236 bp2->bio_data = bp->bio_data;
237 bp2->bio_ma = bp->bio_ma;
238 bp2->bio_ma_n = bp->bio_ma_n;
239 bp2->bio_ma_offset = bp->bio_ma_offset;
240 bp2->bio_attribute = bp->bio_attribute;
243 if ((KTR_COMPILE & KTR_GEOM) && (ktr_mask & KTR_GEOM)) {
246 CTR2(KTR_GEOM, "g_duplicate_bio(%p): %p", bp, bp2);
248 CTRSTACK(KTR_GEOM, &st, 3, 0);
258 g_bioq_init(&g_bio_run_down);
259 g_bioq_init(&g_bio_run_up);
260 g_bioq_init(&g_bio_run_task);
261 biozone = uma_zcreate("g_bio", sizeof (struct bio),
268 g_io_getattr(const char *attr, struct g_consumer *cp, int *len, void *ptr)
273 g_trace(G_T_BIO, "bio_getattr(%s)", attr);
275 bp->bio_cmd = BIO_GETATTR;
277 bp->bio_attribute = attr;
278 bp->bio_length = *len;
280 g_io_request(bp, cp);
281 error = biowait(bp, "ggetattr");
282 *len = bp->bio_completed;
288 g_io_flush(struct g_consumer *cp)
293 g_trace(G_T_BIO, "bio_flush(%s)", cp->provider->name);
295 bp->bio_cmd = BIO_FLUSH;
296 bp->bio_flags |= BIO_ORDERED;
298 bp->bio_attribute = NULL;
299 bp->bio_offset = cp->provider->mediasize;
302 g_io_request(bp, cp);
303 error = biowait(bp, "gflush");
309 g_io_check(struct bio *bp)
311 struct g_consumer *cp;
312 struct g_provider *pp;
317 /* Fail if access counters dont allow the operation */
318 switch(bp->bio_cmd) {
333 /* if provider is marked for error, don't disturb. */
336 if (cp->flags & G_CF_ORPHAN)
339 switch(bp->bio_cmd) {
343 /* Zero sectorsize or mediasize is probably a lack of media. */
344 if (pp->sectorsize == 0 || pp->mediasize == 0)
346 /* Reject I/O not on sector boundary */
347 if (bp->bio_offset % pp->sectorsize)
349 /* Reject I/O not integral sector long */
350 if (bp->bio_length % pp->sectorsize)
352 /* Reject requests before or past the end of media. */
353 if (bp->bio_offset < 0)
355 if (bp->bio_offset > pp->mediasize)
365 * bio classification support.
367 * g_register_classifier() and g_unregister_classifier()
368 * are used to add/remove a classifier from the list.
369 * The list is protected using the g_bio_run_down lock,
370 * because the classifiers are called in this path.
372 * g_io_request() passes bio's that are not already classified
373 * (i.e. those with bio_classifier1 == NULL) to g_run_classifiers().
374 * Classifiers can store their result in the two fields
375 * bio_classifier1 and bio_classifier2.
376 * A classifier that updates one of the fields should
377 * return a non-zero value.
378 * If no classifier updates the field, g_run_classifiers() sets
379 * bio_classifier1 = BIO_NOTCLASSIFIED to avoid further calls.
383 g_register_classifier(struct g_classifier_hook *hook)
386 g_bioq_lock(&g_bio_run_down);
387 TAILQ_INSERT_TAIL(&g_classifier_tailq, hook, link);
388 g_bioq_unlock(&g_bio_run_down);
394 g_unregister_classifier(struct g_classifier_hook *hook)
396 struct g_classifier_hook *entry;
398 g_bioq_lock(&g_bio_run_down);
399 TAILQ_FOREACH(entry, &g_classifier_tailq, link) {
401 TAILQ_REMOVE(&g_classifier_tailq, hook, link);
405 g_bioq_unlock(&g_bio_run_down);
409 g_run_classifiers(struct bio *bp)
411 struct g_classifier_hook *hook;
414 TAILQ_FOREACH(hook, &g_classifier_tailq, link)
415 classified |= hook->func(hook->arg, bp);
418 bp->bio_classifier1 = BIO_NOTCLASSIFIED;
422 g_io_request(struct bio *bp, struct g_consumer *cp)
424 struct g_provider *pp;
427 KASSERT(cp != NULL, ("NULL cp in g_io_request"));
428 KASSERT(bp != NULL, ("NULL bp in g_io_request"));
430 KASSERT(pp != NULL, ("consumer not attached in g_io_request"));
432 KASSERT(bp->bio_driver1 == NULL,
433 ("bio_driver1 used by the consumer (geom %s)", cp->geom->name));
434 KASSERT(bp->bio_driver2 == NULL,
435 ("bio_driver2 used by the consumer (geom %s)", cp->geom->name));
436 KASSERT(bp->bio_pflags == 0,
437 ("bio_pflags used by the consumer (geom %s)", cp->geom->name));
439 * Remember consumer's private fields, so we can detect if they were
440 * modified by the provider.
442 bp->_bio_caller1 = bp->bio_caller1;
443 bp->_bio_caller2 = bp->bio_caller2;
444 bp->_bio_cflags = bp->bio_cflags;
447 if (bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_GETATTR)) {
448 KASSERT(bp->bio_data != NULL,
449 ("NULL bp->data in g_io_request(cmd=%hhu)", bp->bio_cmd));
451 if (bp->bio_cmd & (BIO_DELETE|BIO_FLUSH)) {
452 KASSERT(bp->bio_data == NULL,
453 ("non-NULL bp->data in g_io_request(cmd=%hhu)",
456 if (bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE)) {
457 KASSERT(bp->bio_offset % cp->provider->sectorsize == 0,
458 ("wrong offset %jd for sectorsize %u",
459 bp->bio_offset, cp->provider->sectorsize));
460 KASSERT(bp->bio_length % cp->provider->sectorsize == 0,
461 ("wrong length %jd for sectorsize %u",
462 bp->bio_length, cp->provider->sectorsize));
465 g_trace(G_T_BIO, "bio_request(%p) from %p(%s) to %p(%s) cmd %d",
466 bp, cp, cp->geom->name, pp, pp->name, bp->bio_cmd);
471 bp->bio_completed = 0;
473 KASSERT(!(bp->bio_flags & BIO_ONQUEUE),
474 ("Bio already on queue bp=%p", bp));
475 bp->bio_flags |= BIO_ONQUEUE;
478 binuptime(&bp->bio_t0);
480 getbinuptime(&bp->bio_t0);
483 * The statistics collection is lockless, as such, but we
484 * can not update one instance of the statistics from more
485 * than one thread at a time, so grab the lock first.
487 * We also use the lock to protect the list of classifiers.
489 g_bioq_lock(&g_bio_run_down);
491 if (!TAILQ_EMPTY(&g_classifier_tailq) && !bp->bio_classifier1)
492 g_run_classifiers(bp);
494 if (g_collectstats & 1)
495 devstat_start_transaction(pp->stat, &bp->bio_t0);
496 if (g_collectstats & 2)
497 devstat_start_transaction(cp->stat, &bp->bio_t0);
501 first = TAILQ_EMPTY(&g_bio_run_down.bio_queue);
502 TAILQ_INSERT_TAIL(&g_bio_run_down.bio_queue, bp, bio_queue);
503 g_bio_run_down.bio_queue_length++;
504 g_bioq_unlock(&g_bio_run_down);
506 /* Pass it on down. */
508 wakeup(&g_wait_down);
512 g_io_deliver(struct bio *bp, int error)
514 struct g_consumer *cp;
515 struct g_provider *pp;
518 KASSERT(bp != NULL, ("NULL bp in g_io_deliver"));
520 KASSERT(pp != NULL, ("NULL bio_to in g_io_deliver"));
523 bp->bio_error = error;
527 KASSERT(cp != NULL, ("NULL bio_from in g_io_deliver"));
528 KASSERT(cp->geom != NULL, ("NULL bio_from->geom in g_io_deliver"));
531 * Some classes - GJournal in particular - can modify bio's
532 * private fields while the bio is in transit; G_GEOM_VOLATILE_BIO
533 * flag means it's an expected behaviour for that particular geom.
535 if ((cp->geom->flags & G_GEOM_VOLATILE_BIO) == 0) {
536 KASSERT(bp->bio_caller1 == bp->_bio_caller1,
537 ("bio_caller1 used by the provider %s", pp->name));
538 KASSERT(bp->bio_caller2 == bp->_bio_caller2,
539 ("bio_caller2 used by the provider %s", pp->name));
540 KASSERT(bp->bio_cflags == bp->_bio_cflags,
541 ("bio_cflags used by the provider %s", pp->name));
544 KASSERT(bp->bio_completed >= 0, ("bio_completed can't be less than 0"));
545 KASSERT(bp->bio_completed <= bp->bio_length,
546 ("bio_completed can't be greater than bio_length"));
549 "g_io_deliver(%p) from %p(%s) to %p(%s) cmd %d error %d off %jd len %jd",
550 bp, cp, cp->geom->name, pp, pp->name, bp->bio_cmd, error,
551 (intmax_t)bp->bio_offset, (intmax_t)bp->bio_length);
553 KASSERT(!(bp->bio_flags & BIO_ONQUEUE),
554 ("Bio already on queue bp=%p", bp));
557 * XXX: next two doesn't belong here
559 bp->bio_bcount = bp->bio_length;
560 bp->bio_resid = bp->bio_bcount - bp->bio_completed;
563 * The statistics collection is lockless, as such, but we
564 * can not update one instance of the statistics from more
565 * than one thread at a time, so grab the lock first.
567 g_bioq_lock(&g_bio_run_up);
568 if (g_collectstats & 1)
569 devstat_end_transaction_bio(pp->stat, bp);
570 if (g_collectstats & 2)
571 devstat_end_transaction_bio(cp->stat, bp);
575 if (error != ENOMEM) {
576 bp->bio_error = error;
577 first = TAILQ_EMPTY(&g_bio_run_up.bio_queue);
578 TAILQ_INSERT_TAIL(&g_bio_run_up.bio_queue, bp, bio_queue);
579 bp->bio_flags |= BIO_ONQUEUE;
580 g_bio_run_up.bio_queue_length++;
581 g_bioq_unlock(&g_bio_run_up);
586 g_bioq_unlock(&g_bio_run_up);
589 printf("ENOMEM %p on %p(%s)\n", bp, pp, pp->name);
590 bp->bio_children = 0;
592 bp->bio_driver1 = NULL;
593 bp->bio_driver2 = NULL;
595 g_io_request(bp, cp);
600 SYSCTL_DECL(_kern_geom);
602 static long transient_maps;
603 SYSCTL_LONG(_kern_geom, OID_AUTO, transient_maps, CTLFLAG_RD,
605 "Total count of the transient mapping requests");
606 u_int transient_map_retries = 10;
607 SYSCTL_UINT(_kern_geom, OID_AUTO, transient_map_retries, CTLFLAG_RW,
608 &transient_map_retries, 0,
609 "Max count of retries used before giving up on creating transient map");
610 int transient_map_hard_failures;
611 SYSCTL_INT(_kern_geom, OID_AUTO, transient_map_hard_failures, CTLFLAG_RD,
612 &transient_map_hard_failures, 0,
613 "Failures to establish the transient mapping due to retry attempts "
615 int transient_map_soft_failures;
616 SYSCTL_INT(_kern_geom, OID_AUTO, transient_map_soft_failures, CTLFLAG_RD,
617 &transient_map_soft_failures, 0,
618 "Count of retried failures to establish the transient mapping");
619 int inflight_transient_maps;
620 SYSCTL_INT(_kern_geom, OID_AUTO, inflight_transient_maps, CTLFLAG_RD,
621 &inflight_transient_maps, 0,
622 "Current count of the active transient maps");
625 g_io_transient_map_bio(struct bio *bp)
631 KASSERT(unmapped_buf_allowed, ("unmapped disabled"));
633 size = round_page(bp->bio_ma_offset + bp->bio_length);
634 KASSERT(size / PAGE_SIZE == bp->bio_ma_n, ("Bio too short %p", bp));
637 atomic_add_long(&transient_maps, 1);
639 if (vmem_alloc(transient_arena, size, M_BESTFIT | M_NOWAIT, &addr)) {
640 if (transient_map_retries != 0 &&
641 retried >= transient_map_retries) {
642 g_io_deliver(bp, EDEADLK/* XXXKIB */);
643 CTR2(KTR_GEOM, "g_down cannot map bp %p provider %s",
644 bp, bp->bio_to->name);
645 atomic_add_int(&transient_map_hard_failures, 1);
649 * Naive attempt to quisce the I/O to get more
650 * in-flight requests completed and defragment
651 * the transient_arena.
653 CTR3(KTR_GEOM, "g_down retrymap bp %p provider %s r %d",
654 bp, bp->bio_to->name, retried);
655 pause("g_d_tra", hz / 10);
657 atomic_add_int(&transient_map_soft_failures, 1);
661 atomic_add_int(&inflight_transient_maps, 1);
662 pmap_qenter((vm_offset_t)addr, bp->bio_ma, OFF_TO_IDX(size));
663 bp->bio_data = (caddr_t)addr + bp->bio_ma_offset;
664 bp->bio_flags |= BIO_TRANSIENT_MAPPING;
665 bp->bio_flags &= ~BIO_UNMAPPED;
670 g_io_schedule_down(struct thread *tp __unused)
677 g_bioq_lock(&g_bio_run_down);
678 bp = g_bioq_first(&g_bio_run_down);
680 CTR0(KTR_GEOM, "g_down going to sleep");
681 msleep(&g_wait_down, &g_bio_run_down.bio_queue_lock,
682 PRIBIO | PDROP, "-", 0);
685 CTR0(KTR_GEOM, "g_down has work to do");
686 g_bioq_unlock(&g_bio_run_down);
688 CTR1(KTR_GEOM, "g_down pacing self (pace %d)", pace);
689 pause("g_down", hz/10);
692 error = g_io_check(bp);
694 CTR3(KTR_GEOM, "g_down g_io_check on bp %p provider "
695 "%s returned %d", bp, bp->bio_to->name, error);
696 g_io_deliver(bp, error);
699 CTR2(KTR_GEOM, "g_down processing bp %p provider %s", bp,
701 switch (bp->bio_cmd) {
705 /* Truncate requests to the end of providers media. */
707 * XXX: What if we truncate because of offset being
710 excess = bp->bio_offset + bp->bio_length;
711 if (excess > bp->bio_to->mediasize) {
712 KASSERT((bp->bio_flags & BIO_UNMAPPED) == 0 ||
713 round_page(bp->bio_ma_offset +
714 bp->bio_length) / PAGE_SIZE == bp->bio_ma_n,
715 ("excess bio %p too short", bp));
716 excess -= bp->bio_to->mediasize;
717 bp->bio_length -= excess;
718 if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
719 bp->bio_ma_n = round_page(
721 bp->bio_length) / PAGE_SIZE;
724 CTR3(KTR_GEOM, "g_down truncated bio "
725 "%p provider %s by %d", bp,
726 bp->bio_to->name, excess);
728 /* Deliver zero length transfers right here. */
729 if (bp->bio_length == 0) {
731 CTR2(KTR_GEOM, "g_down terminated 0-length "
732 "bp %p provider %s", bp, bp->bio_to->name);
739 if ((bp->bio_flags & BIO_UNMAPPED) != 0 &&
740 (bp->bio_to->flags & G_PF_ACCEPT_UNMAPPED) == 0 &&
741 (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE)) {
742 if (g_io_transient_map_bio(bp))
745 THREAD_NO_SLEEPING();
746 CTR4(KTR_GEOM, "g_down starting bp %p provider %s off %ld "
747 "len %ld", bp, bp->bio_to->name, bp->bio_offset,
749 bp->bio_to->geom->start(bp);
750 THREAD_SLEEPING_OK();
755 bio_taskqueue(struct bio *bp, bio_task_t *func, void *arg)
758 bp->bio_task_arg = arg;
760 * The taskqueue is actually just a second queue off the "up"
761 * queue, so we use the same lock.
763 g_bioq_lock(&g_bio_run_up);
764 KASSERT(!(bp->bio_flags & BIO_ONQUEUE),
765 ("Bio already on queue bp=%p target taskq", bp));
766 bp->bio_flags |= BIO_ONQUEUE;
767 TAILQ_INSERT_TAIL(&g_bio_run_task.bio_queue, bp, bio_queue);
768 g_bio_run_task.bio_queue_length++;
770 g_bioq_unlock(&g_bio_run_up);
775 g_io_schedule_up(struct thread *tp __unused)
779 g_bioq_lock(&g_bio_run_up);
780 bp = g_bioq_first(&g_bio_run_task);
782 g_bioq_unlock(&g_bio_run_up);
783 THREAD_NO_SLEEPING();
784 CTR1(KTR_GEOM, "g_up processing task bp %p", bp);
785 bp->bio_task(bp->bio_task_arg);
786 THREAD_SLEEPING_OK();
789 bp = g_bioq_first(&g_bio_run_up);
791 g_bioq_unlock(&g_bio_run_up);
792 THREAD_NO_SLEEPING();
793 CTR4(KTR_GEOM, "g_up biodone bp %p provider %s off "
794 "%jd len %ld", bp, bp->bio_to->name,
795 bp->bio_offset, bp->bio_length);
797 THREAD_SLEEPING_OK();
800 CTR0(KTR_GEOM, "g_up going to sleep");
801 msleep(&g_wait_up, &g_bio_run_up.bio_queue_lock,
802 PRIBIO | PDROP, "-", 0);
807 g_read_data(struct g_consumer *cp, off_t offset, off_t length, int *error)
813 KASSERT(length > 0 && length >= cp->provider->sectorsize &&
814 length <= MAXPHYS, ("g_read_data(): invalid length %jd",
818 bp->bio_cmd = BIO_READ;
820 bp->bio_offset = offset;
821 bp->bio_length = length;
822 ptr = g_malloc(length, M_WAITOK);
824 g_io_request(bp, cp);
825 errorc = biowait(bp, "gread");
837 g_write_data(struct g_consumer *cp, off_t offset, void *ptr, off_t length)
842 KASSERT(length > 0 && length >= cp->provider->sectorsize &&
843 length <= MAXPHYS, ("g_write_data(): invalid length %jd",
847 bp->bio_cmd = BIO_WRITE;
849 bp->bio_offset = offset;
850 bp->bio_length = length;
852 g_io_request(bp, cp);
853 error = biowait(bp, "gwrite");
859 g_delete_data(struct g_consumer *cp, off_t offset, off_t length)
864 KASSERT(length > 0 && length >= cp->provider->sectorsize,
865 ("g_delete_data(): invalid length %jd", (intmax_t)length));
868 bp->bio_cmd = BIO_DELETE;
870 bp->bio_offset = offset;
871 bp->bio_length = length;
873 g_io_request(bp, cp);
874 error = biowait(bp, "gdelete");
880 g_print_bio(struct bio *bp)
882 const char *pname, *cmd = NULL;
884 if (bp->bio_to != NULL)
885 pname = bp->bio_to->name;
889 switch (bp->bio_cmd) {
892 printf("%s[%s(attr=%s)]", pname, cmd, bp->bio_attribute);
896 printf("%s[%s]", pname, cmd);
909 printf("%s[%s()]", pname, cmd);
912 printf("%s[%s(offset=%jd, length=%jd)]", pname, cmd,
913 (intmax_t)bp->bio_offset, (intmax_t)bp->bio_length);