From nobody@FreeBSD.org  Sun Sep 25 18:48:00 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 213731065674
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Sep 2011 18:48:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 11C6C8FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Sep 2011 18:48:00 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p8PIlx1H051418
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Sep 2011 18:47:59 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p8PIlxCZ051417;
	Sun, 25 Sep 2011 18:47:59 GMT
	(envelope-from nobody)
Message-Id: <201109251847.p8PIlxCZ051417@red.freebsd.org>
Date: Sun, 25 Sep 2011 18:47:59 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: umount doesn't fully sync UFS filesystems on 9.x
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161016
>Category:       bin
>Synopsis:       umount(8) doesn't fully sync UFS filesystems on 9.x
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mckusick
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 25 18:50:08 UTC 2011
>Closed-Date:    Thu Jan 12 00:08:02 UTC 2012
>Last-Modified:  Sun Feb 03 22:29:32 UTC 2013
>Originator:     Garrett Cooper
>Release:        9.0-BETA2
>Organization:
iXsystems, Inc.
>Environment:
FreeBSD fallout.local 9.0-BETA2 FreeBSD 9.0-BETA2 #10 r225587M: Thu Sep 15 09:07:08 PDT 2011     root@fallout.local:/usr/obj/usr/src/sys/FALLOUT  amd64
>Description:
As discussed here [1] and here [2], there appears to be a bug in how data is being synced out to memory disks in the base system which causes repeated builds in nanobsd to fail unless adds 2 explicit sync's before each umount operation is performed; this is odd because umount(8) explicitly sync's unless -f is specified (previously, it explicitly called sync whenever umount was called -- see http://svnweb.freebsd.org/base?view=revision&revision=222466 ).

I've run into this bug where the underlying storage used for the vnode disk is either housed on UFS or ZFS, which suggests that the vnode backed disk is the problem child.

FreeNAS uses UFS1 SU (we don't modify the arguments passed via the $NANO_NEWFS var), but lev@ also reported that he ran into issues with UFS2 SU, which suggests that it's a generic syncing problem with UFS + SU and/or how md(4)s sync outstanding writes out to disk.

1. http://www.mavetju.org/mail/view_message.php?list=freebsd-embedded&id=3382579&raw=yes
2. http://comments.gmane.org/gmane.os.freebsd.current/135617
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mckusick 
Responsible-Changed-By: mckusick 
Responsible-Changed-When: Wed Sep 28 00:06:28 UTC 2011 
Responsible-Changed-Why:  
I will take responsibility for this bug. 

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

Date: Tue, 27 Sep 2011 17:19:31 -0700
From: Kirk McKusick <mckusick@mckusick.com>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: lev@freebsd.org, freebsd-fs@freebsd.org, Xin LI <delphij@freebsd.org>,
        bug-followup@freebsd.org
Subject: Re: PR kern/161016 Need to force sync(2) before umounting UFS1 filesystems? 

 I have taken responsibility for working on this bug report (PR kern/161016).
 
 I propose the following change to correct it:
 
 Index: sys/kern/vfs_mount.c
 ===================================================================
 --- sys/kern/vfs_mount.c	(revision 225807)
 +++ sys/kern/vfs_mount.c	(working copy)
 @@ -1227,18 +1227,6 @@
  		mp->mnt_kern_flag |= MNTK_UNMOUNTF;
  	error = 0;
  	if (mp->mnt_lockref) {
 -		if ((flags & MNT_FORCE) == 0) {
 -			mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ |
 -			    MNTK_UNMOUNTF);
 -			if (mp->mnt_kern_flag & MNTK_MWAIT) {
 -				mp->mnt_kern_flag &= ~MNTK_MWAIT;
 -				wakeup(mp);
 -			}
 -			MNT_IUNLOCK(mp);
 -			if (coveredvp)
 -				VOP_UNLOCK(coveredvp, 0);
 -			return (EBUSY);
 -		}
  		mp->mnt_kern_flag |= MNTK_DRAINING;
  		error = msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS,
  		    "mount drain", 0);
 
 The things to check for are:
 
 1) That it fixes the EBUSY on unmount.
 
 2) That it does not cause unmount to hang.
 
 I would appreciate feedback as to whether this fix helps.
 
 	Kirk McKusick

Date: Thu, 29 Sep 2011 04:36:35 +0300
From: Kostik Belousov <kostikbel@gmail.com>
To: Kirk McKusick <mckusick@mckusick.com>
Cc: Garrett Cooper <yaneurabeya@gmail.com>, freebsd-fs@freebsd.org,
        Xin LI <delphij@freebsd.org>, bug-followup@freebsd.org
