Whamcloud - gitweb
LU-11698 libcfs: Add checksum speed under /sys/fs
[fs/lustre-release.git] / lustre / obdclass / obd_sysfs.c
index 64ab464..5d9430a 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/obdclass/obd_sysfs.c
  *
@@ -63,6 +62,7 @@
 #include <linux/kobject.h>
 
 #include <libcfs/libcfs.h>
+#include <libcfs/libcfs_crypto.h>
 #include <obd_support.h>
 #include <obd_class.h>
 #include <lprocfs_status.h>
@@ -121,6 +121,7 @@ LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
 LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
 LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
 LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
+LUSTRE_STATIC_UINT_ATTR(lbug_on_eviction, &obd_lbug_on_eviction);
 
 #ifdef HAVE_SERVER_SUPPORT
 LUSTRE_STATIC_UINT_ATTR(ldlm_timeout, &ldlm_timeout);
@@ -160,7 +161,7 @@ static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
 
        val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
 
-       if (val > ((totalram_pages / 10) * 9)) {
+       if (val > ((cfs_totalram_pages() / 10) * 9)) {
                /* Somebody wants to assign too much memory to dirty pages */
                return -EINVAL;
        }
@@ -176,6 +177,34 @@ static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_RW_ATTR(max_dirty_mb);
 
+#ifdef HAVE_SERVER_SUPPORT
+static ssize_t no_transno_store(struct kobject *kobj,
+                               struct attribute *attr,
+                               const char *buffer, size_t count)
+{
+       struct obd_device *obd;
+       unsigned int idx;
+       int rc;
+
+       rc = kstrtouint(buffer, 10, &idx);
+       if (rc)
+               return rc;
+
+       obd = class_num2obd(idx);
+       if (!obd || !obd->obd_attached) {
+               if (obd)
+                       CERROR("%s: not attached\n", obd->obd_name);
+               return -ENODEV;
+       }
+
+       spin_lock(&obd->obd_dev_lock);
+       obd->obd_no_transno = 1;
+       spin_unlock(&obd->obd_dev_lock);
+       return count;
+}
+LUSTRE_WO_ATTR(no_transno);
+#endif /* HAVE_SERVER_SUPPORT */
+
 static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
                            char *buf)
 {
@@ -185,7 +214,7 @@ static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
 static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr,
                           char *buf)
 {
-#ifdef ENABLE_PINGER
+#ifdef CONFIG_LUSTRE_FS_PINGER
        const char *state = "on";
 #else
        const char *state = "off";
@@ -208,10 +237,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++) {
@@ -225,16 +252,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);
 
@@ -252,7 +280,7 @@ static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
        int rc = 0;
 
        if (strlen(obd_jobid_var))
-               rc = snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
+               rc = scnprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
        return rc;
 }
 
@@ -279,7 +307,7 @@ static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr,
        int rc = 0;
 
        if (strlen(obd_jobid_name))
-               rc = snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_name);
+               rc = scnprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_name);
        return rc;
 }
 
@@ -311,13 +339,51 @@ static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr,
        return count;
 }
 
+static ssize_t jobid_this_session_show(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      char *buf)
+{
+       char *jid;
+       int ret = -ENOENT;
+
+       rcu_read_lock();
+       jid = jobid_current();
+       if (jid)
+               ret = scnprintf(buf, PAGE_SIZE, "%s\n", jid);
+       rcu_read_unlock();
+       return ret;
+}
+
+static ssize_t jobid_this_session_store(struct kobject *kobj,
+                                       struct attribute *attr,
+                                       const char *buffer,
+                                       size_t count)
+{
+       char *jobid;
+       int len;
+       int ret;
+
+       if (!count || count > LUSTRE_JOBID_SIZE)
+               return -EINVAL;
+
+       jobid = kstrndup(buffer, count, GFP_KERNEL);
+       if (!jobid)
+               return -ENOMEM;
+       len = strcspn(jobid, "\n ");
+       jobid[len] = '\0';
+       ret = jobid_set_current(jobid);
+       kfree(jobid);
+
+       return ret ?: count;
+}
+
 /* Root for /sys/kernel/debug/lustre */
 struct dentry *debugfs_lustre_root;
 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
