Lines Matching refs:mnt

110 static inline struct hlist_head *m_hash(struct vfsmount *mnt, struct dentry *dentry)  in m_hash()  argument
112 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES); in m_hash()
125 static int mnt_alloc_id(struct mount *mnt) in mnt_alloc_id() argument
131 mnt->mnt_id = res; in mnt_alloc_id()
135 static void mnt_free_id(struct mount *mnt) in mnt_free_id() argument
137 ida_free(&mnt_id_ida, mnt->mnt_id); in mnt_free_id()
143 static int mnt_alloc_group_id(struct mount *mnt) in mnt_alloc_group_id() argument
149 mnt->mnt_group_id = res; in mnt_alloc_group_id()
156 void mnt_release_group_id(struct mount *mnt) in mnt_release_group_id() argument
158 ida_free(&mnt_group_ida, mnt->mnt_group_id); in mnt_release_group_id()
159 mnt->mnt_group_id = 0; in mnt_release_group_id()
165 static inline void mnt_add_count(struct mount *mnt, int n) in mnt_add_count() argument
168 this_cpu_add(mnt->mnt_pcp->mnt_count, n); in mnt_add_count()
171 mnt->mnt_count += n; in mnt_add_count()
179 int mnt_get_count(struct mount *mnt) in mnt_get_count() argument
186 count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count; in mnt_get_count()
191 return mnt->mnt_count; in mnt_get_count()
197 struct mount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL); in alloc_vfsmnt() local
198 if (mnt) { in alloc_vfsmnt()
201 err = mnt_alloc_id(mnt); in alloc_vfsmnt()
206 mnt->mnt_devname = kstrdup_const(name, in alloc_vfsmnt()
208 if (!mnt->mnt_devname) in alloc_vfsmnt()
213 mnt->mnt_pcp = alloc_percpu(struct mnt_pcp); in alloc_vfsmnt()
214 if (!mnt->mnt_pcp) in alloc_vfsmnt()
217 this_cpu_add(mnt->mnt_pcp->mnt_count, 1); in alloc_vfsmnt()
219 mnt->mnt_count = 1; in alloc_vfsmnt()
220 mnt->mnt_writers = 0; in alloc_vfsmnt()
223 INIT_HLIST_NODE(&mnt->mnt_hash); in alloc_vfsmnt()
224 INIT_LIST_HEAD(&mnt->mnt_child); in alloc_vfsmnt()
225 INIT_LIST_HEAD(&mnt->mnt_mounts); in alloc_vfsmnt()
226 INIT_LIST_HEAD(&mnt->mnt_list); in alloc_vfsmnt()
227 INIT_LIST_HEAD(&mnt->mnt_expire); in alloc_vfsmnt()
228 INIT_LIST_HEAD(&mnt->mnt_share); in alloc_vfsmnt()
229 INIT_LIST_HEAD(&mnt->mnt_slave_list); in alloc_vfsmnt()
230 INIT_LIST_HEAD(&mnt->mnt_slave); in alloc_vfsmnt()
231 INIT_HLIST_NODE(&mnt->mnt_mp_list); in alloc_vfsmnt()
232 INIT_LIST_HEAD(&mnt->mnt_umounting); in alloc_vfsmnt()
233 INIT_HLIST_HEAD(&mnt->mnt_stuck_children); in alloc_vfsmnt()
234 mnt->mnt.mnt_userns = &init_user_ns; in alloc_vfsmnt()
236 return mnt; in alloc_vfsmnt()
240 kfree_const(mnt->mnt_devname); in alloc_vfsmnt()
243 mnt_free_id(mnt); in alloc_vfsmnt()
245 kmem_cache_free(mnt_cache, mnt); in alloc_vfsmnt()
268 bool __mnt_is_readonly(struct vfsmount *mnt) in __mnt_is_readonly() argument
270 return (mnt->mnt_flags & MNT_READONLY) || sb_rdonly(mnt->mnt_sb); in __mnt_is_readonly()
274 static inline void mnt_inc_writers(struct mount *mnt) in mnt_inc_writers() argument
277 this_cpu_inc(mnt->mnt_pcp->mnt_writers); in mnt_inc_writers()
279 mnt->mnt_writers++; in mnt_inc_writers()
283 static inline void mnt_dec_writers(struct mount *mnt) in mnt_dec_writers() argument
286 this_cpu_dec(mnt->mnt_pcp->mnt_writers); in mnt_dec_writers()
288 mnt->mnt_writers--; in mnt_dec_writers()
292 static unsigned int mnt_get_writers(struct mount *mnt) in mnt_get_writers() argument
299 count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_writers; in mnt_get_writers()
304 return mnt->mnt_writers; in mnt_get_writers()
308 static int mnt_is_readonly(struct vfsmount *mnt) in mnt_is_readonly() argument
310 if (mnt->mnt_sb->s_readonly_remount) in mnt_is_readonly()
314 return __mnt_is_readonly(mnt); in mnt_is_readonly()
335 struct mount *mnt = real_mount(m); in __mnt_want_write() local
339 mnt_inc_writers(mnt); in __mnt_want_write()
346 while (READ_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD) in __mnt_want_write()
355 mnt_dec_writers(mnt); in __mnt_want_write()
400 if (__mnt_is_readonly(file->f_path.mnt)) in __mnt_want_write_file()
404 return __mnt_want_write(file->f_path.mnt); in __mnt_want_write_file()
436 void __mnt_drop_write(struct vfsmount *mnt) in __mnt_drop_write() argument
439 mnt_dec_writers(real_mount(mnt)); in __mnt_drop_write()
451 void mnt_drop_write(struct vfsmount *mnt) in mnt_drop_write() argument
453 __mnt_drop_write(mnt); in mnt_drop_write()
454 sb_end_write(mnt->mnt_sb); in mnt_drop_write()
461 __mnt_drop_write(file->f_path.mnt); in __mnt_drop_write_file()
471 static inline int mnt_hold_writers(struct mount *mnt) in mnt_hold_writers() argument
473 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; in mnt_hold_writers()
496 if (mnt_get_writers(mnt) > 0) in mnt_hold_writers()
502 static inline void mnt_unhold_writers(struct mount *mnt) in mnt_unhold_writers() argument
509 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; in mnt_unhold_writers()
512 static int mnt_make_readonly(struct mount *mnt) in mnt_make_readonly() argument
516 ret = mnt_hold_writers(mnt); in mnt_make_readonly()
518 mnt->mnt.mnt_flags |= MNT_READONLY; in mnt_make_readonly()
519 mnt_unhold_writers(mnt); in mnt_make_readonly()
525 struct mount *mnt; in sb_prepare_remount_readonly() local
533 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { in sb_prepare_remount_readonly()
534 if (!(mnt->mnt.mnt_flags & MNT_READONLY)) { in sb_prepare_remount_readonly()
535 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; in sb_prepare_remount_readonly()
537 if (mnt_get_writers(mnt) > 0) { in sb_prepare_remount_readonly()
550 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { in sb_prepare_remount_readonly()
551 if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD) in sb_prepare_remount_readonly()
552 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; in sb_prepare_remount_readonly()
559 static void free_vfsmnt(struct mount *mnt) in free_vfsmnt() argument
563 mnt_userns = mnt_user_ns(&mnt->mnt); in free_vfsmnt()
566 kfree_const(mnt->mnt_devname); in free_vfsmnt()
568 free_percpu(mnt->mnt_pcp); in free_vfsmnt()
570 kmem_cache_free(mnt_cache, mnt); in free_vfsmnt()
581 struct mount *mnt; in __legitimize_mnt() local
586 mnt = real_mount(bastard); in __legitimize_mnt()
587 mnt_add_count(mnt, 1); in __legitimize_mnt()
592 mnt_add_count(mnt, -1); in __legitimize_mnt()
597 mnt_add_count(mnt, -1); in __legitimize_mnt()
624 struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry) in __lookup_mnt() argument
626 struct hlist_head *head = m_hash(mnt, dentry); in __lookup_mnt()
630 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) in __lookup_mnt()
660 child_mnt = __lookup_mnt(path->mnt, path->dentry); in lookup_mnt()
661 m = child_mnt ? &child_mnt->mnt : NULL; in lookup_mnt()
677 static inline bool mnt_is_cursor(struct mount *mnt) in mnt_is_cursor() argument
679 return mnt->mnt.mnt_flags & MNT_CURSOR; in mnt_is_cursor()
700 struct mount *mnt; in __is_local_mountpoint() local
705 list_for_each_entry(mnt, &ns->list, mnt_list) { in __is_local_mountpoint()
706 if (mnt_is_cursor(mnt)) in __is_local_mountpoint()
708 is_covered = (mnt->mnt_mountpoint == dentry); in __is_local_mountpoint()
806 static inline int check_mnt(struct mount *mnt) in check_mnt() argument
808 return mnt->mnt_ns == current->nsproxy->mnt_ns; in check_mnt()
836 static struct mountpoint *unhash_mnt(struct mount *mnt) in unhash_mnt() argument
839 mnt->mnt_parent = mnt; in unhash_mnt()
840 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in unhash_mnt()
841 list_del_init(&mnt->mnt_child); in unhash_mnt()
842 hlist_del_init_rcu(&mnt->mnt_hash); in unhash_mnt()
843 hlist_del_init(&mnt->mnt_mp_list); in unhash_mnt()
844 mp = mnt->mnt_mp; in unhash_mnt()
845 mnt->mnt_mp = NULL; in unhash_mnt()
852 static void umount_mnt(struct mount *mnt) in umount_mnt() argument
854 put_mountpoint(unhash_mnt(mnt)); in umount_mnt()
860 void mnt_set_mountpoint(struct mount *mnt, in mnt_set_mountpoint() argument
865 mnt_add_count(mnt, 1); /* essentially, that's mntget */ in mnt_set_mountpoint()
867 child_mnt->mnt_parent = mnt; in mnt_set_mountpoint()
872 static void __attach_mnt(struct mount *mnt, struct mount *parent) in __attach_mnt() argument
874 hlist_add_head_rcu(&mnt->mnt_hash, in __attach_mnt()
875 m_hash(&parent->mnt, mnt->mnt_mountpoint)); in __attach_mnt()
876 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); in __attach_mnt()
882 static void attach_mnt(struct mount *mnt, in attach_mnt() argument
886 mnt_set_mountpoint(parent, mp, mnt); in attach_mnt()
887 __attach_mnt(mnt, parent); in attach_mnt()
890 void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp, struct mount *mnt) in mnt_change_mountpoint() argument
892 struct mountpoint *old_mp = mnt->mnt_mp; in mnt_change_mountpoint()
893 struct mount *old_parent = mnt->mnt_parent; in mnt_change_mountpoint()
895 list_del_init(&mnt->mnt_child); in mnt_change_mountpoint()
896 hlist_del_init(&mnt->mnt_mp_list); in mnt_change_mountpoint()
897 hlist_del_init_rcu(&mnt->mnt_hash); in mnt_change_mountpoint()
899 attach_mnt(mnt, parent, mp); in mnt_change_mountpoint()
908 static void commit_tree(struct mount *mnt) in commit_tree() argument
910 struct mount *parent = mnt->mnt_parent; in commit_tree()
915 BUG_ON(parent == mnt); in commit_tree()
917 list_add_tail(&head, &mnt->mnt_list); in commit_tree()
926 __attach_mnt(mnt, parent); in commit_tree()
967 struct mount *mnt; in vfs_create_mount() local
972 mnt = alloc_vfsmnt(fc->source ?: "none"); in vfs_create_mount()
973 if (!mnt) in vfs_create_mount()
977 mnt->mnt.mnt_flags = MNT_INTERNAL; in vfs_create_mount()
980 mnt->mnt.mnt_sb = fc->root->d_sb; in vfs_create_mount()
981 mnt->mnt.mnt_root = dget(fc->root); in vfs_create_mount()
982 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in vfs_create_mount()
983 mnt->mnt_parent = mnt; in vfs_create_mount()
986 list_add_tail(&mnt->mnt_instance, &mnt->mnt.mnt_sb->s_mounts); in vfs_create_mount()
988 return &mnt->mnt; in vfs_create_mount()
1008 struct vfsmount *mnt; in vfs_kern_mount() local
1024 mnt = fc_mount(fc); in vfs_kern_mount()
1026 mnt = ERR_PTR(ret); in vfs_kern_mount()
1029 return mnt; in vfs_kern_mount()
1051 struct super_block *sb = old->mnt.mnt_sb; in clone_mnt()
1052 struct mount *mnt; in clone_mnt() local
1055 mnt = alloc_vfsmnt(old->mnt_devname); in clone_mnt()
1056 if (!mnt) in clone_mnt()
1060 mnt->mnt_group_id = 0; /* not a peer of original */ in clone_mnt()
1062 mnt->mnt_group_id = old->mnt_group_id; in clone_mnt()
1064 if ((flag & CL_MAKE_SHARED) && !mnt->mnt_group_id) { in clone_mnt()
1065 err = mnt_alloc_group_id(mnt); in clone_mnt()
1070 mnt->mnt.mnt_flags = old->mnt.mnt_flags; in clone_mnt()
1071 mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD|MNT_MARKED|MNT_INTERNAL); in clone_mnt()
1074 mnt->mnt.mnt_userns = mnt_user_ns(&old->mnt); in clone_mnt()
1075 if (mnt->mnt.mnt_userns != &init_user_ns) in clone_mnt()
1076 mnt->mnt.mnt_userns = get_user_ns(mnt->mnt.mnt_userns); in clone_mnt()
1077 mnt->mnt.mnt_sb = sb; in clone_mnt()
1078 mnt->mnt.mnt_root = dget(root); in clone_mnt()
1079 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in clone_mnt()
1080 mnt->mnt_parent = mnt; in clone_mnt()
1082 list_add_tail(&mnt->mnt_instance, &sb->s_mounts); in clone_mnt()
1087 list_add(&mnt->mnt_slave, &old->mnt_slave_list); in clone_mnt()
1088 mnt->mnt_master = old; in clone_mnt()
1089 CLEAR_MNT_SHARED(mnt); in clone_mnt()
1092 list_add(&mnt->mnt_share, &old->mnt_share); in clone_mnt()
1094 list_add(&mnt->mnt_slave, &old->mnt_slave); in clone_mnt()
1095 mnt->mnt_master = old->mnt_master; in clone_mnt()
1097 CLEAR_MNT_SHARED(mnt); in clone_mnt()
1100 set_mnt_shared(mnt); in clone_mnt()
1106 list_add(&mnt->mnt_expire, &old->mnt_expire); in clone_mnt()
1109 return mnt; in clone_mnt()
1112 mnt_free_id(mnt); in clone_mnt()
1113 free_vfsmnt(mnt); in clone_mnt()
1117 static void cleanup_mnt(struct mount *mnt) in cleanup_mnt() argument
1128 WARN_ON(mnt_get_writers(mnt)); in cleanup_mnt()
1129 if (unlikely(mnt->mnt_pins.first)) in cleanup_mnt()
1130 mnt_pin_kill(mnt); in cleanup_mnt()
1131 hlist_for_each_entry_safe(m, p, &mnt->mnt_stuck_children, mnt_umount) { in cleanup_mnt()
1133 mntput(&m->mnt); in cleanup_mnt()
1135 fsnotify_vfsmount_delete(&mnt->mnt); in cleanup_mnt()
1136 dput(mnt->mnt.mnt_root); in cleanup_mnt()
1137 deactivate_super(mnt->mnt.mnt_sb); in cleanup_mnt()
1138 mnt_free_id(mnt); in cleanup_mnt()
1139 call_rcu(&mnt->mnt_rcu, delayed_free_vfsmnt); in cleanup_mnt()
1158 static void mntput_no_expire(struct mount *mnt) in mntput_no_expire() argument
1164 if (likely(READ_ONCE(mnt->mnt_ns))) { in mntput_no_expire()
1174 mnt_add_count(mnt, -1); in mntput_no_expire()
1184 mnt_add_count(mnt, -1); in mntput_no_expire()
1185 count = mnt_get_count(mnt); in mntput_no_expire()
1192 if (unlikely(mnt->mnt.mnt_flags & MNT_DOOMED)) { in mntput_no_expire()
1197 mnt->mnt.mnt_flags |= MNT_DOOMED; in mntput_no_expire()
1200 list_del(&mnt->mnt_instance); in mntput_no_expire()
1202 if (unlikely(!list_empty(&mnt->mnt_mounts))) { in mntput_no_expire()
1204 list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts, mnt_child) { in mntput_no_expire()
1206 hlist_add_head(&p->mnt_umount, &mnt->mnt_stuck_children); in mntput_no_expire()
1212 if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) { in mntput_no_expire()
1215 init_task_work(&mnt->mnt_rcu, __cleanup_mnt); in mntput_no_expire()
1216 if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME)) in mntput_no_expire()
1219 if (llist_add(&mnt->mnt_llist, &delayed_mntput_list)) in mntput_no_expire()
1223 cleanup_mnt(mnt); in mntput_no_expire()
1226 void mntput(struct vfsmount *mnt) in mntput() argument
1228 if (mnt) { in mntput()
1229 struct mount *m = real_mount(mnt); in mntput()
1238 struct vfsmount *mntget(struct vfsmount *mnt) in mntget() argument
1240 if (mnt) in mntget()
1241 mnt_add_count(real_mount(mnt), 1); in mntget()
1242 return mnt; in mntget()
1279 p = clone_mnt(real_mount(path->mnt), path->dentry, CL_PRIVATE); in mnt_clone_internal()
1282 p->mnt.mnt_flags |= MNT_INTERNAL; in mnt_clone_internal()
1283 return &p->mnt; in mnt_clone_internal()
1290 struct mount *mnt, *ret = NULL; in mnt_list_next() local
1294 mnt = list_entry(p, typeof(*mnt), mnt_list); in mnt_list_next()
1295 if (!mnt_is_cursor(mnt)) { in mnt_list_next()
1296 ret = mnt; in mnt_list_next()
1328 struct mount *mnt = v; in m_next() local
1331 return mnt_list_next(p->ns, &mnt->mnt_list); in m_next()
1337 struct mount *mnt = v; in m_stop() local
1340 if (mnt) in m_stop()
1341 list_move_tail(&p->cursor.mnt_list, &mnt->mnt_list); in m_stop()
1352 return p->show(m, &r->mnt); in m_show()
1382 struct mount *mnt = real_mount(m); in may_umount_tree() local
1390 for (p = mnt; p; p = next_mnt(p, mnt)) { in may_umount_tree()
1417 int may_umount(struct vfsmount *mnt) in may_umount() argument
1422 if (propagate_mount_busy(real_mount(mnt), 2)) in may_umount()
1452 mntput(&m->mnt); in namespace_unlock()
1467 static bool disconnect_mount(struct mount *mnt, enum umount_tree_flags how) in disconnect_mount() argument
1474 if (!mnt_has_parent(mnt)) in disconnect_mount()
1481 if (!(mnt->mnt_parent->mnt.mnt_flags & MNT_UMOUNT)) in disconnect_mount()
1489 if (IS_MNT_LOCKED(mnt)) in disconnect_mount()
1500 static void umount_tree(struct mount *mnt, enum umount_tree_flags how) in umount_tree() argument
1506 propagate_mount_unlock(mnt); in umount_tree()
1509 for (p = mnt; p; p = next_mnt(p, mnt)) { in umount_tree()
1510 p->mnt.mnt_flags |= MNT_UMOUNT; in umount_tree()
1536 p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; in umount_tree()
1554 static void shrink_submounts(struct mount *mnt);
1579 static int do_umount(struct mount *mnt, int flags) in do_umount() argument
1581 struct super_block *sb = mnt->mnt.mnt_sb; in do_umount()
1584 retval = security_sb_umount(&mnt->mnt, flags); in do_umount()
1595 if (&mnt->mnt == current->fs->root.mnt || in do_umount()
1604 if (mnt_get_count(mnt) != 2) { in do_umount()
1610 if (!xchg(&mnt->mnt_expiry_mark, 1)) in do_umount()
1637 if (&mnt->mnt == current->fs->root.mnt && !(flags & MNT_DETACH)) { in do_umount()
1652 if (mnt->mnt.mnt_flags & MNT_LOCKED) in do_umount()
1657 if (!list_empty(&mnt->mnt_list)) in do_umount()
1658 umount_tree(mnt, UMOUNT_PROPAGATE); in do_umount()
1661 shrink_submounts(mnt); in do_umount()
1663 if (!propagate_mount_busy(mnt, 2)) { in do_umount()
1664 if (!list_empty(&mnt->mnt_list)) in do_umount()
1665 umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC); in do_umount()
1688 struct mount *mnt; in __detach_mounts() local
1698 mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list); in __detach_mounts()
1699 if (mnt->mnt.mnt_flags & MNT_UMOUNT) { in __detach_mounts()
1700 umount_mnt(mnt); in __detach_mounts()
1701 hlist_add_head(&mnt->mnt_umount, &unmounted); in __detach_mounts()
1703 else umount_tree(mnt, UMOUNT_CONNECTED); in __detach_mounts()
1730 struct mount *mnt = real_mount(path->mnt); in can_umount() local
1734 if (path->dentry != path->mnt->mnt_root) in can_umount()
1736 if (!check_mnt(mnt)) in can_umount()
1738 if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */ in can_umount()
1748 struct mount *mnt = real_mount(path->mnt); in path_umount() local
1753 ret = do_umount(mnt, flags); in path_umount()
1757 mntput_no_expire(mnt); in path_umount()
1808 struct ns_common *from_mnt_ns(struct mnt_namespace *mnt) in from_mnt_ns() argument
1810 return &mnt->ns; in from_mnt_ns()
1826 struct mount *copy_tree(struct mount *mnt, struct dentry *dentry, in copy_tree() argument
1831 if (!(flag & CL_COPY_UNBINDABLE) && IS_MNT_UNBINDABLE(mnt)) in copy_tree()
1837 res = q = clone_mnt(mnt, dentry, flag); in copy_tree()
1841 q->mnt_mountpoint = mnt->mnt_mountpoint; in copy_tree()
1843 p = mnt; in copy_tree()
1844 list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) { in copy_tree()
1852 if (s->mnt.mnt_flags & MNT_LOCKED) { in copy_tree()
1862 is_mnt_ns_file(s->mnt.mnt_root)) { in copy_tree()
1872 q = clone_mnt(p, p->mnt.mnt_root, flag); in copy_tree()
1897 if (!check_mnt(real_mount(path->mnt))) in collect_mounts()
1900 tree = copy_tree(real_mount(path->mnt), path->dentry, in collect_mounts()
1905 return &tree->mnt; in collect_mounts()
1911 void dissolve_on_fput(struct vfsmount *mnt) in dissolve_on_fput() argument
1916 ns = real_mount(mnt)->mnt_ns; in dissolve_on_fput()
1919 umount_tree(real_mount(mnt), UMOUNT_CONNECTED); in dissolve_on_fput()
1929 void drop_collected_mounts(struct vfsmount *mnt) in drop_collected_mounts() argument
1933 umount_tree(real_mount(mnt), 0); in drop_collected_mounts()
1938 static bool has_locked_children(struct mount *mnt, struct dentry *dentry) in has_locked_children() argument
1942 list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { in has_locked_children()
1946 if (child->mnt.mnt_flags & MNT_LOCKED) in has_locked_children()
1964 struct mount *old_mnt = real_mount(path->mnt); in clone_private_mount()
1986 return &new_mnt->mnt; in clone_private_mount()
1997 struct mount *mnt; in iterate_mounts() local
2001 list_for_each_entry(mnt, &real_mount(root)->mnt_list, mnt_list) { in iterate_mounts()
2002 res = f(&mnt->mnt, arg); in iterate_mounts()
2009 static void lock_mnt_tree(struct mount *mnt) in lock_mnt_tree() argument
2013 for (p = mnt; p; p = next_mnt(p, mnt)) { in lock_mnt_tree()
2014 int flags = p->mnt.mnt_flags; in lock_mnt_tree()
2032 p->mnt.mnt_flags = flags; in lock_mnt_tree()
2036 static void cleanup_group_ids(struct mount *mnt, struct mount *end) in cleanup_group_ids() argument
2040 for (p = mnt; p != end; p = next_mnt(p, mnt)) { in cleanup_group_ids()
2046 static int invent_group_ids(struct mount *mnt, bool recurse) in invent_group_ids() argument
2050 for (p = mnt; p; p = recurse ? next_mnt(p, mnt) : NULL) { in invent_group_ids()
2054 cleanup_group_ids(mnt, p); in invent_group_ids()
2063 int count_mounts(struct mnt_namespace *ns, struct mount *mnt) in count_mounts() argument
2069 for (p = mnt; p; p = next_mnt(p, mnt)) in count_mounts()
2164 smp = get_mountpoint(source_mnt->mnt.mnt_root); in attach_recursive_mnt()
2204 q = __lookup_mnt(&child->mnt_parent->mnt, in attach_recursive_mnt()
2211 child->mnt.mnt_flags &= ~MNT_LOCKED; in attach_recursive_mnt()
2239 struct vfsmount *mnt; in lock_mount() local
2248 mnt = lookup_mnt(path); in lock_mount()
2249 if (likely(!mnt)) { in lock_mount()
2261 path->mnt = mnt; in lock_mount()
2262 dentry = path->dentry = dget(mnt->mnt_root); in lock_mount()
2278 static int graft_tree(struct mount *mnt, struct mount *p, struct mountpoint *mp) in graft_tree() argument
2280 if (mnt->mnt.mnt_sb->s_flags & SB_NOUSER) in graft_tree()
2284 d_is_dir(mnt->mnt.mnt_root)) in graft_tree()
2287 return attach_recursive_mnt(mnt, p, mp, false); in graft_tree()
2313 struct mount *mnt = real_mount(path->mnt); in do_change_type() local
2318 if (path->dentry != path->mnt->mnt_root) in do_change_type()
2327 err = invent_group_ids(mnt, recurse); in do_change_type()
2333 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL)) in do_change_type()
2344 struct mount *mnt = ERR_PTR(-EINVAL), *old = real_mount(old_path->mnt); in __do_loopback() local
2347 return mnt; in __do_loopback()
2350 return mnt; in __do_loopback()
2353 return mnt; in __do_loopback()
2356 mnt = copy_tree(old, old_path->dentry, CL_COPY_MNT_NS_FILE); in __do_loopback()
2358 mnt = clone_mnt(old, old_path->dentry, 0); in __do_loopback()
2360 if (!IS_ERR(mnt)) in __do_loopback()
2361 mnt->mnt.mnt_flags &= ~MNT_LOCKED; in __do_loopback()
2363 return mnt; in __do_loopback()
2373 struct mount *mnt = NULL, *parent; in do_loopback() local
2392 parent = real_mount(path->mnt); in do_loopback()
2396 mnt = __do_loopback(&old_path, recurse); in do_loopback()
2397 if (IS_ERR(mnt)) { in do_loopback()
2398 err = PTR_ERR(mnt); in do_loopback()
2402 err = graft_tree(mnt, parent, mp); in do_loopback()
2405 umount_tree(mnt, UMOUNT_SYNC); in do_loopback()
2419 struct mount *mnt, *p; in open_detached_copy() local
2426 mnt = __do_loopback(path, recursive); in open_detached_copy()
2427 if (IS_ERR(mnt)) { in open_detached_copy()
2430 return ERR_CAST(mnt); in open_detached_copy()
2434 for (p = mnt; p; p = next_mnt(p, mnt)) { in open_detached_copy()
2438 ns->root = mnt; in open_detached_copy()
2439 list_add_tail(&ns->list, &mnt->mnt_list); in open_detached_copy()
2440 mntget(&mnt->mnt); in open_detached_copy()
2444 mntput(path->mnt); in open_detached_copy()
2445 path->mnt = &mnt->mnt; in open_detached_copy()
2448 dissolve_on_fput(path->mnt); in open_detached_copy()
2511 static bool can_change_locked_flags(struct mount *mnt, unsigned int mnt_flags) in can_change_locked_flags() argument
2513 unsigned int fl = mnt->mnt.mnt_flags; in can_change_locked_flags()
2538 static int change_mount_ro_state(struct mount *mnt, unsigned int mnt_flags) in change_mount_ro_state() argument
2542 if (readonly_request == __mnt_is_readonly(&mnt->mnt)) in change_mount_ro_state()
2546 return mnt_make_readonly(mnt); in change_mount_ro_state()
2548 mnt->mnt.mnt_flags &= ~MNT_READONLY; in change_mount_ro_state()
2552 static void set_mount_attributes(struct mount *mnt, unsigned int mnt_flags) in set_mount_attributes() argument
2554 mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK; in set_mount_attributes()
2555 mnt->mnt.mnt_flags = mnt_flags; in set_mount_attributes()
2556 touch_mnt_namespace(mnt->mnt_ns); in set_mount_attributes()
2559 static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *mnt) in mnt_warn_timestamp_expiry() argument
2561 struct super_block *sb = mnt->mnt_sb; in mnt_warn_timestamp_expiry()
2563 if (!__mnt_is_readonly(mnt) && in mnt_warn_timestamp_expiry()
2573 is_mounted(mnt) ? "remounted" : "mounted", in mnt_warn_timestamp_expiry()
2588 struct super_block *sb = path->mnt->mnt_sb; in do_reconfigure_mnt()
2589 struct mount *mnt = real_mount(path->mnt); in do_reconfigure_mnt() local
2592 if (!check_mnt(mnt)) in do_reconfigure_mnt()
2595 if (path->dentry != mnt->mnt.mnt_root) in do_reconfigure_mnt()
2598 if (!can_change_locked_flags(mnt, mnt_flags)) in do_reconfigure_mnt()
2607 ret = change_mount_ro_state(mnt, mnt_flags); in do_reconfigure_mnt()
2609 set_mount_attributes(mnt, mnt_flags); in do_reconfigure_mnt()
2613 mnt_warn_timestamp_expiry(path, &mnt->mnt); in do_reconfigure_mnt()
2627 struct super_block *sb = path->mnt->mnt_sb; in do_remount()
2628 struct mount *mnt = real_mount(path->mnt); in do_remount() local
2631 if (!check_mnt(mnt)) in do_remount()
2634 if (path->dentry != path->mnt->mnt_root) in do_remount()
2637 if (!can_change_locked_flags(mnt, mnt_flags)) in do_remount()
2653 set_mount_attributes(mnt, mnt_flags); in do_remount()
2660 mnt_warn_timestamp_expiry(path, &mnt->mnt); in do_remount()
2666 static inline int tree_contains_unbindable(struct mount *mnt) in tree_contains_unbindable() argument
2669 for (p = mnt; p; p = next_mnt(p, mnt)) { in tree_contains_unbindable()
2689 if (mnt_ns_loop(p->mnt.mnt_root)) in check_for_nsfs_mounts()
2703 from = real_mount(from_path->mnt); in do_set_group()
2704 to = real_mount(to_path->mnt); in do_set_group()
2710 if (!is_mounted(&from->mnt)) in do_set_group()
2712 if (!is_mounted(&to->mnt)) in do_set_group()
2724 if (from_path->dentry != from_path->mnt->mnt_root) in do_set_group()
2726 if (to_path->dentry != to_path->mnt->mnt_root) in do_set_group()
2730 if (from->mnt.mnt_sb != to->mnt.mnt_sb) in do_set_group()
2734 if (!is_subdir(to->mnt.mnt_root, from->mnt.mnt_root)) in do_set_group()
2738 if (has_locked_children(from, to->mnt.mnt_root)) in do_set_group()
2784 old = real_mount(old_path->mnt); in do_move_mount()
2785 p = real_mount(new_path->mnt); in do_move_mount()
2797 if (!is_mounted(&old->mnt)) in do_move_mount()
2804 if (old->mnt.mnt_flags & MNT_LOCKED) in do_move_mount()
2807 if (old_path->dentry != old_path->mnt->mnt_root) in do_move_mount()
2831 err = attach_recursive_mnt(old, real_mount(new_path->mnt), mp, in do_move_mount()
2875 struct mount *parent = real_mount(path->mnt); in do_add_mount()
2889 if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && in do_add_mount()
2890 path->mnt->mnt_root == path->dentry) in do_add_mount()
2893 if (d_is_symlink(newmnt->mnt.mnt_root)) in do_add_mount()
2896 newmnt->mnt.mnt_flags = mnt_flags; in do_add_mount()
2909 struct vfsmount *mnt; in do_new_mount_fc() local
2925 mnt = vfs_create_mount(fc); in do_new_mount_fc()
2926 if (IS_ERR(mnt)) in do_new_mount_fc()
2927 return PTR_ERR(mnt); in do_new_mount_fc()
2929 mnt_warn_timestamp_expiry(mountpoint, mnt); in do_new_mount_fc()
2933 mntput(mnt); in do_new_mount_fc()
2936 error = do_add_mount(real_mount(mnt), mp, mountpoint, mnt_flags); in do_new_mount_fc()
2939 mntput(mnt); in do_new_mount_fc()
3000 struct mount *mnt; in finish_automount() local
3008 mnt = real_mount(m); in finish_automount()
3012 BUG_ON(mnt_get_count(mnt) < 2); in finish_automount()
3014 if (m->mnt_sb == path->mnt->mnt_sb && in finish_automount()
3032 if (unlikely(__lookup_mnt(path->mnt, dentry))) { in finish_automount()
3044 err = do_add_mount(mnt, mp, path, path->mnt->mnt_flags | MNT_SHRINKABLE); in finish_automount()
3056 if (!list_empty(&mnt->mnt_expire)) { in finish_automount()
3058 list_del_init(&mnt->mnt_expire); in finish_automount()
3071 void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list) in mnt_set_expiry() argument
3075 list_add_tail(&real_mount(mnt)->mnt_expire, expiry_list); in mnt_set_expiry()
3088 struct mount *mnt, *next; in mark_mounts_for_expiry() local
3103 list_for_each_entry_safe(mnt, next, mounts, mnt_expire) { in mark_mounts_for_expiry()
3104 if (!xchg(&mnt->mnt_expiry_mark, 1) || in mark_mounts_for_expiry()
3105 propagate_mount_busy(mnt, 1)) in mark_mounts_for_expiry()
3107 list_move(&mnt->mnt_expire, &graveyard); in mark_mounts_for_expiry()
3110 mnt = list_first_entry(&graveyard, struct mount, mnt_expire); in mark_mounts_for_expiry()
3111 touch_mnt_namespace(mnt->mnt_ns); in mark_mounts_for_expiry()
3112 umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC); in mark_mounts_for_expiry()
3137 struct mount *mnt = list_entry(tmp, struct mount, mnt_child); in select_submounts() local
3140 if (!(mnt->mnt.mnt_flags & MNT_SHRINKABLE)) in select_submounts()
3145 if (!list_empty(&mnt->mnt_mounts)) { in select_submounts()
3146 this_parent = mnt; in select_submounts()
3150 if (!propagate_mount_busy(mnt, 1)) { in select_submounts()
3151 list_move_tail(&mnt->mnt_expire, graveyard); in select_submounts()
3172 static void shrink_submounts(struct mount *mnt) in shrink_submounts() argument
3178 while (select_submounts(mnt, &graveyard)) { in shrink_submounts()
3295 mnt_flags |= path->mnt->mnt_flags & MNT_ATIME_MASK; in path_mount()
3428 new = copy_tree(old, old->mnt.mnt_root, copy_flags); in copy_mnt_ns()
3453 if (&p->mnt == new_fs->root.mnt) { in copy_mnt_ns()
3454 new_fs->root.mnt = mntget(&q->mnt); in copy_mnt_ns()
3455 rootmnt = &p->mnt; in copy_mnt_ns()
3457 if (&p->mnt == new_fs->pwd.mnt) { in copy_mnt_ns()
3458 new_fs->pwd.mnt = mntget(&q->mnt); in copy_mnt_ns()
3459 pwdmnt = &p->mnt; in copy_mnt_ns()
3466 while (p->mnt.mnt_root != q->mnt.mnt_root) in copy_mnt_ns()
3481 struct mount *mnt = real_mount(m); in mount_subtree() local
3492 mnt->mnt_ns = ns; in mount_subtree()
3493 ns->root = mnt; in mount_subtree()
3495 list_add(&mnt->mnt_list, &ns->list); in mount_subtree()
3506 s = path.mnt->mnt_sb; in mount_subtree()
3508 mntput(path.mnt); in mount_subtree()
3591 struct mount *mnt; in SYSCALL_DEFINE3() local
3652 newmount.mnt = vfs_create_mount(fc); in SYSCALL_DEFINE3()
3653 if (IS_ERR(newmount.mnt)) { in SYSCALL_DEFINE3()
3654 ret = PTR_ERR(newmount.mnt); in SYSCALL_DEFINE3()
3658 newmount.mnt->mnt_flags = mnt_flags; in SYSCALL_DEFINE3()
3672 mnt = real_mount(newmount.mnt); in SYSCALL_DEFINE3()
3673 mnt->mnt_ns = ns; in SYSCALL_DEFINE3()
3674 ns->root = mnt; in SYSCALL_DEFINE3()
3676 list_add(&mnt->mnt_list, &ns->list); in SYSCALL_DEFINE3()
3677 mntget(newmount.mnt); in SYSCALL_DEFINE3()
3684 dissolve_on_fput(newmount.mnt); in SYSCALL_DEFINE3()
3771 bool is_path_reachable(struct mount *mnt, struct dentry *dentry, in is_path_reachable() argument
3774 while (&mnt->mnt != root->mnt && mnt_has_parent(mnt)) { in is_path_reachable()
3775 dentry = mnt->mnt_mountpoint; in is_path_reachable()
3776 mnt = mnt->mnt_parent; in is_path_reachable()
3778 return &mnt->mnt == root->mnt && is_subdir(dentry, root->dentry); in is_path_reachable()
3785 res = is_path_reachable(real_mount(path1->mnt), path1->dentry, path2); in path_is_under()
3848 new_mnt = real_mount(new.mnt); in SYSCALL_DEFINE2()
3849 root_mnt = real_mount(root.mnt); in SYSCALL_DEFINE2()
3850 old_mnt = real_mount(old.mnt); in SYSCALL_DEFINE2()
3859 if (new_mnt->mnt.mnt_flags & MNT_LOCKED) in SYSCALL_DEFINE2()
3868 if (root.mnt->mnt_root != root.dentry) in SYSCALL_DEFINE2()
3872 if (new.mnt->mnt_root != new.dentry) in SYSCALL_DEFINE2()
3885 if (root_mnt->mnt.mnt_flags & MNT_LOCKED) { in SYSCALL_DEFINE2()
3886 new_mnt->mnt.mnt_flags |= MNT_LOCKED; in SYSCALL_DEFINE2()
3887 root_mnt->mnt.mnt_flags &= ~MNT_LOCKED; in SYSCALL_DEFINE2()
3915 static unsigned int recalc_flags(struct mount_kattr *kattr, struct mount *mnt) in recalc_flags() argument
3917 unsigned int flags = mnt->mnt.mnt_flags; in recalc_flags()
3927 static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt) in can_idmap_mount() argument
3929 struct vfsmount *m = &mnt->mnt; in can_idmap_mount()
3955 if (!is_anon_ns(mnt->mnt_ns)) in can_idmap_mount()
3962 struct mount *mnt, int *err) in mount_setattr_prepare() argument
3964 struct mount *m = mnt, *last = NULL; in mount_setattr_prepare()
3966 if (!is_mounted(&m->mnt)) { in mount_setattr_prepare()
3992 !(m->mnt.mnt_flags & MNT_READONLY)) { in mount_setattr_prepare()
3997 } while (kattr->recurse && (m = next_mnt(m, mnt))); in mount_setattr_prepare()
4003 static void do_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt) in do_idmap_mount() argument
4012 smp_store_release(&mnt->mnt.mnt_userns, mnt_userns); in do_idmap_mount()
4016 struct mount *mnt, struct mount *last, in mount_setattr_commit() argument
4019 struct mount *m = mnt; in mount_setattr_commit()
4027 WRITE_ONCE(m->mnt.mnt_flags, flags); in mount_setattr_commit()
4036 (m->mnt.mnt_flags & MNT_WRITE_HOLD)) in mount_setattr_commit()
4048 } while (kattr->recurse && (m = next_mnt(m, mnt))); in mount_setattr_commit()
4051 touch_mnt_namespace(mnt->mnt_ns); in mount_setattr_commit()
4056 struct mount *mnt = real_mount(path->mnt), *last = NULL; in do_mount_setattr() local
4059 if (path->dentry != mnt->mnt.mnt_root) in do_mount_setattr()
4069 err = invent_group_ids(mnt, kattr->recurse); in do_mount_setattr()
4083 last = mount_setattr_prepare(kattr, mnt, &err); in do_mount_setattr()
4085 mount_setattr_commit(kattr, mnt, last, err); in do_mount_setattr()
4092 cleanup_group_ids(mnt, NULL); in do_mount_setattr()
4277 struct vfsmount *mnt; in init_mount_tree() local
4282 mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL); in init_mount_tree()
4283 if (IS_ERR(mnt)) in init_mount_tree()
4289 m = real_mount(mnt); in init_mount_tree()
4297 root.mnt = mnt; in init_mount_tree()
4298 root.dentry = mnt->mnt_root; in init_mount_tree()
4299 mnt->mnt_flags |= MNT_LOCKED; in init_mount_tree()
4344 drop_collected_mounts(&ns->root->mnt); in put_mnt_ns()
4350 struct vfsmount *mnt; in kern_mount() local
4351 mnt = vfs_kern_mount(type, SB_KERNMOUNT, type->name, NULL); in kern_mount()
4352 if (!IS_ERR(mnt)) { in kern_mount()
4357 real_mount(mnt)->mnt_ns = MNT_NS_INTERNAL; in kern_mount()
4359 return mnt; in kern_mount()
4363 void kern_unmount(struct vfsmount *mnt) in kern_unmount() argument
4366 if (!IS_ERR_OR_NULL(mnt)) { in kern_unmount()
4367 real_mount(mnt)->mnt_ns = NULL; in kern_unmount()
4369 mntput(mnt); in kern_unmount()
4374 void kern_unmount_array(struct vfsmount *mnt[], unsigned int num) in kern_unmount_array() argument
4379 if (mnt[i]) in kern_unmount_array()
4380 real_mount(mnt[i])->mnt_ns = NULL; in kern_unmount_array()
4383 mntput(mnt[i]); in kern_unmount_array()
4387 bool our_mnt(struct vfsmount *mnt) in our_mnt() argument
4389 return check_mnt(real_mount(mnt)); in our_mnt()
4400 ns_root.mnt = &current->nsproxy->mnt_ns->root->mnt; in current_chrooted()
4401 ns_root.dentry = ns_root.mnt->mnt_root; in current_chrooted()
4421 struct mount *mnt; in mnt_already_visible() local
4426 list_for_each_entry(mnt, &ns->list, mnt_list) { in mnt_already_visible()
4430 if (mnt_is_cursor(mnt)) in mnt_already_visible()
4433 if (mnt->mnt.mnt_sb->s_type != sb->s_type) in mnt_already_visible()
4439 if (mnt->mnt.mnt_root != mnt->mnt.mnt_sb->s_root) in mnt_already_visible()
4443 mnt_flags = mnt->mnt.mnt_flags; in mnt_already_visible()
4446 if (sb_rdonly(mnt->mnt.mnt_sb)) in mnt_already_visible()
4463 list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { in mnt_already_visible()
4466 if (!(child->mnt.mnt_flags & MNT_LOCKED)) in mnt_already_visible()
4508 bool mnt_may_suid(struct vfsmount *mnt) in mnt_may_suid() argument
4517 return !(mnt->mnt_flags & MNT_NOSUID) && check_mnt(real_mount(mnt)) && in mnt_may_suid()
4518 current_in_userns(mnt->mnt_sb->s_user_ns); in mnt_may_suid()
4567 err = vfs_path_lookup(mnt_ns->root->mnt.mnt_root, &mnt_ns->root->mnt, in mntns_install()