diff options
Diffstat (limited to 'usr/src/cmd/avs/sdbc')
-rw-r--r-- | usr/src/cmd/avs/sdbc/Makefile | 108 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/etc/Makefile | 62 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/etc/dscfg_reconfigure.cluster.sh | 425 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/etc/scm.sh | 348 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/scmadm.c | 2156 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/sd_diag.c | 1169 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/sd_stats.c | 594 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/sd_trace.c | 961 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/sdbc_dynmem.c | 388 | ||||
-rw-r--r-- | usr/src/cmd/avs/sdbc/sdbc_ioctl.c | 156 |
10 files changed, 0 insertions, 6367 deletions
diff --git a/usr/src/cmd/avs/sdbc/Makefile b/usr/src/cmd/avs/sdbc/Makefile deleted file mode 100644 index 97cc48f5a1..0000000000 --- a/usr/src/cmd/avs/sdbc/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# - -# must be before include of Makefile.cmd -DYNPROG = scmadm \ - sd_stats \ - sd_diag - -include ../../Makefile.cmd -include ../Makefile.com - -SUBDIRS= etc - -PROG = $(DYNPROG) - -scmadm := POBJS = scmadm.o sdbc_ioctl.o -sd_stats := POBJS = sd_stats.o sd_trace.o sdbc_ioctl.o rdc_ioctl.o -sd_diag := POBJS = sd_diag.o -sdbc_dynmem := POBJS = sdbc_dynmem.o - -OBJS= scmadm.o\ - sdbc_ioctl.o\ - sd_diag.o\ - sd_stats.o\ - sd_trace.o\ - sdbc_dynmem.o - -XTRA_OBJS= \ - rdc_ioctl.o - -SRCS= $(OBJS:%.o=%.c) - -POFILE = scmadm.po - -scmadm := LDLIBS += -lnsctl -lunistat -ldscfg -sd_stats := LDLIBS += -lunistat -lcurses -sd_diag := LDLIBS += -lnsctl -sdbc_dynmem := LDLIBS += -lkstat - -CFLAGS += $(CCVERBOSE) -D_SCM_ -D_SD_8K_BLKSIZE -D_SYSCALL32 -CPPFLAGS += -DNSC_MULTI_TERABYTE -LINTFLAGS += -Xa -n -s -x -m -u -Dlint -errhdr=%user -LINTFLAGS += -D_SCM_ -D_SD_8K_BLKSIZE -D_SYSCALL32 -LINTFLAGS += -erroff=E_SEC_PRINTF_VAR_FMT -LINTFLAGS += -erroff=E_SEC_SPRINTF_UNBOUNDED_COPY -LINTFLAGS += -erroff=E_SEC_SCANF_UNBOUNDED_COPY -LINTFLAGS += -erroff=E_SEC_FORBIDDEN_WARN_ASCFTIME -LINTFLAGS += -DDEBUG -CERRWARN += -_gcc=-Wno-uninitialized -ROOTLINK = $(ROOTUSRSBIN)/scmadm - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -lint := TARGET= lint - -.KEEP_STATE: - -.PARALLEL: $(OBJS) $(XTRA_OBJS) - -all: $(SUBDIRS) $(PROG) $(POFILE) - -install: $(SUBDIRS) all $(ROOTPROG) $(ROOTLINK) - -lint: $(SUBDIRS) lint_SRCS - -clean: $(SUBDIRS) - $(RM) *.o - -rdc_ioctl.o: ../rdc/rdc_ioctl.c - $(COMPILE.c) ../rdc/rdc_ioctl.c - -$(PROG): $$(POBJS) - $(LINK.c) $(POBJS) -o $@ $(LDLIBS) - $(POST_PROCESS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -$(ROOTLINK): $(ROOTUSRSBIN) $(ROOTBIN)/scmadm - -$(RM) $@; $(LN) $(ROOTBIN)/scmadm $@ - -include ../../Makefile.targ - -FRC: diff --git a/usr/src/cmd/avs/sdbc/etc/Makefile b/usr/src/cmd/avs/sdbc/etc/Makefile deleted file mode 100644 index 0abbf70293..0000000000 --- a/usr/src/cmd/avs/sdbc/etc/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/ns/sdbc/etc/Makefile - -include ../../../Makefile.cmd -include ../../Makefile.com - -INITPROGS = scm -BINPROGS = dscfg_reconfigure.cluster -SHFILES = $(INITPROGS) $(BINPROGS) -ROOTINIT_D = $(ROOTETC)/init.d - -ROOTBINPROGS= $(BINPROGS:%=$(ROOTBIN)/%) -ROOTINITPROGS= $(INITPROGS:%=$(ROOTINIT_D)/%) - -# scm is mode 744, dscfg_reconfigure.cluster is mode 555 -$(ROOTINITPROGS) := FILEMODE= 744 -$(ROOTBINPROGS) := FILEMODE= 555 - -.KEEP_STATE: - -all: $(SHFILES) $(INITPROGS) $(BINPROGS) - -install: $(ROOTBINPROGS) $(ROOTINITPROGS) $(ROOTLIBSVCMETHOD) $(CLUSTERSBINDIR) - -$(RM) $(ROOTLIBSVCMETHOD)/svc-scm - -$(RM) $(CLUSTERSBINDIR)/dscfg_reconfigure - $(LN) $(ROOTINIT_D)/scm $(ROOTLIBSVCMETHOD)/svc-scm - $(LN) $(ROOTBIN)/$(BINPROGS) $(CLUSTERSBINDIR)/dscfg_reconfigure - -$(ROOTINIT_D)/%: % - $(INS.file) - -clean: - $(RM) $(SHFILES) - -clobber: clean - $(RM) $(ROOTBINPROGS) $(ROOTINITPROGS) - -lint: - -FRC: diff --git a/usr/src/cmd/avs/sdbc/etc/dscfg_reconfigure.cluster.sh b/usr/src/cmd/avs/sdbc/etc/dscfg_reconfigure.cluster.sh deleted file mode 100644 index 5dfb40768b..0000000000 --- a/usr/src/cmd/avs/sdbc/etc/dscfg_reconfigure.cluster.sh +++ /dev/null @@ -1,425 +0,0 @@ -#!/usr/bin/ksh -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# NWS DataServices within SunCluster reconfiguration script. -# -# Description: -# -# This script is called from /usr/cluster/lib/sc/run_reserve at -# appropriate times to start and stop the NWS DataServices as SunCluster -# disk device groups are brought online or taken offline. -# -# SNDR configuration requires that a resource group to be configured. -# 1. The resource group name should be same as device group name with -stor-rg -# added. e.g. if device group name is abc-dg then resource group name -# would be abc-dg-stor-rg. -# 2. It should have 2 resources in it, unless one of the resource types is the -# SUNW.GeoCtlAVS. One of type SUNW.LogicalHostname and either SUNW.HAStorage -# or SUNW.HAStoragePlus types. Resource type versioning is ignored. -# HAStorage type resource, should have ServicePaths property set to -# device group name. HAStoragePlus type resource, should have either the -# FilesystemMountPoints pointing to a files system associated with the -# device group name, or GlobalDevicePaths property set to device group name. -# LogicalHostname type resource should have a failoverIP address in it and -# it will be used by SNDR to communicate with the secondary side. -# -# As SNDR requires that the LogicalHost (failover) IP address which is a -# part of resource group for SNDR, to be hosted on the same node where the -# device group is, it tries to move the resource group also alongwith the -# device group, in become_primary case of run_reserve script. While -# in primary_to_secondary case, it will try to kill the switchover function -# if it is still running in background, after stopping NWS data services. -# -# Usage: -# -# /usr/cluster/sbin/dscfg_reconfigure { start | stop } diskgroup -# -# Configuration: -# -# Scripts to be run should have been symlinked into $NWS_START_DIR and -# $NWS_STOP_DIR. Note that the scripts are processed in lexical order, -# and that unlike /etc/rc?.d/ there is no leading S or K character. -# -# Exit status: -# -# 0 - success -# 1 - error -# - -# -# Global variables -# - -# this program -typeset -r ARGV0=$(basename $0) - -# directory full of start scripts -typeset -r NWS_START_DIR=/usr/cluster/lib/dscfg/start - -# directory full of stop scripts -typeset -r NWS_STOP_DIR=/usr/cluster/lib/dscfg/stop - -# the syslog facility to use. -# - conceptually this should be based on the output of -# "scha_cluster_get -O SYSLOG_FACILITY", but that won't work early -# during boot. -typeset -r SYSLOG_FACILITY=daemon - -PATH=$PATH:/usr/cluster/bin:/etc - -# Variables for retrying scswitch of Resource group for SNDR -retry_num=12 -retry_interval=10 -rgname= -rgstat= -skip_resource=0 -count_LogicalHostname=0 -count_HAStoragePlus=0 - -# Since the switchover of the resource group is called in background, -# the stop action of the reconfig script will kill the background switchover -# if it is running. Since we are stopping the NWS services on the node, there -# is no need to switch the resource group, so it is killed. -# The pid of the process is kept in file /var/run/scnws/$dg.pid. -# Input: dg - device group -# Output: Nothing, kills the process - -function kill_scswitch -{ - dg=$1 - if [ -f /var/run/scnws/$dg.pid ] - then - for i in `cat /var/run/scnws/$dg.pid` - do - pid=$i - kill -9 $pid - done - rm -f /var/run/scnws/$dg.pid - fi -} - -# Get the status of the resource group on this node, using scha commands. -# Input: resource group - $1 -# Output: Status - -function get_rgstat -{ - rg=$1 - rgstat=`scha_resourcegroup_get -O RG_STATE -G $rg` -} - -# This function is called in background from do_scswitch function, to -# switch the resource group to this node, which is becoming primary for -# the diskgroup. If the status of resource group is Offline, it will use -# scswitch command to switch the resource group to this node. If it has -# become Online, cleanup pid file. If it is Pending, the resource group -# is in the state of becoming online, so wait for sometime to become Online.. -# scswitch may fail, so the function retries $retry_num times, waiting for -# $retry_interval seconds. -# Input: resource group - $1, Diskgroup/Diskset - $2 -# Output: 0 - success, 1 - failure - -function switchfunc -{ - rg=$1 - dg=$2 - how_many=0 - sleep 2 - while [ $how_many != $retry_num ] - do - get_rgstat $rg - case "$rgstat" in - "ONLINE") - rm -f /var/run/scnws/$dg.pid - return 0 - ;; - - "OFFLINE") - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "scswitch of resource group"` "$rg" - - scswitch -z -g $rg -h $(hostname) - retval=$? - if [ $retval != 0 ] - then - sleep $retry_interval - how_many=$(($how_many + 1)) - fi - ;; - - "PENDING_ONLINE") - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "pending online of resource group"` "$rg" - sleep $retry_interval - how_many=$(($how_many + 1)) - ;; - - *) - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "Improper resource group status for Remote Mirror"` "$rgstat" - rm -f /var/run/scnws/$dg.pid - return 1 - ;; - esac - done - logger -p ${SYSLOG_FACILITY}.err \ - -t "NWS.[$ARGV0]" "Did not switch resource group for Remote Mirror. System Administrator intervention required" - rm -f /var/run/scnws/$dg.pid - return 1 -} - - -# This function calls switchfunc function in background, to switch the -# resource group for SNDR. It validates the diskgroup/diskset is configured -# for SNDR, checks if the resource group is in Managed state etc. -# If it detects a mis-configuration, it will disable SNDR for the -# device group being processed. This is to prevent cluster hangs and panics. -# -# The ServicePaths extension property of HAStorage type resource or the -# GlobalDevicePaths extension property of HAStoragePlus, both of which -# specify the device group, serve as a link or mapping to retrieve the -# resource group associated with the SNDR configured device group. -# Switchfunc is called in the background to avoid the deadlock situation arising -# out of switchover of resource group from within device group switchover. -# -# In run_reserve context, we are doing the device group switchover, trying to -# bring it online on the node. Device group is not completely switched online, -# until the calling script run_reserve returns. In the process, we are calling -# the associated SNDR resource group switchover using scswitch command. -# Resource group switchover will trigger the switchover of device group also. -# -# If resource group switchover is called in foreground, before the device -# group has become online, then it will result in switching the device group -# again, resulting in deadlock. Resource group can not become online until -# the device group is online and the device group can not become online until the -# script returns, causing this circular dependency resulting in deadlock. -# -# Calling the resource group switch in background allows current run_reserve -# script to return immediately, allowing device group to become online. -# If the device group is already online on the node, then the resource group -# does not cause the device group switchover again. -# -# Input: Device group dg - $1 -# Output: 0 - success -# 1 - either dg not applicable for SNDR or error -# 2 - SNDR mis-configuration - -function do_scswitch -{ - dg=$1 - - if [ ! -x /usr/cluster/bin/scha_resource_get \ - -o ! -x /usr/cluster/bin/scha_resourcegroup_get ] - then - return 1 - fi - -# hard coded rg name from dg - rgname="$dg-stor-rg" - scha_resourcegroup_get -O rg_description -G $rgname > /dev/null - if [ $? != 0 ] - then -# There is no device group configured in cluster for SNDR with this cluster tag - return 1 - fi - -# Check the state of resource group - - get_rgstat $rgname - if [ -z "$rgstat" \ - -o "$rgstat" = "UNMANAGED" -o "$rgstat" = "ERROR_STOP_FAILED" ] - then - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" \ - `gettext "Improper Remote Mirror resource group state"` "$rgstat" - return 2 - fi - -# Check whether resources are of proper type and they are enabled - - rs_list=`scha_resourcegroup_get -O resource_list -G $rgname` - if [ -z "$rs_list" ] - then - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" \ - `gettext "No resources in Remote Mirror resource group <$rgname>"` - return 2 - fi - for rs in $rs_list - do - rs_type=`scha_resource_get -O type -R $rs -G $rgname | cut -d':' -f1` - case "$rs_type" in - SUNW.LogicalHostname) - rs_enb=`scha_resource_get -O ON_OFF_SWITCH -R $rs -G $rgname` - if [ "$rs_enb" = "ENABLED" ] - then - count_LogicalHostname=$(($count_LogicalHostname + 1)) - fi - ;; - SUNW.HAStoragePlus) - rs_enb=`scha_resource_get -O ON_OFF_SWITCH -R $rs -G $rgname` - if [ "$rs_enb" = "ENABLED" ] - then - count_HAStoragePlus=$(($count_HAStoragePlus + 1)) - fi - ;; - esac - done - if [ $count_LogicalHostname -lt 1 ] - then - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "Missing Enabled Logical Host in resource group <$rgname> for Remote Mirror"` - return 2 - elif [ $count_LogicalHostname -gt 1 ] - then - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "Too Many Enabled Logical Host in resource group <$rgname> for Remote Mirror"` - return 2 - fi - - if [ $count_HAStoragePlus -lt 1 ] - then - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "Missing Enabled HAStoragePlus in resource group <$rgname> for Remote Mirror"` - return 2 - elif [ $count_HAStoragePlus -gt 1 ] - then - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[$ARGV0]" `gettext "Too Many Enabled HAStoragePlus in resource group <$rgname> for Remote Mirror"` - return 2 - fi - -# Invoke switchfunc to switch the resource group. - - switchfunc $rgname $dg & - pid=$! - mkdir -p /var/run/scnws/ - rm -f /var/run/scnws/$dg.pid - echo $pid > /var/run/scnws/$dg.pid - - return 0 -} - - -# -# Functions -# - -usage() -{ - logger -p ${SYSLOG_FACILITY}.err \ - -t "NWS.[$ARGV0]" "usage: $ARGV0 { start | stop } diskgroup" - exit 1 -} - - -# Input: arg1) $NWS_START_DIR - location of NWS scripts -# arg2) start / stop -# arg3 ) device group - $2 -# arg4) sndr_ena / sndr_dis -# Output: Nothing. Log error if seen - -process_dir() -{ - typeset dir=$1 - typeset arg1=$2 - typeset dg=$3 - typeset arg2=$4 - typeset RDC=$dir/10rdc - - if [[ -d $dir ]] - then - for f in $dir/* - do - # process scripts in the directories in lexical order - # note - no leading S or K unlike /etc/rc?.d/ - - if [ -s $f ] && [ $arg2 != "sndr_dis" ] - then - # run script and pipe output through - # logger into syslog - - /usr/bin/ksh $f $arg1 $dg 2>&1 | - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[${ARGV0}:$(basename $f)]" - else - # SNDR misconfigured - prevent start - if [ -s $f ] && [ $f != $RDC ] - then - # run script and pipe output through - # logger into syslog - /usr/bin/ksh $f $arg1 $dg 2>&1 | - logger -p ${SYSLOG_FACILITY}.notice \ - -t "NWS.[${ARGV0}:$(basename $f)]" - fi - fi - done - else - logger -p ${SYSLOG_FACILITY}.err \ - -t "NWS.[$ARGV0]" "no directory: $dir" - fi -} - - -# -# main -# - -if [ $# -ne 2 ] -then - usage - # not reached -fi - - -case "$1" in -start) - logger -p ${SYSLOG_FACILITY}.notice -t "NWS.[$ARGV0]" "starting: $ARGV0 $*" - do_scswitch $2 - retval=$? - if [ $retval == 2 ] - then - logger -p ${SYSLOG_FACILITY}.err \ - -t "NWS.[$ARGV0]" "**FATAL ERROR** Remote Mirror is mis-configured and DISABLED for devicegroup <"$2"> " - # Disable SNDR - process_dir $NWS_START_DIR start "$2" sndr_dis - else - process_dir $NWS_START_DIR start "$2" sndr_ena - fi - ;; -stop) - logger -p ${SYSLOG_FACILITY}.notice -t "NWS.[$ARGV0]" "stopping: $ARGV0 $*" - process_dir $NWS_STOP_DIR stop "$2" sndr_ena - kill_scswitch $2 - ;; - -*) - usage - # not reached - ;; -esac - -logger -p ${SYSLOG_FACILITY}.notice -t "NWS.[$ARGV0]" "completed: $ARGV0 $*" - -exit 0 diff --git a/usr/src/cmd/avs/sdbc/etc/scm.sh b/usr/src/cmd/avs/sdbc/etc/scm.sh deleted file mode 100644 index f5ce4b1a78..0000000000 --- a/usr/src/cmd/avs/sdbc/etc/scm.sh +++ /dev/null @@ -1,348 +0,0 @@ -#!/bin/ksh -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -####################################################################### -# -# This file contains system setup requirements for scm. -# -# For systems before Solaris 10 it should be located in /etc/init.d -# directory with the following links: -# -# ln /etc/init.d/scm /etc/rc0.d/K84scm -# ln /etc/init.d/scm /etc/rc2.d/S002scm -# -# For Solaris 10 or later systems this script is run as part of SVC by -# svc.startd and should be located in /lib/svc/method -# -#USAGE="Usage: $0 { start | stop } -# -####################################################################### - -SVCS=/usr/bin/svcs -DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid" -OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2` - -. /lib/svc/share/smf_include.sh - -# Make sure prior SMF dependents are not 'online' -# $1 = name of SMF service to validate dependents -# -do_smf_depends () -{ - times=0 - count=1 - - if [ $OS_MINOR -ge 11 ] - then - return 0 - elif [ -f $DSCFG_DEPEND_NOCHK ] - then - for pid in `pgrep dscfgadm` - do - if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ] - then - return 0 - fi - done - elif [ `ps -ef | grep preremove | grep -c SUNWscmu` -gt 0 ] - then - return 0 - - fi - - while [ $count -ne 0 ] - do - count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l` - if [ $count -ne 0 ] - then - # Output banner after waiting first 5 seconds - # - if [ $times -eq 1 ] - then - echo "Waiting for $1 dependents to be 'offline'" - $SVCS -D $1 2>>/dev/null | grep "^online" - fi - - # Has it been longer then 5 minutes? (60 * 5 secs.) - # - if [ $times -eq 60 ] - then - echo "Error: Failed waiting for $1 dependents to be 'offline'" - $SVCS -D $1 2>>/dev/null | grep "^online" - exit $SMF_EXIT_ERR_FATAL - fi - - # Now sleep, giving other services time to stop - # - sleep 5 - times=`expr $times + 1` - fi - done - return 0 -} - -set_system_type() -{ - CLINFO=/usr/sbin/clinfo - ESMSBIN=/usr/sbin - SCMBIN=/usr/sbin - ESMSCMLIB=/usr/lib - SCMLIB=/usr/lib - DSCFG_LOCKDB=/etc/dscfg_lockdb -} - -do_stopsdbc () -{ - if [ ! -r /dev/sdbc ] - then - return - fi - - ${SCMBIN}/scmadm -d - if [ $? -ne 0 ] ; then - # If the disable failed that means we have pinned data. - echo "Cache Not Deconfigured" - fi -} - -do_stopnskernd () -{ - ps -e | grep -w nskernd > /dev/null 2>&1 - if [ $? -eq 0 ] ; then - # make sure that all data services are unloaded before stopping - # nskernd - cannot stop nskernd when its threads could be in use - # Note: sv is unloadable, but its threadset is shutdown in the - # final close(9e) call. - stop=1 - for m in ste rdc rdcsrv ii sdbc ; do - mid=`/usr/sbin/modinfo | grep -w $m | awk '{print $1}' -` - if [ -z "$mid" ] ; then - continue # not loaded - fi - /usr/sbin/modunload -i $mid > /dev/null 2>&1 - if [ $? -ne 0 ] ; then - stop=0 - break - fi - done - - # kill nskernd if we can - pid=`ps -e | grep -w nskernd | sed -e 's/^ *//' -e 's/ .*//'` - if [ $stop -eq 1 ] ; then - if [ -n "$pid" ] ; then - kill -15 $pid - fi - fi - fi - - if [ -r /dev/ncall -a -x $ESMSCMLIB/ncalladm ] - then - $ESMSCMLIB/ncalladm -d - fi -} - -do_stopdscfglockd () -{ - pid=`ps -e | grep -w dscfgloc | sed -e 's/^ *//' -e 's/ .*//'` - if [ -n "$pid" ] ; then - kill -15 $pid - fi -} - -do_stop () -{ - do_smf_depends "system/nws_scm" - do_stopsdbc - do_stopnskernd - do_stopdscfglockd -} - -do_nskernd () -{ - if [ -x $ESMSCMLIB/ncalladm ] - then - $ESMSCMLIB/ncalladm -e - fi - - ps -e | grep -w nskernd > /dev/null 2>&1 - if [ $? -ne 0 ] ; then - ${SCMLIB}/nskernd - if [ $? -ne 0 ] ; then - echo "Error: Unable to start nskernd" - exit $SMF_EXIT_ERR_FATAL - fi - fi -} - -do_dscfglockd () -{ - ps -e | grep -w dscfgloc > /dev/null 2>&1 - if [ $? -ne 0 ] - then - rm -f /var/tmp/.cfglockd.pid - else - # dscfglockd already running - return - fi - - if ${CLINFO} - then - # - # create or update the dscfg_lockdb file - # - - # create clean tmpnodelist - NODELIST=/tmp/$$.dscfg_nodelist - rm -f $NODELIST >/dev/null 2>&1 - touch $NODELIST - - if [ -x /usr/cluster/bin/scstat ] - then - # get valid names in cluster - /usr/cluster/bin/scstat -n | grep node: | \ - awk '{print $3}' >> $NODELIST - if [ ! -f $DSCFG_LOCKDB ] - then - printf "In clustered environment.\n" - printf "creating per node dscfg_lockdb database" - printf " with following nodenames:\n" - cat $NODELIST - cp $NODELIST $DSCFG_LOCKDB - else - # check if there are any changes - diff $NODELIST $DSCFG_LOCKDB > /dev/null - if [ $? != 0 ] - then - printf "The cluster node names have " - printf "changed. Updating dscfg_lockdb " - printf "database.\n" - printf "Previous node names:\n" - cat $DSCFG_LOCKDB - printf "New node names:\n" - cat $NODELIST - rm -f $DSCFG_LOCKDB - cp $NODELIST $DSCFG_LOCKDB - fi - fi - else - # we're in a cluster, but scstat is not available - printf "In clustered environment.\n" - printf "Required configuration file, $DSCFG_LOCKDB\n" - printf "was not properly populated with the cluster " - printf "nodenames.\nThis file needs to be manually" - printf "updated with the cluster\nnodenames before " - printf "reboot. Refer to Sun Storage Availability\n" - printf "Suite Installation Guide for details.\n" - fi - - # clustered start of dscfglockd - if [ -f $DSCFG_LOCKDB ] - then - printf "Starting dscfglockd\n" - ${SCMLIB}/dscfglockd -f $DSCFG_LOCKDB - else - printf "WARNING: Mis-Configuration of Availability " - printf "Suite for Sun Cluster\n" - printf "WARNING: Can't find configuration file for " - printf "dscfglockd\n" - fi - - rm -f $NODELIST - fi - -} - -do_sdbc () -{ - ${SCMBIN}/scmadm -e -} - - -do_start () -{ - # do nothing if we do not have a dscfg - if [ ! -f /etc/dscfg_local ] - then - echo "Cannot find Availability Suite configuration location" - exit $SMF_EXIT_ERR_NOSMF - fi - - # - # Ordering: - # dscfglockd -- locking must be present before any dscfg access - # nskernd -- starts infrastructure (nskernd, ncall). - # sdbc -- start the cache itself - # - do_dscfglockd - do_nskernd - do_sdbc -} - - -do_usage () -{ - echo "Usage: $0" - echo " start" - echo " stop" - exit 1 -} - -set_system_type - -USED=0 -ACTION= -CLUSTERTAG= - -case $# in -'0') - do_usage - ;; -'1') - ACTION=$1 - USED=1 - ;; -'2') - ACTION=$1 - CLUSTERTAG="$2" - USED=1 - exit 0 - ;; -'*') - do_usage - ;; -esac - -if [ $USED = 0 ] ; then - do_usage -fi - -if [ $ACTION = "start" ] ; then - do_start -elif [ $ACTION = "stop" ] ; then - do_stop -else - do_usage -fi - -exit $SMF_EXIT_OK diff --git a/usr/src/cmd/avs/sdbc/scmadm.c b/usr/src/cmd/avs/sdbc/scmadm.c deleted file mode 100644 index f0a28bbf81..0000000000 --- a/usr/src/cmd/avs/sdbc/scmadm.c +++ /dev/null @@ -1,2156 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2010 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Utility for cache configuration - */ -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <strings.h> -#include <locale.h> -#include <langinfo.h> -#include <libintl.h> -#include <time.h> -#include <sys/nsctl/sd_bcache.h> -#include <sys/wait.h> -#include <errno.h> -#include <signal.h> -#include <sys/types.h> -#include <fcntl.h> -#include <stropts.h> -#include <ctype.h> -#include <libgen.h> - -#include <sys/nsctl/sdbc_ioctl.h> -#include <sys/unistat/spcs_s.h> -#include <sys/unistat/spcs_s_u.h> -#include <sys/unistat/spcs_errors.h> -#include <nsctl.h> - -#include <sys/nsctl/cfg.h> -#define STATS_PATH "/usr/bin/sd_stats" - -#define _SD_FNAME /* bring in function names from sd_trace.h */ -#include <sys/nsctl/sd_trace.h> -#include <sys/syslog.h> - -/* - * Since we no longer support nvram cards, the hints wrthru and nowrthru no - * longer serve any purpose, and the system will always be in wrthru mode. - * WRTHRU_HINTS, if defined still allows the setting and reporting of write - * hints. This is defined by default on DEBUG builds. - */ -#ifdef DEBUG -#define WRTHRU_HINTS -#endif - -static int sdbc_max_devices = 0; - -static char alert_file[200] = "/dev/console"; - -/* Variables used to set up paramater block passed to kernel */ -static _sd_cache_param_t user_level_conf; -static int myid; - -static int nodes_configured = 0; -static int minidsp = 0; /* Is it a sp10 */ -static int forced_wrthru = -1; /* 0 clear, 1 set,-1 as is */ -static int no_forced_wrthru = -1; -static short node_defined[MAX_SD_NODES]; -static short nodes_conf[MAX_SD_NODES]; - -#define USAGELEN 1024 -char stats_usage[USAGELEN+128]; -char scmadmUsage[USAGELEN]; - -static caddr_t progname; - - -/* - * Functions exported for fwcadm. - */ -void enable_sdbc(void); -void disable_sdbc(void); -void sdbc_set_maxdev(); - -static void buildusage(char *); - -void print_all_options(void); -void get_cd_all(void); -int toggle_flush(void); -static void sd_gather_alert_dumps(); -static int get_cd(char *); -static int get_hint(char *, int *, int *); -static void check_and_set_mirrors(int, int); -static void print_hint(const uint_t, const int); -static char *get_device_name(char *arg); -static void get_version(); - -extern struct tm *localtime_r(const time_t *, struct tm *); - -#define PRINT_CACHE_SZ_ERR(sz) {\ - (void) fprintf(stderr, gettext("\n%s: desired cache size (%d) "\ - "set to system max (%d)\n"), \ - progname, (sz), MAX_CACHE_SIZE); \ - spcs_log("sdbc", NULL, \ - gettext("desired cache size (%d) "\ - "set to system max (%d)\n"), \ - (sz), MAX_CACHE_SIZE); \ -} - -void -sdbc_report_error(spcs_s_info_t *ustatus) -{ - if (*ustatus != NULL) { - spcs_s_report(*ustatus, stderr); - spcs_s_ufree(ustatus); - } else - (void) fprintf(stderr, "%s\n", strerror(errno)); -} - - -/* - * Return the per-cd hints for a cd. - * - * Since the global (no)wrthru and NSC_NOCACHE hints take precedence - * over the per-cd hints, get them as well and OR the whole lot - * together. - */ -static int -get_cd_hint(const int cd) -{ - spcs_s_info_t ustats; - int nodehint, cdhint; - - nodehint = SDBC_IOCTL(SDBC_GET_NODE_HINT, 0, 0, 0, 0, 0, &ustats); - if (nodehint == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: get system options failed\n"), progname); - sdbc_report_error(&ustats); - exit(1); - } - - cdhint = SDBC_IOCTL(SDBC_GET_CD_HINT, cd, 0, 0, 0, 0, &ustats); - if (cdhint == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: get cd(%d) hint failed\n"), progname, cd); - sdbc_report_error(&ustats); - exit(1); - } - -#ifdef WRTHRU_HINTS - nodehint &= (NSC_FORCED_WRTHRU | NSC_NO_FORCED_WRTHRU | NSC_NOCACHE); -#else - nodehint &= (NSC_NOCACHE); -#endif - if (nodehint) { - /* set the top bit to mark it as a system override */ - nodehint |= 0x80000000; - } - - return (cdhint | nodehint); -} - - - -/* - * Check for a config. - * - * If no suitable config can be found, install the default config. - * - * Calling state: - * libcfg locked (mode describes type of lock) - */ -static void -convert_config(CFGFILE *cfg, CFGLOCK mode) -{ - char buf[CFG_MAX_BUF]; - char *default_cfg = "128 64"; - -retry: - if (cfg_get_cstring(cfg, "scm.set1", buf, sizeof (buf)) >= 0) { - /* config exists, return */ - return; - } - - cfg_rewind(cfg, CFG_SEC_CONF); - -#ifdef DEBUG - (void) printf(gettext("%s: installing default config entry '%s'\n"), - progname, default_cfg); -#endif - if (mode != CFG_WRLOCK) { - cfg_unlock(cfg); - if (!cfg_lock(cfg, CFG_WRLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - mode = CFG_WRLOCK; -#ifdef DEBUG - (void) printf(gettext("%s: upgraded lock, retrying\n"), - progname); -#endif - goto retry; - } - - if (cfg_put_cstring(cfg, "scm", default_cfg, strlen(default_cfg)) < 0) { - (void) fprintf(stderr, - gettext("%s: unable to write configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - if (!cfg_commit(cfg)) { - (void) fprintf(stderr, - gettext("%s: unable to write to configuration: %s\n"), - progname, cfg_error(NULL)); - } - - if (mode != CFG_WRLOCK) { - if (!cfg_lock(cfg, mode)) { - (void) fprintf(stderr, - gettext("%s: unable to relock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - } - - cfg_rewind(cfg, CFG_SEC_CONF); -} - - -static int -iscluster(void) -{ - int rc; - - rc = cfg_iscluster(); - if (rc == 0) { - return (FALSE); - } else if (rc > 0) { - return (TRUE); - } else { - (void) fprintf(stderr, - gettext("%s: unable to ascertain environment\n"), progname); - exit(1); - } - - /* NOTREACHED */ -} - - -static void -restore_hints() -{ - CFGFILE *cfg; - char key[CFG_MAX_KEY], buf[CFG_MAX_BUF]; - int setnumber; - spcs_s_info_t ustatus; - int cd; - - if ((cfg = cfg_open(NULL)) == NULL) { - (void) fprintf(stderr, - gettext("%s: unable to access configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - if (!cfg_lock(cfg, CFG_RDLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - for (setnumber = 1; /*CONSTCOND*/ TRUE; setnumber++) { - (void) snprintf(key, sizeof (key), "cache_hint.set%d.device", - setnumber); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - /* error or not found */ - break; - } - - if (strcmp(buf, "system") == 0) { - cd = -1; - } else { - cd = get_cd(buf); - if (cd < 0) - continue; - } - - (void) snprintf(key, sizeof (key), "cache_hint.set%d.wrthru", - setnumber); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) - continue; - - if (atoi(buf) == 1) { - if (cd == -1) { - /* Node hint */ - if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_WRTHRU, - 1, 0, 0, 0, &ustatus) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set system " - "option failed\n"), - progname); - sdbc_report_error(&ustatus); - exit(1); - } - } else if (SDBC_IOCTL(SDBC_SET_CD_HINT, cd, - NSC_WRTHRU, 1, 0, 0, &ustatus) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set option failed\n"), - progname); - sdbc_report_error(&ustatus); - exit(1); - } - } - - (void) snprintf(key, sizeof (key), "cache_hint.set%d.nordcache", - setnumber); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) - continue; - - if (atoi(buf) == 1) { - if (cd == -1) { - /* Node hint */ - if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_NOCACHE, - 1, 0, 0, 0, &ustatus) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set system " - "option failed\n"), - progname); - sdbc_report_error(&ustatus); - exit(1); - } - } else if (SDBC_IOCTL(SDBC_SET_CD_HINT, cd, NSC_NOCACHE, - 1, 0, 0, &ustatus) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set option failed\n"), - progname); - sdbc_report_error(&ustatus); - exit(1); - } - } - } - - cfg_close(cfg); -} - -void -sdbc_set_maxdev() -{ - spcs_s_info_t ustats; - - if (SDBC_IOCTL(SDBC_MAXFILES, &sdbc_max_devices, - 0, 0, 0, 0, &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, gettext("%s: get maxfiles failed\n"), - progname); - sdbc_report_error(&ustats); - exit(1); - } -} - -static void -bitmapfs_print(void) -{ - CFGFILE *cfg; - char key[CFG_MAX_KEY], buf[CFG_MAX_BUF]; - int setnumber; - - cfg = cfg_open(NULL); - if (cfg == NULL) { - (void) fprintf(stderr, - gettext("%s: unable to access configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - if (!cfg_lock(cfg, CFG_RDLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - for (setnumber = 1; /*CSTYLED*/; setnumber++) { - (void) snprintf(key, sizeof (key), - "bitmaps.set%d.bitmap", setnumber); - buf[0] = 0; - - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - if (errno == ESRCH) { - /* end of list */ - break; - } - - (void) fprintf(stderr, - gettext("%s: error reading configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - (void) printf("%s\n", buf); - } - - cfg_close(cfg); -} - - -static void -bitmapfs_delete(char *bitmapfs) -{ - CFGFILE *cfg; - char key[CFG_MAX_KEY], buf[CFG_MAX_BUF]; - int setnumber; - int commit = 0; - - cfg = cfg_open(NULL); - if (cfg == NULL) { - (void) fprintf(stderr, - gettext("%s: unable to access configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - if (!cfg_lock(cfg, CFG_WRLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - for (setnumber = 1; /*CSTYLED*/; setnumber++) { - (void) snprintf(key, sizeof (key), - "bitmaps.set%d.bitmap", setnumber); - buf[0] = 0; - - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - if (errno == ESRCH) { - /* end of list */ - (void) fprintf(stderr, - gettext("%s: %s not found " - "in configuration\n"), - progname, bitmapfs); - break; - } - - (void) fprintf(stderr, - gettext("%s: error reading configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - if (strcmp(bitmapfs, buf) == 0) { - (void) snprintf(key, sizeof (key), - "bitmaps.set%d", setnumber); - - if (cfg_put_cstring(cfg, key, (char *)NULL, 0) < 0) { - (void) fprintf(stderr, - gettext("%s: unable to delete %s " - "from configuration: %s\n"), - progname, bitmapfs, cfg_error(NULL)); - } else - commit++; - - break; - } - } - - if (commit) { - if (!cfg_commit(cfg)) { - (void) fprintf(stderr, - gettext("%s: unable to write " - "to configuration: %s\n"), - progname, cfg_error(NULL)); - } - commit = 0; - } - - cfg_close(cfg); -} - - -/* - * User visible configuration. - */ - -static const struct { - const char *tag; /* libcfg tag */ - const char *name; /* user presented name */ - const char *help; /* explanation string */ -} sdbc_cfg_options[] = { - { "thread", "nthreads", "number of threads" }, - { "size", "cache_size", "total cache size" }, -#ifdef DEBUG - { "write_cache", "write_cache_size", "write cache size" }, - { "fill_pattern", "fill_pattern", "debug fill pattern" }, - { "reserved1", "reserved1", "unavailable, do not use" }, - { "iobuf", "niobuf", "number of io buffers" }, - { "tdemons", "ntdeamons", "number of sd_test daemons" }, - { "forced_wrthru", "forced_wrthru", "override wrthru detection" }, - { "no_forced_wrthru", "no_forced_wrthru", "override wrthru"}, -#endif - { NULL } -}; - - -static int -configure_sdbc(int argc, char *argv[], int optind) -{ - CFGFILE *cfg; - char key[CFG_MAX_KEY], buf[CFG_MAX_BUF]; - char *cp, option[CFG_MAX_BUF], value[CFG_MAX_BUF]; - const int opt_width = 20; - int error, found, commit; - int i; - - error = commit = 0; - - cfg = cfg_open(NULL); - if (cfg == NULL) { - (void) fprintf(stderr, "%s: unable to open configuration: %s", - progname, cfg_error(NULL)); - return (1); - } - - if (argc == optind) { - /* display current user visible config */ - - if (!cfg_lock(cfg, CFG_RDLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - error = 1; - goto out; - } - - convert_config(cfg, CFG_RDLOCK); - - for (i = 0; sdbc_cfg_options[i].tag != NULL; i++) { - (void) snprintf(key, sizeof (key), - "scm.set1.%s", sdbc_cfg_options[i].tag); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - if (errno == ESRCH) { - /* not found */ - (void) strcpy(buf, ""); - } else { - (void) fprintf(stderr, - gettext("%s: error reading " - "configuration: %s\n"), - progname, cfg_error(NULL)); - error = 1; - goto out; - } - } - - (void) printf("%-*s: %-*s /* %s */\n", - opt_width, sdbc_cfg_options[i].name, - opt_width, buf, sdbc_cfg_options[i].help); - } - } else { - if (!cfg_lock(cfg, CFG_WRLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - error = 1; - goto out; - } - - convert_config(cfg, CFG_WRLOCK); - - for (/*CSTYLED*/; optind < argc; optind++) { - (void) strncpy(option, argv[optind], sizeof (option)); - option[sizeof (option) - 1] = '\0'; /* terminate */ - - cp = strchr(option, '='); - if (cp != NULL) { - *cp = '\0'; /* terminate option */ - cp++; - (void) strncpy(value, cp, sizeof (value)); - value[sizeof (value) - 1] = '\0'; - - if (*value == '\0') - (void) strncpy(value, "-", - sizeof (value)); - } - - found = 0; - for (i = 0; sdbc_cfg_options[i].tag != NULL; i++) { - if (strcmp(option, - sdbc_cfg_options[i].name) == 0) { - found = 1; - break; - } - } - - if (!found) { - (void) fprintf(stderr, - gettext("%s: unknown configuration " - "parameter: %s\n"), progname, option); - continue; - } - - (void) snprintf(key, sizeof (key), - "scm.set1.%s", sdbc_cfg_options[i].tag); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - (void) fprintf(stderr, - gettext("%s: error reading " - "configuration: %s\n"), - progname, cfg_error(NULL)); - error = 1; - goto out; - } - - if (*buf == '\0') - (void) strncpy(buf, "<default>", sizeof (buf)); - - if (cp != NULL) { - char *tmp; - long val; - /* set to new value */ - - if (strcmp(value, "-")) { /* default ? */ - - val = strtol(value, &tmp, 0); - if (strcmp(value, tmp) == 0) { - (void) fprintf(stderr, - gettext( - "%s: bad value (%s) " - "for option %s\n"), - progname, value, option); - error = 1; - goto out; - } - - /* make sure cache size is valid */ - if (strcmp(key, "scm.set1.size") == 0) { - if (val > MAX_CACHE_SIZE) { - PRINT_CACHE_SZ_ERR(val); - - /* - * Overwrite the - * cache size with - * the maximum cache - * size. - */ - (void) snprintf(value, - sizeof (value), - "%ld", - (long) - MAX_CACHE_SIZE); - } - } - } - - if (cfg_put_cstring(cfg, key, value, - strlen(value)) < 0) { - (void) fprintf(stderr, - gettext("\n%s: error writing " - "configuration: %s\n"), - progname, cfg_error(NULL)); - error = 1; - goto out; - } - - (void) snprintf(buf, sizeof (buf), - "%s = %s", buf, - (strcmp(value, "-") == 0) ? - "<default>" : value); - - commit = 1; - } - - (void) printf("%-*s: %-*s /* %s */\n", - opt_width, sdbc_cfg_options[i].name, - opt_width, buf, sdbc_cfg_options[i].help); - } /* end command line args */ - } - -out: - if (commit) { - if (!cfg_commit(cfg)) { - (void) fprintf(stderr, - gettext("%s: unable to write " - "to configuration: %s\n"), - progname, cfg_error(NULL)); - } - commit = 0; - - (void) printf("\n%s\n", - gettext("Changed configuration parameters " - "will take effect when the cache is restarted")); - } - - cfg_close(cfg); - return (error); -} - - -static char * -cd_to_device(int cd) -{ - static _sd_stats_t *cs_cur = NULL; - spcs_s_info_t ustatus; - - if (cs_cur == NULL) { - cs_cur = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - - if (cs_cur == NULL) { - (void) fprintf(stderr, gettext("%s malloc: %s\n"), - progname, strerror(errno)); - exit(1); - } - } - - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, - &ustatus) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: stats ioctl failed\n"), progname); - sdbc_report_error(&ustatus); - exit(1); - } - if (cs_cur->st_cachesize == 0 || cd >= cs_cur->st_count) - return (""); - - return (cs_cur->st_shared[cd].sh_filename); -} - -/* - * takes either either a string containing the cd or the device name, and - * returns the device name. - */ -static char * -get_device_name(char *arg) -{ - long cd = 0; - char *device; - - /* if the arg has a leading '/', assume it's a valid device name */ - if (!arg || *arg == '/') { - return (arg); - } - - /* treat the "all" keyword as a valid device name */ - if (strcmp(arg, "all") == 0) { - return (arg); - } - - /* - * Next, assume it's a cd, and try to convert it to an integer, and - * subsequently convert that cd to its corresponding device name. - * - * Since strtol returns 0 on failure, we need to make a special case - * for a cd of "0", which is valid. - */ - if (((cd = strtol(arg, (char **)NULL, 10)) > 0) || - strcmp(arg, "0") == 0) { - device = cd_to_device((int)cd); - - /* cd_to_device returns NULL or "" on failure--check both */ - if (device && (strcmp(device, ""))) { - /* it seems to be a valid device name */ - return (device); - } - } - - return (NULL); -} - -static void -remove_hint(char *device) -{ - CFGFILE *cfg; - char key[CFG_MAX_KEY], buf[CFG_MAX_BUF]; - int setnumber; - int rc; - - if ((cfg = cfg_open(NULL)) == NULL) { - (void) fprintf(stderr, - gettext("%s: unable to access configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - if (!cfg_lock(cfg, CFG_WRLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - for (setnumber = 1; /*CONSTCOND*/ TRUE; setnumber++) { - (void) snprintf(key, sizeof (key), "cache_hint.set%d.device", - setnumber); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - /* error or not found */ - break; - } - - if (strcmp(device, buf) != 0) - continue; - - /* remove config file entry */ - (void) snprintf(key, sizeof (key), - "cache_hint.set%d", setnumber); - rc = cfg_put_cstring(cfg, key, NULL, 0); - if (rc < 0) - (void) fprintf(stderr, - gettext("%s: unable to update configuration " - "storage: %s"), - progname, cfg_error(NULL)); - else if (!cfg_commit(cfg)) - (void) fprintf(stderr, - gettext("%s: unable to update configuration " - "storage: %s"), - progname, cfg_error(NULL)); - else - (void) fprintf(stderr, - gettext("%s: persistent hint for %s" - " removed from configuration\n"), - progname, device); - break; - } - cfg_close(cfg); -} - - -static void -save_hint(int cd, int hint, int flag) -{ - char device[NSC_MAXPATH]; - CFGFILE *cfg; - char key[CFG_MAX_KEY], buf[CFG_MAX_BUF]; - int setnumber; - int found; - int rc; - - if (hint != NSC_WRTHRU && hint != NSC_NOCACHE) - return; - - if (flag != 0 && flag != 1) - return; - - if ((cfg = cfg_open(NULL)) == NULL) { - (void) fprintf(stderr, - gettext("%s: unable to access configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - if (!cfg_lock(cfg, CFG_WRLOCK)) { - (void) fprintf(stderr, - gettext("%s: unable to lock configuration: %s\n"), - progname, cfg_error(NULL)); - exit(1); - } - - if (cd == -1) - (void) strcpy(device, "system"); - else - (void) strncpy(device, cd_to_device(cd), NSC_MAXPATH); - - found = 0; - for (setnumber = 1; /*CONSTCOND*/ TRUE; setnumber++) { - (void) snprintf(key, sizeof (key), "cache_hint.set%d.device", - setnumber); - if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) { - /* error or not found */ - break; - } - - if (strcmp(device, buf) == 0) { - found = 1; - break; - } - } - - if (found) { - if (hint == NSC_WRTHRU) - (void) snprintf(key, sizeof (key), - "cache_hint.set%d.wrthru", setnumber); - else /* NSC_NOCACHE */ - (void) snprintf(key, sizeof (key), - "cache_hint.set%d.nordcache", setnumber); - if (flag == 0) - rc = cfg_put_cstring(cfg, key, "0", 1); - else - rc = cfg_put_cstring(cfg, key, "1", 1); - } else { - (void) strncpy(buf, device, CFG_MAX_BUF); - if (flag == 0) - (void) strncat(buf, " 0 0", CFG_MAX_BUF); - else if (hint == NSC_WRTHRU) - (void) strncat(buf, " 1 0", CFG_MAX_BUF); - else /* NSC_NOCACHE */ - (void) strncat(buf, " 0 1", CFG_MAX_BUF); - rc = cfg_put_cstring(cfg, "cache_hint", buf, sizeof (buf)); - } - - if (rc < 0) - (void) fprintf(stderr, - gettext("%s: unable to update configuration storage: %s"), - progname, cfg_error(NULL)); - else if (!cfg_commit(cfg)) - (void) fprintf(stderr, - gettext("%s: unable to update configuration storage: %s"), - progname, cfg_error(NULL)); - cfg_close(cfg); -} - -#ifdef lint -int -scmadm_lintmain(int argc, char *argv[]) -#else -int -main(int argc, char *argv[]) -#endif -{ - int o = 0; - int c; - int errflg = 0; - int hflag = 0; - int qflag = 1; - extern int optind; - extern char *optarg; - int cd; - int hint; - int flag; - int optflag = 0; - spcs_s_info_t ustats; - int Dopt, Lopt; - int Oopt = 0; - char *bitmapfs = NULL; - const char *exclusive = gettext( - "-d, -e, -m, -o, -C, -D, -L, and -v " - "are mutually exclusive\n"); - - (void) setlocale(LC_ALL, ""); - (void) textdomain("scm"); - - progname = strdup(basename(argv[0])); - - sdbc_set_maxdev(); - - buildusage(progname); - - Dopt = Lopt = 0; - - while ((c = getopt(argc, argv, -#ifdef DEBUG - "gi:t:S" -#endif - "CD:LOa:devqhm:o:")) != EOF) { - - switch (c) { - - case 'D': - if (optflag) { - (void) fprintf(stderr, exclusive); - goto usage; - } - - Dopt++; - optflag++; - bitmapfs = optarg; - break; - - case 'L': - if (optflag) { - (void) fprintf(stderr, exclusive); - goto usage; - } - - Lopt++; - optflag++; - break; - -#ifdef DEBUG - case 'S': - if (optflag) { - (void) fprintf(stderr, exclusive); - goto usage; - } - - if (putenv(stats_usage) != 0) { - (void) fprintf(stderr, - gettext("%s: unable to putenv()\n"), - progname); - exit(1); - } - - argv[1] = "scmadm"; - if (execv(STATS_PATH, &argv[1]) == -1) { - (void) fprintf(stderr, - gettext("%s: failed to execute " STATS_PATH - "\n"), progname); - (void) fprintf(stderr, - gettext("Please be sure to copy sd_stats" - " from src/cmd/ns/sdbc in a development" - " workspace\n")); - } - exit(0); - break; -#endif - case 'a': - (void) strcpy(alert_file, optarg); - break; - case 'q': - qflag++; - break; - case 'O': /* restore hints */ - Oopt++; - break; - case 'C': /* configure */ - case 'e': /* enable */ - case 'd': /* disable */ - case 'v': /* get version */ - case 'o': /* get/set options */ - case 'm': /* get cd map */ -#ifdef DEBUG - case 't': /* trace */ - case 'i': /* inject_ioerr */ - case 'c': /* clear_ioerr */ - case 'g': /* toggle_flush */ -#endif - if (optflag) { - (void) fprintf(stderr, -#ifdef DEBUG - "%s%s", gettext("-t, -i, -c, -g, "), -#endif - exclusive); - - errflg++; - } - optflag++; - o = c; - break; - case 'h': - hflag = 1; - break; - case '?': - default: - errflg++; - break; - } - if (errflg || hflag) - goto usage; - } - - if (Oopt) { - /* Set hints saved in persistent configuration */ - restore_hints(); - exit(0); - } - if (Dopt || Lopt) { - /* bitmapfs control */ - - if (iscluster()) { - (void) fprintf(stderr, - gettext("%s: bitmap filesystems are not " - "allowed in a cluster\n"), progname); - goto usage; - } - - if ((Dopt + Lopt) > 1) { - (void) fprintf(stderr, gettext("-D and -L are" - "mutually exclusive\n")); - goto usage; - } - - if (Lopt) - bitmapfs_print(); - else /* if (Dopt) */ - bitmapfs_delete(bitmapfs); - - exit(0); - } - - if (!o) { - if (argc > 1) - goto usage; - (void) printf(gettext("%s: Printing all cd's and options:\n"), - progname); - print_all_options(); - } - - /* Configure */ - if (o == 'C') { - exit(configure_sdbc(argc, argv, optind)); - } - /* enable */ - if (o == 'e') { - enable_sdbc(); - if (qflag == 0) - sd_gather_alert_dumps(); - exit(0); - } - /* disable */ - if (o == 'd') { - disable_sdbc(); - exit(0); - } - /* get version */ - if (o == 'v') { - get_version(); - exit(0); - } - /* node_hint or cd_hint */ - if (o == 'o') { - if (!(strcoll(optarg, "system"))) { /* node_hint */ - if ((optind - 1) == (argc - 1)) { /* get */ - if ((hint = SDBC_IOCTL(SDBC_GET_NODE_HINT, 0, 0, - 0, 0, 0, &ustats)) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: get system " - "options failed\n"), - progname); - sdbc_report_error(&ustats); - exit(1); - } -#ifdef WRTHRU_HINTS - (void) printf(gettext("System Status: ")); - print_hint(hint, 1); -#endif - (void) printf(gettext("System Options: ")); - print_hint(hint, 0); - exit(0); - } else { /* set, clear */ - if (get_hint(argv[optind], &hint, &flag) == -1) - goto usage; - if (hint == -1) { - /* remove hint from config */ - remove_hint("system"); - exit(0); - } - - if (SDBC_IOCTL(SDBC_SET_NODE_HINT, hint, flag, - 0, 0, 0, &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set system " - "option failed\n"), - progname); - sdbc_report_error(&ustats); - exit(1); - } - save_hint(-1, hint, flag); - (void) printf(gettext("%s: System option %s" - " now set.\n"), progname, argv[optind]); - exit(0); - } - } else { /* cd_hint */ - cd = get_cd(optarg); - if ((optind - 1) == (argc - 1)) { /* get */ - if (cd < 0) { - (void) fprintf(stderr, - gettext("%s: device %s not " - "found\n"), - progname, optarg); - exit(1); - } - hint = get_cd_hint(cd); - (void) printf(gettext("%s: cd(%d) Current " - "options are: "), progname, cd); - print_hint(hint, 0); - exit(0); - } else { /* set, clear */ - if (get_hint(argv[optind], &hint, &flag) == -1) - goto usage; - if (hint == -1) { - /* remove hint from config */ - if (cd < 0) - remove_hint(optarg); - else - remove_hint(cd_to_device(cd)); - exit(0); - } - if (cd < 0) { - (void) fprintf(stderr, - gettext("%s: device %s not " - "found\n"), - progname, optarg); - exit(1); - } - - if (SDBC_IOCTL(SDBC_SET_CD_HINT, cd, hint, - flag, 0, 0, &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set option " - "failed\n"), progname); - sdbc_report_error(&ustats); - exit(1); - } - save_hint(cd, hint, flag); - (void) printf(gettext("%s: cd %d option %s now" - " set.\n"), progname, cd, argv[optind]); - exit(0); - } - } - } - - if (o == 'm') { /* "get_cd" = map */ - char *dev_name; - - if (!(strcoll(optarg, "all"))) /* all */ - (void) get_cd_all(); - else { - cd = get_cd(optarg); - if (cd < 0) { - (void) fprintf(stderr, - gettext("%s: device or cd %s not found\n"), - progname, optarg); - exit(1); - } - - if ((dev_name = get_device_name(optarg)) == NULL) { - (void) fprintf(stderr, gettext( - "%s: device for cd %d not found\n"), - progname, cd); - exit(1); - } - - (void) printf(gettext("%s: diskname %s; cd %d\n"), - progname, dev_name, cd); - exit(0); - } - } - -#ifdef DEBUG - if (o == 't') { /* "trace" */ - int flag, value; - _sdtr_table_t tt; - if ((optind+1) != (argc-1)) - goto usage; - cd = get_cd(argv[optind]); - if (cd < 0) { - (void) fprintf(stderr, - gettext("%s: device or cd %s not found\n"), - progname, argv[optind]); - exit(1); - } - - value = strtol(argv[optind+1], 0, 0); - if (!(strcoll(optarg, gettext("size")))) { - flag = SD_SET_SIZE; - tt.tt_max = value; - } else if (!(strcoll(optarg, gettext("mask")))) { - flag = SD_SET_MASK; - tt.tt_mask = value; - } else if (!(strcoll(optarg, gettext("lbolt")))) { - flag = SD_SET_LBOLT; - tt.tt_lbolt = value; - } else if (!(strcoll(optarg, gettext("good")))) { - flag = SD_SET_GOOD; - tt.tt_good = value; - } else goto usage; - - if (SDBC_IOCTL(SDBC_ADUMP, (long)cd, &tt, NULL, 0L, - (long)flag, &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: trace %s failed\n"), - progname, optarg); - sdbc_report_error(&ustats); - exit(1); - } - (void) printf(gettext("%s: trace %s processed\n"), - progname, optarg); - if (cd != -1) - (void) printf(gettext(" cd %d; size %d; mask 0x%04x; " - "lbolt %d; good %d;\n"), - cd, tt.tt_max, tt.tt_mask, - tt.tt_lbolt, tt.tt_good); - exit(0); - } - - if (o == 'i') { /* "inject_ioerr" */ - int ioj_err = EIO; - int cd; - int ioj_cnt = 0; - - /* a cd of "-1" represents all devices */ - if (strcmp(optarg, "-1") == 0) { - cd = -1; - } else if ((cd = get_cd(optarg)) < 0) { - (void) fprintf(stderr, - gettext("%s: device or cd %s not found\n"), - progname, optarg); - exit(1); - } - if (argc == 4) - ioj_err = strtol(argv[optind], 0, 0); - if (argc == 5) - ioj_cnt = strtol(argv[optind+1], 0, 0); - - if (SDBC_IOCTL(SDBC_INJ_IOERR, cd, ioj_err, ioj_cnt, 0, 0, - &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: i/o error injection for cd %s " - "failed\n"), progname, optarg); - sdbc_report_error(&ustats); - exit(1); - } - (void) printf(gettext("%s: i/o error injection cd %d errno %d " - "processed\n"), progname, cd, ioj_err); - exit(0); - } - - if (o == 'c') { /* "clear_ioerr" */ - int cd; - - /* a cd of "-1" represents all devices */ - if (strcmp(optarg, "-1") == 0) { - cd = -1; - } else if ((cd = get_cd(optarg)) < 0) { - (void) fprintf(stderr, - gettext("%s: device or cd %s not found\n"), - progname, optarg); - exit(1); - } - - if (SDBC_IOCTL(SDBC_CLR_IOERR, cd, 0, 0, 0, 0, &ustats) - == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: i/o error clear %s failed\n"), - progname, optarg); - sdbc_report_error(&ustats); - exit(1); - } - (void) printf(gettext("%s: i/o error clear for cd %d " - "processed\n"), progname, cd); - exit(0); - } - - if (o == 'g') { /* "toggle_flush" */ - flag = toggle_flush(); - (void) printf(gettext("%s: sdbc cache flush now %s\n"), - progname, flag ? "on" : "off"); - exit(0); - } -#endif /* DEBUG */ - - return (0); -usage: - (void) fprintf(stderr, "%s\n", scmadmUsage); - if (hflag) { - return (0); - } - return (1); -} - - -#define addusage(f__) \ - (void) strncat(scmadmUsage, f__, sizeof (scmadmUsage)); - -#define addusage1(f__, a__) \ - (void) snprintf(fmt, sizeof (fmt), "%s%s", scmadmUsage, f__); \ - (void) snprintf(scmadmUsage, sizeof (scmadmUsage), fmt, a__); - -#define addusage2(f__, a__, b__) \ - (void) snprintf(fmt, sizeof (fmt), "%s%s", scmadmUsage, f__); \ - (void) snprintf(scmadmUsage, sizeof (scmadmUsage), fmt, a__, b__); - -static void -buildusage(char *p) -{ - char fmt[USAGELEN]; -#ifdef WRTHRU_HINTS - char *hints_str = "[nordcache|rdcache|wrthru|nowrthru|forget]\n"; -#else - char *hints_str = "[nordcache|rdcache|forget]\n"; -#endif - - bzero(scmadmUsage, sizeof (scmadmUsage)); - bzero(fmt, sizeof (fmt)); - - addusage(gettext("Usage :\n")); - addusage1(gettext("\t%s\n"), p); - addusage1(gettext("\t%s -h\n"), p); - addusage1(gettext("\t%s -e\n"), p); - addusage1(gettext("\t%s -d\n"), p); - addusage1(gettext("\t%s -v\n"), p); - addusage1(gettext("\t%s {-L | -D bitmapfs}\n"), p); - addusage1(gettext("\t%s -C [parameter[=[value]] ...]\n"), p); - addusage2(gettext("\t%s -o system %s"), p, hints_str); - addusage2(gettext("\t%s -o <cd> %s"), p, hints_str); - addusage2(gettext("\t%s -o <diskname> %s"), p, hints_str); - addusage1(gettext("\t%s -m {<cd>|<diskname>|all}\n"), p); -#ifdef DEBUG - addusage1(gettext( - "\t%s -S [-Mz] [-d delay_time] [-l logfile] [-r range]\n"), p); - addusage1(gettext( - "\t%s -t {size|mask|lbolt|good} <cd|diskname> <value>\n"), p); - addusage1(gettext("\t%s -g\n"), p); - addusage1(gettext( - "\t%s -i {cd|diskname|-1 for all} [errno [countdown]]\n"), p); - addusage1(gettext("\t%s -c {cd|diskname|-1 for all}\n"), p); - addusage(gettext("\nt = trace\tg = toggle_flush\ti = inject ioerr\n" - "c = clear ioerr\tS = stats\n")); -#endif /* DEBUG */ - addusage(gettext( - "e = enable\td = disable\tv=version\to = get/ set options\n")); - addusage(gettext( - "m = get cd map\n")); - addusage1(gettext( - "note: cd is a cache descriptor integer in the range [0-%d]\n"), - sdbc_max_devices - 1); - addusage(gettext( - " bitmapfs is a block device or filesystem mount point\n")); - -#ifdef DEBUG - (void) snprintf(stats_usage, sizeof (stats_usage), - "SD_STATS_USAGE=%s", scmadmUsage); -#endif -} - -static int -get_hint(char *str, int *hint, int *flag) -{ -#ifdef WRTHRU_HINTS - if (!(strcoll(str, gettext("wrthru")))) { - *hint = NSC_WRTHRU; - *flag = 1; - return (0); - } else if (!(strcoll(str, gettext("nowrthru")))) { - *hint = NSC_WRTHRU; - *flag = 0; - return (0); - } else -#endif - if (!(strcoll(str, gettext("nordcache")))) { - *hint = NSC_NOCACHE; - *flag = 1; - return (0); - } else if (!(strcoll(str, gettext("rdcache")))) { - *hint = NSC_NOCACHE; - *flag = 0; - return (0); - } else if (!(strcoll(str, gettext("forget")))) { - *hint = -1; - *flag = 0; - return (0); - } - return (-1); -} - -/*ARGSUSED*/ -void -print_hint(const uint_t type, const int status) -{ -#ifdef WRTHRU_HINTS - if (status) { - if (type & NSC_FORCED_WRTHRU) { - (void) printf(gettext("Fast Writes Overridden\n")); - } else { - /* if (type & NSC_NO_FORCED_WRTHRU) */ - (void) printf(gettext("default\n")); - } - } else { - (void) printf("%swrthru, %srdcache", - (type & (NSC_FORCED_WRTHRU|NSC_WRTHRU)) ? "" : "no", - (type & NSC_NOCACHE) ? "no" : ""); -#else - { - (void) printf("%srdcache", (type & NSC_NOCACHE) ? "no" : ""); -#endif - - if (type & 0x80000000) - (void) printf(" (overridden by system)"); - - (void) printf("\n"); - } -} - -/* - * Read the configuration via libcfg - */ - -int -get_cache_config() -{ - int i; - int sysid; - CFGFILE *cfg; - char buf[CFG_MAX_BUF]; - char key[CFG_MAX_KEY]; - - - if ((cfg = cfg_open(NULL)) == NULL) { - (void) fprintf(stderr, - gettext("Cannot open configuration file\n")); - exit(1); - } - - if (!cfg_lock(cfg, CFG_RDLOCK)) { - (void) fprintf(stderr, - gettext("Cannot lock configuration file\n")); - exit(1); - } - - convert_config(cfg, CFG_RDLOCK); - (void) memset((char *)&user_level_conf, 0, sizeof (_sd_cache_param_t)); - - /* Get the system ID */ - if (nsc_getsystemid(&sysid) < 0) { - (void) fprintf(stderr, - gettext("%s Unable to obtain subsystem ID: %s\n"), - progname, strerror(errno)); - exit(1); - } - myid = sysid; - - user_level_conf.blk_size = 8192; /* DEFAULT */ - user_level_conf.procs = 16; /* DEFAULT */ - user_level_conf.reserved1 = RESERVED1_DEFAULTS; - - bzero(buf, CFG_MAX_BUF); - (void) snprintf(key, sizeof (key), "scm.set1.thread"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - user_level_conf.threads = atoi(buf); - } else - user_level_conf.threads = 128; /* DEFAULT */ - - (void) snprintf(key, sizeof (key), "scm.set1.tdemons"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - user_level_conf.test_demons = atoi(buf); - } - - (void) snprintf(key, sizeof (key), "scm.set1.write_cache"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - user_level_conf.write_cache = atoi(buf); - } - - (void) snprintf(key, sizeof (key), "scm.set1.size"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - /* - * We need to run strtol for backwards compatibility in 3.2. - * A workaround for this bug was put in 3.2 which allowed - * customers to set the cache size up to 1024 if it was - * specified in hexadecimal. Decimal still had the limit - * of 128. This change treats them both identically. - */ - user_level_conf.cache_mem[0] = (int)strtol(buf, NULL, 0); - if (user_level_conf.cache_mem[0] > MAX_CACHE_SIZE) { - (void) fprintf(stderr, gettext( - "The cache size of %ld is larger than " - "the system maximum of %ld.\nUse \"scmadm -C " - "cache_size=<size>\" to set the size to a proper " - "value.\n"), - user_level_conf.cache_mem[0], MAX_CACHE_SIZE); - user_level_conf.cache_mem[0] = MAX_CACHE_SIZE; - } - } - - (void) snprintf(key, sizeof (key), "scm.set1.iobuf"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - user_level_conf.iobuf = atoi(buf); - } - - (void) snprintf(key, sizeof (key), "scm.set1.fill_pattern"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - user_level_conf.fill_pattern = atoi(buf); - user_level_conf.gen_pattern = 1; - } - - (void) snprintf(key, sizeof (key), "scm.set1.no_forced_wrthru"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - no_forced_wrthru = atoi(buf); - } - - (void) snprintf(key, sizeof (key), "scm.set1.forced_wrthru"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - forced_wrthru = atoi(buf); - } - - (void) snprintf(key, sizeof (key), "scm.set1.reserved1"); - if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) > 0) { - user_level_conf.reserved1 = atoi(buf); - } - - cfg_close(cfg); - - /* - * use the default minidsp configuration if no - * node/mirror/remote-mirror/cluster line is in the sd.cf file - */ - if (nodes_configured == 0) - check_and_set_mirrors(myid, _SD_NO_HOST); - - - /* Check if our sysid was defined */ - if (!node_defined[myid]) { - (void) fprintf(stderr, - gettext("This node(%d) is not defined in config.\n"), myid); - exit(1); - } - - /* - * Save off number of nodes so we can calculate the point-to-point - * segements. Code in kernel currently supports MAX_SD_NODES - */ - if ((user_level_conf.num_nodes = nodes_configured) > - MAX_SD_NODES) { - (void) fprintf(stderr, - gettext("Cache can support only %d nodes(%d).\n"), - MAX_SD_NODES, nodes_configured); - exit(1); - } - - if ((nodes_configured % 2) && !minidsp) { - if (nodes_configured == 1) - (void) fprintf(stderr, - gettext("Only one node configured, " - "mirror node must be %d\n"), _SD_NO_HOST); - else - (void) fprintf(stderr, - gettext("Cannot configure odd number of nodes.\n")); - exit(1); - } - - - /* Pass List of Nodes Configured to Cache */ - for (i = 0; i < nodes_configured; i++) - user_level_conf.nodes_conf[i] = nodes_conf[i]; - - /* Place magic number in user_level_conf. Kernel will test for it */ - user_level_conf.magic = _SD_MAGIC; - (void) sleep(1); - return (0); -} - -_sdtr_t hdr; - -/* function name string */ -char * -_sd_fname(int f) -{ - int fn = f & ST_FUNC; - static char c[8]; - char *s; - - if (f & ST_BCACHE) - s = _bcache_fname[fn]; - else if (f & ST_BSUB) - s = _bsub_fname[fn]; - else if (f & ST_IO) - s = _io_fname[fn]; - else if (f & ST_STATS) - s = _stats_fname[fn]; - else if (f & ST_CCIO) - s = _ccio_fname[fn]; - else if (f & ST_FT) - s = _ft_fname[fn]; - else if (f & ST_INFO) - s = _info_fname[fn]; - if (!s) - (void) sprintf(s = c, "0x%04x", f & 0xffff); - return (s); -} - -int alerts = 0; - -/* - * Background daemon to wait for alert (on any device) - * Writes the traces to "sd_alert.CD.NUM", - * and writes an information message to the alert_file. - */ - -void -sd_gather_alert_dumps() -{ - _sdtr_table_t tt; - _sdtr_t *buf; - int cd, count, size, flag; - char filename[64]; - int fd; - time_t tloc; - struct tm tm_storage; - struct tm *tm_ptr; - char timebuf[80]; - spcs_s_info_t ustats; - - /* fork and detach daemon */ - if (fork()) - exit(0); - (void) close(0); - fd = open(alert_file, O_WRONLY|O_APPEND|O_CREAT, 0644); - if (fd == -1) - fd = open("/dev/console", O_WRONLY); - if (fd != -1) { - (void) dup2(fd, 1); - (void) dup2(fd, 2); - (void) close(fd); - } - (void) setsid(); - - size = 10000; - if (size < user_level_conf.trace_size) - size = user_level_conf.trace_size; - - buf = (_sdtr_t *)malloc(size * sizeof (_sdtr_t)); - if (!buf) { - (void) fprintf(stderr, gettext("%s malloc: %s\n"), - progname, strerror(errno)); - exit(1); - } - tloc = time(NULL); - tm_ptr = (struct tm *)localtime_r(&tloc, &tm_storage); - -loop: - cd = SDT_ANY_CD; /* any device */ - flag = SD_ALERT_WAIT; /* block for alert */ - if ((count = SDBC_IOCTL(SDBC_ADUMP, cd, &tt, buf, size, - flag, &ustats)) == SPCS_S_ERROR) { - (void) fprintf(stderr, gettext("%s: sd_adump\n"), progname); - sdbc_report_error(&ustats); - if (errno == EIDRM) { - (void) strftime(timebuf, 80, "%x %X", tm_ptr); - (void) fprintf(stderr, - gettext("%s: cache deconfigured at %s\n"), - progname, timebuf); - exit(0); - } - if (errno == ENOSYS) - exit(0); - exit(errno); - } - if (count == 0) - goto loop; - cd = tt.tt_cd; - (void) sprintf(filename, "%s.%d.%d", "sd_alert", cd, alerts++); - if ((fd = open(filename, O_CREAT | O_RDWR, 0444)) == -1) { - (void) fprintf(stderr, gettext("%s: open: %s\n"), - progname, strerror(errno)); - exit(errno); - } - /* - * write header to identify device, write entries - */ - hdr.t_func = SDF_CD; - hdr.t_len = count; - hdr.t_ret = tt.tt_cd; - if (write(fd, &hdr, sizeof (_sdtr_t)) == -1) { - (void) fprintf(stderr, gettext("%s: write: %s\n"), - progname, strerror(errno)); - exit(errno); - } - - if (write(fd, buf, sizeof (_sdtr_t)*count) == -1) { - (void) fprintf(stderr, gettext("%s: write: %s\n"), - progname, strerror(errno)); - exit(errno); - } - (void) close(fd); - - (void) strftime(timebuf, 80, "%x %X", tm_ptr); - (void) printf("sd alert trace dump %s at %s\n", filename, timebuf); - goto loop; -} - - - -/* - * print list of configured cd's, diskname, options and global options - */ -void -print_all_options() -{ - static _sd_stats_t *cs_cur; - spcs_s_info_t ustats; - int cd; - int hint; - char *s1 = "device name"; - char *s2 = "option"; - char fn[19]; - int len; - - /* No corresponding free because this function exits */ - cs_cur = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - if (cs_cur == NULL) { - (void) fprintf(stderr, gettext("%s malloc: %s\n"), - progname, strerror(errno)); - exit(1); - } - - /* node hints */ - if ((hint = SDBC_IOCTL(SDBC_GET_NODE_HINT, 0, 0, 0, 0, 0, - &ustats)) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: get system option failed\n"), - progname); - sdbc_report_error(&ustats); - exit(1); - } -#ifdef WRTHRU_HINTS - (void) printf(gettext("System Status: ")); - print_hint(hint, 1); -#endif - (void) printf(gettext("System Options: ")); - print_hint(hint, 0); - - /* get cds */ - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) - == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: get_cd failed in print_all options\n"), - progname); - sdbc_report_error(&ustats); - exit(1); - } - if (cs_cur->st_cachesize == 0) - (void) printf(gettext("Cache is disabled\n")); - else if (cs_cur->st_count == 0) - (void) printf(gettext("No devices are configured\n")); - else { - (void) printf( - gettext("\nConfigured cd's, disknames and options: \n")); - (void) printf(gettext("cd\t%-28s\t%-20s\n"), s1, s2); - for (cd = 0; cd < cs_cur->st_count; cd++) { - if (cs_cur->st_shared[cd].sh_alloc) { - hint = get_cd_hint(cd); - if ((len = - strlen(cs_cur->st_shared[cd].sh_filename)) - > 23) { - (void) strcpy(fn, "..."); - (void) strcat(fn, - cs_cur->st_shared[cd].sh_filename + - len - 20); - } else { - (void) strcpy(fn, - cs_cur->st_shared[cd].sh_filename); - } - - (void) printf(gettext("%d\t%-28.*s\t"), cd, - NSC_MAXPATH, fn); - - print_hint(hint, 0); - } - } - } - exit(0); -} - - -/* - * cache device -- lookup names and cache descriptors of all configured devices - */ -void -get_cd_all() -{ - static _sd_stats_t *cs_cur; - spcs_s_info_t ustats; - int cd; - char fn[19]; - int len; - - /* No corresponding free because this function exits */ - cs_cur = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - if (cs_cur == NULL) { - (void) fprintf(stderr, gettext("%s malloc: %s\n"), - progname, strerror(errno)); - exit(1); - } - - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) - == SPCS_S_ERROR) { - (void) fprintf(stderr, gettext("%s: get_cd_all"), - progname); - sdbc_report_error(&ustats); - exit(1); - } - if (cs_cur->st_cachesize == 0) - (void) printf(gettext("Cache is disabled\n")); - else if (cs_cur->st_count == 0) - (void) printf(gettext("No devices are configured\n")); - else { - (void) printf(gettext("\tcd\tdevice name\n")); - for (cd = 0; cd < cs_cur->st_count; cd++) { - if (cs_cur->st_shared[cd].sh_alloc) { - if ((len = strlen( - cs_cur->st_shared[cd].sh_filename)) > 15) { - (void) strcpy(fn, "..."); - (void) strcat(fn, - cs_cur->st_shared[cd].sh_filename + - len - 12); - } else { - (void) strcpy(fn, - cs_cur->st_shared[cd].sh_filename); - } - (void) printf(gettext("\t%d\t%s\n"), - cd, fn); - } - } - } - exit(0); -} - -/* - * cache device -- specified by number or lookup name - */ -static int -get_cd(char *s) -{ - static _sd_stats_t *cs_cur = NULL; - spcs_s_info_t ustats; - int cd, arg_cd = -1; - - if (cs_cur == NULL) { - /* - * No corresponding free because the memory is reused - * every time the function is called. - */ - cs_cur = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - if (cs_cur == NULL) { - (void) fprintf(stderr, gettext("%s malloc: %s\n"), - progname, strerror(errno)); - exit(1); - } - } - - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) - == SPCS_S_ERROR) { - (void) fprintf(stderr, gettext("%s: get_cd\n"), progname); - sdbc_report_error(&ustats); - exit(1); - } - if (cs_cur->st_cachesize == 0) { - (void) printf(gettext("Cache is disabled\n")); - exit(0); - } - - if (*s != '/') { - /* - * Since strtol returns 0 on failure, we need to make a - * special case for a cd of "0", which is valid. - * - * This case also deals with the difference between - * scmadm -o system and scmadm -o 0 - */ - if (((int)strtol(s, (char **)NULL, 10) == 0) && - strcmp(s, "0")) - return (-1); - - /* - * Only return failure at this point, in order to allow - * checking arg_cd against st_count later on. - */ - if ((arg_cd = strtol(s, 0, 0)) < 0) { - return (arg_cd); - } - } - - /* make sure the cd passed as an argument is alloc'd and < st_count */ - if (arg_cd >= 0) { - return (((arg_cd < cs_cur->st_count) && - (cs_cur->st_shared[arg_cd].sh_alloc)) ? arg_cd : -1); - } - - for (cd = 0; cd < cs_cur->st_count; cd++) { - if (cs_cur->st_shared[cd].sh_alloc && - strcmp(s, cs_cur->st_shared[cd].sh_filename) == 0) - return (cd); - } - return (-1); -} - -void -check_and_set_mirrors(int node, int mirror) -{ - - if (minidsp) { - (void) fprintf(stderr, - gettext("%s: minidsp defined. " - "Cannot define other nodes.\n"), - progname); - exit(1); - } - - if (mirror == _SD_NO_HOST) { - minidsp++; - } else if ((!(node % 2) && !(node == mirror - 1)) || - (((node % 2) && !(node == mirror + 1)))) { - (void) fprintf(stderr, - gettext("%s: Node and Mirror identification values " - "must be consecutive\n" - "starting at an even number (Node = %d Mirror = %d)\n"), - progname, node, mirror); - exit(1); - } - - node_defined[node]++; - - nodes_conf[nodes_configured] = node; - nodes_configured++; - - if (node == myid) { - user_level_conf.mirror_host = mirror; - } -} - -char *mem_string = - "%-8s Structures use approx. %8d bytes (%5d pages) of memory\n"; - -void -enable_sdbc() -{ - spcs_s_info_t ustats; - - if (get_cache_config()) { - (void) fprintf(stderr, - gettext("%s: unable to read configuration file\n"), - progname); - exit(1); - } - - if (SDBC_IOCTL(SDBC_ENABLE, &user_level_conf, 0, 0, 0, 0, - &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, gettext("%s: cache enable failed\n"), - progname); - spcs_log("scm", &ustats, gettext("%s cache enable failed"), - progname); - sdbc_report_error(&ustats); - exit(1); - } - spcs_log("scm", NULL, gettext("%s cache enable succeeded"), - progname); -#ifdef DEBUG - (void) printf(gettext("%s: cache has been configured\n"), progname); -#endif -#ifdef WRTHRU_HINTS - if (iscluster()) { - /* Must writethru on a cluster, even if nvram configured */ - forced_wrthru = 1; - } - - if (minidsp && forced_wrthru != -1) { - /* Have minidsp with forced_wrthru hint. Set / Clear hint */ - if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_FORCED_WRTHRU, - forced_wrthru, 0, 0, 0, &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set/clear forced_wrthru failed\n"), - progname); - sdbc_report_error(&ustats); - } else if (forced_wrthru) { - (void) printf(gettext("%s: Node option forced_wrthru " - "now set.\n"), progname); - } else { - (void) printf(gettext("%s: Node option forced_wrthru " - "now cleared.\n"), progname); - } - } - if (no_forced_wrthru != -1) { - if (SDBC_IOCTL(SDBC_SET_NODE_HINT, NSC_NO_FORCED_WRTHRU, - no_forced_wrthru, 0, 0, 0, &ustats) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: set/clear no_forced_wrthru " - "failed\n"), progname); - sdbc_report_error(&ustats); - } else if (no_forced_wrthru) { - (void) printf(gettext("%s: Node option no_forced_wrthru" - " now set.\n"), progname); - } else { - (void) printf(gettext("%s: Node option no_forced_wrthru" - " now cleared.\n"), progname); - } - } -#endif - - /* do scmadm -O to cater for manual cache disable then enable */ - restore_hints(); -} - -void -disable_sdbc() -{ - spcs_s_info_t ustats; - - if (SDBC_IOCTL(SDBC_DISABLE, 0, 0, 0, 0, 0, &ustats) != SPCS_S_OK) { - /* - * If it wasn't already enabled, don't appear to fail - * or users of this program might think the cache is - * configured, when it actually isn't. - */ - if (errno != SDBC_EDISABLE) { - spcs_log("scm", &ustats, - gettext("%s cache disable failed"), progname); - sdbc_report_error(&ustats); - exit(1); - } - } -#ifdef DEBUG - (void) printf(gettext("%s: cache has been deconfigured\n"), progname); -#endif - spcs_log("scm", NULL, gettext("%s cache disable succeeded"), - progname); -} - -static void -get_version() -{ - cache_version_t version; - spcs_s_info_t ustats; - - if (SDBC_IOCTL(SDBC_VERSION, &version, 0, 0, 0, 0, &ustats) == - SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: get cache version failed\n"), progname); - sdbc_report_error(&ustats); - exit(1); - } -#ifdef DEBUG - (void) printf(gettext("Cache version %d.%d.%d.%d\n"), - version.major, version.minor, version.micro, version.baseline); -#else - if (version.micro) { - (void) printf(gettext("Cache version %d.%d.%d\n"), - version.major, version.minor, version.micro); - } else { - (void) printf(gettext("Cache version %d.%d\n"), - version.major, version.minor); - } -#endif -} - -#ifdef DEBUG -int -toggle_flush(void) -{ - int rc; - spcs_s_info_t ustats; - - if ((rc = SDBC_IOCTL(SDBC_TOGGLE_FLUSH, 0, 0, 0, - 0, 0, &ustats)) == SPCS_S_ERROR) { - (void) fprintf(stderr, - gettext("%s: toggle sdbc cache flush failed\n"), - progname); - sdbc_report_error(&ustats); - exit(1); - } - return (rc); -} -#endif diff --git a/usr/src/cmd/avs/sdbc/sd_diag.c b/usr/src/cmd/avs/sdbc/sd_diag.c deleted file mode 100644 index 706f547226..0000000000 --- a/usr/src/cmd/avs/sdbc/sd_diag.c +++ /dev/null @@ -1,1169 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2010 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* #include <version.h> SKK */ -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/param.h> -#include <sys/inttypes.h> -#include <stdio.h> -#include <strings.h> -#include <fcntl.h> -#include <sys/shm.h> -#include <sys/wait.h> -#include <unistd.h> -#include <nsctl.h> - -#include <sys/nsctl/sd_cache.h> -#include <sys/nsctl/sd_conf.h> - -#include <stdlib.h> -#include <thread.h> -#include <synch.h> - -#define MAXPARTS 100 /* Max disks */ -#define MAXBUF 65536 /* Max buffer size in long words */ -#define DISKLIST "disk_config" /* Default config file */ -#define DEF_SIZE 8192 /* Default buffer size */ -#define DEF_LOOP 1000 /* Loops for test */ -#define RAND_LOOPS DEF_LOOP /* # of random ios to do */ - -/* - * >>>>>>>>> USER LEVEL SD CACHE DIAGNOSTICS <<<<<<<<<< - * - * Write and read data blocks w/multiple processes - * Starts one process for each partition specified in - * the config file - */ - -int buf1[MAXBUF]; -int buf2[MAXBUF]; -char name[MAXPARTS][80]; -int pattern[MAXPARTS]; -int bufsize = DEF_SIZE; -int fba_num_bufsize; -nsc_size_t loops = DEF_LOOP; -nsc_size_t r_loops = RAND_LOOPS; -int fsize = -1; -int readercount = 3; -int Rflag = O_EXCL; -char config_file[32]; - -int -read_parts() -{ - FILE *dfile; - int partitions = 0; - int i; - - dfile = fopen(config_file, "r"); - if (dfile == NULL) { - (void) printf("cannot open file: %s\n", config_file); - perror("fopen"); - exit(errno); - } - for (i = 0; i < MAXPARTS; i++) { - if (fscanf(dfile, "%s %x", name[i], (uint_t *)&pattern[i]) == - EOF) { - break; - } else - if (name[i][0] == '#' || strchr(name[i], '/') == NULL) { - i--; - continue; - } - partitions++; - } - (void) fclose(dfile); - (void) printf("No. of partitions listed in file '%s' = %d\n\n", - config_file, partitions); - return (partitions); -} - -void -print_usage() -{ - (void) printf("Usage:\n"); - (void) printf( -"sd_diag [-R] [-b <bufsize>] [-d <datasize>] [-l <loops>] [-r <readers>]\n"); - (void) printf( -" [-f <disk_config_file>] <test#>\n"); - (void) printf(" test 1 = random read/write\n"); - (void) printf(" 2 = random read/write/verify, read after write\n"); - (void) printf(" 3 = random read/write/verify,"); - (void) printf(" all reads after all writes\n"); - (void) printf(" 4 = sequential read/write\n"); - (void) printf(" 5 = sequential write/read/verify,"); - (void) printf(" all reads after all writes\n"); - (void) printf( - " 6 = altenating top/bottom sequential read/write/verify\n"); - (void) printf(" 7 = multiple readers/1 random writer\n"); - (void) printf(" 8 = random writes\n"); - (void) printf(" 9 = sequential write of known data\n"); - (void) printf(" 10 = sequential copy of datasize disk/verify\n"); - (void) printf(" 11 = sequential read/verify test 9 data -"); - (void) printf(" then clear data with timestamp\n"); - (void) printf(" 12 = sequential read/verify test 9 data -"); - (void) printf(" no clear data\n"); - (void) printf("\n"); - (void) printf(" <bufsize> in bytes (minimum is 512 bytes)\n"); - (void) printf(" <datasize> in Mbytes per disk\n"); - (void) printf(" <loops> is count of reads/writes,\n"); - (void) printf(" loops = 0 tests entire datasize disk"); - (void) printf(" for sequential tests.\n"); - (void) printf(" loops = 0 performs %d I/Os for the random " - "tests\n", RAND_LOOPS); - (void) printf(" <readers> is count of readers for test #7 (default " - "is 3).\n"); - (void) printf(" [ defaults: bufsize = %d bytes, loops = %d,", - DEF_SIZE, DEF_LOOP); - (void) printf(" datasize = disksize ]\n"); - (void) printf("\n"); - (void) printf(" -R : do nsc_reserve(), nsc_release(0 around each " - "I/O\n"); -} - -void -parse_opts(int argc, char *argv[]) -{ - extern char *optarg; - int c; - - while ((c = getopt(argc, argv, "b:d:l:r:Rf:")) != -1) { - switch (c) { - case 'f': - /* printf("\n%s", optarg); */ - (void) strcpy(config_file, optarg); - break; - case 'b': - /* bufsize between 1*512 and 512*512 */ - bufsize = strtol(optarg, 0, 0); - if (bufsize > (MAXBUF*4)) - bufsize = MAXBUF*4; - else if (bufsize < FBA_SIZE(1)) - bufsize = FBA_SIZE(1); - break; - case 'd': - /* convert datasize from Mb's to fba */ - fsize = strtol(optarg, 0, 0) * FBA_NUM(1 << 20); - break; - case 'l': - loops = (nsc_size_t)strtoll(optarg, 0, 0); - break; - case 'r': - /* count of readers for test 7 */ - readercount = strtol(optarg, 0, 0); - break; - case 'R': - /* do reserve, release on a per io basis */ - Rflag = 0; - break; - case '?': - print_usage(); - exit(0); - } - } - bufsize &= ~FBA_MASK; /* multiple of 512 bytes for SECTMODE I/O */ - fba_num_bufsize = FBA_NUM(bufsize); - - /* set #ios for random io tests */ - if (loops != 0) - r_loops = loops; - -} - -nsc_size_t -set_part_size(char *path, nsc_fd_t *sdfd) -{ - nsc_size_t filesize; - int rc; - - rc = nsc_partsize(sdfd, &filesize); /* partsize in FBAs (512 bytes) */ - if (rc < 0 || filesize == 0) { - (void) fprintf(stderr, - "set_part_size: cannot access partition size"); - (void) fprintf(stderr, " for %s\n", path); - (void) nsc_close(sdfd); - exit(1); - } - - (void) printf("Partition %s, size:%" NSC_SZFMT " blocks\n", path, - filesize); - - if (fsize != -1 && fsize < filesize) - filesize = fsize; - filesize -= fba_num_bufsize; - if (filesize < fba_num_bufsize) { - (void) printf("ERROR: Max block size %" NSC_SZFMT "\n", - filesize); - (void) nsc_close(sdfd); - exit(0); - } - - return (filesize); -} - -int -do_sdtest1(int fd, nsc_size_t loops, nsc_size_t filesize) -{ - nsc_off_t seekpos; - nsc_size_t i; - ssize_t r; - - for (i = 0; i < loops; i++) { - seekpos = ( -#ifdef NSC_MULTI_TERABYTE - ((nsc_off_t)rand() << 48) | ((nsc_off_t)rand() << 32) | -#endif - (rand() << 16) | rand()) % filesize; - r = pwrite(fd, buf1, bufsize, (off_t)(seekpos << SCTRSHFT)); - if (r <= 0) { - perror("Test1: write"); - return (1); - } - seekpos = ( -#ifdef NSC_MULTI_TERABYTE - ((nsc_off_t)rand() << 48) | ((nsc_off_t)rand() << 32) | -#endif - (rand() << 16) | rand()) % filesize; - r = pread(fd, buf2, bufsize, (off_t)(seekpos << SCTRSHFT)); - if (r <= 0) { - perror("Test1: read"); - return (1); - } - } - return (0); -} - -void -gen_data(int *buffer, int size) -{ - int i; - - size /= 4; - for (i = 0; i < size; i++) - buffer[i] = rand() << 16 | rand(); -} - -int -do_sdtest2(int fd, nsc_size_t loops, nsc_size_t filesize, int h) -{ - nsc_off_t seekpos; - int err = 0; - ssize_t r; - nsc_size_t i; - - for (i = 0; i < loops; i++) { - seekpos = ( -#ifdef NSC_MULTI_TERABYTE - ((nsc_off_t)rand() << 48) | ((nsc_off_t)rand() << 32) | -#endif - (rand() << 16) | rand()) % filesize; - gen_data(buf1, bufsize); - r = pwrite(fd, buf1, bufsize, (off_t)(seekpos << SCTRSHFT)); - if (r <= 0) { - perror("Test2: write"); - err++; - return (err); - } - r = pread(fd, buf2, bufsize, (off_t)(seekpos << SCTRSHFT)); - if (r <= 0) { - perror("Test2: read"); - err++; - return (err); - } - if (memcmp(buf1, buf2, bufsize)) { - (void) printf("Test2: Data corruption," - " fd:%s, fpos:%" PRId64 ", len:%d\n", - name[h], (int64_t)(seekpos << SCTRSHFT), - bufsize); - err++; - } - } - return (err); -} - -int -do_sdtest3(int fd, nsc_size_t loops, nsc_size_t filesize, int h, nsc_fd_t *sdfd) -{ - nsc_off_t *seekpos; - int err = 0; - nsc_size_t i; - ssize_t r; - - seekpos = malloc(loops*sizeof (nsc_off_t)); - if (seekpos == NULL) { - perror("Test3: malloc"); - (void) nsc_close(sdfd); - exit(errno); - } - gen_data(buf1, bufsize); - - for (i = 0; i < loops; i++) { - seekpos[i] = ( -#ifdef NSC_MULTI_TERABYTE - ((nsc_off_t)rand() << 48) | ((nsc_off_t)rand() << 32) | -#endif - (rand() << 16) | rand()) % filesize; - seekpos[i] -= seekpos[i] % fba_num_bufsize; - r = pwrite(fd, buf1, bufsize, (off_t)(seekpos[i] << SCTRSHFT)); - if (r <= 0) { - perror("Test3: write"); - err++; - goto cleanup; - } - } - for (i = 0; i < loops; i++) { - buf2[0] = '\0'; /* clear buf to make sure something is read */ - r = pread(fd, buf2, bufsize, (off_t)(seekpos[i] << SCTRSHFT)); - if (r <= 0) { - perror("Test3: read"); - err++; - goto cleanup; - } - if (memcmp(buf1, buf2, bufsize)) { - (void) printf("Data corruption, fd:%s, fpos:%" PRId64 - ", len:%d\n", name[h], - (int64_t)(seekpos[i] << SCTRSHFT), bufsize); - err++; - } - } - -cleanup: - free(seekpos); - return (err); -} - -int -do_sdtest4(int fd, nsc_size_t loops, nsc_size_t filesize) -{ - ssize_t r; - nsc_size_t i; - - /* - * Do sequential reads/writes for loops number - * of bufsize chunks, unless loops == 0, then do - * entire disk. - * 1. sequential reads from the top down, - * 2. sequential writes from the top down, - * 3. sequential reads from the bottom up, - * 4. sequential writes from the bottom up. - */ - if ((loops > (filesize / fba_num_bufsize)) || (!loops)) - loops = filesize / fba_num_bufsize; /* entire disk */ - - for (i = 0; i < loops; i++) { - r = pread(fd, buf2, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test4: read"); - return (1); - } - } - for (i = 0; i < loops; i++) { - r = pwrite(fd, buf1, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test4: write"); - return (1); - } - } - for (i = loops - 1; i + 1 > 0; i--) { - r = pread(fd, buf2, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test4: read"); - return (1); - } - } - for (i = loops - 1; i + 1 > 0; i--) { - r = pwrite(fd, buf1, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test4: write"); - return (1); - } - } - return (0); -} - -int -do_sdtest5(int fd, nsc_size_t loops, nsc_size_t filesize, int h) -{ - int err = 0; - ssize_t r; - nsc_size_t i; - - /* - * Do sequential writes with verify reads for loops number - * of bufsize chunks, unless loops == 0, then do - * entire disk. - * 1. sequential writes from the top down, - * 2. sequential reads from the top down with verify, - * 3. sequential writes from the bottom up, - * 4. sequential reads from the bottom up with verify. - */ - if ((loops > (filesize / fba_num_bufsize)) || (!loops)) - loops = filesize / fba_num_bufsize; /* entire disk */ - - gen_data(buf1, bufsize); - - for (i = 0; i < loops; i++) { - r = pwrite(fd, buf1, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test5: write"); - err++; - return (err); - } - } - for (i = 0; i < loops; i++) { - buf2[0] = '\0'; /* clear buf to make sure something is read */ - r = pread(fd, buf2, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test5: read"); - err++; - return (err); - } - if (memcmp(buf1, buf2, bufsize)) { - (void) printf("Test5: Data corruption," - " fd:%s, fpos:%" NSC_SZFMT ", len:%d\n", - name[h], i, bufsize); - err++; - } - } - - gen_data(buf1, bufsize); - - for (i = loops - 1; i + 1 > 0; i--) { - r = pwrite(fd, buf1, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test5: write"); - err++; - return (err); - } - } - for (i = loops - 1; i + 1 > 0; i--) { - buf2[0] = '\0'; /* clear buf to make sure something is read */ - r = pread(fd, buf2, bufsize, (i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test5: read"); - err++; - return (err); - } - if (memcmp(buf1, buf2, bufsize)) { - (void) printf("Test5: Data corruption," - " fd:%s, fpos:%" NSC_SZFMT ", len:%d\n", - name[h], i, bufsize); - err++; - } - } - return (err); -} - - -int -do_sdtest6(int fd, nsc_size_t loops, nsc_size_t filesize, int h) -{ - int err = 0; - nsc_size_t i; - ssize_t r; - nsc_size_t endloop = filesize / fba_num_bufsize; - int buf3[MAXBUF]; - int buf4[MAXBUF]; - nsc_off_t top_pos, bottom_pos; - - /* - * Do alternating top down and bottom up sequential writes - * (working towards middle) and verify with reads - * for loops number of bufsize chunks, unless loops == 0, then do - * entire disk. - */ - if ((loops > (filesize / fba_num_bufsize)) || (!loops)) - loops = filesize / fba_num_bufsize; /* entire disk */ - - for (i = 0; i < loops; i++) { - gen_data(buf1, bufsize); - bottom_pos = i*fba_num_bufsize; - r = pwrite(fd, buf1, bufsize, (off_t)(bottom_pos << SCTRSHFT)); - if (r <= 0) { - perror("Test6: write"); - err++; - return (err); - } - gen_data(buf2, bufsize); - top_pos = (endloop - i - 1)*fba_num_bufsize; - - /* Make sure we don't collide in the middle */ - - if (abs(top_pos - bottom_pos) < fba_num_bufsize) - top_pos = bottom_pos + fba_num_bufsize; - - r = pwrite(fd, buf2, bufsize, (off_t)(top_pos << SCTRSHFT)); - if (r <= 0) { - perror("Test6: write"); - err++; - return (err); - } - r = pread(fd, buf3, bufsize, (off_t)(bottom_pos << SCTRSHFT)); - if (r <= 0) { - perror("Test6: read"); - err++; - return (err); - } - if (memcmp(buf1, buf3, bufsize)) { - (void) printf("Data corruption(1), fd:%s, fpos:%" - PRId64 ", len:%d\n", name[h], - (int64_t)(bottom_pos << SCTRSHFT), bufsize); - err++; - } - r = pread(fd, buf4, bufsize, (off_t)(top_pos << SCTRSHFT)); - if (r <= 0) { - perror("Test6: read"); - return (1); - } - if (memcmp(buf2, buf4, bufsize)) { - (void) printf("Test6: Data corruption(2)," - " fd:%s, fpos:%" PRId64 ", len:%d\n", - name[h], (int64_t)(top_pos << SCTRSHFT), bufsize); - err++; - } - } - return (err); -} - -int shmid; - -#define MAXREADERS 32 - -struct shm_struct { - int writebuf[MAXBUF]; - volatile nsc_off_t writepos; - int quit; - int err; - mutex_t err_mutex; - int rd_done[MAXREADERS]; - int rd_done_mask[MAXREADERS]; -} *shm; - -#define WRITEBUF (shm->writebuf) -#define WRITEPOS (shm->writepos) - -#define QUIT (shm->quit) -#define ERR (shm->err) -#define ERRMUTEX (shm->err_mutex) -#define RD_DONE (shm->rd_done) -#define RD_DONE_MASK (shm->rd_done_mask) - -#define LOCKWRITE -#define LOCKREAD(i) - -/* Clear RD_DONE and Set WRITEPOS */ -#define FREEWRITE { \ - bzero(RD_DONE, sizeof (RD_DONE)); \ - WRITEPOS = wr_pos; } - -/* Reader i+1 marks himself as finished */ -#define FREEREAD(i) (RD_DONE[(i)] = 1) - - -int -do_sdtest7read(int fd, int h, int which) -{ - int err; - ssize_t r_rd; - nsc_off_t curr_pos; - nsc_size_t loop_cnt; - err = 0; curr_pos = 0; loop_cnt = 0; - for (;;) { - /* Already read this? */ - if (curr_pos == WRITEPOS) { - if (!QUIT) { - continue; - } else { - /* Time to go! */ - /* printf("Quitting [%d]\n", which+1); */ - break; - } - } - - /* get location to read from */ - curr_pos = WRITEPOS; - - r_rd = pread(fd, buf1, bufsize, (curr_pos << SCTRSHFT)); - loop_cnt += 1; - if (r_rd <= 0) { - FREEREAD(which); - perror("Test7: read"); - err += 1; - continue; - } - - if (memcmp(buf1, WRITEBUF, bufsize)) { - FREEREAD(which); - (void) printf("\nTest7: Data corruption, reader #%d, " - "fd:%s, \ - fpos:%" PRId64 ", len:%d\n", which + 1, name[h], - (int64_t)(curr_pos << SCTRSHFT), bufsize); - err += 1; - continue; - } - - FREEREAD(which); - } - - (void) printf( - "Partition %s, Test 7, reader #%d: %d errors %lld loops\n", - name[h], which+1, err, loop_cnt); - - if (err > 0) { - (void) mutex_lock(&ERRMUTEX); - ERR += err; - (void) mutex_unlock(&ERRMUTEX); - } - - if (err) - return (1); - else - return (0); -} - - -int -do_sdtest7write(int fd, nsc_size_t filesize, int h) -{ - int err = 0; - ssize_t r; - nsc_off_t wr_pos; - - /* Wait for readers to finish */ - while (memcmp(RD_DONE, RD_DONE_MASK, readercount*sizeof (int))) - ; - - gen_data(WRITEBUF, bufsize); - wr_pos = ( -#ifdef NSC_MULTI_TERABYTE - ((nsc_off_t)rand() << 48) | ((nsc_off_t)rand() << 32) | -#endif - (rand() << 16) | rand()) % filesize; - r = pwrite(fd, WRITEBUF, bufsize, (off_t)(wr_pos << SCTRSHFT)); - if (r <= 0) { - FREEWRITE; - perror("Test7: write"); - return (1); - } - FREEWRITE; - - /* verify write */ - r = pread(fd, buf1, bufsize, (off_t)(wr_pos << SCTRSHFT)); - if (r <= 0) { - perror("Test7: writer: read"); - return (1); - } - - - if (memcmp(buf1, WRITEBUF, bufsize)) { - (void) printf("\nTest7: Data corruption in writer," - " fd:%s, fpos:%" PRId64 ", len:%d\n", - name[h], (int64_t)(wr_pos << SCTRSHFT), bufsize); - err++; - } - - - return (err); -} - -void -init_shm() -{ - int i; - - /* Clear out everything */ - bzero(shm, sizeof (struct shm_struct)); - - (void) mutex_init(&ERRMUTEX, USYNC_PROCESS, NULL); - - /* Set up mask (constant) to test reader doneness */ - for (i = 0; i < readercount; i++) - RD_DONE_MASK[i] = 1; - - /* Mark all readers done - so writer can start */ - for (i = 0; i < readercount; i++) - RD_DONE[i] = 1; -} - -int -do_sdtest7(int fd, nsc_size_t loops, nsc_size_t filesize, int h, nsc_fd_t *sdfd) -{ - int r, i, err; - nsc_size_t j; - - if ((shmid = shmget(IPC_PRIVATE, sizeof (struct shm_struct), - IPC_CREAT | 0666)) < 0) { - perror("shmget error: "); - (void) nsc_close(sdfd); - exit(1); - } - - shm = (struct shm_struct *)shmat(shmid, NULL, 0); - if (shm == (struct shm_struct *)-1) { - perror("shmat error: "); - (void) nsc_close(sdfd); - exit(1); /* cleanup exits */ - } - - init_shm(); - - /* Start Readers */ - for (i = 0; i < readercount; i++) { - r = fork(); - if (r == 0) { /* child */ - (void) do_sdtest7read(fd, h, i); - (void) nsc_close(sdfd); - exit(0); - } else - continue; - } - - /* Start Writer */ - srand(getpid()); err = 0; - for (j = 0; j < loops; j++) { - err += do_sdtest7write(fd, filesize, h); - } - QUIT = 1; - - (void) printf("\n\nPartition %s, Test 7, writer: %d errors\n", - name[h], err); - - for (i = 0; i < readercount; i++) - (void) wait(0); - - /* No lock needed here - everybody's finished */ - err += ERR; - - (void) mutex_destroy(&ERRMUTEX); - (void) shmctl(shmid, IPC_RMID, 0); - return (err); -} - -int -do_sdtest8(int fd, nsc_size_t loops, nsc_size_t filesize) -{ - nsc_off_t seekpos; - int err = 0; - ssize_t r; - nsc_size_t i; - - for (i = 0; i < loops; i++) { - seekpos = ( -#ifdef NSC_MULTI_TERABYTE - ((nsc_off_t)rand() << 48) | ((nsc_off_t)rand() << 32) | -#endif - (rand() << 16) | rand()) % filesize; - gen_data(buf1, bufsize); - r = pwrite(fd, buf1, bufsize, (off_t)(seekpos << SCTRSHFT)); - if (r <= 0) { - perror("Test8: write"); - err++; - return (err); - } - } - return (err); -} - -void -gen_data_known(int *buffer, int size, int data) -{ - int i; - - size /= 4; - for (i = 0; i < size; i++) - buffer[i] = data; -} - -int -do_sdtest9(int fd, nsc_size_t loops, nsc_size_t filesize, int h) -{ - int err = 0; - ssize_t r; - nsc_off_t fba_offset; - nsc_size_t i, wrapval; - - /* - * Test 9 will write a given pattern over and over Test 11 or - * Test 12 will read same pattern. - */ - /* Large loop value that would cause write overflow will wrap */ - - gen_data_known(buf1, bufsize, pattern[h]); - - wrapval = filesize / fba_num_bufsize; - - if (loops == 0) - loops = wrapval; /* entire disk */ - - for (i = 0; i < loops; i++) { - fba_offset = i % wrapval; - r = pwrite(fd, buf1, bufsize, - (off_t)(fba_offset * fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test9: write"); - err++; - return (err); - } - } - return (err); -} - -int -do_sdtest10(int fd1, int fd2, nsc_size_t loops, nsc_size_t filesize1, - nsc_size_t filesize2, int h) -{ - nsc_size_t filesize; - int err = 0; - nsc_size_t i; - ssize_t r; - - /* - * Do sequential copy of disk1 to disk2 for loops number - * of bufsize chunks, unless loops == 0, then copy size of - * the smaller disk. - * Go back and verify that the two disks are identical. - */ - - filesize = (filesize1 < filesize2) ? filesize1 : filesize2; - if ((loops > (filesize / fba_num_bufsize)) || (!loops)) - loops = filesize / fba_num_bufsize; - - /* copy disk1 to to disk2 */ - for (i = 0; i < loops; i++) { - r = pread(fd1, buf1, bufsize, - (off_t)(i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test10: read"); - return (1); - } - r = pwrite(fd2, buf1, bufsize, - (off_t)(i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test10: write"); - return (1); - } - } - - /* verify disks are identical */ - for (i = 0; i < loops; i++) { - buf1[0] = '\0'; /* clear buf to make sure something is read */ - r = pread(fd1, buf1, bufsize, - (off_t)(i * fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test10: read"); - return (1); - } - buf2[0] = 'x'; /* make sure something is read */ - r = pread(fd2, buf2, bufsize, - (off_t)(i * fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test10: read"); - return (1); - } - if (memcmp(buf1, buf2, bufsize)) { - (void) printf("Test10: Data corruption," - " fd1:%s, fd2:%s fpos:%" NSC_SZFMT ", len:%d\n", - name[2*h], name[2*h+1], i, bufsize); - err++; - } - } - return (err); -} - -int -buffcmp(int *b1, int *b2, int size) -{ - int i; - - for (i = 0; i < size/4; i++) { - if (b1[i] != b2[i]) { - (void) printf("Word %d does not match b1=0x%x, " - "b2=0x%x\n", i, b1[i], b2[i]); - return (1); - } - } - return (0); - -} - -int -do_sdtest11(int fd, nsc_size_t loops, nsc_size_t filesize, int h) -{ - int err = 0; - nsc_size_t i; - ssize_t r; - int buf3[MAXBUF]; - int buf4[MAXBUF]; - int timestamp; - time_t clock; - struct tm *tm; - - - /* - * Test 9 will write a given pattern over and over Test 11 will read - * same pattern and clear with timestamp data (MM:SS). - */ - - clock = time(NULL); - tm = localtime(&clock); - (void) ascftime((char *)×tamp, "%M""%S", tm); - - gen_data_known(buf1, bufsize, pattern[h]); - gen_data_known(buf4, bufsize, timestamp); - if ((loops > filesize / fba_num_bufsize) || (!loops)) - loops = filesize / fba_num_bufsize; /* entire disk */ - - for (i = 0; i < loops; i++) { - r = pread(fd, buf3, bufsize, - (off_t)(i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test11: read"); - err++; - return (err); - } - if (buffcmp(buf1, buf3, bufsize)) { - (void) printf("Data corr, fd:%s, fpos:%" NSC_SZFMT - ", len:%d\n", name[h], i, bufsize); - err++; - return (err); - } - r = pwrite(fd, buf4, bufsize, - (off_t)(i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test11: write"); - err++; - return (err); - } - } - return (err); -} - -int -do_sdtest12(int fd, nsc_size_t loops, nsc_size_t filesize, int h) -{ - int err = 0; - nsc_size_t i; - ssize_t r; - int buf3[MAXBUF]; - - /* - * Test 9 will write a given pattern over and over Test 12 will read - * same pattern - */ - - gen_data_known(buf1, bufsize, pattern[h]); - if ((loops > filesize / fba_num_bufsize) || (!loops)) - loops = filesize / fba_num_bufsize; /* entire disk */ - - for (i = 0; i < loops; i++) { - r = pread(fd, buf3, bufsize, - (off_t)(i*fba_num_bufsize) << SCTRSHFT); - if (r <= 0) { - perror("Test12: read"); - err++; - return (err); - } - if (buffcmp(buf1, buf3, bufsize)) { - (void) printf("Data corr, fd:%s, fpos:%" NSC_SZFMT - ", len:%d\n", name[h], i, bufsize); - err++; - return (err); - } - } - return (err); -} - -#ifdef lint -int -sd_diag_lintmain(int argc, char *argv[]) -#else -int -main(int argc, char *argv[]) -#endif -{ - int procs; - nsc_size_t filesize, filesize2; - int fd, fd2, r, id, h, i; - nsc_fd_t *sdfd, *sdfd2; - - if (argc < 2) { - print_usage(); - exit(0); - } - (void) strcpy(config_file, DISKLIST); - parse_opts(argc, argv); - - _nsc_nocheck(); - if ((procs = read_parts()) == 0) - exit(0); - - id = strtol(argv[optind], 0, 0); - if (id == 10) { - /* - * each process gets 2 disks and copies disk1 to disk2, - * then goes back and verifies that the two disks are - * identical. - */ - if (procs < 2) { - (void) printf("%s requires having at least 2 disks for test " - "#10.\n", config_file); - exit(0); - } - - for (h = 0; h < procs/2; h++) { - r = fork(); - if (r == 0) { - srand(getpid()); - - - if (!(sdfd = nsc_open(name[2*h], NSC_CACHE, - O_RDWR | Rflag))) { - (void) fprintf(stderr, - "sd_diag: Error opening %s\n", name[2*h]); - exit(1); - } - fd = nsc_fileno(sdfd); - if (fd == -1) { - (void) fprintf(stderr, - "sd_diag: Error opening %s\n", name[2*h]); - (void) nsc_close(sdfd); - exit(1); - } - filesize = set_part_size(name[2*h], sdfd); - if (!(sdfd2 = nsc_open(name[2*h+1], NSC_CACHE, - O_RDWR | Rflag))) { - (void) fprintf(stderr, - "sd_diag: Error opening %s\n", name[2*h+1]); - exit(1); - } - fd2 = nsc_fileno(sdfd2); - if (fd2 == -1) { - (void) fprintf(stderr, - "sd_diag: Error opening %s\n", name[2*h+1]); - (void) nsc_close(sdfd2); - exit(1); - } - filesize2 = set_part_size(name[2*h+1], sdfd2); - (void) sleep(2); - r = do_sdtest10(fd, fd2, loops, filesize, filesize2, h); - - (void) printf("Partitions %s and %s, Test %d," - " Completed %d errors\n", - name[2*h], name[2*h+1], id, r); - (void) nsc_close(sdfd); - (void) nsc_close(sdfd2); - exit(0); - } else if (r == -1) { - perror("fork"); - break; - } else - continue; - } /* for */ - for (i = 0; i < h; i++) - (void) wait(0); - } else { - - for (h = 0; h < procs; h++) { - r = fork(); - if (r == 0) { - srand(getpid()); - - id = strtol(argv[optind], 0, 0); - if (!(sdfd = nsc_open(name[h], NSC_CACHE, - O_RDWR | Rflag))) { - (void) fprintf(stderr, - "sd_diag: Error opening %s\n", name[h]); - exit(1); - } - fd = nsc_fileno(sdfd); - - if (fd == -1) { - (void) fprintf(stderr, - "sd_diag: Error opening %s\n", name[h]); - (void) nsc_close(sdfd); - exit(1); - } - filesize = set_part_size(name[h], sdfd); - - (void) sleep(2); - - - switch (id) { - case 1: - r = do_sdtest1(fd, r_loops, filesize); - break; - case 2: - r = do_sdtest2(fd, r_loops, filesize, h); - break; - case 3: - r = do_sdtest3(fd, r_loops, filesize, h, sdfd); - break; - case 4: - r = do_sdtest4(fd, loops, filesize); - break; - case 5: - r = do_sdtest5(fd, loops, filesize, h); - break; - case 6: - r = do_sdtest6(fd, loops, filesize, h); - break; - case 7: - r = do_sdtest7(fd, r_loops, filesize, h, sdfd); - break; - case 8: - r = do_sdtest8(fd, r_loops, filesize); - break; - case 9: - r = do_sdtest9(fd, loops, filesize, h); - break; - case 11: - r = do_sdtest11(fd, loops, filesize, h); - break; - case 12: - r = do_sdtest12(fd, loops, filesize, h); - break; - default: - break; - } - - (void) printf("Partition %s, Test %d, Completed %d " - "errors\n", name[h], id, r); - (void) nsc_close(sdfd); - exit(r ? 1 : 0); - } else if (r == -1) { - perror("fork"); - break; - } else - continue; - } - for (i = 0; i < h; i++) - (void) wait(0); - } - - return (0); -} diff --git a/usr/src/cmd/avs/sdbc/sd_stats.c b/usr/src/cmd/avs/sdbc/sd_stats.c deleted file mode 100644 index 211ce6c1d6..0000000000 --- a/usr/src/cmd/avs/sdbc/sd_stats.c +++ /dev/null @@ -1,594 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2010 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <strings.h> -#include <curses.h> -#include <signal.h> -#include <fcntl.h> -#include <locale.h> - -#include <sys/types.h> -#include <sys/time.h> -#include <sys/nsctl/sdbc_ioctl.h> -#include <sys/unistat/spcs_s_u.h> -#include <sys/nsctl/sd_bcache.h> -#include <sys/nsctl/sd_conf.h> - -extern void total_display(void); -extern void display_cache(void); -extern void wrefresh_file(WINDOW *, int); -extern int is_dirty(void); -extern int dual_stats(void); -void checkbuf(int); -void setup_ranges(char *); -void prheading(int); -extern int zero_nic(void); - -#ifdef m88k -#define USEC_INIT() usec_ptr = (unsigned int *)timer_init() -#define USEC_READ() (*usec_ptr) -#else /* !m88k */ -#define USEC_INIT() USEC_START() -#include <sys/time.h> -static struct timeval Usec_time; -static int Usec_started = 0; - -extern int higher(int); -extern int is_dirty(); -extern int dual_stats(); -extern void total_display(); -extern void display_cache(); -extern void wrefresh_file(WINDOW *, int); -void setup_ranges(char *); - -void prheading(int); -void checkbuf(int); -void quit(int); -void leave(int); -#pragma does_not_return(quit, leave) - -int sdbc_max_devices = 0; - -static void -USEC_START() -{ - if (!Usec_started) { - (void) gettimeofday(&Usec_time, NULL); - Usec_started = 1; - } -} - -static unsigned int -USEC_READ() -{ - struct timeval tv; - if (!Usec_started) - USEC_START(); - - (void) gettimeofday(&tv, NULL); - return (unsigned)((tv.tv_sec - Usec_time.tv_sec) * 1000000 - + (tv.tv_usec - Usec_time.tv_usec)); -} -#endif /* m88k */ - -int rev_flag = 0; /* Reverse video flag */ -int bold_flg = 0; /* Bold flag */ -int under_flg = 0; /* Underline flag */ -int errflg = 0; /* Error flag */ -int node_sw = 0; /* Per node switch */ -int toggle_total_sw = 0; -int mirror_sw = 0; /* Dual copy switch */ - -int kmemfd; -int delay = 1; /* Display delay (seconds) */ - -time_t *usec_ptr; -time_t currtime = 0; -int lasttime = 0; -int Elapsed_Time = 0; - -static char *range; -static int had_r_option = 0; -int logfd = -1; /* screen output logging */ -extern int range_num; -extern int screen; -extern int dual_screen; -int *on_off; -int *dual_on_off; -int *updates_prev; -double *rate_prev; -int *samples; -_sd_stats_t *cs_cur; -_sd_stats_t *cs_prev; -_sd_stats_t *cs_persec; - -typedef struct { - int lb, ub; -} range_t; - -extern range_t ranges[]; - -#ifdef lint -int -sd_stats_lintmain(int argc, char *argv[]) -#else -int -main(int argc, char *argv[]) -#endif -{ - spcs_s_info_t ustats; - struct timeval tout; - fd_set readfds; - char *errmessage, *ch; - int c, period, prev; - int count = 0, dflag = 0; - int fd = fileno(stdin); - - errmessage = NULL; - - if (strcmp(argv[0], "sd_stats") != 0) - errmessage = getenv("SD_STATS_USAGE"); - - if (errmessage == NULL) - errmessage = gettext("Usage: sd_stats [-Mz] " - "[-d delay_time] [-l logfile] [-r range]"); - - if (SDBC_IOCTL(SDBC_MAXFILES, &sdbc_max_devices, - 0, 0, 0, 0, &ustats) == SPCS_S_ERROR) { - if (ustats) { /* if SPCS_S_ERROR */ - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - (void) fprintf(stderr, gettext("cannot get maxfiles\n")); - exit(1); - } - on_off = calloc(sdbc_max_devices, sizeof (int)); - dual_on_off = calloc(sdbc_max_devices, sizeof (int)); - updates_prev = calloc(sdbc_max_devices, sizeof (int)); - samples = calloc(sdbc_max_devices, sizeof (int)); - rate_prev = calloc(sdbc_max_devices, sizeof (double)); - cs_cur = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - cs_prev = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - cs_persec = malloc(sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - range = malloc(100); - - if (!on_off || !dual_on_off || !updates_prev || !samples || - !rate_prev || !cs_cur || !cs_prev || !cs_persec || !range) { - (void) fprintf(stderr, gettext("no free memory\n")); - exit(1); - } - - *range = '\0'; - - while ((c = getopt(argc, argv, "DMzd:l:r:h")) != EOF) { - - prev = c; - switch (c) { - - case 'd': - delay = atoi(optarg); - ch = optarg; - while (*ch != '\0') { - if (!isdigit(*ch)) - errflg++; - ch++; - } - break; - - case 'l': - logfd = open(optarg, O_CREAT|O_WRONLY|O_TRUNC, 0644); - break; - - case 'r': - ch = optarg; - while (*ch != '\0') { - if ((!isdigit(*ch)) && (*ch != ',') && - (*ch != ':')) - errflg++; - ch++; - } - if (errflg) - break; - - range = realloc((char *)range, - (strlen(range) + strlen(optarg) + 1) - * sizeof (char)); - - if (had_r_option) - (void) strcat(range, ","); - (void) strcat(range, optarg); - had_r_option = 1; - break; - - case 'z': - if (SDBC_IOCTL(SDBC_ZAP_STATS, 0, 0, 0, 0, 0, - &ustats) == SPCS_S_ERROR) { - if (ustats) { - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - } - - break; - - case 'D': - dflag = 1; - break; - - case 'M': - mirror_sw = 1; - break; - - case 'h': - case '?': - default : - errflg++; - break; - } - } - - if (errflg) { - (void) fprintf(stderr, "%s\n", errmessage); - exit(1); - } else if (!prev) { - if (argc > 1) { - (void) fprintf(stderr, "%s\n", errmessage); - exit(1); - } - } - - if (dflag) { - exit(is_dirty()); - } - - - /* - * A few curses routines to setup screen and tty interface - */ - (void) initscr(); - (void) cbreak(); - (void) noecho(); - (void) nonl(); - (void) erase(); - (void) clear(); - (void) refresh(); - - setup_ranges(range); - - /* - * Set signal handle - */ - (void) sigset(SIGPIPE, leave); - (void) sigset(SIGINT, leave); - (void) sigset(SIGQUIT, leave); - (void) signal(SIGFPE, leave); - (void) signal(SIGSEGV, leave); - - USEC_INIT(); - currtime = USEC_READ(); - - /* - * Wait one second before reading the new values - */ - (void) sleep(1); - - /*CONSTCOND*/ - while (1) { - - lasttime = currtime; - currtime = USEC_READ(); - - /* - * If less that 1 second, force it to one second - */ - if ((period = (currtime - lasttime) / 1000000) <= 0) - period = 1; - - /* - * Calculate new per/period values for statistics - */ - Elapsed_Time += period; - - /* - * Display new statistics - */ - prheading(++count); - - if (mirror_sw) { - if (dual_stats() < 0) - mirror_sw = 0; - } else if (toggle_total_sw) - total_display(); - else - display_cache(); - - (void) move(0, 0); - (void) refresh(); - if (logfd > -1) wrefresh_file(stdscr, logfd); - - FD_ZERO(&readfds); - FD_SET(fd, &readfds); - tout.tv_sec = delay; - for (;;) { - tout.tv_usec = 0; - if (select(fd + 1, &readfds, (fd_set *)0, (fd_set *)0, - &tout) <= 0) - break; - if ((c = getch()) == EOF) { - (void) sleep(delay); - break; - } - checkbuf(c); - tout.tv_sec = 0; - } - (void) erase(); - } -#pragma error_messages(off, E_STATEMENT_NOT_REACHED) - return (0); -#pragma error_messages(default, E_STATEMENT_NOT_REACHED) -} - -void -checkbuf(int c) -{ - spcs_s_info_t ustats; - - switch (c) { - case 'b' : /* ctrl b or b -- scroll backward */ - case 2 : - { - if (mirror_sw == 1) { - if (dual_screen > 0) - dual_screen--; - break; - } - if (screen > 0) - screen--; - break; - } - - case 'f' : /* ctrl f or f -- scroll forward */ - case 6 : - { - if (mirror_sw == 1) { - dual_screen++; - break; - } - screen++; - break; - } - - case 't': - case 'T': - if (mirror_sw == 1) - mirror_sw = 0; - - toggle_total_sw ^= 1; - break; - - case '-': - case KEY_DOWN: - if (delay > 1) { - --delay; - } else { - (void) beep(); - } - break; - - case '+': - case KEY_UP: - delay++; - break; - - case 'C': - case 0xc: - (void) clearok(stdscr, TRUE); - break; - - case 'B': - if (bold_flg) { - bold_flg = 0; - (void) attroff(A_BOLD); - } else { - bold_flg = 1; - (void) attron(A_BOLD); - } - break; - - case 'R': - if (rev_flag) { - rev_flag = 0; - (void) attroff(A_REVERSE); - } else { - rev_flag = 1; - (void) attron(A_REVERSE); - } - break; - - case 'z': - if (SDBC_IOCTL(SDBC_ZAP_STATS, 0, 0, 0, 0, 0, - &ustats) == SPCS_S_ERROR) { - if (ustats) { - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - } - break; - - case 'm': - case 'M': - mirror_sw = mirror_sw ? 0 : 1; - (void) clear(); - break; - } -} - -void -prheading(int count) -{ - time_t tim; - - /* - * Print sample count in upper left corner - */ - (void) mvprintw(0, 0, "SAMPLE %-8d", count); - - /* - * Get time and print it in upper right corner - */ - tim = time((time_t *)0); - (void) mvprintw(0, 79 - 10, "%-8.8s\n", &(ctime(&tim)[11])); -} - -/*ARGSUSED*/ -void -leave(int status) -{ - (void) sigignore(SIGPIPE); - (void) sigignore(SIGALRM); - /* clear(); */ - (void) move(LINES, 0); - (void) refresh(); - if (logfd > -1) wrefresh_file(stdscr, logfd); - quit(0); -} - -void -quit(int status) -{ - (void) resetterm(); - (void) endwin(); - exit(status); -} - -void -setup_ranges(char *range) -{ - int ndx; - char chr1; - char prev_chr = '\0'; - int got_colon = 0; - int after_got_colon = 0; - int got_comma = 0; - int after_got_comma = 0; - int number = 0; - int prev_num = 0; - - if (range == NULL || (strlen(range) == 0)) { - ranges[range_num].lb = 0; - ranges[range_num].ub = sdbc_max_devices - 1; - return; - } else { - ndx = 0; - got_comma = 0; - got_colon = 0; - while ((chr1 = (range[ndx++])) != '\0') { - switch (chr1) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - number = number*10 + (chr1 - '0'); - break; - case ':': - got_colon = 1; - break; - case ',': - got_comma = 1; - break; - default: /* ignore any unknown characters */ - break; - } /* switch */ - if (got_comma && after_got_colon) { - after_got_colon = 0; - got_comma = 0; - if (number >= sdbc_max_devices) - number = sdbc_max_devices - 1; - ranges[range_num].lb = prev_num; - ranges[range_num].ub = number; - if (range_num == 99) break; - range_num++; - number = 0; - } else if (got_colon && after_got_comma) { - got_colon = 0; - after_got_colon = 1; - after_got_comma = 0; - if (number >= sdbc_max_devices) - number = sdbc_max_devices - 1; - prev_num = number; - number = 0; - } else if (got_colon) { - got_colon = 0; - after_got_colon = 1; - if ((prev_chr != '\0') && (prev_chr != ':')) { - if (number >= sdbc_max_devices) - number = sdbc_max_devices - 1; - prev_num = number; - number = 0; - } - } else if (got_comma) { - got_comma = 0; - after_got_comma = 1; - after_got_colon = 0; - if (number >= sdbc_max_devices) - number = sdbc_max_devices -1; - if ((prev_chr != '\0') && (prev_chr != ',')) { - ranges[range_num].lb = number; - ranges[range_num].ub = number; - if (range_num == 99) break; - range_num++; - } - number = 0; - } /* if */ - prev_chr = chr1; - } /* while */ - if (number >= sdbc_max_devices) - number = sdbc_max_devices - 1; - if (after_got_colon) { - ranges[range_num].lb = prev_num; - ranges[range_num].ub = number; - } else { - if ((after_got_comma) && (prev_chr == ',')) - range_num--; - else { - ranges[range_num].lb = number; - ranges[range_num].ub = number; - } - } - } -} diff --git a/usr/src/cmd/avs/sdbc/sd_trace.c b/usr/src/cmd/avs/sdbc/sd_trace.c deleted file mode 100644 index 9b237ea057..0000000000 --- a/usr/src/cmd/avs/sdbc/sd_trace.c +++ /dev/null @@ -1,961 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2010 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#include <errno.h> -#include <stdio.h> -#include <unistd.h> -#include <strings.h> -#include <stdlib.h> - -#include <sys/types.h> -#include <sys/time.h> -#include <sys/nsctl/sdbc_ioctl.h> -#include <sys/nsctl/rdc_ioctl.h> -#include <sys/nsctl/sd_bcache.h> -#include <sys/nsctl/sd_conf.h> -#include <sys/nsctl/rdc_io.h> -#include <sys/nsctl/rdc_bitmap.h> -#include <sys/unistat/spcs_s_u.h> -#include <curses.h> - -static rdc_status_t *rdc_status; -static rdc_u_info_t *rdc_info; -static int rdc_maxsets; -static int rdc_enabled_sets; - -static unsigned prev_time, delta_time; -#ifdef m88k -extern unsigned *usec_ptr; -#endif -static int bright = 0; - -extern int sdbc_max_devices; - -extern _sd_stats_t *cs_cur; -extern _sd_stats_t *cs_prev; -extern _sd_stats_t *cs_persec; - -extern int *on_off; -extern int *dual_on_off; -extern int *updates_prev; -extern double *rate_prev; -extern int *samples; - -int range_num = 0; -int screen = 0; -int dual_screen = 0; -static int rnum = 0; - -typedef struct { - int lb, ub; -} range_t; -range_t ranges[100]; - -extern int range_first(); -extern int range_next(int); -extern int range_last(); - -static int dual_initted = 0; -static char status[11][30]; - -unsigned dc_delta_time, dc_prev_time; - -#ifdef m88k -#define USEC_INIT() usec_ptr = (unsigned int *)timer_init() -#define USEC_READ() (*usec_ptr) -#else /* !m88k */ -#define USEC_INIT() USEC_START() -#include <sys/time.h> -static struct timeval Usec_time; -static int Usec_started = 0; - -void total_display(void); -void disp_stats(void); -void do_calc(void); -void init_dual(void); -void calc_time(void); -void calc_completion(int, int, int); -void disp_total_stats(void); -void display_cache(void); - -#define DISPLEN 16 - -static void -USEC_START(void) -{ - if (!Usec_started) { - (void) gettimeofday(&Usec_time, NULL); - Usec_started = 1; - } -} - -static unsigned int -USEC_READ() -{ - struct timeval tv; - if (!Usec_started) - USEC_START(); - - (void) gettimeofday(&tv, NULL); - return (unsigned)((tv.tv_sec - Usec_time.tv_sec) * 1000000 + - (tv.tv_usec - Usec_time.tv_usec)); -} -#endif /* m88k */ - -#define SAMPLE_RATE 5 - -/* - * refresh curses window to file - */ -void -wrefresh_file(WINDOW *win, int fd) -{ - char buf[8192], c, *cp = buf, *line, *blank, *empty; - int x, y; - - empty = NULL; /* cull trailing empty lines */ - for (y = 0; y < win->_maxy; y++) { - line = cp; - blank = NULL; /* cull trailing blanks */ - for (x = 0; x < win->_maxx; x++) { - c = (win->_y[y][x]) & A_CHARTEXT; - if (c != ' ') - blank = NULL; - else if (blank == NULL) - blank = cp; - *cp++ = c; - } - if (blank) - cp = blank; - if (line != cp) - empty = NULL; - else if (empty == NULL) - empty = cp + 1; - *cp++ = '\n'; - } - if (empty) - cp = empty; - *cp++ = '\f'; *cp++ = '\n'; *cp = '\0'; - /* cp is eliminated by short _maxy and _maxx, it won't overflow */ - /* LINTED, cp - buf won't be > INT32_MAX */ - (void) write(fd, buf, cp - buf); -} - - -int -higher(int high) -{ - int i; - - for (i = high + 1; i <= sdbc_max_devices; i++) { - if (cs_cur->st_shared[i].sh_alloc) - return (i); - } - return (0); -} - -int -is_dirty() -{ - int i, dirty = 0; - spcs_s_info_t ustats; - - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, - &ustats) == SPCS_S_ERROR) { - perror("Could not get stats from kernel"); - if (ustats) { - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - return (-errno); - } - if (cs_cur->st_cachesize == 0) - return (0); - - for (i = 0; i < cs_cur->st_count; i++) { - if (cs_cur->st_shared[i].sh_alloc) - dirty += cs_cur->st_shared[i].sh_numdirty; - } - - return (dirty != 0); -} - -void -display_cache(void) -{ - static int first = 1; - spcs_s_info_t ustats; - - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) == - SPCS_S_ERROR) { - perror("sd_stats"); - if (ustats) { - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - } - - do_calc(); - if (first) { - prev_time = USEC_READ(); - first = 0; - } else - disp_stats(); -} - -void -total_display(void) -{ - spcs_s_info_t ustats; - - if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) == - SPCS_S_ERROR) { - if (ustats) { - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - perror("sd_stats"); - } - disp_total_stats(); -} - - -int -range_first() -{ - rnum = 0; - return (ranges[rnum].lb); -} - -int -range_next(int cd) -{ - if (ranges[rnum].ub > cd) - return (cd + 1); - if (range_num > rnum) - rnum++; - else - return (cd + 1); - return (ranges[rnum].lb); -} - -int -range_last() { - return (ranges[range_num].ub); -} - - -void -set_dual_on_off() -{ - int i, j, ct = 0, newct = 0; - - for (i = range_first(); i < rdc_enabled_sets && i <= range_last(); - i = range_next(i)) { - if (rdc_info[i].flags & RDC_ENABLED) { - ct++; - if (ct > dual_screen * ((LINES - 9) / 2)) - break; - } - } - if (((i >= rdc_enabled_sets) || - (i > range_last())) && (dual_screen > 0)) { - dual_screen--; - set_dual_on_off(); - } else { - bzero(dual_on_off, sdbc_max_devices * sizeof (int)); - for (j = i; j < rdc_enabled_sets && j <= range_last(); - j = range_next(j)) { - if (rdc_info[j].flags & RDC_ENABLED) { - newct++; - if (newct <= (LINES - 9) / 2) { - dual_on_off[j] = 1; - } else - break; - } - } - } -} - - -void -set_on_off() -{ - int i, j, ct = 0, newct = 0; - - for (i = range_first(); i <= range_last(); i = range_next(i)) { - if (cs_cur->st_shared[i].sh_alloc) { - ct++; - if (ct > screen*((LINES - 9) / 2)) - break; - } - } - if ((i > range_last()) && (screen > 0)) { - screen--; - set_on_off(); - } else { - bzero(on_off, sdbc_max_devices * sizeof (int)); - for (j = i; j <= range_last(); j = range_next(j)) { - if (cs_cur->st_shared[j].sh_alloc) { - newct++; - if (newct <= (LINES - 9) / 2) - on_off[j] = 1; - else - break; - } - } - } -} - -void -disp_stats(void) -{ - double read_s, write_s, access_s, readp, writep; - double rmiss_s, wmiss_s; - double elapsed = delta_time / 1000000.0; - double kbps = elapsed * 1024.0; /* for Kbytes per second */ - int rtotal, wtotal, i, j; - double throughput = 0.0, rthroughput = 0.0; - double creads = 0.0, cwrites = 0.0; - char status_bit, down = 0; - int len; - char fn[19]; - - if (delta_time != 0) { - read_s = cs_persec->st_rdhits / elapsed; - write_s = cs_persec->st_wrhits / elapsed; - rmiss_s = cs_persec->st_rdmiss / elapsed; - wmiss_s = cs_persec->st_wrmiss / elapsed; - access_s = (cs_persec->st_wrhits + cs_persec->st_rdhits + - cs_persec->st_rdmiss + cs_persec->st_wrmiss) / elapsed; - } else - read_s = write_s = access_s = 0.0; - - rtotal = cs_persec->st_rdhits + cs_persec->st_rdmiss; - wtotal = cs_persec->st_wrhits + cs_persec->st_wrmiss; - if (rtotal != 0) - readp = cs_persec->st_rdhits / (double)rtotal; - else - readp = 0.0; - - if (wtotal != 0) { - writep = cs_persec->st_wrhits / (double)wtotal; - } else - writep = 0.0; - - set_on_off(); - if (cs_cur->st_cachesize == 0) - (void) mvprintw(0, 20, "****** Storage Cache Disabled ******"); - else - (void) mvprintw(0, 20, "****** Storage Cache ******"); - (void) mvprintw(2, 26, "disk_io cache write_blocks"); - (void) attron(A_UNDERLINE); - (void) mvprintw(3, 1, " cd cached_partition reads writes reads writes" - " dirty todisk failed"); - (void) attroff(A_UNDERLINE); - for (i = 0, j = 0; j < cs_cur->st_count; i++) { - if (i >= sdbc_max_devices) - break; - if (cs_cur->st_shared[i].sh_alloc) { - cs_persec->st_shared[i].sh_disk_write /= kbps; - cs_persec->st_shared[i].sh_disk_read /= kbps; - cs_persec->st_shared[i].sh_cache_write /= kbps; - cs_persec->st_shared[i].sh_cache_read /= kbps; - rthroughput += cs_persec->st_shared[i].sh_disk_read; - throughput += cs_persec->st_shared[i].sh_disk_write; - creads += cs_persec->st_shared[i].sh_cache_read; - cwrites += cs_persec->st_shared[i].sh_cache_write; - if (!down) - down = cs_cur->st_shared[i].sh_failed; - if (cs_cur->st_shared[i].sh_failed && bright) { - status_bit = '*'; - } else - status_bit = ' '; - if ((len = strlen(cs_cur->st_shared[i].sh_filename)) - > 15) { - (void) strcpy(fn, "..."); - (void) strcat(fn, - cs_cur->st_shared[i].sh_filename + - len - 12); - } else - (void) strcpy(fn, - cs_cur->st_shared[i].sh_filename); - if (on_off[i]) { - (void) mvprintw(4 + j, 1, - "%3d %-15s%c %6d %6d %6d %6d %6d %6d %6d", - cs_cur->st_shared[i].sh_cd, - fn, - status_bit, - cs_persec->st_shared[i].sh_disk_read, - cs_persec->st_shared[i].sh_disk_write, - cs_persec->st_shared[i].sh_cache_read, - cs_persec->st_shared[i].sh_cache_write, - cs_cur->st_shared[i].sh_numdirty, - cs_cur->st_shared[i].sh_numio, - cs_cur->st_shared[i].sh_numfail); - j++; - } - } - } - bright = !bright; - - (void) mvprintw(4 + j, 22, "------ ------ ------ ------"); - (void) mvprintw(5 + j, 6, " Kbytes/s total:%6d %6d %6d %6d", - (int)rthroughput, (int)throughput, - (int)creads, (int)cwrites); - (void) mvprintw(7 + j, 1, "accesses/s"); - (void) mvprintw(7 + j, 15, "read/s write/s %%readh %%writeh"); - - (void) attron(A_UNDERLINE); - (void) mvprintw(8 + j, 1, " "); - (void) mvprintw(8 + j, 13, - " "); - (void) mvprintw(8 + j, 13, "(misses/s) (misses/s)"); - (void) attroff(A_UNDERLINE); - - (void) mvprintw(9 + j, 0, "%10.2lf %7.2f %7.2f %6.1f %6.1f", - access_s, read_s, write_s, readp * 100.0, writep * 100.0); - (void) mvprintw(10 + j, 0, " (%7.2f ) (%7.2f )\n\n", - rmiss_s, wmiss_s); - - if (down) - (void) mvprintw(20 + j, 1, "* -- disk off-line"); -} - -void -do_calc(void) -{ - int i, j; - - delta_time = USEC_READ() - prev_time; - - cs_persec->st_rdhits = cs_cur->st_rdhits - cs_prev->st_rdhits; - cs_persec->st_rdmiss = cs_cur->st_rdmiss - cs_prev->st_rdmiss; - cs_persec->st_wrhits = cs_cur->st_wrhits - cs_prev->st_wrhits; - cs_persec->st_wrmiss = cs_cur->st_wrmiss - cs_prev->st_wrmiss; - - for (i = 0, j = 0; j < cs_cur->st_count; i++) { - if (i >= sdbc_max_devices) - break; - if (cs_cur->st_shared[i].sh_alloc) { - cs_persec->st_shared[i].sh_disk_write = - FBA_SIZE(cs_cur->st_shared[i].sh_disk_write - - cs_prev->st_shared[i].sh_disk_write); - cs_persec->st_shared[i].sh_disk_read = - FBA_SIZE(cs_cur->st_shared[i].sh_disk_read - - cs_prev->st_shared[i].sh_disk_read); - cs_persec->st_shared[i].sh_cache_read = - FBA_SIZE(cs_cur->st_shared[i].sh_cache_read - - cs_prev->st_shared[i].sh_cache_read); - cs_persec->st_shared[i].sh_cache_write = - FBA_SIZE(cs_cur->st_shared[i].sh_cache_write - - cs_prev->st_shared[i].sh_cache_write); - j++; - } - } - (void) memcpy((char *) cs_prev, (char *) cs_cur, sizeof (_sd_stats_t) + - (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); - prev_time = USEC_READ(); -} - - -void -init_dual(void) -{ -#define IND_ENABLED 0 -#define IND_RESYNC 1 -#define IND_RESYNC_REVERSE 2 -#define IND_VOLUME_DOWN 3 -#define IND_MIRROR_DOWN 4 -#define IND_LOGGING 5 -#define IND_RESYNC_NEEDED 6 -#define IND_REV_RESYNC_NEEDED 7 -#define IND_BITMAP_FAILED 8 -#define IND_FULL_SYNC_NEEDED 9 -#define IND_FCAL_FAILED 10 - (void) strcpy(status[IND_ENABLED], "replicating"); - (void) strcpy(status[IND_RESYNC], "sync"); - (void) strcpy(status[IND_RESYNC_REVERSE], "rev sync"); - (void) strcpy(status[IND_VOLUME_DOWN], "volume down"); - (void) strcpy(status[IND_MIRROR_DOWN], "mirror down"); - (void) strcpy(status[IND_LOGGING], "logging"); - (void) strcpy(status[IND_RESYNC_NEEDED], "need sync"); - (void) strcpy(status[IND_REV_RESYNC_NEEDED], "need rev sync"); - (void) strcpy(status[IND_BITMAP_FAILED], "bitmap failed"); - (void) strcpy(status[IND_FULL_SYNC_NEEDED], "full sync needed"); - (void) strcpy(status[IND_FCAL_FAILED], "fcal failed"); - dual_initted = 1; -} - - -int -rdc_get_maxsets(void) -{ - rdc_status_t rdc_status; - spcs_s_info_t ustatus; - int rc; - - rdc_status.nset = 0; - ustatus = spcs_s_ucreate(); - - rc = RDC_IOCTL(RDC_STATUS, &rdc_status, 0, 0, 0, 0, ustatus); - spcs_s_ufree(&ustatus); - - if (rc == SPCS_S_ERROR) - return (-1); - - return (rdc_status.maxsets); -} - -int -dual_stats() -{ - int ind, i, k, len; - int stars, size, segs; - int rdcindex; - float pct; - char fn[19]; - char *phost; - char *shost; - char *pfile; - char *sfile; - char lhost[16]; - spcs_s_info_t ustats = NULL; - - (void) gethostname(lhost, 16); - - if (rdc_maxsets <= 0) - rdc_maxsets = rdc_get_maxsets(); - - if (rdc_maxsets < 0) - goto no_stats; - - if (!rdc_status) { - rdc_status = malloc(sizeof (rdc_status_t) + - (sizeof (rdc_set_t) * (rdc_maxsets - 1))); - if (!rdc_status) { -no_stats: - (void) mvprintw(0, 20, - "****** Dual Copy Not Available ******"); - return (-1); - } - - rdc_info = rdc_status->rdc_set; - } - - rdc_status->nset = rdc_maxsets; - ustats = spcs_s_ucreate(); - - size = RDC_IOCTL(RDC_STATUS, rdc_status, 0, 0, 0, 0, ustats); - if (size == SPCS_S_ERROR) { - if (ustats) { - spcs_s_report(ustats, stderr); - spcs_s_ufree(&ustats); - } - (void) mvprintw(0, 20, "****** Dual Copy Not Available ******"); - return (-1); - } - spcs_s_ufree(&ustats); - rdc_enabled_sets = rdc_status->nset; - - if (!dual_initted) - init_dual(); - - set_dual_on_off(); - - calc_time(); - - (void) mvprintw(0, 20, "****** Dual Copy Statistics ******"); - (void) attron(A_UNDERLINE); - (void) mvprintw(2, 0, "primary"); - (void) mvprintw(2, 22, "link status"); - (void) mvprintw(2, 36, "secondary"); - (void) mvprintw(2, 54, "dual copy status"); - (void) attroff(A_UNDERLINE); - - for (rdcindex = 0, k = 0; rdcindex < rdc_enabled_sets; rdcindex++) { - if (!(rdc_info[rdcindex].flags & RDC_ENABLED) || - !dual_on_off[rdcindex]) - continue; - - if (rdc_info[rdcindex].sync_flags & RDC_VOL_FAILED) - ind = IND_VOLUME_DOWN; - else if (rdc_info[rdcindex].flags & RDC_FCAL_FAILED) - ind = IND_FCAL_FAILED; - else if (rdc_info[rdcindex].bmap_flags & RDC_BMP_FAILED) - ind = IND_BITMAP_FAILED; - else if (rdc_info[rdcindex].flags & RDC_LOGGING) { - if (rdc_info[rdcindex].sync_flags & - RDC_SYNC_NEEDED) - ind = IND_RESYNC_NEEDED; - else if (rdc_info[rdcindex].sync_flags & - RDC_RSYNC_NEEDED) - ind = IND_REV_RESYNC_NEEDED; - else - ind = IND_LOGGING; - } else if ((rdc_info[rdcindex].flags & RDC_SLAVE) && - (rdc_info[rdcindex].flags & RDC_SYNCING)) { - if (rdc_info[rdcindex].flags & RDC_PRIMARY) - ind = IND_RESYNC_REVERSE; - else - ind = IND_RESYNC; - } else if (rdc_info[rdcindex].flags & RDC_SYNCING) { - if (rdc_info[rdcindex].flags & RDC_PRIMARY) - ind = IND_RESYNC; - else - ind = IND_RESYNC_REVERSE; - } else - ind = IND_ENABLED; - - phost = rdc_info[rdcindex].primary.intf; - pfile = rdc_info[rdcindex].primary.file; - shost = rdc_info[rdcindex].secondary.intf; - sfile = rdc_info[rdcindex].secondary.file; - - if ((len = strlen(phost)) > 8) { - (void) mvprintw(4 + k, 0, ".%+7s:", - phost + len - 7); - } else - (void) mvprintw(4 + k, 0, "%+8s:", phost); - - if ((len = strlen(pfile)) > DISPLEN) { - (void) mvprintw(4 + k, 9, "...%-13s", - pfile + len - DISPLEN + 3); - } else - (void) mvprintw(4 + k, 9, "%-16s", pfile); - - (void) attron(A_BOLD); - (void) mvprintw(4 + k, 26, "*"); - (void) mvprintw(4 + k, 28, "*"); - - (void) mvprintw(4 + k, 56, "%-8s", status[ind]); - (void) attroff(A_BOLD); - - if (ind == IND_RESYNC_REVERSE) { - if (bright && !(rdc_info[rdcindex].flags & RDC_LOGGING)) - (void) mvprintw(4 + k, 27, "<"); - if (rdc_info[rdcindex].flags & RDC_PRIMARY && - !(rdc_info[rdcindex].flags & RDC_LOGGING)) - calc_completion(rdcindex, - rdc_info[rdcindex].bits_set, 4 + k); - } else if (ind == IND_RESYNC) { - if (bright && !(rdc_info[rdcindex].flags & RDC_LOGGING)) - (void) mvprintw(4 + k, 27, ">"); - if (rdc_info[rdcindex].flags & RDC_PRIMARY && - !(rdc_info[rdcindex].flags & RDC_LOGGING)) - calc_completion(rdcindex, - rdc_info[rdcindex].bits_set, 4 + k); - } else if (ind == IND_LOGGING) - (void) mvprintw(4 + k, 27, "."); - else if (ind == IND_ENABLED) - (void) mvprintw(4 + k, 27, "="); - - if ((len = strlen(shost)) > 8) { - (void) mvprintw(4 + k, 30, ".%+7s:", - shost + len - 7); - } else - (void) mvprintw(4 + k, 30, "%+8s:", shost); - - if ((len = strlen(sfile)) > DISPLEN) { - (void) mvprintw(4 + k, 39, "...%-13s", - sfile + len - DISPLEN + 3); - } else - (void) mvprintw(4 + k, 39, "%-16s", sfile); - - k++; - } - - k += 5; - (void) attron(A_UNDERLINE); - for (i = 0; i < 80; i++) - (void) mvprintw(k, i, " "); - k += 2; - (void) mvprintw(k, 0, "partition"); - (void) mvprintw(k, 16, "recovery needed"); - (void) mvprintw(k, 48, "recovery completed"); - (void) attroff(A_UNDERLINE); - k += 2; - - for (rdcindex = 0; rdcindex < rdc_enabled_sets; rdcindex++) { - if (!(rdc_info[rdcindex].flags & RDC_ENABLED) || - !dual_on_off[rdcindex]) - continue; - - if (!(rdc_info[rdcindex].flags & RDC_PRIMARY)) { - continue; - } - if (!(rdc_info[rdcindex].flags & RDC_SLAVE) && - !(rdc_info[rdcindex].flags & RDC_SYNCING) && - !(rdc_info[rdcindex].flags & RDC_LOGGING)) { - continue; - } - - len = strlen(rdc_info[rdcindex].secondary.file); - if (len > 15) { - (void) strcpy(fn, "..."); - (void) strcat(fn, - rdc_info[rdcindex].secondary.file + len - 12); - } else - (void) strcpy(fn, rdc_info[rdcindex].secondary.file); - (void) mvprintw(k, 0, "%-15s", fn); - - segs = FBA_TO_LOG_LEN(rdc_info[rdcindex].volume_size); - pct = segs ? - ((float)rdc_info[rdcindex].bits_set / (float)segs) : 0.0; - stars = (int)(pct * 20.0); - while (stars > 0) { - (void) mvprintw(k, 16 + stars, "*"); - stars--; - } - (void) attron(A_BOLD); - (void) mvprintw(k, 16, "["); - (void) mvprintw(k, 37, "]"); - (void) attroff(A_BOLD); - (void) mvprintw(k, 39, "%6.2f%%", pct * 100.0); - - if (rdc_info[rdcindex].flags & RDC_SYNCING) - pct = ((float)rdc_info[rdcindex].sync_pos / - (float)rdc_info[rdcindex].volume_size); - else - pct = 0.0; - stars = (int)(pct * 20.0); - while (stars > 0) { - (void) mvprintw(k, 48 + stars, "*"); - stars--; - } - (void) attron(A_BOLD); - (void) mvprintw(k, 48, "["); - (void) mvprintw(k, 69, "]"); - (void) attroff(A_BOLD); - (void) mvprintw(k, 70, "%6.2f%%", pct * 100.0); - k++; - } - bright = !bright; - return (0); -} - -/* - * Calculate a time interval in milliseconds using the - * micosecond counter - */ -void -calc_time(void) -{ - unsigned int cur; - - cur = USEC_READ(); - dc_delta_time = cur > dc_prev_time ? cur - dc_prev_time : - cur + 0xFFFFFFFF - dc_prev_time; - dc_delta_time /= 1000; - dc_prev_time = cur; -} - -/* - * Calculate estimated time of completion of resync - */ -void -calc_completion(int cd, int updates_left, int l) -{ - int delta_done; - double rate; - long time_left; - long hours; - long minutes; - static int initted = 0; - - if (!initted) { - updates_prev[cd] = updates_left; - initted = 1; - return; - } - - /* - * Caclulate updates since last check - */ - delta_done = updates_prev[cd] - updates_left; - updates_prev[cd] = updates_left; - - /* - * If no updates, don't bother estimating completion time - */ - if (delta_done <= 0) { - samples[cd] = 0; - return; - } - - rate = delta_done * 1000.0 / dc_delta_time; - - /* - * Calculate rate of updates as a weighted average - * of previous and current rate - */ - if (rate_prev[cd] && samples[cd] > SAMPLE_RATE) - rate = (rate_prev[cd] * 4.0 + rate) / 5.0; - rate_prev[cd] = rate; - samples[cd]++; - - /* - * Get enough samples before making estimate - */ - if (samples[cd]++ < SAMPLE_RATE) - return; - - time_left = (long)(updates_left/rate); /* time left in seconds */ - - if (time_left < 0) - return; - - hours = time_left / (60 * 60); - time_left -= hours * (60 * 60); - minutes = time_left / 60; - time_left -= minutes * 60; - (void) mvprintw(l, 67, - "time %02d:%02d:%02d \n", hours, minutes, time_left); -} - -void -disp_total_stats(void) -{ - unsigned int read_s, write_s, access_s; - double readp, writep; - unsigned int rmiss_s, wmiss_s; - double kbps = 2.0; - int rtotal, wtotal, i, j; - unsigned int throughput = 0, rthroughput = 0, creads = 0, cwrites = 0; - char status_bit, down = 0; - int len; - char fn[19]; - - read_s = cs_cur->st_rdhits; - write_s = cs_cur->st_wrhits; - rmiss_s = cs_cur->st_rdmiss; - wmiss_s = cs_cur->st_wrmiss; - access_s = (read_s + write_s + rmiss_s + wmiss_s); - - rtotal = cs_cur->st_rdhits + cs_cur->st_rdmiss; - wtotal = cs_cur->st_wrhits + cs_cur->st_wrmiss; - if (rtotal != 0) - readp = cs_cur->st_rdhits / (double)rtotal; - else - readp = 0.0; - - if (wtotal != 0) - writep = cs_cur->st_wrhits / (double)wtotal; - else - writep = 0.0; - - set_on_off(); - (void) mvprintw(0, 14, - "****** Storage Cache (Cumulative) ******"); - (void) mvprintw(2, 30, "disk_io cache"); - (void) attron(A_UNDERLINE); - (void) mvprintw(3, 1, - " cd cached_partition reads writes reads writes"); - (void) attroff(A_UNDERLINE); - for (i = 0, j = 0; j < cs_cur->st_count; i++) { - if (i >= sdbc_max_devices) - break; - if (cs_cur->st_shared[i].sh_alloc) { - cs_cur->st_shared[i].sh_disk_write /= kbps; - cs_cur->st_shared[i].sh_disk_read /= kbps; - cs_cur->st_shared[i].sh_cache_write /= kbps; - cs_cur->st_shared[i].sh_cache_read /= kbps; - rthroughput += cs_cur->st_shared[i].sh_disk_read; - throughput += cs_cur->st_shared[i].sh_disk_write; - creads += cs_cur->st_shared[i].sh_cache_read; - cwrites += cs_cur->st_shared[i].sh_cache_write; - if (!down) - down = cs_cur->st_shared[i].sh_failed; - if (cs_cur->st_shared[i].sh_failed && bright) - status_bit = '*'; - else - status_bit = ' '; - if ((len = - strlen(cs_cur->st_shared[i].sh_filename)) > 15) { - (void) strcpy(fn, "..."); - (void) strcat(fn, - cs_cur->st_shared[i].sh_filename + - len - 12); - } else - (void) strcpy(fn, - cs_cur->st_shared[i].sh_filename); - - if (on_off[i]) { - (void) mvprintw(4 + j, 1, - "%3d %-15s%c %10u %10u %10u %10u", - cs_cur->st_shared[i].sh_cd, - fn, - status_bit, - cs_cur->st_shared[i].sh_disk_read, - cs_cur->st_shared[i].sh_disk_write, - cs_cur->st_shared[i].sh_cache_read, - cs_cur->st_shared[i].sh_cache_write); - j++; - } - } - } - bright = !bright; - - (void) mvprintw(4 + j, 22, - "---------- ---------- ---------- ----------"); - (void) mvprintw(5 + j, 8, " Kbytes total:%10u %10u %10u %10u", - (int)rthroughput, (int)throughput, - (int)creads, (int)cwrites); - (void) mvprintw(7 + j, 1, " accesses"); - (void) mvprintw(7 + j, 18, "read write %%readh %%writeh"); - - (void) attron(A_UNDERLINE); - (void) mvprintw(8 + j, 1, " "); - (void) mvprintw(8 + j, 13, - " "); - (void) mvprintw(8 + j, 11, "( misses) ( misses)"); - (void) attroff(A_UNDERLINE); - - (void) mvprintw(9 + j, 0, "%10u %10u %10u %6.1f %6.1f", - access_s, read_s, write_s, readp*100.0, writep*100.0); - (void) mvprintw(10 + j, 0, - " (%10u) (%10u)\n\n", rmiss_s, wmiss_s); - - (void) attron(A_UNDERLINE); - (void) mvprintw(13 + j, 1, "cachesize blocksize"); - (void) attroff(A_UNDERLINE); - (void) mvprintw(14 + j, 1, "%8dK %10d", cs_cur->st_cachesize / 1024, - cs_cur->st_blksize); - - (void) attron(A_UNDERLINE); - (void) mvprintw(16 + j, 1, "Write blocks available:"); - (void) attroff(A_UNDERLINE); - (void) mvprintw(17 + j, 1, "Net 0: %6d", cs_cur->st_wlru_inq); - - (void) attron(A_UNDERLINE); - (void) mvprintw(19 + j, 1, "LRU stats: Blocks Requeued Optimized"); - (void) attroff(A_UNDERLINE); - (void) mvprintw(20 + j, 7, "%12d %12u %12u", cs_cur->st_lru_blocks, - cs_cur->st_lru_req, cs_cur->st_lru_noreq); - - if (down) - (void) mvprintw(25 + j, 1, "* -- disk off-line"); -} diff --git a/usr/src/cmd/avs/sdbc/sdbc_dynmem.c b/usr/src/cmd/avs/sdbc/sdbc_dynmem.c deleted file mode 100644 index f6d25a11f4..0000000000 --- a/usr/src/cmd/avs/sdbc/sdbc_dynmem.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - */ - -/* - * This program is strictly for demonstration purposes and not for - * production use. It demonstrates how to access the dynamic memory - * caching statistics and turning variables via the kstat library. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <stropts.h> -#include <ctype.h> -#include <unistd.h> -#include <memory.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <signal.h> -#include <locale.h> -#include <kstat.h> - -#include <sys/types.h> -#include <sys/time.h> -#include <sys/sysinfo.h> -#include <sys/buf.h> -#include <sys/vfs.h> -#include <sys/dnlc.h> - -#define TRUE 1 -#define FALSE 0 -#define SDBC_KSTAT_MODULE "sdbc" -#define SDBC_KSTAT_DYNMEM "dynmem" - -typedef struct { - int instance; - kstat_t *ksp; - } KSTAT_INFO_DEF; - -typedef struct { - kstat_named_t *knp; - char *named; - int newval; - } DYNMEM_KNP_DEFN; - -typedef enum { -MONITOR = 0, -MAXLIST, -AGECT1, -AGECT2, -AGECT3, -SEC1, -SEC2, -SEC3, -PCNT1, -PCNT2, -HDPCNT, -ALLOC, -DEALLOC, -HISTORY, -NODATA, -CAND, -DEALLOCS, -HOSTS, -PESTS, -METAS, -HOLDS, -OTHERS, -NOTAVAIL, -DIRECTIVE, -SIMPLECT -} arglist_id; - -#define NO_VALUE -1 - -DYNMEM_KNP_DEFN dynmem_knp[] = { - NULL, "sdbc_monitor_dynmem", NO_VALUE, - NULL, "sdbc_max_dyn_list", NO_VALUE, - NULL, "sdbc_cache_aging_ct1", NO_VALUE, - NULL, "sdbc_cache_aging_ct2", NO_VALUE, - NULL, "sdbc_cache_aging_ct3", NO_VALUE, - NULL, "sdbc_cache_aging_sec1", NO_VALUE, - NULL, "sdbc_cache_aging_sec2", NO_VALUE, - NULL, "sdbc_cache_aging_sec3", NO_VALUE, - NULL, "sdbc_cache_aging_pcnt1", NO_VALUE, - NULL, "sdbc_cache_aging_pcnt2", NO_VALUE, - NULL, "sdbc_max_holds_pcnt", NO_VALUE, - NULL, "sdbc_alloc_cnt", NO_VALUE, - NULL, "sdbc_dealloc_cnt", NO_VALUE, - NULL, "sdbc_history", NO_VALUE, - NULL, "sdbc_nodatas", NO_VALUE, - NULL, "sdbc_candidates", NO_VALUE, - NULL, "sdbc_deallocs", NO_VALUE, - NULL, "sdbc_hosts", NO_VALUE, - NULL, "sdbc_pests", NO_VALUE, - NULL, "sdbc_metas", NO_VALUE, - NULL, "sdbc_holds", NO_VALUE, - NULL, "sdbc_others", NO_VALUE, - NULL, "sdbc_notavail", NO_VALUE, - NULL, "sdbc_process_directive", NO_VALUE, - NULL, "sdbc_simplect", NO_VALUE, - NULL, NULL, NO_VALUE - }; - -/* - * Print Usage - */ -static void -print_usage() -{ - (void) printf("USAGE: wake - wakeup thread, hys - max hysteresis\n"); - (void) printf(" mon 1 - monitor shutdown\n"); - (void) printf(" 2 - monitor thread stats1\n"); - (void) printf(" 4 - monitor thread stats2\n"); - (void) printf(" age1 n - num cyc to full host aging and " - "dealloc\n"); - (void) printf(" age2 n - num cyc to full meta aging and " - "dealloc\n"); - (void) printf(" age3 n - num cyc to full one pg aging and " - "dealloc\n"); - (void) printf(" sec1 n - sec1 aging time\n"); - (void) printf(" sec2 n - sec2 aging time\n"); - (void) printf(" sec3 n - sec3 aging time\n"); - (void) printf(" pcnt1 n - percent to sec1/sec2 trans\n"); - (void) printf(" pcnt2 n - percent to sec2/sec3 trans\n"); - (void) printf(" hdpcnt n - max percent of cents for holds\n"); - (void) printf(" list n - host+pest max len\n"); - (void) printf("No Args - print current settings only\n"); -} - -/* - * Main - */ -/* ARGSUSED */ -#ifdef lint -int -sd_dynmem_lintmain(int argc, char *argv[]) -#else -int -main(int argc, char *argv[]) -#endif -{ - DYNMEM_KNP_DEFN *p_dynmem_knp; - kstat_ctl_t *kctl; - KSTAT_INFO_DEF info_ksp; - int val; - char **pargs, **cur_pargs; - - /* - * grab and parse argument list - */ - p_dynmem_knp = dynmem_knp; - pargs = argv; - while (*pargs) { - (void) printf("pargs=%x - %s\n", (uint_t)pargs, *pargs); - - cur_pargs = pargs; - pargs++; - - if (strcmp(*cur_pargs, "h") == 0) { - print_usage(); - return (0); - } - - if (strcmp(*cur_pargs, "wake") == 0) { - if ((p_dynmem_knp+DIRECTIVE)->newval == NO_VALUE) - (p_dynmem_knp+DIRECTIVE)->newval = 0; - (p_dynmem_knp+DIRECTIVE)->newval |= 0x01; - continue; - } - - if (strcmp(*cur_pargs, "hys") == 0) { - if ((p_dynmem_knp+DIRECTIVE)->newval == NO_VALUE) - (p_dynmem_knp+DIRECTIVE)->newval = 0; - (p_dynmem_knp+DIRECTIVE)->newval |= 0x02; - continue; - } - - if (strcmp (*cur_pargs, "mon") == 0) { - val = atoi(*pargs); - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - pargs++; - (p_dynmem_knp+MONITOR)->newval = val; - } - - if (strcmp (*cur_pargs, "age1") == 0) { - val = atoi(*pargs); - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - pargs++; - (p_dynmem_knp+AGECT1)->newval = val; - } - - if (strcmp(*cur_pargs, "age2") == 0) { - val = atoi(*pargs); - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - pargs++; - (p_dynmem_knp+AGECT2)->newval = val; - } - - if (strcmp(*cur_pargs, "age3") == 0) { - val = atoi(*pargs); - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - pargs++; - (p_dynmem_knp+AGECT3)->newval = val; - } - - if (strcmp (*cur_pargs, "sec1") == 0) { - val = atoi(*pargs); - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - pargs++; - if (val == 0) - break; - else { - (p_dynmem_knp+SEC1)->newval = val; - continue; - } - } - - if (strcmp(*cur_pargs, "sec2") == 0) { - val = atoi(*pargs); - pargs++; - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - if (val == 0) - break; - else { - (p_dynmem_knp+SEC2)->newval = val; - continue; - } - } - - if (strcmp(*cur_pargs, "sec3") == 0) { - val = atoi(*pargs); - pargs++; - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - if (val == 0) - break; - else { - (p_dynmem_knp+SEC3)->newval = val; - continue; - } - } - - if (strcmp(*cur_pargs, "pcnt1") == 0) { - val = atoi(*pargs); - pargs++; - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - if (val == 0) - break; - else { - (p_dynmem_knp+PCNT1)->newval = val; - continue; - } - } - - if (strcmp(*cur_pargs, "pcnt2") == 0) { - val = atoi(*pargs); - pargs++; - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - if (val == 0) - break; - else { - (p_dynmem_knp+PCNT2)->newval = val; - continue; - } - } - - if (strcmp(*cur_pargs, "hdpcnt") == 0) { - val = atoi(*pargs); - pargs++; - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - if (val < 0) - break; - else { - (p_dynmem_knp+HDPCNT)->newval = val; - continue; - } - } - - if (strcmp(*cur_pargs, "list") == 0) { - val = atoi(*pargs); - pargs++; - (void) printf("errno=%x, %s=%x\n", errno, *cur_pargs, - val); - if (val == 0) - break; - else { - (p_dynmem_knp+MAXLIST)->newval = val; - continue; - } - } - } /* while(*pargs && cl) */ - - /* - * open the kstat library - */ - kctl = kstat_open(); - if (kctl == NULL) { - (void) printf("kstat_open() failed\n"); - return (1); - } - - /* - * is the name module about - */ - info_ksp.instance = 0; - info_ksp.ksp = kstat_lookup(kctl, SDBC_KSTAT_MODULE, 0, - SDBC_KSTAT_DYNMEM); - if (info_ksp.ksp == NULL) { - (void) printf("No module to report\n"); - return (1); - } - - /* - * using the info get a copy of the data - */ - if (kstat_read(kctl, info_ksp.ksp, NULL) == -1) { - (void) printf("Can't read kstat\n"); - return (1); - } - - /* - * print the current data - */ - p_dynmem_knp = dynmem_knp; - while (p_dynmem_knp->named) { - p_dynmem_knp->knp = - kstat_data_lookup(info_ksp.ksp, p_dynmem_knp->named); - if (p_dynmem_knp->knp == NULL) { - (void) printf("kstat_data_lookup(%s) failed\n", - p_dynmem_knp->named); - return (1); - } else { - (void) printf("%s: %x\n", p_dynmem_knp->named, - (uint_t)p_dynmem_knp->knp->value.ul); - p_dynmem_knp++; - } - } - - /* - * modify the data and write it back - */ - p_dynmem_knp = dynmem_knp; - while (p_dynmem_knp->named) { - if (p_dynmem_knp->newval != NO_VALUE) - p_dynmem_knp->knp->value.ul = p_dynmem_knp->newval; - p_dynmem_knp++; - } - - if (kstat_write(kctl, info_ksp.ksp, NULL) == -1) { - (void) printf("kstat_write() failed\n"); - return (1); - } - - (void) printf("Finished (h for help)\n"); - return (0); -} diff --git a/usr/src/cmd/avs/sdbc/sdbc_ioctl.c b/usr/src/cmd/avs/sdbc/sdbc_ioctl.c deleted file mode 100644 index baa0858236..0000000000 --- a/usr/src/cmd/avs/sdbc/sdbc_ioctl.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * SDBC user level ioctl interface - */ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <sys/types.h> -#include <fcntl.h> -#include <strings.h> - -#include <sys/nsctl/sd_cache.h> -#include <sys/nsctl/sd_conf.h> -#include <sys/nsctl/sdbc_ioctl.h> -#include <sys/unistat/spcs_s.h> -#include <sys/unistat/spcs_s_u.h> - -#include <sys/nsctl/sv.h> -#include <sys/nsctl/sv_impl.h> - - -const char *__sdbc_dev = "/dev/sdbc"; -static int __sdbc_fd; - - -static int -__sdbc_open(void) -{ - int fd; - - fd = open("/dev/nsctl", O_RDONLY); - if (fd >= 0) - (void) close(fd); - - fd = open(__sdbc_dev, O_RDONLY); - if (fd < 0) - return (-1); - - return (__sdbc_fd = fd); -} - - -static void -sv_list() -{ - sv_name_t svn[1]; - sv_name_t *svn_system; - sv_list_t svl; - static int fd = -1; - - if (fd < 0) - fd = open(SV_DEVICE, O_RDONLY); - if (fd < 0) - return; - - bzero(&svl, sizeof (svl)); - bzero(&svn[0], sizeof (svn)); - - svl.svl_names = &svn[0]; - svl.svl_error = spcs_s_ucreate(); - - if (ioctl(fd, SVIOC_LIST, &svl) < 0) - return; - - svn_system = calloc(svl.svl_maxdevs, sizeof (*svn)); - if (svn_system == NULL) - return; - - /* Grab the system list from the driver */ - svl.svl_count = svl.svl_maxdevs; - svl.svl_names = svn_system; - - (void) ioctl(fd, SVIOC_LIST, &svl); - - free(svn_system); - spcs_s_ufree(&svl.svl_error); -} - - -int -sdbc_ioctl(long cmd, long a0, long a1, long a2, long a3, long a4, - spcs_s_info_t *ustatus) -{ - _sdbc_ioctl_t args; - int rc; - - *ustatus = NULL; - - if (!__sdbc_fd && __sdbc_open() < 0) - return (-1); - - switch (cmd) { - /* - * These ioctls work on open cache descriptors. The sv_list() function - * has the side-effect of re-opening all configured descriptors. - * Without this call, devices seem to "disappear" from the system when - * certain reconfiguration operations, for example II or SNDR disable, - * are done. - * It does rely on SV being configured, so in an STE-only environment - * the disappearing will still seem to happen. - */ - case SDBC_SET_CD_HINT: - case SDBC_GET_CD_HINT: - case SDBC_STATS: - case SDBC_GET_CD_BLK: - case SDBC_INJ_IOERR: - case SDBC_CLR_IOERR: - sv_list(); - break; - - default: - break; - } - - args.arg0 = a0; - args.arg1 = a1; - args.arg2 = a2; - args.arg3 = a3; - args.arg4 = a4; - args.magic = _SD_MAGIC; /* for versioning */ - args.sdbc_ustatus = spcs_s_ucreate(); - - if ((rc = ioctl(__sdbc_fd, cmd, &args)) < 0) { - *ustatus = args.sdbc_ustatus; - } else { - spcs_s_ufree(&args.sdbc_ustatus); - *ustatus = NULL; - } - - return (rc); -} |