From pawmal@unia.3lo.lublin.pl  Thu Feb 27 14:21:04 2003
Return-Path: <pawmal@unia.3lo.lublin.pl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2086937B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Feb 2003 14:21:04 -0800 (PST)
Received: from unia.3lo.lublin.pl (unia.3lo.lublin.pl [212.182.70.2])
	by mx1.FreeBSD.org (Postfix) with SMTP id E004E43F75
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Feb 2003 14:21:02 -0800 (PST)
	(envelope-from pawmal@unia.3lo.lublin.pl)
Received: (qmail 56788 invoked by uid 1007); 27 Feb 2003 22:22:22 -0000
Message-Id: <20030227222222.56787.qmail@unia.3lo.lublin.pl>
Date: 27 Feb 2003 22:22:22 -0000
From: Pawel Malachowski <pawmal@unia.3lo.lublin.pl>
Reply-To: Pawel Malachowski <pawmal@unia.3lo.lublin.pl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: kldstat shows module after unsuccessfull kldload
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         48759
>Category:       kern
>Synopsis:       kldstat shows module after unsuccessfull kldload
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    demon
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 27 14:30:07 PST 2003
>Closed-Date:    Sat May 28 22:38:38 GMT 2005
>Last-Modified:  Sat May 28 22:38:38 GMT 2005
>Originator:     Pawe Maachowski
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
ASK ZiN
>Environment:
System: FreeBSD unia.3lo.lublin.pl 4.7-STABLE FreeBSD 4.7-STABLE #1: Wed Nov 27 22:08:42 CET 2002 root@unia.3lo.lublin.pl:/usr/src/sys/compile/UNIA i386


	
>Description:
Loading of driver.ko fails (because it was previously linked with kernel),
but driver.ko is now shown by kldstat.

	
>How-To-Repeat:
Try to load a module that is known to be compiled in kernel.
% grep gif /usr/src/sys/i386/conf/THISPCCONFIG
pseudo-device   gif             # IPv6 and IPv4 tunneling
% kldstat
Id Refs Address    Size     Name
 1    5 0xc0100000 3032c8   kernel
 3    3 0xc6f47000 e000     miibus.ko
 4    1 0xc6f5b000 9000     if_xl.ko
 5    1 0xc6f64000 18000    ipl.ko
 6    1 0xc7090000 6000     if_rl.ko
% kldload if_gif
kldload: can't load if_gif: File exists
Feb 27 23:14:46 ciach /kernel: can't re-use a leaf (gifttl)!
Feb 27 23:14:46 ciach /kernel: module_register: module if_gif already exists!
Feb 27 23:14:46 ciach /kernel: linker_file_sysinit "if_gif.ko" failed to register! 17
% kldstat
Id Refs Address    Size     Name
 1    6 0xc0100000 3032c8   kernel
 3    3 0xc6f47000 e000     miibus.ko
 4    1 0xc6f5b000 9000     if_xl.ko
 5    1 0xc6f64000 18000    ipl.ko
 6    1 0xc7090000 6000     if_rl.ko
 7    1 0xc72b5000 5000     if_gif.ko

	
>Fix:
Unknown.
	


>Release-Note:
>Audit-Trail:

From: Dmitry Sivachenko <demon@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc: pawmal@unia.3lo.lublin.pl
Subject: Re: kern/48759: kldstat shows module after unsuccessfull kldload
Date: Wed, 30 Apr 2003 15:46:52 +0400

 Here is possible fix:
 
 For -stable:
 
 --- /sys/kern/kern_linker.c	Wed Nov 21 20:50:35 2001
 +++ kern_linker.c	Wed Apr 30 14:31:25 2003
 @@ -286,6 +286,14 @@ linker_load_file(const char* filename, l
  	if (lf) {
  	    linker_file_register_sysctls(lf);
  	    error = linker_file_sysinit(lf);
 +	    if (error) {
 +		/*
 +		 * Unset LINKER_FILE_LINKED flag so SYSUNINITs are not
 +		 * executed because of error in linker_file_sysinit() above.
 +		 */
 +		lf->flags &= ~LINKER_FILE_LINKED;
 +		(void)linker_file_unload(lf);
 +	    }
  
  	    *result = lf;
  	    goto out;
 
 for -current:
 
 --- kern_linker.c.orig	Wed Apr 30 14:53:49 2003
 +++ kern_linker.c	Wed Apr 30 15:36:52 2003
 @@ -297,9 +297,11 @@ linker_file_register_modules(linker_file
  		KLD_DPF(FILE, ("Registering module %s in %s\n",
  		    moddata->name, lf->filename));
  		error = module_register(moddata, lf);
 -		if (error)
 +		if (error) {
  			printf("Module %s failed to register: %d\n",
  			    moddata->name, error);
 +			return (error);
 +		}
  	}
  	return (0);
  }
 @@ -351,7 +353,11 @@ linker_load_file(const char *filename, l
  		if (error != ENOENT)
  			foundfile = 1;
  		if (lf) {
 -			linker_file_register_modules(lf);
 +			error = linker_file_register_modules(lf);
 +			if (error == EEXIST) {
 +				(void)linker_file_unload(lf);
 +				goto out;
 +			}
  			linker_file_register_sysctls(lf);
  			linker_file_sysinit(lf);
  			lf->flags |= LINKER_FILE_LINKED;

From: "Pawel Malachowski" <pawmal@unia.3lo.lublin.pl>
To: Dmitry Sivachenko <demon@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/48759: kldstat shows module after unsuccessfull kldload
Date: Wed, 30 Apr 2003 22:41:25 +0200

 On 30 Apr 2003 at 15:46, Dmitry Sivachenko wrote:
 
 > For -stable:
 
 I've applied this on my fresh 4.8-STABLE system and it looks good:
 
 # kldstat
 Id Refs Address    Size     Name
  1    4 0xc0100000 30d664   kernel
  2    1 0xc6f43000 18000    ipl.ko
  3    2 0xc7143000 7000     ipfw.ko
  4    1 0xc714c000 6000     dummynet.ko
 # kldload if_gif
 kldload: can't load if_gif: File exists
 # Apr 30 22:41:26 xxx /kernel: can't re-use a leaf (gifttl)!
 Apr 30 22:41:26 xxx /kernel: module_register: module if_gif already exists!
 Apr 30 22:41:26 xxx /kernel: linker_file_sysinit "if_gif.ko" failed to register! 17
 # kldstat
 Id Refs Address    Size     Name
  1    4 0xc0100000 30d664   kernel
  2    1 0xc6f43000 18000    ipl.ko
  3    2 0xc7143000 7000     ipfw.ko
  4    1 0xc714c000 6000     dummynet.ko
 #
 
 
 cheers,
 -- 
 Pawe Maachowski
 
Responsible-Changed-From-To: freebsd-bugs->demon 
Responsible-Changed-By: kris 
Responsible-Changed-When: Mon Jul 14 04:33:32 PDT 2003 
Responsible-Changed-Why:  
Assign to demon since his fix apparently works 

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

From: Mikhail Teterin <mi+kde@aldan.algebra.com>
To: bug-followup@FreeBSD.org, pawmal@unia.3lo.lublin.pl
Cc:  
Subject: Re: kern/48759: kldstat shows module after unsuccessfull kldload
Date: Sat, 21 May 2005 16:27:19 -0400

 I wonder, why this is still here. The fix is known for two years...
 
 	-mi
 
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: Sat May 28 22:38:11 GMT 2005 
State-Changed-Why:  
Fixed in HEAD, thanks! 

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