Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * dir.c - Operations for configfs directories.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Based on sysfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * 	sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * configfs Copyright (C) 2005 Oracle.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/fsnotify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/configfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include "configfs_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * Protects mutations of configfs_dirent linkage together with proper i_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * Also protects mutations of symlinks linkage to target configfs_dirent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * Mutators of configfs_dirent linkage must *both* have the proper inode locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * and configfs_dirent_lock locked, in that order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * This allows one to safely traverse configfs_dirent trees and symlinks without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * having to lock inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * Protects setting of CONFIGFS_USET_DROPPING: checking the flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * unlocked is not reliable unless in detach_groups() called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * rmdir()/unregister() and from configfs_attach_group()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) DEFINE_SPINLOCK(configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  * All of link_obj/unlink_obj/link_group/unlink_group require that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * subsys->su_mutex is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * But parent configfs_subsystem is NULL when config_item is root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * Use this mutex when config_item is root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) static DEFINE_MUTEX(configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) static void configfs_d_iput(struct dentry * dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 			    struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	struct configfs_dirent *sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	if (sd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 		/* Coordinate with configfs_readdir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 		spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 		 * Set sd->s_dentry to null only when this dentry is the one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 		 * that is going to be killed.  Otherwise configfs_d_iput may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 		 * run just after configfs_attach_attr and set sd->s_dentry to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		 * NULL even it's still in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		if (sd->s_dentry == dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 			sd->s_dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		configfs_put(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) const struct dentry_operations configfs_dentry_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	.d_iput		= configfs_d_iput,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	.d_delete	= always_delete_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  * Helpers to make lockdep happy with our recursive locking of default groups'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  * inodes (see configfs_attach_group() and configfs_detach_group()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * We put default groups i_mutexes in separate classes according to their depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  * from the youngest non-default group ancestor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  * For a non-default group A having default groups A/B, A/C, and A/C/D, default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  * groups A/B and A/C will have their inode's mutex in class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  * default_group_class[0], and default group A/C/D will be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  * default_group_class[1].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  * The lock classes are declared and assigned in inode.c, according to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  * s_depth value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  * The s_depth value is initialized to -1, adjusted to >= 0 when attaching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * default groups, and reset to -1 when all default groups are attached. During
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * attachment, if configfs_create() sees s_depth > 0, the lock class of the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * inode's mutex is set to default_group_class[s_depth - 1].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static void configfs_init_dirent_depth(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	sd->s_depth = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) static void configfs_set_dir_dirent_depth(struct configfs_dirent *parent_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 					  struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	int parent_depth = parent_sd->s_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	if (parent_depth >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		sd->s_depth = parent_depth + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) configfs_adjust_dir_dirent_depth_before_populate(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	 * item's i_mutex class is already setup, so s_depth is now only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	 * used to set new sub-directories s_depth, which is always done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	 * with item's i_mutex locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	 *  sd->s_depth == -1 iff we are a non default group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	 *  else (we are a default group) sd->s_depth > 0 (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	 *  create_dir()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	if (sd->s_depth == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		 * We are a non default group and we are going to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		 * default groups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		sd->s_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) configfs_adjust_dir_dirent_depth_after_populate(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	/* We will not create default groups anymore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	sd->s_depth = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #else /* CONFIG_LOCKDEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static void configfs_init_dirent_depth(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static void configfs_set_dir_dirent_depth(struct configfs_dirent *parent_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 					  struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) configfs_adjust_dir_dirent_depth_before_populate(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) configfs_adjust_dir_dirent_depth_after_populate(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) #endif /* CONFIG_LOCKDEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static struct configfs_fragment *new_fragment(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	struct configfs_fragment *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	p = kmalloc(sizeof(struct configfs_fragment), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		atomic_set(&p->frag_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		init_rwsem(&p->frag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		p->frag_dead = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) void put_fragment(struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	if (frag && atomic_dec_and_test(&frag->frag_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		kfree(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) struct configfs_fragment *get_fragment(struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	if (likely(frag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		atomic_inc(&frag->frag_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	return frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  * Allocates a new configfs_dirent and links it to the parent configfs_dirent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) static struct configfs_dirent *configfs_new_dirent(struct configfs_dirent *parent_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 						   void *element, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 						   struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	struct configfs_dirent * sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	sd = kmem_cache_zalloc(configfs_dir_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	if (!sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	atomic_set(&sd->s_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	INIT_LIST_HEAD(&sd->s_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	sd->s_element = element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	sd->s_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	configfs_init_dirent_depth(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	if (parent_sd->s_type & CONFIGFS_USET_DROPPING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		kmem_cache_free(configfs_dir_cachep, sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	sd->s_frag = get_fragment(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	list_add(&sd->s_sibling, &parent_sd->s_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	return sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  * Return -EEXIST if there is already a configfs element with the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  * name for the same parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  * called with parent inode's i_mutex held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) static int configfs_dirent_exists(struct configfs_dirent *parent_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 				  const unsigned char *new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	struct configfs_dirent * sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		if (sd->s_element) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			const unsigned char *existing = configfs_get_name(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 			if (strcmp(existing, new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 				return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) int configfs_make_dirent(struct configfs_dirent * parent_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 			 struct dentry * dentry, void * element,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			 umode_t mode, int type, struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	struct configfs_dirent * sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	sd = configfs_new_dirent(parent_sd, element, type, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	if (IS_ERR(sd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		return PTR_ERR(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	sd->s_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	sd->s_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	if (dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		dentry->d_fsdata = configfs_get(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) static void configfs_remove_dirent(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	struct configfs_dirent *sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	if (!sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	list_del_init(&sd->s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	configfs_put(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)  *	configfs_create_dir - create a directory for an config_item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)  *	@item:		config_itemwe're creating directory for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277)  *	@dentry:	config_item's dentry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279)  *	Note: user-created entries won't be allowed under this new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280)  *	until it is validated by configfs_dir_set_ready()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) static int configfs_create_dir(struct config_item *item, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 				struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	struct dentry *p = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	BUG_ON(!item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	error = configfs_dirent_exists(p->d_fsdata, dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	error = configfs_make_dirent(p->d_fsdata, dentry, item, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 				     CONFIGFS_DIR | CONFIGFS_USET_CREATING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 				     frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	inode = configfs_create(dentry, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		goto out_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	inode->i_op = &configfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	inode->i_fop = &configfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	/* directory inodes start off with i_nlink == 2 (for "." entry) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	/* already hashed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	dget(dentry);  /* pin directory dentries in core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	inc_nlink(d_inode(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	item->ci_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) out_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	configfs_remove_dirent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325)  * Allow userspace to create new entries under a new directory created with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326)  * configfs_create_dir(), and under all of its chidlren directories recursively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327)  * @sd		configfs_dirent of the new directory to validate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329)  * Caller must hold configfs_dirent_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) static void configfs_dir_set_ready(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	struct configfs_dirent *child_sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	sd->s_type &= ~CONFIGFS_USET_CREATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	list_for_each_entry(child_sd, &sd->s_children, s_sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		if (child_sd->s_type & CONFIGFS_USET_CREATING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			configfs_dir_set_ready(child_sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342)  * Check that a directory does not belong to a directory hierarchy being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)  * attached and not validated yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344)  * @sd		configfs_dirent of the directory to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)  * @return	non-zero iff the directory was validated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)  * Note: takes configfs_dirent_lock, so the result may change from false to true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)  * in two consecutive calls, but never from true to false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) int configfs_dirent_is_ready(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	ret = !(sd->s_type & CONFIGFS_USET_CREATING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) int configfs_create_link(struct configfs_dirent *target, struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		struct dentry *dentry, char *body)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	umode_t mode = S_IFLNK | S_IRWXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	struct configfs_dirent *p = parent->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	err = configfs_make_dirent(p, dentry, target, mode, CONFIGFS_ITEM_LINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			p->s_frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	inode = configfs_create(dentry, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		goto out_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	inode->i_link = body;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	inode->i_op = &configfs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	dget(dentry);  /* pin link dentries in core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) out_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	configfs_remove_dirent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) static void remove_dir(struct dentry * d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	struct dentry * parent = dget(d->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	configfs_remove_dirent(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	if (d_really_is_positive(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		simple_rmdir(d_inode(parent),d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	pr_debug(" o %pd removing done (%d)\n", d, d_count(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  * configfs_remove_dir - remove an config_item's directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  * @item:	config_item we're removing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  * The only thing special about this is that we remove any files in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  * the directory before we remove the directory, and we've inlined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * what used to be configfs_rmdir() below, instead of calling separately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  * Caller holds the mutex of the item's inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) static void configfs_remove_dir(struct config_item * item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	struct dentry * dentry = dget(item->ci_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	remove_dir(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	 * Drop reference from dget() on entrance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) /* attaches attribute's configfs_dirent to the dentry corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431)  * attribute file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	struct configfs_attribute * attr = sd->s_element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	dentry->d_fsdata = configfs_get(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	sd->s_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	inode = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		configfs_put(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		inode->i_fop = &configfs_bin_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		inode->i_size = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		inode->i_fop = &configfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static struct dentry * configfs_lookup(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				       struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 				       unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	struct configfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	struct configfs_dirent * sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	 * Fake invisibility if dir belongs to a group/default groups hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	 * being attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	 * This forbids userspace to read/write attributes of items which may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	 * not complete their initialization, since the dentries of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	 * attributes won't be instantiated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	if (!configfs_dirent_is_ready(parent_sd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		if (sd->s_type & CONFIGFS_NOT_PINNED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			const unsigned char * name = configfs_get_name(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 			if (strcmp(name, dentry->d_name.name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			err = configfs_attach_attr(sd, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		 * If it doesn't exist and it isn't a NOT_PINNED item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		 * it must be negative.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		if (dentry->d_name.len > NAME_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		d_add(dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)  * Only subdirectories count here.  Files (CONFIGFS_NOT_PINNED) are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)  * attributes and are removed by rmdir().  We recurse, setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511)  * CONFIGFS_USET_DROPPING on all children that are candidates for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)  * default detach.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513)  * If there is an error, the caller will reset the flags via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)  * configfs_detach_rollback().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) static int configfs_detach_prep(struct dentry *dentry, struct dentry **wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	struct configfs_dirent *parent_sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	/* Mark that we're trying to drop the group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	parent_sd->s_type |= CONFIGFS_USET_DROPPING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	if (parent_sd->s_links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		if (!sd->s_element ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		    (sd->s_type & CONFIGFS_NOT_PINNED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		if (sd->s_type & CONFIGFS_USET_DEFAULT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 			/* Abort if racing with mkdir() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			if (sd->s_type & CONFIGFS_USET_IN_MKDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 				if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 					*wait= dget(sd->s_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 				return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			 * Yup, recursive.  If there's a problem, blame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			 * deep nesting of default_groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			ret = configfs_detach_prep(sd->s_dentry, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 			ret = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  * Walk the tree, resetting CONFIGFS_USET_DROPPING wherever it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) static void configfs_detach_rollback(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	struct configfs_dirent *parent_sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	parent_sd->s_type &= ~CONFIGFS_USET_DROPPING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	list_for_each_entry(sd, &parent_sd->s_children, s_sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		if (sd->s_type & CONFIGFS_USET_DEFAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 			configfs_detach_rollback(sd->s_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static void detach_attrs(struct config_item * item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	struct dentry * dentry = dget(item->ci_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	struct configfs_dirent * parent_sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct configfs_dirent * sd, * tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	pr_debug("configfs %s: dropping attrs for  dir\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		 dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	parent_sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		if (!sd->s_element || !(sd->s_type & CONFIGFS_NOT_PINNED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		list_del_init(&sd->s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		configfs_drop_dentry(sd, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		configfs_put(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	 * Drop reference from dget() on entrance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) static int populate_attrs(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	const struct config_item_type *t = item->ci_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	struct configfs_attribute *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	struct configfs_bin_attribute *bin_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	if (t->ct_attrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		for (i = 0; (attr = t->ct_attrs[i]) != NULL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			if ((error = configfs_create_file(item, attr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	if (t->ct_bin_attrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		for (i = 0; (bin_attr = t->ct_bin_attrs[i]) != NULL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			error = configfs_create_bin_file(item, bin_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 			if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		detach_attrs(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) static int configfs_attach_group(struct config_item *parent_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 				 struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 				 struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 				 struct configfs_fragment *frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) static void configfs_detach_group(struct config_item *item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) static void detach_groups(struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	struct dentry * dentry = dget(group->cg_item.ci_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	struct dentry *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	struct configfs_dirent *parent_sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	struct configfs_dirent *sd, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	parent_sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		if (!sd->s_element ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		    !(sd->s_type & CONFIGFS_USET_DEFAULT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		child = sd->s_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		inode_lock(d_inode(child));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		configfs_detach_group(sd->s_element);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		d_inode(child)->i_flags |= S_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		dont_mount(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		inode_unlock(d_inode(child));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		d_delete(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		dput(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	 * Drop reference from dget() on entrance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677)  * This fakes mkdir(2) on a default_groups[] entry.  It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678)  * creates a dentry, attachs it, and then does fixup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679)  * on the sd->s_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681)  * We could, perhaps, tweak our parent's ->mkdir for a minute and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682)  * try using vfs_mkdir.  Just a thought.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) static int create_default_group(struct config_group *parent_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 				struct config_group *group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 				struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	/* We trust the caller holds a reference to parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	struct dentry *child, *parent = parent_group->cg_item.ci_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	if (!group->cg_item.ci_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		group->cg_item.ci_name = group->cg_item.ci_namebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	child = d_alloc_name(parent, group->cg_item.ci_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		d_add(child, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		ret = configfs_attach_group(&parent_group->cg_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 					    &group->cg_item, child, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			sd = child->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			sd->s_type |= CONFIGFS_USET_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			BUG_ON(d_inode(child));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			d_drop(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			dput(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) static int populate_groups(struct config_group *group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			   struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	struct config_group *new_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	list_for_each_entry(new_group, &group->default_groups, group_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		ret = create_default_group(group, new_group, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			detach_groups(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) void configfs_remove_default_groups(struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	struct config_group *g, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	list_for_each_entry_safe(g, n, &group->default_groups, group_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		list_del(&g->group_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		config_item_put(&g->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) EXPORT_SYMBOL(configfs_remove_default_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)  * All of link_obj/unlink_obj/link_group/unlink_group require that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)  * subsys->su_mutex is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) static void unlink_obj(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	struct config_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	group = item->ci_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	if (group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		list_del_init(&item->ci_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		item->ci_group = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		item->ci_parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		/* Drop the reference for ci_entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		config_item_put(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		/* Drop the reference for ci_parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		config_group_put(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) static void link_obj(struct config_item *parent_item, struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	 * Parent seems redundant with group, but it makes certain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	 * traversals much nicer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	item->ci_parent = parent_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	 * We hold a reference on the parent for the child's ci_parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	 * link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	item->ci_group = config_group_get(to_config_group(parent_item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	list_add_tail(&item->ci_entry, &item->ci_group->cg_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	 * We hold a reference on the child for ci_entry on the parent's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	 * cg_children
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	config_item_get(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) static void unlink_group(struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	struct config_group *new_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	list_for_each_entry(new_group, &group->default_groups, group_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		unlink_group(new_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	group->cg_subsys = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	unlink_obj(&group->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) static void link_group(struct config_group *parent_group, struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	struct config_group *new_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	struct configfs_subsystem *subsys = NULL; /* gcc is a turd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	link_obj(&parent_group->cg_item, &group->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	if (parent_group->cg_subsys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		subsys = parent_group->cg_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	else if (configfs_is_root(&parent_group->cg_item))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		subsys = to_configfs_subsystem(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	group->cg_subsys = subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	list_for_each_entry(new_group, &group->default_groups, group_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		link_group(group, new_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821)  * The goal is that configfs_attach_item() (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)  * configfs_attach_group()) can be called from either the VFS or this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)  * module.  That is, they assume that the items have been created,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  * the dentry allocated, and the dcache is all ready to go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  * If they fail, they must clean up after themselves as if they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  * had never been called.  The caller (VFS or local function) will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)  * handle cleaning up the dcache bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)  * configfs_detach_group() and configfs_detach_item() behave similarly on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)  * the way out.  They assume that the proper semaphores are held, they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)  * clean up the configfs items, and they expect their callers will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833)  * handle the dcache bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) static int configfs_attach_item(struct config_item *parent_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 				struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 				struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 				struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	ret = configfs_create_dir(item, dentry, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		ret = populate_attrs(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 			 * We are going to remove an inode and its dentry but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			 * the VFS may already have hit and used them. Thus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			 * we must lock them as rmdir() would.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			inode_lock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			configfs_remove_dir(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			d_inode(dentry)->i_flags |= S_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 			dont_mount(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			d_delete(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) /* Caller holds the mutex of the item's inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) static void configfs_detach_item(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	detach_attrs(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	configfs_remove_dir(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) static int configfs_attach_group(struct config_item *parent_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 				 struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 				 struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 				 struct configfs_fragment *frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	ret = configfs_attach_item(parent_item, item, dentry, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		sd->s_type |= CONFIGFS_USET_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		 * FYI, we're faking mkdir in populate_groups()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		 * We must lock the group's inode to avoid races with the VFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		 * which can already hit the inode and try to add/remove entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		 * under it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		 * We must also lock the inode to remove it safely in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		 * error, as rmdir() would.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		configfs_adjust_dir_dirent_depth_before_populate(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		ret = populate_groups(to_config_group(item), frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			configfs_detach_item(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			d_inode(dentry)->i_flags |= S_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 			dont_mount(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		configfs_adjust_dir_dirent_depth_after_populate(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			d_delete(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) /* Caller holds the mutex of the group's inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) static void configfs_detach_group(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	detach_groups(to_config_group(item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	configfs_detach_item(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  * After the item has been detached from the filesystem view, we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  * ready to tear it out of the hierarchy.  Notify the client before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  * we do that so they can perform any cleanup that requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)  * navigating the hierarchy.  A client does not need to provide this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)  * callback.  The subsystem semaphore MUST be held by the caller, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)  * references must be valid for both items.  It also assumes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923)  * caller has validated ci_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) static void client_disconnect_notify(struct config_item *parent_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 				     struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	const struct config_item_type *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	type = parent_item->ci_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	BUG_ON(!type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	if (type->ct_group_ops && type->ct_group_ops->disconnect_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		type->ct_group_ops->disconnect_notify(to_config_group(parent_item),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 						      item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939)  * Drop the initial reference from make_item()/make_group()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940)  * This function assumes that reference is held on item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941)  * and that item holds a valid reference to the parent.  Also, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942)  * assumes the caller has validated ci_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) static void client_drop_item(struct config_item *parent_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			     struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	const struct config_item_type *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	type = parent_item->ci_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	BUG_ON(!type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	 * If ->drop_item() exists, it is responsible for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	 * config_item_put().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	if (type->ct_group_ops && type->ct_group_ops->drop_item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		type->ct_group_ops->drop_item(to_config_group(parent_item),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 					      item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		config_item_put(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) static void configfs_dump_one(struct configfs_dirent *sd, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	pr_info("%*s\"%s\":\n", level, " ", configfs_get_name(sd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) #define type_print(_type) if (sd->s_type & _type) pr_info("%*s %s\n", level, " ", #_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	type_print(CONFIGFS_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	type_print(CONFIGFS_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	type_print(CONFIGFS_ITEM_ATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	type_print(CONFIGFS_ITEM_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	type_print(CONFIGFS_USET_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	type_print(CONFIGFS_USET_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	type_print(CONFIGFS_USET_DROPPING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) #undef type_print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static int configfs_dump(struct configfs_dirent *sd, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	struct configfs_dirent *child_sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	configfs_dump_one(sd, level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	if (!(sd->s_type & (CONFIGFS_DIR|CONFIGFS_ROOT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	list_for_each_entry(child_sd, &sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		ret = configfs_dump(child_sd, level + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)  * configfs_depend_item() and configfs_undepend_item()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)  * WARNING: Do not call these from a configfs callback!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)  * This describes these functions and their helpers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)  * Allow another kernel system to depend on a config_item.  If this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)  * happens, the item cannot go away until the dependent can live without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)  * it.  The idea is to give client modules as simple an interface as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)  * possible.  When a system asks them to depend on an item, they just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)  * call configfs_depend_item().  If the item is live and the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)  * driver is in good shape, we'll happily do the work for them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  * Why is the locking complex?  Because configfs uses the VFS to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  * all locking, but this function is called outside the normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)  * VFS->configfs path.  So it must take VFS locks to prevent the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)  * VFS->configfs stuff (configfs_mkdir(), configfs_rmdir(), etc).  This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)  * why you can't call these functions underneath configfs callbacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)  * Note, btw, that this can be called at *any* time, even when a configfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)  * subsystem isn't registered, or when configfs is loading or unloading.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)  * Just like configfs_register_subsystem().  So we take the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)  * precautions.  We pin the filesystem.  We lock configfs_dirent_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)  * If we can find the target item in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)  * configfs tree, it must be part of the subsystem tree as well, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)  * do not need the subsystem semaphore.  Holding configfs_dirent_lock helps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)  * locking out mkdir() and rmdir(), who might be racing us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)  * configfs_depend_prep()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)  * Only subdirectories count here.  Files (CONFIGFS_NOT_PINNED) are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)  * attributes.  This is similar but not the same to configfs_detach_prep().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)  * Note that configfs_detach_prep() expects the parent to be locked when it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  * is called, but we lock the parent *inside* configfs_depend_prep().  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)  * do that so we can unlock it if we find nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)  * Here we do a depth-first search of the dentry hierarchy looking for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)  * our object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)  * We deliberately ignore items tagged as dropping since they are virtually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)  * dead, as well as items in the middle of attachment since they virtually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)  * do not exist yet. This completes the locking out of racing mkdir() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)  * rmdir().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)  * Note: subdirectories in the middle of attachment start with s_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)  * CONFIGFS_DIR|CONFIGFS_USET_CREATING set by create_dir().  When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)  * CONFIGFS_USET_CREATING is set, we ignore the item.  The actual set of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)  * s_type is in configfs_new_dirent(), which has configfs_dirent_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)  * If the target is not found, -ENOENT is bubbled up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)  * This adds a requirement that all config_items be unique!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)  * This is recursive.  There isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)  * much on the stack, though, so folks that need this function - be careful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)  * about your stack!  Patches will be accepted to make it iterative.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) static int configfs_depend_prep(struct dentry *origin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 				struct config_item *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	struct configfs_dirent *child_sd, *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	BUG_ON(!origin || !origin->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	sd = origin->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (sd->s_element == target)  /* Boo-yah */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	list_for_each_entry(child_sd, &sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		if ((child_sd->s_type & CONFIGFS_DIR) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		    !(child_sd->s_type & CONFIGFS_USET_DROPPING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		    !(child_sd->s_type & CONFIGFS_USET_CREATING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			ret = configfs_depend_prep(child_sd->s_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 						   target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 				goto out;  /* Child path boo-yah */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	/* We looped all our children and didn't find target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) static int configfs_do_depend_item(struct dentry *subsys_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 				   struct config_item *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	struct configfs_dirent *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	/* Scan the tree, return 0 if found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	ret = configfs_depend_prep(subsys_dentry, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		goto out_unlock_dirent_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	 * We are sure that the item is not about to be removed by rmdir(), and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	 * not in the middle of attachment by mkdir().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	p = target->ci_dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	p->s_dependent_count += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) out_unlock_dirent_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) static inline struct configfs_dirent *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) configfs_find_subsys_dentry(struct configfs_dirent *root_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			    struct config_item *subsys_item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	struct configfs_dirent *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	struct configfs_dirent *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	list_for_each_entry(p, &root_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		if (p->s_type & CONFIGFS_DIR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 		    p->s_element == subsys_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			ret = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) int configfs_depend_item(struct configfs_subsystem *subsys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			 struct config_item *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	struct configfs_dirent *subsys_sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	struct config_item *s_item = &subsys->su_group.cg_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	 * Pin the configfs filesystem.  This means we can safely access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	 * the root of the configfs filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	root = configfs_pin_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	if (IS_ERR(root))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		return PTR_ERR(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	 * Next, lock the root directory.  We're going to check that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	 * subsystem is really registered, and so we need to lock out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	 * configfs_[un]register_subsystem().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	inode_lock(d_inode(root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	subsys_sd = configfs_find_subsys_dentry(root->d_fsdata, s_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	if (!subsys_sd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		goto out_unlock_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	/* Ok, now we can trust subsys/s_item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	ret = configfs_do_depend_item(subsys_sd->s_dentry, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) out_unlock_fs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	inode_unlock(d_inode(root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	 * If we succeeded, the fs is pinned via other methods.  If not,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	 * we're done with it anyway.  So release_fs() is always right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	configfs_release_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) EXPORT_SYMBOL(configfs_depend_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  * Release the dependent linkage.  This is much simpler than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  * configfs_depend_item() because we know that the client driver is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)  * pinned, thus the subsystem is pinned, and therefore configfs is pinned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) void configfs_undepend_item(struct config_item *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	 * Since we can trust everything is pinned, we just need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	 * configfs_dirent_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	sd = target->ci_dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	BUG_ON(sd->s_dependent_count < 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	sd->s_dependent_count -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	 * After this unlock, we cannot trust the item to stay alive!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	 * DO NOT REFERENCE item after this unlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) EXPORT_SYMBOL(configfs_undepend_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)  * caller_subsys is a caller's subsystem not target's. This is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)  * determine if we should lock root and check subsys or not. When we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)  * in the same subsystem as our target there is no need to do locking as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)  * we know that subsys is valid and is not unregistered during this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)  * as we are called from callback of one of his children and VFS holds a lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)  * on some inode. Otherwise we have to lock our root to  ensure that target's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)  * subsystem it is not unregistered during this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 				  struct config_item *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	struct configfs_subsystem *target_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	struct config_group *root, *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	struct configfs_dirent *subsys_sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	int ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	/* Disallow this function for configfs root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	if (configfs_is_root(target))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	parent = target->ci_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	 * This may happen when someone is trying to depend root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	 * directory of some subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	if (configfs_is_root(&parent->cg_item)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		target_subsys = to_configfs_subsystem(to_config_group(target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		root = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 		target_subsys = parent->cg_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		/* Find a cofnigfs root as we may need it for locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		for (root = parent; !configfs_is_root(&root->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		     root = root->cg_item.ci_group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	if (target_subsys != caller_subsys) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		 * We are in other configfs subsystem, so we have to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		 * additional locking to prevent other subsystem from being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		 * unregistered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		inode_lock(d_inode(root->cg_item.ci_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		 * As we are trying to depend item from other subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		 * we have to check if this subsystem is still registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		subsys_sd = configfs_find_subsys_dentry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 				root->cg_item.ci_dentry->d_fsdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 				&target_subsys->su_group.cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		if (!subsys_sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 			goto out_root_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		subsys_sd = target_subsys->su_group.cg_item.ci_dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	/* Now we can execute core of depend item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	ret = configfs_do_depend_item(subsys_sd->s_dentry, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	if (target_subsys != caller_subsys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) out_root_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		 * We were called from subsystem other than our target so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		 * took some locks so now it's time to release them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		inode_unlock(d_inode(root->cg_item.ci_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) EXPORT_SYMBOL(configfs_depend_item_unlocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static int configfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	int module_got = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	struct config_group *group = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	struct config_item *item = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	struct config_item *parent_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	struct configfs_subsystem *subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	const struct config_item_type *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	struct module *subsys_owner = NULL, *new_item_owner = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	struct configfs_fragment *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	sd = dentry->d_parent->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	 * Fake invisibility if dir belongs to a group/default groups hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	 * being attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	if (!configfs_dirent_is_ready(sd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	if (!(sd->s_type & CONFIGFS_USET_DIR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	frag = new_fragment();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	if (!frag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	/* Get a working ref for the duration of this function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	parent_item = configfs_get_config_item(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	type = parent_item->ci_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	subsys = to_config_group(parent_item)->cg_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	BUG_ON(!subsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	if (!type || !type->ct_group_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	    (!type->ct_group_ops->make_group &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	     !type->ct_group_ops->make_item)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		ret = -EPERM;  /* Lack-of-mkdir returns -EPERM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	 * The subsystem may belong to a different module than the item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	 * being created.  We don't want to safely pin the new item but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	 * fail to pin the subsystem it sits under.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	if (!subsys->su_group.cg_item.ci_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	subsys_owner = subsys->su_group.cg_item.ci_type->ct_owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	if (!try_module_get(subsys_owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	name = kmalloc(dentry->d_name.len + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	if (!name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		goto out_subsys_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	if (type->ct_group_ops->make_group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		group = type->ct_group_ops->make_group(to_config_group(parent_item), name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		if (!group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			group = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		if (!IS_ERR(group)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 			link_group(to_config_group(parent_item), group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 			item = &group->cg_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			ret = PTR_ERR(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		item = type->ct_group_ops->make_item(to_config_group(parent_item), name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		if (!item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			item = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		if (!IS_ERR(item))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			link_obj(parent_item, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			ret = PTR_ERR(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	mutex_unlock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		 * If ret != 0, then link_obj() was never called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		 * There are no extra references to clean up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		goto out_subsys_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	 * link_obj() has been called (via link_group() for groups).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	 * From here on out, errors must clean that up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	type = item->ci_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	if (!type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		goto out_unlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	new_item_owner = type->ct_owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	if (!try_module_get(new_item_owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		goto out_unlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	 * I hate doing it this way, but if there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	 * an error,  module_put() probably should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	 * happen after any cleanup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	module_got = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	 * Make racing rmdir() fail if it did not tag parent with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	 * CONFIGFS_USET_DROPPING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	 * Note: if CONFIGFS_USET_DROPPING is already set, attach_group() will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	 * fail and let rmdir() terminate correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	/* This will make configfs_detach_prep() fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	sd->s_type |= CONFIGFS_USET_IN_MKDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	if (group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		ret = configfs_attach_group(parent_item, item, dentry, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		ret = configfs_attach_item(parent_item, item, dentry, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	/* inherit uid/gid from process creating the directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	    !gid_eq(current_fsgid(), GLOBAL_ROOT_GID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		struct iattr ia = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 			.ia_uid = current_fsuid(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 			.ia_gid = current_fsgid(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 			.ia_valid = ATTR_UID | ATTR_GID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		inode->i_uid = ia.ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		inode->i_gid = ia.ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		/* the above manual assignments skip the permission checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		configfs_setattr(dentry, &ia);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	sd->s_type &= ~CONFIGFS_USET_IN_MKDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		configfs_dir_set_ready(dentry->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) out_unlink:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		/* Tear down everything we built up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		client_disconnect_notify(parent_item, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		if (group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 			unlink_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 			unlink_obj(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		client_drop_item(parent_item, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		mutex_unlock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		if (module_got)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 			module_put(new_item_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) out_subsys_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		module_put(subsys_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	 * link_obj()/link_group() took a reference from child->parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	 * so the parent is safely pinned.  We can drop our working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	 * reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	config_item_put(parent_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	put_fragment(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	struct config_item *parent_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	struct config_item *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	struct configfs_subsystem *subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	struct configfs_fragment *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	struct module *subsys_owner = NULL, *dead_item_owner = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	if (sd->s_type & CONFIGFS_USET_DEFAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	/* Get a working ref until we have the child */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	parent_item = configfs_get_config_item(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	subsys = to_config_group(parent_item)->cg_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	BUG_ON(!subsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	if (!parent_item->ci_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 		config_item_put(parent_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	/* configfs_mkdir() shouldn't have allowed this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	BUG_ON(!subsys->su_group.cg_item.ci_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	subsys_owner = subsys->su_group.cg_item.ci_type->ct_owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	 * Ensure that no racing symlink() will make detach_prep() fail while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	 * the new link is temporarily attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 		struct dentry *wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		mutex_lock(&configfs_symlink_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 		spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		 * Here's where we check for dependents.  We're protected by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		 * configfs_dirent_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 		 * If no dependent, atomically tag the item as dropping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		ret = sd->s_dependent_count ? -EBUSY : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 			ret = configfs_detach_prep(dentry, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 				configfs_detach_rollback(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 		spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 		mutex_unlock(&configfs_symlink_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 			if (ret != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 				config_item_put(parent_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 			/* Wait until the racing operation terminates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			inode_lock(d_inode(wait));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 			inode_unlock(d_inode(wait));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			dput(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	} while (ret == -EAGAIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	frag = sd->s_frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	if (down_write_killable(&frag->frag_sem)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		configfs_detach_rollback(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		config_item_put(parent_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	frag->frag_dead = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	up_write(&frag->frag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	/* Get a working ref for the duration of this function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	item = configfs_get_config_item(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	/* Drop reference from above, item already holds one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	config_item_put(parent_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	if (item->ci_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		dead_item_owner = item->ci_type->ct_owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	if (sd->s_type & CONFIGFS_USET_DIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		configfs_detach_group(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		client_disconnect_notify(parent_item, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		unlink_group(to_config_group(item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		configfs_detach_item(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		client_disconnect_notify(parent_item, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		unlink_obj(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	client_drop_item(parent_item, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	mutex_unlock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	/* Drop our reference from above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	config_item_put(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	module_put(dead_item_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	module_put(subsys_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) const struct inode_operations configfs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	.mkdir		= configfs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	.rmdir		= configfs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	.symlink	= configfs_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	.unlink		= configfs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	.lookup		= configfs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	.setattr	= configfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) const struct inode_operations configfs_root_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	.lookup		= configfs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	.setattr	= configfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) static int configfs_dir_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	struct dentry * dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	struct configfs_dirent * parent_sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	inode_lock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	 * Fake invisibility if dir belongs to a group/default groups hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	 * being attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	if (configfs_dirent_is_ready(parent_sd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		file->private_data = configfs_new_dirent(parent_sd, NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		if (IS_ERR(file->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 			err = PTR_ERR(file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) static int configfs_dir_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	struct dentry * dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	struct configfs_dirent * cursor = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	inode_lock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	list_del_init(&cursor->s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	release_configfs_dirent(cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) /* Relationship between s_mode and the DT_xxx types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) static inline unsigned char dt_type(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	return (sd->s_mode >> 12) & 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) static int configfs_readdir(struct file *file, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	struct configfs_dirent * parent_sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	struct configfs_dirent *cursor = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	struct list_head *p, *q = &cursor->s_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	ino_t ino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	if (!dir_emit_dots(file, ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	if (ctx->pos == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 		list_move(q, &parent_sd->s_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	for (p = q->next; p != &parent_sd->s_children; p = p->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		struct configfs_dirent *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 		next = list_entry(p, struct configfs_dirent, s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 		if (!next->s_element)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 		 * We'll have a dentry and an inode for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		 * PINNED items and for open attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		 * files.  We lock here to prevent a race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		 * with configfs_d_iput() clearing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		 * s_dentry before calling iput().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		 * Why do we go to the trouble?  If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		 * someone has an attribute file open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 		 * the inode number should match until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		 * they close it.  Beyond that, we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		 * care.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		dentry = next->s_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		if (dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 			inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 			ino = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			ino = iunique(sb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		name = configfs_get_name(next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		if (!dir_emit(ctx, name, len, ino, dt_type(next)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		list_move(q, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		p = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		ctx->pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) static loff_t configfs_dir_lseek(struct file *file, loff_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	struct dentry * dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	switch (whence) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 			offset += file->f_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 			if (offset >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	if (offset != file->f_pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 		file->f_pos = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		if (file->f_pos >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 			struct configfs_dirent *sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 			struct configfs_dirent *cursor = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 			struct list_head *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 			loff_t n = file->f_pos - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 			spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 			list_del(&cursor->s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 			p = sd->s_children.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 			while (n && p != &sd->s_children) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 				struct configfs_dirent *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 				next = list_entry(p, struct configfs_dirent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 						   s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 				if (next->s_element)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 					n--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 				p = p->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 			list_add_tail(&cursor->s_sibling, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 			spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) const struct file_operations configfs_dir_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	.open		= configfs_dir_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	.release	= configfs_dir_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	.llseek		= configfs_dir_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	.read		= generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	.iterate_shared	= configfs_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)  * configfs_register_group - creates a parent-child relation between two groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)  * @parent_group:	parent group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)  * @group:		child group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)  * link groups, creates dentry for the child and attaches it to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)  * parent dentry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)  * Return: 0 on success, negative errno code on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) int configfs_register_group(struct config_group *parent_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 			    struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	struct configfs_subsystem *subsys = parent_group->cg_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	struct configfs_fragment *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	frag = new_fragment();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	if (!frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	link_group(parent_group, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	mutex_unlock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	parent = parent_group->cg_item.ci_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	ret = create_default_group(parent_group, group, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	configfs_dir_set_ready(group->cg_item.ci_dentry->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	inode_unlock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	put_fragment(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	inode_unlock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	unlink_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	mutex_unlock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	put_fragment(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) EXPORT_SYMBOL(configfs_register_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)  * configfs_unregister_group() - unregisters a child group from its parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)  * @group: parent group to be unregistered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)  * Undoes configfs_register_group()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) void configfs_unregister_group(struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	struct configfs_subsystem *subsys = group->cg_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	struct dentry *dentry = group->cg_item.ci_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	struct dentry *parent = group->cg_item.ci_parent->ci_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	struct configfs_dirent *sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	struct configfs_fragment *frag = sd->s_frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	down_write(&frag->frag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	frag->frag_dead = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	up_write(&frag->frag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	configfs_detach_prep(dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	configfs_detach_group(&group->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	d_inode(dentry)->i_flags |= S_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	dont_mount(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	fsnotify_rmdir(d_inode(parent), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	inode_unlock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	mutex_lock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	unlink_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	mutex_unlock(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) EXPORT_SYMBOL(configfs_unregister_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)  * configfs_register_default_group() - allocates and registers a child group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)  * @parent_group:	parent group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)  * @name:		child group name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)  * @item_type:		child item type description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)  * boilerplate to allocate and register a child group with its parent. We need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)  * kzalloc'ed memory because child's default_group is initially empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)  * Return: allocated config group or ERR_PTR() on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) struct config_group *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) configfs_register_default_group(struct config_group *parent_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 				const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 				const struct config_item_type *item_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	struct config_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	group = kzalloc(sizeof(*group), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	if (!group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	config_group_init_type_name(group, name, item_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	ret = configfs_register_group(parent_group, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	return group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) EXPORT_SYMBOL(configfs_register_default_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)  * configfs_unregister_default_group() - unregisters and frees a child group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)  * @group:	the group to act on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) void configfs_unregister_default_group(struct config_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	configfs_unregister_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	kfree(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) EXPORT_SYMBOL(configfs_unregister_default_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) int configfs_register_subsystem(struct configfs_subsystem *subsys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	struct config_group *group = &subsys->su_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	struct configfs_fragment *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	frag = new_fragment();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	if (!frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	root = configfs_pin_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	if (IS_ERR(root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		put_fragment(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		return PTR_ERR(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	if (!group->cg_item.ci_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 		group->cg_item.ci_name = group->cg_item.ci_namebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	sd = root->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	mutex_lock(&configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	link_group(to_config_group(sd->s_element), group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	mutex_unlock(&configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	inode_lock_nested(d_inode(root), I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	dentry = d_alloc_name(root, group->cg_item.ci_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	if (dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 		d_add(dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		err = configfs_attach_group(sd->s_element, &group->cg_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 					    dentry, frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 			BUG_ON(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 			d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 			dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 			configfs_dir_set_ready(dentry->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 			spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	inode_unlock(d_inode(root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		mutex_lock(&configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		unlink_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		mutex_unlock(&configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		configfs_release_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	put_fragment(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	struct config_group *group = &subsys->su_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	struct dentry *dentry = group->cg_item.ci_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	struct dentry *root = dentry->d_sb->s_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	struct configfs_dirent *sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	struct configfs_fragment *frag = sd->s_frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	if (dentry->d_parent != root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 		pr_err("Tried to unregister non-subsystem!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	down_write(&frag->frag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	frag->frag_dead = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	up_write(&frag->frag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	inode_lock_nested(d_inode(root),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 			  I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	mutex_lock(&configfs_symlink_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	if (configfs_detach_prep(dentry, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 		pr_err("Tried to unregister non-empty subsystem!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	mutex_unlock(&configfs_symlink_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	configfs_detach_group(&group->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 	d_inode(dentry)->i_flags |= S_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	dont_mount(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 	inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	fsnotify_rmdir(d_inode(root), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 	inode_unlock(d_inode(root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	mutex_lock(&configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	unlink_group(group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	mutex_unlock(&configfs_subsystem_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	configfs_release_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) EXPORT_SYMBOL(configfs_register_subsystem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) EXPORT_SYMBOL(configfs_unregister_subsystem);