Unsure of SATA drive spindown

Status
Not open for further replies.

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Im using 4G ram and 64bit version of Freenas. The plugins I would like to use are rtorrent, logitech media server but after searching around the forum I found out they are not available yet. I'm thinking of install the full freebsd but still not figuring how to make it run on USB
Doubt you will get FreeBSD to run on a USB drive very well. You would be better off using a single hard drive to run FreeBSD if that is the path you want to go down.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
I bought a M1015 PCIe card and I keep playing with the spindown function in both when HDDs are plugged in directly to the MB and to the M1015 card. For the case of using PCIe card with Millhouse's sasidle script to spindown, I notice that if i create pool when HDDs are in the card, the script work fine. But If I create pool when HDDs were plugged in Sata ports then move to the PCIe card, the sasidle script has problem when sending stop command. It understands as adaX instead of daX which makes the script not working in this case.

I'm using Freenas 8.04 x64
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
The script obtains the disk identifiers from the FreeNAS configuration database associated with the pool being monitored. If you switch the disks from one controller to another, which cases the disk identifiers to change, then the script will continue to query the config database but be told the old and incorrect disk identifiers as they existed on the previous controller (daX for PCIe, adaX for SATA).

You can override the disks by passing a --devices parameter eg. "--devices /dev/da[0-4]", and the script will no longer query the database. Add this to /etc/rc.conf in the sasidled_args line.

Question: Once you've switched the disks from one controller to another, how does FreeNAS handle this, does it mount the pool correctly? Since the script is getting duff disk identifiers from FreeNAS, I'd assume that FreeNAS isn't happy when you create the pool using SATA ports then move them to the PCIe controller. Are you reimporting the pool once you've moved it to PCIe, presumably this would store the correct configuration for the disks in the database.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
yes, the pool is mounted correctly when i switch ports. I don't need to do anything, it just works. In the storage webpage it understands as da [0-4]

I set your script start up at boot, my /etc/rc.conf should be like this?


