diff mbox series

[v3,10/10] ixp4xx: Add hdparm script

Message ID 20231012-ixp4xx-v3-10-e09c74712c0b@linaro.org
State Accepted, archived
Delegated to: Linus Walleij
Headers show
Series Resurrect OpenWrt IXP4xx support | expand

Commit Message

Linus Walleij Oct. 12, 2023, 8:42 a.m. UTC
This script will make sure to spin down harddrives on IXP4xx
NAS devices such as the NSLU2 and siblings after 1 minute
of inactivity.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 target/linux/ixp4xx/base-files/etc/board.d/03_hdparm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Andrey Jr. Melnikov Oct. 12, 2023, 10:07 p.m. UTC | #1
Linus Walleij <linus.walleij@linaro.org> wrote:
> This script will make sure to spin down harddrives on IXP4xx
> NAS devices such as the NSLU2 and siblings after 1 minute
> of inactivity.

Why not use hotplug events?

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  target/linux/ixp4xx/base-files/etc/board.d/03_hdparm | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)

[....]
Linus Walleij Oct. 13, 2023, 7:01 a.m. UTC | #2
On Fri, Oct 13, 2023 at 12:28 AM Andrey Jr. Melnikov
<temnota.am@gmail.com> wrote:
> Linus Walleij <linus.walleij@linaro.org> wrote:

> > This script will make sure to spin down harddrives on IXP4xx
> > NAS devices such as the NSLU2 and siblings after 1 minute
> > of inactivity.
>
> Why not use hotplug events?

Could be a good idea! Do you have a pointer to how we do these
in OpenWrt?

Yours,
Linus Walleij
Andrey Jr. Melnikov Oct. 13, 2023, 9:02 a.m. UTC | #3
Linus Walleij <linus.walleij@linaro.org> wrote:
> On Fri, Oct 13, 2023 at 12:28 AM Andrey Jr. Melnikov
> <temnota.am@gmail.com> wrote:
> > Linus Walleij <linus.walleij@linaro.org> wrote:

> > > This script will make sure to spin down harddrives on IXP4xx
> > > NAS devices such as the NSLU2 and siblings after 1 minute
> > > of inactivity.
> >
> > Why not use hotplug events?

> Could be a good idea! Do you have a pointer to how we do these
> in OpenWrt?

I'm use for external USB disk patched /etc/hotplug.d/block/00-media-change

-- cut /etc/hotplug.d/block/00-media-change --
[ -n "$DISK_MEDIA_CHANGE" ] && /sbin/block info

if [ "$ACTION" = "add" -a "$DEVTYPE" = "disk" ]; then
	case "$DEVNAME" in
		mtd*) : ;;
		*) echo 2000 > /sys/block/$DEVNAME/events_poll_msecs ;;
	esac
	case "$DEVNAME" in
		sd*) /sbin/hdparm -B 127 -S 120 /dev/$DEVNAME | /usr/bin/logger 
		;;
	esac
fi
-- cut --

PS: And 60 seconds timeout for NAS disks is low. Readahead+cache and serve
small files (which fit in memory) - now disk's in spinup-read-spindown cycle.
diff mbox series

Patch

diff --git a/target/linux/ixp4xx/base-files/etc/board.d/03_hdparm b/target/linux/ixp4xx/base-files/etc/board.d/03_hdparm
new file mode 100644
index 000000000000..27f2b760420e
--- /dev/null
+++ b/target/linux/ixp4xx/base-files/etc/board.d/03_hdparm
@@ -0,0 +1,14 @@ 
+# SPDX-License-Identifier: GPL-2.0-only
+# Spin down drives after one minute if inactive
+
+if [ ! -n "$(command -v hdparm)" ]; then
+	exit 0
+fi
+
+DISKS=$(find /dev/sd[a-z] 2>/dev/null)
+for DISK in $DISKS
+do
+	if [ -b $DISK ] ; then
+		hdparm -S 12 $DISK > /dev/null
+	fi
+done