1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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);
}
|