namespace.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  1. /*
  2. * linux/fs/namespace.c
  3. *
  4. * (C) Copyright Al Viro 2000, 2001
  5. * Released under GPL v2.
  6. *
  7. * Based on code from fs/super.c, copyright Linus Torvalds and others.
  8. * Heavily rewritten.
  9. */
  10. #include <linux/syscalls.h>
  11. #include <linux/slab.h>
  12. #include <linux/sched.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/init.h>
  15. #include <linux/quotaops.h>
  16. #include <linux/acct.h>
  17. #include <linux/capability.h>
  18. #include <linux/module.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/namespace.h>
  21. #include <linux/namei.h>
  22. #include <linux/security.h>
  23. #include <linux/mount.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/unistd.h>
  26. #include "pnode.h"
  27. extern int __init init_rootfs(void);
  28. #ifdef CONFIG_SYSFS
  29. extern int __init sysfs_init(void);
  30. #else
  31. static inline int sysfs_init(void)
  32. {
  33. return 0;
  34. }
  35. #endif
  36. /* spinlock for vfsmount related operations, inplace of dcache_lock */
  37. __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
  38. static int event;
  39. static struct list_head *mount_hashtable __read_mostly;
  40. static int hash_mask __read_mostly, hash_bits __read_mostly;
  41. static kmem_cache_t *mnt_cache __read_mostly;
  42. static struct rw_semaphore namespace_sem;
  43. /* /sys/fs */
  44. decl_subsys(fs, NULL, NULL);
  45. EXPORT_SYMBOL_GPL(fs_subsys);
  46. static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
  47. {
  48. unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
  49. tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
  50. tmp = tmp + (tmp >> hash_bits);
  51. return tmp & hash_mask;
  52. }
  53. struct vfsmount *alloc_vfsmnt(const char *name)
  54. {
  55. struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL);
  56. if (mnt) {
  57. memset(mnt, 0, sizeof(struct vfsmount));
  58. atomic_set(&mnt->mnt_count, 1);
  59. INIT_LIST_HEAD(&mnt->mnt_hash);
  60. INIT_LIST_HEAD(&mnt->mnt_child);
  61. INIT_LIST_HEAD(&mnt->mnt_mounts);
  62. INIT_LIST_HEAD(&mnt->mnt_list);
  63. INIT_LIST_HEAD(&mnt->mnt_expire);
  64. INIT_LIST_HEAD(&mnt->mnt_share);
  65. INIT_LIST_HEAD(&mnt->mnt_slave_list);
  66. INIT_LIST_HEAD(&mnt->mnt_slave);
  67. if (name) {
  68. int size = strlen(name) + 1;
  69. char *newname = kmalloc(size, GFP_KERNEL);
  70. if (newname) {
  71. memcpy(newname, name, size);
  72. mnt->mnt_devname = newname;
  73. }
  74. }
  75. }
  76. return mnt;
  77. }
  78. int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
  79. {
  80. mnt->mnt_sb = sb;
  81. mnt->mnt_root = dget(sb->s_root);
  82. return 0;
  83. }
  84. EXPORT_SYMBOL(simple_set_mnt);
  85. void free_vfsmnt(struct vfsmount *mnt)
  86. {
  87. kfree(mnt->mnt_devname);
  88. kmem_cache_free(mnt_cache, mnt);
  89. }
  90. /*
  91. * find the first or last mount at @dentry on vfsmount @mnt depending on
  92. * @dir. If @dir is set return the first mount else return the last mount.
  93. */
  94. struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry,
  95. int dir)
  96. {
  97. struct list_head *head = mount_hashtable + hash(mnt, dentry);
  98. struct list_head *tmp = head;
  99. struct vfsmount *p, *found = NULL;
  100. for (;;) {
  101. tmp = dir ? tmp->next : tmp->prev;
  102. p = NULL;
  103. if (tmp == head)
  104. break;
  105. p = list_entry(tmp, struct vfsmount, mnt_hash);
  106. if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) {
  107. found = p;
  108. break;
  109. }
  110. }
  111. return found;
  112. }
  113. /*
  114. * lookup_mnt increments the ref count before returning
  115. * the vfsmount struct.
  116. */
  117. struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
  118. {
  119. struct vfsmount *child_mnt;
  120. spin_lock(&vfsmount_lock);
  121. if ((child_mnt = __lookup_mnt(mnt, dentry, 1)))
  122. mntget(child_mnt);
  123. spin_unlock(&vfsmount_lock);
  124. return child_mnt;
  125. }
  126. static inline int check_mnt(struct vfsmount *mnt)
  127. {
  128. return mnt->mnt_namespace == current->namespace;
  129. }
  130. static void touch_namespace(struct namespace *ns)
  131. {
  132. if (ns) {
  133. ns->event = ++event;
  134. wake_up_interruptible(&ns->poll);
  135. }
  136. }
  137. static void __touch_namespace(struct namespace *ns)
  138. {
  139. if (ns && ns->event != event) {
  140. ns->event = event;
  141. wake_up_interruptible(&ns->poll);
  142. }
  143. }
  144. static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd)
  145. {
  146. old_nd->dentry = mnt->mnt_mountpoint;
  147. old_nd->mnt = mnt->mnt_parent;
  148. mnt->mnt_parent = mnt;
  149. mnt->mnt_mountpoint = mnt->mnt_root;
  150. list_del_init(&mnt->mnt_child);
  151. list_del_init(&mnt->mnt_hash);
  152. old_nd->dentry->d_mounted--;
  153. }
  154. void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
  155. struct vfsmount *child_mnt)
  156. {
  157. child_mnt->mnt_parent = mntget(mnt);
  158. child_mnt->mnt_mountpoint = dget(dentry);
  159. dentry->d_mounted++;
  160. }
  161. static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd)
  162. {
  163. mnt_set_mountpoint(nd->mnt, nd->dentry, mnt);
  164. list_add_tail(&mnt->mnt_hash, mount_hashtable +
  165. hash(nd->mnt, nd->dentry));
  166. list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts);
  167. }
  168. /*
  169. * the caller must hold vfsmount_lock
  170. */
  171. static void commit_tree(struct vfsmount *mnt)
  172. {
  173. struct vfsmount *parent = mnt->mnt_parent;
  174. struct vfsmount *m;
  175. LIST_HEAD(head);
  176. struct namespace *n = parent->mnt_namespace;
  177. BUG_ON(parent == mnt);
  178. list_add_tail(&head, &mnt->mnt_list);
  179. list_for_each_entry(m, &head, mnt_list)
  180. m->mnt_namespace = n;
  181. list_splice(&head, n->list.prev);
  182. list_add_tail(&mnt->mnt_hash, mount_hashtable +
  183. hash(parent, mnt->mnt_mountpoint));
  184. list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
  185. touch_namespace(n);
  186. }
  187. static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
  188. {
  189. struct list_head *next = p->mnt_mounts.next;
  190. if (next == &p->mnt_mounts) {
  191. while (1) {
  192. if (p == root)
  193. return NULL;
  194. next = p->mnt_child.next;
  195. if (next != &p->mnt_parent->mnt_mounts)
  196. break;
  197. p = p->mnt_parent;
  198. }
  199. }
  200. return list_entry(next, struct vfsmount, mnt_child);
  201. }
  202. static struct vfsmount *skip_mnt_tree(struct vfsmount *p)
  203. {
  204. struct list_head *prev = p->mnt_mounts.prev;
  205. while (prev != &p->mnt_mounts) {
  206. p = list_entry(prev, struct vfsmount, mnt_child);
  207. prev = p->mnt_mounts.prev;
  208. }
  209. return p;
  210. }
  211. static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
  212. int flag)
  213. {
  214. struct super_block *sb = old->mnt_sb;
  215. struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
  216. if (mnt) {
  217. mnt->mnt_flags = old->mnt_flags;
  218. atomic_inc(&sb->s_active);
  219. mnt->mnt_sb = sb;
  220. mnt->mnt_root = dget(root);
  221. mnt->mnt_mountpoint = mnt->mnt_root;
  222. mnt->mnt_parent = mnt;
  223. if (flag & CL_SLAVE) {
  224. list_add(&mnt->mnt_slave, &old->mnt_slave_list);
  225. mnt->mnt_master = old;
  226. CLEAR_MNT_SHARED(mnt);
  227. } else {
  228. if ((flag & CL_PROPAGATION) || IS_MNT_SHARED(old))
  229. list_add(&mnt->mnt_share, &old->mnt_share);
  230. if (IS_MNT_SLAVE(old))
  231. list_add(&mnt->mnt_slave, &old->mnt_slave);
  232. mnt->mnt_master = old->mnt_master;
  233. }
  234. if (flag & CL_MAKE_SHARED)
  235. set_mnt_shared(mnt);
  236. /* stick the duplicate mount on the same expiry list
  237. * as the original if that was on one */
  238. if (flag & CL_EXPIRE) {
  239. spin_lock(&vfsmount_lock);
  240. if (!list_empty(&old->mnt_expire))
  241. list_add(&mnt->mnt_expire, &old->mnt_expire);
  242. spin_unlock(&vfsmount_lock);
  243. }
  244. }
  245. return mnt;
  246. }
  247. static inline void __mntput(struct vfsmount *mnt)
  248. {
  249. struct super_block *sb = mnt->mnt_sb;
  250. dput(mnt->mnt_root);
  251. free_vfsmnt(mnt);
  252. deactivate_super(sb);
  253. }
  254. void mntput_no_expire(struct vfsmount *mnt)
  255. {
  256. repeat:
  257. if (atomic_dec_and_lock(&mnt->mnt_count, &vfsmount_lock)) {
  258. if (likely(!mnt->mnt_pinned)) {
  259. spin_unlock(&vfsmount_lock);
  260. __mntput(mnt);
  261. return;
  262. }
  263. atomic_add(mnt->mnt_pinned + 1, &mnt->mnt_count);
  264. mnt->mnt_pinned = 0;
  265. spin_unlock(&vfsmount_lock);
  266. acct_auto_close_mnt(mnt);
  267. security_sb_umount_close(mnt);
  268. goto repeat;
  269. }
  270. }
  271. EXPORT_SYMBOL(mntput_no_expire);
  272. void mnt_pin(struct vfsmount *mnt)
  273. {
  274. spin_lock(&vfsmount_lock);
  275. mnt->mnt_pinned++;
  276. spin_unlock(&vfsmount_lock);
  277. }
  278. EXPORT_SYMBOL(mnt_pin);
  279. void mnt_unpin(struct vfsmount *mnt)
  280. {
  281. spin_lock(&vfsmount_lock);
  282. if (mnt->mnt_pinned) {
  283. atomic_inc(&mnt->mnt_count);
  284. mnt->mnt_pinned--;
  285. }
  286. spin_unlock(&vfsmount_lock);
  287. }
  288. EXPORT_SYMBOL(mnt_unpin);
  289. /* iterator */
  290. static void *m_start(struct seq_file *m, loff_t *pos)
  291. {
  292. struct namespace *n = m->private;
  293. struct list_head *p;
  294. loff_t l = *pos;
  295. down_read(&namespace_sem);
  296. list_for_each(p, &n->list)
  297. if (!l--)
  298. return list_entry(p, struct vfsmount, mnt_list);
  299. return NULL;
  300. }
  301. static void *m_next(struct seq_file *m, void *v, loff_t *pos)
  302. {
  303. struct namespace *n = m->private;
  304. struct list_head *p = ((struct vfsmount *)v)->mnt_list.next;
  305. (*pos)++;
  306. return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list);
  307. }
  308. static void m_stop(struct seq_file *m, void *v)
  309. {
  310. up_read(&namespace_sem);
  311. }
  312. static inline void mangle(struct seq_file *m, const char *s)
  313. {
  314. seq_escape(m, s, " \t\n\\");
  315. }
  316. static int show_vfsmnt(struct seq_file *m, void *v)
  317. {
  318. struct vfsmount *mnt = v;
  319. int err = 0;
  320. static struct proc_fs_info {
  321. int flag;
  322. char *str;
  323. } fs_info[] = {
  324. { MS_SYNCHRONOUS, ",sync" },
  325. { MS_DIRSYNC, ",dirsync" },
  326. { MS_MANDLOCK, ",mand" },
  327. { 0, NULL }
  328. };
  329. static struct proc_fs_info mnt_info[] = {
  330. { MNT_NOSUID, ",nosuid" },
  331. { MNT_NODEV, ",nodev" },
  332. { MNT_NOEXEC, ",noexec" },
  333. { MNT_NOATIME, ",noatime" },
  334. { MNT_NODIRATIME, ",nodiratime" },
  335. { 0, NULL }
  336. };
  337. struct proc_fs_info *fs_infop;
  338. mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
  339. seq_putc(m, ' ');
  340. seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
  341. seq_putc(m, ' ');
  342. mangle(m, mnt->mnt_sb->s_type->name);
  343. seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
  344. for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
  345. if (mnt->mnt_sb->s_flags & fs_infop->flag)
  346. seq_puts(m, fs_infop->str);
  347. }
  348. for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
  349. if (mnt->mnt_flags & fs_infop->flag)
  350. seq_puts(m, fs_infop->str);
  351. }
  352. if (mnt->mnt_sb->s_op->show_options)
  353. err = mnt->mnt_sb->s_op->show_options(m, mnt);
  354. seq_puts(m, " 0 0\n");
  355. return err;
  356. }
  357. struct seq_operations mounts_op = {
  358. .start = m_start,
  359. .next = m_next,
  360. .stop = m_stop,
  361. .show = show_vfsmnt
  362. };
  363. static int show_vfsstat(struct seq_file *m, void *v)
  364. {
  365. struct vfsmount *mnt = v;
  366. int err = 0;
  367. /* device */
  368. if (mnt->mnt_devname) {
  369. seq_puts(m, "device ");
  370. mangle(m, mnt->mnt_devname);
  371. } else
  372. seq_puts(m, "no device");
  373. /* mount point */
  374. seq_puts(m, " mounted on ");
  375. seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
  376. seq_putc(m, ' ');
  377. /* file system type */
  378. seq_puts(m, "with fstype ");
  379. mangle(m, mnt->mnt_sb->s_type->name);
  380. /* optional statistics */
  381. if (mnt->mnt_sb->s_op->show_stats) {
  382. seq_putc(m, ' ');
  383. err = mnt->mnt_sb->s_op->show_stats(m, mnt);
  384. }
  385. seq_putc(m, '\n');
  386. return err;
  387. }
  388. struct seq_operations mountstats_op = {
  389. .start = m_start,
  390. .next = m_next,
  391. .stop = m_stop,
  392. .show = show_vfsstat,
  393. };
  394. /**
  395. * may_umount_tree - check if a mount tree is busy
  396. * @mnt: root of mount tree
  397. *
  398. * This is called to check if a tree of mounts has any
  399. * open files, pwds, chroots or sub mounts that are
  400. * busy.
  401. */
  402. int may_umount_tree(struct vfsmount *mnt)
  403. {
  404. int actual_refs = 0;
  405. int minimum_refs = 0;
  406. struct vfsmount *p;
  407. spin_lock(&vfsmount_lock);
  408. for (p = mnt; p; p = next_mnt(p, mnt)) {
  409. actual_refs += atomic_read(&p->mnt_count);
  410. minimum_refs += 2;
  411. }
  412. spin_unlock(&vfsmount_lock);
  413. if (actual_refs > minimum_refs)
  414. return 0;
  415. return 1;
  416. }
  417. EXPORT_SYMBOL(may_umount_tree);
  418. /**
  419. * may_umount - check if a mount point is busy
  420. * @mnt: root of mount
  421. *
  422. * This is called to check if a mount point has any
  423. * open files, pwds, chroots or sub mounts. If the
  424. * mount has sub mounts this will return busy
  425. * regardless of whether the sub mounts are busy.
  426. *
  427. * Doesn't take quota and stuff into account. IOW, in some cases it will
  428. * give false negatives. The main reason why it's here is that we need
  429. * a non-destructive way to look for easily umountable filesystems.
  430. */
  431. int may_umount(struct vfsmount *mnt)
  432. {
  433. int ret = 1;
  434. spin_lock(&vfsmount_lock);
  435. if (propagate_mount_busy(mnt, 2))
  436. ret = 0;
  437. spin_unlock(&vfsmount_lock);
  438. return ret;
  439. }
  440. EXPORT_SYMBOL(may_umount);
  441. void release_mounts(struct list_head *head)
  442. {
  443. struct vfsmount *mnt;
  444. while (!list_empty(head)) {
  445. mnt = list_entry(head->next, struct vfsmount, mnt_hash);
  446. list_del_init(&mnt->mnt_hash);
  447. if (mnt->mnt_parent != mnt) {
  448. struct dentry *dentry;
  449. struct vfsmount *m;
  450. spin_lock(&vfsmount_lock);
  451. dentry = mnt->mnt_mountpoint;
  452. m = mnt->mnt_parent;
  453. mnt->mnt_mountpoint = mnt->mnt_root;
  454. mnt->mnt_parent = mnt;
  455. spin_unlock(&vfsmount_lock);
  456. dput(dentry);
  457. mntput(m);
  458. }
  459. mntput(mnt);
  460. }
  461. }
  462. void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
  463. {
  464. struct vfsmount *p;
  465. for (p = mnt; p; p = next_mnt(p, mnt))
  466. list_move(&p->mnt_hash, kill);
  467. if (propagate)
  468. propagate_umount(kill);
  469. list_for_each_entry(p, kill, mnt_hash) {
  470. list_del_init(&p->mnt_expire);
  471. list_del_init(&p->mnt_list);
  472. __touch_namespace(p->mnt_namespace);
  473. p->mnt_namespace = NULL;
  474. list_del_init(&p->mnt_child);
  475. if (p->mnt_parent != p)
  476. p->mnt_mountpoint->d_mounted--;
  477. change_mnt_propagation(p, MS_PRIVATE);
  478. }
  479. }
  480. static int do_umount(struct vfsmount *mnt, int flags)
  481. {
  482. struct super_block *sb = mnt->mnt_sb;
  483. int retval;
  484. LIST_HEAD(umount_list);
  485. retval = security_sb_umount(mnt, flags);
  486. if (retval)
  487. return retval;
  488. /*
  489. * Allow userspace to request a mountpoint be expired rather than
  490. * unmounting unconditionally. Unmount only happens if:
  491. * (1) the mark is already set (the mark is cleared by mntput())
  492. * (2) the usage count == 1 [parent vfsmount] + 1 [sys_umount]
  493. */
  494. if (flags & MNT_EXPIRE) {
  495. if (mnt == current->fs->rootmnt ||
  496. flags & (MNT_FORCE | MNT_DETACH))
  497. return -EINVAL;
  498. if (atomic_read(&mnt->mnt_count) != 2)
  499. return -EBUSY;
  500. if (!xchg(&mnt->mnt_expiry_mark, 1))
  501. return -EAGAIN;
  502. }
  503. /*
  504. * If we may have to abort operations to get out of this
  505. * mount, and they will themselves hold resources we must
  506. * allow the fs to do things. In the Unix tradition of
  507. * 'Gee thats tricky lets do it in userspace' the umount_begin
  508. * might fail to complete on the first run through as other tasks
  509. * must return, and the like. Thats for the mount program to worry
  510. * about for the moment.
  511. */
  512. lock_kernel();
  513. if (sb->s_op->umount_begin)
  514. sb->s_op->umount_begin(mnt, flags);
  515. unlock_kernel();
  516. /*
  517. * No sense to grab the lock for this test, but test itself looks
  518. * somewhat bogus. Suggestions for better replacement?
  519. * Ho-hum... In principle, we might treat that as umount + switch
  520. * to rootfs. GC would eventually take care of the old vfsmount.
  521. * Actually it makes sense, especially if rootfs would contain a
  522. * /reboot - static binary that would close all descriptors and
  523. * call reboot(9). Then init(8) could umount root and exec /reboot.
  524. */
  525. if (mnt == current->fs->rootmnt && !(flags & MNT_DETACH)) {
  526. /*
  527. * Special case for "unmounting" root ...
  528. * we just try to remount it readonly.
  529. */
  530. down_write(&sb->s_umount);
  531. if (!(sb->s_flags & MS_RDONLY)) {
  532. lock_kernel();
  533. DQUOT_OFF(sb);
  534. retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
  535. unlock_kernel();
  536. }
  537. up_write(&sb->s_umount);
  538. return retval;
  539. }
  540. down_write(&namespace_sem);
  541. spin_lock(&vfsmount_lock);
  542. event++;
  543. retval = -EBUSY;
  544. if (flags & MNT_DETACH || !propagate_mount_busy(mnt, 2)) {
  545. if (!list_empty(&mnt->mnt_list))
  546. umount_tree(mnt, 1, &umount_list);
  547. retval = 0;
  548. }
  549. spin_unlock(&vfsmount_lock);
  550. if (retval)
  551. security_sb_umount_busy(mnt);
  552. up_write(&namespace_sem);
  553. release_mounts(&umount_list);
  554. return retval;
  555. }
  556. /*
  557. * Now umount can handle mount points as well as block devices.
  558. * This is important for filesystems which use unnamed block devices.
  559. *
  560. * We now support a flag for forced unmount like the other 'big iron'
  561. * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
  562. */
  563. asmlinkage long sys_umount(char __user * name, int flags)
  564. {
  565. struct nameidata nd;
  566. int retval;
  567. retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
  568. if (retval)
  569. goto out;
  570. retval = -EINVAL;
  571. if (nd.dentry != nd.mnt->mnt_root)
  572. goto dput_and_out;
  573. if (!check_mnt(nd.mnt))
  574. goto dput_and_out;
  575. retval = -EPERM;
  576. if (!capable(CAP_SYS_ADMIN))
  577. goto dput_and_out;
  578. retval = do_umount(nd.mnt, flags);
  579. dput_and_out:
  580. path_release_on_umount(&nd);
  581. out:
  582. return retval;
  583. }
  584. #ifdef __ARCH_WANT_SYS_OLDUMOUNT
  585. /*
  586. * The 2.0 compatible umount. No flags.
  587. */
  588. asmlinkage long sys_oldumount(char __user * name)
  589. {
  590. return sys_umount(name, 0);
  591. }
  592. #endif
  593. static int mount_is_safe(struct nameidata *nd)
  594. {
  595. if (capable(CAP_SYS_ADMIN))
  596. return 0;
  597. return -EPERM;
  598. #ifdef notyet
  599. if (S_ISLNK(nd->dentry->d_inode->i_mode))
  600. return -EPERM;
  601. if (nd->dentry->d_inode->i_mode & S_ISVTX) {
  602. if (current->uid != nd->dentry->d_inode->i_uid)
  603. return -EPERM;
  604. }
  605. if (vfs_permission(nd, MAY_WRITE))
  606. return -EPERM;
  607. return 0;
  608. #endif
  609. }
  610. static int lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
  611. {
  612. while (1) {
  613. if (d == dentry)
  614. return 1;
  615. if (d == NULL || d == d->d_parent)
  616. return 0;
  617. d = d->d_parent;
  618. }
  619. }
  620. struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
  621. int flag)
  622. {
  623. struct vfsmount *res, *p, *q, *r, *s;
  624. struct nameidata nd;
  625. if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
  626. return NULL;
  627. res = q = clone_mnt(mnt, dentry, flag);
  628. if (!q)
  629. goto Enomem;
  630. q->mnt_mountpoint = mnt->mnt_mountpoint;
  631. p = mnt;
  632. list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) {
  633. if (!lives_below_in_same_fs(r->mnt_mountpoint, dentry))
  634. continue;
  635. for (s = r; s; s = next_mnt(s, r)) {
  636. if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(s)) {
  637. s = skip_mnt_tree(s);
  638. continue;
  639. }
  640. while (p != s->mnt_parent) {
  641. p = p->mnt_parent;
  642. q = q->mnt_parent;
  643. }
  644. p = s;
  645. nd.mnt = q;
  646. nd.dentry = p->mnt_mountpoint;
  647. q = clone_mnt(p, p->mnt_root, flag);
  648. if (!q)
  649. goto Enomem;
  650. spin_lock(&vfsmount_lock);
  651. list_add_tail(&q->mnt_list, &res->mnt_list);
  652. attach_mnt(q, &nd);
  653. spin_unlock(&vfsmount_lock);
  654. }
  655. }
  656. return res;
  657. Enomem:
  658. if (res) {
  659. LIST_HEAD(umount_list);
  660. spin_lock(&vfsmount_lock);
  661. umount_tree(res, 0, &umount_list);
  662. spin_unlock(&vfsmount_lock);
  663. release_mounts(&umount_list);
  664. }
  665. return NULL;
  666. }
  667. /*
  668. * @source_mnt : mount tree to be attached
  669. * @nd : place the mount tree @source_mnt is attached
  670. * @parent_nd : if non-null, detach the source_mnt from its parent and
  671. * store the parent mount and mountpoint dentry.
  672. * (done when source_mnt is moved)
  673. *
  674. * NOTE: in the table below explains the semantics when a source mount
  675. * of a given type is attached to a destination mount of a given type.
  676. * ---------------------------------------------------------------------------
  677. * | BIND MOUNT OPERATION |
  678. * |**************************************************************************
  679. * | source-->| shared | private | slave | unbindable |
  680. * | dest | | | | |
  681. * | | | | | | |
  682. * | v | | | | |
  683. * |**************************************************************************
  684. * | shared | shared (++) | shared (+) | shared(+++)| invalid |
  685. * | | | | | |
  686. * |non-shared| shared (+) | private | slave (*) | invalid |
  687. * ***************************************************************************
  688. * A bind operation clones the source mount and mounts the clone on the
  689. * destination mount.
  690. *
  691. * (++) the cloned mount is propagated to all the mounts in the propagation
  692. * tree of the destination mount and the cloned mount is added to
  693. * the peer group of the source mount.
  694. * (+) the cloned mount is created under the destination mount and is marked
  695. * as shared. The cloned mount is added to the peer group of the source
  696. * mount.
  697. * (+++) the mount is propagated to all the mounts in the propagation tree
  698. * of the destination mount and the cloned mount is made slave
  699. * of the same master as that of the source mount. The cloned mount
  700. * is marked as 'shared and slave'.
  701. * (*) the cloned mount is made a slave of the same master as that of the
  702. * source mount.
  703. *
  704. * ---------------------------------------------------------------------------
  705. * | MOVE MOUNT OPERATION |
  706. * |**************************************************************************
  707. * | source-->| shared | private | slave | unbindable |
  708. * | dest | | | | |
  709. * | | | | | | |
  710. * | v | | | | |
  711. * |**************************************************************************
  712. * | shared | shared (+) | shared (+) | shared(+++) | invalid |
  713. * | | | | | |
  714. * |non-shared| shared (+*) | private | slave (*) | unbindable |
  715. * ***************************************************************************
  716. *
  717. * (+) the mount is moved to the destination. And is then propagated to
  718. * all the mounts in the propagation tree of the destination mount.
  719. * (+*) the mount is moved to the destination.
  720. * (+++) the mount is moved to the destination and is then propagated to
  721. * all the mounts belonging to the destination mount's propagation tree.
  722. * the mount is marked as 'shared and slave'.
  723. * (*) the mount continues to be a slave at the new location.
  724. *
  725. * if the source mount is a tree, the operations explained above is
  726. * applied to each mount in the tree.
  727. * Must be called without spinlocks held, since this function can sleep
  728. * in allocations.
  729. */
  730. static int attach_recursive_mnt(struct vfsmount *source_mnt,
  731. struct nameidata *nd, struct nameidata *parent_nd)
  732. {
  733. LIST_HEAD(tree_list);
  734. struct vfsmount *dest_mnt = nd->mnt;
  735. struct dentry *dest_dentry = nd->dentry;
  736. struct vfsmount *child, *p;
  737. if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list))
  738. return -EINVAL;
  739. if (IS_MNT_SHARED(dest_mnt)) {
  740. for (p = source_mnt; p; p = next_mnt(p, source_mnt))
  741. set_mnt_shared(p);
  742. }
  743. spin_lock(&vfsmount_lock);
  744. if (parent_nd) {
  745. detach_mnt(source_mnt, parent_nd);
  746. attach_mnt(source_mnt, nd);
  747. touch_namespace(current->namespace);
  748. } else {
  749. mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
  750. commit_tree(source_mnt);
  751. }
  752. list_for_each_entry_safe(child, p, &tree_list, mnt_hash) {
  753. list_del_init(&child->mnt_hash);
  754. commit_tree(child);
  755. }
  756. spin_unlock(&vfsmount_lock);
  757. return 0;
  758. }
  759. static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
  760. {
  761. int err;
  762. if (mnt->mnt_sb->s_flags & MS_NOUSER)
  763. return -EINVAL;
  764. if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
  765. S_ISDIR(mnt->mnt_root->d_inode->i_mode))
  766. return -ENOTDIR;
  767. err = -ENOENT;
  768. mutex_lock(&nd->dentry->d_inode->i_mutex);
  769. if (IS_DEADDIR(nd->dentry->d_inode))
  770. goto out_unlock;
  771. err = security_sb_check_sb(mnt, nd);
  772. if (err)
  773. goto out_unlock;
  774. err = -ENOENT;
  775. if (IS_ROOT(nd->dentry) || !d_unhashed(nd->dentry))
  776. err = attach_recursive_mnt(mnt, nd, NULL);
  777. out_unlock:
  778. mutex_unlock(&nd->dentry->d_inode->i_mutex);
  779. if (!err)
  780. security_sb_post_addmount(mnt, nd);
  781. return err;
  782. }
  783. /*
  784. * recursively change the type of the mountpoint.
  785. */
  786. static int do_change_type(struct nameidata *nd, int flag)
  787. {
  788. struct vfsmount *m, *mnt = nd->mnt;
  789. int recurse = flag & MS_REC;
  790. int type = flag & ~MS_REC;
  791. if (nd->dentry != nd->mnt->mnt_root)
  792. return -EINVAL;
  793. down_write(&namespace_sem);
  794. spin_lock(&vfsmount_lock);
  795. for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
  796. change_mnt_propagation(m, type);
  797. spin_unlock(&vfsmount_lock);
  798. up_write(&namespace_sem);
  799. return 0;
  800. }
  801. /*
  802. * do loopback mount.
  803. */
  804. static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
  805. {
  806. struct nameidata old_nd;
  807. struct vfsmount *mnt = NULL;
  808. int err = mount_is_safe(nd);
  809. if (err)
  810. return err;
  811. if (!old_name || !*old_name)
  812. return -EINVAL;
  813. err = path_lookup(old_name, LOOKUP_FOLLOW, &old_nd);
  814. if (err)
  815. return err;
  816. down_write(&namespace_sem);
  817. err = -EINVAL;
  818. if (IS_MNT_UNBINDABLE(old_nd.mnt))
  819. goto out;
  820. if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
  821. goto out;
  822. err = -ENOMEM;
  823. if (recurse)
  824. mnt = copy_tree(old_nd.mnt, old_nd.dentry, 0);
  825. else
  826. mnt = clone_mnt(old_nd.mnt, old_nd.dentry, 0);
  827. if (!mnt)
  828. goto out;
  829. err = graft_tree(mnt, nd);
  830. if (err) {
  831. LIST_HEAD(umount_list);
  832. spin_lock(&vfsmount_lock);
  833. umount_tree(mnt, 0, &umount_list);
  834. spin_unlock(&vfsmount_lock);
  835. release_mounts(&umount_list);
  836. }
  837. out:
  838. up_write(&namespace_sem);
  839. path_release(&old_nd);
  840. return err;
  841. }
  842. /*
  843. * change filesystem flags. dir should be a physical root of filesystem.
  844. * If you've mounted a non-root directory somewhere and want to do remount
  845. * on it - tough luck.
  846. */
  847. static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
  848. void *data)
  849. {
  850. int err;
  851. struct super_block *sb = nd->mnt->mnt_sb;
  852. if (!capable(CAP_SYS_ADMIN))
  853. return -EPERM;
  854. if (!check_mnt(nd->mnt))
  855. return -EINVAL;
  856. if (nd->dentry != nd->mnt->mnt_root)
  857. return -EINVAL;
  858. down_write(&sb->s_umount);
  859. err = do_remount_sb(sb, flags, data, 0);
  860. if (!err)
  861. nd->mnt->mnt_flags = mnt_flags;
  862. up_write(&sb->s_umount);
  863. if (!err)
  864. security_sb_post_remount(nd->mnt, flags, data);
  865. return err;
  866. }
  867. static inline int tree_contains_unbindable(struct vfsmount *mnt)
  868. {
  869. struct vfsmount *p;
  870. for (p = mnt; p; p = next_mnt(p, mnt)) {
  871. if (IS_MNT_UNBINDABLE(p))
  872. return 1;
  873. }
  874. return 0;
  875. }
  876. static int do_move_mount(struct nameidata *nd, char *old_name)
  877. {
  878. struct nameidata old_nd, parent_nd;
  879. struct vfsmount *p;
  880. int err = 0;
  881. if (!capable(CAP_SYS_ADMIN))
  882. return -EPERM;
  883. if (!old_name || !*old_name)
  884. return -EINVAL;
  885. err = path_lookup(old_name, LOOKUP_FOLLOW, &old_nd);
  886. if (err)
  887. return err;
  888. down_write(&namespace_sem);
  889. while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
  890. ;
  891. err = -EINVAL;
  892. if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
  893. goto out;
  894. err = -ENOENT;
  895. mutex_lock(&nd->dentry->d_inode->i_mutex);
  896. if (IS_DEADDIR(nd->dentry->d_inode))
  897. goto out1;
  898. if (!IS_ROOT(nd->dentry) && d_unhashed(nd->dentry))
  899. goto out1;
  900. err = -EINVAL;
  901. if (old_nd.dentry != old_nd.mnt->mnt_root)
  902. goto out1;
  903. if (old_nd.mnt == old_nd.mnt->mnt_parent)
  904. goto out1;
  905. if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
  906. S_ISDIR(old_nd.dentry->d_inode->i_mode))
  907. goto out1;
  908. /*
  909. * Don't move a mount residing in a shared parent.
  910. */
  911. if (old_nd.mnt->mnt_parent && IS_MNT_SHARED(old_nd.mnt->mnt_parent))
  912. goto out1;
  913. /*
  914. * Don't move a mount tree containing unbindable mounts to a destination
  915. * mount which is shared.
  916. */
  917. if (IS_MNT_SHARED(nd->mnt) && tree_contains_unbindable(old_nd.mnt))
  918. goto out1;
  919. err = -ELOOP;
  920. for (p = nd->mnt; p->mnt_parent != p; p = p->mnt_parent)
  921. if (p == old_nd.mnt)
  922. goto out1;
  923. if ((err = attach_recursive_mnt(old_nd.mnt, nd, &parent_nd)))
  924. goto out1;
  925. spin_lock(&vfsmount_lock);
  926. /* if the mount is moved, it should no longer be expire
  927. * automatically */
  928. list_del_init(&old_nd.mnt->mnt_expire);
  929. spin_unlock(&vfsmount_lock);
  930. out1:
  931. mutex_unlock(&nd->dentry->d_inode->i_mutex);
  932. out:
  933. up_write(&namespace_sem);
  934. if (!err)
  935. path_release(&parent_nd);
  936. path_release(&old_nd);
  937. return err;
  938. }
  939. /*
  940. * create a new mount for userspace and request it to be added into the
  941. * namespace's tree
  942. */
  943. static int do_new_mount(struct nameidata *nd, char *type, int flags,
  944. int mnt_flags, char *name, void *data)
  945. {
  946. struct vfsmount *mnt;
  947. if (!type || !memchr(type, 0, PAGE_SIZE))
  948. return -EINVAL;
  949. /* we need capabilities... */
  950. if (!capable(CAP_SYS_ADMIN))
  951. return -EPERM;
  952. mnt = do_kern_mount(type, flags, name, data);
  953. if (IS_ERR(mnt))
  954. return PTR_ERR(mnt);
  955. return do_add_mount(mnt, nd, mnt_flags, NULL);
  956. }
  957. /*
  958. * add a mount into a namespace's mount tree
  959. * - provide the option of adding the new mount to an expiration list
  960. */
  961. int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
  962. int mnt_flags, struct list_head *fslist)
  963. {
  964. int err;
  965. down_write(&namespace_sem);
  966. /* Something was mounted here while we slept */
  967. while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
  968. ;
  969. err = -EINVAL;
  970. if (!check_mnt(nd->mnt))
  971. goto unlock;
  972. /* Refuse the same filesystem on the same mount point */
  973. err = -EBUSY;
  974. if (nd->mnt->mnt_sb == newmnt->mnt_sb &&
  975. nd->mnt->mnt_root == nd->dentry)
  976. goto unlock;
  977. err = -EINVAL;
  978. if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
  979. goto unlock;
  980. newmnt->mnt_flags = mnt_flags;
  981. if ((err = graft_tree(newmnt, nd)))
  982. goto unlock;
  983. if (fslist) {
  984. /* add to the specified expiration list */
  985. spin_lock(&vfsmount_lock);
  986. list_add_tail(&newmnt->mnt_expire, fslist);
  987. spin_unlock(&vfsmount_lock);
  988. }
  989. up_write(&namespace_sem);
  990. return 0;
  991. unlock:
  992. up_write(&namespace_sem);
  993. mntput(newmnt);
  994. return err;
  995. }
  996. EXPORT_SYMBOL_GPL(do_add_mount);
  997. static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
  998. struct list_head *umounts)
  999. {
  1000. spin_lock(&vfsmount_lock);
  1001. /*
  1002. * Check if mount is still attached, if not, let whoever holds it deal
  1003. * with the sucker
  1004. */
  1005. if (mnt->mnt_parent == mnt) {
  1006. spin_unlock(&vfsmount_lock);
  1007. return;
  1008. }
  1009. /*
  1010. * Check that it is still dead: the count should now be 2 - as
  1011. * contributed by the vfsmount parent and the mntget above
  1012. */
  1013. if (!propagate_mount_busy(mnt, 2)) {
  1014. /* delete from the namespace */
  1015. touch_namespace(mnt->mnt_namespace);
  1016. list_del_init(&mnt->mnt_list);
  1017. mnt->mnt_namespace = NULL;
  1018. umount_tree(mnt, 1, umounts);
  1019. spin_unlock(&vfsmount_lock);
  1020. } else {
  1021. /*
  1022. * Someone brought it back to life whilst we didn't have any
  1023. * locks held so return it to the expiration list
  1024. */
  1025. list_add_tail(&mnt->mnt_expire, mounts);
  1026. spin_unlock(&vfsmount_lock);
  1027. }
  1028. }
  1029. /*
  1030. * go through the vfsmounts we've just consigned to the graveyard to
  1031. * - check that they're still dead
  1032. * - delete the vfsmount from the appropriate namespace under lock
  1033. * - dispose of the corpse
  1034. */
  1035. static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
  1036. {
  1037. struct namespace *namespace;
  1038. struct vfsmount *mnt;
  1039. while (!list_empty(graveyard)) {
  1040. LIST_HEAD(umounts);
  1041. mnt = list_entry(graveyard->next, struct vfsmount, mnt_expire);
  1042. list_del_init(&mnt->mnt_expire);
  1043. /* don't do anything if the namespace is dead - all the
  1044. * vfsmounts from it are going away anyway */
  1045. namespace = mnt->mnt_namespace;
  1046. if (!namespace || !namespace->root)
  1047. continue;
  1048. get_namespace(namespace);
  1049. spin_unlock(&vfsmount_lock);
  1050. down_write(&namespace_sem);
  1051. expire_mount(mnt, mounts, &umounts);
  1052. up_write(&namespace_sem);
  1053. release_mounts(&umounts);
  1054. mntput(mnt);
  1055. put_namespace(namespace);
  1056. spin_lock(&vfsmount_lock);
  1057. }
  1058. }
  1059. /*
  1060. * process a list of expirable mountpoints with the intent of discarding any
  1061. * mountpoints that aren't in use and haven't been touched since last we came
  1062. * here
  1063. */
  1064. void mark_mounts_for_expiry(struct list_head *mounts)
  1065. {
  1066. struct vfsmount *mnt, *next;
  1067. LIST_HEAD(graveyard);
  1068. if (list_empty(mounts))
  1069. return;
  1070. spin_lock(&vfsmount_lock);
  1071. /* extract from the expiration list every vfsmount that matches the
  1072. * following criteria:
  1073. * - only referenced by its parent vfsmount
  1074. * - still marked for expiry (marked on the last call here; marks are
  1075. * cleared by mntput())
  1076. */
  1077. list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
  1078. if (!xchg(&mnt->mnt_expiry_mark, 1) ||
  1079. atomic_read(&mnt->mnt_count) != 1)
  1080. continue;
  1081. mntget(mnt);
  1082. list_move(&mnt->mnt_expire, &graveyard);
  1083. }
  1084. expire_mount_list(&graveyard, mounts);
  1085. spin_unlock(&vfsmount_lock);
  1086. }
  1087. EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
  1088. /*
  1089. * Ripoff of 'select_parent()'
  1090. *
  1091. * search the list of submounts for a given mountpoint, and move any
  1092. * shrinkable submounts to the 'graveyard' list.
  1093. */
  1094. static int select_submounts(struct vfsmount *parent, struct list_head *graveyard)
  1095. {
  1096. struct vfsmount *this_parent = parent;
  1097. struct list_head *next;
  1098. int found = 0;
  1099. repeat:
  1100. next = this_parent->mnt_mounts.next;
  1101. resume:
  1102. while (next != &this_parent->mnt_mounts) {
  1103. struct list_head *tmp = next;
  1104. struct vfsmount *mnt = list_entry(tmp, struct vfsmount, mnt_child);
  1105. next = tmp->next;
  1106. if (!(mnt->mnt_flags & MNT_SHRINKABLE))
  1107. continue;
  1108. /*
  1109. * Descend a level if the d_mounts list is non-empty.
  1110. */
  1111. if (!list_empty(&mnt->mnt_mounts)) {
  1112. this_parent = mnt;
  1113. goto repeat;
  1114. }
  1115. if (!propagate_mount_busy(mnt, 1)) {
  1116. mntget(mnt);
  1117. list_move_tail(&mnt->mnt_expire, graveyard);
  1118. found++;
  1119. }
  1120. }
  1121. /*
  1122. * All done at this level ... ascend and resume the search
  1123. */
  1124. if (this_parent != parent) {
  1125. next = this_parent->mnt_child.next;
  1126. this_parent = this_parent->mnt_parent;
  1127. goto resume;
  1128. }
  1129. return found;
  1130. }
  1131. /*
  1132. * process a list of expirable mountpoints with the intent of discarding any
  1133. * submounts of a specific parent mountpoint
  1134. */
  1135. void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts)
  1136. {
  1137. LIST_HEAD(graveyard);
  1138. int found;
  1139. spin_lock(&vfsmount_lock);
  1140. /* extract submounts of 'mountpoint' from the expiration list */
  1141. while ((found = select_submounts(mountpoint, &graveyard)) != 0)
  1142. expire_mount_list(&graveyard, mounts);
  1143. spin_unlock(&vfsmount_lock);
  1144. }
  1145. EXPORT_SYMBOL_GPL(shrink_submounts);
  1146. /*
  1147. * Some copy_from_user() implementations do not return the exact number of
  1148. * bytes remaining to copy on a fault. But copy_mount_options() requires that.
  1149. * Note that this function differs from copy_from_user() in that it will oops
  1150. * on bad values of `to', rather than returning a short copy.
  1151. */
  1152. static long exact_copy_from_user(void *to, const void __user * from,
  1153. unsigned long n)
  1154. {
  1155. char *t = to;
  1156. const char __user *f = from;
  1157. char c;
  1158. if (!access_ok(VERIFY_READ, from, n))
  1159. return n;
  1160. while (n) {
  1161. if (__get_user(c, f)) {
  1162. memset(t, 0, n);
  1163. break;
  1164. }
  1165. *t++ = c;
  1166. f++;
  1167. n--;
  1168. }
  1169. return n;
  1170. }
  1171. int copy_mount_options(const void __user * data, unsigned long *where)
  1172. {
  1173. int i;
  1174. unsigned long page;
  1175. unsigned long size;
  1176. *where = 0;
  1177. if (!data)
  1178. return 0;
  1179. if (!(page = __get_free_page(GFP_KERNEL)))
  1180. return -ENOMEM;
  1181. /* We only care that *some* data at the address the user
  1182. * gave us is valid. Just in case, we'll zero
  1183. * the remainder of the page.
  1184. */
  1185. /* copy_from_user cannot cross TASK_SIZE ! */
  1186. size = TASK_SIZE - (unsigned long)data;
  1187. if (size > PAGE_SIZE)
  1188. size = PAGE_SIZE;
  1189. i = size - exact_copy_from_user((void *)page, data, size);
  1190. if (!i) {
  1191. free_page(page);
  1192. return -EFAULT;
  1193. }
  1194. if (i != PAGE_SIZE)
  1195. memset((char *)page + i, 0, PAGE_SIZE - i);
  1196. *where = page;
  1197. return 0;
  1198. }
  1199. /*
  1200. * Flags is a 32-bit value that allows up to 31 non-fs dependent flags to
  1201. * be given to the mount() call (ie: read-only, no-dev, no-suid etc).
  1202. *
  1203. * data is a (void *) that can point to any structure up to
  1204. * PAGE_SIZE-1 bytes, which can contain arbitrary fs-dependent
  1205. * information (or be NULL).
  1206. *
  1207. * Pre-0.97 versions of mount() didn't have a flags word.
  1208. * When the flags word was introduced its top half was required
  1209. * to have the magic value 0xC0ED, and this remained so until 2.4.0-test9.
  1210. * Therefore, if this magic number is present, it carries no information
  1211. * and must be discarded.
  1212. */
  1213. long do_mount(char *dev_name, char *dir_name, char *type_page,
  1214. unsigned long flags, void *data_page)
  1215. {
  1216. struct nameidata nd;
  1217. int retval = 0;
  1218. int mnt_flags = 0;
  1219. /* Discard magic */
  1220. if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
  1221. flags &= ~MS_MGC_MSK;
  1222. /* Basic sanity checks */
  1223. if (!dir_name || !*dir_name || !memchr(dir_name, 0, PAGE_SIZE))
  1224. return -EINVAL;
  1225. if (dev_name && !memchr(dev_name, 0, PAGE_SIZE))
  1226. return -EINVAL;
  1227. if (data_page)
  1228. ((char *)data_page)[PAGE_SIZE - 1] = 0;
  1229. /* Separate the per-mountpoint flags */
  1230. if (flags & MS_NOSUID)
  1231. mnt_flags |= MNT_NOSUID;
  1232. if (flags & MS_NODEV)
  1233. mnt_flags |= MNT_NODEV;
  1234. if (flags & MS_NOEXEC)
  1235. mnt_flags |= MNT_NOEXEC;
  1236. if (flags & MS_NOATIME)
  1237. mnt_flags |= MNT_NOATIME;
  1238. if (flags & MS_NODIRATIME)
  1239. mnt_flags |= MNT_NODIRATIME;
  1240. flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
  1241. MS_NOATIME | MS_NODIRATIME);
  1242. /* ... and get the mountpoint */
  1243. retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
  1244. if (retval)
  1245. return retval;
  1246. retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
  1247. if (retval)
  1248. goto dput_out;
  1249. if (flags & MS_REMOUNT)
  1250. retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
  1251. data_page);
  1252. else if (flags & MS_BIND)
  1253. retval = do_loopback(&nd, dev_name, flags & MS_REC);
  1254. else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
  1255. retval = do_change_type(&nd, flags);
  1256. else if (flags & MS_MOVE)
  1257. retval = do_move_mount(&nd, dev_name);
  1258. else
  1259. retval = do_new_mount(&nd, type_page, flags, mnt_flags,
  1260. dev_name, data_page);
  1261. dput_out:
  1262. path_release(&nd);
  1263. return retval;
  1264. }
  1265. /*
  1266. * Allocate a new namespace structure and populate it with contents
  1267. * copied from the namespace of the passed in task structure.
  1268. */
  1269. struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
  1270. {
  1271. struct namespace *namespace = tsk->namespace;
  1272. struct namespace *new_ns;
  1273. struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
  1274. struct vfsmount *p, *q;
  1275. new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
  1276. if (!new_ns)
  1277. return NULL;
  1278. atomic_set(&new_ns->count, 1);
  1279. INIT_LIST_HEAD(&new_ns->list);
  1280. init_waitqueue_head(&new_ns->poll);
  1281. new_ns->event = 0;
  1282. down_write(&namespace_sem);
  1283. /* First pass: copy the tree topology */
  1284. new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root,
  1285. CL_COPY_ALL | CL_EXPIRE);
  1286. if (!new_ns->root) {
  1287. up_write(&namespace_sem);
  1288. kfree(new_ns);
  1289. return NULL;
  1290. }
  1291. spin_lock(&vfsmount_lock);
  1292. list_add_tail(&new_ns->list, &new_ns->root->mnt_list);
  1293. spin_unlock(&vfsmount_lock);
  1294. /*
  1295. * Second pass: switch the tsk->fs->* elements and mark new vfsmounts
  1296. * as belonging to new namespace. We have already acquired a private
  1297. * fs_struct, so tsk->fs->lock is not needed.
  1298. */
  1299. p = namespace->root;
  1300. q = new_ns->root;
  1301. while (p) {
  1302. q->mnt_namespace = new_ns;
  1303. if (fs) {
  1304. if (p == fs->rootmnt) {
  1305. rootmnt = p;
  1306. fs->rootmnt = mntget(q);
  1307. }
  1308. if (p == fs->pwdmnt) {
  1309. pwdmnt = p;
  1310. fs->pwdmnt = mntget(q);
  1311. }
  1312. if (p == fs->altrootmnt) {
  1313. altrootmnt = p;
  1314. fs->altrootmnt = mntget(q);
  1315. }
  1316. }
  1317. p = next_mnt(p, namespace->root);
  1318. q = next_mnt(q, new_ns->root);
  1319. }
  1320. up_write(&namespace_sem);
  1321. if (rootmnt)
  1322. mntput(rootmnt);
  1323. if (pwdmnt)
  1324. mntput(pwdmnt);
  1325. if (altrootmnt)
  1326. mntput(altrootmnt);
  1327. return new_ns;
  1328. }
  1329. int copy_namespace(int flags, struct task_struct *tsk)
  1330. {
  1331. struct namespace *namespace = tsk->namespace;
  1332. struct namespace *new_ns;
  1333. int err = 0;
  1334. if (!namespace)
  1335. return 0;
  1336. get_namespace(namespace);
  1337. if (!(flags & CLONE_NEWNS))
  1338. return 0;
  1339. if (!capable(CAP_SYS_ADMIN)) {
  1340. err = -EPERM;
  1341. goto out;
  1342. }
  1343. new_ns = dup_namespace(tsk, tsk->fs);
  1344. if (!new_ns) {
  1345. err = -ENOMEM;
  1346. goto out;
  1347. }
  1348. tsk->namespace = new_ns;
  1349. out:
  1350. put_namespace(namespace);
  1351. return err;
  1352. }
  1353. asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
  1354. char __user * type, unsigned long flags,
  1355. void __user * data)
  1356. {
  1357. int retval;
  1358. unsigned long data_page;
  1359. unsigned long type_page;
  1360. unsigned long dev_page;
  1361. char *dir_page;
  1362. retval = copy_mount_options(type, &type_page);
  1363. if (retval < 0)
  1364. return retval;
  1365. dir_page = getname(dir_name);
  1366. retval = PTR_ERR(dir_page);
  1367. if (IS_ERR(dir_page))
  1368. goto out1;
  1369. retval = copy_mount_options(dev_name, &dev_page);
  1370. if (retval < 0)
  1371. goto out2;
  1372. retval = copy_mount_options(data, &data_page);
  1373. if (retval < 0)
  1374. goto out3;
  1375. lock_kernel();
  1376. retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
  1377. flags, (void *)data_page);
  1378. unlock_kernel();
  1379. free_page(data_page);
  1380. out3:
  1381. free_page(dev_page);
  1382. out2:
  1383. putname(dir_page);
  1384. out1:
  1385. free_page(type_page);
  1386. return retval;
  1387. }
  1388. /*
  1389. * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
  1390. * It can block. Requires the big lock held.
  1391. */
  1392. void set_fs_root(struct fs_struct *fs, struct vfsmount *mnt,
  1393. struct dentry *dentry)
  1394. {
  1395. struct dentry *old_root;
  1396. struct vfsmount *old_rootmnt;
  1397. write_lock(&fs->lock);
  1398. old_root = fs->root;
  1399. old_rootmnt = fs->rootmnt;
  1400. fs->rootmnt = mntget(mnt);
  1401. fs->root = dget(dentry);
  1402. write_unlock(&fs->lock);
  1403. if (old_root) {
  1404. dput(old_root);
  1405. mntput(old_rootmnt);
  1406. }
  1407. }
  1408. /*
  1409. * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
  1410. * It can block. Requires the big lock held.
  1411. */
  1412. void set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
  1413. struct dentry *dentry)
  1414. {
  1415. struct dentry *old_pwd;
  1416. struct vfsmount *old_pwdmnt;
  1417. write_lock(&fs->lock);
  1418. old_pwd = fs->pwd;
  1419. old_pwdmnt = fs->pwdmnt;
  1420. fs->pwdmnt = mntget(mnt);
  1421. fs->pwd = dget(dentry);
  1422. write_unlock(&fs->lock);
  1423. if (old_pwd) {
  1424. dput(old_pwd);
  1425. mntput(old_pwdmnt);
  1426. }
  1427. }
  1428. static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
  1429. {
  1430. struct task_struct *g, *p;
  1431. struct fs_struct *fs;
  1432. read_lock(&tasklist_lock);
  1433. do_each_thread(g, p) {
  1434. task_lock(p);
  1435. fs = p->fs;
  1436. if (fs) {
  1437. atomic_inc(&fs->count);
  1438. task_unlock(p);
  1439. if (fs->root == old_nd->dentry
  1440. && fs->rootmnt == old_nd->mnt)
  1441. set_fs_root(fs, new_nd->mnt, new_nd->dentry);
  1442. if (fs->pwd == old_nd->dentry
  1443. && fs->pwdmnt == old_nd->mnt)
  1444. set_fs_pwd(fs, new_nd->mnt, new_nd->dentry);
  1445. put_fs_struct(fs);
  1446. } else
  1447. task_unlock(p);
  1448. } while_each_thread(g, p);
  1449. read_unlock(&tasklist_lock);
  1450. }
  1451. /*
  1452. * pivot_root Semantics:
  1453. * Moves the root file system of the current process to the directory put_old,
  1454. * makes new_root as the new root file system of the current process, and sets
  1455. * root/cwd of all processes which had them on the current root to new_root.
  1456. *
  1457. * Restrictions:
  1458. * The new_root and put_old must be directories, and must not be on the
  1459. * same file system as the current process root. The put_old must be
  1460. * underneath new_root, i.e. adding a non-zero number of /.. to the string
  1461. * pointed to by put_old must yield the same directory as new_root. No other
  1462. * file system may be mounted on put_old. After all, new_root is a mountpoint.
  1463. *
  1464. * Also, the current root cannot be on the 'rootfs' (initial ramfs) filesystem.
  1465. * See Documentation/filesystems/ramfs-rootfs-initramfs.txt for alternatives
  1466. * in this situation.
  1467. *
  1468. * Notes:
  1469. * - we don't move root/cwd if they are not at the root (reason: if something
  1470. * cared enough to change them, it's probably wrong to force them elsewhere)
  1471. * - it's okay to pick a root that isn't the root of a file system, e.g.
  1472. * /nfs/my_root where /nfs is the mount point. It must be a mountpoint,
  1473. * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root
  1474. * first.
  1475. */
  1476. asmlinkage long sys_pivot_root(const char __user * new_root,
  1477. const char __user * put_old)
  1478. {
  1479. struct vfsmount *tmp;
  1480. struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;
  1481. int error;
  1482. if (!capable(CAP_SYS_ADMIN))
  1483. return -EPERM;
  1484. lock_kernel();
  1485. error = __user_walk(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
  1486. &new_nd);
  1487. if (error)
  1488. goto out0;
  1489. error = -EINVAL;
  1490. if (!check_mnt(new_nd.mnt))
  1491. goto out1;
  1492. error = __user_walk(put_old, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &old_nd);
  1493. if (error)
  1494. goto out1;
  1495. error = security_sb_pivotroot(&old_nd, &new_nd);
  1496. if (error) {
  1497. path_release(&old_nd);
  1498. goto out1;
  1499. }
  1500. read_lock(&current->fs->lock);
  1501. user_nd.mnt = mntget(current->fs->rootmnt);
  1502. user_nd.dentry = dget(current->fs->root);
  1503. read_unlock(&current->fs->lock);
  1504. down_write(&namespace_sem);
  1505. mutex_lock(&old_nd.dentry->d_inode->i_mutex);
  1506. error = -EINVAL;
  1507. if (IS_MNT_SHARED(old_nd.mnt) ||
  1508. IS_MNT_SHARED(new_nd.mnt->mnt_parent) ||
  1509. IS_MNT_SHARED(user_nd.mnt->mnt_parent))
  1510. goto out2;
  1511. if (!check_mnt(user_nd.mnt))
  1512. goto out2;
  1513. error = -ENOENT;
  1514. if (IS_DEADDIR(new_nd.dentry->d_inode))
  1515. goto out2;
  1516. if (d_unhashed(new_nd.dentry) && !IS_ROOT(new_nd.dentry))
  1517. goto out2;
  1518. if (d_unhashed(old_nd.dentry) && !IS_ROOT(old_nd.dentry))
  1519. goto out2;
  1520. error = -EBUSY;
  1521. if (new_nd.mnt == user_nd.mnt || old_nd.mnt == user_nd.mnt)
  1522. goto out2; /* loop, on the same file system */
  1523. error = -EINVAL;
  1524. if (user_nd.mnt->mnt_root != user_nd.dentry)
  1525. goto out2; /* not a mountpoint */
  1526. if (user_nd.mnt->mnt_parent == user_nd.mnt)
  1527. goto out2; /* not attached */
  1528. if (new_nd.mnt->mnt_root != new_nd.dentry)
  1529. goto out2; /* not a mountpoint */
  1530. if (new_nd.mnt->mnt_parent == new_nd.mnt)
  1531. goto out2; /* not attached */
  1532. tmp = old_nd.mnt; /* make sure we can reach put_old from new_root */
  1533. spin_lock(&vfsmount_lock);
  1534. if (tmp != new_nd.mnt) {
  1535. for (;;) {
  1536. if (tmp->mnt_parent == tmp)
  1537. goto out3; /* already mounted on put_old */
  1538. if (tmp->mnt_parent == new_nd.mnt)
  1539. break;
  1540. tmp = tmp->mnt_parent;
  1541. }
  1542. if (!is_subdir(tmp->mnt_mountpoint, new_nd.dentry))
  1543. goto out3;
  1544. } else if (!is_subdir(old_nd.dentry, new_nd.dentry))
  1545. goto out3;
  1546. detach_mnt(new_nd.mnt, &parent_nd);
  1547. detach_mnt(user_nd.mnt, &root_parent);
  1548. attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */
  1549. attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
  1550. touch_namespace(current->namespace);
  1551. spin_unlock(&vfsmount_lock);
  1552. chroot_fs_refs(&user_nd, &new_nd);
  1553. security_sb_post_pivotroot(&user_nd, &new_nd);
  1554. error = 0;
  1555. path_release(&root_parent);
  1556. path_release(&parent_nd);
  1557. out2:
  1558. mutex_unlock(&old_nd.dentry->d_inode->i_mutex);
  1559. up_write(&namespace_sem);
  1560. path_release(&user_nd);
  1561. path_release(&old_nd);
  1562. out1:
  1563. path_release(&new_nd);
  1564. out0:
  1565. unlock_kernel();
  1566. return error;
  1567. out3:
  1568. spin_unlock(&vfsmount_lock);
  1569. goto out2;
  1570. }
  1571. static void __init init_mount_tree(void)
  1572. {
  1573. struct vfsmount *mnt;
  1574. struct namespace *namespace;
  1575. struct task_struct *g, *p;
  1576. mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
  1577. if (IS_ERR(mnt))
  1578. panic("Can't create rootfs");
  1579. namespace = kmalloc(sizeof(*namespace), GFP_KERNEL);
  1580. if (!namespace)
  1581. panic("Can't allocate initial namespace");
  1582. atomic_set(&namespace->count, 1);
  1583. INIT_LIST_HEAD(&namespace->list);
  1584. init_waitqueue_head(&namespace->poll);
  1585. namespace->event = 0;
  1586. list_add(&mnt->mnt_list, &namespace->list);
  1587. namespace->root = mnt;
  1588. mnt->mnt_namespace = namespace;
  1589. init_task.namespace = namespace;
  1590. read_lock(&tasklist_lock);
  1591. do_each_thread(g, p) {
  1592. get_namespace(namespace);
  1593. p->namespace = namespace;
  1594. } while_each_thread(g, p);
  1595. read_unlock(&tasklist_lock);
  1596. set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root);
  1597. set_fs_root(current->fs, namespace->root, namespace->root->mnt_root);
  1598. }
  1599. void __init mnt_init(unsigned long mempages)
  1600. {
  1601. struct list_head *d;
  1602. unsigned int nr_hash;
  1603. int i;
  1604. init_rwsem(&namespace_sem);
  1605. mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),
  1606. 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL, NULL);
  1607. mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC);
  1608. if (!mount_hashtable)
  1609. panic("Failed to allocate mount hash table\n");
  1610. /*
  1611. * Find the power-of-two list-heads that can fit into the allocation..
  1612. * We don't guarantee that "sizeof(struct list_head)" is necessarily
  1613. * a power-of-two.
  1614. */
  1615. nr_hash = PAGE_SIZE / sizeof(struct list_head);
  1616. hash_bits = 0;
  1617. do {
  1618. hash_bits++;
  1619. } while ((nr_hash >> hash_bits) != 0);
  1620. hash_bits--;
  1621. /*
  1622. * Re-calculate the actual number of entries and the mask
  1623. * from the number of bits we can fit.
  1624. */
  1625. nr_hash = 1UL << hash_bits;
  1626. hash_mask = nr_hash - 1;
  1627. printk("Mount-cache hash table entries: %d\n", nr_hash);
  1628. /* And initialize the newly allocated array */
  1629. d = mount_hashtable;
  1630. i = nr_hash;
  1631. do {
  1632. INIT_LIST_HEAD(d);
  1633. d++;
  1634. i--;
  1635. } while (i);
  1636. sysfs_init();
  1637. subsystem_register(&fs_subsys);
  1638. init_rootfs();
  1639. init_mount_tree();
  1640. }
  1641. void __put_namespace(struct namespace *namespace)
  1642. {
  1643. struct vfsmount *root = namespace->root;
  1644. LIST_HEAD(umount_list);
  1645. namespace->root = NULL;
  1646. spin_unlock(&vfsmount_lock);
  1647. down_write(&namespace_sem);
  1648. spin_lock(&vfsmount_lock);
  1649. umount_tree(root, 0, &umount_list);
  1650. spin_unlock(&vfsmount_lock);
  1651. up_write(&namespace_sem);
  1652. release_mounts(&umount_list);
  1653. kfree(namespace);
  1654. }