- int rc = 0, i;
- *eof = 1;
-
- if (libcfs_catastrophe)
- rc += snprintf(page + rc, count - rc, "LBUG\n");
-
- spin_lock(&obd_dev_lock);
- for (i = 0; i < class_devno_max(); i++) {
- struct obd_device *obd;
-
- obd = class_num2obd(i);
- if (obd == NULL)
- continue;
-
- LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
- if (obd->obd_stopping)
- continue;
-
- class_incref(obd);
- spin_unlock(&obd_dev_lock);
-
- if (obd_health_check(obd)) {
- rc += snprintf(page + rc, count - rc,
- "device %s reported unhealthy\n",
- obd->obd_name);
- }
- class_decref(obd);
- spin_lock(&obd_dev_lock);
- }
- spin_unlock(&obd_dev_lock);
+ bool healthy = true;
+ size_t len = 0;
+ int i;
+
+ if (libcfs_catastrophe) {
+ len = sprintf(buf, "LBUG\n");
+ healthy = false;
+ }
+
+ read_lock(&obd_dev_lock);
+ for (i = 0; i < class_devno_max(); i++) {
+ struct obd_device *obd;
+
+ obd = class_num2obd(i);
+ if (obd == NULL || !obd->obd_attached || !obd->obd_set_up)
+ continue;
+
+ LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
+ if (obd->obd_stopping)
+ continue;
+
+ class_incref(obd, __FUNCTION__, current);
+ read_unlock(&obd_dev_lock);
+
+ if (obd_health_check(NULL, obd)) {
+ len = sprintf(buf, "device %s reported unhealthy\n",
+ obd->obd_name);
+ healthy = false;
+ }
+ class_decref(obd, __FUNCTION__, current);
+ read_lock(&obd_dev_lock);
+ }
+ read_unlock(&obd_dev_lock);
+
+ if (healthy)
+ len = sprintf(buf, "healthy\n");
+ else
+ len = sprintf(buf, "NOT HEALTHY\n");
+
+ return len;
+}
+
+static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ int rc = 0;
+
+ if (strlen(obd_jobid_var))
+ rc = snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
+ return rc;
+}
+
+static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr,
+ const char *buffer, size_t count)
+{
+ if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
+ return -EINVAL;
+
+ memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
+
+ memcpy(obd_jobid_var, buffer, count);
+
+ /* Trim the trailing '\n' if any */
+ if (obd_jobid_var[count - 1] == '\n')
+ obd_jobid_var[count - 1] = 0;