2 * Copyright (c) 2004-2009 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
34 #include <sys/limits.h>
36 #include <sys/mutex.h>
38 #include <sys/sysctl.h>
39 #include <sys/malloc.h>
40 #include <sys/bitstring.h>
42 #include <machine/atomic.h>
43 #include <geom/geom.h>
44 #include <geom/geom_int.h>
46 #include <sys/kthread.h>
47 #include <geom/mirror/g_mirror.h>
50 static struct g_mirror_softc *
51 g_mirror_find_device(struct g_class *mp, const char *name)
53 struct g_mirror_softc *sc;
57 LIST_FOREACH(gp, &mp->geom, geom) {
61 if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_DESTROY) != 0)
63 if (strcmp(gp->name, name) == 0 ||
64 strcmp(sc->sc_name, name) == 0) {
66 sx_xlock(&sc->sc_lock);
74 static struct g_mirror_disk *
75 g_mirror_find_disk(struct g_mirror_softc *sc, const char *name)
77 struct g_mirror_disk *disk;
79 sx_assert(&sc->sc_lock, SX_XLOCKED);
80 if (strncmp(name, "/dev/", 5) == 0)
82 LIST_FOREACH(disk, &sc->sc_disks, d_next) {
83 if (disk->d_consumer == NULL)
85 if (disk->d_consumer->provider == NULL)
87 if (strcmp(disk->d_consumer->provider->name, name) == 0)
94 g_mirror_ctl_configure(struct gctl_req *req, struct g_class *mp)
96 struct g_mirror_softc *sc;
97 struct g_mirror_disk *disk;
98 const char *name, *balancep, *prov;
99 intmax_t *slicep, *priority;
102 int *autosync, *noautosync, *failsync, *nofailsync, *hardcode, *dynamic;
103 int *nargs, do_sync = 0, dirty = 1, do_priority = 0;
105 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
107 gctl_error(req, "No '%s' argument.", "nargs");
110 if (*nargs != 1 && *nargs != 2) {
111 gctl_error(req, "Invalid number of arguments.");
114 name = gctl_get_asciiparam(req, "arg0");
116 gctl_error(req, "No 'arg%u' argument.", 0);
119 balancep = gctl_get_asciiparam(req, "balance");
120 if (balancep == NULL) {
121 gctl_error(req, "No '%s' argument.", "balance");
124 autosync = gctl_get_paraml(req, "autosync", sizeof(*autosync));
125 if (autosync == NULL) {
126 gctl_error(req, "No '%s' argument.", "autosync");
129 noautosync = gctl_get_paraml(req, "noautosync", sizeof(*noautosync));
130 if (noautosync == NULL) {
131 gctl_error(req, "No '%s' argument.", "noautosync");
134 failsync = gctl_get_paraml(req, "failsync", sizeof(*failsync));
135 if (failsync == NULL) {
136 gctl_error(req, "No '%s' argument.", "failsync");
139 nofailsync = gctl_get_paraml(req, "nofailsync", sizeof(*nofailsync));
140 if (nofailsync == NULL) {
141 gctl_error(req, "No '%s' argument.", "nofailsync");
144 hardcode = gctl_get_paraml(req, "hardcode", sizeof(*hardcode));
145 if (hardcode == NULL) {
146 gctl_error(req, "No '%s' argument.", "hardcode");
149 dynamic = gctl_get_paraml(req, "dynamic", sizeof(*dynamic));
150 if (dynamic == NULL) {
151 gctl_error(req, "No '%s' argument.", "dynamic");
154 priority = gctl_get_paraml(req, "priority", sizeof(*priority));
155 if (priority == NULL) {
156 gctl_error(req, "No '%s' argument.", "priority");
159 if (*priority < -1 || *priority > 255) {
160 gctl_error(req, "Priority range is 0 to 255, %jd given",
165 * Since we have a priority, we also need a provider now.
166 * Note: be WARNS safe, by always assigning prov and only throw an
167 * error if *priority != -1.
169 prov = gctl_get_asciiparam(req, "arg1");
170 if (*priority > -1) {
172 gctl_error(req, "Priority needs a disk name");
177 if (*autosync && *noautosync) {
178 gctl_error(req, "'%s' and '%s' specified.", "autosync",
182 if (*failsync && *nofailsync) {
183 gctl_error(req, "'%s' and '%s' specified.", "failsync",
187 if (*hardcode && *dynamic) {
188 gctl_error(req, "'%s' and '%s' specified.", "hardcode",
192 sc = g_mirror_find_device(mp, name);
194 gctl_error(req, "No such device: %s.", name);
197 if (*balancep == '\0')
198 balance = sc->sc_balance;
200 if (balance_id(balancep) == -1) {
201 gctl_error(req, "Invalid balance algorithm.");
202 sx_xunlock(&sc->sc_lock);
205 balance = balance_id(balancep);
207 slicep = gctl_get_paraml(req, "slice", sizeof(*slicep));
208 if (slicep == NULL) {
209 gctl_error(req, "No '%s' argument.", "slice");
210 sx_xunlock(&sc->sc_lock);
214 slice = sc->sc_slice;
217 /* Enforce usage() of -p not allowing any other options. */
218 if (do_priority && (*autosync || *noautosync || *failsync ||
219 *nofailsync || *hardcode || *dynamic || *slicep != -1 ||
220 *balancep != '\0')) {
221 sx_xunlock(&sc->sc_lock);
222 gctl_error(req, "only -p accepted when setting priority");
225 if (sc->sc_balance == balance && sc->sc_slice == slice && !*autosync &&
226 !*noautosync && !*failsync && !*nofailsync && !*hardcode &&
227 !*dynamic && !do_priority) {
228 sx_xunlock(&sc->sc_lock);
229 gctl_error(req, "Nothing has changed.");
232 if ((!do_priority && *nargs != 1) || (do_priority && *nargs != 2)) {
233 sx_xunlock(&sc->sc_lock);
234 gctl_error(req, "Invalid number of arguments.");
237 if (g_mirror_ndisks(sc, -1) < sc->sc_ndisks) {
238 sx_xunlock(&sc->sc_lock);
239 gctl_error(req, "Not all disks connected. Try 'forget' command "
243 sc->sc_balance = balance;
244 sc->sc_slice = slice;
245 if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_NOAUTOSYNC) != 0) {
247 sc->sc_flags &= ~G_MIRROR_DEVICE_FLAG_NOAUTOSYNC;
252 sc->sc_flags |= G_MIRROR_DEVICE_FLAG_NOAUTOSYNC;
254 if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_NOFAILSYNC) != 0) {
256 sc->sc_flags &= ~G_MIRROR_DEVICE_FLAG_NOFAILSYNC;
259 sc->sc_flags |= G_MIRROR_DEVICE_FLAG_NOFAILSYNC;
263 LIST_FOREACH(disk, &sc->sc_disks, d_next) {
265 * Handle priority first, since we only need one disk, do one
266 * operation on it and then we're done. No need to check other
267 * flags, as usage doesn't allow it.
270 if (strcmp(disk->d_name, prov) == 0) {
271 if (disk->d_priority == *priority)
272 gctl_error(req, "Nothing has changed.");
274 disk->d_priority = *priority;
275 g_mirror_update_metadata(disk);
282 if (disk->d_state == G_MIRROR_DISK_STATE_SYNCHRONIZING)
283 disk->d_flags &= ~G_MIRROR_DISK_FLAG_FORCE_SYNC;
286 disk->d_flags |= G_MIRROR_DISK_FLAG_HARDCODED;
288 disk->d_flags &= ~G_MIRROR_DISK_FLAG_HARDCODED;
290 disk->d_flags &= ~G_MIRROR_DISK_FLAG_DIRTY;
291 g_mirror_update_metadata(disk);
293 if (disk->d_state == G_MIRROR_DISK_STATE_STALE) {
294 g_mirror_event_send(disk,
295 G_MIRROR_DISK_STATE_DISCONNECTED,
296 G_MIRROR_EVENT_DONTWAIT);
300 sx_xunlock(&sc->sc_lock);
304 g_mirror_ctl_rebuild(struct gctl_req *req, struct g_class *mp)
306 struct g_mirror_metadata md;
307 struct g_mirror_softc *sc;
308 struct g_mirror_disk *disk;
309 struct g_provider *pp;
315 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
317 gctl_error(req, "No '%s' argument.", "nargs");
321 gctl_error(req, "Too few arguments.");
324 name = gctl_get_asciiparam(req, "arg0");
326 gctl_error(req, "No 'arg%u' argument.", 0);
329 sc = g_mirror_find_device(mp, name);
331 gctl_error(req, "No such device: %s.", name);
334 for (i = 1; i < (u_int)*nargs; i++) {
335 snprintf(param, sizeof(param), "arg%u", i);
336 name = gctl_get_asciiparam(req, param);
338 gctl_error(req, "No 'arg%u' argument.", i);
341 disk = g_mirror_find_disk(sc, name);
343 gctl_error(req, "No such provider: %s.", name);
346 if (g_mirror_ndisks(sc, G_MIRROR_DISK_STATE_ACTIVE) == 1 &&
347 disk->d_state == G_MIRROR_DISK_STATE_ACTIVE) {
349 * This is the last active disk. There will be nothing
350 * to rebuild it from, so deny this request.
353 "Provider %s is the last active provider in %s.",
354 name, sc->sc_geom->name);
358 * Do rebuild by resetting syncid, disconnecting the disk and
359 * connecting it again.
361 disk->d_sync.ds_syncid = 0;
362 if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_NOAUTOSYNC) != 0)
363 disk->d_flags |= G_MIRROR_DISK_FLAG_FORCE_SYNC;
364 g_mirror_update_metadata(disk);
365 pp = disk->d_consumer->provider;
367 error = g_mirror_read_metadata(disk->d_consumer, &md);
369 g_mirror_event_send(disk, G_MIRROR_DISK_STATE_DISCONNECTED,
370 G_MIRROR_EVENT_WAIT);
372 gctl_error(req, "Cannot read metadata from %s.",
376 error = g_mirror_add_disk(sc, pp, &md);
378 gctl_error(req, "Cannot reconnect component %s.",
383 sx_xunlock(&sc->sc_lock);
387 g_mirror_ctl_insert(struct gctl_req *req, struct g_class *mp)
389 struct g_mirror_softc *sc;
390 struct g_mirror_disk *disk;
391 struct g_mirror_metadata md;
392 struct g_provider *pp;
393 struct g_consumer *cp;
399 int error, *nargs, *hardcode, *inactive;
401 struct g_provider *provider;
402 struct g_consumer *consumer;
405 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
407 gctl_error(req, "No '%s' argument.", "nargs");
411 gctl_error(req, "Too few arguments.");
414 priority = gctl_get_paraml(req, "priority", sizeof(*priority));
415 if (priority == NULL) {
416 gctl_error(req, "No '%s' argument.", "priority");
419 inactive = gctl_get_paraml(req, "inactive", sizeof(*inactive));
420 if (inactive == NULL) {
421 gctl_error(req, "No '%s' argument.", "inactive");
424 hardcode = gctl_get_paraml(req, "hardcode", sizeof(*hardcode));
425 if (hardcode == NULL) {
426 gctl_error(req, "No '%s' argument.", "hardcode");
429 name = gctl_get_asciiparam(req, "arg0");
431 gctl_error(req, "No 'arg%u' argument.", 0);
434 sc = g_mirror_find_device(mp, name);
436 gctl_error(req, "No such device: %s.", name);
439 if (g_mirror_ndisks(sc, -1) < sc->sc_ndisks) {
440 gctl_error(req, "Not all disks connected.");
441 sx_xunlock(&sc->sc_lock);
445 disks = g_malloc(sizeof(*disks) * (*nargs), M_WAITOK | M_ZERO);
447 for (i = 1, n = 0; i < (u_int)*nargs; i++) {
448 snprintf(param, sizeof(param), "arg%u", i);
449 name = gctl_get_asciiparam(req, param);
451 gctl_error(req, "No 'arg%u' argument.", i);
454 if (g_mirror_find_disk(sc, name) != NULL) {
455 gctl_error(req, "Provider %s already inserted.", name);
458 if (strncmp(name, "/dev/", 5) == 0)
460 pp = g_provider_by_name(name);
462 gctl_error(req, "Unknown provider %s.", name);
465 if (sc->sc_provider->mediasize >
466 pp->mediasize - pp->sectorsize) {
467 gctl_error(req, "Provider %s too small.", name);
470 if ((sc->sc_provider->sectorsize % pp->sectorsize) != 0) {
471 gctl_error(req, "Invalid sectorsize of provider %s.",
475 cp = g_new_consumer(sc->sc_geom);
476 if (g_attach(cp, pp) != 0) {
477 g_destroy_consumer(cp);
478 gctl_error(req, "Cannot attach to provider %s.", name);
481 if (g_access(cp, 0, 1, 1) != 0) {
483 g_destroy_consumer(cp);
484 gctl_error(req, "Cannot access provider %s.", name);
487 disks[n].provider = pp;
488 disks[n].consumer = cp;
493 sx_xunlock(&sc->sc_lock);
499 for (i = 0; i < n; i++) {
500 if (disks[i].consumer == NULL)
502 g_mirror_fill_metadata(sc, NULL, &md);
503 md.md_priority = *priority;
505 md.md_dflags |= G_MIRROR_DISK_FLAG_INACTIVE;
506 pp = disks[i].provider;
508 strlcpy(md.md_provider, pp->name,
509 sizeof(md.md_provider));
511 bzero(md.md_provider, sizeof(md.md_provider));
513 md.md_provsize = pp->mediasize;
514 sector = g_malloc(pp->sectorsize, M_WAITOK);
515 mirror_metadata_encode(&md, sector);
516 error = g_write_data(disks[i].consumer,
517 pp->mediasize - pp->sectorsize, sector, pp->sectorsize);
520 gctl_error(req, "Cannot store metadata on %s.",
522 g_access(disks[i].consumer, 0, -1, -1);
523 g_detach(disks[i].consumer);
524 g_destroy_consumer(disks[i].consumer);
525 disks[i].consumer = NULL;
526 disks[i].provider = NULL;
533 /* All writes failed. */
534 sx_xunlock(&sc->sc_lock);
538 LIST_FOREACH(disk, &sc->sc_disks, d_next) {
539 g_mirror_update_metadata(disk);
542 * Release provider and wait for retaste.
545 for (i = 0; i < n; i++) {
546 if (disks[i].consumer == NULL)
548 g_access(disks[i].consumer, 0, -1, -1);
549 g_detach(disks[i].consumer);
550 g_destroy_consumer(disks[i].consumer);
553 sx_xunlock(&sc->sc_lock);
558 g_mirror_ctl_remove(struct gctl_req *req, struct g_class *mp)
560 struct g_mirror_softc *sc;
561 struct g_mirror_disk *disk;
567 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
569 gctl_error(req, "No '%s' argument.", "nargs");
573 gctl_error(req, "Too few arguments.");
576 name = gctl_get_asciiparam(req, "arg0");
578 gctl_error(req, "No 'arg%u' argument.", 0);
581 sc = g_mirror_find_device(mp, name);
583 gctl_error(req, "No such device: %s.", name);
586 if (g_mirror_ndisks(sc, -1) < sc->sc_ndisks) {
587 sx_xunlock(&sc->sc_lock);
588 gctl_error(req, "Not all disks connected. Try 'forget' command "
592 active = g_mirror_ndisks(sc, G_MIRROR_DISK_STATE_ACTIVE);
593 for (i = 1; i < (u_int)*nargs; i++) {
594 snprintf(param, sizeof(param), "arg%u", i);
595 name = gctl_get_asciiparam(req, param);
597 gctl_error(req, "No 'arg%u' argument.", i);
600 disk = g_mirror_find_disk(sc, name);
602 gctl_error(req, "No such provider: %s.", name);
605 if (disk->d_state == G_MIRROR_DISK_STATE_ACTIVE) {
609 gctl_error(req, "%s: Can't remove the last "
610 "ACTIVE component %s.", sc->sc_geom->name,
615 g_mirror_event_send(disk, G_MIRROR_DISK_STATE_DESTROY,
616 G_MIRROR_EVENT_DONTWAIT);
618 sx_xunlock(&sc->sc_lock);
622 g_mirror_ctl_resize(struct gctl_req *req, struct g_class *mp)
624 struct g_mirror_softc *sc;
625 struct g_mirror_disk *disk;
627 const char *name, *s;
631 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
633 gctl_error(req, "No '%s' argument.", "nargs");
637 gctl_error(req, "Missing device.");
640 name = gctl_get_asciiparam(req, "arg0");
642 gctl_error(req, "No 'arg%u' argument.", 0);
645 s = gctl_get_asciiparam(req, "size");
647 gctl_error(req, "No '%s' argument.", "size");
650 mediasize = strtouq(s, &x, 0);
651 if (*x != '\0' || mediasize == 0) {
652 gctl_error(req, "Invalid '%s' argument.", "size");
655 sc = g_mirror_find_device(mp, name);
657 gctl_error(req, "No such device: %s.", name);
660 /* Deny shrinking of an opened provider */
661 if ((g_debugflags & 16) == 0 && (sc->sc_provider->acr > 0 ||
662 sc->sc_provider->acw > 0 || sc->sc_provider->ace > 0)) {
663 if (sc->sc_mediasize > mediasize) {
664 gctl_error(req, "Device %s is busy.",
665 sc->sc_provider->name);
666 sx_xunlock(&sc->sc_lock);
670 LIST_FOREACH(disk, &sc->sc_disks, d_next) {
671 if (mediasize > disk->d_consumer->provider->mediasize -
672 disk->d_consumer->provider->sectorsize) {
673 gctl_error(req, "Provider %s is too small.",
675 sx_xunlock(&sc->sc_lock);
679 /* Update the size. */
680 sc->sc_mediasize = mediasize;
681 LIST_FOREACH(disk, &sc->sc_disks, d_next) {
682 g_mirror_update_metadata(disk);
685 g_resize_provider(sc->sc_provider, mediasize);
687 sx_xunlock(&sc->sc_lock);
691 g_mirror_ctl_deactivate(struct gctl_req *req, struct g_class *mp)
693 struct g_mirror_softc *sc;
694 struct g_mirror_disk *disk;
700 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
702 gctl_error(req, "No '%s' argument.", "nargs");
706 gctl_error(req, "Too few arguments.");
709 name = gctl_get_asciiparam(req, "arg0");
711 gctl_error(req, "No 'arg%u' argument.", 0);
714 sc = g_mirror_find_device(mp, name);
716 gctl_error(req, "No such device: %s.", name);
719 active = g_mirror_ndisks(sc, G_MIRROR_DISK_STATE_ACTIVE);
720 for (i = 1; i < (u_int)*nargs; i++) {
721 snprintf(param, sizeof(param), "arg%u", i);
722 name = gctl_get_asciiparam(req, param);
724 gctl_error(req, "No 'arg%u' argument.", i);
727 disk = g_mirror_find_disk(sc, name);
729 gctl_error(req, "No such provider: %s.", name);
732 if (disk->d_state == G_MIRROR_DISK_STATE_ACTIVE) {
736 gctl_error(req, "%s: Can't deactivate the "
737 "last ACTIVE component %s.",
738 sc->sc_geom->name, name);
742 disk->d_flags |= G_MIRROR_DISK_FLAG_INACTIVE;
743 disk->d_flags &= ~G_MIRROR_DISK_FLAG_FORCE_SYNC;
744 g_mirror_update_metadata(disk);
745 sc->sc_bump_id |= G_MIRROR_BUMP_SYNCID;
746 g_mirror_event_send(disk, G_MIRROR_DISK_STATE_DISCONNECTED,
747 G_MIRROR_EVENT_DONTWAIT);
749 sx_xunlock(&sc->sc_lock);
753 g_mirror_ctl_forget(struct gctl_req *req, struct g_class *mp)
755 struct g_mirror_softc *sc;
756 struct g_mirror_disk *disk;
762 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
764 gctl_error(req, "No '%s' argument.", "nargs");
768 gctl_error(req, "Missing device(s).");
772 for (i = 0; i < (u_int)*nargs; i++) {
773 snprintf(param, sizeof(param), "arg%u", i);
774 name = gctl_get_asciiparam(req, param);
776 gctl_error(req, "No 'arg%u' argument.", i);
779 sc = g_mirror_find_device(mp, name);
781 gctl_error(req, "No such device: %s.", name);
784 if (g_mirror_ndisks(sc, -1) == sc->sc_ndisks) {
785 sx_xunlock(&sc->sc_lock);
787 "All disks connected in %s, skipping.",
791 sc->sc_ndisks = g_mirror_ndisks(sc, -1);
792 LIST_FOREACH(disk, &sc->sc_disks, d_next) {
793 g_mirror_update_metadata(disk);
795 sx_xunlock(&sc->sc_lock);
800 g_mirror_ctl_stop(struct gctl_req *req, struct g_class *mp, int wipe)
802 struct g_mirror_softc *sc;
803 int *force, *nargs, error;
809 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
811 gctl_error(req, "No '%s' argument.", "nargs");
815 gctl_error(req, "Missing device(s).");
818 force = gctl_get_paraml(req, "force", sizeof(*force));
820 gctl_error(req, "No '%s' argument.", "force");
824 how = G_MIRROR_DESTROY_HARD;
826 how = G_MIRROR_DESTROY_SOFT;
828 for (i = 0; i < (u_int)*nargs; i++) {
829 snprintf(param, sizeof(param), "arg%u", i);
830 name = gctl_get_asciiparam(req, param);
832 gctl_error(req, "No 'arg%u' argument.", i);
835 sc = g_mirror_find_device(mp, name);
837 gctl_error(req, "No such device: %s.", name);
842 sc->sc_flags |= G_MIRROR_DEVICE_FLAG_WIPE;
843 error = g_mirror_destroy(sc, how);
845 gctl_error(req, "Cannot destroy device %s (error=%d).",
846 sc->sc_geom->name, error);
848 sc->sc_flags &= ~G_MIRROR_DEVICE_FLAG_WIPE;
849 sx_xunlock(&sc->sc_lock);
852 /* No need to unlock, because lock is already dead. */
857 g_mirror_config(struct gctl_req *req, struct g_class *mp, const char *verb)
863 version = gctl_get_paraml(req, "version", sizeof(*version));
864 if (version == NULL) {
865 gctl_error(req, "No '%s' argument.", "version");
868 if (*version != G_MIRROR_VERSION) {
869 gctl_error(req, "Userland and kernel parts are out of sync.");
874 if (strcmp(verb, "configure") == 0)
875 g_mirror_ctl_configure(req, mp);
876 else if (strcmp(verb, "rebuild") == 0)
877 g_mirror_ctl_rebuild(req, mp);
878 else if (strcmp(verb, "insert") == 0)
879 g_mirror_ctl_insert(req, mp);
880 else if (strcmp(verb, "remove") == 0)
881 g_mirror_ctl_remove(req, mp);
882 else if (strcmp(verb, "resize") == 0)
883 g_mirror_ctl_resize(req, mp);
884 else if (strcmp(verb, "deactivate") == 0)
885 g_mirror_ctl_deactivate(req, mp);
886 else if (strcmp(verb, "forget") == 0)
887 g_mirror_ctl_forget(req, mp);
888 else if (strcmp(verb, "stop") == 0)
889 g_mirror_ctl_stop(req, mp, 0);
890 else if (strcmp(verb, "destroy") == 0)
891 g_mirror_ctl_stop(req, mp, 1);
893 gctl_error(req, "Unknown verb.");