[SCSI] Mention scsi_scan_host() in scsi_mid_low_api.txt
[safe/jmp/linux-2.6] / fs / namespace.c
index 46f99bc..2019899 100644 (file)
@@ -213,6 +213,16 @@ static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
        return list_entry(next, struct vfsmount, mnt_child);
 }
 
+static struct vfsmount *skip_mnt_tree(struct vfsmount *p)
+{
+       struct list_head *prev = p->mnt_mounts.prev;
+       while (prev != &p->mnt_mounts) {
+               p = list_entry(prev, struct vfsmount, mnt_child);
+               prev = p->mnt_mounts.prev;
+       }
+       return p;
+}
+
 static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
                                        int flag)
 {
@@ -227,8 +237,17 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
                mnt->mnt_mountpoint = mnt->mnt_root;
                mnt->mnt_parent = mnt;
 
-               if ((flag & CL_PROPAGATION) || IS_MNT_SHARED(old))
-                       list_add(&mnt->mnt_share, &old->mnt_share);
+               if (flag & CL_SLAVE) {
+                       list_add(&mnt->mnt_slave, &old->mnt_slave_list);
+                       mnt->mnt_master = old;
+                       CLEAR_MNT_SHARED(mnt);
+               } else {
+                       if ((flag & CL_PROPAGATION) || IS_MNT_SHARED(old))
+                               list_add(&mnt->mnt_share, &old->mnt_share);
+                       if (IS_MNT_SLAVE(old))
+                               list_add(&mnt->mnt_slave, &old->mnt_slave);
+                       mnt->mnt_master = old->mnt_master;
+               }
                if (flag & CL_MAKE_SHARED)
                        set_mnt_shared(mnt);
 
@@ -618,7 +637,7 @@ static int mount_is_safe(struct nameidata *nd)
                if (current->uid != nd->dentry->d_inode->i_uid)
                        return -EPERM;
        }
-       if (permission(nd->dentry->d_inode, MAY_WRITE, nd))
+       if (vfs_permission(nd, MAY_WRITE))
                return -EPERM;
        return 0;
 #endif
@@ -641,6 +660,9 @@ struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
        struct vfsmount *res, *p, *q, *r, *s;
        struct nameidata nd;
 
+       if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
+               return NULL;
+
        res = q = clone_mnt(mnt, dentry, flag);
        if (!q)
                goto Enomem;
