diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2005-11-12 08:06:46 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2005-11-12 08:06:46 +0000 |
commit | 7ba80e8bbcfcdcf189fb06056103287b3649d54b (patch) | |
tree | 060ea243374c657c260143fe43829cdd7cd60ce1 /sys | |
parent | 236d76042118245356e605ed70292a293b4f3b24 (diff) |
remove the ses kthread goop and use the sensor kthread for updates instead
tested by deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/scsi/ses.c | 127 |
1 files changed, 43 insertions, 84 deletions
diff --git a/sys/scsi/ses.c b/sys/scsi/ses.c index 17d6167446c..703daff6187 100644 --- a/sys/scsi/ses.c +++ b/sys/scsi/ses.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ses.c,v 1.27 2005/09/29 07:19:35 dlg Exp $ */ +/* $OpenBSD: ses.c,v 1.28 2005/11/12 08:06:45 dlg Exp $ */ /* * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> @@ -69,8 +69,6 @@ struct ses_slot { }; #endif -struct ses_thread; - struct ses_softc { struct device sc_dev; struct scsi_link *sc_link; @@ -87,7 +85,6 @@ struct ses_softc { TAILQ_HEAD(, ses_slot) sc_slots; #endif TAILQ_HEAD(, ses_sensor) sc_sensors; - struct ses_thread *sc_thread; }; struct cfattach ses_ca = { @@ -102,18 +99,10 @@ struct cfdriver ses_cd = { #define SES_BUFLEN 2048 /* XXX is this enough? */ -struct ses_thread { - struct ses_softc *sc; - volatile int running; -}; - -void ses_create_thread(void *); -void ses_refresh(void *); - int ses_read_config(struct ses_softc *); int ses_read_status(struct ses_softc *); int ses_make_sensors(struct ses_softc *, struct ses_type_desc *, int); -int ses_refresh_sensors(struct ses_softc *); +void ses_refresh_sensors(void *); #if NBIO > 0 int ses_ioctl(struct device *, u_long, caddr_t); @@ -157,9 +146,12 @@ ses_attach(struct device *parent, struct device *self, void *aux) struct ses_softc *sc = (struct ses_softc *)self; struct scsibus_attach_args *sa = aux; char vendor[33]; + struct ses_sensor *sensor; +#if NBIO > 0 + struct ses_slot *slot; +#endif sc->sc_link = sa->sa_sc_link; - sc->sc_thread = NULL; sa->sa_sc_link->device_softc = sc; scsi_strvis(vendor, sc->sc_link->inqdata.vendor, @@ -171,37 +163,37 @@ ses_attach(struct device *parent, struct device *self, void *aux) printf("\n"); - sc->sc_thread = malloc(sizeof(struct ses_thread), M_DEVBUF, M_NOWAIT); - if (sc->sc_thread == NULL) { - printf("%s: unable to allocate thread information\n", + if (ses_read_config(sc) != 0) { + printf("%s: unable to read enclosure configuration\n", DEVNAME(sc)); return; } - sc->sc_thread->sc = sc; - sc->sc_thread->running = 1; + if (!TAILQ_EMPTY(&sc->sc_sensors) && + sensor_task_register(sc, ses_refresh_sensors, 10) != 0) { + printf("%s: unable to register update task\n", DEVNAME(sc)); + while (!TAILQ_EMPTY(&sc->sc_sensors)) { + sensor = TAILQ_FIRST(&sc->sc_sensors); + TAILQ_REMOVE(&sc->sc_sensors, sensor, se_entry); + free(sensor, M_DEVBUF); + } + } else { + TAILQ_FOREACH(sensor, &sc->sc_sensors, se_entry) + SENSOR_ADD(&sensor->se_sensor); + } #if NBIO > 0 - if (bio_register(self, ses_ioctl) != 0) { - free(sc->sc_thread, M_DEVBUF); - sc->sc_thread = NULL; + if (!TAILQ_EMPTY(&sc->sc_slots) && + bio_register(self, ses_ioctl) != 0) { printf("%s: unable to register ioctl\n", DEVNAME(sc)); - return; + while (!TAILQ_EMPTY(&sc->sc_slots)) { + slot = TAILQ_FIRST(&sc->sc_slots); + TAILQ_REMOVE(&sc->sc_slots, slot, sl_entry); + free(slot, M_DEVBUF); + } } #endif - if (ses_read_config(sc) != 0) { -#if NBIO > 0 - bio_unregister(self); -#endif - free(sc->sc_thread, M_DEVBUF); - sc->sc_thread = NULL; - printf("%s: unable to read enclosure configuration\n", - DEVNAME(sc)); - return; - } - - kthread_create_deferred(ses_create_thread, sc); } int @@ -213,21 +205,19 @@ ses_detach(struct device *self, int flags) struct ses_slot *slot; #endif - if (sc->sc_thread != NULL) { - sc->sc_thread->running = 0; - wakeup(sc->sc_thread); - sc->sc_thread = NULL; - #if NBIO > 0 + if (!TAILQ_EMPTY(&sc->sc_slots)) { bio_unregister(self); - while (!TAILQ_EMPTY(&sc->sc_slots)) { slot = TAILQ_FIRST(&sc->sc_slots); TAILQ_REMOVE(&sc->sc_slots, slot, sl_entry); free(slot, M_DEVBUF); } + } #endif + if (!TAILQ_EMPTY(&sc->sc_sensors)) { + sensor_task_unregister(sc); /* * We can't free the sensors once theyre in the systems sensor * list, so just mark them as invalid. @@ -235,45 +225,12 @@ ses_detach(struct device *self, int flags) TAILQ_FOREACH(sensor, &sc->sc_sensors, se_entry) sensor->se_sensor.flags |= SENSOR_FINVALID; - free(sc->sc_buf, M_DEVBUF); } - return (0); -} - -void -ses_create_thread(void *arg) -{ - struct ses_softc *sc = arg; - - if (kthread_create(ses_refresh, sc->sc_thread, NULL, DEVNAME(sc)) != 0) - panic("ses thread"); -} - -void -ses_refresh(void *arg) -{ - struct ses_thread *thread = arg; - struct ses_softc *sc = thread->sc; - int ok = 1; - - while (thread->running) { - if (ses_refresh_sensors(sc) != 0) { - if (ok) - printf("%s: status read error\n", DEVNAME(sc)); - ok = 0; - } else { - if (!ok) - printf("%s: status read ok\n", DEVNAME(sc)); - ok = 1; - } - - tsleep(thread, PWAIT, "timeout", 10 * hz); - } - - free(thread, M_DEVBUF); + if (sc->sc_buf != NULL) + free(sc->sc_buf, M_DEVBUF); - kthread_exit(0); + return (0); } int @@ -503,8 +460,6 @@ ses_make_sensors(struct ses_softc *sc, struct ses_type_desc *types, int ntypes) status++; } - TAILQ_FOREACH(sensor, &sc->sc_sensors, se_entry) - SENSOR_ADD(&sensor->se_sensor); return (0); error: #if NBIO > 0 @@ -522,14 +477,17 @@ error: return (1); } -int -ses_refresh_sensors(struct ses_softc *sc) +void +ses_refresh_sensors(void *arg) { + struct ses_softc *sc = (struct ses_softc *)arg; struct ses_sensor *sensor; int ret = 0; - if (ses_read_status(sc) != 0) - return (1); + if (ses_read_status(sc) != 0) { + printf("%s: unable to read enclosure status\n", DEVNAME(sc)); + return; + } TAILQ_FOREACH(sensor, &sc->sc_sensors, se_entry) { DPRINTFN(10, "%s: %s 0x%02x 0x%02x%02x%02x\n", DEVNAME(sc), @@ -577,7 +535,8 @@ ses_refresh_sensors(struct ses_softc *sc) } } - return (ret); + if (ret) + printf("%s: error in sensor data\n"); } #if NBIO > 0 |