2 * Copyright (c) 2004, 2007 Lukas Ertl
3 * Copyright (c) 2007, 2009 Ulf Lilleengen
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * 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>
34 #include <sys/kernel.h>
35 #include <sys/kthread.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
39 #include <sys/mutex.h>
41 #include <sys/sysctl.h>
42 #include <sys/systm.h>
44 #include <geom/geom.h>
45 #include <geom/vinum/geom_vinum_var.h>
46 #include <geom/vinum/geom_vinum.h>
47 #include <geom/vinum/geom_vinum_raid5.h>
49 SYSCTL_DECL(_kern_geom);
50 static SYSCTL_NODE(_kern_geom, OID_AUTO, vinum, CTLFLAG_RW, 0,
52 u_int g_vinum_debug = 0;
53 TUNABLE_INT("kern.geom.vinum.debug", &g_vinum_debug);
54 SYSCTL_UINT(_kern_geom_vinum, OID_AUTO, debug, CTLFLAG_RW, &g_vinum_debug, 0,
57 static int gv_create(struct g_geom *, struct gctl_req *);
58 static void gv_attach(struct gv_softc *, struct gctl_req *);
59 static void gv_detach(struct gv_softc *, struct gctl_req *);
60 static void gv_parityop(struct gv_softc *, struct gctl_req *);
64 gv_orphan(struct g_consumer *cp)
72 KASSERT(cp != NULL, ("gv_orphan: null cp"));
74 KASSERT(gp != NULL, ("gv_orphan: null gp"));
76 KASSERT(sc != NULL, ("gv_orphan: null sc"));
78 KASSERT(d != NULL, ("gv_orphan: null d"));
80 g_trace(G_T_TOPOLOGY, "gv_orphan(%s)", gp->name);
82 gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL, 0, 0);
86 gv_start(struct bio *bp)
91 gp = bp->bio_to->geom;
94 switch (bp->bio_cmd) {
101 g_io_deliver(bp, EOPNOTSUPP);
104 mtx_lock(&sc->bqueue_mtx);
105 bioq_disksort(sc->bqueue_down, bp);
107 mtx_unlock(&sc->bqueue_mtx);
111 gv_done(struct bio *bp)
116 KASSERT(bp != NULL, ("NULL bp"));
118 gp = bp->bio_from->geom;
121 mtx_lock(&sc->bqueue_mtx);
122 bioq_disksort(sc->bqueue_up, bp);
124 mtx_unlock(&sc->bqueue_mtx);
128 gv_access(struct g_provider *pp, int dr, int dw, int de)
132 struct gv_drive *d, *d2;
138 * We want to modify the read count with the write count in case we have
139 * plexes in a RAID-5 organization.
143 LIST_FOREACH(d, &sc->drives, drive) {
144 if (d->consumer == NULL)
146 error = g_access(d->consumer, dr, dw, de);
148 LIST_FOREACH(d2, &sc->drives, drive) {
151 g_access(d2->consumer, -dr, -dw, -de);
153 G_VINUM_DEBUG(0, "g_access '%s' failed: %d", d->name,
162 gv_init(struct g_class *mp)
167 g_trace(G_T_TOPOLOGY, "gv_init(%p)", mp);
169 gp = g_new_geomf(mp, "VINUM");
170 gp->spoiled = gv_orphan;
171 gp->orphan = gv_orphan;
172 gp->access = gv_access;
173 gp->start = gv_start;
174 gp->softc = g_malloc(sizeof(struct gv_softc), M_WAITOK | M_ZERO);
177 sc->bqueue_down = g_malloc(sizeof(struct bio_queue_head),
179 sc->bqueue_up = g_malloc(sizeof(struct bio_queue_head),
181 bioq_init(sc->bqueue_down);
182 bioq_init(sc->bqueue_up);
183 LIST_INIT(&sc->drives);
184 LIST_INIT(&sc->subdisks);
185 LIST_INIT(&sc->plexes);
186 LIST_INIT(&sc->volumes);
187 TAILQ_INIT(&sc->equeue);
188 mtx_init(&sc->config_mtx, "gv_config", NULL, MTX_DEF);
189 mtx_init(&sc->equeue_mtx, "gv_equeue", NULL, MTX_DEF);
190 mtx_init(&sc->bqueue_mtx, "gv_bqueue", NULL, MTX_DEF);
191 kproc_create(gv_worker, sc, &sc->worker, 0, 0, "gv_worker");
195 gv_unload(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
199 g_trace(G_T_TOPOLOGY, "gv_unload(%p)", mp);
207 g_wither_geom(gp, ENXIO);
213 /* Handle userland request of attaching object. */
215 gv_attach(struct gv_softc *sc, struct gctl_req *req)
221 int *rename, type_child, type_parent;
222 char *child, *parent;
224 child = gctl_get_param(req, "child", NULL);
226 gctl_error(req, "no child given");
229 parent = gctl_get_param(req, "parent", NULL);
230 if (parent == NULL) {
231 gctl_error(req, "no parent given");
234 offset = gctl_get_paraml(req, "offset", sizeof(*offset));
235 if (offset == NULL) {
236 gctl_error(req, "no offset given");
239 rename = gctl_get_paraml(req, "rename", sizeof(*rename));
240 if (rename == NULL) {
241 gctl_error(req, "no rename flag given");
245 type_child = gv_object_type(sc, child);
246 type_parent = gv_object_type(sc, parent);
248 switch (type_child) {
250 if (type_parent != GV_TYPE_VOL) {
251 gctl_error(req, "no such volume to attach to");
254 v = gv_find_vol(sc, parent);
255 p = gv_find_plex(sc, child);
256 gv_post_event(sc, GV_EVENT_ATTACH_PLEX, p, v, *offset, *rename);
259 if (type_parent != GV_TYPE_PLEX) {
260 gctl_error(req, "no such plex to attach to");
263 p = gv_find_plex(sc, parent);
264 s = gv_find_sd(sc, child);
265 gv_post_event(sc, GV_EVENT_ATTACH_SD, s, p, *offset, *rename);
268 gctl_error(req, "invalid child type");
273 /* Handle userland request of detaching object. */
275 gv_detach(struct gv_softc *sc, struct gctl_req *req)
282 object = gctl_get_param(req, "object", NULL);
283 if (object == NULL) {
284 gctl_error(req, "no argument given");
288 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
289 type = gv_object_type(sc, object);
292 p = gv_find_plex(sc, object);
293 gv_post_event(sc, GV_EVENT_DETACH_PLEX, p, NULL, *flags, 0);
296 s = gv_find_sd(sc, object);
297 gv_post_event(sc, GV_EVENT_DETACH_SD, s, NULL, *flags, 0);
300 gctl_error(req, "invalid object type");
305 /* Handle userland requests for creating new objects. */
307 gv_create(struct g_geom *gp, struct gctl_req *req)
310 struct gv_drive *d, *d2;
311 struct gv_plex *p, *p2;
312 struct gv_sd *s, *s2;
313 struct gv_volume *v, *v2;
314 struct g_provider *pp;
315 int error, i, *drives, *flags, *plexes, *subdisks, *volumes;
322 /* Find out how many of each object have been passed in. */
323 volumes = gctl_get_paraml(req, "volumes", sizeof(*volumes));
324 plexes = gctl_get_paraml(req, "plexes", sizeof(*plexes));
325 subdisks = gctl_get_paraml(req, "subdisks", sizeof(*subdisks));
326 drives = gctl_get_paraml(req, "drives", sizeof(*drives));
327 if (volumes == NULL || plexes == NULL || subdisks == NULL ||
329 gctl_error(req, "number of objects not given");
332 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
334 gctl_error(req, "flags not given");
338 /* First, handle drive definitions ... */
339 for (i = 0; i < *drives; i++) {
340 snprintf(buf, sizeof(buf), "drive%d", i);
341 d2 = gctl_get_paraml(req, buf, sizeof(*d2));
343 gctl_error(req, "no drive definition given");
347 * Make sure that the device specified in the drive config is
348 * an active GEOM provider.
350 pp = g_provider_by_name(d2->device);
352 gctl_error(req, "%s: device not found", d2->device);
355 if (gv_find_drive(sc, d2->name) != NULL) {
357 if (*flags & GV_FLAG_F)
359 gctl_error(req, "drive '%s' already exists", d2->name);
362 if (gv_find_drive_device(sc, d2->device) != NULL) {
363 gctl_error(req, "device '%s' already configured in "
364 "gvinum", d2->device);
369 d = g_malloc(sizeof(*d), M_WAITOK | M_ZERO);
370 bcopy(d2, d, sizeof(*d));
372 gv_post_event(sc, GV_EVENT_CREATE_DRIVE, d, NULL, 0, 0);
375 /* ... then volume definitions ... */
376 for (i = 0; i < *volumes; i++) {
378 snprintf(buf, sizeof(buf), "volume%d", i);
379 v2 = gctl_get_paraml(req, buf, sizeof(*v2));
381 gctl_error(req, "no volume definition given");
384 if (gv_find_vol(sc, v2->name) != NULL) {
386 if (*flags & GV_FLAG_F)
388 gctl_error(req, "volume '%s' already exists", v2->name);
392 v = g_malloc(sizeof(*v), M_WAITOK | M_ZERO);
393 bcopy(v2, v, sizeof(*v));
395 gv_post_event(sc, GV_EVENT_CREATE_VOLUME, v, NULL, 0, 0);
398 /* ... then plex definitions ... */
399 for (i = 0; i < *plexes; i++) {
401 snprintf(buf, sizeof(buf), "plex%d", i);
402 p2 = gctl_get_paraml(req, buf, sizeof(*p2));
404 gctl_error(req, "no plex definition given");
407 if (gv_find_plex(sc, p2->name) != NULL) {
409 if (*flags & GV_FLAG_F)
411 gctl_error(req, "plex '%s' already exists", p2->name);
415 p = g_malloc(sizeof(*p), M_WAITOK | M_ZERO);
416 bcopy(p2, p, sizeof(*p));
418 gv_post_event(sc, GV_EVENT_CREATE_PLEX, p, NULL, 0, 0);
421 /* ... and, finally, subdisk definitions. */
422 for (i = 0; i < *subdisks; i++) {
424 snprintf(buf, sizeof(buf), "sd%d", i);
425 s2 = gctl_get_paraml(req, buf, sizeof(*s2));
427 gctl_error(req, "no subdisk definition given");
430 if (gv_find_sd(sc, s2->name) != NULL) {
432 if (*flags & GV_FLAG_F)
434 gctl_error(req, "sd '%s' already exists", s2->name);
438 s = g_malloc(sizeof(*s), M_WAITOK | M_ZERO);
439 bcopy(s2, s, sizeof(*s));
441 gv_post_event(sc, GV_EVENT_CREATE_SD, s, NULL, 0, 0);
445 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc, NULL, 0, 0);
446 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
452 gv_config(struct gctl_req *req, struct g_class *mp, char const *verb)
461 gp = LIST_FIRST(&mp->geom);
464 if (!strcmp(verb, "attach")) {
467 } else if (!strcmp(verb, "concat")) {
470 } else if (!strcmp(verb, "detach")) {
473 } else if (!strcmp(verb, "list")) {
476 /* Save our configuration back to disk. */
477 } else if (!strcmp(verb, "saveconfig")) {
478 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
480 /* Return configuration in string form. */
481 } else if (!strcmp(verb, "getconfig")) {
482 comment = gctl_get_param(req, "comment", NULL);
483 if (comment == NULL) {
484 gctl_error(req, "no comment parameter given");
487 sb = sbuf_new(NULL, NULL, GV_CFG_LEN, SBUF_FIXEDLEN);
488 gv_format_config(sc, sb, 0, comment);
490 gctl_set_param(req, "config", sbuf_data(sb), sbuf_len(sb) + 1);
493 } else if (!strcmp(verb, "create")) {
496 } else if (!strcmp(verb, "mirror")) {
499 } else if (!strcmp(verb, "move")) {
502 } else if (!strcmp(verb, "raid5")) {
505 } else if (!strcmp(verb, "rebuildparity") ||
506 !strcmp(verb, "checkparity")) {
507 gv_parityop(sc, req);
509 } else if (!strcmp(verb, "remove")) {
512 } else if (!strcmp(verb, "rename")) {
515 } else if (!strcmp(verb, "resetconfig")) {
516 gv_post_event(sc, GV_EVENT_RESET_CONFIG, sc, NULL, 0, 0);
518 } else if (!strcmp(verb, "start")) {
519 gv_start_obj(gp, req);
521 } else if (!strcmp(verb, "stripe")) {
524 } else if (!strcmp(verb, "setstate")) {
525 gv_setstate(gp, req);
527 gctl_error(req, "Unknown verb parameter");
531 gv_parityop(struct gv_softc *sc, struct gctl_req *req)
534 int *flags, *rebuild, type;
537 plex = gctl_get_param(req, "plex", NULL);
539 gctl_error(req, "no plex given");
543 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
545 gctl_error(req, "no flags given");
549 rebuild = gctl_get_paraml(req, "rebuild", sizeof(*rebuild));
550 if (rebuild == NULL) {
551 gctl_error(req, "no operation given");
555 type = gv_object_type(sc, plex);
556 if (type != GV_TYPE_PLEX) {
557 gctl_error(req, "'%s' is not a plex", plex);
560 p = gv_find_plex(sc, plex);
562 if (p->state != GV_PLEX_UP) {
563 gctl_error(req, "plex %s is not completely accessible",
568 if (p->org != GV_PLEX_RAID5) {
569 gctl_error(req, "plex %s is not a RAID5 plex", p->name);
573 /* Put it in the event queue. */
574 /* XXX: The state of the plex might have changed when this event is
575 * picked up ... We should perhaps check this afterwards. */
577 gv_post_event(sc, GV_EVENT_PARITY_REBUILD, p, NULL, 0, 0);
579 gv_post_event(sc, GV_EVENT_PARITY_CHECK, p, NULL, 0, 0);
583 static struct g_geom *
584 gv_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
587 struct g_consumer *cp;
593 g_trace(G_T_TOPOLOGY, "gv_taste(%s, %s)", mp->name, pp->name);
595 gp = LIST_FIRST(&mp->geom);
597 G_VINUM_DEBUG(0, "error: tasting, but not initialized?");
602 cp = g_new_consumer(gp);
603 if (g_attach(cp, pp) != 0) {
604 g_destroy_consumer(cp);
607 if (g_access(cp, 1, 0, 0) != 0) {
609 g_destroy_consumer(cp);
614 error = gv_read_header(cp, &vhdr);
617 g_access(cp, -1, 0, 0);
619 g_destroy_consumer(cp);
621 /* Check if what we've been given is a valid vinum drive. */
623 gv_post_event(sc, GV_EVENT_DRIVE_TASTED, pp, NULL, 0, 0);
631 struct g_provider *pp;
639 int newstate, flags, err, rename;
644 KASSERT(sc != NULL, ("NULL sc"));
646 /* Look at the events first... */
647 ev = gv_get_event(sc);
649 gv_remove_event(sc, ev);
652 case GV_EVENT_DRIVE_TASTED:
653 G_VINUM_DEBUG(2, "event 'drive tasted'");
655 gv_drive_tasted(sc, pp);
658 case GV_EVENT_DRIVE_LOST:
659 G_VINUM_DEBUG(2, "event 'drive lost'");
661 gv_drive_lost(sc, d);
664 case GV_EVENT_CREATE_DRIVE:
665 G_VINUM_DEBUG(2, "event 'create drive'");
667 gv_create_drive(sc, d);
670 case GV_EVENT_CREATE_VOLUME:
671 G_VINUM_DEBUG(2, "event 'create volume'");
673 gv_create_volume(sc, v);
676 case GV_EVENT_CREATE_PLEX:
677 G_VINUM_DEBUG(2, "event 'create plex'");
679 gv_create_plex(sc, p);
682 case GV_EVENT_CREATE_SD:
683 G_VINUM_DEBUG(2, "event 'create sd'");
688 case GV_EVENT_RM_DRIVE:
689 G_VINUM_DEBUG(2, "event 'remove drive'");
692 gv_rm_drive(sc, d, flags);
693 /*gv_setup_objects(sc);*/
696 case GV_EVENT_RM_VOLUME:
697 G_VINUM_DEBUG(2, "event 'remove volume'");
700 /*gv_setup_objects(sc);*/
703 case GV_EVENT_RM_PLEX:
704 G_VINUM_DEBUG(2, "event 'remove plex'");
707 /*gv_setup_objects(sc);*/
711 G_VINUM_DEBUG(2, "event 'remove sd'");
714 /*gv_setup_objects(sc);*/
717 case GV_EVENT_SAVE_CONFIG:
718 G_VINUM_DEBUG(2, "event 'save config'");
722 case GV_EVENT_SET_SD_STATE:
723 G_VINUM_DEBUG(2, "event 'setstate sd'");
727 err = gv_set_sd_state(s, newstate, flags);
729 G_VINUM_DEBUG(0, "error setting subdisk"
730 " state: error code %d", err);
733 case GV_EVENT_SET_DRIVE_STATE:
734 G_VINUM_DEBUG(2, "event 'setstate drive'");
738 err = gv_set_drive_state(d, newstate, flags);
740 G_VINUM_DEBUG(0, "error setting drive "
741 "state: error code %d", err);
744 case GV_EVENT_SET_VOL_STATE:
745 G_VINUM_DEBUG(2, "event 'setstate volume'");
749 err = gv_set_vol_state(v, newstate, flags);
751 G_VINUM_DEBUG(0, "error setting volume "
752 "state: error code %d", err);
755 case GV_EVENT_SET_PLEX_STATE:
756 G_VINUM_DEBUG(2, "event 'setstate plex'");
760 err = gv_set_plex_state(p, newstate, flags);
762 G_VINUM_DEBUG(0, "error setting plex "
763 "state: error code %d", err);
766 case GV_EVENT_SETUP_OBJECTS:
767 G_VINUM_DEBUG(2, "event 'setup objects'");
768 gv_setup_objects(sc);
771 case GV_EVENT_RESET_CONFIG:
772 G_VINUM_DEBUG(2, "event 'resetconfig'");
773 err = gv_resetconfig(sc);
775 G_VINUM_DEBUG(0, "error resetting "
776 "config: error code %d", err);
779 case GV_EVENT_PARITY_REBUILD:
781 * Start the rebuild. The gv_plex_done will
782 * handle issuing of the remaining rebuild bio's
783 * until it's finished.
785 G_VINUM_DEBUG(2, "event 'rebuild'");
787 if (p->state != GV_PLEX_UP) {
788 G_VINUM_DEBUG(0, "plex %s is not "
789 "completely accessible", p->name);
792 if (p->flags & GV_PLEX_SYNCING ||
793 p->flags & GV_PLEX_REBUILDING ||
794 p->flags & GV_PLEX_GROWING) {
795 G_VINUM_DEBUG(0, "plex %s is busy with "
796 "syncing or parity build", p->name);
800 p->flags |= GV_PLEX_REBUILDING;
801 g_topology_assert_not();
803 err = gv_access(p->vol_sc->provider, 1, 1, 0);
805 G_VINUM_DEBUG(0, "unable to access "
810 gv_parity_request(p, GV_BIO_CHECK |
814 case GV_EVENT_PARITY_CHECK:
815 /* Start parity check. */
816 G_VINUM_DEBUG(2, "event 'check'");
818 if (p->state != GV_PLEX_UP) {
819 G_VINUM_DEBUG(0, "plex %s is not "
820 "completely accessible", p->name);
823 if (p->flags & GV_PLEX_SYNCING ||
824 p->flags & GV_PLEX_REBUILDING ||
825 p->flags & GV_PLEX_GROWING) {
826 G_VINUM_DEBUG(0, "plex %s is busy with "
827 "syncing or parity build", p->name);
831 g_topology_assert_not();
833 err = gv_access(p->vol_sc->provider, 1, 1, 0);
835 G_VINUM_DEBUG(0, "unable to access "
840 gv_parity_request(p, GV_BIO_CHECK, 0);
843 case GV_EVENT_START_PLEX:
844 G_VINUM_DEBUG(2, "event 'start' plex");
849 case GV_EVENT_START_VOLUME:
850 G_VINUM_DEBUG(2, "event 'start' volume");
855 case GV_EVENT_ATTACH_PLEX:
856 G_VINUM_DEBUG(2, "event 'attach' plex");
860 err = gv_attach_plex(p, v, rename);
862 G_VINUM_DEBUG(0, "error attaching %s to"
863 " %s: error code %d", p->name,
867 case GV_EVENT_ATTACH_SD:
868 G_VINUM_DEBUG(2, "event 'attach' sd");
873 err = gv_attach_sd(s, p, offset, rename);
875 G_VINUM_DEBUG(0, "error attaching %s to"
876 " %s: error code %d", s->name,
880 case GV_EVENT_DETACH_PLEX:
881 G_VINUM_DEBUG(2, "event 'detach' plex");
884 err = gv_detach_plex(p, flags);
886 G_VINUM_DEBUG(0, "error detaching %s: "
887 "error code %d", p->name, err);
890 case GV_EVENT_DETACH_SD:
891 G_VINUM_DEBUG(2, "event 'detach' sd");
894 err = gv_detach_sd(s, flags);
896 G_VINUM_DEBUG(0, "error detaching %s: "
897 "error code %d", s->name, err);
900 case GV_EVENT_RENAME_VOL:
901 G_VINUM_DEBUG(2, "event 'rename' volume");
905 err = gv_rename_vol(sc, v, newname, flags);
907 G_VINUM_DEBUG(0, "error renaming %s to "
908 "%s: error code %d", v->name,
911 /* Destroy and recreate the provider if we can. */
912 if (gv_provider_is_open(v->provider)) {
913 G_VINUM_DEBUG(0, "unable to rename "
914 "provider to %s: provider in use",
919 g_wither_provider(v->provider, ENOENT);
922 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc,
926 case GV_EVENT_RENAME_PLEX:
927 G_VINUM_DEBUG(2, "event 'rename' plex");
931 err = gv_rename_plex(sc, p, newname, flags);
933 G_VINUM_DEBUG(0, "error renaming %s to "
934 "%s: error code %d", p->name,
939 case GV_EVENT_RENAME_SD:
940 G_VINUM_DEBUG(2, "event 'rename' sd");
944 err = gv_rename_sd(sc, s, newname, flags);
946 G_VINUM_DEBUG(0, "error renaming %s to "
947 "%s: error code %d", s->name,
952 case GV_EVENT_RENAME_DRIVE:
953 G_VINUM_DEBUG(2, "event 'rename' drive");
957 err = gv_rename_drive(sc, d, newname, flags);
959 G_VINUM_DEBUG(0, "error renaming %s to "
960 "%s: error code %d", d->name,
965 case GV_EVENT_MOVE_SD:
966 G_VINUM_DEBUG(2, "event 'move' sd");
970 err = gv_move_sd(sc, s, d, flags);
972 G_VINUM_DEBUG(0, "error moving %s to "
973 "%s: error code %d", s->name,
977 case GV_EVENT_THREAD_EXIT:
978 G_VINUM_DEBUG(2, "event 'thread exit'");
980 mtx_lock(&sc->equeue_mtx);
981 mtx_lock(&sc->bqueue_mtx);
983 mtx_destroy(&sc->bqueue_mtx);
984 mtx_destroy(&sc->equeue_mtx);
985 g_free(sc->bqueue_down);
986 g_free(sc->bqueue_up);
992 G_VINUM_DEBUG(1, "unknown event %d", ev->type);
999 /* ... then do I/O processing. */
1000 mtx_lock(&sc->bqueue_mtx);
1001 /* First do new requests. */
1002 bp = bioq_takefirst(sc->bqueue_down);
1004 mtx_unlock(&sc->bqueue_mtx);
1005 /* A bio that interfered with another bio. */
1006 if (bp->bio_pflags & GV_BIO_ONHOLD) {
1007 s = bp->bio_caller1;
1009 /* Is it still locked out? */
1010 if (gv_stripe_active(p, bp)) {
1011 /* Park the bio on the waiting queue. */
1012 bioq_disksort(p->wqueue, bp);
1014 bp->bio_pflags &= ~GV_BIO_ONHOLD;
1015 g_io_request(bp, s->drive_sc->consumer);
1017 /* A special request requireing special handling. */
1018 } else if (bp->bio_pflags & GV_BIO_INTERNAL) {
1019 p = bp->bio_caller1;
1020 gv_plex_start(p, bp);
1022 gv_volume_start(sc, bp);
1024 mtx_lock(&sc->bqueue_mtx);
1026 /* Then do completed requests. */
1027 bp = bioq_takefirst(sc->bqueue_up);
1029 msleep(sc, &sc->bqueue_mtx, PRIBIO, "-", hz/10);
1030 mtx_unlock(&sc->bqueue_mtx);
1033 mtx_unlock(&sc->bqueue_mtx);
1034 gv_bio_done(sc, bp);
1038 #define VINUM_CLASS_NAME "VINUM"
1040 static struct g_class g_vinum_class = {
1041 .name = VINUM_CLASS_NAME,
1042 .version = G_VERSION,
1045 .ctlreq = gv_config,
1046 .destroy_geom = gv_unload,
1049 DECLARE_GEOM_CLASS(g_vinum_class, g_vinum);