dir.c 51 KB

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