Module Name:    src
Committed By:   kre
Date:           Tue Jun 14 08:06:18 UTC 2022

Modified Files:
        src/sbin/raidctl: raidctl.8 raidctl.c

Log Message:
Implement "raidctl -t config-file"

This does the same config file parse  that -c/-C do, but only
that (hence no raidframe device is needed, or accepted).

Any syntax errors in the config file will be reported, nothing
else happens.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sbin/raidctl/raidctl.8
cvs rdiff -u -r1.77 -r1.78 src/sbin/raidctl/raidctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/raidctl/raidctl.8
diff -u src/sbin/raidctl/raidctl.8:1.78 src/sbin/raidctl/raidctl.8:1.79
--- src/sbin/raidctl/raidctl.8:1.78	Mon Aug  2 20:31:15 2021
+++ src/sbin/raidctl/raidctl.8	Tue Jun 14 08:06:18 2022
@@ -1,4 +1,4 @@
-.\"     $NetBSD: raidctl.8,v 1.78 2021/08/02 20:31:15 oster Exp $
+.\"     $NetBSD: raidctl.8,v 1.79 2022/06/14 08:06:18 kre Exp $
 .\"
 .\" Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -53,7 +53,7 @@
 .\" any improvements or extensions that they make and grant Carnegie the
 .\" rights to redistribute these changes.
 .\"
-.Dd August 2, 2021
+.Dd June 13, 2022
 .Dt RAIDCTL 8
 .Os
 .Sh NAME
@@ -127,6 +127,9 @@
 .Fl s Ar dev
 .Nm
 .Op Fl v
+.Fl t Ar config_file
+.Nm
+.Op Fl v
 .Fl U Ar unit Ar dev
 .Nm
 .Op Fl v
@@ -330,6 +333,11 @@ achieved in each of these areas.
 .It Fl s Ar dev
 Display the status of the RAIDframe device for each of the components
 and spares.
+.It Fl t Ar config_file
+Read and parse the
+.Ar config_file ,
+reporting any errors, then exit.
+No raidframe operations are performed.
 .It Fl U Ar unit Ar dev
 Set the
 .Dv last_unit

Index: src/sbin/raidctl/raidctl.c
diff -u src/sbin/raidctl/raidctl.c:1.77 src/sbin/raidctl/raidctl.c:1.78
--- src/sbin/raidctl/raidctl.c:1.77	Tue Jun 14 08:06:07 2022
+++ src/sbin/raidctl/raidctl.c	Tue Jun 14 08:06:18 2022
@@ -1,4 +1,4 @@
-/*      $NetBSD: raidctl.c,v 1.77 2022/06/14 08:06:07 kre Exp $   */
+/*      $NetBSD: raidctl.c,v 1.78 2022/06/14 08:06:18 kre Exp $   */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: raidctl.c,v 1.77 2022/06/14 08:06:07 kre Exp $");
+__RCSID("$NetBSD: raidctl.c,v 1.78 2022/06/14 08:06:18 kre Exp $");
 #endif
 
 
@@ -64,6 +64,8 @@ __RCSID("$NetBSD: raidctl.c,v 1.77 2022/
 #include "rf_configure.h"
 #include "prog_ops.h"
 
+#define	CONFIGURE_TEST	1	/* must be different from any raidframe ioctl */
+
 void	do_ioctl(int, u_long, void *, const char *);
 static  void rf_configure(int, char*, int);
 static  const char *device_status(RF_DiskStatus_t);
@@ -133,9 +135,9 @@ main(int argc,char *argv[])
 	last_unit = 0;
 	openmode = O_RDWR;	/* default to read/write */
 
-	while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:LmM:r:R:sSpPuU:v"))
-	       != -1)
-		switch(ch) {
+	while ((ch = getopt(argc, argv,
+	    "a:A:Bc:C:f:F:g:GiI:l:LmM:r:R:sSpPt:uU:v")) != -1)
+		switch (ch) {
 		case 'a':
 			action = RAIDFRAME_ADD_HOT_SPARE;
 			get_comp(component, optarg, sizeof(component));
@@ -253,6 +255,12 @@ main(int argc,char *argv[])
 			openmode = O_RDONLY;
 			num_options++;
 			break;
+		case 't':
+			action = CONFIGURE_TEST;
+			strlcpy(config_filename, optarg,
+			    sizeof(config_filename));
+			num_options++;
+			break;
 		case 'u':
 			action = RAIDFRAME_SHUTDOWN;
 			num_options++;
@@ -276,7 +284,20 @@ main(int argc,char *argv[])
 	argc -= optind;
 	argv += optind;
 
-	if ((num_options > 1) || (argc == 0)) 
+	if (num_options > 1)
+		usage();
+
+	if (action == CONFIGURE_TEST) {
+		RF_Config_t cfg;
+
+		if (argc != 0)
+			usage();
+		if (rf_MakeConfig(config_filename, &cfg) != 0)
+			exit(1);
+		exit(0);;
+	}
+
+	if (argc != 1)
 		usage();
 
 	if (prog_init && prog_init() == -1)
@@ -1216,6 +1237,7 @@ usage(void)
 	fprintf(stderr, "       %s [-v] -r component dev\n", progname); 
 	fprintf(stderr, "       %s [-v] -S dev\n", progname);
 	fprintf(stderr, "       %s [-v] -s dev\n", progname);
+	fprintf(stderr, "       %s [-v] -t config_file\n", progname);
 	fprintf(stderr, "       %s [-v] -U unit dev\n", progname);
 	fprintf(stderr, "       %s [-v] -u dev\n", progname);
 	exit(1);

Reply via email to