aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2013-02-26 03:10:22 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-26 11:04:13 -0500
commitfda2832febb1928da0625b2c5d15559b29d7e740 (patch)
treedac83eff57b657dfc04ba72fa7bcce4b4674b810 /fs/btrfs/inode.c
parent8c4ce81e911ab6c84e4f75e18d4ceb3fa555c35b (diff)
btrfs: cleanup for open-coded alignment
Though most of the btrfs codes are using ALIGN macro for page alignment, there are still some codes using open-coded alignment like the following: ------ u64 mask = ((u64)root->stripesize - 1); u64 ret = (val + mask) & ~mask; ------ Or even hidden one: ------ num_bytes = (end - start + blocksize) & ~(blocksize - 1); ------ Sometimes these open-coded alignment is not so easy to understand for newbie like me. This commit changes the open-coded alignment to the ALIGN macro for a better readability. Also there is a previous patch from David Sterba with similar changes, but the patch is for 3.2 kernel and seems not merged. http://www.spinics.net/lists/linux-btrfs/msg12747.html Cc: David Sterba <dave@jikos.cz> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index be09654e11b9..9ef7a5b1b77e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -233,8 +233,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,
233 u64 isize = i_size_read(inode); 233 u64 isize = i_size_read(inode);
234 u64 actual_end = min(end + 1, isize); 234 u64 actual_end = min(end + 1, isize);
235 u64 inline_len = actual_end - start; 235 u64 inline_len = actual_end - start;
236 u64 aligned_end = (end + root->sectorsize - 1) & 236 u64 aligned_end = ALIGN(end, root->sectorsize);
237 ~((u64)root->sectorsize - 1);
238 u64 data_len = inline_len; 237 u64 data_len = inline_len;
239 int ret; 238 int ret;
240 239
@@ -391,7 +390,7 @@ again:
391 * a compressed extent to 128k. 390 * a compressed extent to 128k.
392 */ 391 */
393 total_compressed = min(total_compressed, max_uncompressed); 392 total_compressed = min(total_compressed, max_uncompressed);
394 num_bytes = (end - start + blocksize) & ~(blocksize - 1); 393 num_bytes = ALIGN(end - start + 1, blocksize);
395 num_bytes = max(blocksize, num_bytes); 394 num_bytes = max(blocksize, num_bytes);
396 total_in = 0; 395 total_in = 0;
397 ret = 0; 396 ret = 0;
@@ -490,15 +489,13 @@ cont:
490 * up to a block size boundary so the allocator does sane 489 * up to a block size boundary so the allocator does sane
491 * things 490 * things
492 */ 491 */
493 total_compressed = (total_compressed + blocksize - 1) & 492 total_compressed = ALIGN(total_compressed, blocksize);
494 ~(blocksize - 1);
495 493
496 /* 494 /*
497 * one last check to make sure the compression is really a 495 * one last check to make sure the compression is really a
498 * win, compare the page count read with the blocks on disk 496 * win, compare the page count read with the blocks on disk
499 */ 497 */
500 total_in = (total_in + PAGE_CACHE_SIZE - 1) & 498 total_in = ALIGN(total_in, PAGE_CACHE_SIZE);
501 ~(PAGE_CACHE_SIZE - 1);
502 if (total_compressed >= total_in) { 499 if (total_compressed >= total_in) {
503 will_compress = 0; 500 will_compress = 0;
504 } else { 501 } else {
@@ -856,7 +853,7 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans,
856 853
857 BUG_ON(btrfs_is_free_space_inode(inode)); 854 BUG_ON(btrfs_is_free_space_inode(inode));
858 855
859 num_bytes = (end - start + blocksize) & ~(blocksize - 1); 856 num_bytes = ALIGN(end - start + 1, blocksize);
860 num_bytes = max(blocksize, num_bytes); 857 num_bytes = max(blocksize, num_bytes);
861 disk_num_bytes = num_bytes; 858 disk_num_bytes = num_bytes;
862 859
@@ -4015,7 +4012,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
4015 u64 extent_num_bytes = 0; 4012 u64 extent_num_bytes = 0;
4016 u64 extent_offset = 0; 4013 u64 extent_offset = 0;
4017 u64 item_end = 0; 4014 u64 item_end = 0;
4018 u64 mask = root->sectorsize - 1;
4019 u32 found_type = (u8)-1; 4015 u32 found_type = (u8)-1;
4020 int found_extent; 4016 int found_extent;
4021 int del_item; 4017 int del_item;
@@ -4039,7 +4035,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
4039 * extent just the way it is. 4035 * extent just the way it is.
4040 */ 4036 */
4041 if (root->ref_cows || root == root->fs_info->tree_root) 4037 if (root->ref_cows || root == root->fs_info->tree_root)
4042 btrfs_drop_extent_cache(inode, (new_size + mask) & (~mask), (u64)-1, 0); 4038 btrfs_drop_extent_cache(inode, ALIGN(new_size,
4039 root->sectorsize), (u64)-1, 0);
4043 4040
4044 /* 4041 /*
4045 * This function is also used to drop the items in the log tree before 4042 * This function is also used to drop the items in the log tree before
@@ -4118,10 +4115,9 @@ search_again:
4118 if (!del_item) { 4115 if (!del_item) {
4119 u64 orig_num_bytes = 4116 u64 orig_num_bytes =
4120 btrfs_file_extent_num_bytes(leaf, fi); 4117 btrfs_file_extent_num_bytes(leaf, fi);
4121 extent_num_bytes = new_size - 4118 extent_num_bytes = ALIGN(new_size -
4122 found_key.offset + root->sectorsize - 1; 4119 found_key.offset,
4123 extent_num_bytes = extent_num_bytes & 4120 root->sectorsize);
4124 ~((u64)root->sectorsize - 1);
4125 btrfs_set_file_extent_num_bytes(leaf, fi, 4121 btrfs_set_file_extent_num_bytes(leaf, fi,
4126 extent_num_bytes); 4122 extent_num_bytes);
4127 num_dec = (orig_num_bytes - 4123 num_dec = (orig_num_bytes -
@@ -4357,9 +4353,8 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
4357 struct extent_map *em = NULL; 4353 struct extent_map *em = NULL;
4358 struct extent_state *cached_state = NULL; 4354 struct extent_state *cached_state = NULL;
4359 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 4355 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
4360 u64 mask = root->sectorsize - 1; 4356 u64 hole_start = ALIGN(oldsize, root->sectorsize);
4361 u64 hole_start = (oldsize + mask) & ~mask; 4357 u64 block_end = ALIGN(size, root->sectorsize);
4362 u64 block_end = (size + mask) & ~mask;
4363 u64 last_byte; 4358 u64 last_byte;
4364 u64 cur_offset; 4359 u64 cur_offset;
4365 u64 hole_size; 4360 u64 hole_size;
@@ -4392,7 +4387,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
4392 break; 4387 break;
4393 } 4388 }
4394 last_byte = min(extent_map_end(em), block_end); 4389 last_byte = min(extent_map_end(em), block_end);
4395 last_byte = (last_byte + mask) & ~mask; 4390 last_byte = ALIGN(last_byte , root->sectorsize);
4396 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { 4391 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) {
4397 struct extent_map *hole_em; 4392 struct extent_map *hole_em;
4398 hole_size = last_byte - cur_offset; 4393 hole_size = last_byte - cur_offset;
@@ -6111,8 +6106,7 @@ again:
6111 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { 6106 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
6112 size_t size; 6107 size_t size;
6113 size = btrfs_file_extent_inline_len(leaf, item); 6108 size = btrfs_file_extent_inline_len(leaf, item);
6114 extent_end = (extent_start + size + root->sectorsize - 1) & 6109 extent_end = ALIGN(extent_start + size, root->sectorsize);
6115 ~((u64)root->sectorsize - 1);
6116 } 6110 }
6117 6111
6118 if (start >= extent_end) { 6112 if (start >= extent_end) {
@@ -6184,8 +6178,7 @@ again:
6184 copy_size = min_t(u64, PAGE_CACHE_SIZE - pg_offset, 6178 copy_size = min_t(u64, PAGE_CACHE_SIZE - pg_offset,
6185 size - extent_offset); 6179 size - extent_offset);
6186 em->start = extent_start + extent_offset; 6180 em->start = extent_start + extent_offset;
6187 em->len = (copy_size + root->sectorsize - 1) & 6181 em->len = ALIGN(copy_size, root->sectorsize);
6188 ~((u64)root->sectorsize - 1);
6189 em->orig_block_len = em->len; 6182 em->orig_block_len = em->len;
6190 em->orig_start = em->start; 6183 em->orig_start = em->start;
6191 if (compress_type) { 6184 if (compress_type) {