[Midnightbsd-cvs] src: geom/core: merge changes

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Nov 21 16:49:00 EST 2008


Log Message:
-----------
merge changes

Modified Files:
--------------
    src/sbin/geom/core:
        geom.8 (r1.1 -> r1.2)
        geom.c (r1.2 -> r1.3)
        geom.h (r1.2 -> r1.3)

-------------- next part --------------
Index: geom.8
===================================================================
RCS file: /home/cvs/src/sbin/geom/core/geom.8,v
retrieving revision 1.1
retrieving revision 1.2
diff -L sbin/geom/core/geom.8 -L sbin/geom/core/geom.8 -u -r1.1 -r1.2
--- sbin/geom/core/geom.8
+++ sbin/geom/core/geom.8
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: src/sbin/geom/core/geom.8,v 1.17.2.1 2006/01/31 12:39:26 pjd Exp $
+.\" $FreeBSD: src/sbin/geom/core/geom.8,v 1.19 2007/09/23 07:34:22 pjd Exp $
 .\"
 .Dd May 21, 2004
 .Dt GEOM 8
@@ -123,6 +123,8 @@
 SHSEC
 .It
 STRIPE
+.It
+VIRSTOR
 .El
 .Sh ENVIRONMENT
 The following environment variables affect the execution of
@@ -161,7 +163,8 @@
 .Xr gnop 8 ,
 .Xr graid3 8 ,
 .Xr gshsec 8 ,
-.Xr gstripe 8
+.Xr gstripe 8 ,
+.Xr gvirstor 8
 .Sh HISTORY
 The
 .Nm
Index: geom.h
===================================================================
RCS file: /home/cvs/src/sbin/geom/core/geom.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/geom/core/geom.h -L sbin/geom/core/geom.h -u -r1.2 -r1.3
--- sbin/geom/core/geom.h
+++ sbin/geom/core/geom.h
@@ -23,28 +23,32 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sbin/geom/core/geom.h,v 1.2.2.1 2006/04/05 22:20:44 pjd Exp $
+ * $FreeBSD: src/sbin/geom/core/geom.h,v 1.6 2007/05/16 23:32:40 marcel Exp $
  */
 
 #ifndef _GEOM_H_
 #define	_GEOM_H_
-#define	G_LIB_VERSION	1
+#define	G_LIB_VERSION	3
 
 #define	G_FLAG_NONE	0x0000
 #define	G_FLAG_VERBOSE	0x0001
 #define	G_FLAG_LOADKLD	0x0002
 
-#define	G_TYPE_NONE	0
-#define	G_TYPE_STRING	1
-#define	G_TYPE_NUMBER	2
+#define	G_TYPE_NONE	0x00
+#define	G_TYPE_BOOL	0x01
+#define	G_TYPE_STRING	0x02
+#define	G_TYPE_NUMBER	0x03
+#define	G_TYPE_MASK	0x03
+#define	G_TYPE_DONE	0x10
 
 #define	G_OPT_MAX	16
-#define	G_OPT_DONE(opt)		(opt)->go_char = '\0'
-#define	G_OPT_ISDONE(opt)	((opt)->go_char == '\0')
+#define	G_OPT_DONE(opt)		do { (opt)->go_type |= G_TYPE_DONE; } while (0)
+#define	G_OPT_ISDONE(opt)	((opt)->go_type & G_TYPE_DONE)
+#define	G_OPT_TYPE(opt)		((opt)->go_type & G_TYPE_MASK)
 
 #define G_OPT_SENTINEL	{ '\0', NULL, NULL, G_TYPE_NONE }
 #define G_NULL_OPTS	{ G_OPT_SENTINEL }
-#define	G_CMD_SENTINEL	{ NULL, 0, NULL, G_NULL_OPTS, NULL }
+#define	G_CMD_SENTINEL	{ NULL, 0, NULL, G_NULL_OPTS, NULL, NULL }
 
 struct g_option {
 	char		 go_char;
@@ -58,6 +62,7 @@
 	unsigned	 gc_flags;
 	void		(*gc_func)(struct gctl_req *, unsigned);
 	struct g_option	gc_options[G_OPT_MAX];
+	const char	*gc_argname;
 	const char	*gc_usage;
 };
 #endif	/* !_GEOM_H_ */
