unregister softraid sensors when the volumes are removed
authorphessler <phessler@openbsd.org>
Sun, 18 Aug 2024 19:44:10 +0000 (19:44 +0000)
committerphessler <phessler@openbsd.org>
Sun, 18 Aug 2024 19:44:10 +0000 (19:44 +0000)
From Sven M. Hallberg

tested and OK phessler@
OK mvs@

sys/dev/softraid.c

index b73f2d1..3acccfa 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.430 2024/02/03 18:51:58 beck Exp $ */
+/* $OpenBSD: softraid.c,v 1.431 2024/08/18 19:44:10 phessler Exp $ */
 /*
  * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
  * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -4862,10 +4862,25 @@ bad:
 void
 sr_sensors_delete(struct sr_discipline *sd)
 {
+       struct sr_softc         *sc = sd->sd_sc;
+
        DNPRINTF(SR_D_STATE, "%s: sr_sensors_delete\n", DEVNAME(sd->sd_sc));
 
-       if (sd->sd_vol.sv_sensor_attached)
+       if (sd->sd_vol.sv_sensor_attached) {
                sensor_detach(&sd->sd_sc->sc_sensordev, &sd->sd_vol.sv_sensor);
+               sd->sd_vol.sv_sensor_attached = 0;
+       }
+
+       /*
+        * Unregister the refresh task if we detached our last sensor.
+        */
+       TAILQ_FOREACH(sd, &sc->sc_dis_list, sd_link)
+               if (sd->sd_vol.sv_sensor_attached)
+                       return;
+       if (sc->sc_sensor_task != NULL) {
+               sensor_task_unregister(sc->sc_sensor_task);
+               sc->sc_sensor_task = NULL;
+       }
 }
 
 void