Skip to content

Commit 988f1f5

Browse files
committed
Merge branch 'for-chris-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/fdmanana/linux into for-linus-4.5
Signed-off-by: Chris Mason <[email protected]>
2 parents b28cf57 + 8cdc7c5 commit 988f1f5

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

fs/btrfs/extent-tree.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,6 +3768,25 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
37683768
}
37693769
if (!ret) {
37703770
ret = write_one_cache_group(trans, root, path, cache);
3771+
/*
3772+
* One of the free space endio workers might have
3773+
* created a new block group while updating a free space
3774+
* cache's inode (at inode.c:btrfs_finish_ordered_io())
3775+
* and hasn't released its transaction handle yet, in
3776+
* which case the new block group is still attached to
3777+
* its transaction handle and its creation has not
3778+
* finished yet (no block group item in the extent tree
3779+
* yet, etc). If this is the case, wait for all free
3780+
* space endio workers to finish and retry. This is a
3781+
* a very rare case so no need for a more efficient and
3782+
* complex approach.
3783+
*/
3784+
if (ret == -ENOENT) {
3785+
wait_event(cur_trans->writer_wait,
3786+
atomic_read(&cur_trans->num_writers) == 1);
3787+
ret = write_one_cache_group(trans, root, path,
3788+
cache);
3789+
}
37713790
if (ret)
37723791
btrfs_abort_transaction(trans, root, ret);
37733792
}

fs/btrfs/inode.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6478,7 +6478,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
64786478
static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
64796479
struct dentry *dentry)
64806480
{
6481-
struct btrfs_trans_handle *trans;
6481+
struct btrfs_trans_handle *trans = NULL;
64826482
struct btrfs_root *root = BTRFS_I(dir)->root;
64836483
struct inode *inode = d_inode(old_dentry);
64846484
u64 index;
@@ -6504,6 +6504,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
65046504
trans = btrfs_start_transaction(root, 5);
65056505
if (IS_ERR(trans)) {
65066506
err = PTR_ERR(trans);
6507+
trans = NULL;
65076508
goto fail;
65086509
}
65096510

@@ -6537,9 +6538,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
65376538
btrfs_log_new_name(trans, inode, NULL, parent);
65386539
}
65396540

6540-
btrfs_end_transaction(trans, root);
65416541
btrfs_balance_delayed_items(root);
65426542
fail:
6543+
if (trans)
6544+
btrfs_end_transaction(trans, root);
65436545
if (drop_inode) {
65446546
inode_dec_link_count(inode);
65456547
iput(inode);
@@ -9655,9 +9657,11 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
96559657
/*
96569658
* 2 items for inode item and ref
96579659
* 2 items for dir items
9660+
* 1 item for updating parent inode item
9661+
* 1 item for the inline extent item
96589662
* 1 item for xattr if selinux is on
96599663
*/
9660-
trans = btrfs_start_transaction(root, 5);
9664+
trans = btrfs_start_transaction(root, 7);
96619665
if (IS_ERR(trans))
96629666
return PTR_ERR(trans);
96639667

@@ -9688,10 +9692,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
96889692
if (err)
96899693
goto out_unlock_inode;
96909694

9691-
err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
9692-
if (err)
9693-
goto out_unlock_inode;
9694-
96959695
path = btrfs_alloc_path();
96969696
if (!path) {
96979697
err = -ENOMEM;
@@ -9728,6 +9728,13 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
97289728
inode_set_bytes(inode, name_len);
97299729
btrfs_i_size_write(inode, name_len);
97309730
err = btrfs_update_inode(trans, root, inode);
9731+
/*
9732+
* Last step, add directory indexes for our symlink inode. This is the
9733+
* last step to avoid extra cleanup of these indexes if an error happens
9734+
* elsewhere above.
9735+
*/
9736+
if (!err)
9737+
err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
97319738
if (err) {
97329739
drop_inode = 1;
97339740
goto out_unlock_inode;

fs/btrfs/send.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,21 @@ static int read_symlink(struct btrfs_root *root,
14691469
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
14701470
if (ret < 0)
14711471
goto out;
1472-
BUG_ON(ret);
1472+
if (ret) {
1473+
/*
1474+
* An empty symlink inode. Can happen in rare error paths when
1475+
* creating a symlink (transaction committed before the inode
1476+
* eviction handler removed the symlink inode items and a crash
1477+
* happened in between or the subvol was snapshoted in between).
1478+
* Print an informative message to dmesg/syslog so that the user
1479+
* can delete the symlink.
1480+
*/
1481+
btrfs_err(root->fs_info,
1482+
"Found empty symlink inode %llu at root %llu",
1483+
ino, root->root_key.objectid);
1484+
ret = -EIO;
1485+
goto out;
1486+
}
14731487

14741488
ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
14751489
struct btrfs_file_extent_item);

fs/btrfs/volumes.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,15 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction,
12581258
int ret;
12591259
int slot;
12601260
struct extent_buffer *l;
1261+
u64 min_search_start;
1262+
1263+
/*
1264+
* We don't want to overwrite the superblock on the drive nor any area
1265+
* used by the boot loader (grub for example), so we make sure to start
1266+
* at an offset of at least 1MB.
1267+
*/
1268+
min_search_start = max(root->fs_info->alloc_start, 1024ull * 1024);
1269+
search_start = max(search_start, min_search_start);
12611270

12621271
path = btrfs_alloc_path();
12631272
if (!path)
@@ -1398,18 +1407,9 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
13981407
struct btrfs_device *device, u64 num_bytes,
13991408
u64 *start, u64 *len)
14001409
{
1401-
struct btrfs_root *root = device->dev_root;
1402-
u64 search_start;
1403-
14041410
/* FIXME use last free of some kind */
1405-
1406-
/*
1407-
* we don't want to overwrite the superblock on the drive,
1408-
* so we make sure to start at an offset of at least 1MB
1409-
*/
1410-
search_start = max_t(u64, root->fs_info->alloc_start, SZ_1M);
14111411
return find_free_dev_extent_start(trans->transaction, device,
1412-
num_bytes, search_start, start, len);
1412+
num_bytes, 0, start, len);
14131413
}
14141414

14151415
static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)