From nobody@FreeBSD.org  Tue Jan 10 11:58:01 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 73A35106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Jan 2012 11:58:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 481068FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Jan 2012 11:58:01 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0ABw0E2070167
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Jan 2012 11:58:00 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0ABw0Ml070166;
	Tue, 10 Jan 2012 11:58:00 GMT
	(envelope-from nobody)
Message-Id: <201201101158.q0ABw0Ml070166@red.freebsd.org>
Date: Tue, 10 Jan 2012 11:58:00 GMT
From: Robert Nagy <robert@nerd.hu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: avoid reloading modules in devd for usb devices
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         163986
>Category:       kern
>Synopsis:       [modules] [patch] avoid reloading modules in devd for usb devices
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 10 12:00:24 UTC 2012
>Closed-Date:    
>Last-Modified:  Tue Jan 10 16:04:42 UTC 2012
>Originator:     Robert Nagy
>Release:        FreeBSD 9.0-RC3 amd64
>Organization:
>Environment:
FreeBSD x200s.humppa.hu 9.0-RC3 FreeBSD 9.0-RC3 #0: Sun Dec 4 08:56:36 UTC 2011 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
devd tries to reload kernel modules which are loaded already because of multiple already-attached devices
in a system. e.g.: umodem, ng_ubt.

This causes a lot of error messages on boot which is quiet annoying.

>How-To-Repeat:
boot any machine with multiple usb devices attached to it
>Fix:
Only try to load the module if it's not loaded already.
The attached patch adds a quiet feature to kldstat's -n flag so that we can rely on just the return values of kldstat and load based on that in the action fields of /etc/devd/usb.conf.

The diff does not actually include the generated usb.conf because that would have been too big for the attachment.


Patch attached with submission follows:

Index: sbin/kldstat/kldstat.c
===================================================================
--- sbin/kldstat/kldstat.c	(revision 229928)
+++ sbin/kldstat/kldstat.c	(working copy)
@@ -146,8 +146,12 @@
     }
 
     if (filename != NULL) {
-	if ((fileid = kldfind(filename)) < 0)
-	    err(1, "can't find file %s", filename);
+	if ((fileid = kldfind(filename)) < 0) {
+	    if (!quiet)
+		warn("can't find file %s", filename);
+	    return 1;
+	} else if (quiet)
+	    return 0;
     }
 
     printf("Id Refs Address%*c Size     Name\n", POINTER_WIDTH - 7, ' ');
Index: sbin/kldstat/kldstat.8
===================================================================
--- sbin/kldstat/kldstat.8	(revision 229928)
+++ sbin/kldstat/kldstat.8	(working copy)
@@ -35,10 +35,12 @@
 .Nm
 .Op Fl v
 .Op Fl i Ar id
-.Op Fl n Ar filename
 .Nm
 .Op Fl q
 .Op Fl m Ar modname
+.Nm
+.Op Fl qv
+.Op Fl n Ar filename
 .Sh DESCRIPTION
 The
 .Nm
Index: tools/tools/bus_autoconf/bus_usb.c
===================================================================
--- tools/tools/bus_autoconf/bus_usb.c	(revision 229928)
+++ tools/tools/bus_autoconf/bus_usb.c	(working copy)
@@ -317,8 +317,8 @@
 		printf("	match \"intprotocol\" \"0x%02x\";\n",
 		    id->bInterfaceProtocol);
 	}
-	printf("	action \"kldload %s\";\n"
-	    "};\n\n", id->module_name);
+	printf("	action \"kldstat -qn %s || kldload %s\";\n"
+	    "};\n\n", id->module_name, id->module_name);
 
 	return (n);
 }


>Release-Note:
>Audit-Trail:
>Unformatted:
