misc/162519: [zfs] "zpool import" relies on buggy realpath()
rmh at FreeBSD.org
Sun Nov 13 14:50:08 UTC 2011
>Synopsis: [zfs] "zpool import" relies on buggy realpath() behaviour
>Arrival-Date: Sun Nov 13 14:50:07 UTC 2011
>Originator: Robert Millan
>Release: Debian GNU/kFreeBSD "sid"
zpool_find_import_impl() in cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c is relying on buggy realpath() behaviour.
FreeBSD realpath() does not currently conform to SUS specification (see PR 128933). It returns succesfully for invalid paths for which it should return ENOENT.
The code in zpool will stop working correctly when this bug is fixed:
- By default zpool_find_import_impl() operates on "/dev/dsk/" directory, which on FreeBSD doesn't exist.
- It begins by attempting to canonicalize this path using realpath(). This should fail with ENOENT and abort execution, but realpath() returns succesfully.
- It then proceeds to replace "/dev/dsk/" with "/dev/".
- Finally it opens devices from the (now correct) directory and imports them.
The correct solution IMHO is to replace all instances of "/dev/dsk/" with "/dev/". However this could be undesirable wrt new code imports.
Other possibilities could be to move the 'rdsk = "/dev/";' correction up so that it happens before realpath() call, or to add "errno != ENOENT" requirement before aborting with error.
More information about the freebsd-bugs