Index: geom.c
===================================================================
RCS file: /home/cvs/src/sbin/geom/core/geom.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/geom/core/geom.c -L sbin/geom/core/geom.c -u -r1.2 -r1.3
--- sbin/geom/core/geom.c
+++ sbin/geom/core/geom.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sbin/geom/core/geom.c,v 1.22.2.3.2.1 2006/04/13 06:36:26 pjd Exp $");
+__FBSDID("$FreeBSD: src/sbin/geom/core/geom.c,v 1.32 2007/09/21 10:00:05 pjd Exp $");
 
 #include <sys/param.h>
 #include <sys/linker.h>
@@ -69,19 +69,20 @@
 static void std_unload(struct gctl_req *req, unsigned flags);
 
 struct g_command std_commands[] = {
-	{ "help", 0, std_help, G_NULL_OPTS, NULL },
-	{ "list", 0, std_list, G_NULL_OPTS,
+	{ "help", 0, std_help, G_NULL_OPTS, NULL, NULL },
+	{ "list", 0, std_list, G_NULL_OPTS, NULL, 
 	    "[name ...]"
 	},
 	{ "status", 0, std_status,
 	    {
-		{ 's', "script", NULL, G_TYPE_NONE },
+		{ 's', "script", NULL, G_TYPE_BOOL },
 		G_OPT_SENTINEL
 	    },
-	    "[-s] [name ...]"
+	    NULL, "[-s] [name ...]"
 	},
-	{ "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS, NULL },
-	{ "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL },
+	{ "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS,
+	    NULL, NULL },
+	{ "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL, NULL },
 	G_CMD_SENTINEL
 };
 
@@ -102,16 +103,18 @@
 		opt = &cmd->gc_options[i];
 		if (opt->go_name == NULL)
 			break;
-		if (opt->go_val != NULL || opt->go_type == G_TYPE_NONE)
+		if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
 			fprintf(stderr, " [");
 		else
 			fprintf(stderr, " ");
 		fprintf(stderr, "-%c", opt->go_char);
-		if (opt->go_type != G_TYPE_NONE)
+		if (G_OPT_TYPE(opt) != G_TYPE_BOOL)
 			fprintf(stderr, " %s", opt->go_name);
-		if (opt->go_val != NULL || opt->go_type == G_TYPE_NONE)
+		if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
 			fprintf(stderr, "]");
 	}
+	if (cmd->gc_argname)
+		fprintf(stderr, " %s", cmd->gc_argname);
 	fprintf(stderr, "\n");
 }
 
@@ -218,12 +221,10 @@
 set_option(struct gctl_req *req, struct g_option *opt, const char *val)
 {
 
-	if (opt->go_type == G_TYPE_NUMBER) {
+	if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) {
 		intmax_t number;
 
-		errno = 0;
-		number = strtoimax(optarg, NULL, 0);
-		if (errno != 0) {
+		if (expand_number(val, &number) == -1) {
 			err(EXIT_FAILURE, "Invalid value for '%c' argument.",
 			    opt->go_char);
 		}
@@ -233,9 +234,9 @@
 		*(intmax_t *)opt->go_val = number;
 
 		gctl_ro_param(req, opt->go_name, sizeof(intmax_t), opt->go_val);
-	} else if (opt->go_type == G_TYPE_STRING) {
-		gctl_ro_param(req, opt->go_name, -1, optarg);
-	} else /* if (opt->go_type == G_TYPE_NONE) */ {
+	} else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
+		gctl_ro_param(req, opt->go_name, -1, val);
+	} else if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
 		opt->go_val = malloc(sizeof(int));
 		if (opt->go_val == NULL)
 			errx(EXIT_FAILURE, "No memory.");
@@ -243,6 +244,8 @@
 
 		gctl_ro_param(req, opt->go_name, sizeof(int),
 		    opt->go_val);
+	} else {
+		assert(!"Invalid type");
 	}
 }
 
@@ -267,8 +270,10 @@
 		opt = &cmd->gc_options[i];
 		if (opt->go_name == NULL)
 			break;
+		assert(G_OPT_TYPE(opt) != 0);
+		assert((opt->go_type & ~G_TYPE_MASK) == 0);
 		strlcatf(opts, sizeof(opts), "%c", opt->go_char);
-		if (opt->go_type != G_TYPE_NONE)
+		if (G_OPT_TYPE(opt) != G_TYPE_BOOL)
 			strlcat(opts, ":", sizeof(opts));
 	}
 
