NetBSD Problem Report #45607

From gregoire.sutre@gmail.com  Sat Nov 12 15:34:51 2011
Return-Path: <gregoire.sutre@gmail.com>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 6CA7163B8A8
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 12 Nov 2011 15:34:51 +0000 (UTC)
Message-Id: <20111112153440.AB269364B3@yosemite.localdomain>
Date: Sat, 12 Nov 2011 16:34:40 +0100 (CET)
From: gregoire.sutre@gmail.com
Reply-To: gregoire.sutre@gmail.com
To: gnats-bugs@gnats.NetBSD.org
Subject: mount_nilfs(8) on wedge panic
X-Send-Pr-Version: 3.95

>Number:         45607
>Category:       kern
>Synopsis:       Mounting a NILFS(2) file system on a wedge panics the kernel
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 12 15:35:00 +0000 2011
>Closed-Date:    Mon Nov 14 01:08:18 +0000 2011
>Last-Modified:  Mon Nov 14 01:08:18 +0000 2011
>Originator:     Gregoire Sutre
>Release:        NetBSD 5.99.56 (2011-11-11)
>Organization:
>Environment:
System: NetBSD yosemite 5.99.56 NetBSD 5.99.56 (GENERIC) #0: Fri Nov 11 17:26:37 CET 2011 sutre@tahoe:/data/sutre/build-amd64/home/sutre/NetBSD/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
I get a kernel panic when mounting a NILFS(2) file system on a wedge.
The reason is the following: when nilfs_mount_device() isn't able to
detect the device's size, it calls nilfs_unmount_device() before
registering the device in the global list of nilfs devices.  Then,
nilfs_unmount_device() attempts to remove the element from the list,
which leads to the kernel panic.

The patch below fixes the problem.  But mount_nilfs(8) still does not
work on wedges.  The patch only fixes the panic.

>How-To-Repeat:
Attempt to mount_nilfs(8) a NILFS(2) file system stored in a GPT
partition, detected as a dk(4) wedge.
>Fix:

Index: nilfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/nilfs/nilfs_vfsops.c,v
retrieving revision 1.5
diff -U 5 -p -r1.5 nilfs_vfsops.c
--- nilfs_vfsops.c	11 Aug 2010 13:26:25 -0000	1.5
+++ nilfs_vfsops.c	12 Nov 2011 15:29:04 -0000
@@ -633,22 +633,22 @@ nilfs_mount_device(struct vnode *devvp, 
 	nilfsdev->devvp         = devvp;
 	nilfsdev->uncomitted_bl = 0;
 	cv_init(&nilfsdev->sync_cv, "nilfssyn");
 	STAILQ_INIT(&nilfsdev->mounts);

+	/* register nilfs_device in list */
+	SLIST_INSERT_HEAD(&nilfs_devices, nilfsdev, next_device);
+
 	/* get our device's size */
 	error = VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, NOCRED);
 	if (error) {
 		/* remove all our information */
 		nilfs_unmount_device(nilfsdev);
 		return EINVAL;
 	}
 	nilfsdev->devsize = dpart.part->p_size * dpart.disklab->d_secsize;

-	/* register nilfs_device in list */
-	SLIST_INSERT_HEAD(&nilfs_devices, nilfsdev, next_device);
-
 	/* connect to the head for most recent files XXX really pass mp and args? */
 	error = nilfs_mount_base(nilfsdev, mp, args);
 	if (error) {
 		/* remove all our information */
 		nilfs_unmount_device(nilfsdev);

>Release-Note:

>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45607 CVS commit: src/sys/fs/nilfs
Date: Sun, 13 Nov 2011 17:22:51 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Sun Nov 13 17:22:51 UTC 2011

 Modified Files:
 	src/sys/fs/nilfs: nilfs_vfsops.c

 Log Message:
 Avoid panic on error path, from PR 45607. The error path is exercised
 because this is using DIOCGPART to get the volume size, which doesn't
 work on wedges. It should be calling getdisksize() instead.


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/sys/fs/nilfs/nilfs_vfsops.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: gregoire.sutre@gmail.com
Subject: Re: kern/45607: mount_nilfs(8) on wedge panic
Date: Sun, 13 Nov 2011 17:29:02 +0000

 On Sat, Nov 12, 2011 at 03:35:00PM +0000, gregoire.sutre@gmail.com wrote:
  > The patch below fixes the problem.  But mount_nilfs(8) still does not
  > work on wedges.  The patch only fixes the panic.

 The following completely untested patch (applied after yours) may make
 it work, or at least get farther.

 Index: nilfs_vfsops.c
 ===================================================================
 RCS file: /cvsroot/src/sys/fs/nilfs/nilfs_vfsops.c,v
 retrieving revision 1.6
 diff -u -r1.6 nilfs_vfsops.c
 --- nilfs_vfsops.c	13 Nov 2011 17:22:51 -0000	1.6
 +++ nilfs_vfsops.c	13 Nov 2011 17:26:59 -0000
 @@ -563,10 +563,11 @@
  nilfs_mount_device(struct vnode *devvp, struct mount *mp, struct nilfs_args *args,
  	struct nilfs_device **nilfsdev_p)
  {
 -	struct partinfo dpart;
  	struct nilfs_device *nilfsdev;
  	struct lwp *l = curlwp;
  	int openflags, accessmode, error;
 +	uint64_t numblocks;
 +	unsigned blocksize;

  	DPRINTF(VOLUMES, ("Mounting NILFS device\n"));

 @@ -639,13 +640,13 @@
  	SLIST_INSERT_HEAD(&nilfs_devices, nilfsdev, next_device);

  	/* get our device's size */
 -	error = VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, NOCRED);
 +	error = getdisksize(devvp, DIOCGPART, &numblocks, &blocksize);
  	if (error) {
  		/* remove all our information */
  		nilfs_unmount_device(nilfsdev);
  		return EINVAL;
  	}
 -	nilfsdev->devsize = dpart.part->p_size * dpart.disklab->d_secsize;
 +	nilfsdev->devsize = numblocks * blocksize;

  	/* connect to the head for most recent files XXX really pass mp and args? */
  	error = nilfs_mount_base(nilfsdev, mp, args);


 -- 
 David A. Holland
 dholland@netbsd.org

State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 13 Nov 2011 18:47:12 +0000
State-Changed-Why:
never mind my patch, Christos committed essentially the same change just
now along with some other minor cleanup.

Please give that a try...


From: =?ISO-8859-1?Q?Gr=E9goire_Sutre?= <gregoire.sutre@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: dholland@NetBSD.org
Subject: Re: kern/45607 (Mounting a NILFS(2) file system on a wedge panics
 the kernel)
Date: Mon, 14 Nov 2011 00:47:27 +0100

 On 11/13/2011 07:47 PM, dholland@NetBSD.org wrote:
 > Synopsis: Mounting a NILFS(2) file system on a wedge panics the kernel
 >
 > State-Changed-From-To: open->feedback
 > State-Changed-By: dholland@NetBSD.org
 > State-Changed-When: Sun, 13 Nov 2011 18:47:12 +0000
 > State-Changed-Why:
 > never mind my patch, Christos committed essentially the same change just
 > now along with some other minor cleanup.
 >
 > Please give that a try...

 I tried and mount_nilfs on a wedge works as expected now.  Thanks!

 Grégoire

State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 14 Nov 2011 01:08:18 +0000
State-Changed-Why:
Excellent. Thanks for the patch!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.