~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/namespace.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
196
196
#endif
197
197
}
198
198
 
199
 
struct vfsmount *alloc_vfsmnt(const char *name)
 
199
static struct vfsmount *alloc_vfsmnt(const char *name)
200
200
{
201
201
        struct vfsmount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
202
202
        if (mnt) {
466
466
        br_write_unlock(vfsmount_lock);
467
467
}
468
468
 
469
 
void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
470
 
{
471
 
        mnt->mnt_sb = sb;
472
 
        mnt->mnt_root = dget(sb->s_root);
473
 
}
474
 
 
475
 
EXPORT_SYMBOL(simple_set_mnt);
476
 
 
477
 
void free_vfsmnt(struct vfsmount *mnt)
 
469
static void free_vfsmnt(struct vfsmount *mnt)
478
470
{
479
471
        kfree(mnt->mnt_devname);
480
472
        mnt_free_id(mnt);
678
670
        return p;
679
671
}
680
672
 
 
673
struct vfsmount *
 
674
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
 
675
{
 
676
        struct vfsmount *mnt;
 
677
        struct dentry *root;
 
678
 
 
679
        if (!type)
 
680
                return ERR_PTR(-ENODEV);
 
681
 
 
682
        mnt = alloc_vfsmnt(name);
 
683
        if (!mnt)
 
684
                return ERR_PTR(-ENOMEM);
 
685
 
 
686
        if (flags & MS_KERNMOUNT)
 
687
                mnt->mnt_flags = MNT_INTERNAL;
 
688
 
 
689
        root = mount_fs(type, flags, name, data);
 
690
        if (IS_ERR(root)) {
 
691
                free_vfsmnt(mnt);
 
692
                return ERR_CAST(root);
 
693
        }
 
694
 
 
695
        mnt->mnt_root = root;
 
696
        mnt->mnt_sb = root->d_sb;
 
697
        mnt->mnt_mountpoint = mnt->mnt_root;
 
698
        mnt->mnt_parent = mnt;
 
699
        return mnt;
 
700
}
 
701
EXPORT_SYMBOL_GPL(vfs_kern_mount);
 
702
 
681
703
static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
682
704
                                        int flag)
683
705
{
978
1000
        int err = 0;
979
1001
        struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
980
1002
 
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);
 
1005
                if (err)
 
1006
                        goto out;
 
1007
        } else {
 
1008
                mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
 
1009
        }
982
1010
        seq_putc(m, ' ');
983
1011
        seq_path(m, &mnt_path, " \t\n\\");
984
1012
        seq_putc(m, ' ');
1013
1041
 
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);
 
1046
        else
 
1047
                seq_dentry(m, mnt->mnt_root, " \t\n\\");
 
1048
        if (err)
 
1049
                goto out;
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);
 
1082
        else
 
1083
                mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
 
1084
        if (err)
 
1085
                goto out;
1048
1086
        seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
1049
1087
        err = show_sb_opts(m, sb);
1050
1088
        if (err)
1070
1108
        int err = 0;
1071
1109
 
1072
1110
        /* device */
1073
 
        if (mnt->mnt_devname) {
1074
 
                seq_puts(m, "device ");
1075
 
                mangle(m, mnt->mnt_devname);
1076
 
        } else
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);
 
1113
        } else {
 
1114
                if (mnt->mnt_devname) {
 
1115
                        seq_puts(m, "device ");
 
1116
                        mangle(m, mnt->mnt_devname);
 
1117
                } else
 
1118
                        seq_puts(m, "no device");
 
1119
        }
1078
1120
 
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);
 
1133
                if (!err)
 
1134
                        err = mnt->mnt_sb->s_op->show_stats(m, mnt);
1092
1135
        }
1093
1136
 
1094
1137
        seq_putc(m, '\n');
1605
1648
        return err;
1606
1649
}
1607
1650
 
 
1651
static int lock_mount(struct path *path)
 
1652
{
 
1653
        struct vfsmount *mnt;
 
1654
retry:
 
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);
 
1658
                return -ENOENT;
 
1659
        }
 
1660
        down_write(&namespace_sem);
 
1661
        mnt = lookup_mnt(path);
 
1662
        if (likely(!mnt))
 
1663
                return 0;
 
1664
        up_write(&namespace_sem);
 
1665
        mutex_unlock(&path->dentry->d_inode->i_mutex);
 
1666
        path_put(path);
 
1667
        path->mnt = mnt;
 
1668
        path->dentry = dget(mnt->mnt_root);
 
1669
        goto retry;
 
1670
}
 
1671
 
 
1672
static void unlock_mount(struct path *path)
 
1673
{
 
1674
        up_write(&namespace_sem);
 
1675
        mutex_unlock(&path->dentry->d_inode->i_mutex);
 
1676
}
 
1677
 
1608
1678
static int graft_tree(struct vfsmount *mnt, struct path *path)
1609
1679
{
1610
 
        int err;
1611
1680
        if (mnt->mnt_sb->s_flags & MS_NOUSER)
1612
1681
                return -EINVAL;
1613
1682
 
1615
1684
              S_ISDIR(mnt->mnt_root->d_inode->i_mode))
1616
1685
                return -ENOTDIR;
1617
1686
 
1618
 
        err = -ENOENT;
1619
 
        mutex_lock(&path->dentry->d_inode->i_mutex);
1620
 
        if (cant_mount(path->dentry))
1621
 
                goto out_unlock;
 
1687
        if (d_unlinked(path->dentry))
 
1688
                return -ENOENT;
1622
1689
 
1623
 
        if (!d_unlinked(path->dentry))
1624
 
                err = attach_recursive_mnt(mnt, path, NULL);
1625
 
out_unlock:
1626
 
        mutex_unlock(&path->dentry->d_inode->i_mutex);
1627
 
        return err;
 
1690
        return attach_recursive_mnt(mnt, path, NULL);
1628
1691
}
1629
1692
 
1630
1693
/*
1633
1696
 
1634
1697
static int flags_to_propagation_type(int flags)
1635
1698
{
1636
 
        int type = flags & ~MS_REC;
 
1699
        int type = flags & ~(MS_REC | MS_SILENT);
1637
1700
 
1638
1701
        /* Fail if any non-propagation flags are set */
1639
1702
        if (type & ~(MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
1687
1750
static int do_loopback(struct path *path, char *old_name,
1688
1751
                                int recurse)
1689
1752
{
 
1753
        LIST_HEAD(umount_list);
1690
1754
        struct path old_path;
1691
1755
        struct vfsmount *mnt = NULL;
1692
1756
        int err = mount_is_safe(path);
1698
1762
        if (err)
1699
1763
                return err;
1700
1764
 
1701
 
        down_write(&namespace_sem);
 
1765
        err = lock_mount(path);
 
1766
        if (err)
 
1767
                goto out;
 
1768
 
1702
1769
        err = -EINVAL;
1703
1770
        if (IS_MNT_UNBINDABLE(old_path.mnt))
1704
 
                goto out;
 
1771
                goto out2;
1705
1772
 
1706
1773
        if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt))
1707
 
                goto out;
 
1774
                goto out2;
1708
1775
 
1709
1776
        err = -ENOMEM;
1710
1777
        if (recurse)
1713
1780
                mnt = clone_mnt(old_path.mnt, old_path.dentry, 0);
1714
1781
 
1715
1782
        if (!mnt)
1716
 
                goto out;
 
1783
                goto out2;
1717
1784
 
1718
1785
        err = graft_tree(mnt, path);
1719
1786
        if (err) {
1720
 
                LIST_HEAD(umount_list);
1721
 
 
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);
1726
1790
        }
1727
 
 
 
1791
out2:
 
1792
        unlock_mount(path);
 
1793
        release_mounts(&umount_list);
1728
1794
out:
1729
 
        up_write(&namespace_sem);
1730
1795
        path_put(&old_path);
1731
1796
        return err;
1732
1797
}
1768
1833
        if (path->dentry != path->mnt->mnt_root)
1769
1834
                return -EINVAL;
1770
1835
 
 
1836
        err = security_sb_remount(sb, data);
 
1837
        if (err)
 
1838
                return err;
 
1839
 
1771
1840
        down_write(&sb->s_umount);
1772
1841
        if (flags & MS_BIND)
1773
1842
                err = change_mount_flags(path->mnt, flags);
