Skip to content

Commit cb5520f

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
* git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable: (33 commits) Btrfs: Fix page count calculation btrfs: Drop __exit attribute on btrfs_exit_compress btrfs: cleanup error handling in btrfs_unlink_inode() Btrfs: exclude super blocks when we read in block groups Btrfs: make sure search_bitmap finds something in remove_from_bitmap btrfs: fix return value check of btrfs_start_transaction() btrfs: checking NULL or not in some functions Btrfs: avoid uninit variable warnings in ordered-data.c Btrfs: catch errors from btrfs_sync_log Btrfs: make shrink_delalloc a little friendlier Btrfs: handle no memory properly in prepare_pages Btrfs: do error checking in btrfs_del_csums Btrfs: use the global block reserve if we cannot reserve space Btrfs: do not release more reserved bytes to the global_block_rsv than we need Btrfs: fix check_path_shared so it returns the right value btrfs: check return value of btrfs_start_ioctl_transaction() properly btrfs: fix return value check of btrfs_join_transaction() fs/btrfs/inode.c: Add missing IS_ERR test btrfs: fix missing break in switch phrase btrfs: fix several uncheck memory allocations ...
2 parents eee4da2 + 3a90983 commit cb5520f

18 files changed

Lines changed: 371 additions & 116 deletions

‎fs/btrfs/acl.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
3737
char *value = NULL;
3838
struct posix_acl *acl;
3939

40+
if (!IS_POSIXACL(inode))
41+
return NULL;
42+
4043
acl = get_cached_acl(inode, type);
4144
if (acl != ACL_NOT_CACHED)
4245
return acl;
@@ -84,6 +87,9 @@ static int btrfs_xattr_acl_get(struct dentry *dentry, const char *name,
8487
struct posix_acl *acl;
8588
int ret = 0;
8689

90+
if (!IS_POSIXACL(dentry->d_inode))
91+
return -EOPNOTSUPP;
92+
8793
acl = btrfs_get_acl(dentry->d_inode, type);
8894

8995
if (IS_ERR(acl))

‎fs/btrfs/compression.c‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
562562
u64 em_len;
563563
u64 em_start;
564564
struct extent_map *em;
565-
int ret;
565+
int ret = -ENOMEM;
566566
u32 *sums;
567567

568568
tree = &BTRFS_I(inode)->io_tree;
@@ -577,6 +577,9 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
577577

578578
compressed_len = em->block_len;
579579
cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS);
580+
if (!cb)
581+
goto out;
582+
580583
atomic_set(&cb->pending_bios, 0);
581584
cb->errors = 0;
582585
cb->inode = inode;
@@ -597,13 +600,18 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
597600

598601
nr_pages = (compressed_len + PAGE_CACHE_SIZE - 1) /
599602
PAGE_CACHE_SIZE;
600-
cb->compressed_pages = kmalloc(sizeof(struct page *) * nr_pages,
603+
cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages,
601604
GFP_NOFS);
605+
if (!cb->compressed_pages)
606+
goto fail1;
607+
602608
bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
603609

604610
for (page_index = 0; page_index < nr_pages; page_index++) {
605611
cb->compressed_pages[page_index] = alloc_page(GFP_NOFS |
606612
__GFP_HIGHMEM);
613+
if (!cb->compressed_pages[page_index])
614+
goto fail2;
607615
}
608616
cb->nr_pages = nr_pages;
609617

@@ -614,6 +622,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
614622
cb->len = uncompressed_len;
615623

616624
comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, GFP_NOFS);
625+
if (!comp_bio)
626+
goto fail2;
617627
comp_bio->bi_private = cb;
618628
comp_bio->bi_end_io = end_compressed_bio_read;
619629
atomic_inc(&cb->pending_bios);
@@ -681,6 +691,17 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
681691

682692
bio_put(comp_bio);
683693
return 0;
694+
695+
fail2:
696+
for (page_index = 0; page_index < nr_pages; page_index++)
697+
free_page((unsigned long)cb->compressed_pages[page_index]);
698+
699+
kfree(cb->compressed_pages);
700+
fail1:
701+
kfree(cb);
702+
out:
703+
free_extent_map(em);
704+
return ret;
684705
}
685706

686707
static struct list_head comp_idle_workspace[BTRFS_COMPRESS_TYPES];
@@ -900,7 +921,7 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
900921
return ret;
901922
}
902923

