From: zhaoyanbai Date: Sat, 5 Dec 2026 13:51:57 +0000 (+0800) Subject: 移除管理mount的哈希表,改用一个全局链表记录所有mount结构 X-Git-Url: http://repos.zhaoyanbai.com/sitemap.xml?a=commitdiff_plain;h=1086977b86612d1a1d45810b18afa8154f34ef1e;p=kernel.git 移除管理mount的哈希表,改用一个全局链表记录所有mount结构 --- diff --git a/fs/mount.c b/fs/mount.c index 3808320..d729532 100644 --- a/fs/mount.c +++ b/fs/mount.c @@ -17,10 +17,7 @@ kmem_cache_t* mount_kmem_cache = 0; -// 通过挂载点目录的 path_t 也就是 {mount, dentry}计算hash -// 就可以得到所有挂载在该目录上的挂载描述符 mount -mount_t** mount_hash_table = 0; -int mount_hash_table_size = 0; +static list_head_t g_mounts = LIST_HEAD_INIT(g_mounts); mount_t* alloc_mount(const char* name) { mount_t* mnt = 0; @@ -40,7 +37,7 @@ mount_t* alloc_mount(const char* name) { return mnt; } -mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data) { +mount_t* vfs_create_mount(fs_type_t* type, int flags, const char* name, void* data) { int ret = 0; mount_t* mnt = 0; @@ -60,63 +57,23 @@ mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* da mnt->mnt_point = mnt->mnt_root; mnt->mnt_parent = mnt; - // if (type->flags & FS_TYPE_NODEV) { - // } + list_add(&mnt->mnt_list, &g_mounts); return mnt; } -unsigned long mount_table_hash(mount_t* mnt, dentry_t* dentry) { - unsigned long h = (unsigned long)mnt / 5; - h += 1; - h += (unsigned long)dentry / 5; - h = h + (h >> 9); - return h & (mount_hash_table_size - 1); -} - -void add_mount_to_hash_table(mount_t* mnt) { - unsigned long hash = mount_table_hash(mnt->mnt_parent, mnt->mnt_point); - - uint32_t eflags; - irq_save(eflags); - - mount_t** p = mount_hash_table + hash; - - mnt->hash_next = *p; - - *p = mnt; - - irq_restore(eflags); -} - void init_mount() { mount_kmem_cache = kmem_cache_create("mount", sizeof(mount_t), 4); if (0 == mount_kmem_cache) { panic("create mount kmem cache failed"); } - - mount_hash_table = (mount_t**)page2va(alloc_one_page(0)); - memset(mount_hash_table, 0, PAGE_SIZE); - - mount_hash_table_size = PAGE_SIZE / sizeof(mount_t*); - - assert(mount_hash_table_size != 0); - - // mount_hash_table_size 应该是2的n次方的数 - int bit1_cnt = 0; - for (int i = 0; i < sizeof(mount_hash_table_size) * 8; i++) { - if (mount_hash_table_size & (1 << i)) { - bit1_cnt++; - } - } - assert(bit1_cnt == 1); } void mount_root() { fs_type_t* type = vfs_find_filesystem("ramfs"); assert(type != NULL); - mount_t* mnt = vfs_kernel_mount(type, 0, "ramfs", NULL); + mount_t* mnt = vfs_create_mount(type, 0, "ramfs", NULL); assert(mnt != NULL); assert(mnt->mnt_root != NULL); diff --git a/fs/mount.h b/fs/mount.h index 2e894e0..0dbbced 100644 --- a/fs/mount.h +++ b/fs/mount.h @@ -11,4 +11,4 @@ #include "vfs.h" -mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data); +mount_t* vfs_create_mount(fs_type_t* type, int flags, const char* name, void* data);