NetBSD Problem Report #42799

From www@NetBSD.org  Fri Feb 12 13:46:45 2010
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 49E8963C2AF
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 12 Feb 2010 13:46:45 +0000 (UTC)
Message-Id: <20100212134644.F01AE63BBAC@www.NetBSD.org>
Date: Fri, 12 Feb 2010 13:46:44 +0000 (UTC)
From: hugo@barafranca.com
Reply-To: hugo@barafranca.com
To: gnats-bugs@NetBSD.org
Subject: LVM logical volumes fail to attach if 'pseudo-device dm' is compiled in th kernel
X-Send-Pr-Version: www-1.0

>Number:         42799
>Category:       kern
>Synopsis:       LVM logical volumes fail to attach if 'pseudo-device dm' is compiled in th kernel
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    haad
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 12 13:50:00 +0000 2010
>Closed-Date:    Thu Feb 25 23:44:51 +0000 2010
>Last-Modified:  Sun Feb 28 23:40:03 +0000 2010
>Originator:     Hugo Silva
>Release:        5.99.24
>Organization:
>Environment:
NetBSD 5.99.24 (GENERIC) #1: Thu Feb 4 13:18:12 WET 2010 root@:/usr/obj/sys/arch/amd64/compile/GENERIC amd64 
>Description:
# lvm vgchange -a y fails on a kernel with pseudo-device dm compiled in:

**** KERNEL WITH dm BUILTIN ****

# modstat|grep dm
dm driver builtin 0 - -

# lvm vgchange -a y
Found duplicate PV NocTy4YPiwyYjss19YXT0mIEb59EeLTi: using /dev/rwd2f not /dev/rwd0f
0 logical volume(s) in volume group "xenvg0" now active
0 logical volume(s) in volume group "sysvg0" now active

dmesg output:
Unable to attach pseudo device dm/xenvg0-arcturus_sys0
Unable to attach pseudo device dm/xenvg0-procyon_sys0
Unable to attach pseudo device dm/xenvg0-procyon_data0
Unable to attach pseudo device dm/xenvg0-capella_sys0
Unable to attach pseudo device dm/xenvg0-capella_data0
Unable to attach pseudo device dm/xenvg0-sirius_sys0
Unable to attach pseudo device dm/sysvg0-root
Unable to attach pseudo device dm/sysvg0-tmp
Unable to attach pseudo device dm/sysvg0-var
Unable to attach pseudo device dm/sysvg0-usr
Unable to attach pseudo device dm/sysvg0-home
Unable to attach pseudo device dm/sysvg0-swap
Unable to attach pseudo device dm/sysvg0-usrlocal

# head /dev/xenvg0/arcturus_sys0
head: /dev/xenvg0/arcturus_sys0: Device not configured 



**** GENERIC kernel (dm dynamically loaded as a module) ****

# lvm vgchange -a y
Found duplicate PV NocTy4YPiwyYjss19YXT0mIEb59EeLTi: using /dev/rwd2f not /dev/rwd0f
6 logical volume(s) in volume group "xenvg0" now active
7 logical volume(s) in volume group "sysvg0" now active

# modstat | grep dm
dm driver filesys 0 20968 -

