Module Name:    src
Committed By:   sborrill
Date:           Wed Jun 13 14:00:49 UTC 2012

Modified Files:
        src/sbin/raidctl [netbsd-5]: raidctl.c
        src/sys/dev/raidframe [netbsd-5]: raidframevar.h rf_copyback.c
            rf_disks.c rf_netbsdkintf.c rf_reconstruct.c

Log Message:
Pull up the following revisions(s) (requested by mrg in ticket #1774):
        sbin/raidctl/raidctl.c:                 revision 1.52
        sys/dev/raidframe/raidframevar.h:       revision 1.15
        sys/dev/raidframe/rf_copyback.c:        revision 1.45
        sys/dev/raidframe/rf_disks.c:           revision 1.78
        sys/dev/raidframe/rf_netbsdkintf.c:     revision 1.282,1.284
        sys/dev/raidframe/rf_reconstruct.c:     revision 1.111

Fix garbage values in partitionSizeHi with RAID array > 2TB. Stops the check 
against
rf_component_label_partitionsize() failing and stopping auto-configure.


To generate a diff of this commit:
cvs rdiff -u -r1.39.4.3 -r1.39.4.4 src/sbin/raidctl/raidctl.c
cvs rdiff -u -r1.12.10.2 -r1.12.10.3 src/sys/dev/raidframe/raidframevar.h
cvs rdiff -u -r1.41.20.2 -r1.41.20.3 src/sys/dev/raidframe/rf_copyback.c
cvs rdiff -u -r1.70.10.4 -r1.70.10.5 src/sys/dev/raidframe/rf_disks.c
cvs rdiff -u -r1.250.4.11 -r1.250.4.12 src/sys/dev/raidframe/rf_netbsdkintf.c
cvs rdiff -u -r1.105.4.5 -r1.105.4.6 src/sys/dev/raidframe/rf_reconstruct.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.c
diff -u src/sbin/raidctl/raidctl.c:1.39.4.3 src/sbin/raidctl/raidctl.c:1.39.4.4
--- src/sbin/raidctl/raidctl.c:1.39.4.3	Fri Dec 11 09:37:09 2009
+++ src/sbin/raidctl/raidctl.c	Wed Jun 13 14:00:48 2012
@@ -1,4 +1,4 @@
-/*      $NetBSD: raidctl.c,v 1.39.4.3 2009/12/11 09:37:09 sborrill Exp $   */
+/*      $NetBSD: raidctl.c,v 1.39.4.4 2012/06/13 14:00:48 sborrill 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.39.4.3 2009/12/11 09:37:09 sborrill Exp $");
+__RCSID("$NetBSD: raidctl.c,v 1.39.4.4 2012/06/13 14:00:48 sborrill Exp $");
 #endif
 
 
@@ -751,9 +751,9 @@ get_component_label(int fd, char *compon
 	printf("   sectPerSU: %d, SUsPerPU: %d, SUsPerRU: %d\n",
 	       component_label.sectPerSU, component_label.SUsPerPU, 
 	       component_label.SUsPerRU);
-	printf("   Queue size: %d, blocksize: %d, numBlocks: %u\n",
+	printf("   Queue size: %d, blocksize: %d, numBlocks: %"PRIu64"\n",
 	       component_label.maxOutstanding, component_label.blockSize,
-	       component_label.numBlocks);
+	       rf_component_label_numblocks(&component_label));
 	printf("   RAID Level: %c\n", (char) component_label.parityConfig);
 	printf("   Autoconfig: %s\n", 
 	       component_label.autoconfigure ? "Yes" : "No" );

Index: src/sys/dev/raidframe/raidframevar.h
diff -u src/sys/dev/raidframe/raidframevar.h:1.12.10.2 src/sys/dev/raidframe/raidframevar.h:1.12.10.3
--- src/sys/dev/raidframe/raidframevar.h:1.12.10.2	Sun Nov 21 22:06:53 2010
+++ src/sys/dev/raidframe/raidframevar.h	Wed Jun 13 14:00:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: raidframevar.h,v 1.12.10.2 2010/11/21 22:06:53 riz Exp $ */
+/*	$NetBSD: raidframevar.h,v 1.12.10.3 2012/06/13 14:00:49 sborrill Exp $ */
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -444,9 +444,9 @@ typedef struct RF_ComponentLabel_s {
 	int maxOutstanding;   /* maxOutstanding disk requests */
 	int blockSize;        /* size of component block.
 				 (disklabel->d_secsize) */
-	u_int numBlocks;      /* number of blocks on this component.  May
+	u_int __numBlocks;    /* number of blocks on this component.  May
 			         be smaller than the partition size. */
-	u_int partitionSize;  /* number of blocks on this *partition*.
+	u_int __partitionSize;/* number of blocks on this *partition*.
 				 Must exactly match the partition size
 				 from the disklabel. */
 	/* Parity map stuff. */
@@ -476,6 +476,43 @@ typedef struct RF_ComponentLabel_s {
 	int future_use2[42];  /* More future expansion */
 } RF_ComponentLabel_t;
 
+/*
+ * Following four functions are access macros for the number of blocks
+ * and partition size in component label.
+ */
+static inline RF_SectorCount_t
+rf_component_label_numblocks(const RF_ComponentLabel_t *cl)
+{
+
+	return ((RF_SectorCount_t)cl->numBlocksHi << 32) |
+	    cl->__numBlocks;
+}
+
+static inline void
+rf_component_label_set_numblocks(RF_ComponentLabel_t *cl, RF_SectorCount_t siz)
+{
+
+	cl->numBlocksHi = siz >> 32;
+	cl->__numBlocks = siz;
+}
+
+static inline RF_SectorCount_t
+rf_component_label_partitionsize(const RF_ComponentLabel_t *cl)
+{
+
+	return ((RF_SectorCount_t)cl->partitionSizeHi << 32) |
+	    cl->__partitionSize;
+}
+
+static inline void
+rf_component_label_set_partitionsize(RF_ComponentLabel_t *cl,
+    RF_SectorCount_t siz)
+{
+
+	cl->partitionSizeHi = siz >> 32;
+	cl->__partitionSize = siz;
+}
+
 typedef struct RF_SingleComponent_s {
 	int row;
 	int column;

Index: src/sys/dev/raidframe/rf_copyback.c
diff -u src/sys/dev/raidframe/rf_copyback.c:1.41.20.2 src/sys/dev/raidframe/rf_copyback.c:1.41.20.3
--- src/sys/dev/raidframe/rf_copyback.c:1.41.20.2	Sun Nov 21 22:06:53 2010
+++ src/sys/dev/raidframe/rf_copyback.c	Wed Jun 13 14:00:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_copyback.c,v 1.41.20.2 2010/11/21 22:06:53 riz Exp $	*/
+/*	$NetBSD: rf_copyback.c,v 1.41.20.3 2012/06/13 14:00:49 sborrill Exp $	*/
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -38,7 +38,7 @@
  ****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_copyback.c,v 1.41.20.2 2010/11/21 22:06:53 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_copyback.c,v 1.41.20.3 2012/06/13 14:00:49 sborrill Exp $");
 
 #include <dev/raidframe/raidframevar.h>
 
@@ -212,8 +212,8 @@ rf_CopybackReconstructedData(RF_Raid_t *
 
 	c_label->row = 0;
 	c_label->column = fcol;
-	c_label->partitionSize = raidPtr->Disks[fcol].partitionSize;
-	c_label->partitionSizeHi = raidPtr->Disks[fcol].partitionSize >> 32;
+	rf_component_label_set_partitionsize(c_label,
+	    raidPtr->Disks[fcol].partitionSize);
 
 	raidflush_component_label(raidPtr, fcol);
 

Index: src/sys/dev/raidframe/rf_disks.c
diff -u src/sys/dev/raidframe/rf_disks.c:1.70.10.4 src/sys/dev/raidframe/rf_disks.c:1.70.10.5
--- src/sys/dev/raidframe/rf_disks.c:1.70.10.4	Fri Jan  7 23:25:59 2011
+++ src/sys/dev/raidframe/rf_disks.c	Wed Jun 13 14:00:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_disks.c,v 1.70.10.4 2011/01/07 23:25:59 riz Exp $	*/
+/*	$NetBSD: rf_disks.c,v 1.70.10.5 2012/06/13 14:00:49 sborrill Exp $	*/
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -60,7 +60,7 @@
  ***************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_disks.c,v 1.70.10.4 2011/01/07 23:25:59 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_disks.c,v 1.70.10.5 2012/06/13 14:00:49 sborrill Exp $");
 
 #include <dev/raidframe/raidframevar.h>
 
@@ -452,9 +452,8 @@ rf_AutoConfigureDisks(RF_Raid_t *raidPtr
 		if (ac!=NULL) {
 			/* Found it.  Configure it.. */
 			diskPtr->blockSize = ac->clabel->blockSize;
-			diskPtr->numBlocks = ac->clabel->numBlocks;
-			diskPtr->numBlocks |=
-			    (uint64_t)ac->clabel->numBlocksHi << 32;
+			diskPtr->numBlocks =
+			    rf_component_label_numblocks(ac->clabel);
 			/* Note: rf_protectedSectors is already
 			   factored into numBlocks here */
 			raidPtr->raid_cinfo[c].ci_vp = ac->vp;

Index: src/sys/dev/raidframe/rf_netbsdkintf.c
diff -u src/sys/dev/raidframe/rf_netbsdkintf.c:1.250.4.11 src/sys/dev/raidframe/rf_netbsdkintf.c:1.250.4.12
--- src/sys/dev/raidframe/rf_netbsdkintf.c:1.250.4.11	Fri May 20 19:24:54 2011
+++ src/sys/dev/raidframe/rf_netbsdkintf.c	Wed Jun 13 14:00:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_netbsdkintf.c,v 1.250.4.11 2011/05/20 19:24:54 bouyer Exp $	*/
+/*	$NetBSD: rf_netbsdkintf.c,v 1.250.4.12 2012/06/13 14:00:49 sborrill Exp $	*/
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -139,7 +139,7 @@
  ***********************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.250.4.11 2011/05/20 19:24:54 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.250.4.12 2012/06/13 14:00:49 sborrill Exp $");
 
 #include <sys/param.h>
 #include <sys/errno.h>
@@ -321,7 +321,7 @@ void rf_buildroothack(RF_ConfigSet_t *);
 RF_AutoConfig_t *rf_find_raid_components(void);
 RF_ConfigSet_t *rf_create_auto_sets(RF_AutoConfig_t *);
 static int rf_does_it_fit(RF_ConfigSet_t *,RF_AutoConfig_t *);
-static int rf_reasonable_label(RF_ComponentLabel_t *);
+static int rf_reasonable_label(RF_ComponentLabel_t *, uint64_t);
 void rf_create_configuration(RF_AutoConfig_t *,RF_Config_t *, RF_Raid_t *);
 int rf_set_autoconfig(RF_Raid_t *, int);
 int rf_set_rootpartition(RF_Raid_t *, int);
@@ -1306,8 +1306,8 @@ raidioctl(dev_t dev, u_long cmd, void *d
 				ci_label->serial_number = 
 				    raidPtr->serial_number;
 				ci_label->row = 0; /* we dont' pretend to support more */
-				ci_label->partitionSize =
-				    diskPtr->partitionSize;
+				rf_component_label_set_partitionsize(ci_label,
+				    diskPtr->partitionSize);
 				ci_label->column = column;
 				raidflush_component_label(raidPtr, column);
 			}
@@ -2948,9 +2948,8 @@ oomem:
 
 	if (!raidread_component_label(secsize, dev, vp, clabel)) {
 		/* Got the label.  Does it look reasonable? */
-		if (rf_reasonable_label(clabel) && 
-		    (clabel->partitionSize <= size)) {
-			rf_fix_old_label_size(clabel, numsecs);
+		if (rf_reasonable_label(clabel, numsecs) && 
+		    (rf_component_label_partitionsize(clabel) <= size)) {
 #ifdef DEBUG
 			printf("Component on: %s: %llu\n",
 				cname, (unsigned long long)size);
@@ -3135,7 +3134,7 @@ rf_find_raid_components()
 
 
 static int
-rf_reasonable_label(RF_ComponentLabel_t *clabel)
+rf_reasonable_label(RF_ComponentLabel_t *clabel, uint64_t numsecs)
 {
 
 	if (((clabel->version==RF_COMPONENT_LABEL_VERSION_1) ||
@@ -3149,8 +3148,17 @@ rf_reasonable_label(RF_ComponentLabel_t 
 	    clabel->row < clabel->num_rows &&
 	    clabel->column < clabel->num_columns &&
 	    clabel->blockSize > 0 &&
-	    clabel->numBlocks > 0) {
-		/* label looks reasonable enough... */
+	    /*
+	     * numBlocksHi may contain garbage, but it is ok since
+	     * the type is unsigned.  If it is really garbage,
+	     * rf_fix_old_label_size() will fix it.
+	     */
+	    rf_component_label_numblocks(clabel) > 0) {
+		/*
+		 * label looks reasonable enough...
+		 * let's make sure it has no old garbage.
+		 */
+		rf_fix_old_label_size(clabel, numsecs);
 		return(1);
 	}
 	return(0);
@@ -3162,15 +3170,28 @@ rf_reasonable_label(RF_ComponentLabel_t 
  * the newer numBlocksHi region, and this causes lossage.  Since those
  * disks will also have numsecs set to less than 32 bits of sectors,
  * we can determine when this corruption has occured, and fix it.
+ *
+ * The exact same problem, with the same unknown reason, happens to
+ * the partitionSizeHi member as well.
  */
 static void
 rf_fix_old_label_size(RF_ComponentLabel_t *clabel, uint64_t numsecs)
 {
 
-	if (clabel->numBlocksHi && numsecs < ((uint64_t)1 << 32)) {
-		printf("WARNING: total sectors < 32 bits, yet numBlocksHi set\n"
-		       "WARNING: resetting numBlocksHi to zero.\n");
-		clabel->numBlocksHi = 0;
+	if (numsecs < ((uint64_t)1 << 32)) {
+		if (clabel->numBlocksHi) {
+			printf("WARNING: total sectors < 32 bits, yet "
+			       "numBlocksHi set\n"
+			       "WARNING: resetting numBlocksHi to zero.\n");
+			clabel->numBlocksHi = 0;
+		}
+
+		if (clabel->partitionSizeHi) {
+			printf("WARNING: total sectors < 32 bits, yet "
+			       "partitionSizeHi set\n"
+			       "WARNING: resetting partitionSizeHi to zero.\n");
+			clabel->partitionSizeHi = 0;
+		}
 	}
 }
 
@@ -3179,9 +3200,9 @@ rf_fix_old_label_size(RF_ComponentLabel_
 void
 rf_print_component_label(RF_ComponentLabel_t *clabel)
 {
-	uint64_t numBlocks = clabel->numBlocks;
+	uint64_t numBlocks;
 
-	numBlocks |= (uint64_t)clabel->numBlocksHi << 32;
+	numBlocks = rf_component_label_numblocks(clabel);
 
 	printf("   Row: %d Column: %d Num Rows: %d Num Columns: %d\n",
 	       clabel->row, clabel->column,
@@ -3314,8 +3335,8 @@ rf_does_it_fit(RF_ConfigSet_t *cset, RF_
 	    (clabel1->parityConfig == clabel2->parityConfig) &&
 	    (clabel1->maxOutstanding == clabel2->maxOutstanding) &&
 	    (clabel1->blockSize == clabel2->blockSize) &&
-	    (clabel1->numBlocks == clabel2->numBlocks) &&
-	    (clabel1->numBlocksHi == clabel2->numBlocksHi) &&
+	    rf_component_label_numblocks(clabel1) ==
+	    rf_component_label_numblocks(clabel2) &&
 	    (clabel1->autoconfigure == clabel2->autoconfigure) &&
 	    (clabel1->root_partition == clabel2->root_partition) &&
 	    (clabel1->last_unit == clabel2->last_unit) &&
@@ -3579,8 +3600,7 @@ raid_init_component_label(RF_Raid_t *rai
 	clabel->SUsPerRU = raidPtr->Layout.SUsPerRU;
 
 	clabel->blockSize = raidPtr->bytesPerSector;
-	clabel->numBlocks = raidPtr->sectorsPerDisk;
-	clabel->numBlocksHi = raidPtr->sectorsPerDisk >> 32;
+	rf_component_label_set_numblocks(clabel, raidPtr->sectorsPerDisk);
 
 	/* XXX not portable */
 	clabel->parityConfig = raidPtr->Layout.map->parityConfig;

Index: src/sys/dev/raidframe/rf_reconstruct.c
diff -u src/sys/dev/raidframe/rf_reconstruct.c:1.105.4.5 src/sys/dev/raidframe/rf_reconstruct.c:1.105.4.6
--- src/sys/dev/raidframe/rf_reconstruct.c:1.105.4.5	Fri Feb 24 17:58:44 2012
+++ src/sys/dev/raidframe/rf_reconstruct.c	Wed Jun 13 14:00:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_reconstruct.c,v 1.105.4.5 2012/02/24 17:58:44 sborrill Exp $	*/
+/*	$NetBSD: rf_reconstruct.c,v 1.105.4.6 2012/06/13 14:00:49 sborrill Exp $	*/
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -33,7 +33,7 @@
  ************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.105.4.5 2012/02/24 17:58:44 sborrill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.105.4.6 2012/06/13 14:00:49 sborrill Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -296,9 +296,8 @@ rf_ReconstructFailedDiskBasic(RF_Raid_t 
 		c_label->column = col;
 		c_label->clean = RF_RAID_DIRTY;
 		c_label->status = rf_ds_optimal;
-		c_label->partitionSize = raidPtr->Disks[scol].partitionSize;
-		c_label->partitionSizeHi =
-		   raidPtr->Disks[scol].partitionSize >> 32;
+		rf_component_label_set_partitionsize(c_label,
+		    raidPtr->Disks[scol].partitionSize);
 
 		/* We've just done a rebuild based on all the other
 		   disks, so at this point the parity is known to be

Reply via email to