From mitja@lamu.hermes.si  Fri Feb 23 06:54:49 2001
Return-Path: <mitja@lamu.hermes.si>
Received: from guardian.hermes.si (guardian.hermes.si [193.77.5.150])
	by hub.freebsd.org (Postfix) with ESMTP id EE5AF37B503
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Feb 2001 06:54:45 -0800 (PST)
	(envelope-from mitja@lamu.hermes.si)
Received: from hermes.si (primus.hermes.si [193.77.5.98])
	by guardian.hermes.si (8.9.3/8.9.3) with ESMTP id PAA03859
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Feb 2001 15:54:32 +0100 (MET)
Received: (from uucp@localhost)
	by hermes.si (8.9.3/8.9.3) id PAA22625
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Feb 2001 15:54:30 +0100
Received: from lamu.hermes.si(10.17.1.230) by primus.hermes.si via smap (V2.1)
	id xma021435; Fri, 23 Feb 01 15:53:21 +0100
Received: (from mitja@localhost)
	by lamu.hermes.si (8.11.1/8.9.3) id f1NExwD15609;
	Fri, 23 Feb 2001 15:59:59 +0100 (CET)
Message-Id: <200102231459.f1NExwD15609@lamu.hermes.si>
Date: Fri, 23 Feb 2001 15:59:59 +0100 (CET)
From: mitja.horvat@hermes.si
Reply-To: mitja.horvat@hermes.si
To: FreeBSD-gnats-submit@freebsd.org
Subject: kernel panic related to umount -f & kevents
X-Send-Pr-Version: 3.2

>Number:         25309
>Category:       kern
>Synopsis:       Bug with kevent & umount -f
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    dwmalone
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 23 07:00:02 PST 2001
>Closed-Date:    Mon Feb 26 03:01:29 PST 2001
>Last-Modified:  Mon Feb 26 03:02:08 PST 2001
>Originator:     Mitja Horvat
>Release:        FreeBSD 4.2-STABLE i386
>Organization:
>Environment:

FreeBSD 4.2-STABLE i386, cvsupped on Feb 11th 2001.
PIII/800Mhz, 256MB of RAM, 15GB ATA/66 hard drive.

>Description:

Kernel panic occurs when waiting for a kevent on a UFS file and the
filesystem is forcibly unmounted.

>How-To-Repeat:

Since tail (in conjunction with -f) uses kevent to achieve it's job,
it can be used to reproduce the problem. Mount a filesystem, and 
tail -f a file. Unmount the filesystem using the -f flag(force). Note,
that the bug may not manifestate immediately.



#!/bin/sh
while true
do
	mount /dev/DEVICE /MOUNT_POINT
	tail -f /MOUNT_POINT/RANDOM_FILE &
	umount -f /MOUNT_POINT
	kill %%
done

Replace /dev/DEVICE with a device(eg. CDROM), /MOUNT_POINT with the mount point
of the device, and RANDOM_FILE with a random file on the filesystem.

>Fix:

The following patch fixes the problem for me. Please note that I'm far away from being
a kernel hacker, so I'm not 100% sure if it breaks something else or not
(although it's a very simple fix).

--- vfs_vnops.c.orig    Mon Feb 12 14:17:19 2001
+++ vfs_vnops.c Fri Feb 23 15:55:18 2001
@@ -722,6 +722,15 @@
        struct vnode *vp = (struct vnode *)kn->kn_fp->f_data;
        struct inode *ip = VTOI(vp);
 
+       /*
+        * If the underlying inode was freed(this can happen
+        * if the filesystem is forcibly unmounted with 
+        * umount -f), return as there was activity on the file,
+        * so the process will be woken up and later it will
+        * receive an error during read XXX
+        */
+       if (ip == NULL) return 1;
+
        kn->kn_data = ip->i_size - kn->kn_fp->f_offset;
        return (kn->kn_data != 0);
 }



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dwmalone 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Fri Feb 23 07:39:38 PST 2001 
Responsible-Changed-Why:  
I'll try to get someone to review this. 

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

From: David Malone <dwmalone@maths.tcd.ie>
To: mitja.horvat@hermes.si
Cc: FreeBSD-gnats-submit@freebsd.org, peter@freebsd.org,
	jlemon@freebsd.org
Subject: Re: kern/25309: kernel panic related to umount -f & kevents
Date: Fri, 23 Feb 2001 15:38:42 +0000

 On Fri, Feb 23, 2001 at 03:59:59PM +0100, mitja.horvat@hermes.si wrote:
 > --- vfs_vnops.c.orig    Mon Feb 12 14:17:19 2001
 > +++ vfs_vnops.c Fri Feb 23 15:55:18 2001
 > @@ -722,6 +722,15 @@
 >         struct vnode *vp = (struct vnode *)kn->kn_fp->f_data;
 >         struct inode *ip = VTOI(vp);
 >  
 > +       /*
 > +        * If the underlying inode was freed(this can happen
 > +        * if the filesystem is forcibly unmounted with 
 > +        * umount -f), return as there was activity on the file,
 > +        * so the process will be woken up and later it will
 > +        * receive an error during read XXX
 > +        */
 > +       if (ip == NULL) return 1;
 > +
 >         kn->kn_data = ip->i_size - kn->kn_fp->f_offset;
 >         return (kn->kn_data != 0);
 >  }
 
 Amazingly, I suggested an almost identical patch earlier in the
 week for another problem due to revoking file discriptors. I'll
 try to get Peter or Jonathan to review the patch and I'll commit
 it.
 
 	David.

From: Mitja Horvat <mitja.horvat@hermes.si>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: FreeBSD-gnats-submit@freebsd.org, peter@freebsd.org,
	jlemon@freebsd.org
Subject: Re: kern/25309: kernel panic related to umount -f & kevents
Date: Fri, 23 Feb 2001 17:44:30 +0100

 On Friday 23 February 2001 16:38, you wrote:
 > On Fri, Feb 23, 2001 at 03:59:59PM +0100, mitja.horvat@hermes.si wrote:
 > > --- vfs_vnops.c.orig    Mon Feb 12 14:17:19 2001
 > > +++ vfs_vnops.c Fri Feb 23 15:55:18 2001
 > > @@ -722,6 +722,15 @@
 > >         struct vnode *vp = (struct vnode *)kn->kn_fp->f_data;
 > >         struct inode *ip = VTOI(vp);
 > >
 > > +       /*
 > > +        * If the underlying inode was freed(this can happen
 > > +        * if the filesystem is forcibly unmounted with
 > > +        * umount -f), return as there was activity on the file,
 > > +        * so the process will be woken up and later it will
 > > +        * receive an error during read XXX
 > > +        */
 > > +       if (ip == NULL) return 1;
 > > +
 > >         kn->kn_data = ip->i_size - kn->kn_fp->f_offset;
 > >         return (kn->kn_data != 0);
 > >  }
 >
 > Amazingly, I suggested an almost identical patch earlier in the
 > week for another problem due to revoking file discriptors. I'll
 > try to get Peter or Jonathan to review the patch and I'll commit
 > it.
 >
 > 	David.
 
 Great, I'm glad that I have contributed to the comunity. Hopefully this will 
 get committed before 4.3-RELEASE.
 
 Regards,
 Mitja
State-Changed-From-To: open->closed 
State-Changed-By: dwmalone 
State-Changed-When: Mon Feb 26 03:01:29 PST 2001 
State-Changed-Why:  
I believe the fix for this has now been merged into -stable. 

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