xfs: clean up calculation of LR header blocks
PATCH 1/1 xfs: clean up calculation of LR header blocks
Let's use DIV_ROUND_UP() to calculate log record header blocks as what did in xlog_get_iclog_buffer_size() and also wrap up a common helper for log recovery code.
--- fs/xfs/libxfs/xfs_log_format.h | 10 +++++++++ fs/xfs/xfs_log.c | 4 +--- fs/xfs/xfs_log_recover.c | 37 ++++++++-------------------------- 3 files changed, 19 insertions(+), 32 deletions(-)
fs/xfs/libxfs/xfs_log_format.h +10 -0
@@ -860,4 +860,14 @@ struct xfs_icreate_log { __be32 icl_gen; /* inode generation number to use */ }; +static inline int xlog_logv2_rec_hblks (struct xlog_rec_header *rh) +{ +int h_size =be32_to_cpu (rh->h_size); + +if ((be32_to_cpu (rh->h_version) &XLOG_VERSION_2 ) && + (h_size >XLOG_HEADER_CYCLE_SIZE )) +return DIV_ROUND_UP (h_size,XLOG_HEADER_CYCLE_SIZE ); +return 1 ; +} +#endif /* __XFS_LOG_FORMAT_H__ */
fs/xfs/xfs_log.c +1 -3
@@ -1604,9 +1604,7 @@ xlog_cksum(int i;int xheads; - xheads = size /XLOG_HEADER_CYCLE_SIZE ; -if (size %XLOG_HEADER_CYCLE_SIZE ) - xheads++; + xheads =DIV_ROUND_UP (size,XLOG_HEADER_CYCLE_SIZE );for (i =1 ; i < xheads; i++) { crc = crc32c(crc, &xhdr[i].hic_xheader,
fs/xfs/xfs_log_recover.c +8 -29
@@ -489,15 +489,10 @@ xlog_find_verify_log_record(* reset last_blk. Only when last_blk points in the middle of a log * record do we update last_blk. */ -if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) { -uint h_size =be32_to_cpu (head->h_size); - - xhdrs = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - xhdrs++; - }else { +if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) + xhdrs =xlog_logv2_rec_hblks (head); +else xhdrs =1 ; - }if (*last_blk - i + extra_bblks !=BTOBB (be32_to_cpu (head->h_len)) + xhdrs)
@@ -1184,21 +1179,10 @@ xlog_check_unmount_rec(* below. We won't want to clear the unmount record if there is one, so * we pass the lsn of the unmount record rather than the block after it. */ -if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) { -int h_size =be32_to_cpu (rhead->h_size); -int h_version =be32_to_cpu (rhead->h_version); - -if ((h_version &XLOG_VERSION_2 ) && - (h_size >XLOG_HEADER_CYCLE_SIZE )) { - hblks = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - hblks++; - }else { - hblks =1 ; - } - }else { +if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) + hblks =xlog_logv2_rec_hblks (rhead); +else hblks =1 ; - } after_umount_blk =xlog_wrap_logbno (log, rhead_blk + hblks +BTOBB (be32_to_cpu (rhead->h_len)));
@@ -3016,15 +3000,10 @@ xlog_do_recovery_pass( } } -if ((be32_to_cpu (rhead->h_version) &XLOG_VERSION_2 ) && - (h_size >XLOG_HEADER_CYCLE_SIZE )) { - hblks = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - hblks++; + hblks =xlog_logv2_rec_hblks (rhead); +if (hblks !=1 ) {kmem_free (hbp); hbp =xlog_alloc_buffer (log, hblks); - }else { - hblks =1 ; } }else {ASSERT (log->l_sectBBsize ==1 );
Signature · 1 line
2.18.1
Quoted 11 lines · Gao Xiang
Let's use
DIV_ROUND_UP()to calculate log record header blocks as what did inxlog_get_iclog_buffer_size()and also wrap up a common helper for log recovery code.Signed-off-by Gao Xiang <[email protected]>--- fs/xfs/libxfs/xfs_log_format.h | 10 +++++++++ fs/xfs/xfs_log.c | 4 +--- fs/xfs/xfs_log_recover.c | 37 ++++++++-------------------------- 3 files changed, 19 insertions(+), 32 deletions(-)
...
Quoted 10 lines
fs/xfs/xfs_log_recover.c +0
-2@@ -489,15 +489,10 @@ xlog_find_verify_log_record(* reset last_blk. Only when last_blk points in the middle of a log * record do we update last_blk. */ -if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) { -uint h_size =be32_to_cpu (head->h_size);
fs/xfs/xfs_log_recover.c xlog_find_verify_log_record( · line 500
Quoted 10 lines
fs/xfs/xfs_log_recover.c +3
-6- - xhdrs = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - xhdrs++; - }else { +if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) + xhdrs =xlog_logv2_rec_hblks (head); +else xhdrs =1 ; - }
Can we fold the _haslogv2() check into the helper as well (then perhaps drop the 'v2' from the name)? Otherwise looks like a nice cleanup to me..
Brian
Quoted 49 lines
fs/xfs/xfs_log_recover.c +5
-21if (*last_blk - i + extra_bblks !=BTOBB (be32_to_cpu (head->h_len)) + xhdrs)@@ -1184,21 +1179,10 @@ xlog_check_unmount_rec(* below. We won't want to clear the unmount record if there is one, so * we pass the lsn of the unmount record rather than the block after it. */ -if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) { -int h_size =be32_to_cpu (rhead->h_size); -int h_version =be32_to_cpu (rhead->h_version); - -if ((h_version &XLOG_VERSION_2 ) && - (h_size >XLOG_HEADER_CYCLE_SIZE )) { - hblks = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - hblks++; - }else { - hblks =1 ; - } - }else { +if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) + hblks =xlog_logv2_rec_hblks (rhead); +else hblks =1 ; - } after_umount_blk =xlog_wrap_logbno (log, rhead_blk + hblks +BTOBB (be32_to_cpu (rhead->h_len)));@@ -3016,15 +3000,10 @@ xlog_do_recovery_pass( } } -if ((be32_to_cpu (rhead->h_version) &XLOG_VERSION_2 ) && - (h_size >XLOG_HEADER_CYCLE_SIZE )) { - hblks = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - hblks++; + hblks =xlog_logv2_rec_hblks (rhead); +if (hblks !=1 ) {kmem_free (hbp); hbp =xlog_alloc_buffer (log, hblks); - }else { - hblks =1 ; } }else {ASSERT (log->l_sectBBsize ==1 );Signature · 1 line
2.18.1
Hi Brian,
Quoted 29 lines · Brian Foster
Quoted 11 lines · Gao Xiang
Let's use
DIV_ROUND_UP()to calculate log record header blocks as what did inxlog_get_iclog_buffer_size()and also wrap up a common helper for log recovery code.Signed-off-by Gao Xiang <[email protected]>--- fs/xfs/libxfs/xfs_log_format.h | 10 +++++++++ fs/xfs/xfs_log.c | 4 +--- fs/xfs/xfs_log_recover.c | 37 ++++++++-------------------------- 3 files changed, 19 insertions(+), 32 deletions(-)...
Quoted 16 lines
fs/xfs/xfs_log_recover.c +1
-7@@ -489,15 +489,10 @@ xlog_find_verify_log_record(* reset last_blk. Only when last_blk points in the middle of a log * record do we update last_blk. */ -if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) { -uint h_size =be32_to_cpu (head->h_size); - - xhdrs = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - xhdrs++; - }else { +if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb))
Quoted 8 lines
fs/xfs/xfs_log_recover.c xlog_find_verify_log_record( · line 500
Quoted 4 lines
fs/xfs/xfs_log_recover.c +2
-1+ xhdrs =xlog_logv2_rec_hblks (head); + else xhdrs =1 ; - }Can we fold the
_haslogv2()check into the helper as well (then perhaps drop the 'v2' from the name)? Otherwise looks like a nice cleanup to me..
Thanks for your suggestion.
I would have done the same at the beginning, but the case in xlog_do_recovery_pass() from the current codebase is a bit complex for now.
I will try to simplify the logic in xlog_do_recovery_pass() tomorrow, but if it makes more complex.. I'd suggest leave it as-is...
Thanks,
Gao Xiang
Quoted 53 lines
Brian
Quoted 49 lines
fs/xfs/xfs_log_recover.c +5
-21if (*last_blk - i + extra_bblks !=BTOBB (be32_to_cpu (head->h_len)) + xhdrs)@@ -1184,21 +1179,10 @@ xlog_check_unmount_rec(* below. We won't want to clear the unmount record if there is one, so * we pass the lsn of the unmount record rather than the block after it. */ -if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) { -int h_size =be32_to_cpu (rhead->h_size); -int h_version =be32_to_cpu (rhead->h_version); - -if ((h_version &XLOG_VERSION_2 ) && - (h_size >XLOG_HEADER_CYCLE_SIZE )) { - hblks = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - hblks++; - }else { - hblks =1 ; - } - }else { +if (xfs_sb_version_haslogv2 (&log->l_mp->m_sb)) + hblks =xlog_logv2_rec_hblks (rhead); +else hblks =1 ; - } after_umount_blk =xlog_wrap_logbno (log, rhead_blk + hblks +BTOBB (be32_to_cpu (rhead->h_len)));@@ -3016,15 +3000,10 @@ xlog_do_recovery_pass( } } -if ((be32_to_cpu (rhead->h_version) &XLOG_VERSION_2 ) && - (h_size >XLOG_HEADER_CYCLE_SIZE )) { - hblks = h_size /XLOG_HEADER_CYCLE_SIZE ; -if (h_size %XLOG_HEADER_CYCLE_SIZE ) - hblks++; + hblks =xlog_logv2_rec_hblks (rhead); +if (hblks !=1 ) {kmem_free (hbp); hbp =xlog_alloc_buffer (log, hblks); - }else { - hblks =1 ; } }else {ASSERT (log->l_sectBBsize ==1 );Signature · 1 line
2.18.1