From stijn@pcwin002.win.tue.nl  Thu Dec  8 10:18:07 2005
Return-Path: <stijn@pcwin002.win.tue.nl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 838A716A41F;
	Thu,  8 Dec 2005 10:18:07 +0000 (GMT)
	(envelope-from stijn@pcwin002.win.tue.nl)
Received: from pastinakel.tue.nl (pastinakel.tue.nl [131.155.2.7])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B2E1643D62;
	Thu,  8 Dec 2005 10:17:55 +0000 (GMT)
	(envelope-from stijn@pcwin002.win.tue.nl)
Received: from localhost (localhost [127.0.0.1])
	by pastinakel.tue.nl (Postfix) with ESMTP id 079E614BD3B;
	Thu,  8 Dec 2005 11:17:49 +0100 (CET)
Received: from pastinakel.tue.nl ([127.0.0.1])
 by localhost (pastinakel.tue.nl [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 70333-08; Thu,  8 Dec 2005 11:17:48 +0100 (CET)
Received: from umta.win.tue.nl (umta.win.tue.nl [131.155.71.100])
	by pastinakel.tue.nl (Postfix) with ESMTP id 0635D14BD1A;
	Thu,  8 Dec 2005 11:17:48 +0100 (CET)
Received: from pcwin002.win.tue.nl (pcwin002 [131.155.71.72])
	by umta.win.tue.nl (Postfix) with ESMTP id 035D831401C;
	Thu,  8 Dec 2005 11:17:48 +0100 (CET)
Received: by pcwin002.win.tue.nl (Postfix, from userid 1001)
	id DC76040B8; Thu,  8 Dec 2005 11:17:47 +0100 (CET)
Message-Id: <20051208101747.GB912@pcwin002.win.tue.nl>
Date: Thu, 8 Dec 2005 11:17:47 +0100
From: Stijn Hoop <stijn@win.tue.nl>
To: Lukas Ertl <le@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
In-Reply-To: <20051207084253.GO855@pcwin002.win.tue.nl>
Subject: [PATCH] for kern/89660
References: <200511281310.jASDAAlX013752@freefall.freebsd.org>

>Number:         90100
>Category:       kern
>Synopsis:       [PATCH] for kern/89660
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 08 10:20:02 GMT 2005
>Closed-Date:    Thu Dec 08 17:03:48 GMT 2005
>Last-Modified:  Mon Jul 02 06:02:50 GMT 2007
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 --Nq2Wo0NMKNjxTN9z
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hi,
 
 The previous patch had a minor problem on boot, because the drive init
 was also done somewhere else and I missed that one. The attached patch
 appears to work on a gvinum mirror volume.
 
 Being brave I decided to run this on the machine that panics on random
 nights. Let's hope it survives for > 1 week. If only I could reproduce
 the panic :(
 
 If this patch is bogus in some way please let me know; it certainly
 appears to work fine but as stated in my previous e-mail this is my
 first time hacking the kernel, I may certainly have missed some
 serious interaction bugs.
 
 --Stijn
 
 -- 
 "Diane, 2:15 in the afternoon, November 14. Entering town of Twin Peaks.
  Five miles south of the Canadian border, twelve miles west of the state
  line. Never seen so many trees in my life. As W.C. Fields would say, I'd
  rather be here than Philadelphia."
 		-- Special Agent Dale Cooper, "Twin Peaks"
 
 --Nq2Wo0NMKNjxTN9z
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="gvinum-tested.patch"
 
 Index: geom_vinum_drive.c
 ===================================================================
 RCS file: /net/freebsd/cvsroot/src/sys/geom/vinum/geom_vinum_drive.c,v
 retrieving revision 1.18.2.2
 diff -u -u -r1.18.2.2 geom_vinum_drive.c
 --- geom_vinum_drive.c	9 Oct 2005 04:34:29 -0000	1.18.2.2
 +++ geom_vinum_drive.c	8 Dec 2005 09:28:01 -0000
 @@ -79,6 +79,7 @@
  	d->freelist_entries = 1;
  
  	TAILQ_INIT(&d->bqueue);
 +	TAILQ_INIT(&d->reserve);
  	mtx_init(&d->bqueue_mtx, "gv_drive", NULL, MTX_DEF);
  	kthread_create(gv_drive_worker, d, NULL, 0, 0, "gv_d %s", d->name);
  	d->flags |= GV_DRIVE_THREAD_ACTIVE;
 @@ -241,9 +242,11 @@
  	/* Put the BIO on the worker queue again. */
  	d = bp->bio_from->geom->softc;
  	bp->bio_cflags |= GV_BIO_DONE;
 -	bq = g_malloc(sizeof(*bq), M_NOWAIT | M_ZERO);
 -	bq->bp = bp;
 +	/* XXX: do not malloc but get the next reserve bioq */
  	mtx_lock(&d->bqueue_mtx);
 +	bq = TAILQ_FIRST(&d->reserve);
 +	TAILQ_REMOVE(&d->reserve, bq, queue);
 +	bq->bp = bp;
  	TAILQ_INSERT_TAIL(&d->bqueue, bq, queue);
  	wakeup(d);
  	mtx_unlock(&d->bqueue_mtx);
 @@ -361,6 +364,18 @@
  				mtx_lock(&d->bqueue_mtx);
  				continue;
  			}
 +
 +			bq2 = g_malloc(sizeof(*bq2), M_WAITOK | M_ZERO);
 +			if (bq2 == NULL) {
 +				g_io_deliver(bp, ENOMEM);
 +				mtx_lock(&d->bqueue_mtx);
 +				continue;
 +			}
 +
 +			mtx_lock(&d->bqueue_mtx);
 +			TAILQ_INSERT_HEAD(&d->reserve, bq2, queue);
 +			mtx_unlock(&d->bqueue_mtx);
 +
  			if (cbp->bio_offset + cbp->bio_length > s->size)
  				cbp->bio_length = s->size -
  				    cbp->bio_offset;
 @@ -498,6 +513,7 @@
  			d->freelist_entries = 1;
  
  			TAILQ_INIT(&d->bqueue);
 +			TAILQ_INIT(&d->reserve);
  
  			/* Save it into the main configuration. */
  			LIST_INSERT_HEAD(&sc->drives, d, drive);
 Index: geom_vinum_var.h
 ===================================================================
 RCS file: /net/freebsd/cvsroot/src/sys/geom/vinum/geom_vinum_var.h,v
 retrieving revision 1.8.2.1
 diff -u -u -r1.8.2.1 geom_vinum_var.h
 --- geom_vinum_var.h	19 Aug 2005 08:48:04 -0000	1.8.2.1
 +++ geom_vinum_var.h	7 Dec 2005 08:22:49 -0000
 @@ -203,6 +203,9 @@
  
  	struct g_geom	*geom;			/* The geom of this drive. */
  	struct gv_softc	*vinumconf;		/* Pointer to the vinum conf. */
 +
 +	/* XXX: bioq gv_drive_done reserve, also protected by bqueue_mtx */
 +	TAILQ_HEAD(,gv_bioq)	reserve;	/* To avoid running out of mem */
  };
  
  /* softc for a subdisk. */
 
 --Nq2Wo0NMKNjxTN9z--
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Thu Dec 8 17:01:42 GMT 2005 
State-Changed-Why:  
Misfiled followup to kern/89660; content migrated. 
 
To submitter: please use the canonical form of the Synopsis line to avoid 
this problem in the future, e.g.: 
 
Re: kern/89660: [panic] due to g_malloc returning null in gv_drive_done 
 
 
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Dec 8 17:01:42 GMT 2005 
Responsible-Changed-Why:  
 
http://www.freebsd.org/cgi/query-pr.cgi?pr=90100 
>Unformatted:
