#!/bin/ksh #******************************************************************************* # # NAME: symdisks # SUMMARY: %description% # COMPONENT: solsysd # VERSION: rm6_10 # UPDATE DATE: %date_modified: Tue Jul 29 15:54:24 1997 % # PROGRAMMER: %created_by: mgallagh % # # Copyright 1997 by Symbios Logic Inc. # # DESCRIPTION: # symdisks is a variation on the Solaris "disks" program which is part of and # which is used by SYMplicity storage manager. Its two main functions are # (1) to generate the device names which are private to SYMplicity storage # manager, and (2) to generate the public (i.e., in /dev) device names ensuring # that names which are hidden by the layered RDAC driver do not show up # inappropriately. # # NOTES: # symdisks calls "disks" to accomplish its task. # # REFERENCE: # # CODING STANDARD WAIVERS: # #******************************************************************************* #******************************************************************************* # PROCEDURE: MutexAcquire # SUMMARY: Acquire ownership of the mutual exclusion file # # DESCRIPTION: # MutexAcquire makes up to 3600 attempts, delaying one second between tries, to # acquire the "add disk" mutex file. The purpose of this mutex file is to # enusre that only one thread is altering the hidden/non-hidden state of RDAC- # controlled sd nodes (otherwise, device names can really get fouled up.) # # SYNTAX: # MutexAcquire # # NOTES: # The actual mutex acquisition is implemented in the C program rm_mutex_acquire, # which relies on standard UNIX O_CREAT semantics # # RETURNS: # Nothing # MutexAcquire() { while true do $RM_HOME/bin/rm_mutex_acquire /tmp/mutex.symdisks if [ $? = 0 ] then break; fi sleep 1 done; } #******************************************************************************* # PROCEDURE: MutexRelease # SUMMARY: Release the mutual exclusion file # # DESCRIPTION: # MutexRelease deletes the "add disk" mutex file (the same one MutexAcquire # tries to acquire); again, because of O_CREAT semantics, this action has # the effect of releasing the mutex, so that it may be acquired by another # thread. # # SYNTAX: # MutexRelease # # NOTES: # # RETURNS: # Nothing # MutexRelease() { /bin/rm /tmp/mutex.symdisks; } #******************************************************************************* # PROCEDURE: CleanSd # SUMMARY: Remove sd driver nodes corresponding to RAID devices # # DESCRIPTION: # CleanSd removes sd driver nodes FOR RAID DEVICES ONLY from a device directory. # The directory to be cleaned is given by "$1". Both raw and block directories # are cleaned. # # SYNTAX: # CleanSd # - the path to the device directory from which the nodes are to # be removed (e.g., /dev/SYMsm, or just "/") # # NOTES: # Other parts of rdacctrl may wish to know if this routing encountered any sd # nodes to delete - for this reason, this routine set the flag (really a file) # /tmp/sdDeleted. if sd nodes are actually deleted. # # RETURNS: # Nothing # CleanSd() { $LAD 2>/dev/null | while read CTRL_INFO do DEV=`echo $CTRL_INFO | cut -d" " -f1` TARGET=`echo $DEV | cut -dt -f2 | cut -dd -f1` PHYS_PATH=/`ls -l $RMDEVROOT/dev/rdsk/$DEV 2>/dev/null | cut -d\> -f2 | awk -F/ '{ ORS = "/"; for (i = 4; i < NF-1; ++i) print $i; ORS="\n"; print $(NF-1) }'`/sd@$TARGET DEL_LIST=`ls -l $1/dev/rdsk | grep $PHYS_PATH | tr -s " " | cut -d" " -f9` if [ -n "$DEL_LIST" ] then ( if [ -d $1/dev/rdsk ] then cd $1/dev/rdsk rm $DEL_LIST 2>/dev/null fi ) & ( if [ -d $1/dev/dsk ] then cd $1/dev/dsk rm $DEL_LIST 2>/dev/null fi ) & wait touch /tmp/sdDeleted.$$ fi done; } #******************************************************************************* # PROCEDURE: CleanRd # SUMMARY: Remove rdriver nodes from device directories. # # DESCRIPTION: # CleanRd removes all node referring to the RDAC driver from a set of device # directories (both dsk and rdsk). The directory to be cleaned is given by # "$1". # # SYNTAX: # CleanRd # - the path to the device directory from which the nodes are to be # removed (e.g., /dev/SYMsm, or just "/") # # NOTES: # # RETURNS: # Nothing # CleanRd() { DELETE_LIST=`ls -l $1/dev/rdsk | grep $RDAC_DRIVER_NAME | tr -s " " | cut -d" " -f9` ( if [ -d $1/dev/rdsk ] then cd $1/dev/rdsk /bin/rm $DELETE_LIST 2>/dev/null fi ) & ( if [ -d $1/dev/dsk ] then cd $1/dev/dsk /bin/rm $DELETE_LIST 2>/dev/null fi ) & wait; } #******************************************************************************* # PROCEDURE: PrimeDisks # SUMMARY: "Prime" the disks utility to make the desired device names. # # DESCRIPTION: # PrimeDisks determines what rdriver devices are configured and creates # "placeholder" symlinks in /dev, so as to force disks to create the expected # device name. Without this sort of action, device name links generated by # disks during parallel LUN creation is unpredictable. # # SYNTAX: # PrimeDisks # # NOTES: # # RETURNS: # Nothing # PrimeDisks() { grep -v "^#" ${RD_CONF} | grep "dev_" | while read RD_CONF_ENTRY do UNIT=`echo "${RD_CONF_ENTRY}" | cut -d= -f4 | cut -d" " -f1` UNIT_HEX=`echo ${UNIT} | awk '{printf("%x", $0)}'` TARG=`echo "${RD_CONF_ENTRY}" | cut -d= -f5 | cut -d" " -f1` TARG_HEX=`echo ${TARG} | awk '{printf("%x", $0)}'` CTRL=`echo "${RD_CONF_ENTRY}" | cut -d@ -f2 | cut -d\" -f1` PHYS_NAME=../../devices/pseudo/rdnexus@${CTRL}/rdriver@${TARG_HEX},${UNIT_HEX}:a DEV_NAME=c${CTRL}t${TARG}d${UNIT}s0 if [ ! -h ${ROOT}/dev/rdsk/${DEV_NAME} ] then ln -s ${PHYS_NAME} ${ROOT}/dev/dsk/${DEV_NAME} >/dev/null 2>&1 ln -s ${PHYS_NAME},raw ${ROOT}/dev/rdsk/${DEV_NAME} >/dev/null 2>&1 fi done; } #******************************************************************************* # PROCEDURE: symdisks (main) # SUMMARY: Create device names for SYMplicity storage manager # # DESCRIPTION: # The main procedure of symdisks does the following: (1) extracts pertinent # parameters from the rmparams file, (2) parses the command line options, # (3) conceals (or exposes, in the case of -x) the sd nodes, (4) runs the # Solaris disks program, (5) eliminates extraneous RDAC nodes (DEVDIR = # RMDEVROOT only),and (5) conceals the sd nodes before exiting. # # SYNTAX: # symdisks [ -v ] [ -x ] [ -r ] # -v operate in "verbose" mode ("set -x") # -x run disks with sd nodes exposed # leave created RDAC nodes laying around; (normal mode is: make sd # nodes and DON'T leave RDAC nodes laying around # -r specify a directory where the names are to be created # (default is $RMDEVROOT) # -d run "drvconfig" before disks on the driver # # NOTES: # # RETURNS: # 0 - success # 1 - illegal command line options # S Y M D I S K S M A I N P R O C E D U R E # RDAC_DRIVER_NAME=rdriver RD_CONF=/kernel/drv/rdriver.conf RMPARAMS_FILE=/etc/raid/rmparams RM_HOME=`grep -v "^#" $RMPARAMS_FILE | grep System_RmHomeDirectory | cut -d= -f2` RM_BOOT_HOME=`grep -v "^#" $RMPARAMS_FILE | grep System_RmBootHomeDirectory | cut -d= -f2` LAD=$RM_BOOT_HOME/lad RMDEVROOT=`grep -v "^#" $RMPARAMS_FILE | grep "System_AltDevDirRoot" | cut -d= -f2 | awk -F/ '{ ORS = "/"; for (i = NF; i > 1; --i) print $i; ORS = "\n"; print $1 }' | cut -d"/" -f3-32 | awk -F/ '{ ORS = "/"; for (i = NF; i > 1; --i) print $i; ORS = "\n"; print $1 }'` if grep -v "^#" $RMPARAMS_FILE | grep "Rdac_SupportDisabled.*=.*TRUE" >/dev/null 2>&1 then RDAC_DISABLED=TRUE HIDE_SD=/bin/true # NO-OP command else HIDE_SD=$RM_BOOT_HOME/hide_sd # command to conceal sd nodes from "disks" fi USAGE="Usage: $0 [ -v ] [ -x ] [ -r ] [ -d driver-name ]" set -- `getopt xvr:d: $* 2>/dev/null` if [ $? != 0 ] then echo $USAGE exit 1 fi #defaults DEVDIR="$RMDEVROOT" OFF=on ON=on for i in $* do case $i in -x) EXPOSE=TRUE; shift;; -v) VERBOSE=TRUE; shift;; -r) DEVDIR=$2; shift 2;; -d) DRVCONFIG_DRIVER=$2; shift 2;; --) shift; break;; esac done if [ "$DEVDIR" = "$RMDEVROOT" ] then EXPOSE=TRUE fi if [ -n "$EXPOSE" ] then OFF=off ON=on fi if [ -n "${VERBOSE}" ] then set -x fi MutexAcquire if [ -n "$DRVCONFIG_DRIVER" ] then /usr/sbin/drvconfig -i $DRVCONFIG_DRIVER >/dev/null 2>&1 fi if [ -z "$EXPOSE" ] && [ -z "$RDAC_DISABLED" ] then CleanSd $DEVDIR PrimeDisks fi $HIDE_SD $OFF >/dev/null 2>&1 # has no effect if RDAC disabled /usr/sbin/disks -r $DEVDIR 2>/dev/null $HIDE_SD $ON >/dev/null 2>&1 if [ -z "$EXPOSE" ] && [ -z "$RDAC_DISABLED" ] then CleanSd $DEVDIR fi if [ -n "$EXPOSE" ] then CleanRd $DEVDIR fi MutexRelease exit 0