Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24676da4 authored by Theodore Ts'o's avatar Theodore Ts'o
Browse files

ext4: Convert calls of ext4_error() to EXT4_ERROR_INODE()



EXT4_ERROR_INODE() tends to provide better error information and in a
more consistent format.  Some errors were not even identifying the inode
or directory which was corrupted, which made them not very useful.

Addresses-Google-Bug: #2507977

Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 2ed88685
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -83,11 +83,10 @@ int ext4_check_dir_entry(const char *function, struct inode *dir,
		error_msg = "inode out of bounds";

	if (error_msg != NULL)
		__ext4_error(dir->i_sb, function,
			"bad entry in directory #%lu: %s - block=%llu"
		ext4_error_inode(function, dir,
			"bad entry in directory: %s - block=%llu"
			"offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
			dir->i_ino, error_msg, 
			(unsigned long long) bh->b_blocknr,     
			error_msg, (unsigned long long) bh->b_blocknr,
			(unsigned) (offset%bh->b_size), offset,
			le32_to_cpu(de->inode),
			rlen, de->name_len);
@@ -152,9 +151,8 @@ static int ext4_readdir(struct file *filp,
		 */
		if (!bh) {
			if (!dir_has_error) {
				ext4_error(sb, "directory #%lu "
				EXT4_ERROR_INODE(inode, "directory "
					   "contains a hole at offset %Lu",
					   inode->i_ino,
					   (unsigned long long) filp->f_pos);
				dir_has_error = 1;
			}
+2 −2
Original line number Diff line number Diff line
@@ -54,10 +54,10 @@
#endif

#define EXT4_ERROR_INODE(inode, fmt, a...) \
	ext4_error_inode(__func__, (inode), (fmt), ## a);
	ext4_error_inode(__func__, (inode), (fmt), ## a)

#define EXT4_ERROR_FILE(file, fmt, a...)	\
	ext4_error_file(__func__, (file), (fmt), ## a);
	ext4_error_file(__func__, (file), (fmt), ## a)

/* data type for block offset of block group */
typedef int ext4_grpblk_t;
+4 −6
Original line number Diff line number Diff line
@@ -439,10 +439,10 @@ static int __ext4_ext_check(const char *function, struct inode *inode,
	return 0;

corrupted:
	__ext4_error(inode->i_sb, function,
			"bad header/extent in inode #%lu: %s - magic %x, "
	ext4_error_inode(function, inode,
			"bad header/extent: %s - magic %x, "
			"entries %u, max %u(%u), depth %u(%u)",
			inode->i_ino, error_msg, le16_to_cpu(eh->eh_magic),
			error_msg, le16_to_cpu(eh->eh_magic),
			le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max),
			max, le16_to_cpu(eh->eh_depth), depth);

@@ -1622,9 +1622,7 @@ int ext4_ext_try_to_merge(struct inode *inode,
		merge_done = 1;
		WARN_ON(eh->eh_entries == 0);
		if (!eh->eh_entries)
			ext4_error(inode->i_sb,
				   "inode#%lu, eh->eh_entries = 0!",
				   inode->i_ino);
			EXT4_ERROR_INODE(inode, "eh->eh_entries = 0!");
	}

	return merge_done;
+38 −45
Original line number Diff line number Diff line
@@ -348,9 +348,8 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
		if (blk &&
		    unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
						    blk, 1))) {
			__ext4_error(inode->i_sb, function,
				   "invalid block reference %u "
				   "in inode #%lu", blk, inode->i_ino);
			ext4_error_inode(function, inode,
					 "invalid block reference %u", blk);
			return -EIO;
		}
	}
@@ -1129,15 +1128,15 @@ void ext4_da_update_reserve_space(struct inode *inode,
		ext4_discard_preallocations(inode);
}

static int check_block_validity(struct inode *inode, const char *msg,
				sector_t logical, sector_t phys, int len)
static int check_block_validity(struct inode *inode, const char *func,
				struct ext4_map_blocks *map)
{
	if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), phys, len)) {
		__ext4_error(inode->i_sb, msg,
			   "inode #%lu logical block %llu mapped to %llu "
			   "(size %d)", inode->i_ino,
			   (unsigned long long) logical,
			   (unsigned long long) phys, len);
	if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk,
				   map->m_len)) {
		ext4_error_inode(func, inode,
			   "lblock %lu mapped to illegal pblock %llu "
			   "(length %d)", (unsigned long) map->m_lblk,
				 map->m_pblk, map->m_len);
		return -EIO;
	}
	return 0;
@@ -1245,8 +1244,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
	up_read((&EXT4_I(inode)->i_data_sem));

	if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
		int ret = check_block_validity(inode, "file system corruption",
					map->m_lblk, map->m_pblk, retval);
		int ret = check_block_validity(inode, __func__, map);
		if (ret != 0)
			return ret;
	}
@@ -1326,10 +1324,9 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,

	up_write((&EXT4_I(inode)->i_data_sem));
	if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
		int ret = check_block_validity(inode, "file system "
					       "corruption after allocation",
					       map->m_lblk, map->m_pblk,
					       retval);
		int ret = check_block_validity(inode,
					       "ext4_map_blocks_after_alloc",
					       map);
		if (ret != 0)
			return ret;
	}
@@ -4327,10 +4324,9 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode,

	if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), block_to_free,
				   count)) {
		ext4_error(inode->i_sb, "inode #%lu: "
			   "attempt to clear blocks %llu len %lu, invalid",
			   inode->i_ino, (unsigned long long) block_to_free,
			   count);
		EXT4_ERROR_INODE(inode, "attempt to clear invalid "
				 "blocks %llu len %lu",
				 (unsigned long long) block_to_free, count);
		return 1;
	}

