Bug 157691 - [zfs] [patch] zpool import -d broken
Summary: [zfs] [patch] zpool import -d broken
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Xin LI
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-07 18:30 UTC by Christopher Key
Modified: 2011-06-09 23:58 UTC (History)
0 users

See Also:


Attachments
zpool-import-d-patch (1.53 KB, text/plain)
2011-06-07 18:30 UTC, Christopher Key
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Key 2011-06-07 18:30:09 UTC
zfs import -d <dir> is supposed to enumerate the contents of dir, opening and statting each item within before possible further processing.  However, the way in which the path to be opened and statted is built is broken.  The fundamental problem is repeated usage of,

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

where,

rdsk == path

How-To-Repeat: Without patch:

chris@chacal:~> ls -al /dev/mirror
total 1
dr-xr-xr-x   2 root  wheel          512  6 Jun 19:20 .
dr-xr-xr-x  11 root  wheel          512  6 Jun 19:20 ..
crw-r-----   1 root  operator    0, 108  6 Jun 19:20 gm0
crw-r-----   1 root  operator    0, 112  6 Jun 19:20 gm0p1
crw-r-----   1 root  operator    0, 113  6 Jun 19:20 gm0p2
crw-r-----   1 root  operator    0, 114  6 Jun 19:20 gm0p3
crw-r-----   1 root  operator    0, 115  6 Jun 19:20 gm0p4
crw-r-----   1 root  operator    0, 116  6 Jun 19:20 gm0p5
crw-r-----   1 root  operator    0, 117  6 Jun 19:20 gm0p6
crw-r-----   1 root  operator    0, 143  6 Jun 19:20 gm1
crw-r-----   1 root  operator    0, 189  6 Jun 19:20 gm1s1
crw-r-----   1 root  operator    0, 190  6 Jun 19:20 gm1s2
crw-r-----   1 root  operator    0, 191  6 Jun 19:20 gm1s3
chris@chacal:~> sudo truss zpool import -d /dev/mirror 2>&1 | grep /dev
open("/dev/zfs",O_RDWR,00) 	 	 = 3 (0x3)
open("/dev/zero",O_RDONLY,0666)		      = 4 (0x4)
lstat("/dev",{ mode=dr-xr-xr-x ,inode=2,size=512,blksize=4096 }) = 0 (0x0)
lstat("/dev/mirror",{ mode=dr-xr-xr-x ,inode=215,size=512,blksize=4096 }) = 0 (0x0)
stat("/dev/mirror/",{ mode=dr-xr-xr-x ,inode=215,size=512,blksize=4096 }) = 0 (0x0)
open("/dev/mirror/",O_NONBLOCK,01)    				        = 6 (0x6)
open("/dev/mirror//gm0",O_RDONLY,00)					   = 7 (0x7)
open("/dev/mirror//gm0/gm0p1",O_RDONLY,00)				    ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4/gm0p5",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4/gm0p5/gm0p6",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4/gm0p5/gm0p6/gm1",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4/gm0p5/gm0p6/gm1/gm1s1",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4/gm0p5/gm0p6/gm1/gm1s1/gm1s2",O_RDONLY,00) ERR#20 'Not a directory'
open("/dev/mirror//gm0/gm0p1/gm0p2/gm0p3/gm0p4/gm0p5/gm0p6/gm1/gm1s1/gm1s2/gm1s3",O_RDONLY,00) ERR#20 'Not a directory'


With patch:

chris@chacal:~> ls -al /dev/mirror
total 1
dr-xr-xr-x   2 root  wheel          512  6 Jun 19:20 .
dr-xr-xr-x  11 root  wheel          512  6 Jun 19:20 ..
crw-r-----   1 root  operator    0, 108  6 Jun 19:20 gm0
crw-r-----   1 root  operator    0, 112  6 Jun 19:20 gm0p1
crw-r-----   1 root  operator    0, 113  6 Jun 19:20 gm0p2
crw-r-----   1 root  operator    0, 114  6 Jun 19:20 gm0p3
crw-r-----   1 root  operator    0, 115  6 Jun 19:20 gm0p4
crw-r-----   1 root  operator    0, 116  6 Jun 19:20 gm0p5
crw-r-----   1 root  operator    0, 117  6 Jun 19:20 gm0p6
crw-r-----   1 root  operator    0, 143  6 Jun 19:20 gm1
crw-r-----   1 root  operator    0, 189  6 Jun 19:20 gm1s1
crw-r-----   1 root  operator    0, 190  6 Jun 19:20 gm1s2
crw-r-----   1 root  operator    0, 191  6 Jun 19:20 gm1s3
chris@chacal:~> sudo truss zpool import -d /dev/mirror 2>&1 | grep /dev
open("/dev/zfs",O_RDWR,00) 	 	 = 3 (0x3)
open("/dev/zero",O_RDONLY,0666)		      = 4 (0x4)
lstat("/dev",{ mode=dr-xr-xr-x ,inode=2,size=512,blksize=4096 }) = 0 (0x0)
lstat("/dev/mirror",{ mode=dr-xr-xr-x ,inode=215,size=512,blksize=4096 }) = 0 (0x0)
stat("/dev/mirror/",{ mode=dr-xr-xr-x ,inode=215,size=512,blksize=4096 }) = 0 (0x0)
open("/dev/mirror/",O_NONBLOCK,0144)  				        = 6 (0x6)
open("/dev/mirror/gm0",O_RDONLY,01760)					   = 7 (0x7)
open("/dev/mirror/gm0p1",O_RDONLY,01756)				    = 7 (0x7)
open("/dev/mirror/gm0p2",O_RDONLY,01756)				     = 7 (0x7)
open("/dev/mirror/gm0p3",O_RDONLY,01756)				      = 7 (0x7)
open("/dev/mirror/gm0p4",O_RDONLY,01756)				       = 7 (0x7)
open("/dev/mirror/gm0p5",O_RDONLY,01756)				        = 7 (0x7)
open("/dev/mirror/gm0p6",O_RDONLY,01756)					 = 7 (0x7)
open("/dev/mirror/gm1",O_RDONLY,01760)						    = 7 (0x7)
open("/dev/mirror/gm1s1",O_RDONLY,01756)					     = 7 (0x7)
open("/dev/mirror/gm1s2",O_RDONLY,01756)					      = 7 (0x7)
open("/dev/mirror/gm1s3",O_RDONLY,01756)					       = 7 (0x7)
Comment 1 Christopher Key 2011-06-08 15:32:53 UTC
Forgot to mention that this has apparently been fixed in 9-CURRENT by
the newer version of ZFS.

Subsequent investigation has shown that the new version of ZFS has also
been MFCed to 8-STABLE, so 8.2 is the last release affected by this
bug.  It can therefore probably be closed.
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2011-06-09 22:28:54 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 3 Xin LI freebsd_committer freebsd_triage 2011-06-09 23:58:07 UTC
State Changed
From-To: open->closed

This should have been fixed in a newer 8-STABLE snapshot, per 
submitter. 


Comment 4 Xin LI freebsd_committer freebsd_triage 2011-06-09 23:58:07 UTC
Responsible Changed
From-To: freebsd-fs->delphij

Take just in case.