diff options
author | Theodore Ts'o <tytso@mit.edu> | 2011-06-27 19:16:02 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-06-27 19:16:02 -0400 |
commit | 1f7d1e77419050831a905353683807fa69a26625 (patch) | |
tree | 0f32626160b1ecab1e6067ff0e94746c3da068c4 | |
parent | 8bb2b247124ba6093455d4aef26743b1bef27bc5 (diff) |
ext4: move __ext4_check_blockref to block_validity.c
In preparation for moving the indirect functions to a separate file,
move __ext4_check_blockref() to block_validity.c and rename it to
ext4_check_blockref() which is exported as globally visible function.
Also, rename the cpp macro ext4_check_inode_blockref() to
ext4_ind_check_inode(), to make it clear that it is only valid for use
with non-extent mapped inodes.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r-- | fs/ext4/block_validity.c | 20 | ||||
-rw-r--r-- | fs/ext4/ext4.h | 15 | ||||
-rw-r--r-- | fs/ext4/inode.c | 35 |
3 files changed, 36 insertions, 34 deletions
diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c index fac90f3fba80..af103be491b0 100644 --- a/fs/ext4/block_validity.c +++ b/fs/ext4/block_validity.c | |||
@@ -246,3 +246,23 @@ int ext4_data_block_valid(struct ext4_sb_info *sbi, ext4_fsblk_t start_blk, | |||
246 | return 1; | 246 | return 1; |
247 | } | 247 | } |
248 | 248 | ||
249 | int ext4_check_blockref(const char *function, unsigned int line, | ||
250 | struct inode *inode, __le32 *p, unsigned int max) | ||
251 | { | ||
252 | struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; | ||
253 | __le32 *bref = p; | ||
254 | unsigned int blk; | ||
255 | |||
256 | while (bref < p+max) { | ||
257 | blk = le32_to_cpu(*bref++); | ||
258 | if (blk && | ||
259 | unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb), | ||
260 | blk, 1))) { | ||
261 | es->s_last_error_block = cpu_to_le64(blk); | ||
262 | ext4_error_inode(inode, function, line, blk, | ||
263 | "invalid block"); | ||
264 | return -EIO; | ||
265 | } | ||
266 | } | ||
267 | return 0; | ||
268 | } | ||
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 8532dd43d320..82ba7eb7c4a5 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -2125,6 +2125,19 @@ static inline void ext4_mark_super_dirty(struct super_block *sb) | |||
2125 | } | 2125 | } |
2126 | 2126 | ||
2127 | /* | 2127 | /* |
2128 | * Block validity checking | ||
2129 | */ | ||
2130 | #define ext4_check_indirect_blockref(inode, bh) \ | ||
2131 | ext4_check_blockref(__func__, __LINE__, inode, \ | ||
2132 | (__le32 *)(bh)->b_data, \ | ||
2133 | EXT4_ADDR_PER_BLOCK((inode)->i_sb)) | ||
2134 | |||
2135 | #define ext4_ind_check_inode(inode) \ | ||
2136 | ext4_check_blockref(__func__, __LINE__, inode, \ | ||
2137 | EXT4_I(inode)->i_data, \ | ||
2138 | EXT4_NDIR_BLOCKS) | ||
2139 | |||
2140 | /* | ||
2128 | * Inodes and files operations | 2141 | * Inodes and files operations |
2129 | */ | 2142 | */ |
2130 | 2143 | ||
@@ -2153,6 +2166,8 @@ extern void ext4_exit_system_zone(void); | |||
2153 | extern int ext4_data_block_valid(struct ext4_sb_info *sbi, | 2166 | extern int ext4_data_block_valid(struct ext4_sb_info *sbi, |
2154 | ext4_fsblk_t start_blk, | 2167 | ext4_fsblk_t start_blk, |
2155 | unsigned int count); | 2168 | unsigned int count); |
2169 | extern int ext4_check_blockref(const char *, unsigned int, | ||
2170 | struct inode *, __le32 *, unsigned int); | ||
2156 | 2171 | ||
2157 | /* extents.c */ | 2172 | /* extents.c */ |
2158 | extern int ext4_ext_tree_init(handle_t *handle, struct inode *); | 2173 | extern int ext4_ext_tree_init(handle_t *handle, struct inode *); |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 6c1d28e37235..3dca5264ccff 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -360,39 +360,6 @@ static int ext4_block_to_path(struct inode *inode, | |||
360 | return n; | 360 | return n; |
361 | } | 361 | } |
362 | 362 | ||
363 | static int __ext4_check_blockref(const char *function, unsigned int line, | ||
364 | struct inode *inode, | ||
365 | __le32 *p, unsigned int max) | ||
366 | { | ||
367 | struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; | ||
368 | __le32 *bref = p; | ||
369 | unsigned int blk; | ||
370 | |||
371 | while (bref < p+max) { | ||
372 | blk = le32_to_cpu(*bref++); | ||
373 | if (blk && | ||
374 | unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb), | ||
375 | blk, 1))) { | ||
376 | es->s_last_error_block = cpu_to_le64(blk); | ||
377 | ext4_error_inode(inode, function, line, blk, | ||
378 | "invalid block"); | ||
379 | return -EIO; | ||
380 | } | ||
381 | } | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | |||
386 | #define ext4_check_indirect_blockref(inode, bh) \ | ||
387 | __ext4_check_blockref(__func__, __LINE__, inode, \ | ||
388 | (__le32 *)(bh)->b_data, \ | ||
389 | EXT4_ADDR_PER_BLOCK((inode)->i_sb)) | ||
390 | |||
391 | #define ext4_check_inode_blockref(inode) \ | ||
392 | __ext4_check_blockref(__func__, __LINE__, inode, \ | ||
393 | EXT4_I(inode)->i_data, \ | ||
394 | EXT4_NDIR_BLOCKS) | ||
395 | |||
396 | /** | 363 | /** |
397 | * ext4_get_branch - read the chain of indirect blocks leading to data | 364 | * ext4_get_branch - read the chain of indirect blocks leading to data |
398 | * @inode: inode in question | 365 | * @inode: inode in question |
@@ -5010,7 +4977,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
5010 | (S_ISLNK(inode->i_mode) && | 4977 | (S_ISLNK(inode->i_mode) && |
5011 | !ext4_inode_is_fast_symlink(inode))) { | 4978 | !ext4_inode_is_fast_symlink(inode))) { |
5012 | /* Validate block references which are part of inode */ | 4979 | /* Validate block references which are part of inode */ |
5013 | ret = ext4_check_inode_blockref(inode); | 4980 | ret = ext4_ind_check_inode(inode); |
5014 | } | 4981 | } |
5015 | if (ret) | 4982 | if (ret) |
5016 | goto bad_inode; | 4983 | goto bad_inode; |