diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/acl.c | 12 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 32 | ||||
-rw-r--r-- | fs/btrfs/file.c | 100 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 12 | ||||
-rw-r--r-- | fs/btrfs/ordered-data.c | 2 | ||||
-rw-r--r-- | fs/btrfs/relocation.c | 4 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 4 |
7 files changed, 125 insertions, 41 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 2e9e69987a82..54f4798ab46a 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -112,12 +112,14 @@ static int btrfs_set_acl(struct btrfs_trans_handle *trans, | |||
112 | switch (type) { | 112 | switch (type) { |
113 | case ACL_TYPE_ACCESS: | 113 | case ACL_TYPE_ACCESS: |
114 | mode = inode->i_mode; | 114 | mode = inode->i_mode; |
115 | ret = posix_acl_equiv_mode(acl, &mode); | ||
116 | if (ret < 0) | ||
117 | return ret; | ||
118 | ret = 0; | ||
119 | inode->i_mode = mode; | ||
120 | name = POSIX_ACL_XATTR_ACCESS; | 115 | name = POSIX_ACL_XATTR_ACCESS; |
116 | if (acl) { | ||
117 | ret = posix_acl_equiv_mode(acl, &mode); | ||
118 | if (ret < 0) | ||
119 | return ret; | ||
120 | inode->i_mode = mode; | ||
121 | } | ||
122 | ret = 0; | ||
121 | break; | 123 | break; |
122 | case ACL_TYPE_DEFAULT: | 124 | case ACL_TYPE_DEFAULT: |
123 | if (!S_ISDIR(inode->i_mode)) | 125 | if (!S_ISDIR(inode->i_mode)) |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 56e50137d0e6..432a2da4641e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -83,6 +83,17 @@ static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) | |||
83 | return (cache->flags & bits) == bits; | 83 | return (cache->flags & bits) == bits; |
84 | } | 84 | } |
85 | 85 | ||
86 | void btrfs_get_block_group(struct btrfs_block_group_cache *cache) | ||
87 | { | ||
88 | atomic_inc(&cache->count); | ||
89 | } | ||
90 | |||
91 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache) | ||
92 | { | ||
93 | if (atomic_dec_and_test(&cache->count)) | ||
94 | kfree(cache); | ||
95 | } | ||
96 | |||
86 | /* | 97 | /* |
87 | * this adds the block group to the fs_info rb tree for the block group | 98 | * this adds the block group to the fs_info rb tree for the block group |
88 | * cache | 99 | * cache |
@@ -156,7 +167,7 @@ block_group_cache_tree_search(struct btrfs_fs_info *info, u64 bytenr, | |||
156 | } | 167 | } |
157 | } | 168 | } |
158 | if (ret) | 169 | if (ret) |
159 | atomic_inc(&ret->count); | 170 | btrfs_get_block_group(ret); |
160 | spin_unlock(&info->block_group_cache_lock); | 171 | spin_unlock(&info->block_group_cache_lock); |
161 | 172 | ||
162 | return ret; | 173 | return ret; |
@@ -407,6 +418,8 @@ err: | |||
407 | 418 | ||
408 | put_caching_control(caching_ctl); | 419 | put_caching_control(caching_ctl); |
409 | atomic_dec(&block_group->space_info->caching_threads); | 420 | atomic_dec(&block_group->space_info->caching_threads); |
421 | btrfs_put_block_group(block_group); | ||
422 | |||
410 | return 0; | 423 | return 0; |
411 | } | 424 | } |
412 | 425 | ||
@@ -447,6 +460,7 @@ static int cache_block_group(struct btrfs_block_group_cache *cache) | |||
447 | up_write(&fs_info->extent_commit_sem); | 460 | up_write(&fs_info->extent_commit_sem); |
448 | 461 | ||
449 | atomic_inc(&cache->space_info->caching_threads); | 462 | atomic_inc(&cache->space_info->caching_threads); |
463 | btrfs_get_block_group(cache); | ||
450 | 464 | ||
451 | tsk = kthread_run(caching_kthread, cache, "btrfs-cache-%llu\n", | 465 | tsk = kthread_run(caching_kthread, cache, "btrfs-cache-%llu\n", |
452 | cache->key.objectid); | 466 | cache->key.objectid); |
@@ -486,12 +500,6 @@ struct btrfs_block_group_cache *btrfs_lookup_block_group( | |||
486 | return cache; | 500 | return cache; |
487 | } | 501 | } |
488 | 502 | ||
489 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache) | ||
490 | { | ||
491 | if (atomic_dec_and_test(&cache->count)) | ||
492 | kfree(cache); | ||
493 | } | ||
494 | |||
495 | static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info, | 503 | static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info, |
496 | u64 flags) | 504 | u64 flags) |
497 | { | 505 | { |
@@ -2582,7 +2590,7 @@ next_block_group(struct btrfs_root *root, | |||
2582 | if (node) { | 2590 | if (node) { |
2583 | cache = rb_entry(node, struct btrfs_block_group_cache, | 2591 | cache = rb_entry(node, struct btrfs_block_group_cache, |
2584 | cache_node); | 2592 | cache_node); |
2585 | atomic_inc(&cache->count); | 2593 | btrfs_get_block_group(cache); |
2586 | } else | 2594 | } else |
2587 | cache = NULL; | 2595 | cache = NULL; |
2588 | spin_unlock(&root->fs_info->block_group_cache_lock); | 2596 | spin_unlock(&root->fs_info->block_group_cache_lock); |
@@ -4227,7 +4235,7 @@ search: | |||
4227 | u64 offset; | 4235 | u64 offset; |
4228 | int cached; | 4236 | int cached; |
4229 | 4237 | ||
4230 | atomic_inc(&block_group->count); | 4238 | btrfs_get_block_group(block_group); |
4231 | search_start = block_group->key.objectid; | 4239 | search_start = block_group->key.objectid; |
4232 | 4240 | ||
4233 | have_block_group: | 4241 | have_block_group: |
@@ -4315,7 +4323,7 @@ have_block_group: | |||
4315 | 4323 | ||
4316 | btrfs_put_block_group(block_group); | 4324 | btrfs_put_block_group(block_group); |
4317 | block_group = last_ptr->block_group; | 4325 | block_group = last_ptr->block_group; |
4318 | atomic_inc(&block_group->count); | 4326 | btrfs_get_block_group(block_group); |
4319 | spin_unlock(&last_ptr->lock); | 4327 | spin_unlock(&last_ptr->lock); |
4320 | spin_unlock(&last_ptr->refill_lock); | 4328 | spin_unlock(&last_ptr->refill_lock); |
4321 | 4329 | ||
@@ -7395,9 +7403,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) | |||
7395 | wait_block_group_cache_done(block_group); | 7403 | wait_block_group_cache_done(block_group); |
7396 | 7404 | ||
7397 | btrfs_remove_free_space_cache(block_group); | 7405 | btrfs_remove_free_space_cache(block_group); |
7398 | 7406 | btrfs_put_block_group(block_group); | |
7399 | WARN_ON(atomic_read(&block_group->count) != 1); | ||
7400 | kfree(block_group); | ||
7401 | 7407 | ||
7402 | spin_lock(&info->block_group_cache_lock); | 7408 | spin_lock(&info->block_group_cache_lock); |
7403 | } | 7409 | } |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index feaa13b105d9..c02033596f02 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -506,7 +506,8 @@ next_slot: | |||
506 | } | 506 | } |
507 | 507 | ||
508 | static int extent_mergeable(struct extent_buffer *leaf, int slot, | 508 | static int extent_mergeable(struct extent_buffer *leaf, int slot, |
509 | u64 objectid, u64 bytenr, u64 *start, u64 *end) | 509 | u64 objectid, u64 bytenr, u64 orig_offset, |
510 | u64 *start, u64 *end) | ||
510 | { | 511 | { |
511 | struct btrfs_file_extent_item *fi; | 512 | struct btrfs_file_extent_item *fi; |
512 | struct btrfs_key key; | 513 | struct btrfs_key key; |
@@ -522,6 +523,7 @@ static int extent_mergeable(struct extent_buffer *leaf, int slot, | |||
522 | fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item); | 523 | fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item); |
523 | if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG || | 524 | if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG || |
524 | btrfs_file_extent_disk_bytenr(leaf, fi) != bytenr || | 525 | btrfs_file_extent_disk_bytenr(leaf, fi) != bytenr || |
526 | btrfs_file_extent_offset(leaf, fi) != key.offset - orig_offset || | ||
525 | btrfs_file_extent_compression(leaf, fi) || | 527 | btrfs_file_extent_compression(leaf, fi) || |
526 | btrfs_file_extent_encryption(leaf, fi) || | 528 | btrfs_file_extent_encryption(leaf, fi) || |
527 | btrfs_file_extent_other_encoding(leaf, fi)) | 529 | btrfs_file_extent_other_encoding(leaf, fi)) |
@@ -561,6 +563,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | |||
561 | u64 split; | 563 | u64 split; |
562 | int del_nr = 0; | 564 | int del_nr = 0; |
563 | int del_slot = 0; | 565 | int del_slot = 0; |
566 | int recow; | ||
564 | int ret; | 567 | int ret; |
565 | 568 | ||
566 | btrfs_drop_extent_cache(inode, start, end - 1, 0); | 569 | btrfs_drop_extent_cache(inode, start, end - 1, 0); |
@@ -568,6 +571,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | |||
568 | path = btrfs_alloc_path(); | 571 | path = btrfs_alloc_path(); |
569 | BUG_ON(!path); | 572 | BUG_ON(!path); |
570 | again: | 573 | again: |
574 | recow = 0; | ||
571 | split = start; | 575 | split = start; |
572 | key.objectid = inode->i_ino; | 576 | key.objectid = inode->i_ino; |
573 | key.type = BTRFS_EXTENT_DATA_KEY; | 577 | key.type = BTRFS_EXTENT_DATA_KEY; |
@@ -591,12 +595,60 @@ again: | |||
591 | bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); | 595 | bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); |
592 | num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); | 596 | num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); |
593 | orig_offset = key.offset - btrfs_file_extent_offset(leaf, fi); | 597 | orig_offset = key.offset - btrfs_file_extent_offset(leaf, fi); |
598 | memcpy(&new_key, &key, sizeof(new_key)); | ||
599 | |||
600 | if (start == key.offset && end < extent_end) { | ||
601 | other_start = 0; | ||
602 | other_end = start; | ||
603 | if (extent_mergeable(leaf, path->slots[0] - 1, | ||
604 | inode->i_ino, bytenr, orig_offset, | ||
605 | &other_start, &other_end)) { | ||
606 | new_key.offset = end; | ||
607 | btrfs_set_item_key_safe(trans, root, path, &new_key); | ||
608 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
609 | struct btrfs_file_extent_item); | ||
610 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
611 | extent_end - end); | ||
612 | btrfs_set_file_extent_offset(leaf, fi, | ||
613 | end - orig_offset); | ||
614 | fi = btrfs_item_ptr(leaf, path->slots[0] - 1, | ||
615 | struct btrfs_file_extent_item); | ||
616 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
617 | end - other_start); | ||
618 | btrfs_mark_buffer_dirty(leaf); | ||
619 | goto out; | ||
620 | } | ||
621 | } | ||
622 | |||
623 | if (start > key.offset && end == extent_end) { | ||
624 | other_start = end; | ||
625 | other_end = 0; | ||
626 | if (extent_mergeable(leaf, path->slots[0] + 1, | ||
627 | inode->i_ino, bytenr, orig_offset, | ||
628 | &other_start, &other_end)) { | ||
629 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
630 | struct btrfs_file_extent_item); | ||
631 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
632 | start - key.offset); | ||
633 | path->slots[0]++; | ||
634 | new_key.offset = start; | ||
635 | btrfs_set_item_key_safe(trans, root, path, &new_key); | ||
636 | |||
637 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
638 | struct btrfs_file_extent_item); | ||
639 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
640 | other_end - start); | ||
641 | btrfs_set_file_extent_offset(leaf, fi, | ||
642 | start - orig_offset); | ||
643 | btrfs_mark_buffer_dirty(leaf); | ||
644 | goto out; | ||
645 | } | ||
646 | } | ||
594 | 647 | ||
595 | while (start > key.offset || end < extent_end) { | 648 | while (start > key.offset || end < extent_end) { |
596 | if (key.offset == start) | 649 | if (key.offset == start) |
597 | split = end; | 650 | split = end; |
598 | 651 | ||
599 | memcpy(&new_key, &key, sizeof(new_key)); | ||
600 | new_key.offset = split; | 652 | new_key.offset = split; |
601 | ret = btrfs_duplicate_item(trans, root, path, &new_key); | 653 | ret = btrfs_duplicate_item(trans, root, path, &new_key); |
602 | if (ret == -EAGAIN) { | 654 | if (ret == -EAGAIN) { |
@@ -631,15 +683,18 @@ again: | |||
631 | path->slots[0]--; | 683 | path->slots[0]--; |
632 | extent_end = end; | 684 | extent_end = end; |
633 | } | 685 | } |
686 | recow = 1; | ||
634 | } | 687 | } |
635 | 688 | ||
636 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
637 | struct btrfs_file_extent_item); | ||
638 | |||
639 | other_start = end; | 689 | other_start = end; |
640 | other_end = 0; | 690 | other_end = 0; |
641 | if (extent_mergeable(leaf, path->slots[0] + 1, inode->i_ino, | 691 | if (extent_mergeable(leaf, path->slots[0] + 1, |
642 | bytenr, &other_start, &other_end)) { | 692 | inode->i_ino, bytenr, orig_offset, |
693 | &other_start, &other_end)) { | ||
694 | if (recow) { | ||
695 | btrfs_release_path(root, path); | ||
696 | goto again; | ||
697 | } | ||
643 | extent_end = other_end; | 698 | extent_end = other_end; |
644 | del_slot = path->slots[0] + 1; | 699 | del_slot = path->slots[0] + 1; |
645 | del_nr++; | 700 | del_nr++; |
@@ -650,8 +705,13 @@ again: | |||
650 | } | 705 | } |
651 | other_start = 0; | 706 | other_start = 0; |
652 | other_end = start; | 707 | other_end = start; |
653 | if (extent_mergeable(leaf, path->slots[0] - 1, inode->i_ino, | 708 | if (extent_mergeable(leaf, path->slots[0] - 1, |
654 | bytenr, &other_start, &other_end)) { | 709 | inode->i_ino, bytenr, orig_offset, |
710 | &other_start, &other_end)) { | ||
711 | if (recow) { | ||
712 | btrfs_release_path(root, path); | ||
713 | goto again; | ||
714 | } | ||
655 | key.offset = other_start; | 715 | key.offset = other_start; |
656 | del_slot = path->slots[0]; | 716 | del_slot = path->slots[0]; |
657 | del_nr++; | 717 | del_nr++; |
@@ -660,22 +720,22 @@ again: | |||
660 | inode->i_ino, orig_offset); | 720 | inode->i_ino, orig_offset); |
661 | BUG_ON(ret); | 721 | BUG_ON(ret); |
662 | } | 722 | } |
723 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
724 | struct btrfs_file_extent_item); | ||
663 | if (del_nr == 0) { | 725 | if (del_nr == 0) { |
664 | btrfs_set_file_extent_type(leaf, fi, | 726 | btrfs_set_file_extent_type(leaf, fi, |
665 | BTRFS_FILE_EXTENT_REG); | 727 | BTRFS_FILE_EXTENT_REG); |
666 | btrfs_mark_buffer_dirty(leaf); | 728 | btrfs_mark_buffer_dirty(leaf); |
667 | goto out; | 729 | } else { |
668 | } | 730 | btrfs_set_file_extent_type(leaf, fi, |
669 | 731 | BTRFS_FILE_EXTENT_REG); | |
670 | fi = btrfs_item_ptr(leaf, del_slot - 1, | 732 | btrfs_set_file_extent_num_bytes(leaf, fi, |
671 | struct btrfs_file_extent_item); | 733 | extent_end - key.offset); |
672 | btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); | 734 | btrfs_mark_buffer_dirty(leaf); |
673 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
674 | extent_end - key.offset); | ||
675 | btrfs_mark_buffer_dirty(leaf); | ||
676 | 735 | ||
677 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); | 736 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); |
678 | BUG_ON(ret); | 737 | BUG_ON(ret); |
738 | } | ||
679 | out: | 739 | out: |
680 | btrfs_free_path(path); | 740 | btrfs_free_path(path); |
681 | return 0; | 741 | return 0; |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5440bab23635..b330e27c2d8b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -3796,6 +3796,12 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3796 | 3796 | ||
3797 | if (location.type == BTRFS_INODE_ITEM_KEY) { | 3797 | if (location.type == BTRFS_INODE_ITEM_KEY) { |
3798 | inode = btrfs_iget(dir->i_sb, &location, root); | 3798 | inode = btrfs_iget(dir->i_sb, &location, root); |
3799 | if (unlikely(root->clean_orphans) && | ||
3800 | !(inode->i_sb->s_flags & MS_RDONLY)) { | ||
3801 | down_read(&root->fs_info->cleanup_work_sem); | ||
3802 | btrfs_orphan_cleanup(root); | ||
3803 | up_read(&root->fs_info->cleanup_work_sem); | ||
3804 | } | ||
3799 | return inode; | 3805 | return inode; |
3800 | } | 3806 | } |
3801 | 3807 | ||
@@ -3995,7 +4001,11 @@ skip: | |||
3995 | 4001 | ||
3996 | /* Reached end of directory/root. Bump pos past the last item. */ | 4002 | /* Reached end of directory/root. Bump pos past the last item. */ |
3997 | if (key_type == BTRFS_DIR_INDEX_KEY) | 4003 | if (key_type == BTRFS_DIR_INDEX_KEY) |
3998 | filp->f_pos = INT_LIMIT(off_t); | 4004 | /* |
4005 | * 32-bit glibc will use getdents64, but then strtol - | ||
4006 | * so the last number we can serve is this. | ||
4007 | */ | ||
4008 | filp->f_pos = 0x7fffffff; | ||
3999 | else | 4009 | else |
4000 | filp->f_pos++; | 4010 | filp->f_pos++; |
4001 | nopos: | 4011 | nopos: |
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index b10a49d4bc6a..5c2a9e78a949 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -626,6 +626,8 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, | |||
626 | 626 | ||
627 | if (ordered) | 627 | if (ordered) |
628 | offset = entry_end(ordered); | 628 | offset = entry_end(ordered); |
629 | else | ||
630 | offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize); | ||
629 | 631 | ||
630 | mutex_lock(&tree->mutex); | 632 | mutex_lock(&tree->mutex); |
631 | disk_i_size = BTRFS_I(inode)->disk_i_size; | 633 | disk_i_size = BTRFS_I(inode)->disk_i_size; |
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index a9728680eca8..ed3e4a2ec2c8 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -3281,8 +3281,10 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) | |||
3281 | return -ENOMEM; | 3281 | return -ENOMEM; |
3282 | 3282 | ||
3283 | path = btrfs_alloc_path(); | 3283 | path = btrfs_alloc_path(); |
3284 | if (!path) | 3284 | if (!path) { |
3285 | kfree(cluster); | ||
3285 | return -ENOMEM; | 3286 | return -ENOMEM; |
3287 | } | ||
3286 | 3288 | ||
3287 | rc->extents_found = 0; | 3289 | rc->extents_found = 0; |
3288 | rc->extents_skipped = 0; | 3290 | rc->extents_skipped = 0; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 198cff28766d..220dad5db017 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -2649,8 +2649,10 @@ again: | |||
2649 | em = lookup_extent_mapping(em_tree, logical, *length); | 2649 | em = lookup_extent_mapping(em_tree, logical, *length); |
2650 | read_unlock(&em_tree->lock); | 2650 | read_unlock(&em_tree->lock); |
2651 | 2651 | ||
2652 | if (!em && unplug_page) | 2652 | if (!em && unplug_page) { |
2653 | kfree(multi); | ||
2653 | return 0; | 2654 | return 0; |
2655 | } | ||
2654 | 2656 | ||
2655 | if (!em) { | 2657 | if (!em) { |
2656 | printk(KERN_CRIT "unable to find logical %llu len %llu\n", | 2658 | printk(KERN_CRIT "unable to find logical %llu len %llu\n", |