From owner-svn-src-all@FreeBSD.ORG Sun Mar 1 10:51:34 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BEAAF1065670; Sun, 1 Mar 2009 10:51:34 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AB9F78FC1D; Sun, 1 Mar 2009 10:51:34 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n21ApY2t041205; Sun, 1 Mar 2009 10:51:34 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n21ApYYP041203; Sun, 1 Mar 2009 10:51:34 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <200903011051.n21ApYYP041203@svn.freebsd.org> From: Edward Tomasz Napierala Date: Sun, 1 Mar 2009 10:51:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189224 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Mar 2009 10:51:35 -0000 Author: trasz Date: Sun Mar 1 10:51:34 2009 New Revision: 189224 URL: http://svn.freebsd.org/changeset/base/189224 Log: MFC r174937 by imp. Reviewed by: imp Approved by: rwatson (mentor) Original commit log: A partial solution to some of the 'pull the umass device with a mounted FS' problems. These are more along the lines of 'avoiding an avoidable panic' than a complete solution to removable devices. We now close the barn door after the horse has gotten lose and has been hit by a truck, as it were. The barn no longer catches fire in this case, but the horse is still dead :-). The vfs_bio.c fix causes us not to put a failed write back into the dirty pool if the error returned was ENXIO. In that case, the buffer is treated like any other clean buffer that's being retured. ENXIO means the device isn't there anymore and will never be there again in the future, so retrying is futile. The vfs_mount.c fix treats 'ENXIO' as success for unmounting a file system. If the device is gone, retrying later won't help and we'll never be able to unmount the device. These two are part of a larger patch set submitted by the author. The other patches will be forth coming. I added comments to these two patches. Submitted by: Henrik Gulbrandsen Reviewed by: phk@ PR: usb/46176 (partial) Modified: stable/7/sys/ (props changed) stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/ath/ath_hal/ (props changed) stable/7/sys/dev/cxgb/ (props changed) stable/7/sys/kern/vfs_bio.c stable/7/sys/kern/vfs_mount.c Modified: stable/7/sys/kern/vfs_bio.c ============================================================================== --- stable/7/sys/kern/vfs_bio.c Sun Mar 1 09:51:50 2009 (r189223) +++ stable/7/sys/kern/vfs_bio.c Sun Mar 1 10:51:34 2009 (r189224) @@ -1170,6 +1170,7 @@ brelse(struct buf *bp) if (bp->b_iocmd == BIO_WRITE && (bp->b_ioflags & BIO_ERROR) && + bp->b_error != ENXIO && !(bp->b_flags & B_INVAL)) { /* * Failed write, redirty. Must clear BIO_ERROR to prevent @@ -1177,6 +1178,9 @@ brelse(struct buf *bp) * this case is not run and the next case is run to * destroy the buffer. B_INVAL can occur if the buffer * is outside the range supported by the underlying device. + * If the error is that the device went away (ENXIO), we + * shouldn't redirty the buffer either, but discard the + * data too. */ bp->b_ioflags &= ~BIO_ERROR; bdirty(bp); Modified: stable/7/sys/kern/vfs_mount.c ============================================================================== --- stable/7/sys/kern/vfs_mount.c Sun Mar 1 09:51:50 2009 (r189223) +++ stable/7/sys/kern/vfs_mount.c Sun Mar 1 10:51:34 2009 (r189224) @@ -1293,8 +1293,13 @@ dounmount(mp, flags, td) error = VFS_UNMOUNT(mp, flags, td); } vn_finished_write(mp); - if (error) { - /* Undo cdir/rdir and rootvnode changes made above. */ + /* + * If we failed to flush the dirty blocks for this mount point, + * undo all the cdir/rdir and rootvnode changes we made above. + * Unless we failed to do so because the device is reporting that + * it doesn't exist anymore. + */ + if (error && error != ENXIO) { if ((flags & MNT_FORCE) && VFS_ROOT(mp, LK_EXCLUSIVE, &fsrootvp, td) == 0) { if (mp->mnt_vnodecovered != NULL)