GEOM: Introduce gctl_add_param() API.

Make gctl_add_param() API public, allowing more precise control over
parameter flags.  Previously it was impossible to properly declare
write-only ASCII parameters, used for result reporting, they were
declared as read-write binary instead, that was not nice.

MFC after:	1 month
This commit is contained in:
Alexander Motin 2022-03-07 11:06:11 -05:00
parent 01b9c48b5d
commit 2117cdd4b4
7 changed files with 33 additions and 16 deletions

View file

@ -1327,8 +1327,9 @@ gpart_issue(struct gctl_req *req, unsigned int fl __unused)
goto done; goto done;
} }
bzero(buf, sizeof(buf)); buf[0] = '\0';
gctl_rw_param(req, "output", sizeof(buf), buf); gctl_add_param(req, "output", sizeof(buf), buf,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(req); errstr = gctl_issue(req);
if (errstr == NULL || errstr[0] == '\0') { if (errstr == NULL || errstr[0] == '\0') {
if (buf[0] != '\0') if (buf[0] != '\0')

View file

@ -151,8 +151,8 @@ gctl_new_arg(struct gctl_req *req)
return (ap); return (ap);
} }
static void void
gctl_param_add(struct gctl_req *req, const char *name, int len, void *value, gctl_add_param(struct gctl_req *req, const char *name, int len, void *value,
int flag) int flag)
{ {
struct gctl_req_arg *ap; struct gctl_req_arg *ap;
@ -181,14 +181,14 @@ void
gctl_ro_param(struct gctl_req *req, const char *name, int len, const void* value) gctl_ro_param(struct gctl_req *req, const char *name, int len, const void* value)
{ {
gctl_param_add(req, name, len, __DECONST(void *, value), GCTL_PARAM_RD); gctl_add_param(req, name, len, __DECONST(void *, value), GCTL_PARAM_RD);
} }
void void
gctl_rw_param(struct gctl_req *req, const char *name, int len, void *value) gctl_rw_param(struct gctl_req *req, const char *name, int len, void *value)
{ {
gctl_param_add(req, name, len, value, GCTL_PARAM_RW); gctl_add_param(req, name, len, value, GCTL_PARAM_RW);
} }
const char * const char *

View file

@ -149,6 +149,8 @@ void gctl_dump(struct gctl_req *, FILE *);
void gctl_free(struct gctl_req *); void gctl_free(struct gctl_req *);
struct gctl_req *gctl_get_handle(void); struct gctl_req *gctl_get_handle(void);
const char *gctl_issue(struct gctl_req *); const char *gctl_issue(struct gctl_req *);
void gctl_add_param(struct gctl_req *req, const char *name, int len,
void *value, int flag);
void gctl_ro_param(struct gctl_req *, const char *, int, const void *); void gctl_ro_param(struct gctl_req *, const char *, int, const void *);
void gctl_rw_param(struct gctl_req *, const char *, int, void *); void gctl_rw_param(struct gctl_req *, const char *, int, void *);

View file

@ -263,7 +263,9 @@ do_single(int argc, char **argv, int action)
cp += strlen(_PATH_DEV); cp += strlen(_PATH_DEV);
gctl_ro_param(grq, buf1, -1, cp); gctl_ro_param(grq, buf1, -1, cp);
} }
gctl_rw_param(grq, "output", sizeof(buf1), buf1); buf1[0] = '\0';
gctl_add_param(grq, "output", sizeof(buf1), buf1,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(grq); errstr = gctl_issue(grq);
if (errstr == NULL) { if (errstr == NULL) {
if (verbose) { if (verbose) {
@ -371,10 +373,12 @@ dumpout(int unit)
grq = gctl_get_handle(); grq = gctl_get_handle();
ncp = 65536; ncp = 65536;
cp = malloc(ncp); cp = malloc(ncp);
cp[0] = '\0';
gctl_ro_param(grq, "verb", -1, "list"); gctl_ro_param(grq, "verb", -1, "list");
gctl_ro_param(grq, "class", -1, "CCD"); gctl_ro_param(grq, "class", -1, "CCD");
gctl_ro_param(grq, "unit", sizeof(unit), &unit); gctl_ro_param(grq, "unit", sizeof(unit), &unit);
gctl_rw_param(grq, "output", ncp, cp); gctl_add_param(grq, "output", ncp, cp,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(grq); errstr = gctl_issue(grq);
if (errstr != NULL) if (errstr != NULL)
errx(1, "%s\nor possibly kernel and ccdconfig out of sync", errx(1, "%s\nor possibly kernel and ccdconfig out of sync",

View file

@ -487,7 +487,7 @@ run_command(int argc, char *argv[])
gctl_ro_param(req, "version", sizeof(*version), version); gctl_ro_param(req, "version", sizeof(*version), version);
parse_arguments(cmd, req, &argc, &argv); parse_arguments(cmd, req, &argc, &argv);
bzero(buf, sizeof(buf)); buf[0] = '\0';
if (cmd->gc_func != NULL) { if (cmd->gc_func != NULL) {
unsigned flags; unsigned flags;
@ -495,7 +495,8 @@ run_command(int argc, char *argv[])
cmd->gc_func(req, flags); cmd->gc_func(req, flags);
errstr = req->error; errstr = req->error;
} else { } else {
gctl_rw_param(req, "output", sizeof(buf), buf); gctl_add_param(req, "output", sizeof(buf), buf,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(req); errstr = gctl_issue(req);
} }
if (errstr != NULL && errstr[0] != '\0') { if (errstr != NULL && errstr[0] != '\0') {

View file

@ -575,13 +575,15 @@ find_name(const char *prefix, int type, int namelen)
char line[1024]; char line[1024];
comment[0] = '\0'; comment[0] = '\0';
buf[0] = '\0';
/* Find a name. Fetch out configuration first. */ /* Find a name. Fetch out configuration first. */
req = gctl_get_handle(); req = gctl_get_handle();
gctl_ro_param(req, "class", -1, "VINUM"); gctl_ro_param(req, "class", -1, "VINUM");
gctl_ro_param(req, "verb", -1, "getconfig"); gctl_ro_param(req, "verb", -1, "getconfig");
gctl_ro_param(req, "comment", -1, comment); gctl_ro_param(req, "comment", -1, comment);
gctl_rw_param(req, "config", sizeof(buf), buf); gctl_add_param(req, "config", sizeof(buf), buf,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(req); errstr = gctl_issue(req);
if (errstr != NULL) { if (errstr != NULL) {
warnx("can't get configuration: %s", errstr); warnx("can't get configuration: %s", errstr);
@ -841,13 +843,16 @@ gvinum_list(int argc, char * const *argv)
} }
config[0] = '\0';
req = gctl_get_handle(); req = gctl_get_handle();
gctl_ro_param(req, "class", -1, "VINUM"); gctl_ro_param(req, "class", -1, "VINUM");
gctl_ro_param(req, "verb", -1, "list"); gctl_ro_param(req, "verb", -1, "list");
gctl_ro_param(req, "cmd", -1, cmd); gctl_ro_param(req, "cmd", -1, cmd);
gctl_ro_param(req, "argc", sizeof(int), &argc); gctl_ro_param(req, "argc", sizeof(int), &argc);
gctl_ro_param(req, "flags", sizeof(int), &flags); gctl_ro_param(req, "flags", sizeof(int), &flags);
gctl_rw_param(req, "config", sizeof(config), config); gctl_add_param(req, "config", sizeof(config), config,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
if (argc) { if (argc) {
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
snprintf(buf, sizeof(buf), "argv%d", i); snprintf(buf, sizeof(buf), "argv%d", i);
@ -1418,15 +1423,17 @@ printconfig(FILE *of, const char *comment)
const char *errstr; const char *errstr;
time_t now; time_t now;
char buf[GV_CFG_LEN + 1]; char buf[GV_CFG_LEN + 1];
uname(&uname_s); uname(&uname_s);
time(&now); time(&now);
buf[0] = '\0';
req = gctl_get_handle(); req = gctl_get_handle();
gctl_ro_param(req, "class", -1, "VINUM"); gctl_ro_param(req, "class", -1, "VINUM");
gctl_ro_param(req, "verb", -1, "getconfig"); gctl_ro_param(req, "verb", -1, "getconfig");
gctl_ro_param(req, "comment", -1, comment); gctl_ro_param(req, "comment", -1, comment);
gctl_rw_param(req, "config", sizeof(buf), buf); gctl_add_param(req, "config", sizeof(buf), buf,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(req); errstr = gctl_issue(req);
if (errstr != NULL) { if (errstr != NULL) {
warnx("can't get configuration: %s", errstr); warnx("can't get configuration: %s", errstr);

View file

@ -1207,12 +1207,13 @@ gpart_create(struct gprovider *pp, const char *default_type,
} }
} }
output[0] = '\0';
r = gctl_get_handle(); r = gctl_get_handle();
gctl_ro_param(r, "class", -1, "PART"); gctl_ro_param(r, "class", -1, "PART");
gctl_ro_param(r, "arg0", -1, geom->lg_name); gctl_ro_param(r, "arg0", -1, geom->lg_name);
gctl_ro_param(r, "flags", -1, GPART_FLAGS); gctl_ro_param(r, "flags", -1, GPART_FLAGS);
gctl_ro_param(r, "verb", -1, "add"); gctl_ro_param(r, "verb", -1, "add");
gctl_ro_param(r, "type", -1, items[0].text); gctl_ro_param(r, "type", -1, items[0].text);
snprintf(sizestr, sizeof(sizestr), "%jd", size); snprintf(sizestr, sizeof(sizestr), "%jd", size);
gctl_ro_param(r, "size", -1, sizestr); gctl_ro_param(r, "size", -1, sizestr);
@ -1220,7 +1221,8 @@ gpart_create(struct gprovider *pp, const char *default_type,
gctl_ro_param(r, "start", -1, startstr); gctl_ro_param(r, "start", -1, startstr);
if (items[3].text[0] != '\0') if (items[3].text[0] != '\0')
gctl_ro_param(r, "label", -1, items[3].text); gctl_ro_param(r, "label", -1, items[3].text);
gctl_rw_param(r, "output", sizeof(output), output); gctl_add_param(r, "output", sizeof(output), output,
GCTL_PARAM_WR | GCTL_PARAM_ASCII);
errstr = gctl_issue(r); errstr = gctl_issue(r);
if (errstr != NULL && errstr[0] != '\0') { if (errstr != NULL && errstr[0] != '\0') {
gpart_show_error("Error", NULL, errstr); gpart_show_error("Error", NULL, errstr);