diff options
author | phk <phk@FreeBSD.org> | 2008-03-17 10:33:23 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2008-03-17 10:33:23 +0000 |
commit | 916647a52a03a583385f5a55dd2c00410a3c2075 (patch) | |
tree | 42facee2a8a6b82282cf32d98ef5558ca3765746 /sbin/atacontrol | |
parent | 341d5f653b205917fac261a059ef06e686ae47ab (diff) | |
download | FreeBSD-src-916647a52a03a583385f5a55dd2c00410a3c2075.zip FreeBSD-src-916647a52a03a583385f5a55dd2c00410a3c2075.tar.gz |
Add a "spindown" facility to ata-disks: If no requests have been received
for a configurable number of seconds, spin the disk down. Spin it back
up on the next request.
Notice that the timeout is only armed by a request, so to spin down a
disk you may have to do:
atacontrol spindown ad10 5
dd if=/dev/ad10 of=/dev/null count=1
To disable spindown, set timeout to zero:
atacontrol spindown ad10 0
In order to debug any trouble caused, this code is somewhat noisy on the
console.
Enabling spindown on a disk containing / or /var/log/messages is not
going to do anything sensible.
Spinning a disk up and down all the time will wear it out, use sensibly.
Approved by: sos
Diffstat (limited to 'sbin/atacontrol')
-rw-r--r-- | sbin/atacontrol/atacontrol.8 | 8 | ||||
-rw-r--r-- | sbin/atacontrol/atacontrol.c | 27 |
2 files changed, 35 insertions, 0 deletions
diff --git a/sbin/atacontrol/atacontrol.8 b/sbin/atacontrol/atacontrol.8 index dd25f57..a755483 100644 --- a/sbin/atacontrol/atacontrol.8 +++ b/sbin/atacontrol/atacontrol.8 @@ -70,6 +70,10 @@ .Ic cap .Ar device .Nm +.Ic spindown +.Ar device +.Op Ar seconds +.Nm .Ic list .Sh DESCRIPTION The @@ -190,6 +194,10 @@ The device name and manufacture/version strings are shown. .It Ic cap Show detailed info about the device on .Ar device . +.It Ic spindown +Set or report timeout after which the +.Ar device +will be spun down. .It Ic info Show info about the attached devices on the .Ar channel . diff --git a/sbin/atacontrol/atacontrol.c b/sbin/atacontrol/atacontrol.c index 42ee65f..590b29c 100644 --- a/sbin/atacontrol/atacontrol.c +++ b/sbin/atacontrol/atacontrol.c @@ -102,6 +102,7 @@ usage(void) " atacontrol status array\n" " atacontrol mode device [mode]\n" " atacontrol cap device\n" + " atacontrol spindown device [seconds]\n" ); exit(EX_USAGE); } @@ -285,6 +286,26 @@ info_print(int fd, int channel, int prchan) printf(" no device present\n"); } +static void +ata_spindown(int fd, const char *dev, const char *arg) +{ + int tmo; + + if (arg != NULL) { + tmo = strtoul(arg, NULL, 0); + if (ioctl(fd, IOCATASSPINDOWN, &tmo) < 0) + err(1, "ioctl(IOCATASSPINDOWN)"); + } else { + if (ioctl(fd, IOCATAGSPINDOWN, &tmo) < 0) + err(1, "ioctl(IOCATAGSPINDOWN)"); + if (tmo == 0) + printf("%s: idle spin down disabled\n", dev); + else + printf("%s: spin down after %d seconds idle\n", + dev, tmo); + } +} + static int open_dev(const char *arg, int mode) { @@ -356,6 +377,12 @@ main(int argc, char **argv) exit(EX_OK); } + if (!strcmp(argv[1], "spindown") && (argc == 3 || argc == 4)) { + fd = open_dev(argv[2], O_RDONLY); + ata_spindown(fd, argv[2], argv[3]); + exit(EX_OK); + } + if ((fd = open("/dev/ata", O_RDWR)) < 0) err(1, "control device not found"); |