@@ -328,6 +394,7 @@ LUSTRE_RO_ATTR(pinger);
 LUSTRE_RO_ATTR(health_check);
 LUSTRE_RW_ATTR(jobid_var);
 LUSTRE_RW_ATTR(jobid_name);
+LUSTRE_RW_ATTR(jobid_this_session);
 
 static struct attribute *lustre_attrs[] = {
        &lustre_attr_version.attr,
@@ -335,6 +402,7 @@ static struct attribute *lustre_attrs[] = {
        &lustre_attr_health_check.attr,
        &lustre_attr_jobid_name.attr,
        &lustre_attr_jobid_var.attr,
+       &lustre_attr_jobid_this_session.attr,
        &lustre_sattr_timeout.u.attr,
        &lustre_attr_max_dirty_mb.attr,
        &lustre_sattr_debug_peer_on_timeout.u.attr,
@@ -350,16 +418,18 @@ static struct attribute *lustre_attrs[] = {
 #ifdef HAVE_SERVER_SUPPORT
        &lustre_sattr_ldlm_timeout.u.attr,
        &lustre_sattr_bulk_timeout.u.attr,
+       &lustre_attr_no_transno.attr,
 #endif
+       &lustre_sattr_lbug_on_eviction.u.attr,
        NULL,
 };
 
 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)
@@ -368,33 +438,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,
@@ -404,10 +474,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)
@@ -424,13 +494,104 @@ 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,
+};
+
+/* checksum_speed */
+static void *checksum_speed_start(struct seq_file *p, loff_t *pos)
+{
+       return pos;
+}
+
+static void checksum_speed_stop(struct seq_file *p, void *v)
+{
+}
+
+static void *checksum_speed_next(struct seq_file *p, void *v, loff_t *pos)
+{
+       ++(*pos);
+       if (*pos >= CFS_HASH_ALG_SPEED_MAX - 1)
+               return NULL;
+
+       return pos;
+}
+
+static int checksum_speed_show(struct seq_file *p, void *v)
+{
+       loff_t index = *(loff_t *)v;
+
+       if (!index || index > CFS_HASH_ALG_SPEED_MAX - 1)
+               return 0;
+
+       seq_printf(p, "%s: %d\n", cfs_crypto_hash_name(index),
+                  cfs_crypto_hash_speeds[index]);
+
+       return 0;
+}
+
+static const struct seq_operations checksum_speed_sops = {
+       .start = checksum_speed_start,
+       .stop = checksum_speed_stop,
+       .next = checksum_speed_next,
+       .show = checksum_speed_show,
+};
+
+static int checksum_speed_open(struct inode *inode, struct file *file)
+{
+       int rc = seq_open(file, &checksum_speed_sops);
+
+       if (rc)
+               return rc;
+
+       return 0;
+}
+
+static const struct file_operations checksum_speed_fops = {
+       .owner   = THIS_MODULE,
+       .open    = checksum_speed_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);
 
@@ -461,6 +622,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);
@@ -481,22 +643,15 @@ int class_procfs_init(void)
        }
 
        debugfs_lustre_root = debugfs_create_dir("lustre", NULL);
-       if (IS_ERR_OR_NULL(debugfs_lustre_root)) {
-               rc = debugfs_lustre_root ? PTR_ERR(debugfs_lustre_root)
-                                        : -ENOMEM;
-               debugfs_lustre_root = NULL;
-               kset_unregister(lustre_kset);
-               goto out;
-       }
 
        file = debugfs_create_file("devices", 0444, debugfs_lustre_root, NULL,
                                   &obd_device_list_fops);
-       if (IS_ERR_OR_NULL(file)) {
-               rc = file ? PTR_ERR(file) : -ENOMEM;
-               debugfs_remove(debugfs_lustre_root);
-               kset_unregister(lustre_kset);
-               goto out;
-       }
+
+       file = debugfs_create_file("health_check", 0444, debugfs_lustre_root,
+                                  NULL, &health_check_fops);
+
+       file = debugfs_create_file("checksum_speed", 0444, debugfs_lustre_root,
+                                  NULL, &checksum_speed_fops);
 
        entry = lprocfs_register("fs/lustre", NULL, NULL, NULL);
        if (IS_ERR(entry)) {