From nobody@FreeBSD.org  Wed Oct 30 02:30:41 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CBFB437B401
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Oct 2002 02:30:41 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 8CE4743E42
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Oct 2002 02:30:41 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g9UAUZ7R070928
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Oct 2002 02:30:35 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.6/8.12.6/Submit) id g9UAUZYJ070927;
	Wed, 30 Oct 2002 02:30:35 -0800 (PST)
Message-Id: <200210301030.g9UAUZYJ070927@www.freebsd.org>
Date: Wed, 30 Oct 2002 02:30:35 -0800 (PST)
From: "&#321;ukasz Gryglicki" <morgothdbma@o2.pl>
To: freebsd-gnats-submit@FreeBSD.org
Subject: VN devices can hang system FreeBSD v4.5
X-Send-Pr-Version: www-1.0

>Number:         44744
>Category:       kern
>Synopsis:       [vn] [patch] VN devices can hang system FreeBSD v4.5
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 30 02:40:01 PST 2002
>Closed-Date:    Wed Feb 28 08:20:42 GMT 2007
>Last-Modified:  Wed Feb 28 08:20:42 GMT 2007
>Originator:     &#321;ukasz Gryglicki
>Release:        4.5
>Organization:
student
>Environment:
FreeBSD v4.5 /usr/src/sys/compile/MORGOTH i386 192MB RAM 
>Description:
When I mount file (vn0 points to file) into /directory and then before
unmounting /directory do vnconfig -u vn0 there will be no error but when I create in this diretory files (device is not configured now) there wouldn't be error event now, but when I umount /directory kernel hungs up (sometimes). I know I shouldn't do that but I think system should prevent me from doing that...
>How-To-Repeat:
Just try to do what I've described in Full Description
>Fix:
Hmmm... I think this is kernel's fault (maybe fix vn management in kernel?)
>Release-Note:
>Audit-Trail:

From: Peter Pentchev <roam@ringlet.net>
To: "&#321;ukasz Gryglicki" <morgothdbma@o2.pl>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/44744: VN devices can hang system FreeBSD v4.5
Date: Wed, 30 Oct 2002 14:17:40 +0200

 On Wed, Oct 30, 2002 at 02:30:35AM -0800, &#321;ukasz Gryglicki wrote:
 > 
 > >Number:         44744
 > >Category:       kern
 > >Synopsis:       VN devices can hang system FreeBSD v4.5
 > >Originator:     &#321;ukasz Gryglicki
 > >Release:        4.5
 > >Organization:
 > student
 > >Environment:
 > FreeBSD v4.5 /usr/src/sys/compile/MORGOTH i386 192MB RAM 
 > >Description:
 > When I mount file (vn0 points to file) into /directory and then before
 > unmounting /directory do vnconfig -u vn0 there will be no error but
 > when I create in this diretory files (device is not configured now)
 > there wouldn't be error event now, but when I umount /directory kernel
 > hungs up (sometimes). I know I shouldn't do that but I think system
 > should prevent me from doing that...
 > >How-To-Repeat:
 > Just try to do what I've described in Full Description
 > >Fix:
 > Hmmm... I think this is kernel's fault (maybe fix vn management in kernel?)
 
 For the record, this - or a very similar - problem is still present in
 4.7-STABLE.  When a vn device is mounted, there is nothing to stop
 anyone from running 'vnconfig -u' - the device is happily torn down, and
 any further access to the still-mounted filesystem returns ENXIO, as it
 well should.
 
 Would there be a way to detect that a filesystem is mounted on the
 device and stop the 'un-configuring' process?
 
 G'luck,
 Peter
 
 -- 
 Peter Pentchev	roam@ringlet.net	roam@FreeBSD.org
 PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
 Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
 This sentence every third, but it still comprehensible.

From: Dima Dorfman <dima@trit.org>
To: Peter Pentchev <roam@ringlet.net>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/44744: VN devices can hang system FreeBSD v4.5
Date: Wed, 30 Oct 2002 21:49:13 +0000

 Peter Pentchev <roam@ringlet.net> wrote:
 >  For the record, this - or a very similar - problem is still present in
 >  4.7-STABLE.  When a vn device is mounted, there is nothing to stop
 >  anyone from running 'vnconfig -u' - the device is happily torn down, and
 >  any further access to the still-mounted filesystem returns ENXIO, as it
 >  well should.
 >  
 >  Would there be a way to detect that a filesystem is mounted on the
 >  device and stop the 'un-configuring' process?
 
 Should be pretty easy.  I think something like the attached (untested,
 since I don't have a -stable machine I can use to test it) patch
 should do it.  Note that the patch prevents "detach", not
 "unconfigure", and I'm not sure what the difference is.
 
 Index: vn.c
 ===================================================================
 RCS file: /ref/cvsf/src/sys/dev/vn/Attic/vn.c,v
 retrieving revision 1.105.2.4
 diff -u -r1.105.2.4 vn.c
 --- vn.c	18 Nov 2001 07:11:00 -0000	1.105.2.4
 +++ vn.c	30 Oct 2002 21:44:51 -0000
 @@ -130,6 +130,7 @@
  struct vn_softc {
  	int		sc_unit;
  	int		sc_flags;	/* flags 			*/
 +	int		sc_opencount;
  	int		sc_size;	/* size of vn, sc_secsize scale	*/
  	int		sc_secsize;	/* sector size			*/
  	struct diskslices *sc_slices;
 @@ -168,6 +169,7 @@
  	IFOPT(vn, VN_LABELS)
  		if (vn->sc_slices != NULL)
  			dsclose(dev, mode, vn->sc_slices);
 +	--vn->sc_opencount;
  	return (0);
  }
  
 @@ -267,6 +269,7 @@
  			return (ENXIO);
  		}
  	}
 +	++vn->sc_opencount;
  	return(0);
  }
  
 @@ -480,11 +483,11 @@
  	case VNIOCDETACH:
  		if ((vn->sc_flags & VNF_INITED) == 0)
  			return(ENXIO);
 +		if (vn->sc_opencount != 0)
 +			return(EBUSY);
  		/*
  		 * XXX handle i/o in progress.  Return EBUSY, or wait, or
  		 * flush the i/o.
 -		 * XXX handle multiple opens of the device.  Return EBUSY,
 -		 * or revoke the fd's.
  		 * How are these problems handled for removable and failing
  		 * hardware devices? (Hint: They are not)
  		 */
State-Changed-From-To: open->closed 
State-Changed-By: remko 
State-Changed-When: Wed Feb 28 08:20:38 UTC 2007 
State-Changed-Why:  
I am sorry but vn and friends are no longer available within FreeBSD. If 
this problem still persists with mdconfig, please notify me. 

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