aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent_io.c
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2016-09-23 16:44:44 -0400
committerDavid Sterba <dsterba@suse.com>2016-09-26 13:37:06 -0400
commit851cd173f06045816528176001cf82948282029c (patch)
tree280bf393ed2e9f10130fd8eea3bc08e3c601d083 /fs/btrfs/extent_io.c
parent0f5053eb90f58c619885eac2757ccdc5eccd9046 (diff)
Btrfs: memset to avoid stale content in btree leaf
This is an additional patch to "Btrfs: memset to avoid stale content in btree node block". This uses memset to initialize the unused space in a leaf to avoid potential stale content, which may be incurred by pushing items between sibling leaves. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/extent_io.c')
-rw-r--r--fs/btrfs/extent_io.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 0d1876c76732..ee40384c394d 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3725,8 +3725,10 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
3725 struct block_device *bdev = fs_info->fs_devices->latest_bdev; 3725 struct block_device *bdev = fs_info->fs_devices->latest_bdev;
3726 struct extent_io_tree *tree = &BTRFS_I(fs_info->btree_inode)->io_tree; 3726 struct extent_io_tree *tree = &BTRFS_I(fs_info->btree_inode)->io_tree;
3727 u64 offset = eb->start; 3727 u64 offset = eb->start;
3728 u32 nritems;
3728 unsigned long i, num_pages; 3729 unsigned long i, num_pages;
3729 unsigned long bio_flags = 0; 3730 unsigned long bio_flags = 0;
3731 unsigned long start, end;
3730 int write_flags = (epd->sync_io ? WRITE_SYNC : 0) | REQ_META; 3732 int write_flags = (epd->sync_io ? WRITE_SYNC : 0) | REQ_META;
3731 int ret = 0; 3733 int ret = 0;
3732 3734
@@ -3736,15 +3738,21 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
3736 if (btrfs_header_owner(eb) == BTRFS_TREE_LOG_OBJECTID) 3738 if (btrfs_header_owner(eb) == BTRFS_TREE_LOG_OBJECTID)
3737 bio_flags = EXTENT_BIO_TREE_LOG; 3739 bio_flags = EXTENT_BIO_TREE_LOG;
3738 3740
3739 /* set btree node beyond nritems with 0 to avoid stale content */ 3741 /* set btree blocks beyond nritems with 0 to avoid stale content. */
3742 nritems = btrfs_header_nritems(eb);
3740 if (btrfs_header_level(eb) > 0) { 3743 if (btrfs_header_level(eb) > 0) {
3741 u32 nritems;
3742 unsigned long end;
3743
3744 nritems = btrfs_header_nritems(eb);
3745 end = btrfs_node_key_ptr_offset(nritems); 3744 end = btrfs_node_key_ptr_offset(nritems);
3746 3745
3747 memset_extent_buffer(eb, 0, end, eb->len - end); 3746 memset_extent_buffer(eb, 0, end, eb->len - end);
3747 } else {
3748 /*
3749 * leaf:
3750 * header 0 1 2 .. N ... data_N .. data_2 data_1 data_0
3751 */
3752 start = btrfs_item_nr_offset(nritems);
3753 end = btrfs_leaf_data(eb) +
3754 leaf_data_end(fs_info->tree_root, eb);
3755 memset_extent_buffer(eb, 0, start, end - start);
3748 } 3756 }
3749 3757
3750 for (i = 0; i < num_pages; i++) { 3758 for (i = 0; i < num_pages; i++) {