Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tmpfs spinlock error. #7216

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ static int _free_subdir(struct tmpfs_file *dfile)
{
struct tmpfs_file *file;
rt_list_t *list, *temp_list;

RT_DEFINE_SPINLOCK(lock);
struct tmpfs_sb *superblock;

RT_ASSERT(dfile->type == TMPFS_TYPE_DIR);

Expand All @@ -101,9 +100,14 @@ static int _free_subdir(struct tmpfs_file *dfile)
/* TODO: fix for rt-smart */
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_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);

rt_free(file);
}
return 0;
Expand All @@ -126,6 +130,8 @@ int dfs_tmpfs_mount(struct dfs_filesystem *fs,
rt_list_init(&superblock->root.sibling);
rt_list_init(&superblock->root.subdirs);

rt_spin_lock_init(&superblock->lock);

fs->data = superblock;

return RT_EOK;
Expand Down Expand Up @@ -208,8 +214,6 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
struct tmpfs_file *file, *curfile;
rt_list_t *list;

RT_DEFINE_SPINLOCK(lock);

subpath = path;
while (*subpath == '/' && *subpath)
subpath ++;
Expand All @@ -234,7 +238,7 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
memset(subdir_name, 0, TMPFS_NAME_MAX);
_get_subdir(curpath, subdir_name);

rt_hw_spin_lock(&lock);
rt_spin_lock(&superblock->lock);

rt_list_for_each(list, &curfile->subdirs)
{
Expand All @@ -245,7 +249,7 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
{
*size = file->size;

rt_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);
return file;
}
}
Expand All @@ -254,11 +258,11 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
*size = file->size;
curpath = subpath;
curfile = file;
rt_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);
goto find_subpath;
}
}
rt_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);
/* not found */
return NULL;
}
Expand Down Expand Up @@ -357,8 +361,6 @@ int dfs_tmpfs_open(struct dfs_file *file)
struct dfs_filesystem *fs;
char parent_path[DFS_PATH_MAX],file_name[TMPFS_NAME_MAX];

RT_DEFINE_SPINLOCK(lock);

RT_ASSERT(file->vnode->ref_count > 0);
if (file->vnode->ref_count > 1)
{
Expand Down Expand Up @@ -419,9 +421,9 @@ int dfs_tmpfs_open(struct dfs_file *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_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);
}
}
/* Creates a new file.
Expand Down Expand Up @@ -559,18 +561,16 @@ int dfs_tmpfs_unlink(struct dfs_filesystem *fs, const char *path)
struct tmpfs_sb *superblock;
struct tmpfs_file *d_file;

RT_DEFINE_SPINLOCK(lock);

superblock = (struct tmpfs_sb *)fs->data;
RT_ASSERT(superblock != NULL);

d_file = dfs_tmpfs_lookup(superblock, path, &size);
if (d_file == NULL)
return -ENOENT;

rt_hw_spin_lock(&lock);
rt_spin_lock(&superblock->lock);
rt_list_remove(&(d_file->sibling));
rt_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);

if (d_file->data != NULL)
rt_free(d_file->data);
Expand All @@ -588,8 +588,6 @@ int dfs_tmpfs_rename(struct dfs_filesystem *fs,
rt_size_t size;
char parent_path[DFS_PATH_MAX],file_name[TMPFS_NAME_MAX];

RT_DEFINE_SPINLOCK(lock);

superblock = (struct tmpfs_sb *)fs->data;
RT_ASSERT(superblock != NULL);

Expand All @@ -609,15 +607,15 @@ int dfs_tmpfs_rename(struct dfs_filesystem *fs,
p_file = dfs_tmpfs_lookup(superblock, parent_path, &size);
RT_ASSERT(p_file != NULL);

rt_hw_spin_lock(&lock);
rt_spin_lock(&superblock->lock);
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);

rt_hw_spin_lock(&lock);
rt_spin_lock(&superblock->lock);
rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling));
rt_hw_spin_unlock(&lock);
rt_spin_unlock(&superblock->lock);

return RT_EOK;
}
Expand Down
1 change: 1 addition & 0 deletions components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct tmpfs_sb
struct tmpfs_file root; /* root dir */
rt_size_t df_size; /* df size */
rt_list_t sibling; /* sb sibling list */
struct rt_spinlock lock; /* tmpfs lock */
};

int dfs_tmpfs_init(void);
Expand Down
7 changes: 5 additions & 2 deletions include/rthw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_unlock(lock) rt_hw_interrupt_enable(*(lock))

typedef int rt_spinlock_t;

typedef rt_ubase_t rt_spinlock_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是因为之前单核没定义嘛

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

定义的前后不搭

struct rt_spinlock
{
rt_spinlock_t lock;
};
#endif

#ifdef RT_USING_CACHE
Expand Down