#!/bin/ksh # # We maintain a list of usable cache devices that can be assigned # to each pool as needed (think of it as an Object Pool of cache devices) # This list lives in $ZPOOL_CACHE_DB # ZPOOL_CACHE_DB=/tmp/zpool_cache_devices.txt ZPOOL_CACHE=$(cat $ZPOOL_CACHE_DB) case $1 in "create") set -A zpool_cache $ZPOOL_CACHE # the pool name is the first arg without a - :-) set -A args $@ FOUND="" i=0 while [ -z "$FOUND" ] && [ $i -le "$#" ] do i=$(($i + 1)) FOUND=$(echo ${args[$i]} | /usr/bin/grep -v '^-') done POOL=${args[$i]} /usr/sbin/zpool_real $@ RET=$? if [ $RET -ne 0 ] then exit $RET fi # pull device from cache CACHE=${zpool_cache[0]} if [ -z "${CACHE}" ] then /usr/sbin/zpool_real add $POOL else /usr/sbin/zpool_real add $POOL cache $CACHE cat $ZPOOL_CACHE_DB | grep -v $CACHE > ${ZPOOL_CACHE_DB}.$$ mv ${ZPOOL_CACHE_DB}.$$ $ZPOOL_CACHE_DB fi exit $RET ;; "destroy") # the pool name is the first arg without a - :-) set -A args $@ FOUND="" i=0 while [ -z "$FOUND" ] && [ $i -le "$#" ] do i=$(($i + 1)) FOUND=$(echo ${args[$i]} | /usr/bin/grep -v '^-') done POOL=${args[$i]} # check to see if this pool has a cache device CACHE_DEV="" /usr/sbin/zpool_real iostat -v $POOL 1 1 > /tmp/file.$$ grep "^cache " /tmp/file.$$ > /dev/null if [ $? -eq 0 ] then CACHE_DEV=$(tail -3 /tmp/file.$$ | head -1 | awk '{print $1}') fi rm /tmp/file.$$ /usr/sbin/zpool_real $@ RET=$? if [ $RET -ne 0 ] then return $RET fi # if we had a cache device, return it to the pool if [ ! -z "${CACHE_DEV}" ] then echo $CACHE_DEV >> $ZPOOL_CACHE_DB fi exit $RET ;; *) /usr/sbin/zpool_real $@ exit $? esac