# head /dev/xenvg0/arcturus_sys0
&#65533;<&#65533;NetBSD401&#65533;&#65533;&#65533;&#65533;R&#65533;Z&#65533;&#65533;&#65533;&#65533;&#65533;f1&#65533;f&#65533;f;|tpf1&#65533;f1&#65533;&#65533;&#65533;&#65533;Ef&#65533;f.&#65533;}<&#65533;u
f&#65533;&#65533;tTf9&#65533;tO<<t<&#65533;uf&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;u&#65533;g&#65533;f&#65533;&#65533;uf&#65533;&#65533;f&#65533;f&#65533;&#65533;}&#65533;&#65533;&#65533;&#65533;f&#65533;&#65533;&#65533;w}tLf1&#65533;f&#65533;6&#65533;}&#65533;7&#65533;&#65533;u&#65533;M&#65533;u&#65533;Nf&#65533;.&#65533;}f&#65533;&#65533;uAR&#65533;&#65533;EP&#65533;&#65533;&#65533;&#65533;&#65533;B&#65533;&#65533;&#65533;U&#65533;&#65533;&#65533;?&#65533;&#65533;Z&#65533;&#65533;?&#65533;HZ9&#65533;t&#65533;&#65533;P&#65533;P}&#65533;z^&#65533;v&#65533;W}&#65533;p&#65533;&#65533;&#65533;&#65533;&#65533;f&#65533;>
&#65533;&#65533;&#65533;x&#65533;d}u&#65533;f&#65533;&#65533;&#65533;
`&#65533;&#65533;}&#65533;B&#65533;a&#65533;Z}r&#65533;&#65533;&#65533;`&#65533;&#65533;&#65533;Error
Disk readNot a bootxx imageNo NetBSD partition`&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;u&#65533;a&#65533;U&#65533;WEV&#65533;Xen Virtual ESDWEV&#65533;&#65533;&#65533; $&#65533;&#65533;&#65533;~&#65533;&#65533;&#65533;&#65533;&#65533;xx&#65533;%&#65533;&#65533;f&#65533;&#65533;&#65533; &#65533;L )&#65533;&#65533;&#65533;1&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;V&#65533;&#65533;RVR&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;ufZf[f&#65533;



>How-To-Repeat:
Compile dm in the kernel and try to enable lvs.
>Fix:
modload dm

However and due to another problem, Xen kernels are unable to load modules at this point in time- rendering LVM useless with Xen (builtin dm dm results in the problem in this PR, and modload'ing does not work) 

>Release-Note:

>Audit-Trail:
From: "Jonathan A. Kollasch" <jakllsch@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/42799 CVS commit: src/sys/dev/dm
Date: Thu, 25 Feb 2010 20:48:59 +0000

 Module Name:	src
 Committed By:	jakllsch
 Date:		Thu Feb 25 20:48:59 UTC 2010

 Modified Files:
 	src/sys/dev/dm: device-mapper.c dm_ioctl.c

 Log Message:
 Be sure to config_cfattach_attach() in dmattach().
 Loosely based on patch from Brian Brombacher,
 with other inspriation from vnd(4).

 This should fix PR kern/42799.

 While here, a few prototype, style and namespace pollution-related changes.


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.16 src/sys/dev/dm/device-mapper.c
 cvs rdiff -u -r1.20 -r1.21 src/sys/dev/dm/dm_ioctl.c

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

Responsible-Changed-From-To: kern-bug-people->haad
Responsible-Changed-By: haad@NetBSD.org
Responsible-Changed-When: Thu, 25 Feb 2010 23:43:14 +0000
Responsible-Changed-Why:
Assign PR to me. As I'm basically responsible for dm driver.


State-Changed-From-To: open->closed
State-Changed-By: haad@NetBSD.org
State-Changed-When: Thu, 25 Feb 2010 23:44:51 +0000
State-Changed-Why:
Problem was fixed in device-mapper.c revision 1.17.


From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/42799: LVM logical volumes fail to attach if
	'pseudo-device dm' is compiled in the kernel
Date: Sun, 28 Feb 2010 23:35:32 +0000

 This whole discussion wasn't sent to gnats...

    ------

 From: Brian <brian@planetunix.net>
 To: netbsd-bugs@netbsd.org, hugo@barafranca.com, haad@netbsd.org
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device
 	dm' is compiled in th kernel
 Date: Wed, 17 Feb 2010 20:39:47 -0500

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 Good evening all,

 I have provided a patch below to fix kern/42799: LVM logical volumes
 fail to attach if 'pseudo-device dm' is compiled in th kernel.

 The device-mapper written by Adam Hamsik for his GSoC project cannot be
 used as a builtin kernel module due to a bug.

 I have modified sys/dev/dm/device-mapper.c to fix this by calling
 config_cfattach_attach from dmattach and changed the order in which
 dmattach is called in dm_modcmd during module initialization.

 This allows LVM to be used under NetBSD/Xen dom0 and domU.  A different
 bug related to module loading for NetBSD/Xen prevents the device-mapper
 from being used as a module.

 I have not tested this change built as a module because I cannot load
 any modules on my NetBSD/Xen systems.  I will look into the module
 loading issue and create a patch at a later time.

 I have provided the patch inline below and as a file attachment.

 Sorry for creating a new thread as I was not on the list during the
 original bug report so I cannot 'Reply' to it directly.

 Sincerely,
 Brian Brombacher
 PlanetUnix Networks

 Index: sys/dev/dm/device-mapper.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dm/device-mapper.c,v
 retrieving revision 1.15
 diff -u -r1.15 device-mapper.c
 - --- sys/dev/dm/device-mapper.c  8 Jan 2010 00:27:48 -0000       1.15
 +++ sys/dev/dm/device-mapper.c  18 Feb 2010 01:17:20 -0000
 @@ -156,16 +156,13 @@

  	switch (cmd) {
  	case MODULE_CMD_INIT:
 - -		dmattach();
 - -
  		error = config_cfdriver_attach(&dm_cd);
  		if (error)
  			break;

 - -		error = config_cfattach_attach(dm_cd.cd_name, &dm_ca);
 +		error = dmattach();
  		if (error) {
  			config_cfdriver_detach(&dm_cd);
 - -			aprint_error("Unable to register cfattach for dm driver\n");

  			break;
  		}
 @@ -279,6 +276,14 @@
  int
  dmattach(void)
  {
 +	int error;
 +
 +	error = config_cfattach_attach(dm_cd.cd_name, &dm_ca);
 +	if (error) {
 +		aprint_error("Unable to register cfattach for dm driver\n");
 +
 +		return error;
 +	}

 	dm_target_init();
 	dm_dev_init();

 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (OpenBSD)

 iEYEARECAAYFAkt8mmEACgkQGTUZ+lOxJfCMZACgnAt7+CPpunwXgcvXXjnbJl9R
 kQcAoKCMyH8YVztdg6DWaZ+njA+l9oIW
 =yo+S
 -----END PGP SIGNATURE-----

 Index: sys/dev/dm/device-mapper.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/dm/device-mapper.c,v
 retrieving revision 1.15
 diff -u -r1.15 device-mapper.c
 --- sys/dev/dm/device-mapper.c	8 Jan 2010 00:27:48 -0000	1.15
 +++ sys/dev/dm/device-mapper.c	18 Feb 2010 01:17:20 -0000
 @@ -156,16 +156,13 @@

  	switch (cmd) {
  	case MODULE_CMD_INIT:
 -		dmattach();
 -
  		error = config_cfdriver_attach(&dm_cd);
  		if (error)
  			break;

 -		error = config_cfattach_attach(dm_cd.cd_name, &dm_ca);
 +		error = dmattach();
  		if (error) {
  			config_cfdriver_detach(&dm_cd);
 -			aprint_error("Unable to register cfattach for dm driver\n");

  			break;
  		}
 @@ -279,6 +276,14 @@
  int
  dmattach(void)
  {
 +	int error;
 +
 +	error = config_cfattach_attach(dm_cd.cd_name, &dm_ca);
 +	if (error) {
 +		aprint_error("Unable to register cfattach for dm driver\n");
 +
 +		return error;
 +	}

  	dm_target_init();
  	dm_dev_init();



 From: Manuel Bouyer <bouyer@antioche.eu.org>
 To: Brian <brian@planetunix.net>
 Cc: netbsd-bugs@NetBSD.org, hugo@barafranca.com, haad@NetBSD.org
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device
 	dm' is compiled in th kernel
 Date: Thu, 18 Feb 2010 19:56:01 +0100

 On Wed, Feb 17, 2010 at 08:39:47PM -0500, Brian wrote:
 > [...]
 > I have not tested this change built as a module because I cannot load
 > any modules on my NetBSD/Xen systems.  I will look into the module
 > loading issue and create a patch at a later time.

 This is not a bug, but a much, much deeper issue: different ABI.
 NetBSD/native and NetBSD/Xen are really different machines, I really
 don't think we want to share modules between the two.

 -- 
 Manuel Bouyer <bouyer@antioche.eu.org>
      NetBSD: 26 ans d'experience feront toujours la difference
 --


 From: haad <haaaad@gmail.com>
 To: Manuel Bouyer <bouyer@antioche.eu.org>
 Cc: Brian <brian@planetunix.net>, netbsd-bugs@netbsd.org,
 	hugo@barafranca.com
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device 
 	dm' is compiled in th kernel
 Date: Thu, 18 Feb 2010 22:07:44 +0100

 hi,

 On Thu, Feb 18, 2010 at 7:56 PM, Manuel Bouyer <bouyer@antioche.eu.org> wrote:
 > On Wed, Feb 17, 2010 at 08:39:47PM -0500, Brian wrote:
 >> [...]
 >> I have not tested this change built as a module because I cannot load
 >> any modules on my NetBSD/Xen systems. ?I will look into the module
 >> loading issue and create a patch at a later time.
 >
 > This is not a bug, but a much, much deeper issue: different ABI.
 > NetBSD/native and NetBSD/Xen are really different machines, I really
 > don't think we want to share modules between the two.

 Then it should be possible to build modules for NetBSD/Xen. Modules doesn't
 need to be shared but should be loadable and buildable for xen.



 -- 


 Regards.

 Adam


 From: Manuel Bouyer <bouyer@antioche.eu.org>
 To: haad <haaaad@gmail.com>
 Cc: Brian <brian@planetunix.net>, netbsd-bugs@netbsd.org,
 	hugo@barafranca.com
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device
 	dm' is compiled in th kernel
 Date: Thu, 18 Feb 2010 23:21:27 +0100

 On Thu, Feb 18, 2010 at 10:07:44PM +0100, haad wrote:
 > Then it should be possible to build modules for NetBSD/Xen. Modules doesn't
 > need to be shared but should be loadable and buildable for xen.

 Sure. The build system doesn't support this at this time ...

 -- 
 Manuel Bouyer <bouyer@antioche.eu.org>
      NetBSD: 26 ans d'experience feront toujours la difference
 --


 From: matthew green <mrg@eterna.com.au>
 to: Manuel Bouyer <bouyer@antioche.eu.org>
 cc: Brian <brian@planetunix.net>, netbsd-bugs@netbsd.org,
 	hugo@barafranca.com, haad <haaaad@gmail.com>
 subject: re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device
 	dm' is compiled in th kernel
 Date: Sat, 20 Feb 2010 14:30:05 +1100


    On Thu, Feb 18, 2010 at 10:07:44PM +0100, haad wrote:
    > Then it should be possible to build modules for NetBSD/Xen. Modules doesn't
    > need to be shared but should be loadable and buildable for xen.

    Sure. The build system doesn't support this at this time ...


 i hope to have a solution for this in place for netbsd-6, reusing
 the work i've done in src/compat.


 .mrg.


 From: haad <haaaad@gmail.com>
 To: Brian <brian@planetunix.net>
 Cc: netbsd-bugs@netbsd.org, hugo@barafranca.com
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device 
 	dm' is compiled in th kernel
 Date: Thu, 18 Feb 2010 22:18:23 +0100

 On Thu, Feb 18, 2010 at 2:39 AM, Brian <brian@planetunix.net> wrote:
 > -----BEGIN PGP SIGNED MESSAGE-----
 > Hash: SHA1
 >
 > Good evening all,
 >
 > I have provided a patch below to fix kern/42799: LVM logical volumes
 > fail to attach if 'pseudo-device dm' is compiled in th kernel.
 >
 > The device-mapper written by Adam Hamsik for his GSoC project cannot be
 > used as a builtin kernel module due to a bug.
 >
 > I have modified sys/dev/dm/device-mapper.c to fix this by calling
 > config_cfattach_attach from dmattach and changed the order in which
 > dmattach is called in dm_modcmd during module initialization.


 I think that we need to change dmdetach routine as well.  Because it
 is called from shutdown hooks ?

 -- 


 Regards.

 Adam


 From: Brian <brian@planetunix.net>
 To: haad <haaaad@gmail.com>
 CC: netbsd-bugs@NetBSD.org, hugo@barafranca.com
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device
 	dm' is compiled in th kernel
 Date: Thu, 18 Feb 2010 21:00:40 -0500

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 haad wrote:
 > 
 > I think that we need to change dmdetach routine as well.  Because it
 > is called from shutdown hooks ?
 > 

 Yes, it looks like dmdestroy and dm_modcmd for MODULE_CMD_FINI should
 probably also be refactored to call config_cfattach_detach in dmdestroy.

 Sincerely,
 Brian Brombacher
 PlanetUnix Networks
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (OpenBSD)

 iEYEARECAAYFAkt98McACgkQGTUZ+lOxJfDlNwCfSrmYyL5hb8MiYKxQn6Hfmv0s
 334Anj+NaZSc4g8QyJhD8Et8e6xulFxB
 =SJS4
 -----END PGP SIGNATURE-----


 From: Hugo Silva <hugo@barafranca.com>
 To: Brian <brian@planetunix.net>
 CC: haad <haaaad@gmail.com>, netbsd-bugs@NetBSD.org
 Subject: Re: kern/42799: LVM logical volumes fail to attach if 'pseudo-device
 	dm' is compiled in th kernel
 Date: Sat, 20 Feb 2010 20:23:48 +0000

 Brian wrote:
 > -----BEGIN PGP SIGNED MESSAGE-----
 > Hash: SHA1
 >
 > haad wrote:
 >   
 >> I think that we need to change dmdetach routine as well.  Because it
 >> is called from shutdown hooks ?
 >>
 >>     
 >
 > Yes, it looks like dmdestroy and dm_modcmd for MODULE_CMD_FINI should
 > probably also be refactored to call config_cfattach_detach in dmdestroy.
 >
 > Sincerely,
 > Brian Brombacher
 > PlanetUnix Networks
 > -----BEGIN PGP SIGNATURE-----
 > Version: GnuPG v1.4.9 (OpenBSD)
 >
 > iEYEARECAAYFAkt98McACgkQGTUZ+lOxJfDlNwCfSrmYyL5hb8MiYKxQn6Hfmv0s
 > 334Anj+NaZSc4g8QyJhD8Et8e6xulFxB
 > =SJS4
 > -----END PGP SIGNATURE-----
 >   

 I confirm the patch works as expected. I am now able to use lvm when  
 'pseudo-device dm' is in the kernel.

>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.