Commit 837c23fb authored by Chunguang Xu's avatar Chunguang Xu Committed by Theodore Ts'o

ext4: use ASSERT() to replace J_ASSERT()

There are currently multiple forms of assertion, such as J_ASSERT().
J_ASEERT() is provided for the jbd module, which is a public module.
Maybe we should use custom ASSERT() like other file systems, such as
xfs, which would be better.
Signed-off-by: default avatarChunguang Xu <brookxu@tencent.com>
Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
Link: https://lore.kernel.org/r/1604764698-4269-1-git-send-email-brookxu@tencent.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent ca9b404f
...@@ -185,7 +185,7 @@ static int ext4_init_block_bitmap(struct super_block *sb, ...@@ -185,7 +185,7 @@ static int ext4_init_block_bitmap(struct super_block *sb,
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
ext4_fsblk_t start, tmp; ext4_fsblk_t start, tmp;
J_ASSERT_BH(bh, buffer_locked(bh)); ASSERT(buffer_locked(bh));
/* If checksum is bad mark all blocks used to prevent allocation /* If checksum is bad mark all blocks used to prevent allocation
* essentially implementing a per-group read-only flag. */ * essentially implementing a per-group read-only flag. */
......
...@@ -98,6 +98,16 @@ ...@@ -98,6 +98,16 @@
#define ext_debug(ino, fmt, ...) no_printk(fmt, ##__VA_ARGS__) #define ext_debug(ino, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
#endif #endif
#define ASSERT(assert) \
do { \
if (unlikely(!(assert))) { \
printk(KERN_EMERG \
"Assertion failure in %s() at %s:%d: '%s'\n", \
__func__, __FILE__, __LINE__, #assert); \
BUG(); \
} \
} while (0)
/* data type for block offset of block group */ /* data type for block offset of block group */
typedef int ext4_grpblk_t; typedef int ext4_grpblk_t;
......
...@@ -136,7 +136,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -136,7 +136,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (unlikely(ext4_forced_shutdown(sbi))) if (unlikely(ext4_forced_shutdown(sbi)))
return -EIO; return -EIO;
J_ASSERT(ext4_journal_current_handle() == NULL); ASSERT(ext4_journal_current_handle() == NULL);
trace_ext4_sync_file_enter(file, datasync); trace_ext4_sync_file_enter(file, datasync);
......
...@@ -534,8 +534,8 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, ...@@ -534,8 +534,8 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
ext4_fsblk_t first_block = 0; ext4_fsblk_t first_block = 0;
trace_ext4_ind_map_blocks_enter(inode, map->m_lblk, map->m_len, flags); trace_ext4_ind_map_blocks_enter(inode, map->m_lblk, map->m_len, flags);
J_ASSERT(!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))); ASSERT(!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)));
J_ASSERT(handle != NULL || (flags & EXT4_GET_BLOCKS_CREATE) == 0); ASSERT(handle != NULL || (flags & EXT4_GET_BLOCKS_CREATE) == 0);
depth = ext4_block_to_path(inode, map->m_lblk, offsets, depth = ext4_block_to_path(inode, map->m_lblk, offsets,
&blocks_to_boundary); &blocks_to_boundary);
......
...@@ -830,8 +830,8 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, ...@@ -830,8 +830,8 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
int create = map_flags & EXT4_GET_BLOCKS_CREATE; int create = map_flags & EXT4_GET_BLOCKS_CREATE;
int err; int err;
J_ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
|| handle != NULL || create == 0); || handle != NULL || create == 0);
map.m_lblk = block; map.m_lblk = block;
map.m_len = 1; map.m_len = 1;
...@@ -846,9 +846,9 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, ...@@ -846,9 +846,9 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
if (unlikely(!bh)) if (unlikely(!bh))
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (map.m_flags & EXT4_MAP_NEW) { if (map.m_flags & EXT4_MAP_NEW) {
J_ASSERT(create != 0); ASSERT(create != 0);
J_ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
|| (handle != NULL)); || (handle != NULL));
/* /*
* Now that we do not always journal data, we should * Now that we do not always journal data, we should
......
...@@ -182,10 +182,6 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode, ...@@ -182,10 +182,6 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
return bh; return bh;
} }
#ifndef assert
#define assert(test) J_ASSERT(test)
#endif
#ifdef DX_DEBUG #ifdef DX_DEBUG
#define dxtrace(command) command #define dxtrace(command) command
#else #else
...@@ -849,7 +845,7 @@ dx_probe(struct ext4_filename *fname, struct inode *dir, ...@@ -849,7 +845,7 @@ dx_probe(struct ext4_filename *fname, struct inode *dir,
break; break;
} }
} }
assert (at == p - 1); ASSERT(at == p - 1);
} }
at = p - 1; at = p - 1;
...@@ -1265,8 +1261,8 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) ...@@ -1265,8 +1261,8 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block)
struct dx_entry *old = frame->at, *new = old + 1; struct dx_entry *old = frame->at, *new = old + 1;
int count = dx_get_count(entries); int count = dx_get_count(entries);
assert(count < dx_get_limit(entries)); ASSERT(count < dx_get_limit(entries));
assert(old < entries + count); ASSERT(old < entries + count);
memmove(new + 1, new, (char *)(entries + count) - (char *)(new)); memmove(new + 1, new, (char *)(entries + count) - (char *)(new));
dx_set_hash(new, hash); dx_set_hash(new, hash);
dx_set_block(new, block); dx_set_block(new, block);
...@@ -2961,7 +2957,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode) ...@@ -2961,7 +2957,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
* hold i_mutex, or the inode can not be referenced from outside, * hold i_mutex, or the inode can not be referenced from outside,
* so i_nlink should not be bumped due to race * so i_nlink should not be bumped due to race
*/ */
J_ASSERT((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || ASSERT((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
BUFFER_TRACE(sbi->s_sbh, "get_write_access"); BUFFER_TRACE(sbi->s_sbh, "get_write_access");
......
...@@ -1240,7 +1240,7 @@ static void ext4_put_super(struct super_block *sb) ...@@ -1240,7 +1240,7 @@ static void ext4_put_super(struct super_block *sb)
* in-memory list had better be clean by this point. */ * in-memory list had better be clean by this point. */
if (!list_empty(&sbi->s_orphan)) if (!list_empty(&sbi->s_orphan))
dump_orphan_list(sb, sbi); dump_orphan_list(sb, sbi);
J_ASSERT(list_empty(&sbi->s_orphan)); ASSERT(list_empty(&sbi->s_orphan));
sync_blockdev(sb->s_bdev); sync_blockdev(sb->s_bdev);
invalidate_bdev(sb->s_bdev); invalidate_bdev(sb->s_bdev);
......
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