2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004, 2007 Lukas Ertl
5 * Copyright (c) 2007, 2009 Ulf Lilleengen
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/kthread.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/mutex.h>
43 #include <sys/sysctl.h>
44 #include <sys/systm.h>
46 #include <geom/geom.h>
47 #include <geom/geom_dbg.h>
48 #include <geom/vinum/geom_vinum_var.h>
49 #include <geom/vinum/geom_vinum.h>
50 #include <geom/vinum/geom_vinum_raid5.h>
52 SYSCTL_DECL(_kern_geom);
53 static SYSCTL_NODE(_kern_geom, OID_AUTO, vinum, CTLFLAG_RW, 0,
55 u_int g_vinum_debug = 0;
56 SYSCTL_UINT(_kern_geom_vinum, OID_AUTO, debug, CTLFLAG_RWTUN, &g_vinum_debug, 0,
59 static int gv_create(struct g_geom *, struct gctl_req *);
60 static void gv_attach(struct gv_softc *, struct gctl_req *);
61 static void gv_detach(struct gv_softc *, struct gctl_req *);
62 static void gv_parityop(struct gv_softc *, struct gctl_req *);
66 gv_orphan(struct g_consumer *cp)
74 KASSERT(cp != NULL, ("gv_orphan: null cp"));
76 KASSERT(gp != NULL, ("gv_orphan: null gp"));
78 KASSERT(sc != NULL, ("gv_orphan: null sc"));
80 KASSERT(d != NULL, ("gv_orphan: null d"));
82 g_trace(G_T_TOPOLOGY, "gv_orphan(%s)", gp->name);
84 gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL, 0, 0);
88 gv_start(struct bio *bp)
93 gp = bp->bio_to->geom;
96 switch (bp->bio_cmd) {
103 g_io_deliver(bp, EOPNOTSUPP);
106 mtx_lock(&sc->bqueue_mtx);
107 bioq_disksort(sc->bqueue_down, bp);
109 mtx_unlock(&sc->bqueue_mtx);
113 gv_done(struct bio *bp)
118 KASSERT(bp != NULL, ("NULL bp"));
120 gp = bp->bio_from->geom;
123 mtx_lock(&sc->bqueue_mtx);
124 bioq_disksort(sc->bqueue_up, bp);
126 mtx_unlock(&sc->bqueue_mtx);
130 gv_access(struct g_provider *pp, int dr, int dw, int de)
134 struct gv_drive *d, *d2;
140 * We want to modify the read count with the write count in case we have
141 * plexes in a RAID-5 organization.
145 LIST_FOREACH(d, &sc->drives, drive) {
146 if (d->consumer == NULL)
148 error = g_access(d->consumer, dr, dw, de);
150 LIST_FOREACH(d2, &sc->drives, drive) {
153 g_access(d2->consumer, -dr, -dw, -de);
155 G_VINUM_DEBUG(0, "g_access '%s' failed: %d", d->name,
164 gv_init(struct g_class *mp)
169 g_trace(G_T_TOPOLOGY, "gv_init(%p)", mp);
171 gp = g_new_geomf(mp, "VINUM");
172 gp->spoiled = gv_orphan;
173 gp->orphan = gv_orphan;
174 gp->access = gv_access;
175 gp->start = gv_start;
176 gp->softc = g_malloc(sizeof(struct gv_softc), M_WAITOK | M_ZERO);
179 sc->bqueue_down = g_malloc(sizeof(struct bio_queue_head),
181 sc->bqueue_up = g_malloc(sizeof(struct bio_queue_head),
183 bioq_init(sc->bqueue_down);
184 bioq_init(sc->bqueue_up);
185 LIST_INIT(&sc->drives);
186 LIST_INIT(&sc->subdisks);
187 LIST_INIT(&sc->plexes);
188 LIST_INIT(&sc->volumes);
189 TAILQ_INIT(&sc->equeue);
190 mtx_init(&sc->config_mtx, "gv_config", NULL, MTX_DEF);
191 mtx_init(&sc->equeue_mtx, "gv_equeue", NULL, MTX_DEF);
192 mtx_init(&sc->bqueue_mtx, "gv_bqueue", NULL, MTX_DEF);
193 kproc_create(gv_worker, sc, &sc->worker, 0, 0, "gv_worker");
197 gv_unload(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
201 g_trace(G_T_TOPOLOGY, "gv_unload(%p)", mp);
209 g_wither_geom(gp, ENXIO);
215 /* Handle userland request of attaching object. */
217 gv_attach(struct gv_softc *sc, struct gctl_req *req)
223 int *rename, type_child, type_parent;
224 char *child, *parent;
226 child = gctl_get_param(req, "child", NULL);
228 gctl_error(req, "no child given");
231 parent = gctl_get_param(req, "parent", NULL);
232 if (parent == NULL) {
233 gctl_error(req, "no parent given");
236 offset = gctl_get_paraml(req, "offset", sizeof(*offset));
237 if (offset == NULL) {
238 gctl_error(req, "no offset given");
241 rename = gctl_get_paraml(req, "rename", sizeof(*rename));
242 if (rename == NULL) {
243 gctl_error(req, "no rename flag given");
247 type_child = gv_object_type(sc, child);
248 type_parent = gv_object_type(sc, parent);
250 switch (type_child) {
252 if (type_parent != GV_TYPE_VOL) {
253 gctl_error(req, "no such volume to attach to");
256 v = gv_find_vol(sc, parent);
257 p = gv_find_plex(sc, child);
258 gv_post_event(sc, GV_EVENT_ATTACH_PLEX, p, v, *offset, *rename);
261 if (type_parent != GV_TYPE_PLEX) {
262 gctl_error(req, "no such plex to attach to");
265 p = gv_find_plex(sc, parent);
266 s = gv_find_sd(sc, child);
267 gv_post_event(sc, GV_EVENT_ATTACH_SD, s, p, *offset, *rename);
270 gctl_error(req, "invalid child type");
275 /* Handle userland request of detaching object. */
277 gv_detach(struct gv_softc *sc, struct gctl_req *req)
284 object = gctl_get_param(req, "object", NULL);
285 if (object == NULL) {
286 gctl_error(req, "no argument given");
290 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
291 type = gv_object_type(sc, object);
294 p = gv_find_plex(sc, object);
295 gv_post_event(sc, GV_EVENT_DETACH_PLEX, p, NULL, *flags, 0);
298 s = gv_find_sd(sc, object);
299 gv_post_event(sc, GV_EVENT_DETACH_SD, s, NULL, *flags, 0);
302 gctl_error(req, "invalid object type");
307 /* Handle userland requests for creating new objects. */
309 gv_create(struct g_geom *gp, struct gctl_req *req)
312 struct gv_drive *d, *d2;
313 struct gv_plex *p, *p2;
314 struct gv_sd *s, *s2;
315 struct gv_volume *v, *v2;
316 struct g_provider *pp;
317 int error, i, *drives, *flags, *plexes, *subdisks, *volumes;
324 /* Find out how many of each object have been passed in. */
325 volumes = gctl_get_paraml(req, "volumes", sizeof(*volumes));
326 plexes = gctl_get_paraml(req, "plexes", sizeof(*plexes));
327 subdisks = gctl_get_paraml(req, "subdisks", sizeof(*subdisks));
328 drives = gctl_get_paraml(req, "drives", sizeof(*drives));
329 if (volumes == NULL || plexes == NULL || subdisks == NULL ||
331 gctl_error(req, "number of objects not given");
334 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
336 gctl_error(req, "flags not given");
340 /* First, handle drive definitions ... */
341 for (i = 0; i < *drives; i++) {
342 snprintf(buf, sizeof(buf), "drive%d", i);
343 d2 = gctl_get_paraml(req, buf, sizeof(*d2));
345 gctl_error(req, "no drive definition given");
349 * Make sure that the device specified in the drive config is
350 * an active GEOM provider.
352 pp = g_provider_by_name(d2->device);
354 gctl_error(req, "%s: device not found", d2->device);
357 if (gv_find_drive(sc, d2->name) != NULL) {
359 if (*flags & GV_FLAG_F)
361 gctl_error(req, "drive '%s' already exists", d2->name);
364 if (gv_find_drive_device(sc, d2->device) != NULL) {
365 gctl_error(req, "device '%s' already configured in "
366 "gvinum", d2->device);
371 d = g_malloc(sizeof(*d), M_WAITOK | M_ZERO);
372 bcopy(d2, d, sizeof(*d));
374 gv_post_event(sc, GV_EVENT_CREATE_DRIVE, d, NULL, 0, 0);
377 /* ... then volume definitions ... */
378 for (i = 0; i < *volumes; i++) {
380 snprintf(buf, sizeof(buf), "volume%d", i);
381 v2 = gctl_get_paraml(req, buf, sizeof(*v2));
383 gctl_error(req, "no volume definition given");
386 if (gv_find_vol(sc, v2->name) != NULL) {
388 if (*flags & GV_FLAG_F)
390 gctl_error(req, "volume '%s' already exists", v2->name);
394 v = g_malloc(sizeof(*v), M_WAITOK | M_ZERO);
395 bcopy(v2, v, sizeof(*v));
397 gv_post_event(sc, GV_EVENT_CREATE_VOLUME, v, NULL, 0, 0);
400 /* ... then plex definitions ... */
401 for (i = 0; i < *plexes; i++) {
403 snprintf(buf, sizeof(buf), "plex%d", i);
404 p2 = gctl_get_paraml(req, buf, sizeof(*p2));
406 gctl_error(req, "no plex definition given");
409 if (gv_find_plex(sc, p2->name) != NULL) {
411 if (*flags & GV_FLAG_F)
413 gctl_error(req, "plex '%s' already exists", p2->name);
417 p = g_malloc(sizeof(*p), M_WAITOK | M_ZERO);
418 bcopy(p2, p, sizeof(*p));
420 gv_post_event(sc, GV_EVENT_CREATE_PLEX, p, NULL, 0, 0);
423 /* ... and, finally, subdisk definitions. */
424 for (i = 0; i < *subdisks; i++) {
426 snprintf(buf, sizeof(buf), "sd%d", i);
427 s2 = gctl_get_paraml(req, buf, sizeof(*s2));
429 gctl_error(req, "no subdisk definition given");
432 if (gv_find_sd(sc, s2->name) != NULL) {
434 if (*flags & GV_FLAG_F)
436 gctl_error(req, "sd '%s' already exists", s2->name);
440 s = g_malloc(sizeof(*s), M_WAITOK | M_ZERO);
441 bcopy(s2, s, sizeof(*s));
443 gv_post_event(sc, GV_EVENT_CREATE_SD, s, NULL, 0, 0);
447 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc, NULL, 0, 0);
448 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
454 gv_config(struct gctl_req *req, struct g_class *mp, char const *verb)
463 gp = LIST_FIRST(&mp->geom);
466 if (!strcmp(verb, "attach")) {
469 } else if (!strcmp(verb, "concat")) {
472 } else if (!strcmp(verb, "detach")) {
475 } else if (!strcmp(verb, "list")) {
478 /* Save our configuration back to disk. */
479 } else if (!strcmp(verb, "saveconfig")) {
480 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
482 /* Return configuration in string form. */
483 } else if (!strcmp(verb, "getconfig")) {
484 comment = gctl_get_param(req, "comment", NULL);
485 if (comment == NULL) {
486 gctl_error(req, "no comment parameter given");
489 sb = sbuf_new(NULL, NULL, GV_CFG_LEN, SBUF_FIXEDLEN);
490 gv_format_config(sc, sb, 0, comment);
492 gctl_set_param(req, "config", sbuf_data(sb), sbuf_len(sb) + 1);
495 } else if (!strcmp(verb, "create")) {
498 } else if (!strcmp(verb, "mirror")) {
501 } else if (!strcmp(verb, "move")) {
504 } else if (!strcmp(verb, "raid5")) {
507 } else if (!strcmp(verb, "rebuildparity") ||
508 !strcmp(verb, "checkparity")) {
509 gv_parityop(sc, req);
511 } else if (!strcmp(verb, "remove")) {
514 } else if (!strcmp(verb, "rename")) {
517 } else if (!strcmp(verb, "resetconfig")) {
518 gv_post_event(sc, GV_EVENT_RESET_CONFIG, sc, NULL, 0, 0);
520 } else if (!strcmp(verb, "start")) {
521 gv_start_obj(gp, req);
523 } else if (!strcmp(verb, "stripe")) {
526 } else if (!strcmp(verb, "setstate")) {
527 gv_setstate(gp, req);
529 gctl_error(req, "Unknown verb parameter");
533 gv_parityop(struct gv_softc *sc, struct gctl_req *req)
536 int *flags, *rebuild, type;
539 plex = gctl_get_param(req, "plex", NULL);
541 gctl_error(req, "no plex given");
545 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
547 gctl_error(req, "no flags given");
551 rebuild = gctl_get_paraml(req, "rebuild", sizeof(*rebuild));
552 if (rebuild == NULL) {
553 gctl_error(req, "no operation given");
557 type = gv_object_type(sc, plex);
558 if (type != GV_TYPE_PLEX) {
559 gctl_error(req, "'%s' is not a plex", plex);
562 p = gv_find_plex(sc, plex);
564 if (p->state != GV_PLEX_UP) {
565 gctl_error(req, "plex %s is not completely accessible",
570 if (p->org != GV_PLEX_RAID5) {
571 gctl_error(req, "plex %s is not a RAID5 plex", p->name);
575 /* Put it in the event queue. */
576 /* XXX: The state of the plex might have changed when this event is
577 * picked up ... We should perhaps check this afterwards. */
579 gv_post_event(sc, GV_EVENT_PARITY_REBUILD, p, NULL, 0, 0);
581 gv_post_event(sc, GV_EVENT_PARITY_CHECK, p, NULL, 0, 0);
585 static struct g_geom *
586 gv_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
589 struct g_consumer *cp;
595 g_trace(G_T_TOPOLOGY, "gv_taste(%s, %s)", mp->name, pp->name);
597 gp = LIST_FIRST(&mp->geom);
599 G_VINUM_DEBUG(0, "error: tasting, but not initialized?");
604 cp = g_new_consumer(gp);
605 if (g_attach(cp, pp) != 0) {
606 g_destroy_consumer(cp);
609 if (g_access(cp, 1, 0, 0) != 0) {
611 g_destroy_consumer(cp);
616 error = gv_read_header(cp, &vhdr);
619 g_access(cp, -1, 0, 0);
621 g_destroy_consumer(cp);
623 /* Check if what we've been given is a valid vinum drive. */
625 gv_post_event(sc, GV_EVENT_DRIVE_TASTED, pp, NULL, 0, 0);
633 struct g_provider *pp;
641 int newstate, flags, err, rename;
646 KASSERT(sc != NULL, ("NULL sc"));
648 /* Look at the events first... */
649 ev = gv_get_event(sc);
651 gv_remove_event(sc, ev);
654 case GV_EVENT_DRIVE_TASTED:
655 G_VINUM_DEBUG(2, "event 'drive tasted'");
657 gv_drive_tasted(sc, pp);
660 case GV_EVENT_DRIVE_LOST:
661 G_VINUM_DEBUG(2, "event 'drive lost'");
663 gv_drive_lost(sc, d);
666 case GV_EVENT_CREATE_DRIVE:
667 G_VINUM_DEBUG(2, "event 'create drive'");
669 gv_create_drive(sc, d);
672 case GV_EVENT_CREATE_VOLUME:
673 G_VINUM_DEBUG(2, "event 'create volume'");
675 gv_create_volume(sc, v);
678 case GV_EVENT_CREATE_PLEX:
679 G_VINUM_DEBUG(2, "event 'create plex'");
681 gv_create_plex(sc, p);
684 case GV_EVENT_CREATE_SD:
685 G_VINUM_DEBUG(2, "event 'create sd'");
690 case GV_EVENT_RM_DRIVE:
691 G_VINUM_DEBUG(2, "event 'remove drive'");
694 gv_rm_drive(sc, d, flags);
695 /*gv_setup_objects(sc);*/
698 case GV_EVENT_RM_VOLUME:
699 G_VINUM_DEBUG(2, "event 'remove volume'");
702 /*gv_setup_objects(sc);*/
705 case GV_EVENT_RM_PLEX:
706 G_VINUM_DEBUG(2, "event 'remove plex'");
709 /*gv_setup_objects(sc);*/
713 G_VINUM_DEBUG(2, "event 'remove sd'");
716 /*gv_setup_objects(sc);*/
719 case GV_EVENT_SAVE_CONFIG:
720 G_VINUM_DEBUG(2, "event 'save config'");
724 case GV_EVENT_SET_SD_STATE:
725 G_VINUM_DEBUG(2, "event 'setstate sd'");
729 err = gv_set_sd_state(s, newstate, flags);
731 G_VINUM_DEBUG(0, "error setting subdisk"
732 " state: error code %d", err);
735 case GV_EVENT_SET_DRIVE_STATE:
736 G_VINUM_DEBUG(2, "event 'setstate drive'");
740 err = gv_set_drive_state(d, newstate, flags);
742 G_VINUM_DEBUG(0, "error setting drive "
743 "state: error code %d", err);
746 case GV_EVENT_SET_VOL_STATE:
747 G_VINUM_DEBUG(2, "event 'setstate volume'");
751 err = gv_set_vol_state(v, newstate, flags);
753 G_VINUM_DEBUG(0, "error setting volume "
754 "state: error code %d", err);
757 case GV_EVENT_SET_PLEX_STATE:
758 G_VINUM_DEBUG(2, "event 'setstate plex'");
762 err = gv_set_plex_state(p, newstate, flags);
764 G_VINUM_DEBUG(0, "error setting plex "
765 "state: error code %d", err);
768 case GV_EVENT_SETUP_OBJECTS:
769 G_VINUM_DEBUG(2, "event 'setup objects'");
770 gv_setup_objects(sc);
773 case GV_EVENT_RESET_CONFIG:
774 G_VINUM_DEBUG(2, "event 'resetconfig'");
775 err = gv_resetconfig(sc);
777 G_VINUM_DEBUG(0, "error resetting "
778 "config: error code %d", err);
781 case GV_EVENT_PARITY_REBUILD:
783 * Start the rebuild. The gv_plex_done will
784 * handle issuing of the remaining rebuild bio's
785 * until it's finished.
787 G_VINUM_DEBUG(2, "event 'rebuild'");
789 if (p->state != GV_PLEX_UP) {
790 G_VINUM_DEBUG(0, "plex %s is not "
791 "completely accessible", p->name);
794 if (p->flags & GV_PLEX_SYNCING ||
795 p->flags & GV_PLEX_REBUILDING ||
796 p->flags & GV_PLEX_GROWING) {
797 G_VINUM_DEBUG(0, "plex %s is busy with "
798 "syncing or parity build", p->name);
802 p->flags |= GV_PLEX_REBUILDING;
803 g_topology_assert_not();
805 err = gv_access(p->vol_sc->provider, 1, 1, 0);
807 G_VINUM_DEBUG(0, "unable to access "
812 gv_parity_request(p, GV_BIO_CHECK |
816 case GV_EVENT_PARITY_CHECK:
817 /* Start parity check. */
818 G_VINUM_DEBUG(2, "event 'check'");
820 if (p->state != GV_PLEX_UP) {
821 G_VINUM_DEBUG(0, "plex %s is not "
822 "completely accessible", p->name);
825 if (p->flags & GV_PLEX_SYNCING ||
826 p->flags & GV_PLEX_REBUILDING ||
827 p->flags & GV_PLEX_GROWING) {
828 G_VINUM_DEBUG(0, "plex %s is busy with "
829 "syncing or parity build", p->name);
833 g_topology_assert_not();
835 err = gv_access(p->vol_sc->provider, 1, 1, 0);
837 G_VINUM_DEBUG(0, "unable to access "
842 gv_parity_request(p, GV_BIO_CHECK, 0);
845 case GV_EVENT_START_PLEX:
846 G_VINUM_DEBUG(2, "event 'start' plex");
851 case GV_EVENT_START_VOLUME:
852 G_VINUM_DEBUG(2, "event 'start' volume");
857 case GV_EVENT_ATTACH_PLEX:
858 G_VINUM_DEBUG(2, "event 'attach' plex");
862 err = gv_attach_plex(p, v, rename);
864 G_VINUM_DEBUG(0, "error attaching %s to"
865 " %s: error code %d", p->name,
869 case GV_EVENT_ATTACH_SD:
870 G_VINUM_DEBUG(2, "event 'attach' sd");
875 err = gv_attach_sd(s, p, offset, rename);
877 G_VINUM_DEBUG(0, "error attaching %s to"
878 " %s: error code %d", s->name,
882 case GV_EVENT_DETACH_PLEX:
883 G_VINUM_DEBUG(2, "event 'detach' plex");
886 err = gv_detach_plex(p, flags);
888 G_VINUM_DEBUG(0, "error detaching %s: "
889 "error code %d", p->name, err);
892 case GV_EVENT_DETACH_SD:
893 G_VINUM_DEBUG(2, "event 'detach' sd");
896 err = gv_detach_sd(s, flags);
898 G_VINUM_DEBUG(0, "error detaching %s: "
899 "error code %d", s->name, err);
902 case GV_EVENT_RENAME_VOL:
903 G_VINUM_DEBUG(2, "event 'rename' volume");
907 err = gv_rename_vol(sc, v, newname, flags);
909 G_VINUM_DEBUG(0, "error renaming %s to "
910 "%s: error code %d", v->name,
913 /* Destroy and recreate the provider if we can. */
914 if (gv_provider_is_open(v->provider)) {
915 G_VINUM_DEBUG(0, "unable to rename "
916 "provider to %s: provider in use",
921 g_wither_provider(v->provider, ENOENT);
924 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc,
928 case GV_EVENT_RENAME_PLEX:
929 G_VINUM_DEBUG(2, "event 'rename' plex");
933 err = gv_rename_plex(sc, p, newname, flags);
935 G_VINUM_DEBUG(0, "error renaming %s to "
936 "%s: error code %d", p->name,
941 case GV_EVENT_RENAME_SD:
942 G_VINUM_DEBUG(2, "event 'rename' sd");
946 err = gv_rename_sd(sc, s, newname, flags);
948 G_VINUM_DEBUG(0, "error renaming %s to "
949 "%s: error code %d", s->name,
954 case GV_EVENT_RENAME_DRIVE:
955 G_VINUM_DEBUG(2, "event 'rename' drive");
959 err = gv_rename_drive(sc, d, newname, flags);
961 G_VINUM_DEBUG(0, "error renaming %s to "
962 "%s: error code %d", d->name,
967 case GV_EVENT_MOVE_SD:
968 G_VINUM_DEBUG(2, "event 'move' sd");
972 err = gv_move_sd(sc, s, d, flags);
974 G_VINUM_DEBUG(0, "error moving %s to "
975 "%s: error code %d", s->name,
979 case GV_EVENT_THREAD_EXIT:
980 G_VINUM_DEBUG(2, "event 'thread exit'");
982 mtx_lock(&sc->equeue_mtx);
983 mtx_lock(&sc->bqueue_mtx);
985 mtx_destroy(&sc->bqueue_mtx);
986 mtx_destroy(&sc->equeue_mtx);
987 g_free(sc->bqueue_down);
988 g_free(sc->bqueue_up);
994 G_VINUM_DEBUG(1, "unknown event %d", ev->type);
1001 /* ... then do I/O processing. */
1002 mtx_lock(&sc->bqueue_mtx);
1003 /* First do new requests. */
1004 bp = bioq_takefirst(sc->bqueue_down);
1006 mtx_unlock(&sc->bqueue_mtx);
1007 /* A bio that interfered with another bio. */
1008 if (bp->bio_pflags & GV_BIO_ONHOLD) {
1009 s = bp->bio_caller1;
1011 /* Is it still locked out? */
1012 if (gv_stripe_active(p, bp)) {
1013 /* Park the bio on the waiting queue. */
1014 bioq_disksort(p->wqueue, bp);
1016 bp->bio_pflags &= ~GV_BIO_ONHOLD;
1017 g_io_request(bp, s->drive_sc->consumer);
1019 /* A special request requireing special handling. */
1020 } else if (bp->bio_pflags & GV_BIO_INTERNAL) {
1021 p = bp->bio_caller1;
1022 gv_plex_start(p, bp);
1024 gv_volume_start(sc, bp);
1026 mtx_lock(&sc->bqueue_mtx);
1028 /* Then do completed requests. */
1029 bp = bioq_takefirst(sc->bqueue_up);
1031 msleep(sc, &sc->bqueue_mtx, PRIBIO, "-", hz/10);
1032 mtx_unlock(&sc->bqueue_mtx);
1035 mtx_unlock(&sc->bqueue_mtx);
1036 gv_bio_done(sc, bp);
1040 #define VINUM_CLASS_NAME "VINUM"
1042 static struct g_class g_vinum_class = {
1043 .name = VINUM_CLASS_NAME,
1044 .version = G_VERSION,
1047 .ctlreq = gv_config,
1048 .destroy_geom = gv_unload,
1051 DECLARE_GEOM_CLASS(g_vinum_class, g_vinum);
1052 MODULE_VERSION(geom_vinum, 0);