1811
1880
        if (err)
1812
1881
                return err;
1813
1882
 
1814
 
        down_write(&namespace_sem);
1815
 
        err = follow_down(path, true);
 
1883
        err = lock_mount(path);
1816
1884
        if (err < 0)
1817
1885
                goto out;
1818
1886
 
1819
1887
        err = -EINVAL;
1820
1888
        if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt))
1821
 
                goto out;
1822
 
 
1823
 
        err = -ENOENT;
1824
 
        mutex_lock(&path->dentry->d_inode->i_mutex);
1825
 
        if (cant_mount(path->dentry))
1826
1889
                goto out1;
1827
1890
 
1828
1891
        if (d_unlinked(path->dentry))
1864
1927
         * automatically */
1865
1928
        list_del_init(&old_path.mnt->mnt_expire);
1866
1929
out1:
1867
 
        mutex_unlock(&path->dentry->d_inode->i_mutex);
 
1930
        unlock_mount(path);
1868
1931
out:
1869
 
        up_write(&namespace_sem);
1870
1932
        if (!err)
1871
1933
                path_put(&parent_path);
1872
1934
        path_put(&old_path);
1873
1935
        return err;
1874
1936
}
1875
1937
 
1876
 
static int do_add_mount(struct vfsmount *, struct path *, int);
 
1938
static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype)
 
1939
{
 
1940
        int err;
 
1941
        const char *subtype = strchr(fstype, '.');
 
1942
        if (subtype) {
 
1943
                subtype++;
 
1944
                err = -EINVAL;
 
1945
                if (!subtype[0])
 
1946
                        goto err;
 
1947
        } else
 
1948
                subtype = "";
 
1949
 
 
1950
        mnt->mnt_sb->s_subtype = kstrdup(subtype, GFP_KERNEL);
 
1951
        err = -ENOMEM;
 
1952
        if (!mnt->mnt_sb->s_subtype)
 
1953
                goto err;
 
1954
        return mnt;
 
1955
 
 
1956
 err:
 
1957
        mntput(mnt);
 
1958
        return ERR_PTR(err);
 
1959
}
 
1960
 
 
1961
struct vfsmount *
 
1962
do_kern_mount(const char *fstype, int flags, const char *name, void *data)
 
1963
{
 
1964
        struct file_system_type *type = get_fs_type(fstype);
 
1965
        struct vfsmount *mnt;
 
1966
        if (!type)
 
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);
 
1973
        return mnt;
 
1974
}
 
1975
EXPORT_SYMBOL_GPL(do_kern_mount);
 
1976
 
 
1977
/*
 
1978
 * add a mount into a namespace's mount tree
 
1979
 */
 
1980
static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags)
 
1981
{
 
1982
        int err;
 
1983
 
 
1984
        mnt_flags &= ~(MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL);
 
1985
 
 
1986
        err = lock_mount(path);
 
1987
        if (err)
 
1988
                return err;
 
1989
 
 
1990
        err = -EINVAL;
 
1991
        if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(path->mnt))
 
1992
                goto unlock;
 
1993
 
 
1994
        /* Refuse the same filesystem on the same mount point */
 
1995
        err = -EBUSY;
 
1996
        if (path->mnt->mnt_sb == newmnt->mnt_sb &&
 
1997
            path->mnt->mnt_root == path->dentry)
 
1998
                goto unlock;
 
1999
 
 
2000
        err = -EINVAL;
 
2001
        if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
 
2002
                goto unlock;
 
2003
 
 
2004
        newmnt->mnt_flags = mnt_flags;
 
2005
        err = graft_tree(newmnt, path);
 
2006
 
 
2007
unlock:
 
2008
        unlock_mount(path);
 
2009
        return err;
 
2010
}
1877
2011
 
1878
2012
/*
1879
2013
 * create a new mount for userspace and request it to be added into the
1933
2067
        return err;
1934
2068
}
1935
2069
 
1936
 
/*
1937
 
 * add a mount into a namespace's mount tree
1938
 
 */
1939
 
static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags)
1940
 
