Early serial console slowness and reboot - cvs diff

Andrew Randrianasulu <[email protected]> Tue, 24 Feb 2009 12:32:20 -0800 (PST)
Newsgroups gmane.os.netbsd.ports.sgimips
Message-ID <[email protected]>
command was 

cvs diff -D 20090210 -D 20090211 -u src/sys > diff-20090210-20090211-src-sys.diff

for me only changes to bus.h looks potentially troublesome. May be somewhere code was not updated to reflect this change?
diff-20090210-20090211-src-sys.diff (application/octet-stream, 19.2 KB)
? src/sys/arch/sgimips/conf/sgi-O2
Index: src/sys/arch/sgimips/README.IPn
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/README.IPn,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- src/sys/arch/sgimips/README.IPn	22 Dec 2006 01:32:37 -0000	1.9
+++ src/sys/arch/sgimips/README.IPn	10 Feb 2009 06:12:27 -0000	1.10
@@ -1,4 +1,4 @@
-$NetBSD: README.IPn,v 1.9 2006/12/22 01:32:37 rumble Exp $
+$NetBSD: README.IPn,v 1.10 2009/02/10 06:12:27 rumble Exp $
 
 Arch (kernel)	Models				Codename
 -------------	------				--------
@@ -6,8 +6,8 @@
 IP4		4D/50, 4D/70
 IP4.5		4D/60, 4D/80, 4D/85
 IP5		4D/1x0
-IP6		4D/20
-IP10 (IP6)	4D/25
+IP6		4D/20				Eclipse
+IP10 (IP6)	4D/25				Eclipse
 IP7		4D/2x0
 IP9		4D/210
 IP13 (IP7)	4D/3x0
Index: src/sys/arch/sgimips/gio/gio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/gio.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- src/sys/arch/sgimips/gio/gio.c	22 Feb 2007 16:54:26 -0000	1.29
+++ src/sys/arch/sgimips/gio/gio.c	10 Feb 2009 06:11:49 -0000	1.30
@@ -1,4 +1,4 @@
-/*	$NetBSD: gio.c,v 1.29 2007/02/22 16:54:26 thorpej Exp $	*/
+/*	$NetBSD: gio.c,v 1.30 2009/02/10 06:11:49 rumble Exp $	*/
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gio.c,v 1.29 2007/02/22 16:54:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gio.c,v 1.30 2009/02/10 06:11:49 rumble Exp $");
 
 #include "opt_ddb.h"
 
@@ -176,8 +176,11 @@
 static int
 gio_match(struct device *parent, struct cfdata *match, void *aux)
 {
-
-	return 1;
+	if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20 ||
+	    mach_type == MACH_SGI_IP22)
+		return 1;
+	
+	return 0;
 }
 
 static void
Index: src/sys/arch/sgimips/gio/newport.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/newport.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- src/sys/arch/sgimips/gio/newport.c	4 Mar 2007 06:00:39 -0000	1.10
+++ src/sys/arch/sgimips/gio/newport.c	10 Feb 2009 03:40:26 -0000	1.11
@@ -1,4 +1,4 @@
-/*	$NetBSD: newport.c,v 1.10 2007/03/04 06:00:39 christos Exp $	*/
+/*	$NetBSD: newport.c,v 1.11 2009/02/10 03:40:26 macallan Exp $	*/
 
 /*
  * Copyright (c) 2003 Ilpo Ruotsalainen
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: newport.c,v 1.10 2007/03/04 06:00:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: newport.c,v 1.11 2009/02/10 03:40:26 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -407,7 +407,22 @@
 	uint32_t tmp;
 
 	rex3_wait_gfifo(dc);
-	
+	if (dy > y1) {
+		/* need to copy bottom up */
+		dy += (y2 - y1);
+		tmp = y2;
+		y2 = y1;
+		y1 = tmp;
+	}
+
+	if (dx > x1) {
+		/* need to copy right to left */
+		dx += (x2 - x1);
+		tmp = x2;
+		x2 = x1;
+		x1 = tmp;
+	}
+
 	rex3_write(dc, REX3_REG_DRAWMODE0, REX3_DRAWMODE0_OPCODE_SCR2SCR |
 	    REX3_DRAWMODE0_ADRMODE_BLOCK | REX3_DRAWMODE0_DOSETUP |
 	    REX3_DRAWMODE0_STOPONX | REX3_DRAWMODE0_STOPONY);
