/* * mount 'source_mnt' under the destination 'dest_mnt' at * dentry 'dest_dentry'. And propagate that mount to * all the peer and slave mounts of 'dest_mnt'. * Link all the new mounts into a propagation tree headed at * source_mnt. Also link all the new mounts using ->mnt_list * headed at source_mnt's ->mnt_list * * @dest_mnt: destination mount. * @dest_dentry: destination dentry. * @source_mnt: source mount. * @tree_list : list of heads of trees to be attached. */ int propagate_mnt(struct mount *dest_mnt, struct dentry *dest_dentry, struct mount *source_mnt, struct list_head *tree_list) { struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns; struct mount *m, *child; int ret = 0; struct mount *prev_dest_mnt = dest_mnt; struct mount *prev_src_mnt = source_mnt; LIST_HEAD(tmp_list); LIST_HEAD(umount_list); for (m = propagation_next(dest_mnt, dest_mnt); m; m = propagation_next(m, dest_mnt)) { int type; struct mount *source; if (IS_MNT_NEW(m)) continue; source = get_source(m, prev_dest_mnt, prev_src_mnt, &type); /* Notice when we are propagating across user namespaces */ if (m->mnt_ns->user_ns != user_ns) type |= CL_UNPRIVILEGED; child = copy_tree(source, source->mnt.mnt_root, type); if (IS_ERR(child)) { ret = PTR_ERR(child); list_splice(tree_list, tmp_list.prev); goto out; } if (is_subdir(dest_dentry, m->mnt.mnt_root)) { mnt_set_mountpoint(m, dest_dentry, child); list_add_tail(&child->mnt_hash, tree_list); } else { /* * This can happen if the parent mount was bind mounted * on some subdirectory of a shared/slave mount. */ list_add_tail(&child->mnt_hash, &tmp_list); } prev_dest_mnt = m; prev_src_mnt = child; } out: br_write_lock(&vfsmount_lock); while (!list_empty(&tmp_list)) { child = list_first_entry(&tmp_list, struct mount, mnt_hash); umount_tree(child, 0, &umount_list); } br_write_unlock(&vfsmount_lock); release_mounts(&umount_list); return ret; }
int propagate_mnt(struct mount *dest_mnt, struct dentry *dest_dentry, struct mount *source_mnt, struct list_head *tree_list) { struct mount *m, *child; int ret = 0; struct mount *prev_dest_mnt = dest_mnt; struct mount *prev_src_mnt = source_mnt; LIST_HEAD(tmp_list); LIST_HEAD(umount_list); for (m = propagation_next(dest_mnt, dest_mnt); m; m = propagation_next(m, dest_mnt)) { int type; struct mount *source; if (IS_MNT_NEW(m)) continue; source = get_source(m, prev_dest_mnt, prev_src_mnt, &type); if (!(child = copy_tree(source, source->mnt.mnt_root, type))) { ret = -ENOMEM; list_splice(tree_list, tmp_list.prev); goto out; } if (is_subdir(dest_dentry, m->mnt.mnt_root)) { mnt_set_mountpoint(m, dest_dentry, child); list_add_tail(&child->mnt_hash, tree_list); } else { list_add_tail(&child->mnt_hash, &tmp_list); } prev_dest_mnt = m; prev_src_mnt = child; } out: br_write_lock(vfsmount_lock); while (!list_empty(&tmp_list)) { child = list_first_entry(&tmp_list, struct mount, mnt_hash); umount_tree(child, 0, &umount_list); } br_write_unlock(vfsmount_lock); release_mounts(&umount_list); return ret; }
/* This returns 0 if everything went fine. * It will return 1 if the group was killed as a result. * A negative return indicates failure. * * The RTNL lock must be held. */ static int unregister_vlan_dev(struct net_device *real_dev, unsigned short vlan_id) { struct net_device *dev = NULL; int real_dev_ifindex = real_dev->ifindex; struct vlan_group *grp; int i, ret; #ifdef VLAN_DEBUG printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id); #endif /* sanity check */ if (vlan_id >= VLAN_VID_MASK) return -EINVAL; spin_lock_bh(&vlan_group_lock); grp = __vlan_find_group(real_dev_ifindex); spin_unlock_bh(&vlan_group_lock); ret = 0; if (grp) { dev = grp->vlan_devices[vlan_id]; if (dev) { /* Remove proc entry */ vlan_proc_rem_dev(dev); /* Take it out of our own structures, but be sure to * interlock with HW accelerating devices or SW vlan * input packet processing. */ if (real_dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER)) { real_dev->vlan_rx_kill_vid(real_dev, vlan_id); } br_write_lock(BR_NETPROTO_LOCK); grp->vlan_devices[vlan_id] = NULL; br_write_unlock(BR_NETPROTO_LOCK); /* Caller unregisters (and if necessary, puts) * VLAN device, but we get rid of the reference to * real_dev here. */ dev_put(real_dev); /* If the group is now empty, kill off the * group. */ for (i = 0; i < VLAN_VID_MASK; i++) if (grp->vlan_devices[i]) break; if (i == VLAN_VID_MASK) { if (real_dev->features & NETIF_F_HW_VLAN_RX) real_dev->vlan_rx_register(real_dev, NULL); spin_lock_bh(&vlan_group_lock); __grp_unhash(grp); spin_unlock_bh(&vlan_group_lock); /* Free the group, after we have removed it * from the hash. */ kfree(grp); grp = NULL; ret = 1; } MOD_DEC_USE_COUNT; } } return ret; }