int may_umount(struct vfsmount *mnt)用于判断文件系统的mount point是否busy
其源码分析如下:
int may_umount(struct vfsmount *mnt)
{
int ret = 1;
down_read(&namespace_sem);
lock_mount_hash();
#检查mount point是否busy 要通过锁保护,这里通过real_mount 这个函数将vfsmount 转成mount 结构体。
#然后同下面这个函数检查mount point是否有文件打开
if (propagate_mount_busy(real_mount(mnt), 2))
ret = 0;
unlock_mount_hash();
up_read(&namespace_sem);
return ret;
}
int propagate_mount_busy(struct mount *mnt, int refcnt)
{
struct mount *m, *child, *topper;
struct mount *parent = mnt->mnt_parent;
if (mnt == parent)
return do_refcount_check(mnt, refcnt);
/*
* quickly check if the current mount can be unmounted.
* If not, we don't have to go checking for all other
* mounts
*/
#如果mnt_mount 这个list为null,或者refcnt 不为1,则返回1,表示这个mount point不是busy的
if (!list_empty(&mnt->mnt_mounts) || do_refcount_check(mnt, refcnt))
return 1;
#遍历这个mount point上所有的inode
for (m = propagation_next(parent, parent); m;
m = propagation_next(m, parent)) {
int count = 1;
child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint);
if (!child)
continue;
/* Is there exactly one mount on the child that covers
* it completely whose reference should be ignored?
*/
topper = find_topper(child);
if (topper)
count += 1;
else if (!list_empty(&child->mnt_mounts))
continue;
#如果mount point下面还有mount point 说明这个mount point是busy的
if (do_refcount_check(child, count))
return 1;
}
#返回零,说明不是busy
return 0;
}
内核文件系统API之may_umount
最新推荐文章于 2022-04-07 21:15:38 发布