sasidled_enable=YES
sasidled_cmdpath=/root
sasidled_args="--devices /dev/da[0-4]"
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
That may work (it's been a while since I tested it!) - if not, you'll need specify the individual disks explicitly, eg. sasidled_args="--devices '/dev/da0 /dev/da1 /dev/da2'" (note that there's a second apostrophe before the closing double quote).

Just out of interest - and before you override the default disk detection - when you have the disks plugged into the SATA ports (ie. when using the configuration that doesn't work) can you paste the output of the following commands into this thread - it may give me a better idea of what is going on:
Code:
grep sasidle /var/log/messages
camcontrol devlist


And if you could also run the same commands with the disks back in the PCIe ports (where the pool was created) that would be very helpful too... Thanks.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
I will do it again and let you know soon. Good that's i'm still in testing period, so no worry about data
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
Scenario 1: pool created when HDDs are plugged in SATA ports in MB then switch all HDDs to PCIe

Code:
[root@freenas] ~# grep sasidle /var/log/messages
May 28 13:56:49 freenas sasidle[1461]: /root/sasidle starting
May 28 13:56:49 freenas sasidle[1461]: Identifying devices for pool "tank"...
May 28 13:56:49 freenas sasidle[1461]: ---------------------------------------------------------
May 28 13:56:49 freenas sasidle[1461]: Monitored Pool:    tank
May 28 13:56:49 freenas sasidle[1461]: Monitored Devices: ada1 ada2 ada3 ada4
May 28 13:56:49 freenas sasidle[1461]: Polling Interval:  60 seconds
May 28 13:56:49 freenas sasidle[1461]: Idle Timeout:      30 * 60 seconds
May 28 13:56:49 freenas sasidle[1461]: ASync Enabled:     Yes
May 28 13:56:49 freenas sasidle[1461]: Simulated Stop:    No
May 28 13:56:49 freenas sasidle[1461]: Log Disk Start:    Yes
May 28 13:56:49 freenas sasidle[1461]: ---------------------------------------------------------
May 28 13:56:49 freenas sasidle[1461]:
May 28 13:56:49 freenas sasidle[1461]: 030: capacity     operations    bandwidth
May 28 13:56:49 freenas sasidle[1461]: 030: pool         used  avail   read  write   read  write
May 28 13:56:49 freenas sasidle[1461]: 030: ----------  -----  -----  -----  -----  -----  -----
May 28 13:56:49 freenas sasidle[1461]: 030: tank         824K  10.9T      0      6  4.02K  25.5K
May 28 13:57:49 freenas sasidle[1461]: 029: tank         824K  10.9T      0      0      0      0
May 28 13:58:49 freenas sasidle[1461]: 028: tank         824K  10.9T      0      0      0      0
May 28 13:59:49 freenas sasidle[1461]: 027: tank         824K  10.9T      0      0      0      0
May 28 14:00:49 freenas sasidle[1461]: 026: tank         824K  10.9T      0      0      0      0
May 28 14:01:49 freenas sasidle[1461]: 025: tank         824K  10.9T      0      0      0      0
May 28 14:02:49 freenas sasidle[1461]: 024: tank         824K  10.9T      0      0      0      0
May 28 14:03:49 freenas sasidle[1461]: 023: tank         824K  10.9T      0      0      0      0



Code:

[root@freenas] ~# camcontrol devlist
<ATA ST3000DM001-9YN1 CC9D>        at scbus0 target 0 lun 0 (da0,pass0)
<ATA ST3000DM001-9YN1 CC9D>        at scbus0 target 1 lun 0 (da1,pass1)
<ATA ST33000651AS CC45>            at scbus0 target 2 lun 0 (da2,pass2)
<ATA ST3000DM001-9YN1 CC4C>        at scbus0 target 3 lun 0 (da3,pass3)
<SanDisk U3 Cruzer Micro 8.01>     at scbus7 target 0 lun 0 (da4,pass4)
<SanDisk U3 Cruzer Micro 8.01>     at scbus7 target 0 lun 1 (cd0,pass5)




Scenario 2: Pool created when HDDs are plugged in PCIe

Code:
[root@freenas] ~# grep sasidle /var/log/messages
May 28 14:10:53 freenas sasidle[1500]: /root/sasidle starting
May 28 14:10:53 freenas sasidle[1500]: Identifying devices for pool "tank"...
May 28 14:10:53 freenas sasidle[1500]: ---------------------------------------------------------
May 28 14:10:53 freenas sasidle[1500]: Monitored Pool:    tank
May 28 14:10:53 freenas sasidle[1500]: Monitored Devices: da0 da1 da2 da3
May 28 14:10:53 freenas sasidle[1500]: Polling Interval:  60 seconds
May 28 14:10:53 freenas sasidle[1500]: Idle Timeout:      30 * 60 seconds
May 28 14:10:53 freenas sasidle[1500]: ASync Enabled:     Yes
May 28 14:10:53 freenas sasidle[1500]: Simulated Stop:    No
May 28 14:10:53 freenas sasidle[1500]: Log Disk Start:    Yes
May 28 14:10:53 freenas sasidle[1500]: ---------------------------------------------------------
May 28 14:10:53 freenas sasidle[1500]:
May 28 14:10:53 freenas sasidle[1500]: 030: capacity     operations    bandwidth
May 28 14:10:53 freenas sasidle[1500]: 030: pool         used  avail   read  write   read  write
May 28 14:10:53 freenas sasidle[1500]: 030: ----------  -----  -----  -----  -----  -----  -----
May 28 14:10:53 freenas sasidle[1500]: 030: tank         159K  10.9T      1     10  1.83K  12.9K
May 28 14:11:53 freenas sasidle[1500]: 029: tank         159K  10.9T      0      0      0      0


Code:
[root@freenas] ~# camcontrol devlist
<ATA ST3000DM001-9YN1 CC9D>        at scbus0 target 0 lun 0 (da0,pass0)
<ATA ST3000DM001-9YN1 CC9D>        at scbus0 target 1 lun 0 (da1,pass1)
<ATA ST33000651AS CC45>            at scbus0 target 2 lun 0 (da2,pass2)
<ATA ST3000DM001-9YN1 CC4C>        at scbus0 target 3 lun 0 (da3,pass3)
<SanDisk U3 Cruzer Micro 8.01>     at scbus7 target 0 lun 0 (da4,pass4)
<SanDisk U3 Cruzer Micro 8.01>     at scbus7 target 0 lun 1 (cd0,pass5)

 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
Thanks for that. Well, in scenario 1 it's definitely as I thought and the FreeNAS database is holding false information, ie. the old disk identifiers as they were if the disks remained connected to the SATA ports - I'm surprised FreeNAS is able to manage the volume/pool correctly if it has the wrong disk identifiers in its database (in Scenario #1, are you able to edit disks succesfully, eg. change HDD Standby, in "View Disks"?)

Hopefully you've got a workaround though, by specifying --devices to the script.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
yeah, it's good to know how it works so I can plan ahead what to do in the future, since I will be using 2 pools in my server, 1 pool will be from MB and the other from PCIe. I'm thinking of adding another M1015 to my system when I upgrade my CPU that supports Vt-d, in that case I have to move from MB sata ports to the new PCIe card

Thanks Milhouse for your script again. it works great
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I think one thing very important to take away from the experiment is the pools operated, or in other words you could access your data. That is so important if you had a failure of a card/MB. Not everything appears to be 100% but data access seems to be which is one reason I chose FreeNAS. I don't want to be limited to the same hardware to access my data if there were a failure.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
@Milhouse: I have two pools (1 raidz1 4HDD and 1 mirror), all of the pools connected to 1 SAS card. When I have sasidle run at boot, I notice that only 1 pool is recognized in the log so it means only that pool is monitored by your script. What should I do to to make 2 pools or more monitored? Thank you
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
@Milhouse: I have two pools (1 raidz1 4HDD and 1 mirror), all of the pools connected to 1 SAS card. When I have sasidle run at boot, I notice that only 1 pool is recognized in the log so it means only that pool is monitored by your script. What should I do to to make 2 pools or more monitored? Thank you

Yes, it's a limitation of the script (think I acknowledged that somewhere) - it's only designed to monitor a single pool... it will need to be extended somehow to support multiple pools. Easiest way to do this would be to fork two instances of the sasidle script, one for each pool. So where you have the following line in sasidle.sh to fork a background instance of the monitoring job:

Code:
		zpool iostat ${POOL} ${INTERVAL} | /bin/sh $0 ${ALL_ARGS} | logger -i -t sasidle &


you might want a loop that iterates over your available pools, then forks one background monitoring task for each pool:

Code:
		for p in `zpool list -H -o name`; do
			zpool iostat ${p} ${INTERVAL} | /bin/sh $0 --pool ${p} ${ALL_ARGS} | logger -i -t sasidle &
		done


Try the above, it should work, although it will mean the wrong pid (the pid of the last task to be instantiated) is stored in the pid file which will make stopping all of the tasks a problem - fixing that minor issue will require a bit more work to resolve. Putting a "sleep 2" before the end of the loop should prevent the log output at startup from becoming intermingled.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
So the new script should be like this ?

Code:
for p in `zpool list -H -o name`; do
			zpool iostat ${p} ${INTERVAL} | /bin/sh $0 --pool ${p} ${ALL_ARGS} | logger -i -t sasidle &
                        sleep 2
		done
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
Here's the log with edited script. Should it be like this?


Jun 4 09:35:02 freenas sasidle[1517]: Identifying devices for pool "music"...
Jun 4 09:35:02 freenas sasidle[1517]: ---------------------------------------------------------
Jun 4 09:35:02 freenas sasidle[1517]: Monitored Pool: music
Jun 4 09:35:02 freenas sasidle[1517]: Monitored Devices: da5 da6
Jun 4 09:35:02 freenas sasidle[1517]: Polling Interval: 60 seconds
Jun 4 09:35:02 freenas sasidle[1517]: Idle Timeout: 30 * 60 seconds
Jun 4 09:35:02 freenas sasidle[1517]: ASync Enabled: Yes
Jun 4 09:35:02 freenas sasidle[1517]: Simulated Stop: No
Jun 4 09:35:02 freenas sasidle[1517]: Log Disk Start: Yes
Jun 4 09:35:02 freenas sasidle[1517]: ---------------------------------------------------------
Jun 4 09:35:02 freenas sasidle[1517]:
Jun 4 09:35:02 freenas sasidle[1517]: 030: capacity operations bandwidth
Jun 4 09:35:02 freenas sasidle[1517]: 030: pool used avail read write read write
Jun 4 09:35:02 freenas sasidle[1517]: 030: ---------- ----- ----- ----- ----- ----- -----
Jun 4 09:35:02 freenas sasidle[1517]: 030: music 412K 2.72T 1 7 4.87K 30.9K
Jun 4 09:35:04 freenas sasidle[1543]: /root/sasidle starting
Jun 4 09:35:04 freenas sasidle[1543]: Identifying devices for pool "tank"...
Jun 4 09:35:04 freenas sasidle[1543]: ---------------------------------------------------------
Jun 4 09:35:04 freenas sasidle[1543]: Monitored Pool: tank
Jun 4 09:35:04 freenas sasidle[1543]: Monitored Devices: da1 da2 da3 da4
Jun 4 09:35:04 freenas sasidle[1543]: Polling Interval: 60 seconds
Jun 4 09:35:04 freenas sasidle[1543]: Idle Timeout: 30 * 60 seconds
Jun 4 09:35:04 freenas sasidle[1543]: ASync Enabled: Yes
Jun 4 09:35:04 freenas sasidle[1543]: Simulated Stop: No
Jun 4 09:35:04 freenas sasidle[1543]: Log Disk Start: Yes
Jun 4 09:35:04 freenas sasidle[1543]: ---------------------------------------------------------
Jun 4 09:35:04 freenas sasidle[1543]:
Jun 4 09:35:04 freenas sasidle[1543]: 030: capacity operations bandwidth
Jun 4 09:35:04 freenas sasidle[1543]: 030: pool used avail read write read write
Jun 4 09:35:04 freenas sasidle[1543]: 030: ---------- ----- ----- ----- ----- ----- -----

Jun 4 09:35:04 freenas sasidle[1543]: 030: tank 5.03T 5.84T 1 13 5.60K 72.3K
Jun 4 09:35:07 freenas ntpd[1720]: ntpd 4.2.4p5-a (1)
Jun 4 09:35:17 freenas ntpd[1721]: time reset +0.436392 s
Jun 4 09:36:03 freenas sasidle[1517]: 029: music 412K 2.72T 0 0 0 0
Jun 4 09:36:05 freenas sasidle[1543]: 029: tank 5.03T 5.84T 0 0 0 0
Jun 4 09:37:03 freenas sasidle[1517]: 028: music 412K 2.72T 0 0 0 0
Jun 4 09:37:05 freenas sasidle[1543]: 028: tank 5.03T 5.84T 0 0 0 0
Jun 4 09:38:03 freenas sasidle[1517]: 027: music 412K 2.72T 0 0 0 0
Jun 4 09:38:05 freenas sasidle[1543]: 027: tank 5.03T 5.84T 0 0 0 0
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
So the new script should be like this ?

Code:
for p in `zpool list -H -o name`; do
			zpool iostat ${p} ${INTERVAL} | /bin/sh $0 --pool ${p} ${ALL_ARGS} | logger -i -t sasidle &
                        sleep 2
		done

Yes, that should create a separate monitoring job for each pool.
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
It's working as it should. Thank you, Milhouse

So this should work for pool plugs in on a different HBA card too right?
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
So this should work for pool plugs in on a different HBA card too right?

Should do, as long as the FreeNAS configuration database has got the drive identifiers correctly associated with each pool, but if you're using the trick we discussed previously (specifying --devices as an argument) to overcome the problem with the configuration database referencing incorrect drives then no, it won't work... you'd need to add even more hacks to the script so that it knows which devices correspond with which pool, maybe an argument like "--devices 'music:/dev/da5,/dev/da6 tank:/dev/ada1,/dev/ada2,/dev/ada3'" then use a bit of sed/awk to parse out the devices corresponding with the pool being instantiated/monitored but that is pretty hackish and something you can add as a one off. :)
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
OK, here's a hack for you.

If you amend the device detection code as follows, you should be able to specify pool specific devices, eg --devices 'music:da5,da6 tank:ada1,ada2,ada3' (the format being pool name, a colon, comma separated devices then a single space for the next pool and devices etc.). Iif you don't specify devices for a particular pool they will be retrieved from the config database.

EDit: Here's the whole sasidle script, which should support multiple pools when called by the startup daemon, and also and device specific pools.

Code:
#!/bin/sh
#set -xv
 
#VERSION:  0.3.3
#MODIFIED: 22 Oct 2013
#AUTHOR:  Milhouse
#
#DESCRIPTION: Created on FreeNAS 8.0.1-BETA4 with LSI 9211-8i HBA
#            Tested on FreeNAS 8.0.2-RELEASE with LSI 9211-8i HBA
#            Tested on FreeNAS 9.1.1-RELEASE with onboard SATA
#
#  This script will attempt to stop disks in a ZFS pool connected
#  by a SAS HBA controller, using the camcontrol command. In effect,
#  this is a poor mans ATAIDLE.
#
#  The script is designed to run as a "daemon" process, running
#  constantly from bootup. The idea is that it will consume standard
#  input, which will itself be the output of "zpool iostat n" where n
#  is a time interval, usually 60 (seconds).
#
#  A count (--timeout) is specified as an argument for the script, and this
#  quantity is decremented each time there is no iostat activity, and reset
#  whenever there is iostat activity. When the count reaches zero, the disks
#  will be stopped using "camcontrol stop" (unless the --test option is
#  specified).
#
#  The amount of time elapsed before disks are stopped is calculated as
#  the product of the timeout and the value n specified for zpool iostat.
#  For example, a timeout of 15 and an interval of 60 gives 15 * 60, or
#  900 seconds (ie. 15 minutes). The default timeout is 30.
#
#  By default, disks will be stopped asynchronously (ie. simultaneously)
#  however if this is a problem, specify the --sync option to stop disks
#  in sequence, one after the other.
#
#  If a system has multiple pools, run individual commands for each pool.
#
#  If the script is unable to automatically detect disks/devices, specific
#  devices can be specified using the --devices argument.
#
#CHANGELOG:
#
#  0.1.0: 2011-08-01  - Initial version
#  0.2.0: 2011-09-05  - Tweak CAMCONTROL detection
#  0.2.1: 2011-10-08  - Rewrite device detection to read devices from SQLITE db
#  0.2.2: 2011-11-11  - Log when new disc activity detected after a stop (disable with --nologstart)
#                      Simplify logging.
#  0.2.3: 2011-11-12  - Minor fix for logging.
#  0.3.0: 2012-06-04  - Add support for multiple pools and pool specific devices
#  0.3.1: 2012-06-05  - Minor coding style corrections, remove trailing comma from default pools
#  0.3.2: 2012-06-17  - Fix regression decoding devices and expansion of args
#  0.3.3: 2013-10-22  - Fix unterminated string which FreeNAS 9.1.1 detects (but wasn't a problem in FreeNAS 8.x!)
#
#
#USAGE:
#  Execute the script with the -h or --help arguments.
#
#EXAMPLES:
#  zpool iostat tank 60 | sh sasidle --timeout 15
#  zpool iostat tank 60 | sh sasidle --timeout 15 --devices "/dev/da[2-3]"
#  zpool iostat tank 60 | sh sasidle --timeout 15 --devices "tank:/dev/da[1-2] music:/dev/da[3-4]" --pool tank,music
#  zpool iostat tank 60 | sh sasidle --timeout 15 --sync
#  zpool iostat tank 60 | sh sasidle --timeout 15 --test --verbose
#
 
POOL=`zpool list -H -o name | tr -s '\n' ',' | sed 's/,$//g'`
INTERVAL=60
TIMEOUT=30
DEVICES=
ASYNC=Y
LOGSTART=Y
DOSTOP=Y
DEBUG=
INFO=Y
 
_log() {
    [ ! -z $RC_PID ] && echo "$1" || echo "`date +'%Y/%m/%d %H:%M:%S'` $1"
}
 
_help() {
    echo "usage: ${0} [-p --pool <pool1,pool2>] [-i --interval #] [-t --timeout #] [-s -sync]
[-d --devices "pool1:/dev/da[0-2] pool2:/dev/da[3-6]"] [--nologstart] [-x --test]
[-q --quiet|-v --verbose] [-h --help]
-p --pool      name of pool(s) to monitor, comma separated list
-i --inteval    time interval between checks, in seconds
-t --timeout    number of intervals to elaps before stopping disks (default 30)
-s --sync      stop disks synchronously (default, async)
-d --devices    override device detection by specifying devices eg. "/dev/da[0-4]",
                or pool specific (pool1:dev1,dev2 pool2:dev3,dev4)
  --nologstart log message when disk activity detected after a prior stop
-x --test      do not stop disks (simulation)
-q --quiet      suppress all informational and debug messages
-v --verbose    output debug messages
-h --help      display this help"
}
 
# Total hack to avoid consuming arguments (needed for later expansion)
# getopts doesn't support long options in BSD, so this hack will have
# to do.
# In order to kick off the background task, we only need to know --pool
# and --interval so make sure they're first in any arguments, and we'll
# pass them in again to the background job where they can be consumed...
P=1
while [ $P -le $# ]; do
    [ $P -gt 9 ] && break;
 
    ARG1=`eval echo \$"$P"`
    let P=P+1 >/dev/null
    ARG2=`eval echo \$"$P"`
    let PN=P+1 >/dev/null
 
    case ${ARG1} in
        "-p" | "--pool")    POOL=${ARG2}; P=$PN;;
        "-i" | "--interval")    INTERVAL=${ARG2}; P=$PN;;
    esac
done
 
# Being called by rc - fork off a backgroun task
if [ ! -z $RC_PID ]; then
    if [ -z ${PROCMAIN} ]; then
        export PROCMAIN=YES;
        for p in `echo ${POOL} | sed "s/,/ /g"`; do
            zpool list $p >/dev/null
# Pool must exist - if not, ignore it (error message will appear in logs)
            if [ $? -eq 0 ]; then
                zpool iostat ${p} ${INTERVAL} | \
                    /bin/sh $0 "$@" --pool ${p} --interval ${INTERVAL} | \
                    logger -i -t sasidle &
            fi
        done
        exit 0
    fi
    echo $$ >>/var/run/sasidled.pid
fi
 
# To have got here, we're either being run manually from the command line, or
# called from rc, so lets validate all arguments - they're safe to consume now.
while [ $# -gt 0 ]; do
    case ${1} in
        "-p" | "--pool")    shift 1; POOL=${1};;
        "-i" | "--interval")    shift 1; INTERVAL=${1};;
        "-t" | "--timeout")    shift 1; TIMEOUT=${1};;
        "-s" | "--sync")    ASYNC=;;
        "-d" | "--devices")    shift 1; DEVICES=${1};;
              "--nologstart")  LOGSTART=;;
        "-x" | "--test")    DOSTOP=;;
        "-q" | "--quiet")    DEBUG=; INFO=;;
        "-v" | "--verbose")    DEBUG=Y; INFO=Y;;
 
        "-h" | "--help")    _help; exit;;
        *)            echo "Unrecognised argument: $1"; _help; exit;;
    esac
    shift 1
