From 7e0e46828b2a6bfad8c26466e914ade862fca4f3 Mon Sep 17 00:00:00 2001 From: Far Date: Fri, 16 Apr 2021 10:10:41 +0800 Subject: [PATCH] Bugfix: add vnode iteration debug feature for a bug buginfo: when try to umount a nfs node, it may casue stack overflow. Change-Id: I7d96f74a770607c990ca5f51cb92fb2843a08d12 --- fs/include/fs/path_cache.h | 1 + fs/vfs/path_cache.c | 3 ++- fs/vfs/vnode.c | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/fs/include/fs/path_cache.h b/fs/include/fs/path_cache.h index 43bce86c..d4087904 100644 --- a/fs/include/fs/path_cache.h +++ b/fs/include/fs/path_cache.h @@ -52,5 +52,6 @@ int PathCacheAllocDummy(struct Vnode *parent, struct Vnode **vnode, const char * int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnode **vnode); void VnodePathCacheFree(struct Vnode *vnode); void PathCacheMemoryDump(void); +void PathCacheDump(void); #endif /* _PATH_CACHE_H */ diff --git a/fs/vfs/path_cache.c b/fs/vfs/path_cache.c index ab279104..5cd4afb1 100755 --- a/fs/vfs/path_cache.c +++ b/fs/vfs/path_cache.c @@ -54,7 +54,8 @@ void PathCacheDump(void) LIST_HEAD *nhead = &g_pathCacheHashEntrys[i]; LOS_DL_LIST_FOR_EACH_ENTRY(nc, nhead, struct PathCache, hashEntry) { - PRINTK(" pathCache dump hash %d item %s %p %d\n", i, nc->name, nc->parentVnode, nc->nameLen); + PRINTK(" pathCache dump hash %d item %s %p %p %d\n", i, + nc->name, nc->parentVnode, nc->childVnode, nc->nameLen); } } PRINTK("-------->pathCache dump out\n"); diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index 0293cfd0..8a3969f9 100755 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -47,6 +47,7 @@ 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) { @@ -241,12 +242,29 @@ int VnodeFreeAll(struct Mount *mnt) 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(); + } +} + BOOL VnodeInUseIter(struct Vnode *vnode) { struct Vnode *vp = NULL; struct PathCache *item = NULL; struct PathCache *nextItem = 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) { @@ -255,9 +273,11 @@ BOOL VnodeInUseIter(struct Vnode *vnode) continue; } if (VnodeInUseIter(vp) == TRUE) { + VnodeIterDump(vnode, -1); return TRUE; } } + VnodeIterDump(vnode, -1); return FALSE; }