Restore the ability to open a raw disk or partition in loader(8).

The disk_open() function searches for "the best partition" when slice and
partition information is not provided as part of the device name.  As of
r345477 the slice and partition fields of a disk_devdesc are initialized to
D_SLICEWILD and D_PARTWILD; in the past they were initialized to -1, which
was sometimes interpreted as meaning 'wildcard' and sometimes as 'open the
raw partition' depending on the context.  So as an unintended side effect of
r345477 it became basically impossible to ever open a disk or partition
without doing the 'best partition' search.  One visible effect of that was
the inability to open the raw disk to read the partition table correctly in
zfs_probe_dev(), leading to failures to find the zfs pool unless it was on
the first partition.

Now instead of always initializing slice and partition to wildcards, the
disk_parsedev() function initializes them based on the presence of a
path/file name following the device.  If there is any path or filename
following the ':' that ends the device name, then slice and partition are
initialized to D_SLICEWILD and D_PARTWILD.  If there is nothing after the
':' then it is considered to be a request to open the raw device or
partition itself (not a file stored within it), and the fields are
initialized to D_SLICENONE and D_PARTNONE.

With this change in place, all the tests in src/tools/boot are succesful
again, including the recently-added cases of booting from a zfs pool on
a partition other than slice 1 of the device.

PR:		236981
This commit is contained in:
Ian Lepore 2019-04-25 15:09:21 +00:00
parent c83651445b
commit e77f4eb2a0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346675

View File

@ -392,8 +392,20 @@ disk_parsedev(struct disk_devdesc *dev, const char *devspec, const char **path)
np = devspec;
unit = -1;
slice = D_SLICEWILD;
partition = D_PARTWILD;
/*
* If there is path/file info after the device info, then any missing
* slice or partition info should be considered a request to search for
* an appropriate partition. Otherwise we want to open the raw device
* itself and not try to fill in missing info by searching.
*/
if ((cp = strchr(np, ':')) != NULL && cp[1] != '\0') {
slice = D_SLICEWILD;
partition = D_PARTWILD;
} else {
slice = D_SLICENONE;
partition = D_PARTNONE;
}
if (*np != '\0' && *np != ':') {
unit = strtol(np, &cp, 10);
if (cp == np)