Skip to content

fanctrlplus2: keep CPU and aux sensors across hwmon renumbering - #33

Closed
luuvasara wants to merge 1 commit into
andrebrait:mainfrom
luuvasara:fix/sensor-identity
Closed

luuvasara wants to merge 1 commit into
andrebrait:mainfrom
luuvasara:fix/sensor-identity

Conversation

@luuvasara

Copy link
Copy Markdown

Change

cpu_sensor and aux_sensor are saved as /sys/class/hwmon/hwmonN/tempM_input, and hwmonN follows probe order. NVMe drives register hwmon devices too, so after a reboot that probes them in another order the saved path can name a different chip. On an Asustor NAS the devices were hwmon0/1 nvme, hwmon2 acpitz, hwmon3 it8625 and hwmon4 coretemp; a boot that probes the drives last moves the CPU sensor's hwmon4 onto an NVMe drive, and the fan follows the drive instead of the CPU without any warning.

#12 fixed this for controllers with controller_identity. This does the same for temperature sensors:

  • Each selected hwmon sensor is also saved with its chip name, its device path below /sys/devices and its tempN input, e.g. hwmon:coretemp:temp1:platform/coretemp.0, in cpu_sensor_identity and aux_sensor_identity (one entry per aux sensor, in order). The key is readable and holds nothing a cfg value, the shell or the comma-separated aux list would need to escape; a chip whose name or device path holds anything else keeps its path binding.
  • Service start resolves the identities again, in migrate_cfg_and_labels, and rewrites only those four fields. Existing configurations get their identities recorded at their first start, from the sensors their saved paths name then.
  • A missing or ambiguous identity is never replaced by another sensor. The identity stands in for the path, has no reading, and so raises the missing-sensor warning from fanctrlplus2: warn when a configured sensor gives no reading (#21) #23, which names it. The settings page lists it as "Not found: coretemp - temp1 (platform/coretemp.0)" and keeps it selected, so saving the form does not quietly switch the fan to the first sensor in the list; the same applies to a saved aux sensor that gives no reading when the page opens.
  • storcli:, nvidia:, mlx: and custom: sensors are already stable and are saved as they are. Backups validate and restore the new fields.
After a reboot that renumbers hwmon
Before cpu_sensor still points at hwmon4, now an NVMe drive; the fan follows the drive
After cpu_sensor is resolved to the hwmonN where coretemp now is; if it cannot be found, or two inputs match, the fan has no reading from it and warns

Tests

  • tests/sensor_identity_test.php: a fake sysfs with the layout above, renumbered between two boots (NVMe first, then last): identities recorded for an old config without moving anything, both CPU and aux sensors followed to their new hwmonN, unrelated escaped values untouched, no rewrite when nothing changed, an ambiguous identity left unresolved and recovered once the duplicate is gone, a missing chip kept as its identity and found again when it is back, the values the page saves, the "Not found" option, and backup validation (path escape and stray characters refused).
  • tests/aux_sensor_read_test.sh: an unresolved identity in the aux list counts as unread; the other sensors are still read.
  • bash tests/run-all.sh: 36 of 36 pass.

No physical-hardware verification yet: the test VM has no hwmon devices, so the renumbering is covered by the fake sysfs only.

Note on #31

#31's diagnostics count aux sensors by kind and file a value that does not start with /sys/ under "other" (Diagnostics.php, the $kind line). A sensor that is saved but not found right now is kept in its identity form, e.g. hwmon:coretemp:temp1:platform/coretemp.0. With both merged that one line would want str_starts_with($sensor, 'hwmon:') counted as hwmon too. I can add it to whichever of the two lands second.

cpu_sensor and aux_sensor are /sys/class/hwmon/hwmonN paths, and hwmonN
follows probe order, so after a reboot that probes NVMe drives in another
order a saved path can name a different chip. Save each hwmon sensor with
its chip name, device path below /sys/devices and tempN input as well, and
resolve those again at service start, as controller_identity is for PWM
controllers. Existing configurations get the identity recorded at start.

A missing or ambiguous identity is never replaced by another sensor: it
stands in for the path, has no reading, and so raises the missing-sensor
warning; the settings page lists it as not found and keeps it selected.
@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 46914657-5da7-413d-a661-08660e631882
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@luuvasara

Copy link
Copy Markdown
Author

Closing this as superseded by #43 and #44. They solve the same problem another way: the page saves the sensor's resolved /sys/devices/... path, and fcp_pin_sensor() moves it to the chip's new hwmon number at every start, accepting only a unique match. I checked the case this PR was written for (coretemp moving from hwmon4 to hwmon5 while an NVMe drive takes hwmon4, plus an ambiguous twin and an absent device) against main at 4d9dd97: it passes there, and the same check fails on the base this PR started from. Rebasing would only add a second sensor identity next to yours.

@luuvasara luuvasara closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant