4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "@(#)spa_boot.c 1.1 08/04/09 SMI"
30 #include <sys/sunddi.h>
37 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
38 DDI_PROP_DONTPASS, "zfs-bootfs", &zfs_bp) !=
45 spa_free_bootfs(char *bootfs)
47 ddi_prop_free(bootfs);
51 * Calculate how many device pathnames are in devpath_list.
52 * The devpath_list could look like this:
54 * "/pci@1f,0/ide@d/disk@0,0:a /pci@1f,o/ide@d/disk@2,0:a"
57 spa_count_devpath(char *devpath_list)
60 char *tmp_path, *blank;
63 tmp_path = devpath_list;
65 /* skip leading blanks */
66 while (*tmp_path == ' ')
69 while ((blank = strchr(tmp_path, ' ')) != NULL) {
72 /* skip contiguous blanks */
78 if (strlen(tmp_path) > 0)
85 * Only allow booting the device if it has the same vdev information as
86 * the most recently updated vdev (highest txg) and is in a valid state.
88 * GRUB passes online/active device path names, e.g.
89 * "/pci@1f,0/ide@d/disk@0,0:a /pci@1f,o/ide@d/disk@2,0:a"
90 * to the kernel. The best vdev should have the same matching online/active
91 * list as what GRUB passes in.
94 spa_check_devstate(char *devpath_list, char *dev, nvlist_t *conf)
96 nvlist_t *nvtop, **child;
97 uint_t label_path, grub_path, c, children;
100 VERIFY(nvlist_lookup_nvlist(conf, ZPOOL_CONFIG_VDEV_TREE,
102 VERIFY(nvlist_lookup_string(nvtop, ZPOOL_CONFIG_TYPE, &type) == 0);
104 if (strcmp(type, VDEV_TYPE_DISK) == 0)
105 return (spa_rootdev_validate(nvtop)? 0 : EINVAL);
107 ASSERT(strcmp(type, VDEV_TYPE_MIRROR) == 0);
109 VERIFY(nvlist_lookup_nvlist_array(nvtop, ZPOOL_CONFIG_CHILDREN,
110 &child, &children) == 0);
113 * Check if the devpath_list is the same as the path list in conf.
114 * If these two lists are different, then the booting device is not an
115 * up-to-date device that can be booted.
118 for (c = 0; c < children; c++) {
121 if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_PHYS_PATH,
125 if (spa_rootdev_validate(child[c])) {
126 if (strstr(devpath_list, physpath) == NULL)
132 if (blank = strchr(dev, ' '))
134 if (strcmp(physpath, dev) == 0)
141 grub_path = spa_count_devpath(devpath_list);
143 if (label_path != grub_path)
150 * Given a list of vdev physpath names, pick the vdev with the most recent txg,
151 * and return the point of the device's physpath in the list and the device's
152 * label configuration. The content of the label would be the most recent
153 * updated information.
156 spa_get_rootconf(char *devpath_list, char **bestdev, nvlist_t **bestconf)
158 nvlist_t *conf = NULL;
161 char *devpath, *blank;
163 devpath = devpath_list;
166 while (devpath[0] == ' ')
169 while ((blank = strchr(devpath, ' ')) != NULL) {
171 spa_check_rootconf(devpath, &dev, &conf, &txg);
174 while (*blank == ' ')
179 /* for the only or the last devpath in the devpath_list */
180 if (strlen(devpath) > 0)
181 spa_check_rootconf(devpath, &dev, &conf, &txg);
187 * dev/conf is the vdev with the most recent txg.
188 * Check if the device is in a bootable state.
189 * dev may have a trailing blank since it points to a string
190 * in the devpath_list.
192 if (spa_check_devstate(devpath_list, dev, conf) != 0)