diff options
| author | Zheng Liu <wenqing.lz@taobao.com> | 2013-07-29 12:51:42 -0400 |
|---|---|---|
| committer | Theodore Ts'o <tytso@mit.edu> | 2013-07-29 12:51:42 -0400 |
| commit | 44fb851dfb2f8e3462617e19a7b3b9025db9d919 (patch) | |
| tree | 163882d4f6c13c064ad522127990e5eab23d8d94 | |
| parent | 94eec0fc3520c759831763d866421b4d60b599b4 (diff) | |
ext4: add WARN_ON to check the length of allocated blocks
In commit 921f266b: ext4: add self-testing infrastructure to do a
sanity check, some sanity checks were added in map_blocks to make sure
'retval == map->m_len'.
Enable these checks by default and report any assertion failures using
ext4_warning() and WARN_ON() since they can help us to figure out some
bugs that are otherwise hard to hit.
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
| -rw-r--r-- | fs/ext4/inode.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index ba33c67d6e48..dd32a2eacd0d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
| @@ -555,14 +555,13 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, | |||
| 555 | int ret; | 555 | int ret; |
| 556 | unsigned long long status; | 556 | unsigned long long status; |
| 557 | 557 | ||
| 558 | #ifdef ES_AGGRESSIVE_TEST | 558 | if (unlikely(retval != map->m_len)) { |
| 559 | if (retval != map->m_len) { | 559 | ext4_warning(inode->i_sb, |
| 560 | printk("ES len assertion failed for inode: %lu " | 560 | "ES len assertion failed for inode " |
| 561 | "retval %d != map->m_len %d " | 561 | "%lu: retval %d != map->m_len %d", |
| 562 | "in %s (lookup)\n", inode->i_ino, retval, | 562 | inode->i_ino, retval, map->m_len); |
| 563 | map->m_len, __func__); | 563 | WARN_ON(1); |
| 564 | } | 564 | } |
| 565 | #endif | ||
| 566 | 565 | ||
| 567 | status = map->m_flags & EXT4_MAP_UNWRITTEN ? | 566 | status = map->m_flags & EXT4_MAP_UNWRITTEN ? |
| 568 | EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; | 567 | EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; |
| @@ -656,14 +655,13 @@ found: | |||
| 656 | int ret; | 655 | int ret; |
| 657 | unsigned long long status; | 656 | unsigned long long status; |
| 658 | 657 | ||
| 659 | #ifdef ES_AGGRESSIVE_TEST | 658 | if (unlikely(retval != map->m_len)) { |
| 660 | if (retval != map->m_len) { | 659 | ext4_warning(inode->i_sb, |
| 661 | printk("ES len assertion failed for inode: %lu " | 660 | "ES len assertion failed for inode " |
| 662 | "retval %d != map->m_len %d " | 661 | "%lu: retval %d != map->m_len %d", |
| 663 | "in %s (allocation)\n", inode->i_ino, retval, | 662 | inode->i_ino, retval, map->m_len); |
| 664 | map->m_len, __func__); | 663 | WARN_ON(1); |
| 665 | } | 664 | } |
| 666 | #endif | ||
| 667 | 665 | ||
| 668 | /* | 666 | /* |
| 669 | * If the extent has been zeroed out, we don't need to update | 667 | * If the extent has been zeroed out, we don't need to update |
| @@ -1637,14 +1635,13 @@ add_delayed: | |||
| 1637 | int ret; | 1635 | int ret; |
| 1638 | unsigned long long status; | 1636 | unsigned long long status; |
| 1639 | 1637 | ||
| 1640 | #ifdef ES_AGGRESSIVE_TEST | 1638 | if (unlikely(retval != map->m_len)) { |
| 1641 | if (retval != map->m_len) { | 1639 | ext4_warning(inode->i_sb, |
| 1642 | printk("ES len assertion failed for inode: %lu " | 1640 | "ES len assertion failed for inode " |
| 1643 | "retval %d != map->m_len %d " | 1641 | "%lu: retval %d != map->m_len %d", |
| 1644 | "in %s (lookup)\n", inode->i_ino, retval, | 1642 | inode->i_ino, retval, map->m_len); |
| 1645 | map->m_len, __func__); | 1643 | WARN_ON(1); |
| 1646 | } | 1644 | } |
| 1647 | #endif | ||
| 1648 | 1645 | ||
| 1649 | status = map->m_flags & EXT4_MAP_UNWRITTEN ? | 1646 | status = map->m_flags & EXT4_MAP_UNWRITTEN ? |
| 1650 | EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; | 1647 | EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; |
