From ac0d083b1c89c4ad3fdaab0347d11f174d0185cb Mon Sep 17 00:00:00 2001 From: chenwei Date: Wed, 21 Apr 2021 17:07:02 +0800 Subject: [PATCH] fix: kernel crashed after rmdir the umounted folder Close: I3NGBT Change-Id: I70130c42061e51f5978b48befea66a5925386343 --- fs/jffs2/src/vfs_jffs2.c | 19 +++++++++---------- fs/vfs/vnode.c | 15 --------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/fs/jffs2/src/vfs_jffs2.c b/fs/jffs2/src/vfs_jffs2.c index 58133d4e..31eb8e27 100755 --- a/fs/jffs2/src/vfs_jffs2.c +++ b/fs/jffs2/src/vfs_jffs2.c @@ -145,7 +145,6 @@ int VfsJffs2Bind(struct Mount *mnt, struct Vnode *blkDriver, const void *data) g_jffs2PartList[partNo] = blkDriver; - PRINTK("%s-%d: vnode=%p, inode=%p, i_nlink=%d\n", __FUNCTION__, __LINE__, pv, rootNode, rootNode->i_nlink); LOS_MuxUnlock(&g_jffs2FsLock); return 0; @@ -220,6 +219,9 @@ int VfsJffs2Lookup(struct Vnode *parentVnode, const char *path, int len, struct Jffs2SetVtype(node, newVnode); node->i_vnode = newVnode; + if (&g_jffs2Vops != parentVnode->vop) { + LOS_Panic("jffs2 vop failed"); + } newVnode->vop = parentVnode->vop; newVnode->fop = parentVnode->fop; newVnode->data = node; @@ -232,7 +234,6 @@ int VfsJffs2Lookup(struct Vnode *parentVnode, const char *path, int len, struct (void)VfsHashInsert(newVnode, node->i_ino); *ppVnode = newVnode; - PRINTK("%s-%d: vnode=%p, inode=%p, i_nlink=%d path=%s\n", __FUNCTION__, __LINE__, newVnode, node, node->i_nlink, path); LOS_MuxUnlock(&g_jffs2FsLock); return 0; @@ -260,6 +261,9 @@ int VfsJffs2Create(struct Vnode *parentVnode, const char *path, int mode, struct newVnode->type = VNODE_TYPE_REG; newNode->i_vnode = newVnode; newVnode->vop = parentVnode->vop; + if (&g_jffs2Vops != parentVnode->vop) { + LOS_Panic("jffs2 vop failed"); + } newVnode->fop = parentVnode->fop; newVnode->data = newNode; newVnode->parent = parentVnode; @@ -271,7 +275,6 @@ int VfsJffs2Create(struct Vnode *parentVnode, const char *path, int mode, struct (void)VfsHashInsert(newVnode, newNode->i_ino); *ppVnode = newVnode; - PRINTK("%s-%d: vnode=%p, inode=%p, i_nlink=%d path=%s\n", __FUNCTION__, __LINE__, newVnode, newNode, newNode->i_nlink, path); LOS_MuxUnlock(&g_jffs2FsLock); return 0; @@ -531,6 +534,9 @@ int VfsJffs2Mkdir(struct Vnode *parentNode, const char *dirName, mode_t mode, st newVnode->type = VNODE_TYPE_DIR; node->i_vnode = newVnode; newVnode->vop = parentNode->vop; + if (&g_jffs2Vops != parentVnode->vop) { + LOS_Panic("jffs2 vop failed"); + } newVnode->fop = parentNode->fop; newVnode->data = node; newVnode->parent = parentNode; @@ -542,7 +548,6 @@ int VfsJffs2Mkdir(struct Vnode *parentNode, const char *dirName, mode_t mode, st *ppVnode = newVnode; (void)VfsHashInsert(newVnode, node->i_ino); - PRINTK("%s-%d: vnode=%p, inode=%p, i_nlink=%d path=%s\n", __FUNCTION__, __LINE__, newVnode, node, node->i_nlink, dirName); LOS_MuxUnlock(&g_jffs2FsLock); @@ -597,8 +602,6 @@ int VfsJffs2Chattr(struct Vnode *pVnode, struct IATTR *attr) return ret; } -extern struct Vnode *g_parentOfCoveredVnode; - int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, char *path) { int ret; @@ -609,10 +612,6 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, char *pa LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); - if (parentVnode->data == NULL) { - PRINT_ERR("%s-%d: rmdir parent of mounted vnode. vnode=%p userCount=%d inode=%p\n", __FUNCTION__, __LINE__, parentVnode, parentVnode->useCount, parentVnode->data); - PRINT_ERR("%s-%d: global rmdir parent of mounted vnode. vnode=%p userCount=%d inode=%p\n", __FUNCTION__, __LINE__, g_parentOfCoveredVnode, g_parentOfCoveredVnode->useCount, g_parentOfCoveredVnode->data); - } ret = jffs2_rmdir((struct jffs2_inode *)parentVnode->data, (struct jffs2_inode *)targetVnode->data, (const unsigned char *)path); diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index 0840218e..0293cfd0 100755 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -44,9 +44,6 @@ static LosMux g_vnodeMux; static struct Vnode *g_rootVnode = NULL; static struct VnodeOps g_devfsOps; -extern int g_coveredVnodeTop; -extern struct Vnode *g_coveredVnodeList[100]; - #define ENTRY_TO_VNODE(ptr) LOS_DL_LIST_ENTRY(ptr, struct Vnode, actFreeEntry) #define VNODE_LRU_COUNT 10 #define DEV_VNODE_MODE 0755 @@ -92,8 +89,6 @@ static struct Vnode *GetFromFreeList(void) return vnode; } -extern struct Vnode *g_parentOfCoveredVnode; - struct Vnode *VnodeReclaimLru(void) { struct Vnode *item = NULL; @@ -164,7 +159,6 @@ int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode) VnodeDrop(); *newVnode = vnode; - PRINTK("%s-%d: vnode=%p userCount=%d inode=%p\n", __FUNCTION__, __LINE__, vnode, vnode->useCount, vnode->data); return LOS_OK; } @@ -178,14 +172,6 @@ int VnodeFree(struct Vnode *vnode) struct PathCache *nextItem = NULL; VnodeHold(); - for (int i = 0; i < g_coveredVnodeTop; i++) { - if (vnode == g_coveredVnodeList[i]) { - PRINTK("%s-%d: reclaim mounted vnode. vnode=%p userCount=%d inode=%p\n", __FUNCTION__, __LINE__, vnode, vnode->useCount, vnode->data); - } - } - if (g_parentOfCoveredVnode == vnode) { - PRINTK("%s-%d: reclaim parent of mounted vnode. vnode=%p userCount=%d inode=%p\n", __FUNCTION__, __LINE__, vnode, vnode->useCount, vnode->data); - } if (vnode->useCount > 0) { VnodeDrop(); return -EBUSY; @@ -204,7 +190,6 @@ int VnodeFree(struct Vnode *vnode) vnode->vop->Reclaim(vnode); } - PRINTK("%s-%d: vnode=%p userCount=%d inode=%p\n", __FUNCTION__, __LINE__, vnode, vnode->useCount, vnode->data); LOS_ListDelete(&vnode->actFreeEntry); memset_s(vnode, sizeof(struct Vnode), 0, sizeof(struct Vnode)); LOS_ListAdd(&g_vnodeFreeList, &vnode->actFreeEntry);