903-
void __exit btrfs_exit_compress(void)
924+
void btrfs_exit_compress(void)
904925
{
905926
free_workspaces();
906927
}

‎fs/btrfs/disk-io.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,7 @@ static int transaction_kthread(void *arg)
15501550
spin_unlock(&root->fs_info->new_trans_lock);
15511551

15521552
trans = btrfs_join_transaction(root, 1);
1553+
BUG_ON(IS_ERR(trans));
15531554
if (transid == trans->transid) {
15541555
ret = btrfs_commit_transaction(trans, root);
15551556
BUG_ON(ret);
@@ -2453,10 +2454,14 @@ int btrfs_commit_super(struct btrfs_root *root)
24532454
up_write(&root->fs_info->cleanup_work_sem);
24542455

24552456
trans = btrfs_join_transaction(root, 1);
2457+
if (IS_ERR(trans))
2458+
return PTR_ERR(trans);
24562459
ret = btrfs_commit_transaction(trans, root);
24572460
BUG_ON(ret);
24582461
/* run commit again to drop the original snapshot */
24592462
trans = btrfs_join_transaction(root, 1);
2463+
if (IS_ERR(trans))
2464+
return PTR_ERR(trans);
24602465
btrfs_commit_transaction(trans, root);
24612466
ret = btrfs_write_and_wait_transaction(NULL, root);
24622467
BUG_ON(ret);
@@ -2554,6 +2559,8 @@ int close_ctree(struct btrfs_root *root)
25542559
kfree(fs_info->chunk_root);
25552560
kfree(fs_info->dev_root);
25562561
kfree(fs_info->csum_root);
2562+
kfree(fs_info);
2563+
25572564
return 0;
25582565
}
25592566

‎fs/btrfs/export.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
171171
int ret;
172172

173173
path = btrfs_alloc_path();
174+
if (!path)
175+
return ERR_PTR(-ENOMEM);
174176

