summaryrefslogtreecommitdiffstats
path: root/sys/geom/geom_ctl.c
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2006-04-07 16:19:48 +0000
committermarcel <marcel@FreeBSD.org>2006-04-07 16:19:48 +0000
commita5bd277da080a89464e393bfbb625d892e539861 (patch)
tree1ae38084ee26369df55e59710dde0dc2d083301b /sys/geom/geom_ctl.c
parentaa5c1066ffe09e054adbe29e77187418997d933b (diff)
downloadFreeBSD-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/geom/geom_ctl.c')
-rw-r--r--sys/geom/geom_ctl.c40
1 files changed, 28 insertions, 12 deletions
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 *
OpenPOWER on IntegriCloud