Subject: Re: PR kern/161016 Need to force sync(2) before umounting UFS1 filesystems?

 >=20
 > The things to check for are:
 >=20
 > 1) That it fixes the EBUSY on unmount.
 >=20
 > 2) That it does not cause unmount to hang.
 >=20
 > I would appreciate feedback as to whether this fix helps.
 
 I think the item 2) should be tested mostly on the hung NFS server.
 
 I understand what you are doing, you do not want a transient mount point
 busy caller to fail the unmount. But my belief is that this is the
 intended mode of operation for non-forced unmounts.
 
 As I compare the original bug report and your change, the reason that
 UFS gives spurious EBUSY on soft unmounts is that SU code busies mp
 around some processing. Is my guess right ? Then, restoring some amount
 of sync(2) before the unmount would be useful, please see r222466 for
 the most likely reason why the issue appeared.
 
 Might be, the best route would be to add a kludge mnt_flag that request
 dounmount() to do a VFS_SYNC() before checking for the busy holder ?
 
 
 --ssSfcPohcXNs3135
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (FreeBSD)
 
 iEYEARECAAYFAk6Dy6MACgkQC3+MBN1Mb4hhwQCgzuj/4OgfYVYgROYIjridzOs5
 wooAnje938vnGjgW9UincSwhn0+Sj7Fq
 =4iJ6
 -----END PGP SIGNATURE-----
 
 --ssSfcPohcXNs3135--

Date: Wed, 28 Sep 2011 19:19:52 -0700
From: Garrett Cooper <yaneurabeya@gmail.com>
To: Kostik Belousov <kostikbel@gmail.com>
Cc: Kirk McKusick <mckusick@mckusick.com>, freebsd-fs@freebsd.org, 
	Xin LI <delphij@freebsd.org>, bug-followup@freebsd.org
Subject: Re: PR kern/161016 Need to force sync(2) before umounting UFS1 filesystems?

 > I think the item 2) should be tested mostly on the hung NFS server.
 >
 > I understand what you are doing, you do not want a transient mount point
 > busy caller to fail the unmount. But my belief is that this is the
 > intended mode of operation for non-forced unmounts.
 >
 > As I compare the original bug report and your change, the reason that
 > UFS gives spurious EBUSY on soft unmounts is that SU code busies mp
 > around some processing. Is my guess right ? Then, restoring some amount
 > of sync(2) before the unmount would be useful, please see r222466 for
 > the most likely reason why the issue appeared.
 >
 > Might be, the best route would be to add a kludge mnt_flag that request
 > dounmount() to do a VFS_SYNC() before checking for the busy holder ?
 
 This would undo some of the changes attillio added for the locking
 stuff in r184554. Not sure what the prior behavior was because I only
 traced back the change a little bit.
 Thanks,
 -Garrett
 
 1. http://svnweb.freebsd.org/base/head/sys/kern/vfs_mount.c?revision=3D1845=
 54&view=3Dmarkup

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161016: commit references a PR
Date: Tue, 11 Oct 2011 18:46:50 +0000 (UTC)

 Author: mckusick
 Date: Tue Oct 11 18:46:41 2011
 New Revision: 226265
 URL: http://svn.freebsd.org/changeset/base/226265
 
 Log:
   When unmounting a filesystem always wait for the vfs_busy lock to clear
   so that if no vnodes in the filesystem are actively in use the unmount
   will succeed rather than failing with EBUSY.
   
   Reported by: Garrett Cooper
   Reviewed by: Attilio Rao and Kostik Belousov
   Tested by:   Garrett Cooper
   PR:          kern/161016
   MFC after:   3 weeks
 
 Modified:
   head/sys/kern/vfs_mount.c
 
 Modified: head/sys/kern/vfs_mount.c
 ==============================================================================
 --- head/sys/kern/vfs_mount.c	Tue Oct 11 18:26:31 2011	(r226264)
 +++ head/sys/kern/vfs_mount.c	Tue Oct 11 18:46:41 2011	(r226265)
 @@ -1227,18 +1227,6 @@ dounmount(mp, flags, td)
  		mp->mnt_kern_flag |= MNTK_UNMOUNTF;
  	error = 0;
  	if (mp->mnt_lockref) {
 -		if ((flags & MNT_FORCE) == 0) {
 -			mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ |
 -			    MNTK_UNMOUNTF);
 -			if (mp->mnt_kern_flag & MNTK_MWAIT) {
 -				mp->mnt_kern_flag &= ~MNTK_MWAIT;
 -				wakeup(mp);
 -			}
 -			MNT_IUNLOCK(mp);
 -			if (coveredvp)
 -				VOP_UNLOCK(coveredvp, 0);
 -			return (EBUSY);
 -		}
  		mp->mnt_kern_flag |= MNTK_DRAINING;
  		error = msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS,
  		    "mount drain", 0);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: mckusick 
