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/vinum/geom_vinum_var.h>
48 #include <geom/vinum/geom_vinum.h>
49 #include <geom/vinum/geom_vinum_raid5.h>
51 SYSCTL_DECL(_kern_geom);
52 static SYSCTL_NODE(_kern_geom, OID_AUTO, vinum, CTLFLAG_RW, 0,
54 u_int g_vinum_debug = 0;
55 SYSCTL_UINT(_kern_geom_vinum, OID_AUTO, debug, CTLFLAG_RWTUN, &g_vinum_debug, 0,
58 static int gv_create(struct g_geom *, struct gctl_req *);
59 static void gv_attach(struct gv_softc *, struct gctl_req *);
60 static void gv_detach(struct gv_softc *, struct gctl_req *);
61 static void gv_parityop(struct gv_softc *, struct gctl_req *);
65 gv_orphan(struct g_consumer *cp)
73 KASSERT(cp != NULL, ("gv_orphan: null cp"));
75 KASSERT(gp != NULL, ("gv_orphan: null gp"));
77 KASSERT(sc != NULL, ("gv_orphan: null sc"));
79 KASSERT(d != NULL, ("gv_orphan: null d"));
81 g_trace(G_T_TOPOLOGY, "gv_orphan(%s)", gp->name);
83 gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL, 0, 0);
87 gv_start(struct bio *bp)
92 gp = bp->bio_to->geom;
95 switch (bp->bio_cmd) {
102 g_io_deliver(bp, EOPNOTSUPP);
105 mtx_lock(&sc->bqueue_mtx);
106 bioq_disksort(sc->bqueue_down, bp);
108 mtx_unlock(&sc->bqueue_mtx);
112 gv_done(struct bio *bp)
117 KASSERT(bp != NULL, ("NULL bp"));
119 gp = bp->bio_from->geom;
122 mtx_lock(&sc->bqueue_mtx);
123 bioq_disksort(sc->bqueue_up, bp);
125 mtx_unlock(&sc->bqueue_mtx);
129 gv_access(struct g_provider *pp, int dr, int dw, int de)
133 struct gv_drive *d, *d2;
139 * We want to modify the read count with the write count in case we have
140 * plexes in a RAID-5 organization.
144 LIST_FOREACH(d, &sc->drives, drive) {
145 if (d->consumer == NULL)
147 error = g_access(d->consumer, dr, dw, de);
149 LIST_FOREACH(d2, &sc->drives, drive) {
152 g_access(d2->consumer, -dr, -dw, -de);
154 G_VINUM_DEBUG(0, "g_access '%s' failed: %d", d->name,
163 gv_init(struct g_class *mp)
168 g_trace(G_T_TOPOLOGY, "gv_init(%p)", mp);
170 gp = g_new_geomf(mp, "VINUM");
171 gp->spoiled = gv_orphan;
172 gp->orphan = gv_orphan;
173 gp->access = gv_access;
174 gp->start = gv_start;
175 gp->softc = g_malloc(sizeof(struct gv_softc), M_WAITOK | M_ZERO);
178 sc->bqueue_down = g_malloc(sizeof(struct bio_queue_head),
180 sc->bqueue_up = g_malloc(sizeof(struct bio_queue_head),
182 bioq_init(sc->bqueue_down);
183 bioq_init(sc->bqueue_up);
184 LIST_INIT(&sc->drives);
185 LIST_INIT(&sc->subdisks);
186 LIST_INIT(&sc->plexes);
187 LIST_INIT(&sc->volumes);
188 TAILQ_INIT(&sc->equeue);
189 mtx_init(&sc->config_mtx, "gv_config", NULL, MTX_DEF);
190 mtx_init(&sc->equeue_mtx, "gv_equeue", NULL, MTX_DEF);
191 mtx_init(&sc->bqueue_mtx, "gv_bqueue", NULL, MTX_DEF);
192 kproc_create(gv_worker, sc, &sc->worker, 0, 0, "gv_worker");
196 gv_unload(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
200 g_trace(G_T_TOPOLOGY, "gv_unload(%p)", mp);
208 g_wither_geom(gp, ENXIO);
214 /* Handle userland request of attaching object. */
216 gv_attach(struct gv_softc *sc, struct gctl_req *req)
222 int *rename, type_child, type_parent;
223 char *child, *parent;
225 child = gctl_get_param(req, "child", NULL);
227 gctl_error(req, "no child given");
230 parent = gctl_get_param(req, "parent", NULL);
231 if (parent == NULL) {
232 gctl_error(req, "no parent given");
235 offset = gctl_get_paraml(req, "offset", sizeof(*offset));
236 if (offset == NULL) {
237 gctl_error(req, "no offset given");
240 rename = gctl_get_paraml(req, "rename", sizeof(*rename));
241 if (rename == NULL) {
242 gctl_error(req, "no rename flag given");
246 type_child = gv_object_type(sc, child);
247 type_parent = gv_object_type(sc, parent);
249 switch (type_child) {
251 if (type_parent != GV_TYPE_VOL) {
252 gctl_error(req, "no such volume to attach to");
255 v = gv_find_vol(sc, parent);
256 p = gv_find_plex(sc, child);
257 gv_post_event(sc, GV_EVENT_ATTACH_PLEX, p, v, *offset, *rename);
260 if (type_parent != GV_TYPE_PLEX) {
261 gctl_error(req, "no such plex to attach to");
264 p = gv_find_plex(sc, parent);
265 s = gv_find_sd(sc, child);
266 gv_post_event(sc, GV_EVENT_ATTACH_SD, s, p, *offset, *rename);
269 gctl_error(req, "invalid child type");
274 /* Handle userland request of detaching object. */
276 gv_detach(struct gv_softc *sc, struct gctl_req *req)
283 object = gctl_get_param(req, "object", NULL);
284 if (object == NULL) {
285 gctl_error(req, "no argument given");
289 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
290 type = gv_object_type(sc, object);
293 p = gv_find_plex(sc, object);
294 gv_post_event(sc, GV_EVENT_DETACH_PLEX, p, NULL, *flags, 0);
297 s = gv_find_sd(sc, object);
298 gv_post_event(sc, GV_EVENT_DETACH_SD, s, NULL, *flags, 0);
301 gctl_error(req, "invalid object type");
306 /* Handle userland requests for creating new objects. */
308 gv_create(struct g_geom *gp, struct gctl_req *req)
311 struct gv_drive *d, *d2;
312 struct gv_plex *p, *p2;
313 struct gv_sd *s, *s2;
314 struct gv_volume *v, *v2;
315 struct g_provider *pp;
316 int error, i, *drives, *flags, *plexes, *subdisks, *volumes;
323 /* Find out how many of each object have been passed in. */
324 volumes = gctl_get_paraml(req, "volumes", sizeof(*volumes));
325 plexes = gctl_get_paraml(req, "plexes", sizeof(*plexes));
326 subdisks = gctl_get_paraml(req, "subdisks", sizeof(*subdisks));
327 drives = gctl_get_paraml(req, "drives", sizeof(*drives));
328 if (volumes == NULL || plexes == NULL || subdisks == NULL ||
330 gctl_error(req, "number of objects not given");
333 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
335 gctl_error(req, "flags not given");
339 /* First, handle drive definitions ... */
340 for (i = 0; i < *drives; i++) {
341 snprintf(buf, sizeof(buf), "drive%d", i);
342 d2 = gctl_get_paraml(req, buf, sizeof(*d2));
344 gctl_error(req, "no drive definition given");
348 * Make sure that the device specified in the drive config is
349 * an active GEOM provider.
351 pp = g_provider_by_name(d2->device);
353 gctl_error(req, "%s: device not found", d2->device);
356 if (gv_find_drive(sc, d2->name) != NULL) {
358 if (*flags & GV_FLAG_F)
360 gctl_error(req, "drive '%s' already exists", d2->name);
363 if (gv_find_drive_device(sc, d2->device) != NULL) {
364 gctl_error(req, "device '%s' already configured in "
365 "gvinum", d2->device);
370 d = g_malloc(sizeof(*d), M_WAITOK | M_ZERO);
371 bcopy(d2, d, sizeof(*d));
373 gv_post_event(sc, GV_EVENT_CREATE_DRIVE, d, NULL, 0, 0);
376 /* ... then volume definitions ... */
377 for (i = 0; i < *volumes; i++) {
379 snprintf(buf, sizeof(buf), "volume%d", i);
380 v2 = gctl_get_paraml(req, buf, sizeof(*v2));
382 gctl_error(req, "no volume definition given");
385 if (gv_find_vol(sc, v2->name) != NULL) {
387 if (*flags & GV_FLAG_F)
389 gctl_error(req, "volume '%s' already exists", v2->name);
393 v = g_malloc(sizeof(*v), M_WAITOK | M_ZERO);
394 bcopy(v2, v, sizeof(*v));
396 gv_post_event(sc, GV_EVENT_CREATE_VOLUME, v, NULL, 0, 0);
399 /* ... then plex definitions ... */
400 for (i = 0; i < *plexes; i++) {
402 snprintf(buf, sizeof(buf), "plex%d", i);
403 p2 = gctl_get_paraml(req, buf, sizeof(*p2));
405 gctl_error(req, "no plex definition given");
408 if (gv_find_plex(sc, p2->name) != NULL) {
410 if (*flags & GV_FLAG_F)
412 gctl_error(req, "plex '%s' already exists", p2->name);
416 p = g_malloc(sizeof(*p), M_WAITOK | M_ZERO);
417 bcopy(p2, p, sizeof(*p));
419 gv_post_event(sc, GV_EVENT_CREATE_PLEX, p, NULL, 0, 0);
422 /* ... and, finally, subdisk definitions. */
423 for (i = 0; i < *subdisks; i++) {
425 snprintf(buf, sizeof(buf), "sd%d", i);
426 s2 = gctl_get_paraml(req, buf, sizeof(*s2));
428 gctl_error(req, "no subdisk definition given");
431 if (gv_find_sd(sc, s2->name) != NULL) {
433 if (*flags & GV_FLAG_F)
435 gctl_error(req, "sd '%s' already exists", s2->name);
439 s = g_malloc(sizeof(*s), M_WAITOK | M_ZERO);
440 bcopy(s2, s, sizeof(*s));
442 gv_post_event(sc, GV_EVENT_CREATE_SD, s, NULL, 0, 0);
446 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc, NULL, 0, 0);
447 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
453 gv_config(struct gctl_req *req, struct g_class *mp, char const *verb)
462 gp = LIST_FIRST(&mp->geom);
465 if (!strcmp(verb, "attach")) {
468 } else if (!strcmp(verb, "concat")) {
471 } else if (!strcmp(verb, "detach")) {
474 } else if (!strcmp(verb, "list")) {
477 /* Save our configuration back to disk. */
478 } else if (!strcmp(verb, "saveconfig")) {
479 gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, 0, 0);
481 /* Return configuration in string form. */
482 } else if (!strcmp(verb, "getconfig")) {
483 comment = gctl_get_param(req, "comment", NULL);
484 if (comment == NULL) {
485 gctl_error(req, "no comment parameter given");
488 sb = sbuf_new(NULL, NULL, GV_CFG_LEN, SBUF_FIXEDLEN);
489 gv_format_config(sc, sb, 0, comment);
491 gctl_set_param(req, "config", sbuf_data(sb), sbuf_len(sb) + 1);
494 } else if (!strcmp(verb, "create")) {
497 } else if (!strcmp(verb, "mirror")) {
500 } else if (!strcmp(verb, "move")) {
503 } else if (!strcmp(verb, "raid5")) {
506 } else if (!strcmp(verb, "rebuildparity") ||
507 !strcmp(verb, "checkparity")) {
508 gv_parityop(sc, req);
510 } else if (!strcmp(verb, "remove")) {
513 } else if (!strcmp(verb, "rename")) {
516 } else if (!strcmp(verb, "resetconfig")) {
517 gv_post_event(sc, GV_EVENT_RESET_CONFIG, sc, NULL, 0, 0);
519 } else if (!strcmp(verb, "start")) {
520 gv_start_obj(gp, req);
522 } else if (!strcmp(verb, "stripe")) {
525 } else if (!strcmp(verb, "setstate")) {
526 gv_setstate(gp, req);
528 gctl_error(req, "Unknown verb parameter");
532 gv_parityop(struct gv_softc *sc, struct gctl_req *req)
535 int *flags, *rebuild, type;
538 plex = gctl_get_param(req, "plex", NULL);
540 gctl_error(req, "no plex given");
544 flags = gctl_get_paraml(req, "flags", sizeof(*flags));
546 gctl_error(req, "no flags given");
550 rebuild = gctl_get_paraml(req, "rebuild", sizeof(*rebuild));
551 if (rebuild == NULL) {
552 gctl_error(req, "no operation given");
556 type = gv_object_type(sc, plex);
557 if (type != GV_TYPE_PLEX) {
558 gctl_error(req, "'%s' is not a plex", plex);
561 p = gv_find_plex(sc, plex);
563 if (p->state != GV_PLEX_UP) {
564 gctl_error(req, "plex %s is not completely accessible",
569 if (p->org != GV_PLEX_RAID5) {
570 gctl_error(req, "plex %s is not a RAID5 plex", p->name);
574 /* Put it in the event queue. */
575 /* XXX: The state of the plex might have changed when this event is
576 * picked up ... We should perhaps check this afterwards. */
578 gv_post_event(sc, GV_EVENT_PARITY_REBUILD, p, NULL, 0, 0);
580 gv_post_event(sc, GV_EVENT_PARITY_CHECK, p, NULL, 0, 0);
584 static struct g_geom *
585 gv_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
588 struct g_consumer *cp;
594 g_trace(G_T_TOPOLOGY, "gv_taste(%s, %s)", mp->name, pp->name);
596 gp = LIST_FIRST(&mp->geom);
598 G_VINUM_DEBUG(0, "error: tasting, but not initialized?");
603 cp = g_new_consumer(gp);
604 if (g_attach(cp, pp) != 0) {
605 g_destroy_consumer(cp);
608 if (g_access(cp, 1, 0, 0) != 0) {
610 g_destroy_consumer(cp);
615 error = gv_read_header(cp, &vhdr);
618 g_access(cp, -1, 0, 0);
620 g_destroy_consumer(cp);
622 /* Check if what we've been given is a valid vinum drive. */
624 gv_post_event(sc, GV_EVENT_DRIVE_TASTED, pp, NULL, 0, 0);
632 struct g_provider *pp;
640 int newstate, flags, err, rename;
645 KASSERT(sc != NULL, ("NULL sc"));
647 /* Look at the events first... */
648 ev = gv_get_event(sc);
650 gv_remove_event(sc, ev);
653 case GV_EVENT_DRIVE_TASTED:
654 G_VINUM_DEBUG(2, "event 'drive tasted'");
656 gv_drive_tasted(sc, pp);
659 case GV_EVENT_DRIVE_LOST:
660 G_VINUM_DEBUG(2, "event 'drive lost'");
662 gv_drive_lost(sc, d);
665 case GV_EVENT_CREATE_DRIVE:
666 G_VINUM_DEBUG(2, "event 'create drive'");
668 gv_create_drive(sc, d);
671 case GV_EVENT_CREATE_VOLUME:
672 G_VINUM_DEBUG(2, "event 'create volume'");
674 gv_create_volume(sc, v);
677 case GV_EVENT_CREATE_PLEX:
678 G_VINUM_DEBUG(2, "event 'create plex'");
680 gv_create_plex(sc, p);
683 case GV_EVENT_CREATE_SD:
684 G_VINUM_DEBUG(2, "event 'create sd'");
689 case GV_EVENT_RM_DRIVE:
690 G_VINUM_DEBUG(2, "event 'remove drive'");
693 gv_rm_drive(sc, d, flags);
694 /*gv_setup_objects(sc);*/
697 case GV_EVENT_RM_VOLUME:
698 G_VINUM_DEBUG(2, "event 'remove volume'");
701 /*gv_setup_objects(sc);*/
704 case GV_EVENT_RM_PLEX:
705 G_VINUM_DEBUG(2, "event 'remove plex'");
708 /*gv_setup_objects(sc);*/
712 G_VINUM_DEBUG(2, "event 'remove sd'");
715 /*gv_setup_objects(sc);*/
718 case GV_EVENT_SAVE_CONFIG:
719 G_VINUM_DEBUG(2, "event 'save config'");
723 case GV_EVENT_SET_SD_STATE:
724 G_VINUM_DEBUG(2, "event 'setstate sd'");
728 err = gv_set_sd_state(s, newstate, flags);
730 G_VINUM_DEBUG(0, "error setting subdisk"
731 " state: error code %d", err);
734 case GV_EVENT_SET_DRIVE_STATE:
735 G_VINUM_DEBUG(2, "event 'setstate drive'");
739 err = gv_set_drive_state(d, newstate, flags);
741 G_VINUM_DEBUG(0, "error setting drive "
742 "state: error code %d", err);
745 case GV_EVENT_SET_VOL_STATE:
746 G_VINUM_DEBUG(2, "event 'setstate volume'");
750 err = gv_set_vol_state(v, newstate, flags);
752 G_VINUM_DEBUG(0, "error setting volume "
753 "state: error code %d", err);
756 case GV_EVENT_SET_PLEX_STATE:
757 G_VINUM_DEBUG(2, "event 'setstate plex'");
761 err = gv_set_plex_state(p, newstate, flags);
763 G_VINUM_DEBUG(0, "error setting plex "
764 "state: error code %d", err);
767 case GV_EVENT_SETUP_OBJECTS:
768 G_VINUM_DEBUG(2, "event 'setup objects'");
769 gv_setup_objects(sc);
772 case GV_EVENT_RESET_CONFIG:
773 G_VINUM_DEBUG(2, "event 'resetconfig'");
774 err = gv_resetconfig(sc);
776 G_VINUM_DEBUG(0, "error resetting "
777 "config: error code %d", err);
780 case GV_EVENT_PARITY_REBUILD:
782 * Start the rebuild. The gv_plex_done will
783 * handle issuing of the remaining rebuild bio's
784 * until it's finished.
786 G_VINUM_DEBUG(2, "event 'rebuild'");
788 if (p->state != GV_PLEX_UP) {
789 G_VINUM_DEBUG(0, "plex %s is not "
790 "completely accessible", p->name);
793 if (p->flags & GV_PLEX_SYNCING ||
794 p->flags & GV_PLEX_REBUILDING ||
795 p->flags & GV_PLEX_GROWING) {
796 G_VINUM_DEBUG(0, "plex %s is busy with "
797 "syncing or parity build", p->name);
801 p->flags |= GV_PLEX_REBUILDING;
802 g_topology_assert_not();
804 err = gv_access(p->vol_sc->provider, 1, 1, 0);
806 G_VINUM_DEBUG(0, "unable to access "
811 gv_parity_request(p, GV_BIO_CHECK |
815 case GV_EVENT_PARITY_CHECK:
816 /* Start parity check. */
817 G_VINUM_DEBUG(2, "event 'check'");
819 if (p->state != GV_PLEX_UP) {
820 G_VINUM_DEBUG(0, "plex %s is not "
821 "completely accessible", p->name);
824 if (p->flags & GV_PLEX_SYNCING ||
825 p->flags & GV_PLEX_REBUILDING ||
826 p->flags & GV_PLEX_GROWING) {
827 G_VINUM_DEBUG(0, "plex %s is busy with "
828 "syncing or parity build", p->name);
832 g_topology_assert_not();
834 err = gv_access(p->vol_sc->provider, 1, 1, 0);
836 G_VINUM_DEBUG(0, "unable to access "
841 gv_parity_request(p, GV_BIO_CHECK, 0);
844 case GV_EVENT_START_PLEX:
845 G_VINUM_DEBUG(2, "event 'start' plex");
850 case GV_EVENT_START_VOLUME:
851 G_VINUM_DEBUG(2, "event 'start' volume");
856 case GV_EVENT_ATTACH_PLEX:
857 G_VINUM_DEBUG(2, "event 'attach' plex");
861 err = gv_attach_plex(p, v, rename);
863 G_VINUM_DEBUG(0, "error attaching %s to"
864 " %s: error code %d", p->name,
868 case GV_EVENT_ATTACH_SD:
869 G_VINUM_DEBUG(2, "event 'attach' sd");
874 err = gv_attach_sd(s, p, offset, rename);
876 G_VINUM_DEBUG(0, "error attaching %s to"
877 " %s: error code %d", s->name,
881 case GV_EVENT_DETACH_PLEX:
882 G_VINUM_DEBUG(2, "event 'detach' plex");
885 err = gv_detach_plex(p, flags);
887 G_VINUM_DEBUG(0, "error detaching %s: "
888 "error code %d", p->name, err);
891 case GV_EVENT_DETACH_SD:
892 G_VINUM_DEBUG(2, "event 'detach' sd");
895 err = gv_detach_sd(s, flags);
897 G_VINUM_DEBUG(0, "error detaching %s: "
898 "error code %d", s->name, err);
901 case GV_EVENT_RENAME_VOL:
902 G_VINUM_DEBUG(2, "event 'rename' volume");
906 err = gv_rename_vol(sc, v, newname, flags);
908 G_VINUM_DEBUG(0, "error renaming %s to "
909 "%s: error code %d", v->name,
912 /* Destroy and recreate the provider if we can. */
913 if (gv_provider_is_open(v->provider)) {
914 G_VINUM_DEBUG(0, "unable to rename "
915 "provider to %s: provider in use",
920 g_wither_provider(v->provider, ENOENT);
923 gv_post_event(sc, GV_EVENT_SETUP_OBJECTS, sc,
927 case GV_EVENT_RENAME_PLEX:
928 G_VINUM_DEBUG(2, "event 'rename' plex");
932 err = gv_rename_plex(sc, p, newname, flags);
934 G_VINUM_DEBUG(0, "error renaming %s to "
935 "%s: error code %d", p->name,
940 case GV_EVENT_RENAME_SD:
941 G_VINUM_DEBUG(2, "event 'rename' sd");
945 err = gv_rename_sd(sc, s, newname, flags);
947 G_VINUM_DEBUG(0, "error renaming %s to "
948 "%s: error code %d", s->name,
953 case GV_EVENT_RENAME_DRIVE:
954 G_VINUM_DEBUG(2, "event 'rename' drive");
958 err = gv_rename_drive(sc, d, newname, flags);
960 G_VINUM_DEBUG(0, "error renaming %s to "
961 "%s: error code %d", d->name,
966 case GV_EVENT_MOVE_SD:
967 G_VINUM_DEBUG(2, "event 'move' sd");
971 err = gv_move_sd(sc, s, d, flags);
973 G_VINUM_DEBUG(0, "error moving %s to "
974 "%s: error code %d", s->name,
978 case GV_EVENT_THREAD_EXIT:
979 G_VINUM_DEBUG(2, "event 'thread exit'");
981 mtx_lock(&sc->equeue_mtx);
982 mtx_lock(&sc->bqueue_mtx);
984 mtx_destroy(&sc->bqueue_mtx);
985 mtx_destroy(&sc->equeue_mtx);
986 g_free(sc->bqueue_down);
987 g_free(sc->bqueue_up);
993 G_VINUM_DEBUG(1, "unknown event %d", ev->type);
1000 /* ... then do I/O processing. */
1001 mtx_lock(&sc->bqueue_mtx);
1002 /* First do new requests. */
1003 bp = bioq_takefirst(sc->bqueue_down);
1005 mtx_unlock(&sc->bqueue_mtx);
1006 /* A bio that interfered with another bio. */
1007 if (bp->bio_pflags & GV_BIO_ONHOLD) {
1008 s = bp->bio_caller1;
1010 /* Is it still locked out? */
1011 if (gv_stripe_active(p, bp)) {
1012 /* Park the bio on the waiting queue. */
1013 bioq_disksort(p->wqueue, bp);
1015 bp->bio_pflags &= ~GV_BIO_ONHOLD;
1016 g_io_request(bp, s->drive_sc->consumer);
1018 /* A special request requireing special handling. */
1019 } else if (bp->bio_pflags & GV_BIO_INTERNAL) {
1020 p = bp->bio_caller1;
1021 gv_plex_start(p, bp);
1023 gv_volume_start(sc, bp);
1025 mtx_lock(&sc->bqueue_mtx);
1027 /* Then do completed requests. */
1028 bp = bioq_takefirst(sc->bqueue_up);
1030 msleep(sc, &sc->bqueue_mtx, PRIBIO, "-", hz/10);
1031 mtx_unlock(&sc->bqueue_mtx);
1034 mtx_unlock(&sc->bqueue_mtx);
1035 gv_bio_done(sc, bp);
1039 #define VINUM_CLASS_NAME "VINUM"
1041 static struct g_class g_vinum_class = {
1042 .name = VINUM_CLASS_NAME,
1043 .version = G_VERSION,
1046 .ctlreq = gv_config,
1047 .destroy_geom = gv_unload,
1050 DECLARE_GEOM_CLASS(g_vinum_class, g_vinum);