Module Name:    src
Committed By:   riz
Date:           Fri Jan  7 23:25:59 UTC 2011

Modified Files:
        src/sys/dev/raidframe [netbsd-5]: rf_disks.c rf_netbsdkintf.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1522):
        sys/dev/raidframe/rf_disks.c: revision 1.76
        sys/dev/raidframe/rf_netbsdkintf.c: revision 1.276
apply my patch to support non-512K sector disks (at least, upto 16KB
sector disks..)  from my tech-kern post:
the following patch let's me access both 512 byte and 4K
sector disks at the same time, as long as they are in
separate raids.  the existing rf code assumes/enforces
this part, i just made it support other sets concurrently.
the main change is moving the parity bitmap to the sector
after the component label sector(s), instead of being
immediately after the label, which meant it was on the same
sector as the label for >1024 byte devices.
i'm a little annoyed at having to add a 2nd call to
getdisksize() to enable auto-configure to work, but i
don't see another way that wasn't much uglier.


To generate a diff of this commit:
cvs rdiff -u -r1.70.10.3 -r1.70.10.4 src/sys/dev/raidframe/rf_disks.c
cvs rdiff -u -r1.250.4.8 -r1.250.4.9 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/sys/dev/raidframe/rf_disks.c
diff -u src/sys/dev/raidframe/rf_disks.c:1.70.10.3 src/sys/dev/raidframe/rf_disks.c:1.70.10.4
--- src/sys/dev/raidframe/rf_disks.c:1.70.10.3	Sun Nov 21 22:06:53 2010
+++ src/sys/dev/raidframe/rf_disks.c	Fri Jan  7 23:25:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_disks.c,v 1.70.10.3 2010/11/21 22:06:53 riz Exp $	*/
+/*	$NetBSD: rf_disks.c,v 1.70.10.4 2011/01/07 23:25:59 riz 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.3 2010/11/21 22:06:53 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_disks.c,v 1.70.10.4 2011/01/07 23:25:59 riz Exp $");
 
 #include <dev/raidframe/raidframevar.h>
 
@@ -597,16 +597,26 @@
 		if (error == ENXIO) {
 			/* the component isn't there... must be dead :-( */
 			diskPtr->status = rf_ds_failed;
+			return 0;
 		} else {
 			return (error);
 		}
 	}
