Skip to content

Commit

Permalink
[PATCH] configfs: Convenience macros for attribute definition.
Browse files Browse the repository at this point in the history
Sysfs has the _ATTR() and _ATTR_RO() macros to make defining extended
form attributes easier.  configfs should have something similiar.

- _CONFIGFS_ATTR() and _CONFIGFS_ATTR_RO() are the counterparts to the
  sysfs macros.
- CONFIGFS_ATTR_STRUCT() creates the extended form attribute structure.
- CONFIGFS_ATTR_OPS() defines the show_attribute()/store_attribute()
  operations that call the show()/store() operations of the extended
  form configfs_attributes.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
  • Loading branch information
Joel Becker authored and Mark Fasheh committed Jul 31, 2008
1 parent 70526b6 commit ecb3d28
Show file tree
Hide file tree
Showing 4 changed files with 536 additions and 14 deletions.
17 changes: 14 additions & 3 deletions Documentation/filesystems/configfs/configfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,20 @@ the subsystem must be ready for it.
[An Example]

The best example of these basic concepts is the simple_children
subsystem/group and the simple_child item in configfs_example.c It
shows a trivial object displaying and storing an attribute, and a simple
group creating and destroying these children.
subsystem/group and the simple_child item in configfs_example_explicit.c
and configfs_example_macros.c. It shows a trivial object displaying and
storing an attribute, and a simple group creating and destroying these
children.

The only difference between configfs_example_explicit.c and
configfs_example_macros.c is how the attributes of the childless item
are defined. The childless item has extended attributes, each with
their own show()/store() operation. This follows a convention commonly
used in sysfs. configfs_example_explicit.c creates these attributes
by explicitly defining the structures involved. Conversely
configfs_example_macros.c uses some convenience macros from configfs.h
to define the attributes. These macros are similar to their sysfs
counterparts.

[Hierarchy Navigation and the Subsystem Mutex]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* vim: noexpandtab ts=8 sts=0 sw=8:
*
* configfs_example.c - This file is a demonstration module containing
* a number of configfs subsystems.
* configfs_example_explicit.c - This file is a demonstration module
* containing a number of configfs subsystems. It explicitly defines
* each structure without using the helper macros defined in
* configfs.h.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Expand Down Expand Up @@ -281,7 +283,6 @@ static struct config_item *simple_children_make_item(struct config_group *group,
if (!simple_child)
return ERR_PTR(-ENOMEM);


config_item_init_type_name(&simple_child->item, name,
&simple_child_type);

Expand All @@ -302,8 +303,8 @@ static struct configfs_attribute *simple_children_attrs[] = {
};

static ssize_t simple_children_attr_show(struct config_item *item,
struct configfs_attribute *attr,
char *page)
struct configfs_attribute *attr,
char *page)
{
return sprintf(page,
"[02-simple-children]\n"
Expand All @@ -318,7 +319,7 @@ static void simple_children_release(struct config_item *item)
}

static struct configfs_item_operations simple_children_item_ops = {
.release = simple_children_release,
.release = simple_children_release,
.show_attribute = simple_children_attr_show,
};

Expand Down Expand Up @@ -368,7 +369,6 @@ static struct config_group *group_children_make_group(struct config_group *group
if (!simple_children)
return ERR_PTR(-ENOMEM);


config_group_init_type_name(&simple_children->group, name,
&simple_children_type);

Expand All @@ -387,8 +387,8 @@ static struct configfs_attribute *group_children_attrs[] = {
};

static ssize_t group_children_attr_show(struct config_item *item,
struct configfs_attribute *attr,
char *page)
struct configfs_attribute *attr,
char *page)
{
return sprintf(page,
"[03-group-children]\n"
Expand Down
Loading

0 comments on commit ecb3d28

Please sign in to comment.