1 #ifndef _BCACHE_SYSFS_H_
2 #define _BCACHE_SYSFS_H_
7 struct kobj_type type ## _ktype = { \
8 .release = type ## _release, \
9 .sysfs_ops = &((const struct sysfs_ops) { \
10 .show = type ## _show, \
11 .store = type ## _store \
13 .default_attrs = type ## _files \
17 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
21 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
22 const char *buf, size_t size) \
24 #define STORE_LOCKED(fn) \
28 mutex_lock(&bch_register_lock); \
29 ret = __ ## fn ## _store(kobj, attr, buf, size); \
30 mutex_unlock(&bch_register_lock); \
34 #define __sysfs_attribute(_name, _mode) \
35 static struct attribute sysfs_##_name = \
36 { .name = #_name, .mode = _mode }
38 #define write_attribute(n) __sysfs_attribute(n, S_IWUSR)
39 #define read_attribute(n) __sysfs_attribute(n, S_IRUGO)
40 #define rw_attribute(n) __sysfs_attribute(n, S_IRUGO|S_IWUSR)
42 #define sysfs_printf(file, fmt, ...) \
44 if (attr == &sysfs_ ## file) \
45 return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__); \
48 #define sysfs_print(file, var) \
50 if (attr == &sysfs_ ## file) \
51 return snprint(buf, PAGE_SIZE, var); \
54 #define sysfs_hprint(file, val) \
56 if (attr == &sysfs_ ## file) { \
57 ssize_t ret = bch_hprint(buf, val); \
63 #define var_printf(_var, fmt) sysfs_printf(_var, fmt, var(_var))
64 #define var_print(_var) sysfs_print(_var, var(_var))
65 #define var_hprint(_var) sysfs_hprint(_var, var(_var))
67 #define sysfs_strtoul(file, var) \
69 if (attr == &sysfs_ ## file) \
70 return strtoul_safe(buf, var) ?: (ssize_t) size; \
73 #define sysfs_strtoul_clamp(file, var, min, max) \
75 if (attr == &sysfs_ ## file) \
76 return strtoul_safe_clamp(buf, var, min, max) \
80 #define strtoul_or_return(cp) \
83 int _r = kstrtoul(cp, 10, &_v); \
89 #define strtoul_restrict_or_return(cp, min, max) \
91 unsigned long __v = 0; \
92 int _r = strtoul_safe_restrict(cp, __v, min, max); \
98 #define strtoi_h_or_return(cp) \
101 int _r = strtoi_h(cp, &_v); \
107 #define sysfs_hatoi(file, var) \
109 if (attr == &sysfs_ ## file) \
110 return strtoi_h(buf, &var) ?: (ssize_t) size; \
113 #endif /* _BCACHE_SYSFS_H_ */