Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/nop/g_nop.c
Show First 20 Lines • Show All 538 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
g_nop_ctl_create(struct gctl_req *req, struct g_class *mp) | g_nop_ctl_create(struct gctl_req *req, struct g_class *mp) | ||||
{ | { | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
intmax_t *val, error, rfailprob, wfailprob, count_until_fail, offset, | intmax_t *val, error, rfailprob, wfailprob, count_until_fail, offset, | ||||
secsize, size, stripesize, stripeoffset, delaymsec, | secsize, size, stripesize, stripeoffset, delaymsec, | ||||
rdelayprob, wdelayprob; | rdelayprob, wdelayprob; | ||||
const char *name, *physpath, *gnopname; | const char *physpath, *gnopname; | ||||
char param[16]; | char param[16]; | ||||
int i, *nargs; | int i, *nargs; | ||||
g_topology_assert(); | g_topology_assert(); | ||||
error = -1; | error = -1; | ||||
rfailprob = -1; | rfailprob = -1; | ||||
wfailprob = -1; | wfailprob = -1; | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | if (stripeoffset < 0) { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
physpath = gctl_get_asciiparam(req, "physpath"); | physpath = gctl_get_asciiparam(req, "physpath"); | ||||
gnopname = gctl_get_asciiparam(req, "gnopname"); | gnopname = gctl_get_asciiparam(req, "gnopname"); | ||||
for (i = 0; i < *nargs; i++) { | for (i = 0; i < *nargs; i++) { | ||||
snprintf(param, sizeof(param), "arg%d", i); | snprintf(param, sizeof(param), "arg%d", i); | ||||
name = gctl_get_asciiparam(req, param); | pp = gctl_get_provider(req, param); | ||||
if (name == NULL) { | if (pp == NULL) | ||||
gctl_error(req, "No 'arg%d' argument", i); | |||||
return; | return; | ||||
} | |||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | |||||
name += strlen(_PATH_DEV); | |||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL) { | |||||
G_NOP_DEBUG(1, "Provider %s is invalid.", name); | |||||
gctl_error(req, "Provider %s is invalid.", name); | |||||
return; | |||||
} | |||||
if (g_nop_create(req, mp, pp, | if (g_nop_create(req, mp, pp, | ||||
gnopname, | gnopname, | ||||
error == -1 ? EIO : (int)error, | error == -1 ? EIO : (int)error, | ||||
count_until_fail == -1 ? 0 : (u_int)count_until_fail, | count_until_fail == -1 ? 0 : (u_int)count_until_fail, | ||||
rfailprob == -1 ? 0 : (u_int)rfailprob, | rfailprob == -1 ? 0 : (u_int)rfailprob, | ||||
wfailprob == -1 ? 0 : (u_int)wfailprob, | wfailprob == -1 ? 0 : (u_int)wfailprob, | ||||
delaymsec == -1 ? 1 : (u_int)delaymsec, | delaymsec == -1 ? 1 : (u_int)delaymsec, | ||||
rdelayprob == -1 ? 0 : (u_int)rdelayprob, | rdelayprob == -1 ? 0 : (u_int)rdelayprob, | ||||
wdelayprob == -1 ? 0 : (u_int)wdelayprob, | wdelayprob == -1 ? 0 : (u_int)wdelayprob, | ||||
(off_t)offset, (off_t)size, (u_int)secsize, | (off_t)offset, (off_t)size, (u_int)secsize, | ||||
(off_t)stripesize, (off_t)stripeoffset, | (off_t)stripesize, (off_t)stripeoffset, | ||||
physpath) != 0) { | physpath) != 0) { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp) | g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp) | ||||
{ | { | ||||
struct g_nop_softc *sc; | struct g_nop_softc *sc; | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
intmax_t *val, delaymsec, error, rdelayprob, rfailprob, wdelayprob, | intmax_t *val, delaymsec, error, rdelayprob, rfailprob, wdelayprob, | ||||
wfailprob, count_until_fail; | wfailprob, count_until_fail; | ||||
const char *name; | |||||
char param[16]; | char param[16]; | ||||
int i, *nargs; | int i, *nargs; | ||||
g_topology_assert(); | g_topology_assert(); | ||||
count_until_fail = -1; | count_until_fail = -1; | ||||
delaymsec = -1; | delaymsec = -1; | ||||
error = -1; | error = -1; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | if (val != NULL) { | ||||
if (wdelayprob < -1 || wdelayprob > 100) { | if (wdelayprob < -1 || wdelayprob > 100) { | ||||
gctl_error(req, "Invalid '%s' argument", "wdelayprob"); | gctl_error(req, "Invalid '%s' argument", "wdelayprob"); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
for (i = 0; i < *nargs; i++) { | for (i = 0; i < *nargs; i++) { | ||||
snprintf(param, sizeof(param), "arg%d", i); | snprintf(param, sizeof(param), "arg%d", i); | ||||
name = gctl_get_asciiparam(req, param); | pp = gctl_get_provider(req, param); | ||||
if (name == NULL) { | if (pp == NULL) | ||||
gctl_error(req, "No 'arg%d' argument", i); | |||||
return; | return; | ||||
} | if (pp->geom->class != mp) { | ||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | G_NOP_DEBUG(1, "Provider %s is invalid.", pp->name); | ||||
name += strlen(_PATH_DEV); | gctl_error(req, "Provider %s is invalid.", pp->name); | ||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL || pp->geom->class != mp) { | |||||
G_NOP_DEBUG(1, "Provider %s is invalid.", name); | |||||
gctl_error(req, "Provider %s is invalid.", name); | |||||
return; | return; | ||||
} | } | ||||
sc = pp->geom->softc; | sc = pp->geom->softc; | ||||
if (error != -1) | if (error != -1) | ||||
sc->sc_error = (int)error; | sc->sc_error = (int)error; | ||||
if (rfailprob != -1) | if (rfailprob != -1) | ||||
sc->sc_rfailprob = (u_int)rfailprob; | sc->sc_rfailprob = (u_int)rfailprob; | ||||
if (wfailprob != -1) | if (wfailprob != -1) | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | g_nop_ctl_destroy(struct gctl_req *req, struct g_class *mp) | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp) | g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp) | ||||
{ | { | ||||
struct g_nop_softc *sc; | struct g_nop_softc *sc; | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
const char *name; | |||||
char param[16]; | char param[16]; | ||||
int i, *nargs; | int i, *nargs; | ||||
g_topology_assert(); | g_topology_assert(); | ||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); | nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); | ||||
if (nargs == NULL) { | if (nargs == NULL) { | ||||
gctl_error(req, "No '%s' argument", "nargs"); | gctl_error(req, "No '%s' argument", "nargs"); | ||||
return; | return; | ||||
} | } | ||||
if (*nargs <= 0) { | if (*nargs <= 0) { | ||||
gctl_error(req, "Missing device(s)."); | gctl_error(req, "Missing device(s)."); | ||||
return; | return; | ||||
} | } | ||||
for (i = 0; i < *nargs; i++) { | for (i = 0; i < *nargs; i++) { | ||||
snprintf(param, sizeof(param), "arg%d", i); | snprintf(param, sizeof(param), "arg%d", i); | ||||
name = gctl_get_asciiparam(req, param); | pp = gctl_get_provider(req, param); | ||||
if (name == NULL) { | if (pp == NULL) | ||||
gctl_error(req, "No 'arg%d' argument", i); | |||||
return; | return; | ||||
} | if (pp->geom->class != mp) { | ||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | G_NOP_DEBUG(1, "Provider %s is invalid.", pp->name); | ||||
name += strlen(_PATH_DEV); | gctl_error(req, "Provider %s is invalid.", pp->name); | ||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL || pp->geom->class != mp) { | |||||
G_NOP_DEBUG(1, "Provider %s is invalid.", name); | |||||
gctl_error(req, "Provider %s is invalid.", name); | |||||
return; | return; | ||||
} | } | ||||
sc = pp->geom->softc; | sc = pp->geom->softc; | ||||
sc->sc_reads = 0; | sc->sc_reads = 0; | ||||
sc->sc_writes = 0; | sc->sc_writes = 0; | ||||
sc->sc_deletes = 0; | sc->sc_deletes = 0; | ||||
sc->sc_getattrs = 0; | sc->sc_getattrs = 0; | ||||
sc->sc_flushes = 0; | sc->sc_flushes = 0; | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |