From aa8445e7a9d88d34ab3763980a775bfcf65c8cdd Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 28 Sep 2026 15:43:37 +0200 Subject: [PATCH] Report smartctl open failures as unknown power state --- cmdline/mingwapp.c | 16 +++++++++++----- cmdline/unixapp.c | 16 +++++++++++----- doc/snapraid_log.1 | 4 ++++ doc/snapraid_log.d | 4 ++++ doc/snapraid_log.txt | 4 ++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/cmdline/mingwapp.c b/cmdline/mingwapp.c index e19cb97e..992eb409 100644 --- a/cmdline/mingwapp.c +++ b/cmdline/mingwapp.c @@ -1750,12 +1750,17 @@ retry: log_tag("attr:%s:%s:power:standby\n", file, name); *power = POWER_STANDBY; } else { - log_tag("attr:%s:%s:power:active\n", file, name); - *power = POWER_ACTIVE; - /* store the smartctl return value */ if (smart) smart[SMART_FLAGS].raw = WEXITSTATUS(ret); + + if (WEXITSTATUS(ret) & SMARTCTL_FLAG_OPEN) { + log_tag("attr:%s:%s:power:unknown\n", file, name); + *power = POWER_UNKNOWN; + } else { + log_tag("attr:%s:%s:power:active\n", file, name); + *power = POWER_ACTIVE; + } } return 0; @@ -1913,7 +1918,8 @@ static int devdownifup(uint64_t device, const char* name, const char* smartctl, if (devprobe(device, name, smartctl, smartctl_info, power, 0, 0, 0, 0, 0, 0) != 0) return -1; - if (*power == POWER_ACTIVE) + /* a failed probe may hide an active disk, so skip only confirmed standby */ + if (*power != POWER_STANDBY) return devdown(device, name, smartctl); return 0; @@ -2089,7 +2095,7 @@ static void* thread_spindownifup(void* arg) /* LCOV_EXCL_STOP */ } - if (power == POWER_ACTIVE) + if (power != POWER_STANDBY) msg_status("Spundown device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, os_tick_ms() - start); } diff --git a/cmdline/unixapp.c b/cmdline/unixapp.c index 357e3f99..de8b0ba0 100644 --- a/cmdline/unixapp.c +++ b/cmdline/unixapp.c @@ -3797,12 +3797,17 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, const log_tag("attr:%s:%s:power:standby\n", file, name); *power = POWER_STANDBY; } else { - log_tag("attr:%s:%s:power:active\n", file, name); - *power = POWER_ACTIVE; - /* store the smartctl return value */ if (smart) smart[SMART_FLAGS].raw = WEXITSTATUS(ret); + + if (WEXITSTATUS(ret) & SMARTCTL_FLAG_OPEN) { + log_tag("attr:%s:%s:power:unknown\n", file, name); + *power = POWER_UNKNOWN; + } else { + log_tag("attr:%s:%s:power:active\n", file, name); + *power = POWER_ACTIVE; + } } return 0; @@ -3929,7 +3934,8 @@ static int devdownifup(dev_t device, const char* name, const char* smartctl, con if (devprobe(device, name, smartctl, smartctl_info, power, 0, 0, 0, 0, 0, 0) != 0) return -1; - if (*power == POWER_ACTIVE) + /* a failed probe may hide an active disk, so skip only confirmed standby */ + if (*power != POWER_STANDBY) return devdown(device, name, smartctl); return 0; @@ -4156,7 +4162,7 @@ static void* thread_spindownifup(void* arg) /* LCOV_EXCL_STOP */ } - if (power == POWER_ACTIVE) + if (power != POWER_STANDBY) msg_status("Spundown device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, os_tick_ms() - start); } diff --git a/doc/snapraid_log.1 b/doc/snapraid_log.1 index fb3d2b5d..403065a0 100644 --- a/doc/snapraid_log.1 +++ b/doc/snapraid_log.1 @@ -1866,6 +1866,10 @@ read. Logs a successful spin\-down operation initiated via the smartctl command. .TP +.B attr::[/]:power:unknown +Logs that the device power state could not be determined +after a status probe. +.TP .B stat:: Logs the total number of read and write accesses done on the disk. This is a cumulative value that include all the devices diff --git a/doc/snapraid_log.d b/doc/snapraid_log.d index bcdc2546..3ce80829 100644 --- a/doc/snapraid_log.d +++ b/doc/snapraid_log.d @@ -1170,6 +1170,10 @@ Command Smart And Probe Tags Logs a successful spin-down operation initiated via the smartctl command. + =attr::[/]:power:unknown + Logs that the device power state could not be determined + after a status probe. + =stat:: Logs the total number of read and write accesses done on the disk. This is a cumulative value that include all the devices diff --git a/doc/snapraid_log.txt b/doc/snapraid_log.txt index 39cf518a..0dca77c2 100644 --- a/doc/snapraid_log.txt +++ b/doc/snapraid_log.txt @@ -1216,6 +1216,10 @@ Tags logging specific disk identification and attribute values. Logs a successful spin-down operation initiated via the smartctl command. + attr::[/]:power:unknown + Logs that the device power state could not be determined + after a status probe. + stat:: Logs the total number of read and write accesses done on the disk. This is a cumulative value that include all the devices