175177
if (dir->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
176178
key.objectid = root->root_key.objectid;

‎fs/btrfs/extent-tree.c‎

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,6 @@ static int caching_kthread(void *data)
320320
if (!path)
321321
return -ENOMEM;
322322

323-
exclude_super_stripes(extent_root, block_group);
324-
spin_lock(&block_group->space_info->lock);
325-
block_group->space_info->bytes_readonly += block_group->bytes_super;
326-
spin_unlock(&block_group->space_info->lock);
327-
328323
last = max_t(u64, block_group->key.objectid, BTRFS_SUPER_INFO_OFFSET);
329324

330325
/*
@@ -467,8 +462,10 @@ static int cache_block_group(struct btrfs_block_group_cache *cache,
467462
cache->cached = BTRFS_CACHE_NO;
468463
}
469464
spin_unlock(&cache->lock);
470-
if (ret == 1)
465+
if (ret == 1) {
466+
free_excluded_extents(fs_info->extent_root, cache);
471467
return 0;
468+
}
472469
}
473470

474471
if (load_cache_only)
@@ -3344,8 +3341,10 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans,
33443341
u64 reserved;
33453342
u64 max_reclaim;
33463343
u64 reclaimed = 0;
3344+
long time_left;
33473345
int pause = 1;
33483346
int nr_pages = (2 * 1024 * 1024) >> PAGE_CACHE_SHIFT;
3347+
int loops = 0;
33493348

33503349
block_rsv = &root->fs_info->delalloc_block_rsv;
33513350
space_info = block_rsv->space_info;
@@ -3358,16 +3357,20 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans,
33583357

33593358
max_reclaim = min(reserved, to_reclaim);
33603359

3361-
while (1) {
3360+
while (loops < 1024) {
33623361
/* have the flusher threads jump in and do some IO */
33633362
smp_mb();
33643363
nr_pages = min_t(unsigned long, nr_pages,
33653364
root->fs_info->delalloc_bytes >> PAGE_CACHE_SHIFT);
33663365
writeback_inodes_sb_nr_if_idle(root->fs_info->sb, nr_pages);
33673366

33683367
spin_lock(&space_info->lock);
3369-
if (reserved > space_info->bytes_reserved)
3368+
if (reserved > space_info->bytes_reserved) {
3369+
loops = 0;
33703370
reclaimed += reserved - space_info->bytes_reserved;
3371+
} else {
3372+
loops++;
3373+
}
33713374
reserved = space_info->bytes_reserved;
33723375
spin_unlock(&space_info->lock);
33733376

@@ -3378,7 +3381,12 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans,
33783381
return -EAGAIN;
33793382

33803383
__set_current_state(TASK_INTERRUPTIBLE);
3381-
schedule_timeout(pause);
3384+
time_left = schedule_timeout(pause);
3385+
3386+
/* We were interrupted, exit */
3387+
if (time_left)
3388+
break;
3389+
33823390
pause <<= 1;
33833391
if (pause > HZ / 10)
33843392
pause = HZ / 10;
@@ -3588,8 +3596,20 @@ void block_rsv_release_bytes(struct btrfs_block_rsv *block_rsv,
35883596

35893597
if (num_bytes > 0) {
35903598
if (dest) {
3591-
block_rsv_add_bytes(dest, num_bytes, 0);
3592-
} else {
3599+
spin_lock(&dest->lock);
3600+
if (!dest->full) {
3601+
u64 bytes_to_add;
3602+
3603+
bytes_to_add = dest->size - dest->reserved;
3604+
bytes_to_add = min(num_bytes, bytes_to_add);
3605+
dest->reserved += bytes_to_add;
3606+
if (dest->reserved >= dest->size)
3607+
dest->full = 1;
3608+
num_bytes -= bytes_to_add;
3609+
}
3610+
spin_unlock(&dest->lock);
3611+
}
3612+
if (num_bytes) {
35933613
spin_lock(&space_info->lock);
35943614
space_info->bytes_reserved -= num_bytes;
35953615
spin_unlock(&space_info->lock);
@@ -4012,6 +4032,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
40124032

40134033
num_bytes = ALIGN(num_bytes, root->sectorsize);
40144034
atomic_dec(&BTRFS_I(inode)->outstanding_extents);
4035+
WARN_ON(atomic_read(&BTRFS_I(inode)->outstanding_extents) < 0);
40154036

40164037
spin_lock(&BTRFS_I(inode)->accounting_lock);
40174038
nr_extents = atomic_read(&BTRFS_I(inode)->outstanding_extents);
@@ -5633,21 +5654,47 @@ use_block_rsv(struct btrfs_trans_handle *trans,
56335654
struct btrfs_root *root, u32 blocksize)
56345655
{
56355656
struct btrfs_block_rsv *block_rsv;
5657+
struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv;
56365658
int ret;
56375659

56385660
block_rsv = get_block_rsv(trans, root);
56395661

56405662
if (block_rsv->size == 0) {
56415663
ret = reserve_metadata_bytes(trans, root, block_rsv,
56425664
blocksize, 0);
5643-
if (ret)
5665+
/*
5666+
* If we couldn't reserve metadata bytes try and use some from
5667+
* the global reserve.
5668+
*/
5669+
if (ret && block_rsv != global_rsv) {
5670+
ret = block_rsv_use_bytes(global_rsv, blocksize);
5671+
if (!ret)
5672+
return global_rsv;
5673+
return ERR_PTR(ret);
5674+
} else if (ret) {
56445675
return ERR_PTR(ret);
5676+
}
56455677
return block_rsv;
56465678
}
56475679

56485680
ret = block_rsv_use_bytes(block_rsv, blocksize);
56495681
if (!ret)
56505682
return block_rsv;
5683+
if (ret) {
5684+
WARN_ON(1);
5685+
ret = reserve_metadata_bytes(trans, root, block_rsv, blocksize,
5686+
0);
5687+
if (!ret) {
5688+
spin_lock(&block_rsv->lock);
5689+
block_rsv->size += blocksize;
5690+
spin_unlock(&block_rsv->lock);
5691+
return block_rsv;
5692+
} else if (ret && block_rsv != global_rsv) {
5693+
ret = block_rsv_use_bytes(global_rsv, blocksize);
5694+
if (!ret)
5695+
return global_rsv;
5696+
}
5697+
}
56515698

56525699
return ERR_PTR(-ENOSPC);
56535700
}
@@ -6221,6 +6268,8 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
62216268
BUG_ON(!wc);
62226269

62236270
trans = btrfs_start_transaction(tree_root, 0);
6271+
BUG_ON(IS_ERR(trans));
6272+
62246273
if (block_rsv)
62256274
trans->block_rsv = block_rsv;
62266275

@@ -6318,6 +6367,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
63186367

63196368
btrfs_end_transaction_throttle(trans, tree_root);
63206369
trans = btrfs_start_transaction(tree_root, 0);
6370+
BUG_ON(IS_ERR(trans));
63216371
if (block_rsv)
63226372
trans->block_rsv = block_rsv;
63236373
}
@@ -6446,6 +6496,8 @@ static noinline int relocate_inode_pages(struct inode *inode, u64 start,
64466496
int ret = 0;
64476497

64486498
ra = kzalloc(sizeof(*ra), GFP_NOFS);
6499+
if (!ra)
6500+
return -ENOMEM;
64496501

64506502
mutex_lock(&inode->i_mutex);
64516503
first_index = start >> PAGE_CACHE_SHIFT;
@@ -7477,7 +7529,7 @@ int btrfs_drop_dead_reloc_roots(struct btrfs_root *root)
74777529
BUG_ON(reloc_root->commit_root != NULL);
74787530
while (1) {
74797531
trans = btrfs_join_transaction(root, 1);
7480-
BUG_ON(!trans);
7532+
BUG_ON(IS_ERR(trans));
74817533

74827534
mutex_lock(&root->fs_info->drop_mutex);
74837535
ret = btrfs_drop_snapshot(trans, reloc_root);
@@ -7535,7 +7587,7 @@ int btrfs_cleanup_reloc_trees(struct btrfs_root *root)
75357587

75367588
if (found) {
75377589
trans = btrfs_start_transaction(root, 1);
7538-
BUG_ON(!trans);
7590+
BUG_ON(IS_ERR(trans));
75397591
ret = btrfs_commit_transaction(trans, root);
75407592
BUG_ON(ret);
75417593
}
@@ -7779,7 +7831,7 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,
77797831

77807832

77817833
trans = btrfs_start_transaction(extent_root, 1);
7782-
BUG_ON(!trans);
7834+
BUG_ON(IS_ERR(trans));
77837835

77847836
if (extent_key->objectid == 0) {
77857837
ret = del_extent_zero(trans, extent_root, path, extent_key);
@@ -8270,6 +8322,13 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
82708322
if (block_group->cached == BTRFS_CACHE_STARTED)
82718323
wait_block_group_cache_done(block_group);
82728324

8325+
/*
8326+
* We haven't cached this block group, which means we could
8327+
* possibly have excluded extents on this block group.
8328+
*/
8329+
if (block_group->cached == BTRFS_CACHE_NO)
8330+
free_excluded_extents(info->extent_root, block_group);
8331+
82738332
btrfs_remove_free_space_cache(block_group);
82748333
btrfs_put_block_group(block_group);
82758334

@@ -8384,6 +8443,13 @@ int btrfs_read_block_groups(struct btrfs_root *root)
83848443
cache->flags = btrfs_block_group_flags(&cache->item);
83858444
cache->sectorsize = root->sectorsize;
83868445

8446+
/*
8447+
* We need to exclude the super stripes now so that the space
8448+
* info has super bytes accounted for, otherwise we'll think
8449+
* we have more space than we actually do.
8450+
*/
8451+
exclude_super_stripes(root, cache);
8452+
83878453
/*
83888454
* check for two cases, either we are full, and therefore
83898455
* don't need to bother with the caching work since we won't
@@ -8392,12 +8458,10 @@ int btrfs_read_block_groups(struct btrfs_root *root)
83928458
* time, particularly in the full case.
83938459
*/
83948460
if (found_key.offset == btrfs_block_group_used(&cache->item)) {
8395-
exclude_super_stripes(root, cache);
83968461
cache->last_byte_to_unpin = (u64)-1;
83978462
cache->cached = BTRFS_CACHE_FINISHED;
83988463
free_excluded_extents(root, cache);
83998464
} else if (btrfs_block_group_used(&cache->item) == 0) {
8400-
exclude_super_stripes(root, cache);
84018465
cache->last_byte_to_unpin = (u64)-1;
84028466
cache->cached = BTRFS_CACHE_FINISHED;
84038467
add_new_free_space(cache, root->fs_info,

0 commit comments

Comments
 (0)