From nobody@FreeBSD.org  Wed Sep  1 22:51:07 2010
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 01D1310656C9
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Sep 2010 22:51:07 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 93ABD8FC25
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Sep 2010 22:51:06 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o81Mp63T052736
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 1 Sep 2010 22:51:06 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o81Mp6Xe052735;
	Wed, 1 Sep 2010 22:51:06 GMT
	(envelope-from nobody)
Message-Id: <201009012251.o81Mp6Xe052735@www.freebsd.org>
Date: Wed, 1 Sep 2010 22:51:06 GMT
From: Aurelien Jarno <aurelien@aurel32.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: zpool import -d /dev tries to open weird devices
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         150207
>Category:       kern
>Synopsis:       zpool(1): zpool import -d /dev tries to open weird devices
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 01 23:00:09 UTC 2010
>Closed-Date:    Sun Oct 23 10:07:39 UTC 2011
>Last-Modified:  Sun Oct 23 10:07:39 UTC 2011
>Originator:     Aurelien Jarno
>Release:        8.1
>Organization:
>Environment:
FreeBSD freebsd.aurel32.net 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:55:53 UTC 2010     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
When running "zpool import -d /dev", this command should loop on all devices in /dev and try to open them to look for a zpool. Unfortunately there is a small programming error in the way the name of the device is computed, as shown with ktrace:

 16061 zpool    CALL  open(0xbfbfa724,O_RDONLY,<unused>0x280cdaef)
 16061 zpool    NAMI  "/dev//geom.ctl"
 16061 zpool    CALL  open(0xbfbfa724,O_RDONLY,<unused>0x280cdaef)
 16061 zpool    NAMI  "/dev//geom.ctl/console"
 16061 zpool    RET   open -1 errno 20 Not a directory
 16061 zpool    CALL  open(0xbfbfa724,O_RDONLY,<unused>0x280cdaef)
 16061 zpool    NAMI  "/dev//geom.ctl/console/devctl"

[...]

 16061 zpool    CALL  open(0xbfbfa724,O_RDONLY,<unused>0x280cdaef)
 16061 zpool    NAMI  "/dev//geom.ctl/console/devctl/null/zero/klog/pci/ptmx/ctty/random/urandom/bpf/bpf0/sysmouse/dcons/dgdb/fido/nfslock/audit/fd/stdin/stdout/stderr/io/kbdmux0/kbd1/mem/kmem/ata/acpi/led/atkbd0/kbd0/psm0/bpsm0/lpt0/lpt0.ctl/ppi0/ttyu0/ttyu0.init/ttyu0.lock/cuau0/cuau0.init/cuau0.lock/ttyv0/ttyv1/ttyv2/ttyv3/ttyv4/ttyv5/ttyv6/ttyv7/ttyv8/ttyv9/ttyva/ttyvb/ttyvc/ttyvd/ttyve/ttyvf/consolectl/usbctl/mdctl/devstat/xpt0/ad0/ad0s1/acd0/ad0s1a/ad0s1b/ufsid/log/pts/zfs"

>How-To-Repeat:
Just run zpool import -d /dev
>Fix:
The problem comes from cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c 

The file name is computed using:

  (void) snprintf(path, sizeof (path), "%s/%s", rdsk,
                  dp->d_name);

However, a few lines upper, rpath is assigned to rdev:

  if (strcmp(path, "/dev/dsk/") == 0)
          rdsk = "/dev/rdsk/";
  else
          rdsk = path;

Thes best way to fix that is probably to avoid reusing variables.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: arundel 
Responsible-Changed-When: Thu Sep 2 00:50:09 UTC 2010 
Responsible-Changed-Why:  
Assign to maintainer(s). 

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

From: Robert Millan <rmh@freebsd.org>
To: bug-followup@FreeBSD.org, aurelien@aurel32.net
Cc: pjd@freebsd.org
Subject: Re: kern/150207: zpool(1): zpool import -d /dev tries to open weird devices
Date: Fri, 21 Oct 2011 22:12:38 +0200

 This might have been fixed by pjd@ in r219089. A quick look in the
 code doesn't show traces of this problem.
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: ndz 23 paź 2011 10:06:19 UTC 
State-Changed-Why:  
Thanks for the report. 
I tried to reproduce it on HEAD/9.0 and there is no such problem anymore. 


Responsible-Changed-From-To: freebsd-fs->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: ndz 23 paź 2011 10:06:19 UTC 
Responsible-Changed-Why:  
I'll take this one. 

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