diff options
author | Sherry Moore <Sherry.Moore@Sun.COM> | 2009-03-24 14:38:50 -0700 |
---|---|---|
committer | Sherry Moore <Sherry.Moore@Sun.COM> | 2009-03-24 14:38:50 -0700 |
commit | 753a6d457b330b1b29b2d3eefcd0831116ce950d (patch) | |
tree | c18350d4e3f43265a05f156f9c9175474f3fc3e7 /usr/src/lib/libscf/common/highlevel.c | |
parent | 0c59ba075fc10821b752d32ee83a714261bca290 (diff) | |
download | illumos-joyent-753a6d457b330b1b29b2d3eefcd0831116ce950d.tar.gz |
PSARC/2008/760 Boot configuration Service
PSARC/2009/091 Reboot to firmware
PSARC/2009/092 libgrubmgmt - library for GRUB menu management
6768468 Introducing svc:/system/boot-config service
6775160 reboot -f ignores active BE and resets zfs pool bootfs property
6760845 Add checksum verification when loading the new kernel and boot archive for fast reboot
6815215 quiesce_active should be added to MUTEX_NOT_HELD()
Diffstat (limited to 'usr/src/lib/libscf/common/highlevel.c')
-rw-r--r-- | usr/src/lib/libscf/common/highlevel.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/usr/src/lib/libscf/common/highlevel.c b/usr/src/lib/libscf/common/highlevel.c new file mode 100644 index 0000000000..6444d260c2 --- /dev/null +++ b/usr/src/lib/libscf/common/highlevel.c @@ -0,0 +1,193 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * This file contains high level functions used by multiple utilities. + */ + +#include "libscf_impl.h" + +#include <assert.h> +#include <libuutil.h> +#include <string.h> +#include <stdlib.h> +#include <sys/systeminfo.h> +#include <sys/uadmin.h> +#include <sys/utsname.h> + +#ifdef __x86 +#include <smbios.h> + +/* + * Check whether the platform is on the fastreboot_blacklist. + * Return 1 if the platform has been blacklisted, 0 otherwise. + */ +static int +scf_is_fb_blacklisted(void) +{ + smbios_hdl_t *shp; + smbios_system_t sys; + smbios_info_t info; + + id_t id; + int err; + int i; + + scf_simple_prop_t *prop = NULL; + ssize_t numvals; + char *platform_name; + + int blacklisted = 0; + + /* + * If there's no SMBIOS, assume it's blacklisted. + */ + if ((shp = smbios_open(NULL, SMB_VERSION, 0, &err)) == NULL) + return (1); + + /* + * If we can't read system info, assume it's blacklisted. + */ + if ((id = smbios_info_system(shp, &sys)) == SMB_ERR || + smbios_info_common(shp, id, &info) == SMB_ERR) { + blacklisted = 1; + goto fb_out; + } + + /* + * If we can't read the "platforms" property from property group + * BOOT_CONFIG_PG_FBBLACKLIST, assume no platforms have + * been blacklisted. + */ + if ((prop = scf_simple_prop_get(NULL, FMRI_BOOT_CONFIG, + BOOT_CONFIG_PG_FBBLACKLIST, "platforms")) == NULL) + goto fb_out; + + numvals = scf_simple_prop_numvalues(prop); + + for (i = 0; i < numvals; i++) { + platform_name = scf_simple_prop_next_astring(prop); + if (platform_name == NULL) + break; + if (strcmp(platform_name, info.smbi_product) == 0) { + blacklisted = 1; + break; + } + } + +fb_out: + smbios_close(shp); + scf_simple_prop_free(prop); + + return (blacklisted); +} +#endif /* __x86 */ + +/* + * Get config properties from svc:/system/boot-config:default. + * It prints errors with uu_warn(). + */ +void +scf_get_boot_config(uint8_t *boot_config) +{ + assert(boot_config); + *boot_config = 0; + +#ifndef __x86 + return; +#else + { + /* + * Property vector for BOOT_CONFIG_PG_PARAMS property group. + */ + scf_propvec_t ua_boot_config[] = { + { "fastreboot_default", NULL, SCF_TYPE_BOOLEAN, NULL, + UA_FASTREBOOT_DEFAULT }, + { FASTREBOOT_ONPANIC, NULL, SCF_TYPE_BOOLEAN, NULL, + UA_FASTREBOOT_ONPANIC }, + { NULL } + }; + scf_propvec_t *prop; + + for (prop = ua_boot_config; prop->pv_prop != NULL; prop++) + prop->pv_ptr = boot_config; + prop = NULL; + if (scf_read_propvec(FMRI_BOOT_CONFIG, BOOT_CONFIG_PG_PARAMS, + B_TRUE, ua_boot_config, &prop) != SCF_FAILED) { + /* + * Unset both flags if the platform has been + * blacklisted. + */ + if (scf_is_fb_blacklisted()) + *boot_config &= ~(UA_FASTREBOOT_DEFAULT | + UA_FASTREBOOT_ONPANIC); + return; + } +#if defined(FASTREBOOT_DEBUG) + if (prop != NULL) { + (void) uu_warn("Service %s property '%s/%s' " + "not found.\n", FMRI_BOOT_CONFIG, + BOOT_CONFIG_PG_PARAMS, prop->pv_prop); + } else { + (void) uu_warn("Unable to read service %s " + "property '%s': %s\n", FMRI_BOOT_CONFIG, + BOOT_CONFIG_PG_PARAMS, scf_strerror(scf_error())); + } +#endif /* FASTREBOOT_DEBUG */ + } +#endif /* __x86 */ +} + +/* + * Check whether Fast Reboot is the default operating mode. + * Return 0 if + * 1. the platform is xVM + * or + * 2. svc:/system/boot-config:default service doesn't exist, + * or + * 3. property "fastreboot_default" doesn't exist, + * or + * 4. value of property "fastreboot_default" is set to 0. + * or + * 5. the platform has been blacklisted. + * Return non-zero otherwise. + */ +int +scf_is_fastboot_default(void) +{ + uint8_t boot_config = 0; + char procbuf[SYS_NMLN]; + + /* + * If we are on xVM, do not fast reboot by default. + */ + if (sysinfo(SI_PLATFORM, procbuf, sizeof (procbuf)) == -1 || + strcmp(procbuf, "i86xpv") == 0) + return (0); + + scf_get_boot_config(&boot_config); + return (boot_config & UA_FASTREBOOT_DEFAULT); +} |