From 8b82844505699f10f80c7e554364e3d0618cd77d Mon Sep 17 00:00:00 2001 From: Oleg Drokin Date: Thu, 21 May 2015 15:31:36 -0400 Subject: [PATCH] staging/lustre: Move /proc/fs/lustre root level files to sysfs except devices, for now. Signed-off-by: Oleg Drokin Signed-off-by: Dmitry Eremin Signed-off-by: Greg Kroah-Hartman --- .../lustre/lustre/include/lprocfs_status.h | 2 + .../lustre/obdclass/linux/linux-module.c | 111 ++++++++++-------- drivers/staging/lustre/sysfs-fs-lustre | 41 +++++++ 3 files changed, 108 insertions(+), 46 deletions(-) create mode 100644 drivers/staging/lustre/sysfs-fs-lustre diff --git a/drivers/staging/lustre/lustre/include/lprocfs_status.h b/drivers/staging/lustre/lustre/include/lprocfs_status.h index 37f00e429614..b46cd54f2081 100644 --- a/drivers/staging/lustre/lustre/include/lprocfs_status.h +++ b/drivers/staging/lustre/lustre/include/lprocfs_status.h @@ -350,6 +350,8 @@ enum { /* class_obd.c */ extern struct proc_dir_entry *proc_lustre_root; +extern struct kobject *lustre_kobj; + struct obd_device; struct obd_histogram; diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c index 06944b863d16..df3aa8fd253e 100644 --- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c +++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c @@ -64,6 +64,7 @@ #include #include #include +#include #include "../../../include/linux/libcfs/libcfs.h" #include "../../../include/linux/lnet/lnetctl.h" @@ -216,29 +217,27 @@ struct miscdevice obd_psdev = { }; -#if defined (CONFIG_PROC_FS) -static int obd_proc_version_seq_show(struct seq_file *m, void *v) +static ssize_t version_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - seq_printf(m, "lustre: %s\nkernel: %s\nbuild: %s\n", - LUSTRE_VERSION_STRING, "patchless_client", BUILD_VERSION); - return 0; + return sprintf(buf, "%s\n", LUSTRE_VERSION_STRING); } -LPROC_SEQ_FOPS_RO(obd_proc_version); -int obd_proc_pinger_seq_show(struct seq_file *m, void *v) +static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - seq_printf(m, "%s\n", "on"); - return 0; + return sprintf(buf, "%s\n", "on"); } -LPROC_SEQ_FOPS_RO(obd_proc_pinger); -static int obd_proc_health_seq_show(struct seq_file *m, void *v) +static ssize_t health_show(struct kobject *kobj, struct attribute *attr, + char *buf) { bool healthy = true; int i; + size_t len = 0; if (libcfs_catastrophe) - seq_printf(m, "LBUG\n"); + return sprintf(buf, "LBUG\n"); read_lock(&obd_dev_lock); for (i = 0; i < class_devno_max(); i++) { @@ -256,8 +255,6 @@ static int obd_proc_health_seq_show(struct seq_file *m, void *v) read_unlock(&obd_dev_lock); if (obd_health_check(NULL, obd)) { - seq_printf(m, "device %s reported unhealthy\n", - obd->obd_name); healthy = false; } class_decref(obd, __func__, current); @@ -266,32 +263,29 @@ static int obd_proc_health_seq_show(struct seq_file *m, void *v) read_unlock(&obd_dev_lock); if (healthy) - seq_puts(m, "healthy\n"); + len = sprintf(buf, "healthy\n"); else - seq_puts(m, "NOT HEALTHY\n"); + len = sprintf(buf, "NOT HEALTHY\n"); - return 0; + return len; } -LPROC_SEQ_FOPS_RO(obd_proc_health); -static int obd_proc_jobid_var_seq_show(struct seq_file *m, void *v) +static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - seq_printf(m, "%s\n", obd_jobid_var); - return 0; + return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var); } -static ssize_t obd_proc_jobid_var_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) +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); - /* This might leave the var invalid on error, which is probably fine.*/ - if (copy_from_user(obd_jobid_var, buffer, count)) - return -EFAULT; + memcpy(obd_jobid_var, buffer, count); /* Trim the trailing '\n' if any */ if (obd_jobid_var[count - 1] == '\n') @@ -299,23 +293,21 @@ static ssize_t obd_proc_jobid_var_seq_write(struct file *file, return count; } -LPROC_SEQ_FOPS(obd_proc_jobid_var); -static int obd_proc_jobid_name_seq_show(struct seq_file *m, void *v) +static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - seq_printf(m, "%s\n", obd_jobid_var); - return 0; + return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_node); } -static ssize_t obd_proc_jobid_name_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) +static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, + size_t count) { if (!count || count > JOBSTATS_JOBID_SIZE) return -EINVAL; - if (copy_from_user(obd_jobid_node, buffer, count)) - return -EFAULT; + memcpy(obd_jobid_node, buffer, count); obd_jobid_node[count] = 0; @@ -325,20 +317,25 @@ static ssize_t obd_proc_jobid_name_seq_write(struct file *file, return count; } -LPROC_SEQ_FOPS(obd_proc_jobid_name); +#if defined(CONFIG_PROC_FS) /* Root for /proc/fs/lustre */ struct proc_dir_entry *proc_lustre_root = NULL; EXPORT_SYMBOL(proc_lustre_root); -struct lprocfs_vars lprocfs_base[] = { - { "version", &obd_proc_version_fops }, - { "pinger", &obd_proc_pinger_fops }, - { "health_check", &obd_proc_health_fops }, - { "jobid_var", &obd_proc_jobid_var_fops }, - { .name = "jobid_name", - .fops = &obd_proc_jobid_name_fops}, - { NULL } +LUSTRE_RO_ATTR(version); +LUSTRE_RO_ATTR(pinger); +LUSTRE_RO_ATTR(health); +LUSTRE_RW_ATTR(jobid_var); +LUSTRE_RW_ATTR(jobid_name); + +static struct attribute *lustre_attrs[] = { + &lustre_attr_version.attr, + &lustre_attr_pinger.attr, + &lustre_attr_health.attr, + &lustre_attr_jobid_name.attr, + &lustre_attr_jobid_var.attr, + NULL, }; static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos) @@ -419,15 +416,34 @@ struct file_operations obd_device_list_fops = { .release = seq_release, }; +struct kobject *lustre_kobj; +EXPORT_SYMBOL_GPL(lustre_kobj); + +static struct attribute_group lustre_attr_group = { + .attrs = lustre_attrs, +}; + int class_procfs_init(void) { int rc = 0; + lustre_kobj = kobject_create_and_add("lustre", fs_kobj); + if (lustre_kobj == NULL) + goto out; + + /* Create the files associated with this kobject */ + rc = sysfs_create_group(lustre_kobj, &lustre_attr_group); + if (rc) { + kobject_put(lustre_kobj); + goto out; + } + proc_lustre_root = lprocfs_register("fs/lustre", NULL, - lprocfs_base, NULL); + NULL, NULL); if (IS_ERR(proc_lustre_root)) { rc = PTR_ERR(proc_lustre_root); proc_lustre_root = NULL; + kobject_put(lustre_kobj); goto out; } @@ -444,6 +460,9 @@ int class_procfs_clean(void) if (proc_lustre_root) { lprocfs_remove(&proc_lustre_root); } + + kobject_put(lustre_kobj); + return 0; } #endif /* CONFIG_PROC_FS */ diff --git a/drivers/staging/lustre/sysfs-fs-lustre b/drivers/staging/lustre/sysfs-fs-lustre new file mode 100644 index 000000000000..df90a1b63e1a --- /dev/null +++ b/drivers/staging/lustre/sysfs-fs-lustre @@ -0,0 +1,41 @@ +What: /sys/fs/lustre/version +Date: May 2015 +Contact: "Oleg Drokin" +Description: + Shows current running lustre version. + +What: /sys/fs/lustre/pinger +Date: May 2015 +Contact: "Oleg Drokin" +Description: + Shows if the lustre module has pinger support. + "on" means yes and "off" means no. + +What: /sys/fs/lustre/health +Date: May 2015 +Contact: "Oleg Drokin" +Description: + Shows whenever current system state believed to be "healthy", + "NOT HEALTHY", or "LBUG" whenever lustre has experienced + an internal assertion failure + +What: /sys/fs/lustre/jobid_name +Date: May 2015 +Contact: "Oleg Drokin" +Description: + Currently running job "name" for this node to be transferred + to Lustre servers for purposes of QoS and statistics gathering. + Writing into this file will change the name, reading outputs + currently set value. + +What: /sys/fs/lustre/jobid_var +Date: May 2015 +Contact: "Oleg Drokin" +Description: + Control file for lustre "jobstats" functionality, write new + value from the list below to change the mode: + disable - disable job name reporting to the servers (default) + procname_uid - form the job name as the current running + command name and pid with a dot in between + e.g. dd.1253 + nodelocal - use jobid_name value from above. -- 2.20.1