From hampi@rootshell.be  Sat Aug 20 18:50:34 2005
Return-Path: <hampi@rootshell.be>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 861B616A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 20 Aug 2005 18:50:34 +0000 (GMT)
	(envelope-from hampi@rootshell.be)
Received: from mail20.bluewin.ch (mail20.bluewin.ch [195.186.19.65])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E9A3743D45
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 20 Aug 2005 18:50:33 +0000 (GMT)
	(envelope-from hampi@rootshell.be)
Received: from twelvegates.homeip.net (83.77.209.32) by mail20.bluewin.ch (Bluewin 7.2.063)
        id 42D281C400605C6E for FreeBSD-gnats-submit@freebsd.org; Sat, 20 Aug 2005 18:50:30 +0000
Received: from goofy.here (localhost [127.0.0.1])
	by twelvegates.homeip.net (8.13.4/8.13.4) with ESMTP id j7KIoWo9000895
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 20 Aug 2005 20:50:32 +0200 (CEST)
	(envelope-from idefix@goofy.here)
Received: (from idefix@localhost)
	by goofy.here (8.13.4/8.13.4/Submit) id j7KIoWON000894;
	Sat, 20 Aug 2005 20:50:32 +0200 (CEST)
	(envelope-from idefix)
Message-Id: <200508201850.j7KIoWON000894@goofy.here>
Date: Sat, 20 Aug 2005 20:50:32 +0200 (CEST)
From: Hanspeter Roth <hampi@rootshell.be>
Reply-To: hampi@rootshell.be
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Giving up on 2 buffers with readonly mounted ext2fs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         85163
>Category:       kern
>Synopsis:       Giving up on 2 buffers with readonly mounted ext2fs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    truckman
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 20 19:00:43 GMT 2005
>Closed-Date:    Fri Sep 16 03:01:29 GMT 2005
>Last-Modified:  Fri Sep 16 03:01:29 GMT 2005
>Originator:     Hanspeter Roth
>Release:        FreeBSD 6.0-BETA2 i386
>Organization:
>Environment:
System: FreeBSD goofy.here 6.0-BETA2 FreeBSD 6.0-BETA2 #0: Wed Aug 3 08:22:24 UTC 2005 root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386


	USB-disk with two ext2fs slices
>Description:
	If an ext2fs slice on a USB-disk is mounted readonly during reboot
	FreeBSD has 2 buffers remaining.
>How-To-Repeat:
	boot Linux
	fsck -f /dev/sda1
	fsck -f /dev/sda2

	boot FreeBSD 6.0-BETA2
	mount -r -t ext2fs /dev/da0s1 /mnt
	reboot
	Syncing disks, buffers remaining... 2 2 2 2 ...
	Giving up on 2 buffers

	boot Linux
	fsck /dev/sda1
	/dev/sda1 was not cleanly unmounted, check forced.
>Fix:

	


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: truckman 
State-Changed-When: Wed Sep 7 01:01:47 GMT 2005 
State-Changed-Why:  
The patch below was sent to the PR submitter for testing: 

Index: sys/kern/kern_shutdown.c 
=================================================================== 
RCS file: /home/ncvs/src/sys/kern/kern_shutdown.c,v 
retrieving revision 1.174 
diff -u -r1.174 kern_shutdown.c 
--- sys/kern/kern_shutdown.c	12 Apr 2005 05:45:58 -0000	1.174 
+++ sys/kern/kern_shutdown.c	5 Sep 2005 19:21:38 -0000 
@@ -236,6 +236,16 @@ 
dumpsys(&dumper); 
} 

