namespace.c 47 KB

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