Whamcloud - gitweb
LU-8066 obd: Generic helpers for sysfs 09/22209/3
authorOleg Drokin <oleg.drokin@intel.com>
Thu, 27 Oct 2016 14:43:49 +0000 (10:43 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 1 Jan 2017 02:00:19 +0000 (02:00 +0000)
Add generic helpers to allow displaying of lustre-specific values
in /sys/fs/lustre

except devices, for now.

Linux-commit : 5e66f70e963e4ba2266071343f5a153c7db4327b

Change-Id: Idfbf419d8218546463b993a8031ef00609f8dce9
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/22209
Tested-by: Jenkins
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lprocfs_status.h
lustre/obdclass/lprocfs_status.c

index beba078..df2c0bf 100644 (file)
@@ -715,6 +715,27 @@ static const struct file_operations name##_fops = {                        \
                .release = lprocfs_single_release,                      \
        };
 
+struct lustre_attr {
+       struct attribute attr;
+       ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
+                       char *buf);
+       ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
+                        const char *buf, size_t len);
+};
+
+#define LUSTRE_ATTR(name, mode, show, store) \
+static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
+
+#define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
+#define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
+
+ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
+                        char *buf);
+ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
+                         const char *buf, size_t len);
+
+extern const struct sysfs_ops lustre_sysfs_ops;
+
 /* lproc_ptlrpc.c */
 struct ptlrpc_request;
 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
index 70fb906..c9b4711 100644 (file)
@@ -2174,6 +2174,30 @@ void lprocfs_oh_clear(struct obd_histogram *oh)
 }
 EXPORT_SYMBOL(lprocfs_oh_clear);
 
+ssize_t lustre_attr_show(struct kobject *kobj,
+                        struct attribute *attr, char *buf)
+{
+       struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
+
+       return a->show ? a->show(kobj, attr, buf) : 0;
+}
+EXPORT_SYMBOL_GPL(lustre_attr_show);
+
+ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
+                         const char *buf, size_t len)
+{
+       struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
+
+       return a->store ? a->store(kobj, attr, buf, len) : len;
+}
+EXPORT_SYMBOL_GPL(lustre_attr_store);
+
+const struct sysfs_ops lustre_sysfs_ops = {
+       .show  = lustre_attr_show,
+       .store = lustre_attr_store,
+};
+EXPORT_SYMBOL_GPL(lustre_sysfs_ops);
+
 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
                                     int count, int *eof, void *data)
 {