Bug 150207 - zpool(1): zpool import -d /dev tries to open weird devices
Summary: zpool(1): zpool import -d /dev tries to open weird devices
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Pawel Jakub Dawidek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-02 00:00 UTC by Aurelien Jarno
Modified: 2011-10-23 11:07 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aurelien Jarno 2010-09-02 00:00:09 UTC
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"

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.
How-To-Repeat: Just run zpool import -d /dev
Comment 1 Alexander Best freebsd_committer freebsd_triage 2010-09-02 01:50:09 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Assign to maintainer(s).
Comment 2 Robert Millan freebsd_committer freebsd_triage 2011-10-21 21:12:38 UTC
This might have been fixed by pjd@ in r219089. A quick look in the
code doesn't show traces of this problem.
Comment 3 Pawel Jakub Dawidek freebsd_committer freebsd_triage 2014-06-01 07:23:23 UTC
State Changed
From-To: open->closed

Thanks for the report. 
I tried to reproduce it on HEAD/9.0 and there is no such problem anymore. 


Comment 4 Pawel Jakub Dawidek freebsd_committer freebsd_triage 2014-06-01 07:23:23 UTC
Responsible Changed
From-To: freebsd-fs->pjd

I'll take this one.