Skip spinup and spindown for non-rotational devices

This commit is contained in:
Andrea Mazzoleni 2026-06-15 00:45:45 +02:00
parent 1764377f93
commit bcb2e862b9
4 changed files with 112 additions and 8 deletions

View file

@ -3218,6 +3218,34 @@ static int devdownifup(dev_t device, const char* name, const char* smartctl, int
}
#endif
/**
* Check if the device needs power management (it's a rotational one)
*/
#if HAVE_LINUX_DEVICE
static int devpower(dev_t device)
{
char path[PATH_MAX];
char buf[512];
uint64_t rotational;
rotational = SMART_UNASSIGNED;
pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/queue/rotational", major(device), minor(device));
if (sysattr(path, buf, sizeof(buf)) == 0) {
char* e;
uint64_t v;
v = strtoul(buf, &e, 10);
if (*e == 0)
rotational = v;
}
if (rotational == SMART_UNASSIGNED)
return 0; /* assume not rotational */
return rotational != 0;
}
#endif
/**
* Spin up a specific device.
*/
@ -3329,6 +3357,10 @@ static void* thread_spinup(void* arg)
devinfo_t* devinfo = arg;
uint64_t start;
/* skip not rotational devices */
if (devpower(devinfo->device) == 0)
return (void*)-1;
start = os_tick_ms();
if (devup(devinfo->device, devinfo->name) != 0) {
@ -3370,6 +3402,10 @@ static void* thread_spindown(void* arg)
devinfo_t* devinfo = arg;
uint64_t start;
/* skip not rotational devices */
if (devpower(devinfo->device) == 0)
return (void*)-1;
start = os_tick_ms();
if (devdown(devinfo->device, devinfo->name, devinfo->smartctl) != 0) {