@@ -696,10 +711,10 @@
 		    control & ~VC2_CONTROL_CURSOR_ENABLE);
 	} else {
 		/* Work around bug in some board revisions */
-		if (dc->dc_boardrev < 6)
-			x_offset = 21;
-		else if (dc->dc_vc2rev == 0) 
+		if (dc->dc_vc2rev == 0) 
 			x_offset = 29;
+		else if (dc->dc_boardrev < 6)
+			x_offset = 21;
 		else
 			x_offset = 31;
 
@@ -783,7 +798,7 @@
 	newport_copy_rectangle(dc,
 	    srccol * font->fontwidth,			/* x1 */
 	    row * font->fontheight,			/* y1 */
-	    (srccol + ncols + 1) * font->fontwidth - 1,	/* x2 */
+	    (srccol + ncols) * font->fontwidth - 1,	/* x2 */
 	    (row + 1) * font->fontheight - 1,		/* y2 */
 	    dstcol * font->fontheight,			/* dx */
 	    row * font->fontheight);			/* dy */
@@ -799,7 +814,7 @@
 	newport_fill_rectangle(dc,
 	    startcol * font->fontwidth,				/* x1 */
 	    row * font->fontheight,				/* y1 */
-	    (startcol + ncols + 1) * font->fontwidth - 1,	/* x2 */
+	    (startcol + ncols) * font->fontwidth - 1,		/* x2 */
 	    (row + 1) * font->fontheight - 1,			/* y2 */
 	    NEWPORT_ATTR_BG(attr));
 }
@@ -814,7 +829,7 @@
 	    0,							/* x1 */
 	    srcrow * font->fontheight,				/* y1 */
 	    dc->dc_xres,					/* x2 */
-	    (srcrow + nrows + 1) * font->fontheight - 1,	/* y2 */
+	    (srcrow + nrows) * font->fontheight - 1,		/* y2 */
 	    0,							/* dx */
 	    dstrow * font->fontheight);				/* dy */
 }
@@ -829,7 +844,7 @@
 	    0,							/* x1 */
 	    startrow * font->fontheight,			/* y1 */
 	    dc->dc_xres,					/* x2 */
-	    (startrow + nrows + 1) * font->fontheight - 1,	/* y2 */
+	    (startrow + nrows) * font->fontheight - 1,		/* y2 */
 	    NEWPORT_ATTR_BG(attr));
 }
 
Index: src/sys/arch/sgimips/gio/newportreg.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/newportreg.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- src/sys/arch/sgimips/gio/newportreg.h	11 Dec 2005 12:18:53 -0000	1.3
+++ src/sys/arch/sgimips/gio/newportreg.h	10 Feb 2009 03:35:29 -0000	1.4
@@ -1,5 +1,5 @@
 
-/*	$NetBSD: newportreg.h,v 1.3 2005/12/11 12:18:53 christos Exp $	*/
+/*	$NetBSD: newportreg.h,v 1.4 2009/02/10 03:35:29 macallan Exp $	*/
 
 /*
  * Copyright (c) 2003 Ilpo Ruotsalainen
@@ -128,7 +128,13 @@
 #define  REX3_DRAWMODE0_LSADVLAST	0x00004000
 #define  REX3_DRAWMODE0_LENGTH32	0x00008000
 #define  REX3_DRAWMODE0_ZPOPAQUE	0x00010000
-
+#define  REX3_DRAWMODE0_LSOPAQUE	0x00020000
+#define  REX3_DRAWMODE0_SHADE		0x00040000
+#define  REX3_DRAWMODE0_LRONLY		0x00080000
+#define  REX3_DRAWMODE0_XYOFFSET	0x00100000
+#define  REX3_DRAWMODE0_CICLAMP		0x00200000
+#define  REX3_DRAWMODE0_ENDPTFILTER	0x00400000
+#define  REX3_DRAWMODE0_YSTRIDE		0x00800000
 #define REX3_REG_LSMODE			0x0008
 
 #define REX3_REG_LSPATTERN		0x000c
Index: src/sys/arch/sgimips/include/bus.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/include/bus.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- src/sys/arch/sgimips/include/bus.h	28 Apr 2008 20:23:34 -0000	1.27
+++ src/sys/arch/sgimips/include/bus.h	10 Feb 2009 06:10:50 -0000	1.28
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.h,v 1.27 2008/04/28 20:23:34 martin Exp $	*/
+/*	$NetBSD: bus.h,v 1.28 2009/02/10 06:10:50 rumble Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -59,11 +59,12 @@
  * Values for sgimips bus space tag, not to be used directly by MI code.
  */
 #define	SGIMIPS_BUS_SPACE_NORMAL	0