-	if (diskPtr->status == rf_ds_optimal) {
 
+	if ((error = rf_getdisksize(vp, curlwp, diskPtr)) != 0)
+		return (error);
+
+	/*
+	 * If this raidPtr's bytesPerSector is zero, fill it in with this
+	 * components blockSize.  This will give us something to work with
+	 * initially, and if it is wrong, we'll get errors later.
+	 */
+	if (raidPtr->bytesPerSector == 0)
+		raidPtr->bytesPerSector = diskPtr->blockSize;
+
+	if (diskPtr->status == rf_ds_optimal) {
 		if ((error = VOP_GETATTR(vp, &va, curlwp->l_cred)) != 0) 
 			return (error);
-		if ((error = rf_getdisksize(vp, curlwp, diskPtr)) != 0)
-			return (error);
 
 		raidPtr->raid_cinfo[col].ci_vp = vp;
 		raidPtr->raid_cinfo[col].ci_dev = va.va_rdev;

Index: src/sys/dev/raidframe/rf_netbsdkintf.c
diff -u src/sys/dev/raidframe/rf_netbsdkintf.c:1.250.4.8 src/sys/dev/raidframe/rf_netbsdkintf.c:1.250.4.9
--- src/sys/dev/raidframe/rf_netbsdkintf.c:1.250.4.8	Sun Nov 21 22:06:53 2010
+++ src/sys/dev/raidframe/rf_netbsdkintf.c	Fri Jan  7 23:25:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_netbsdkintf.c,v 1.250.4.8 2010/11/21 22:06:53 riz Exp $	*/
+/*	$NetBSD: rf_netbsdkintf.c,v 1.250.4.9 2011/01/07 23:25:59 riz 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.8 2010/11/21 22:06:53 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.250.4.9 2011/01/07 23:25:59 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/errno.h>
@@ -219,10 +219,10 @@
 static int raidwrite_component_area(dev_t, struct vnode *, void *, size_t,
     daddr_t, daddr_t, int);
 
-static int raidwrite_component_label(dev_t, struct vnode *,
-    RF_ComponentLabel_t *);
-static int raidread_component_label(dev_t, struct vnode *,
-    RF_ComponentLabel_t *);
+static int raidwrite_component_label(unsigned,
+    dev_t, struct vnode *, RF_ComponentLabel_t *);
+static int raidread_component_label(unsigned,
+    dev_t, struct vnode *, RF_ComponentLabel_t *);
 
 
 dev_type_open(raidopen);
@@ -1001,8 +1001,8 @@
 	rs = &raid_softc[unit];
 	raidPtr = raidPtrs[unit];
 
-	db1_printf(("raidioctl: %d %d %d %d\n", (int) dev,
-		(int) DISKPART(dev), (int) unit, (int) cmd));
+	db1_printf(("raidioctl: %d %d %d %lu\n", (int) dev,
+		(int) DISKPART(dev), (int) unit, cmd));
 
 	/* Must be open for writes for these commands... */
 	switch (cmd) {
@@ -2400,10 +2400,57 @@
 
 #define RF_COMPONENT_INFO_OFFSET  16384 /* bytes */
 #define RF_COMPONENT_INFO_SIZE     1024 /* bytes */
-#define RF_PARITY_MAP_OFFSET \
-	(RF_COMPONENT_INFO_OFFSET + RF_COMPONENT_INFO_SIZE)
 #define RF_PARITY_MAP_SIZE   RF_PARITYMAP_NBYTE
 
+static daddr_t
+rf_component_info_offset(void)
+{
+
+	return RF_COMPONENT_INFO_OFFSET;
+}
+
+static daddr_t
+rf_component_info_size(unsigned secsize)
+{
+	daddr_t info_size;
+
+	KASSERT(secsize);
+	if (secsize > RF_COMPONENT_INFO_SIZE)
+		info_size = secsize;
+	else
+		info_size = RF_COMPONENT_INFO_SIZE;
+
+	return info_size;
+}
+
+static daddr_t
+rf_parity_map_offset(RF_Raid_t *raidPtr)
+{
+	daddr_t map_offset;
+
+	KASSERT(raidPtr->bytesPerSector);
+	if (raidPtr->bytesPerSector > RF_COMPONENT_INFO_SIZE)
+		map_offset = raidPtr->bytesPerSector;
+	else
+		map_offset = RF_COMPONENT_INFO_SIZE;
+	map_offset += rf_component_info_offset();
+
+	return map_offset;
+}
+
+static daddr_t
+rf_parity_map_size(RF_Raid_t *raidPtr)
+{
+	daddr_t map_size;
+
+	if (raidPtr->bytesPerSector > RF_PARITY_MAP_SIZE)
+		map_size = raidPtr->bytesPerSector;
+	else
+		map_size = RF_PARITY_MAP_SIZE;
+
+	return map_size;
+}
+
 int
 raidmarkclean(RF_Raid_t *raidPtr, RF_RowCol_t col)
 {
@@ -2430,7 +2477,9 @@
 int
 raidfetch_component_label(RF_Raid_t *raidPtr, RF_RowCol_t col)
 {
-	return raidread_component_label(raidPtr->Disks[col].dev,
+	KASSERT(raidPtr->bytesPerSector);
+	return raidread_component_label(raidPtr->bytesPerSector,
+	    raidPtr->Disks[col].dev,
 	    raidPtr->raid_cinfo[col].ci_vp, 
 	    &raidPtr->raid_cinfo[col].ci_label);
 }
@@ -2451,18 +2500,20 @@
 #ifndef RF_NO_PARITY_MAP
 	label->parity_map_modcount = label->mod_counter;
 #endif
-	return raidwrite_component_label(raidPtr->Disks[col].dev,
+	return raidwrite_component_label(raidPtr->bytesPerSector,
+	    raidPtr->Disks[col].dev,
 	    raidPtr->raid_cinfo[col].ci_vp, label);
 }
 
 
 static int
-raidread_component_label(dev_t dev, struct vnode *b_vp,
+raidread_component_label(unsigned secsize, dev_t dev, struct vnode *b_vp,
     RF_ComponentLabel_t *clabel)
 {
 	return raidread_component_area(dev, b_vp, clabel, 
 	    sizeof(RF_ComponentLabel_t),
-	    RF_COMPONENT_INFO_OFFSET, RF_COMPONENT_INFO_SIZE);
+	    rf_component_info_offset(),
+	    rf_component_info_size(secsize));
 }
 
 /* ARGSUSED */
@@ -2510,12 +2561,13 @@
 
 
 static int
-raidwrite_component_label(dev_t dev, struct vnode *b_vp,
-	RF_ComponentLabel_t *clabel)
+raidwrite_component_label(unsigned secsize, dev_t dev, struct vnode *b_vp,
+    RF_ComponentLabel_t *clabel)
 {
 	return raidwrite_component_area(dev, b_vp, clabel,
 	    sizeof(RF_ComponentLabel_t),
-	    RF_COMPONENT_INFO_OFFSET, RF_COMPONENT_INFO_SIZE, 0);
+	    rf_component_info_offset(),
+	    rf_component_info_size(secsize), 0);
 }
 
 /* ARGSUSED */
@@ -2570,7 +2622,8 @@
 		raidwrite_component_area(raidPtr->Disks[c].dev,
 		    raidPtr->raid_cinfo[c].ci_vp, map,
 		    RF_PARITYMAP_NBYTE,
-		    RF_PARITY_MAP_OFFSET, RF_PARITY_MAP_SIZE, 0);
+		    rf_parity_map_offset(raidPtr),
+		    rf_parity_map_size(raidPtr), 0);
 	}
 }
 
@@ -2588,7 +2641,8 @@
 		raidread_component_area(raidPtr->Disks[c].dev,
 		    raidPtr->raid_cinfo[c].ci_vp, &tmp,
 		    RF_PARITYMAP_NBYTE,
-		    RF_PARITY_MAP_OFFSET, RF_PARITY_MAP_SIZE);
+		    rf_parity_map_offset(raidPtr),
+		    rf_parity_map_size(raidPtr));
 		if (first) {
 			memcpy(map, &tmp, sizeof(*map));
 			first = 0;
@@ -2868,7 +2922,8 @@
 
 static RF_AutoConfig_t *
 rf_get_component(RF_AutoConfig_t *ac_list, dev_t dev, struct vnode *vp,
-    const char *cname, RF_SectorCount_t size)
+    const char *cname, RF_SectorCount_t size, uint64_t numsecs,
+    unsigned secsize)
 {
 	int good_one = 0;
 	RF_ComponentLabel_t *clabel; 
@@ -2888,30 +2943,30 @@
 		    return NULL; /* XXX probably should panic? */
 	}
 
