Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

debugfs: add get/set for atomic types

debugfs currently lack the ability to create attributes
that set/get atomic_t values.

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

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Acked-by: Rik van Riel <riel@redhat.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Seth Jennings and committed by
Greg Kroah-Hartman
3a76e5e0 49936322

+44 -21
+42
fs/debugfs/file.c
··· 21 21 #include <linux/debugfs.h> 22 22 #include <linux/io.h> 23 23 #include <linux/slab.h> 24 + #include <linux/atomic.h> 24 25 25 26 static ssize_t default_read_file(struct file *file, char __user *buf, 26 27 size_t count, loff_t *ppos) ··· 404 403 } 405 404 EXPORT_SYMBOL_GPL(debugfs_create_size_t); 406 405 406 + static int debugfs_atomic_t_set(void *data, u64 val) 407 + { 408 + atomic_set((atomic_t *)data, val); 409 + return 0; 410 + } 411 + static int debugfs_atomic_t_get(void *data, u64 *val) 412 + { 413 + *val = atomic_read((atomic_t *)data); 414 + return 0; 415 + } 416 + DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, 417 + debugfs_atomic_t_set, "%lld\n"); 418 + DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, "%lld\n"); 419 + DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, "%lld\n"); 420 + 421 + /** 422 + * debugfs_create_atomic_t - create a debugfs file that is used to read and 423 + * write an atomic_t value 424 + * @name: a pointer to a string containing the name of the file to create. 425 + * @mode: the permission that the file should have 426 + * @parent: a pointer to the parent dentry for this file. This should be a 427 + * directory dentry if set. If this parameter is %NULL, then the 428 + * file will be created in the root of the debugfs filesystem. 429 + * @value: a pointer to the variable that the file should read to and write 430 + * from. 431 + */ 432 + struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode, 433 + struct dentry *parent, atomic_t *value) 434 + { 435 + /* if there are no write bits set, make read only */ 436 + if (!(mode & S_IWUGO)) 437 + return debugfs_create_file(name, mode, parent, value, 438 + &fops_atomic_t_ro); 439 + /* if there are no read bits set, make write only */ 440 + if (!(mode & S_IRUGO)) 441 + return debugfs_create_file(name, mode, parent, value, 442 + &fops_atomic_t_wo); 443 + 444 + return debugfs_create_file(name, mode, parent, value, &fops_atomic_t); 445 + } 446 + EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); 407 447 408 448 static ssize_t read_file_bool(struct file *file, char __user *user_buf, 409 449 size_t count, loff_t *ppos)
+2
include/linux/debugfs.h
··· 79 79 struct dentry *parent, u64 *value); 80 80 struct dentry *debugfs_create_size_t(const char *name, umode_t mode, 81 81 struct dentry *parent, size_t *value); 82 + struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode, 83 + struct dentry *parent, atomic_t *value); 82 84 struct dentry *debugfs_create_bool(const char *name, umode_t mode, 83 85 struct dentry *parent, u32 *value); 84 86
-21
lib/fault-inject.c
··· 182 182 183 183 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ 184 184 185 - static int debugfs_atomic_t_set(void *data, u64 val) 186 - { 187 - atomic_set((atomic_t *)data, val); 188 - return 0; 189 - } 190 - 191 - static int debugfs_atomic_t_get(void *data, u64 *val) 192 - { 193 - *val = atomic_read((atomic_t *)data); 194 - return 0; 195 - } 196 - 197 - DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, 198 - debugfs_atomic_t_set, "%lld\n"); 199 - 200 - static struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode, 201 - struct dentry *parent, atomic_t *value) 202 - { 203 - return debugfs_create_file(name, mode, parent, value, &fops_atomic_t); 204 - } 205 - 206 185 struct dentry *fault_create_debugfs_attr(const char *name, 207 186 struct dentry *parent, struct fault_attr *attr) 208 187 {