State-Changed-When: Tue Oct 11 19:21:05 UTC 2011 
State-Changed-Why:  
An agreed upon fix has been applied to head. 
Baring resulting problems it will be MFC'ed 
to 8 and 9 in three weeks time. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161016: commit references a PR
Date: Fri, 21 Oct 2011 22:12:33 +0000 (UTC)

 Author: mckusick
 Date: Fri Oct 21 22:12:24 2011
 New Revision: 226622
 URL: http://svn.freebsd.org/changeset/base/226622
 
 Log:
   MFC: 226265
   
   When unmounting a filesystem always wait for the vfs_busy lock to clear
   so that if no vnodes in the filesystem are actively in use the unmount
   will succeed rather than failing with EBUSY.
   
   Reported by: Garrett Cooper
   Reviewed by: Attilio Rao and Kostik Belousov
   Tested by:   Garrett Cooper
   Approved by: re (kib)
   PR:          kern/161016
 
 Modified:
   stable/9/sys/kern/vfs_mount.c
 
 Modified: stable/9/sys/kern/vfs_mount.c
 ==============================================================================
 --- stable/9/sys/kern/vfs_mount.c	Fri Oct 21 22:07:52 2011	(r226621)
 +++ stable/9/sys/kern/vfs_mount.c	Fri Oct 21 22:12:24 2011	(r226622)
 @@ -1227,18 +1227,6 @@ dounmount(mp, flags, td)
  		mp->mnt_kern_flag |= MNTK_UNMOUNTF;
  	error = 0;
  	if (mp->mnt_lockref) {
 -		if ((flags & MNT_FORCE) == 0) {
 -			mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ |
 -			    MNTK_UNMOUNTF);
 -			if (mp->mnt_kern_flag & MNTK_MWAIT) {
 -				mp->mnt_kern_flag &= ~MNTK_MWAIT;
 -				wakeup(mp);
 -			}
 -			MNT_IUNLOCK(mp);
 -			if (coveredvp)
 -				VOP_UNLOCK(coveredvp, 0);
 -			return (EBUSY);
 -		}
  		mp->mnt_kern_flag |= MNTK_DRAINING;
  		error = msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS,
  		    "mount drain", 0);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161016: commit references a PR
Date: Wed, 11 Jan 2012 19:12:40 +0000 (UTC)

 Author: mckusick
 Date: Wed Jan 11 19:12:29 2012
 New Revision: 229978
 URL: http://svn.freebsd.org/changeset/base/229978
 
 Log:
   MFC: 226265
   
   When unmounting a filesystem always wait for the vfs_busy lock to clear
   so that if no vnodes in the filesystem are actively in use the unmount
   will succeed rather than failing with EBUSY.
   
   Reported by: Garrett Cooper
   Reviewed by: Attilio Rao and Kostik Belousov
   Tested by:   Garrett Cooper
   PR:          kern/161016
 
 Modified:
   stable/8/sys/kern/vfs_mount.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
 
 Modified: stable/8/sys/kern/vfs_mount.c
 ==============================================================================
 --- stable/8/sys/kern/vfs_mount.c	Wed Jan 11 18:38:52 2012	(r229977)
 +++ stable/8/sys/kern/vfs_mount.c	Wed Jan 11 19:12:29 2012	(r229978)
 @@ -1260,18 +1260,6 @@ dounmount(mp, flags, td)
  		mp->mnt_kern_flag |= MNTK_UNMOUNTF;
  	error = 0;
  	if (mp->mnt_lockref) {
 -		if ((flags & MNT_FORCE) == 0) {
 -			mp->mnt_kern_flag &= ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ |
 -			    MNTK_UNMOUNTF);
 -			if (mp->mnt_kern_flag & MNTK_MWAIT) {
 -				mp->mnt_kern_flag &= ~MNTK_MWAIT;
 -				wakeup(mp);
 -			}
 -			MNT_IUNLOCK(mp);
 -			if (coveredvp)
 -				VOP_UNLOCK(coveredvp, 0);
 -			return (EBUSY);
 -		}
  		mp->mnt_kern_flag |= MNTK_DRAINING;
  		error = msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS,
  		    "mount drain", 0);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: mckusick 
State-Changed-When: Thu Jan 12 00:06:33 UTC 2012 
State-Changed-Why:  
The fix has been verified in head. 
The fix was MFC'ed to 9 in time for the release. 
The fix has been MFC'ed to 8. 

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