1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * dir.c - Operations for configfs directories.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
22 * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
24 * configfs Copyright (C) 2005 Oracle. All rights reserved.
30 #include <linux/mount.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
34 #include <linux/configfs.h>
35 #include "configfs_internal.h"
37 DECLARE_RWSEM(configfs_rename_sem);
39 static void configfs_d_iput(struct dentry * dentry,
42 struct configfs_dirent * sd = dentry->d_fsdata;
45 BUG_ON(sd->s_dentry != dentry);
53 * We _must_ delete our dentries on last dput, as the chain-to-parent
54 * behavior is required to clear the parents of default_groups.
56 static int configfs_d_delete(struct dentry *dentry)
61 static struct dentry_operations configfs_dentry_ops = {
62 .d_iput = configfs_d_iput,
63 /* simple_delete_dentry() isn't exported */
64 .d_delete = configfs_d_delete,
68 * Allocates a new configfs_dirent and links it to the parent configfs_dirent
70 static struct configfs_dirent *configfs_new_dirent(struct configfs_dirent * parent_sd,
73 struct configfs_dirent * sd;
75 sd = kmem_cache_alloc(configfs_dir_cachep, GFP_KERNEL);
79 memset(sd, 0, sizeof(*sd));
80 atomic_set(&sd->s_count, 1);
81 INIT_LIST_HEAD(&sd->s_links);
82 INIT_LIST_HEAD(&sd->s_children);
83 list_add(&sd->s_sibling, &parent_sd->s_children);
84 sd->s_element = element;
89 int configfs_make_dirent(struct configfs_dirent * parent_sd,
90 struct dentry * dentry, void * element,
91 umode_t mode, int type)
93 struct configfs_dirent * sd;
95 sd = configfs_new_dirent(parent_sd, element);
101 sd->s_dentry = dentry;
103 dentry->d_fsdata = configfs_get(sd);
104 dentry->d_op = &configfs_dentry_ops;
110 static int init_dir(struct inode * inode)
112 inode->i_op = &configfs_dir_inode_operations;
113 inode->i_fop = &configfs_dir_operations;
115 /* directory inodes start off with i_nlink == 2 (for "." entry) */
120 static int init_file(struct inode * inode)
122 inode->i_size = PAGE_SIZE;
123 inode->i_fop = &configfs_file_operations;
127 static int init_symlink(struct inode * inode)
129 inode->i_op = &configfs_symlink_inode_operations;
133 static int create_dir(struct config_item * k, struct dentry * p,
137 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
139 error = configfs_make_dirent(p->d_fsdata, d, k, mode,
142 error = configfs_create(d, mode, init_dir);
144 p->d_inode->i_nlink++;
145 (d)->d_op = &configfs_dentry_ops;
147 struct configfs_dirent *sd = d->d_fsdata;
149 list_del_init(&sd->s_sibling);
159 * configfs_create_dir - create a directory for an config_item.
160 * @item: config_itemwe're creating directory for.
161 * @dentry: config_item's dentry.
164 static int configfs_create_dir(struct config_item * item, struct dentry *dentry)
166 struct dentry * parent;
172 parent = item->ci_parent->ci_dentry;
173 else if (configfs_mount && configfs_mount->mnt_sb)
174 parent = configfs_mount->mnt_sb->s_root;
178 error = create_dir(item,parent,dentry);
180 item->ci_dentry = dentry;
184 int configfs_create_link(struct configfs_symlink *sl,
185 struct dentry *parent,
186 struct dentry *dentry)
189 umode_t mode = S_IFLNK | S_IRWXUGO;
191 err = configfs_make_dirent(parent->d_fsdata, dentry, sl, mode,
194 err = configfs_create(dentry, mode, init_symlink);
196 dentry->d_op = &configfs_dentry_ops;
198 struct configfs_dirent *sd = dentry->d_fsdata;
200 list_del_init(&sd->s_sibling);
208 static void remove_dir(struct dentry * d)
210 struct dentry * parent = dget(d->d_parent);
211 struct configfs_dirent * sd;
214 list_del_init(&sd->s_sibling);
217 simple_rmdir(parent->d_inode,d);
219 pr_debug(" o %s removing done (%d)\n",d->d_name.name,
220 atomic_read(&d->d_count));
226 * configfs_remove_dir - remove an config_item's directory.
227 * @item: config_item we're removing.
229 * The only thing special about this is that we remove any files in
230 * the directory before we remove the directory, and we've inlined
231 * what used to be configfs_rmdir() below, instead of calling separately.
234 static void configfs_remove_dir(struct config_item * item)
236 struct dentry * dentry = dget(item->ci_dentry);
243 * Drop reference from dget() on entrance.
249 /* attaches attribute's configfs_dirent to the dentry corresponding to the
252 static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry)
254 struct configfs_attribute * attr = sd->s_element;
257 dentry->d_fsdata = configfs_get(sd);
258 sd->s_dentry = dentry;
259 error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG, init_file);
265 dentry->d_op = &configfs_dentry_ops;
271 static struct dentry * configfs_lookup(struct inode *dir,
272 struct dentry *dentry,
273 struct nameidata *nd)
275 struct configfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
276 struct configfs_dirent * sd;
280 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
281 if (sd->s_type & CONFIGFS_NOT_PINNED) {
282 const unsigned char * name = configfs_get_name(sd);
284 if (strcmp(name, dentry->d_name.name))
288 err = configfs_attach_attr(sd, dentry);
295 * If it doesn't exist and it isn't a NOT_PINNED item,
296 * it must be negative.
298 return simple_lookup(dir, dentry, nd);
305 * Only subdirectories count here. Files (CONFIGFS_NOT_PINNED) are
306 * attributes and are removed by rmdir(). We recurse, taking i_mutex
307 * on all children that are candidates for default detach. If the
308 * result is clean, then configfs_detach_group() will handle dropping
309 * i_mutex. If there is an error, the caller will clean up the i_mutex
310 * holders via configfs_detach_rollback().
312 static int configfs_detach_prep(struct dentry *dentry)
314 struct configfs_dirent *parent_sd = dentry->d_fsdata;
315 struct configfs_dirent *sd;
319 if (!list_empty(&parent_sd->s_links))
323 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
324 if (sd->s_type & CONFIGFS_NOT_PINNED)
326 if (sd->s_type & CONFIGFS_USET_DEFAULT) {
327 mutex_lock(&sd->s_dentry->d_inode->i_mutex);
328 /* Mark that we've taken i_mutex */
329 sd->s_type |= CONFIGFS_USET_DROPPING;
331 ret = configfs_detach_prep(sd->s_dentry);
345 * Walk the tree, dropping i_mutex wherever CONFIGFS_USET_DROPPING is
348 static void configfs_detach_rollback(struct dentry *dentry)
350 struct configfs_dirent *parent_sd = dentry->d_fsdata;
351 struct configfs_dirent *sd;
353 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
354 if (sd->s_type & CONFIGFS_USET_DEFAULT) {
355 configfs_detach_rollback(sd->s_dentry);
357 if (sd->s_type & CONFIGFS_USET_DROPPING) {
358 sd->s_type &= ~CONFIGFS_USET_DROPPING;
359 mutex_unlock(&sd->s_dentry->d_inode->i_mutex);
365 static void detach_attrs(struct config_item * item)
367 struct dentry * dentry = dget(item->ci_dentry);
368 struct configfs_dirent * parent_sd;
369 struct configfs_dirent * sd, * tmp;
374 pr_debug("configfs %s: dropping attrs for dir\n",
375 dentry->d_name.name);
377 parent_sd = dentry->d_fsdata;
378 list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
379 if (!sd->s_element || !(sd->s_type & CONFIGFS_NOT_PINNED))
381 list_del_init(&sd->s_sibling);
382 configfs_drop_dentry(sd, dentry);
387 * Drop reference from dget() on entrance.
392 static int populate_attrs(struct config_item *item)
394 struct config_item_type *t = item->ci_type;
395 struct configfs_attribute *attr;
402 for (i = 0; (attr = t->ct_attrs[i]) != NULL; i++) {
403 if ((error = configfs_create_file(item, attr)))
414 static int configfs_attach_group(struct config_item *parent_item,
415 struct config_item *item,
416 struct dentry *dentry);
417 static void configfs_detach_group(struct config_item *item);
419 static void detach_groups(struct config_group *group)
421 struct dentry * dentry = dget(group->cg_item.ci_dentry);
422 struct dentry *child;
423 struct configfs_dirent *parent_sd;
424 struct configfs_dirent *sd, *tmp;
429 parent_sd = dentry->d_fsdata;
430 list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
431 if (!sd->s_element ||
432 !(sd->s_type & CONFIGFS_USET_DEFAULT))
435 child = sd->s_dentry;
437 configfs_detach_group(sd->s_element);
438 child->d_inode->i_flags |= S_DEAD;
441 * From rmdir/unregister, a configfs_detach_prep() pass
442 * has taken our i_mutex for us. Drop it.
443 * From mkdir/register cleanup, there is no sem held.
445 if (sd->s_type & CONFIGFS_USET_DROPPING)
446 mutex_unlock(&child->d_inode->i_mutex);
453 * Drop reference from dget() on entrance.
459 * This fakes mkdir(2) on a default_groups[] entry. It
460 * creates a dentry, attachs it, and then does fixup
463 * We could, perhaps, tweak our parent's ->mkdir for a minute and
464 * try using vfs_mkdir. Just a thought.
466 static int create_default_group(struct config_group *parent_group,
467 struct config_group *group)
471 struct configfs_dirent *sd;
472 /* We trust the caller holds a reference to parent */
473 struct dentry *child, *parent = parent_group->cg_item.ci_dentry;
475 if (!group->cg_item.ci_name)
476 group->cg_item.ci_name = group->cg_item.ci_namebuf;
477 name.name = group->cg_item.ci_name;
478 name.len = strlen(name.name);
479 name.hash = full_name_hash(name.name, name.len);
482 child = d_alloc(parent, &name);
486 ret = configfs_attach_group(&parent_group->cg_item,
487 &group->cg_item, child);
489 sd = child->d_fsdata;
490 sd->s_type |= CONFIGFS_USET_DEFAULT;
500 static int populate_groups(struct config_group *group)
502 struct config_group *new_group;
503 struct dentry *dentry = group->cg_item.ci_dentry;
507 if (group->default_groups) {
509 * FYI, we're faking mkdir here
510 * I'm not sure we need this semaphore, as we're called
511 * from our parent's mkdir. That holds our parent's
512 * i_mutex, so afaik lookup cannot continue through our
513 * parent to find us, let alone mess with our tree.
514 * That said, taking our i_mutex is closer to mkdir
515 * emulation, and shouldn't hurt.
517 mutex_lock(&dentry->d_inode->i_mutex);
519 for (i = 0; group->default_groups[i]; i++) {
520 new_group = group->default_groups[i];
522 ret = create_default_group(group, new_group);
527 mutex_unlock(&dentry->d_inode->i_mutex);
531 detach_groups(group);
537 * All of link_obj/unlink_obj/link_group/unlink_group require that
538 * subsys->su_sem is held.
541 static void unlink_obj(struct config_item *item)
543 struct config_group *group;
545 group = item->ci_group;
547 list_del_init(&item->ci_entry);
549 item->ci_group = NULL;
550 item->ci_parent = NULL;
552 /* Drop the reference for ci_entry */
553 config_item_put(item);
555 /* Drop the reference for ci_parent */
556 config_group_put(group);
560 static void link_obj(struct config_item *parent_item, struct config_item *item)
563 * Parent seems redundant with group, but it makes certain
564 * traversals much nicer.
566 item->ci_parent = parent_item;
569 * We hold a reference on the parent for the child's ci_parent
572 item->ci_group = config_group_get(to_config_group(parent_item));
573 list_add_tail(&item->ci_entry, &item->ci_group->cg_children);
576 * We hold a reference on the child for ci_entry on the parent's
579 config_item_get(item);
582 static void unlink_group(struct config_group *group)
585 struct config_group *new_group;
587 if (group->default_groups) {
588 for (i = 0; group->default_groups[i]; i++) {
589 new_group = group->default_groups[i];
590 unlink_group(new_group);
594 group->cg_subsys = NULL;
595 unlink_obj(&group->cg_item);
598 static void link_group(struct config_group *parent_group, struct config_group *group)
601 struct config_group *new_group;
602 struct configfs_subsystem *subsys = NULL; /* gcc is a turd */
604 link_obj(&parent_group->cg_item, &group->cg_item);
606 if (parent_group->cg_subsys)
607 subsys = parent_group->cg_subsys;
608 else if (configfs_is_root(&parent_group->cg_item))
609 subsys = to_configfs_subsystem(group);
612 group->cg_subsys = subsys;
614 if (group->default_groups) {
615 for (i = 0; group->default_groups[i]; i++) {
616 new_group = group->default_groups[i];
617 link_group(group, new_group);
623 * The goal is that configfs_attach_item() (and
624 * configfs_attach_group()) can be called from either the VFS or this
625 * module. That is, they assume that the items have been created,
626 * the dentry allocated, and the dcache is all ready to go.
628 * If they fail, they must clean up after themselves as if they
629 * had never been called. The caller (VFS or local function) will
630 * handle cleaning up the dcache bits.
632 * configfs_detach_group() and configfs_detach_item() behave similarly on
633 * the way out. They assume that the proper semaphores are held, they
634 * clean up the configfs items, and they expect their callers will
635 * handle the dcache bits.
637 static int configfs_attach_item(struct config_item *parent_item,
638 struct config_item *item,
639 struct dentry *dentry)
643 ret = configfs_create_dir(item, dentry);
645 ret = populate_attrs(item);
647 configfs_remove_dir(item);
655 static void configfs_detach_item(struct config_item *item)
658 configfs_remove_dir(item);
661 static int configfs_attach_group(struct config_item *parent_item,
662 struct config_item *item,
663 struct dentry *dentry)
666 struct configfs_dirent *sd;
668 ret = configfs_attach_item(parent_item, item, dentry);
670 sd = dentry->d_fsdata;
671 sd->s_type |= CONFIGFS_USET_DIR;
673 ret = populate_groups(to_config_group(item));
675 configfs_detach_item(item);
683 static void configfs_detach_group(struct config_item *item)
685 detach_groups(to_config_group(item));
686 configfs_detach_item(item);
690 * Drop the initial reference from make_item()/make_group()
691 * This function assumes that reference is held on item
692 * and that item holds a valid reference to the parent. Also, it
693 * assumes the caller has validated ci_type.
695 static void client_drop_item(struct config_item *parent_item,
696 struct config_item *item)
698 struct config_item_type *type;
700 type = parent_item->ci_type;
704 * If ->drop_item() exists, it is responsible for the
707 if (type->ct_group_ops && type->ct_group_ops->drop_item)
708 type->ct_group_ops->drop_item(to_config_group(parent_item),
711 config_item_put(item);
715 static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
717 int ret, module_got = 0;
718 struct config_group *group;
719 struct config_item *item;
720 struct config_item *parent_item;
721 struct configfs_subsystem *subsys;
722 struct configfs_dirent *sd;
723 struct config_item_type *type;
724 struct module *owner = NULL;
727 if (dentry->d_parent == configfs_sb->s_root) {
732 sd = dentry->d_parent->d_fsdata;
733 if (!(sd->s_type & CONFIGFS_USET_DIR)) {
738 /* Get a working ref for the duration of this function */
739 parent_item = configfs_get_config_item(dentry->d_parent);
740 type = parent_item->ci_type;
741 subsys = to_config_group(parent_item)->cg_subsys;
744 if (!type || !type->ct_group_ops ||
745 (!type->ct_group_ops->make_group &&
746 !type->ct_group_ops->make_item)) {
747 ret = -EPERM; /* Lack-of-mkdir returns -EPERM */
751 name = kmalloc(dentry->d_name.len + 1, GFP_KERNEL);
757 snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
759 down(&subsys->su_sem);
762 if (type->ct_group_ops->make_group) {
763 group = type->ct_group_ops->make_group(to_config_group(parent_item), name);
765 link_group(to_config_group(parent_item), group);
766 item = &group->cg_item;
769 item = type->ct_group_ops->make_item(to_config_group(parent_item), name);
771 link_obj(parent_item, item);
778 * If item == NULL, then link_obj() was never called.
779 * There are no extra references to clean up.
786 * link_obj() has been called (via link_group() for groups).
787 * From here on out, errors must clean that up.
790 type = item->ci_type;
796 owner = type->ct_owner;
797 if (!try_module_get(owner)) {
803 * I hate doing it this way, but if there is
804 * an error, module_put() probably should
805 * happen after any cleanup.
810 ret = configfs_attach_group(parent_item, item, dentry);
812 ret = configfs_attach_item(parent_item, item, dentry);
816 /* Tear down everything we built up */
817 down(&subsys->su_sem);
822 client_drop_item(parent_item, item);
831 * link_obj()/link_group() took a reference from child->parent,
832 * so the parent is safely pinned. We can drop our working
835 config_item_put(parent_item);
841 static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
843 struct config_item *parent_item;
844 struct config_item *item;
845 struct configfs_subsystem *subsys;
846 struct configfs_dirent *sd;
847 struct module *owner = NULL;
850 if (dentry->d_parent == configfs_sb->s_root)
853 sd = dentry->d_fsdata;
854 if (sd->s_type & CONFIGFS_USET_DEFAULT)
857 /* Get a working ref until we have the child */
858 parent_item = configfs_get_config_item(dentry->d_parent);
859 subsys = to_config_group(parent_item)->cg_subsys;
862 if (!parent_item->ci_type) {
863 config_item_put(parent_item);
867 ret = configfs_detach_prep(dentry);
869 configfs_detach_rollback(dentry);
870 config_item_put(parent_item);
874 /* Get a working ref for the duration of this function */
875 item = configfs_get_config_item(dentry);
877 /* Drop reference from above, item already holds one. */
878 config_item_put(parent_item);
881 owner = item->ci_type->ct_owner;
883 if (sd->s_type & CONFIGFS_USET_DIR) {
884 configfs_detach_group(item);
886 down(&subsys->su_sem);
887 unlink_group(to_config_group(item));
889 configfs_detach_item(item);
891 down(&subsys->su_sem);
895 client_drop_item(parent_item, item);
898 /* Drop our reference from above */
899 config_item_put(item);
906 struct inode_operations configfs_dir_inode_operations = {
907 .mkdir = configfs_mkdir,
908 .rmdir = configfs_rmdir,
909 .symlink = configfs_symlink,
910 .unlink = configfs_unlink,
911 .lookup = configfs_lookup,
912 .setattr = configfs_setattr,
916 int configfs_rename_dir(struct config_item * item, const char *new_name)
919 struct dentry * new_dentry, * parent;
921 if (!strcmp(config_item_name(item), new_name))
927 down_write(&configfs_rename_sem);
928 parent = item->parent->dentry;
930 mutex_lock(&parent->d_inode->i_mutex);
932 new_dentry = lookup_one_len(new_name, parent, strlen(new_name));
933 if (!IS_ERR(new_dentry)) {
934 if (!new_dentry->d_inode) {
935 error = config_item_set_name(item, "%s", new_name);
937 d_add(new_dentry, NULL);
938 d_move(item->dentry, new_dentry);
941 d_delete(new_dentry);
946 mutex_unlock(&parent->d_inode->i_mutex);
947 up_write(&configfs_rename_sem);
953 static int configfs_dir_open(struct inode *inode, struct file *file)
955 struct dentry * dentry = file->f_dentry;
956 struct configfs_dirent * parent_sd = dentry->d_fsdata;
958 mutex_lock(&dentry->d_inode->i_mutex);
959 file->private_data = configfs_new_dirent(parent_sd, NULL);
960 mutex_unlock(&dentry->d_inode->i_mutex);
962 return file->private_data ? 0 : -ENOMEM;
966 static int configfs_dir_close(struct inode *inode, struct file *file)
968 struct dentry * dentry = file->f_dentry;
969 struct configfs_dirent * cursor = file->private_data;
971 mutex_lock(&dentry->d_inode->i_mutex);
972 list_del_init(&cursor->s_sibling);
973 mutex_unlock(&dentry->d_inode->i_mutex);
975 release_configfs_dirent(cursor);
980 /* Relationship between s_mode and the DT_xxx types */
981 static inline unsigned char dt_type(struct configfs_dirent *sd)
983 return (sd->s_mode >> 12) & 15;
986 static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
988 struct dentry *dentry = filp->f_dentry;
989 struct configfs_dirent * parent_sd = dentry->d_fsdata;
990 struct configfs_dirent *cursor = filp->private_data;
991 struct list_head *p, *q = &cursor->s_sibling;
997 ino = dentry->d_inode->i_ino;
998 if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
1004 ino = parent_ino(dentry);
1005 if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
1011 if (filp->f_pos == 2) {
1012 list_move(q, &parent_sd->s_children);
1014 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
1015 struct configfs_dirent *next;
1019 next = list_entry(p, struct configfs_dirent,
1021 if (!next->s_element)
1024 name = configfs_get_name(next);
1027 ino = next->s_dentry->d_inode->i_ino;
1029 ino = iunique(configfs_sb, 2);
1031 if (filldir(dirent, name, len, filp->f_pos, ino,
1043 static loff_t configfs_dir_lseek(struct file * file, loff_t offset, int origin)
1045 struct dentry * dentry = file->f_dentry;
1047 mutex_lock(&dentry->d_inode->i_mutex);
1050 offset += file->f_pos;
1055 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
1058 if (offset != file->f_pos) {
1059 file->f_pos = offset;
1060 if (file->f_pos >= 2) {
1061 struct configfs_dirent *sd = dentry->d_fsdata;
1062 struct configfs_dirent *cursor = file->private_data;
1063 struct list_head *p;
1064 loff_t n = file->f_pos - 2;
1066 list_del(&cursor->s_sibling);
1067 p = sd->s_children.next;
1068 while (n && p != &sd->s_children) {
1069 struct configfs_dirent *next;
1070 next = list_entry(p, struct configfs_dirent,
1072 if (next->s_element)
1076 list_add_tail(&cursor->s_sibling, p);
1079 mutex_unlock(&dentry->d_inode->i_mutex);
1083 const struct file_operations configfs_dir_operations = {
1084 .open = configfs_dir_open,
1085 .release = configfs_dir_close,
1086 .llseek = configfs_dir_lseek,
1087 .read = generic_read_dir,
1088 .readdir = configfs_readdir,
1091 int configfs_register_subsystem(struct configfs_subsystem *subsys)
1094 struct config_group *group = &subsys->su_group;
1096 struct dentry *dentry;
1097 struct configfs_dirent *sd;
1099 err = configfs_pin_fs();
1103 if (!group->cg_item.ci_name)
1104 group->cg_item.ci_name = group->cg_item.ci_namebuf;
1106 sd = configfs_sb->s_root->d_fsdata;
1107 link_group(to_config_group(sd->s_element), group);
1109 mutex_lock(&configfs_sb->s_root->d_inode->i_mutex);
1111 name.name = group->cg_item.ci_name;
1112 name.len = strlen(name.name);
1113 name.hash = full_name_hash(name.name, name.len);
1116 dentry = d_alloc(configfs_sb->s_root, &name);
1120 d_add(dentry, NULL);
1122 err = configfs_attach_group(sd->s_element, &group->cg_item,
1129 mutex_unlock(&configfs_sb->s_root->d_inode->i_mutex);
1134 unlink_group(group);
1135 configfs_release_fs();
1141 void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
1143 struct config_group *group = &subsys->su_group;
1144 struct dentry *dentry = group->cg_item.ci_dentry;
1146 if (dentry->d_parent != configfs_sb->s_root) {
1147 printk(KERN_ERR "configfs: Tried to unregister non-subsystem!\n");
1151 mutex_lock(&configfs_sb->s_root->d_inode->i_mutex);
1152 mutex_lock(&dentry->d_inode->i_mutex);
1153 if (configfs_detach_prep(dentry)) {
1154 printk(KERN_ERR "configfs: Tried to unregister non-empty subsystem!\n");
1156 configfs_detach_group(&group->cg_item);
1157 dentry->d_inode->i_flags |= S_DEAD;
1158 mutex_unlock(&dentry->d_inode->i_mutex);
1162 mutex_unlock(&configfs_sb->s_root->d_inode->i_mutex);
1166 unlink_group(group);
1167 configfs_release_fs();
1170 EXPORT_SYMBOL(configfs_register_subsystem);
1171 EXPORT_SYMBOL(configfs_unregister_subsystem);