Commit 8508e44a authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: fix to determine start_cp_addr by sbi->cur_cp_pack

We don't guarantee cp_addr is fixed by cp_version.
This is to sync with f2fs-tools.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 19c52651
...@@ -772,6 +772,11 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -772,6 +772,11 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
if (sanity_check_ckpt(sbi)) if (sanity_check_ckpt(sbi))
goto fail_no_cp; goto fail_no_cp;
if (cur_page == cp1)
sbi->cur_cp_pack = 1;
else
sbi->cur_cp_pack = 2;
if (cp_blks <= 1) if (cp_blks <= 1)
goto done; goto done;
...@@ -1127,7 +1132,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1127,7 +1132,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
le32_to_cpu(ckpt->checksum_offset))) le32_to_cpu(ckpt->checksum_offset)))
= cpu_to_le32(crc32); = cpu_to_le32(crc32);
start_blk = __start_cp_addr(sbi); start_blk = __start_cp_next_addr(sbi);
/* need to wait for end_io results */ /* need to wait for end_io results */
wait_on_all_pages_writeback(sbi); wait_on_all_pages_writeback(sbi);
...@@ -1190,6 +1195,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1190,6 +1195,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
clear_sbi_flag(sbi, SBI_IS_DIRTY); clear_sbi_flag(sbi, SBI_IS_DIRTY);
clear_sbi_flag(sbi, SBI_NEED_CP); clear_sbi_flag(sbi, SBI_NEED_CP);
__set_cp_next_pack(sbi);
/* /*
* redirty superblock if metadata like node page or inode cache is * redirty superblock if metadata like node page or inode cache is
......
...@@ -792,6 +792,7 @@ struct f2fs_sb_info { ...@@ -792,6 +792,7 @@ struct f2fs_sb_info {
/* for checkpoint */ /* for checkpoint */
struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
int cur_cp_pack; /* remain current cp pack */
spinlock_t cp_lock; /* for flag in ckpt */ spinlock_t cp_lock; /* for flag in ckpt */
struct inode *meta_inode; /* cache meta blocks */ struct inode *meta_inode; /* cache meta blocks */
struct mutex cp_mutex; /* checkpoint procedure lock */ struct mutex cp_mutex; /* checkpoint procedure lock */
...@@ -1352,22 +1353,27 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) ...@@ -1352,22 +1353,27 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
{ {
block_t start_addr; block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
unsigned long long ckpt_version = cur_cp_version(ckpt);
start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
/* if (sbi->cur_cp_pack == 2)
* odd numbered checkpoint should at cp segment 0
* and even segment must be at cp segment 1
*/
if (!(ckpt_version & 1))
start_addr += sbi->blocks_per_seg; start_addr += sbi->blocks_per_seg;
return start_addr;
}
static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
{
block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
if (sbi->cur_cp_pack == 1)
start_addr += sbi->blocks_per_seg;
return start_addr; return start_addr;
} }
static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
{
sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
}
static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
{ {
return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment