Add initial configfs support for IIO
Subsystems (5)
v6 cover Add initial configfs support for IIO
This patchset introduces IIO software triggers, offers a way of configuring them via configfs and adds the IIO hrtimer based interrupt source to be used with software triggers.
The arhitecture is now split in 3 parts, to remove all IIO trigger specific parts from IIO configfs core:
(1) IIO software triggers - are independent of configfs.
(2) IIO configfs - offers a generic way of creating IIO objects. So far we can create software triggers.
(3) IIO hrtimer trigger - is the first interrupt source for software triggers (with syfs to follow). Each trigger type can implement its own set of attributes.
Changes since v5: (after Lars comments)
* the most important change is that we moved sampling_frequency attribute from configfs to trigger's directory in /sys.
* couple of const added to strings
* documentation to public API in sw_trigger.h
* replace pr_err with WARN_ONCE in trigger_make_group to avoid spamming kernel log, but without leaving user clueless in case of errors.
* we still need to decide if we get a real gain by adding min/max limits for sampling frequency in /config dir. Anyhow, this can be done in a later patch.
* fix race in hrtimer_remove
Changes since v4:
* patch 1/4
- fixed "new line" nit in industrialio-sw-trigger.c
- added license header in sw_trigger.ho
* patch 2/4
- none
* patch 3/4
- none
* patch 4/4
- removed "Further work" chapter in iio_configfs.txt
- added configfs-iio file in Documentation/ABI/testing
Daniel Baluta (4):
iio: core: Introduce IIO software triggers
iio: core: Introduce IIO configfs support
iio: trigger: Introduce IIO hrtimer based trigger
iio: Documentation: Add IIO configfs documentation
Documentation/ABI/testing/configfs-iio | 20 ++++ Documentation/iio/iio_configfs.txt | 58 ++++++++++ drivers/iio/Kconfig | 16 +++ drivers/iio/Makefile | 2 + drivers/iio/industrialio-configfs.c | 117 ++++++++++++++++++++ drivers/iio/industrialio-sw-trigger.c | 115 +++++++++++++++++++ drivers/iio/trigger/Kconfig | 10 ++ drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 194 +++++++++++++++++++++++++++++++++ include/linux/iio/sw_trigger.h | 85 +++++++++++++++ 10 files changed, 619 insertions(+) create mode 100644 Documentation/ABI/testing/configfs-iio create mode 100644 Documentation/iio/iio_configfs.txt create mode 100644 drivers/iio/industrialio-configfs.c create mode 100644 drivers/iio/industrialio-sw-trigger.c create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c create mode 100644 include/linux/iio/sw_trigger.h
Signature · 1 line
1.9.1
PATCH v6 1/4 iio: core: Introduce IIO software triggers
A software trigger associates an IIO device trigger with a software interrupt source (e.g: timer, sysfs). This patch adds the generic infrastructure for handling software triggers.
Software interrupts sources are kept in a iio_trigger_types_list and registered separately when the associated kernel module is loaded.
Software triggers can be created directly from drivers or from user space via configfs interface.
--- drivers/iio/Kconfig | 8 +++ drivers/iio/Makefile | 1 + drivers/iio/industrialio-sw-trigger.c | 115 ++++++++++++++++++++++++++++++++++ include/linux/iio/sw_trigger.h | 58 +++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 drivers/iio/industrialio-sw-trigger.c create mode 100644 include/linux/iio/sw_trigger.h
drivers/iio/Kconfig +8 -0
@@ -58,6 +58,14 @@ config IIO_CONSUMERS_PER_TRIGGER This value controls the maximum number of consumers that a given trigger may handle. Default is 2. +config IIO_SW_TRIGGER + bool "Enable software triggers support" + depends on IIO_TRIGGER + help + Provides IIO core support for software triggers. A software + trigger can be created via configfs or directly by a driver + using the API provided. + source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/amplifiers/Kconfig"
drivers/iio/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o +industrialio-$(CONFIG_IIO_SW_TRIGGER) += industrialio-sw-trigger.o industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
drivers/iio/industrialio-sw-trigger.c new file +115 -0
115 lines not on this page · raw message
include/linux/iio/sw_trigger.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v6 2/4 iio: core: Introduce IIO configfs support
In reply to Daniel BalutaThis creates an IIO configfs subystem named "iio", with a default "triggers" group.
Triggers group is used for handling software triggers. To create a new software trigger one must create a directory inside the trigger directory.
Software trigger name MUST follow the following convention:
* <trigger-type>-<trigger-name>
Where:
* <trigger_type>, specifies the interrupt source (e.g: hrtimer)
* <trigger-name>, specifies the IIO device trigger name
Failing to follow this convention will result in an directory creation error.
E.g, assuming that hrtimer trigger type is registered with IIO software trigger core:
$ mkdir /config/iio/triggers/hrtimer-instance1
--- drivers/iio/Kconfig | 8 +++ drivers/iio/Makefile | 1 + drivers/iio/industrialio-configfs.c | 117 ++++++++++++++++++++++++++++++++++++ include/linux/iio/sw_trigger.h | 27 +++++++++ 4 files changed, 153 insertions(+) create mode 100644 drivers/iio/industrialio-configfs.c
drivers/iio/Kconfig +8 -0
@@ -18,6 +18,14 @@ config IIO_BUFFER Provide core support for various buffer based data acquisition methods. +config IIO_CONFIGFS + tristate "Enable IIO configuration via configfs" + select CONFIGFS_FS + help + This allows configuring various IIO bits through configfs + (e.g. software triggers). For more info see + Documentation/iio/iio_configfs.txt. + if IIO_BUFFER config IIO_BUFFER_CB
drivers/iio/Makefile +1 -0
@@ -10,6 +10,7 @@ industrialio-$(CONFIG_IIO_SW_TRIGGER) += industrialio-sw-trigger.o industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o +obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o obj-y += accel/
drivers/iio/industrialio-configfs.c new file +117 -0
117 lines not on this page · raw message
include/linux/iio/sw_trigger.h +27 -0
@@ -14,6 +14,7 @@#include <linux/module.h> #include <linux/device.h> #include <linux/iio/iio.h> +#include <linux/configfs.h> #define module_iio_sw_trigger_driver (__iio_sw_trigger_type) \ module_driver(__iio_sw_trigger_type, iio_register_sw_trigger_type, \
@@ -31,6 +32,9 @@ struct iio_sw_trigger_type {struct iio_sw_trigger {struct iio_trigger *trigger;struct iio_sw_trigger_type *trigger_type; +#ifdef CONFIG_CONFIGFS_FS +struct config_group group; +#endif };struct iio_sw_trigger_ops {
@@ -55,4 +59,27 @@ int iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *tt);struct iio_sw_trigger *iio_sw_trigger_create (const char *,const char *);void iio_sw_trigger_destroy (struct iio_sw_trigger *); +#ifdef CONFIG_CONFIGFS_FS +static inline +struct iio_sw_trigger *to_iio_sw_trigger (struct config_item *item) +{ + return container_of(to_config_group(item), struct iio_sw_trigger, + group); +} + +static inline +void iio_config_group_init_type_name (struct config_group *group, +const char *name, +struct config_item_type *type) +{ +config_group_init_type_name (group, name, type); +} +#else +static inline +void iio_config_group_init_type_name (struct config_group *group, +const char *name, +struct config_item_type *type) +{ } +#endif +#endif /* __IIO_SW_TRIGGER */
Signature · 1 line
1.9.1
PATCH v6 3/4 iio: trigger: Introduce IIO hrtimer based trigger
In reply to Daniel BalutaThis patch registers a new IIO software trigger interrupt source based on high resolution timers.
Notice that if configfs is enabled we create sampling_frequency attribute allowing users to change hrtimer period (1/sampling_frequency).
The IIO hrtimer trigger has a long history, this patch is based on an older version from Marten and Lars-Peter.
--- drivers/iio/trigger/Kconfig | 10 ++ drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 194 +++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c
drivers/iio/trigger/Kconfig +10 -0
@@ -5,6 +5,16 @@ menu "Triggers - standalone" +config IIO_HRTIMER_TRIGGER + tristate "High resolution timer trigger" + select IIO_SW_TRIGGER + help + Provides a frequency based IIO trigger using high resolution + timers as interrupt source. + + To compile this driver as a module, choose M here: the + module will be called iio-trig-hrtimer. + config IIO_INTERRUPT_TRIGGER tristate "Generic interrupt trigger" help
drivers/iio/trigger/Makefile +2 -0
@@ -3,5 +3,7 @@ # # When adding new entries keep the list in alphabetical order + +obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o
drivers/iio/trigger/iio-trig-hrtimer.c new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v6 4/4 iio: Documentation: Add IIO configfs documentation
In reply to Daniel Baluta--- Documentation/ABI/testing/configfs-iio | 20 ++++++++++++ Documentation/iio/iio_configfs.txt | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Documentation/ABI/testing/configfs-iio create mode 100644 Documentation/iio/iio_configfs.txt
Documentation/ABI/testing/configfs-iio new file +20 -0
@@ -0,0 +1,20 @@ +What: /config/iio +Date: May 2015 +KernelVersion: 4.2 +Contact: [email protected] +Description: + This represents Industrial IO configuration entry point + directory. It contains sub-groups corresponding to IIO + objects. + +What: /config/iio/triggers +Date: May 2015 +KernelVersion: 4.2 +Description: + Industrial IO software triggers directory. + +What: /config/iio/triggers/hrtimer-name +Date: May 2015 +KernelVersion: 4.2 +Description: + High resolution timer instance.
Documentation/iio/iio_configfs.txt new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
1.9.1
Jonathan Cameron
maintainerQuoted 7 lines · Daniel Baluta
This patchset introduces IIO software triggers, offers a way of configuring them via configfs and adds the IIO hrtimer based interrupt source to be used with software triggers.
The arhitecture is now split in 3 parts, to remove all IIO trigger specific parts from IIO configfs core:
Quoted 6 lines
(1) IIO software triggers - are independent of configfs.
(2) IIO configfs - offers a generic way of creating IIO objects. So far we can create software triggers.
(3) IIO hrtimer trigger - is the first interrupt source for software triggers (with syfs to follow). Each trigger type can implement its own set of attributes.
I'm happy with the whole series, but given Lars' involvement would like to give him a bit of time for another look / reviewed-by / acked-by or similar.
Obviously comments from anyone else welcome as well.
Now all we need to do is all the other uses for configfs that we've discussed in earlier threads :) Easy really ;)
Quoted 49 lines
Changes since v5: (after Lars comments)
* the most important change is that we movedsampling_frequencyattribute from configfs to trigger's directory in /sys.
* couple of const added to strings
* documentation to public API insw_trigger.h
* replacepr_errwithWARN_ONCEintrigger_make_groupto avoid spamming kernel log, but without leaving user clueless in case of errors.
* we still need to decide if we get a real gain by adding min/max limits for sampling frequency in /config dir. Anyhow, this can be done in a later patch.
* fix race inhrtimer_removeChanges since v4:
* patch 1/4
- fixed "new line" nit inindustrialio-sw-trigger.c
- added license header in sw_trigger.ho
* patch 2/4
- none
* patch 3/4
- none
* patch 4/4
- removed "Further work" chapter in iio_configfs.txt
- added configfs-iio file inDocumentation/ABI/testingDaniel Baluta (4):
iio: core: Introduce IIO software triggers
iio: core: Introduce IIO configfs support
iio: trigger: Introduce IIO hrtimer based trigger
iio: Documentation: Add IIO configfs documentationDocumentation/ABI/testing/configfs-iio | 20 ++++ Documentation/iio/iio_configfs.txt | 58 ++++++++++ drivers/iio/Kconfig | 16 +++ drivers/iio/Makefile | 2 + drivers/iio/industrialio-configfs.c | 117 ++++++++++++++++++++ drivers/iio/industrialio-sw-trigger.c | 115 +++++++++++++++++++ drivers/iio/trigger/Kconfig | 10 ++ drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 194 +++++++++++++++++++++++++++++++++ include/linux/iio/sw_trigger.h | 85 +++++++++++++++ 10 files changed, 619 insertions(+) create mode 100644 Documentation/ABI/testing/configfs-iio create mode 100644 Documentation/iio/iio_configfs.txt create mode 100644 drivers/iio/industrialio-configfs.c create mode 100644 drivers/iio/industrialio-sw-trigger.c create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c create mode 100644 include/linux/iio/sw_trigger.h
Quoted 14 lines · Jonathan Cameron
Quoted 7 lines · Daniel Baluta
This patchset introduces IIO software triggers, offers a way of configuring them via configfs and adds the IIO hrtimer based interrupt source to be used with software triggers.
The arhitecture is now split in 3 parts, to remove all IIO trigger specific parts from IIO configfs core:
Quoted 6 lines
(1) IIO software triggers - are independent of configfs.
(2) IIO configfs - offers a generic way of creating IIO objects. So far we can create software triggers.
(3) IIO hrtimer trigger - is the first interrupt source for software triggers (with syfs to follow). Each trigger type can implement its own set of attributes.
Quoted 7 lines
I'm happy with the whole series, but given Lars' involvement would like to give him a bit of time for another look / reviewed-by / acked-by or similar.
Obviously comments from anyone else welcome as well.
Now all we need to do is all the other uses for configfs that we've discussed in earlier threads :) Easy really ;)
Agree. :)
The important thing now is to get Acked-by/Reviewed-by on the interface because once accepted this cannot be changed.
For the rest of the code we can send patches later.
Quoted 54 lines
Quoted 40 lines
Changes since v5: (after Lars comments)
* the most important change is that we movedsampling_frequencyattribute from configfs to trigger's directory in /sys.
* couple of const added to strings
* documentation to public API insw_trigger.h
* replacepr_errwithWARN_ONCEintrigger_make_groupto avoid spamming kernel log, but without leaving user clueless in case of errors.
* we still need to decide if we get a real gain by adding min/max limits for sampling frequency in /config dir. Anyhow, this can be done in a later patch.
* fix race inhrtimer_removeChanges since v4:
* patch 1/4
- fixed "new line" nit inindustrialio-sw-trigger.c
- added license header insw_trigger.ho
* patch 2/4
- none
* patch 3/4
- none
* patch 4/4
- removed "Further work" chapter in iio_configfs.txt
- added configfs-iio file inDocumentation/ABI/testingDaniel Baluta (4):
iio: core: Introduce IIO software triggers
iio: core: Introduce IIO configfs support
iio: trigger: Introduce IIO hrtimer based trigger
iio: Documentation: Add IIO configfs documentationDocumentation/ABI/testing/configfs-iio | 20 ++++ Documentation/iio/iio_configfs.txt | 58 ++++++++++ drivers/iio/Kconfig | 16 +++ drivers/iio/Makefile | 2 + drivers/iio/industrialio-configfs.c | 117 ++++++++++++++++++++ drivers/iio/industrialio-sw-trigger.c | 115 +++++++++++++++++++ drivers/iio/trigger/Kconfig | 10 ++ drivers/iio/trigger/Makefile | 2 + drivers/iio/trigger/iio-trig-hrtimer.c | 194 +++++++++++++++++++++++++++++++++Quoted 9 lines
include/linux/iio/sw_trigger.h | 85 +++++++++++++++ 10 files changed, 619 insertions(+) create mode 100644 Documentation/ABI/testing/configfs-iio create mode 100644 Documentation/iio/iio_configfs.txt create mode 100644 drivers/iio/industrialio-configfs.c create mode 100644 drivers/iio/industrialio-sw-trigger.c create mode 100644 drivers/iio/trigger/iio-trig-hrtimer.c create mode 100644 include/linux/iio/sw_trigger.h--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
I'd like to go back to the issue of having one folder per trigger type and create triggers for a type in their respective folder.
I'm not convinced that it is an intentional design restriction of configfs that we can't do this, but rather a case of it not being implemented because nobody needed it so far.
See the proof-of-concept patch below. With this we get one sub-folder per trigger type in /config/iio/triggers. It's not complete and doesn't do proper locking yet and also unregister is not yet implemented but it shows the concept how it could be done.
I'm not saying that we definitely should go down that road, but it feels cleaner to me. And another advantage is that it is discoverable which types of triggers are available. Thoughts?
- Lars
--- drivers/iio/industrialio-configfs.c | 43 ++++++++++++++++++----------------- drivers/iio/industrialio-sw-trigger.c | 12 ++++++---- fs/configfs/dir.c | 28 +++++++++++++++++++++-- include/linux/configfs.h | 4 ++++ include/linux/iio/sw_trigger.h | 19 ++++++++++++++++ 5 files changed, 79 insertions(+), 27 deletions(-)
drivers/iio/industrialio-configfs.c +22 -21
@@ -22,27 +22,9 @@static struct config_group *trigger_make_group (struct config_group *group,const char *name) { -char *type_name; -char *trigger_name; -char buf[MAX_NAME_LEN ];struct iio_sw_trigger *t; -snprintf (buf,MAX_NAME_LEN ,"%s" , name); - -/* group name should have the form <trigger-type>-<trigger-name> */ - type_name = buf; - trigger_name =strchr (buf,'-' ); -if (!trigger_name) { -WARN_ONCE (1 ,"Unable to locate '-' in %s. Use <type>-<name>.\n" , - buf); -return ERR_PTR (-EINVAL ); - } - -/* replace - with \0, this nicely separates the two strings */ - *trigger_name ='\0' ; - trigger_name++; - - t =iio_sw_trigger_create (type_name, trigger_name); + t =iio_sw_trigger_create (group->cg_item.ci_name, name);if (IS_ERR (t))return ERR_CAST (t);
@@ -60,13 +42,17 @@ static void trigger_drop_group(struct config_group *group,config_item_put (item); } -static struct configfs_group_operations triggers_ops = { +static struct configfs_group_operations trigger_ops = { .make_group = &trigger_make_group, .drop_item = &trigger_drop_group, }; +static struct config_item_type iio_trigger_group_type = { + .ct_group_ops = &trigger_ops, + .ct_owner =THIS_MODULE , +}; +static struct config_item_type iio_triggers_group_type = { - .ct_group_ops = &triggers_ops, .ct_owner =THIS_MODULE , };
@@ -97,6 +83,21 @@ static struct configfs_subsystem iio_configfs_subsys = { .su_mutex = __MUTEX_INITIALIZER(iio_configfs_subsys.su_mutex), }; +int iio_sw_trigger_type_configs_register (struct iio_sw_trigger_type *tt) +{ +config_group_init_type_name (&tt->group, tt->name, + &iio_trigger_group_type); + +return configfs_register_group (&iio_triggers_group, &tt->group); +} +EXPORT_SYMBOL_GPL (iio_sw_trigger_type_configs_register); + +void iio_sw_trigger_type_configs_unregister (struct iio_sw_trigger_type *tt) +{ +configfs_unregister_group (&tt->group); +} +EXPORT_SYMBOL_GPL (iio_sw_trigger_type_configs_unregister); +static int __init iio_configfs_init (void ) {config_group_init (&iio_triggers_group);
drivers/iio/industrialio-sw-trigger.c +8 -4
@@ -41,10 +41,12 @@ int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t)write_lock (&iio_trigger_types_lock); iter =__iio_find_sw_trigger_type (t->name,strlen (t->name)); -if (iter) +if (iter) { ret = -EBUSY ; -else + }else {list_add_tail (&t->list, &iio_trigger_types_list); +iio_sw_trigger_type_configs_register (t); + }write_unlock (&iio_trigger_types_lock);return ret;
@@ -58,10 +60,12 @@ int iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *t)write_lock (&iio_trigger_types_lock); iter =__iio_find_sw_trigger_type (t->name,strlen (t->name)); -if (!iter) +if (!iter) { ret = -EINVAL ; -else + }else { +iio_sw_trigger_type_configs_unregister (t);list_del (&t->list); + }write_unlock (&iio_trigger_types_lock);return ret;
fs/configfs/dir.c +26 -2
@@ -659,7 +659,7 @@ static void detach_groups(struct config_group *group)* try using vfs_mkdir. Just a thought. */ static int create_default_group (struct config_group *parent_group, -struct config_group *group) +struct config_group *group,struct dentry **dentry) {int ret;struct configfs_dirent *sd;
@@ -679,6 +679,8 @@ static int create_default_group(struct config_group *parent_group,if (!ret) { sd = child->d_fsdata; sd->s_type |=CONFIGFS_USET_DEFAULT ; +if (dentry) + *dentry = child; }else {BUG_ON (child->d_inode);d_drop (child);
@@ -699,7 +701,7 @@ static int populate_groups(struct config_group *group)for (i =0 ; group->default_groups[i]; i++) { new_group = group->default_groups[i]; - ret =create_default_group (group, new_group); + ret =create_default_group (group, new_group,NULL );if (ret) {detach_groups (group);break ;
@@ -1644,6 +1646,28 @@ const struct file_operations configfs_dir_operations = { .iterate = configfs_readdir, }; +int configfs_register_group (struct config_group *parent_group, +struct config_group *group) +{ +struct dentry *dentry; +int ret; + +link_group (parent_group, group); + + ret =create_default_group (parent_group, group, &dentry); +if (ret ==0 ) +configfs_dir_set_ready (dentry->d_fsdata); + +return ret; +} +EXPORT_SYMBOL (configfs_register_group); + +void configfs_unregister_group (struct config_group *group) +{ +/* TODO */ +} +EXPORT_SYMBOL (configfs_unregister_group); +int configfs_register_subsystem (struct configfs_subsystem *subsys) {int err;
include/linux/configfs.h +4 -0
@@ -252,6 +252,10 @@ static inline struct configfs_subsystem *to_configfs_subsystem(struct config_groint configfs_register_subsystem (struct configfs_subsystem *subsys);void configfs_unregister_subsystem (struct configfs_subsystem *subsys); +int configfs_register_group (struct config_group *parent_group, +struct config_group *group); +void configfs_unregister_group (struct config_group *group); +/* These functions can sleep and can alloc with GFP_KERNEL */ /* WARNING: These cannot be called underneath configfs callbacks!! */ int configfs_depend_item (struct configfs_subsystem *subsys,struct config_item *target);
include/linux/iio/sw_trigger.h +19 -0
@@ -27,6 +27,10 @@ struct iio_sw_trigger_type {struct module *owner;const struct iio_sw_trigger_ops *ops;struct list_head list; +#ifdef CONFIG_CONFIGFS_FS +struct config_group group; +#endif + };struct iio_sw_trigger {
@@ -60,6 +64,10 @@ struct iio_sw_trigger *iio_sw_trigger_create(const char *, const char *);void iio_sw_trigger_destroy (struct iio_sw_trigger *);#ifdef CONFIG_CONFIGFS_FS + +int iio_sw_trigger_type_configs_register (struct iio_sw_trigger_type *tt); +void iio_sw_trigger_type_configs_unregister (struct iio_sw_trigger_type *tt); +static inline struct iio_sw_trigger *to_iio_sw_trigger (struct config_item *item) {
@@ -75,6 +83,17 @@ void iio_config_group_init_type_name(struct config_group *group,config_group_init_type_name (group, name, type); }#else +static inline int iio_sw_trigger_type_configs_register ( +struct iio_sw_trigger_type *tt) +{ +return 0 ; +} + +static inline void iio_sw_trigger_type_configs_unregister ( +struct iio_sw_trigger_type *tt) +{ +} + static inline void iio_config_group_init_type_name(struct config_group *group, const char *name,
Signature · 1 line
1.8.0
Jonathan Cameron
maintainerQuoted 9 lines · Lars-Peter Clausen
Hi,
I'd like to go back to the issue of having one folder per trigger type and create triggers for a type in their respective folder.
I'm not convinced that it is an intentional design restriction of configfs that we can't do this, but rather a case of it not being implemented because nobody needed it so far.
Quoted 8 lines
See the proof-of-concept patch below. With this we get one sub-folder per trigger type in /config/iio/triggers. It's not complete and doesn't do proper locking yet and also unregister is not yet implemented but it shows the concept how it could be done.
I'm not saying that we definitely should go down that road, but it feels cleaner to me. And another advantage is that it is discoverable which types of triggers are available. Thoughts?
Nice iff it doesn't break from the intent of configfs. I know both Daniel and I looked for how to do this before taking the non directory based approach that the usbgadget driver took.
What you loose is the possibility for auto probing modules based on trigger naming (equivalent of what the usbgadget driver does). I undecided on whether we would want to do that anyway.
Joel, it's your filesystem. Is doing this acceptable to you?
Quoted 240 lines
- Lars
--- drivers/iio/industrialio-configfs.c | 43 ++++++++++++++++++----------------- drivers/iio/industrialio-sw-trigger.c | 12 ++++++---- fs/configfs/dir.c | 28 +++++++++++++++++++++-- include/linux/configfs.h | 4 ++++ include/linux/iio/sw_trigger.h | 19 ++++++++++++++++ 5 files changed, 79 insertions(+), 27 deletions(-)drivers/iio/industrialio-configfs.c +22
-21@@ -22,27 +22,9 @@static struct config_group *trigger_make_group (struct config_group *group,const char *name) { -char *type_name; -char *trigger_name; -char buf[MAX_NAME_LEN ];struct iio_sw_trigger *t; -snprintf (buf,MAX_NAME_LEN ,"%s" , name); - -/* group name should have the form <trigger-type>-<trigger-name> */ - type_name = buf; - trigger_name =strchr (buf,'-' ); -if (!trigger_name) { -WARN_ONCE (1 ,"Unable to locate '-' in %s. Use <type>-<name>.\n" , - buf); -return ERR_PTR (-EINVAL ); - } - -/* replace - with \0, this nicely separates the two strings */ - *trigger_name ='\0' ; - trigger_name++; - - t =iio_sw_trigger_create (type_name, trigger_name); + t =iio_sw_trigger_create (group->cg_item.ci_name, name);if (IS_ERR (t))return ERR_CAST (t);@@ -60,13 +42,17 @@ static void trigger_drop_group(struct config_group *group,config_item_put (item); } -static struct configfs_group_operations triggers_ops = { +static struct configfs_group_operations trigger_ops = { .make_group = &trigger_make_group, .drop_item = &trigger_drop_group, }; +static struct config_item_type iio_trigger_group_type = { + .ct_group_ops = &trigger_ops, + .ct_owner =THIS_MODULE , +}; +static struct config_item_type iio_triggers_group_type = { - .ct_group_ops = &triggers_ops, .ct_owner =THIS_MODULE , };@@ -97,6 +83,21 @@ static struct configfs_subsystem iio_configfs_subsys = { .su_mutex = __MUTEX_INITIALIZER(iio_configfs_subsys.su_mutex), }; +int iio_sw_trigger_type_configs_register (struct iio_sw_trigger_type *tt) +{ +config_group_init_type_name (&tt->group, tt->name, + &iio_trigger_group_type); + +return configfs_register_group (&iio_triggers_group, &tt->group); +} +EXPORT_SYMBOL_GPL (iio_sw_trigger_type_configs_register); + +void iio_sw_trigger_type_configs_unregister (struct iio_sw_trigger_type *tt) +{ +configfs_unregister_group (&tt->group); +} +EXPORT_SYMBOL_GPL (iio_sw_trigger_type_configs_unregister); +static int __init iio_configfs_init (void ) {config_group_init (&iio_triggers_group);drivers/iio/industrialio-sw-trigger.c +8
-4@@ -41,10 +41,12 @@ int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t)write_lock (&iio_trigger_types_lock); iter =__iio_find_sw_trigger_type (t->name,strlen (t->name)); -if (iter) +if (iter) { ret = -EBUSY ; -else + }else {list_add_tail (&t->list, &iio_trigger_types_list); +iio_sw_trigger_type_configs_register (t); + }write_unlock (&iio_trigger_types_lock);return ret;@@ -58,10 +60,12 @@ int iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *t)write_lock (&iio_trigger_types_lock); iter =__iio_find_sw_trigger_type (t->name,strlen (t->name)); -if (!iter) +if (!iter) { ret = -EINVAL ; -else + }else { +iio_sw_trigger_type_configs_unregister (t);list_del (&t->list); + }write_unlock (&iio_trigger_types_lock);return ret;fs/configfs/dir.c +26
-2@@ -659,7 +659,7 @@ static void detach_groups(struct config_group *group)* try using vfs_mkdir. Just a thought. */ static int create_default_group (struct config_group *parent_group, -struct config_group *group) +struct config_group *group,struct dentry **dentry) {int ret;struct configfs_dirent *sd;@@ -679,6 +679,8 @@ static int create_default_group(struct config_group *parent_group,if (!ret) { sd = child->d_fsdata; sd->s_type |=CONFIGFS_USET_DEFAULT ; +if (dentry) + *dentry = child; }else {BUG_ON (child->d_inode);d_drop (child);@@ -699,7 +701,7 @@ static int populate_groups(struct config_group *group)for (i =0 ; group->default_groups[i]; i++) { new_group = group->default_groups[i]; - ret =create_default_group (group, new_group); + ret =create_default_group (group, new_group,NULL );if (ret) {detach_groups (group);break ;@@ -1644,6 +1646,28 @@ const struct file_operations configfs_dir_operations = { .iterate = configfs_readdir, }; +int configfs_register_group (struct config_group *parent_group, +struct config_group *group) +{ +struct dentry *dentry; +int ret; + +link_group (parent_group, group); + + ret =create_default_group (parent_group, group, &dentry); +if (ret ==0 ) +configfs_dir_set_ready (dentry->d_fsdata); + +return ret; +} +EXPORT_SYMBOL (configfs_register_group); + +void configfs_unregister_group (struct config_group *group) +{ +/* TODO */ +} +EXPORT_SYMBOL (configfs_unregister_group); +int configfs_register_subsystem (struct configfs_subsystem *subsys) {int err;include/linux/configfs.h +4
-0@@ -252,6 +252,10 @@ static inline struct configfs_subsystem *to_configfs_subsystem(struct config_groint configfs_register_subsystem (struct configfs_subsystem *subsys);void configfs_unregister_subsystem (struct configfs_subsystem *subsys); +int configfs_register_group (struct config_group *parent_group, +struct config_group *group); +void configfs_unregister_group (struct config_group *group); +/* These functions can sleep and can alloc with GFP_KERNEL */ /* WARNING: These cannot be called underneath configfs callbacks!! */ int configfs_depend_item (struct configfs_subsystem *subsys,struct config_item *target);include/linux/iio/sw_trigger.h +19
-0@@ -27,6 +27,10 @@ struct iio_sw_trigger_type {struct module *owner;const struct iio_sw_trigger_ops *ops;struct list_head list; +#ifdef CONFIG_CONFIGFS_FS +struct config_group group; +#endif + };struct iio_sw_trigger {@@ -60,6 +64,10 @@ struct iio_sw_trigger *iio_sw_trigger_create(const char *, const char *);void iio_sw_trigger_destroy (struct iio_sw_trigger *);#ifdef CONFIG_CONFIGFS_FS + +int iio_sw_trigger_type_configs_register (struct iio_sw_trigger_type *tt); +void iio_sw_trigger_type_configs_unregister (struct iio_sw_trigger_type *tt); +static inline struct iio_sw_trigger *to_iio_sw_trigger (struct config_item *item) {@@ -75,6 +83,17 @@ void iio_config_group_init_type_name(struct config_group *group,config_group_init_type_name (group, name, type); }#else +static inline int iio_sw_trigger_type_configs_register ( +struct iio_sw_trigger_type *tt) +{ +return 0 ; +} + +static inline void iio_sw_trigger_type_configs_unregister ( +struct iio_sw_trigger_type *tt) +{ +} + static inline void iio_config_group_init_type_name(struct config_group *group, const char *name,
Quoted 18 lines · Jonathan Cameron
Quoted 9 lines · Lars-Peter Clausen
Hi,
I'd like to go back to the issue of having one folder per trigger type and create triggers for a type in their respective folder.
I'm not convinced that it is an intentional design restriction of configfs that we can't do this, but rather a case of it not being implemented because nobody needed it so far.
Quoted 8 lines
See the proof-of-concept patch below. With this we get one sub-folder per trigger type in /config/iio/triggers. It's not complete and doesn't do proper locking yet and also unregister is not yet implemented but it shows the concept how it could be done.
I'm not saying that we definitely should go down that road, but it feels cleaner to me. And another advantage is that it is discoverable which types of triggers are available. Thoughts?
Quoted 7 lines
Nice iff it doesn't break from the intent of configfs. I know both Daniel and I looked for how to do this before taking the non directory based approach that the usbgadget driver took.
What you loose is the possibility for auto probing modules based on trigger naming (equivalent of what the usbgadget driver does). I undecided on whether we would want to do that anyway.
Ok, I will have a closer look.
Quoted 2 lines
Joel, it's your filesystem. Is doing this acceptable to you?
Adding fsdevel and ocfs2 people. Joel seems to be idle for an awful long period of time.
I'm not sure if there is anyone maintaining configfs now :).
Quoted 245 lines
Quoted 230 lines
- Lars
--- drivers/iio/industrialio-configfs.c | 43 ++++++++++++++++++----------------- drivers/iio/industrialio-sw-trigger.c | 12 ++++++---- fs/configfs/dir.c | 28 +++++++++++++++++++++-- include/linux/configfs.h | 4 ++++ include/linux/iio/sw_trigger.h | 19 ++++++++++++++++ 5 files changed, 79 insertions(+), 27 deletions(-)drivers/iio/industrialio-configfs.c +22
-21@@ -22,27 +22,9 @@static struct config_group *trigger_make_group (struct config_group *group,const char *name) { -char *type_name; -char *trigger_name; -char buf[MAX_NAME_LEN ];struct iio_sw_trigger *t; -snprintf (buf,MAX_NAME_LEN ,"%s" , name); - -/* group name should have the form <trigger-type>-<trigger-name> */ - type_name = buf; - trigger_name =strchr (buf,'-' ); -if (!trigger_name) { -WARN_ONCE (1 ,"Unable to locate '-' in %s. Use <type>-<name>.\n" , - buf); -return ERR_PTR (-EINVAL ); - } - -/* replace - with \0, this nicely separates the two strings */ - *trigger_name ='\0' ; - trigger_name++; - - t =iio_sw_trigger_create (type_name, trigger_name); + t =iio_sw_trigger_create (group->cg_item.ci_name, name);if (IS_ERR (t))return ERR_CAST (t);@@ -60,13 +42,17 @@ static void trigger_drop_group(struct config_group *group,config_item_put (item); } -static struct configfs_group_operations triggers_ops = { +static struct configfs_group_operations trigger_ops = { .make_group = &trigger_make_group, .drop_item = &trigger_drop_group, }; +static struct config_item_type iio_trigger_group_type = { + .ct_group_ops = &trigger_ops, + .ct_owner =THIS_MODULE , +}; +static struct config_item_type iio_triggers_group_type = { - .ct_group_ops = &triggers_ops, .ct_owner =THIS_MODULE , };@@ -97,6 +83,21 @@ static struct configfs_subsystem iio_configfs_subsys = { .su_mutex = __MUTEX_INITIALIZER(iio_configfs_subsys.su_mutex), }; +int iio_sw_trigger_type_configs_register (struct iio_sw_trigger_type *tt) +{ +config_group_init_type_name (&tt->group, tt->name, + &iio_trigger_group_type); + +return configfs_register_group (&iio_triggers_group, &tt->group); +} +EXPORT_SYMBOL_GPL (iio_sw_trigger_type_configs_register); + +void iio_sw_trigger_type_configs_unregister (struct iio_sw_trigger_type *tt) +{ +configfs_unregister_group (&tt->group); +} +EXPORT_SYMBOL_GPL (iio_sw_trigger_type_configs_unregister); +static int __init iio_configfs_init (void ) {config_group_init (&iio_triggers_group);drivers/iio/industrialio-sw-trigger.c +8
-4@@ -41,10 +41,12 @@ int iio_register_sw_trigger_type(struct iio_sw_trigger_type *t)write_lock (&iio_trigger_types_lock); iter =__iio_find_sw_trigger_type (t->name,strlen (t->name)); -if (iter) +if (iter) { ret = -EBUSY ; -else + }else {list_add_tail (&t->list, &iio_trigger_types_list); +iio_sw_trigger_type_configs_register (t); + }write_unlock (&iio_trigger_types_lock);return ret;@@ -58,10 +60,12 @@ int iio_unregister_sw_trigger_type(struct iio_sw_trigger_type *t)write_lock (&iio_trigger_types_lock); iter =__iio_find_sw_trigger_type (t->name,strlen (t->name)); -if (!iter) +if (!iter) { ret = -EINVAL ; -else + }else { +iio_sw_trigger_type_configs_unregister (t);list_del (&t->list); + }write_unlock (&iio_trigger_types_lock);return ret;fs/configfs/dir.c +26
-2@@ -659,7 +659,7 @@ static void detach_groups(struct config_group *group)* try using vfs_mkdir. Just a thought. */ static int create_default_group (struct config_group *parent_group, -struct config_group *group) +struct config_group *group,struct dentry **dentry) {int ret;struct configfs_dirent *sd;@@ -679,6 +679,8 @@ static int create_default_group(struct config_group *parent_group,if (!ret) { sd = child->d_fsdata; sd->s_type |=CONFIGFS_USET_DEFAULT ; +if (dentry) + *dentry = child; }else {BUG_ON (child->d_inode);d_drop (child);@@ -699,7 +701,7 @@ static int populate_groups(struct config_group *group)for (i =0 ; group->default_groups[i]; i++) { new_group = group->default_groups[i]; - ret =create_default_group (group, new_group); + ret =create_default_group (group, new_group,NULL );if (ret) {detach_groups (group);break ;@@ -1644,6 +1646,28 @@ const struct file_operations configfs_dir_operations = { .iterate = configfs_readdir, }; +int configfs_register_group (struct config_group *parent_group, +struct config_group *group) +{ +struct dentry *dentry; +int ret; + +link_group (parent_group, group); + + ret =create_default_group (parent_group, group, &dentry); +if (ret ==0 ) +configfs_dir_set_ready (dentry->d_fsdata); + +return ret; +} +EXPORT_SYMBOL (configfs_register_group); + +void configfs_unregister_group (struct config_group *group) +{ +/* TODO */ +} +EXPORT_SYMBOL (configfs_unregister_group); +int configfs_register_subsystem (struct configfs_subsystem *subsys) {int err;include/linux/configfs.h +4
-0@@ -252,6 +252,10 @@ static inline struct configfs_subsystem *to_configfs_subsystem(struct config_groint configfs_register_subsystem (struct configfs_subsystem *subsys);void configfs_unregister_subsystem (struct configfs_subsystem *subsys); +int configfs_register_group (struct config_group *parent_group, +struct config_group *group); +void configfs_unregister_group (struct config_group *group); +/* These functions can sleep and can alloc with GFP_KERNEL */ /* WARNING: These cannot be called underneath configfs callbacks!! */ int configfs_depend_item (struct configfs_subsystem *subsys,struct config_item *target);include/linux/iio/sw_trigger.h +12
-0@@ -27,6 +27,10 @@ struct iio_sw_trigger_type {struct module *owner;const struct iio_sw_trigger_ops *ops;struct list_head list; +#ifdef CONFIG_CONFIGFS_FS +struct config_group group; +#endif + };struct iio_sw_trigger {@@ -60,6 +64,10 @@ struct iio_sw_trigger *iio_sw_trigger_create(const char *, const char *);void iio_sw_trigger_destroy (struct iio_sw_trigger *);#ifdef CONFIG_CONFIGFS_FS + +int iio_sw_trigger_type_configs_register (struct iio_sw_trigger_type *tt); +void iio_sw_trigger_type_configs_unregister (struct iio_sw_trigger_type *tt); +static inline struct iio_sw_trigger *to_iio_sw_trigger (struct config_item *item) {@@ -75,6 +83,17 @@ void iio_config_group_init_type_name(struct config_group *group, config_group_init_type_name(group, name, type); }#else +static inline int iio_sw_trigger_type_configs_register ( +struct iio_sw_trigger_type *tt) +{ +return 0 ;include/linux/iio/sw_trigger.h void iio_config_group_init_type_name(struct config_group *group, · line 99
Quoted 10 lines
include/linux/iio/sw_trigger.h +7
-0+} + +static inline void iio_sw_trigger_type_configs_unregister ( +struct iio_sw_trigger_type *tt) +{ +} + static inline void iio_config_group_init_type_name(struct config_group *group, const char *name,--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html