Skip to content

Commit f583381

Browse files
committed
Merge branch 'for-linus-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs fixes from Chris Mason: "Filipe hit two problems in my block group cache patches. We finalized the fixes last week and ran through more tests" * 'for-linus-4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: Btrfs: prevent list corruption during free space cache processing Btrfs: fix inode cache writeout
2 parents 59953fb + a3bdccc commit f583381

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

fs/btrfs/free-space-cache.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,10 +1119,7 @@ static int flush_dirty_cache(struct inode *inode)
11191119
}
11201120

11211121
static void noinline_for_stack
1122-
cleanup_write_cache_enospc(struct inode *inode,
1123-
struct btrfs_io_ctl *io_ctl,
1124-
struct extent_state **cached_state,
1125-
struct list_head *bitmap_list)
1122+
cleanup_bitmap_list(struct list_head *bitmap_list)
11261123
{
11271124
struct list_head *pos, *n;
11281125

@@ -1131,6 +1128,14 @@ cleanup_write_cache_enospc(struct inode *inode,
11311128
list_entry(pos, struct btrfs_free_space, list);
11321129
list_del_init(&entry->list);
11331130
}
1131+
}
1132+
1133+
static void noinline_for_stack
1134+
cleanup_write_cache_enospc(struct inode *inode,
1135+
struct btrfs_io_ctl *io_ctl,
1136+
struct extent_state **cached_state,
1137+
struct list_head *bitmap_list)
1138+
{
11341139
io_ctl_drop_pages(io_ctl);
11351140
unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
11361141
i_size_read(inode) - 1, cached_state,
@@ -1149,7 +1154,8 @@ int btrfs_wait_cache_io(struct btrfs_root *root,
11491154
if (!inode)
11501155
return 0;
11511156

1152-
root = root->fs_info->tree_root;
1157+
if (block_group)
1158+
root = root->fs_info->tree_root;
11531159

11541160
/* Flush the dirty pages in the cache file. */
11551161
ret = flush_dirty_cache(inode);
@@ -1265,11 +1271,8 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
12651271
ret = write_cache_extent_entries(io_ctl, ctl,
12661272
block_group, &entries, &bitmaps,
12671273
&bitmap_list);
1268-
spin_unlock(&ctl->tree_lock);
1269-
if (ret) {
1270-
mutex_unlock(&ctl->cache_writeout_mutex);
1271-
goto out_nospc;
1272-
}
1274+
if (ret)
1275+
goto out_nospc_locked;
12731276

12741277
/*
12751278
* Some spaces that are freed in the current transaction are pinned,
@@ -1280,17 +1283,14 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
12801283
* the dirty list and redo it. No locking needed
12811284
*/
12821285
ret = write_pinned_extent_entries(root, block_group, io_ctl, &entries);
1283-
if (ret) {
1284-
mutex_unlock(&ctl->cache_writeout_mutex);
1285-
goto out_nospc;
1286-
}
1286+
if (ret)
1287+
goto out_nospc_locked;
12871288

12881289
/*
12891290
* At last, we write out all the bitmaps and keep cache_writeout_mutex
12901291
* locked while doing it because a concurrent trim can be manipulating
12911292
* or freeing the bitmap.
12921293
*/
1293-
spin_lock(&ctl->tree_lock);
12941294
ret = write_bitmap_entries(io_ctl, &bitmap_list);
12951295
spin_unlock(&ctl->tree_lock);
12961296
mutex_unlock(&ctl->cache_writeout_mutex);
@@ -1343,6 +1343,11 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
13431343
iput(inode);
13441344
return ret;
13451345

1346+
out_nospc_locked:
1347+
cleanup_bitmap_list(&bitmap_list);
1348+
spin_unlock(&ctl->tree_lock);
1349+
mutex_unlock(&ctl->cache_writeout_mutex);
1350+
13461351
out_nospc:
13471352
cleanup_write_cache_enospc(inode, io_ctl, &cached_state, &bitmap_list);
13481353

@@ -3463,9 +3468,12 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
34633468
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
34643469
return 0;
34653470

3471+
memset(&io_ctl, 0, sizeof(io_ctl));
34663472
ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl,
3467-
trans, path, 0) ||
3468-
btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0);
3473+
trans, path, 0);
3474+
if (!ret)
3475+
ret = btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0);
3476+
34693477
if (ret) {
34703478
btrfs_delalloc_release_metadata(inode, inode->i_size);
34713479
#ifdef DEBUG

0 commit comments

Comments
 (0)