提交 5f6656cb 编写于 作者: F Far

fix: VnodeInUseIter and VnodeFreeAll used to be recursive

Function VnodeInUseIter and VnodeFreeAll used to be recursive.
Now we traverse the current in-use vnode list to find the vnode in
1 filesystem

Close #I3NN3U
上级 806ce4eb
......@@ -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);
......
......@@ -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
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册