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

Merge branch 'for-linus-4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

Pull btrfs fixes from Chris Mason:
"A couple of small fixes"

* 'for-linus-4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
Btrfs: check prepare_uptodate_page() error code earlier
Btrfs: check for empty bitmap list in setup_cluster_bitmaps
btrfs: fix misleading warning when space cache failed to load
Btrfs: fix transaction handle leak in balance
Btrfs: fix unprotected list move from unused_bgs to deleted_bgs list

+29 -15
+7 -3
fs/btrfs/extent-tree.c
··· 10480 10480 * until transaction commit to do the actual discard. 10481 10481 */ 10482 10482 if (trimming) { 10483 - WARN_ON(!list_empty(&block_group->bg_list)); 10484 - spin_lock(&trans->transaction->deleted_bgs_lock); 10483 + spin_lock(&fs_info->unused_bgs_lock); 10484 + /* 10485 + * A concurrent scrub might have added us to the list 10486 + * fs_info->unused_bgs, so use a list_move operation 10487 + * to add the block group to the deleted_bgs list. 10488 + */ 10485 10489 list_move(&block_group->bg_list, 10486 10490 &trans->transaction->deleted_bgs); 10487 - spin_unlock(&trans->transaction->deleted_bgs_lock); 10491 + spin_unlock(&fs_info->unused_bgs_lock); 10488 10492 btrfs_get_block_group(block_group); 10489 10493 } 10490 10494 end_trans:
+14 -4
fs/btrfs/file.c
··· 1291 1291 * on error we return an unlocked page and the error value 1292 1292 * on success we return a locked page and 0 1293 1293 */ 1294 - static int prepare_uptodate_page(struct page *page, u64 pos, 1294 + static int prepare_uptodate_page(struct inode *inode, 1295 + struct page *page, u64 pos, 1295 1296 bool force_uptodate) 1296 1297 { 1297 1298 int ret = 0; ··· 1306 1305 if (!PageUptodate(page)) { 1307 1306 unlock_page(page); 1308 1307 return -EIO; 1308 + } 1309 + if (page->mapping != inode->i_mapping) { 1310 + unlock_page(page); 1311 + return -EAGAIN; 1309 1312 } 1310 1313 } 1311 1314 return 0; ··· 1329 1324 int faili; 1330 1325 1331 1326 for (i = 0; i < num_pages; i++) { 1327 + again: 1332 1328 pages[i] = find_or_create_page(inode->i_mapping, index + i, 1333 1329 mask | __GFP_WRITE); 1334 1330 if (!pages[i]) { ··· 1339 1333 } 1340 1334 1341 1335 if (i == 0) 1342 - err = prepare_uptodate_page(pages[i], pos, 1336 + err = prepare_uptodate_page(inode, pages[i], pos, 1343 1337 force_uptodate); 1344 - if (i == num_pages - 1) 1345 - err = prepare_uptodate_page(pages[i], 1338 + if (!err && i == num_pages - 1) 1339 + err = prepare_uptodate_page(inode, pages[i], 1346 1340 pos + write_bytes, false); 1347 1341 if (err) { 1348 1342 page_cache_release(pages[i]); 1343 + if (err == -EAGAIN) { 1344 + err = 0; 1345 + goto again; 1346 + } 1349 1347 faili = i - 1; 1350 1348 goto fail; 1351 1349 }
+6 -4
fs/btrfs/free-space-cache.c
··· 891 891 spin_unlock(&block_group->lock); 892 892 ret = 0; 893 893 894 - btrfs_warn(fs_info, "failed to load free space cache for block group %llu, rebuild it now", 894 + btrfs_warn(fs_info, "failed to load free space cache for block group %llu, rebuilding it now", 895 895 block_group->key.objectid); 896 896 } 897 897 ··· 2972 2972 u64 cont1_bytes, u64 min_bytes) 2973 2973 { 2974 2974 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 2975 - struct btrfs_free_space *entry; 2975 + struct btrfs_free_space *entry = NULL; 2976 2976 int ret = -ENOSPC; 2977 2977 u64 bitmap_offset = offset_to_bitmap(ctl, offset); 2978 2978 ··· 2983 2983 * The bitmap that covers offset won't be in the list unless offset 2984 2984 * is just its start offset. 2985 2985 */ 2986 - entry = list_first_entry(bitmaps, struct btrfs_free_space, list); 2987 - if (entry->offset != bitmap_offset) { 2986 + if (!list_empty(bitmaps)) 2987 + entry = list_first_entry(bitmaps, struct btrfs_free_space, list); 2988 + 2989 + if (!entry || entry->offset != bitmap_offset) { 2988 2990 entry = tree_search_offset(ctl, bitmap_offset, 1, 0); 2989 2991 if (entry && list_empty(&entry->list)) 2990 2992 list_add(&entry->list, bitmaps);
-1
fs/btrfs/transaction.c
··· 274 274 cur_trans->num_dirty_bgs = 0; 275 275 spin_lock_init(&cur_trans->dirty_bgs_lock); 276 276 INIT_LIST_HEAD(&cur_trans->deleted_bgs); 277 - spin_lock_init(&cur_trans->deleted_bgs_lock); 278 277 spin_lock_init(&cur_trans->dropped_roots_lock); 279 278 list_add_tail(&cur_trans->list, &fs_info->trans_list); 280 279 extent_io_tree_init(&cur_trans->dirty_pages,
+1 -1
fs/btrfs/transaction.h
··· 77 77 */ 78 78 struct mutex cache_write_mutex; 79 79 spinlock_t dirty_bgs_lock; 80 + /* Protected by spin lock fs_info->unused_bgs_lock. */ 80 81 struct list_head deleted_bgs; 81 - spinlock_t deleted_bgs_lock; 82 82 spinlock_t dropped_roots_lock; 83 83 struct btrfs_delayed_ref_root delayed_refs; 84 84 int aborted;
+1 -2
fs/btrfs/volumes.c
··· 3548 3548 3549 3549 ret = btrfs_force_chunk_alloc(trans, chunk_root, 3550 3550 BTRFS_BLOCK_GROUP_DATA); 3551 + btrfs_end_transaction(trans, chunk_root); 3551 3552 if (ret < 0) { 3552 3553 mutex_unlock(&fs_info->delete_unused_bgs_mutex); 3553 3554 goto error; 3554 3555 } 3555 - 3556 - btrfs_end_transaction(trans, chunk_root); 3557 3556 chunk_reserved = 1; 3558 3557 } 3559 3558