@@ -287,13 +292,12 @@
 		if (opt == NULL)
 			usage();
 		if (G_OPT_ISDONE(opt)) {
-			fprintf(stderr, "Flag '%c' specified twice.\n",
-			    opt->go_char);
+			warnx("Option '%c' specified twice.", opt->go_char);
 			usage();
 		}
 		G_OPT_DONE(opt);
 
-		if (opt->go_type == G_TYPE_NONE)
+		if (G_OPT_TYPE(opt) == G_TYPE_BOOL)
 			set_option(req, opt, "1");
 		else
 			set_option(req, opt, optarg);
@@ -311,34 +315,46 @@
 		if (G_OPT_ISDONE(opt))
 			continue;
 
-		if (opt->go_type == G_TYPE_NONE) {
+		if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
 			assert(opt->go_val == NULL);
 			set_option(req, opt, "0");
 		} else {
 			if (opt->go_val == NULL) {
-				fprintf(stderr, "Flag '%c' not specified.\n",
+				warnx("Option '%c' not specified.",
 				    opt->go_char);
 				usage();
 			} else {
-				if (opt->go_type == G_TYPE_NUMBER) {
+				if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) {
 					gctl_ro_param(req, opt->go_name,
 					    sizeof(intmax_t), opt->go_val);
-				} else /* if (opt->go_type == G_TYPE_STRING)*/ {
-					gctl_ro_param(req, opt->go_name, -1,
-					    opt->go_val);
+				} else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
+					if (cmd->gc_argname == NULL ||
+					    opt->go_val == NULL ||
+					    *(char *)opt->go_val != '\0')
+						gctl_ro_param(req, opt->go_name,
+						    -1, opt->go_val);
+				} else {
+					assert(!"Invalid type");
 				}
 			}
 		}
 	}
-	/*
-	 * Add rest of given arguments.
-	 */
-	gctl_ro_param(req, "nargs", sizeof(int), argc);
-	for (i = 0; i < (unsigned)*argc; i++) {
-		char argname[16];
 
-		snprintf(argname, sizeof(argname), "arg%u", i);
-		gctl_ro_param(req, argname, -1, (*argv)[i]);
+	if (cmd->gc_argname == NULL) {
+		/*
+		 * Add rest of given arguments.
+		 */
+		gctl_ro_param(req, "nargs", sizeof(int), argc);
+		for (i = 0; i < (unsigned)*argc; i++) {
+			char argname[16];
+
+			snprintf(argname, sizeof(argname), "arg%u", i);
+			gctl_ro_param(req, argname, -1, (*argv)[i]);
+		}
+	} else {
+		if (*argc != 1)
+			usage();
+		gctl_ro_param(req, cmd->gc_argname, -1, (*argv)[0]);
 	}
 }
 
@@ -406,12 +422,11 @@
 		/* Now, try to find a standard command. */
 		cmd = find_command(argv[0], GEOM_STD_CMDS);
 		if (cmd == NULL) {
-			fprintf(stderr, "Unknown command: %s\n", argv[0]);
+			warnx("Unknown command: %s.", argv[0]);
 			usage();
 		}
 		if (!std_available(cmd->gc_name)) {
-			fprintf(stderr, "Command '%s' not available.\n",
-			    argv[0]);
+			warnx("Command '%s' not available.", argv[0]);
 			exit(EXIT_FAILURE);
 		}
 	}
