debugfs currently can not create attributes that set/get
atomic_long_t values.

This patch adds support for this through a new
debugfs_create_atomic_long_t() function.

Signed-off-by: Ganesh Mahendran <[email protected]>
---
 fs/debugfs/file.c       |   45 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/debugfs.h |    2 ++
 2 files changed, 47 insertions(+)

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 76c08c2..65a1b53 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -446,6 +446,51 @@ struct dentry *debugfs_create_atomic_t(const char *name, 
umode_t mode,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
 
+static int debugfs_atomic_long_t_set(void *data, u64 val)
+{
+       atomic_long_set((atomic_long_t *)data, val);
+       return 0;
+}
+static int debugfs_atomic_long_t_get(void *data, u64 *val)
+{
+       *val = atomic_long_read((atomic_long_t *)data);
+       return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_long_t, debugfs_atomic_long_t_get,
+                       debugfs_atomic_long_t_set, "%lld\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_long_t_ro, debugfs_atomic_long_t_get,
+                       NULL, "%lld\n");
+DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_long_t_wo, NULL, debugfs_atomic_long_t_set,
+                       "%lld\n");
+
+/**
+ * debugfs_create_atomic_long_t - create a debugfs file that is used to read 
and
+ * write an atomic_long_t value
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this parameter is %NULL, then the
+ *          file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ *         from.
+ */
+struct dentry *debugfs_create_atomic_long_t(const char *name, umode_t mode,
+                                struct dentry *parent, atomic_long_t *value)
+{
+       /* if there are no write bits set, make read only */
+       if (!(mode & S_IWUGO))
+               return debugfs_create_file(name, mode, parent, value,
+                                       &fops_atomic_long_t_ro);
+       /* if there are no read bits set, make write only */
+       if (!(mode & S_IRUGO))
+               return debugfs_create_file(name, mode, parent, value,
+                                       &fops_atomic_long_t_wo);
+
+       return debugfs_create_file(name, mode, parent, value,
+                                       &fops_atomic_long_t);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_atomic_long_t);
+
 static ssize_t read_file_bool(struct file *file, char __user *user_buf,
                              size_t count, loff_t *ppos)
 {
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 4d0b4d1..b759231 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -81,6 +81,8 @@ struct dentry *debugfs_create_size_t(const char *name, 
umode_t mode,
                                     struct dentry *parent, size_t *value);
 struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
                                     struct dentry *parent, atomic_t *value);
+struct dentry *debugfs_create_atomic_long_t(const char *name, umode_t mode,
+                                struct dentry *parent, atomic_long_t *value);
 struct dentry *debugfs_create_bool(const char *name, umode_t mode,
                                  struct dentry *parent, u32 *value);
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to