-#define	SGIMIPS_BUS_SPACE_HPC		1
-#define	SGIMIPS_BUS_SPACE_MEM		2
-#define	SGIMIPS_BUS_SPACE_MACE		3
-#define	SGIMIPS_BUS_SPACE_IO		4
-#define SGIMIPS_BUS_SPACE_CRIME		5
+#define	SGIMIPS_BUS_SPACE_IP6_DPCLOCK	1
+#define	SGIMIPS_BUS_SPACE_HPC		2
+#define	SGIMIPS_BUS_SPACE_MEM		3
+#define	SGIMIPS_BUS_SPACE_MACE		4
+#define	SGIMIPS_BUS_SPACE_IO		5
+#define	SGIMIPS_BUS_SPACE_CRIME		6
 
 /* Initialization for bus_dmamap_sync, which differs from MIPS1 to MIPS3 */
 
Index: src/sys/arch/sgimips/include/machtype.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/include/machtype.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- src/sys/arch/sgimips/include/machtype.h	22 Dec 2006 01:32:37 -0000	1.6
+++ src/sys/arch/sgimips/include/machtype.h	10 Feb 2009 06:10:50 -0000	1.7
@@ -1,4 +1,4 @@
-/*	$NetBSD: machtype.h,v 1.6 2006/12/22 01:32:37 rumble Exp $	*/
+/*	$NetBSD: machtype.h,v 1.7 2009/02/10 06:10:50 rumble Exp $	*/
 
 /*
  * Copyright (c) 2001 Rafal K. Boni
@@ -39,13 +39,14 @@
 #define MACH_SGI_IP6		6	/* 4D/20 */
 #define MACH_SGI_IP7		7	/* 4D/2x0, 4D/3x0, 4D/4x0 */
 #define MACH_SGI_IP9		9	/* 4D/210 */
-#define MACH_SGI_IP10		10	/* 4D/25 */
+#define MACH_SGI_IP10	MACH_SGI_IP6	/* 4D/25 */
 #define MACH_SGI_IP12		12	/* 4D/30, 4D/35, Indigo R3K */
 #define MACH_SGI_IP17		17	/* Crimson */
 #define MACH_SGI_IP19		19	/* Onyx, Challenge M/L(/XL?) */
 #define MACH_SGI_IP20		20	/* Indigo R4K */
 #define MACH_SGI_IP21		21	/* Power Challenge, Power Onyx */
-#define MACH_SGI_IP22		22	/* Indigo2, Indy, Challenge S */
+#define MACH_SGI_IP22		22	/* Indigo2, Challenge M */
+#define MACH_SGI_IP24	MACH_SGI_IP22	/* Indy, Challenge S */
 #define MACH_SGI_IP25		25	/* Power Challenge R10K */
 #define MACH_SGI_IP26		26	/* Power Indigo2 R8K ("Teton") */
 #define MACH_SGI_IP27		27	/* Origin 200, Origin 2000, Onyx2 */
Index: src/sys/dev/ata/wd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/wd.c,v
retrieving revision 1.369
retrieving revision 1.370
diff -u -r1.369 -r1.370
--- src/sys/dev/ata/wd.c	9 Feb 2009 22:34:23 -0000	1.369
+++ src/sys/dev/ata/wd.c	10 Feb 2009 19:45:22 -0000	1.370
@@ -1,4 +1,4 @@
-/*	$NetBSD: wd.c,v 1.369 2009/02/09 22:34:23 tron Exp $ */
+/*	$NetBSD: wd.c,v 1.370 2009/02/10 19:45:22 tron Exp $ */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.369 2009/02/09 22:34:23 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.370 2009/02/10 19:45:22 tron Exp $");
 
 #include "opt_ata.h"
 
