Reset all SMART attribute fields (raw, norm, worst, thresh) to SMART_UNASSIGNED when ignored

This commit is contained in:
Andrea Mazzoleni 2026-08-10 11:41:55 +02:00
parent 3a3152a36f
commit 97b13557fe
2 changed files with 16 additions and 8 deletions

View file

@ -533,6 +533,14 @@ static void state_info_log(devinfo_t* devinfo)
log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->info[INFO_ROTATION_RATE]);
}
static void smart_attr_clear(struct smart_attr* attr)
{
attr->raw = SMART_UNASSIGNED;
attr->norm = SMART_UNASSIGNED;
attr->worst = SMART_UNASSIGNED;
attr->thresh = SMART_UNASSIGNED;
}
void state_smart_ignore(struct snapraid_state* state, devinfo_t* devinfo)
{
int i, j;
@ -541,26 +549,26 @@ void state_smart_ignore(struct snapraid_state* state, devinfo_t* devinfo)
for (i = 0; i < SMART_IGNORE_MAX; ++i) {
/* global ignore */
if (state->smartignore[i].attr_index > 0 && state->smartignore[i].attr_index < 256) {
devinfo->smart[state->smartignore[i].attr_index].raw = SMART_UNASSIGNED;
smart_attr_clear(&devinfo->smart[state->smartignore[i].attr_index]);
}
if (state->smartignore[i].attr_name[0] != 0) {
for (j = 0; j < SMART_COUNT; ++j) {
if (devinfo->smart[j].name[0] != 0
&& strcasecmp(devinfo->smart[j].name, state->smartignore[i].attr_name) == 0) {
devinfo->smart[j].raw = SMART_UNASSIGNED;
smart_attr_clear(&devinfo->smart[j]);
}
}
}
/* devinfo ignore */
if (devinfo->smartignore[i].attr_index > 0 && devinfo->smartignore[i].attr_index < 256) {
devinfo->smart[devinfo->smartignore[i].attr_index].raw = SMART_UNASSIGNED;
smart_attr_clear(&devinfo->smart[devinfo->smartignore[i].attr_index]);
}
if (devinfo->smartignore[i].attr_name[0] != 0) {
for (j = 0; j < SMART_COUNT; ++j) {
if (devinfo->smart[j].name[0] != 0
&& strcasecmp(devinfo->smart[j].name, devinfo->smartignore[i].attr_name) == 0) {
devinfo->smart[j].raw = SMART_UNASSIGNED;
smart_attr_clear(&devinfo->smart[j]);
}
}
}

View file

@ -971,19 +971,19 @@ static void test_smart_ignore(void)
state_smart_ignore(&state, &devinfo);
/* Check that ignored attributes are set to SMART_UNASSIGNED */
if (devinfo.smart[5].raw != SMART_UNASSIGNED) {
if (devinfo.smart[5].raw != SMART_UNASSIGNED || devinfo.smart[5].norm != SMART_UNASSIGNED) {
log_fatal(EINTERNAL, "test_smart_ignore: numerical global ignore failed\n");
exit(EXIT_FAILURE);
}
if (devinfo.smart[197].raw != SMART_UNASSIGNED) {
if (devinfo.smart[197].raw != SMART_UNASSIGNED || devinfo.smart[197].norm != SMART_UNASSIGNED) {
log_fatal(EINTERNAL, "test_smart_ignore: name global ignore failed\n");
exit(EXIT_FAILURE);
}
if (devinfo.smart[10].raw != SMART_UNASSIGNED) {
if (devinfo.smart[10].raw != SMART_UNASSIGNED || devinfo.smart[10].norm != SMART_UNASSIGNED) {
log_fatal(EINTERNAL, "test_smart_ignore: numerical devinfo ignore failed\n");
exit(EXIT_FAILURE);
}
if (devinfo.smart[20].raw != SMART_UNASSIGNED) {
if (devinfo.smart[20].raw != SMART_UNASSIGNED || devinfo.smart[20].norm != SMART_UNASSIGNED) {
log_fatal(EINTERNAL, "test_smart_ignore: name devinfo ignore failed\n");
exit(EXIT_FAILURE);
}