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 if (sc->sc_count_until_fail != 0 && --sc->sc_count_until_fail == 0) {
199 sc->sc_rfailprob = 100;
200 sc->sc_wfailprob = 100;
202 switch (bp->bio_cmd) {
205 sc->sc_readbytes += bp->bio_length;
206 failprob = sc->sc_rfailprob;
207 delayprob = sc->sc_rdelayprob;
208 delaytime = sc->sc_delaymsec;
212 sc->sc_wrotebytes += bp->bio_length;
213 failprob = sc->sc_wfailprob;
214 delayprob = sc->sc_wdelayprob;
215 delaytime = sc->sc_delaymsec;
222 if (sc->sc_physpath &&
223 g_handleattr_str(bp, "GEOM::physpath", sc->sc_physpath))
225 else if (strcmp(bp->bio_attribute, "GEOM::kerneldump") == 0)
226 g_nop_kerneldump(bp, sc);
229 * Fallthrough to forwarding the GETATTR down to the
230 * lower level device.
233 mtx_unlock(&sc->sc_lock);
248 mtx_unlock(&sc->sc_lock);
252 rval = arc4random() % 100;
253 if (rval < failprob) {
254 G_NOP_LOGREQLVL(1, bp, "Returning error=%d.", sc->sc_error);
255 g_io_deliver(bp, sc->sc_error);
260 cbp = g_clone_bio(bp);
262 g_io_deliver(bp, ENOMEM);
265 cbp->bio_done = g_std_done;
266 cbp->bio_offset = bp->bio_offset + sc->sc_offset;
267 pp = LIST_FIRST(&gp->provider);
268 KASSERT(pp != NULL, ("NULL pp"));
272 struct g_nop_delay *gndelay;
275 rval = arc4random() % 100;
276 if (rval < delayprob) {
277 gndelay = g_malloc(sizeof(*gndelay), M_NOWAIT | M_ZERO);
278 if (gndelay != NULL) {
279 callout_init(&gndelay->dl_cal, 1);
281 gndelay->dl_bio = cbp;
283 mtx_lock(&sc->sc_lock);
284 TAILQ_INSERT_TAIL(&sc->sc_head_delay, gndelay,
286 mtx_unlock(&sc->sc_lock);
288 callout_reset(&gndelay->dl_cal,
289 MSEC_2_TICKS(delaytime), g_nop_pass_timeout,
300 g_nop_access(struct g_provider *pp, int dr, int dw, int de)
303 struct g_consumer *cp;
307 cp = LIST_FIRST(&gp->consumer);
308 error = g_access(cp, dr, dw, de);
314 g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
315 int ioerror, u_int count_until_fail, u_int rfailprob, u_int wfailprob,
316 u_int delaymsec, u_int rdelayprob, u_int wdelayprob, off_t offset,
317 off_t size, u_int secsize, off_t stripesize, off_t stripeoffset,
318 const char *physpath)
320 struct g_nop_softc *sc;
322 struct g_provider *newpp;
323 struct g_consumer *cp;
334 if ((offset % pp->sectorsize) != 0) {
335 gctl_error(req, "Invalid offset for provider %s.", pp->name);
338 if ((size % pp->sectorsize) != 0) {
339 gctl_error(req, "Invalid size for provider %s.", pp->name);
342 if (offset >= pp->mediasize) {
343 gctl_error(req, "Invalid offset for provider %s.", pp->name);
348 size = pp->mediasize - offset;
349 if (offset + size > pp->mediasize) {
350 gctl_error(req, "Invalid size for provider %s.", pp->name);
354 secsize = pp->sectorsize;
355 else if ((secsize % pp->sectorsize) != 0) {
356 gctl_error(req, "Invalid secsize for provider %s.", pp->name);
359 if (secsize > MAXPHYS) {
360 gctl_error(req, "secsize is too big.");
363 size -= size % secsize;
364 if ((stripesize % pp->sectorsize) != 0) {
365 gctl_error(req, "Invalid stripesize for provider %s.", pp->name);
368 if ((stripeoffset % pp->sectorsize) != 0) {
369 gctl_error(req, "Invalid stripeoffset for provider %s.", pp->name);
372 if (stripesize != 0 && stripeoffset >= stripesize) {
373 gctl_error(req, "stripeoffset is too big.");
376 snprintf(name, sizeof(name), "%s%s", pp->name, G_NOP_SUFFIX);
377 LIST_FOREACH(gp, &mp->geom, geom) {
378 if (strcmp(gp->name, name) == 0) {
379 gctl_error(req, "Provider %s already exists.", name);
383 gp = g_new_geomf(mp, "%s", name);
384 sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
385 sc->sc_offset = offset;
386 sc->sc_explicitsize = explicitsize;
387 sc->sc_stripesize = stripesize;
388 sc->sc_stripeoffset = stripeoffset;
389 if (physpath && strcmp(physpath, G_NOP_PHYSPATH_PASSTHROUGH)) {
390 sc->sc_physpath = strndup(physpath, MAXPATHLEN, M_GEOM);
392 sc->sc_physpath = NULL;
393 sc->sc_error = ioerror;
394 sc->sc_count_until_fail = count_until_fail;
395 sc->sc_rfailprob = rfailprob;
396 sc->sc_wfailprob = wfailprob;
397 sc->sc_delaymsec = delaymsec;
398 sc->sc_rdelayprob = rdelayprob;
399 sc->sc_wdelayprob = wdelayprob;
408 sc->sc_readbytes = 0;
409 sc->sc_wrotebytes = 0;
410 TAILQ_INIT(&sc->sc_head_delay);
411 mtx_init(&sc->sc_lock, "gnop lock", NULL, MTX_DEF);
414 newpp = g_new_providerf(gp, "%s", gp->name);
415 newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
416 newpp->mediasize = size;
417 newpp->sectorsize = secsize;
418 newpp->stripesize = stripesize;
419 newpp->stripeoffset = stripeoffset;
421 cp = g_new_consumer(gp);
422 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
423 error = g_attach(cp, pp);
425 gctl_error(req, "Cannot attach to provider %s.", pp->name);
429 newpp->flags |= pp->flags & G_PF_ACCEPT_UNMAPPED;
430 g_error_provider(newpp, 0);
431 G_NOP_DEBUG(0, "Device %s created.", gp->name);
434 if (cp->provider != NULL)
436 g_destroy_consumer(cp);
437 g_destroy_provider(newpp);
438 mtx_destroy(&sc->sc_lock);
439 free(sc->sc_physpath, M_GEOM);
446 g_nop_providergone(struct g_provider *pp)
448 struct g_geom *gp = pp->geom;
449 struct g_nop_softc *sc = gp->softc;
451 KASSERT(TAILQ_EMPTY(&sc->sc_head_delay),
452 ("delayed request list is not empty"));
455 free(sc->sc_physpath, M_GEOM);
456 mtx_destroy(&sc->sc_lock);
461 g_nop_destroy(struct g_geom *gp, boolean_t force)
463 struct g_nop_softc *sc;
464 struct g_provider *pp;
470 pp = LIST_FIRST(&gp->provider);
471 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
473 G_NOP_DEBUG(0, "Device %s is still open, so it "
474 "can't be definitely removed.", pp->name);
476 G_NOP_DEBUG(1, "Device %s is still open (r%dw%de%d).",
477 pp->name, pp->acr, pp->acw, pp->ace);
481 G_NOP_DEBUG(0, "Device %s removed.", gp->name);
484 g_wither_geom(gp, ENXIO);
490 g_nop_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
493 return (g_nop_destroy(gp, 0));
497 g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
499 struct g_provider *pp;
500 intmax_t *error, *rfailprob, *wfailprob, *count_until_fail, *offset,
501 *secsize, *size, *stripesize, *stripeoffset, *delaymsec,
502 *rdelayprob, *wdelayprob;
503 const char *name, *physpath;
509 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
511 gctl_error(req, "No '%s' argument", "nargs");
515 gctl_error(req, "Missing device(s).");
518 error = gctl_get_paraml(req, "error", sizeof(*error));
520 gctl_error(req, "No '%s' argument", "error");
523 rfailprob = gctl_get_paraml(req, "rfailprob", sizeof(*rfailprob));
524 if (rfailprob == NULL) {
525 gctl_error(req, "No '%s' argument", "rfailprob");
528 if (*rfailprob < -1 || *rfailprob > 100) {
529 gctl_error(req, "Invalid '%s' argument", "rfailprob");
532 wfailprob = gctl_get_paraml(req, "wfailprob", sizeof(*wfailprob));
533 if (wfailprob == NULL) {
534 gctl_error(req, "No '%s' argument", "wfailprob");
537 if (*wfailprob < -1 || *wfailprob > 100) {
538 gctl_error(req, "Invalid '%s' argument", "wfailprob");
541 delaymsec = gctl_get_paraml(req, "delaymsec", sizeof(*delaymsec));
542 if (delaymsec == NULL) {
543 gctl_error(req, "No '%s' argument", "delaymsec");
546 if (*delaymsec < 1 && *delaymsec != -1) {
547 gctl_error(req, "Invalid '%s' argument", "delaymsec");
550 rdelayprob = gctl_get_paraml(req, "rdelayprob", sizeof(*rdelayprob));
551 if (rdelayprob == NULL) {
552 gctl_error(req, "No '%s' argument", "rdelayprob");
555 if (*rdelayprob < -1 || *rdelayprob > 100) {
556 gctl_error(req, "Invalid '%s' argument", "rdelayprob");
559 wdelayprob = gctl_get_paraml(req, "wdelayprob", sizeof(*wdelayprob));
560 if (wdelayprob == NULL) {
561 gctl_error(req, "No '%s' argument", "wdelayprob");
564 if (*wdelayprob < -1 || *wdelayprob > 100) {
565 gctl_error(req, "Invalid '%s' argument", "wdelayprob");
568 count_until_fail = gctl_get_paraml(req, "count_until_fail",
569 sizeof(*count_until_fail));
570 if (count_until_fail == NULL) {
571 gctl_error(req, "No '%s' argument", "count_until_fail");
574 if (*count_until_fail < -1) {
575 gctl_error(req, "Invalid '%s' argument", "count_until_fail");
578 offset = gctl_get_paraml(req, "offset", sizeof(*offset));
579 if (offset == NULL) {
580 gctl_error(req, "No '%s' argument", "offset");
584 gctl_error(req, "Invalid '%s' argument", "offset");
587 size = gctl_get_paraml(req, "size", sizeof(*size));
589 gctl_error(req, "No '%s' argument", "size");
593 gctl_error(req, "Invalid '%s' argument", "size");
596 secsize = gctl_get_paraml(req, "secsize", sizeof(*secsize));
597 if (secsize == NULL) {
598 gctl_error(req, "No '%s' argument", "secsize");
602 gctl_error(req, "Invalid '%s' argument", "secsize");
605 stripesize = gctl_get_paraml(req, "stripesize", sizeof(*stripesize));
606 if (stripesize == NULL) {
607 gctl_error(req, "No '%s' argument", "stripesize");
610 if (*stripesize < 0) {
611 gctl_error(req, "Invalid '%s' argument", "stripesize");
614 stripeoffset = gctl_get_paraml(req, "stripeoffset", sizeof(*stripeoffset));
615 if (stripeoffset == NULL) {
616 gctl_error(req, "No '%s' argument", "stripeoffset");
619 if (*stripeoffset < 0) {
620 gctl_error(req, "Invalid '%s' argument", "stripeoffset");
623 physpath = gctl_get_asciiparam(req, "physpath");
625 for (i = 0; i < *nargs; i++) {
626 snprintf(param, sizeof(param), "arg%d", i);
627 name = gctl_get_asciiparam(req, param);
629 gctl_error(req, "No 'arg%d' argument", i);
632 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
633 name += strlen("/dev/");
634 pp = g_provider_by_name(name);
636 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
637 gctl_error(req, "Provider %s is invalid.", name);
640 if (g_nop_create(req, mp, pp,
641 *error == -1 ? EIO : (int)*error,
642 *count_until_fail == -1 ? 0 : (u_int)*count_until_fail,
643 *rfailprob == -1 ? 0 : (u_int)*rfailprob,
644 *wfailprob == -1 ? 0 : (u_int)*wfailprob,
645 *delaymsec == -1 ? 1 : (u_int)*delaymsec,
646 *rdelayprob == -1 ? 0 : (u_int)*rdelayprob,
647 *wdelayprob == -1 ? 0 : (u_int)*wdelayprob,
648 (off_t)*offset, (off_t)*size, (u_int)*secsize,
649 (off_t)*stripesize, (off_t)*stripeoffset,
657 g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp)
659 struct g_nop_softc *sc;
660 struct g_provider *pp;
661 intmax_t *delaymsec, *error, *rdelayprob, *rfailprob, *wdelayprob,
662 *wfailprob, *count_until_fail;
669 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
671 gctl_error(req, "No '%s' argument", "nargs");
675 gctl_error(req, "Missing device(s).");
678 error = gctl_get_paraml(req, "error", sizeof(*error));
680 gctl_error(req, "No '%s' argument", "error");
683 count_until_fail = gctl_get_paraml(req, "count_until_fail",
684 sizeof(*count_until_fail));
685 if (count_until_fail == NULL) {
686 gctl_error(req, "No '%s' argument", "count_until_fail");
689 rfailprob = gctl_get_paraml(req, "rfailprob", sizeof(*rfailprob));
690 if (rfailprob == NULL) {
691 gctl_error(req, "No '%s' argument", "rfailprob");
694 if (*rfailprob < -1 || *rfailprob > 100) {
695 gctl_error(req, "Invalid '%s' argument", "rfailprob");
698 wfailprob = gctl_get_paraml(req, "wfailprob", sizeof(*wfailprob));
699 if (wfailprob == NULL) {
700 gctl_error(req, "No '%s' argument", "wfailprob");
703 if (*wfailprob < -1 || *wfailprob > 100) {
704 gctl_error(req, "Invalid '%s' argument", "wfailprob");
708 delaymsec = gctl_get_paraml(req, "delaymsec", sizeof(*delaymsec));
709 if (delaymsec == NULL) {
710 gctl_error(req, "No '%s' argument", "delaymsec");
713 if (*delaymsec < 1 && *delaymsec != -1) {
714 gctl_error(req, "Invalid '%s' argument", "delaymsec");
717 rdelayprob = gctl_get_paraml(req, "rdelayprob", sizeof(*rdelayprob));
718 if (rdelayprob == NULL) {
719 gctl_error(req, "No '%s' argument", "rdelayprob");
722 if (*rdelayprob < -1 || *rdelayprob > 100) {
723 gctl_error(req, "Invalid '%s' argument", "rdelayprob");
726 wdelayprob = gctl_get_paraml(req, "wdelayprob", sizeof(*wdelayprob));
727 if (wdelayprob == NULL) {
728 gctl_error(req, "No '%s' argument", "wdelayprob");
731 if (*wdelayprob < -1 || *wdelayprob > 100) {
732 gctl_error(req, "Invalid '%s' argument", "wdelayprob");
736 for (i = 0; i < *nargs; i++) {
737 snprintf(param, sizeof(param), "arg%d", i);
738 name = gctl_get_asciiparam(req, param);
740 gctl_error(req, "No 'arg%d' argument", i);
743 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
744 name += strlen("/dev/");
745 pp = g_provider_by_name(name);
746 if (pp == NULL || pp->geom->class != mp) {
747 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
748 gctl_error(req, "Provider %s is invalid.", name);
751 sc = pp->geom->softc;
753 sc->sc_error = (int)*error;
754 if (*rfailprob != -1)
755 sc->sc_rfailprob = (u_int)*rfailprob;
756 if (*wfailprob != -1)
757 sc->sc_wfailprob = (u_int)*wfailprob;
758 if (*rdelayprob != -1)
759 sc->sc_rdelayprob = (u_int)*rdelayprob;
760 if (*wdelayprob != -1)
761 sc->sc_wdelayprob = (u_int)*wdelayprob;
762 if (*delaymsec != -1)
763 sc->sc_delaymsec = (u_int)*delaymsec;
764 if (*count_until_fail != -1)
765 sc->sc_count_until_fail = (u_int)*count_until_fail;
769 static struct g_geom *
770 g_nop_find_geom(struct g_class *mp, const char *name)
774 LIST_FOREACH(gp, &mp->geom, geom) {
775 if (strcmp(gp->name, name) == 0)
782 g_nop_ctl_destroy(struct gctl_req *req, struct g_class *mp)
784 int *nargs, *force, error, i;
791 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
793 gctl_error(req, "No '%s' argument", "nargs");
797 gctl_error(req, "Missing device(s).");
800 force = gctl_get_paraml(req, "force", sizeof(*force));
802 gctl_error(req, "No 'force' argument");
806 for (i = 0; i < *nargs; i++) {
807 snprintf(param, sizeof(param), "arg%d", i);
808 name = gctl_get_asciiparam(req, param);
810 gctl_error(req, "No 'arg%d' argument", i);
813 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
814 name += strlen("/dev/");
815 gp = g_nop_find_geom(mp, name);
817 G_NOP_DEBUG(1, "Device %s is invalid.", name);
818 gctl_error(req, "Device %s is invalid.", name);
821 error = g_nop_destroy(gp, *force);
823 gctl_error(req, "Cannot destroy device %s (error=%d).",
831 g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp)
833 struct g_nop_softc *sc;
834 struct g_provider *pp;
841 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
843 gctl_error(req, "No '%s' argument", "nargs");
847 gctl_error(req, "Missing device(s).");
851 for (i = 0; i < *nargs; i++) {
852 snprintf(param, sizeof(param), "arg%d", i);
853 name = gctl_get_asciiparam(req, param);
855 gctl_error(req, "No 'arg%d' argument", i);
858 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
859 name += strlen("/dev/");
860 pp = g_provider_by_name(name);
861 if (pp == NULL || pp->geom->class != mp) {
862 G_NOP_DEBUG(1, "Provider %s is invalid.", name);
863 gctl_error(req, "Provider %s is invalid.", name);
866 sc = pp->geom->softc;
875 sc->sc_readbytes = 0;
876 sc->sc_wrotebytes = 0;
881 g_nop_config(struct gctl_req *req, struct g_class *mp, const char *verb)
887 version = gctl_get_paraml(req, "version", sizeof(*version));
888 if (version == NULL) {
889 gctl_error(req, "No '%s' argument.", "version");
892 if (*version != G_NOP_VERSION) {
893 gctl_error(req, "Userland and kernel parts are out of sync.");
897 if (strcmp(verb, "create") == 0) {
898 g_nop_ctl_create(req, mp);
900 } else if (strcmp(verb, "configure") == 0) {
901 g_nop_ctl_configure(req, mp);
903 } else if (strcmp(verb, "destroy") == 0) {
904 g_nop_ctl_destroy(req, mp);
906 } else if (strcmp(verb, "reset") == 0) {
907 g_nop_ctl_reset(req, mp);
911 gctl_error(req, "Unknown verb.");
915 g_nop_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
916 struct g_consumer *cp, struct g_provider *pp)
918 struct g_nop_softc *sc;
920 if (pp != NULL || cp != NULL)
923 sbuf_printf(sb, "%s<Offset>%jd</Offset>\n", indent,
924 (intmax_t)sc->sc_offset);
925 sbuf_printf(sb, "%s<ReadFailProb>%u</ReadFailProb>\n", indent,
927 sbuf_printf(sb, "%s<WriteFailProb>%u</WriteFailProb>\n", indent,
929 sbuf_printf(sb, "%s<ReadDelayedProb>%u</ReadDelayedProb>\n", indent,
931 sbuf_printf(sb, "%s<WriteDelayedProb>%u</WriteDelayedProb>\n", indent,
933 sbuf_printf(sb, "%s<Delay>%d</Delay>\n", indent, sc->sc_delaymsec);
934 sbuf_printf(sb, "%s<CountUntilFail>%u</CountUntilFail>\n", indent,
935 sc->sc_count_until_fail);
936 sbuf_printf(sb, "%s<Error>%d</Error>\n", indent, sc->sc_error);
937 sbuf_printf(sb, "%s<Reads>%ju</Reads>\n", indent, sc->sc_reads);
938 sbuf_printf(sb, "%s<Writes>%ju</Writes>\n", indent, sc->sc_writes);
939 sbuf_printf(sb, "%s<Deletes>%ju</Deletes>\n", indent, sc->sc_deletes);
940 sbuf_printf(sb, "%s<Getattrs>%ju</Getattrs>\n", indent, sc->sc_getattrs);
941 sbuf_printf(sb, "%s<Flushes>%ju</Flushes>\n", indent, sc->sc_flushes);
942 sbuf_printf(sb, "%s<Cmd0s>%ju</Cmd0s>\n", indent, sc->sc_cmd0s);
943 sbuf_printf(sb, "%s<Cmd1s>%ju</Cmd1s>\n", indent, sc->sc_cmd1s);
944 sbuf_printf(sb, "%s<Cmd2s>%ju</Cmd2s>\n", indent, sc->sc_cmd2s);
945 sbuf_printf(sb, "%s<ReadBytes>%ju</ReadBytes>\n", indent,
947 sbuf_printf(sb, "%s<WroteBytes>%ju</WroteBytes>\n", indent,
951 DECLARE_GEOM_CLASS(g_nop_class, g_nop);
952 MODULE_VERSION(geom_nop, 0);