@@ -245,12 +245,8 @@
 	  WD_QUIRK_FORCE_LBA48 },
 	{ "ST3160023A*",
 	  WD_QUIRK_FORCE_LBA48 },
-	{ "ST3160815A*",
-	  WD_QUIRK_FORCE_LBA48 },
 	{ "ST3160827A*",
 	  WD_QUIRK_FORCE_LBA48 },
-	{ "FB160C4081",
-	  WD_QUIRK_FORCE_LBA48 },
 	/* Attempt to catch all seagate drives larger than 200GB */
 	{ "ST3[2-9][0-9][0-9][0-9][0-9][0-9][A-Z]*",
 	  WD_QUIRK_FORCE_LBA48 },
Index: src/sys/dev/usb/usb_mem.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usb_mem.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- src/sys/dev/usb/usb_mem.c	28 Jun 2008 17:42:53 -0000	1.37
+++ src/sys/dev/usb/usb_mem.c	10 Feb 2009 17:00:06 -0000	1.38
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_mem.c,v 1.37 2008/06/28 17:42:53 bouyer Exp $	*/
+/*	$NetBSD: usb_mem.c,v 1.38 2009/02/10 17:00:06 drochner Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.37 2008/06/28 17:42:53 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.38 2009/02/10 17:00:06 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -303,7 +303,7 @@
 	u_long start;
 	bus_addr_t baddr;
 
-	if (rs->vaddr == 0)
+	if (rs->vaddr == 0 || size > USB_MEM_RESERVE)
 		return USBD_NOMEM;
 
 	dma->block = malloc(sizeof *dma->block, M_USB, M_ZERO | M_NOWAIT);
@@ -378,7 +378,7 @@
 
 	rs->paddr = rs->map->dm_segs[0].ds_addr;
 	rs->extent = extent_create(device_xname(dv), (u_long)rs->paddr,
-	    (u_long)(rs->paddr + USB_MEM_RESERVE),
+	    (u_long)(rs->paddr + USB_MEM_RESERVE - 1),
 	    M_USB, 0, 0, 0);
 	if (rs->extent == NULL) {
 		rs->vaddr = 0;
Index: src/sys/fs/udf/udf_strat_direct.c
===================================================================
RCS file: /cvsroot/src/sys/fs/udf/udf_strat_direct.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- src/sys/fs/udf/udf_strat_direct.c	8 Feb 2009 19:14:52 -0000	1.8
+++ src/sys/fs/udf/udf_strat_direct.c	10 Feb 2009 17:49:02 -0000	1.9
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_strat_direct.c,v 1.8 2009/02/08 19:14:52 reinoud Exp $ */
+/* $NetBSD: udf_strat_direct.c,v 1.9 2009/02/10 17:49:02 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_strat_direct.c,v 1.8 2009/02/08 19:14:52 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_strat_direct.c,v 1.9 2009/02/10 17:49:02 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -301,23 +301,10 @@
 			"type %d, b_resid %d, b_bcount %d, b_bufsize %d\n",
 			buf, (uint32_t) buf->b_blkno / blks, buf->b_udf_c_type,
 			buf->b_resid, buf->b_bcount, buf->b_bufsize));
-		/* if we have FIDs fixup using buffer's sector number(s) */
-		if (buf->b_udf_c_type == UDF_C_FIDS) {
-			panic("UDF_C_FIDS in SHED_WRITING!\n");
-			buf_len = buf->b_bcount;
-			sectornr = our_sectornr;
-			bpos = 0;
-			while (buf_len) {
-				len = MIN(buf_len, sector_size);
-				fidblk = (uint8_t *) buf->b_data + bpos;
-				udf_fixup_fid_block(fidblk, sector_size,
-					0, len, sectornr);
-				sectornr++;
-				bpos += len;
-				buf_len -= len;
-			}
-		}
-		udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
+		KASSERT(buf->b_udf_c_type == UDF_C_DSCR || 
+			buf->b_udf_c_type == UDF_C_ABSOLUTE ||
+			buf->b_udf_c_type == UDF_C_NODE);
+		 udf_fixup_node_internals(ump, buf->b_data, buf->b_udf_c_type);
 		VOP_STRATEGY(ump->devvp, buf);
 		return;
 	}
