Lines Matching refs:mnt
222 static inline struct hlist_head *m_hash(struct vfsmount *mnt, struct dentry *dentry) in m_hash() argument
224 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES); in m_hash()
237 static int mnt_alloc_id(struct mount *mnt) in mnt_alloc_id() argument
243 mnt->mnt_id = res; in mnt_alloc_id()
244 mnt->mnt_id_unique = atomic64_inc_return(&mnt_id_ctr); in mnt_alloc_id()
248 static void mnt_free_id(struct mount *mnt) in mnt_free_id() argument
250 ida_free(&mnt_id_ida, mnt->mnt_id); in mnt_free_id()
256 static int mnt_alloc_group_id(struct mount *mnt) in mnt_alloc_group_id() argument
262 mnt->mnt_group_id = res; in mnt_alloc_group_id()
269 void mnt_release_group_id(struct mount *mnt) in mnt_release_group_id() argument
271 ida_free(&mnt_group_ida, mnt->mnt_group_id); in mnt_release_group_id()
272 mnt->mnt_group_id = 0; in mnt_release_group_id()
278 static inline void mnt_add_count(struct mount *mnt, int n) in mnt_add_count() argument
281 this_cpu_add(mnt->mnt_pcp->mnt_count, n); in mnt_add_count()
284 mnt->mnt_count += n; in mnt_add_count()
292 int mnt_get_count(struct mount *mnt) in mnt_get_count() argument
299 count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count; in mnt_get_count()
304 return mnt->mnt_count; in mnt_get_count()
310 struct mount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL); in alloc_vfsmnt() local
311 if (mnt) { in alloc_vfsmnt()
314 err = mnt_alloc_id(mnt); in alloc_vfsmnt()
319 mnt->mnt_devname = kstrdup_const(name, in alloc_vfsmnt()
321 if (!mnt->mnt_devname) in alloc_vfsmnt()
326 mnt->mnt_pcp = alloc_percpu(struct mnt_pcp); in alloc_vfsmnt()
327 if (!mnt->mnt_pcp) in alloc_vfsmnt()
330 this_cpu_add(mnt->mnt_pcp->mnt_count, 1); in alloc_vfsmnt()
332 mnt->mnt_count = 1; in alloc_vfsmnt()
333 mnt->mnt_writers = 0; in alloc_vfsmnt()
336 INIT_HLIST_NODE(&mnt->mnt_hash); in alloc_vfsmnt()
337 INIT_LIST_HEAD(&mnt->mnt_child); in alloc_vfsmnt()
338 INIT_LIST_HEAD(&mnt->mnt_mounts); in alloc_vfsmnt()
339 INIT_LIST_HEAD(&mnt->mnt_list); in alloc_vfsmnt()
340 INIT_LIST_HEAD(&mnt->mnt_expire); in alloc_vfsmnt()
341 INIT_LIST_HEAD(&mnt->mnt_share); in alloc_vfsmnt()
342 INIT_LIST_HEAD(&mnt->mnt_slave_list); in alloc_vfsmnt()
343 INIT_LIST_HEAD(&mnt->mnt_slave); in alloc_vfsmnt()
344 INIT_HLIST_NODE(&mnt->mnt_mp_list); in alloc_vfsmnt()
345 INIT_LIST_HEAD(&mnt->mnt_umounting); in alloc_vfsmnt()
346 INIT_HLIST_HEAD(&mnt->mnt_stuck_children); in alloc_vfsmnt()
347 mnt->mnt.mnt_idmap = &nop_mnt_idmap; in alloc_vfsmnt()
349 return mnt; in alloc_vfsmnt()
353 kfree_const(mnt->mnt_devname); in alloc_vfsmnt()
356 mnt_free_id(mnt); in alloc_vfsmnt()
358 kmem_cache_free(mnt_cache, mnt); in alloc_vfsmnt()
381 bool __mnt_is_readonly(struct vfsmount *mnt) in __mnt_is_readonly() argument
383 return (mnt->mnt_flags & MNT_READONLY) || sb_rdonly(mnt->mnt_sb); in __mnt_is_readonly()
387 static inline void mnt_inc_writers(struct mount *mnt) in mnt_inc_writers() argument
390 this_cpu_inc(mnt->mnt_pcp->mnt_writers); in mnt_inc_writers()
392 mnt->mnt_writers++; in mnt_inc_writers()
396 static inline void mnt_dec_writers(struct mount *mnt) in mnt_dec_writers() argument
399 this_cpu_dec(mnt->mnt_pcp->mnt_writers); in mnt_dec_writers()
401 mnt->mnt_writers--; in mnt_dec_writers()
405 static unsigned int mnt_get_writers(struct mount *mnt) in mnt_get_writers() argument
412 count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_writers; in mnt_get_writers()
417 return mnt->mnt_writers; in mnt_get_writers()
421 static int mnt_is_readonly(struct vfsmount *mnt) in mnt_is_readonly() argument
423 if (READ_ONCE(mnt->mnt_sb->s_readonly_remount)) in mnt_is_readonly()
434 return __mnt_is_readonly(mnt); in mnt_is_readonly()
455 struct mount *mnt = real_mount(m); in mnt_get_write_access() local
459 mnt_inc_writers(mnt); in mnt_get_write_access()
467 while (READ_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD) { in mnt_get_write_access()
493 mnt_dec_writers(mnt); in mnt_get_write_access()
539 if (__mnt_is_readonly(file->f_path.mnt)) in mnt_get_write_access_file()
543 return mnt_get_write_access(file->f_path.mnt); in mnt_get_write_access_file()
575 void mnt_put_write_access(struct vfsmount *mnt) in mnt_put_write_access() argument
578 mnt_dec_writers(real_mount(mnt)); in mnt_put_write_access()
591 void mnt_drop_write(struct vfsmount *mnt) in mnt_drop_write() argument
593 mnt_put_write_access(mnt); in mnt_drop_write()
594 sb_end_write(mnt->mnt_sb); in mnt_drop_write()
601 mnt_put_write_access(file->f_path.mnt); in mnt_put_write_access_file()
629 static inline int mnt_hold_writers(struct mount *mnt) in mnt_hold_writers() argument
631 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; in mnt_hold_writers()
654 if (mnt_get_writers(mnt) > 0) in mnt_hold_writers()
672 static inline void mnt_unhold_writers(struct mount *mnt) in mnt_unhold_writers() argument
679 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; in mnt_unhold_writers()
682 static int mnt_make_readonly(struct mount *mnt) in mnt_make_readonly() argument
686 ret = mnt_hold_writers(mnt); in mnt_make_readonly()
688 mnt->mnt.mnt_flags |= MNT_READONLY; in mnt_make_readonly()
689 mnt_unhold_writers(mnt); in mnt_make_readonly()
695 struct mount *mnt; in sb_prepare_remount_readonly() local
703 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { in sb_prepare_remount_readonly()
704 if (!(mnt->mnt.mnt_flags & MNT_READONLY)) { in sb_prepare_remount_readonly()
705 err = mnt_hold_writers(mnt); in sb_prepare_remount_readonly()
715 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { in sb_prepare_remount_readonly()
716 if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD) in sb_prepare_remount_readonly()
717 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; in sb_prepare_remount_readonly()
724 static void free_vfsmnt(struct mount *mnt) in free_vfsmnt() argument
726 mnt_idmap_put(mnt_idmap(&mnt->mnt)); in free_vfsmnt()
727 kfree_const(mnt->mnt_devname); in free_vfsmnt()
729 free_percpu(mnt->mnt_pcp); in free_vfsmnt()
731 kmem_cache_free(mnt_cache, mnt); in free_vfsmnt()
742 struct mount *mnt; in __legitimize_mnt() local
747 mnt = real_mount(bastard); in __legitimize_mnt()
748 mnt_add_count(mnt, 1); in __legitimize_mnt()
753 mnt_add_count(mnt, -1); in __legitimize_mnt()
758 mnt_add_count(mnt, -1); in __legitimize_mnt()
801 struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry) in __lookup_mnt() argument
803 struct hlist_head *head = m_hash(mnt, dentry); in __lookup_mnt()
807 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) in __lookup_mnt()
837 child_mnt = __lookup_mnt(path->mnt, path->dentry); in lookup_mnt()
838 m = child_mnt ? &child_mnt->mnt : NULL; in lookup_mnt()
862 struct mount *mnt, *n; in __is_local_mountpoint() local
866 rbtree_postorder_for_each_entry_safe(mnt, n, &ns->mounts, mnt_node) { in __is_local_mountpoint()
867 is_covered = (mnt->mnt_mountpoint == dentry); in __is_local_mountpoint()
964 static inline int check_mnt(struct mount *mnt) in check_mnt() argument
966 return mnt->mnt_ns == current->nsproxy->mnt_ns; in check_mnt()
994 static struct mountpoint *unhash_mnt(struct mount *mnt) in unhash_mnt() argument
997 mnt->mnt_parent = mnt; in unhash_mnt()
998 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in unhash_mnt()
999 list_del_init(&mnt->mnt_child); in unhash_mnt()
1000 hlist_del_init_rcu(&mnt->mnt_hash); in unhash_mnt()
1001 hlist_del_init(&mnt->mnt_mp_list); in unhash_mnt()
1002 mp = mnt->mnt_mp; in unhash_mnt()
1003 mnt->mnt_mp = NULL; in unhash_mnt()
1010 static void umount_mnt(struct mount *mnt) in umount_mnt() argument
1012 put_mountpoint(unhash_mnt(mnt)); in umount_mnt()
1018 void mnt_set_mountpoint(struct mount *mnt, in mnt_set_mountpoint() argument
1023 mnt_add_count(mnt, 1); /* essentially, that's mntget */ in mnt_set_mountpoint()
1025 child_mnt->mnt_parent = mnt; in mnt_set_mountpoint()
1057 static void __attach_mnt(struct mount *mnt, struct mount *parent) in __attach_mnt() argument
1059 hlist_add_head_rcu(&mnt->mnt_hash, in __attach_mnt()
1060 m_hash(&parent->mnt, mnt->mnt_mountpoint)); in __attach_mnt()
1061 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); in __attach_mnt()
1086 static void attach_mnt(struct mount *mnt, struct mount *parent, in attach_mnt() argument
1090 mnt_set_mountpoint_beneath(mnt, parent, mp); in attach_mnt()
1092 mnt_set_mountpoint(parent, mp, mnt); in attach_mnt()
1099 __attach_mnt(mnt, mnt->mnt_parent); in attach_mnt()
1102 void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp, struct mount *mnt) in mnt_change_mountpoint() argument
1104 struct mountpoint *old_mp = mnt->mnt_mp; in mnt_change_mountpoint()
1105 struct mount *old_parent = mnt->mnt_parent; in mnt_change_mountpoint()
1107 list_del_init(&mnt->mnt_child); in mnt_change_mountpoint()
1108 hlist_del_init(&mnt->mnt_mp_list); in mnt_change_mountpoint()
1109 hlist_del_init_rcu(&mnt->mnt_hash); in mnt_change_mountpoint()
1111 attach_mnt(mnt, parent, mp, false); in mnt_change_mountpoint()
1122 static void mnt_add_to_ns(struct mnt_namespace *ns, struct mount *mnt) in mnt_add_to_ns() argument
1127 WARN_ON(mnt->mnt.mnt_flags & MNT_ONRB); in mnt_add_to_ns()
1128 mnt->mnt_ns = ns; in mnt_add_to_ns()
1131 if (mnt->mnt_id_unique < node_to_mount(parent)->mnt_id_unique) in mnt_add_to_ns()
1136 rb_link_node(&mnt->mnt_node, parent, link); in mnt_add_to_ns()
1137 rb_insert_color(&mnt->mnt_node, &ns->mounts); in mnt_add_to_ns()
1138 mnt->mnt.mnt_flags |= MNT_ONRB; in mnt_add_to_ns()
1144 static void commit_tree(struct mount *mnt) in commit_tree() argument
1146 struct mount *parent = mnt->mnt_parent; in commit_tree()
1151 BUG_ON(parent == mnt); in commit_tree()
1153 list_add_tail(&head, &mnt->mnt_list); in commit_tree()
1163 __attach_mnt(mnt, parent); in commit_tree()
1204 struct mount *mnt; in vfs_create_mount() local
1209 mnt = alloc_vfsmnt(fc->source ?: "none"); in vfs_create_mount()
1210 if (!mnt) in vfs_create_mount()
1214 mnt->mnt.mnt_flags = MNT_INTERNAL; in vfs_create_mount()
1217 mnt->mnt.mnt_sb = fc->root->d_sb; in vfs_create_mount()
1218 mnt->mnt.mnt_root = dget(fc->root); in vfs_create_mount()
1219 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in vfs_create_mount()
1220 mnt->mnt_parent = mnt; in vfs_create_mount()
1223 list_add_tail(&mnt->mnt_instance, &mnt->mnt.mnt_sb->s_mounts); in vfs_create_mount()
1225 return &mnt->mnt; in vfs_create_mount()
1245 struct vfsmount *mnt; in vfs_kern_mount() local
1261 mnt = fc_mount(fc); in vfs_kern_mount()
1263 mnt = ERR_PTR(ret); in vfs_kern_mount()
1266 return mnt; in vfs_kern_mount()
1288 struct super_block *sb = old->mnt.mnt_sb; in clone_mnt()
1289 struct mount *mnt; in clone_mnt() local
1292 mnt = alloc_vfsmnt(old->mnt_devname); in clone_mnt()
1293 if (!mnt) in clone_mnt()
1297 mnt->mnt_group_id = 0; /* not a peer of original */ in clone_mnt()
1299 mnt->mnt_group_id = old->mnt_group_id; in clone_mnt()
1301 if ((flag & CL_MAKE_SHARED) && !mnt->mnt_group_id) { in clone_mnt()
1302 err = mnt_alloc_group_id(mnt); in clone_mnt()
1307 mnt->mnt.mnt_flags = old->mnt.mnt_flags; in clone_mnt()
1308 mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD|MNT_MARKED|MNT_INTERNAL|MNT_ONRB); in clone_mnt()
1311 mnt->mnt.mnt_idmap = mnt_idmap_get(mnt_idmap(&old->mnt)); in clone_mnt()
1313 mnt->mnt.mnt_sb = sb; in clone_mnt()
1314 mnt->mnt.mnt_root = dget(root); in clone_mnt()
1315 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in clone_mnt()
1316 mnt->mnt_parent = mnt; in clone_mnt()
1318 list_add_tail(&mnt->mnt_instance, &sb->s_mounts); in clone_mnt()
1323 list_add(&mnt->mnt_slave, &old->mnt_slave_list); in clone_mnt()
1324 mnt->mnt_master = old; in clone_mnt()
1325 CLEAR_MNT_SHARED(mnt); in clone_mnt()
1328 list_add(&mnt->mnt_share, &old->mnt_share); in clone_mnt()
1330 list_add(&mnt->mnt_slave, &old->mnt_slave); in clone_mnt()
1331 mnt->mnt_master = old->mnt_master; in clone_mnt()
1333 CLEAR_MNT_SHARED(mnt); in clone_mnt()
1336 set_mnt_shared(mnt); in clone_mnt()
1342 list_add(&mnt->mnt_expire, &old->mnt_expire); in clone_mnt()
1345 return mnt; in clone_mnt()
1348 mnt_free_id(mnt); in clone_mnt()
1349 free_vfsmnt(mnt); in clone_mnt()
1353 static void cleanup_mnt(struct mount *mnt) in cleanup_mnt() argument
1364 WARN_ON(mnt_get_writers(mnt)); in cleanup_mnt()
1365 if (unlikely(mnt->mnt_pins.first)) in cleanup_mnt()
1366 mnt_pin_kill(mnt); in cleanup_mnt()
1367 hlist_for_each_entry_safe(m, p, &mnt->mnt_stuck_children, mnt_umount) { in cleanup_mnt()
1369 mntput(&m->mnt); in cleanup_mnt()
1371 fsnotify_vfsmount_delete(&mnt->mnt); in cleanup_mnt()
1372 dput(mnt->mnt.mnt_root); in cleanup_mnt()
1373 deactivate_super(mnt->mnt.mnt_sb); in cleanup_mnt()
1374 mnt_free_id(mnt); in cleanup_mnt()
1375 call_rcu(&mnt->mnt_rcu, delayed_free_vfsmnt); in cleanup_mnt()
1394 static void mntput_no_expire(struct mount *mnt) in mntput_no_expire() argument
1400 if (likely(READ_ONCE(mnt->mnt_ns))) { in mntput_no_expire()
1410 mnt_add_count(mnt, -1); in mntput_no_expire()
1420 mnt_add_count(mnt, -1); in mntput_no_expire()
1421 count = mnt_get_count(mnt); in mntput_no_expire()
1428 if (unlikely(mnt->mnt.mnt_flags & MNT_DOOMED)) { in mntput_no_expire()
1433 mnt->mnt.mnt_flags |= MNT_DOOMED; in mntput_no_expire()
1436 list_del(&mnt->mnt_instance); in mntput_no_expire()
1438 if (unlikely(!list_empty(&mnt->mnt_mounts))) { in mntput_no_expire()
1440 list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts, mnt_child) { in mntput_no_expire()
1442 hlist_add_head(&p->mnt_umount, &mnt->mnt_stuck_children); in mntput_no_expire()
1448 if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) { in mntput_no_expire()
1451 init_task_work(&mnt->mnt_rcu, __cleanup_mnt); in mntput_no_expire()
1452 if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME)) in mntput_no_expire()
1455 if (llist_add(&mnt->mnt_llist, &delayed_mntput_list)) in mntput_no_expire()
1459 cleanup_mnt(mnt); in mntput_no_expire()
1462 void mntput(struct vfsmount *mnt) in mntput() argument
1464 if (mnt) { in mntput()
1465 struct mount *m = real_mount(mnt); in mntput()
1474 struct vfsmount *mntget(struct vfsmount *mnt) in mntget() argument
1476 if (mnt) in mntget()
1477 mnt_add_count(real_mount(mnt), 1); in mntget()
1478 return mnt; in mntget()
1487 void mnt_make_shortterm(struct vfsmount *mnt) in mnt_make_shortterm() argument
1489 if (mnt) in mnt_make_shortterm()
1490 real_mount(mnt)->mnt_ns = NULL; in mnt_make_shortterm()
1526 p = clone_mnt(real_mount(path->mnt), path->dentry, CL_PRIVATE); in mnt_clone_internal()
1529 p->mnt.mnt_flags |= MNT_INTERNAL; in mnt_clone_internal()
1530 return &p->mnt; in mnt_clone_internal()
1595 struct mount *next = NULL, *mnt = v; in m_next() local
1596 struct rb_node *node = rb_next(&mnt->mnt_node); in m_next()
1615 return p->show(m, &r->mnt); in m_show()
1637 struct mount *mnt = real_mount(m); in may_umount_tree() local
1645 for (p = mnt; p; p = next_mnt(p, mnt)) { in may_umount_tree()
1672 int may_umount(struct vfsmount *mnt) in may_umount() argument
1677 if (propagate_mount_busy(real_mount(mnt), 2)) in may_umount()
1707 mntput(&m->mnt); in namespace_unlock()
1722 static bool disconnect_mount(struct mount *mnt, enum umount_tree_flags how) in disconnect_mount() argument
1729 if (!mnt_has_parent(mnt)) in disconnect_mount()
1736 if (!(mnt->mnt_parent->mnt.mnt_flags & MNT_UMOUNT)) in disconnect_mount()
1744 if (IS_MNT_LOCKED(mnt)) in disconnect_mount()
1755 static void umount_tree(struct mount *mnt, enum umount_tree_flags how) in umount_tree() argument
1761 propagate_mount_unlock(mnt); in umount_tree()
1764 for (p = mnt; p; p = next_mnt(p, mnt)) { in umount_tree()
1765 p->mnt.mnt_flags |= MNT_UMOUNT; in umount_tree()
1766 if (p->mnt.mnt_flags & MNT_ONRB) in umount_tree()
1794 p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; in umount_tree()
1812 static void shrink_submounts(struct mount *mnt);
1837 static int do_umount(struct mount *mnt, int flags) in do_umount() argument
1839 struct super_block *sb = mnt->mnt.mnt_sb; in do_umount()
1842 retval = security_sb_umount(&mnt->mnt, flags); in do_umount()
1853 if (&mnt->mnt == current->fs->root.mnt || in do_umount()
1862 if (mnt_get_count(mnt) != 2) { in do_umount()
1868 if (!xchg(&mnt->mnt_expiry_mark, 1)) in do_umount()
1895 if (&mnt->mnt == current->fs->root.mnt && !(flags & MNT_DETACH)) { in do_umount()
1910 if (mnt->mnt.mnt_flags & MNT_LOCKED) in do_umount()
1915 if (mnt->mnt.mnt_flags & MNT_ONRB || in do_umount()
1916 !list_empty(&mnt->mnt_list)) in do_umount()
1917 umount_tree(mnt, UMOUNT_PROPAGATE); in do_umount()
1920 shrink_submounts(mnt); in do_umount()
1922 if (!propagate_mount_busy(mnt, 2)) { in do_umount()
1923 if (mnt->mnt.mnt_flags & MNT_ONRB || in do_umount()
1924 !list_empty(&mnt->mnt_list)) in do_umount()
1925 umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC); in do_umount()
1948 struct mount *mnt; in __detach_mounts() local
1958 mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list); in __detach_mounts()
1959 if (mnt->mnt.mnt_flags & MNT_UMOUNT) { in __detach_mounts()
1960 umount_mnt(mnt); in __detach_mounts()
1961 hlist_add_head(&mnt->mnt_umount, &unmounted); in __detach_mounts()
1963 else umount_tree(mnt, UMOUNT_CONNECTED); in __detach_mounts()
1990 struct mount *mnt = real_mount(path->mnt); in can_umount() local
1996 if (!check_mnt(mnt)) in can_umount()
1998 if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */ in can_umount()
2008 struct mount *mnt = real_mount(path->mnt); in path_umount() local
2013 ret = do_umount(mnt, flags); in path_umount()
2017 mntput_no_expire(mnt); in path_umount()
2063 struct ns_common *from_mnt_ns(struct mnt_namespace *mnt) in from_mnt_ns() argument
2065 return &mnt->ns; in from_mnt_ns()
2140 if (src_mnt->mnt.mnt_flags & MNT_LOCKED) { in copy_tree()
2150 is_mnt_ns_file(src_mnt->mnt.mnt_root)) { in copy_tree()
2161 dst_mnt = clone_mnt(src_mnt, src_mnt->mnt.mnt_root, flag); in copy_tree()
2187 if (!check_mnt(real_mount(path->mnt))) in collect_mounts()
2190 tree = copy_tree(real_mount(path->mnt), path->dentry, in collect_mounts()
2195 return &tree->mnt; in collect_mounts()
2201 void dissolve_on_fput(struct vfsmount *mnt) in dissolve_on_fput() argument
2206 ns = real_mount(mnt)->mnt_ns; in dissolve_on_fput()
2209 umount_tree(real_mount(mnt), UMOUNT_CONNECTED); in dissolve_on_fput()
2219 void drop_collected_mounts(struct vfsmount *mnt) in drop_collected_mounts() argument
2223 umount_tree(real_mount(mnt), 0); in drop_collected_mounts()
2228 bool has_locked_children(struct mount *mnt, struct dentry *dentry) in has_locked_children() argument
2232 list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { in has_locked_children()
2236 if (child->mnt.mnt_flags & MNT_LOCKED) in has_locked_children()
2254 struct mount *old_mnt = real_mount(path->mnt); in clone_private_mount()
2276 return &new_mnt->mnt; in clone_private_mount()
2287 struct mount *mnt; in iterate_mounts() local
2291 list_for_each_entry(mnt, &real_mount(root)->mnt_list, mnt_list) { in iterate_mounts()
2292 res = f(&mnt->mnt, arg); in iterate_mounts()
2299 static void lock_mnt_tree(struct mount *mnt) in lock_mnt_tree() argument
2303 for (p = mnt; p; p = next_mnt(p, mnt)) { in lock_mnt_tree()
2304 int flags = p->mnt.mnt_flags; in lock_mnt_tree()
2322 p->mnt.mnt_flags = flags; in lock_mnt_tree()
2326 static void cleanup_group_ids(struct mount *mnt, struct mount *end) in cleanup_group_ids() argument
2330 for (p = mnt; p != end; p = next_mnt(p, mnt)) { in cleanup_group_ids()
2336 static int invent_group_ids(struct mount *mnt, bool recurse) in invent_group_ids() argument
2340 for (p = mnt; p; p = recurse ? next_mnt(p, mnt) : NULL) { in invent_group_ids()
2344 cleanup_group_ids(mnt, p); in invent_group_ids()
2353 int count_mounts(struct mnt_namespace *ns, struct mount *mnt) in count_mounts() argument
2366 for (p = mnt; p; p = next_mnt(p, mnt)) in count_mounts()
2466 smp = get_mountpoint(source_mnt->mnt.mnt_root); in attach_recursive_mnt()
2522 q = __lookup_mnt(&child->mnt_parent->mnt, in attach_recursive_mnt()
2529 child->mnt.mnt_flags &= ~MNT_LOCKED; in attach_recursive_mnt()
2591 struct vfsmount *mnt = path->mnt; in do_lock_mount() local
2599 m = real_mount(mnt); in do_lock_mount()
2615 if (beneath && (!is_mounted(mnt) || m->mnt_mountpoint != dentry)) { in do_lock_mount()
2621 mnt = lookup_mnt(path); in do_lock_mount()
2622 if (likely(!mnt)) in do_lock_mount()
2630 path->mnt = mnt; in do_lock_mount()
2631 path->dentry = dget(mnt->mnt_root); in do_lock_mount()
2664 static int graft_tree(struct mount *mnt, struct mount *p, struct mountpoint *mp) in graft_tree() argument
2666 if (mnt->mnt.mnt_sb->s_flags & SB_NOUSER) in graft_tree()
2670 d_is_dir(mnt->mnt.mnt_root)) in graft_tree()
2673 return attach_recursive_mnt(mnt, p, mp, 0); in graft_tree()
2699 struct mount *mnt = real_mount(path->mnt); in do_change_type() local
2713 err = invent_group_ids(mnt, recurse); in do_change_type()
2719 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL)) in do_change_type()
2730 struct mount *mnt = ERR_PTR(-EINVAL), *old = real_mount(old_path->mnt); in __do_loopback() local
2733 return mnt; in __do_loopback()
2736 return mnt; in __do_loopback()
2739 return mnt; in __do_loopback()
2742 mnt = copy_tree(old, old_path->dentry, CL_COPY_MNT_NS_FILE); in __do_loopback()
2744 mnt = clone_mnt(old, old_path->dentry, 0); in __do_loopback()
2746 if (!IS_ERR(mnt)) in __do_loopback()
2747 mnt->mnt.mnt_flags &= ~MNT_LOCKED; in __do_loopback()
2749 return mnt; in __do_loopback()
2759 struct mount *mnt = NULL, *parent; in do_loopback() local
2778 parent = real_mount(path->mnt); in do_loopback()
2782 mnt = __do_loopback(&old_path, recurse); in do_loopback()
2783 if (IS_ERR(mnt)) { in do_loopback()
2784 err = PTR_ERR(mnt); in do_loopback()
2788 err = graft_tree(mnt, parent, mp); in do_loopback()
2791 umount_tree(mnt, UMOUNT_SYNC); in do_loopback()
2805 struct mount *mnt, *p; in open_detached_copy() local
2812 mnt = __do_loopback(path, recursive); in open_detached_copy()
2813 if (IS_ERR(mnt)) { in open_detached_copy()
2816 return ERR_CAST(mnt); in open_detached_copy()
2820 for (p = mnt; p; p = next_mnt(p, mnt)) { in open_detached_copy()
2824 ns->root = mnt; in open_detached_copy()
2825 mntget(&mnt->mnt); in open_detached_copy()
2829 mntput(path->mnt); in open_detached_copy()
2830 path->mnt = &mnt->mnt; in open_detached_copy()
2833 dissolve_on_fput(path->mnt); in open_detached_copy()
2896 static bool can_change_locked_flags(struct mount *mnt, unsigned int mnt_flags) in can_change_locked_flags() argument
2898 unsigned int fl = mnt->mnt.mnt_flags; in can_change_locked_flags()
2923 static int change_mount_ro_state(struct mount *mnt, unsigned int mnt_flags) in change_mount_ro_state() argument
2927 if (readonly_request == __mnt_is_readonly(&mnt->mnt)) in change_mount_ro_state()
2931 return mnt_make_readonly(mnt); in change_mount_ro_state()
2933 mnt->mnt.mnt_flags &= ~MNT_READONLY; in change_mount_ro_state()
2937 static void set_mount_attributes(struct mount *mnt, unsigned int mnt_flags) in set_mount_attributes() argument
2939 mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK; in set_mount_attributes()
2940 mnt->mnt.mnt_flags = mnt_flags; in set_mount_attributes()
2941 touch_mnt_namespace(mnt->mnt_ns); in set_mount_attributes()
2944 static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *mnt) in mnt_warn_timestamp_expiry() argument
2946 struct super_block *sb = mnt->mnt_sb; in mnt_warn_timestamp_expiry()
2948 if (!__mnt_is_readonly(mnt) && in mnt_warn_timestamp_expiry()
2963 is_mounted(mnt) ? "remounted" : "mounted", in mnt_warn_timestamp_expiry()
2980 struct super_block *sb = path->mnt->mnt_sb; in do_reconfigure_mnt()
2981 struct mount *mnt = real_mount(path->mnt); in do_reconfigure_mnt() local
2984 if (!check_mnt(mnt)) in do_reconfigure_mnt()
2990 if (!can_change_locked_flags(mnt, mnt_flags)) in do_reconfigure_mnt()
2999 ret = change_mount_ro_state(mnt, mnt_flags); in do_reconfigure_mnt()
3001 set_mount_attributes(mnt, mnt_flags); in do_reconfigure_mnt()
3005 mnt_warn_timestamp_expiry(path, &mnt->mnt); in do_reconfigure_mnt()
3019 struct super_block *sb = path->mnt->mnt_sb; in do_remount()
3020 struct mount *mnt = real_mount(path->mnt); in do_remount() local
3023 if (!check_mnt(mnt)) in do_remount()
3029 if (!can_change_locked_flags(mnt, mnt_flags)) in do_remount()
3050 set_mount_attributes(mnt, mnt_flags); in do_remount()
3057 mnt_warn_timestamp_expiry(path, &mnt->mnt); in do_remount()
3063 static inline int tree_contains_unbindable(struct mount *mnt) in tree_contains_unbindable() argument
3066 for (p = mnt; p; p = next_mnt(p, mnt)) { in tree_contains_unbindable()
3086 if (mnt_ns_loop(p->mnt.mnt_root)) in check_for_nsfs_mounts()
3100 from = real_mount(from_path->mnt); in do_set_group()
3101 to = real_mount(to_path->mnt); in do_set_group()
3107 if (!is_mounted(&from->mnt)) in do_set_group()
3109 if (!is_mounted(&to->mnt)) in do_set_group()
3127 if (from->mnt.mnt_sb != to->mnt.mnt_sb) in do_set_group()
3131 if (!is_subdir(to->mnt.mnt_root, from->mnt.mnt_root)) in do_set_group()
3135 if (has_locked_children(from, to->mnt.mnt_root)) in do_set_group()
3180 if (unlikely(__lookup_mnt(path->mnt, path->dentry))) { in path_overmounted()
3213 struct mount *mnt_from = real_mount(from->mnt), in can_move_mount_beneath()
3214 *mnt_to = real_mount(to->mnt), in can_move_mount_beneath()
3234 if (&mnt_to->mnt == current->fs->root.mnt) in can_move_mount_beneath()
3286 old = real_mount(old_path->mnt); in do_move_mount()
3287 p = real_mount(new_path->mnt); in do_move_mount()
3301 if (!is_mounted(&old->mnt)) in do_move_mount()
3308 if (old->mnt.mnt_flags & MNT_LOCKED) in do_move_mount()
3346 err = attach_recursive_mnt(old, real_mount(new_path->mnt), mp, flags); in do_move_mount()
3389 struct mount *parent = real_mount(path->mnt); in do_add_mount()
3403 if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && path_mounted(path)) in do_add_mount()
3406 if (d_is_symlink(newmnt->mnt.mnt_root)) in do_add_mount()
3409 newmnt->mnt.mnt_flags = mnt_flags; in do_add_mount()
3422 struct vfsmount *mnt; in do_new_mount_fc() local
3438 mnt = vfs_create_mount(fc); in do_new_mount_fc()
3439 if (IS_ERR(mnt)) in do_new_mount_fc()
3440 return PTR_ERR(mnt); in do_new_mount_fc()
3442 mnt_warn_timestamp_expiry(mountpoint, mnt); in do_new_mount_fc()
3446 mntput(mnt); in do_new_mount_fc()
3449 error = do_add_mount(real_mount(mnt), mp, mountpoint, mnt_flags); in do_new_mount_fc()
3452 mntput(mnt); in do_new_mount_fc()
3519 struct mount *mnt; in finish_automount() local
3527 mnt = real_mount(m); in finish_automount()
3531 BUG_ON(mnt_get_count(mnt) < 2); in finish_automount()
3533 if (m->mnt_sb == path->mnt->mnt_sb && in finish_automount()
3560 err = do_add_mount(mnt, mp, path, path->mnt->mnt_flags | MNT_SHRINKABLE); in finish_automount()
3572 if (!list_empty(&mnt->mnt_expire)) { in finish_automount()
3574 list_del_init(&mnt->mnt_expire); in finish_automount()
3587 void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list) in mnt_set_expiry() argument
3591 list_add_tail(&real_mount(mnt)->mnt_expire, expiry_list); in mnt_set_expiry()
3604 struct mount *mnt, *next; in mark_mounts_for_expiry() local
3619 list_for_each_entry_safe(mnt, next, mounts, mnt_expire) { in mark_mounts_for_expiry()
3620 if (!xchg(&mnt->mnt_expiry_mark, 1) || in mark_mounts_for_expiry()
3621 propagate_mount_busy(mnt, 1)) in mark_mounts_for_expiry()
3623 list_move(&mnt->mnt_expire, &graveyard); in mark_mounts_for_expiry()
3626 mnt = list_first_entry(&graveyard, struct mount, mnt_expire); in mark_mounts_for_expiry()
3627 touch_mnt_namespace(mnt->mnt_ns); in mark_mounts_for_expiry()
3628 umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC); in mark_mounts_for_expiry()
3653 struct mount *mnt = list_entry(tmp, struct mount, mnt_child); in select_submounts() local
3656 if (!(mnt->mnt.mnt_flags & MNT_SHRINKABLE)) in select_submounts()
3661 if (!list_empty(&mnt->mnt_mounts)) { in select_submounts()
3662 this_parent = mnt; in select_submounts()
3666 if (!propagate_mount_busy(mnt, 1)) { in select_submounts()
3667 list_move_tail(&mnt->mnt_expire, graveyard); in select_submounts()
3688 static void shrink_submounts(struct mount *mnt) in shrink_submounts() argument
3694 while (select_submounts(mnt, &graveyard)) { in shrink_submounts()
3811 mnt_flags |= path->mnt->mnt_flags & MNT_ATIME_MASK; in path_mount()
3944 new = copy_tree(old, old->mnt.mnt_root, copy_flags); in copy_mnt_ns()
3970 if (&p->mnt == new_fs->root.mnt) { in copy_mnt_ns()
3971 new_fs->root.mnt = mntget(&q->mnt); in copy_mnt_ns()
3972 rootmnt = &p->mnt; in copy_mnt_ns()
3974 if (&p->mnt == new_fs->pwd.mnt) { in copy_mnt_ns()
3975 new_fs->pwd.mnt = mntget(&q->mnt); in copy_mnt_ns()
3976 pwdmnt = &p->mnt; in copy_mnt_ns()
3984 while (p->mnt.mnt_root != q->mnt.mnt_root) in copy_mnt_ns()
4000 struct mount *mnt = real_mount(m); in mount_subtree() local
4011 ns->root = mnt; in mount_subtree()
4013 mnt_add_to_ns(ns, mnt); in mount_subtree()
4024 s = path.mnt->mnt_sb; in mount_subtree()
4026 mntput(path.mnt); in mount_subtree()
4109 struct mount *mnt; in SYSCALL_DEFINE3() local
4170 newmount.mnt = vfs_create_mount(fc); in SYSCALL_DEFINE3()
4171 if (IS_ERR(newmount.mnt)) { in SYSCALL_DEFINE3()
4172 ret = PTR_ERR(newmount.mnt); in SYSCALL_DEFINE3()
4176 newmount.mnt->mnt_flags = mnt_flags; in SYSCALL_DEFINE3()
4190 mnt = real_mount(newmount.mnt); in SYSCALL_DEFINE3()
4191 ns->root = mnt; in SYSCALL_DEFINE3()
4193 mnt_add_to_ns(ns, mnt); in SYSCALL_DEFINE3()
4194 mntget(newmount.mnt); in SYSCALL_DEFINE3()
4201 dissolve_on_fput(newmount.mnt); in SYSCALL_DEFINE3()
4293 bool is_path_reachable(struct mount *mnt, struct dentry *dentry, in is_path_reachable() argument
4296 while (&mnt->mnt != root->mnt && mnt_has_parent(mnt)) { in is_path_reachable()
4297 dentry = mnt->mnt_mountpoint; in is_path_reachable()
4298 mnt = mnt->mnt_parent; in is_path_reachable()
4300 return &mnt->mnt == root->mnt && is_subdir(dentry, root->dentry); in is_path_reachable()
4307 res = is_path_reachable(real_mount(path1->mnt), path1->dentry, path2); in path_is_under()
4370 new_mnt = real_mount(new.mnt); in SYSCALL_DEFINE2()
4371 root_mnt = real_mount(root.mnt); in SYSCALL_DEFINE2()
4372 old_mnt = real_mount(old.mnt); in SYSCALL_DEFINE2()
4381 if (new_mnt->mnt.mnt_flags & MNT_LOCKED) in SYSCALL_DEFINE2()
4407 if (root_mnt->mnt.mnt_flags & MNT_LOCKED) { in SYSCALL_DEFINE2()
4408 new_mnt->mnt.mnt_flags |= MNT_LOCKED; in SYSCALL_DEFINE2()
4409 root_mnt->mnt.mnt_flags &= ~MNT_LOCKED; in SYSCALL_DEFINE2()
4437 static unsigned int recalc_flags(struct mount_kattr *kattr, struct mount *mnt) in recalc_flags() argument
4439 unsigned int flags = mnt->mnt.mnt_flags; in recalc_flags()
4449 static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt) in can_idmap_mount() argument
4451 struct vfsmount *m = &mnt->mnt; in can_idmap_mount()
4485 if (!is_anon_ns(mnt->mnt_ns)) in can_idmap_mount()
4501 const struct mount *mnt) in mnt_allow_writers() argument
4504 (mnt->mnt.mnt_flags & MNT_READONLY)) && in mnt_allow_writers()
4508 static int mount_setattr_prepare(struct mount_kattr *kattr, struct mount *mnt) in mount_setattr_prepare() argument
4513 for (m = mnt; m; m = next_mnt(m, mnt)) { in mount_setattr_prepare()
4541 for (p = mnt; p; p = next_mnt(p, mnt)) { in mount_setattr_prepare()
4543 if (p->mnt.mnt_flags & MNT_WRITE_HOLD) in mount_setattr_prepare()
4557 static void do_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt) in do_idmap_mount() argument
4570 smp_store_release(&mnt->mnt.mnt_idmap, mnt_idmap_get(kattr->mnt_idmap)); in do_idmap_mount()
4573 static void mount_setattr_commit(struct mount_kattr *kattr, struct mount *mnt) in mount_setattr_commit() argument
4577 for (m = mnt; m; m = next_mnt(m, mnt)) { in mount_setattr_commit()
4582 WRITE_ONCE(m->mnt.mnt_flags, flags); in mount_setattr_commit()
4585 if (m->mnt.mnt_flags & MNT_WRITE_HOLD) in mount_setattr_commit()
4593 touch_mnt_namespace(mnt->mnt_ns); in mount_setattr_commit()
4598 struct mount *mnt = real_mount(path->mnt); in do_mount_setattr() local
4620 err = invent_group_ids(mnt, kattr->recurse); in do_mount_setattr()
4632 if (!is_mounted(&mnt->mnt)) in do_mount_setattr()
4646 if ((mnt_has_parent(mnt) || !is_anon_ns(mnt->mnt_ns)) && !check_mnt(mnt)) in do_mount_setattr()
4654 err = mount_setattr_prepare(kattr, mnt); in do_mount_setattr()
4656 mount_setattr_commit(kattr, mnt); in do_mount_setattr()
4663 cleanup_group_ids(mnt, NULL); in do_mount_setattr()
4869 struct mount *mnt = mnt_find_id_at(ns, id); in lookup_mnt_in_ns() local
4871 if (!mnt || mnt->mnt_id_unique != id) in lookup_mnt_in_ns()
4874 return &mnt->mnt; in lookup_mnt_in_ns()
4880 struct vfsmount *mnt; member
4887 static u64 mnt_to_attr_flags(struct vfsmount *mnt) in mnt_to_attr_flags() argument
4889 unsigned int mnt_flags = READ_ONCE(mnt->mnt_flags); in mnt_to_attr_flags()
4912 if (is_idmapped_mnt(mnt)) in mnt_to_attr_flags()
4936 struct super_block *sb = s->mnt->mnt_sb; in statmount_sb_basic()
4947 struct mount *m = real_mount(s->mnt); in statmount_mnt_basic()
4954 s->sm.mnt_attr = mnt_to_attr_flags(&m->mnt); in statmount_mnt_basic()
4962 struct mount *m = real_mount(s->mnt); in statmount_propagate_from()
4974 ret = show_path(seq, s->mnt->mnt_root); in statmount_mnt_root()
4993 struct vfsmount *mnt = s->mnt; in statmount_mnt_point() local
4994 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; in statmount_mnt_point()
5003 struct super_block *sb = s->mnt->mnt_sb; in statmount_fs_type()
5017 struct vfsmount *mnt = s->mnt; in statmount_mnt_opts() local
5018 struct super_block *sb = mnt->mnt_sb; in statmount_mnt_opts()
5024 err = sb->s_op->show_options(seq, mnt->mnt_root); in statmount_mnt_opts()
5147 root->mnt = mntget(&child->mnt); in grab_requested_root()
5148 root->dentry = dget(root->mnt->mnt_root); in grab_requested_root()
5163 s->mnt = lookup_mnt_in_ns(mnt_id, ns); in do_statmount()
5164 if (!s->mnt) in do_statmount()
5175 m = real_mount(s->mnt); in do_statmount()
5176 if (!is_path_reachable(m, m->mnt.mnt_root, &root) && in do_statmount()
5180 err = security_sb_statfs(s->mnt->mnt_root); in do_statmount()
5384 orig.mnt = lookup_mnt_in_ns(mnt_parent_id, ns); in do_listmount()
5385 if (!orig.mnt) in do_listmount()
5387 orig.dentry = orig.mnt->mnt_root; in do_listmount()
5394 if (!is_path_reachable(real_mount(orig.mnt), orig.dentry, &root) && in do_listmount()
5417 if (!is_path_reachable(r, r->mnt.mnt_root, &orig)) in do_listmount()
5487 struct vfsmount *mnt; in init_mount_tree() local
5492 mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL); in init_mount_tree()
5493 if (IS_ERR(mnt)) in init_mount_tree()
5499 m = real_mount(mnt); in init_mount_tree()
5506 root.mnt = mnt; in init_mount_tree()
5507 root.dentry = mnt->mnt_root; in init_mount_tree()
5508 mnt->mnt_flags |= MNT_LOCKED; in init_mount_tree()
5555 drop_collected_mounts(&ns->root->mnt); in put_mnt_ns()
5561 struct vfsmount *mnt; in kern_mount() local
5562 mnt = vfs_kern_mount(type, SB_KERNMOUNT, type->name, NULL); in kern_mount()
5563 if (!IS_ERR(mnt)) { in kern_mount()
5568 real_mount(mnt)->mnt_ns = MNT_NS_INTERNAL; in kern_mount()
5570 return mnt; in kern_mount()
5574 void kern_unmount(struct vfsmount *mnt) in kern_unmount() argument
5577 if (!IS_ERR(mnt)) { in kern_unmount()
5578 mnt_make_shortterm(mnt); in kern_unmount()
5580 mntput(mnt); in kern_unmount()
5585 void kern_unmount_array(struct vfsmount *mnt[], unsigned int num) in kern_unmount_array() argument
5590 mnt_make_shortterm(mnt[i]); in kern_unmount_array()
5593 mntput(mnt[i]); in kern_unmount_array()
5597 bool our_mnt(struct vfsmount *mnt) in our_mnt() argument
5599 return check_mnt(real_mount(mnt)); in our_mnt()
5610 ns_root.mnt = ¤t->nsproxy->mnt_ns->root->mnt; in current_chrooted()
5611 ns_root.dentry = ns_root.mnt->mnt_root; in current_chrooted()
5631 struct mount *mnt, *n; in mnt_already_visible() local
5635 rbtree_postorder_for_each_entry_safe(mnt, n, &ns->mounts, mnt_node) { in mnt_already_visible()
5639 if (mnt->mnt.mnt_sb->s_type != sb->s_type) in mnt_already_visible()
5645 if (mnt->mnt.mnt_root != mnt->mnt.mnt_sb->s_root) in mnt_already_visible()
5649 mnt_flags = mnt->mnt.mnt_flags; in mnt_already_visible()
5652 if (sb_rdonly(mnt->mnt.mnt_sb)) in mnt_already_visible()
5669 list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { in mnt_already_visible()
5672 if (!(child->mnt.mnt_flags & MNT_LOCKED)) in mnt_already_visible()
5713 bool mnt_may_suid(struct vfsmount *mnt) in mnt_may_suid() argument
5722 return !(mnt->mnt_flags & MNT_NOSUID) && check_mnt(real_mount(mnt)) && in mnt_may_suid()
5723 current_in_userns(mnt->mnt_sb->s_user_ns); in mnt_may_suid()
5772 err = vfs_path_lookup(mnt_ns->root->mnt.mnt_root, &mnt_ns->root->mnt, in mntns_install()