diff options
author | Marco Peereboom <marco@cvs.openbsd.org> | 2007-04-21 23:05:20 +0000 |
---|---|---|
committer | Marco Peereboom <marco@cvs.openbsd.org> | 2007-04-21 23:05:20 +0000 |
commit | f0ad0e23481cd28bfe28ae749f36211812173433 (patch) | |
tree | 85bf3c4d06867e56a62d858bbb39aa22f4225f18 /sys | |
parent | f45092b9b5beee0075cf194130e00b35028c650e (diff) |
Add volumes to sensors.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/softraid.c | 84 | ||||
-rw-r--r-- | sys/dev/softraidvar.h | 9 |
2 files changed, 90 insertions, 3 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 856dbe728f9..ff6f7575c81 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.25 2007/04/19 22:12:41 marco Exp $ */ +/* $OpenBSD: softraid.c,v 1.26 2007/04/21 23:05:19 marco Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * @@ -32,8 +32,8 @@ #include <sys/namei.h> #include <sys/fcntl.h> #include <sys/disklabel.h> - #include <sys/mount.h> +#include <sys/sensors.h> #include <machine/bus.h> @@ -124,6 +124,8 @@ void sr_raid1_startwu(struct sr_workunit *); void sr_get_uuid(struct sr_uuid *); u_int32_t sr_checksum(char *, u_int32_t *, u_int32_t); int sr_save_metadata(struct sr_discipline *); +void sr_refresh_sensors(void *); +int sr_create_sensors(struct sr_discipline *); struct scsi_adapter sr_switch = { sr_scsi_cmd, sr_minphys, NULL, NULL, sr_scsi_ioctl @@ -859,6 +861,10 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc) rv = sr_save_metadata(sd); /* save metadata to disk */ + if (sr_create_sensors(sd) != 0) + printf("%s: unable to create sensor for %s\n", DEVNAME(sc), + dev->dv_xname); + return (rv); unwind: @@ -1621,6 +1627,9 @@ sr_raid1_set_vol_state(struct sr_discipline *sd) int new_state, i, s, nd; int old_state = sd->sd_vol.sv_meta.svm_status; + DNPRINTF(SR_D_STATE, "%s: %s: sr_raid1_set_vol_state\n", + DEVNAME(sd->sd_sc), sd->sd_vol.sv_meta.svm_devname); + nd = sd->sd_vol.sv_meta.svm_no_chunk; for (i = 0; i < SR_MAX_STATES; i++) @@ -1872,3 +1881,74 @@ sr_save_metadata(struct sr_discipline *sd) bad: return (rv); } + +int +sr_create_sensors(struct sr_discipline *sd) +{ + struct sr_softc *sc = sd->sd_sc; + int rv = 1; + + DNPRINTF(SR_D_STATE, "%s: %s: sr_create_sensors\n", + DEVNAME(sc), sd->sd_vol.sv_meta.svm_devname); + + strlcpy(sd->sd_vol.sv_sensordev.xname, DEVNAME(sc), + sizeof(sd->sd_vol.sv_sensordev.xname)); + + sd->sd_vol.sv_sensor.type = SENSOR_DRIVE; + sd->sd_vol.sv_sensor.status = SENSOR_S_UNKNOWN; + strlcpy(sd->sd_vol.sv_sensor.desc, sd->sd_vol.sv_meta.svm_devname, + sizeof(sd->sd_vol.sv_sensor.desc)); + + sensor_attach(&sd->sd_vol.sv_sensordev, &sd->sd_vol.sv_sensor); + + if (sc->sc_sensors_running == 0) { + if (sensor_task_register(sc, sr_refresh_sensors, 10) != 0) + goto bad; + sc->sc_sensors_running = 1; + } + sensordev_install(&sd->sd_vol.sv_sensordev); + + rv = 0; +bad: + return (rv); +} +void +sr_refresh_sensors(void *arg) +{ + struct sr_softc *sc = arg; + int i, vol; + struct sr_volume *sv; + + DNPRINTF(SR_D_STATE, "%s: sr_refresh_sensors\n", DEVNAME(sc)); + + for (i = 0, vol = -1; i < SR_MAXSCSIBUS; i++) { + /* XXX this will not work when we stagger disciplines */ + if (!sc->sc_dis[i]) + continue; + + sv = &sc->sc_dis[i]->sd_vol; + + switch(sv->sv_meta.svm_status) { + case BIOC_SVOFFLINE: + sv->sv_sensor.value = SENSOR_DRIVE_FAIL; + sv->sv_sensor.status = SENSOR_S_CRIT; + break; + + case BIOC_SVDEGRADED: + sv->sv_sensor.value = SENSOR_DRIVE_PFAIL; + sv->sv_sensor.status = SENSOR_S_WARN; + break; + + case BIOC_SVSCRUB: + case BIOC_SVONLINE: + sv->sv_sensor.value = SENSOR_DRIVE_ONLINE; + sv->sv_sensor.status = SENSOR_S_OK; + break; + + default: + sv->sv_sensor.value = 0; /* unknown */ + sv->sv_sensor.status = SENSOR_S_UNKNOWN; + } + + } +} diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h index 7fba3477ae8..4a0dcbef094 100644 --- a/sys/dev/softraidvar.h +++ b/sys/dev/softraidvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: softraidvar.h,v 1.9 2007/04/19 02:44:29 marco Exp $ */ +/* $OpenBSD: softraidvar.h,v 1.10 2007/04/21 23:05:19 marco Exp $ */ /* * Copyright (c) 2006 Marco Peereboom <sro@peereboom.us> * @@ -187,6 +187,10 @@ struct sr_volume { /* runtime data */ struct sr_chunk_head sv_chunk_list; /* linked list of all chunks */ struct sr_chunk **sv_chunks; /* array to same chunks */ + + /* sensors */ + struct ksensor sv_sensor; + struct ksensordev sv_sensordev; }; /* RAID 1 */ @@ -257,11 +261,14 @@ struct sr_softc { int (*sc_ioctl)(struct device *, u_long, caddr_t); struct rwlock sc_lock; + + int sc_sensors_running; /* * during scsibus attach this is the discipline that is in use * this variable is protected by sc_lock and splhigh */ struct sr_discipline *sc_attach_dis; + /* * XXX expensive, alternative would be nice but has to be cheap * since the scsibus lookup happens on each IO |