Skip to content

Commit

Permalink
tlp-stat -d: distinguish SATA from ATA(IDE) disks
Browse files Browse the repository at this point in the history
  • Loading branch information
linrunner committed Nov 7, 2020
1 parent 2278e6d commit 2440277
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Discharge malfunction: hint to check battery, charger
Disks:
- tlp-stat -d
- Distinguish SATA from ATA(IDE) disks
- Show disks attached to SATA links/ports
- Show a disk's host
- Show ALPM state in the sysfs directory of the AHCI host
Expand Down
13 changes: 11 additions & 2 deletions func.d/15-tlp-func-disk
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ readonly DISK_NOP_WORDS="_ keep"
get_disk_dev () { # translate disk id to device (sdX)
# $1: id or device (sans /dev)
# retval: $_disk_dev, $_disk_id, $_disk_type
local bus dpath path
local bus dpath dpath2 path

if [ -h /dev/disk/by-id/$1 ]; then
# $1 is disk id
Expand Down Expand Up @@ -66,6 +66,15 @@ get_disk_dev () { # translate disk id to device (sdX)
;;
esac
esac

if [ "$_disk_type" = "ata" ]; then
# distinguish sata from ata(ide) disks
dpath2="$($UDEVADM info -q property /dev/$_disk_dev 2>/dev/null | sed -n 's/^DEVPATH=/\/sys/; s/\/target.*//p')"
if ls ${dpath2}/scsi_host/host*/link_power_management_policy > /dev/null 2>&1; then
_disk_type=sata
fi
fi

echo_debug "disk" "get_disk_dev($1): dev=$_disk_dev; type=$_disk_type; path=$path; bus=$bus; dpath=$dpath"
return 0
else
Expand Down Expand Up @@ -356,7 +365,7 @@ set_ahci_disk_runtime_pm () { # set runtime power management for ahci disks
devbn=${device##/*/}
get_disk_dev $devbn
# consider only ahci == ata disks
if [ "$_disk_type" = "ata" ]; then
if [ "$_disk_type" = "sata" ] || [ "$_disk_type" = "ata" ]; then
# write timeout first because writing "auto" with the default
# timeout -1 still active will lockup the machine!
rc=0
Expand Down
6 changes: 3 additions & 3 deletions func.d/tlp-func-stat
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ show_disk_data () { # formatted output of NVMe / SATA disk data
# TODO: more features?
;;

ata|usb|ieee1394)
sata|ata|usb|ieee1394)
# ATA/USB/IEEE1394 disk
printf "\n%s:\n" /dev/$_disk_dev
[ -n "$_disk_id" ] && printf " Disk ID = %s\n" $_disk_id
Expand Down Expand Up @@ -427,7 +427,7 @@ show_disk_data () { # formatted output of NVMe / SATA disk data
1) printf " TRIM = supported\n" ;;
esac

if [ "$_disk_type" = "ata" ]; then
if [ "$_disk_type" = "sata" ] || [ "$_disk_type" = "ata" ]; then
get_ahci_host $_disk_dev && printf " Host = %s\n" $_ahci_host
fi

Expand Down Expand Up @@ -472,7 +472,7 @@ show_disk_data () { # formatted output of NVMe / SATA disk data
sed 's/^/ /'
;;

ata|usb)
sata|ata|usb)
printf "\n SMART info:\n"
$SMARTCTL -A /dev/$_disk_dev | grep -v '<==' | \
awk -F ' ' '$2 ~ /Power_Cycle_Count|Start_Stop_Count|Load_Cycle_Count|Reallocated_Sector_Ct/ \
Expand Down
4 changes: 2 additions & 2 deletions tlp-stat.in
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ if [ "$show_disk" = "1" ] || [ "$show_all" = "1" ]; then

# --- show sata alpm mode
if stat -t ${ALPMD}/link_power_management_policy > /dev/null 2>&1; then
echo "+++ AHCI Link Power Management (ALPM) :: SATA Links"
echo "+++ AHCI Link Power Management (ALPM) :: Links"
for i in ${ALPMD} ; do
printparm_ahci $i/link_power_management_policy
done
Expand All @@ -594,7 +594,7 @@ if [ "$show_disk" = "1" ] || [ "$show_all" = "1" ]; then

# --- show ahci runtime pm
if stat -t ${AHCID}/power > /dev/null 2>&1; then
echo "+++ AHCI Port Runtime Power Management :: SATA Ports"
echo "+++ AHCI Port Runtime Power Management :: Ports"
for dev in ${AHCID}/power ; do
printparm_ahci $dev/control
done
Expand Down

0 comments on commit 2440277

Please sign in to comment.