从内核链表中脱离
- /*完成实际的底层的卸载文件系统的任务。首先他将mnt的所有子移动至kill链表中,
- 也就是传递进去的umount_list,然后将kill链表中的所有的vfsmount对象的一些字段设为无效状态。
- */
- void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
- {
- struct vfsmount *p;
- for (p = mnt; p; p = next_mnt(p, mnt))
- list_move(&p->mnt_hash, kill);
- if (propagate)
- propagate_umount(kill);
- list_for_each_entry(p, kill, mnt_hash) {
- list_del_init(&p->mnt_expire);
- list_del_init(&p->mnt_list);
- __touch_mnt_namespace(p->mnt_ns);
- p->mnt_ns = NULL;
- list_del_init(&p->mnt_child);
- if (p->mnt_parent != p) {
- p->mnt_parent->mnt_ghosts++;
- p->mnt_mountpoint->d_mounted--;
- }
- change_mnt_propagation(p, MS_PRIVATE);
- }
- }
释放引用计数
- void release_mounts(struct list_head *head)
- {
- struct vfsmount *mnt;
- while (!list_empty(head)) {
- mnt = list_first_entry(head, struct vfsmount, mnt_hash);
- list_del_init(&mnt->mnt_hash);
- if (mnt->mnt_parent != mnt) {
- struct dentry *dentry;
- struct vfsmount *m;
- spin_lock(&vfsmount_lock);
- dentry = mnt->mnt_mountpoint;
- m = mnt->mnt_parent;
- mnt->mnt_mountpoint = mnt->mnt_root;
- mnt->mnt_parent = mnt;
- m->mnt_ghosts--;
- spin_unlock(&vfsmount_lock);
- /*下面两个函数为减小引用计数,减到0时释放*/
- dput(dentry);
- mntput(m);
- }
- /*vfsmount对象所占的内存空间最终在mntput()函数中释放*/
- mntput(mnt);
- }
- }
