1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * pooladm - set, remove, or display active pool configurations. 31*7c478bd9Sstevel@tonic-gate */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <sys/zone.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 36*7c478bd9Sstevel@tonic-gate #include <stdio.h> 37*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 38*7c478bd9Sstevel@tonic-gate #include <libintl.h> 39*7c478bd9Sstevel@tonic-gate #include <locale.h> 40*7c478bd9Sstevel@tonic-gate #include <string.h> 41*7c478bd9Sstevel@tonic-gate #include <priv.h> 42*7c478bd9Sstevel@tonic-gate #include <errno.h> 43*7c478bd9Sstevel@tonic-gate #include <zone.h> 44*7c478bd9Sstevel@tonic-gate #include <pool.h> 45*7c478bd9Sstevel@tonic-gate #include <unistd.h> 46*7c478bd9Sstevel@tonic-gate #include "utils.h" 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN 49*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 50*7c478bd9Sstevel@tonic-gate #endif 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate static int Cflag; 53*7c478bd9Sstevel@tonic-gate static int Sflag; 54*7c478bd9Sstevel@tonic-gate static int Dflag; 55*7c478bd9Sstevel@tonic-gate static int Eflag; 56*7c478bd9Sstevel@tonic-gate static int Nflag; 57*7c478bd9Sstevel@tonic-gate static int Xflag; 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate static void 60*7c478bd9Sstevel@tonic-gate usage(void) 61*7c478bd9Sstevel@tonic-gate { 62*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 63*7c478bd9Sstevel@tonic-gate gettext("Usage:\tpooladm [-n] [-s] [-c] [filename]\n")); 64*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 65*7c478bd9Sstevel@tonic-gate gettext("Usage:\tpooladm [-n] -x\n")); 66*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 67*7c478bd9Sstevel@tonic-gate gettext("Usage:\tpooladm -d | -e\n")); 68*7c478bd9Sstevel@tonic-gate exit(E_USAGE); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate static void 72*7c478bd9Sstevel@tonic-gate config_print(pool_conf_t *conf) 73*7c478bd9Sstevel@tonic-gate { 74*7c478bd9Sstevel@tonic-gate char *buf; 75*7c478bd9Sstevel@tonic-gate pool_value_t *pv; 76*7c478bd9Sstevel@tonic-gate const char *tgt; 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) 79*7c478bd9Sstevel@tonic-gate != PO_SUCCESS) 80*7c478bd9Sstevel@tonic-gate die(gettext(ERR_OPEN_DYNAMIC), get_errstr()); 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate if ((pv = pool_value_alloc()) == NULL || 83*7c478bd9Sstevel@tonic-gate pool_get_property(conf, pool_conf_to_elem(conf), "system.name", 84*7c478bd9Sstevel@tonic-gate pv) == POC_INVAL || 85*7c478bd9Sstevel@tonic-gate pool_value_get_string(pv, &tgt) != PO_SUCCESS) 86*7c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 87*7c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate if ((buf = pool_conf_info(conf, PO_TRUE)) == NULL) 90*7c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), gettext(CONFIGURATION), 91*7c478bd9Sstevel@tonic-gate tgt, get_errstr()); 92*7c478bd9Sstevel@tonic-gate pool_value_free(pv); 93*7c478bd9Sstevel@tonic-gate (void) printf("%s", buf); 94*7c478bd9Sstevel@tonic-gate free(buf); 95*7c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate static void 99*7c478bd9Sstevel@tonic-gate config_destroy(pool_conf_t *conf) 100*7c478bd9Sstevel@tonic-gate { 101*7c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDWR) 102*7c478bd9Sstevel@tonic-gate != PO_SUCCESS) 103*7c478bd9Sstevel@tonic-gate die(gettext(ERR_OPEN_DYNAMIC), get_errstr()); 104*7c478bd9Sstevel@tonic-gate if (pool_conf_remove(conf) != PO_SUCCESS) 105*7c478bd9Sstevel@tonic-gate die(gettext(ERR_REMOVE_DYNAMIC), get_errstr()); 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate static void 109*7c478bd9Sstevel@tonic-gate config_commit(pool_conf_t *conf, const char *static_conf_name) 110*7c478bd9Sstevel@tonic-gate { 111*7c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, static_conf_name, Nflag || !Sflag ? 112*7c478bd9Sstevel@tonic-gate PO_RDONLY : PO_RDWR) != PO_SUCCESS) 113*7c478bd9Sstevel@tonic-gate die(gettext(ERR_OPEN_STATIC), static_conf_name, get_errstr()); 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate if (pool_conf_validate(conf, POV_RUNTIME) != PO_SUCCESS) 116*7c478bd9Sstevel@tonic-gate die(gettext(ERR_VALIDATE_RUNTIME), static_conf_name); 117*7c478bd9Sstevel@tonic-gate if (!Nflag) { 118*7c478bd9Sstevel@tonic-gate if (pool_conf_commit(conf, PO_TRUE) != PO_SUCCESS) 119*7c478bd9Sstevel@tonic-gate die(gettext(ERR_COMMIT_DYNAMIC), static_conf_name, 120*7c478bd9Sstevel@tonic-gate get_errstr()); 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * Dump the updated state to the specified location 123*7c478bd9Sstevel@tonic-gate */ 124*7c478bd9Sstevel@tonic-gate if (Sflag) { 125*7c478bd9Sstevel@tonic-gate if (pool_conf_commit(conf, PO_FALSE) != PO_SUCCESS) 126*7c478bd9Sstevel@tonic-gate die(gettext(ERR_COMMIT_STATIC), 127*7c478bd9Sstevel@tonic-gate static_conf_name, get_errstr()); 128*7c478bd9Sstevel@tonic-gate } 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate int 134*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 135*7c478bd9Sstevel@tonic-gate { 136*7c478bd9Sstevel@tonic-gate char c; 137*7c478bd9Sstevel@tonic-gate pool_conf_t *conf = NULL; 138*7c478bd9Sstevel@tonic-gate const char *static_conf_loc; 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate (void) getpname(argv[0]); 141*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 142*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "cdensx")) != EOF) { 146*7c478bd9Sstevel@tonic-gate switch (c) { 147*7c478bd9Sstevel@tonic-gate case 'c': /* Create (or modify) system configuration */ 148*7c478bd9Sstevel@tonic-gate Cflag++; 149*7c478bd9Sstevel@tonic-gate break; 150*7c478bd9Sstevel@tonic-gate case 'd': /* Disable the pools facility */ 151*7c478bd9Sstevel@tonic-gate Dflag++; 152*7c478bd9Sstevel@tonic-gate break; 153*7c478bd9Sstevel@tonic-gate case 'e': /* Enable the pools facility */ 154*7c478bd9Sstevel@tonic-gate Eflag++; 155*7c478bd9Sstevel@tonic-gate break; 156*7c478bd9Sstevel@tonic-gate case 'n': /* Don't actually do anything */ 157*7c478bd9Sstevel@tonic-gate Nflag++; 158*7c478bd9Sstevel@tonic-gate break; 159*7c478bd9Sstevel@tonic-gate case 's': /* Update the submitted configuration */ 160*7c478bd9Sstevel@tonic-gate Sflag++; 161*7c478bd9Sstevel@tonic-gate break; 162*7c478bd9Sstevel@tonic-gate case 'x': /* Delete current system configuration */ 163*7c478bd9Sstevel@tonic-gate Xflag++; 164*7c478bd9Sstevel@tonic-gate break; 165*7c478bd9Sstevel@tonic-gate case '?': 166*7c478bd9Sstevel@tonic-gate default: 167*7c478bd9Sstevel@tonic-gate usage(); 168*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 169*7c478bd9Sstevel@tonic-gate } 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate /* 173*7c478bd9Sstevel@tonic-gate * Not all flags can be used at the same time. 174*7c478bd9Sstevel@tonic-gate */ 175*7c478bd9Sstevel@tonic-gate if ((Cflag || Sflag || Dflag || Eflag) && Xflag) 176*7c478bd9Sstevel@tonic-gate usage(); 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate if ((Dflag || Eflag) && (Cflag || Sflag || Xflag)) 179*7c478bd9Sstevel@tonic-gate usage(); 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate if (Dflag && Eflag) 182*7c478bd9Sstevel@tonic-gate usage(); 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate argc -= optind; 185*7c478bd9Sstevel@tonic-gate argv += optind; 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate if (! (Cflag || Sflag)) { 188*7c478bd9Sstevel@tonic-gate if (argc != 0) 189*7c478bd9Sstevel@tonic-gate usage(); 190*7c478bd9Sstevel@tonic-gate } else { 191*7c478bd9Sstevel@tonic-gate if (argc == 0) 192*7c478bd9Sstevel@tonic-gate static_conf_loc = pool_static_location(); 193*7c478bd9Sstevel@tonic-gate else if (argc == 1) 194*7c478bd9Sstevel@tonic-gate static_conf_loc = argv[0]; 195*7c478bd9Sstevel@tonic-gate else 196*7c478bd9Sstevel@tonic-gate usage(); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate if (!Nflag && (Cflag + Dflag + Eflag + Xflag != 0) && 200*7c478bd9Sstevel@tonic-gate !priv_ineffect(PRIV_SYS_RES_CONFIG)) 201*7c478bd9Sstevel@tonic-gate die(gettext(ERR_PERMISSIONS)); 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate if (Dflag) { 204*7c478bd9Sstevel@tonic-gate if (pool_set_status(POOL_DISABLED) != PO_SUCCESS) 205*7c478bd9Sstevel@tonic-gate die(gettext(ERR_DISABLE)); 206*7c478bd9Sstevel@tonic-gate } else if (Eflag) { 207*7c478bd9Sstevel@tonic-gate if (pool_set_status(POOL_ENABLED) != PO_SUCCESS) { 208*7c478bd9Sstevel@tonic-gate if (errno == EEXIST) 209*7c478bd9Sstevel@tonic-gate die(gettext(ERR_ENABLE 210*7c478bd9Sstevel@tonic-gate ": System has active processor sets\n")); 211*7c478bd9Sstevel@tonic-gate else 212*7c478bd9Sstevel@tonic-gate die(gettext(ERR_ENABLE)); 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate } else { 215*7c478bd9Sstevel@tonic-gate if ((conf = pool_conf_alloc()) == NULL) 216*7c478bd9Sstevel@tonic-gate die(gettext(ERR_NOMEM)); 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate if (Cflag + Sflag + Xflag == 0) { 219*7c478bd9Sstevel@tonic-gate /* 220*7c478bd9Sstevel@tonic-gate * No flags means print current system configuration 221*7c478bd9Sstevel@tonic-gate */ 222*7c478bd9Sstevel@tonic-gate config_print(conf); 223*7c478bd9Sstevel@tonic-gate } else if (!Nflag && Xflag) { 224*7c478bd9Sstevel@tonic-gate /* 225*7c478bd9Sstevel@tonic-gate * Destroy active pools configuration and 226*7c478bd9Sstevel@tonic-gate * remove the state file. 227*7c478bd9Sstevel@tonic-gate */ 228*7c478bd9Sstevel@tonic-gate config_destroy(conf); 229*7c478bd9Sstevel@tonic-gate } else { 230*7c478bd9Sstevel@tonic-gate /* 231*7c478bd9Sstevel@tonic-gate * Commit a new configuration. 232*7c478bd9Sstevel@tonic-gate */ 233*7c478bd9Sstevel@tonic-gate if (Cflag) 234*7c478bd9Sstevel@tonic-gate config_commit(conf, static_conf_loc); 235*7c478bd9Sstevel@tonic-gate else { 236*7c478bd9Sstevel@tonic-gate /* 237*7c478bd9Sstevel@tonic-gate * Dump the dynamic state to the 238*7c478bd9Sstevel@tonic-gate * specified location 239*7c478bd9Sstevel@tonic-gate */ 240*7c478bd9Sstevel@tonic-gate if (!Nflag && Sflag) { 241*7c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, 242*7c478bd9Sstevel@tonic-gate pool_dynamic_location(), PO_RDONLY) 243*7c478bd9Sstevel@tonic-gate != PO_SUCCESS) 244*7c478bd9Sstevel@tonic-gate die(gettext(ERR_OPEN_DYNAMIC), 245*7c478bd9Sstevel@tonic-gate get_errstr()); 246*7c478bd9Sstevel@tonic-gate if (pool_conf_export(conf, 247*7c478bd9Sstevel@tonic-gate static_conf_loc, POX_NATIVE) != 248*7c478bd9Sstevel@tonic-gate PO_SUCCESS) 249*7c478bd9Sstevel@tonic-gate die(gettext(ERR_EXPORT_DYNAMIC), 250*7c478bd9Sstevel@tonic-gate static_conf_loc, get_errstr()); 251*7c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate } 254*7c478bd9Sstevel@tonic-gate } 255*7c478bd9Sstevel@tonic-gate pool_conf_free(conf); 256*7c478bd9Sstevel@tonic-gate } 257*7c478bd9Sstevel@tonic-gate return (E_PO_SUCCESS); 258*7c478bd9Sstevel@tonic-gate } 259