done
 
[ "${INFO}" ] && _log "$0 starting"
 
if [ "${DEVICES}" ]; then
    TEMP_DEV=${DEVICES}
    DEVICES=
 
    for x in ${TEMP_DEV}; do
        if [ -n "$(echo $x | grep "^${POOL}:")" ]; then
            [ "${INFO}" ] && _log "Parsing devices for pool \"${POOL}\"..."
            DEVICES="`echo "$x" | cut -d: -f2- | sed 's/,/ /g'`"
            break
        fi
# Use these unamed devices if no pool is matched
        [ `echo $x | grep -v ":"` ] && DEVICES="${DEVICES} $x"
    done
 
# Clean up devices if necessary...
    [ "$DEVICES" ] && DEVICES=`eval echo '$DEVICES' | sed 's/,/ /g' | sed 's/"//g'`
fi
 
# Determine managed devices if not already known...
if [ ! "${DEVICES}" ]; then
    [ "${INFO}" ] && _log "Identifying devices for pool \"${POOL}\"..."
 
    OLD_RC_PID=$RC_PID
    . /etc/rc.freenas
    RC_PID=$OLD_RC_PID
 
    DEVICES=`${FREENAS_SQLITE_CMD} ${FREENAS_CONFIG} \
        "SELECT disk_name FROM storage_disk  \
        WHERE LOWER(disk_description) LIKE LOWER('% ${POOL} %') \
        ORDER BY disk_name ASC" | \
        while read disk_name; do
            echo $disk_name|sed "s/p.$//"
        done|tr -s "\n" " "`
