git: 2117cdd4b4eb - main - GEOM: Introduce gctl_add_param() API.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Mon, 07 Mar 2022 16:12:33 UTC
The branch main has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=2117cdd4b4ebda7db0270c56f5a3cbdd37ec8cfc

commit 2117cdd4b4ebda7db0270c56f5a3cbdd37ec8cfc
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-03-07 16:06:11 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-03-07 16:12:25 +0000

    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
---
 lib/geom/part/geom_part.c                |  5 +++--
 lib/libgeom/geom_ctl.c                   |  8 ++++----
 lib/libgeom/libgeom.h                    |  2 ++
 sbin/ccdconfig/ccdconfig.c               |  8 ++++++--
 sbin/geom/core/geom.c                    |  5 +++--
 sbin/gvinum/gvinum.c                     | 15 +++++++++++----
 usr.sbin/bsdinstall/partedit/gpart_ops.c |  6 ++++--
 7 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/lib/geom/part/geom_part.c b/lib/geom/part/geom_part.c
index b21ebf7ef8d8..41131646e246 100644
--- a/lib/geom/part/geom_part.c
+++ b/lib/geom/part/geom_part.c
@@ -1327,8 +1327,9 @@ gpart_issue(struct gctl_req *req, unsigned int fl __unused)
 		goto done;
 	}
 
-	bzero(buf, sizeof(buf));
-	gctl_rw_param(req, "output", sizeof(buf), buf);
+	buf[0] = '\0';
+	gctl_add_param(req, "output", sizeof(buf), buf,
+	    GCTL_PARAM_WR | GCTL_PARAM_ASCII);
 	errstr = gctl_issue(req);
 	if (errstr == NULL || errstr[0] == '\0') {
 		if (buf[0] != '\0')
diff --git a/lib/libgeom/geom_ctl.c b/lib/libgeom/geom_ctl.c
index 1d5c52fc3779..b60c4c297257 100644
--- a/lib/libgeom/geom_ctl.c
+++ b/lib/libgeom/geom_ctl.c
@@ -151,8 +151,8 @@ gctl_new_arg(struct gctl_req *req)
 	return (ap);
 }
 
-static void
-gctl_param_add(struct gctl_req *req, const char *name, int len, void *value,
+void
+gctl_add_param(struct gctl_req *req, const char *name, int len, void *value,
     int flag)
 {
 	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_param_add(req, name, len, __DECONST(void *, value), GCTL_PARAM_RD);
+	gctl_add_param(req, name, len, __DECONST(void *, value), GCTL_PARAM_RD);
 }
 
 void
 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 *
diff --git a/lib/libgeom/libgeom.h b/lib/libgeom/libgeom.h
index fc593b234302..9be27208a98c 100644
--- a/lib/libgeom/libgeom.h
+++ b/lib/libgeom/libgeom.h
@@ -149,6 +149,8 @@ void gctl_dump(struct gctl_req *, FILE *);
 void gctl_free(struct gctl_req *);
 struct gctl_req *gctl_get_handle(void);
 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_rw_param(struct gctl_req *, const char *, int, void *);
 
diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c
index 6d22b14deed8..1429426e8638 100644
--- a/sbin/ccdconfig/ccdconfig.c
+++ b/sbin/ccdconfig/ccdconfig.c
@@ -263,7 +263,9 @@ do_single(int argc, char **argv, int action)
 			cp += strlen(_PATH_DEV);
 		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);
 	if (errstr == NULL) {		
 		if (verbose) {
@@ -371,10 +373,12 @@ dumpout(int unit)
 	grq = gctl_get_handle();
 	ncp = 65536;
 	cp = malloc(ncp);
+	cp[0] = '\0';
 	gctl_ro_param(grq, "verb", -1, "list");
 	gctl_ro_param(grq, "class", -1, "CCD");
 	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);
 	if (errstr != NULL)
 		errx(1, "%s\nor possibly kernel and ccdconfig out of sync",
diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c
index 0202be9a063e..9d93e9b9989f 100644
--- a/sbin/geom/core/geom.c
+++ b/sbin/geom/core/geom.c
@@ -487,7 +487,7 @@ run_command(int argc, char *argv[])
 		gctl_ro_param(req, "version", sizeof(*version), version);
 	parse_arguments(cmd, req, &argc, &argv);
 
-	bzero(buf, sizeof(buf));
+	buf[0] = '\0';
 	if (cmd->gc_func != NULL) {
 		unsigned flags;
 
@@ -495,7 +495,8 @@ run_command(int argc, char *argv[])
 		cmd->gc_func(req, flags);
 		errstr = req->error;
 	} 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);
 	}
 	if (errstr != NULL && errstr[0] != '\0') {
diff --git a/sbin/gvinum/gvinum.c b/sbin/gvinum/gvinum.c
index 50947a30a725..5a081e92a8df 100644
--- a/sbin/gvinum/gvinum.c
+++ b/sbin/gvinum/gvinum.c
@@ -575,13 +575,15 @@ find_name(const char *prefix, int type, int namelen)
 	char line[1024];
 
 	comment[0] = '\0';
+	buf[0] = '\0';
 
 	/* Find a name. Fetch out configuration first. */
 	req = gctl_get_handle();
 	gctl_ro_param(req, "class", -1, "VINUM");
 	gctl_ro_param(req, "verb", -1, "getconfig");
 	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);
 	if (errstr != NULL) {
 		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();
 	gctl_ro_param(req, "class", -1, "VINUM");
 	gctl_ro_param(req, "verb", -1, "list");
 	gctl_ro_param(req, "cmd", -1, cmd);
 	gctl_ro_param(req, "argc", sizeof(int), &argc);
 	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) {
 		for (i = 0; i < argc; i++) {
 			snprintf(buf, sizeof(buf), "argv%d", i);
@@ -1418,15 +1423,17 @@ printconfig(FILE *of, const char *comment)
 	const char *errstr;
 	time_t now;
 	char buf[GV_CFG_LEN + 1];
-	
+
 	uname(&uname_s);
 	time(&now);
+	buf[0] = '\0';
 
 	req = gctl_get_handle();
 	gctl_ro_param(req, "class", -1, "VINUM");
 	gctl_ro_param(req, "verb", -1, "getconfig");
 	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);
 	if (errstr != NULL) {
 		warnx("can't get configuration: %s", errstr);
diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c
index b49ff1c9fd42..f95cc514903b 100644
--- a/usr.sbin/bsdinstall/partedit/gpart_ops.c
+++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c
@@ -1207,12 +1207,13 @@ addpartform:
 		}
 	}
 
+	output[0] = '\0';
+
 	r = gctl_get_handle();
 	gctl_ro_param(r, "class", -1, "PART");
 	gctl_ro_param(r, "arg0", -1, geom->lg_name);
 	gctl_ro_param(r, "flags", -1, GPART_FLAGS);
 	gctl_ro_param(r, "verb", -1, "add");
-
 	gctl_ro_param(r, "type", -1, items[0].text);
 	snprintf(sizestr, sizeof(sizestr), "%jd", size);
 	gctl_ro_param(r, "size", -1, sizestr);
@@ -1220,7 +1221,8 @@ addpartform:
 	gctl_ro_param(r, "start", -1, startstr);
 	if (items[3].text[0] != '\0')
 		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);
 	if (errstr != NULL && errstr[0] != '\0') {
 		gpart_show_error("Error", NULL, errstr);