Commit c1867eb3 authored by David Sterba's avatar David Sterba

btrfs: clean up chained assignments

The chained assignments may be convenient to write, but make readability
a bit worse as it's too easy to overlook that there are several values
set on the same line while this is rather an exception.  Making it
consistent everywhere avoids surprises.

The pattern where inode times are initialized reuses the first value and
the order is mtime, ctime. In other blocks the assignments are expanded
so the order of variables is similar to the neighboring code.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ac067734
...@@ -587,7 +587,8 @@ bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev, ...@@ -587,7 +587,8 @@ bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
ASSERT(!IS_ERR(em)); ASSERT(!IS_ERR(em));
map = em->map_lookup; map = em->map_lookup;
num_extents = cur_extent = 0; num_extents = 0;
cur_extent = 0;
for (i = 0; i < map->num_stripes; i++) { for (i = 0; i < map->num_stripes; i++) {
/* We have more device extent to copy */ /* We have more device extent to copy */
if (srcdev != map->stripes[i].dev) if (srcdev != map->stripes[i].dev)
......
...@@ -2058,9 +2058,11 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from, ...@@ -2058,9 +2058,11 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,
num_written = btrfs_encoded_write(iocb, from, encoded); num_written = btrfs_encoded_write(iocb, from, encoded);
num_sync = encoded->len; num_sync = encoded->len;
} else if (iocb->ki_flags & IOCB_DIRECT) { } else if (iocb->ki_flags & IOCB_DIRECT) {
num_written = num_sync = btrfs_direct_write(iocb, from); num_written = btrfs_direct_write(iocb, from);
num_sync = num_written;
} else { } else {
num_written = num_sync = btrfs_buffered_write(iocb, from); num_written = btrfs_buffered_write(iocb, from);
num_sync = num_written;
} }
btrfs_set_inode_last_sub_trans(inode); btrfs_set_inode_last_sub_trans(inode);
...@@ -3100,7 +3102,8 @@ static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len) ...@@ -3100,7 +3102,8 @@ static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len)
ASSERT(trans != NULL); ASSERT(trans != NULL);
inode_inc_iversion(inode); inode_inc_iversion(inode);
inode->i_mtime = inode->i_ctime = current_time(inode); inode->i_mtime = current_time(inode);
inode->i_ctime = inode->i_mtime;
ret = btrfs_update_inode(trans, root, BTRFS_I(inode)); ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
updated_inode = true; updated_inode = true;
btrfs_end_transaction(trans); btrfs_end_transaction(trans);
......
...@@ -3536,7 +3536,8 @@ int btrfs_find_space_cluster(struct btrfs_block_group *block_group, ...@@ -3536,7 +3536,8 @@ int btrfs_find_space_cluster(struct btrfs_block_group *block_group,
* data, keep it dense. * data, keep it dense.
*/ */
if (btrfs_test_opt(fs_info, SSD_SPREAD)) { if (btrfs_test_opt(fs_info, SSD_SPREAD)) {
cont1_bytes = min_bytes = bytes + empty_size; cont1_bytes = bytes + empty_size;
min_bytes = cont1_bytes;
} else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) { } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
cont1_bytes = bytes; cont1_bytes = bytes;
min_bytes = fs_info->sectorsize; min_bytes = fs_info->sectorsize;
......
...@@ -3129,8 +3129,10 @@ static int insert_ordered_extent_file_extent(struct btrfs_trans_handle *trans, ...@@ -3129,8 +3129,10 @@ static int insert_ordered_extent_file_extent(struct btrfs_trans_handle *trans,
btrfs_set_stack_file_extent_disk_num_bytes(&stack_fi, btrfs_set_stack_file_extent_disk_num_bytes(&stack_fi,
oe->disk_num_bytes); oe->disk_num_bytes);
btrfs_set_stack_file_extent_offset(&stack_fi, oe->offset); btrfs_set_stack_file_extent_offset(&stack_fi, oe->offset);
if (test_bit(BTRFS_ORDERED_TRUNCATED, &oe->flags)) if (test_bit(BTRFS_ORDERED_TRUNCATED, &oe->flags)) {
num_bytes = ram_bytes = oe->truncated_len; num_bytes = oe->truncated_len;
ram_bytes = num_bytes;
}
btrfs_set_stack_file_extent_num_bytes(&stack_fi, num_bytes); btrfs_set_stack_file_extent_num_bytes(&stack_fi, num_bytes);
btrfs_set_stack_file_extent_ram_bytes(&stack_fi, ram_bytes); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, ram_bytes);
btrfs_set_stack_file_extent_compression(&stack_fi, oe->compress_type); btrfs_set_stack_file_extent_compression(&stack_fi, oe->compress_type);
...@@ -4317,8 +4319,9 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, ...@@ -4317,8 +4319,9 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
btrfs_i_size_write(dir, dir->vfs_inode.i_size - name_len * 2); btrfs_i_size_write(dir, dir->vfs_inode.i_size - name_len * 2);
inode_inc_iversion(&inode->vfs_inode); inode_inc_iversion(&inode->vfs_inode);
inode_inc_iversion(&dir->vfs_inode); inode_inc_iversion(&dir->vfs_inode);
inode->vfs_inode.i_ctime = dir->vfs_inode.i_mtime = inode->vfs_inode.i_ctime = current_time(&inode->vfs_inode);
dir->vfs_inode.i_ctime = current_time(&inode->vfs_inode); dir->vfs_inode.i_mtime = inode->vfs_inode.i_ctime;
dir->vfs_inode.i_ctime = inode->vfs_inode.i_ctime;
ret = btrfs_update_inode(trans, root, dir); ret = btrfs_update_inode(trans, root, dir);
out: out:
return ret; return ret;
...@@ -4480,7 +4483,8 @@ static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, ...@@ -4480,7 +4483,8 @@ static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
btrfs_i_size_write(BTRFS_I(dir), dir->i_size - name_len * 2); btrfs_i_size_write(BTRFS_I(dir), dir->i_size - name_len * 2);
inode_inc_iversion(dir); inode_inc_iversion(dir);
dir->i_mtime = dir->i_ctime = current_time(dir); dir->i_mtime = current_time(dir);
dir->i_ctime = dir->i_mtime;
ret = btrfs_update_inode_fallback(trans, root, BTRFS_I(dir)); ret = btrfs_update_inode_fallback(trans, root, BTRFS_I(dir));
if (ret) if (ret)
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
...@@ -5121,9 +5125,10 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) ...@@ -5121,9 +5125,10 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
*/ */
if (newsize != oldsize) { if (newsize != oldsize) {
inode_inc_iversion(inode); inode_inc_iversion(inode);
if (!(mask & (ATTR_CTIME | ATTR_MTIME))) if (!(mask & (ATTR_CTIME | ATTR_MTIME))) {
inode->i_ctime = inode->i_mtime = inode->i_mtime = current_time(inode);
current_time(inode); inode->i_ctime = inode->i_mtime;
}
} }
if (newsize > oldsize) { if (newsize > oldsize) {
...@@ -7571,7 +7576,8 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map, ...@@ -7571,7 +7576,8 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
btrfs_dec_nocow_writers(bg); btrfs_dec_nocow_writers(bg);
if (type == BTRFS_ORDERED_PREALLOC) { if (type == BTRFS_ORDERED_PREALLOC) {
free_extent_map(em); free_extent_map(em);
*map = em = em2; *map = em2;
em = em2;
} }
if (IS_ERR(em2)) { if (IS_ERR(em2)) {
...@@ -9208,8 +9214,10 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -9208,8 +9214,10 @@ static int btrfs_rename_exchange(struct inode *old_dir,
inode_inc_iversion(new_dir); inode_inc_iversion(new_dir);
inode_inc_iversion(old_inode); inode_inc_iversion(old_inode);
inode_inc_iversion(new_inode); inode_inc_iversion(new_inode);
old_dir->i_ctime = old_dir->i_mtime = ctime; old_dir->i_mtime = ctime;
new_dir->i_ctime = new_dir->i_mtime = ctime; old_dir->i_ctime = ctime;
new_dir->i_mtime = ctime;
new_dir->i_ctime = ctime;
old_inode->i_ctime = ctime; old_inode->i_ctime = ctime;
new_inode->i_ctime = ctime; new_inode->i_ctime = ctime;
...@@ -9472,9 +9480,11 @@ static int btrfs_rename(struct user_namespace *mnt_userns, ...@@ -9472,9 +9480,11 @@ static int btrfs_rename(struct user_namespace *mnt_userns,
inode_inc_iversion(old_dir); inode_inc_iversion(old_dir);
inode_inc_iversion(new_dir); inode_inc_iversion(new_dir);
inode_inc_iversion(old_inode); inode_inc_iversion(old_inode);
old_dir->i_ctime = old_dir->i_mtime = old_dir->i_mtime = current_time(old_dir);
new_dir->i_ctime = new_dir->i_mtime = old_dir->i_ctime = old_dir->i_mtime;
old_inode->i_ctime = current_time(old_dir); new_dir->i_mtime = old_dir->i_mtime;
new_dir->i_ctime = old_dir->i_mtime;
old_inode->i_ctime = old_dir->i_mtime;
if (old_dentry->d_parent != new_dentry->d_parent) if (old_dentry->d_parent != new_dentry->d_parent)
btrfs_record_unlink_dir(trans, BTRFS_I(old_dir), btrfs_record_unlink_dir(trans, BTRFS_I(old_dir),
...@@ -10629,7 +10639,8 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, ...@@ -10629,7 +10639,8 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter,
ret = -ENOBUFS; ret = -ENOBUFS;
goto out_em; goto out_em;
} }
disk_io_size = count = em->block_len; disk_io_size = em->block_len;
count = em->block_len;
encoded->unencoded_len = em->ram_bytes; encoded->unencoded_len = em->ram_bytes;
encoded->unencoded_offset = iocb->ki_pos - em->orig_start; encoded->unencoded_offset = iocb->ki_pos - em->orig_start;
ret = btrfs_encoded_io_compression_from_extent(fs_info, ret = btrfs_encoded_io_compression_from_extent(fs_info,
......
...@@ -23,8 +23,10 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans, ...@@ -23,8 +23,10 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans,
int ret; int ret;
inode_inc_iversion(inode); inode_inc_iversion(inode);
if (!no_time_update) if (!no_time_update) {
inode->i_mtime = inode->i_ctime = current_time(inode); inode->i_mtime = current_time(inode);
inode->i_ctime = inode->i_mtime;
}
/* /*
* We round up to the block size at eof when determining which * We round up to the block size at eof when determining which
* extents to clone above, but shouldn't round up the file size. * extents to clone above, but shouldn't round up the file size.
......
...@@ -47,7 +47,8 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize) ...@@ -47,7 +47,8 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
goto out; goto out;
} }
path->nodes[0] = eb = alloc_dummy_extent_buffer(fs_info, nodesize); eb = alloc_dummy_extent_buffer(fs_info, nodesize);
path->nodes[0] = eb;
if (!eb) { if (!eb) {
test_std_err(TEST_ALLOC_EXTENT_BUFFER); test_std_err(TEST_ALLOC_EXTENT_BUFFER);
ret = -ENOMEM; ret = -ENOMEM;
......
...@@ -1832,8 +1832,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1832,8 +1832,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
btrfs_i_size_write(BTRFS_I(parent_inode), parent_inode->i_size + btrfs_i_size_write(BTRFS_I(parent_inode), parent_inode->i_size +
dentry->d_name.len * 2); dentry->d_name.len * 2);
parent_inode->i_mtime = parent_inode->i_ctime = parent_inode->i_mtime = current_time(parent_inode);
current_time(parent_inode); parent_inode->i_ctime = parent_inode->i_mtime;
ret = btrfs_update_inode_fallback(trans, parent_root, BTRFS_I(parent_inode)); ret = btrfs_update_inode_fallback(trans, parent_root, BTRFS_I(parent_inode));
if (ret) { if (ret) {
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
......
...@@ -7211,7 +7211,8 @@ static int read_one_dev(struct extent_buffer *leaf, ...@@ -7211,7 +7211,8 @@ static int read_one_dev(struct extent_buffer *leaf,
u8 fs_uuid[BTRFS_FSID_SIZE]; u8 fs_uuid[BTRFS_FSID_SIZE];
u8 dev_uuid[BTRFS_UUID_SIZE]; u8 dev_uuid[BTRFS_UUID_SIZE];
devid = args.devid = btrfs_device_id(leaf, dev_item); devid = btrfs_device_id(leaf, dev_item);
args.devid = devid;
read_extent_buffer(leaf, dev_uuid, btrfs_device_uuid(dev_item), read_extent_buffer(leaf, dev_uuid, btrfs_device_uuid(dev_item),
BTRFS_UUID_SIZE); BTRFS_UUID_SIZE);
read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item), read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment