aboutsummaryrefslogtreecommitdiffstats
path: root/fs
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
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')
-rw-r--r--fs/btrfs/extent-tree.c9
-rw-r--r--fs/btrfs/extent_io.c8
-rw-r--r--fs/btrfs/file.c3
-rw-r--r--fs/btrfs/inode.c37
-rw-r--r--fs/btrfs/tree-log.c3
-rw-r--r--fs/btrfs/volumes.c3
6 files changed, 25 insertions, 38 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 8520354f086e..5681a91ed400 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3431,7 +3431,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes)
3431 int ret = 0, committed = 0, alloc_chunk = 1; 3431 int ret = 0, committed = 0, alloc_chunk = 1;
3432 3432
3433 /* make sure bytes are sectorsize aligned */ 3433 /* make sure bytes are sectorsize aligned */
3434 bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1); 3434 bytes = ALIGN(bytes, root->sectorsize);
3435 3435
3436 if (root == root->fs_info->tree_root || 3436 if (root == root->fs_info->tree_root ||
3437 BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) { 3437 BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) {
@@ -3526,7 +3526,7 @@ void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes)
3526 struct btrfs_space_info *data_sinfo; 3526 struct btrfs_space_info *data_sinfo;
3527 3527
3528 /* make sure bytes are sectorsize aligned */ 3528 /* make sure bytes are sectorsize aligned */
3529 bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1); 3529 bytes = ALIGN(bytes, root->sectorsize);
3530 3530
3531 data_sinfo = root->fs_info->data_sinfo; 3531 data_sinfo = root->fs_info->data_sinfo;
3532 spin_lock(&data_sinfo->lock); 3532 spin_lock(&data_sinfo->lock);
@@ -5607,10 +5607,7 @@ static u64 stripe_align(struct btrfs_root *root,
5607 struct btrfs_block_group_cache *cache, 5607 struct btrfs_block_group_cache *cache,
5608 u64 val, u64 num_bytes) 5608 u64 val, u64 num_bytes)
5609{ 5609{
5610 u64 mask; 5610 u64 ret = ALIGN(val, root->stripesize);
5611 u64 ret;
5612 mask = ((u64)root->stripesize - 1);
5613 ret = (val + mask) & ~mask;
5614 return ret; 5611 return ret;
5615} 5612}
5616 5613
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 66f999b97cbb..597ab8966c80 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2686,7 +2686,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree,
2686 2686
2687 iosize = min(extent_map_end(em) - cur, end - cur + 1); 2687 iosize = min(extent_map_end(em) - cur, end - cur + 1);
2688 cur_end = min(extent_map_end(em) - 1, end); 2688 cur_end = min(extent_map_end(em) - 1, end);
2689 iosize = (iosize + blocksize - 1) & ~((u64)blocksize - 1); 2689 iosize = ALIGN(iosize, blocksize);
2690 if (this_bio_flag & EXTENT_BIO_COMPRESSED) { 2690 if (this_bio_flag & EXTENT_BIO_COMPRESSED) {
2691 disk_io_size = em->block_len; 2691 disk_io_size = em->block_len;
2692 sector = em->block_start >> 9; 2692 sector = em->block_start >> 9;
@@ -2977,7 +2977,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,
2977 BUG_ON(extent_map_end(em) <= cur); 2977 BUG_ON(extent_map_end(em) <= cur);
2978 BUG_ON(end < cur); 2978 BUG_ON(end < cur);
2979 iosize = min(extent_map_end(em) - cur, end - cur + 1); 2979 iosize = min(extent_map_end(em) - cur, end - cur + 1);
2980 iosize = (iosize + blocksize - 1) & ~((u64)blocksize - 1); 2980 iosize = ALIGN(iosize, blocksize);
2981 sector = (em->block_start + extent_offset) >> 9; 2981 sector = (em->block_start + extent_offset) >> 9;
2982 bdev = em->bdev; 2982 bdev = em->bdev;
2983 block_start = em->block_start; 2983 block_start = em->block_start;
@@ -3664,7 +3664,7 @@ int extent_invalidatepage(struct extent_io_tree *tree,
3664 u64 end = start + PAGE_CACHE_SIZE - 1; 3664 u64 end = start + PAGE_CACHE_SIZE - 1;
3665 size_t blocksize = page->mapping->host->i_sb->s_blocksize; 3665 size_t blocksize = page->mapping->host->i_sb->s_blocksize;
3666 3666
3667 start += (offset + blocksize - 1) & ~(blocksize - 1); 3667 start += ALIGN(offset, blocksize);
3668 if (start > end) 3668 if (start > end)
3669 return 0; 3669 return 0;
3670 3670
@@ -3783,7 +3783,7 @@ static struct extent_map *get_extent_skip_holes(struct inode *inode,
3783 len = last - offset; 3783 len = last - offset;
3784 if (len == 0) 3784 if (len == 0)
3785 break; 3785 break;
3786 len = (len + sectorsize - 1) & ~(sectorsize - 1); 3786 len = ALIGN(len, sectorsize);
3787 em = get_extent(inode, NULL, 0, offset, len, 0); 3787 em = get_extent(inode, NULL, 0, offset, len, 0);
3788 if (IS_ERR_OR_NULL(em)) 3788 if (IS_ERR_OR_NULL(em))
3789 return em; 3789 return em;
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 6e6dd8cdad92..83c790d84038 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -510,8 +510,7 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
510 loff_t isize = i_size_read(inode); 510 loff_t isize = i_size_read(inode);
511 511
512 start_pos = pos & ~((u64)root->sectorsize - 1); 512 start_pos = pos & ~((u64)root->sectorsize - 1);
513 num_bytes = (write_bytes + pos - start_pos + 513 num_bytes = ALIGN(write_bytes + pos - start_pos, root->sectorsize);
514 root->sectorsize - 1) & ~((u64)root->sectorsize - 1);
515 514
516 end_of_last_block = start_pos + num_bytes - 1; 515 end_of_last_block = start_pos + num_bytes - 1;
517 err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, 516 err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block,
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) {
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 1a79087c4575..e8b7a68e1b37 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -484,7 +484,6 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
484 struct btrfs_key *key) 484 struct btrfs_key *key)
485{ 485{
486 int found_type; 486 int found_type;
487 u64 mask = root->sectorsize - 1;
488 u64 extent_end; 487 u64 extent_end;
489 u64 start = key->offset; 488 u64 start = key->offset;
490 u64 saved_nbytes; 489 u64 saved_nbytes;
@@ -501,7 +500,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
501 extent_end = start + btrfs_file_extent_num_bytes(eb, item); 500 extent_end = start + btrfs_file_extent_num_bytes(eb, item);
502 else if (found_type == BTRFS_FILE_EXTENT_INLINE) { 501 else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
503 size = btrfs_file_extent_inline_len(eb, item); 502 size = btrfs_file_extent_inline_len(eb, item);
504 extent_end = (start + size + mask) & ~mask; 503 extent_end = ALIGN(start + size, root->sectorsize);
505 } else { 504 } else {
506 ret = 0; 505 ret = 0;
507 goto out; 506 goto out;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 538c5cfa005f..db72e0cc6f87 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4556,8 +4556,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
4556 num_stripes = 1; 4556 num_stripes = 1;
4557 stripe_index = 0; 4557 stripe_index = 0;
4558 stripe_nr_orig = stripe_nr; 4558 stripe_nr_orig = stripe_nr;
4559 stripe_nr_end = (offset + *length + map->stripe_len - 1) & 4559 stripe_nr_end = ALIGN(offset + *length, map->stripe_len);
4560 (~(map->stripe_len - 1));
4561 do_div(stripe_nr_end, map->stripe_len); 4560 do_div(stripe_nr_end, map->stripe_len);
4562 stripe_end_offset = stripe_nr_end * map->stripe_len - 4561 stripe_end_offset = stripe_nr_end * map->stripe_len -
4563 (offset + *length); 4562 (offset + *length);