diff options
author | marcel <marcel@FreeBSD.org> | 2006-04-07 16:19:48 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2006-04-07 16:19:48 +0000 |
commit | a5bd277da080a89464e393bfbb625d892e539861 (patch) | |
tree | 1ae38084ee26369df55e59710dde0dc2d083301b /sys | |
parent | aa5c1066ffe09e054adbe29e77187418997d933b (diff) | |
download | FreeBSD-src-a5bd277da080a89464e393bfbb625d892e539861.zip FreeBSD-src-a5bd277da080a89464e393bfbb625d892e539861.tar.gz |
Change gctl_set_param() to return an error instead of setting an
error on the request. Add a wrapper, gctl_set_param_err(), that
sets the error on the request from the error returned by
gctl_set_param() and update current callers of gctl_set_param()
to call gctl_set_param_err() instead.
This makes gctl_set_param() much more usable in situations where
the caller knows better what to do with certain (apparent) error
conditions and setting an error on the request is not one of the
things that need to be done.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/geom/geom.h | 3 | ||||
-rw-r--r-- | sys/geom/geom_bsd.c | 4 | ||||
-rw-r--r-- | sys/geom/geom_ccd.c | 4 | ||||
-rw-r--r-- | sys/geom/geom_ctl.c | 40 |
4 files changed, 34 insertions, 17 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h index d00deb3..7f6bf5a 100644 --- a/sys/geom/geom.h +++ b/sys/geom/geom.h @@ -336,7 +336,8 @@ extern struct sx topology_lock; #endif /* _KERNEL */ /* geom_ctl.c */ -void gctl_set_param(struct gctl_req *req, const char *param, void const *ptr, int len); +int gctl_set_param(struct gctl_req *req, const char *param, void const *ptr, int len); +void gctl_set_param_err(struct gctl_req *req, const char *param, void const *ptr, int len); void *gctl_get_param(struct gctl_req *req, const char *param, int *len); char const *gctl_get_asciiparam(struct gctl_req *req, const char *param); void *gctl_get_paraml(struct gctl_req *req, const char *param, int len); diff --git a/sys/geom/geom_bsd.c b/sys/geom/geom_bsd.c index b7402cf..7d5b5d1 100644 --- a/sys/geom/geom_bsd.c +++ b/sys/geom/geom_bsd.c @@ -635,8 +635,8 @@ g_bsd_config(struct gctl_req *req, struct g_class *mp, char const *verb) gsp = gp->softc; ms = gsp->softc; if (!strcmp(verb, "read mbroffset")) { - gctl_set_param(req, "mbroffset", - &ms->mbroffset, sizeof(ms->mbroffset)); + gctl_set_param_err(req, "mbroffset", &ms->mbroffset, + sizeof(ms->mbroffset)); return; } else if (!strcmp(verb, "write label")) { label = gctl_get_paraml(req, "label", LABELSIZE); diff --git a/sys/geom/geom_ccd.c b/sys/geom/geom_ccd.c index bfa125d..fb66882 100644 --- a/sys/geom/geom_ccd.c +++ b/sys/geom/geom_ccd.c @@ -782,7 +782,7 @@ g_ccd_create(struct gctl_req *req, struct g_class *mp) else sbuf_printf(sb, "concatenated\n"); sbuf_finish(sb); - gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); + gctl_set_param_err(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); sbuf_delete(sb); } @@ -833,7 +833,7 @@ g_ccd_list(struct gctl_req *req, struct g_class *mp) sbuf_printf(sb, "\n"); } sbuf_finish(sb); - gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); + gctl_set_param_err(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); sbuf_delete(sb); } diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c index 8186bc7..9c183b1 100644 --- a/sys/geom/geom_ctl.c +++ b/sys/geom/geom_ctl.c @@ -268,8 +268,9 @@ gctl_dump(struct gctl_req *req) } } -void -gctl_set_param(struct gctl_req *req, const char *param, void const *ptr, int len) +int +gctl_set_param(struct gctl_req *req, const char *param, void const *ptr, + int len) { int i; struct gctl_req_arg *ap; @@ -278,20 +279,35 @@ gctl_set_param(struct gctl_req *req, const char *param, void const *ptr, int len ap = &req->arg[i]; if (strcmp(param, ap->name)) continue; - if (!(ap->flag & GCTL_PARAM_WR)) { - gctl_error(req, "No write access %s argument", param); - return; - } + if (!(ap->flag & GCTL_PARAM_WR)) + return (EPERM); + ap->flag |= GCTL_PARAM_CHANGED; if (ap->len < len) { - gctl_error(req, "Wrong length %s argument", param); - return; + bcopy(ptr, ap->kvalue, ap->len); + return (ENOSPC); } bcopy(ptr, ap->kvalue, len); - ap->flag |= GCTL_PARAM_CHANGED; - return; + return (0); + } + return (EINVAL); +} + +void +gctl_set_param_err(struct gctl_req *req, const char *param, void const *ptr, + int len) +{ + + switch (gctl_set_param(req, param, ptr, len)) { + case EPERM: + gctl_error(req, "No write access %s argument", param); + break; + case ENOSPC: + gctl_error(req, "Wrong length %s argument", param); + break; + case EINVAL: + gctl_error(req, "Missing %s argument", param); + break; } - gctl_error(req, "Missing %s argument", param); - return; } void * |