From 04bcb11c3cebbac2080fe8cf2e6bfc8cd46e53ce Mon Sep 17 00:00:00 2001 From: mucor Date: Fri, 30 Apr 2021 15:11:51 +0800 Subject: [PATCH] fix:add vnode destory for unregister dev node Change-Id: I2205bbf42e7c2339f81443ace6924b12f4fa1c09 --- fs/include/fs/vnode.h | 1 + fs/vfs/vnode.c | 38 +++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/fs/include/fs/vnode.h b/fs/include/fs/vnode.h index cc95765d..0312b5ea 100644 --- a/fs/include/fs/vnode.h +++ b/fs/include/fs/vnode.h @@ -121,5 +121,6 @@ void ChangeRoot(struct Vnode *newRoot); BOOL VnodeInUseIter(const struct Mount *mount); struct Vnode *VnodeGetRoot(void); void VnodeMemoryDump(void); +int VnodeDestory(struct Vnode *vnode); #endif /* !_VNODE_H_ */ diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index 8aafb1f5..fd72631f 100644 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -168,29 +168,21 @@ int VnodeFree(struct Vnode *vnode) if (vnode == NULL) { return LOS_OK; } - struct PathCache *item = NULL; - struct PathCache *nextItem = NULL; VnodeHold(); if (vnode->useCount > 0) { VnodeDrop(); return -EBUSY; } - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &vnode->childPathCaches, struct PathCache, childEntry) { - PathCacheFree(item); - } - - LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &vnode->parentPathCaches, struct PathCache, parentEntry) { - PathCacheFree(item); - } + VnodePathCacheFree(vnode); LOS_ListDelete(&(vnode->hashEntry)); + LOS_ListDelete(&vnode->actFreeEntry); if (vnode->vop->Reclaim) { vnode->vop->Reclaim(vnode); } - LOS_ListDelete(&vnode->actFreeEntry); memset_s(vnode, sizeof(struct Vnode), 0, sizeof(struct Vnode)); LOS_ListAdd(&g_vnodeFreeList, &vnode->actFreeEntry); @@ -629,4 +621,28 @@ 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 +} + +int VnodeDestory(struct Vnode *vnode) +{ + if (vnode == NULL || vnode->vop != &g_devfsOps) { + /* destory only support dev vnode */ + return -EINVAL; + } + + VnodeHold(); + if (vnode->useCount > 0) { + VnodeDrop(); + return -EBUSY; + } + + VnodePathCacheFree(vnode); + LOS_ListDelete(&(vnode->hashEntry)); + LOS_ListDelete(&vnode->actFreeEntry); + + free(vnode->data); + free(vnode); + VnodeDrop(); + + return LOS_OK; +}