@@ -652,6 +674,10 @@ struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
                        continue;
 
                for (s = r; s; s = next_mnt(s, r)) {
+                       if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(s)) {
+                               s = skip_mnt_tree(s);
+                               continue;
+                       }
                        while (p != s->mnt_parent) {
                                p = p->mnt_parent;
                                q = q->mnt_parent;
@@ -689,18 +715,18 @@ Enomem:
  *
  *  NOTE: in the table below explains the semantics when a source mount
  *  of a given type is attached to a destination mount of a given type.
- *     ---------------------------------------------
- *     |         BIND MOUNT OPERATION              |
- *     |********************************************
- *     | source-->| shared        |       private  |
- *     | dest     |               |                |
- *     |   |      |               |                |
- *     |   v      |               |                |
- *     |********************************************
- *     |  shared  | shared (++)   |     shared (+) |
- *     |          |               |                |
- *     |non-shared| shared (+)    |      private   |
- *     *********************************************
+ * ---------------------------------------------------------------------------
+ * |         BIND MOUNT OPERATION                                            |
+ * |**************************************************************************
+ * | source-->| shared        |       private  |       slave    | unbindable |
+ * | dest     |               |                |                |            |
+ * |   |      |               |                |                |            |
+ * |   v      |               |                |                |            |
+ * |**************************************************************************
+ * |  shared  | shared (++)   |     shared (+) |     shared(+++)|  invalid   |
+ * |          |               |                |                |            |
+ * |non-shared| shared (+)    |      private   |      slave (*) |  invalid   |
+ * ***************************************************************************
  * A bind operation clones the source mount and mounts the clone on the
  * destination mount.
  *
@@ -710,21 +736,33 @@ Enomem:
  * (+)   the cloned mount is created under the destination mount and is marked
  *       as shared. The cloned mount is added to the peer group of the source
  *       mount.
- *     ---------------------------------------------
- *     |               MOVE MOUNT OPERATION        |
- *     |********************************************
- *     | source-->| shared        |       private  |
- *     | dest     |               |                |
- *     |   |      |               |                |
- *     |   v      |               |                |
- *     |********************************************
- *     |  shared  | shared (+)    |     shared (+) |
- *     |          |               |                |
- *     |non-shared| shared (+*)   |      private   |
- *     *********************************************
- * (+)  the mount is moved to the destination. And is then propagated to all
- *     the mounts in the propagation tree of the destination mount.
+ * (+++) the mount is propagated to all the mounts in the propagation tree
+ *       of the destination mount and the cloned mount is made slave
+ *       of the same master as that of the source mount. The cloned mount
+ *       is marked as 'shared and slave'.
+ * (*)   the cloned mount is made a slave of the same master as that of the
+ *      source mount.
+ *
+ * ---------------------------------------------------------------------------
+ * |                   MOVE MOUNT OPERATION                                 |
+ * |**************************************************************************
+ * | source-->| shared        |       private  |       slave    | unbindable |
+ * | dest     |               |                |                |            |
+ * |   |      |               |                |                |            |
+ * |   v      |               |                |                |            |
+ * |**************************************************************************
+ * |  shared  | shared (+)    |     shared (+) |    shared(+++) |  invalid   |
+ * |          |               |                |                |            |
+ * |non-shared| shared (+*)   |      private   |    slave (*)   | unbindable |
+ * ***************************************************************************
+ *
+ * (+)  the mount is moved to the destination. And is then propagated to
+ *     all the mounts in the propagation tree of the destination mount.
  * (+*)  the mount is moved to the destination.
+ * (+++)  the mount is moved to the destination and is then propagated to
+ *     all the mounts belonging to the destination mount's propagation tree.
+ *     the mount is marked as 'shared and slave'.
+ * (*) the mount continues to be a slave at the new location.
  *
  * if the source mount is a tree, the operations explained above is
  * applied to each mount in the tree.
@@ -833,6 +871,9 @@ static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
 
        down_write(&namespace_sem);
        err = -EINVAL;
+       if (IS_MNT_UNBINDABLE(old_nd.mnt))
+               goto out;
+
        if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
                goto out;
 
@@ -890,6 +931,16 @@ static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
        return err;
 }
 
+static inline int tree_contains_unbindable(struct vfsmount *mnt)
+{
+       struct vfsmount *p;
+       for (p = mnt; p; p = next_mnt(p, mnt)) {
+               if (IS_MNT_UNBINDABLE(p))
+                       return 1;
+       }
+       return 0;
+}
+
 static int do_move_mount(struct nameidata *nd, char *old_name)
 {
        struct nameidata old_nd, parent_nd;
@@ -933,6 +984,12 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
         */
        if (old_nd.mnt->mnt_parent && IS_MNT_SHARED(old_nd.mnt->mnt_parent))
                goto out1;
+       /*
+        * Don't move a mount tree containing unbindable mounts to a destination
+        * mount which is shared.
+        */
+       if (IS_MNT_SHARED(nd->mnt) && tree_contains_unbindable(old_nd.mnt))
+               goto out1;
        err = -ELOOP;
        for (p = nd->mnt; p->mnt_parent != p; p = p->mnt_parent)
                if (p == old_nd.mnt)
@@ -1245,7 +1302,7 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
                                    data_page);
        else if (flags & MS_BIND)
                retval = do_loopback(&nd, dev_name, flags & MS_REC);
-       else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE))
+       else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
                retval = do_change_type(&nd, flags);
        else if (flags & MS_MOVE)
                retval = do_move_mount(&nd, dev_name);
@@ -1290,7 +1347,7 @@ int copy_namespace(int flags, struct task_struct *tsk)
        down_write(&namespace_sem);
        /* First pass: copy the tree topology */
        new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root,
-                                       CL_EXPIRE);
+                                       CL_COPY_ALL | CL_EXPIRE);
        if (!new_ns->root) {
                up_write(&namespace_sem);
                kfree(new_ns);