2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2007 Lukas Ertl
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/malloc.h>
36 #include <sys/systm.h>
38 #include <geom/geom.h>
39 #include <geom/vinum/geom_vinum_var.h>
40 #include <geom/vinum/geom_vinum.h>
43 gv_volume_flush(struct gv_volume *v)
48 KASSERT(v != NULL, ("NULL v"));
50 KASSERT(sc != NULL, ("NULL sc"));
52 bp = bioq_takefirst(v->wqueue);
54 gv_volume_start(sc, bp);
55 bp = bioq_takefirst(v->wqueue);
60 gv_volume_start(struct gv_softc *sc, struct bio *bp)
64 struct gv_plex *p, *lp;
68 v = bp->bio_to->private;
69 if (v == NULL || v->state != GV_VOL_UP) {
70 g_io_deliver(bp, ENXIO);
74 switch (bp->bio_cmd) {
77 * Try to find a good plex where we can send the request to,
78 * round-robin-style. The plex either has to be up, or it's a
79 * degraded RAID5 plex. Check if we have delayed requests. Put
80 * this request on the delayed queue if so. This makes sure that
81 * we don't read old values.
83 if (bioq_first(v->wqueue) != NULL) {
84 bioq_insert_tail(v->wqueue, bp);
87 lp = v->last_read_plex;
89 lp = LIST_FIRST(&v->plexes);
90 p = LIST_NEXT(lp, in_volume);
92 p = LIST_FIRST(&v->plexes);
98 if ((p->state > GV_PLEX_DEGRADED) ||
99 (p->state >= GV_PLEX_DEGRADED &&
100 p->org == GV_PLEX_RAID5))
102 p = LIST_NEXT(p, in_volume);
104 p = LIST_FIRST(&v->plexes);
108 (p->org == GV_PLEX_RAID5 && p->state < GV_PLEX_DEGRADED) ||
109 (p->org != GV_PLEX_RAID5 && p->state <= GV_PLEX_DEGRADED)) {
110 g_io_deliver(bp, ENXIO);
113 v->last_read_plex = p;
115 /* Hand it down to the plex logic. */
116 gv_plex_start(p, bp);
121 /* Delay write-requests if any plex is synchronizing. */
122 LIST_FOREACH(p, &v->plexes, in_volume) {
123 if (p->flags & GV_PLEX_SYNCING) {
124 bioq_insert_tail(v->wqueue, bp);
130 /* Give the BIO to each plex of this volume. */
131 LIST_FOREACH(p, &v->plexes, in_volume) {
132 if (p->state < GV_PLEX_DEGRADED)
134 gv_plex_start(p, bp);
138 g_io_deliver(bp, ENXIO);
144 gv_bio_done(struct gv_softc *sc, struct bio *bp)
151 KASSERT(s != NULL, ("gv_bio_done: NULL s"));
153 KASSERT(p != NULL, ("gv_bio_done: NULL p"));
155 KASSERT(v != NULL, ("gv_bio_done: NULL v"));
159 case GV_PLEX_STRIPED:
160 gv_plex_normal_done(p, bp);
163 gv_plex_raid5_done(p, bp);
167 gv_drive_done(s->drive_sc);