17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM * CDDL HEADER START
37836SJohn.Forte@Sun.COM *
47836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM *
87836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM * and limitations under the License.
127836SJohn.Forte@Sun.COM *
137836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM *
197836SJohn.Forte@Sun.COM * CDDL HEADER END
207836SJohn.Forte@Sun.COM */
21*11576SSurya.Prakki@Sun.COM
227836SJohn.Forte@Sun.COM /*
23*11576SSurya.Prakki@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
247836SJohn.Forte@Sun.COM * Use is subject to license terms.
257836SJohn.Forte@Sun.COM */
267836SJohn.Forte@Sun.COM
277836SJohn.Forte@Sun.COM /*
287836SJohn.Forte@Sun.COM * Utility for cache configuration
297836SJohn.Forte@Sun.COM */
307836SJohn.Forte@Sun.COM #include <unistd.h>
317836SJohn.Forte@Sun.COM #include <stdio.h>
327836SJohn.Forte@Sun.COM #include <stdlib.h>
337836SJohn.Forte@Sun.COM #include <strings.h>
347836SJohn.Forte@Sun.COM #include <locale.h>
357836SJohn.Forte@Sun.COM #include <langinfo.h>
367836SJohn.Forte@Sun.COM #include <libintl.h>
377836SJohn.Forte@Sun.COM #include <time.h>
387836SJohn.Forte@Sun.COM #include <sys/nsctl/sd_bcache.h>
397836SJohn.Forte@Sun.COM #include <sys/wait.h>
407836SJohn.Forte@Sun.COM #include <errno.h>
417836SJohn.Forte@Sun.COM #include <signal.h>
427836SJohn.Forte@Sun.COM #include <sys/types.h>
437836SJohn.Forte@Sun.COM #include <fcntl.h>
447836SJohn.Forte@Sun.COM #include <stropts.h>
457836SJohn.Forte@Sun.COM #include <ctype.h>
467836SJohn.Forte@Sun.COM #include <libgen.h>
477836SJohn.Forte@Sun.COM
487836SJohn.Forte@Sun.COM #include <sys/nsctl/sdbc_ioctl.h>
497836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s.h>
507836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s_u.h>
517836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_errors.h>
527836SJohn.Forte@Sun.COM #include <nsctl.h>
537836SJohn.Forte@Sun.COM
547836SJohn.Forte@Sun.COM #include <sys/nsctl/cfg.h>
557836SJohn.Forte@Sun.COM #define STATS_PATH "/usr/bin/sd_stats"
567836SJohn.Forte@Sun.COM
577836SJohn.Forte@Sun.COM #define _SD_FNAME /* bring in function names from sd_trace.h */
587836SJohn.Forte@Sun.COM #include <sys/nsctl/sd_trace.h>
597836SJohn.Forte@Sun.COM #include <sys/syslog.h>
607836SJohn.Forte@Sun.COM
617836SJohn.Forte@Sun.COM /*
627836SJohn.Forte@Sun.COM * Since we no longer support nvram cards, the hints wrthru and nowrthru no
637836SJohn.Forte@Sun.COM * longer serve any purpose, and the system will always be in wrthru mode.
647836SJohn.Forte@Sun.COM * WRTHRU_HINTS, if defined still allows the setting and reporting of write
657836SJohn.Forte@Sun.COM * hints. This is defined by default on DEBUG builds.
667836SJohn.Forte@Sun.COM */
677836SJohn.Forte@Sun.COM #ifdef DEBUG
687836SJohn.Forte@Sun.COM #define WRTHRU_HINTS
697836SJohn.Forte@Sun.COM #endif
707836SJohn.Forte@Sun.COM
717836SJohn.Forte@Sun.COM static int sdbc_max_devices = 0;
727836SJohn.Forte@Sun.COM
737836SJohn.Forte@Sun.COM static char alert_file[200] = "/dev/console";
747836SJohn.Forte@Sun.COM
757836SJohn.Forte@Sun.COM /* Variables used to set up paramater block passed to kernel */
767836SJohn.Forte@Sun.COM static _sd_cache_param_t user_level_conf;
777836SJohn.Forte@Sun.COM static int myid;
787836SJohn.Forte@Sun.COM
797836SJohn.Forte@Sun.COM static int nodes_configured = 0;
807836SJohn.Forte@Sun.COM static int minidsp = 0; /* Is it a sp10 */
817836SJohn.Forte@Sun.COM static int forced_wrthru = -1; /* 0 clear, 1 set,-1 as is */
827836SJohn.Forte@Sun.COM static int no_forced_wrthru = -1;
837836SJohn.Forte@Sun.COM static short node_defined[MAX_SD_NODES];
847836SJohn.Forte@Sun.COM static short nodes_conf[MAX_SD_NODES];
857836SJohn.Forte@Sun.COM
867836SJohn.Forte@Sun.COM #define USAGELEN 1024
877836SJohn.Forte@Sun.COM char stats_usage[USAGELEN+128];
887836SJohn.Forte@Sun.COM char scmadmUsage[USAGELEN];
897836SJohn.Forte@Sun.COM
907836SJohn.Forte@Sun.COM static caddr_t progname;
917836SJohn.Forte@Sun.COM
927836SJohn.Forte@Sun.COM
937836SJohn.Forte@Sun.COM /*
947836SJohn.Forte@Sun.COM * Functions exported for fwcadm.
957836SJohn.Forte@Sun.COM */
967836SJohn.Forte@Sun.COM void enable_sdbc(void);
977836SJohn.Forte@Sun.COM void disable_sdbc(void);
987836SJohn.Forte@Sun.COM void sdbc_set_maxdev();
997836SJohn.Forte@Sun.COM
1007836SJohn.Forte@Sun.COM static void buildusage(char *);
1017836SJohn.Forte@Sun.COM
1027836SJohn.Forte@Sun.COM void print_all_options(void);
1037836SJohn.Forte@Sun.COM void get_cd_all(void);
1047836SJohn.Forte@Sun.COM int toggle_flush(void);
1057836SJohn.Forte@Sun.COM static void sd_gather_alert_dumps();
1067836SJohn.Forte@Sun.COM static int get_cd(char *);
1077836SJohn.Forte@Sun.COM static int get_hint(char *, int *, int *);
1087836SJohn.Forte@Sun.COM static void check_and_set_mirrors(int, int);
1097836SJohn.Forte@Sun.COM static void print_hint(const uint_t, const int);
1107836SJohn.Forte@Sun.COM static char *get_device_name(char *arg);
1117836SJohn.Forte@Sun.COM static void get_version();
1127836SJohn.Forte@Sun.COM
1137836SJohn.Forte@Sun.COM extern struct tm *localtime_r(const time_t *, struct tm *);
1147836SJohn.Forte@Sun.COM
1157836SJohn.Forte@Sun.COM #define PRINT_CACHE_SZ_ERR(sz) {\
1167836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("\n%s: desired cache size (%d) "\
1177836SJohn.Forte@Sun.COM "set to system max (%d)\n"), \
1187836SJohn.Forte@Sun.COM progname, (sz), MAX_CACHE_SIZE); \
1197836SJohn.Forte@Sun.COM spcs_log("sdbc", NULL, \
1207836SJohn.Forte@Sun.COM gettext("desired cache size (%d) "\
1217836SJohn.Forte@Sun.COM "set to system max (%d)\n"), \
1227836SJohn.Forte@Sun.COM (sz), MAX_CACHE_SIZE); \
1237836SJohn.Forte@Sun.COM }
1247836SJohn.Forte@Sun.COM
1257836SJohn.Forte@Sun.COM void
sdbc_report_error(spcs_s_info_t * ustatus)1267836SJohn.Forte@Sun.COM sdbc_report_error(spcs_s_info_t *ustatus)
1277836SJohn.Forte@Sun.COM {
1287836SJohn.Forte@Sun.COM if (*ustatus != NULL) {
1297836SJohn.Forte@Sun.COM spcs_s_report(*ustatus, stderr);
1307836SJohn.Forte@Sun.COM spcs_s_ufree(ustatus);
1317836SJohn.Forte@Sun.COM } else
1327836SJohn.Forte@Sun.COM (void) fprintf(stderr, "%s\n", strerror(errno));
1337836SJohn.Forte@Sun.COM }
1347836SJohn.Forte@Sun.COM
1357836SJohn.Forte@Sun.COM
1367836SJohn.Forte@Sun.COM /*
1377836SJohn.Forte@Sun.COM * Return the per-cd hints for a cd.
1387836SJohn.Forte@Sun.COM *
1397836SJohn.Forte@Sun.COM * Since the global (no)wrthru and NSC_NOCACHE hints take precedence
1407836SJohn.Forte@Sun.COM * over the per-cd hints, get them as well and OR the whole lot
1417836SJohn.Forte@Sun.COM * together.
1427836SJohn.Forte@Sun.COM */
1437836SJohn.Forte@Sun.COM static int
get_cd_hint(const int cd)1447836SJohn.Forte@Sun.COM get_cd_hint(const int cd)
1457836SJohn.Forte@Sun.COM {
1467836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
1477836SJohn.Forte@Sun.COM int nodehint, cdhint;
1487836SJohn.Forte@Sun.COM
1497836SJohn.Forte@Sun.COM nodehint = SDBC_IOCTL(SDBC_GET_NODE_HINT, 0, 0, 0, 0, 0, &ustats);
1507836SJohn.Forte@Sun.COM if (nodehint == SPCS_S_ERROR) {
1517836SJohn.Forte@Sun.COM (void) fprintf(stderr,
1527836SJohn.Forte@Sun.COM gettext("%s: get system options failed\n"), progname);
1537836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
1547836SJohn.Forte@Sun.COM exit(1);
1557836SJohn.Forte@Sun.COM }
1567836SJohn.Forte@Sun.COM
1577836SJohn.Forte@Sun.COM cdhint = SDBC_IOCTL(SDBC_GET_CD_HINT, cd, 0, 0, 0, 0, &ustats);
1587836SJohn.Forte@Sun.COM if (cdhint == SPCS_S_ERROR) {
1597836SJohn.Forte@Sun.COM (void) fprintf(stderr,
1607836SJohn.Forte@Sun.COM gettext("%s: get cd(%d) hint failed\n"), progname, cd);
1617836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
1627836SJohn.Forte@Sun.COM exit(1);
1637836SJohn.Forte@Sun.COM }
1647836SJohn.Forte@Sun.COM
1657836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
1667836SJohn.Forte@Sun.COM nodehint &= (NSC_FORCED_WRTHRU | NSC_NO_FORCED_WRTHRU | NSC_NOCACHE);
1677836SJohn.Forte@Sun.COM #else
1687836SJohn.Forte@Sun.COM nodehint &= (NSC_NOCACHE);
1697836SJohn.Forte@Sun.COM #endif
1707836SJohn.Forte@Sun.COM if (nodehint) {
1717836SJohn.Forte@Sun.COM /* set the top bit to mark it as a system override */
1727836SJohn.Forte@Sun.COM nodehint |= 0x80000000;
1737836SJohn.Forte@Sun.COM }
1747836SJohn.Forte@Sun.COM
1757836SJohn.Forte@Sun.COM return (cdhint | nodehint);
1767836SJohn.Forte@Sun.COM }
1777836SJohn.Forte@Sun.COM
1787836SJohn.Forte@Sun.COM
1797836SJohn.Forte@Sun.COM
1807836SJohn.Forte@Sun.COM /*
1817836SJohn.Forte@Sun.COM * Check for a config.
1827836SJohn.Forte@Sun.COM *
1837836SJohn.Forte@Sun.COM * If no suitable config can be found, install the default config.
1847836SJohn.Forte@Sun.COM *
1857836SJohn.Forte@Sun.COM * Calling state:
1867836SJohn.Forte@Sun.COM * libcfg locked (mode describes type of lock)
1877836SJohn.Forte@Sun.COM */
1887836SJohn.Forte@Sun.COM static void
convert_config(CFGFILE * cfg,CFGLOCK mode)1897836SJohn.Forte@Sun.COM convert_config(CFGFILE *cfg, CFGLOCK mode)
1907836SJohn.Forte@Sun.COM {
1917836SJohn.Forte@Sun.COM char buf[CFG_MAX_BUF];
1927836SJohn.Forte@Sun.COM char *default_cfg = "128 64";
1937836SJohn.Forte@Sun.COM
1947836SJohn.Forte@Sun.COM retry:
1957836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, "scm.set1", buf, sizeof (buf)) >= 0) {
1967836SJohn.Forte@Sun.COM /* config exists, return */
1977836SJohn.Forte@Sun.COM return;
1987836SJohn.Forte@Sun.COM }
1997836SJohn.Forte@Sun.COM
2007836SJohn.Forte@Sun.COM cfg_rewind(cfg, CFG_SEC_CONF);
2017836SJohn.Forte@Sun.COM
2027836SJohn.Forte@Sun.COM #ifdef DEBUG
2037836SJohn.Forte@Sun.COM (void) printf(gettext("%s: installing default config entry '%s'\n"),
204*11576SSurya.Prakki@Sun.COM progname, default_cfg);
2057836SJohn.Forte@Sun.COM #endif
2067836SJohn.Forte@Sun.COM if (mode != CFG_WRLOCK) {
2077836SJohn.Forte@Sun.COM cfg_unlock(cfg);
2087836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_WRLOCK)) {
2097836SJohn.Forte@Sun.COM (void) fprintf(stderr,
2107836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
2117836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
2127836SJohn.Forte@Sun.COM exit(1);
2137836SJohn.Forte@Sun.COM }
2147836SJohn.Forte@Sun.COM mode = CFG_WRLOCK;
2157836SJohn.Forte@Sun.COM #ifdef DEBUG
2167836SJohn.Forte@Sun.COM (void) printf(gettext("%s: upgraded lock, retrying\n"),
2177836SJohn.Forte@Sun.COM progname);
2187836SJohn.Forte@Sun.COM #endif
2197836SJohn.Forte@Sun.COM goto retry;
2207836SJohn.Forte@Sun.COM }
2217836SJohn.Forte@Sun.COM
2227836SJohn.Forte@Sun.COM if (cfg_put_cstring(cfg, "scm", default_cfg, strlen(default_cfg)) < 0) {
2237836SJohn.Forte@Sun.COM (void) fprintf(stderr,
2247836SJohn.Forte@Sun.COM gettext("%s: unable to write configuration: %s\n"),
2257836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
2267836SJohn.Forte@Sun.COM exit(1);
2277836SJohn.Forte@Sun.COM }
2287836SJohn.Forte@Sun.COM
2297836SJohn.Forte@Sun.COM if (!cfg_commit(cfg)) {
2307836SJohn.Forte@Sun.COM (void) fprintf(stderr,
2317836SJohn.Forte@Sun.COM gettext("%s: unable to write to configuration: %s\n"),
2327836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
2337836SJohn.Forte@Sun.COM }
2347836SJohn.Forte@Sun.COM
2357836SJohn.Forte@Sun.COM if (mode != CFG_WRLOCK) {
2367836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, mode)) {
2377836SJohn.Forte@Sun.COM (void) fprintf(stderr,
2387836SJohn.Forte@Sun.COM gettext("%s: unable to relock configuration: %s\n"),
2397836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
2407836SJohn.Forte@Sun.COM exit(1);
2417836SJohn.Forte@Sun.COM }
2427836SJohn.Forte@Sun.COM }
2437836SJohn.Forte@Sun.COM
2447836SJohn.Forte@Sun.COM cfg_rewind(cfg, CFG_SEC_CONF);
2457836SJohn.Forte@Sun.COM }
2467836SJohn.Forte@Sun.COM
2477836SJohn.Forte@Sun.COM
2487836SJohn.Forte@Sun.COM static int
iscluster(void)2497836SJohn.Forte@Sun.COM iscluster(void)
2507836SJohn.Forte@Sun.COM {
2517836SJohn.Forte@Sun.COM int rc;
2527836SJohn.Forte@Sun.COM
2537836SJohn.Forte@Sun.COM rc = cfg_iscluster();
2547836SJohn.Forte@Sun.COM if (rc == 0) {
2557836SJohn.Forte@Sun.COM return (FALSE);
2567836SJohn.Forte@Sun.COM } else if (rc > 0) {
2577836SJohn.Forte@Sun.COM return (TRUE);
2587836SJohn.Forte@Sun.COM } else {
259*11576SSurya.Prakki@Sun.COM (void) fprintf(stderr,
260*11576SSurya.Prakki@Sun.COM gettext("%s: unable to ascertain environment\n"), progname);
2617836SJohn.Forte@Sun.COM exit(1);
2627836SJohn.Forte@Sun.COM }
2637836SJohn.Forte@Sun.COM
2647836SJohn.Forte@Sun.COM /* NOTREACHED */
2657836SJohn.Forte@Sun.COM }
2667836SJohn.Forte@Sun.COM
2677836SJohn.Forte@Sun.COM
2687836SJohn.Forte@Sun.COM static void
restore_hints()2697836SJohn.Forte@Sun.COM restore_hints()
2707836SJohn.Forte@Sun.COM {
2717836SJohn.Forte@Sun.COM CFGFILE *cfg;
2727836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
2737836SJohn.Forte@Sun.COM int setnumber;
2747836SJohn.Forte@Sun.COM spcs_s_info_t ustatus;
2757836SJohn.Forte@Sun.COM int cd;
2767836SJohn.Forte@Sun.COM
2777836SJohn.Forte@Sun.COM if ((cfg = cfg_open(NULL)) == NULL) {
2787836SJohn.Forte@Sun.COM (void) fprintf(stderr,
2797836SJohn.Forte@Sun.COM gettext("%s: unable to access configuration: %s\n"),
2807836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
2817836SJohn.Forte@Sun.COM exit(1);
2827836SJohn.Forte@Sun.COM }
2837836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_RDLOCK)) {
2847836SJohn.Forte@Sun.COM (void) fprintf(stderr,
2857836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
2867836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
2877836SJohn.Forte@Sun.COM exit(1);
2887836SJohn.Forte@Sun.COM }
2897836SJohn.Forte@Sun.COM
2907836SJohn.Forte@Sun.COM for (setnumber = 1; /*CONSTCOND*/ TRUE; setnumber++) {
2917836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "cache_hint.set%d.device",
2927836SJohn.Forte@Sun.COM setnumber);
2937836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
2947836SJohn.Forte@Sun.COM /* error or not found */
2957836SJohn.Forte@Sun.COM break;
2967836SJohn.Forte@Sun.COM }
2977836SJohn.Forte@Sun.COM
2987836SJohn.Forte@Sun.COM if (strcmp(buf, "system") == 0) {
2997836SJohn.Forte@Sun.COM cd = -1;
3007836SJohn.Forte@Sun.COM } else {
3017836SJohn.Forte@Sun.COM cd = get_cd(buf);
3027836SJohn.Forte@Sun.COM if (cd < 0)
3037836SJohn.Forte@Sun.COM continue;
3047836SJohn.Forte@Sun.COM }
3057836SJohn.Forte@Sun.COM
3067836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "cache_hint.set%d.wrthru",
3077836SJohn.Forte@Sun.COM setnumber);
3087836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0)
3097836SJohn.Forte@Sun.COM continue;
3107836SJohn.Forte@Sun.COM
3117836SJohn.Forte@Sun.COM if (atoi(buf) == 1) {
3127836SJohn.Forte@Sun.COM if (cd == -1) {
3137836SJohn.Forte@Sun.COM /* Node hint */
3147836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_WRTHRU,
3157836SJohn.Forte@Sun.COM 1, 0, 0, 0, &ustatus) == SPCS_S_ERROR) {
3167836SJohn.Forte@Sun.COM (void) fprintf(stderr,
3177836SJohn.Forte@Sun.COM gettext("%s: set system "
3187836SJohn.Forte@Sun.COM "option failed\n"),
3197836SJohn.Forte@Sun.COM progname);
3207836SJohn.Forte@Sun.COM sdbc_report_error(&ustatus);
3217836SJohn.Forte@Sun.COM exit(1);
3227836SJohn.Forte@Sun.COM }
3237836SJohn.Forte@Sun.COM } else if (SDBC_IOCTL(SDBC_SET_CD_HINT, cd,
3247836SJohn.Forte@Sun.COM NSC_WRTHRU, 1, 0, 0, &ustatus) == SPCS_S_ERROR) {
3257836SJohn.Forte@Sun.COM (void) fprintf(stderr,
3267836SJohn.Forte@Sun.COM gettext("%s: set option failed\n"),
3277836SJohn.Forte@Sun.COM progname);
3287836SJohn.Forte@Sun.COM sdbc_report_error(&ustatus);
3297836SJohn.Forte@Sun.COM exit(1);
3307836SJohn.Forte@Sun.COM }
3317836SJohn.Forte@Sun.COM }
3327836SJohn.Forte@Sun.COM
3337836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "cache_hint.set%d.nordcache",
3347836SJohn.Forte@Sun.COM setnumber);
3357836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0)
3367836SJohn.Forte@Sun.COM continue;
3377836SJohn.Forte@Sun.COM
3387836SJohn.Forte@Sun.COM if (atoi(buf) == 1) {
3397836SJohn.Forte@Sun.COM if (cd == -1) {
3407836SJohn.Forte@Sun.COM /* Node hint */
3417836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_NOCACHE,
3427836SJohn.Forte@Sun.COM 1, 0, 0, 0, &ustatus) == SPCS_S_ERROR) {
3437836SJohn.Forte@Sun.COM (void) fprintf(stderr,
3447836SJohn.Forte@Sun.COM gettext("%s: set system "
3457836SJohn.Forte@Sun.COM "option failed\n"),
3467836SJohn.Forte@Sun.COM progname);
3477836SJohn.Forte@Sun.COM sdbc_report_error(&ustatus);
3487836SJohn.Forte@Sun.COM exit(1);
3497836SJohn.Forte@Sun.COM }
3507836SJohn.Forte@Sun.COM } else if (SDBC_IOCTL(SDBC_SET_CD_HINT, cd, NSC_NOCACHE,
3517836SJohn.Forte@Sun.COM 1, 0, 0, &ustatus) == SPCS_S_ERROR) {
3527836SJohn.Forte@Sun.COM (void) fprintf(stderr,
3537836SJohn.Forte@Sun.COM gettext("%s: set option failed\n"),
3547836SJohn.Forte@Sun.COM progname);
3557836SJohn.Forte@Sun.COM sdbc_report_error(&ustatus);
3567836SJohn.Forte@Sun.COM exit(1);
3577836SJohn.Forte@Sun.COM }
3587836SJohn.Forte@Sun.COM }
3597836SJohn.Forte@Sun.COM }
3607836SJohn.Forte@Sun.COM
3617836SJohn.Forte@Sun.COM cfg_close(cfg);
3627836SJohn.Forte@Sun.COM }
3637836SJohn.Forte@Sun.COM
3647836SJohn.Forte@Sun.COM void
sdbc_set_maxdev()3657836SJohn.Forte@Sun.COM sdbc_set_maxdev()
3667836SJohn.Forte@Sun.COM {
3677836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
3687836SJohn.Forte@Sun.COM
3697836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_MAXFILES, &sdbc_max_devices,
3707836SJohn.Forte@Sun.COM 0, 0, 0, 0, &ustats) == SPCS_S_ERROR) {
3717836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: get maxfiles failed\n"),
3727836SJohn.Forte@Sun.COM progname);
3737836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
3747836SJohn.Forte@Sun.COM exit(1);
3757836SJohn.Forte@Sun.COM }
3767836SJohn.Forte@Sun.COM }
3777836SJohn.Forte@Sun.COM
3787836SJohn.Forte@Sun.COM static void
bitmapfs_print(void)3797836SJohn.Forte@Sun.COM bitmapfs_print(void)
3807836SJohn.Forte@Sun.COM {
3817836SJohn.Forte@Sun.COM CFGFILE *cfg;
3827836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
3837836SJohn.Forte@Sun.COM int setnumber;
3847836SJohn.Forte@Sun.COM
3857836SJohn.Forte@Sun.COM cfg = cfg_open(NULL);
3867836SJohn.Forte@Sun.COM if (cfg == NULL) {
3877836SJohn.Forte@Sun.COM (void) fprintf(stderr,
3887836SJohn.Forte@Sun.COM gettext("%s: unable to access configuration: %s\n"),
3897836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
3907836SJohn.Forte@Sun.COM exit(1);
3917836SJohn.Forte@Sun.COM }
3927836SJohn.Forte@Sun.COM
3937836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_RDLOCK)) {
3947836SJohn.Forte@Sun.COM (void) fprintf(stderr,
3957836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
3967836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
3977836SJohn.Forte@Sun.COM exit(1);
3987836SJohn.Forte@Sun.COM }
3997836SJohn.Forte@Sun.COM
4007836SJohn.Forte@Sun.COM for (setnumber = 1; /*CSTYLED*/; setnumber++) {
4017836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
4027836SJohn.Forte@Sun.COM "bitmaps.set%d.bitmap", setnumber);
4037836SJohn.Forte@Sun.COM buf[0] = 0;
4047836SJohn.Forte@Sun.COM
4057836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
4067836SJohn.Forte@Sun.COM if (errno == ESRCH) {
4077836SJohn.Forte@Sun.COM /* end of list */
4087836SJohn.Forte@Sun.COM break;
4097836SJohn.Forte@Sun.COM }
4107836SJohn.Forte@Sun.COM
4117836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4127836SJohn.Forte@Sun.COM gettext("%s: error reading configuration: %s\n"),
4137836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
4147836SJohn.Forte@Sun.COM exit(1);
4157836SJohn.Forte@Sun.COM }
4167836SJohn.Forte@Sun.COM
4177836SJohn.Forte@Sun.COM (void) printf("%s\n", buf);
4187836SJohn.Forte@Sun.COM }
4197836SJohn.Forte@Sun.COM
4207836SJohn.Forte@Sun.COM cfg_close(cfg);
4217836SJohn.Forte@Sun.COM }
4227836SJohn.Forte@Sun.COM
4237836SJohn.Forte@Sun.COM
4247836SJohn.Forte@Sun.COM static void
bitmapfs_delete(char * bitmapfs)4257836SJohn.Forte@Sun.COM bitmapfs_delete(char *bitmapfs)
4267836SJohn.Forte@Sun.COM {
4277836SJohn.Forte@Sun.COM CFGFILE *cfg;
4287836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
4297836SJohn.Forte@Sun.COM int setnumber;
4307836SJohn.Forte@Sun.COM int commit = 0;
4317836SJohn.Forte@Sun.COM
4327836SJohn.Forte@Sun.COM cfg = cfg_open(NULL);
4337836SJohn.Forte@Sun.COM if (cfg == NULL) {
4347836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4357836SJohn.Forte@Sun.COM gettext("%s: unable to access configuration: %s\n"),
4367836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
4377836SJohn.Forte@Sun.COM exit(1);
4387836SJohn.Forte@Sun.COM }
4397836SJohn.Forte@Sun.COM
4407836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_WRLOCK)) {
4417836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4427836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
4437836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
4447836SJohn.Forte@Sun.COM exit(1);
4457836SJohn.Forte@Sun.COM }
4467836SJohn.Forte@Sun.COM
4477836SJohn.Forte@Sun.COM for (setnumber = 1; /*CSTYLED*/; setnumber++) {
4487836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
4497836SJohn.Forte@Sun.COM "bitmaps.set%d.bitmap", setnumber);
4507836SJohn.Forte@Sun.COM buf[0] = 0;
4517836SJohn.Forte@Sun.COM
4527836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
4537836SJohn.Forte@Sun.COM if (errno == ESRCH) {
4547836SJohn.Forte@Sun.COM /* end of list */
4557836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4567836SJohn.Forte@Sun.COM gettext("%s: %s not found "
4577836SJohn.Forte@Sun.COM "in configuration\n"),
4587836SJohn.Forte@Sun.COM progname, bitmapfs);
4597836SJohn.Forte@Sun.COM break;
4607836SJohn.Forte@Sun.COM }
4617836SJohn.Forte@Sun.COM
4627836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4637836SJohn.Forte@Sun.COM gettext("%s: error reading configuration: %s\n"),
4647836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
4657836SJohn.Forte@Sun.COM exit(1);
4667836SJohn.Forte@Sun.COM }
4677836SJohn.Forte@Sun.COM
4687836SJohn.Forte@Sun.COM if (strcmp(bitmapfs, buf) == 0) {
4697836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
4707836SJohn.Forte@Sun.COM "bitmaps.set%d", setnumber);
4717836SJohn.Forte@Sun.COM
4727836SJohn.Forte@Sun.COM if (cfg_put_cstring(cfg, key, (char *)NULL, 0) < 0) {
4737836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4747836SJohn.Forte@Sun.COM gettext("%s: unable to delete %s "
4757836SJohn.Forte@Sun.COM "from configuration: %s\n"),
4767836SJohn.Forte@Sun.COM progname, bitmapfs, cfg_error(NULL));
4777836SJohn.Forte@Sun.COM } else
4787836SJohn.Forte@Sun.COM commit++;
4797836SJohn.Forte@Sun.COM
4807836SJohn.Forte@Sun.COM break;
4817836SJohn.Forte@Sun.COM }
4827836SJohn.Forte@Sun.COM }
4837836SJohn.Forte@Sun.COM
4847836SJohn.Forte@Sun.COM if (commit) {
4857836SJohn.Forte@Sun.COM if (!cfg_commit(cfg)) {
4867836SJohn.Forte@Sun.COM (void) fprintf(stderr,
4877836SJohn.Forte@Sun.COM gettext("%s: unable to write "
4887836SJohn.Forte@Sun.COM "to configuration: %s\n"),
4897836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
4907836SJohn.Forte@Sun.COM }
4917836SJohn.Forte@Sun.COM commit = 0;
4927836SJohn.Forte@Sun.COM }
4937836SJohn.Forte@Sun.COM
4947836SJohn.Forte@Sun.COM cfg_close(cfg);
4957836SJohn.Forte@Sun.COM }
4967836SJohn.Forte@Sun.COM
4977836SJohn.Forte@Sun.COM
4987836SJohn.Forte@Sun.COM /*
4997836SJohn.Forte@Sun.COM * User visible configuration.
5007836SJohn.Forte@Sun.COM */
5017836SJohn.Forte@Sun.COM
5027836SJohn.Forte@Sun.COM static const struct {
5037836SJohn.Forte@Sun.COM const char *tag; /* libcfg tag */
5047836SJohn.Forte@Sun.COM const char *name; /* user presented name */
5057836SJohn.Forte@Sun.COM const char *help; /* explanation string */
5067836SJohn.Forte@Sun.COM } sdbc_cfg_options[] = {
5077836SJohn.Forte@Sun.COM { "thread", "nthreads", "number of threads" },
5087836SJohn.Forte@Sun.COM { "size", "cache_size", "total cache size" },
5097836SJohn.Forte@Sun.COM #ifdef DEBUG
5107836SJohn.Forte@Sun.COM { "write_cache", "write_cache_size", "write cache size" },
5117836SJohn.Forte@Sun.COM { "fill_pattern", "fill_pattern", "debug fill pattern" },
5127836SJohn.Forte@Sun.COM { "reserved1", "reserved1", "unavailable, do not use" },
5137836SJohn.Forte@Sun.COM { "iobuf", "niobuf", "number of io buffers" },
5147836SJohn.Forte@Sun.COM { "tdemons", "ntdeamons", "number of sd_test daemons" },
5157836SJohn.Forte@Sun.COM { "forced_wrthru", "forced_wrthru", "override wrthru detection" },
5167836SJohn.Forte@Sun.COM { "no_forced_wrthru", "no_forced_wrthru", "override wrthru"},
5177836SJohn.Forte@Sun.COM #endif
5187836SJohn.Forte@Sun.COM { NULL }
5197836SJohn.Forte@Sun.COM };
5207836SJohn.Forte@Sun.COM
5217836SJohn.Forte@Sun.COM
5227836SJohn.Forte@Sun.COM static int
configure_sdbc(int argc,char * argv[],int optind)5237836SJohn.Forte@Sun.COM configure_sdbc(int argc, char *argv[], int optind)
5247836SJohn.Forte@Sun.COM {
5257836SJohn.Forte@Sun.COM CFGFILE *cfg;
5267836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
5277836SJohn.Forte@Sun.COM char *cp, option[CFG_MAX_BUF], value[CFG_MAX_BUF];
5287836SJohn.Forte@Sun.COM const int opt_width = 20;
5297836SJohn.Forte@Sun.COM int error, found, commit;
5307836SJohn.Forte@Sun.COM int i;
5317836SJohn.Forte@Sun.COM
5327836SJohn.Forte@Sun.COM error = commit = 0;
5337836SJohn.Forte@Sun.COM
5347836SJohn.Forte@Sun.COM cfg = cfg_open(NULL);
5357836SJohn.Forte@Sun.COM if (cfg == NULL) {
5367836SJohn.Forte@Sun.COM (void) fprintf(stderr, "%s: unable to open configuration: %s",
5377836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
5387836SJohn.Forte@Sun.COM return (1);
5397836SJohn.Forte@Sun.COM }
5407836SJohn.Forte@Sun.COM
5417836SJohn.Forte@Sun.COM if (argc == optind) {
5427836SJohn.Forte@Sun.COM /* display current user visible config */
5437836SJohn.Forte@Sun.COM
5447836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_RDLOCK)) {
5457836SJohn.Forte@Sun.COM (void) fprintf(stderr,
5467836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
5477836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
5487836SJohn.Forte@Sun.COM error = 1;
5497836SJohn.Forte@Sun.COM goto out;
5507836SJohn.Forte@Sun.COM }
5517836SJohn.Forte@Sun.COM
5527836SJohn.Forte@Sun.COM convert_config(cfg, CFG_RDLOCK);
5537836SJohn.Forte@Sun.COM
5547836SJohn.Forte@Sun.COM for (i = 0; sdbc_cfg_options[i].tag != NULL; i++) {
5557836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
5567836SJohn.Forte@Sun.COM "scm.set1.%s", sdbc_cfg_options[i].tag);
5577836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
5587836SJohn.Forte@Sun.COM if (errno == ESRCH) {
5597836SJohn.Forte@Sun.COM /* not found */
560*11576SSurya.Prakki@Sun.COM (void) strcpy(buf, "");
5617836SJohn.Forte@Sun.COM } else {
5627836SJohn.Forte@Sun.COM (void) fprintf(stderr,
5637836SJohn.Forte@Sun.COM gettext("%s: error reading "
5647836SJohn.Forte@Sun.COM "configuration: %s\n"),
5657836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
5667836SJohn.Forte@Sun.COM error = 1;
5677836SJohn.Forte@Sun.COM goto out;
5687836SJohn.Forte@Sun.COM }
5697836SJohn.Forte@Sun.COM }
5707836SJohn.Forte@Sun.COM
5717836SJohn.Forte@Sun.COM (void) printf("%-*s: %-*s /* %s */\n",
5727836SJohn.Forte@Sun.COM opt_width, sdbc_cfg_options[i].name,
5737836SJohn.Forte@Sun.COM opt_width, buf, sdbc_cfg_options[i].help);
5747836SJohn.Forte@Sun.COM }
5757836SJohn.Forte@Sun.COM } else {
5767836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_WRLOCK)) {
5777836SJohn.Forte@Sun.COM (void) fprintf(stderr,
5787836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
5797836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
5807836SJohn.Forte@Sun.COM error = 1;
5817836SJohn.Forte@Sun.COM goto out;
5827836SJohn.Forte@Sun.COM }
5837836SJohn.Forte@Sun.COM
5847836SJohn.Forte@Sun.COM convert_config(cfg, CFG_WRLOCK);
5857836SJohn.Forte@Sun.COM
5867836SJohn.Forte@Sun.COM for (/*CSTYLED*/; optind < argc; optind++) {
587*11576SSurya.Prakki@Sun.COM (void) strncpy(option, argv[optind], sizeof (option));
5887836SJohn.Forte@Sun.COM option[sizeof (option) - 1] = '\0'; /* terminate */
5897836SJohn.Forte@Sun.COM
5907836SJohn.Forte@Sun.COM cp = strchr(option, '=');
5917836SJohn.Forte@Sun.COM if (cp != NULL) {
5927836SJohn.Forte@Sun.COM *cp = '\0'; /* terminate option */
5937836SJohn.Forte@Sun.COM cp++;
594*11576SSurya.Prakki@Sun.COM (void) strncpy(value, cp, sizeof (value));
5957836SJohn.Forte@Sun.COM value[sizeof (value) - 1] = '\0';
5967836SJohn.Forte@Sun.COM
5977836SJohn.Forte@Sun.COM if (*value == '\0')
598*11576SSurya.Prakki@Sun.COM (void) strncpy(value, "-",
599*11576SSurya.Prakki@Sun.COM sizeof (value));
6007836SJohn.Forte@Sun.COM }
6017836SJohn.Forte@Sun.COM
6027836SJohn.Forte@Sun.COM found = 0;
6037836SJohn.Forte@Sun.COM for (i = 0; sdbc_cfg_options[i].tag != NULL; i++) {
6047836SJohn.Forte@Sun.COM if (strcmp(option,
6057836SJohn.Forte@Sun.COM sdbc_cfg_options[i].name) == 0) {
6067836SJohn.Forte@Sun.COM found = 1;
6077836SJohn.Forte@Sun.COM break;
6087836SJohn.Forte@Sun.COM }
6097836SJohn.Forte@Sun.COM }
6107836SJohn.Forte@Sun.COM
6117836SJohn.Forte@Sun.COM if (!found) {
6127836SJohn.Forte@Sun.COM (void) fprintf(stderr,
6137836SJohn.Forte@Sun.COM gettext("%s: unknown configuration "
6147836SJohn.Forte@Sun.COM "parameter: %s\n"), progname, option);
6157836SJohn.Forte@Sun.COM continue;
6167836SJohn.Forte@Sun.COM }
6177836SJohn.Forte@Sun.COM
6187836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
6197836SJohn.Forte@Sun.COM "scm.set1.%s", sdbc_cfg_options[i].tag);
6207836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
6217836SJohn.Forte@Sun.COM (void) fprintf(stderr,
6227836SJohn.Forte@Sun.COM gettext("%s: error reading "
6237836SJohn.Forte@Sun.COM "configuration: %s\n"),
6247836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
6257836SJohn.Forte@Sun.COM error = 1;
6267836SJohn.Forte@Sun.COM goto out;
6277836SJohn.Forte@Sun.COM }
6287836SJohn.Forte@Sun.COM
6297836SJohn.Forte@Sun.COM if (*buf == '\0')
630*11576SSurya.Prakki@Sun.COM (void) strncpy(buf, "<default>", sizeof (buf));
6317836SJohn.Forte@Sun.COM
6327836SJohn.Forte@Sun.COM if (cp != NULL) {
6337836SJohn.Forte@Sun.COM char *tmp;
6347836SJohn.Forte@Sun.COM long val;
6357836SJohn.Forte@Sun.COM /* set to new value */
6367836SJohn.Forte@Sun.COM
6377836SJohn.Forte@Sun.COM if (strcmp(value, "-")) { /* default ? */
6387836SJohn.Forte@Sun.COM
6397836SJohn.Forte@Sun.COM val = strtol(value, &tmp, 0);
6407836SJohn.Forte@Sun.COM if (strcmp(value, tmp) == 0) {
6417836SJohn.Forte@Sun.COM (void) fprintf(stderr,
6427836SJohn.Forte@Sun.COM gettext(
643*11576SSurya.Prakki@Sun.COM "%s: bad value (%s) "
644*11576SSurya.Prakki@Sun.COM "for option %s\n"),
6457836SJohn.Forte@Sun.COM progname, value, option);
6467836SJohn.Forte@Sun.COM error = 1;
6477836SJohn.Forte@Sun.COM goto out;
6487836SJohn.Forte@Sun.COM }
6497836SJohn.Forte@Sun.COM
6507836SJohn.Forte@Sun.COM /* make sure cache size is valid */
6517836SJohn.Forte@Sun.COM if (strcmp(key, "scm.set1.size") == 0) {
6527836SJohn.Forte@Sun.COM if (val > MAX_CACHE_SIZE) {
6537836SJohn.Forte@Sun.COM PRINT_CACHE_SZ_ERR(val);
6547836SJohn.Forte@Sun.COM
6557836SJohn.Forte@Sun.COM /*
6567836SJohn.Forte@Sun.COM * Overwrite the
6577836SJohn.Forte@Sun.COM * cache size with
6587836SJohn.Forte@Sun.COM * the maximum cache
6597836SJohn.Forte@Sun.COM * size.
6607836SJohn.Forte@Sun.COM */
6617836SJohn.Forte@Sun.COM (void) snprintf(value,
6627836SJohn.Forte@Sun.COM sizeof (value),
6637836SJohn.Forte@Sun.COM "%ld",
6647836SJohn.Forte@Sun.COM (long)
6657836SJohn.Forte@Sun.COM MAX_CACHE_SIZE);
6667836SJohn.Forte@Sun.COM }
6677836SJohn.Forte@Sun.COM }
6687836SJohn.Forte@Sun.COM }
6697836SJohn.Forte@Sun.COM
6707836SJohn.Forte@Sun.COM if (cfg_put_cstring(cfg, key, value,
6717836SJohn.Forte@Sun.COM strlen(value)) < 0) {
6727836SJohn.Forte@Sun.COM (void) fprintf(stderr,
6737836SJohn.Forte@Sun.COM gettext("\n%s: error writing "
6747836SJohn.Forte@Sun.COM "configuration: %s\n"),
6757836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
6767836SJohn.Forte@Sun.COM error = 1;
6777836SJohn.Forte@Sun.COM goto out;
6787836SJohn.Forte@Sun.COM }
6797836SJohn.Forte@Sun.COM
6807836SJohn.Forte@Sun.COM (void) snprintf(buf, sizeof (buf),
6817836SJohn.Forte@Sun.COM "%s = %s", buf,
6827836SJohn.Forte@Sun.COM (strcmp(value, "-") == 0) ?
6837836SJohn.Forte@Sun.COM "<default>" : value);
6847836SJohn.Forte@Sun.COM
6857836SJohn.Forte@Sun.COM commit = 1;
6867836SJohn.Forte@Sun.COM }
6877836SJohn.Forte@Sun.COM
6887836SJohn.Forte@Sun.COM (void) printf("%-*s: %-*s /* %s */\n",
6897836SJohn.Forte@Sun.COM opt_width, sdbc_cfg_options[i].name,
6907836SJohn.Forte@Sun.COM opt_width, buf, sdbc_cfg_options[i].help);
6917836SJohn.Forte@Sun.COM } /* end command line args */
6927836SJohn.Forte@Sun.COM }
6937836SJohn.Forte@Sun.COM
6947836SJohn.Forte@Sun.COM out:
6957836SJohn.Forte@Sun.COM if (commit) {
6967836SJohn.Forte@Sun.COM if (!cfg_commit(cfg)) {
6977836SJohn.Forte@Sun.COM (void) fprintf(stderr,
6987836SJohn.Forte@Sun.COM gettext("%s: unable to write "
6997836SJohn.Forte@Sun.COM "to configuration: %s\n"),
7007836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
7017836SJohn.Forte@Sun.COM }
7027836SJohn.Forte@Sun.COM commit = 0;
7037836SJohn.Forte@Sun.COM
7047836SJohn.Forte@Sun.COM (void) printf("\n%s\n",
7057836SJohn.Forte@Sun.COM gettext("Changed configuration parameters "
7067836SJohn.Forte@Sun.COM "will take effect when the cache is restarted"));
7077836SJohn.Forte@Sun.COM }
7087836SJohn.Forte@Sun.COM
7097836SJohn.Forte@Sun.COM cfg_close(cfg);
7107836SJohn.Forte@Sun.COM return (error);
7117836SJohn.Forte@Sun.COM }
7127836SJohn.Forte@Sun.COM
7137836SJohn.Forte@Sun.COM
7147836SJohn.Forte@Sun.COM static char *
cd_to_device(int cd)7157836SJohn.Forte@Sun.COM cd_to_device(int cd)
7167836SJohn.Forte@Sun.COM {
7177836SJohn.Forte@Sun.COM static _sd_stats_t *cs_cur = NULL;
7187836SJohn.Forte@Sun.COM spcs_s_info_t ustatus;
7197836SJohn.Forte@Sun.COM
7207836SJohn.Forte@Sun.COM if (cs_cur == NULL) {
7217836SJohn.Forte@Sun.COM cs_cur = malloc(sizeof (_sd_stats_t) +
7227836SJohn.Forte@Sun.COM (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
7237836SJohn.Forte@Sun.COM
7247836SJohn.Forte@Sun.COM if (cs_cur == NULL) {
7257836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s malloc: %s\n"),
7267836SJohn.Forte@Sun.COM progname, strerror(errno));
7277836SJohn.Forte@Sun.COM exit(1);
7287836SJohn.Forte@Sun.COM }
7297836SJohn.Forte@Sun.COM }
7307836SJohn.Forte@Sun.COM
7317836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0,
7327836SJohn.Forte@Sun.COM &ustatus) == SPCS_S_ERROR) {
7337836SJohn.Forte@Sun.COM (void) fprintf(stderr,
7347836SJohn.Forte@Sun.COM gettext("%s: stats ioctl failed\n"), progname);
7357836SJohn.Forte@Sun.COM sdbc_report_error(&ustatus);
7367836SJohn.Forte@Sun.COM exit(1);
7377836SJohn.Forte@Sun.COM }
7387836SJohn.Forte@Sun.COM if (cs_cur->st_cachesize == 0 || cd >= cs_cur->st_count)
7397836SJohn.Forte@Sun.COM return ("");
7407836SJohn.Forte@Sun.COM
7417836SJohn.Forte@Sun.COM return (cs_cur->st_shared[cd].sh_filename);
7427836SJohn.Forte@Sun.COM }
7437836SJohn.Forte@Sun.COM
7447836SJohn.Forte@Sun.COM /*
7457836SJohn.Forte@Sun.COM * takes either either a string containing the cd or the device name, and
7467836SJohn.Forte@Sun.COM * returns the device name.
7477836SJohn.Forte@Sun.COM */
7487836SJohn.Forte@Sun.COM static char *
get_device_name(char * arg)7497836SJohn.Forte@Sun.COM get_device_name(char *arg)
7507836SJohn.Forte@Sun.COM {
7517836SJohn.Forte@Sun.COM long cd = 0;
7527836SJohn.Forte@Sun.COM char *device;
7537836SJohn.Forte@Sun.COM
7547836SJohn.Forte@Sun.COM /* if the arg has a leading '/', assume it's a valid device name */
7557836SJohn.Forte@Sun.COM if (!arg || *arg == '/') {
7567836SJohn.Forte@Sun.COM return (arg);
7577836SJohn.Forte@Sun.COM }
7587836SJohn.Forte@Sun.COM
7597836SJohn.Forte@Sun.COM /* treat the "all" keyword as a valid device name */
7607836SJohn.Forte@Sun.COM if (strcmp(arg, "all") == 0) {
7617836SJohn.Forte@Sun.COM return (arg);
7627836SJohn.Forte@Sun.COM }
7637836SJohn.Forte@Sun.COM
7647836SJohn.Forte@Sun.COM /*
7657836SJohn.Forte@Sun.COM * Next, assume it's a cd, and try to convert it to an integer, and
7667836SJohn.Forte@Sun.COM * subsequently convert that cd to its corresponding device name.
7677836SJohn.Forte@Sun.COM *
7687836SJohn.Forte@Sun.COM * Since strtol returns 0 on failure, we need to make a special case
7697836SJohn.Forte@Sun.COM * for a cd of "0", which is valid.
7707836SJohn.Forte@Sun.COM */
7717836SJohn.Forte@Sun.COM if (((cd = strtol(arg, (char **)NULL, 10)) > 0) ||
7727836SJohn.Forte@Sun.COM strcmp(arg, "0") == 0) {
7737836SJohn.Forte@Sun.COM device = cd_to_device((int)cd);
7747836SJohn.Forte@Sun.COM
7757836SJohn.Forte@Sun.COM /* cd_to_device returns NULL or "" on failure--check both */
7767836SJohn.Forte@Sun.COM if (device && (strcmp(device, ""))) {
7777836SJohn.Forte@Sun.COM /* it seems to be a valid device name */
7787836SJohn.Forte@Sun.COM return (device);
7797836SJohn.Forte@Sun.COM }
7807836SJohn.Forte@Sun.COM }
7817836SJohn.Forte@Sun.COM
7827836SJohn.Forte@Sun.COM return (NULL);
7837836SJohn.Forte@Sun.COM }
7847836SJohn.Forte@Sun.COM
7857836SJohn.Forte@Sun.COM static void
remove_hint(char * device)7867836SJohn.Forte@Sun.COM remove_hint(char *device)
7877836SJohn.Forte@Sun.COM {
7887836SJohn.Forte@Sun.COM CFGFILE *cfg;
7897836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
7907836SJohn.Forte@Sun.COM int setnumber;
7917836SJohn.Forte@Sun.COM int rc;
7927836SJohn.Forte@Sun.COM
7937836SJohn.Forte@Sun.COM if ((cfg = cfg_open(NULL)) == NULL) {
7947836SJohn.Forte@Sun.COM (void) fprintf(stderr,
7957836SJohn.Forte@Sun.COM gettext("%s: unable to access configuration: %s\n"),
7967836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
7977836SJohn.Forte@Sun.COM exit(1);
7987836SJohn.Forte@Sun.COM }
7997836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_WRLOCK)) {
8007836SJohn.Forte@Sun.COM (void) fprintf(stderr,
8017836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
8027836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
8037836SJohn.Forte@Sun.COM exit(1);
8047836SJohn.Forte@Sun.COM }
8057836SJohn.Forte@Sun.COM
8067836SJohn.Forte@Sun.COM for (setnumber = 1; /*CONSTCOND*/ TRUE; setnumber++) {
8077836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "cache_hint.set%d.device",
8087836SJohn.Forte@Sun.COM setnumber);
8097836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
8107836SJohn.Forte@Sun.COM /* error or not found */
8117836SJohn.Forte@Sun.COM break;
8127836SJohn.Forte@Sun.COM }
8137836SJohn.Forte@Sun.COM
8147836SJohn.Forte@Sun.COM if (strcmp(device, buf) != 0)
8157836SJohn.Forte@Sun.COM continue;
8167836SJohn.Forte@Sun.COM
8177836SJohn.Forte@Sun.COM /* remove config file entry */
8187836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
8197836SJohn.Forte@Sun.COM "cache_hint.set%d", setnumber);
8207836SJohn.Forte@Sun.COM rc = cfg_put_cstring(cfg, key, NULL, 0);
8217836SJohn.Forte@Sun.COM if (rc < 0)
8227836SJohn.Forte@Sun.COM (void) fprintf(stderr,
8237836SJohn.Forte@Sun.COM gettext("%s: unable to update configuration "
8247836SJohn.Forte@Sun.COM "storage: %s"),
8257836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
8267836SJohn.Forte@Sun.COM else if (!cfg_commit(cfg))
8277836SJohn.Forte@Sun.COM (void) fprintf(stderr,
8287836SJohn.Forte@Sun.COM gettext("%s: unable to update configuration "
8297836SJohn.Forte@Sun.COM "storage: %s"),
8307836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
8317836SJohn.Forte@Sun.COM else
8327836SJohn.Forte@Sun.COM (void) fprintf(stderr,
8337836SJohn.Forte@Sun.COM gettext("%s: persistent hint for %s"
8347836SJohn.Forte@Sun.COM " removed from configuration\n"),
8357836SJohn.Forte@Sun.COM progname, device);
8367836SJohn.Forte@Sun.COM break;
8377836SJohn.Forte@Sun.COM }
8387836SJohn.Forte@Sun.COM cfg_close(cfg);
8397836SJohn.Forte@Sun.COM }
8407836SJohn.Forte@Sun.COM
8417836SJohn.Forte@Sun.COM
8427836SJohn.Forte@Sun.COM static void
save_hint(int cd,int hint,int flag)8437836SJohn.Forte@Sun.COM save_hint(int cd, int hint, int flag)
8447836SJohn.Forte@Sun.COM {
8457836SJohn.Forte@Sun.COM char device[NSC_MAXPATH];
8467836SJohn.Forte@Sun.COM CFGFILE *cfg;
8477836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
8487836SJohn.Forte@Sun.COM int setnumber;
8497836SJohn.Forte@Sun.COM int found;
8507836SJohn.Forte@Sun.COM int rc;
8517836SJohn.Forte@Sun.COM
8527836SJohn.Forte@Sun.COM if (hint != NSC_WRTHRU && hint != NSC_NOCACHE)
8537836SJohn.Forte@Sun.COM return;
8547836SJohn.Forte@Sun.COM
8557836SJohn.Forte@Sun.COM if (flag != 0 && flag != 1)
8567836SJohn.Forte@Sun.COM return;
8577836SJohn.Forte@Sun.COM
8587836SJohn.Forte@Sun.COM if ((cfg = cfg_open(NULL)) == NULL) {
8597836SJohn.Forte@Sun.COM (void) fprintf(stderr,
8607836SJohn.Forte@Sun.COM gettext("%s: unable to access configuration: %s\n"),
8617836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
8627836SJohn.Forte@Sun.COM exit(1);
8637836SJohn.Forte@Sun.COM }
8647836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_WRLOCK)) {
8657836SJohn.Forte@Sun.COM (void) fprintf(stderr,
8667836SJohn.Forte@Sun.COM gettext("%s: unable to lock configuration: %s\n"),
8677836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
8687836SJohn.Forte@Sun.COM exit(1);
8697836SJohn.Forte@Sun.COM }
8707836SJohn.Forte@Sun.COM
8717836SJohn.Forte@Sun.COM if (cd == -1)
872*11576SSurya.Prakki@Sun.COM (void) strcpy(device, "system");
8737836SJohn.Forte@Sun.COM else
874*11576SSurya.Prakki@Sun.COM (void) strncpy(device, cd_to_device(cd), NSC_MAXPATH);
8757836SJohn.Forte@Sun.COM
8767836SJohn.Forte@Sun.COM found = 0;
8777836SJohn.Forte@Sun.COM for (setnumber = 1; /*CONSTCOND*/ TRUE; setnumber++) {
8787836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "cache_hint.set%d.device",
8797836SJohn.Forte@Sun.COM setnumber);
8807836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
8817836SJohn.Forte@Sun.COM /* error or not found */
8827836SJohn.Forte@Sun.COM break;
8837836SJohn.Forte@Sun.COM }
8847836SJohn.Forte@Sun.COM
8857836SJohn.Forte@Sun.COM if (strcmp(device, buf) == 0) {
8867836SJohn.Forte@Sun.COM found = 1;
8877836SJohn.Forte@Sun.COM break;
8887836SJohn.Forte@Sun.COM }
8897836SJohn.Forte@Sun.COM }
8907836SJohn.Forte@Sun.COM
8917836SJohn.Forte@Sun.COM if (found) {
8927836SJohn.Forte@Sun.COM if (hint == NSC_WRTHRU)
8937836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
8947836SJohn.Forte@Sun.COM "cache_hint.set%d.wrthru", setnumber);
8957836SJohn.Forte@Sun.COM else /* NSC_NOCACHE */
8967836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key),
8977836SJohn.Forte@Sun.COM "cache_hint.set%d.nordcache", setnumber);
8987836SJohn.Forte@Sun.COM if (flag == 0)
8997836SJohn.Forte@Sun.COM rc = cfg_put_cstring(cfg, key, "0", 1);
9007836SJohn.Forte@Sun.COM else
9017836SJohn.Forte@Sun.COM rc = cfg_put_cstring(cfg, key, "1", 1);
9027836SJohn.Forte@Sun.COM } else {
903*11576SSurya.Prakki@Sun.COM (void) strncpy(buf, device, CFG_MAX_BUF);
9047836SJohn.Forte@Sun.COM if (flag == 0)
905*11576SSurya.Prakki@Sun.COM (void) strncat(buf, " 0 0", CFG_MAX_BUF);
9067836SJohn.Forte@Sun.COM else if (hint == NSC_WRTHRU)
907*11576SSurya.Prakki@Sun.COM (void) strncat(buf, " 1 0", CFG_MAX_BUF);
9087836SJohn.Forte@Sun.COM else /* NSC_NOCACHE */
909*11576SSurya.Prakki@Sun.COM (void) strncat(buf, " 0 1", CFG_MAX_BUF);
9107836SJohn.Forte@Sun.COM rc = cfg_put_cstring(cfg, "cache_hint", buf, sizeof (buf));
9117836SJohn.Forte@Sun.COM }
9127836SJohn.Forte@Sun.COM
9137836SJohn.Forte@Sun.COM if (rc < 0)
9147836SJohn.Forte@Sun.COM (void) fprintf(stderr,
9157836SJohn.Forte@Sun.COM gettext("%s: unable to update configuration storage: %s"),
9167836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
9177836SJohn.Forte@Sun.COM else if (!cfg_commit(cfg))
9187836SJohn.Forte@Sun.COM (void) fprintf(stderr,
9197836SJohn.Forte@Sun.COM gettext("%s: unable to update configuration storage: %s"),
9207836SJohn.Forte@Sun.COM progname, cfg_error(NULL));
9217836SJohn.Forte@Sun.COM cfg_close(cfg);
9227836SJohn.Forte@Sun.COM }
9237836SJohn.Forte@Sun.COM
9247836SJohn.Forte@Sun.COM #ifdef lint
9257836SJohn.Forte@Sun.COM int
scmadm_lintmain(int argc,char * argv[])9267836SJohn.Forte@Sun.COM scmadm_lintmain(int argc, char *argv[])
9277836SJohn.Forte@Sun.COM #else
9287836SJohn.Forte@Sun.COM int
9297836SJohn.Forte@Sun.COM main(int argc, char *argv[])
9307836SJohn.Forte@Sun.COM #endif
9317836SJohn.Forte@Sun.COM {
9327836SJohn.Forte@Sun.COM int o = 0;
9337836SJohn.Forte@Sun.COM int c;
9347836SJohn.Forte@Sun.COM int errflg = 0;
9357836SJohn.Forte@Sun.COM int hflag = 0;
9367836SJohn.Forte@Sun.COM int qflag = 1;
9377836SJohn.Forte@Sun.COM extern int optind;
9387836SJohn.Forte@Sun.COM extern char *optarg;
9397836SJohn.Forte@Sun.COM int cd;
9407836SJohn.Forte@Sun.COM int hint;
9417836SJohn.Forte@Sun.COM int flag;
9427836SJohn.Forte@Sun.COM int optflag = 0;
9437836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
9447836SJohn.Forte@Sun.COM int Dopt, Lopt;
9457836SJohn.Forte@Sun.COM int Oopt = 0;
9467836SJohn.Forte@Sun.COM char *bitmapfs = NULL;
9477836SJohn.Forte@Sun.COM const char *exclusive = gettext(
9487836SJohn.Forte@Sun.COM "-d, -e, -m, -o, -C, -D, -L, and -v "
9497836SJohn.Forte@Sun.COM "are mutually exclusive\n");
9507836SJohn.Forte@Sun.COM
9517836SJohn.Forte@Sun.COM (void) setlocale(LC_ALL, "");
9527836SJohn.Forte@Sun.COM (void) textdomain("scm");
9537836SJohn.Forte@Sun.COM
9547836SJohn.Forte@Sun.COM progname = strdup(basename(argv[0]));
9557836SJohn.Forte@Sun.COM
9567836SJohn.Forte@Sun.COM sdbc_set_maxdev();
9577836SJohn.Forte@Sun.COM
9587836SJohn.Forte@Sun.COM buildusage(progname);
9597836SJohn.Forte@Sun.COM
9607836SJohn.Forte@Sun.COM Dopt = Lopt = 0;
9617836SJohn.Forte@Sun.COM
9627836SJohn.Forte@Sun.COM while ((c = getopt(argc, argv,
9637836SJohn.Forte@Sun.COM #ifdef DEBUG
9647836SJohn.Forte@Sun.COM "gi:t:S"
9657836SJohn.Forte@Sun.COM #endif
9667836SJohn.Forte@Sun.COM "CD:LOa:devqhm:o:")) != EOF) {
9677836SJohn.Forte@Sun.COM
9687836SJohn.Forte@Sun.COM switch (c) {
9697836SJohn.Forte@Sun.COM
9707836SJohn.Forte@Sun.COM case 'D':
9717836SJohn.Forte@Sun.COM if (optflag) {
9727836SJohn.Forte@Sun.COM (void) fprintf(stderr, exclusive);
9737836SJohn.Forte@Sun.COM goto usage;
9747836SJohn.Forte@Sun.COM }
9757836SJohn.Forte@Sun.COM
9767836SJohn.Forte@Sun.COM Dopt++;
9777836SJohn.Forte@Sun.COM optflag++;
9787836SJohn.Forte@Sun.COM bitmapfs = optarg;
9797836SJohn.Forte@Sun.COM break;
9807836SJohn.Forte@Sun.COM
9817836SJohn.Forte@Sun.COM case 'L':
9827836SJohn.Forte@Sun.COM if (optflag) {
9837836SJohn.Forte@Sun.COM (void) fprintf(stderr, exclusive);
9847836SJohn.Forte@Sun.COM goto usage;
9857836SJohn.Forte@Sun.COM }
9867836SJohn.Forte@Sun.COM
9877836SJohn.Forte@Sun.COM Lopt++;
9887836SJohn.Forte@Sun.COM optflag++;
9897836SJohn.Forte@Sun.COM break;
9907836SJohn.Forte@Sun.COM
9917836SJohn.Forte@Sun.COM #ifdef DEBUG
9927836SJohn.Forte@Sun.COM case 'S':
9937836SJohn.Forte@Sun.COM if (optflag) {
9947836SJohn.Forte@Sun.COM (void) fprintf(stderr, exclusive);
9957836SJohn.Forte@Sun.COM goto usage;
9967836SJohn.Forte@Sun.COM }
9977836SJohn.Forte@Sun.COM
9987836SJohn.Forte@Sun.COM if (putenv(stats_usage) != 0) {
9997836SJohn.Forte@Sun.COM (void) fprintf(stderr,
10007836SJohn.Forte@Sun.COM gettext("%s: unable to putenv()\n"),
10017836SJohn.Forte@Sun.COM progname);
10027836SJohn.Forte@Sun.COM exit(1);
10037836SJohn.Forte@Sun.COM }
10047836SJohn.Forte@Sun.COM
10057836SJohn.Forte@Sun.COM argv[1] = "scmadm";
10067836SJohn.Forte@Sun.COM if (execv(STATS_PATH, &argv[1]) == -1) {
10077836SJohn.Forte@Sun.COM (void) fprintf(stderr,
10087836SJohn.Forte@Sun.COM gettext("%s: failed to execute " STATS_PATH
10097836SJohn.Forte@Sun.COM "\n"), progname);
10107836SJohn.Forte@Sun.COM (void) fprintf(stderr,
10117836SJohn.Forte@Sun.COM gettext("Please be sure to copy sd_stats"
10127836SJohn.Forte@Sun.COM " from src/cmd/ns/sdbc in a development"
10137836SJohn.Forte@Sun.COM " workspace\n"));
10147836SJohn.Forte@Sun.COM }
10157836SJohn.Forte@Sun.COM exit(0);
10167836SJohn.Forte@Sun.COM break;
10177836SJohn.Forte@Sun.COM #endif
10187836SJohn.Forte@Sun.COM case 'a':
1019*11576SSurya.Prakki@Sun.COM (void) strcpy(alert_file, optarg);
10207836SJohn.Forte@Sun.COM break;
10217836SJohn.Forte@Sun.COM case 'q':
10227836SJohn.Forte@Sun.COM qflag++;
10237836SJohn.Forte@Sun.COM break;
10247836SJohn.Forte@Sun.COM case 'O': /* restore hints */
10257836SJohn.Forte@Sun.COM Oopt++;
10267836SJohn.Forte@Sun.COM break;
10277836SJohn.Forte@Sun.COM case 'C': /* configure */
10287836SJohn.Forte@Sun.COM case 'e': /* enable */
10297836SJohn.Forte@Sun.COM case 'd': /* disable */
10307836SJohn.Forte@Sun.COM case 'v': /* get version */
10317836SJohn.Forte@Sun.COM case 'o': /* get/set options */
10327836SJohn.Forte@Sun.COM case 'm': /* get cd map */
10337836SJohn.Forte@Sun.COM #ifdef DEBUG
10347836SJohn.Forte@Sun.COM case 't': /* trace */
10357836SJohn.Forte@Sun.COM case 'i': /* inject_ioerr */
10367836SJohn.Forte@Sun.COM case 'c': /* clear_ioerr */
10377836SJohn.Forte@Sun.COM case 'g': /* toggle_flush */
10387836SJohn.Forte@Sun.COM #endif
10397836SJohn.Forte@Sun.COM if (optflag) {
10407836SJohn.Forte@Sun.COM (void) fprintf(stderr,
10417836SJohn.Forte@Sun.COM #ifdef DEBUG
10427836SJohn.Forte@Sun.COM "%s%s", gettext("-t, -i, -c, -g, "),
10437836SJohn.Forte@Sun.COM #endif
10447836SJohn.Forte@Sun.COM exclusive);
10457836SJohn.Forte@Sun.COM
10467836SJohn.Forte@Sun.COM errflg++;
10477836SJohn.Forte@Sun.COM }
10487836SJohn.Forte@Sun.COM optflag++;
10497836SJohn.Forte@Sun.COM o = c;
10507836SJohn.Forte@Sun.COM break;
10517836SJohn.Forte@Sun.COM case 'h':
10527836SJohn.Forte@Sun.COM hflag = 1;
10537836SJohn.Forte@Sun.COM break;
10547836SJohn.Forte@Sun.COM case '?':
10557836SJohn.Forte@Sun.COM default:
10567836SJohn.Forte@Sun.COM errflg++;
10577836SJohn.Forte@Sun.COM break;
10587836SJohn.Forte@Sun.COM }
10597836SJohn.Forte@Sun.COM if (errflg || hflag)
10607836SJohn.Forte@Sun.COM goto usage;
10617836SJohn.Forte@Sun.COM }
10627836SJohn.Forte@Sun.COM
10637836SJohn.Forte@Sun.COM if (Oopt) {
10647836SJohn.Forte@Sun.COM /* Set hints saved in persistent configuration */
10657836SJohn.Forte@Sun.COM restore_hints();
10667836SJohn.Forte@Sun.COM exit(0);
10677836SJohn.Forte@Sun.COM }
10687836SJohn.Forte@Sun.COM if (Dopt || Lopt) {
10697836SJohn.Forte@Sun.COM /* bitmapfs control */
10707836SJohn.Forte@Sun.COM
10717836SJohn.Forte@Sun.COM if (iscluster()) {
10727836SJohn.Forte@Sun.COM (void) fprintf(stderr,
10737836SJohn.Forte@Sun.COM gettext("%s: bitmap filesystems are not "
10747836SJohn.Forte@Sun.COM "allowed in a cluster\n"), progname);
10757836SJohn.Forte@Sun.COM goto usage;
10767836SJohn.Forte@Sun.COM }
10777836SJohn.Forte@Sun.COM
10787836SJohn.Forte@Sun.COM if ((Dopt + Lopt) > 1) {
10797836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("-D and -L are"
10807836SJohn.Forte@Sun.COM "mutually exclusive\n"));
10817836SJohn.Forte@Sun.COM goto usage;
10827836SJohn.Forte@Sun.COM }
10837836SJohn.Forte@Sun.COM
10847836SJohn.Forte@Sun.COM if (Lopt)
10857836SJohn.Forte@Sun.COM bitmapfs_print();
10867836SJohn.Forte@Sun.COM else /* if (Dopt) */
10877836SJohn.Forte@Sun.COM bitmapfs_delete(bitmapfs);
10887836SJohn.Forte@Sun.COM
10897836SJohn.Forte@Sun.COM exit(0);
10907836SJohn.Forte@Sun.COM }
10917836SJohn.Forte@Sun.COM
10927836SJohn.Forte@Sun.COM if (!o) {
10937836SJohn.Forte@Sun.COM if (argc > 1)
10947836SJohn.Forte@Sun.COM goto usage;
10957836SJohn.Forte@Sun.COM (void) printf(gettext("%s: Printing all cd's and options:\n"),
10967836SJohn.Forte@Sun.COM progname);
10977836SJohn.Forte@Sun.COM print_all_options();
10987836SJohn.Forte@Sun.COM }
10997836SJohn.Forte@Sun.COM
11007836SJohn.Forte@Sun.COM /* Configure */
11017836SJohn.Forte@Sun.COM if (o == 'C') {
11027836SJohn.Forte@Sun.COM exit(configure_sdbc(argc, argv, optind));
11037836SJohn.Forte@Sun.COM }
11047836SJohn.Forte@Sun.COM /* enable */
11057836SJohn.Forte@Sun.COM if (o == 'e') {
11067836SJohn.Forte@Sun.COM enable_sdbc();
11077836SJohn.Forte@Sun.COM if (qflag == 0)
11087836SJohn.Forte@Sun.COM sd_gather_alert_dumps();
11097836SJohn.Forte@Sun.COM exit(0);
11107836SJohn.Forte@Sun.COM }
11117836SJohn.Forte@Sun.COM /* disable */
11127836SJohn.Forte@Sun.COM if (o == 'd') {
11137836SJohn.Forte@Sun.COM disable_sdbc();
11147836SJohn.Forte@Sun.COM exit(0);
11157836SJohn.Forte@Sun.COM }
11167836SJohn.Forte@Sun.COM /* get version */
11177836SJohn.Forte@Sun.COM if (o == 'v') {
11187836SJohn.Forte@Sun.COM get_version();
11197836SJohn.Forte@Sun.COM exit(0);
11207836SJohn.Forte@Sun.COM }
11217836SJohn.Forte@Sun.COM /* node_hint or cd_hint */
11227836SJohn.Forte@Sun.COM if (o == 'o') {
11237836SJohn.Forte@Sun.COM if (!(strcoll(optarg, "system"))) { /* node_hint */
11247836SJohn.Forte@Sun.COM if ((optind - 1) == (argc - 1)) { /* get */
11257836SJohn.Forte@Sun.COM if ((hint = SDBC_IOCTL(SDBC_GET_NODE_HINT, 0, 0,
11267836SJohn.Forte@Sun.COM 0, 0, 0, &ustats)) == SPCS_S_ERROR) {
11277836SJohn.Forte@Sun.COM (void) fprintf(stderr,
11287836SJohn.Forte@Sun.COM gettext("%s: get system "
11297836SJohn.Forte@Sun.COM "options failed\n"),
11307836SJohn.Forte@Sun.COM progname);
11317836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
11327836SJohn.Forte@Sun.COM exit(1);
11337836SJohn.Forte@Sun.COM }
11347836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
11357836SJohn.Forte@Sun.COM (void) printf(gettext("System Status: "));
11367836SJohn.Forte@Sun.COM print_hint(hint, 1);
11377836SJohn.Forte@Sun.COM #endif
11387836SJohn.Forte@Sun.COM (void) printf(gettext("System Options: "));
11397836SJohn.Forte@Sun.COM print_hint(hint, 0);
11407836SJohn.Forte@Sun.COM exit(0);
11417836SJohn.Forte@Sun.COM } else { /* set, clear */
11427836SJohn.Forte@Sun.COM if (get_hint(argv[optind], &hint, &flag) == -1)
11437836SJohn.Forte@Sun.COM goto usage;
11447836SJohn.Forte@Sun.COM if (hint == -1) {
11457836SJohn.Forte@Sun.COM /* remove hint from config */
11467836SJohn.Forte@Sun.COM remove_hint("system");
11477836SJohn.Forte@Sun.COM exit(0);
11487836SJohn.Forte@Sun.COM }
11497836SJohn.Forte@Sun.COM
11507836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_SET_NODE_HINT, hint, flag,
11517836SJohn.Forte@Sun.COM 0, 0, 0, &ustats) == SPCS_S_ERROR) {
11527836SJohn.Forte@Sun.COM (void) fprintf(stderr,
11537836SJohn.Forte@Sun.COM gettext("%s: set system "
11547836SJohn.Forte@Sun.COM "option failed\n"),
11557836SJohn.Forte@Sun.COM progname);
11567836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
11577836SJohn.Forte@Sun.COM exit(1);
11587836SJohn.Forte@Sun.COM }
11597836SJohn.Forte@Sun.COM save_hint(-1, hint, flag);
11607836SJohn.Forte@Sun.COM (void) printf(gettext("%s: System option %s"
11617836SJohn.Forte@Sun.COM " now set.\n"), progname, argv[optind]);
11627836SJohn.Forte@Sun.COM exit(0);
11637836SJohn.Forte@Sun.COM }
11647836SJohn.Forte@Sun.COM } else { /* cd_hint */
11657836SJohn.Forte@Sun.COM cd = get_cd(optarg);
11667836SJohn.Forte@Sun.COM if ((optind - 1) == (argc - 1)) { /* get */
11677836SJohn.Forte@Sun.COM if (cd < 0) {
11687836SJohn.Forte@Sun.COM (void) fprintf(stderr,
11697836SJohn.Forte@Sun.COM gettext("%s: device %s not "
11707836SJohn.Forte@Sun.COM "found\n"),
11717836SJohn.Forte@Sun.COM progname, optarg);
11727836SJohn.Forte@Sun.COM exit(1);
11737836SJohn.Forte@Sun.COM }
11747836SJohn.Forte@Sun.COM hint = get_cd_hint(cd);
11757836SJohn.Forte@Sun.COM (void) printf(gettext("%s: cd(%d) Current "
11767836SJohn.Forte@Sun.COM "options are: "), progname, cd);
11777836SJohn.Forte@Sun.COM print_hint(hint, 0);
11787836SJohn.Forte@Sun.COM exit(0);
11797836SJohn.Forte@Sun.COM } else { /* set, clear */
11807836SJohn.Forte@Sun.COM if (get_hint(argv[optind], &hint, &flag) == -1)
11817836SJohn.Forte@Sun.COM goto usage;
11827836SJohn.Forte@Sun.COM if (hint == -1) {
11837836SJohn.Forte@Sun.COM /* remove hint from config */
11847836SJohn.Forte@Sun.COM if (cd < 0)
11857836SJohn.Forte@Sun.COM remove_hint(optarg);
11867836SJohn.Forte@Sun.COM else
11877836SJohn.Forte@Sun.COM remove_hint(cd_to_device(cd));
11887836SJohn.Forte@Sun.COM exit(0);
11897836SJohn.Forte@Sun.COM }
11907836SJohn.Forte@Sun.COM if (cd < 0) {
11917836SJohn.Forte@Sun.COM (void) fprintf(stderr,
11927836SJohn.Forte@Sun.COM gettext("%s: device %s not "
11937836SJohn.Forte@Sun.COM "found\n"),
11947836SJohn.Forte@Sun.COM progname, optarg);
11957836SJohn.Forte@Sun.COM exit(1);
11967836SJohn.Forte@Sun.COM }
11977836SJohn.Forte@Sun.COM
11987836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_SET_CD_HINT, cd, hint,
11997836SJohn.Forte@Sun.COM flag, 0, 0, &ustats) == SPCS_S_ERROR) {
12007836SJohn.Forte@Sun.COM (void) fprintf(stderr,
12017836SJohn.Forte@Sun.COM gettext("%s: set option "
12027836SJohn.Forte@Sun.COM "failed\n"), progname);
12037836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
12047836SJohn.Forte@Sun.COM exit(1);
12057836SJohn.Forte@Sun.COM }
12067836SJohn.Forte@Sun.COM save_hint(cd, hint, flag);
12077836SJohn.Forte@Sun.COM (void) printf(gettext("%s: cd %d option %s now"
12087836SJohn.Forte@Sun.COM " set.\n"), progname, cd, argv[optind]);
12097836SJohn.Forte@Sun.COM exit(0);
12107836SJohn.Forte@Sun.COM }
12117836SJohn.Forte@Sun.COM }
12127836SJohn.Forte@Sun.COM }
12137836SJohn.Forte@Sun.COM
12147836SJohn.Forte@Sun.COM if (o == 'm') { /* "get_cd" = map */
12157836SJohn.Forte@Sun.COM char *dev_name;
12167836SJohn.Forte@Sun.COM
12177836SJohn.Forte@Sun.COM if (!(strcoll(optarg, "all"))) /* all */
12187836SJohn.Forte@Sun.COM (void) get_cd_all();
12197836SJohn.Forte@Sun.COM else {
12207836SJohn.Forte@Sun.COM cd = get_cd(optarg);
12217836SJohn.Forte@Sun.COM if (cd < 0) {
12227836SJohn.Forte@Sun.COM (void) fprintf(stderr,
12237836SJohn.Forte@Sun.COM gettext("%s: device or cd %s not found\n"),
12247836SJohn.Forte@Sun.COM progname, optarg);
12257836SJohn.Forte@Sun.COM exit(1);
12267836SJohn.Forte@Sun.COM }
12277836SJohn.Forte@Sun.COM
12287836SJohn.Forte@Sun.COM if ((dev_name = get_device_name(optarg)) == NULL) {
12297836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext(
12307836SJohn.Forte@Sun.COM "%s: device for cd %d not found\n"),
12317836SJohn.Forte@Sun.COM progname, cd);
12327836SJohn.Forte@Sun.COM exit(1);
12337836SJohn.Forte@Sun.COM }
12347836SJohn.Forte@Sun.COM
12357836SJohn.Forte@Sun.COM (void) printf(gettext("%s: diskname %s; cd %d\n"),
12367836SJohn.Forte@Sun.COM progname, dev_name, cd);
12377836SJohn.Forte@Sun.COM exit(0);
12387836SJohn.Forte@Sun.COM }
12397836SJohn.Forte@Sun.COM }
12407836SJohn.Forte@Sun.COM
12417836SJohn.Forte@Sun.COM #ifdef DEBUG
12427836SJohn.Forte@Sun.COM if (o == 't') { /* "trace" */
12437836SJohn.Forte@Sun.COM int flag, value;
12447836SJohn.Forte@Sun.COM _sdtr_table_t tt;
12457836SJohn.Forte@Sun.COM if ((optind+1) != (argc-1))
12467836SJohn.Forte@Sun.COM goto usage;
12477836SJohn.Forte@Sun.COM cd = get_cd(argv[optind]);
12487836SJohn.Forte@Sun.COM if (cd < 0) {
12497836SJohn.Forte@Sun.COM (void) fprintf(stderr,
12507836SJohn.Forte@Sun.COM gettext("%s: device or cd %s not found\n"),
12517836SJohn.Forte@Sun.COM progname, argv[optind]);
12527836SJohn.Forte@Sun.COM exit(1);
12537836SJohn.Forte@Sun.COM }
12547836SJohn.Forte@Sun.COM
12557836SJohn.Forte@Sun.COM value = strtol(argv[optind+1], 0, 0);
12567836SJohn.Forte@Sun.COM if (!(strcoll(optarg, gettext("size")))) {
12577836SJohn.Forte@Sun.COM flag = SD_SET_SIZE;
12587836SJohn.Forte@Sun.COM tt.tt_max = value;
12597836SJohn.Forte@Sun.COM } else if (!(strcoll(optarg, gettext("mask")))) {
12607836SJohn.Forte@Sun.COM flag = SD_SET_MASK;
12617836SJohn.Forte@Sun.COM tt.tt_mask = value;
12627836SJohn.Forte@Sun.COM } else if (!(strcoll(optarg, gettext("lbolt")))) {
12637836SJohn.Forte@Sun.COM flag = SD_SET_LBOLT;
12647836SJohn.Forte@Sun.COM tt.tt_lbolt = value;
12657836SJohn.Forte@Sun.COM } else if (!(strcoll(optarg, gettext("good")))) {
12667836SJohn.Forte@Sun.COM flag = SD_SET_GOOD;
12677836SJohn.Forte@Sun.COM tt.tt_good = value;
12687836SJohn.Forte@Sun.COM } else goto usage;
12697836SJohn.Forte@Sun.COM
12707836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_ADUMP, (long)cd, &tt, NULL, 0L,
12717836SJohn.Forte@Sun.COM (long)flag, &ustats) == SPCS_S_ERROR) {
12727836SJohn.Forte@Sun.COM (void) fprintf(stderr,
12737836SJohn.Forte@Sun.COM gettext("%s: trace %s failed\n"),
12747836SJohn.Forte@Sun.COM progname, optarg);
12757836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
12767836SJohn.Forte@Sun.COM exit(1);
12777836SJohn.Forte@Sun.COM }
12787836SJohn.Forte@Sun.COM (void) printf(gettext("%s: trace %s processed\n"),
12797836SJohn.Forte@Sun.COM progname, optarg);
12807836SJohn.Forte@Sun.COM if (cd != -1)
12817836SJohn.Forte@Sun.COM (void) printf(gettext(" cd %d; size %d; mask 0x%04x; "
12827836SJohn.Forte@Sun.COM "lbolt %d; good %d;\n"),
12837836SJohn.Forte@Sun.COM cd, tt.tt_max, tt.tt_mask,
12847836SJohn.Forte@Sun.COM tt.tt_lbolt, tt.tt_good);
12857836SJohn.Forte@Sun.COM exit(0);
12867836SJohn.Forte@Sun.COM }
12877836SJohn.Forte@Sun.COM
12887836SJohn.Forte@Sun.COM if (o == 'i') { /* "inject_ioerr" */
12897836SJohn.Forte@Sun.COM int ioj_err = EIO;
12907836SJohn.Forte@Sun.COM int cd;
12917836SJohn.Forte@Sun.COM int ioj_cnt = 0;
12927836SJohn.Forte@Sun.COM
12937836SJohn.Forte@Sun.COM /* a cd of "-1" represents all devices */
12947836SJohn.Forte@Sun.COM if (strcmp(optarg, "-1") == 0) {
12957836SJohn.Forte@Sun.COM cd = -1;
12967836SJohn.Forte@Sun.COM } else if ((cd = get_cd(optarg)) < 0) {
12977836SJohn.Forte@Sun.COM (void) fprintf(stderr,
12987836SJohn.Forte@Sun.COM gettext("%s: device or cd %s not found\n"),
12997836SJohn.Forte@Sun.COM progname, optarg);
13007836SJohn.Forte@Sun.COM exit(1);
13017836SJohn.Forte@Sun.COM }
13027836SJohn.Forte@Sun.COM if (argc == 4)
13037836SJohn.Forte@Sun.COM ioj_err = strtol(argv[optind], 0, 0);
13047836SJohn.Forte@Sun.COM if (argc == 5)
13057836SJohn.Forte@Sun.COM ioj_cnt = strtol(argv[optind+1], 0, 0);
13067836SJohn.Forte@Sun.COM
13077836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_INJ_IOERR, cd, ioj_err, ioj_cnt, 0, 0,
13087836SJohn.Forte@Sun.COM &ustats) == SPCS_S_ERROR) {
13097836SJohn.Forte@Sun.COM (void) fprintf(stderr,
13107836SJohn.Forte@Sun.COM gettext("%s: i/o error injection for cd %s "
13117836SJohn.Forte@Sun.COM "failed\n"), progname, optarg);
13127836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
13137836SJohn.Forte@Sun.COM exit(1);
13147836SJohn.Forte@Sun.COM }
13157836SJohn.Forte@Sun.COM (void) printf(gettext("%s: i/o error injection cd %d errno %d "
13167836SJohn.Forte@Sun.COM "processed\n"), progname, cd, ioj_err);
13177836SJohn.Forte@Sun.COM exit(0);
13187836SJohn.Forte@Sun.COM }
13197836SJohn.Forte@Sun.COM
13207836SJohn.Forte@Sun.COM if (o == 'c') { /* "clear_ioerr" */
13217836SJohn.Forte@Sun.COM int cd;
13227836SJohn.Forte@Sun.COM
13237836SJohn.Forte@Sun.COM /* a cd of "-1" represents all devices */
13247836SJohn.Forte@Sun.COM if (strcmp(optarg, "-1") == 0) {
13257836SJohn.Forte@Sun.COM cd = -1;
13267836SJohn.Forte@Sun.COM } else if ((cd = get_cd(optarg)) < 0) {
13277836SJohn.Forte@Sun.COM (void) fprintf(stderr,
13287836SJohn.Forte@Sun.COM gettext("%s: device or cd %s not found\n"),
13297836SJohn.Forte@Sun.COM progname, optarg);
13307836SJohn.Forte@Sun.COM exit(1);
13317836SJohn.Forte@Sun.COM }
13327836SJohn.Forte@Sun.COM
13337836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_CLR_IOERR, cd, 0, 0, 0, 0, &ustats)
13347836SJohn.Forte@Sun.COM == SPCS_S_ERROR) {
13357836SJohn.Forte@Sun.COM (void) fprintf(stderr,
13367836SJohn.Forte@Sun.COM gettext("%s: i/o error clear %s failed\n"),
13377836SJohn.Forte@Sun.COM progname, optarg);
13387836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
13397836SJohn.Forte@Sun.COM exit(1);
13407836SJohn.Forte@Sun.COM }
13417836SJohn.Forte@Sun.COM (void) printf(gettext("%s: i/o error clear for cd %d "
13427836SJohn.Forte@Sun.COM "processed\n"), progname, cd);
13437836SJohn.Forte@Sun.COM exit(0);
13447836SJohn.Forte@Sun.COM }
13457836SJohn.Forte@Sun.COM
13467836SJohn.Forte@Sun.COM if (o == 'g') { /* "toggle_flush" */
13477836SJohn.Forte@Sun.COM flag = toggle_flush();
13487836SJohn.Forte@Sun.COM (void) printf(gettext("%s: sdbc cache flush now %s\n"),
13497836SJohn.Forte@Sun.COM progname, flag ? "on" : "off");
13507836SJohn.Forte@Sun.COM exit(0);
13517836SJohn.Forte@Sun.COM }
13527836SJohn.Forte@Sun.COM #endif /* DEBUG */
13537836SJohn.Forte@Sun.COM
13547836SJohn.Forte@Sun.COM return (0);
13557836SJohn.Forte@Sun.COM usage:
13567836SJohn.Forte@Sun.COM (void) fprintf(stderr, "%s\n", scmadmUsage);
13577836SJohn.Forte@Sun.COM if (hflag) {
13587836SJohn.Forte@Sun.COM return (0);
13597836SJohn.Forte@Sun.COM }
13607836SJohn.Forte@Sun.COM return (1);
13617836SJohn.Forte@Sun.COM }
13627836SJohn.Forte@Sun.COM
13637836SJohn.Forte@Sun.COM
13647836SJohn.Forte@Sun.COM #define addusage(f__) \
1365*11576SSurya.Prakki@Sun.COM (void) strncat(scmadmUsage, f__, sizeof (scmadmUsage));
13667836SJohn.Forte@Sun.COM
13677836SJohn.Forte@Sun.COM #define addusage1(f__, a__) \
13687836SJohn.Forte@Sun.COM (void) snprintf(fmt, sizeof (fmt), "%s%s", scmadmUsage, f__); \
13697836SJohn.Forte@Sun.COM (void) snprintf(scmadmUsage, sizeof (scmadmUsage), fmt, a__);
13707836SJohn.Forte@Sun.COM
13717836SJohn.Forte@Sun.COM #define addusage2(f__, a__, b__) \
13727836SJohn.Forte@Sun.COM (void) snprintf(fmt, sizeof (fmt), "%s%s", scmadmUsage, f__); \
13737836SJohn.Forte@Sun.COM (void) snprintf(scmadmUsage, sizeof (scmadmUsage), fmt, a__, b__);
13747836SJohn.Forte@Sun.COM
13757836SJohn.Forte@Sun.COM static void
buildusage(char * p)13767836SJohn.Forte@Sun.COM buildusage(char *p)
13777836SJohn.Forte@Sun.COM {
13787836SJohn.Forte@Sun.COM char fmt[USAGELEN];
13797836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
13807836SJohn.Forte@Sun.COM char *hints_str = "[nordcache|rdcache|wrthru|nowrthru|forget]\n";
13817836SJohn.Forte@Sun.COM #else
13827836SJohn.Forte@Sun.COM char *hints_str = "[nordcache|rdcache|forget]\n";
13837836SJohn.Forte@Sun.COM #endif
13847836SJohn.Forte@Sun.COM
13857836SJohn.Forte@Sun.COM bzero(scmadmUsage, sizeof (scmadmUsage));
13867836SJohn.Forte@Sun.COM bzero(fmt, sizeof (fmt));
13877836SJohn.Forte@Sun.COM
13887836SJohn.Forte@Sun.COM addusage(gettext("Usage :\n"));
13897836SJohn.Forte@Sun.COM addusage1(gettext("\t%s\n"), p);
13907836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -h\n"), p);
13917836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -e\n"), p);
13927836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -d\n"), p);
13937836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -v\n"), p);
13947836SJohn.Forte@Sun.COM addusage1(gettext("\t%s {-L | -D bitmapfs}\n"), p);
13957836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -C [parameter[=[value]] ...]\n"), p);
13967836SJohn.Forte@Sun.COM addusage2(gettext("\t%s -o system %s"), p, hints_str);
13977836SJohn.Forte@Sun.COM addusage2(gettext("\t%s -o <cd> %s"), p, hints_str);
13987836SJohn.Forte@Sun.COM addusage2(gettext("\t%s -o <diskname> %s"), p, hints_str);
13997836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -m {<cd>|<diskname>|all}\n"), p);
14007836SJohn.Forte@Sun.COM #ifdef DEBUG
14017836SJohn.Forte@Sun.COM addusage1(gettext(
14027836SJohn.Forte@Sun.COM "\t%s -S [-Mz] [-d delay_time] [-l logfile] [-r range]\n"), p);
14037836SJohn.Forte@Sun.COM addusage1(gettext(
14047836SJohn.Forte@Sun.COM "\t%s -t {size|mask|lbolt|good} <cd|diskname> <value>\n"), p);
14057836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -g\n"), p);
14067836SJohn.Forte@Sun.COM addusage1(gettext(
14077836SJohn.Forte@Sun.COM "\t%s -i {cd|diskname|-1 for all} [errno [countdown]]\n"), p);
14087836SJohn.Forte@Sun.COM addusage1(gettext("\t%s -c {cd|diskname|-1 for all}\n"), p);
14097836SJohn.Forte@Sun.COM addusage(gettext("\nt = trace\tg = toggle_flush\ti = inject ioerr\n"
14107836SJohn.Forte@Sun.COM "c = clear ioerr\tS = stats\n"));
14117836SJohn.Forte@Sun.COM #endif /* DEBUG */
14127836SJohn.Forte@Sun.COM addusage(gettext(
14137836SJohn.Forte@Sun.COM "e = enable\td = disable\tv=version\to = get/ set options\n"));
14147836SJohn.Forte@Sun.COM addusage(gettext(
14157836SJohn.Forte@Sun.COM "m = get cd map\n"));
14167836SJohn.Forte@Sun.COM addusage1(gettext(
14177836SJohn.Forte@Sun.COM "note: cd is a cache descriptor integer in the range [0-%d]\n"),
14187836SJohn.Forte@Sun.COM sdbc_max_devices - 1);
14197836SJohn.Forte@Sun.COM addusage(gettext(
14207836SJohn.Forte@Sun.COM " bitmapfs is a block device or filesystem mount point\n"));
14217836SJohn.Forte@Sun.COM
14227836SJohn.Forte@Sun.COM #ifdef DEBUG
14237836SJohn.Forte@Sun.COM (void) snprintf(stats_usage, sizeof (stats_usage),
14247836SJohn.Forte@Sun.COM "SD_STATS_USAGE=%s", scmadmUsage);
14257836SJohn.Forte@Sun.COM #endif
14267836SJohn.Forte@Sun.COM }
14277836SJohn.Forte@Sun.COM
14287836SJohn.Forte@Sun.COM static int
get_hint(char * str,int * hint,int * flag)14297836SJohn.Forte@Sun.COM get_hint(char *str, int *hint, int *flag)
14307836SJohn.Forte@Sun.COM {
14317836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
14327836SJohn.Forte@Sun.COM if (!(strcoll(str, gettext("wrthru")))) {
14337836SJohn.Forte@Sun.COM *hint = NSC_WRTHRU;
14347836SJohn.Forte@Sun.COM *flag = 1;
14357836SJohn.Forte@Sun.COM return (0);
14367836SJohn.Forte@Sun.COM } else if (!(strcoll(str, gettext("nowrthru")))) {
14377836SJohn.Forte@Sun.COM *hint = NSC_WRTHRU;
14387836SJohn.Forte@Sun.COM *flag = 0;
14397836SJohn.Forte@Sun.COM return (0);
14407836SJohn.Forte@Sun.COM } else
14417836SJohn.Forte@Sun.COM #endif
14427836SJohn.Forte@Sun.COM if (!(strcoll(str, gettext("nordcache")))) {
14437836SJohn.Forte@Sun.COM *hint = NSC_NOCACHE;
14447836SJohn.Forte@Sun.COM *flag = 1;
14457836SJohn.Forte@Sun.COM return (0);
14467836SJohn.Forte@Sun.COM } else if (!(strcoll(str, gettext("rdcache")))) {
14477836SJohn.Forte@Sun.COM *hint = NSC_NOCACHE;
14487836SJohn.Forte@Sun.COM *flag = 0;
14497836SJohn.Forte@Sun.COM return (0);
14507836SJohn.Forte@Sun.COM } else if (!(strcoll(str, gettext("forget")))) {
14517836SJohn.Forte@Sun.COM *hint = -1;
14527836SJohn.Forte@Sun.COM *flag = 0;
14537836SJohn.Forte@Sun.COM return (0);
14547836SJohn.Forte@Sun.COM }
14557836SJohn.Forte@Sun.COM return (-1);
14567836SJohn.Forte@Sun.COM }
14577836SJohn.Forte@Sun.COM
14587836SJohn.Forte@Sun.COM /*ARGSUSED*/
14597836SJohn.Forte@Sun.COM void
print_hint(const uint_t type,const int status)14607836SJohn.Forte@Sun.COM print_hint(const uint_t type, const int status)
14617836SJohn.Forte@Sun.COM {
14627836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
14637836SJohn.Forte@Sun.COM if (status) {
14647836SJohn.Forte@Sun.COM if (type & NSC_FORCED_WRTHRU) {
14657836SJohn.Forte@Sun.COM (void) printf(gettext("Fast Writes Overridden\n"));
14667836SJohn.Forte@Sun.COM } else {
14677836SJohn.Forte@Sun.COM /* if (type & NSC_NO_FORCED_WRTHRU) */
14687836SJohn.Forte@Sun.COM (void) printf(gettext("default\n"));
14697836SJohn.Forte@Sun.COM }
14707836SJohn.Forte@Sun.COM } else {
14717836SJohn.Forte@Sun.COM (void) printf("%swrthru, %srdcache",
14727836SJohn.Forte@Sun.COM (type & (NSC_FORCED_WRTHRU|NSC_WRTHRU)) ? "" : "no",
14737836SJohn.Forte@Sun.COM (type & NSC_NOCACHE) ? "no" : "");
14747836SJohn.Forte@Sun.COM #else
14757836SJohn.Forte@Sun.COM {
14767836SJohn.Forte@Sun.COM (void) printf("%srdcache", (type & NSC_NOCACHE) ? "no" : "");
14777836SJohn.Forte@Sun.COM #endif
14787836SJohn.Forte@Sun.COM
14797836SJohn.Forte@Sun.COM if (type & 0x80000000)
14807836SJohn.Forte@Sun.COM (void) printf(" (overridden by system)");
14817836SJohn.Forte@Sun.COM
14827836SJohn.Forte@Sun.COM (void) printf("\n");
14837836SJohn.Forte@Sun.COM }
14847836SJohn.Forte@Sun.COM }
14857836SJohn.Forte@Sun.COM
14867836SJohn.Forte@Sun.COM /*
14877836SJohn.Forte@Sun.COM * Read the configuration via libcfg
14887836SJohn.Forte@Sun.COM */
14897836SJohn.Forte@Sun.COM
14907836SJohn.Forte@Sun.COM int
14917836SJohn.Forte@Sun.COM get_cache_config()
14927836SJohn.Forte@Sun.COM {
14937836SJohn.Forte@Sun.COM int i;
14947836SJohn.Forte@Sun.COM int sysid;
14957836SJohn.Forte@Sun.COM CFGFILE *cfg;
14967836SJohn.Forte@Sun.COM char buf[CFG_MAX_BUF];
14977836SJohn.Forte@Sun.COM char key[CFG_MAX_KEY];
14987836SJohn.Forte@Sun.COM
14997836SJohn.Forte@Sun.COM
15007836SJohn.Forte@Sun.COM if ((cfg = cfg_open(NULL)) == NULL) {
15017836SJohn.Forte@Sun.COM (void) fprintf(stderr,
15027836SJohn.Forte@Sun.COM gettext("Cannot open configuration file\n"));
15037836SJohn.Forte@Sun.COM exit(1);
15047836SJohn.Forte@Sun.COM }
15057836SJohn.Forte@Sun.COM
15067836SJohn.Forte@Sun.COM if (!cfg_lock(cfg, CFG_RDLOCK)) {
15077836SJohn.Forte@Sun.COM (void) fprintf(stderr,
15087836SJohn.Forte@Sun.COM gettext("Cannot lock configuration file\n"));
15097836SJohn.Forte@Sun.COM exit(1);
15107836SJohn.Forte@Sun.COM }
15117836SJohn.Forte@Sun.COM
15127836SJohn.Forte@Sun.COM convert_config(cfg, CFG_RDLOCK);
15137836SJohn.Forte@Sun.COM (void) memset((char *)&user_level_conf, 0, sizeof (_sd_cache_param_t));
15147836SJohn.Forte@Sun.COM
15157836SJohn.Forte@Sun.COM /* Get the system ID */
15167836SJohn.Forte@Sun.COM if (nsc_getsystemid(&sysid) < 0) {
15177836SJohn.Forte@Sun.COM (void) fprintf(stderr,
15187836SJohn.Forte@Sun.COM gettext("%s Unable to obtain subsystem ID: %s\n"),
15197836SJohn.Forte@Sun.COM progname, strerror(errno));
15207836SJohn.Forte@Sun.COM exit(1);
15217836SJohn.Forte@Sun.COM }
15227836SJohn.Forte@Sun.COM myid = sysid;
15237836SJohn.Forte@Sun.COM
15247836SJohn.Forte@Sun.COM user_level_conf.blk_size = 8192; /* DEFAULT */
15257836SJohn.Forte@Sun.COM user_level_conf.procs = 16; /* DEFAULT */
15267836SJohn.Forte@Sun.COM user_level_conf.reserved1 = RESERVED1_DEFAULTS;
15277836SJohn.Forte@Sun.COM
15287836SJohn.Forte@Sun.COM bzero(buf, CFG_MAX_BUF);
15297836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.thread");
15307836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15317836SJohn.Forte@Sun.COM user_level_conf.threads = atoi(buf);
15327836SJohn.Forte@Sun.COM } else
15337836SJohn.Forte@Sun.COM user_level_conf.threads = 128; /* DEFAULT */
15347836SJohn.Forte@Sun.COM
15357836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.tdemons");
15367836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15377836SJohn.Forte@Sun.COM user_level_conf.test_demons = atoi(buf);
15387836SJohn.Forte@Sun.COM }
15397836SJohn.Forte@Sun.COM
15407836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.write_cache");
15417836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15427836SJohn.Forte@Sun.COM user_level_conf.write_cache = atoi(buf);
15437836SJohn.Forte@Sun.COM }
15447836SJohn.Forte@Sun.COM
15457836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.size");
15467836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15477836SJohn.Forte@Sun.COM /*
15487836SJohn.Forte@Sun.COM * We need to run strtol for backwards compatibility in 3.2.
15497836SJohn.Forte@Sun.COM * A workaround for this bug was put in 3.2 which allowed
15507836SJohn.Forte@Sun.COM * customers to set the cache size up to 1024 if it was
15517836SJohn.Forte@Sun.COM * specified in hexadecimal. Decimal still had the limit
15527836SJohn.Forte@Sun.COM * of 128. This change treats them both identically.
15537836SJohn.Forte@Sun.COM */
15547836SJohn.Forte@Sun.COM user_level_conf.cache_mem[0] = (int)strtol(buf, NULL, 0);
15557836SJohn.Forte@Sun.COM if (user_level_conf.cache_mem[0] > MAX_CACHE_SIZE) {
15567836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext(
15577836SJohn.Forte@Sun.COM "The cache size of %ld is larger than "
15587836SJohn.Forte@Sun.COM "the system maximum of %ld.\nUse \"scmadm -C "
15597836SJohn.Forte@Sun.COM "cache_size=<size>\" to set the size to a proper "
15607836SJohn.Forte@Sun.COM "value.\n"),
15617836SJohn.Forte@Sun.COM user_level_conf.cache_mem[0], MAX_CACHE_SIZE);
15627836SJohn.Forte@Sun.COM user_level_conf.cache_mem[0] = MAX_CACHE_SIZE;
15637836SJohn.Forte@Sun.COM }
15647836SJohn.Forte@Sun.COM }
15657836SJohn.Forte@Sun.COM
15667836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.iobuf");
15677836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15687836SJohn.Forte@Sun.COM user_level_conf.iobuf = atoi(buf);
15697836SJohn.Forte@Sun.COM }
15707836SJohn.Forte@Sun.COM
15717836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.fill_pattern");
15727836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15737836SJohn.Forte@Sun.COM user_level_conf.fill_pattern = atoi(buf);
15747836SJohn.Forte@Sun.COM user_level_conf.gen_pattern = 1;
15757836SJohn.Forte@Sun.COM }
15767836SJohn.Forte@Sun.COM
15777836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.no_forced_wrthru");
15787836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15797836SJohn.Forte@Sun.COM no_forced_wrthru = atoi(buf);
15807836SJohn.Forte@Sun.COM }
15817836SJohn.Forte@Sun.COM
15827836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.forced_wrthru");
15837836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15847836SJohn.Forte@Sun.COM forced_wrthru = atoi(buf);
15857836SJohn.Forte@Sun.COM }
15867836SJohn.Forte@Sun.COM
15877836SJohn.Forte@Sun.COM (void) snprintf(key, sizeof (key), "scm.set1.reserved1");
15887836SJohn.Forte@Sun.COM if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) {
15897836SJohn.Forte@Sun.COM user_level_conf.reserved1 = atoi(buf);
15907836SJohn.Forte@Sun.COM }
15917836SJohn.Forte@Sun.COM
15927836SJohn.Forte@Sun.COM cfg_close(cfg);
15937836SJohn.Forte@Sun.COM
15947836SJohn.Forte@Sun.COM /*
15957836SJohn.Forte@Sun.COM * use the default minidsp configuration if no
15967836SJohn.Forte@Sun.COM * node/mirror/remote-mirror/cluster line is in the sd.cf file
15977836SJohn.Forte@Sun.COM */
15987836SJohn.Forte@Sun.COM if (nodes_configured == 0)
15997836SJohn.Forte@Sun.COM check_and_set_mirrors(myid, _SD_NO_HOST);
16007836SJohn.Forte@Sun.COM
16017836SJohn.Forte@Sun.COM
16027836SJohn.Forte@Sun.COM /* Check if our sysid was defined */
16037836SJohn.Forte@Sun.COM if (!node_defined[myid]) {
16047836SJohn.Forte@Sun.COM (void) fprintf(stderr,
16057836SJohn.Forte@Sun.COM gettext("This node(%d) is not defined in config.\n"), myid);
16067836SJohn.Forte@Sun.COM exit(1);
16077836SJohn.Forte@Sun.COM }
16087836SJohn.Forte@Sun.COM
16097836SJohn.Forte@Sun.COM /*
16107836SJohn.Forte@Sun.COM * Save off number of nodes so we can calculate the point-to-point
16117836SJohn.Forte@Sun.COM * segements. Code in kernel currently supports MAX_SD_NODES
16127836SJohn.Forte@Sun.COM */
16137836SJohn.Forte@Sun.COM if ((user_level_conf.num_nodes = nodes_configured) >
16147836SJohn.Forte@Sun.COM MAX_SD_NODES) {
16157836SJohn.Forte@Sun.COM (void) fprintf(stderr,
16167836SJohn.Forte@Sun.COM gettext("Cache can support only %d nodes(%d).\n"),
16177836SJohn.Forte@Sun.COM MAX_SD_NODES, nodes_configured);
16187836SJohn.Forte@Sun.COM exit(1);
16197836SJohn.Forte@Sun.COM }
16207836SJohn.Forte@Sun.COM
16217836SJohn.Forte@Sun.COM if ((nodes_configured % 2) && !minidsp) {
16227836SJohn.Forte@Sun.COM if (nodes_configured == 1)
16237836SJohn.Forte@Sun.COM (void) fprintf(stderr,
16247836SJohn.Forte@Sun.COM gettext("Only one node configured, "
16257836SJohn.Forte@Sun.COM "mirror node must be %d\n"), _SD_NO_HOST);
16267836SJohn.Forte@Sun.COM else
16277836SJohn.Forte@Sun.COM (void) fprintf(stderr,
16287836SJohn.Forte@Sun.COM gettext("Cannot configure odd number of nodes.\n"));
16297836SJohn.Forte@Sun.COM exit(1);
16307836SJohn.Forte@Sun.COM }
16317836SJohn.Forte@Sun.COM
16327836SJohn.Forte@Sun.COM
16337836SJohn.Forte@Sun.COM /* Pass List of Nodes Configured to Cache */
16347836SJohn.Forte@Sun.COM for (i = 0; i < nodes_configured; i++)
16357836SJohn.Forte@Sun.COM user_level_conf.nodes_conf[i] = nodes_conf[i];
16367836SJohn.Forte@Sun.COM
16377836SJohn.Forte@Sun.COM /* Place magic number in user_level_conf. Kernel will test for it */
16387836SJohn.Forte@Sun.COM user_level_conf.magic = _SD_MAGIC;
16397836SJohn.Forte@Sun.COM (void) sleep(1);
16407836SJohn.Forte@Sun.COM return (0);
16417836SJohn.Forte@Sun.COM }
16427836SJohn.Forte@Sun.COM
16437836SJohn.Forte@Sun.COM _sdtr_t hdr;
16447836SJohn.Forte@Sun.COM
16457836SJohn.Forte@Sun.COM /* function name string */
16467836SJohn.Forte@Sun.COM char *
16477836SJohn.Forte@Sun.COM _sd_fname(int f)
16487836SJohn.Forte@Sun.COM {
16497836SJohn.Forte@Sun.COM int fn = f & ST_FUNC;
16507836SJohn.Forte@Sun.COM static char c[8];
16517836SJohn.Forte@Sun.COM char *s;
16527836SJohn.Forte@Sun.COM
16537836SJohn.Forte@Sun.COM if (f & ST_BCACHE)
16547836SJohn.Forte@Sun.COM s = _bcache_fname[fn];
16557836SJohn.Forte@Sun.COM else if (f & ST_BSUB)
16567836SJohn.Forte@Sun.COM s = _bsub_fname[fn];
16577836SJohn.Forte@Sun.COM else if (f & ST_IO)
16587836SJohn.Forte@Sun.COM s = _io_fname[fn];
16597836SJohn.Forte@Sun.COM else if (f & ST_STATS)
16607836SJohn.Forte@Sun.COM s = _stats_fname[fn];
16617836SJohn.Forte@Sun.COM else if (f & ST_CCIO)
16627836SJohn.Forte@Sun.COM s = _ccio_fname[fn];
16637836SJohn.Forte@Sun.COM else if (f & ST_FT)
16647836SJohn.Forte@Sun.COM s = _ft_fname[fn];
16657836SJohn.Forte@Sun.COM else if (f & ST_INFO)
16667836SJohn.Forte@Sun.COM s = _info_fname[fn];
16677836SJohn.Forte@Sun.COM if (!s)
16687836SJohn.Forte@Sun.COM (void) sprintf(s = c, "0x%04x", f & 0xffff);
16697836SJohn.Forte@Sun.COM return (s);
16707836SJohn.Forte@Sun.COM }
16717836SJohn.Forte@Sun.COM
16727836SJohn.Forte@Sun.COM int alerts = 0;
16737836SJohn.Forte@Sun.COM
16747836SJohn.Forte@Sun.COM /*
16757836SJohn.Forte@Sun.COM * Background daemon to wait for alert (on any device)
16767836SJohn.Forte@Sun.COM * Writes the traces to "sd_alert.CD.NUM",
16777836SJohn.Forte@Sun.COM * and writes an information message to the alert_file.
16787836SJohn.Forte@Sun.COM */
16797836SJohn.Forte@Sun.COM
16807836SJohn.Forte@Sun.COM void
16817836SJohn.Forte@Sun.COM sd_gather_alert_dumps()
16827836SJohn.Forte@Sun.COM {
16837836SJohn.Forte@Sun.COM _sdtr_table_t tt;
16847836SJohn.Forte@Sun.COM _sdtr_t *buf;
16857836SJohn.Forte@Sun.COM int cd, count, size, flag;
16867836SJohn.Forte@Sun.COM char filename[64];
16877836SJohn.Forte@Sun.COM int fd;
16887836SJohn.Forte@Sun.COM time_t tloc;
16897836SJohn.Forte@Sun.COM struct tm tm_storage;
16907836SJohn.Forte@Sun.COM struct tm *tm_ptr;
16917836SJohn.Forte@Sun.COM char timebuf[80];
16927836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
16937836SJohn.Forte@Sun.COM
16947836SJohn.Forte@Sun.COM /* fork and detach daemon */
16957836SJohn.Forte@Sun.COM if (fork())
16967836SJohn.Forte@Sun.COM exit(0);
16977836SJohn.Forte@Sun.COM (void) close(0);
16987836SJohn.Forte@Sun.COM fd = open(alert_file, O_WRONLY|O_APPEND|O_CREAT, 0644);
16997836SJohn.Forte@Sun.COM if (fd == -1)
17007836SJohn.Forte@Sun.COM fd = open("/dev/console", O_WRONLY);
17017836SJohn.Forte@Sun.COM if (fd != -1) {
17027836SJohn.Forte@Sun.COM (void) dup2(fd, 1);
17037836SJohn.Forte@Sun.COM (void) dup2(fd, 2);
17047836SJohn.Forte@Sun.COM (void) close(fd);
17057836SJohn.Forte@Sun.COM }
17067836SJohn.Forte@Sun.COM (void) setsid();
17077836SJohn.Forte@Sun.COM
17087836SJohn.Forte@Sun.COM size = 10000;
17097836SJohn.Forte@Sun.COM if (size < user_level_conf.trace_size)
17107836SJohn.Forte@Sun.COM size = user_level_conf.trace_size;
17117836SJohn.Forte@Sun.COM
17127836SJohn.Forte@Sun.COM buf = (_sdtr_t *)malloc(size * sizeof (_sdtr_t));
17137836SJohn.Forte@Sun.COM if (!buf) {
17147836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s malloc: %s\n"),
17157836SJohn.Forte@Sun.COM progname, strerror(errno));
17167836SJohn.Forte@Sun.COM exit(1);
17177836SJohn.Forte@Sun.COM }
17187836SJohn.Forte@Sun.COM tloc = time(NULL);
17197836SJohn.Forte@Sun.COM tm_ptr = (struct tm *)localtime_r(&tloc, &tm_storage);
17207836SJohn.Forte@Sun.COM
17217836SJohn.Forte@Sun.COM loop:
17227836SJohn.Forte@Sun.COM cd = SDT_ANY_CD; /* any device */
17237836SJohn.Forte@Sun.COM flag = SD_ALERT_WAIT; /* block for alert */
17247836SJohn.Forte@Sun.COM if ((count = SDBC_IOCTL(SDBC_ADUMP, cd, &tt, buf, size,
1725*11576SSurya.Prakki@Sun.COM flag, &ustats)) == SPCS_S_ERROR) {
17267836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: sd_adump\n"), progname);
17277836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
17287836SJohn.Forte@Sun.COM if (errno == EIDRM) {
17297836SJohn.Forte@Sun.COM (void) strftime(timebuf, 80, "%x %X", tm_ptr);
17307836SJohn.Forte@Sun.COM (void) fprintf(stderr,
17317836SJohn.Forte@Sun.COM gettext("%s: cache deconfigured at %s\n"),
17327836SJohn.Forte@Sun.COM progname, timebuf);
17337836SJohn.Forte@Sun.COM exit(0);
17347836SJohn.Forte@Sun.COM }
17357836SJohn.Forte@Sun.COM if (errno == ENOSYS)
17367836SJohn.Forte@Sun.COM exit(0);
17377836SJohn.Forte@Sun.COM exit(errno);
17387836SJohn.Forte@Sun.COM }
17397836SJohn.Forte@Sun.COM if (count == 0)
17407836SJohn.Forte@Sun.COM goto loop;
17417836SJohn.Forte@Sun.COM cd = tt.tt_cd;
17427836SJohn.Forte@Sun.COM (void) sprintf(filename, "%s.%d.%d", "sd_alert", cd, alerts++);
17437836SJohn.Forte@Sun.COM if ((fd = open(filename, O_CREAT | O_RDWR, 0444)) == -1) {
17447836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: open: %s\n"),
17457836SJohn.Forte@Sun.COM progname, strerror(errno));
17467836SJohn.Forte@Sun.COM exit(errno);
17477836SJohn.Forte@Sun.COM }
17487836SJohn.Forte@Sun.COM /*
17497836SJohn.Forte@Sun.COM * write header to identify device, write entries
17507836SJohn.Forte@Sun.COM */
17517836SJohn.Forte@Sun.COM hdr.t_func = SDF_CD;
17527836SJohn.Forte@Sun.COM hdr.t_len = count;
17537836SJohn.Forte@Sun.COM hdr.t_ret = tt.tt_cd;
17547836SJohn.Forte@Sun.COM if (write(fd, &hdr, sizeof (_sdtr_t)) == -1) {
17557836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: write: %s\n"),
17567836SJohn.Forte@Sun.COM progname, strerror(errno));
17577836SJohn.Forte@Sun.COM exit(errno);
17587836SJohn.Forte@Sun.COM }
17597836SJohn.Forte@Sun.COM
17607836SJohn.Forte@Sun.COM if (write(fd, buf, sizeof (_sdtr_t)*count) == -1) {
17617836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: write: %s\n"),
17627836SJohn.Forte@Sun.COM progname, strerror(errno));
17637836SJohn.Forte@Sun.COM exit(errno);
17647836SJohn.Forte@Sun.COM }
17657836SJohn.Forte@Sun.COM (void) close(fd);
17667836SJohn.Forte@Sun.COM
17677836SJohn.Forte@Sun.COM (void) strftime(timebuf, 80, "%x %X", tm_ptr);
17687836SJohn.Forte@Sun.COM (void) printf("sd alert trace dump %s at %s\n", filename, timebuf);
17697836SJohn.Forte@Sun.COM goto loop;
17707836SJohn.Forte@Sun.COM }
17717836SJohn.Forte@Sun.COM
17727836SJohn.Forte@Sun.COM
17737836SJohn.Forte@Sun.COM
17747836SJohn.Forte@Sun.COM /*
17757836SJohn.Forte@Sun.COM * print list of configured cd's, diskname, options and global options
17767836SJohn.Forte@Sun.COM */
17777836SJohn.Forte@Sun.COM void
17787836SJohn.Forte@Sun.COM print_all_options()
17797836SJohn.Forte@Sun.COM {
17807836SJohn.Forte@Sun.COM static _sd_stats_t *cs_cur;
17817836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
17827836SJohn.Forte@Sun.COM int cd;
17837836SJohn.Forte@Sun.COM int hint;
17847836SJohn.Forte@Sun.COM char *s1 = "device name";
17857836SJohn.Forte@Sun.COM char *s2 = "option";
17867836SJohn.Forte@Sun.COM char fn[19];
17877836SJohn.Forte@Sun.COM int len;
17887836SJohn.Forte@Sun.COM
17897836SJohn.Forte@Sun.COM /* No corresponding free because this function exits */
17907836SJohn.Forte@Sun.COM cs_cur = malloc(sizeof (_sd_stats_t) +
17917836SJohn.Forte@Sun.COM (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
17927836SJohn.Forte@Sun.COM if (cs_cur == NULL) {
17937836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s malloc: %s\n"),
17947836SJohn.Forte@Sun.COM progname, strerror(errno));
17957836SJohn.Forte@Sun.COM exit(1);
17967836SJohn.Forte@Sun.COM }
17977836SJohn.Forte@Sun.COM
17987836SJohn.Forte@Sun.COM /* node hints */
17997836SJohn.Forte@Sun.COM if ((hint = SDBC_IOCTL(SDBC_GET_NODE_HINT, 0, 0, 0, 0, 0,
18007836SJohn.Forte@Sun.COM &ustats)) == SPCS_S_ERROR) {
18017836SJohn.Forte@Sun.COM (void) fprintf(stderr,
18027836SJohn.Forte@Sun.COM gettext("%s: get system option failed\n"),
18037836SJohn.Forte@Sun.COM progname);
18047836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
18057836SJohn.Forte@Sun.COM exit(1);
18067836SJohn.Forte@Sun.COM }
18077836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
18087836SJohn.Forte@Sun.COM (void) printf(gettext("System Status: "));
18097836SJohn.Forte@Sun.COM print_hint(hint, 1);
18107836SJohn.Forte@Sun.COM #endif
18117836SJohn.Forte@Sun.COM (void) printf(gettext("System Options: "));
18127836SJohn.Forte@Sun.COM print_hint(hint, 0);
18137836SJohn.Forte@Sun.COM
18147836SJohn.Forte@Sun.COM /* get cds */
18157836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats)
18167836SJohn.Forte@Sun.COM == SPCS_S_ERROR) {
18177836SJohn.Forte@Sun.COM (void) fprintf(stderr,
18187836SJohn.Forte@Sun.COM gettext("%s: get_cd failed in print_all options\n"),
18197836SJohn.Forte@Sun.COM progname);
18207836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
18217836SJohn.Forte@Sun.COM exit(1);
18227836SJohn.Forte@Sun.COM }
18237836SJohn.Forte@Sun.COM if (cs_cur->st_cachesize == 0)
18247836SJohn.Forte@Sun.COM (void) printf(gettext("Cache is disabled\n"));
18257836SJohn.Forte@Sun.COM else if (cs_cur->st_count == 0)
18267836SJohn.Forte@Sun.COM (void) printf(gettext("No devices are configured\n"));
18277836SJohn.Forte@Sun.COM else {
18287836SJohn.Forte@Sun.COM (void) printf(
18297836SJohn.Forte@Sun.COM gettext("\nConfigured cd's, disknames and options: \n"));
18307836SJohn.Forte@Sun.COM (void) printf(gettext("cd\t%-28s\t%-20s\n"), s1, s2);
18317836SJohn.Forte@Sun.COM for (cd = 0; cd < cs_cur->st_count; cd++) {
18327836SJohn.Forte@Sun.COM if (cs_cur->st_shared[cd].sh_alloc) {
18337836SJohn.Forte@Sun.COM hint = get_cd_hint(cd);
18347836SJohn.Forte@Sun.COM if ((len =
18357836SJohn.Forte@Sun.COM strlen(cs_cur->st_shared[cd].sh_filename))
18367836SJohn.Forte@Sun.COM > 23) {
1837*11576SSurya.Prakki@Sun.COM (void) strcpy(fn, "...");
1838*11576SSurya.Prakki@Sun.COM (void) strcat(fn,
18397836SJohn.Forte@Sun.COM cs_cur->st_shared[cd].sh_filename +
18407836SJohn.Forte@Sun.COM len - 20);
18417836SJohn.Forte@Sun.COM } else {
1842*11576SSurya.Prakki@Sun.COM (void) strcpy(fn,
18437836SJohn.Forte@Sun.COM cs_cur->st_shared[cd].sh_filename);
18447836SJohn.Forte@Sun.COM }
18457836SJohn.Forte@Sun.COM
18467836SJohn.Forte@Sun.COM (void) printf(gettext("%d\t%-28.*s\t"), cd,
18477836SJohn.Forte@Sun.COM NSC_MAXPATH, fn);
18487836SJohn.Forte@Sun.COM
18497836SJohn.Forte@Sun.COM print_hint(hint, 0);
18507836SJohn.Forte@Sun.COM }
18517836SJohn.Forte@Sun.COM }
18527836SJohn.Forte@Sun.COM }
18537836SJohn.Forte@Sun.COM exit(0);
18547836SJohn.Forte@Sun.COM }
18557836SJohn.Forte@Sun.COM
18567836SJohn.Forte@Sun.COM
18577836SJohn.Forte@Sun.COM /*
18587836SJohn.Forte@Sun.COM * cache device -- lookup names and cache descriptors of all configured devices
18597836SJohn.Forte@Sun.COM */
18607836SJohn.Forte@Sun.COM void
18617836SJohn.Forte@Sun.COM get_cd_all()
18627836SJohn.Forte@Sun.COM {
18637836SJohn.Forte@Sun.COM static _sd_stats_t *cs_cur;
18647836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
18657836SJohn.Forte@Sun.COM int cd;
18667836SJohn.Forte@Sun.COM char fn[19];
18677836SJohn.Forte@Sun.COM int len;
18687836SJohn.Forte@Sun.COM
18697836SJohn.Forte@Sun.COM /* No corresponding free because this function exits */
18707836SJohn.Forte@Sun.COM cs_cur = malloc(sizeof (_sd_stats_t) +
18717836SJohn.Forte@Sun.COM (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
18727836SJohn.Forte@Sun.COM if (cs_cur == NULL) {
18737836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s malloc: %s\n"),
18747836SJohn.Forte@Sun.COM progname, strerror(errno));
18757836SJohn.Forte@Sun.COM exit(1);
18767836SJohn.Forte@Sun.COM }
18777836SJohn.Forte@Sun.COM
18787836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats)
18797836SJohn.Forte@Sun.COM == SPCS_S_ERROR) {
18807836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: get_cd_all"),
18817836SJohn.Forte@Sun.COM progname);
18827836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
18837836SJohn.Forte@Sun.COM exit(1);
18847836SJohn.Forte@Sun.COM }
18857836SJohn.Forte@Sun.COM if (cs_cur->st_cachesize == 0)
18867836SJohn.Forte@Sun.COM (void) printf(gettext("Cache is disabled\n"));
18877836SJohn.Forte@Sun.COM else if (cs_cur->st_count == 0)
18887836SJohn.Forte@Sun.COM (void) printf(gettext("No devices are configured\n"));
18897836SJohn.Forte@Sun.COM else {
18907836SJohn.Forte@Sun.COM (void) printf(gettext("\tcd\tdevice name\n"));
18917836SJohn.Forte@Sun.COM for (cd = 0; cd < cs_cur->st_count; cd++) {
18927836SJohn.Forte@Sun.COM if (cs_cur->st_shared[cd].sh_alloc) {
18937836SJohn.Forte@Sun.COM if ((len = strlen(
18947836SJohn.Forte@Sun.COM cs_cur->st_shared[cd].sh_filename)) > 15) {
1895*11576SSurya.Prakki@Sun.COM (void) strcpy(fn, "...");
1896*11576SSurya.Prakki@Sun.COM (void) strcat(fn,
18977836SJohn.Forte@Sun.COM cs_cur->st_shared[cd].sh_filename +
18987836SJohn.Forte@Sun.COM len - 12);
18997836SJohn.Forte@Sun.COM } else {
1900*11576SSurya.Prakki@Sun.COM (void) strcpy(fn,
19017836SJohn.Forte@Sun.COM cs_cur->st_shared[cd].sh_filename);
19027836SJohn.Forte@Sun.COM }
19037836SJohn.Forte@Sun.COM (void) printf(gettext("\t%d\t%s\n"),
19047836SJohn.Forte@Sun.COM cd, fn);
19057836SJohn.Forte@Sun.COM }
19067836SJohn.Forte@Sun.COM }
19077836SJohn.Forte@Sun.COM }
19087836SJohn.Forte@Sun.COM exit(0);
19097836SJohn.Forte@Sun.COM }
19107836SJohn.Forte@Sun.COM
19117836SJohn.Forte@Sun.COM /*
19127836SJohn.Forte@Sun.COM * cache device -- specified by number or lookup name
19137836SJohn.Forte@Sun.COM */
19147836SJohn.Forte@Sun.COM static int
19157836SJohn.Forte@Sun.COM get_cd(char *s)
19167836SJohn.Forte@Sun.COM {
19177836SJohn.Forte@Sun.COM static _sd_stats_t *cs_cur = NULL;
19187836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
19197836SJohn.Forte@Sun.COM int cd, arg_cd = -1;
19207836SJohn.Forte@Sun.COM
19217836SJohn.Forte@Sun.COM if (cs_cur == NULL) {
19227836SJohn.Forte@Sun.COM /*
19237836SJohn.Forte@Sun.COM * No corresponding free because the memory is reused
19247836SJohn.Forte@Sun.COM * every time the function is called.
19257836SJohn.Forte@Sun.COM */
19267836SJohn.Forte@Sun.COM cs_cur = malloc(sizeof (_sd_stats_t) +
19277836SJohn.Forte@Sun.COM (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
19287836SJohn.Forte@Sun.COM if (cs_cur == NULL) {
19297836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s malloc: %s\n"),
19307836SJohn.Forte@Sun.COM progname, strerror(errno));
19317836SJohn.Forte@Sun.COM exit(1);
19327836SJohn.Forte@Sun.COM }
19337836SJohn.Forte@Sun.COM }
19347836SJohn.Forte@Sun.COM
19357836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats)
19367836SJohn.Forte@Sun.COM == SPCS_S_ERROR) {
19377836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: get_cd\n"), progname);
19387836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
19397836SJohn.Forte@Sun.COM exit(1);
19407836SJohn.Forte@Sun.COM }
19417836SJohn.Forte@Sun.COM if (cs_cur->st_cachesize == 0) {
19427836SJohn.Forte@Sun.COM (void) printf(gettext("Cache is disabled\n"));
19437836SJohn.Forte@Sun.COM exit(0);
19447836SJohn.Forte@Sun.COM }
19457836SJohn.Forte@Sun.COM
19467836SJohn.Forte@Sun.COM if (*s != '/') {
19477836SJohn.Forte@Sun.COM /*
19487836SJohn.Forte@Sun.COM * Since strtol returns 0 on failure, we need to make a
19497836SJohn.Forte@Sun.COM * special case for a cd of "0", which is valid.
19507836SJohn.Forte@Sun.COM *
19517836SJohn.Forte@Sun.COM * This case also deals with the difference between
19527836SJohn.Forte@Sun.COM * scmadm -o system and scmadm -o 0
19537836SJohn.Forte@Sun.COM */
19547836SJohn.Forte@Sun.COM if (((int)strtol(s, (char **)NULL, 10) == 0) &&
19557836SJohn.Forte@Sun.COM strcmp(s, "0"))
19567836SJohn.Forte@Sun.COM return (-1);
19577836SJohn.Forte@Sun.COM
19587836SJohn.Forte@Sun.COM /*
19597836SJohn.Forte@Sun.COM * Only return failure at this point, in order to allow
19607836SJohn.Forte@Sun.COM * checking arg_cd against st_count later on.
19617836SJohn.Forte@Sun.COM */
19627836SJohn.Forte@Sun.COM if ((arg_cd = strtol(s, 0, 0)) < 0) {
19637836SJohn.Forte@Sun.COM return (arg_cd);
19647836SJohn.Forte@Sun.COM }
19657836SJohn.Forte@Sun.COM }
19667836SJohn.Forte@Sun.COM
19677836SJohn.Forte@Sun.COM /* make sure the cd passed as an argument is alloc'd and < st_count */
19687836SJohn.Forte@Sun.COM if (arg_cd >= 0) {
19697836SJohn.Forte@Sun.COM return (((arg_cd < cs_cur->st_count) &&
19707836SJohn.Forte@Sun.COM (cs_cur->st_shared[arg_cd].sh_alloc)) ? arg_cd : -1);
19717836SJohn.Forte@Sun.COM }
19727836SJohn.Forte@Sun.COM
19737836SJohn.Forte@Sun.COM for (cd = 0; cd < cs_cur->st_count; cd++) {
19747836SJohn.Forte@Sun.COM if (cs_cur->st_shared[cd].sh_alloc &&
19757836SJohn.Forte@Sun.COM strcmp(s, cs_cur->st_shared[cd].sh_filename) == 0)
19767836SJohn.Forte@Sun.COM return (cd);
19777836SJohn.Forte@Sun.COM }
19787836SJohn.Forte@Sun.COM return (-1);
19797836SJohn.Forte@Sun.COM }
19807836SJohn.Forte@Sun.COM
19817836SJohn.Forte@Sun.COM void
19827836SJohn.Forte@Sun.COM check_and_set_mirrors(int node, int mirror)
19837836SJohn.Forte@Sun.COM {
19847836SJohn.Forte@Sun.COM
19857836SJohn.Forte@Sun.COM if (minidsp) {
19867836SJohn.Forte@Sun.COM (void) fprintf(stderr,
19877836SJohn.Forte@Sun.COM gettext("%s: minidsp defined. "
19887836SJohn.Forte@Sun.COM "Cannot define other nodes.\n"),
19897836SJohn.Forte@Sun.COM progname);
19907836SJohn.Forte@Sun.COM exit(1);
19917836SJohn.Forte@Sun.COM }
19927836SJohn.Forte@Sun.COM
19937836SJohn.Forte@Sun.COM if (mirror == _SD_NO_HOST) {
19947836SJohn.Forte@Sun.COM minidsp++;
19957836SJohn.Forte@Sun.COM } else if ((!(node % 2) && !(node == mirror - 1)) ||
19967836SJohn.Forte@Sun.COM (((node % 2) && !(node == mirror + 1)))) {
19977836SJohn.Forte@Sun.COM (void) fprintf(stderr,
19987836SJohn.Forte@Sun.COM gettext("%s: Node and Mirror identification values "
19997836SJohn.Forte@Sun.COM "must be consecutive\n"
20007836SJohn.Forte@Sun.COM "starting at an even number (Node = %d Mirror = %d)\n"),
20017836SJohn.Forte@Sun.COM progname, node, mirror);
20027836SJohn.Forte@Sun.COM exit(1);
20037836SJohn.Forte@Sun.COM }
20047836SJohn.Forte@Sun.COM
20057836SJohn.Forte@Sun.COM node_defined[node]++;
20067836SJohn.Forte@Sun.COM
20077836SJohn.Forte@Sun.COM nodes_conf[nodes_configured] = node;
20087836SJohn.Forte@Sun.COM nodes_configured++;
20097836SJohn.Forte@Sun.COM
20107836SJohn.Forte@Sun.COM if (node == myid) {
20117836SJohn.Forte@Sun.COM user_level_conf.mirror_host = mirror;
20127836SJohn.Forte@Sun.COM }
20137836SJohn.Forte@Sun.COM }
20147836SJohn.Forte@Sun.COM
20157836SJohn.Forte@Sun.COM char *mem_string =
20167836SJohn.Forte@Sun.COM "%-8s Structures use approx. %8d bytes (%5d pages) of memory\n";
20177836SJohn.Forte@Sun.COM
20187836SJohn.Forte@Sun.COM void
20197836SJohn.Forte@Sun.COM enable_sdbc()
20207836SJohn.Forte@Sun.COM {
20217836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
20227836SJohn.Forte@Sun.COM
20237836SJohn.Forte@Sun.COM if (get_cache_config()) {
20247836SJohn.Forte@Sun.COM (void) fprintf(stderr,
20257836SJohn.Forte@Sun.COM gettext("%s: unable to read configuration file\n"),
20267836SJohn.Forte@Sun.COM progname);
20277836SJohn.Forte@Sun.COM exit(1);
20287836SJohn.Forte@Sun.COM }
20297836SJohn.Forte@Sun.COM
20307836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_ENABLE, &user_level_conf, 0, 0, 0, 0,
20317836SJohn.Forte@Sun.COM &ustats) == SPCS_S_ERROR) {
20327836SJohn.Forte@Sun.COM (void) fprintf(stderr, gettext("%s: cache enable failed\n"),
20337836SJohn.Forte@Sun.COM progname);
20347836SJohn.Forte@Sun.COM spcs_log("scm", &ustats, gettext("%s cache enable failed"),
20357836SJohn.Forte@Sun.COM progname);
20367836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
20377836SJohn.Forte@Sun.COM exit(1);
20387836SJohn.Forte@Sun.COM }
20397836SJohn.Forte@Sun.COM spcs_log("scm", NULL, gettext("%s cache enable succeeded"),
20407836SJohn.Forte@Sun.COM progname);
20417836SJohn.Forte@Sun.COM #ifdef DEBUG
20427836SJohn.Forte@Sun.COM (void) printf(gettext("%s: cache has been configured\n"), progname);
20437836SJohn.Forte@Sun.COM #endif
20447836SJohn.Forte@Sun.COM #ifdef WRTHRU_HINTS
20457836SJohn.Forte@Sun.COM if (iscluster()) {
20467836SJohn.Forte@Sun.COM /* Must writethru on a cluster, even if nvram configured */
20477836SJohn.Forte@Sun.COM forced_wrthru = 1;
20487836SJohn.Forte@Sun.COM }
20497836SJohn.Forte@Sun.COM
20507836SJohn.Forte@Sun.COM if (minidsp && forced_wrthru != -1) {
20517836SJohn.Forte@Sun.COM /* Have minidsp with forced_wrthru hint. Set / Clear hint */
20527836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_FORCED_WRTHRU,
20537836SJohn.Forte@Sun.COM forced_wrthru, 0, 0, 0, &ustats) == SPCS_S_ERROR) {
20547836SJohn.Forte@Sun.COM (void) fprintf(stderr,
20557836SJohn.Forte@Sun.COM gettext("%s: set/clear forced_wrthru failed\n"),
20567836SJohn.Forte@Sun.COM progname);
20577836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
20587836SJohn.Forte@Sun.COM } else if (forced_wrthru) {
20597836SJohn.Forte@Sun.COM (void) printf(gettext("%s: Node option forced_wrthru "
20607836SJohn.Forte@Sun.COM "now set.\n"), progname);
20617836SJohn.Forte@Sun.COM } else {
20627836SJohn.Forte@Sun.COM (void) printf(gettext("%s: Node option forced_wrthru "
20637836SJohn.Forte@Sun.COM "now cleared.\n"), progname);
20647836SJohn.Forte@Sun.COM }
20657836SJohn.Forte@Sun.COM }
20667836SJohn.Forte@Sun.COM if (no_forced_wrthru != -1) {
20677836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_NO_FORCED_WRTHRU,
20687836SJohn.Forte@Sun.COM no_forced_wrthru, 0, 0, 0, &ustats) == SPCS_S_ERROR) {
20697836SJohn.Forte@Sun.COM (void) fprintf(stderr,
20707836SJohn.Forte@Sun.COM gettext("%s: set/clear no_forced_wrthru "
20717836SJohn.Forte@Sun.COM "failed\n"), progname);
20727836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
20737836SJohn.Forte@Sun.COM } else if (no_forced_wrthru) {
20747836SJohn.Forte@Sun.COM (void) printf(gettext("%s: Node option no_forced_wrthru"
20757836SJohn.Forte@Sun.COM " now set.\n"), progname);
20767836SJohn.Forte@Sun.COM } else {
20777836SJohn.Forte@Sun.COM (void) printf(gettext("%s: Node option no_forced_wrthru"
20787836SJohn.Forte@Sun.COM " now cleared.\n"), progname);
20797836SJohn.Forte@Sun.COM }
20807836SJohn.Forte@Sun.COM }
20817836SJohn.Forte@Sun.COM #endif
20827836SJohn.Forte@Sun.COM
20837836SJohn.Forte@Sun.COM /* do scmadm -O to cater for manual cache disable then enable */
20847836SJohn.Forte@Sun.COM restore_hints();
20857836SJohn.Forte@Sun.COM }
20867836SJohn.Forte@Sun.COM
20877836SJohn.Forte@Sun.COM void
20887836SJohn.Forte@Sun.COM disable_sdbc()
20897836SJohn.Forte@Sun.COM {
20907836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
20917836SJohn.Forte@Sun.COM
20927836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_DISABLE, 0, 0, 0, 0, 0, &ustats) != SPCS_S_OK) {
20937836SJohn.Forte@Sun.COM /*
20947836SJohn.Forte@Sun.COM * If it wasn't already enabled, don't appear to fail
20957836SJohn.Forte@Sun.COM * or users of this program might think the cache is
20967836SJohn.Forte@Sun.COM * configured, when it actually isn't.
20977836SJohn.Forte@Sun.COM */
20987836SJohn.Forte@Sun.COM if (errno != SDBC_EDISABLE) {
20997836SJohn.Forte@Sun.COM spcs_log("scm", &ustats,
21007836SJohn.Forte@Sun.COM gettext("%s cache disable failed"), progname);
21017836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
21027836SJohn.Forte@Sun.COM exit(1);
21037836SJohn.Forte@Sun.COM }
21047836SJohn.Forte@Sun.COM }
21057836SJohn.Forte@Sun.COM #ifdef DEBUG
21067836SJohn.Forte@Sun.COM (void) printf(gettext("%s: cache has been deconfigured\n"), progname);
21077836SJohn.Forte@Sun.COM #endif
21087836SJohn.Forte@Sun.COM spcs_log("scm", NULL, gettext("%s cache disable succeeded"),
21097836SJohn.Forte@Sun.COM progname);
21107836SJohn.Forte@Sun.COM }
21117836SJohn.Forte@Sun.COM
21127836SJohn.Forte@Sun.COM static void
21137836SJohn.Forte@Sun.COM get_version()
21147836SJohn.Forte@Sun.COM {
21157836SJohn.Forte@Sun.COM cache_version_t version;
21167836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
21177836SJohn.Forte@Sun.COM
21187836SJohn.Forte@Sun.COM if (SDBC_IOCTL(SDBC_VERSION, &version, 0, 0, 0, 0, &ustats) ==
21197836SJohn.Forte@Sun.COM SPCS_S_ERROR) {
21207836SJohn.Forte@Sun.COM (void) fprintf(stderr,
21217836SJohn.Forte@Sun.COM gettext("%s: get cache version failed\n"), progname);
21227836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
21237836SJohn.Forte@Sun.COM exit(1);
21247836SJohn.Forte@Sun.COM }
21257836SJohn.Forte@Sun.COM #ifdef DEBUG
21267836SJohn.Forte@Sun.COM (void) printf(gettext("Cache version %d.%d.%d.%d\n"),
21277836SJohn.Forte@Sun.COM version.major, version.minor, version.micro, version.baseline);
21287836SJohn.Forte@Sun.COM #else
21297836SJohn.Forte@Sun.COM if (version.micro) {
21307836SJohn.Forte@Sun.COM (void) printf(gettext("Cache version %d.%d.%d\n"),
21317836SJohn.Forte@Sun.COM version.major, version.minor, version.micro);
21327836SJohn.Forte@Sun.COM } else {
21337836SJohn.Forte@Sun.COM (void) printf(gettext("Cache version %d.%d\n"),
21347836SJohn.Forte@Sun.COM version.major, version.minor);
21357836SJohn.Forte@Sun.COM }
21367836SJohn.Forte@Sun.COM #endif
21377836SJohn.Forte@Sun.COM }
21387836SJohn.Forte@Sun.COM
21397836SJohn.Forte@Sun.COM #ifdef DEBUG
21407836SJohn.Forte@Sun.COM int
21417836SJohn.Forte@Sun.COM toggle_flush(void)
21427836SJohn.Forte@Sun.COM {
21437836SJohn.Forte@Sun.COM int rc;
21447836SJohn.Forte@Sun.COM spcs_s_info_t ustats;
21457836SJohn.Forte@Sun.COM
21467836SJohn.Forte@Sun.COM if ((rc = SDBC_IOCTL(SDBC_TOGGLE_FLUSH, 0, 0, 0,
21477836SJohn.Forte@Sun.COM 0, 0, &ustats)) == SPCS_S_ERROR) {
21487836SJohn.Forte@Sun.COM (void) fprintf(stderr,
21497836SJohn.Forte@Sun.COM gettext("%s: toggle sdbc cache flush failed\n"),
21507836SJohn.Forte@Sun.COM progname);
21517836SJohn.Forte@Sun.COM sdbc_report_error(&ustats);
21527836SJohn.Forte@Sun.COM exit(1);
21537836SJohn.Forte@Sun.COM }
21547836SJohn.Forte@Sun.COM return (rc);
21557836SJohn.Forte@Sun.COM }
21567836SJohn.Forte@Sun.COM #endif
2157