mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 01:38:57 +00:00
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.
This commit is contained in:
parent
cb94ab3088
commit
41063f9380
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=157581
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 *
|
||||
|
Loading…
Reference in New Issue
Block a user