-	if (!raidread_component_label(dev, vp, clabel)) {
-		    /* Got the label.  Does it look reasonable? */
-		    if (rf_reasonable_label(clabel) && 
-			(clabel->partitionSize <= size)) {
+	if (!raidread_component_label(secsize, dev, vp, clabel)) {
+		/* Got the label.  Does it look reasonable? */
+		if (rf_reasonable_label(clabel) && 
+		    (clabel->partitionSize <= size)) {
 #ifdef DEBUG
-			    printf("Component on: %s: %llu\n",
+			printf("Component on: %s: %llu\n",
 				cname, (unsigned long long)size);
-			    rf_print_component_label(clabel);
+			rf_print_component_label(clabel);
 #endif
-			    /* if it's reasonable, add it, else ignore it. */
-			    ac = malloc(sizeof(RF_AutoConfig_t), M_RAIDFRAME,
+			/* if it's reasonable, add it, else ignore it. */
+			ac = malloc(sizeof(RF_AutoConfig_t), M_RAIDFRAME,
 				M_NOWAIT);
-			    if (ac == NULL) {
-				    free(clabel, M_RAIDFRAME);
-				    goto oomem;
-			    }
-			    strlcpy(ac->devname, cname, sizeof(ac->devname));
-			    ac->dev = dev;
-			    ac->vp = vp;
-			    ac->clabel = clabel;
-			    ac->next = ac_list;
-			    ac_list = ac;
-			    good_one = 1;
-		    }
+			if (ac == NULL) {
+				free(clabel, M_RAIDFRAME);
+				goto oomem;
+			}
+			strlcpy(ac->devname, cname, sizeof(ac->devname));
+			ac->dev = dev;
+			ac->vp = vp;
+			ac->clabel = clabel;
+			ac->next = ac_list;
+			ac_list = ac;
+			good_one = 1;
+		}
 	}
 	if (!good_one) {
 		/* cleanup */
@@ -2934,7 +2989,10 @@
 	int error;
 	int i;
 	RF_AutoConfig_t *ac_list;
+	uint64_t numsecs;
+	unsigned secsize;
 
+	RF_ASSERT(raidPtr->bytesPerSector < rf_component_info_offset());
 
 	/* initialize the AutoConfig list */
 	ac_list = NULL;
@@ -2994,6 +3052,11 @@
 			continue;
 		}
 
+		error = getdisksize(vp, &numsecs, &secsize);
+		if (error) {
+			vput(vp);
+			continue;
+		}
 		if (wedge) {
 			struct dkwedge_info dkw;
 			error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD,
@@ -3015,7 +3078,7 @@
 			}
 				
 			ac_list = rf_get_component(ac_list, dev, vp,
-			    device_xname(dv), dkw.dkw_size);
+			    device_xname(dv), dkw.dkw_size, numsecs, secsize);
 			continue;
 		}
 
@@ -3060,7 +3123,7 @@
 			snprintf(cname, sizeof(cname), "%s%c",
 			    device_xname(dv), 'a' + i);
 			ac_list = rf_get_component(ac_list, dev, vp, cname,
-				label.d_partitions[i].p_size);
+				label.d_partitions[i].p_size, numsecs, secsize);
 		}
 	}
 	return ac_list;

Reply via email to