Cleanups for 3.2
Hi,
I'm sending a short series containg some rather simple cleanups which I came accross while going through code (like opencoded macros which hide semantics). As they could clash with other patches being merged I generated them. I would like to see them merged of course, but do not want to make merging harder and I can regenerate them any time when the main features/fixes are integrated.
I've added one patch which is not new but has not been merged yet. It separates the super_block items from fs_info structure. New features add more items to fs_info and this patch will make some space.
You can pull this series from
git://repo.or.cz/linux-2.6/btrfs-unstable.git cleanups-for-3.2
thanks,
david
---
David Sterba (8):
btrfs: separate superblock items out of fs_info
btrfs: fix misleading variable name for flags
btrfs: use unsigned long type for extent state bits
btrfs: no need to mask out GFP_HIGHMEM in radix preload
btrfs: kill key type helpers
btrfs: use ALIGN instead of open-coded variants
btrfs: use DIV_ROUND_UP instead of open-coded variants
btrfs: cleanup: use BUG_ON when appropriate
fs/btrfs/compression.c | 12 ++++---- fs/btrfs/ctree.c | 8 ++--- fs/btrfs/ctree.h | 23 ++++++---------- fs/btrfs/delayed-inode.c | 8 +++--- fs/btrfs/dir-item.c | 10 +++--- fs/btrfs/disk-io.c | 23 ++++++++-------- fs/btrfs/export.c | 4 +- fs/btrfs/extent-tree.c | 53 ++++++++++++++++---------------------- fs/btrfs/extent_io.c | 59 ++++++++++++++++++++++-------------------- fs/btrfs/extent_io.h | 33 ++++++++++++++---------- fs/btrfs/file-item.c | 29 ++++++++------------ fs/btrfs/file.c | 21 ++++++-------- fs/btrfs/free-space-cache.c | 3 +- fs/btrfs/inode-item.c | 10 +++--- fs/btrfs/inode.c | 56 +++++++++++++++++++---------------------- fs/btrfs/ioctl.c | 14 +++++----- fs/btrfs/lzo.c | 3 +- fs/btrfs/ordered-data.h | 3 +- fs/btrfs/orphan.c | 4 +- fs/btrfs/print-tree.c | 10 ++----- fs/btrfs/root-tree.c | 4 +- fs/btrfs/scrub.c | 6 ++-- fs/btrfs/super.c | 17 ++++++++--- fs/btrfs/transaction.c | 10 +++--- fs/btrfs/tree-log.c | 10 +++--- fs/btrfs/volumes.c | 35 ++++++++++++------------- fs/btrfs/xattr.c | 4 +- fs/btrfs/zlib.c | 3 +- 28 files changed, 227 insertions(+), 248 deletions(-)
Signature · 1 line
1.7.6
PATCH 1/8 btrfs: separate superblock items out of fs_info
fs_info has now ~9kb, more than fits into one page. This will cause mount failure when memory is too fragmented. Top space consumers are super block structures super_copy and super_for_commit, ~2.8kb each. Allocate them dynamically. fs_info will be ~3.5kb. (measured on x86_64)
Add a wrapper for freeing fs_info.
--- fs/btrfs/compression.c | 3 ++- fs/btrfs/ctree.h | 10 ++++++++-- fs/btrfs/disk-io.c | 21 ++++++++++----------- fs/btrfs/extent-tree.c | 18 +++++++++--------- fs/btrfs/file-item.c | 17 ++++++----------- fs/btrfs/inode.c | 2 +- fs/btrfs/ioctl.c | 6 +++--- fs/btrfs/scrub.c | 2 +- fs/btrfs/super.c | 17 ++++++++++++----- fs/btrfs/transaction.c | 10 +++++----- fs/btrfs/tree-log.c | 4 ++-- fs/btrfs/volumes.c | 24 ++++++++++++------------ 12 files changed, 71 insertions(+), 63 deletions(-)
fs/btrfs/compression.c +2 -1
@@ -85,7 +85,8 @@ struct compressed_bio {static inline int compressed_bio_size (struct btrfs_root *root,unsigned long disk_size) { -u16 csum_size =btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy); +return sizeof (struct compressed_bio ) + ((disk_size + root->sectorsize -1 ) / root->sectorsize) * csum_size;
fs/btrfs/ctree.h +8 -2
@@ -935,8 +935,8 @@ struct btrfs_fs_info {wait_queue_head_t transaction_blocked_wait;wait_queue_head_t async_submit_wait; -struct btrfs_super_block super_copy; -struct btrfs_super_block super_for_commit; +struct btrfs_super_block *super_copy; +struct btrfs_super_block *super_for_commit;struct block_device *__bdev;struct super_block *sb;struct inode *btree_inode;
@@ -2379,6 +2379,12 @@ static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)smp_mb ();return fs_info->closing; } +static inline void free_fs_info (struct btrfs_fs_info *fs_info) +{ +kfree (fs_info->super_copy); +kfree (fs_info->super_for_commit); +kfree (fs_info); +}/* root-item.c */ int btrfs_find_root_ref(struct btrfs_root *tree_root,
fs/btrfs/disk-io.c +10 -11
@@ -256,8 +256,7 @@ void btrfs_csum_final(u32 crc, char *result)static int csum_tree_block (struct btrfs_root *root,struct extent_buffer *buf,int verify) { -u16 csum_size = -btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy);char *result =NULL ;unsigned long len;unsigned long cur_len;
@@ -1766,14 +1765,14 @@ struct btrfs_root *open_ctree(struct super_block *sb, goto fail_alloc; } -memcpy (&fs_info->super_copy, bh->b_data,sizeof (fs_info->super_copy)); -memcpy (&fs_info->super_for_commit, &fs_info->super_copy, -sizeof (fs_info->super_for_commit)); +memcpy (fs_info->super_copy, bh->b_data,sizeof (*fs_info->super_copy)); +memcpy (fs_info->super_for_commit, fs_info->super_copy, +sizeof (*fs_info->super_for_commit));brelse (bh); -memcpy (fs_info->fsid, fs_info->super_copy.fsid,BTRFS_FSID_SIZE ); +memcpy (fs_info->fsid, fs_info->super_copy->fsid,BTRFS_FSID_SIZE ); - disk_super = &fs_info->super_copy; + disk_super = fs_info->super_copy;if (!btrfs_super_root (disk_super)) goto fail_alloc;
@@ -2166,10 +2165,10 @@ fail_srcu: fail:kfree (extent_root);kfree (tree_root); -kfree (fs_info);kfree (chunk_root);kfree (dev_root);kfree (csum_root); +free_fs_info (fs_info);return ERR_PTR (err); }
@@ -2338,10 +2337,10 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)int total_errors =0 ;u64 flags; - max_errors =btrfs_super_num_devices (&root->fs_info->super_copy) -1 ; + max_errors =btrfs_super_num_devices (root->fs_info->super_copy) -1 ; do_barriers = !btrfs_test_opt (root,NOBARRIER ); - sb = &root->fs_info->super_for_commit; + sb = root->fs_info->super_for_commit; dev_item = &sb->dev_item;mutex_lock (&root->fs_info->fs_devices->device_list_mutex);
@@ -2629,7 +2628,7 @@ int close_ctree(struct btrfs_root *root)kfree (fs_info->chunk_root);kfree (fs_info->dev_root);kfree (fs_info->csum_root); -kfree (fs_info); +free_fs_info (fs_info);return 0 ; }
fs/btrfs/extent-tree.c +9 -9
@@ -3201,7 +3201,7 @@ static int should_alloc_chunk(struct btrfs_root *root,* about 1% of the FS size. */ if (force ==CHUNK_ALLOC_LIMITED ) { - thresh =btrfs_super_total_bytes (&root->fs_info->super_copy); + thresh =btrfs_super_total_bytes (root->fs_info->super_copy); thresh =max_t (u64,64 *1024 *1024 ,div_factor_fine (thresh,1 ));
@@ -3223,7 +3223,7 @@ static int should_alloc_chunk(struct btrfs_root *root,if (num_allocated + alloc_bytes <div_factor (num_bytes,8 ))return 0 ; - thresh =btrfs_super_total_bytes (&root->fs_info->super_copy); + thresh =btrfs_super_total_bytes (root->fs_info->super_copy);/* 256MB or 5% of the FS */ thresh =max_t (u64,256 *1024 *1024 ,div_factor_fine (thresh,5 ));
@@ -3808,7 +3808,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)u64 num_bytes;u64 meta_used;u64 data_used; -int csum_size =btrfs_super_csum_size (&fs_info->super_copy); +int csum_size =btrfs_super_csum_size (fs_info->super_copy); sinfo =__find_space_info (fs_info,BTRFS_BLOCK_GROUP_DATA );spin_lock (&sinfo->lock);
@@ -4190,12 +4190,12 @@ static int update_block_group(struct btrfs_trans_handle *trans,/* block accounting for super block */ spin_lock (&info->delalloc_lock); - old_val =btrfs_super_bytes_used (&info->super_copy); + old_val =btrfs_super_bytes_used (info->super_copy);if (alloc) old_val += num_bytes;else old_val -= num_bytes; -btrfs_set_super_bytes_used (&info->super_copy, old_val); +btrfs_set_super_bytes_used (info->super_copy, old_val);spin_unlock (&info->delalloc_lock);while (total) {
@@ -4223,7 +4223,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,spin_lock (&cache->space_info->lock);spin_lock (&cache->lock); -if (btrfs_super_cache_generation (&info->super_copy) !=0 && +if (btrfs_super_cache_generation (info->super_copy) !=0 && cache->disk_cache_state <BTRFS_DC_CLEAR ) cache->disk_cache_state =BTRFS_DC_CLEAR ;
@@ -7037,9 +7037,9 @@ int btrfs_read_block_groups(struct btrfs_root *root)return -ENOMEM ; path->reada =1 ; - cache_gen =btrfs_super_cache_generation (&root->fs_info->super_copy); + cache_gen =btrfs_super_cache_generation (root->fs_info->super_copy);if (cache_gen !=0 && -btrfs_super_generation (&root->fs_info->super_copy) != cache_gen) +btrfs_super_generation (root->fs_info->super_copy) != cache_gen) need_clear =1 ;if (btrfs_test_opt (root,CLEAR_CACHE )) need_clear =1 ;
@@ -7370,7 +7370,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)int mixed =0 ;int ret; - disk_super = &fs_info->super_copy; + disk_super = fs_info->super_copy;if (!btrfs_super_root (disk_super))return 1 ;
fs/btrfs/file-item.c +6 -11
@@ -91,8 +91,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,struct btrfs_csum_item *item;struct extent_buffer *leaf;u64 csum_offset =0 ; -u16 csum_size = -btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy);int csums_in_item; file_key.objectid =BTRFS_EXTENT_CSUM_OBJECTID ;
@@ -162,8 +161,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,u64 item_last_offset =0 ;u64 disk_bytenr;u32 diff; -u16 csum_size = -btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy);int ret;struct btrfs_path *path;struct btrfs_csum_item *item =NULL ;
@@ -290,7 +288,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,int ret;size_t size;u64 csum_end; -u16 csum_size =btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy); path =btrfs_alloc_path ();if (!path)
@@ -492,8 +490,7 @@ static noinline int truncate_one_csum(struct btrfs_trans_handle *trans, u64 bytenr, u64 len) {struct extent_buffer *leaf; -u16 csum_size = -btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy);u64 csum_end;u64 end_byte = bytenr + len;u32 blocksize_bits = root->fs_info->sb->s_blocksize_bits;
@@ -549,8 +546,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,u64 csum_end;struct extent_buffer *leaf;int ret; -u16 csum_size = -btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy);int blocksize_bits = root->fs_info->sb->s_blocksize_bits; root = root->fs_info->csum_root;
@@ -676,8 +672,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,struct btrfs_sector_sum *sector_sum;u32 nritems;u32 ins_size; -u16 csum_size = -btrfs_super_csum_size (&root->fs_info->super_copy); +u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy); path =btrfs_alloc_path ();if (!path)
fs/btrfs/inode.c +1 -1
@@ -820,7 +820,7 @@ static noinline int cow_file_range(struct inode *inode, }BUG_ON (disk_num_bytes > -btrfs_super_total_bytes (&root->fs_info->super_copy)); +btrfs_super_total_bytes (root->fs_info->super_copy)); alloc_hint =get_extent_allocation_hint (inode, start, num_bytes);btrfs_drop_extent_cache (inode, start, start + num_bytes -1 ,0 );
fs/btrfs/ioctl.c +3 -3
@@ -1128,7 +1128,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,mutex_unlock (&inode->i_mutex); } - disk_super = &root->fs_info->super_copy; + disk_super = root->fs_info->super_copy; features =btrfs_super_incompat_flags (disk_super);if (range->compress_type ==BTRFS_COMPRESS_LZO ) { features |=BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO ;
@@ -2579,7 +2579,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)return PTR_ERR (trans); } - dir_id =btrfs_super_root_dir (&root->fs_info->super_copy); + dir_id =btrfs_super_root_dir (root->fs_info->super_copy); di =btrfs_lookup_dir_item (trans, root->fs_info->tree_root, path, dir_id,"default" ,7 ,1 );if (IS_ERR_OR_NULL (di)) {
@@ -2595,7 +2595,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)btrfs_mark_buffer_dirty (path->nodes[0 ]);btrfs_free_path (path); - disk_super = &root->fs_info->super_copy; + disk_super = root->fs_info->super_copy; features =btrfs_super_incompat_flags (disk_super);if (!(features &BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL )) { features |=BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL ;
fs/btrfs/scrub.c +1 -1
@@ -182,7 +182,7 @@ struct scrub_dev *scrub_setup_dev(struct btrfs_device *dev) sdev->curr =-1 ;atomic_set (&sdev->in_flight,0 );atomic_set (&sdev->cancel_req,0 ); - sdev->csum_size =btrfs_super_csum_size (&fs_info->super_copy); + sdev->csum_size =btrfs_super_csum_size (fs_info->super_copy);INIT_LIST_HEAD (&sdev->csum_list);spin_lock_init (&sdev->list_lock);
fs/btrfs/super.c +12 -5
@@ -507,7 +507,7 @@ static struct dentry *get_default_root(struct super_block *sb,* will mount by default if we haven't been given a specific subvolume * to mount. */ - dir_id =btrfs_super_root_dir (&root->fs_info->super_copy); + dir_id =btrfs_super_root_dir (root->fs_info->super_copy); di =btrfs_lookup_dir_item (NULL , root, path, dir_id,"default" ,7 ,0 );if (IS_ERR (di)) {btrfs_free_path (path);
@@ -899,6 +899,13 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, fs_info->fs_devices = fs_devices; tree_root->fs_info = fs_info; + fs_info->super_copy =kzalloc (BTRFS_SUPER_INFO_SIZE ,GFP_NOFS ); + fs_info->super_for_commit =kzalloc (BTRFS_SUPER_INFO_SIZE ,GFP_NOFS ); +if (!fs_info->super_copy || !fs_info->super_for_commit) { + error = -ENOMEM ; + goto error_close_devices; + } + bdev = fs_devices->latest_bdev; s =sget (fs_type, btrfs_test_super, btrfs_set_super, tree_root);if (IS_ERR (s)) {
@@ -913,7 +920,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, }btrfs_close_devices (fs_devices); -kfree (fs_info); +free_fs_info (fs_info);kfree (tree_root); }else {char b[BDEVNAME_SIZE ];
@@ -941,7 +948,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, error_close_devices:btrfs_close_devices (fs_devices); -kfree (fs_info); +free_fs_info (fs_info);kfree (tree_root);return ERR_PTR (error); }
@@ -967,7 +974,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)if (root->fs_info->fs_devices->rw_devices ==0 )return -EACCES ; -if (btrfs_super_log_root (&root->fs_info->super_copy) !=0 ) +if (btrfs_super_log_root (root->fs_info->super_copy) !=0 )return -EINVAL ; ret =btrfs_cleanup_fs_roots (root->fs_info);
@@ -1133,7 +1140,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)static int btrfs_statfs (struct dentry *dentry,struct kstatfs *buf) {struct btrfs_root *root =btrfs_sb (dentry->d_sb); -struct btrfs_super_block *disk_super = &root->fs_info->super_copy; +struct btrfs_super_block *disk_super = root->fs_info->super_copy;struct list_head *head = &root->fs_info->space_info;struct btrfs_space_info *found;u64 total_used =0 ;
fs/btrfs/transaction.c +5 -5
@@ -992,7 +992,7 @@ static void update_super_roots(struct btrfs_root *root)struct btrfs_root_item *root_item;struct btrfs_super_block *super; - super = &root->fs_info->super_copy; + super = root->fs_info->super_copy; root_item = &root->fs_info->chunk_root->root_item; super->chunk_root = root_item->bytenr;
@@ -1303,12 +1303,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,update_super_roots (root);if (!root->fs_info->log_root_recovering) { -btrfs_set_super_log_root (&root->fs_info->super_copy,0 ); -btrfs_set_super_log_root_level (&root->fs_info->super_copy,0 ); +btrfs_set_super_log_root (root->fs_info->super_copy,0 ); +btrfs_set_super_log_root_level (root->fs_info->super_copy,0 ); } -memcpy (&root->fs_info->super_for_commit, &root->fs_info->super_copy, -sizeof (root->fs_info->super_copy)); +memcpy (root->fs_info->super_for_commit, root->fs_info->super_copy, +sizeof (*root->fs_info->super_copy)); trans->transaction->blocked =0 ;spin_lock (&root->fs_info->trans_lock);
fs/btrfs/tree-log.c +2 -2
@@ -2117,9 +2117,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,BUG_ON (ret);btrfs_wait_marked_extents (log, &log->dirty_log_pages, mark); -btrfs_set_super_log_root (&root->fs_info->super_for_commit, +btrfs_set_super_log_root (root->fs_info->super_for_commit, log_root_tree->node->start); -btrfs_set_super_log_root_level (&root->fs_info->super_for_commit, +btrfs_set_super_log_root_level (root->fs_info->super_for_commit,btrfs_header_level (log_root_tree->node)); log_root_tree->log_batch =0 ;
fs/btrfs/volumes.c +12 -12
@@ -1397,8 +1397,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)call_rcu (&device->rcu, free_device);mutex_unlock (&root->fs_info->fs_devices->device_list_mutex); - num_devices =btrfs_super_num_devices (&root->fs_info->super_copy) -1 ; -btrfs_set_super_num_devices (&root->fs_info->super_copy, num_devices); + num_devices =btrfs_super_num_devices (root->fs_info->super_copy) -1 ; +btrfs_set_super_num_devices (root->fs_info->super_copy, num_devices);if (cur_devices->open_devices ==0 ) {struct btrfs_fs_devices *fs_devices;
@@ -1460,7 +1460,7 @@ static int btrfs_prepare_sprout(struct btrfs_trans_handle *trans,struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;struct btrfs_fs_devices *old_devices;struct btrfs_fs_devices *seed_devices; -struct btrfs_super_block *disk_super = &root->fs_info->super_copy; +struct btrfs_super_block *disk_super = root->fs_info->super_copy;struct btrfs_device *device;u64 super_flags;
@@ -1708,12 +1708,12 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)if (!blk_queue_nonrot (bdev_get_queue (bdev))) root->fs_info->fs_devices->rotating =1 ; - total_bytes =btrfs_super_total_bytes (&root->fs_info->super_copy); -btrfs_set_super_total_bytes (&root->fs_info->super_copy, + total_bytes =btrfs_super_total_bytes (root->fs_info->super_copy); +btrfs_set_super_total_bytes (root->fs_info->super_copy, total_bytes + device->total_bytes); - total_bytes =btrfs_super_num_devices (&root->fs_info->super_copy); -btrfs_set_super_num_devices (&root->fs_info->super_copy, + total_bytes =btrfs_super_num_devices (root->fs_info->super_copy); +btrfs_set_super_num_devices (root->fs_info->super_copy, total_bytes +1 );mutex_unlock (&root->fs_info->fs_devices->device_list_mutex);
@@ -1804,7 +1804,7 @@ static int __btrfs_grow_device(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 new_size) {struct btrfs_super_block *super_copy = - &device->dev_root->fs_info->super_copy; + device->dev_root->fs_info->super_copy;u64 old_total =btrfs_super_total_bytes (super_copy);u64 diff = new_size - device->total_bytes;
@@ -1863,7 +1863,7 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans,static int btrfs_del_sys_chunk (struct btrfs_root *root,u64 chunk_objectid,u64 chunk_offset) { -struct btrfs_super_block *super_copy = &root->fs_info->super_copy; +struct btrfs_super_block *super_copy = root->fs_info->super_copy;struct btrfs_disk_key *disk_key;struct btrfs_chunk *chunk;u8 *ptr;
@@ -2189,7 +2189,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)bool retried = false;struct extent_buffer *l;struct btrfs_key key; -struct btrfs_super_block *super_copy = &root->fs_info->super_copy; +struct btrfs_super_block *super_copy = root->fs_info->super_copy;u64 old_total =btrfs_super_total_bytes (super_copy);u64 old_size = device->total_bytes;u64 diff = device->total_bytes - new_size;
@@ -2313,7 +2313,7 @@ static int btrfs_add_system_chunk(struct btrfs_trans_handle *trans,struct btrfs_key *key, struct btrfs_chunk *chunk, int item_size) { - struct btrfs_super_block *super_copy = &root->fs_info->super_copy; + struct btrfs_super_block *super_copy = root->fs_info->super_copy;struct btrfs_disk_key disk_key;u32 array_size;u8 *ptr;
@@ -3655,7 +3655,7 @@ static int read_one_dev(struct btrfs_root *root,int btrfs_read_sys_array (struct btrfs_root *root) { -struct btrfs_super_block *super_copy = &root->fs_info->super_copy; +struct btrfs_super_block *super_copy = root->fs_info->super_copy;struct extent_buffer *sb;struct btrfs_disk_key *disk_key;struct btrfs_chunk *chunk;
Signature · 1 line
1.7.6
PATCH 2/8 btrfs: fix misleading variable name for flags
In reply to David Sterba--- fs/btrfs/ctree.h | 2 +- fs/btrfs/extent-tree.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -2190,7 +2190,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, u64 num_bytes, u64 min_alloc_size, u64 empty_size, u64 hint_byte, u64 search_end, struct btrfs_key *ins, - u64 data); + u64 flags);int btrfs_inc_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct extent_buffer *buf,int full_backref); int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
fs/btrfs/extent-tree.c +7 -7
@@ -5404,12 +5404,12 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, u64 num_bytes, u64 min_alloc_size, u64 empty_size, u64 hint_byte, u64 search_end, struct btrfs_key *ins, - u64 data) + u64 flags) { int ret;u64 search_start =0 ; - data =btrfs_get_alloc_profile (root, data); + flags =btrfs_get_alloc_profile (root, flags); again:/* * the only place that sets empty_size is btrfs_realloc_node, which
@@ -5417,28 +5417,28 @@ again:*/ if (empty_size || root->ref_cows) ret =do_chunk_alloc (trans, root->fs_info->extent_root, - num_bytes +2 *1024 *1024 , data, + num_bytes +2 *1024 *1024 , flags,CHUNK_ALLOC_NO_FORCE );WARN_ON (num_bytes < root->sectorsize); ret =find_free_extent (trans, root, num_bytes, empty_size, search_start, search_end, hint_byte, - ins, data); + ins, flags);if (ret == -ENOSPC && num_bytes > min_alloc_size) { num_bytes = num_bytes >>1 ; num_bytes = num_bytes & ~(root->sectorsize -1 ); num_bytes =max (num_bytes, min_alloc_size);do_chunk_alloc (trans, root->fs_info->extent_root, - num_bytes, data,CHUNK_ALLOC_FORCE ); + num_bytes, flags,CHUNK_ALLOC_FORCE ); goto again; }if (ret == -ENOSPC &&btrfs_test_opt (root,ENOSPC_DEBUG )) {struct btrfs_space_info *sinfo; - sinfo =__find_space_info (root->fs_info, data); + sinfo =__find_space_info (root->fs_info, flags);printk (KERN_ERR "btrfs allocation failed flags %llu, " -"wanted %llu\n" , (unsigned long long )data, +"wanted %llu\n" , (unsigned long long )flags, (unsigned long long )num_bytes);dump_space_info (sinfo, num_bytes,1 ); }
Signature · 1 line
1.7.6
PATCH 3/8 btrfs: use unsigned long type for extent state bits
In reply to David Sterba--- fs/btrfs/extent_io.c | 45 ++++++++++++++++++++++++--------------------- fs/btrfs/extent_io.h | 33 +++++++++++++++++++-------------- fs/btrfs/inode.c | 7 ++++--- 3 files changed, 47 insertions(+), 38 deletions(-)
fs/btrfs/extent_io.c +24 -21
@@ -290,21 +290,21 @@ static void merge_state(struct extent_io_tree *tree, }static void set_state_cb (struct extent_io_tree *tree, -struct extent_state *state,int *bits) +struct extent_state *state,unsigned long *bits) {if (tree->ops && tree->ops->set_bit_hook) tree->ops->set_bit_hook (tree->mapping->host, state, bits); }static void clear_state_cb (struct extent_io_tree *tree, -struct extent_state *state,int *bits) +struct extent_state *state,unsigned long *bits) {if (tree->ops && tree->ops->clear_bit_hook) tree->ops->clear_bit_hook (tree->mapping->host, state, bits); }static void set_state_bits (struct extent_io_tree *tree, -struct extent_state *state,int *bits); +struct extent_state *state,unsigned long *bits);/* * insert an extent_state struct into the tree. 'bits' are set on the
@@ -318,7 +318,7 @@ static void set_state_bits(struct extent_io_tree *tree,*/ static int insert_state (struct extent_io_tree *tree,struct extent_state *state,u64 start,u64 end, -int *bits) +unsigned long *bits) {struct rb_node *node;
@@ -400,9 +400,9 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig,*/ static int clear_state_bit (struct extent_io_tree *tree,struct extent_state *state, -int *bits,int wake) +unsigned long *bits,int wake) { -int bits_to_clear = *bits & ~EXTENT_CTLBITS ; +unsigned long bits_to_clear = *bits & ~EXTENT_CTLBITS ;int ret = state->state & bits_to_clear;if ((bits_to_clear &EXTENT_DIRTY ) && (state->state &EXTENT_DIRTY )) {
@@ -451,7 +451,7 @@ alloc_extent_state_atomic(struct extent_state *prealloc)* bits were already set, or zero if none of the bits were already set. */ int clear_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int wake,int delete, +unsigned long bits,int wake,int delete,struct extent_state **cached_state,gfp_t mask) {
@@ -615,7 +615,7 @@ static int wait_on_state(struct extent_io_tree *tree,* The range [start, end] is inclusive. * The tree lock is taken by this function */ -int wait_extent_bit (struct extent_io_tree *tree,u64 start,u64 end,int bits) +int wait_extent_bit (struct extent_io_tree *tree,u64 start,u64 end,unsigned long bits) {struct extent_state *state;struct rb_node *node;
@@ -657,9 +657,9 @@ out:static void set_state_bits (struct extent_io_tree *tree,struct extent_state *state, -int *bits) +unsigned long *bits) { -int bits_to_set = *bits & ~EXTENT_CTLBITS ; +unsigned long bits_to_set = *bits & ~EXTENT_CTLBITS ;set_state_cb (tree, state, bits);if ((bits_to_set &EXTENT_DIRTY ) && !(state->state &EXTENT_DIRTY )) {
@@ -700,9 +700,10 @@ static void uncache_state(struct extent_state **cached_ptr)* [start, end] is inclusive This takes the tree lock. */ -int set_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int exclusive_bits,u64 *failed_start, -struct extent_state **cached_state,gfp_t mask) +int set_extent_bit (struct extent_io_tree *tree,u64 start,u64 end,unsigned +long bits,unsigned long exclusive_bits, +u64 *failed_start,struct extent_state **cached_state, +gfp_t mask) {struct extent_state *state;struct extent_state *prealloc =NULL ;
@@ -910,7 +911,8 @@ search_again:* boundary bits like LOCK. */ int convert_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int clear_bits,gfp_t mask) +unsigned long bits,unsigned long clear_bits, +gfp_t mask) {struct extent_state *state;struct extent_state *prealloc =NULL ;
@@ -1091,14 +1093,14 @@ int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, }int set_extent_bits (struct extent_io_tree *tree,u64 start,u64 end, -int bits,gfp_t mask) +unsigned long bits,gfp_t mask) {return set_extent_bit (tree, start, end, bits,0 ,NULL ,NULL , mask); }int clear_extent_bits (struct extent_io_tree *tree,u64 start,u64 end, -int bits,gfp_t mask) +unsigned long bits,gfp_t mask) {return clear_extent_bit (tree, start, end, bits,0 ,0 ,NULL , mask); }
@@ -1146,7 +1148,8 @@ static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,* us if waiting is desired. */ int lock_extent_bits (struct extent_io_tree *tree,u64 start,u64 end, -int bits,struct extent_state **cached_state,gfp_t mask) +unsigned long bits,struct extent_state **cached_state, +gfp_t mask) {int err;u64 failed_start;
@@ -1224,7 +1227,7 @@ static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)* nothing was found after 'start' */ struct extent_state *find_first_extent_bit_state (struct extent_io_tree *tree, -u64 start,int bits) +u64 start,unsigned long bits) {struct rb_node *node;struct extent_state *state;
@@ -1258,7 +1261,7 @@ out:* If nothing was found, 1 is returned, < 0 on error */ int find_first_extent_bit (struct extent_io_tree *tree,u64 start, -u64 *start_ret,u64 *end_ret,int bits) +u64 *start_ret,u64 *end_ret,unsigned long bits) {struct extent_state *state;int ret =1 ;
@@ -1526,7 +1529,7 @@ int extent_clear_unlock_delalloc(struct inode *inode,unsigned long end_index = end >>PAGE_CACHE_SHIFT ;unsigned long nr_pages = end_index - index +1 ;int i; -int clear_bits =0 ; +unsigned long clear_bits =0 ;if (op &EXTENT_CLEAR_UNLOCK ) clear_bits |=EXTENT_LOCKED ;
@@ -1699,7 +1702,7 @@ out:* range is found set. */ int test_range_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int filled,struct extent_state *cached) +unsigned long bits,int filled,struct extent_state *cached) {struct extent_state *state =NULL ;struct rb_node *node;
fs/btrfs/extent_io.h +19 -14
@@ -78,9 +78,9 @@ struct extent_io_ops {int (*writepage_end_io_hook)(struct page *page,u64 start,u64 end,struct extent_state *state,int uptodate);void (*set_bit_hook)(struct inode *inode,struct extent_state *state, -int *bits); +unsigned long *bits);void (*clear_bit_hook)(struct inode *inode,struct extent_state *state, -int *bits); +unsigned long *bits);void (*merge_extent_hook)(struct inode *inode,struct extent_state *new,struct extent_state *other);
@@ -179,7 +179,8 @@ int try_release_extent_state(struct extent_map_tree *map, gfp_t mask);int lock_extent (struct extent_io_tree *tree,u64 start,u64 end,gfp_t mask);int lock_extent_bits (struct extent_io_tree *tree,u64 start,u64 end, -int bits,struct extent_state **cached,gfp_t mask); +unsigned long bits,struct extent_state **cached, +gfp_t mask);int unlock_extent (struct extent_io_tree *tree,u64 start,u64 end,gfp_t mask);int unlock_extent_cached (struct extent_io_tree *tree,u64 start,u64 end,struct extent_state **cached,gfp_t mask);
@@ -196,17 +197,19 @@ u64 count_range_bits(struct extent_io_tree *tree,void free_extent_state (struct extent_state *state);int test_range_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int filled,struct extent_state *cached_state); +unsigned long bits,int filled,struct extent_state + *cached_state);int clear_extent_bits (struct extent_io_tree *tree,u64 start,u64 end, -int bits,gfp_t mask); +unsigned long bits,gfp_t mask);int clear_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int wake,int delete,struct extent_state **cached, -gfp_t mask); +unsigned long bits,int wake,int delete, +struct extent_state **cached,gfp_t mask);int set_extent_bits (struct extent_io_tree *tree,u64 start,u64 end, -int bits,gfp_t mask); +unsigned long bits,gfp_t mask);int set_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int exclusive_bits,u64 *failed_start, -struct extent_state **cached_state,gfp_t mask); +unsigned long bits,unsigned long exclusive_bits, +u64 *failed_start,struct extent_state **cached_state, +gfp_t mask);int set_extent_uptodate (struct extent_io_tree *tree,u64 start,u64 end,struct extent_state **cached_state,gfp_t mask); int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
@@ -216,13 +219,14 @@ int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,int clear_extent_dirty (struct extent_io_tree *tree,u64 start,u64 end,gfp_t mask);int convert_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, -int bits,int clear_bits,gfp_t mask); +unsigned long bits,unsigned long clear_bits, +gfp_t mask);int set_extent_delalloc (struct extent_io_tree *tree,u64 start,u64 end,struct extent_state **cached_state,gfp_t mask);int find_first_extent_bit (struct extent_io_tree *tree,u64 start, -u64 *start_ret,u64 *end_ret,int bits); +u64 *start_ret,u64 *end_ret,unsigned long bits);struct extent_state *find_first_extent_bit_state (struct extent_io_tree *tree, -u64 start,int bits); +u64 start,unsigned long bits);int extent_invalidatepage (struct extent_io_tree *tree,struct page *page,unsigned long offset); int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
@@ -277,7 +281,8 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, unsigned long src_offset, unsigned long len);void memset_extent_buffer (struct extent_buffer *eb,char c,unsigned long start,unsigned long len); -int wait_extent_bit (struct extent_io_tree *tree,u64 start,u64 end,int bits); +int wait_extent_bit (struct extent_io_tree *tree,u64 start,u64 end, +unsigned long bits);int clear_extent_buffer_dirty (struct extent_io_tree *tree,struct extent_buffer *eb); int set_extent_buffer_dirty(struct extent_io_tree *tree,
fs/btrfs/inode.c +4 -3
@@ -1320,7 +1320,7 @@ static void btrfs_merge_extent_hook(struct inode *inode,* have pending delalloc work to be done. */ static void btrfs_set_bit_hook (struct inode *inode, -struct extent_state *state,int *bits) +struct extent_state *state,unsigned long *bits) {/*
@@ -1356,7 +1356,8 @@ static void btrfs_set_bit_hook(struct inode *inode,* extent_io.c clear_bit_hook, see set_bit_hook for why */ static void btrfs_clear_bit_hook (struct inode *inode, -struct extent_state *state,int *bits) +struct extent_state *state, +unsigned long *bits) {/* * set_bit and clear bit hooks normally require _irqsave/restore
@@ -6161,7 +6162,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,u64 lockstart, lockend;ssize_t ret;int writing = rw &WRITE ; -int write_bits =0 ; +unsigned long write_bits =0 ;size_t count =iov_length (iov, nr_segs); if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iov,
Signature · 1 line
1.7.6
PATCH 4/8 btrfs: no need to mask out GFP_HIGHMEM in radix preload
In reply to David SterbaGFP_NOFS does not have the GFP_HIGHMEM bit set.
--- fs/btrfs/delayed-inode.c | 2 +- fs/btrfs/disk-io.c | 2 +- fs/btrfs/extent_io.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/delayed-inode.c +1 -1
@@ -137,7 +137,7 @@ again:atomic_inc (&node->refs);/* cached in the btrfs inode */ atomic_inc (&node->refs);/* can be accessed */ - ret =radix_tree_preload (GFP_NOFS & ~__GFP_HIGHMEM); + ret =radix_tree_preload (GFP_NOFS );if (ret) {kmem_cache_free (delayed_node_cache, node);return ERR_PTR (ret);
fs/btrfs/disk-io.c +1 -1
@@ -1354,7 +1354,7 @@ again:if (ret ==0 ) root->orphan_item_inserted =1 ; - ret =radix_tree_preload (GFP_NOFS & ~__GFP_HIGHMEM); + ret =radix_tree_preload (GFP_NOFS );if (ret) goto fail;
fs/btrfs/extent_io.c +1 -1
@@ -3297,7 +3297,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,if (uptodate)set_bit (EXTENT_BUFFER_UPTODATE , &eb->bflags); - ret =radix_tree_preload (GFP_NOFS & ~__GFP_HIGHMEM); + ret =radix_tree_preload (GFP_NOFS );if (ret) goto free_eb;
Signature · 1 line
1.7.6
PATCH 5/8 btrfs: kill key type helpers
In reply to David Sterbabtrfs_set_key_type and btrfs_key_type are used inconsistently along with open coded variants. Other members of btrfs_key are accessed directly without any helpers anyway.
Generated by spatch:
<Smpl>
@setkeyaddr@
expression KEY, VALUE;
@@
- btrfs_set_key_type(&KEY, VALUE)
+ KEY.type = VALUE
@setkeyptr@
expression KEY, VALUE;
@@
- btrfs_set_key_type(KEY, VALUE)
+ KEY->type = VALUE
@getkeyaddr@
expression KEY;
@@
- btrfs_key_type(&KEY)
+ KEY.type
@getkeyexpr@
expression KEY;
identifier IDX;
@@
- btrfs_key_type(KEY+IDX)
+ KEY[IDX].type
@getkeyptr@
expression KEY;
@@
- btrfs_key_type(KEY)
+ KEY->type
@setkillproto@
type T;
@@
- T btrfs_set_key_type(...) {
- ...
- }
@getkillproto@
type T;
@@
- T btrfs_key_type(...) {
- ...
- }
</Smpl>
--- fs/btrfs/ctree.h | 11 ----------- fs/btrfs/delayed-inode.c | 6 +++--- fs/btrfs/dir-item.c | 10 +++++----- fs/btrfs/export.c | 4 ++-- fs/btrfs/extent-tree.c | 8 ++++---- fs/btrfs/extent_io.c | 2 +- fs/btrfs/file-item.c | 12 ++++++------ fs/btrfs/file.c | 4 ++-- fs/btrfs/inode-item.c | 10 +++++----- fs/btrfs/inode.c | 28 ++++++++++++++-------------- fs/btrfs/ioctl.c | 6 +++--- fs/btrfs/orphan.c | 4 ++-- fs/btrfs/print-tree.c | 2 +- fs/btrfs/root-tree.c | 4 ++-- fs/btrfs/scrub.c | 4 ++-- fs/btrfs/tree-log.c | 6 +++--- fs/btrfs/volumes.c | 4 ++-- fs/btrfs/xattr.c | 4 ++-- 18 files changed, 59 insertions(+), 70 deletions(-)
fs/btrfs/ctree.h +0 -11
@@ -1876,17 +1876,6 @@ static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,btrfs_disk_key_to_cpu (key, &disk_key); } - -static inline u8 btrfs_key_type (struct btrfs_key *key) -{ -return key->type; -} - -static inline void btrfs_set_key_type (struct btrfs_key *key,u8 val) -{ - key->type = val; -} -/* struct btrfs_header */ BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
fs/btrfs/delayed-inode.c +3 -3
@@ -982,7 +982,7 @@ static int btrfs_update_delayed_inode(struct btrfs_trans_handle *trans, } key.objectid = node->inode_id; -btrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); + key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; ret =btrfs_lookup_inode (trans, root, path, &key,1 );if (ret >0 ) {
@@ -1302,7 +1302,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,BUG_ON (ret); delayed_item->key.objectid =btrfs_ino (dir); -btrfs_set_key_type (&delayed_item->key,BTRFS_DIR_INDEX_KEY ); + delayed_item->key.type =BTRFS_DIR_INDEX_KEY ; delayed_item->key.offset = index; dir_item = (struct btrfs_dir_item *)delayed_item->data;
@@ -1365,7 +1365,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,return PTR_ERR (node); item_key.objectid =btrfs_ino (dir); -btrfs_set_key_type (&item_key,BTRFS_DIR_INDEX_KEY ); + item_key.type =BTRFS_DIR_INDEX_KEY ; item_key.offset = index; ret =btrfs_delete_delayed_insertion_item (root, node, &item_key);
fs/btrfs/dir-item.c +5 -5
@@ -83,7 +83,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,BUG_ON (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root)); key.objectid = objectid; -btrfs_set_key_type (&key,BTRFS_XATTR_ITEM_KEY ); + key.type =BTRFS_XATTR_ITEM_KEY ; key.offset =btrfs_name_hash (name, name_len); data_size =sizeof (*dir_item) + name_len + data_len;
@@ -133,7 +133,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_rootu32 data_size; key.objectid =btrfs_ino (dir); -btrfs_set_key_type (&key,BTRFS_DIR_ITEM_KEY ); + key.type =BTRFS_DIR_ITEM_KEY ; key.offset =btrfs_name_hash (name, name_len); path =btrfs_alloc_path ();
@@ -200,7 +200,7 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,int cow = mod !=0 ; key.objectid = dir; -btrfs_set_key_type (&key,BTRFS_DIR_ITEM_KEY ); + key.type =BTRFS_DIR_ITEM_KEY ; key.offset =btrfs_name_hash (name, name_len);
@@ -234,7 +234,7 @@ btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,int cow = mod !=0 ; key.objectid = dir; -btrfs_set_key_type (&key,BTRFS_DIR_INDEX_KEY ); + key.type =BTRFS_DIR_INDEX_KEY ; key.offset = objectid; ret =btrfs_search_slot (trans, root, &key, path, ins_len, cow);
@@ -304,7 +304,7 @@ struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,int cow = mod !=0 ; key.objectid = dir; -btrfs_set_key_type (&key,BTRFS_XATTR_ITEM_KEY ); + key.type =BTRFS_XATTR_ITEM_KEY ; key.offset =btrfs_name_hash (name, name_len); ret =btrfs_search_slot (trans, root, &key, path, ins_len, cow);if (ret <0 )
fs/btrfs/export.c +2 -2
@@ -78,7 +78,7 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,return ERR_PTR (-ESTALE ); key.objectid = root_objectid; -btrfs_set_key_type (&key,BTRFS_ROOT_ITEM_KEY ); + key.type =BTRFS_ROOT_ITEM_KEY ; key.offset = (u64)-1 ; index =srcu_read_lock (&fs_info->subvol_srcu);
@@ -95,7 +95,7 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid, } key.objectid = objectid; -btrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); + key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; inode =btrfs_iget (sb, &key, root,NULL );
fs/btrfs/extent-tree.c +4 -4
@@ -684,7 +684,7 @@ int btrfs_lookup_extent(struct btrfs_root *root, u64 start, u64 len) key.objectid = start; key.offset = len; -btrfs_set_key_type (&key,BTRFS_EXTENT_ITEM_KEY ); + key.type =BTRFS_EXTENT_ITEM_KEY ; ret =btrfs_search_slot (NULL , root->fs_info->extent_root, &key, path,0 ,0 );btrfs_free_path (path);
@@ -2582,7 +2582,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,for (i =0 ; i < nritems; i++) {if (level ==0 ) {btrfs_item_key_to_cpu (buf, &key, i); -if (btrfs_key_type (&key) !=BTRFS_EXTENT_DATA_KEY ) +if (key.type !=BTRFS_EXTENT_DATA_KEY )continue ; fi =btrfs_item_ptr (buf, i, struct btrfs_file_extent_item);
@@ -4927,7 +4927,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,u64 ideal_cache_offset =0 ;WARN_ON (num_bytes < root->sectorsize); -btrfs_set_key_type (ins,BTRFS_EXTENT_ITEM_KEY ); + ins->type =BTRFS_EXTENT_ITEM_KEY ; ins->objectid =0 ; ins->offset =0 ;
@@ -7031,7 +7031,7 @@ int btrfs_read_block_groups(struct btrfs_root *root) root = info->extent_root; key.objectid =0 ; key.offset =0 ; -btrfs_set_key_type (&key,BTRFS_BLOCK_GROUP_ITEM_KEY ); + key.type =BTRFS_BLOCK_GROUP_ITEM_KEY ; path =btrfs_alloc_path ();if (!path)return -ENOMEM ;
fs/btrfs/extent_io.c +1 -1
@@ -3000,7 +3000,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, item =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], struct btrfs_file_extent_item);btrfs_item_key_to_cpu (path->nodes[0 ], &found_key, path->slots[0 ]); - found_type =btrfs_key_type (&found_key); + found_type = found_key.type;/* No extents, but there might be delalloc bits */ if (found_key.objectid != btrfs_ino(inode) ||
fs/btrfs/file-item.c +6 -6
@@ -52,7 +52,7 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,return -ENOMEM ; file_key.objectid = objectid; file_key.offset = pos; -btrfs_set_key_type (&file_key,BTRFS_EXTENT_DATA_KEY ); + file_key.type =BTRFS_EXTENT_DATA_KEY ; path->leave_spinning =1 ; ret = btrfs_insert_empty_item(trans, root, path, &file_key,
@@ -96,7 +96,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, file_key.objectid =BTRFS_EXTENT_CSUM_OBJECTID ; file_key.offset = bytenr; -btrfs_set_key_type (&file_key,BTRFS_EXTENT_CSUM_KEY ); + file_key.type =BTRFS_EXTENT_CSUM_KEY ; ret =btrfs_search_slot (trans, root, &file_key, path,0 , cow);if (ret <0 ) goto fail;
@@ -107,7 +107,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, goto fail; path->slots[0 ]--;btrfs_item_key_to_cpu (leaf, &found_key, path->slots[0 ]); -if (btrfs_key_type (&found_key) !=BTRFS_EXTENT_CSUM_KEY ) +if (found_key.type !=BTRFS_EXTENT_CSUM_KEY ) goto fail; csum_offset = (bytenr - found_key.offset) >>
@@ -143,7 +143,7 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, file_key.objectid = objectid; file_key.offset = offset; -btrfs_set_key_type (&file_key,BTRFS_EXTENT_DATA_KEY ); + file_key.type =BTRFS_EXTENT_DATA_KEY ; ret =btrfs_search_slot (trans, root, &file_key, path, ins_len, cow);return ret; }
@@ -685,7 +685,7 @@ again: file_key.objectid =BTRFS_EXTENT_CSUM_OBJECTID ; file_key.offset = sector_sum->bytenr; bytenr = sector_sum->bytenr; -btrfs_set_key_type (&file_key,BTRFS_EXTENT_CSUM_KEY ); + file_key.type =BTRFS_EXTENT_CSUM_KEY ; item =btrfs_lookup_csum (trans, root, path, sector_sum->bytenr,1 );if (!IS_ERR (item)) {
@@ -751,7 +751,7 @@ again: csum_offset = (bytenr - found_key.offset) >> root->fs_info->sb->s_blocksize_bits; -if (btrfs_key_type (&found_key) !=BTRFS_EXTENT_CSUM_KEY || +if (found_key.type !=BTRFS_EXTENT_CSUM_KEY || found_key.objectid !=BTRFS_EXTENT_CSUM_OBJECTID || csum_offset >=MAX_CSUM_ITEMS (root, csum_size)) { goto insert;
fs/btrfs/file.c +2 -2
@@ -237,14 +237,14 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)/* get the inode */ key.objectid = defrag->root; -btrfs_set_key_type (&key,BTRFS_ROOT_ITEM_KEY ); + key.type =BTRFS_ROOT_ITEM_KEY ; key.offset = (u64)-1 ; inode_root =btrfs_read_fs_root_no_name (fs_info, &key);if (IS_ERR (inode_root)) goto next; key.objectid = defrag->ino; -btrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); + key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; inode =btrfs_iget (fs_info->sb, &key, inode_root,NULL );
fs/btrfs/inode-item.c +5 -5
@@ -94,7 +94,7 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, key.objectid = inode_objectid; key.offset = ref_objectid; -btrfs_set_key_type (&key,BTRFS_INODE_REF_KEY ); + key.type =BTRFS_INODE_REF_KEY ; path =btrfs_alloc_path ();if (!path)
@@ -149,7 +149,7 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, key.objectid = inode_objectid; key.offset = ref_objectid; -btrfs_set_key_type (&key,BTRFS_INODE_REF_KEY ); + key.type =BTRFS_INODE_REF_KEY ; path =btrfs_alloc_path ();if (!path)
@@ -199,7 +199,7 @@ int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,struct btrfs_key key;int ret; key.objectid = objectid; -btrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); + key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; ret = btrfs_insert_empty_item(trans, root, path, &key,
@@ -219,13 +219,13 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_rootstruct btrfs_key found_key; ret =btrfs_search_slot (trans, root, location, path, ins_len, cow); -if (ret >0 &&btrfs_key_type (location) ==BTRFS_ROOT_ITEM_KEY && +if (ret >0 && location->type ==BTRFS_ROOT_ITEM_KEY && location->offset == (u64)-1 && path->slots[0 ] !=0 ) { slot = path->slots[0 ] -1 ; leaf = path->nodes[0 ];btrfs_item_key_to_cpu (leaf, &found_key, slot);if (found_key.objectid == location->objectid && -btrfs_key_type (&found_key) ==btrfs_key_type (location)) { + found_key.type == location->type) { path->slots[0 ]--;return 0 ; }
fs/btrfs/inode.c +14 -14
@@ -141,7 +141,7 @@ static noinline int insert_inline_extent(struct btrfs_trans_handle *trans, key.objectid =btrfs_ino (inode); key.offset = start; -btrfs_set_key_type (&key,BTRFS_EXTENT_DATA_KEY ); + key.type =BTRFS_EXTENT_DATA_KEY ; datasize =btrfs_file_extent_calc_inline_size (cur_size);inode_add_bytes (inode, size);
@@ -2245,7 +2245,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) path->reada =-1 ; key.objectid =BTRFS_ORPHAN_OBJECTID ; -btrfs_set_key_type (&key,BTRFS_ORPHAN_ITEM_KEY ); + key.type =BTRFS_ORPHAN_ITEM_KEY ; key.offset = (u64)-1 ;while (1 ) {
@@ -2272,7 +2272,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)/* make sure the item matches what we want */ if (found_key.objectid !=BTRFS_ORPHAN_OBJECTID )break ; -if (btrfs_key_type (&found_key) !=BTRFS_ORPHAN_ITEM_KEY ) +if (found_key.type !=BTRFS_ORPHAN_ITEM_KEY )break ;/* release the path since we're done with it */
@@ -3118,7 +3118,7 @@ search_again: fi =NULL ; leaf = path->nodes[0 ];btrfs_item_key_to_cpu (leaf, &found_key, path->slots[0 ]); - found_type =btrfs_key_type (&found_key); + found_type = found_key.type; encoding =0 ;if (found_key.objectid != ino)
@@ -4125,7 +4125,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,btrfs_get_delayed_items (inode, &ins_list, &del_list); } -btrfs_set_key_type (&key, key_type); + key.type = key_type; key.offset = filp->f_pos; key.objectid =btrfs_ino (inode);
@@ -4150,7 +4150,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,if (found_key.objectid != key.objectid)break ; -if (btrfs_key_type (&found_key) != key_type) +if (found_key.type != key_type)break ;if (found_key.offset < filp->f_pos) goto next;
@@ -4356,7 +4356,7 @@ static int btrfs_set_inode_index_count(struct inode *inode)int ret; key.objectid =btrfs_ino (inode); -btrfs_set_key_type (&key,BTRFS_DIR_INDEX_KEY ); + key.type =BTRFS_DIR_INDEX_KEY ; key.offset = (u64)-1 ; path =btrfs_alloc_path ();
@@ -4388,7 +4388,7 @@ static int btrfs_set_inode_index_count(struct inode *inode)btrfs_item_key_to_cpu (leaf, &found_key, path->slots[0 ]);if (found_key.objectid !=btrfs_ino (inode) || -btrfs_key_type (&found_key) !=BTRFS_DIR_INDEX_KEY ) { + found_key.type !=BTRFS_DIR_INDEX_KEY ) {BTRFS_I (inode)->index_cnt =2 ; goto out; }
@@ -4483,11 +4483,11 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, owner =1 ; key[0 ].objectid = objectid; -btrfs_set_key_type (&key[0 ],BTRFS_INODE_ITEM_KEY ); + key[0 ].type =BTRFS_INODE_ITEM_KEY ; key[0 ].offset =0 ; key[1 ].objectid = objectid; -btrfs_set_key_type (&key[1 ],BTRFS_INODE_REF_KEY ); + key[1 ].type =BTRFS_INODE_REF_KEY ; key[1 ].offset = ref_objectid; sizes[0 ] =sizeof (struct btrfs_inode_item );
@@ -4518,7 +4518,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, location = &BTRFS_I (inode)->location; location->objectid = objectid; location->offset =0 ; -btrfs_set_key_type (location,BTRFS_INODE_ITEM_KEY ); + location->type =BTRFS_INODE_ITEM_KEY ;btrfs_inherit_iflags (inode, dir);
@@ -4570,7 +4570,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,memcpy (&key, &BTRFS_I (inode)->root->root_key,sizeof (key)); }else { key.objectid = ino; -btrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); + key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; }
@@ -5007,7 +5007,7 @@ again: struct btrfs_file_extent_item);/* are we inside the extent that was found? */ btrfs_item_key_to_cpu (leaf, &found_key, path->slots[0 ]); - found_type =btrfs_key_type (&found_key); + found_type = found_key.type;if (found_key.objectid != objectid || found_type !=BTRFS_EXTENT_DATA_KEY ) { goto not_found;
@@ -7193,7 +7193,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, } key.objectid =btrfs_ino (inode); key.offset =0 ; -btrfs_set_key_type (&key,BTRFS_EXTENT_DATA_KEY ); + key.type =BTRFS_EXTENT_DATA_KEY ; datasize =btrfs_file_extent_calc_inline_size (name_len); err =btrfs_insert_empty_item (trans, root, path, &key, datasize);
fs/btrfs/ioctl.c +3 -3
@@ -398,7 +398,7 @@ static noinline int create_subvol(struct btrfs_root *root, key.objectid = objectid; key.offset =0 ; -btrfs_set_key_type (&key,BTRFS_ROOT_ITEM_KEY ); + key.type =BTRFS_ROOT_ITEM_KEY ; ret =btrfs_insert_root (trans, root->fs_info->tree_root, &key, &root_item);if (ret)
@@ -2279,11 +2279,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, slot = path->slots[0 ];btrfs_item_key_to_cpu (leaf, &key, slot); -if (btrfs_key_type (&key) >BTRFS_EXTENT_DATA_KEY || +if (key.type >BTRFS_EXTENT_DATA_KEY || key.objectid !=btrfs_ino (src))break ; -if (btrfs_key_type (&key) ==BTRFS_EXTENT_DATA_KEY ) { +if (key.type ==BTRFS_EXTENT_DATA_KEY ) {struct btrfs_file_extent_item *extent;int type;u32 size;
fs/btrfs/orphan.c +2 -2
@@ -27,7 +27,7 @@ int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,int ret =0 ; key.objectid =BTRFS_ORPHAN_OBJECTID ; -btrfs_set_key_type (&key,BTRFS_ORPHAN_ITEM_KEY ); + key.type =BTRFS_ORPHAN_ITEM_KEY ; key.offset = offset; path =btrfs_alloc_path ();
@@ -48,7 +48,7 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,int ret =0 ; key.objectid =BTRFS_ORPHAN_OBJECTID ; -btrfs_set_key_type (&key,BTRFS_ORPHAN_ITEM_KEY ); + key.type =BTRFS_ORPHAN_ITEM_KEY ; key.offset = offset; path =btrfs_alloc_path ();
fs/btrfs/print-tree.c +1 -1
@@ -178,7 +178,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)for (i =0 ; i < nr ; i++) { item =btrfs_item_nr (l, i);btrfs_item_key_to_cpu (l, &key, i); - type =btrfs_key_type (&key); + type = key.type; printk(KERN_INFO "\titem %d key (%llu %x %llu) itemoff %d " "itemsize %d\n", i,
fs/btrfs/root-tree.c +2 -2
@@ -144,7 +144,7 @@ int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid)int slot; key.objectid = objectid; -btrfs_set_key_type (&key,BTRFS_ROOT_ITEM_KEY ); + key.type =BTRFS_ROOT_ITEM_KEY ; key.offset =0 ; path =btrfs_alloc_path ();if (!path)
@@ -167,7 +167,7 @@ again: slot = path->slots[0 ]; }btrfs_item_key_to_cpu (leaf, &key, slot); -if (btrfs_key_type (&key) !=BTRFS_ROOT_ITEM_KEY ) +if (key.type !=BTRFS_ROOT_ITEM_KEY ) goto next;if (key.objectid < objectid)
fs/btrfs/scrub.c +2 -2
@@ -930,7 +930,7 @@ again:if (key.objectid >= logical + map->stripe_len)break ; -if (btrfs_key_type (&key) !=BTRFS_EXTENT_ITEM_KEY ) +if (key.type !=BTRFS_EXTENT_ITEM_KEY ) goto next; extent = btrfs_item_ptr(l, slot,
@@ -1076,7 +1076,7 @@ int scrub_enumerate_chunks(struct scrub_dev *sdev, u64 start, u64 end)if (found_key.objectid != sdev->dev->devid)break ; -if (btrfs_key_type (&found_key) !=BTRFS_DEV_EXTENT_KEY ) +if (found_key.type !=BTRFS_DEV_EXTENT_KEY )break ;if (found_key.offset >= end)
fs/btrfs/tree-log.c +3 -3
@@ -1123,7 +1123,7 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,return -EIO ; key.objectid =BTRFS_TREE_LOG_FIXUP_OBJECTID ; -btrfs_set_key_type (&key,BTRFS_ORPHAN_ITEM_KEY ); + key.type =BTRFS_ORPHAN_ITEM_KEY ; key.offset = objectid; ret =btrfs_insert_empty_item (trans, root, path, &key,0 );
@@ -2704,7 +2704,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,* or deletes of this inode don't have to relog the inode * again */ -if (btrfs_key_type (ins_keys + i) ==BTRFS_EXTENT_DATA_KEY ) { +if (ins_keys[i].type ==BTRFS_EXTENT_DATA_KEY ) {int found_type; extent =btrfs_item_ptr (src, start_slot + i, struct btrfs_file_extent_item);
@@ -3177,7 +3177,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree) again: key.objectid =BTRFS_TREE_LOG_OBJECTID ; key.offset = (u64)-1 ; -btrfs_set_key_type (&key,BTRFS_ROOT_ITEM_KEY ); + key.type =BTRFS_ROOT_ITEM_KEY ;while (1 ) { ret =btrfs_search_slot (NULL , log_root_tree, &key, path,0 ,0 );
fs/btrfs/volumes.c +2 -2
@@ -787,7 +787,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,if (key.objectid > device->devid)break ; -if (btrfs_key_type (&key) !=BTRFS_DEV_EXTENT_KEY ) +if (key.type !=BTRFS_DEV_EXTENT_KEY ) goto next; dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent);
@@ -910,7 +910,7 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,if (key.objectid > device->devid)break ; -if (btrfs_key_type (&key) !=BTRFS_DEV_EXTENT_KEY ) +if (key.type !=BTRFS_DEV_EXTENT_KEY ) goto next;if (key.offset > search_start) {
fs/btrfs/xattr.c +2 -2
@@ -212,7 +212,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)* first xattr that we find and walk forward */ key.objectid =btrfs_ino (inode); -btrfs_set_key_type (&key,BTRFS_XATTR_ITEM_KEY ); + key.type =BTRFS_XATTR_ITEM_KEY ; key.offset =0 ; path =btrfs_alloc_path ();
@@ -248,7 +248,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)/* check to make sure this item is what we want */ if (found_key.objectid != key.objectid)break ; -if (btrfs_key_type (&found_key) !=BTRFS_XATTR_ITEM_KEY ) +if (found_key.type !=BTRFS_XATTR_ITEM_KEY )break ; di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
Signature · 1 line
1.7.6
PATCH 6/8 btrfs: use ALIGN instead of open-coded variants
In reply to David SterbaGenerated by spatch:
<Smpl>
@nomask_1@
expression E,VAL;
@@
- (E + VAL - 1) & (~(VAL - 1))
+ ALIGN(E, VAL)
@nomask_2@
expression E,VAL;
type T;
@@
- (E + VAL - 1) & (~((T)VAL - 1))
+ ALIGN(E, VAL)
@rangealign_1@
expression E, VAL;
@@
- (E + VAL) & (~(VAL - 1))
+ ALIGN(E + 1, VAL)
@rangealign_2@
expression E, VAL;
type T;
@@
- (E + VAL) & (~((T)VAL - 1))
+ ALIGN(E + 1, VAL)
@specialized_stripe_align@
identifier root, offset;
@@
- stripe_align(root, offset)
+ ALIGN(offset, root->stripesize)
@specialized_stripe_align_rmfunc@
type T;
@@
- T stripe_align(...) {
- ...
- }
</Smpl>
--- fs/btrfs/extent-tree.c | 13 +++---------- fs/btrfs/extent_io.c | 8 ++++---- fs/btrfs/file.c | 3 +-- fs/btrfs/inode.c | 19 +++++++------------ fs/btrfs/volumes.c | 3 +-- 5 files changed, 16 insertions(+), 30 deletions(-)
fs/btrfs/extent-tree.c +3 -10
@@ -3061,7 +3061,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes)int ret =0 , committed =0 , alloc_chunk =1 ;/* make sure bytes are sectorsize aligned */ - bytes = (bytes + root->sectorsize -1 ) & ~((u64 )root->sectorsize -1 ); + bytes =ALIGN (bytes, root->sectorsize);if (root == root->fs_info->tree_root ||BTRFS_I (inode)->location.objectid ==BTRFS_FREE_INO_OBJECTID ) {
@@ -3156,7 +3156,7 @@ void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes)struct btrfs_space_info *data_sinfo;/* make sure bytes are sectorsize aligned */ - bytes = (bytes + root->sectorsize -1 ) & ~((u64 )root->sectorsize -1 ); + bytes =ALIGN (bytes, root->sectorsize); data_sinfo =BTRFS_I (inode)->space_info;spin_lock (&data_sinfo->lock);
@@ -4815,13 +4815,6 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,return ret; } -static u64 stripe_align (struct btrfs_root *root,u64 val) -{ -u64 mask = ((u64 )root->stripesize -1 ); -u64 ret = (val + mask) & ~mask; -return ret; -} -/* * when we wait for progress in the block group caching, its because * our allocation attempt failed at least once. So, we must sleep
@@ -5216,7 +5209,7 @@ refill_cluster: goto loop; } checks: - search_start =stripe_align (root, offset); + search_start =ALIGN (offset, root->stripesize);/* move on to the next group */ if (search_start + num_bytes >= search_end) {btrfs_add_free_space (block_group, offset, num_bytes);
fs/btrfs/extent_io.c +4 -4
@@ -2182,7 +2182,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, iosize =min (extent_map_end (em) - cur, end - cur +1 ); cur_end =min (extent_map_end (em) -1 , end); - iosize = (iosize + blocksize -1 ) & ~((u64 )blocksize -1 ); + iosize =ALIGN (iosize, blocksize);if (this_bio_flag &EXTENT_BIO_COMPRESSED ) { disk_io_size = em->block_len; sector = em->block_start >>9 ;
@@ -2464,7 +2464,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,BUG_ON (extent_map_end (em) <= cur);BUG_ON (end < cur); iosize =min (extent_map_end (em) - cur, end - cur +1 ); - iosize = (iosize + blocksize -1 ) & ~((u64 )blocksize -1 ); + iosize =ALIGN (iosize, blocksize); sector = (em->block_start + extent_offset) >>9 ; bdev = em->bdev; block_start = em->block_start;
@@ -2815,7 +2815,7 @@ int extent_invalidatepage(struct extent_io_tree *tree,u64 end = start +PAGE_CACHE_SIZE -1 ;size_t blocksize = page->mapping->host->i_sb->s_blocksize; - start += (offset + blocksize -1 ) & ~(blocksize -1 ); + start +=ALIGN (offset, blocksize);if (start > end)return 0 ;
@@ -2934,7 +2934,7 @@ static struct extent_map *get_extent_skip_holes(struct inode *inode, len = last - offset;if (len ==0 )break ; - len = (len + sectorsize -1 ) & ~(sectorsize -1 ); + len =ALIGN (len, sectorsize); em =get_extent (inode,NULL ,0 , offset, len,0 );if (IS_ERR_OR_NULL (em))return em;
fs/btrfs/file.c +1 -2
@@ -399,8 +399,7 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,loff_t isize =i_size_read (inode); start_pos = pos & ~((u64 )root->sectorsize -1 ); - num_bytes = (write_bytes + pos - start_pos + - root->sectorsize -1 ) & ~((u64 )root->sectorsize -1 ); + num_bytes =ALIGN (write_bytes + pos - start_pos, root->sectorsize); end_of_last_block = start_pos + num_bytes -1 ; err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block,
fs/btrfs/inode.c +7 -12
@@ -226,8 +226,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,u64 isize =i_size_read (inode);u64 actual_end =min (end +1 , isize);u64 inline_len = actual_end - start; -u64 aligned_end = (end + root->sectorsize -1 ) & - ~((u64 )root->sectorsize -1 ); +u64 aligned_end =ALIGN (end, root->sectorsize);u64 hint_byte;u64 data_len = inline_len;int ret;
@@ -377,7 +376,7 @@ again:* a compressed extent to 128k. */ total_compressed =min (total_compressed, max_uncompressed); - num_bytes = (end - start + blocksize) & ~(blocksize -1 ); + num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); total_in =0 ; ret =0 ;
@@ -468,15 +467,13 @@ again:* up to a block size boundary so the allocator does sane * things */ - total_compressed = (total_compressed + blocksize -1 ) & - ~(blocksize -1 ); + total_compressed =ALIGN (total_compressed, blocksize);/* * one last check to make sure the compression is really a * win, compare the page count read with the blocks on disk */ - total_in = (total_in +PAGE_CACHE_SIZE -1 ) & - ~(PAGE_CACHE_SIZE -1 ); + total_in =ALIGN (total_in,PAGE_CACHE_SIZE );if (total_compressed >= total_in) { will_compress =0 ; }else {
@@ -787,7 +784,7 @@ static noinline int cow_file_range(struct inode *inode,BUG_ON (IS_ERR (trans)); trans->block_rsv = &root->fs_info->delalloc_block_rsv; - num_bytes = (end - start + blocksize) & ~(blocksize -1 ); + num_bytes =ALIGN (end - start +1 , blocksize); num_bytes =max (blocksize, num_bytes); disk_num_bytes = num_bytes; ret =0 ;
@@ -5023,8 +5020,7 @@ again: }else if (found_type ==BTRFS_FILE_EXTENT_INLINE ) {size_t size; size =btrfs_file_extent_inline_len (leaf, item); - extent_end = (extent_start + size + root->sectorsize -1 ) & - ~((u64 )root->sectorsize -1 ); + extent_end =ALIGN (extent_start + size, root->sectorsize); }if (start >= extent_end) {
@@ -5094,8 +5090,7 @@ again: copy_size =min_t (u64,PAGE_CACHE_SIZE - pg_offset, size - extent_offset); em->start = extent_start + extent_offset; - em->len = (copy_size + root->sectorsize -1 ) & - ~((u64 )root->sectorsize -1 ); + em->len =ALIGN (copy_size, root->sectorsize); em->orig_start =EXTENT_MAP_INLINE ;if (compress_type) {set_bit (EXTENT_FLAG_COMPRESSED , &em->flags);
fs/btrfs/volumes.c +1 -2
@@ -2982,8 +2982,7 @@ again: num_stripes =1 ; stripe_index =0 ; stripe_nr_orig = stripe_nr; - stripe_nr_end = (offset + *length + map->stripe_len -1 ) & - (~(map->stripe_len -1 )); + stripe_nr_end =ALIGN (offset + *length, map->stripe_len);do_div (stripe_nr_end, map->stripe_len); stripe_end_offset = stripe_nr_end * map->stripe_len - (offset + *length);
Signature · 1 line
1.7.6
PATCH 7/8 btrfs: use DIV_ROUND_UP instead of open-coded variants
In reply to David SterbaGenerated by spatch:
<Smpl>
@expr1@
expression E,VAL;
@@
- (E + VAL - 1) / (VAL)
+ DIV_ROUND_UP(E, VAL)
@page_cache_shift@
expression E;
@@
- ((E + PAGE_CACHE_SIZE - 1) >> (PAGE_CACHE_SHIFT))
+ DIV_ROUND_UP(E, PAGE_CACHE_SIZE) @page_cache_size@
expression E;
@@
- ((E + PAGE_CACHE_SIZE - 1) / (PAGE_CACHE_SHIFT))
+ DIV_ROUND_UP(E, PAGE_CACHE_SIZE)
</Smpl>
--- fs/btrfs/compression.c | 9 ++++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/file.c | 14 ++++++-------- fs/btrfs/free-space-cache.c | 3 +-- fs/btrfs/ioctl.c | 2 +- fs/btrfs/lzo.c | 3 +-- fs/btrfs/ordered-data.h | 3 +-- fs/btrfs/zlib.c | 3 +-- 8 files changed, 16 insertions(+), 23 deletions(-)
fs/btrfs/compression.c +4 -5
@@ -88,7 +88,7 @@ static inline int compressed_bio_size(struct btrfs_root *root,u16 csum_size =btrfs_super_csum_size (root->fs_info->super_copy);return sizeof (struct compressed_bio ) + - ((disk_size + root->sectorsize -1 ) / root->sectorsize) * + (DIV_ROUND_UP (disk_size, root->sectorsize)) * csum_size; }
@@ -612,8 +612,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, cb->compress_type =extent_compress_type (bio_flags); cb->orig_bio = bio; - nr_pages = (compressed_len +PAGE_CACHE_SIZE -1 ) / -PAGE_CACHE_SIZE ; + nr_pages =DIV_ROUND_UP (compressed_len,PAGE_CACHE_SIZE ); cb->compressed_pages =kzalloc (sizeof (struct page *) * nr_pages,GFP_NOFS );if (!cb->compressed_pages)
@@ -675,8 +674,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, comp_bio, sums);BUG_ON (ret); } - sums += (comp_bio->bi_size + root->sectorsize -1 ) / - root->sectorsize; + sums +=DIV_ROUND_UP (comp_bio->bi_size, + root->sectorsize); ret =btrfs_map_bio (root,READ , comp_bio, mirror_num,0 );
fs/btrfs/extent_io.c +1 -1
@@ -3148,7 +3148,7 @@ static inline struct page *extent_buffer_page(struct extent_buffer *eb,static inline unsigned long num_extent_pages (u64 start,u64 len) { -return ((start + len +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ) - +return DIV_ROUND_UP (start + len,PAGE_CACHE_SIZE ) - (start >>PAGE_CACHE_SHIFT ); }
fs/btrfs/file.c +6 -8
@@ -1163,9 +1163,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,int ret =0 ;bool force_page_uptodate = false; - nrptrs =min ((iov_iter_count (i) +PAGE_CACHE_SIZE -1 ) / -PAGE_CACHE_SIZE ,PAGE_CACHE_SIZE / - (sizeof (struct page *))); + nrptrs =min (DIV_ROUND_UP (iov_iter_count (i),PAGE_CACHE_SIZE ), +PAGE_CACHE_SIZE / (sizeof (struct page *))); pages =kmalloc (nrptrs *sizeof (struct page *),GFP_KERNEL );if (!pages)return -ENOMEM ;
@@ -1177,8 +1176,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,size_t write_bytes =min (iov_iter_count (i), nrptrs * (size_t )PAGE_CACHE_SIZE - offset); -size_t num_pages = (write_bytes + offset + -PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ; +size_t num_pages =DIV_ROUND_UP (write_bytes + offset, +PAGE_CACHE_SIZE );size_t dirty_pages;size_t copied;
@@ -1227,9 +1226,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, dirty_pages =0 ; }else { force_page_uptodate = false; - dirty_pages = (copied + offset + -PAGE_CACHE_SIZE -1 ) >> -PAGE_CACHE_SHIFT ; + dirty_pages =DIV_ROUND_UP (copied + offset, +PAGE_CACHE_SIZE ); }/*
fs/btrfs/free-space-cache.c +1 -2
@@ -582,8 +582,7 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,if (!i_size_read (inode))return -1 ; - num_pages = (i_size_read (inode) +PAGE_CACHE_SIZE -1 ) >> -PAGE_CACHE_SHIFT ; + num_pages =DIV_ROUND_UP (i_size_read (inode),PAGE_CACHE_SIZE );filemap_write_and_wait (inode->i_mapping); btrfs_wait_ordered_range(inode, inode->i_size &
fs/btrfs/ioctl.c +1 -1
@@ -1067,7 +1067,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,* the should_defrag function tells us how much to skip * bump our counter by the suggested amount */ - next = (skip +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ; + next =DIV_ROUND_UP (skip,PAGE_CACHE_SIZE ); i =max (i +1 , next);continue ; }
fs/btrfs/lzo.c +1 -2
@@ -264,8 +264,7 @@ static int lzo_decompress_biovec(struct list_head *ws,char *data_in;unsigned long page_in_index =0 ;unsigned long page_out_index =0 ; -unsigned long total_pages_in = (srclen +PAGE_CACHE_SIZE -1 ) / -PAGE_CACHE_SIZE ; +unsigned long total_pages_in =DIV_ROUND_UP (srclen,PAGE_CACHE_SIZE );unsigned long buf_start;unsigned long buf_offset =0 ;unsigned long bytes;
fs/btrfs/ordered-data.h +1 -2
@@ -123,8 +123,7 @@ struct btrfs_ordered_extent {static inline int btrfs_ordered_sum_size (struct btrfs_root *root,unsigned long bytes) { -unsigned long num_sectors = (bytes + root->sectorsize -1 ) / - root->sectorsize; +unsigned long num_sectors =DIV_ROUND_UP (bytes, root->sectorsize); num_sectors++;return sizeof (struct btrfs_ordered_sum ) + num_sectors *sizeof (struct btrfs_sector_sum );
fs/btrfs/zlib.c +1 -2
@@ -225,8 +225,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,size_t total_out =0 ;unsigned long page_in_index =0 ;unsigned long page_out_index =0 ; -unsigned long total_pages_in = (srclen +PAGE_CACHE_SIZE -1 ) / -PAGE_CACHE_SIZE ; +unsigned long total_pages_in =DIV_ROUND_UP (srclen,PAGE_CACHE_SIZE );unsigned long buf_start;unsigned long pg_offset;
Signature · 1 line
1.7.6
PATCH 8/8 btrfs: cleanup: use BUG_ON when appropriate
In reply to David SterbaGenerated by spatch:
<Smpl>
@r@
expression E;
@@
- if(E)
- BUG();
+ BUG_ON(E);
</Smpl>
--- fs/btrfs/ctree.c | 8 +++----- fs/btrfs/print-tree.c | 8 ++------ fs/btrfs/volumes.c | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-)
fs/btrfs/ctree.c +3 -5
@@ -1068,9 +1068,8 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, } }/* double check we haven't messed things up */ -if (orig_ptr != -btrfs_node_blockptr (path->nodes[level], path->slots[level])) -BUG (); +BUG_ON (orig_ptr !=btrfs_node_blockptr (path->nodes[level], + path->slots[level])); enospc:if (right) {btrfs_tree_unlock (right);
@@ -2138,8 +2137,7 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root lower = path->nodes[level]; nritems =btrfs_header_nritems (lower);BUG_ON (slot > nritems); -if (nritems ==BTRFS_NODEPTRS_PER_BLOCK (root)) -BUG (); +BUG_ON (nritems ==BTRFS_NODEPTRS_PER_BLOCK (root));if (slot != nritems) { memmove_extent_buffer(lower, btrfs_node_key_ptr_offset(slot + 1),
fs/btrfs/print-tree.c +2 -6
@@ -326,12 +326,8 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *c)btrfs_node_blockptr (c, i),btrfs_level_size (root, level -1 ), btrfs_node_ptr_generation(c, i)); -if (btrfs_is_leaf (next) && - level !=1 ) -BUG (); -if (btrfs_header_level (next) != - level -1 ) -BUG (); +BUG_ON (btrfs_is_leaf (next) && level !=1 ); +BUG_ON (btrfs_header_level (next) != level -1 );btrfs_print_tree (root, next);free_extent_buffer (next); }
fs/btrfs/volumes.c +2 -2
@@ -2040,8 +2040,8 @@ again: found_key.offset);if (ret == -ENOSPC ) failed++; -else if (ret) -BUG (); +else +BUG_ON (ret); }if (found_key.offset ==0 )
Signature · 1 line
1.7.6