f2fs: simplify write_orphan_inodes for better readable
Simplify write_orphan_inodes for better readable. Because we hold the orphan_inode_mutex, so it's safe to use list_for_each_entry instead of list_for_each_safe. Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
parent
ef86d70994
commit
502c6e0bcd
|
@ -300,12 +300,13 @@ int recover_orphan_inodes(struct f2fs_sb_info *sbi)
|
||||||
|
|
||||||
static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
|
static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
|
||||||
{
|
{
|
||||||
struct list_head *head, *this, *next;
|
struct list_head *head;
|
||||||
struct f2fs_orphan_block *orphan_blk = NULL;
|
struct f2fs_orphan_block *orphan_blk = NULL;
|
||||||
struct page *page = NULL;
|
struct page *page = NULL;
|
||||||
unsigned int nentries = 0;
|
unsigned int nentries = 0;
|
||||||
unsigned short index = 1;
|
unsigned short index = 1;
|
||||||
unsigned short orphan_blocks;
|
unsigned short orphan_blocks;
|
||||||
|
struct orphan_inode_entry *orphan = NULL;
|
||||||
|
|
||||||
orphan_blocks = (unsigned short)((sbi->n_orphans +
|
orphan_blocks = (unsigned short)((sbi->n_orphans +
|
||||||
(F2FS_ORPHANS_PER_BLOCK - 1)) / F2FS_ORPHANS_PER_BLOCK);
|
(F2FS_ORPHANS_PER_BLOCK - 1)) / F2FS_ORPHANS_PER_BLOCK);
|
||||||
|
@ -314,12 +315,17 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
|
||||||
head = &sbi->orphan_inode_list;
|
head = &sbi->orphan_inode_list;
|
||||||
|
|
||||||
/* loop for each orphan inode entry and write them in Jornal block */
|
/* loop for each orphan inode entry and write them in Jornal block */
|
||||||
list_for_each_safe(this, next, head) {
|
list_for_each_entry(orphan, head, list) {
|
||||||
struct orphan_inode_entry *orphan;
|
if (!page) {
|
||||||
|
page = grab_meta_page(sbi, start_blk);
|
||||||
|
orphan_blk =
|
||||||
|
(struct f2fs_orphan_block *)page_address(page);
|
||||||
|
memset(orphan_blk, 0, sizeof(*orphan_blk));
|
||||||
|
}
|
||||||
|
|
||||||
orphan = list_entry(this, struct orphan_inode_entry, list);
|
orphan_blk->ino[nentries] = cpu_to_le32(orphan->ino);
|
||||||
|
|
||||||
if (nentries == F2FS_ORPHANS_PER_BLOCK) {
|
if (nentries++ == F2FS_ORPHANS_PER_BLOCK) {
|
||||||
/*
|
/*
|
||||||
* an orphan block is full of 1020 entries,
|
* an orphan block is full of 1020 entries,
|
||||||
* then we need to flush current orphan blocks
|
* then we need to flush current orphan blocks
|
||||||
|
@ -335,24 +341,16 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
|
||||||
nentries = 0;
|
nentries = 0;
|
||||||
page = NULL;
|
page = NULL;
|
||||||
}
|
}
|
||||||
if (page)
|
|
||||||
goto page_exist;
|
|
||||||
|
|
||||||
page = grab_meta_page(sbi, start_blk);
|
|
||||||
orphan_blk = (struct f2fs_orphan_block *)page_address(page);
|
|
||||||
memset(orphan_blk, 0, sizeof(*orphan_blk));
|
|
||||||
page_exist:
|
|
||||||
orphan_blk->ino[nentries++] = cpu_to_le32(orphan->ino);
|
|
||||||
}
|
}
|
||||||
if (!page)
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
orphan_blk->blk_addr = cpu_to_le16(index);
|
if (page) {
|
||||||
orphan_blk->blk_count = cpu_to_le16(orphan_blocks);
|
orphan_blk->blk_addr = cpu_to_le16(index);
|
||||||
orphan_blk->entry_count = cpu_to_le32(nentries);
|
orphan_blk->blk_count = cpu_to_le16(orphan_blocks);
|
||||||
set_page_dirty(page);
|
orphan_blk->entry_count = cpu_to_le32(nentries);
|
||||||
f2fs_put_page(page, 1);
|
set_page_dirty(page);
|
||||||
end:
|
f2fs_put_page(page, 1);
|
||||||
|
}
|
||||||
|
|
||||||
mutex_unlock(&sbi->orphan_inode_mutex);
|
mutex_unlock(&sbi->orphan_inode_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue