Module Name:    src
Committed By:   oster
Date:           Mon Aug  2 20:31:15 UTC 2021

Modified Files:
        src/sbin/raidctl: raidctl.8 raidctl.c
        src/sys/dev/raidframe: raidframeio.h rf_netbsdkintf.c

Log Message:
Support on-demand re-scanning all devices to look for
autoconfig RAID sets.  raidctl now supports looking
for autoconfig RAID sets with a new '-L' flag.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sbin/raidctl/raidctl.8
cvs rdiff -u -r1.73 -r1.74 src/sbin/raidctl/raidctl.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/raidframe/raidframeio.h
cvs rdiff -u -r1.397 -r1.398 src/sys/dev/raidframe/rf_netbsdkintf.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.77 src/sbin/raidctl/raidctl.8:1.78
--- src/sbin/raidctl/raidctl.8:1.77	Thu May 27 07:03:27 2021
+++ src/sbin/raidctl/raidctl.8	Mon Aug  2 20:31:15 2021
@@ -1,4 +1,4 @@
-.\"     $NetBSD: raidctl.8,v 1.77 2021/05/27 07:03:27 wiz Exp $
+.\"     $NetBSD: raidctl.8,v 1.78 2021/08/02 20:31:15 oster 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 May 26, 2021
+.Dd August 2, 2021
 .Dt RAIDCTL 8
 .Os
 .Sh NAME
@@ -96,6 +96,9 @@
 .Fl i Ar dev
 .Nm
 .Op Fl v
+.Fl L Ar dev
+.Nm
+.Op Fl v
 .Fl M
 .Oo yes | no | set
 .Ar params
@@ -251,6 +254,15 @@ be done for
 .Em all
 RAID sets before the RAID device is labeled and before
 file systems are created on the RAID device.
+.It Fl L Ar dev
+Rescan all devices on the system, looking for RAID sets that can be 
+auto-configured.  The RAID device provided here has to be a valid 
+device, but does not need to be configured.  (e.g.
+.Bd -literal -offset indent
+raidctl -L raid0
+.Ed
+.Pp
+is all that is needed to perform a rescan.)
 .It Fl M Ic yes Ar dev
 .\"XXX should there be a section with more info on the parity map feature?
 Enable the use of a parity map on the RAID set; this is the default,

Index: src/sbin/raidctl/raidctl.c
diff -u src/sbin/raidctl/raidctl.c:1.73 src/sbin/raidctl/raidctl.c:1.74
--- src/sbin/raidctl/raidctl.c:1.73	Sun Aug  1 20:26:53 2021
+++ src/sbin/raidctl/raidctl.c	Mon Aug  2 20:31:15 2021
@@ -1,4 +1,4 @@
-/*      $NetBSD: raidctl.c,v 1.73 2021/08/01 20:26:53 oster Exp $   */
+/*      $NetBSD: raidctl.c,v 1.74 2021/08/02 20:31:15 oster 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.73 2021/08/01 20:26:53 oster Exp $");
+__RCSID("$NetBSD: raidctl.c,v 1.74 2021/08/02 20:31:15 oster Exp $");
 #endif
 
 
@@ -133,7 +133,7 @@ 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:mM:r:R:sSpPuU:v"))
+	while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:LmM:r:R:sSpPuU:v"))
 	       != -1)
 		switch(ch) {
 		case 'a':
@@ -202,6 +202,10 @@ main(int argc,char *argv[])
 			get_comp(component, optarg, sizeof(component));
 			num_options++;
 			break;
+		case 'L':
+			action = RAIDFRAME_RESCAN;
+			num_options++;
+			break;
 		case 'm':
 			action = RAIDFRAME_PARITYMAP_STATUS;
 			openmode = O_RDONLY;
@@ -362,6 +366,9 @@ main(int argc,char *argv[])
 		do_ioctl(fd, RAIDFRAME_SET_LAST_UNIT, &last_unit,
 		    "RAIDFRAME_SET_LAST_UNIT");
 		break;
+	case RAIDFRAME_RESCAN:
+		do_ioctl(fd, RAIDFRAME_RESCAN, NULL, "RAIDFRAME_RESCAN");
+		break;
 	default:
 		break;
 	}

Index: src/sys/dev/raidframe/raidframeio.h
diff -u src/sys/dev/raidframe/raidframeio.h:1.9 src/sys/dev/raidframe/raidframeio.h:1.10
--- src/sys/dev/raidframe/raidframeio.h:1.9	Sat Jan 20 01:32:45 2018
+++ src/sys/dev/raidframe/raidframeio.h	Mon Aug  2 20:31:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: raidframeio.h,v 1.9 2018/01/20 01:32:45 mrg Exp $ */
+/*	$NetBSD: raidframeio.h,v 1.10 2021/08/02 20:31:14 oster Exp $ */
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -133,5 +133,6 @@
 #define RAIDFRAME_SET_LAST_UNIT _IOW('r', 41, int)
 #define RAIDFRAME_GET_INFO          _IOWR('r', 42, RF_DeviceConfig_t *)	/* get configuration */
 #define RAIDFRAME_CONFIGURE         _IOW ('r',  43, void *)	/* configure the driver */
-
+#define RAIDFRAME_RESCAN  _IO ('r', 44)
 #endif				/* !_RF_RAIDFRAMEIO_H_ */
+