Index: src/sys/fs/udf/udf_strat_sequential.c
===================================================================
RCS file: /cvsroot/src/sys/fs/udf/udf_strat_sequential.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- src/sys/fs/udf/udf_strat_sequential.c	8 Feb 2009 19:14:52 -0000	1.8
+++ src/sys/fs/udf/udf_strat_sequential.c	10 Feb 2009 17:48:19 -0000	1.9
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_strat_sequential.c,v 1.8 2009/02/08 19:14:52 reinoud Exp $ */
+/* $NetBSD: udf_strat_sequential.c,v 1.9 2009/02/10 17:48:19 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_strat_sequential.c,v 1.8 2009/02/08 19:14:52 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_strat_sequential.c,v 1.9 2009/02/10 17:48:19 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -518,10 +518,10 @@
 
 	if (bufq_peek(priv->queues[UDF_SHED_READING]))
 		new_queue = UDF_SHED_READING;
-	if (bufq_peek(priv->queues[UDF_SHED_SEQWRITING]))
-		new_queue = UDF_SHED_SEQWRITING;
 	if (bufq_peek(priv->queues[UDF_SHED_WRITING]))		/* only for unmount */
 		new_queue = UDF_SHED_WRITING;
+	if (bufq_peek(priv->queues[UDF_SHED_SEQWRITING]))
+		new_queue = UDF_SHED_SEQWRITING;
 	if (priv->cur_queue == UDF_SHED_READING) {
 		if (new_queue == UDF_SHED_SEQWRITING) {
 			/* TODO use flag to signal if this is needed */
Index: src/sys/fs/udf/udf_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/udf/udf_vnops.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- src/sys/fs/udf/udf_vnops.c	16 Dec 2008 14:28:34 -0000	1.34
+++ src/sys/fs/udf/udf_vnops.c	10 Feb 2009 21:24:27 -0000	1.35
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_vnops.c,v 1.34 2008/12/16 14:28:34 reinoud Exp $ */
+/* $NetBSD: udf_vnops.c,v 1.35 2009/02/10 21:24:27 reinoud Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.34 2008/12/16 14:28:34 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.35 2009/02/10 21:24:27 reinoud Exp $");
 #endif /* not lint */
 
 
@@ -273,8 +273,9 @@
 	struct udf_node      *udf_node = VTOI(vp);
 	struct file_entry    *fe;
 	struct extfile_entry *efe;
-	uint64_t file_size, old_size;
+	uint64_t file_size, old_size, old_offset;
 	vsize_t len;
+	int async = vp->v_mount->mnt_flag & MNT_ASYNC;
 	int error;
 	int resid, extended;
 
@@ -342,10 +343,22 @@
 			break;
 
 		/* ubc, here we come, prepare to trap */
+		old_offset = uio->uio_offset;
 		error = ubc_uiomove(uobj, uio, len, advice,
 		    UBC_WRITE | UBC_UNMAP_FLAG(vp));
 		if (error)
 			break;
+
+		/*
+		 * flush what we just wrote if necessary.
+		 * XXXUBC simplistic async flushing.
+		 */
+
+		if (!async && old_offset >> 16 != uio->uio_offset >> 16) {
+			mutex_enter(&vp->v_interlock);
+			error = VOP_PUTPAGES(vp, (old_offset >> 16) << 16,
+			    (uio->uio_offset >> 16) << 16, PGO_CLEANIT);
+		}
 	}
 	uvm_vnp_setsize(vp, file_size);
 
Index: src/sys/rump/librump/rumpvfs/rumpblk.c
===================================================================
RCS file: /cvsroot/src/sys/rump/librump/rumpvfs/rumpblk.c,v
retrieving revision 1.2
retrieving revision 1.4
diff -u -r1.2 -r1.4
--- src/sys/rump/librump/rumpvfs/rumpblk.c	27 Jan 2009 09:14:01 -0000	1.2
+++ src/sys/rump/librump/rumpvfs/rumpblk.c	10 Feb 2009 20:44:57 -0000	1.4
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpblk.c,v 1.2 2009/01/27 09:14:01 pooka Exp $	*/
+/*	$NetBSD: rumpblk.c,v 1.4 2009/02/10 20:44:57 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.2 2009/01/27 09:14:01 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.4 2009/02/10 20:44:57 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -66,6 +66,7 @@
 dev_type_write(rumpblk_write);
 dev_type_ioctl(rumpblk_ioctl);
 dev_type_strategy(rumpblk_strategy);
+dev_type_strategy(rumpblk_strategy_fail);
 dev_type_dump(rumpblk_dump);
 dev_type_size(rumpblk_size);
 
@@ -74,20 +75,53 @@
 	nodump, nosize, D_DISK
 };
 
+static const struct bdevsw rumpblk_bdevsw_fail = {
+	rumpblk_open, rumpblk_close, rumpblk_strategy_fail, rumpblk_ioctl,
+	nodump, nosize, D_DISK
+};
+
 static const struct cdevsw rumpblk_cdevsw = {
 	rumpblk_open, rumpblk_close, rumpblk_read, rumpblk_write,
 	rumpblk_ioctl, nostop, notty, nopoll, nommap, nokqfilter, D_DISK
 };
 
-/* XXX: not mpsafe */
+/* fail every n out of BLKFAIL_MAX */
+#define BLKFAIL_MAX 10000
+static int blkfail;
+static unsigned randstate;
 
 int
 rumpblk_init()
 {
+	char buf[64];
 	int rumpblk = RUMPBLK;
+	int error;
 
-	return devsw_attach("rumpblk", &rumpblk_bdevsw, &rumpblk,
-	    &rumpblk_cdevsw, &rumpblk);
+	if (rumpuser_getenv("RUMP_BLKFAIL", buf, sizeof(buf), &error) == 0) {
+		blkfail = strtoul(buf, NULL, 10);
+		/* fail everything */
+		if (blkfail > BLKFAIL_MAX)
+			blkfail = BLKFAIL_MAX;
+		if (rumpuser_getenv("RUMP_BLKFAIL_SEED", buf, sizeof(buf),
+		    &error) == 0) {
+			randstate = strtoul(buf, NULL, 10);
+		} else {
+			randstate = arc4random(); /* XXX: not enough entropy */
+		}
+		printf("rumpblk: FAULT INJECTION ACTIVE!  every %d out of"
+		    " %d I/O will fail.  key %u\n", blkfail, BLKFAIL_MAX,
+		    randstate);
+	} else {
+		blkfail = 0;
+	}
+
+	if (blkfail) {
+		return devsw_attach("rumpblk", &rumpblk_bdevsw_fail, &rumpblk,
+		    &rumpblk_cdevsw, &rumpblk);
+	} else {
+		return devsw_attach("rumpblk", &rumpblk_bdevsw, &rumpblk,
+		    &rumpblk_cdevsw, &rumpblk);
+	}
 }
 
 int
@@ -203,8 +237,8 @@
 	panic("%s: unimplemented", __func__);
 }
 
