Whamcloud - gitweb
LU-8066 obd: make health_check sysfs compliant
[fs/lustre-release.git] / lustre / obdclass / obd_sysfs.c
index a297e52..f83c6f3 100644 (file)
@@ -209,10 +209,8 @@ health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
        size_t len = 0;
        int i;
 
-       if (libcfs_catastrophe) {
-               len = sprintf(buf, "LBUG\n");
-               healthy = false;
-       }
+       if (libcfs_catastrophe)
+               return sprintf(buf, "LBUG\n");
 
        read_lock(&obd_dev_lock);
        for (i = 0; i < class_devno_max(); i++) {
@@ -226,16 +224,17 @@ health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
                if (obd->obd_stopping)
                        continue;
 
-               class_incref(obd, __FUNCTION__, current);
+               class_incref(obd, __func__, current);
                read_unlock(&obd_dev_lock);
 
-               if (obd_health_check(NULL, obd)) {
-                       len = sprintf(buf, "device %s reported unhealthy\n",
-                                     obd->obd_name);
+               if (obd_health_check(NULL, obd))
                        healthy = false;
-               }
-               class_decref(obd, __FUNCTION__, current);
+
+               class_decref(obd, __func__, current);
                read_lock(&obd_dev_lock);
+
+               if (!healthy)
+                       break;
        }
        read_unlock(&obd_dev_lock);
 
@@ -318,7 +317,7 @@ EXPORT_SYMBOL_GPL(debugfs_lustre_root);
 
 #ifdef CONFIG_PROC_FS
 /* Root for /proc/fs/lustre */
-struct proc_dir_entry *proc_lustre_root = NULL;
+struct proc_dir_entry *proc_lustre_root;
 EXPORT_SYMBOL(proc_lustre_root);
 #else
 #define lprocfs_base NULL
@@ -358,10 +357,10 @@ static struct attribute *lustre_attrs[] = {
 
 static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos)
 {
-        if (*pos >= class_devno_max())
-                return NULL;
+       if (*pos >= class_devno_max())
+               return NULL;
 
-        return pos;
+       return pos;
 }
 
 static void obd_device_list_seq_stop(struct seq_file *p, void *v)
@@ -370,33 +369,33 @@ static void obd_device_list_seq_stop(struct seq_file *p, void *v)
 
 static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
 {
-        ++*pos;
-        if (*pos >= class_devno_max())
-                return NULL;
+       ++*pos;
+       if (*pos >= class_devno_max())
+               return NULL;
 
-        return pos;
+       return pos;
 }
 
 static int obd_device_list_seq_show(struct seq_file *p, void *v)
 {
-        loff_t index = *(loff_t *)v;
-        struct obd_device *obd = class_num2obd((int)index);
-        char *status;
-
-        if (obd == NULL)
-                return 0;
-
-        LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
-        if (obd->obd_stopping)
-                status = "ST";
-        else if (obd->obd_inactive)
-                status = "IN";
-        else if (obd->obd_set_up)
-                status = "UP";
-        else if (obd->obd_attached)
-                status = "AT";
-        else
-                status = "--";
+       loff_t index = *(loff_t *)v;
+       struct obd_device *obd = class_num2obd((int)index);
+       char *status;
+
+       if (obd == NULL)
+               return 0;
+
+       LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
+       if (obd->obd_stopping)
+               status = "ST";
+       else if (obd->obd_inactive)
+               status = "IN";
+       else if (obd->obd_set_up)
+               status = "UP";
+       else if (obd->obd_attached)
+               status = "AT";
+       else
+               status = "--";
 
        seq_printf(p, "%3d %s %s %s %s %d\n",
                   (int)index, status, obd->obd_type->typ_name,
@@ -406,10 +405,10 @@ static int obd_device_list_seq_show(struct seq_file *p, void *v)
 }
 
 static const struct seq_operations obd_device_list_sops = {
-        .start = obd_device_list_seq_start,
-        .stop = obd_device_list_seq_stop,
-        .next = obd_device_list_seq_next,
-        .show = obd_device_list_seq_show,
+       .start = obd_device_list_seq_start,
+       .stop = obd_device_list_seq_stop,
+       .next = obd_device_list_seq_next,
+       .show = obd_device_list_seq_show,
 };
 
 static int obd_device_list_open(struct inode *inode, struct file *file)
@@ -426,13 +425,47 @@ static int obd_device_list_open(struct inode *inode, struct file *file)
 }
 
 static const struct file_operations obd_device_list_fops = {
-        .owner   = THIS_MODULE,
-        .open    = obd_device_list_open,
-        .read    = seq_read,
-        .llseek  = seq_lseek,
-        .release = seq_release,
+       .owner   = THIS_MODULE,
+       .open    = obd_device_list_open,
+       .read    = seq_read,
+       .llseek  = seq_lseek,
+       .release = seq_release,
 };
 
+static int
+health_check_seq_show(struct seq_file *m, void *unused)
+{
+       int i;
+
+       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, __func__, current);
+               read_unlock(&obd_dev_lock);
+
+               if (obd_health_check(NULL, obd)) {
+                       seq_printf(m, "device %s reported unhealthy\n",
+                                  obd->obd_name);
+               }
+               class_decref(obd, __func__, current);
+               read_lock(&obd_dev_lock);
+       }
+       read_unlock(&obd_dev_lock);
+
+       return 0;
+}
+
+LDEBUGFS_SEQ_FOPS_RO(health_check);
+
 struct kset *lustre_kset;
 EXPORT_SYMBOL_GPL(lustre_kset);
 
@@ -463,6 +496,7 @@ int class_procfs_init(void)
        struct proc_dir_entry *entry;
        struct dentry *file;
        int rc = -ENOMEM;
+
        ENTRY;
 
        lustre_kset = kset_create_and_add("lustre", NULL, fs_kobj);
@@ -500,6 +534,15 @@ int class_procfs_init(void)
                goto out;
        }
 
+       file = debugfs_create_file("health_check", 0444, debugfs_lustre_root,
+                                  NULL, &health_check_fops);
+       if (IS_ERR_OR_NULL(file)) {
+               rc = file ? PTR_ERR(file) : -ENOMEM;
+               debugfs_remove_recursive(debugfs_lustre_root);
+               kset_unregister(lustre_kset);
+               goto out;
+       }
+
        entry = lprocfs_register("fs/lustre", NULL, NULL, NULL);
        if (IS_ERR(entry)) {
                rc = PTR_ERR(entry);