{
1941
 
        int err;
1942
 
 
1943
 
        mnt_flags &= ~(MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL);
1944
 
 
1945
 
        down_write(&namespace_sem);
1946
 
        /* Something was mounted here while we slept */
1947
 
        err = follow_down(path, true);
1948
 
        if (err < 0)
1949
 
                goto unlock;
1950
 
 
1951
 
        err = -EINVAL;
1952
 
        if (!(mnt_flags & MNT_SHRINKABLE) && !check_mnt(path->mnt))
1953
 
                goto unlock;
1954
 
 
1955
 
        /* Refuse the same filesystem on the same mount point */
1956
 
        err = -EBUSY;
1957
 
        if (path->mnt->mnt_sb == newmnt->mnt_sb &&
1958
 
            path->mnt->mnt_root == path->dentry)
1959
 
                goto unlock;
1960
 
 
1961
 
        err = -EINVAL;
1962
 
        if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
1963
 
                goto unlock;
1964
 
 
1965
 
        newmnt->mnt_flags = mnt_flags;
1966
 
        err = graft_tree(newmnt, path);
1967
 
 
1968
 
unlock:
1969
 
        up_write(&namespace_sem);
1970
 
        return err;
1971
 
}
1972
 
 
1973
2070
/**
1974
2071
 * mnt_set_expiry - Put a mount on an expiration list
1975
2072
 * @mnt: The mount to list.
2476
2573
                goto out1;
2477
2574
 
2478
2575
        error = security_sb_pivotroot(&old, &new);
2479
 
        if (error) {
2480
 
                path_put(&old);
2481
 
                goto out1;
2482
 
        }
 
2576
        if (error)
 
2577
                goto out2;
2483
2578
 
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);
 
2581
        if (error)
 
2582
                goto out3;
 
2583
 
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))
2491
 
                goto out2;
 
2588
                goto out4;
2492
2589
        if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
2493
 
                goto out2;
 
2590
                goto out4;
2494
2591
        error = -ENOENT;
2495
 
        if (cant_mount(old.dentry))
2496
 
                goto out2;
2497
2592
        if (d_unlinked(new.dentry))
2498
 
                goto out2;
 
2593
                goto out4;
2499
2594
        if (d_unlinked(old.dentry))
2500
 
                goto out2;
 
2595
                goto out4;
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 */
2515
2610
        tmp = old.mnt;
2516
2611
        if (tmp != new.mnt) {
2517
2612
                for (;;) {
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)
2521
2616
                                break;
2522
2617
                        tmp = tmp->mnt_parent;
2523
2618
                }
2524
2619
                if (!is_subdir(tmp->mnt_mountpoint, new.dentry))
2525
 
                        goto out2;
 
2620
                        goto out4;
2526
2621
        } else if (!is_subdir(old.dentry, new.dentry))
2527
 
                goto out2;
 
2622
                goto out4;
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);
2538
 
 
2539
2633
        error = 0;
2540
 
        path_put(&root_parent);
2541
 
        path_put(&parent_path);
2542
 
out2:
2543
 
        mutex_unlock(&old.dentry->d_inode->i_mutex);
2544
 
        up_write(&namespace_sem);
 
2634
out4:
 
2635
        unlock_mount(&old);
 
2636
        if (!error) {
 
2637
                path_put(&root_parent);
 
2638
                path_put(&parent_path);
 
2639
        }
 
2640
out3:
2545
2641
        path_put(&root);
 
2642
out2:
2546
2643
        path_put(&old);
2547
2644
out1:
2548
2645
        path_put(&new);
2589
2686
        if (!mount_hashtable)
2590
2687
                panic("Failed to allocate mount hash table\n");
2591
2688
 
2592
 
        printk("Mount-cache hash table entries: %lu\n", HASH_SIZE);
 
2689
        printk(KERN_INFO "Mount-cache hash table entries: %lu\n", HASH_SIZE);
2593
2690
 
2594
2691
        for (u = 0; u < HASH_SIZE; u++)
2595
2692
                INIT_LIST_HEAD(&mount_hashtable[u]);
2622
2719
        kfree(ns);
2623
2720
}
2624
2721
EXPORT_SYMBOL(put_mnt_ns);
 
2722
 
 
2723
struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
 
2724
{
 
2725
        return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
 
2726
}
 
2727
EXPORT_SYMBOL_GPL(kern_mount_data);