-void
-rumpblk_strategy(struct buf *bp)
+static void
+dostrategy(struct buf *bp)
 {
 	struct rblkdev *rblk = &minors[minor(bp->b_dev)];
 	off_t off;
@@ -278,3 +312,43 @@
 		}
 	}
 }
+
+void
+rumpblk_strategy(struct buf *bp)
+{
+
+	dostrategy(bp);
+}
+
+/*
+ * Simple random number generator.  This is private so that we can
+ * very repeatedly control which blocks will fail.
+ *
+ * <mlelstv> pooka, rand()
+ * <mlelstv> [paste]
+ */
+static unsigned
+gimmerand(void)
+{
+
+	return (randstate = randstate * 1103515245 + 12345) % (0x80000000L);
+}
+
+/*
+ * Block device with very simple fault injection.  Fails every
+ * n out of BLKFAIL_MAX I/O with EIO.  n is determined by the env
+ * variable RUMP_BLKFAIL.
+ */
+void
+rumpblk_strategy_fail(struct buf *bp)
+{
+
+	if (gimmerand() % BLKFAIL_MAX >= blkfail) {
+		dostrategy(bp);
+	} else { 
+		printf("block fault injection: failing I/O on block %lld\n",
+		    (long long)bp->b_blkno);
+		bp->b_error = EIO;
+		biodone(bp);
+	}
+}