[PATCH] Btrfs: Coding style fixes
Per Documentation/CodingStyle remove brackets on single expression if statements, add missing spaces after `,` and around `=`, remove unnecessary line continuations, add missing blank lines after declarations and fix mixed spaces and tabs. Signed-off-by: Seraphime Kirkovski --- fs/btrfs/ioctl.c | 31 +++ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 7acbd2c..fc6dc14 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -200,9 +200,9 @@ static int btrfs_ioctl_getflags(struct file *file, void __user *arg) static int check_flags(unsigned int flags) { - if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \ - FS_NOATIME_FL | FS_NODUMP_FL | \ - FS_SYNC_FL | FS_DIRSYNC_FL | \ + if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | + FS_NOATIME_FL | FS_NODUMP_FL | + FS_SYNC_FL | FS_DIRSYNC_FL | FS_NOCOMP_FL | FS_COMPR_FL | FS_NOCOW_FL)) return -EOPNOTSUPP; @@ -301,7 +301,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) if (S_ISREG(mode)) { if (inode->i_size == 0) ip->flags &= ~(BTRFS_INODE_NODATACOW -| BTRFS_INODE_NODATASUM); + | BTRFS_INODE_NODATASUM); } else { ip->flags &= ~BTRFS_INODE_NODATACOW; } @@ -394,7 +394,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) q = bdev_get_queue(device->bdev); if (blk_queue_discard(q)) { num_devices++; - minlen = min((u64)q->limits.discard_granularity, + minlen = min_t(u64, q->limits.discard_granularity, minlen); } } @@ -1464,9 +1464,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, atomic_dec(&root->fs_info->async_submit_draining); } - if (range->compress_type == BTRFS_COMPRESS_LZO) { + if (range->compress_type == BTRFS_COMPRESS_LZO) btrfs_set_fs_incompat(root->fs_info, COMPRESS_LZO); - } ret = defrag_count; @@ -1659,6 +1658,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file, } else { struct fd src = fdget(fd); struct inode *src_inode; + if (!src.file) { ret = -EINVAL; goto out_drop_write; @@ -2236,7 +2236,7 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, struct btrfs_path *path; if (dirid == BTRFS_FIRST_FREE_OBJECTID) { - name[0]='\0'; + name[0] = '\0'; return 0; } @@ -2679,7 +2679,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg) ret = btrfs_init_new_device(root, vol_args->name); if (!ret) - btrfs_info(root->fs_info, "disk added %s",vol_args->name); + btrfs_info(root->fs_info, "disk added %s", vol_args->name); kfree(vol_args); out: @@ -2773,7 +2773,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) mutex_unlock(&root->fs_info->volume_mutex); if (!ret) - btrfs_info(root->fs_info, "disk deleted %s",vol_args->name); + btrfs_info(root->fs_info, "disk deleted %s", vol_args->name); kfree(vol_args); out: atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0); @@ -2927,6 +2927,7 @@ static int lock_extent_range(struct inode *inode, u64 off, u64 len, */ while (1) { struct btrfs_ordered_extent *ordered; + lock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1); ordered = btrfs_lookup_first_ordered_extent(inode, off + len - 1); @@ -3895,11 +3896,10 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, if (S_ISDIR(src->i_mode) || S_ISDIR(inode->i_mode)) return -EISDIR; - if (!same_inode) { + if (!same_inode) btrfs_double_inode_lock(src, inode); - } else { + else inode_lock(src); - } /* determine range to clone */ ret = -EINVAL; @@ -4972,11 +4972,10 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg) } /* FIXME: check if the IDs really exist */ -
Re: [PATCH] Btrfs: Coding style fixes
On Mon, Dec 12, 2016 at 05:11:56PM +0100, David Sterba wrote: > This type of change is more like a cleanup and you can find more > instances where the type is applied to just one of the operands, while > min_t/max_t would be better. Feel free to send a separate patch for > that. Thanks for the feedback. I will try to do the sweep in the following days. I'm sorry, but I didn't quite understand. Should I resend the min/min_t change of this patch in a separate patch ? -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/4] Btrfs: ACCESS_ONCE cleanup
This replaces ACCESS_ONCE macro with the corresponding READ|WRITE macros Signed-off-by: Seraphime Kirkovski --- fs/btrfs/delayed-inode.c | 4 ++-- fs/btrfs/super.c | 2 +- fs/btrfs/transaction.c | 10 +- fs/btrfs/tree-log.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 6b23ef8..68e0e09 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -85,7 +85,7 @@ static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode) u64 ino = btrfs_ino(inode); struct btrfs_delayed_node *node; - node = ACCESS_ONCE(btrfs_inode->delayed_node); + node = READ_ONCE(btrfs_inode->delayed_node); if (node) { atomic_inc(&node->refs); return node; @@ -1294,7 +1294,7 @@ void btrfs_remove_delayed_node(struct inode *inode) { struct btrfs_delayed_node *delayed_node; - delayed_node = ACCESS_ONCE(BTRFS_I(inode)->delayed_node); + delayed_node = READ_ONCE(BTRFS_I(inode)->delayed_node); if (!delayed_node) return; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 3e25cfe..a445d4cd 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, function, line, errstr); return; } - ACCESS_ONCE(trans->transaction->aborted) = errno; + WRITE_ONCE(trans->transaction->aborted, errno); /* Wake up anybody who may be waiting on this transaction */ wake_up(&fs_info->transaction_wait); wake_up(&fs_info->transaction_blocked_wait); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 1bddef0..e340db1 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -859,14 +859,14 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, if (lock && !atomic_read(&root->fs_info->open_ioctl_trans) && should_end_transaction(trans, root) && - ACCESS_ONCE(cur_trans->state) == TRANS_STATE_RUNNING) { + READ_ONCE(cur_trans->state) == TRANS_STATE_RUNNING) { spin_lock(&info->trans_lock); if (cur_trans->state == TRANS_STATE_RUNNING) cur_trans->state = TRANS_STATE_BLOCKED; spin_unlock(&info->trans_lock); } - if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { + if (lock && READ_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { if (throttle) return btrfs_commit_transaction(trans, root); else @@ -1919,7 +1919,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, int ret; /* Stop the commit early if ->aborted is set */ - if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { + if (unlikely(READ_ONCE(cur_trans->aborted))) { ret = cur_trans->aborted; btrfs_end_transaction(trans, root); return ret; @@ -2059,7 +2059,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, atomic_read(&cur_trans->num_writers) == 1); /* ->aborted might be set after the previous check, so check it */ - if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { + if (unlikely(READ_ONCE(cur_trans->aborted))) { ret = cur_trans->aborted; goto scrub_continue; } @@ -2173,7 +2173,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, * The tasks which save the space cache and inode cache may also * update ->aborted, check it. */ - if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { + if (unlikely(READ_ONCE(cur_trans->aborted))) { ret = cur_trans->aborted; mutex_unlock(&root->fs_info->tree_log_mutex); mutex_unlock(&root->fs_info->reloc_mutex); diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index ab858e3..127eae0 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h @@ -48,13 +48,13 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx, static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info, struct btrfs_trans_handle *trans) { - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid; + WRITE_ONCE(fs_info->last_trans_log_full_commit, trans->transid); } static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info, struct btrfs_trans_handle *trans) { - return ACCESS_ONCE(fs_info->last_trans_log_full_
[PATCH 2/4] Btrfs: coding style fixes
This eliminates the rare uses of `unsigned` instead of `unsigned int`. Signed-off-by: Seraphime Kirkovski --- fs/btrfs/dir-item.c | 6 ++--- fs/btrfs/extent-tree.c | 20 - fs/btrfs/extent_io.c| 55 +++-- fs/btrfs/free-space-cache.c | 4 ++-- fs/btrfs/inode.c| 12 +- fs/btrfs/send.c | 6 ++--- fs/btrfs/super.c| 4 ++-- fs/btrfs/volumes.c | 6 ++--- 8 files changed, 57 insertions(+), 56 deletions(-) diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index ae496fd..2d68c17 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -466,7 +466,7 @@ int verify_dir_item(struct btrfs_root *root, if (btrfs_dir_name_len(leaf, dir_item) > namelen) { btrfs_crit(root->fs_info, "invalid dir item name len: %u", - (unsigned)btrfs_dir_data_len(leaf, dir_item)); + (unsigned int)btrfs_dir_data_len(leaf, dir_item)); return 1; } @@ -475,8 +475,8 @@ int verify_dir_item(struct btrfs_root *root, btrfs_dir_name_len(leaf, dir_item)) > BTRFS_MAX_XATTR_SIZE(root)) { btrfs_crit(root->fs_info, "invalid dir item name + data len: %u + %u", - (unsigned)btrfs_dir_name_len(leaf, dir_item), - (unsigned)btrfs_dir_data_len(leaf, dir_item)); + (unsigned int)btrfs_dir_name_len(leaf, dir_item), + (unsigned int)btrfs_dir_data_len(leaf, dir_item)); return 1; } diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index e5c19d9..cc82eae 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4106,7 +4106,7 @@ static u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) static u64 get_alloc_profile(struct btrfs_root *root, u64 orig_flags) { - unsigned seq; + unsigned int seq; u64 flags; do { @@ -5863,13 +5863,13 @@ void btrfs_subvolume_release_metadata(struct btrfs_root *root, * reserved extents that need to be freed. This must be called with * BTRFS_I(inode)->lock held. */ -static unsigned drop_outstanding_extent(struct inode *inode, u64 num_bytes) +static unsigned int drop_outstanding_extent(struct inode *inode, u64 num_bytes) { - unsigned drop_inode_space = 0; - unsigned dropped_extents = 0; - unsigned num_extents = 0; + unsigned int drop_inode_space = 0; + unsigned int dropped_extents = 0; + unsigned int num_extents = 0; - num_extents = (unsigned)div64_u64(num_bytes + + num_extents = (unsigned int)div64_u64(num_bytes + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); ASSERT(num_extents); @@ -5947,12 +5947,12 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) struct btrfs_block_rsv *block_rsv = &root->fs_info->delalloc_block_rsv; u64 to_reserve = 0; u64 csum_bytes; - unsigned nr_extents = 0; + unsigned int nr_extents = 0; enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL; int ret = 0; bool delalloc_lock = true; u64 to_free = 0; - unsigned dropped; + unsigned int dropped; bool release_extra = false; /* If we are a free space inode we need to not flush since we will be in @@ -5980,7 +5980,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) num_bytes = ALIGN(num_bytes, root->sectorsize); spin_lock(&BTRFS_I(inode)->lock); - nr_extents = (unsigned)div64_u64(num_bytes + + nr_extents = (unsigned int)div64_u64(num_bytes + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); BTRFS_I(inode)->outstanding_extents += nr_extents; @@ -6108,7 +6108,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes) { struct btrfs_root *root = BTRFS_I(inode)->root; u64 to_free = 0; - unsigned dropped; + unsigned int dropped; num_bytes = ALIGN(num_bytes, root->sectorsize); spin_lock(&BTRFS_I(inode)->lock); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index b92bcf3..4ffb29a 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -131,7 +131,7 @@ struct extent_page_data { unsigned int sync_io:1; }; -static void add_extent_changeset(struct extent_state *state, unsigned bits, +static void add_extent_changeset(struct extent_state *state, unsigned int bits, struct extent_changeset *changeset, int set) { @@ -413,21 +413,21 @@ static void
[PATCH 4/4] Btrfs: code cleanup min/max -> min_t/max_t
This cleans up the cases where the min/max macros were used with a cast rather than using directly min_t/max_t. Signed-off-by: Seraphime Kirkovski --- fs/btrfs/file-item.c | 4 ++-- fs/btrfs/ioctl.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 5fd5f45..7ae52cf 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -867,8 +867,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, tmp = min(tmp, (next_offset - file_key.offset) >> root->fs_info->sb->s_blocksize_bits); - tmp = max((u64)1, tmp); - tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root, csum_size)); + tmp = max_t(u64, 1, tmp); + tmp = min_t(u64, tmp, MAX_CSUM_ITEMS(root, csum_size)); ins_size = csum_size * tmp; } else { ins_size = csum_size; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 8bf0d44..fc6dc14 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -394,7 +394,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) q = bdev_get_queue(device->bdev); if (blk_queue_discard(q)) { num_devices++; - minlen = min((u64)q->limits.discard_granularity, + minlen = min_t(u64, q->limits.discard_granularity, minlen); } } -- 2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html