target: Add target_core_backend_configfs.h helper macros
authorNicholas Bellinger <nab@linux-iscsi.org>
Fri, 28 Nov 2014 02:57:27 +0000 (18:57 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 2 Dec 2014 05:35:40 +0000 (21:35 -0800)
This patch adds a number of configfs e-attr macros following
what existing target_core_configfs.c code does for internal
target_backend_dev_attrib setup, and similar to how target
fabric drivers allow for external config_item_type + cit->ct_attrs.
assignment.

This is useful for backend drivers like PSCSI who need to only
expose a small subset of device attributes, while still retaining
a default list of attributes for other backend drivers like
IBLOCK, FILEIO, RAMDISK, and TCMU.

Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
include/target/target_core_backend_configfs.h [new file with mode: 0644]

diff --git a/include/target/target_core_backend_configfs.h b/include/target/target_core_backend_configfs.h
new file mode 100644 (file)
index 0000000..f91935b
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef TARGET_CORE_BACKEND_CONFIGFS_H
+#define TARGET_CORE_BACKEND_CONFIGFS_H
+
+#include <target/configfs_macros.h>
+
+#define DEF_TB_DEV_ATTRIB_SHOW(_backend, _name)                                \
+static ssize_t _backend##_dev_show_attr_##_name(                       \
+       struct se_dev_attrib *da,                                       \
+       char *page)                                                     \
+{                                                                      \
+       return snprintf(page, PAGE_SIZE, "%u\n",                        \
+                       (u32)da->da_dev->dev_attrib._name);             \
+}
+
+#define DEF_TB_DEV_ATTRIB_STORE(_backend, _name)                       \
+static ssize_t _backend##_dev_store_attr_##_name(                      \
+       struct se_dev_attrib *da,                                       \
+       const char *page,                                               \
+       size_t count)                                                   \
+{                                                                      \
+       unsigned long val;                                              \
+       int ret;                                                        \
+                                                                       \
+       ret = kstrtoul(page, 0, &val);                                  \
+       if (ret < 0) {                                                  \
+               pr_err("kstrtoul() failed with ret: %d\n", ret);        \
+               return -EINVAL;                                         \
+       }                                                               \
+       ret = se_dev_set_##_name(da->da_dev, (u32)val);                 \
+                                                                       \
+       return (!ret) ? count : -EINVAL;                                \
+}
+
+#define DEF_TB_DEV_ATTRIB(_backend, _name)                             \
+DEF_TB_DEV_ATTRIB_SHOW(_backend, _name);                               \
+DEF_TB_DEV_ATTRIB_STORE(_backend, _name);
+
+#define DEF_TB_DEV_ATTRIB_RO(_backend, name)                           \
+DEF_TB_DEV_ATTRIB_SHOW(_backend, name);
+
+CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib, se_dev_attrib);
+#define TB_DEV_ATTR(_backend, _name, _mode)                            \
+static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \
+               __CONFIGFS_EATTR(_name, _mode,                          \
+               _backend##_dev_show_attr_##_name,                       \
+               _backend##_dev_store_attr_##_name);
+
+#define TB_DEV_ATTR_RO(_backend, _name)                                                \
+static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \
+       __CONFIGFS_EATTR_RO(_name,                                      \
+       _backend##_dev_show_attr_##_name);
+
+#endif /* TARGET_CORE_BACKEND_CONFIGFS_H */