fi
 
# Strip /dev/ prefix, eliminate any duplicates and stop disks in ascending sequence...
DEVICES=`echo ${DEVICES} | sed "s#/dev/##g" | tr -s " " "\n" | sort -u | tr -s "\n" " "`
 
# Show config info...
if [ "${INFO}" ]; then
    _log "---------------------------------------------------------"
    _log "Monitored Pool:    ${POOL}"
    _log "Monitored Devices: ${DEVICES}"
    _log "Polling Interval:  ${INTERVAL} seconds"
    _log "Idle Timeout:      ${TIMEOUT} * ${INTERVAL} seconds"
    _log "ASync Enabled:    $([ ${ASYNC} ] && echo "Yes" || echo "No")"
    _log "Simulated Stop:    $([ ${DOSTOP} ] && echo "No" || echo "Yes")"
    _log "Log Disk Start:    $([ ${LOGSTART} ] && echo "Yes" || echo "No")"
    _log "---------------------------------------------------------"
    _log ""
fi
 
# Skip 3 lines of "zpool iostat" headers...
for H in 1 2 3; do
    read HEADER
    [ "$DEBUG" ] && _log "$(printf "%.3d: %s\n" ${TIMEOUT} "${HEADER}")"
done
 
COUNT=${TIMEOUT}
STOPPED=
 
