4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * pooladm - set, remove, or display active pool configurations.
34 #include <sys/types.h>
49 #define TEXT_DOMAIN "SYS_TEST"
62 (void) fprintf(stderr
,
63 gettext("Usage:\tpooladm [-n] [-s] [-c] [filename]\n"));
64 (void) fprintf(stderr
,
65 gettext("Usage:\tpooladm [-n] -x\n"));
66 (void) fprintf(stderr
,
67 gettext("Usage:\tpooladm -d | -e\n"));
72 config_print(pool_conf_t
*conf
)
78 if (pool_conf_open(conf
, pool_dynamic_location(), PO_RDONLY
)
80 die(gettext(ERR_OPEN_DYNAMIC
), get_errstr());
82 if ((pv
= pool_value_alloc()) == NULL
||
83 pool_get_property(conf
, pool_conf_to_elem(conf
), "system.name",
85 pool_value_get_string(pv
, &tgt
) != PO_SUCCESS
)
86 die(gettext(ERR_GET_ELEMENT_DETAILS
),
87 gettext(CONFIGURATION
), "unknown", get_errstr());
89 if ((buf
= pool_conf_info(conf
, PO_TRUE
)) == NULL
)
90 die(gettext(ERR_GET_ELEMENT_DETAILS
), gettext(CONFIGURATION
),
93 (void) printf("%s", buf
);
95 (void) pool_conf_close(conf
);
99 config_destroy(pool_conf_t
*conf
)
101 if (pool_conf_open(conf
, pool_dynamic_location(), PO_RDWR
)
103 die(gettext(ERR_OPEN_DYNAMIC
), get_errstr());
104 if (pool_conf_remove(conf
) != PO_SUCCESS
)
105 die(gettext(ERR_REMOVE_DYNAMIC
), get_errstr());
109 config_commit(pool_conf_t
*conf
, const char *static_conf_name
)
111 if (pool_conf_open(conf
, static_conf_name
, Nflag
|| !Sflag
?
112 PO_RDONLY
: PO_RDWR
) != PO_SUCCESS
)
113 die(gettext(ERR_OPEN_STATIC
), static_conf_name
, get_errstr());
115 if (pool_conf_validate(conf
, POV_RUNTIME
) != PO_SUCCESS
)
116 die(gettext(ERR_VALIDATE_RUNTIME
), static_conf_name
);
118 if (pool_conf_commit(conf
, PO_TRUE
) != PO_SUCCESS
)
119 die(gettext(ERR_COMMIT_DYNAMIC
), static_conf_name
,
122 * Dump the updated state to the specified location
125 if (pool_conf_commit(conf
, PO_FALSE
) != PO_SUCCESS
)
126 die(gettext(ERR_COMMIT_STATIC
),
127 static_conf_name
, get_errstr());
130 (void) pool_conf_close(conf
);
134 main(int argc
, char *argv
[])
137 pool_conf_t
*conf
= NULL
;
138 const char *static_conf_loc
;
140 (void) getpname(argv
[0]);
141 (void) setlocale(LC_ALL
, "");
142 (void) textdomain(TEXT_DOMAIN
);
145 while ((c
= getopt(argc
, argv
, "cdensx")) != EOF
) {
147 case 'c': /* Create (or modify) system configuration */
150 case 'd': /* Disable the pools facility */
153 case 'e': /* Enable the pools facility */
156 case 'n': /* Don't actually do anything */
159 case 's': /* Update the submitted configuration */
162 case 'x': /* Delete current system configuration */
173 * Not all flags can be used at the same time.
175 if ((Cflag
|| Sflag
|| Dflag
|| Eflag
) && Xflag
)
178 if ((Dflag
|| Eflag
) && (Cflag
|| Sflag
|| Xflag
))
187 if (! (Cflag
|| Sflag
)) {
192 static_conf_loc
= pool_static_location();
194 static_conf_loc
= argv
[0];
199 if (!Nflag
&& (Cflag
+ Dflag
+ Eflag
+ Xflag
!= 0) &&
200 !priv_ineffect(PRIV_SYS_RES_CONFIG
))
201 die(gettext(ERR_PERMISSIONS
));
204 if (pool_set_status(POOL_DISABLED
) != PO_SUCCESS
)
205 die(gettext(ERR_DISABLE
));
207 if (pool_set_status(POOL_ENABLED
) != PO_SUCCESS
) {
209 die(gettext(ERR_ENABLE
210 ": System has active processor sets\n"));
212 die(gettext(ERR_ENABLE
));
215 if ((conf
= pool_conf_alloc()) == NULL
)
216 die(gettext(ERR_NOMEM
));
218 if (Cflag
+ Sflag
+ Xflag
== 0) {
220 * No flags means print current system configuration
223 } else if (!Nflag
&& Xflag
) {
225 * Destroy active pools configuration and
226 * remove the state file.
228 config_destroy(conf
);
231 * Commit a new configuration.
234 config_commit(conf
, static_conf_loc
);
237 * Dump the dynamic state to the
240 if (!Nflag
&& Sflag
) {
241 if (pool_conf_open(conf
,
242 pool_dynamic_location(), PO_RDONLY
)
244 die(gettext(ERR_OPEN_DYNAMIC
),
246 if (pool_conf_export(conf
,
247 static_conf_loc
, POX_NATIVE
) !=
249 die(gettext(ERR_EXPORT_DYNAMIC
),
250 static_conf_loc
, get_errstr());
251 (void) pool_conf_close(conf
);
255 pool_conf_free(conf
);
257 return (E_PO_SUCCESS
);