@@ -437,7 +452,7 @@
 		errstr = gctl_issue(req);
 	}
 	if (errstr != NULL && errstr[0] != '\0') {
-		fprintf(stderr, "%s\n", errstr);
+		warnx("%s", errstr);
 		if (strncmp(errstr, "warning: ", strlen("warning: ")) != 0) {
 			gctl_free(req);
 			exit(EXIT_FAILURE);
@@ -486,8 +501,7 @@
 		errx(EXIT_FAILURE, "Cannot open library: %s.", dlerror());
 	lib_version = dlsym(dlh, "lib_version");
 	if (lib_version == NULL) {
-		fprintf(stderr, "Cannot find symbol %s: %s.\n", "lib_version",
-		    dlerror());
+		warnx("Cannot find symbol %s: %s.", "lib_version", dlerror());
 		dlclose(dlh);
 		exit(EXIT_FAILURE);
 	}
@@ -498,15 +512,14 @@
 	}
 	version = dlsym(dlh, "version");
 	if (version == NULL) {
-		fprintf(stderr, "Cannot find symbol %s: %s.\n", "version",
-		    dlerror());
+		warnx("Cannot find symbol %s: %s.", "version", dlerror());
 		dlclose(dlh);
 		exit(EXIT_FAILURE);
 	}
 	class_commands = dlsym(dlh, "class_commands");
 	if (class_commands == NULL) {
-		fprintf(stderr, "Cannot find symbol %s: %s.\n",
-		    "class_commands", dlerror());
+		warnx("Cannot find symbol %s: %s.", "class_commands",
+		    dlerror());
 		dlclose(dlh);
 		exit(EXIT_FAILURE);
 	}
@@ -688,10 +701,8 @@
 	int error;
 
 	error = geom_gettree(&mesh);
-	if (error != 0) {
-		fprintf(stderr, "Cannot get GEOM tree: %s.\n", strerror(error));
-		exit(EXIT_FAILURE);
-	}
+	if (error != 0)
+		errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
 	classp = find_class(&mesh, gclass_name);
 	geom_deletetree(&mesh);
 	if (classp != NULL)
@@ -709,15 +720,12 @@
 	int error, i, nargs;
 
 	error = geom_gettree(&mesh);
-	if (error != 0) {
-		fprintf(stderr, "Cannot get GEOM tree: %s.\n", strerror(error));
-		exit(EXIT_FAILURE);
-	}
+	if (error != 0)
+		errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
 	classp = find_class(&mesh, gclass_name);
 	if (classp == NULL) {
 		geom_deletetree(&mesh);
-		fprintf(stderr, "Class %s not found.\n", gclass_name);
-		return;
+		errx(EXIT_FAILURE, "Class %s not found.", gclass_name);
 	}
 	nargs = gctl_get_int(req, "nargs");
 	if (nargs > 0) {
@@ -727,7 +735,7 @@
 			if (gp != NULL)
 				list_one_geom(gp);
 			else
-				fprintf(stderr, "No such geom: %s.\n", name);
+				errx(EXIT_FAILURE, "No such geom: %s.", name);
 		}
 	} else {
 		LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
@@ -847,15 +855,11 @@
 	int error, i, n, nargs, script;
 
 	error = geom_gettree(&mesh);
-	if (error != 0) {
-		fprintf(stderr, "Cannot get GEOM tree: %s.\n", strerror(error));
-		exit(EXIT_FAILURE);
-	}
+	if (error != 0)
+		errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
 	classp = find_class(&mesh, gclass_name);
-	if (classp == NULL) {
-		fprintf(stderr, "Class %s not found.\n", gclass_name);
-		goto end;
-	}
+	if (classp == NULL)
+		errx(EXIT_FAILURE, "Class %s not found.", gclass_name);
 	nargs = gctl_get_int(req, "nargs");
 	script = gctl_get_int(req, "script");
 	name_len = strlen("Name");
@@ -865,7 +869,7 @@
 			name = gctl_get_ascii(req, "arg%d", i);
 			gp = find_geom(classp, name);
 			if (gp == NULL)
-				fprintf(stderr, "No such geom: %s.\n", name);
+				errx(EXIT_FAILURE, "No such geom: %s.", name);
 			else {
 				status_update_len(gp, &name_len, &status_len);
 				n++;


More information about the Midnightbsd-cvs mailing list