# Main infinite loop...
while [ true ]; do
    read POOL_NAME POOL_USED POOL_AVAIL POOL_OP_READ POOL_OP_WRITE POOL_BW_READ POOL_BW_WRITE
 
# If no activity, decrement count, else reset it
    if [ ${POOL_OP_READ-1} = 0 -a ${POOL_OP_WRITE-1} = 0 -a \
        ${POOL_BW_READ-1} = 0 -a ${POOL_BW_WRITE-1} = 0 ]; then
        [ ! ${STOPPED} ] && let COUNT=COUNT-1 >/dev/null
    else
        if [ "${STOPPED}" -a "${LOGSTART}" ]; then
            [ "${INFO}" ] && _log "** Restarting devices in pool \"${POOL_NAME}\" due to activity **"
        fi
 
        COUNT=${TIMEOUT}
        STOPPED=
    fi
 
# Optional diagnostic output...
    [ "${DEBUG}" ] && _log "$(printf "%.3d: %-10s  %5s  %5s  %5s  %5s  %5s  %5s\n" \
        ${COUNT} ${POOL_NAME} ${POOL_USED} ${POOL_AVAIL} \
        ${POOL_OP_READ} ${POOL_OP_WRITE} ${POOL_BW_READ} ${POOL_BW_WRITE})"
 