Index: src/sys/dev/raidframe/rf_netbsdkintf.c
diff -u src/sys/dev/raidframe/rf_netbsdkintf.c:1.397 src/sys/dev/raidframe/rf_netbsdkintf.c:1.398
--- src/sys/dev/raidframe/rf_netbsdkintf.c:1.397	Mon Jul 26 22:50:36 2021
+++ src/sys/dev/raidframe/rf_netbsdkintf.c	Mon Aug  2 20:31:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_netbsdkintf.c,v 1.397 2021/07/26 22:50:36 oster Exp $	*/
+/*	$NetBSD: rf_netbsdkintf.c,v 1.398 2021/08/02 20:31:14 oster Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008-2011 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
  ***********************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.397 2021/07/26 22:50:36 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.398 2021/08/02 20:31:14 oster Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_raid_autoconfig.h"
@@ -305,6 +305,7 @@ static void rf_RewriteParityThread(RF_Ra
 static void rf_CopybackThread(RF_Raid_t *raidPtr);
 static void rf_ReconstructInPlaceThread(struct rf_recon_req_internal *);
 static int rf_autoconfig(device_t);
+static int rf_rescan(void);
 static void rf_buildroothack(RF_ConfigSet_t *);
 
 static RF_AutoConfig_t *rf_find_raid_components(void);
@@ -480,6 +481,56 @@ rf_containsboot(RF_Raid_t *r, device_t b
 	return 0;
 }
 
+static int
+rf_rescan(void)
+{
+	RF_AutoConfig_t *ac_list;
+	RF_ConfigSet_t *config_sets, *cset, *next_cset;
+	struct raid_softc *sc;
+	int raid_added;
+	
+	ac_list = rf_find_raid_components();
+	config_sets = rf_create_auto_sets(ac_list);
+
+	raid_added = 1;
+	while (raid_added > 0) {
+		raid_added = 0;
+		cset = config_sets;
+		while (cset != NULL) {
+			next_cset = cset->next;
+			if (rf_have_enough_components(cset) &&
+			    cset->ac->clabel->autoconfigure == 1) {
+				sc = rf_auto_config_set(cset);
+				if (sc != NULL) {
+					aprint_debug("raid%d: configured ok, rootable %d\n",
+						     sc->sc_unit, cset->rootable);
+					/* We added one RAID set */
+					raid_added++;
+				} else {
+					/* The autoconfig didn't work :( */
+					aprint_debug("Autoconfig failed\n");
+					rf_release_all_vps(cset);
+				}
+			} else {
+				/* we're not autoconfiguring this set...
+				   release the associated resources */
+				rf_release_all_vps(cset);
+			}
+			/* cleanup */
+			rf_cleanup_config_set(cset);
+			cset = next_cset;
+		}
+		if (raid_added > 0) {
+			/* We added at least one RAID set, so re-scan for recursive RAID */
+			ac_list = rf_find_raid_components();
+			config_sets = rf_create_auto_sets(ac_list);
+		}
+	}
+	
+	return 0;
+}
+
+
 static void
 rf_buildroothack(RF_ConfigSet_t *config_sets)
 {
@@ -1529,7 +1580,7 @@ raidioctl(dev_t dev, u_long cmd, void *d
 
 	case RAIDFRAME_REBUILD_IN_PLACE:
 		return rf_rebuild_in_place(raidPtr, data);
-
+		
 	case RAIDFRAME_GET_INFO:
 		ucfgp = *(RF_DeviceConfig_t **)data;
 		d_cfg = RF_Malloc(sizeof(*d_cfg));
@@ -1574,6 +1625,9 @@ raidioctl(dev_t dev, u_long cmd, void *d
 		/* XXX should errors be passed up? */
 		return 0;
 
+	case RAIDFRAME_RESCAN:
+		return rf_rescan();
+
 	case RAIDFRAME_RESET_ACCTOTALS:
 		memset(&raidPtr->acc_totals, 0, sizeof(raidPtr->acc_totals));
 		return 0;
@@ -2680,9 +2734,17 @@ rf_ReconThread(struct rf_recon_req_inter
 	raidPtr = (RF_Raid_t *) req->raidPtr;
 	raidPtr->recon_in_progress = 1;
 
+	if (req->flags & RF_FDFLAGS_RECON_FORCE) {
+		raidPtr->forceRecon = 1;
+	}
+	
 	rf_FailDisk((RF_Raid_t *) req->raidPtr, req->col,
 		    ((req->flags & RF_FDFLAGS_RECON) ? 1 : 0));
 
+	if (req->flags & RF_FDFLAGS_RECON_FORCE) {
+		raidPtr->forceRecon = 0;
+	}
+
 	RF_Free(req, sizeof(*req));
 
 	raidPtr->recon_in_progress = 0;
@@ -2751,7 +2813,17 @@ rf_ReconstructInPlaceThread(struct rf_re
 	s = splbio();
 	raidPtr = req->raidPtr;
 	raidPtr->recon_in_progress = 1;
+
+	if (req->flags & RF_FDFLAGS_RECON_FORCE) {
+		raidPtr->forceRecon = 1;
+	}
+
 	rf_ReconstructInPlace(raidPtr, req->col);
+
+	if (req->flags & RF_FDFLAGS_RECON_FORCE) {
+		raidPtr->forceRecon = 0;
+	}
+
 	RF_Free(req, sizeof(*req));
 	raidPtr->recon_in_progress = 0;
 	splx(s);

Reply via email to