diff --git a/fs/include/fs/vnode.h b/fs/include/fs/vnode.h index 6c4bf4e8fd8b122d9ec25e7733a2750583d2ee10..cc95765d2e6326c3e195b33d516f21914216023a 100644 --- a/fs/include/fs/vnode.h +++ b/fs/include/fs/vnode.h @@ -111,15 +111,14 @@ int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags); int VnodeHold(void); int VnodeDrop(void); void VnodeRefDec(struct Vnode *vnode); -int VnodeFreeIter(struct Vnode *vnode); -int VnodeFreeAll(struct Mount *mnt); +int VnodeFreeAll(const struct Mount *mnt); int VnodeHashInit(void); uint32_t VfsHashIndex(struct Vnode *vnode); int VfsHashGet(const struct Mount *mount, uint32_t hash, struct Vnode **vnode, VfsHashCmp *fun, void *arg); void VfsHashRemove(struct Vnode *vnode); int VfsHashInsert(struct Vnode *vnode, uint32_t hash); void ChangeRoot(struct Vnode *newRoot); -BOOL VnodeInUseIter(struct Vnode *vnode); +BOOL VnodeInUseIter(const struct Mount *mount); struct Vnode *VnodeGetRoot(void); void VnodeMemoryDump(void); diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index af4971e0c14ab491ec42b397e0d1b046b341d177..8aafb1f5eb50c3cfde7b8b35a7cc08e9ff64e7ee 100644 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -47,7 +47,6 @@ static struct VnodeOps g_devfsOps; #define ENTRY_TO_VNODE(ptr) LOS_DL_LIST_ENTRY(ptr, struct Vnode, actFreeEntry) #define VNODE_LRU_COUNT 10 #define DEV_VNODE_MODE 0755 -#define MAX_ITER_TIMES 10 int VnodesInit(void) { @@ -98,8 +97,8 @@ struct Vnode *VnodeReclaimLru(void) LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeCurrList, struct Vnode, actFreeEntry) { if ((item->useCount > 0) || - (item->flag & VNODE_FLAG_MOUNT_NEW) || - (item->flag & VNODE_FLAG_MOUNT_ORIGIN)) { + (item->flag & VNODE_FLAG_MOUNT_ORIGIN) || + (item->flag & VNODE_FLAG_MOUNT_NEW)) { continue; } @@ -201,83 +200,35 @@ int VnodeFree(struct Vnode *vnode) return LOS_OK; } -int VnodeFreeIter(struct Vnode *vnode) +int VnodeFreeAll(const struct Mount *mount) { - struct Vnode *vp = NULL; - struct PathCache *item = NULL; - struct PathCache *nextItem = NULL; - int ret; - - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &vnode->childPathCaches, struct PathCache, childEntry) { - vp = item->childVnode; - if (vp == NULL) { - continue; - } - ret = VnodeFreeIter(vp); - if (ret != LOS_OK) { - return ret; - } - } - return VnodeFree(vnode); -} - -int VnodeFreeAll(struct Mount *mnt) -{ - struct Vnode *vp = NULL; - struct Vnode *mountptVnode = mnt->vnodeCovered; - struct PathCache *item = NULL; - struct PathCache *nextItem = NULL; + struct Vnode *vnode = NULL; + struct Vnode *nextVnode = NULL; int ret; - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &mountptVnode->childPathCaches, struct PathCache, childEntry) { - vp = item->childVnode; - if (vp == NULL) { - continue; - } - ret = VnodeFreeIter(vp); - if (ret != LOS_OK) { - return ret; + LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(vnode, nextVnode, &g_vnodeCurrList, struct Vnode, actFreeEntry) { + if ((vnode->originMount == mount) && !(vnode->flag & VNODE_FLAG_MOUNT_NEW)) { + ret = VnodeFree(vnode); + if (ret != LOS_OK) { + return ret; + } } } - return 0; -} -static VOID VnodeIterDump(struct Vnode *vnode, int increase) -{ - static int count = 0; - LIST_ENTRY *list = &vnode->parentPathCaches; - struct PathCache *pathCache = LOS_DL_LIST_ENTRY(list->pstNext, struct PathCache, parentEntry); - count += increase; - if (count >= MAX_ITER_TIMES) { - PRINTK("########## Vnode In Use Iteration ##########\n"); - PRINTK("Iteration times: %d\n", count); - PRINTK("%p -- %s --> %p\n", vnode->parent, pathCache->name, vnode); - PathCacheDump(); - } + return LOS_OK; } -BOOL VnodeInUseIter(struct Vnode *vnode) +BOOL VnodeInUseIter(const struct Mount *mount) { - struct Vnode *vp = NULL; - struct PathCache *item = NULL; - struct PathCache *nextItem = NULL; + struct Vnode *vnode = NULL; - VnodeIterDump(vnode, 1); - if (vnode->useCount > 0) { - VnodeIterDump(vnode, -1); - return TRUE; - } - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &vnode->childPathCaches, struct PathCache, childEntry) { - vp = item->childVnode; - if (vp == NULL) { - continue; - } - if (VnodeInUseIter(vp) == TRUE) { - VnodeIterDump(vnode, -1); - return TRUE; + LOS_DL_LIST_FOR_EACH_ENTRY(vnode, &g_vnodeCurrList, struct Vnode, actFreeEntry) { + if (vnode->originMount == mount) { + if ((vnode->useCount > 0) || (vnode->flag & VNODE_FLAG_MOUNT_ORIGIN)) { + return TRUE; + } } } - VnodeIterDump(vnode, -1); return FALSE; } @@ -335,7 +286,7 @@ static int PreProcess(const char *originPath, struct Vnode **startVnode, char ** static struct Vnode *ConvertVnodeIfMounted(struct Vnode *vnode) { - if ((vnode == NULL) || !(vnode->flag & VNODE_FLAG_MOUNT_NEW)) { + if ((vnode == NULL) || !(vnode->flag & VNODE_FLAG_MOUNT_ORIGIN)) { return vnode; } return vnode->newMount->vnodeCovered; @@ -487,7 +438,7 @@ static void ChangeRootInternal(struct Vnode *rootOld, char *dirname) mnt->vnodeBeCovered = nodeInFs; nodeInFs->newMount = mnt; - nodeInFs->flag |= VNODE_FLAG_MOUNT_NEW; + nodeInFs->flag |= VNODE_FLAG_MOUNT_ORIGIN; break; } @@ -600,7 +551,7 @@ int VnodeDevInit() return -ENOMEM; } devMount->vnodeCovered = devNode; - devMount->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_NEW; + devMount->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_ORIGIN; return LOS_OK; } @@ -668,8 +619,8 @@ void VnodeMemoryDump(void) LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeCurrList, struct Vnode, actFreeEntry) { if ((item->useCount > 0) || - (item->flag & VNODE_FLAG_MOUNT_NEW) || - (item->flag & VNODE_FLAG_MOUNT_ORIGIN)) { + (item->flag & VNODE_FLAG_MOUNT_ORIGIN) || + (item->flag & VNODE_FLAG_MOUNT_NEW)) { continue; } @@ -678,4 +629,4 @@ void VnodeMemoryDump(void) PRINTK("Vnode number = %d\n", vnodeCount); PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode)); -} +} \ No newline at end of file diff --git a/fs/vfs/vnode_hash.c b/fs/vfs/vnode_hash.c index c50733dd49712af2020eb1bf057796939e7bb92a..9a97bfaddb9fb99e00c915e4314f2c65a5e961cd 100644 --- a/fs/vfs/vnode_hash.c +++ b/fs/vfs/vnode_hash.c @@ -134,4 +134,4 @@ int VfsHashInsert(struct Vnode *vnode, uint32_t hash) LOS_ListHeadInsert(VfsHashBucket(vnode->originMount, hash), &vnode->hashEntry); (void)LOS_MuxUnlock(&g_vnodeHashMux); return LOS_OK; -} +} \ No newline at end of file