Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-4.17-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

Pull btrfs fixes from David Sterba:
"We've accumulated some fixes during the last week, some of them were
in the works for a longer time but there are some newer ones too.

Most of the fixes have a reproducer and fix user visible problems,
also candidates for stable kernels. They IMHO qualify for a late rc,
though I did not expect that many"

* tag 'for-4.17-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: fix crash when trying to resume balance without the resume flag
btrfs: Fix delalloc inodes invalidation during transaction abort
btrfs: Split btrfs_del_delalloc_inode into 2 functions
btrfs: fix reading stale metadata blocks after degraded raid1 mounts
btrfs: property: Set incompat flag if lzo/zstd compression is set
Btrfs: fix duplicate extents after fsync of file with prealloc extents
Btrfs: fix xattr loss after power failure
Btrfs: send, fix invalid access to commit roots due to concurrent snapshotting

+180 -48
+17 -5
fs/btrfs/ctree.c
··· 2436 2436 if (p->reada != READA_NONE) 2437 2437 reada_for_search(fs_info, p, level, slot, key->objectid); 2438 2438 2439 - btrfs_release_path(p); 2440 - 2441 2439 ret = -EAGAIN; 2442 - tmp = read_tree_block(fs_info, blocknr, 0, parent_level - 1, 2440 + tmp = read_tree_block(fs_info, blocknr, gen, parent_level - 1, 2443 2441 &first_key); 2444 2442 if (!IS_ERR(tmp)) { 2445 2443 /* ··· 2452 2454 } else { 2453 2455 ret = PTR_ERR(tmp); 2454 2456 } 2457 + 2458 + btrfs_release_path(p); 2455 2459 return ret; 2456 2460 } 2457 2461 ··· 5414 5414 down_read(&fs_info->commit_root_sem); 5415 5415 left_level = btrfs_header_level(left_root->commit_root); 5416 5416 left_root_level = left_level; 5417 - left_path->nodes[left_level] = left_root->commit_root; 5417 + left_path->nodes[left_level] = 5418 + btrfs_clone_extent_buffer(left_root->commit_root); 5419 + if (!left_path->nodes[left_level]) { 5420 + up_read(&fs_info->commit_root_sem); 5421 + ret = -ENOMEM; 5422 + goto out; 5423 + } 5418 5424 extent_buffer_get(left_path->nodes[left_level]); 5419 5425 5420 5426 right_level = btrfs_header_level(right_root->commit_root); 5421 5427 right_root_level = right_level; 5422 - right_path->nodes[right_level] = right_root->commit_root; 5428 + right_path->nodes[right_level] = 5429 + btrfs_clone_extent_buffer(right_root->commit_root); 5430 + if (!right_path->nodes[right_level]) { 5431 + up_read(&fs_info->commit_root_sem); 5432 + ret = -ENOMEM; 5433 + goto out; 5434 + } 5423 5435 extent_buffer_get(right_path->nodes[right_level]); 5424 5436 up_read(&fs_info->commit_root_sem); 5425 5437
+2
fs/btrfs/ctree.h
··· 3182 3182 u64 *orig_start, u64 *orig_block_len, 3183 3183 u64 *ram_bytes); 3184 3184 3185 + void __btrfs_del_delalloc_inode(struct btrfs_root *root, 3186 + struct btrfs_inode *inode); 3185 3187 struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); 3186 3188 int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index); 3187 3189 int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
+15 -11
fs/btrfs/disk-io.c
··· 3818 3818 set_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags); 3819 3819 3820 3820 btrfs_free_qgroup_config(fs_info); 3821 + ASSERT(list_empty(&fs_info->delalloc_roots)); 3821 3822 3822 3823 if (percpu_counter_sum(&fs_info->delalloc_bytes)) { 3823 3824 btrfs_info(fs_info, "at unmount delalloc count %lld", ··· 4126 4125 4127 4126 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info) 4128 4127 { 4128 + /* cleanup FS via transaction */ 4129 + btrfs_cleanup_transaction(fs_info); 4130 + 4129 4131 mutex_lock(&fs_info->cleaner_mutex); 4130 4132 btrfs_run_delayed_iputs(fs_info); 4131 4133 mutex_unlock(&fs_info->cleaner_mutex); 4132 4134 4133 4135 down_write(&fs_info->cleanup_work_sem); 4134 4136 up_write(&fs_info->cleanup_work_sem); 4135 - 4136 - /* cleanup FS via transaction */ 4137 - btrfs_cleanup_transaction(fs_info); 4138 4137 } 4139 4138 4140 4139 static void btrfs_destroy_ordered_extents(struct btrfs_root *root) ··· 4259 4258 list_splice_init(&root->delalloc_inodes, &splice); 4260 4259 4261 4260 while (!list_empty(&splice)) { 4261 + struct inode *inode = NULL; 4262 4262 btrfs_inode = list_first_entry(&splice, struct btrfs_inode, 4263 4263 delalloc_inodes); 4264 - 4265 - list_del_init(&btrfs_inode->delalloc_inodes); 4266 - clear_bit(BTRFS_INODE_IN_DELALLOC_LIST, 4267 - &btrfs_inode->runtime_flags); 4264 + __btrfs_del_delalloc_inode(root, btrfs_inode); 4268 4265 spin_unlock(&root->delalloc_lock); 4269 4266 4270 - btrfs_invalidate_inodes(btrfs_inode->root); 4271 - 4267 + /* 4268 + * Make sure we get a live inode and that it'll not disappear 4269 + * meanwhile. 4270 + */ 4271 + inode = igrab(&btrfs_inode->vfs_inode); 4272 + if (inode) { 4273 + invalidate_inode_pages2(inode->i_mapping); 4274 + iput(inode); 4275 + } 4272 4276 spin_lock(&root->delalloc_lock); 4273 4277 } 4274 - 4275 4278 spin_unlock(&root->delalloc_lock); 4276 4279 } 4277 4280 ··· 4291 4286 while (!list_empty(&splice)) { 4292 4287 root = list_first_entry(&splice, struct btrfs_root, 4293 4288 delalloc_root); 4294 - list_del_init(&root->delalloc_root); 4295 4289 root = btrfs_grab_fs_root(root); 4296 4290 BUG_ON(!root); 4297 4291 spin_unlock(&fs_info->delalloc_root_lock);
+10 -3
fs/btrfs/inode.c
··· 1742 1742 spin_unlock(&root->delalloc_lock); 1743 1743 } 1744 1744 1745 - static void btrfs_del_delalloc_inode(struct btrfs_root *root, 1746 - struct btrfs_inode *inode) 1745 + 1746 + void __btrfs_del_delalloc_inode(struct btrfs_root *root, 1747 + struct btrfs_inode *inode) 1747 1748 { 1748 1749 struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb); 1749 1750 1750 - spin_lock(&root->delalloc_lock); 1751 1751 if (!list_empty(&inode->delalloc_inodes)) { 1752 1752 list_del_init(&inode->delalloc_inodes); 1753 1753 clear_bit(BTRFS_INODE_IN_DELALLOC_LIST, ··· 1760 1760 spin_unlock(&fs_info->delalloc_root_lock); 1761 1761 } 1762 1762 } 1763 + } 1764 + 1765 + static void btrfs_del_delalloc_inode(struct btrfs_root *root, 1766 + struct btrfs_inode *inode) 1767 + { 1768 + spin_lock(&root->delalloc_lock); 1769 + __btrfs_del_delalloc_inode(root, inode); 1763 1770 spin_unlock(&root->delalloc_lock); 1764 1771 } 1765 1772
+8 -4
fs/btrfs/props.c
··· 380 380 const char *value, 381 381 size_t len) 382 382 { 383 + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 383 384 int type; 384 385 385 386 if (len == 0) { ··· 391 390 return 0; 392 391 } 393 392 394 - if (!strncmp("lzo", value, 3)) 393 + if (!strncmp("lzo", value, 3)) { 395 394 type = BTRFS_COMPRESS_LZO; 396 - else if (!strncmp("zlib", value, 4)) 395 + btrfs_set_fs_incompat(fs_info, COMPRESS_LZO); 396 + } else if (!strncmp("zlib", value, 4)) { 397 397 type = BTRFS_COMPRESS_ZLIB; 398 - else if (!strncmp("zstd", value, len)) 398 + } else if (!strncmp("zstd", value, len)) { 399 399 type = BTRFS_COMPRESS_ZSTD; 400 - else 400 + btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD); 401 + } else { 401 402 return -EINVAL; 403 + } 402 404 403 405 BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS; 404 406 BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
+119 -25
fs/btrfs/tree-log.c
··· 4320 4320 return ret; 4321 4321 } 4322 4322 4323 + /* 4324 + * Log all prealloc extents beyond the inode's i_size to make sure we do not 4325 + * lose them after doing a fast fsync and replaying the log. We scan the 4326 + * subvolume's root instead of iterating the inode's extent map tree because 4327 + * otherwise we can log incorrect extent items based on extent map conversion. 4328 + * That can happen due to the fact that extent maps are merged when they 4329 + * are not in the extent map tree's list of modified extents. 4330 + */ 4331 + static int btrfs_log_prealloc_extents(struct btrfs_trans_handle *trans, 4332 + struct btrfs_inode *inode, 4333 + struct btrfs_path *path) 4334 + { 4335 + struct btrfs_root *root = inode->root; 4336 + struct btrfs_key key; 4337 + const u64 i_size = i_size_read(&inode->vfs_inode); 4338 + const u64 ino = btrfs_ino(inode); 4339 + struct btrfs_path *dst_path = NULL; 4340 + u64 last_extent = (u64)-1; 4341 + int ins_nr = 0; 4342 + int start_slot; 4343 + int ret; 4344 + 4345 + if (!(inode->flags & BTRFS_INODE_PREALLOC)) 4346 + return 0; 4347 + 4348 + key.objectid = ino; 4349 + key.type = BTRFS_EXTENT_DATA_KEY; 4350 + key.offset = i_size; 4351 + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 4352 + if (ret < 0) 4353 + goto out; 4354 + 4355 + while (true) { 4356 + struct extent_buffer *leaf = path->nodes[0]; 4357 + int slot = path->slots[0]; 4358 + 4359 + if (slot >= btrfs_header_nritems(leaf)) { 4360 + if (ins_nr > 0) { 4361 + ret = copy_items(trans, inode, dst_path, path, 4362 + &last_extent, start_slot, 4363 + ins_nr, 1, 0); 4364 + if (ret < 0) 4365 + goto out; 4366 + ins_nr = 0; 4367 + } 4368 + ret = btrfs_next_leaf(root, path); 4369 + if (ret < 0) 4370 + goto out; 4371 + if (ret > 0) { 4372 + ret = 0; 4373 + break; 4374 + } 4375 + continue; 4376 + } 4377 + 4378 + btrfs_item_key_to_cpu(leaf, &key, slot); 4379 + if (key.objectid > ino) 4380 + break; 4381 + if (WARN_ON_ONCE(key.objectid < ino) || 4382 + key.type < BTRFS_EXTENT_DATA_KEY || 4383 + key.offset < i_size) { 4384 + path->slots[0]++; 4385 + continue; 4386 + } 4387 + if (last_extent == (u64)-1) { 4388 + last_extent = key.offset; 4389 + /* 4390 + * Avoid logging extent items logged in past fsync calls 4391 + * and leading to duplicate keys in the log tree. 4392 + */ 4393 + do { 4394 + ret = btrfs_truncate_inode_items(trans, 4395 + root->log_root, 4396 + &inode->vfs_inode, 4397 + i_size, 4398 + BTRFS_EXTENT_DATA_KEY); 4399 + } while (ret == -EAGAIN); 4400 + if (ret) 4401 + goto out; 4402 + } 4403 + if (ins_nr == 0) 4404 + start_slot = slot; 4405 + ins_nr++; 4406 + path->slots[0]++; 4407 + if (!dst_path) { 4408 + dst_path = btrfs_alloc_path(); 4409 + if (!dst_path) { 4410 + ret = -ENOMEM; 4411 + goto out; 4412 + } 4413 + } 4414 + } 4415 + if (ins_nr > 0) { 4416 + ret = copy_items(trans, inode, dst_path, path, &last_extent, 4417 + start_slot, ins_nr, 1, 0); 4418 + if (ret > 0) 4419 + ret = 0; 4420 + } 4421 + out: 4422 + btrfs_release_path(path); 4423 + btrfs_free_path(dst_path); 4424 + return ret; 4425 + } 4426 + 4323 4427 static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, 4324 4428 struct btrfs_root *root, 4325 4429 struct btrfs_inode *inode, ··· 4466 4362 if (em->generation <= test_gen) 4467 4363 continue; 4468 4364 4365 + /* We log prealloc extents beyond eof later. */ 4366 + if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags) && 4367 + em->start >= i_size_read(&inode->vfs_inode)) 4368 + continue; 4369 + 4469 4370 if (em->start < logged_start) 4470 4371 logged_start = em->start; 4471 4372 if ((em->start + em->len - 1) > logged_end) ··· 4481 4372 set_bit(EXTENT_FLAG_LOGGING, &em->flags); 4482 4373 list_add_tail(&em->list, &extents); 4483 4374 num++; 4484 - } 4485 - 4486 - /* 4487 - * Add all prealloc extents beyond the inode's i_size to make sure we 4488 - * don't lose them after doing a fast fsync and replaying the log. 4489 - */ 4490 - if (inode->flags & BTRFS_INODE_PREALLOC) { 4491 - struct rb_node *node; 4492 - 4493 - for (node = rb_last(&tree->map); node; node = rb_prev(node)) { 4494 - em = rb_entry(node, struct extent_map, rb_node); 4495 - if (em->start < i_size_read(&inode->vfs_inode)) 4496 - break; 4497 - if (!list_empty(&em->list)) 4498 - continue; 4499 - /* Same as above loop. */ 4500 - if (++num > 32768) { 4501 - list_del_init(&tree->modified_extents); 4502 - ret = -EFBIG; 4503 - goto process; 4504 - } 4505 - refcount_inc(&em->refs); 4506 - set_bit(EXTENT_FLAG_LOGGING, &em->flags); 4507 - list_add_tail(&em->list, &extents); 4508 - } 4509 4375 } 4510 4376 4511 4377 list_sort(NULL, &extents, extent_cmp); ··· 4527 4443 up_write(&inode->dio_sem); 4528 4444 4529 4445 btrfs_release_path(path); 4446 + if (!ret) 4447 + ret = btrfs_log_prealloc_extents(trans, inode, path); 4448 + 4530 4449 return ret; 4531 4450 } 4532 4451 ··· 4914 4827 struct extent_map_tree *em_tree = &inode->extent_tree; 4915 4828 u64 logged_isize = 0; 4916 4829 bool need_log_inode_item = true; 4830 + bool xattrs_logged = false; 4917 4831 4918 4832 path = btrfs_alloc_path(); 4919 4833 if (!path) ··· 5216 5128 err = btrfs_log_all_xattrs(trans, root, inode, path, dst_path); 5217 5129 if (err) 5218 5130 goto out_unlock; 5131 + xattrs_logged = true; 5219 5132 if (max_key.type >= BTRFS_EXTENT_DATA_KEY && !fast_search) { 5220 5133 btrfs_release_path(path); 5221 5134 btrfs_release_path(dst_path); ··· 5229 5140 btrfs_release_path(dst_path); 5230 5141 if (need_log_inode_item) { 5231 5142 err = log_inode_item(trans, log, dst_path, inode); 5143 + if (!err && !xattrs_logged) { 5144 + err = btrfs_log_all_xattrs(trans, root, inode, path, 5145 + dst_path); 5146 + btrfs_release_path(path); 5147 + } 5232 5148 if (err) 5233 5149 goto out_unlock; 5234 5150 }
+9
fs/btrfs/volumes.c
··· 4052 4052 return 0; 4053 4053 } 4054 4054 4055 + /* 4056 + * A ro->rw remount sequence should continue with the paused balance 4057 + * regardless of who pauses it, system or the user as of now, so set 4058 + * the resume flag. 4059 + */ 4060 + spin_lock(&fs_info->balance_lock); 4061 + fs_info->balance_ctl->flags |= BTRFS_BALANCE_RESUME; 4062 + spin_unlock(&fs_info->balance_lock); 4063 + 4055 4064 tsk = kthread_run(balance_kthread, fs_info, "btrfs-balance"); 4056 4065 return PTR_ERR_OR_ZERO(tsk); 4057 4066 }