466
466
br_write_unlock(vfsmount_lock);
469
void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
472
mnt->mnt_root = dget(sb->s_root);
475
EXPORT_SYMBOL(simple_set_mnt);
477
void free_vfsmnt(struct vfsmount *mnt)
469
static void free_vfsmnt(struct vfsmount *mnt)
479
471
kfree(mnt->mnt_devname);
480
472
mnt_free_id(mnt);
674
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
676
struct vfsmount *mnt;
680
return ERR_PTR(-ENODEV);
682
mnt = alloc_vfsmnt(name);
684
return ERR_PTR(-ENOMEM);
686
if (flags & MS_KERNMOUNT)
687
mnt->mnt_flags = MNT_INTERNAL;
689
root = mount_fs(type, flags, name, data);
692
return ERR_CAST(root);
695
mnt->mnt_root = root;
696
mnt->mnt_sb = root->d_sb;
697
mnt->mnt_mountpoint = mnt->mnt_root;
698
mnt->mnt_parent = mnt;
701
EXPORT_SYMBOL_GPL(vfs_kern_mount);
681
703
static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
979
1001
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
981
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
1003
if (mnt->mnt_sb->s_op->show_devname) {
1004
err = mnt->mnt_sb->s_op->show_devname(m, mnt);
1008
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
982
1010
seq_putc(m, ' ');
983
1011
seq_path(m, &mnt_path, " \t\n\\");
984
1012
seq_putc(m, ' ');
1014
1042
seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
1015
1043
MAJOR(sb->s_dev), MINOR(sb->s_dev));
1016
seq_dentry(m, mnt->mnt_root, " \t\n\\");
1044
if (sb->s_op->show_path)
1045
err = sb->s_op->show_path(m, mnt);
1047
seq_dentry(m, mnt->mnt_root, " \t\n\\");
1017
1050
seq_putc(m, ' ');
1018
1051
seq_path_root(m, &mnt_path, &root, " \t\n\\");
1019
1052
if (root.mnt != p->root.mnt || root.dentry != p->root.dentry) {
1044
1077
seq_puts(m, " - ");
1045
1078
show_type(m, sb);
1046
1079
seq_putc(m, ' ');
1047
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
1080
if (sb->s_op->show_devname)
1081
err = sb->s_op->show_devname(m, mnt);
1083
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
1048
1086
seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
1049
1087
err = show_sb_opts(m, sb);
1073
if (mnt->mnt_devname) {
1074
seq_puts(m, "device ");
1075
mangle(m, mnt->mnt_devname);
1077
seq_puts(m, "no device");
1111
if (mnt->mnt_sb->s_op->show_devname) {
1112
err = mnt->mnt_sb->s_op->show_devname(m, mnt);
1114
if (mnt->mnt_devname) {
1115
seq_puts(m, "device ");
1116
mangle(m, mnt->mnt_devname);
1118
seq_puts(m, "no device");
1079
1121
/* mount point */
1080
1122
seq_puts(m, " mounted on ");
1088
1130
/* optional statistics */
1089
1131
if (mnt->mnt_sb->s_op->show_stats) {
1090
1132
seq_putc(m, ' ');
1091
err = mnt->mnt_sb->s_op->show_stats(m, mnt);
1134
err = mnt->mnt_sb->s_op->show_stats(m, mnt);
1094
1137
seq_putc(m, '\n');
1651
static int lock_mount(struct path *path)
1653
struct vfsmount *mnt;
1655
mutex_lock(&path->dentry->d_inode->i_mutex);
1656
if (unlikely(cant_mount(path->dentry))) {
1657
mutex_unlock(&path->dentry->d_inode->i_mutex);
1660
down_write(&namespace_sem);
1661
mnt = lookup_mnt(path);
1664
up_write(&namespace_sem);
1665
mutex_unlock(&path->dentry->d_inode->i_mutex);
1668
path->dentry = dget(mnt->mnt_root);
1672
static void unlock_mount(struct path *path)
1674
up_write(&namespace_sem);
1675
mutex_unlock(&path->dentry->d_inode->i_mutex);
1608
1678
static int graft_tree(struct vfsmount *mnt, struct path *path)
1611
1680
if (mnt->mnt_sb->s_flags & MS_NOUSER)
1612
1681
return -EINVAL;
1615
1684
S_ISDIR(mnt->mnt_root->d_inode->i_mode))
1616
1685
return -ENOTDIR;
1619
mutex_lock(&path->dentry->d_inode->i_mutex);
1620
if (cant_mount(path->dentry))
1687
if (d_unlinked(path->dentry))
1623
if (!d_unlinked(path->dentry))
1624
err = attach_recursive_mnt(mnt, path, NULL);
1626
mutex_unlock(&path->dentry->d_inode->i_mutex);
1690
return attach_recursive_mnt(mnt, path, NULL);
1634
1697
static int flags_to_propagation_type(int flags)
1636
int type = flags & ~MS_REC;
1699
int type = flags & ~(MS_REC | MS_SILENT);
1638
1701
/* Fail if any non-propagation flags are set */
1639
1702
if (type & ~(MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
1713
1780
mnt = clone_mnt(old_path.mnt, old_path.dentry, 0);
1718
1785
err = graft_tree(mnt, path);
1720
LIST_HEAD(umount_list);
1722
1787
br_write_lock(vfsmount_lock);
1723
1788
umount_tree(mnt, 0, &umount_list);
1724
1789
br_write_unlock(vfsmount_lock);
1725
release_mounts(&umount_list);
1793
release_mounts(&umount_list);
1729
up_write(&namespace_sem);
1730
1795
path_put(&old_path);
1768
1833
if (path->dentry != path->mnt->mnt_root)
1769
1834
return -EINVAL;
1836
err = security_sb_remount(sb, data);
1771
1840
down_write(&sb->s_umount);
1772
1841
if (flags & MS_BIND)
1773
1842
err = change_mount_flags(path->mnt, flags);
1814
down_write(&namespace_sem);
1815
err = follow_down(path, true);
1883
err = lock_mount(path);
1820
1888
if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt))
1824
mutex_lock(&path->dentry->d_inode->i_mutex);
1825
if (cant_mount(path->dentry))
1828
1891
if (d_unlinked(path->dentry))
1864
1927
* automatically */
1865
1928
list_del_init(&old_path.mnt->mnt_expire);
1867
mutex_unlock(&path->dentry->d_inode->i_mutex);
1869
up_write(&namespace_sem);
1871
1933
path_put(&parent_path);
1872
1934
path_put(&old_path);
1876
static int do_add_mount(struct vfsmount *, struct path *, int);
1938
static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype)
1941
const char *subtype = strchr(fstype, '.');
1950
mnt->mnt_sb->s_subtype = kstrdup(subtype, GFP_KERNEL);
1952
if (!mnt->mnt_sb->s_subtype)
1958
return ERR_PTR(err);
1962
do_kern_mount(const char *fstype, int flags, const char *name, void *data)
1964
struct file_system_type *type = get_fs_type(fstype);
1965
struct vfsmount *mnt;
1967
return ERR_PTR(-ENODEV);
1968
mnt = vfs_kern_mount(type, flags, name, data);
1969
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
1970
!mnt->mnt_sb->s_subtype)
1971
mnt = fs_set_subtype(mnt, fstype);
1972
put_filesystem(type);
1975
EXPORT_SYMBOL_GPL(do_kern_mount);
1978
* add a mount into a namespace's mount tree
1980
static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags)
1984
mnt_flags &= ~(MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL);
1986
err = lock_mount(path);
1991
if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(path->mnt))
1994
/* Refuse the same filesystem on the same mount point */
1996
if (path->mnt->mnt_sb == newmnt->mnt_sb &&
1997
path->mnt->mnt_root == path->dentry)
2001
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
2004
newmnt->mnt_flags = mnt_flags;
2005
err = graft_tree(newmnt, path);
1879
2013
* create a new mount for userspace and request it to be added into the
1937
* add a mount into a namespace's mount tree
1939
static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags)
1943
mnt_flags &= ~(MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL);
1945
down_write(&namespace_sem);
1946
/* Something was mounted here while we slept */
1947
err = follow_down(path, true);
1952
if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(path->mnt))
1955
/* Refuse the same filesystem on the same mount point */
1957
if (path->mnt->mnt_sb == newmnt->mnt_sb &&
1958
path->mnt->mnt_root == path->dentry)
1962
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
1965
newmnt->mnt_flags = mnt_flags;
1966
err = graft_tree(newmnt, path);
1969
up_write(&namespace_sem);
1974
2071
* mnt_set_expiry - Put a mount on an expiration list
1975
2072
* @mnt: The mount to list.
2478
2575
error = security_sb_pivotroot(&old, &new);
2484
2579
get_fs_root(current->fs, &root);
2485
down_write(&namespace_sem);
2486
mutex_lock(&old.dentry->d_inode->i_mutex);
2580
error = lock_mount(&old);
2487
2584
error = -EINVAL;
2488
2585
if (IS_MNT_SHARED(old.mnt) ||
2489
2586
IS_MNT_SHARED(new.mnt->mnt_parent) ||
2490
2587
IS_MNT_SHARED(root.mnt->mnt_parent))
2492
2589
if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
2494
2591
error = -ENOENT;
2495
if (cant_mount(old.dentry))
2497
2592
if (d_unlinked(new.dentry))
2499
2594
if (d_unlinked(old.dentry))
2501
2596
error = -EBUSY;
2502
2597
if (new.mnt == root.mnt ||
2503
2598
old.mnt == root.mnt)
2504
goto out2; /* loop, on the same file system */
2599
goto out4; /* loop, on the same file system */
2505
2600
error = -EINVAL;
2506
2601
if (root.mnt->mnt_root != root.dentry)
2507
goto out2; /* not a mountpoint */
2602
goto out4; /* not a mountpoint */
2508
2603
if (root.mnt->mnt_parent == root.mnt)
2509
goto out2; /* not attached */
2604
goto out4; /* not attached */
2510
2605
if (new.mnt->mnt_root != new.dentry)
2511
goto out2; /* not a mountpoint */
2606
goto out4; /* not a mountpoint */
2512
2607
if (new.mnt->mnt_parent == new.mnt)
2513
goto out2; /* not attached */
2608
goto out4; /* not attached */
2514
2609
/* make sure we can reach put_old from new_root */
2516
2611
if (tmp != new.mnt) {
2518
2613
if (tmp->mnt_parent == tmp)
2519
goto out2; /* already mounted on put_old */
2614
goto out4; /* already mounted on put_old */
2520
2615
if (tmp->mnt_parent == new.mnt)
2522
2617
tmp = tmp->mnt_parent;
2524
2619
if (!is_subdir(tmp->mnt_mountpoint, new.dentry))
2526
2621
} else if (!is_subdir(old.dentry, new.dentry))
2528
2623
br_write_lock(vfsmount_lock);
2529
2624
detach_mnt(new.mnt, &parent_path);
2530
2625
detach_mnt(root.mnt, &root_parent);
2535
2630
touch_mnt_namespace(current->nsproxy->mnt_ns);
2536
2631
br_write_unlock(vfsmount_lock);
2537
2632
chroot_fs_refs(&root, &new);
2540
path_put(&root_parent);
2541
path_put(&parent_path);
2543
mutex_unlock(&old.dentry->d_inode->i_mutex);
2544
up_write(&namespace_sem);
2637
path_put(&root_parent);
2638
path_put(&parent_path);
2545
2641
path_put(&root);
2546
2643
path_put(&old);
2548
2645
path_put(&new);
2589
2686
if (!mount_hashtable)
2590
2687
panic("Failed to allocate mount hash table\n");
2592
printk("Mount-cache hash table entries: %lu\n", HASH_SIZE);
2689
printk(KERN_INFO "Mount-cache hash table entries: %lu\n", HASH_SIZE);
2594
2691
for (u = 0; u < HASH_SIZE; u++)
2595
2692
INIT_LIST_HEAD(&mount_hashtable[u]);
2624
2721
EXPORT_SYMBOL(put_mnt_ns);
2723
struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
2725
return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
2727
EXPORT_SYMBOL_GPL(kern_mount_data);