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 SYSCTL_UINT(_kern_geom_vinum, OID_AUTO, debug, CTLFLAG_RWTUN, &g_vinum_debug, 0,
56 static int gv_create(struct g_geom *, struct gctl_req *);
57 static void gv_attach(struct gv_softc *, struct gctl_req *);
58 static void gv_detach(struct gv_softc *, struct gctl_req *);
59 static void gv_parityop(struct gv_softc *, struct gctl_req *);
63 gv_orphan(struct g_consumer *cp)
71 KASSERT(cp != NULL, ("gv_orphan: null cp"));
73 KASSERT(gp != NULL, ("gv_orphan: null gp"));
75 KASSERT(sc != NULL, ("gv_orphan: null sc"));
77 KASSERT(d != NULL, ("gv_orphan: null d"));
79 g_trace(G_T_TOPOLOGY, "gv_orphan(%s)", gp->name);
81 gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL, 0, 0);
85 gv_start(struct bio *bp)
90 gp = bp->bio_to->geom;
93 switch (bp->bio_cmd) {
100 g_io_deliver(bp, EOPNOTSUPP);
103 mtx_lock(&sc->bqueue_mtx);
104 bioq_disksort(sc->bqueue_down, bp);
106 mtx_unlock(&sc->bqueue_mtx);
110 gv_done(struct bio *bp)
115 KASSERT(bp != NULL, ("NULL bp"));
117 gp = bp->bio_from->geom;
120 mtx_lock(&sc->bqueue_mtx);
121 bioq_disksort(sc->bqueue_up, bp);
123 mtx_unlock(&sc->bqueue_mtx);
127 gv_access(struct g_provider *pp, int dr, int dw, int de)
131 struct gv_drive *d, *d2;
137 * We want to modify the read count with the write count in case we have
138 * plexes in a RAID-5 organization.
142 LIST_FOREACH(d, &sc->drives, drive) {
143 if (d->consumer == NULL)
145 error = g_access(d->consumer, dr, dw, de);
147 LIST_FOREACH(d2, &sc->drives, drive) {
150 g_access(d2->consumer, -dr, -dw, -de);
152 G_VINUM_DEBUG(0, "g_access '%s' failed: %d", d->name,
161 gv_init(struct g_class *mp)
166 g_trace(G_T_TOPOLOGY, "gv_init(%p)", mp);
168 gp = g_new_geomf(mp, "VINUM");
169 gp->spoiled = gv_orphan;
170 gp->orphan = gv_orphan;
171 gp->access = gv_access;
172 gp->start = gv_start;
173 gp->softc = g_malloc(sizeof(struct gv_softc), M_WAITOK | M_ZERO);
176 sc->bqueue_down = g_malloc(sizeof(struct bio_queue_head),
178 sc->bqueue_up = g_malloc(sizeof(struct bio_queue_head),
180 bioq_init(sc->bqueue_down);
181 bioq_init(sc->bqueue_up);
182 LIST_INIT(&sc->drives);
183 LIST_INIT(&sc->subdisks);
184 LIST_INIT(&sc->plexes);
185 LIST_INIT(&sc->volumes);
186 TAILQ_INIT(&sc->equeue);
187 mtx_init(&sc->config_mtx, "gv_config", NULL, MTX_DEF);
188 mtx_init(&sc->equeue_mtx, "gv_equeue", NULL, MTX_DEF);
189 mtx_init(&sc->bqueue_mtx, "gv_bqueue", NULL, MTX_DEF);
190 kproc_create(gv_worker, sc, &sc->worker, 0, 0, "gv_worker");
194 gv_unload(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
198 g_trace(G_T_TOPOLOGY, "gv_unload(%p)", mp);
206 g_wither_geom(gp, ENXIO);
212 /* Handle userland request of attaching object. */
214 gv_attach(struct gv_softc *sc, struct gctl_req *req)
220 int *rename, type_child, type_parent;
221 char *child, *parent;
223 child = gctl_get_param(req, "child", NULL);
225 gctl_error(req, "no child given");
228 parent = gctl_get_param(req, "parent", NULL);
229 if (parent == NULL) {
230 gctl_error(req, "no parent given");
233 offset = gctl_get_paraml(req, "offset", sizeof(*offset));
234 if (offset == NULL) {
235 gctl_error(req, "no offset given");
238 rename = gctl_get_paraml(req, "rename", sizeof(*rename));
239 if (rename == NULL) {
240 gctl_error(req, "no rename flag given");
244 type_child = gv_object_type(sc, child);
245 type_parent = gv_object_type(sc, parent);
247 switch (type_child) {
249 if (type_parent != GV_TYPE_VOL) {
250 gctl_error(req, "no such volume to attach to");
253 v = gv_find_vol(sc, parent);
254 p = gv_find_plex(sc, child);
255 gv_post_event(sc, GV_EVENT_ATTACH_PLEX, p, v, *offset, *rename);
258 if (type_parent != GV_TYPE_PLEX) {
259 gctl_error(req, "no such plex to attach to");
262 p = gv_find_plex(sc, parent);
263 s = gv_find_sd(sc, child);
264 gv_post_event(sc, GV_EVENT_ATTACH_SD, s, p, *offset, *rename);
267 gctl_error(req, "invalid child type");
272 /* Handle userland request of detaching object. */
274 gv_detach(struct gv_softc *sc, struct gctl_req *req)
281 object = gctl_get_param(req, "object", NULL);
282 if (object == NULL) {
283 gctl_error(req, "no argument given");
287 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
288 type = gv_object_type(sc, object);
291 p = gv_find_plex(sc, object);
292 gv_post_event(sc, GV_EVENT_DETACH_PLEX, p, NULL, *flags, 0);
295 s = gv_find_sd(sc, object);
296 gv_post_event(sc, GV_EVENT_DETACH_SD, s, NULL, *flags, 0);
299 gctl_error(req, "invalid object type");
304 /* Handle userland requests for creating new objects. */
306 gv_create(struct g_geom *gp, struct gctl_req *req)
309 struct gv_drive *d, *d2;
310 struct gv_plex *p, *p2;
311 struct gv_sd *s, *s2;
312 struct gv_volume *v, *v2;
313 struct g_provider *pp;
314 int error, i, *drives, *flags, *plexes, *subdisks, *volumes;
321 /* Find out how many of each object have been passed in. */
322 volumes = gctl_get_paraml(req, "volumes", sizeof(*volumes));
323 plexes = gctl_get_paraml(req, "plexes", sizeof(*plexes));
324 subdisks = gctl_get_paraml(req, "subdisks", sizeof(*subdisks));
325 drives = gctl_get_paraml(req, "drives", sizeof(*drives));
326 if (volumes == NULL || plexes == NULL || subdisks == NULL ||
328 gctl_error(req, "number of objects not given");
331 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
333 gctl_error(req, "flags not given");
337 /* First, handle drive definitions ... */
338 for (i = 0; i < *drives; i++) {
339 snprintf(buf, sizeof(buf), "drive%d", i);
340 d2 = gctl_get_paraml(req, buf, sizeof(*d2));
342 gctl_error(req, "no drive definition given");
346 * Make sure that the device specified in the drive config is
347 * an active GEOM provider.
349 pp = g_provider_by_name(d2->device);
351 gctl_error(req, "%s: device not found", d2->device);
354 if (gv_find_drive(sc, d2->name) != NULL) {
356 if (*flags & GV_FLAG_F)
358 gctl_error(req, "drive '%s' already exists", d2->name);
361 if (gv_find_drive_device(sc, d2->device) != NULL) {
362 gctl_error(req, "device '%s' already configured in "
363 "gvinum", d2->device);
368 d = g_malloc(sizeof(*d), M_WAITOK | M_ZERO);
369 bcopy(d2, d, sizeof(*d));
371 gv_post_event(sc, GV_EVENT_CREATE_DRIVE, d, NULL, 0, 0);
374 /* ... then volume definitions ... */
375 for (i = 0; i < *volumes; i++) {
377 snprintf(buf, sizeof(buf), "volume%d", i);
378 v2 = gctl_get_paraml(req, buf, sizeof(*v2));
380 gctl_error(req, "no volume definition given");
383 if (gv_find_vol(sc, v2->name) != NULL) {
385 if (*flags & GV_FLAG_F)
387 gctl_error(req, "volume '%s' already exists", v2->name);
391 v = g_malloc(sizeof(*v), M_WAITOK | M_ZERO);
392 bcopy(v2, v, sizeof(*v));
394 gv_post_event(sc, GV_EVENT_CREATE_VOLUME, v, NULL, 0, 0);
397 /* ... then plex definitions ... */
398 for (i = 0; i < *plexes; i++) {
400 snprintf(buf, sizeof(buf), "plex%d", i);
401 p2 = gctl_get_paraml(req, buf, sizeof(*p2));
403 gctl_error(req, "no plex definition given");
406 if (gv_find_plex(sc, p2->name) != NULL) {
408 if (*flags & GV_FLAG_F)
410 gctl_error(req, "plex '%s' already exists", p2->name);
414 p = g_malloc(sizeof(*p), M_WAITOK | M_ZERO);
415 bcopy(p2, p, sizeof(*p));
417 gv_post_event(sc, GV_EVENT_CREATE_PLEX, p, NULL, 0, 0);
420 /* ... and, finally, subdisk definitions. */
421 for (i = 0; i < *subdisks; i++) {
423 snprintf(buf, sizeof(buf), "sd%d", i);
424 s2 = gctl_get_paraml(req, buf, sizeof(*s2));
426 gctl_error(req, "no subdisk definition given");
429 if (gv_find_sd(sc, s2->name) != NULL) {
431 if (*flags & GV_FLAG_F)
433 gctl_error(req, "sd '%s' already exists", s2->name);
437 s = g_malloc(sizeof(*s), M_WAITOK | M_ZERO);
438 bcopy(s2, s, sizeof(*s));
440 gv_post_event(sc, GV_EVENT_CREATE_SD, s, NULL, 0, 0);
444 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc, NULL, 0, 0);
445 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
451 gv_config(struct gctl_req *req, struct g_class *mp, char const *verb)
460 gp = LIST_FIRST(&mp->geom);
463 if (!strcmp(verb, "attach")) {
466 } else if (!strcmp(verb, "concat")) {
469 } else if (!strcmp(verb, "detach")) {
472 } else if (!strcmp(verb, "list")) {
475 /* Save our configuration back to disk. */
476 } else if (!strcmp(verb, "saveconfig")) {
477 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
479 /* Return configuration in string form. */
480 } else if (!strcmp(verb, "getconfig")) {
481 comment = gctl_get_param(req, "comment", NULL);
482 if (comment == NULL) {
483 gctl_error(req, "no comment parameter given");
486 sb = sbuf_new(NULL, NULL, GV_CFG_LEN, SBUF_FIXEDLEN);
487 gv_format_config(sc, sb, 0, comment);
489 gctl_set_param(req, "config", sbuf_data(sb), sbuf_len(sb) + 1);
492 } else if (!strcmp(verb, "create")) {
495 } else if (!strcmp(verb, "mirror")) {
498 } else if (!strcmp(verb, "move")) {
501 } else if (!strcmp(verb, "raid5")) {
504 } else if (!strcmp(verb, "rebuildparity") ||
505 !strcmp(verb, "checkparity")) {
506 gv_parityop(sc, req);
508 } else if (!strcmp(verb, "remove")) {
511 } else if (!strcmp(verb, "rename")) {
514 } else if (!strcmp(verb, "resetconfig")) {
515 gv_post_event(sc, GV_EVENT_RESET_CONFIG, sc, NULL, 0, 0);
517 } else if (!strcmp(verb, "start")) {
518 gv_start_obj(gp, req);
520 } else if (!strcmp(verb, "stripe")) {
523 } else if (!strcmp(verb, "setstate")) {
524 gv_setstate(gp, req);
526 gctl_error(req, "Unknown verb parameter");
530 gv_parityop(struct gv_softc *sc, struct gctl_req *req)
533 int *flags, *rebuild, type;
536 plex = gctl_get_param(req, "plex", NULL);
538 gctl_error(req, "no plex given");
542 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
544 gctl_error(req, "no flags given");
548 rebuild = gctl_get_paraml(req, "rebuild", sizeof(*rebuild));
549 if (rebuild == NULL) {
550 gctl_error(req, "no operation given");
554 type = gv_object_type(sc, plex);
555 if (type != GV_TYPE_PLEX) {
556 gctl_error(req, "'%s' is not a plex", plex);
559 p = gv_find_plex(sc, plex);
561 if (p->state != GV_PLEX_UP) {
562 gctl_error(req, "plex %s is not completely accessible",
567 if (p->org != GV_PLEX_RAID5) {
568 gctl_error(req, "plex %s is not a RAID5 plex", p->name);
572 /* Put it in the event queue. */
573 /* XXX: The state of the plex might have changed when this event is
574 * picked up ... We should perhaps check this afterwards. */
576 gv_post_event(sc, GV_EVENT_PARITY_REBUILD, p, NULL, 0, 0);
578 gv_post_event(sc, GV_EVENT_PARITY_CHECK, p, NULL, 0, 0);
582 static struct g_geom *
583 gv_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
586 struct g_consumer *cp;
592 g_trace(G_T_TOPOLOGY, "gv_taste(%s, %s)", mp->name, pp->name);
594 gp = LIST_FIRST(&mp->geom);
596 G_VINUM_DEBUG(0, "error: tasting, but not initialized?");
601 cp = g_new_consumer(gp);
602 if (g_attach(cp, pp) != 0) {
603 g_destroy_consumer(cp);
606 if (g_access(cp, 1, 0, 0) != 0) {
608 g_destroy_consumer(cp);
613 error = gv_read_header(cp, &vhdr);
616 g_access(cp, -1, 0, 0);
618 g_destroy_consumer(cp);
620 /* Check if what we've been given is a valid vinum drive. */
622 gv_post_event(sc, GV_EVENT_DRIVE_TASTED, pp, NULL, 0, 0);
630 struct g_provider *pp;
638 int newstate, flags, err, rename;
643 KASSERT(sc != NULL, ("NULL sc"));
645 /* Look at the events first... */
646 ev = gv_get_event(sc);
648 gv_remove_event(sc, ev);
651 case GV_EVENT_DRIVE_TASTED:
652 G_VINUM_DEBUG(2, "event 'drive tasted'");
654 gv_drive_tasted(sc, pp);
657 case GV_EVENT_DRIVE_LOST:
658 G_VINUM_DEBUG(2, "event 'drive lost'");
660 gv_drive_lost(sc, d);
663 case GV_EVENT_CREATE_DRIVE:
664 G_VINUM_DEBUG(2, "event 'create drive'");
666 gv_create_drive(sc, d);
669 case GV_EVENT_CREATE_VOLUME:
670 G_VINUM_DEBUG(2, "event 'create volume'");
672 gv_create_volume(sc, v);
675 case GV_EVENT_CREATE_PLEX:
676 G_VINUM_DEBUG(2, "event 'create plex'");
678 gv_create_plex(sc, p);
681 case GV_EVENT_CREATE_SD:
682 G_VINUM_DEBUG(2, "event 'create sd'");
687 case GV_EVENT_RM_DRIVE:
688 G_VINUM_DEBUG(2, "event 'remove drive'");
691 gv_rm_drive(sc, d, flags);
692 /*gv_setup_objects(sc);*/
695 case GV_EVENT_RM_VOLUME:
696 G_VINUM_DEBUG(2, "event 'remove volume'");
699 /*gv_setup_objects(sc);*/
702 case GV_EVENT_RM_PLEX:
703 G_VINUM_DEBUG(2, "event 'remove plex'");
706 /*gv_setup_objects(sc);*/
710 G_VINUM_DEBUG(2, "event 'remove sd'");
713 /*gv_setup_objects(sc);*/
716 case GV_EVENT_SAVE_CONFIG:
717 G_VINUM_DEBUG(2, "event 'save config'");
721 case GV_EVENT_SET_SD_STATE:
722 G_VINUM_DEBUG(2, "event 'setstate sd'");
726 err = gv_set_sd_state(s, newstate, flags);
728 G_VINUM_DEBUG(0, "error setting subdisk"
729 " state: error code %d", err);
732 case GV_EVENT_SET_DRIVE_STATE:
733 G_VINUM_DEBUG(2, "event 'setstate drive'");
737 err = gv_set_drive_state(d, newstate, flags);
739 G_VINUM_DEBUG(0, "error setting drive "
740 "state: error code %d", err);
743 case GV_EVENT_SET_VOL_STATE:
744 G_VINUM_DEBUG(2, "event 'setstate volume'");
748 err = gv_set_vol_state(v, newstate, flags);
750 G_VINUM_DEBUG(0, "error setting volume "
751 "state: error code %d", err);
754 case GV_EVENT_SET_PLEX_STATE:
755 G_VINUM_DEBUG(2, "event 'setstate plex'");
759 err = gv_set_plex_state(p, newstate, flags);
761 G_VINUM_DEBUG(0, "error setting plex "
762 "state: error code %d", err);
765 case GV_EVENT_SETUP_OBJECTS:
766 G_VINUM_DEBUG(2, "event 'setup objects'");
767 gv_setup_objects(sc);
770 case GV_EVENT_RESET_CONFIG:
771 G_VINUM_DEBUG(2, "event 'resetconfig'");
772 err = gv_resetconfig(sc);
774 G_VINUM_DEBUG(0, "error resetting "
775 "config: error code %d", err);
778 case GV_EVENT_PARITY_REBUILD:
780 * Start the rebuild. The gv_plex_done will
781 * handle issuing of the remaining rebuild bio's
782 * until it's finished.
784 G_VINUM_DEBUG(2, "event 'rebuild'");
786 if (p->state != GV_PLEX_UP) {
787 G_VINUM_DEBUG(0, "plex %s is not "
788 "completely accessible", p->name);
791 if (p->flags & GV_PLEX_SYNCING ||
792 p->flags & GV_PLEX_REBUILDING ||
793 p->flags & GV_PLEX_GROWING) {
794 G_VINUM_DEBUG(0, "plex %s is busy with "
795 "syncing or parity build", p->name);
799 p->flags |= GV_PLEX_REBUILDING;
800 g_topology_assert_not();
802 err = gv_access(p->vol_sc->provider, 1, 1, 0);
804 G_VINUM_DEBUG(0, "unable to access "
809 gv_parity_request(p, GV_BIO_CHECK |
813 case GV_EVENT_PARITY_CHECK:
814 /* Start parity check. */
815 G_VINUM_DEBUG(2, "event 'check'");
817 if (p->state != GV_PLEX_UP) {
818 G_VINUM_DEBUG(0, "plex %s is not "
819 "completely accessible", p->name);
822 if (p->flags & GV_PLEX_SYNCING ||
823 p->flags & GV_PLEX_REBUILDING ||
824 p->flags & GV_PLEX_GROWING) {
825 G_VINUM_DEBUG(0, "plex %s is busy with "
826 "syncing or parity build", p->name);
830 g_topology_assert_not();
832 err = gv_access(p->vol_sc->provider, 1, 1, 0);
834 G_VINUM_DEBUG(0, "unable to access "
839 gv_parity_request(p, GV_BIO_CHECK, 0);
842 case GV_EVENT_START_PLEX:
843 G_VINUM_DEBUG(2, "event 'start' plex");
848 case GV_EVENT_START_VOLUME:
849 G_VINUM_DEBUG(2, "event 'start' volume");
854 case GV_EVENT_ATTACH_PLEX:
855 G_VINUM_DEBUG(2, "event 'attach' plex");
859 err = gv_attach_plex(p, v, rename);
861 G_VINUM_DEBUG(0, "error attaching %s to"
862 " %s: error code %d", p->name,
866 case GV_EVENT_ATTACH_SD:
867 G_VINUM_DEBUG(2, "event 'attach' sd");
872 err = gv_attach_sd(s, p, offset, rename);
874 G_VINUM_DEBUG(0, "error attaching %s to"
875 " %s: error code %d", s->name,
879 case GV_EVENT_DETACH_PLEX:
880 G_VINUM_DEBUG(2, "event 'detach' plex");
883 err = gv_detach_plex(p, flags);
885 G_VINUM_DEBUG(0, "error detaching %s: "
886 "error code %d", p->name, err);
889 case GV_EVENT_DETACH_SD:
890 G_VINUM_DEBUG(2, "event 'detach' sd");
893 err = gv_detach_sd(s, flags);
895 G_VINUM_DEBUG(0, "error detaching %s: "
896 "error code %d", s->name, err);
899 case GV_EVENT_RENAME_VOL:
900 G_VINUM_DEBUG(2, "event 'rename' volume");
904 err = gv_rename_vol(sc, v, newname, flags);
906 G_VINUM_DEBUG(0, "error renaming %s to "
907 "%s: error code %d", v->name,
910 /* Destroy and recreate the provider if we can. */
911 if (gv_provider_is_open(v->provider)) {
912 G_VINUM_DEBUG(0, "unable to rename "
913 "provider to %s: provider in use",
918 g_wither_provider(v->provider, ENOENT);
921 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc,
925 case GV_EVENT_RENAME_PLEX:
926 G_VINUM_DEBUG(2, "event 'rename' plex");
930 err = gv_rename_plex(sc, p, newname, flags);
932 G_VINUM_DEBUG(0, "error renaming %s to "
933 "%s: error code %d", p->name,
938 case GV_EVENT_RENAME_SD:
939 G_VINUM_DEBUG(2, "event 'rename' sd");
943 err = gv_rename_sd(sc, s, newname, flags);
945 G_VINUM_DEBUG(0, "error renaming %s to "
946 "%s: error code %d", s->name,
951 case GV_EVENT_RENAME_DRIVE:
952 G_VINUM_DEBUG(2, "event 'rename' drive");
956 err = gv_rename_drive(sc, d, newname, flags);
958 G_VINUM_DEBUG(0, "error renaming %s to "
959 "%s: error code %d", d->name,
964 case GV_EVENT_MOVE_SD:
965 G_VINUM_DEBUG(2, "event 'move' sd");
969 err = gv_move_sd(sc, s, d, flags);
971 G_VINUM_DEBUG(0, "error moving %s to "
972 "%s: error code %d", s->name,
976 case GV_EVENT_THREAD_EXIT:
977 G_VINUM_DEBUG(2, "event 'thread exit'");
979 mtx_lock(&sc->equeue_mtx);
980 mtx_lock(&sc->bqueue_mtx);
982 mtx_destroy(&sc->bqueue_mtx);
983 mtx_destroy(&sc->equeue_mtx);
984 g_free(sc->bqueue_down);
985 g_free(sc->bqueue_up);
991 G_VINUM_DEBUG(1, "unknown event %d", ev->type);
998 /* ... then do I/O processing. */
999 mtx_lock(&sc->bqueue_mtx);
1000 /* First do new requests. */
1001 bp = bioq_takefirst(sc->bqueue_down);
1003 mtx_unlock(&sc->bqueue_mtx);
1004 /* A bio that interfered with another bio. */
1005 if (bp->bio_pflags & GV_BIO_ONHOLD) {
1006 s = bp->bio_caller1;
1008 /* Is it still locked out? */
1009 if (gv_stripe_active(p, bp)) {
1010 /* Park the bio on the waiting queue. */
1011 bioq_disksort(p->wqueue, bp);
1013 bp->bio_pflags &= ~GV_BIO_ONHOLD;
1014 g_io_request(bp, s->drive_sc->consumer);
1016 /* A special request requireing special handling. */
1017 } else if (bp->bio_pflags & GV_BIO_INTERNAL) {
1018 p = bp->bio_caller1;
1019 gv_plex_start(p, bp);
1021 gv_volume_start(sc, bp);
1023 mtx_lock(&sc->bqueue_mtx);
1025 /* Then do completed requests. */
1026 bp = bioq_takefirst(sc->bqueue_up);
1028 msleep(sc, &sc->bqueue_mtx, PRIBIO, "-", hz/10);
1029 mtx_unlock(&sc->bqueue_mtx);
1032 mtx_unlock(&sc->bqueue_mtx);
1033 gv_bio_done(sc, bp);
1037 #define VINUM_CLASS_NAME "VINUM"
1039 static struct g_class g_vinum_class = {
1040 .name = VINUM_CLASS_NAME,
1041 .version = G_VERSION,
1044 .ctlreq = gv_config,
1045 .destroy_geom = gv_unload,
1048 DECLARE_GEOM_CLASS(g_vinum_class, g_vinum);