2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * 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>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <sys/mutex.h>
40 #include <sys/sysctl.h>
41 #include <sys/malloc.h>
42 #include <geom/geom.h>
43 #include <geom/geom_dbg.h>
44 #include <geom/nop/g_nop.h>
47 SYSCTL_DECL(_kern_geom);
48 static SYSCTL_NODE(_kern_geom, OID_AUTO, nop, CTLFLAG_RW, 0, "GEOM_NOP stuff");
49 static u_int g_nop_debug = 0;
50 SYSCTL_UINT(_kern_geom_nop, OID_AUTO, debug, CTLFLAG_RW, &g_nop_debug, 0,
53 static int g_nop_destroy(struct g_geom *gp, boolean_t force);
54 static int g_nop_destroy_geom(struct gctl_req *req, struct g_class *mp,
56 static void g_nop_config(struct gctl_req *req, struct g_class *mp,
58 static g_access_t g_nop_access;
59 static g_dumpconf_t g_nop_dumpconf;
60 static g_orphan_t g_nop_orphan;
61 static g_provgone_t g_nop_providergone;
62 static g_resize_t g_nop_resize;
63 static g_start_t g_nop_start;
65 struct g_class g_nop_class = {
66 .name = G_NOP_CLASS_NAME,
68 .ctlreq = g_nop_config,
69 .destroy_geom = g_nop_destroy_geom,
70 .access = g_nop_access,
71 .dumpconf = g_nop_dumpconf,
72 .orphan = g_nop_orphan,
73 .providergone = g_nop_providergone,
74 .resize = g_nop_resize,
79 struct callout dl_cal;
81 TAILQ_ENTRY(g_nop_delay) dl_next;
85 g_nop_orphan(struct g_consumer *cp)
89 g_nop_destroy(cp->geom, 1);
93 g_nop_resize(struct g_consumer *cp)
95 struct g_nop_softc *sc;
97 struct g_provider *pp;
105 if (sc->sc_explicitsize != 0)
107 if (cp->provider->mediasize < sc->sc_offset) {
108 g_nop_destroy(gp, 1);
111 size = cp->provider->mediasize - sc->sc_offset;
112 LIST_FOREACH(pp, &gp->provider, provider)
113 g_resize_provider(pp, size);
117 g_nop_dumper(void *priv, void *virtual, vm_offset_t physical, off_t offset,
125 g_nop_kerneldump(struct bio *bp, struct g_nop_softc *sc)
127 struct g_kerneldump *gkd;
129 struct g_provider *pp;
131 gkd = (struct g_kerneldump *)bp->bio_data;
132 gp = bp->bio_to->geom;
133 g_trace(G_T_TOPOLOGY, "%s(%s, %jd, %jd)", __func__, gp->name,
134 (intmax_t)gkd->offset, (intmax_t)gkd->length);
136 pp = LIST_FIRST(&gp->provider);
138 gkd->di.dumper = g_nop_dumper;
140 gkd->di.blocksize = pp->sectorsize;
141 gkd->di.maxiosize = DFLTPHYS;
142 gkd->di.mediaoffset = sc->sc_offset + gkd->offset;
143 if (gkd->offset > sc->sc_explicitsize) {
144 g_io_deliver(bp, ENODEV);
147 if (gkd->offset + gkd->length > sc->sc_explicitsize)
148 gkd->length = sc->sc_explicitsize - gkd->offset;
149 gkd->di.mediasize = gkd->length;
154 g_nop_pass(struct bio *cbp, struct g_geom *gp)
157 G_NOP_LOGREQ(cbp, "Sending request.");
158 g_io_request(cbp, LIST_FIRST(&gp->consumer));
162 g_nop_pass_timeout(void *data)
164 struct g_nop_softc *sc;
166 struct g_nop_delay *gndelay;
168 gndelay = (struct g_nop_delay *)data;
170 gp = gndelay->dl_bio->bio_to->geom;
173 mtx_lock(&sc->sc_lock);
174 TAILQ_REMOVE(&sc->sc_head_delay, gndelay, dl_next);
175 mtx_unlock(&sc->sc_lock);
177 g_nop_pass(gndelay->dl_bio, gp);
183 g_nop_start(struct bio *bp)
185 struct g_nop_softc *sc;
187 struct g_provider *pp;
189 u_int failprob, delayprob, delaytime;
191 failprob = delayprob = 0;
193 gp = bp->bio_to->geom;
196 G_NOP_LOGREQ(bp, "Request received.");
197 mtx_lock(&sc->sc_lock);
198 switch (bp->bio_cmd) {
201 sc->sc_readbytes += bp->bio_length;
202 failprob = sc->sc_rfailprob;
203 delayprob = sc->sc_rdelayprob;
204 delaytime = sc->sc_delaymsec;
208 sc->sc_wrotebytes += bp->bio_length;
209 failprob = sc->sc_wfailprob;
210 delayprob = sc->sc_wdelayprob;
211 delaytime = sc->sc_delaymsec;
218 if (sc->sc_physpath &&
219 g_handleattr_str(bp, "GEOM::physpath", sc->sc_physpath))
221 else if (strcmp(bp->bio_attribute, "GEOM::kerneldump") == 0)
222 g_nop_kerneldump(bp, sc);
225 * Fallthrough to forwarding the GETATTR down to the
226 * lower level device.
229 mtx_unlock(&sc->sc_lock);
244 mtx_unlock(&sc->sc_lock);
248 rval = arc4random() % 100;
249 if (rval < failprob) {
250 G_NOP_LOGREQLVL(1, bp, "Returning error=%d.", sc->sc_error);
251 g_io_deliver(bp, sc->sc_error);
256 cbp = g_clone_bio(bp);
258 g_io_deliver(bp, ENOMEM);
261 cbp->bio_done = g_std_done;
262 cbp->bio_offset = bp->bio_offset + sc->sc_offset;
263 pp = LIST_FIRST(&gp->provider);
264 KASSERT(pp != NULL, ("NULL pp"));
268 struct g_nop_delay *gndelay;
271 rval = arc4random() % 100;
272 if (rval < delayprob) {
273 gndelay = g_malloc(sizeof(*gndelay), M_NOWAIT | M_ZERO);
274 if (gndelay != NULL) {
275 callout_init(&gndelay->dl_cal, 1);
277 gndelay->dl_bio = cbp;
279 mtx_lock(&sc->sc_lock);
280 TAILQ_INSERT_TAIL(&sc->sc_head_delay, gndelay,
282 mtx_unlock(&sc->sc_lock);
284 callout_reset(&gndelay->dl_cal,
285 MSEC_2_TICKS(delaytime), g_nop_pass_timeout,
296 g_nop_access(struct g_provider *pp, int dr, int dw, int de)
299 struct g_consumer *cp;
303 cp = LIST_FIRST(&gp->consumer);
304 error = g_access(cp, dr, dw, de);
310 g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
311 int ioerror, u_int rfailprob, u_int wfailprob, u_int delaymsec, u_int rdelayprob,
312 u_int wdelayprob, off_t offset, off_t size, u_int secsize, off_t stripesize,
313 off_t stripeoffset, const char *physpath)
315 struct g_nop_softc *sc;
317 struct g_provider *newpp;
318 struct g_consumer *cp;
329 if ((offset % pp->sectorsize) != 0) {
330 gctl_error(req, "Invalid offset for provider %s.", pp->name);
333 if ((size % pp->sectorsize) != 0) {
334 gctl_error(req, "Invalid size for provider %s.", pp->name);
337 if (offset >= pp->mediasize) {
338 gctl_error(req, "Invalid offset for provider %s.", pp->name);
343 size = pp->mediasize - offset;
344 if (offset + size > pp->mediasize) {
345 gctl_error(req, "Invalid size for provider %s.", pp->name);
349 secsize = pp->sectorsize;
350 else if ((secsize % pp->sectorsize) != 0) {
351 gctl_error(req, "Invalid secsize for provider %s.", pp->name);
354 if (secsize > MAXPHYS) {
355 gctl_error(req, "secsize is too big.");
358 size -= size % secsize;
359 if ((stripesize % pp->sectorsize) != 0) {
360 gctl_error(req, "Invalid stripesize for provider %s.", pp->name);
363 if ((stripeoffset % pp->sectorsize) != 0) {
364 gctl_error(req, "Invalid stripeoffset for provider %s.", pp->name);
367 if (stripesize != 0 && stripeoffset >= stripesize) {
368 gctl_error(req, "stripeoffset is too big.");
371 snprintf(name, sizeof(name), "%s%s", pp->name, G_NOP_SUFFIX);
372 LIST_FOREACH(gp, &mp->geom, geom) {
373 if (strcmp(gp->name, name) == 0) {
374 gctl_error(req, "Provider %s already exists.", name);
378 gp = g_new_geomf(mp, "%s", name);
379 sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
380 sc->sc_offset = offset;
381 sc->sc_explicitsize = explicitsize;
382 sc->sc_stripesize = stripesize;
383 sc->sc_stripeoffset = stripeoffset;
384 if (physpath && strcmp(physpath, G_NOP_PHYSPATH_PASSTHROUGH)) {
385 sc->sc_physpath = strndup(physpath, MAXPATHLEN, M_GEOM);
387 sc->sc_physpath = NULL;
388 sc->sc_error = ioerror;
389 sc->sc_rfailprob = rfailprob;
390 sc->sc_wfailprob = wfailprob;
391 sc->sc_delaymsec = delaymsec;
392 sc->sc_rdelayprob = rdelayprob;
393 sc->sc_wdelayprob = wdelayprob;
402 sc->sc_readbytes = 0;
403 sc->sc_wrotebytes = 0;
404 TAILQ_INIT(&sc->sc_head_delay);
405 mtx_init(&sc->sc_lock, "gnop lock", NULL, MTX_DEF);
408 newpp = g_new_providerf(gp, "%s", gp->name);
409 newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
410 newpp->mediasize = size;
411 newpp->sectorsize = secsize;
412 newpp->stripesize = stripesize;
413 newpp->stripeoffset = stripeoffset;
415 cp = g_new_consumer(gp);
416 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
417 error = g_attach(cp, pp);
419 gctl_error(req, "Cannot attach to provider %s.", pp->name);
423 newpp->flags |= pp->flags & G_PF_ACCEPT_UNMAPPED;
424 g_error_provider(newpp, 0);
425 G_NOP_DEBUG(0, "Device %s created.", gp->name);
428 if (cp->provider != NULL)
430 g_destroy_consumer(cp);
431 g_destroy_provider(newpp);
432 mtx_destroy(&sc->sc_lock);
433 free(sc->sc_physpath, M_GEOM);
440 g_nop_providergone(struct g_provider *pp)
442 struct g_geom *gp = pp->geom;
443 struct g_nop_softc *sc = gp->softc;
445 KASSERT(TAILQ_EMPTY(&sc->sc_head_delay),
446 ("delayed request list is not empty"));
449 free(sc->sc_physpath, M_GEOM);
450 mtx_destroy(&sc->sc_lock);
455 g_nop_destroy(struct g_geom *gp, boolean_t force)
457 struct g_nop_softc *sc;
458 struct g_provider *pp;
464 pp = LIST_FIRST(&gp->provider);
465 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
467 G_NOP_DEBUG(0, "Device %s is still open, so it "
468 "can't be definitely removed.", pp->name);
470 G_NOP_DEBUG(1, "Device %s is still open (r%dw%de%d).",
471 pp->name, pp->acr, pp->acw, pp->ace);
475 G_NOP_DEBUG(0, "Device %s removed.", gp->name);
478 g_wither_geom(gp, ENXIO);
484 g_nop_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
487 return (g_nop_destroy(gp, 0));
491 g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
493 struct g_provider *pp;
494 intmax_t *error, *rfailprob, *wfailprob, *offset, *secsize, *size,
495 *stripesize, *stripeoffset, *delaymsec, *rdelayprob, *wdelayprob;
496 const char *name, *physpath;
502 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
504 gctl_error(req, "No '%s' argument", "nargs");
508 gctl_error(req, "Missing device(s).");
511 error = gctl_get_paraml(req, "error", sizeof(*error));
513 gctl_error(req, "No '%s' argument", "error");
516 rfailprob = gctl_get_paraml(req, "rfailprob", sizeof(*rfailprob));
517 if (rfailprob == NULL) {
518 gctl_error(req, "No '%s' argument", "rfailprob");
521 if (*rfailprob < -1 || *rfailprob > 100) {
522 gctl_error(req, "Invalid '%s' argument", "rfailprob");
525 wfailprob = gctl_get_paraml(req, "wfailprob", sizeof(*wfailprob));
526 if (wfailprob == NULL) {
527 gctl_error(req, "No '%s' argument", "wfailprob");
530 if (*wfailprob < -1 || *wfailprob > 100) {
531 gctl_error(req, "Invalid '%s' argument", "wfailprob");
534 delaymsec = gctl_get_paraml(req, "delaymsec", sizeof(*delaymsec));
535 if (delaymsec == NULL) {
536 gctl_error(req, "No '%s' argument", "delaymsec");
539 if (*delaymsec < 1 && *delaymsec != -1) {
540 gctl_error(req, "Invalid '%s' argument", "delaymsec");
543 rdelayprob = gctl_get_paraml(req, "rdelayprob", sizeof(*rdelayprob));
544 if (rdelayprob == NULL) {
545 gctl_error(req, "No '%s' argument", "rdelayprob");
548 if (*rdelayprob < -1 || *rdelayprob > 100) {
549 gctl_error(req, "Invalid '%s' argument", "rdelayprob");
552 wdelayprob = gctl_get_paraml(req, "wdelayprob", sizeof(*wdelayprob));
553 if (wdelayprob == NULL) {
554 gctl_error(req, "No '%s' argument", "wdelayprob");
557 if (*wdelayprob < -1 || *wdelayprob > 100) {
558 gctl_error(req, "Invalid '%s' argument", "wdelayprob");
561 offset = gctl_get_paraml(req, "offset", sizeof(*offset));
562 if (offset == NULL) {
563 gctl_error(req, "No '%s' argument", "offset");
567 gctl_error(req, "Invalid '%s' argument", "offset");
570 size = gctl_get_paraml(req, "size", sizeof(*size));
572 gctl_error(req, "No '%s' argument", "size");
576 gctl_error(req, "Invalid '%s' argument", "size");
579 secsize = gctl_get_paraml(req, "secsize", sizeof(*secsize));
580 if (secsize == NULL) {
581 gctl_error(req, "No '%s' argument", "secsize");
585 gctl_error(req, "Invalid '%s' argument", "secsize");
588 stripesize = gctl_get_paraml(req, "stripesize", sizeof(*stripesize));
589 if (stripesize == NULL) {
590 gctl_error(req, "No '%s' argument", "stripesize");
593 if (*stripesize < 0) {
594 gctl_error(req, "Invalid '%s' argument", "stripesize");
597 stripeoffset = gctl_get_paraml(req, "stripeoffset", sizeof(*stripeoffset));
598 if (stripeoffset == NULL) {
599 gctl_error(req, "No '%s' argument", "stripeoffset");
602 if (*stripeoffset < 0) {
603 gctl_error(req, "Invalid '%s' argument", "stripeoffset");
606 physpath = gctl_get_asciiparam(req, "physpath");
608 for (i = 0; i < *nargs; i++) {
609 snprintf(param, sizeof(param), "arg%d", i);
610 name = gctl_get_asciiparam(req, param);
612 gctl_error(req, "No 'arg%d' argument", i);
615 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
616 name += strlen("/dev/");
617 pp = g_provider_by_name(name);
619 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
620 gctl_error(req, "Provider %s is invalid.", name);
623 if (g_nop_create(req, mp, pp,
624 *error == -1 ? EIO : (int)*error,
625 *rfailprob == -1 ? 0 : (u_int)*rfailprob,
626 *wfailprob == -1 ? 0 : (u_int)*wfailprob,
627 *delaymsec == -1 ? 1 : (u_int)*delaymsec,
628 *rdelayprob == -1 ? 0 : (u_int)*rdelayprob,
629 *wdelayprob == -1 ? 0 : (u_int)*wdelayprob,
630 (off_t)*offset, (off_t)*size, (u_int)*secsize,
631 (off_t)*stripesize, (off_t)*stripeoffset,
639 g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp)
641 struct g_nop_softc *sc;
642 struct g_provider *pp;
643 intmax_t *delaymsec, *error, *rdelayprob, *rfailprob, *wdelayprob, *wfailprob;
650 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
652 gctl_error(req, "No '%s' argument", "nargs");
656 gctl_error(req, "Missing device(s).");
659 error = gctl_get_paraml(req, "error", sizeof(*error));
661 gctl_error(req, "No '%s' argument", "error");
664 rfailprob = gctl_get_paraml(req, "rfailprob", sizeof(*rfailprob));
665 if (rfailprob == NULL) {
666 gctl_error(req, "No '%s' argument", "rfailprob");
669 if (*rfailprob < -1 || *rfailprob > 100) {
670 gctl_error(req, "Invalid '%s' argument", "rfailprob");
673 wfailprob = gctl_get_paraml(req, "wfailprob", sizeof(*wfailprob));
674 if (wfailprob == NULL) {
675 gctl_error(req, "No '%s' argument", "wfailprob");
678 if (*wfailprob < -1 || *wfailprob > 100) {
679 gctl_error(req, "Invalid '%s' argument", "wfailprob");
683 delaymsec = gctl_get_paraml(req, "delaymsec", sizeof(*delaymsec));
684 if (delaymsec == NULL) {
685 gctl_error(req, "No '%s' argument", "delaymsec");
688 if (*delaymsec < 1 && *delaymsec != -1) {
689 gctl_error(req, "Invalid '%s' argument", "delaymsec");
692 rdelayprob = gctl_get_paraml(req, "rdelayprob", sizeof(*rdelayprob));
693 if (rdelayprob == NULL) {
694 gctl_error(req, "No '%s' argument", "rdelayprob");
697 if (*rdelayprob < -1 || *rdelayprob > 100) {
698 gctl_error(req, "Invalid '%s' argument", "rdelayprob");
701 wdelayprob = gctl_get_paraml(req, "wdelayprob", sizeof(*wdelayprob));
702 if (wdelayprob == NULL) {
703 gctl_error(req, "No '%s' argument", "wdelayprob");
706 if (*wdelayprob < -1 || *wdelayprob > 100) {
707 gctl_error(req, "Invalid '%s' argument", "wdelayprob");
711 for (i = 0; i < *nargs; i++) {
712 snprintf(param, sizeof(param), "arg%d", i);
713 name = gctl_get_asciiparam(req, param);
715 gctl_error(req, "No 'arg%d' argument", i);
718 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
719 name += strlen("/dev/");
720 pp = g_provider_by_name(name);
721 if (pp == NULL || pp->geom->class != mp) {
722 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
723 gctl_error(req, "Provider %s is invalid.", name);
726 sc = pp->geom->softc;
728 sc->sc_error = (int)*error;
729 if (*rfailprob != -1)
730 sc->sc_rfailprob = (u_int)*rfailprob;
731 if (*wfailprob != -1)
732 sc->sc_wfailprob = (u_int)*wfailprob;
733 if (*rdelayprob != -1)
734 sc->sc_rdelayprob = (u_int)*rdelayprob;
735 if (*wdelayprob != -1)
736 sc->sc_wdelayprob = (u_int)*wdelayprob;
737 if (*delaymsec != -1)
738 sc->sc_delaymsec = (u_int)*delaymsec;
742 static struct g_geom *
743 g_nop_find_geom(struct g_class *mp, const char *name)
747 LIST_FOREACH(gp, &mp->geom, geom) {
748 if (strcmp(gp->name, name) == 0)
755 g_nop_ctl_destroy(struct gctl_req *req, struct g_class *mp)
757 int *nargs, *force, error, i;
764 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
766 gctl_error(req, "No '%s' argument", "nargs");
770 gctl_error(req, "Missing device(s).");
773 force = gctl_get_paraml(req, "force", sizeof(*force));
775 gctl_error(req, "No 'force' argument");
779 for (i = 0; i < *nargs; i++) {
780 snprintf(param, sizeof(param), "arg%d", i);
781 name = gctl_get_asciiparam(req, param);
783 gctl_error(req, "No 'arg%d' argument", i);
786 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
787 name += strlen("/dev/");
788 gp = g_nop_find_geom(mp, name);
790 G_NOP_DEBUG(1, "Device %s is invalid.", name);
791 gctl_error(req, "Device %s is invalid.", name);
794 error = g_nop_destroy(gp, *force);
796 gctl_error(req, "Cannot destroy device %s (error=%d).",
804 g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp)
806 struct g_nop_softc *sc;
807 struct g_provider *pp;
814 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
816 gctl_error(req, "No '%s' argument", "nargs");
820 gctl_error(req, "Missing device(s).");
824 for (i = 0; i < *nargs; i++) {
825 snprintf(param, sizeof(param), "arg%d", i);
826 name = gctl_get_asciiparam(req, param);
828 gctl_error(req, "No 'arg%d' argument", i);
831 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
832 name += strlen("/dev/");
833 pp = g_provider_by_name(name);
834 if (pp == NULL || pp->geom->class != mp) {
835 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
836 gctl_error(req, "Provider %s is invalid.", name);
839 sc = pp->geom->softc;
848 sc->sc_readbytes = 0;
849 sc->sc_wrotebytes = 0;
854 g_nop_config(struct gctl_req *req, struct g_class *mp, const char *verb)
860 version = gctl_get_paraml(req, "version", sizeof(*version));
861 if (version == NULL) {
862 gctl_error(req, "No '%s' argument.", "version");
865 if (*version != G_NOP_VERSION) {
866 gctl_error(req, "Userland and kernel parts are out of sync.");
870 if (strcmp(verb, "create") == 0) {
871 g_nop_ctl_create(req, mp);
873 } else if (strcmp(verb, "configure") == 0) {
874 g_nop_ctl_configure(req, mp);
876 } else if (strcmp(verb, "destroy") == 0) {
877 g_nop_ctl_destroy(req, mp);
879 } else if (strcmp(verb, "reset") == 0) {
880 g_nop_ctl_reset(req, mp);
884 gctl_error(req, "Unknown verb.");
888 g_nop_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
889 struct g_consumer *cp, struct g_provider *pp)
891 struct g_nop_softc *sc;
893 if (pp != NULL || cp != NULL)
896 sbuf_printf(sb, "%s<Offset>%jd</Offset>\n", indent,
897 (intmax_t)sc->sc_offset);
898 sbuf_printf(sb, "%s<ReadFailProb>%u</ReadFailProb>\n", indent,
900 sbuf_printf(sb, "%s<WriteFailProb>%u</WriteFailProb>\n", indent,
902 sbuf_printf(sb, "%s<ReadDelayedProb>%u</ReadDelayedProb>\n", indent,
904 sbuf_printf(sb, "%s<WriteDelayedProb>%u</WriteDelayedProb>\n", indent,
906 sbuf_printf(sb, "%s<Delay>%d</Delay>\n", indent, sc->sc_delaymsec);
907 sbuf_printf(sb, "%s<Error>%d</Error>\n", indent, sc->sc_error);
908 sbuf_printf(sb, "%s<Reads>%ju</Reads>\n", indent, sc->sc_reads);
909 sbuf_printf(sb, "%s<Writes>%ju</Writes>\n", indent, sc->sc_writes);
910 sbuf_printf(sb, "%s<Deletes>%ju</Deletes>\n", indent, sc->sc_deletes);
911 sbuf_printf(sb, "%s<Getattrs>%ju</Getattrs>\n", indent, sc->sc_getattrs);
912 sbuf_printf(sb, "%s<Flushes>%ju</Flushes>\n", indent, sc->sc_flushes);
913 sbuf_printf(sb, "%s<Cmd0s>%ju</Cmd0s>\n", indent, sc->sc_cmd0s);
914 sbuf_printf(sb, "%s<Cmd1s>%ju</Cmd1s>\n", indent, sc->sc_cmd1s);
915 sbuf_printf(sb, "%s<Cmd2s>%ju</Cmd2s>\n", indent, sc->sc_cmd2s);
916 sbuf_printf(sb, "%s<ReadBytes>%ju</ReadBytes>\n", indent,
918 sbuf_printf(sb, "%s<WroteBytes>%ju</WroteBytes>\n", indent,
922 DECLARE_GEOM_CLASS(g_nop_class, g_nop);
923 MODULE_VERSION(geom_nop, 0);