2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * Copyright (c) 2019 Mariusz Zaborski <oshogbo@FreeBSD.org>
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 THE AUTHORS 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 THE AUTHORS 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
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/ctype.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
39 #include <sys/mutex.h>
42 #include <sys/sysctl.h>
43 #include <sys/malloc.h>
44 #include <geom/geom.h>
45 #include <geom/geom_dbg.h>
46 #include <geom/nop/g_nop.h>
49 SYSCTL_DECL(_kern_geom);
50 static SYSCTL_NODE(_kern_geom, OID_AUTO, nop, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
52 static u_int g_nop_debug = 0;
53 SYSCTL_UINT(_kern_geom_nop, OID_AUTO, debug, CTLFLAG_RW, &g_nop_debug, 0,
56 static int g_nop_destroy(struct g_geom *gp, boolean_t force);
57 static int g_nop_destroy_geom(struct gctl_req *req, struct g_class *mp,
59 static void g_nop_config(struct gctl_req *req, struct g_class *mp,
61 static g_access_t g_nop_access;
62 static g_dumpconf_t g_nop_dumpconf;
63 static g_orphan_t g_nop_orphan;
64 static g_provgone_t g_nop_providergone;
65 static g_resize_t g_nop_resize;
66 static g_start_t g_nop_start;
68 struct g_class g_nop_class = {
69 .name = G_NOP_CLASS_NAME,
71 .ctlreq = g_nop_config,
72 .destroy_geom = g_nop_destroy_geom,
73 .access = g_nop_access,
74 .dumpconf = g_nop_dumpconf,
75 .orphan = g_nop_orphan,
76 .providergone = g_nop_providergone,
77 .resize = g_nop_resize,
82 struct callout dl_cal;
84 TAILQ_ENTRY(g_nop_delay) dl_next;
88 g_nop_verify_nprefix(const char *name)
92 for (i = 0; i < strlen(name); i++) {
93 if (isalpha(name[i]) == 0 && isdigit(name[i]) == 0) {
102 g_nop_orphan(struct g_consumer *cp)
106 g_nop_destroy(cp->geom, 1);
110 g_nop_resize(struct g_consumer *cp)
112 struct g_nop_softc *sc;
114 struct g_provider *pp;
122 if (sc->sc_explicitsize != 0)
124 if (cp->provider->mediasize < sc->sc_offset) {
125 g_nop_destroy(gp, 1);
128 size = cp->provider->mediasize - sc->sc_offset;
129 LIST_FOREACH(pp, &gp->provider, provider)
130 g_resize_provider(pp, size);
134 g_nop_dumper(void *priv, void *virtual, vm_offset_t physical, off_t offset,
142 g_nop_kerneldump(struct bio *bp, struct g_nop_softc *sc)
144 struct g_kerneldump *gkd;
146 struct g_provider *pp;
148 gkd = (struct g_kerneldump *)bp->bio_data;
149 gp = bp->bio_to->geom;
150 g_trace(G_T_TOPOLOGY, "%s(%s, %jd, %jd)", __func__, gp->name,
151 (intmax_t)gkd->offset, (intmax_t)gkd->length);
153 pp = LIST_FIRST(&gp->provider);
155 gkd->di.dumper = g_nop_dumper;
157 gkd->di.blocksize = pp->sectorsize;
158 gkd->di.maxiosize = DFLTPHYS;
159 gkd->di.mediaoffset = sc->sc_offset + gkd->offset;
160 if (gkd->offset > sc->sc_explicitsize) {
161 g_io_deliver(bp, ENODEV);
164 if (gkd->offset + gkd->length > sc->sc_explicitsize)
165 gkd->length = sc->sc_explicitsize - gkd->offset;
166 gkd->di.mediasize = gkd->length;
171 g_nop_pass(struct bio *cbp, struct g_geom *gp)
174 G_NOP_LOGREQ(cbp, "Sending request.");
175 g_io_request(cbp, LIST_FIRST(&gp->consumer));
179 g_nop_pass_timeout(void *data)
181 struct g_nop_softc *sc;
183 struct g_nop_delay *gndelay;
185 gndelay = (struct g_nop_delay *)data;
187 gp = gndelay->dl_bio->bio_to->geom;
190 mtx_lock(&sc->sc_lock);
191 TAILQ_REMOVE(&sc->sc_head_delay, gndelay, dl_next);
192 mtx_unlock(&sc->sc_lock);
194 g_nop_pass(gndelay->dl_bio, gp);
200 g_nop_start(struct bio *bp)
202 struct g_nop_softc *sc;
204 struct g_provider *pp;
206 u_int failprob, delayprob, delaytime;
208 failprob = delayprob = delaytime = 0;
210 gp = bp->bio_to->geom;
213 G_NOP_LOGREQ(bp, "Request received.");
214 mtx_lock(&sc->sc_lock);
215 switch (bp->bio_cmd) {
218 sc->sc_readbytes += bp->bio_length;
219 if (sc->sc_count_until_fail != 0) {
220 sc->sc_count_until_fail -= 1;
222 failprob = sc->sc_rfailprob;
223 delayprob = sc->sc_rdelayprob;
224 delaytime = sc->sc_delaymsec;
229 sc->sc_wrotebytes += bp->bio_length;
230 if (sc->sc_count_until_fail != 0) {
231 sc->sc_count_until_fail -= 1;
233 failprob = sc->sc_wfailprob;
234 delayprob = sc->sc_wdelayprob;
235 delaytime = sc->sc_delaymsec;
243 if (sc->sc_physpath &&
244 g_handleattr_str(bp, "GEOM::physpath", sc->sc_physpath))
246 else if (strcmp(bp->bio_attribute, "GEOM::kerneldump") == 0)
247 g_nop_kerneldump(bp, sc);
250 * Fallthrough to forwarding the GETATTR down to the
251 * lower level device.
254 mtx_unlock(&sc->sc_lock);
272 mtx_unlock(&sc->sc_lock);
277 rval = arc4random() % 100;
278 if (rval < failprob) {
279 G_NOP_LOGREQLVL(1, bp, "Returning error=%d.", sc->sc_error);
280 g_io_deliver(bp, sc->sc_error);
285 cbp = g_clone_bio(bp);
287 g_io_deliver(bp, ENOMEM);
290 cbp->bio_done = g_std_done;
291 cbp->bio_offset = bp->bio_offset + sc->sc_offset;
292 pp = LIST_FIRST(&gp->provider);
293 KASSERT(pp != NULL, ("NULL pp"));
297 struct g_nop_delay *gndelay;
300 rval = arc4random() % 100;
301 if (rval < delayprob) {
302 gndelay = g_malloc(sizeof(*gndelay), M_NOWAIT | M_ZERO);
303 if (gndelay != NULL) {
304 callout_init(&gndelay->dl_cal, 1);
306 gndelay->dl_bio = cbp;
308 mtx_lock(&sc->sc_lock);
309 TAILQ_INSERT_TAIL(&sc->sc_head_delay, gndelay,
311 mtx_unlock(&sc->sc_lock);
313 callout_reset(&gndelay->dl_cal,
314 MSEC_2_TICKS(delaytime), g_nop_pass_timeout,
325 g_nop_access(struct g_provider *pp, int dr, int dw, int de)
328 struct g_consumer *cp;
332 cp = LIST_FIRST(&gp->consumer);
333 error = g_access(cp, dr, dw, de);
339 g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
340 const char *gnopname, int ioerror, u_int count_until_fail,
341 u_int rfailprob, u_int wfailprob, u_int delaymsec, u_int rdelayprob,
342 u_int wdelayprob, off_t offset, off_t size, u_int secsize, off_t stripesize,
343 off_t stripeoffset, const char *physpath)
345 struct g_nop_softc *sc;
347 struct g_provider *newpp;
348 struct g_consumer *cp;
349 struct g_geom_alias *gap;
360 if ((offset % pp->sectorsize) != 0) {
361 gctl_error(req, "Invalid offset for provider %s.", pp->name);
364 if ((size % pp->sectorsize) != 0) {
365 gctl_error(req, "Invalid size for provider %s.", pp->name);
368 if (offset >= pp->mediasize) {
369 gctl_error(req, "Invalid offset for provider %s.", pp->name);
374 size = pp->mediasize - offset;
375 if (offset + size > pp->mediasize) {
376 gctl_error(req, "Invalid size for provider %s.", pp->name);
380 secsize = pp->sectorsize;
381 else if ((secsize % pp->sectorsize) != 0) {
382 gctl_error(req, "Invalid secsize for provider %s.", pp->name);
385 if (secsize > MAXPHYS) {
386 gctl_error(req, "secsize is too big.");
389 size -= size % secsize;
390 if ((stripesize % pp->sectorsize) != 0) {
391 gctl_error(req, "Invalid stripesize for provider %s.", pp->name);
394 if ((stripeoffset % pp->sectorsize) != 0) {
395 gctl_error(req, "Invalid stripeoffset for provider %s.", pp->name);
398 if (stripesize != 0 && stripeoffset >= stripesize) {
399 gctl_error(req, "stripeoffset is too big.");
402 if (gnopname != NULL && !g_nop_verify_nprefix(gnopname)) {
403 gctl_error(req, "Name %s is invalid.", gnopname);
407 if (gnopname != NULL) {
408 n = snprintf(name, sizeof(name), "%s%s", gnopname,
411 n = snprintf(name, sizeof(name), "%s%s", pp->name,
414 if (n <= 0 || n >= sizeof(name)) {
415 gctl_error(req, "Invalid provider name.");
418 LIST_FOREACH(gp, &mp->geom, geom) {
419 if (strcmp(gp->name, name) == 0) {
420 gctl_error(req, "Provider %s already exists.", name);
424 gp = g_new_geomf(mp, "%s", name);
425 sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
426 sc->sc_offset = offset;
427 sc->sc_explicitsize = explicitsize;
428 sc->sc_stripesize = stripesize;
429 sc->sc_stripeoffset = stripeoffset;
430 if (physpath && strcmp(physpath, G_NOP_PHYSPATH_PASSTHROUGH)) {
431 sc->sc_physpath = strndup(physpath, MAXPATHLEN, M_GEOM);
433 sc->sc_physpath = NULL;
434 sc->sc_error = ioerror;
435 sc->sc_count_until_fail = count_until_fail;
436 sc->sc_rfailprob = rfailprob;
437 sc->sc_wfailprob = wfailprob;
438 sc->sc_delaymsec = delaymsec;
439 sc->sc_rdelayprob = rdelayprob;
440 sc->sc_wdelayprob = wdelayprob;
450 sc->sc_readbytes = 0;
451 sc->sc_wrotebytes = 0;
452 TAILQ_INIT(&sc->sc_head_delay);
453 mtx_init(&sc->sc_lock, "gnop lock", NULL, MTX_DEF);
456 newpp = g_new_providerf(gp, "%s", gp->name);
457 newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
458 newpp->mediasize = size;
459 newpp->sectorsize = secsize;
460 newpp->stripesize = stripesize;
461 newpp->stripeoffset = stripeoffset;
462 LIST_FOREACH(gap, &pp->aliases, ga_next)
463 g_provider_add_alias(newpp, "%s%s", gap->ga_alias, G_NOP_SUFFIX);
465 cp = g_new_consumer(gp);
466 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
467 error = g_attach(cp, pp);
469 gctl_error(req, "Cannot attach to provider %s.", pp->name);
473 newpp->flags |= pp->flags & G_PF_ACCEPT_UNMAPPED;
474 g_error_provider(newpp, 0);
475 G_NOP_DEBUG(0, "Device %s created.", gp->name);
478 if (cp->provider != NULL)
480 g_destroy_consumer(cp);
481 g_destroy_provider(newpp);
482 mtx_destroy(&sc->sc_lock);
483 free(sc->sc_physpath, M_GEOM);
490 g_nop_providergone(struct g_provider *pp)
492 struct g_geom *gp = pp->geom;
493 struct g_nop_softc *sc = gp->softc;
495 KASSERT(TAILQ_EMPTY(&sc->sc_head_delay),
496 ("delayed request list is not empty"));
499 free(sc->sc_physpath, M_GEOM);
500 mtx_destroy(&sc->sc_lock);
505 g_nop_destroy(struct g_geom *gp, boolean_t force)
507 struct g_nop_softc *sc;
508 struct g_provider *pp;
514 pp = LIST_FIRST(&gp->provider);
515 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
517 G_NOP_DEBUG(0, "Device %s is still open, so it "
518 "can't be definitely removed.", pp->name);
520 G_NOP_DEBUG(1, "Device %s is still open (r%dw%de%d).",
521 pp->name, pp->acr, pp->acw, pp->ace);
525 G_NOP_DEBUG(0, "Device %s removed.", gp->name);
528 g_wither_geom(gp, ENXIO);
534 g_nop_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
537 return (g_nop_destroy(gp, 0));
541 g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
543 struct g_provider *pp;
544 intmax_t *val, error, rfailprob, wfailprob, count_until_fail, offset,
545 secsize, size, stripesize, stripeoffset, delaymsec,
546 rdelayprob, wdelayprob;
547 const char *name, *physpath, *gnopname;
556 count_until_fail = -1;
566 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
568 gctl_error(req, "No '%s' argument", "nargs");
572 gctl_error(req, "Missing device(s).");
575 val = gctl_get_paraml_opt(req, "error", sizeof(*val));
579 val = gctl_get_paraml_opt(req, "rfailprob", sizeof(*val));
582 if (rfailprob < -1 || rfailprob > 100) {
583 gctl_error(req, "Invalid '%s' argument", "rfailprob");
587 val = gctl_get_paraml_opt(req, "wfailprob", sizeof(*val));
590 if (wfailprob < -1 || wfailprob > 100) {
591 gctl_error(req, "Invalid '%s' argument", "wfailprob");
595 val = gctl_get_paraml_opt(req, "delaymsec", sizeof(*val));
598 if (delaymsec < 1 && delaymsec != -1) {
599 gctl_error(req, "Invalid '%s' argument", "delaymsec");
603 val = gctl_get_paraml_opt(req, "rdelayprob", sizeof(*val));
606 if (rdelayprob < -1 || rdelayprob > 100) {
607 gctl_error(req, "Invalid '%s' argument", "rdelayprob");
611 val = gctl_get_paraml_opt(req, "wdelayprob", sizeof(*val));
614 if (wdelayprob < -1 || wdelayprob > 100) {
615 gctl_error(req, "Invalid '%s' argument", "wdelayprob");
619 val = gctl_get_paraml_opt(req, "count_until_fail", sizeof(*val));
621 count_until_fail = *val;
622 if (count_until_fail < -1) {
623 gctl_error(req, "Invalid '%s' argument",
628 val = gctl_get_paraml_opt(req, "offset", sizeof(*val));
632 gctl_error(req, "Invalid '%s' argument", "offset");
636 val = gctl_get_paraml_opt(req, "size", sizeof(*val));
640 gctl_error(req, "Invalid '%s' argument", "size");
644 val = gctl_get_paraml_opt(req, "secsize", sizeof(*val));
648 gctl_error(req, "Invalid '%s' argument", "secsize");
652 val = gctl_get_paraml_opt(req, "stripesize", sizeof(*val));
655 if (stripesize < 0) {
656 gctl_error(req, "Invalid '%s' argument", "stripesize");
660 val = gctl_get_paraml_opt(req, "stripeoffset", sizeof(*val));
663 if (stripeoffset < 0) {
664 gctl_error(req, "Invalid '%s' argument",
669 physpath = gctl_get_asciiparam(req, "physpath");
670 gnopname = gctl_get_asciiparam(req, "gnopname");
672 for (i = 0; i < *nargs; i++) {
673 snprintf(param, sizeof(param), "arg%d", i);
674 name = gctl_get_asciiparam(req, param);
676 gctl_error(req, "No 'arg%d' argument", i);
679 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
680 name += strlen(_PATH_DEV);
681 pp = g_provider_by_name(name);
683 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
684 gctl_error(req, "Provider %s is invalid.", name);
687 if (g_nop_create(req, mp, pp,
689 error == -1 ? EIO : (int)error,
690 count_until_fail == -1 ? 0 : (u_int)count_until_fail,
691 rfailprob == -1 ? 0 : (u_int)rfailprob,
692 wfailprob == -1 ? 0 : (u_int)wfailprob,
693 delaymsec == -1 ? 1 : (u_int)delaymsec,
694 rdelayprob == -1 ? 0 : (u_int)rdelayprob,
695 wdelayprob == -1 ? 0 : (u_int)wdelayprob,
696 (off_t)offset, (off_t)size, (u_int)secsize,
697 (off_t)stripesize, (off_t)stripeoffset,
705 g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp)
707 struct g_nop_softc *sc;
708 struct g_provider *pp;
709 intmax_t *val, delaymsec, error, rdelayprob, rfailprob, wdelayprob,
710 wfailprob, count_until_fail;
717 count_until_fail = -1;
725 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
727 gctl_error(req, "No '%s' argument", "nargs");
731 gctl_error(req, "Missing device(s).");
734 val = gctl_get_paraml_opt(req, "error", sizeof(*val));
738 val = gctl_get_paraml_opt(req, "count_until_fail", sizeof(*val));
740 count_until_fail = *val;
742 val = gctl_get_paraml_opt(req, "rfailprob", sizeof(*val));
745 if (rfailprob < -1 || rfailprob > 100) {
746 gctl_error(req, "Invalid '%s' argument", "rfailprob");
750 val = gctl_get_paraml_opt(req, "wfailprob", sizeof(*val));
753 if (wfailprob < -1 || wfailprob > 100) {
754 gctl_error(req, "Invalid '%s' argument", "wfailprob");
758 val = gctl_get_paraml_opt(req, "delaymsec", sizeof(*val));
761 if (delaymsec < 1 && delaymsec != -1) {
762 gctl_error(req, "Invalid '%s' argument", "delaymsec");
766 val = gctl_get_paraml_opt(req, "rdelayprob", sizeof(*val));
769 if (rdelayprob < -1 || rdelayprob > 100) {
770 gctl_error(req, "Invalid '%s' argument", "rdelayprob");
774 val = gctl_get_paraml_opt(req, "wdelayprob", sizeof(*val));
777 if (wdelayprob < -1 || wdelayprob > 100) {
778 gctl_error(req, "Invalid '%s' argument", "wdelayprob");
783 for (i = 0; i < *nargs; i++) {
784 snprintf(param, sizeof(param), "arg%d", i);
785 name = gctl_get_asciiparam(req, param);
787 gctl_error(req, "No 'arg%d' argument", i);
790 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
791 name += strlen(_PATH_DEV);
792 pp = g_provider_by_name(name);
793 if (pp == NULL || pp->geom->class != mp) {
794 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
795 gctl_error(req, "Provider %s is invalid.", name);
798 sc = pp->geom->softc;
800 sc->sc_error = (int)error;
802 sc->sc_rfailprob = (u_int)rfailprob;
804 sc->sc_wfailprob = (u_int)wfailprob;
805 if (rdelayprob != -1)
806 sc->sc_rdelayprob = (u_int)rdelayprob;
807 if (wdelayprob != -1)
808 sc->sc_wdelayprob = (u_int)wdelayprob;
810 sc->sc_delaymsec = (u_int)delaymsec;
811 if (count_until_fail != -1)
812 sc->sc_count_until_fail = (u_int)count_until_fail;
816 static struct g_geom *
817 g_nop_find_geom(struct g_class *mp, const char *name)
821 LIST_FOREACH(gp, &mp->geom, geom) {
822 if (strcmp(gp->name, name) == 0)
829 g_nop_ctl_destroy(struct gctl_req *req, struct g_class *mp)
831 int *nargs, *force, error, i;
838 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
840 gctl_error(req, "No '%s' argument", "nargs");
844 gctl_error(req, "Missing device(s).");
847 force = gctl_get_paraml(req, "force", sizeof(*force));
849 gctl_error(req, "No 'force' argument");
853 for (i = 0; i < *nargs; i++) {
854 snprintf(param, sizeof(param), "arg%d", i);
855 name = gctl_get_asciiparam(req, param);
857 gctl_error(req, "No 'arg%d' argument", i);
860 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
861 name += strlen(_PATH_DEV);
862 gp = g_nop_find_geom(mp, name);
864 G_NOP_DEBUG(1, "Device %s is invalid.", name);
865 gctl_error(req, "Device %s is invalid.", name);
868 error = g_nop_destroy(gp, *force);
870 gctl_error(req, "Cannot destroy device %s (error=%d).",
878 g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp)
880 struct g_nop_softc *sc;
881 struct g_provider *pp;
888 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
890 gctl_error(req, "No '%s' argument", "nargs");
894 gctl_error(req, "Missing device(s).");
898 for (i = 0; i < *nargs; i++) {
899 snprintf(param, sizeof(param), "arg%d", i);
900 name = gctl_get_asciiparam(req, param);
902 gctl_error(req, "No 'arg%d' argument", i);
905 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
906 name += strlen(_PATH_DEV);
907 pp = g_provider_by_name(name);
908 if (pp == NULL || pp->geom->class != mp) {
909 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
910 gctl_error(req, "Provider %s is invalid.", name);
913 sc = pp->geom->softc;
923 sc->sc_readbytes = 0;
924 sc->sc_wrotebytes = 0;
929 g_nop_config(struct gctl_req *req, struct g_class *mp, const char *verb)
935 version = gctl_get_paraml(req, "version", sizeof(*version));
936 if (version == NULL) {
937 gctl_error(req, "No '%s' argument.", "version");
940 if (*version != G_NOP_VERSION) {
941 gctl_error(req, "Userland and kernel parts are out of sync.");
945 if (strcmp(verb, "create") == 0) {
946 g_nop_ctl_create(req, mp);
948 } else if (strcmp(verb, "configure") == 0) {
949 g_nop_ctl_configure(req, mp);
951 } else if (strcmp(verb, "destroy") == 0) {
952 g_nop_ctl_destroy(req, mp);
954 } else if (strcmp(verb, "reset") == 0) {
955 g_nop_ctl_reset(req, mp);
959 gctl_error(req, "Unknown verb.");
963 g_nop_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
964 struct g_consumer *cp, struct g_provider *pp)
966 struct g_nop_softc *sc;
968 if (pp != NULL || cp != NULL)
971 sbuf_printf(sb, "%s<Offset>%jd</Offset>\n", indent,
972 (intmax_t)sc->sc_offset);
973 sbuf_printf(sb, "%s<ReadFailProb>%u</ReadFailProb>\n", indent,
975 sbuf_printf(sb, "%s<WriteFailProb>%u</WriteFailProb>\n", indent,
977 sbuf_printf(sb, "%s<ReadDelayedProb>%u</ReadDelayedProb>\n", indent,
979 sbuf_printf(sb, "%s<WriteDelayedProb>%u</WriteDelayedProb>\n", indent,
981 sbuf_printf(sb, "%s<Delay>%d</Delay>\n", indent, sc->sc_delaymsec);
982 sbuf_printf(sb, "%s<CountUntilFail>%u</CountUntilFail>\n", indent,
983 sc->sc_count_until_fail);
984 sbuf_printf(sb, "%s<Error>%d</Error>\n", indent, sc->sc_error);
985 sbuf_printf(sb, "%s<Reads>%ju</Reads>\n", indent, sc->sc_reads);
986 sbuf_printf(sb, "%s<Writes>%ju</Writes>\n", indent, sc->sc_writes);
987 sbuf_printf(sb, "%s<Deletes>%ju</Deletes>\n", indent, sc->sc_deletes);
988 sbuf_printf(sb, "%s<Getattrs>%ju</Getattrs>\n", indent, sc->sc_getattrs);
989 sbuf_printf(sb, "%s<Flushes>%ju</Flushes>\n", indent, sc->sc_flushes);
990 sbuf_printf(sb, "%s<Speedups>%ju</Speedups>\n", indent, sc->sc_speedups);
991 sbuf_printf(sb, "%s<Cmd0s>%ju</Cmd0s>\n", indent, sc->sc_cmd0s);
992 sbuf_printf(sb, "%s<Cmd1s>%ju</Cmd1s>\n", indent, sc->sc_cmd1s);
993 sbuf_printf(sb, "%s<Cmd2s>%ju</Cmd2s>\n", indent, sc->sc_cmd2s);
994 sbuf_printf(sb, "%s<ReadBytes>%ju</ReadBytes>\n", indent,
996 sbuf_printf(sb, "%s<WroteBytes>%ju</WroteBytes>\n", indent,
1000 DECLARE_GEOM_CLASS(g_nop_class, g_nop);
1001 MODULE_VERSION(geom_nop, 0);