Skip to content

Commit

Permalink
fs/inode: add reference to protect filelist of group
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
  • Loading branch information
Donny9 committed Sep 8, 2024
1 parent 9d5b9b7 commit d9c5e56
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
42 changes: 36 additions & 6 deletions fs/inode/fs_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ static void task_fssync(FAR struct tcb_s *tcb, FAR void *arg)
int i;
int j;

list = &tcb->group->tg_filelist;

list = files_getlist(tcb);
for (i = 0; i < list->fl_rows; i++)
{
for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++)
Expand All @@ -189,6 +188,8 @@ static void task_fssync(FAR struct tcb_s *tcb, FAR void *arg)
}
}
}

files_putlist(list);
}

/****************************************************************************
Expand Down Expand Up @@ -309,6 +310,7 @@ void files_initlist(FAR struct filelist *list)
*/

list->fl_rows = 1;
list->fl_crefs = 1;
list->fl_files = &list->fl_prefile;
list->fl_prefile = list->fl_prefiles;
}
Expand Down Expand Up @@ -375,19 +377,47 @@ void files_dumplist(FAR struct filelist *list)
}

/****************************************************************************
* Name: files_releaselist
* Name: files_getlist
*
* Description:
* Release a reference to the file list
* Get the list of files by tcb.
*
* Assumptions:
* Called during task deletion in a safe context.
*
****************************************************************************/

void files_releaselist(FAR struct filelist *list)
FAR struct filelist *files_getlist(FAR struct tcb_s *tcb)
{
FAR struct filelist *list = &tcb->group->tg_filelist;

DEBUGASSERT(list->fl_crefs >= 1);
list->fl_crefs++;

return list;
}

/****************************************************************************
* Name: files_putlist
*
* Description:
* Release the list of files.
*
* Assumptions:
* Called during task deletion in a safe context.
*
****************************************************************************/

void files_putlist(FAR struct filelist *list)
{
int i;
int j;

DEBUGASSERT(list);
DEBUGASSERT(list->fl_crefs >= 1);
if (--list->fl_crefs > 0)
{
return;
}

/* Close each file descriptor .. Normally, you would need take the list
* mutex, but it is safe to ignore the mutex in this context
Expand Down
17 changes: 14 additions & 3 deletions include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ struct file
struct filelist
{
uint8_t fl_rows; /* The number of rows of fl_files array */
uint8_t fl_crefs; /* The references to filelist */
FAR struct file **fl_files; /* The pointer of two layer file descriptors array */

/* Pre-allocated files to avoid allocator access during thread creation
Expand Down Expand Up @@ -876,14 +877,24 @@ void files_initlist(FAR struct filelist *list);
void files_dumplist(FAR struct filelist *list);

/****************************************************************************
* Name: files_releaselist
* Name: files_getlist
*
* Description:
* Release a reference to the file list
* Get the list of files by tcb.
*
****************************************************************************/

void files_releaselist(FAR struct filelist *list);
FAR struct filelist *files_getlist(FAR struct tcb_s *tcb);

/****************************************************************************
* Name: files_putlist
*
* Description:
* Release the list of files.
*
****************************************************************************/

void files_putlist(FAR struct filelist * list);

/****************************************************************************
* Name: files_countlist
Expand Down
2 changes: 1 addition & 1 deletion sched/group/group_leave.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ group_release(FAR struct task_group_s *group, uint8_t ttype)

/* Free resources held by the file descriptor list */

files_releaselist(&group->tg_filelist);
files_putlist(&group->tg_filelist);

#ifndef CONFIG_DISABLE_ENVIRON
/* Release all shared environment variables */
Expand Down

0 comments on commit d9c5e56

Please sign in to comment.