# If count reaches zero, stop devices
    if [ ${COUNT} -le 0 -a ! "${STOPPED}" ]; then
        [ "${INFO}" ] && _log "** Stopping devices in pool \"${POOL_NAME}\" **"
 
        for DISK in ${DEVICES}; do
            if [ "${DOSTOP}" ]; then
                [ "${INFO}" ] && _log "camcontrol stop ${DISK}"
                [  "${ASYNC}" ] && camcontrol stop ${DISK} &
                [ ! "${ASYNC}" ] && camcontrol stop ${DISK}
            else
                [ "${INFO}" ] && _log "#camcontrol stop ${DISK}"
            fi
        done
 
        STOPPED=Y
    fi
done
 
exit 0
 

arryo

Dabbler
Joined
May 5, 2012
Messages
42
It seems that, when none of the pool has any activity, then the script works well. But when one pool is in activity, camcontrol command seems not working, even though in the log, it said it stops correctly

Code:
Jun  4 17:27:06 freenas sasidle[1553]: ** Stopping devices in pool "music" **
Jun  4 17:27:06 freenas sasidle[1553]: camcontrol stop da5
Jun  4 17:27:06 freenas sasidle[1553]: camcontrol stop da6
Jun  4 17:27:07 freenas sasidle[1553]: Unit stopped successfully
Jun  4 17:27:07 freenas sasidle[1553]: Unit stopped successfully
Jun  4 17:27:08 freenas sasidle[1579]: 030: tank        5.02T  5.85T      8      0  1.07M      0
Jun  4 17:28:06 freenas sasidle[1553]: 000: music       6.81G  2.71T      0      0      0      0
Jun  4 17:28:08 freenas sasidle[1579]: 030: tank        5.02T  5.85T      8      1  1.07M  5.27K



Since I have kill-a-watt plugged in to monitor the power consumption, and the power hasn't changed before and after the script sending the camcontrol stop. It makes me think maybe because all the pools are plugged in in the same HBA card, so it can either stop every HDDs or not at all.
 
Status
Not open for further replies.
Top