Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

configfs: remove old API

Remove the old show_attribute and store_attribute methods and update
the documentation. Also replace the two C samples with a single new
one in the proper samples directory where people expect to find it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Christoph Hellwig and committed by
Nicholas Bellinger
51798222 45b99773

+77 -705
-2
Documentation/filesystems/Makefile
··· 1 - subdir-y := configfs 2 - 3 1 # List of programs to build 4 2 hostprogs-y := dnotify_test 5 3
-3
Documentation/filesystems/configfs/Makefile
··· 1 - ifneq ($(CONFIG_CONFIGFS_FS),) 2 - obj-m += configfs_example_explicit.o configfs_example_macros.o 3 - endif
+11 -27
Documentation/filesystems/configfs/configfs.txt
··· 160 160 161 161 struct configfs_item_operations { 162 162 void (*release)(struct config_item *); 163 - ssize_t (*show_attribute)(struct config_item *, 164 - struct configfs_attribute *, 165 - char *); 166 - ssize_t (*store_attribute)(struct config_item *, 167 - struct configfs_attribute *, 168 - const char *, size_t); 169 163 int (*allow_link)(struct config_item *src, 170 164 struct config_item *target); 171 165 int (*drop_link)(struct config_item *src, ··· 177 183 operations can be performed on a config_item. All items that have been 178 184 allocated dynamically will need to provide the ct_item_ops->release() 179 185 method. This method is called when the config_item's reference count 180 - reaches zero. Items that wish to display an attribute need to provide 181 - the ct_item_ops->show_attribute() method. Similarly, storing a new 182 - attribute value uses the store_attribute() method. 186 + reaches zero. 183 187 184 188 [struct configfs_attribute] 185 189 ··· 185 193 char *ca_name; 186 194 struct module *ca_owner; 187 195 umode_t ca_mode; 196 + ssize_t (*show)(struct config_item *, char *); 197 + ssize_t (*store)(struct config_item *, const char *, size_t); 188 198 }; 189 199 190 200 When a config_item wants an attribute to appear as a file in the item's ··· 196 202 attribute file will appear with the configfs_attribute->ca_name 197 203 filename. configfs_attribute->ca_mode specifies the file permissions. 198 204 199 - If an attribute is readable and the config_item provides a 200 - ct_item_ops->show_attribute() method, that method will be called 201 - whenever userspace asks for a read(2) on the attribute. The converse 202 - will happen for write(2). 205 + If an attribute is readable and provides a ->show method, that method will 206 + be called whenever userspace asks for a read(2) on the attribute. If an 207 + attribute is writable and provides a ->store method, that method will be 208 + be called whenever userspace asks for a write(2) on the attribute. 203 209 204 210 [struct config_group] 205 211 ··· 305 311 [An Example] 306 312 307 313 The best example of these basic concepts is the simple_children 308 - subsystem/group and the simple_child item in configfs_example_explicit.c 309 - and configfs_example_macros.c. It shows a trivial object displaying and 310 - storing an attribute, and a simple group creating and destroying these 311 - children. 312 - 313 - The only difference between configfs_example_explicit.c and 314 - configfs_example_macros.c is how the attributes of the childless item 315 - are defined. The childless item has extended attributes, each with 316 - their own show()/store() operation. This follows a convention commonly 317 - used in sysfs. configfs_example_explicit.c creates these attributes 318 - by explicitly defining the structures involved. Conversely 319 - configfs_example_macros.c uses some convenience macros from configfs.h 320 - to define the attributes. These macros are similar to their sysfs 321 - counterparts. 314 + subsystem/group and the simple_child item in 315 + samples/configfs/configfs_sample.c. It shows a trivial object displaying 316 + and storing an attribute, and a simple group creating and destroying 317 + these children. 322 318 323 319 [Hierarchy Navigation and the Subsystem Mutex] 324 320
+53 -132
Documentation/filesystems/configfs/configfs_example_explicit.c samples/configfs/configfs_sample.c
··· 1 1 /* 2 2 * vim: noexpandtab ts=8 sts=0 sw=8: 3 3 * 4 - * configfs_example_explicit.c - This file is a demonstration module 5 - * containing a number of configfs subsystems. It explicitly defines 6 - * each structure without using the helper macros defined in 7 - * configfs.h. 4 + * configfs_example_macros.c - This file is a demonstration module 5 + * containing a number of configfs subsystems. It uses the helper 6 + * macros defined by configfs.h 8 7 * 9 8 * This program is free software; you can redistribute it and/or 10 9 * modify it under the terms of the GNU General Public ··· 52 53 int storeme; 53 54 }; 54 55 55 - struct childless_attribute { 56 - struct configfs_attribute attr; 57 - ssize_t (*show)(struct childless *, char *); 58 - ssize_t (*store)(struct childless *, const char *, size_t); 59 - }; 60 - 61 56 static inline struct childless *to_childless(struct config_item *item) 62 57 { 63 - return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct childless, subsys) : NULL; 58 + return item ? container_of(to_configfs_subsystem(to_config_group(item)), 59 + struct childless, subsys) : NULL; 64 60 } 65 61 66 - static ssize_t childless_showme_read(struct childless *childless, 67 - char *page) 62 + static ssize_t childless_showme_show(struct config_item *item, char *page) 68 63 { 64 + struct childless *childless = to_childless(item); 69 65 ssize_t pos; 70 66 71 67 pos = sprintf(page, "%d\n", childless->showme); ··· 69 75 return pos; 70 76 } 71 77 72 - static ssize_t childless_storeme_read(struct childless *childless, 73 - char *page) 78 + static ssize_t childless_storeme_show(struct config_item *item, char *page) 74 79 { 75 - return sprintf(page, "%d\n", childless->storeme); 80 + return sprintf(page, "%d\n", to_childless(item)->storeme); 76 81 } 77 82 78 - static ssize_t childless_storeme_write(struct childless *childless, 79 - const char *page, 80 - size_t count) 83 + static ssize_t childless_storeme_store(struct config_item *item, 84 + const char *page, size_t count) 81 85 { 86 + struct childless *childless = to_childless(item); 82 87 unsigned long tmp; 83 88 char *p = (char *) page; 84 89 85 90 tmp = simple_strtoul(p, &p, 10); 86 - if ((*p != '\0') && (*p != '\n')) 91 + if (!p || (*p && (*p != '\n'))) 87 92 return -EINVAL; 88 93 89 94 if (tmp > INT_MAX) ··· 93 100 return count; 94 101 } 95 102 96 - static ssize_t childless_description_read(struct childless *childless, 97 - char *page) 103 + static ssize_t childless_description_show(struct config_item *item, char *page) 98 104 { 99 105 return sprintf(page, 100 106 "[01-childless]\n" ··· 104 112 "than a directory in /proc.\n"); 105 113 } 106 114 107 - static struct childless_attribute childless_attr_showme = { 108 - .attr = { .ca_owner = THIS_MODULE, .ca_name = "showme", .ca_mode = S_IRUGO }, 109 - .show = childless_showme_read, 110 - }; 111 - static struct childless_attribute childless_attr_storeme = { 112 - .attr = { .ca_owner = THIS_MODULE, .ca_name = "storeme", .ca_mode = S_IRUGO | S_IWUSR }, 113 - .show = childless_storeme_read, 114 - .store = childless_storeme_write, 115 - }; 116 - static struct childless_attribute childless_attr_description = { 117 - .attr = { .ca_owner = THIS_MODULE, .ca_name = "description", .ca_mode = S_IRUGO }, 118 - .show = childless_description_read, 119 - }; 115 + CONFIGFS_ATTR_RO(childless_, showme); 116 + CONFIGFS_ATTR(childless_, storeme); 117 + CONFIGFS_ATTR_RO(childless_, description); 120 118 121 119 static struct configfs_attribute *childless_attrs[] = { 122 - &childless_attr_showme.attr, 123 - &childless_attr_storeme.attr, 124 - &childless_attr_description.attr, 120 + &childless_attr_showme, 121 + &childless_attr_storeme, 122 + &childless_attr_description, 125 123 NULL, 126 124 }; 127 125 128 - static ssize_t childless_attr_show(struct config_item *item, 129 - struct configfs_attribute *attr, 130 - char *page) 131 - { 132 - struct childless *childless = to_childless(item); 133 - struct childless_attribute *childless_attr = 134 - container_of(attr, struct childless_attribute, attr); 135 - ssize_t ret = 0; 136 - 137 - if (childless_attr->show) 138 - ret = childless_attr->show(childless, page); 139 - return ret; 140 - } 141 - 142 - static ssize_t childless_attr_store(struct config_item *item, 143 - struct configfs_attribute *attr, 144 - const char *page, size_t count) 145 - { 146 - struct childless *childless = to_childless(item); 147 - struct childless_attribute *childless_attr = 148 - container_of(attr, struct childless_attribute, attr); 149 - ssize_t ret = -EINVAL; 150 - 151 - if (childless_attr->store) 152 - ret = childless_attr->store(childless, page, count); 153 - return ret; 154 - } 155 - 156 - static struct configfs_item_operations childless_item_ops = { 157 - .show_attribute = childless_attr_show, 158 - .store_attribute = childless_attr_store, 159 - }; 160 - 161 126 static struct config_item_type childless_type = { 162 - .ct_item_ops = &childless_item_ops, 163 127 .ct_attrs = childless_attrs, 164 128 .ct_owner = THIS_MODULE, 165 129 }; ··· 153 205 return item ? container_of(item, struct simple_child, item) : NULL; 154 206 } 155 207 156 - static struct configfs_attribute simple_child_attr_storeme = { 157 - .ca_owner = THIS_MODULE, 158 - .ca_name = "storeme", 159 - .ca_mode = S_IRUGO | S_IWUSR, 160 - }; 161 - 162 - static struct configfs_attribute *simple_child_attrs[] = { 163 - &simple_child_attr_storeme, 164 - NULL, 165 - }; 166 - 167 - static ssize_t simple_child_attr_show(struct config_item *item, 168 - struct configfs_attribute *attr, 169 - char *page) 208 + static ssize_t simple_child_storeme_show(struct config_item *item, char *page) 170 209 { 171 - ssize_t count; 172 - struct simple_child *simple_child = to_simple_child(item); 173 - 174 - count = sprintf(page, "%d\n", simple_child->storeme); 175 - 176 - return count; 210 + return sprintf(page, "%d\n", to_simple_child(item)->storeme); 177 211 } 178 212 179 - static ssize_t simple_child_attr_store(struct config_item *item, 180 - struct configfs_attribute *attr, 181 - const char *page, size_t count) 213 + static ssize_t simple_child_storeme_store(struct config_item *item, 214 + const char *page, size_t count) 182 215 { 183 216 struct simple_child *simple_child = to_simple_child(item); 184 217 unsigned long tmp; ··· 177 248 return count; 178 249 } 179 250 251 + CONFIGFS_ATTR(simple_child_, storeme); 252 + 253 + static struct configfs_attribute *simple_child_attrs[] = { 254 + &simple_child_attr_storeme, 255 + NULL, 256 + }; 257 + 180 258 static void simple_child_release(struct config_item *item) 181 259 { 182 260 kfree(to_simple_child(item)); ··· 191 255 192 256 static struct configfs_item_operations simple_child_item_ops = { 193 257 .release = simple_child_release, 194 - .show_attribute = simple_child_attr_show, 195 - .store_attribute = simple_child_attr_store, 196 258 }; 197 259 198 260 static struct config_item_type simple_child_type = { ··· 206 272 207 273 static inline struct simple_children *to_simple_children(struct config_item *item) 208 274 { 209 - return item ? container_of(to_config_group(item), struct simple_children, group) : NULL; 275 + return item ? container_of(to_config_group(item), 276 + struct simple_children, group) : NULL; 210 277 } 211 278 212 - static struct config_item *simple_children_make_item(struct config_group *group, const char *name) 279 + static struct config_item *simple_children_make_item(struct config_group *group, 280 + const char *name) 213 281 { 214 282 struct simple_child *simple_child; 215 283 ··· 227 291 return &simple_child->item; 228 292 } 229 293 230 - static struct configfs_attribute simple_children_attr_description = { 231 - .ca_owner = THIS_MODULE, 232 - .ca_name = "description", 233 - .ca_mode = S_IRUGO, 234 - }; 235 - 236 - static struct configfs_attribute *simple_children_attrs[] = { 237 - &simple_children_attr_description, 238 - NULL, 239 - }; 240 - 241 - static ssize_t simple_children_attr_show(struct config_item *item, 242 - struct configfs_attribute *attr, 243 - char *page) 294 + static ssize_t simple_children_description_show(struct config_item *item, 295 + char *page) 244 296 { 245 297 return sprintf(page, 246 298 "[02-simple-children]\n" ··· 237 313 "items have only one attribute that is readable and writeable.\n"); 238 314 } 239 315 316 + CONFIGFS_ATTR_RO(simple_children_, description); 317 + 318 + static struct configfs_attribute *simple_children_attrs[] = { 319 + &simple_children_attr_description, 320 + NULL, 321 + }; 322 + 240 323 static void simple_children_release(struct config_item *item) 241 324 { 242 325 kfree(to_simple_children(item)); ··· 251 320 252 321 static struct configfs_item_operations simple_children_item_ops = { 253 322 .release = simple_children_release, 254 - .show_attribute = simple_children_attr_show, 255 323 }; 256 324 257 325 /* ··· 290 360 * children of its own. 291 361 */ 292 362 293 - static struct config_group *group_children_make_group(struct config_group *group, const char *name) 363 + static struct config_group *group_children_make_group( 364 + struct config_group *group, const char *name) 294 365 { 295 366 struct simple_children *simple_children; 296 367 ··· 306 375 return &simple_children->group; 307 376 } 308 377 309 - static struct configfs_attribute group_children_attr_description = { 310 - .ca_owner = THIS_MODULE, 311 - .ca_name = "description", 312 - .ca_mode = S_IRUGO, 313 - }; 314 - 315 - static struct configfs_attribute *group_children_attrs[] = { 316 - &group_children_attr_description, 317 - NULL, 318 - }; 319 - 320 - static ssize_t group_children_attr_show(struct config_item *item, 321 - struct configfs_attribute *attr, 322 - char *page) 378 + static ssize_t group_children_description_show(struct config_item *item, 379 + char *page) 323 380 { 324 381 return sprintf(page, 325 382 "[03-group-children]\n" ··· 316 397 "groups are like the subsystem simple-children.\n"); 317 398 } 318 399 319 - static struct configfs_item_operations group_children_item_ops = { 320 - .show_attribute = group_children_attr_show, 400 + CONFIGFS_ATTR_RO(group_children_, description); 401 + 402 + static struct configfs_attribute *group_children_attrs[] = { 403 + &group_children_attr_description, 404 + NULL, 321 405 }; 322 406 323 407 /* ··· 332 410 }; 333 411 334 412 static struct config_item_type group_children_type = { 335 - .ct_item_ops = &group_children_item_ops, 336 413 .ct_group_ops = &group_children_group_ops, 337 414 .ct_attrs = group_children_attrs, 338 415 .ct_owner = THIS_MODULE,
-446
Documentation/filesystems/configfs/configfs_example_macros.c
··· 1 - /* 2 - * vim: noexpandtab ts=8 sts=0 sw=8: 3 - * 4 - * configfs_example_macros.c - This file is a demonstration module 5 - * containing a number of configfs subsystems. It uses the helper 6 - * macros defined by configfs.h 7 - * 8 - * This program is free software; you can redistribute it and/or 9 - * modify it under the terms of the GNU General Public 10 - * License as published by the Free Software Foundation; either 11 - * version 2 of the License, or (at your option) any later version. 12 - * 13 - * This program is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 - * General Public License for more details. 17 - * 18 - * You should have received a copy of the GNU General Public 19 - * License along with this program; if not, write to the 20 - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 - * Boston, MA 021110-1307, USA. 22 - * 23 - * Based on sysfs: 24 - * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel 25 - * 26 - * configfs Copyright (C) 2005 Oracle. All rights reserved. 27 - */ 28 - 29 - #include <linux/init.h> 30 - #include <linux/module.h> 31 - #include <linux/slab.h> 32 - 33 - #include <linux/configfs.h> 34 - 35 - 36 - 37 - /* 38 - * 01-childless 39 - * 40 - * This first example is a childless subsystem. It cannot create 41 - * any config_items. It just has attributes. 42 - * 43 - * Note that we are enclosing the configfs_subsystem inside a container. 44 - * This is not necessary if a subsystem has no attributes directly 45 - * on the subsystem. See the next example, 02-simple-children, for 46 - * such a subsystem. 47 - */ 48 - 49 - struct childless { 50 - struct configfs_subsystem subsys; 51 - int showme; 52 - int storeme; 53 - }; 54 - 55 - static inline struct childless *to_childless(struct config_item *item) 56 - { 57 - return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct childless, subsys) : NULL; 58 - } 59 - 60 - CONFIGFS_ATTR_STRUCT(childless); 61 - #define CHILDLESS_ATTR(_name, _mode, _show, _store) \ 62 - struct childless_attribute childless_attr_##_name = __CONFIGFS_ATTR(_name, _mode, _show, _store) 63 - #define CHILDLESS_ATTR_RO(_name, _show) \ 64 - struct childless_attribute childless_attr_##_name = __CONFIGFS_ATTR_RO(_name, _show); 65 - 66 - static ssize_t childless_showme_read(struct childless *childless, 67 - char *page) 68 - { 69 - ssize_t pos; 70 - 71 - pos = sprintf(page, "%d\n", childless->showme); 72 - childless->showme++; 73 - 74 - return pos; 75 - } 76 - 77 - static ssize_t childless_storeme_read(struct childless *childless, 78 - char *page) 79 - { 80 - return sprintf(page, "%d\n", childless->storeme); 81 - } 82 - 83 - static ssize_t childless_storeme_write(struct childless *childless, 84 - const char *page, 85 - size_t count) 86 - { 87 - unsigned long tmp; 88 - char *p = (char *) page; 89 - 90 - tmp = simple_strtoul(p, &p, 10); 91 - if (!p || (*p && (*p != '\n'))) 92 - return -EINVAL; 93 - 94 - if (tmp > INT_MAX) 95 - return -ERANGE; 96 - 97 - childless->storeme = tmp; 98 - 99 - return count; 100 - } 101 - 102 - static ssize_t childless_description_read(struct childless *childless, 103 - char *page) 104 - { 105 - return sprintf(page, 106 - "[01-childless]\n" 107 - "\n" 108 - "The childless subsystem is the simplest possible subsystem in\n" 109 - "configfs. It does not support the creation of child config_items.\n" 110 - "It only has a few attributes. In fact, it isn't much different\n" 111 - "than a directory in /proc.\n"); 112 - } 113 - 114 - CHILDLESS_ATTR_RO(showme, childless_showme_read); 115 - CHILDLESS_ATTR(storeme, S_IRUGO | S_IWUSR, childless_storeme_read, 116 - childless_storeme_write); 117 - CHILDLESS_ATTR_RO(description, childless_description_read); 118 - 119 - static struct configfs_attribute *childless_attrs[] = { 120 - &childless_attr_showme.attr, 121 - &childless_attr_storeme.attr, 122 - &childless_attr_description.attr, 123 - NULL, 124 - }; 125 - 126 - CONFIGFS_ATTR_OPS(childless); 127 - static struct configfs_item_operations childless_item_ops = { 128 - .show_attribute = childless_attr_show, 129 - .store_attribute = childless_attr_store, 130 - }; 131 - 132 - static struct config_item_type childless_type = { 133 - .ct_item_ops = &childless_item_ops, 134 - .ct_attrs = childless_attrs, 135 - .ct_owner = THIS_MODULE, 136 - }; 137 - 138 - static struct childless childless_subsys = { 139 - .subsys = { 140 - .su_group = { 141 - .cg_item = { 142 - .ci_namebuf = "01-childless", 143 - .ci_type = &childless_type, 144 - }, 145 - }, 146 - }, 147 - }; 148 - 149 - 150 - /* ----------------------------------------------------------------- */ 151 - 152 - /* 153 - * 02-simple-children 154 - * 155 - * This example merely has a simple one-attribute child. Note that 156 - * there is no extra attribute structure, as the child's attribute is 157 - * known from the get-go. Also, there is no container for the 158 - * subsystem, as it has no attributes of its own. 159 - */ 160 - 161 - struct simple_child { 162 - struct config_item item; 163 - int storeme; 164 - }; 165 - 166 - static inline struct simple_child *to_simple_child(struct config_item *item) 167 - { 168 - return item ? container_of(item, struct simple_child, item) : NULL; 169 - } 170 - 171 - static struct configfs_attribute simple_child_attr_storeme = { 172 - .ca_owner = THIS_MODULE, 173 - .ca_name = "storeme", 174 - .ca_mode = S_IRUGO | S_IWUSR, 175 - }; 176 - 177 - static struct configfs_attribute *simple_child_attrs[] = { 178 - &simple_child_attr_storeme, 179 - NULL, 180 - }; 181 - 182 - static ssize_t simple_child_attr_show(struct config_item *item, 183 - struct configfs_attribute *attr, 184 - char *page) 185 - { 186 - ssize_t count; 187 - struct simple_child *simple_child = to_simple_child(item); 188 - 189 - count = sprintf(page, "%d\n", simple_child->storeme); 190 - 191 - return count; 192 - } 193 - 194 - static ssize_t simple_child_attr_store(struct config_item *item, 195 - struct configfs_attribute *attr, 196 - const char *page, size_t count) 197 - { 198 - struct simple_child *simple_child = to_simple_child(item); 199 - unsigned long tmp; 200 - char *p = (char *) page; 201 - 202 - tmp = simple_strtoul(p, &p, 10); 203 - if (!p || (*p && (*p != '\n'))) 204 - return -EINVAL; 205 - 206 - if (tmp > INT_MAX) 207 - return -ERANGE; 208 - 209 - simple_child->storeme = tmp; 210 - 211 - return count; 212 - } 213 - 214 - static void simple_child_release(struct config_item *item) 215 - { 216 - kfree(to_simple_child(item)); 217 - } 218 - 219 - static struct configfs_item_operations simple_child_item_ops = { 220 - .release = simple_child_release, 221 - .show_attribute = simple_child_attr_show, 222 - .store_attribute = simple_child_attr_store, 223 - }; 224 - 225 - static struct config_item_type simple_child_type = { 226 - .ct_item_ops = &simple_child_item_ops, 227 - .ct_attrs = simple_child_attrs, 228 - .ct_owner = THIS_MODULE, 229 - }; 230 - 231 - 232 - struct simple_children { 233 - struct config_group group; 234 - }; 235 - 236 - static inline struct simple_children *to_simple_children(struct config_item *item) 237 - { 238 - return item ? container_of(to_config_group(item), struct simple_children, group) : NULL; 239 - } 240 - 241 - static struct config_item *simple_children_make_item(struct config_group *group, const char *name) 242 - { 243 - struct simple_child *simple_child; 244 - 245 - simple_child = kzalloc(sizeof(struct simple_child), GFP_KERNEL); 246 - if (!simple_child) 247 - return ERR_PTR(-ENOMEM); 248 - 249 - config_item_init_type_name(&simple_child->item, name, 250 - &simple_child_type); 251 - 252 - simple_child->storeme = 0; 253 - 254 - return &simple_child->item; 255 - } 256 - 257 - static struct configfs_attribute simple_children_attr_description = { 258 - .ca_owner = THIS_MODULE, 259 - .ca_name = "description", 260 - .ca_mode = S_IRUGO, 261 - }; 262 - 263 - static struct configfs_attribute *simple_children_attrs[] = { 264 - &simple_children_attr_description, 265 - NULL, 266 - }; 267 - 268 - static ssize_t simple_children_attr_show(struct config_item *item, 269 - struct configfs_attribute *attr, 270 - char *page) 271 - { 272 - return sprintf(page, 273 - "[02-simple-children]\n" 274 - "\n" 275 - "This subsystem allows the creation of child config_items. These\n" 276 - "items have only one attribute that is readable and writeable.\n"); 277 - } 278 - 279 - static void simple_children_release(struct config_item *item) 280 - { 281 - kfree(to_simple_children(item)); 282 - } 283 - 284 - static struct configfs_item_operations simple_children_item_ops = { 285 - .release = simple_children_release, 286 - .show_attribute = simple_children_attr_show, 287 - }; 288 - 289 - /* 290 - * Note that, since no extra work is required on ->drop_item(), 291 - * no ->drop_item() is provided. 292 - */ 293 - static struct configfs_group_operations simple_children_group_ops = { 294 - .make_item = simple_children_make_item, 295 - }; 296 - 297 - static struct config_item_type simple_children_type = { 298 - .ct_item_ops = &simple_children_item_ops, 299 - .ct_group_ops = &simple_children_group_ops, 300 - .ct_attrs = simple_children_attrs, 301 - .ct_owner = THIS_MODULE, 302 - }; 303 - 304 - static struct configfs_subsystem simple_children_subsys = { 305 - .su_group = { 306 - .cg_item = { 307 - .ci_namebuf = "02-simple-children", 308 - .ci_type = &simple_children_type, 309 - }, 310 - }, 311 - }; 312 - 313 - 314 - /* ----------------------------------------------------------------- */ 315 - 316 - /* 317 - * 03-group-children 318 - * 319 - * This example reuses the simple_children group from above. However, 320 - * the simple_children group is not the subsystem itself, it is a 321 - * child of the subsystem. Creation of a group in the subsystem creates 322 - * a new simple_children group. That group can then have simple_child 323 - * children of its own. 324 - */ 325 - 326 - static struct config_group *group_children_make_group(struct config_group *group, const char *name) 327 - { 328 - struct simple_children *simple_children; 329 - 330 - simple_children = kzalloc(sizeof(struct simple_children), 331 - GFP_KERNEL); 332 - if (!simple_children) 333 - return ERR_PTR(-ENOMEM); 334 - 335 - config_group_init_type_name(&simple_children->group, name, 336 - &simple_children_type); 337 - 338 - return &simple_children->group; 339 - } 340 - 341 - static struct configfs_attribute group_children_attr_description = { 342 - .ca_owner = THIS_MODULE, 343 - .ca_name = "description", 344 - .ca_mode = S_IRUGO, 345 - }; 346 - 347 - static struct configfs_attribute *group_children_attrs[] = { 348 - &group_children_attr_description, 349 - NULL, 350 - }; 351 - 352 - static ssize_t group_children_attr_show(struct config_item *item, 353 - struct configfs_attribute *attr, 354 - char *page) 355 - { 356 - return sprintf(page, 357 - "[03-group-children]\n" 358 - "\n" 359 - "This subsystem allows the creation of child config_groups. These\n" 360 - "groups are like the subsystem simple-children.\n"); 361 - } 362 - 363 - static struct configfs_item_operations group_children_item_ops = { 364 - .show_attribute = group_children_attr_show, 365 - }; 366 - 367 - /* 368 - * Note that, since no extra work is required on ->drop_item(), 369 - * no ->drop_item() is provided. 370 - */ 371 - static struct configfs_group_operations group_children_group_ops = { 372 - .make_group = group_children_make_group, 373 - }; 374 - 375 - static struct config_item_type group_children_type = { 376 - .ct_item_ops = &group_children_item_ops, 377 - .ct_group_ops = &group_children_group_ops, 378 - .ct_attrs = group_children_attrs, 379 - .ct_owner = THIS_MODULE, 380 - }; 381 - 382 - static struct configfs_subsystem group_children_subsys = { 383 - .su_group = { 384 - .cg_item = { 385 - .ci_namebuf = "03-group-children", 386 - .ci_type = &group_children_type, 387 - }, 388 - }, 389 - }; 390 - 391 - /* ----------------------------------------------------------------- */ 392 - 393 - /* 394 - * We're now done with our subsystem definitions. 395 - * For convenience in this module, here's a list of them all. It 396 - * allows the init function to easily register them. Most modules 397 - * will only have one subsystem, and will only call register_subsystem 398 - * on it directly. 399 - */ 400 - static struct configfs_subsystem *example_subsys[] = { 401 - &childless_subsys.subsys, 402 - &simple_children_subsys, 403 - &group_children_subsys, 404 - NULL, 405 - }; 406 - 407 - static int __init configfs_example_init(void) 408 - { 409 - int ret; 410 - int i; 411 - struct configfs_subsystem *subsys; 412 - 413 - for (i = 0; example_subsys[i]; i++) { 414 - subsys = example_subsys[i]; 415 - 416 - config_group_init(&subsys->su_group); 417 - mutex_init(&subsys->su_mutex); 418 - ret = configfs_register_subsystem(subsys); 419 - if (ret) { 420 - printk(KERN_ERR "Error %d while registering subsystem %s\n", 421 - ret, 422 - subsys->su_group.cg_item.ci_namebuf); 423 - goto out_unregister; 424 - } 425 - } 426 - 427 - return 0; 428 - 429 - out_unregister: 430 - for (i--; i >= 0; i--) 431 - configfs_unregister_subsystem(example_subsys[i]); 432 - 433 - return ret; 434 - } 435 - 436 - static void __exit configfs_example_exit(void) 437 - { 438 - int i; 439 - 440 - for (i = 0; example_subsys[i]; i++) 441 - configfs_unregister_subsystem(example_subsys[i]); 442 - } 443 - 444 - module_init(configfs_example_init); 445 - module_exit(configfs_example_exit); 446 - MODULE_LICENSE("GPL");
+3 -12
fs/configfs/file.c
··· 65 65 { 66 66 struct configfs_attribute * attr = to_attr(dentry); 67 67 struct config_item * item = to_item(dentry->d_parent); 68 - struct configfs_item_operations * ops = buffer->ops; 69 68 int ret = 0; 70 69 ssize_t count; 71 70 ··· 73 74 if (!buffer->page) 74 75 return -ENOMEM; 75 76 76 - if (ops->show_attribute) 77 - count = ops->show_attribute(item, attr, buffer->page); 78 - else 79 - count = attr->show(item, buffer->page); 77 + count = attr->show(item, buffer->page); 80 78 81 79 buffer->needs_read_fill = 0; 82 80 BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE); ··· 171 175 { 172 176 struct configfs_attribute * attr = to_attr(dentry); 173 177 struct config_item * item = to_item(dentry->d_parent); 174 - struct configfs_item_operations * ops = buffer->ops; 175 178 176 - if (ops->store_attribute) 177 - return ops->store_attribute(item, attr, buffer->page, count); 178 179 return attr->store(item, buffer->page, count); 179 180 } 180 181 ··· 236 243 * and we must have a store method. 237 244 */ 238 245 if (file->f_mode & FMODE_WRITE) { 239 - if (!(inode->i_mode & S_IWUGO) || 240 - (!ops->store_attribute && !attr->store)) 246 + if (!(inode->i_mode & S_IWUGO) || !attr->store) 241 247 goto Eaccess; 242 248 243 249 } ··· 246 254 * must be a show method for it. 247 255 */ 248 256 if (file->f_mode & FMODE_READ) { 249 - if (!(inode->i_mode & S_IRUGO) || 250 - (!ops->show_attribute && !attr->show)) 257 + if (!(inode->i_mode & S_IRUGO) || !attr->show) 251 258 goto Eaccess; 252 259 } 253 260
-82
include/linux/configfs.h
··· 155 155 } 156 156 157 157 /* 158 - * Users often need to create attribute structures for their configurable 159 - * attributes, containing a configfs_attribute member and function pointers 160 - * for the show() and store() operations on that attribute. If they don't 161 - * need anything else on the extended attribute structure, they can use 162 - * this macro to define it The argument _item is the name of the 163 - * config_item structure. 164 - */ 165 - #define CONFIGFS_ATTR_STRUCT(_item) \ 166 - struct _item##_attribute { \ 167 - struct configfs_attribute attr; \ 168 - ssize_t (*show)(struct _item *, char *); \ 169 - ssize_t (*store)(struct _item *, const char *, size_t); \ 170 - } 171 - 172 - /* 173 - * With the extended attribute structure, users can use this macro 174 - * (similar to sysfs' __ATTR) to make defining attributes easier. 175 - * An example: 176 - * #define MYITEM_ATTR(_name, _mode, _show, _store) \ 177 - * struct myitem_attribute childless_attr_##_name = \ 178 - * __CONFIGFS_ATTR(_name, _mode, _show, _store) 179 - */ 180 - #define __CONFIGFS_ATTR(_name, _mode, _show, _store) \ 181 - { \ 182 - .attr = { \ 183 - .ca_name = __stringify(_name), \ 184 - .ca_mode = _mode, \ 185 - .ca_owner = THIS_MODULE, \ 186 - }, \ 187 - .show = _show, \ 188 - .store = _store, \ 189 - } 190 - /* Here is a readonly version, only requiring a show() operation */ 191 - #define __CONFIGFS_ATTR_RO(_name, _show) \ 192 - { \ 193 - .attr = { \ 194 - .ca_name = __stringify(_name), \ 195 - .ca_mode = 0444, \ 196 - .ca_owner = THIS_MODULE, \ 197 - }, \ 198 - .show = _show, \ 199 - } 200 - 201 - /* 202 - * With these extended attributes, the simple show_attribute() and 203 - * store_attribute() operations need to call the show() and store() of the 204 - * attributes. This is a common pattern, so we provide a macro to define 205 - * them. The argument _item is the name of the config_item structure. 206 - * This macro expects the attributes to be named "struct <name>_attribute" 207 - * and the function to_<name>() to exist; 208 - */ 209 - #define CONFIGFS_ATTR_OPS(_item) \ 210 - static ssize_t _item##_attr_show(struct config_item *item, \ 211 - struct configfs_attribute *attr, \ 212 - char *page) \ 213 - { \ 214 - struct _item *_item = to_##_item(item); \ 215 - struct _item##_attribute *_item##_attr = \ 216 - container_of(attr, struct _item##_attribute, attr); \ 217 - ssize_t ret = 0; \ 218 - \ 219 - if (_item##_attr->show) \ 220 - ret = _item##_attr->show(_item, page); \ 221 - return ret; \ 222 - } \ 223 - static ssize_t _item##_attr_store(struct config_item *item, \ 224 - struct configfs_attribute *attr, \ 225 - const char *page, size_t count) \ 226 - { \ 227 - struct _item *_item = to_##_item(item); \ 228 - struct _item##_attribute *_item##_attr = \ 229 - container_of(attr, struct _item##_attribute, attr); \ 230 - ssize_t ret = -EINVAL; \ 231 - \ 232 - if (_item##_attr->store) \ 233 - ret = _item##_attr->store(_item, page, count); \ 234 - return ret; \ 235 - } 236 - 237 - /* 238 158 * If allow_link() exists, the item can symlink(2) out to other 239 159 * items. If the item is a group, it may support mkdir(2). 240 160 * Groups supply one of make_group() and make_item(). If the ··· 170 250 */ 171 251 struct configfs_item_operations { 172 252 void (*release)(struct config_item *); 173 - ssize_t (*show_attribute)(struct config_item *, struct configfs_attribute *,char *); 174 - ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t); 175 253 int (*allow_link)(struct config_item *src, struct config_item *target); 176 254 int (*drop_link)(struct config_item *src, struct config_item *target); 177 255 };
+6
samples/Kconfig
··· 70 70 Builds a sample live patch that replaces the procfs handler 71 71 for /proc/cmdline to print "this has been live patched". 72 72 73 + config SAMPLE_CONFIGFS 74 + tristate "Build configfs patching sample -- loadable modules only" 75 + depends on CONFIGFS_FS && m 76 + help 77 + Builds a sample configfs interface. 78 + 73 79 endif # SAMPLES
+2 -1
samples/Makefile
··· 1 1 # Makefile for Linux samples code 2 2 3 3 obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ 4 - hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ 4 + hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ 5 + configfs/
+2
samples/configfs/Makefile
··· 1 + 2 + obj-$(CONFIG_SAMPLE_CONFIGFS) += configfs_sample.o