aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/configfs.h
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-10-03 09:32:37 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2015-10-14 01:08:43 -0400
commit870823e629ea194e6cf8e82a9694ac62cad49512 (patch)
treeb48ab62284a125096e42d6628850c7a8e4629aa7 /include/linux/configfs.h
parent6ff33f3902c3b1c5d0db6b1e2c70b6d76fba357f (diff)
configfs: add show and store methods to struct configfs_attribute
Add methods to struct configfs_attribute to directly show and store attributes without adding boilerplate code to every user. In addition to the methods this also adds 3 helper macros to define read/write, read-only and write-only attributes with a single line of code. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Nicholas Bellinger <nab@linux-iscsi.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'include/linux/configfs.h')
-rw-r--r--include/linux/configfs.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index 63a36e89d0eb..85e9956a86de 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -125,8 +125,35 @@ struct configfs_attribute {
125 const char *ca_name; 125 const char *ca_name;
126 struct module *ca_owner; 126 struct module *ca_owner;
127 umode_t ca_mode; 127 umode_t ca_mode;
128 ssize_t (*show)(struct config_item *, char *);
129 ssize_t (*store)(struct config_item *, const char *, size_t);
128}; 130};
129 131
132#define CONFIGFS_ATTR(_pfx, _name) \
133static struct configfs_attribute _pfx##attr_##_name = { \
134 .ca_name = __stringify(_name), \
135 .ca_mode = S_IRUGO | S_IWUSR, \
136 .ca_owner = THIS_MODULE, \
137 .show = _pfx##_name##_show, \
138 .store = _pfx##_name##_store, \
139}
140
141#define CONFIGFS_ATTR_RO(_pfx, _name) \
142static struct configfs_attribute _pfx##attr_##_name = { \
143 .ca_name = __stringify(_name), \
144 .ca_mode = S_IRUGO, \
145 .ca_owner = THIS_MODULE, \
146 .show = _pfx##_name##_show, \
147}
148
149#define CONFIGFS_ATTR_WO(_pfx, _name) \
150static struct configfs_attribute _pfx##attr_##_name = { \
151 .ca_name = __stringify(_name), \
152 .ca_mode = S_IWUSR, \
153 .ca_owner = THIS_MODULE, \
154 .store = _pfx##_name##_store, \
155}
156
130/* 157/*
131 * Users often need to create attribute structures for their configurable 158 * Users often need to create attribute structures for their configurable
132 * attributes, containing a configfs_attribute member and function pointers 159 * attributes, containing a configfs_attribute member and function pointers