@@ -4435,10 +4431,9 @@ static void ext4_free_data(handle_t *handle, struct inode *inode,
		if ((EXT4_JOURNAL(inode) == NULL) || bh2jh(this_bh))
			ext4_handle_dirty_metadata(handle, inode, this_bh);
		else
			ext4_error(inode->i_sb,
				   "circular indirect block detected, "
				   "inode=%lu, block=%llu",
				   inode->i_ino,
			EXT4_ERROR_INODE(inode,
					 "circular indirect block detected at "
					 "block %llu",
				(unsigned long long) this_bh->b_blocknr);
	}
}
@@ -4477,11 +4472,10 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,

			if (!ext4_data_block_valid(EXT4_SB(inode->i_sb),
						   nr, 1)) {
				ext4_error(inode->i_sb,
					   "indirect mapped block in inode "
					   "#%lu invalid (level %d, blk #%lu)",
					   inode->i_ino, depth,
					   (unsigned long) nr);
				EXT4_ERROR_INODE(inode,
						 "invalid indirect mapped "
						 "block %lu (level %d)",
						 (unsigned long) nr, depth);
				break;
			}

@@ -4493,9 +4487,9 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
			 * (should be rare).
			 */
			if (!bh) {
				ext4_error(inode->i_sb,
					   "Read failure, inode=%lu, block=%llu",
					   inode->i_ino, nr);
				EXT4_ERROR_INODE(inode,
						 "Read failure block=%llu",
						 (unsigned long long) nr);
				continue;
			}

@@ -4810,8 +4804,8 @@ static int __ext4_get_inode_loc(struct inode *inode,

	bh = sb_getblk(sb, block);
	if (!bh) {
		ext4_error(sb, "unable to read inode block - "
			   "inode=%lu, block=%llu", inode->i_ino, block);
		EXT4_ERROR_INODE(inode, "unable to read inode block - "
				 "block %llu", block);
		return -EIO;
	}
	if (!buffer_uptodate(bh)) {
@@ -4909,8 +4903,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
		submit_bh(READ_META, bh);
		wait_on_buffer(bh);
		if (!buffer_uptodate(bh)) {
			ext4_error(sb, "unable to read inode block - inode=%lu,"
				   " block=%llu", inode->i_ino, block);
			EXT4_ERROR_INODE(inode, "unable to read inode "
					 "block %llu", block);
			brelse(bh);
			return -EIO;
		}
@@ -5121,8 +5115,8 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
	ret = 0;
	if (ei->i_file_acl &&
	    !ext4_data_block_valid(EXT4_SB(sb), ei->i_file_acl, 1)) {
		ext4_error(sb, "bad extended attribute block %llu inode #%lu",
			   ei->i_file_acl, inode->i_ino);
		EXT4_ERROR_INODE(inode, "bad extended attribute block %llu",
				 ei->i_file_acl);
		ret = -EIO;
		goto bad_inode;
	} else if (ei->i_flags & EXT4_EXTENTS_FL) {
@@ -5167,8 +5161,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
			   new_decode_dev(le32_to_cpu(raw_inode->i_block[1])));
	} else {
		ret = -EIO;
		ext4_error(inode->i_sb, "bogus i_mode (%o) for inode=%lu",
			   inode->i_mode, inode->i_ino);
		EXT4_ERROR_INODE(inode, "bogus i_mode (%o)", inode->i_mode);
		goto bad_inode;
	}
	brelse(iloc.bh);
@@ -5406,8 +5399,8 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
		if (wbc->sync_mode == WB_SYNC_ALL)
			sync_dirty_buffer(iloc.bh);
		if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
			ext4_error(inode->i_sb, "IO error syncing inode, "
				   "inode=%lu, block=%llu", inode->i_ino,
			EXT4_ERROR_INODE(inode,
				"IO error syncing inode (block=%llu)",
				(unsigned long long) iloc.bh->b_blocknr);
			err = -EIO;
		}
+4 −4
Original line number Diff line number Diff line
@@ -530,7 +530,7 @@ mext_leaf_block(handle_t *handle, struct inode *orig_inode,
	 * new_ext       |-------|
	 */
	if (le32_to_cpu(oext->ee_block) + oext_alen - 1 < new_ext_end) {
		ext4_error(orig_inode->i_sb,
		EXT4_ERROR_INODE(orig_inode,
			"new_ext_end(%u) should be less than or equal to "
			"oext->ee_block(%u) + oext_alen(%d) - 1",
			new_ext_end, le32_to_cpu(oext->ee_block),
@@ -693,12 +693,12 @@ mext_replace_branches(handle_t *handle, struct inode *orig_inode,
	while (1) {
		/* The extent for donor must be found. */
		if (!dext) {
			ext4_error(donor_inode->i_sb,
			EXT4_ERROR_INODE(donor_inode,
				   "The extent for donor must be found");
			*err = -EIO;
			goto out;
		} else if (donor_off != le32_to_cpu(tmp_dext.ee_block)) {
			ext4_error(donor_inode->i_sb,
			EXT4_ERROR_INODE(donor_inode,
				"Donor offset(%u) and the first block of donor "
				"extent(%u) should be equal",
				donor_off,
@@ -1355,7 +1355,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp,
			if (ret1 < 0)
				break;
			if (*moved_len > len) {
				ext4_error(orig_inode->i_sb,
				EXT4_ERROR_INODE(orig_inode,
					"We replaced blocks too much! "
					"sum of replaced: %llu requested: %llu",
					*moved_len, len);
Loading