未验证 提交 5bbcb5dc 编写于 作者: G geniusgogo 提交者: GitHub

fix tmpfs spinlock error. (#7216)

上级 dc243888
...@@ -84,8 +84,7 @@ static int _free_subdir(struct tmpfs_file *dfile) ...@@ -84,8 +84,7 @@ static int _free_subdir(struct tmpfs_file *dfile)
{ {
struct tmpfs_file *file; struct tmpfs_file *file;
rt_list_t *list, *temp_list; rt_list_t *list, *temp_list;
struct tmpfs_sb *superblock;
RT_DEFINE_SPINLOCK(lock);
RT_ASSERT(dfile->type == TMPFS_TYPE_DIR); RT_ASSERT(dfile->type == TMPFS_TYPE_DIR);
...@@ -101,9 +100,14 @@ static int _free_subdir(struct tmpfs_file *dfile) ...@@ -101,9 +100,14 @@ static int _free_subdir(struct tmpfs_file *dfile)
/* TODO: fix for rt-smart */ /* TODO: fix for rt-smart */
rt_free(file->data); rt_free(file->data);
} }
rt_hw_spin_lock(&lock);
superblock = file->sb;
RT_ASSERT(superblock != NULL);
rt_spin_lock(&superblock->lock);
rt_list_remove(&(file->sibling)); rt_list_remove(&(file->sibling));
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
rt_free(file); rt_free(file);
} }
return 0; return 0;
...@@ -126,6 +130,8 @@ int dfs_tmpfs_mount(struct dfs_filesystem *fs, ...@@ -126,6 +130,8 @@ int dfs_tmpfs_mount(struct dfs_filesystem *fs,
rt_list_init(&superblock->root.sibling); rt_list_init(&superblock->root.sibling);
rt_list_init(&superblock->root.subdirs); rt_list_init(&superblock->root.subdirs);
rt_spin_lock_init(&superblock->lock);
fs->data = superblock; fs->data = superblock;
return RT_EOK; return RT_EOK;
...@@ -208,8 +214,6 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock, ...@@ -208,8 +214,6 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
struct tmpfs_file *file, *curfile; struct tmpfs_file *file, *curfile;
rt_list_t *list; rt_list_t *list;
RT_DEFINE_SPINLOCK(lock);
subpath = path; subpath = path;
while (*subpath == '/' && *subpath) while (*subpath == '/' && *subpath)
subpath ++; subpath ++;
...@@ -234,7 +238,7 @@ find_subpath: ...@@ -234,7 +238,7 @@ find_subpath:
memset(subdir_name, 0, TMPFS_NAME_MAX); memset(subdir_name, 0, TMPFS_NAME_MAX);
_get_subdir(curpath, subdir_name); _get_subdir(curpath, subdir_name);
rt_hw_spin_lock(&lock); rt_spin_lock(&superblock->lock);
rt_list_for_each(list, &curfile->subdirs) rt_list_for_each(list, &curfile->subdirs)
{ {
...@@ -245,7 +249,7 @@ find_subpath: ...@@ -245,7 +249,7 @@ find_subpath:
{ {
*size = file->size; *size = file->size;
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
return file; return file;
} }
} }
...@@ -254,11 +258,11 @@ find_subpath: ...@@ -254,11 +258,11 @@ find_subpath:
*size = file->size; *size = file->size;
curpath = subpath; curpath = subpath;
curfile = file; curfile = file;
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
goto find_subpath; goto find_subpath;
} }
} }
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
/* not found */ /* not found */
return NULL; return NULL;
} }
...@@ -357,8 +361,6 @@ int dfs_tmpfs_open(struct dfs_file *file) ...@@ -357,8 +361,6 @@ int dfs_tmpfs_open(struct dfs_file *file)
struct dfs_filesystem *fs; struct dfs_filesystem *fs;
char parent_path[DFS_PATH_MAX],file_name[TMPFS_NAME_MAX]; char parent_path[DFS_PATH_MAX],file_name[TMPFS_NAME_MAX];
RT_DEFINE_SPINLOCK(lock);
RT_ASSERT(file->vnode->ref_count > 0); RT_ASSERT(file->vnode->ref_count > 0);
if (file->vnode->ref_count > 1) if (file->vnode->ref_count > 1)
{ {
...@@ -419,9 +421,9 @@ int dfs_tmpfs_open(struct dfs_file *file) ...@@ -419,9 +421,9 @@ int dfs_tmpfs_open(struct dfs_file *file)
{ {
d_file->type = TMPFS_TYPE_FILE; d_file->type = TMPFS_TYPE_FILE;
} }
rt_hw_spin_lock(&lock); rt_spin_lock(&superblock->lock);
rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling)); rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling));
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
} }
} }
/* Creates a new file. /* Creates a new file.
...@@ -559,8 +561,6 @@ int dfs_tmpfs_unlink(struct dfs_filesystem *fs, const char *path) ...@@ -559,8 +561,6 @@ int dfs_tmpfs_unlink(struct dfs_filesystem *fs, const char *path)
struct tmpfs_sb *superblock; struct tmpfs_sb *superblock;
struct tmpfs_file *d_file; struct tmpfs_file *d_file;
RT_DEFINE_SPINLOCK(lock);
superblock = (struct tmpfs_sb *)fs->data; superblock = (struct tmpfs_sb *)fs->data;
RT_ASSERT(superblock != NULL); RT_ASSERT(superblock != NULL);
...@@ -568,9 +568,9 @@ int dfs_tmpfs_unlink(struct dfs_filesystem *fs, const char *path) ...@@ -568,9 +568,9 @@ int dfs_tmpfs_unlink(struct dfs_filesystem *fs, const char *path)
if (d_file == NULL) if (d_file == NULL)
return -ENOENT; return -ENOENT;
rt_hw_spin_lock(&lock); rt_spin_lock(&superblock->lock);
rt_list_remove(&(d_file->sibling)); rt_list_remove(&(d_file->sibling));
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
if (d_file->data != NULL) if (d_file->data != NULL)
rt_free(d_file->data); rt_free(d_file->data);
...@@ -588,8 +588,6 @@ int dfs_tmpfs_rename(struct dfs_filesystem *fs, ...@@ -588,8 +588,6 @@ int dfs_tmpfs_rename(struct dfs_filesystem *fs,
rt_size_t size; rt_size_t size;
char parent_path[DFS_PATH_MAX],file_name[TMPFS_NAME_MAX]; char parent_path[DFS_PATH_MAX],file_name[TMPFS_NAME_MAX];
RT_DEFINE_SPINLOCK(lock);
superblock = (struct tmpfs_sb *)fs->data; superblock = (struct tmpfs_sb *)fs->data;
RT_ASSERT(superblock != NULL); RT_ASSERT(superblock != NULL);
...@@ -609,15 +607,15 @@ int dfs_tmpfs_rename(struct dfs_filesystem *fs, ...@@ -609,15 +607,15 @@ int dfs_tmpfs_rename(struct dfs_filesystem *fs,
p_file = dfs_tmpfs_lookup(superblock, parent_path, &size); p_file = dfs_tmpfs_lookup(superblock, parent_path, &size);
RT_ASSERT(p_file != NULL); RT_ASSERT(p_file != NULL);
rt_hw_spin_lock(&lock); rt_spin_lock(&superblock->lock);
rt_list_remove(&(d_file->sibling)); rt_list_remove(&(d_file->sibling));
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
strncpy(d_file->name, file_name, TMPFS_NAME_MAX); strncpy(d_file->name, file_name, TMPFS_NAME_MAX);
rt_hw_spin_lock(&lock); rt_spin_lock(&superblock->lock);
rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling)); rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling));
rt_hw_spin_unlock(&lock); rt_spin_unlock(&superblock->lock);
return RT_EOK; return RT_EOK;
} }
......
...@@ -39,6 +39,7 @@ struct tmpfs_sb ...@@ -39,6 +39,7 @@ struct tmpfs_sb
struct tmpfs_file root; /* root dir */ struct tmpfs_file root; /* root dir */
rt_size_t df_size; /* df size */ rt_size_t df_size; /* df size */
rt_list_t sibling; /* sb sibling list */ rt_list_t sibling; /* sb sibling list */
struct rt_spinlock lock; /* tmpfs lock */
}; };
int dfs_tmpfs_init(void); int dfs_tmpfs_init(void);
......
...@@ -207,8 +207,11 @@ void rt_hw_secondary_cpu_idle_exec(void); ...@@ -207,8 +207,11 @@ void rt_hw_secondary_cpu_idle_exec(void);
#define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable() #define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable()
#define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock)) #define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock))
typedef int rt_spinlock_t; typedef rt_ubase_t rt_spinlock_t;
struct rt_spinlock
{
rt_spinlock_t lock;
};
#endif #endif
#ifdef RT_USING_CACHE #ifdef RT_USING_CACHE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册