+static int 
+isbufbusy(struct buf *bp) 
+{ 
+	if (((bp->b_flags & (B_INVAL | B_PERSISTENT)) == 0 && 
+	    BUF_REFCNT(bp) > 0) || 
+	    ((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI)) 
+		return (1); 
+	return (0); 
+} 
+ 
/* 
* Shutdown the system cleanly to prepare for reboot, halt, or power off. 
*/ 
@@ -288,16 +298,9 @@ 
*/ 
for (iter = pbusy = 0; iter < 20; iter++) { 
nbusy = 0; 
-			for (bp = &buf[nbuf]; --bp >= buf; ) { 
-				if ((bp->b_flags & B_INVAL) == 0 && 
-				    BUF_REFCNT(bp) > 0) { 
+			for (bp = &buf[nbuf]; --bp >= buf; ) 
+				if (isbufbusy(bp)) 
nbusy++; 
-				} else if ((bp->b_flags & (B_DELWRI | B_INVAL)) 
-						== B_DELWRI) { 
-					/* bawrite(bp);*/ 
-					nbusy++; 
-				} 
-			} 
if (nbusy == 0) { 
if (first_buf_printf) 
printf("All buffers synced."); 
@@ -343,8 +346,7 @@ 
*/ 
nbusy = 0; 
for (bp = &buf[nbuf]; --bp >= buf; ) { 
-			if (((bp->b_flags&B_INVAL) == 0 && BUF_REFCNT(bp)) || 
-			    ((bp->b_flags & (B_DELWRI|B_INVAL)) == B_DELWRI)) { 
+			if (isbufbusy(bp)) { 
#if 0 
/* XXX: This is bogus.  We should probably have a BO_REMOTE flag instead */ 
if (bp->b_dev == NULL) { 
Index: sys/kern/vfs_bio.c 
=================================================================== 
RCS file: /home/ncvs/src/sys/kern/vfs_bio.c,v 
retrieving revision 1.493 
diff -u -r1.493 vfs_bio.c 
--- sys/kern/vfs_bio.c	3 Aug 2005 05:02:08 -0000	1.493 
+++ sys/kern/vfs_bio.c	5 Sep 2005 07:46:49 -0000 
@@ -1365,7 +1365,8 @@ 
if (bp->b_bufsize || bp->b_kvasize) 
bufspacewakeup(); 

-	bp->b_flags &= ~(B_ASYNC | B_NOCACHE | B_AGE | B_RELBUF | B_DIRECT); 
+	bp->b_flags &= ~(B_ASYNC | B_NOCACHE | B_AGE | B_RELBUF | B_DIRECT | 
+	    B_PERSISTENT); 
if ((bp->b_flags & B_DELWRI) == 0 && (bp->b_xflags & BX_VNDIRTY)) 
panic("brelse: not dirty"); 
/* unlock */ 
Index: sys/sys/buf.h 
=================================================================== 
RCS file: /home/ncvs/src/sys/sys/buf.h,v 
retrieving revision 1.188 
diff -u -r1.188 buf.h 
--- sys/sys/buf.h	13 Aug 2005 20:21:33 -0000	1.188 
+++ sys/sys/buf.h	5 Sep 2005 19:36:24 -0000 
@@ -195,7 +195,7 @@ 
#define	B_CACHE		0x00000020	/* Bread found us in the cache. */ 
#define	B_VALIDSUSPWRT	0x00000040	/* Valid write during suspension. */ 
#define	B_DELWRI	0x00000080	/* Delay I/O until buffer reused. */ 
-#define	B_00000100	0x00000100	/* Available flag. */ 
+#define	B_PERSISTENT	0x00000100	/* Perm. ref'ed while fs mounted. */ 
#define	B_DONE		0x00000200	/* I/O completed. */ 
#define	B_EINTR		0x00000400	/* I/O was interrupted */ 
#define	B_00000800	0x00000800	/* Available flag. */ 
@@ -220,10 +220,10 @@ 
#define B_CLUSTER	0x40000000	/* pagein op, so swap() can count it */ 
#define B_REMFREE	0x80000000	/* Delayed bremfree */ 

-#define PRINT_BUF_FLAGS "2040b3137cluster36vmio35ram34b27"  
+#define PRINT_BUF_FLAGS "2040remfree37cluster36vmio35ram34b27"  
"33paging32b2531b2430b2327relbuf26dirty25b20"  
-	"24b1923phys22clusterok21malloc20nocache17locked16inval"  
-	"15scanned14nowdrain13eintr12done11b810delwri7validsuspwrt"  
+	"24b1923b1822clusterok21malloc20nocache17b1416inval"  
+	"15b1214b1113eintr12done11persist10delwri7validsuspwrt"  
"6cache5deferred4direct3async2needcommit1age" 

/* 
Index: sys/gnu/fs/ext2fs/fs.h 
=================================================================== 
RCS file: /home/ncvs/src/sys/gnu/fs/ext2fs/fs.h,v 
retrieving revision 1.17 
diff -u -r1.17 fs.h 
--- sys/gnu/fs/ext2fs/fs.h	6 Jan 2005 18:27:30 -0000	1.17 
+++ sys/gnu/fs/ext2fs/fs.h	5 Sep 2005 21:29:11 -0000 
@@ -150,11 +150,16 @@ 

/* 
* Historically, ext2fs kept it's metadata buffers on the LOCKED queue.  Now, 
- * we simply change the lock owner to kern so that it may be released from 
- * another context.  Later, we release the buffer, and conditionally write it 
- * when we're done. 
+ * we simply change the lock owner to kern so that we may use it from contexts 
+ * other than the one that originally locked it.  When we are finished with 
+ * the buffer, we release it, writing it first if it was dirty.  The 
+ * B_PERSISTENT flag is cleared by brelse(), which bwrite() calls after the 
+ * buffer is written in the B_DIRTY case. 
*/ 
-#define LCK_BUF(bp)	BUF_KERNPROC(bp); 
+#define LCK_BUF(bp) {  
+	(bp)->b_flags |= B_PERSISTENT;  
+	BUF_KERNPROC(bp);  
+} 

#define ULCK_BUF(bp) {  
long flags;  




Responsible-Changed-From-To: freebsd-bugs->truckman 
Responsible-Changed-By: truckman 
Responsible-Changed-When: Wed Sep 7 01:01:47 GMT 2005 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=85163 
State-Changed-From-To: feedback->patched 
State-Changed-By: truckman 
State-Changed-When: Thu Sep 8 06:33:55 GMT 2005 
State-Changed-Why:  
Patched in HEAD: 
1.18      +8 -8      src/sys/gnu/fs/ext2fs/fs.h 
1.175     +13 -11    src/sys/kern/kern_shutdown.c 
1.189     +4 -4      src/sys/sys/buf.h 

Will MFC to RELENG_6 in about 3 days, assuming re@ approval. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85163 

From: Hanspeter Roth <hampi@rootshell.be>
To: bug-followup@FreeBSD.org, hampi@rootshell.be
Cc:  
Subject: Re: kern/85163: Giving up on 2 buffers with readonly mounted ext2fs
Date: Fri, 9 Sep 2005 22:49:36 +0200

 Yes, applying the patch of Sep 6th solved the problem.
State-Changed-From-To: patched->closed 
State-Changed-By: truckman 
State-Changed-When: Fri Sep 16 02:59:03 GMT 2005 
State-Changed-Why:  
Fixed in RELENG_6 by this commit: 

From: Don Lewis <truckman@FreeBSD.org> 
Subject: cvs commit: src/sys/gnu/fs/ext2fs fs.h src/sys/kern         kern_shutdown.c src/sys/sys buf.h 
Date: Sun, 11 Sep 2005 19:06:50 +0000 (UTC) 
To: src-committers@FreeBSD.org, 
cvs-src@FreeBSD.org, 
cvs-all@FreeBSD.org 

truckman    2005-09-11 19:06:50 UTC 

FreeBSD src repository 

Modified files:        (Branch: RELENG_6) 
sys/gnu/fs/ext2fs    fs.h  
sys/kern             kern_shutdown.c  
sys/sys              buf.h  
Log: 
MFC     src/sys/gnu/fs/ext2fs/fs.h      1.18 
src/sys/kern/kern_shutdown.c    1.175 
src/sys/sys/buf.h               1.189 

Modified files: 
sys/gnu/fs/ext2fs    fs.h 
sys/kern             kern_shutdown.c 
sys/sys              buf.h 
Log: 
Add a new struct buf flag bit, B_PERSISTENT, and use it to tag 
struct bufs that are persistently held by ext2fs.  Ignore any buffers 
with this flag in the code in boot() that counts "busy" and dirty 
buffers and attempts to sync the dirty buffers, which is done before 
attempting to unmount all the file systems during shutdown. 

This fixes the problem caused by any ext2fs file systems that are 
mounted at system shutdown time, which caused boot() to give up on 
a non-zero number of buffers and skip the call to vfs_unmountall(). 
This left all the mounted file systems in a dirty state and caused 
them to all require cleanup by fsck on reboot. 

Move the two separate copies of the "busy" buffer test in boot() 
to a separate function. 

Nuke the useless spl() stuff in the ext2fs ULCK_BUF() macro. 

Bring the PRINT_BUF_FLAGS definition in sys/buf.h up to date with 
this and previous flag changes. 

PR:             kern/56675, kern/85163 
Tested by:      "Matthias Andree" matthias.andree at gmx.de 
Reviewed by:    bde 
MFC after:      3 days 

PR:             kern/56675, kern/85163 
Tested by:      "Hanspeter Roth" hampi at rootshell.be 
Tested by:      "Matthias Andree" matthias.andree at gmx.de 
Reviewed by:    bde 
Approved by:    re (scottl) 

Revision   Changes    Path 
1.17.2.1   +8 -8      src/sys/gnu/fs/ext2fs/fs.h 
1.174.2.1  +13 -11    src/sys/kern/kern_shutdown.c 
1.187.2.2  +4 -4      src/sys/sys/buf.h 


http://www.freebsd.org/cgi/query-pr.cgi?pr=85163 
>Unformatted:
