GLAN TANK四日目

ファンとHDDの停止を同期させることに成功。

ファンを停止するプログラムusbhdmngは前回の日記参照。

noflushdのソースコードを改変し、HDDのスピンアップ時とスピンダウン時に外部のプログラムを実行するようにしました。その外部のプログラムとしてusbhdmngの起動/停止スクリプトを指定すれば完成です。
※2006/06/07追記 [id:viver:20060607]GLAN TANK五日目でスピンダウン方法を改訂


noflushd-2.7.5に対するパッチ

diff -crN noflushd-2.7.5/src/state.c noflushd-2.7.5-notify/src/state.c
*** noflushd-2.7.5/src/state.c  Fri Apr  9 05:13:44 2004
--- noflushd-2.7.5-notify/src/state.c   Wed May 10 22:20:30 2006
***************
*** 335,347 ****
                                 * little bit into negative should be okay. */
                                if (di->time_left > 0)
                                        di->time_left-=interval;
!                               if (irq_is_idle && try_spindown(ds, di))
                                        di->state=DISK_STATE_STOPPED;
                        }
                        break;
                case DISK_STATE_STOPPED:
                        if (io_flags==DISK_STAT_INVALID) {
                                ERR("No stats for stopped disk %s", di->name);
                                di->state=DISK_STATE_SPINNING;
                                break;
                        }
--- 335,350 ----
                                 * little bit into negative should be okay. */
                                if (di->time_left > 0)
                                        di->time_left-=interval;
!                               if (irq_is_idle && try_spindown(ds, di)) {
!                                       if (access(NFD_CMD_SPIN_DOWN, X_OK) == 0) { system(NFD_CMD_SPIN_DOWN); }
                                        di->state=DISK_STATE_STOPPED;
+                               }
                        }
                        break;
                case DISK_STATE_STOPPED:
                        if (io_flags==DISK_STAT_INVALID) {
                                ERR("No stats for stopped disk %s", di->name);
+                               if (access(NFD_CMD_SPIN_UP, X_OK) == 0) { system(NFD_CMD_SPIN_UP); }
                                di->state=DISK_STATE_SPINNING;
                                break;
                        }
***************
*** 349,354 ****
--- 352,358 ----
                                time_t now, delta;

                                di->time_left=timeout_get(di->timeouts);
+                               if (access(NFD_CMD_SPIN_UP, X_OK) == 0) { system(NFD_CMD_SPIN_UP); }
                                di->state=DISK_STATE_SPINNING;

                                now = time(NULL);
diff -crN noflushd-2.7.5/src/state.h noflushd-2.7.5-notify/src/state.h
*** noflushd-2.7.5/src/state.h  Fri Apr  9 05:13:44 2004
--- noflushd-2.7.5-notify/src/state.h   Wed May 10 22:19:50 2006
***************
*** 26,31 ****
--- 26,34 ----
  #ifndef _NFD_STATE_H
  #define _NFD_STATE_H

+ #define NFD_CMD_SPIN_UP "/etc/noflushd/spinup"
+ #define NFD_CMD_SPIN_DOWN "/etc/noflushd/spindown"
+
  typedef enum nfd_states {
        NFD_STATE_UNINITIALISED,
        NFD_STATE_SPINNING,

パッチを当てたら、普通に./configure --prefix=/usr/local; make; sudo make installすればOKです。
ただしこのとき、起動スクリプト(/etc/init.d/noflushd)が勝手に書き換えられるので、make installする前に/etc/init.d/noflushdをバックアップしておいて、make install後に元に戻す。
その後/etc/default/noflushdに

DAEMON="/usr/local/sbin/noflushd"

と書いておけばOK。次回から標準のnoflushd起動スクリプトで/usr/local/sbin/noflushdが起動されます。
(apt-get install noflushd してある場合)



/etc/noflushd/spinup

#!/bin/sh
if ps ax | grep usbhdmng | grep -q -v grep;then
        killall usbhdmng 2&>1 /dev/null
        if ps ax | grep usbhdmng | grep -q -v grep;then
                killall -9 usbhdmng 2&>1 /dev/null
        fi
fi


/etc/noflushd/spindown

#!/bin/sh
if [ -x /usr/local/bin/usbhdmng ];then
        if [ ! -f /tmp/spindownd.conf ];then
                echo "\
IDE:    hda     /dev/hda        /dev/hda        1
IDE:    hdb     /dev/hda        /dev/hda        1
" > /tmp/spindownd.conf
        fi
        /usr/local/bin/usbhdmng
fi


HDDとファンの停止は完全に同期するのでは無く、HDDが停止してから1分後にファンが停止します。




釈迦に説法ですが、使うなら自己責任で。