summaryrefslogtreecommitdiff
path: root/include/linux/configfs.h
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-10-03 15:32:37 +0200
committerNicholas Bellinger <nab@linux-iscsi.org>2015-10-13 22:08:43 -0700
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 {
const char *ca_name;
struct module *ca_owner;
umode_t ca_mode;
+ ssize_t (*show)(struct config_item *, char *);
+ ssize_t (*store)(struct config_item *, const char *, size_t);
};
+#define CONFIGFS_ATTR(_pfx, _name) \
+static struct configfs_attribute _pfx##attr_##_name = { \
+ .ca_name = __stringify(_name), \
+ .ca_mode = S_IRUGO | S_IWUSR, \
+ .ca_owner = THIS_MODULE, \
+ .show = _pfx##_name##_show, \
+ .store = _pfx##_name##_store, \
+}
+
+#define CONFIGFS_ATTR_RO(_pfx, _name) \
+static struct configfs_attribute _pfx##attr_##_name = { \
+ .ca_name = __stringify(_name), \
+ .ca_mode = S_IRUGO, \
+ .ca_owner = THIS_MODULE, \
+ .show = _pfx##_name##_show, \
+}
+
+#define CONFIGFS_ATTR_WO(_pfx, _name) \
+static struct configfs_attribute _pfx##attr_##_name = { \
+ .ca_name = __stringify(_name), \
+ .ca_mode = S_IWUSR, \
+ .ca_owner = THIS_MODULE, \
+ .store = _pfx##_name##_store, \
+}
+
/*
* Users often need to create attribute structures for their configurable
* attributes, containing a configfs_attribute member and function pointers