Commit 67f15b06c1a7e5417b7042b515ca2695de30beda

Authored by Linus Torvalds

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:
  Btrfs: check total number of devices when removing missing
  Btrfs: check return value of open_bdev_exclusive properly
  Btrfs: do not mark the chunk as readonly if in degraded mode
  Btrfs: run orphan cleanup on default fs root
  Btrfs: fix a memory leak in btrfs_init_acl
  Btrfs: Use correct values when updating inode i_size on fallocate
  Btrfs: remove tree_search() in extent_map.c
  Btrfs: Add mount -o compress-force

Showing 7 changed files Side-by-side Diff

... ... @@ -244,6 +244,7 @@
244 244 ACL_TYPE_ACCESS);
245 245 }
246 246 }
  247 + posix_acl_release(clone);
247 248 }
248 249 failed:
249 250 posix_acl_release(acl);
... ... @@ -1161,6 +1161,7 @@
1161 1161 #define BTRFS_MOUNT_SSD_SPREAD (1 << 8)
1162 1162 #define BTRFS_MOUNT_NOSSD (1 << 9)
1163 1163 #define BTRFS_MOUNT_DISCARD (1 << 10)
  1164 +#define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
1164 1165  
1165 1166 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1166 1167 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
... ... @@ -1993,6 +1993,12 @@
1993 1993 if (!fs_info->fs_root)
1994 1994 goto fail_trans_kthread;
1995 1995  
  1996 + if (!(sb->s_flags & MS_RDONLY)) {
  1997 + down_read(&fs_info->cleanup_work_sem);
  1998 + btrfs_orphan_cleanup(fs_info->fs_root);
  1999 + up_read(&fs_info->cleanup_work_sem);
  2000 + }
  2001 +
1996 2002 return tree_root;
1997 2003  
1998 2004 fail_trans_kthread:
fs/btrfs/extent_map.c
... ... @@ -155,20 +155,6 @@
155 155 return NULL;
156 156 }
157 157  
158   -/*
159   - * look for an offset in the tree, and if it can't be found, return
160   - * the first offset we can find smaller than 'offset'.
161   - */
162   -static inline struct rb_node *tree_search(struct rb_root *root, u64 offset)
163   -{
164   - struct rb_node *prev;
165   - struct rb_node *ret;
166   - ret = __tree_search(root, offset, &prev, NULL);
167   - if (!ret)
168   - return prev;
169   - return ret;
170   -}
171   -
172 158 /* check to see if two extent_map structs are adjacent and safe to merge */
173 159 static int mergable_maps(struct extent_map *prev, struct extent_map *next)
174 160 {
... ... @@ -483,7 +483,8 @@
483 483 nr_pages_ret = 0;
484 484  
485 485 /* flag the file so we don't compress in the future */
486   - BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
  486 + if (!btrfs_test_opt(root, FORCE_COMPRESS))
  487 + BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
487 488 }
488 489 if (will_compress) {
489 490 *num_added += 1;
... ... @@ -3796,12 +3797,6 @@
3796 3797  
3797 3798 if (location.type == BTRFS_INODE_ITEM_KEY) {
3798 3799 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   - }
3805 3800 return inode;
3806 3801 }
3807 3802  
... ... @@ -5799,7 +5794,7 @@
5799 5794 }
5800 5795  
5801 5796 static int prealloc_file_range(struct inode *inode, u64 start, u64 end,
5802   - u64 alloc_hint, int mode)
  5797 + u64 alloc_hint, int mode, loff_t actual_len)
5803 5798 {
5804 5799 struct btrfs_trans_handle *trans;
5805 5800 struct btrfs_root *root = BTRFS_I(inode)->root;
... ... @@ -5808,6 +5803,7 @@
5808 5803 u64 cur_offset = start;
5809 5804 u64 num_bytes = end - start;
5810 5805 int ret = 0;
  5806 + u64 i_size;
5811 5807  
5812 5808 while (num_bytes > 0) {
5813 5809 alloc_size = min(num_bytes, root->fs_info->max_extent);
... ... @@ -5846,8 +5842,12 @@
5846 5842 BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC;
5847 5843 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
5848 5844 cur_offset > inode->i_size) {
5849   - i_size_write(inode, cur_offset);
5850   - btrfs_ordered_update_i_size(inode, cur_offset, NULL);
  5845 + if (cur_offset > actual_len)
  5846 + i_size = actual_len;
  5847 + else
  5848 + i_size = cur_offset;
  5849 + i_size_write(inode, i_size);
  5850 + btrfs_ordered_update_i_size(inode, i_size, NULL);
5851 5851 }
5852 5852  
5853 5853 ret = btrfs_update_inode(trans, root, inode);
... ... @@ -5940,7 +5940,7 @@
5940 5940 !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) {
5941 5941 ret = prealloc_file_range(inode,
5942 5942 cur_offset, last_byte,
5943   - alloc_hint, mode);
  5943 + alloc_hint, mode, offset+len);
5944 5944 if (ret < 0) {
5945 5945 free_extent_map(em);
5946 5946 break;
... ... @@ -66,7 +66,8 @@
66 66 Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow,
67 67 Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
68 68 Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
69   - Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
  69 + Opt_compress, Opt_compress_force, Opt_notreelog, Opt_ratio,
  70 + Opt_flushoncommit,
70 71 Opt_discard, Opt_err,
71 72 };
72 73  
... ... @@ -82,6 +83,7 @@
82 83 {Opt_alloc_start, "alloc_start=%s"},
83 84 {Opt_thread_pool, "thread_pool=%d"},
84 85 {Opt_compress, "compress"},
  86 + {Opt_compress_force, "compress-force"},
85 87 {Opt_ssd, "ssd"},
86 88 {Opt_ssd_spread, "ssd_spread"},
87 89 {Opt_nossd, "nossd"},
... ... @@ -171,6 +173,11 @@
171 173 break;
172 174 case Opt_compress:
173 175 printk(KERN_INFO "btrfs: use compression\n");
  176 + btrfs_set_opt(info->mount_opt, COMPRESS);
  177 + break;
  178 + case Opt_compress_force:
  179 + printk(KERN_INFO "btrfs: forcing compression\n");
  180 + btrfs_set_opt(info->mount_opt, FORCE_COMPRESS);
174 181 btrfs_set_opt(info->mount_opt, COMPRESS);
175 182 break;
176 183 case Opt_ssd:
... ... @@ -1135,7 +1135,7 @@
1135 1135 root->fs_info->avail_metadata_alloc_bits;
1136 1136  
1137 1137 if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) &&
1138   - root->fs_info->fs_devices->rw_devices <= 4) {
  1138 + root->fs_info->fs_devices->num_devices <= 4) {
1139 1139 printk(KERN_ERR "btrfs: unable to go below four devices "
1140 1140 "on raid10\n");
1141 1141 ret = -EINVAL;
... ... @@ -1143,7 +1143,7 @@
1143 1143 }
1144 1144  
1145 1145 if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) &&
1146   - root->fs_info->fs_devices->rw_devices <= 2) {
  1146 + root->fs_info->fs_devices->num_devices <= 2) {
1147 1147 printk(KERN_ERR "btrfs: unable to go below two "
1148 1148 "devices on raid1\n");
1149 1149 ret = -EINVAL;
... ... @@ -1434,8 +1434,8 @@
1434 1434 return -EINVAL;
1435 1435  
1436 1436 bdev = open_bdev_exclusive(device_path, 0, root->fs_info->bdev_holder);
1437   - if (!bdev)
1438   - return -EIO;
  1437 + if (IS_ERR(bdev))
  1438 + return PTR_ERR(bdev);
1439 1439  
1440 1440 if (root->fs_info->fs_devices->seeding) {
1441 1441 seeding_dev = 1;
... ... @@ -2537,6 +2537,11 @@
2537 2537 read_unlock(&map_tree->map_tree.lock);
2538 2538 if (!em)
2539 2539 return 1;
  2540 +
  2541 + if (btrfs_test_opt(root, DEGRADED)) {
  2542 + free_extent_map(em);
  2543 + return 0;
  2544 + }
2540 2545  
2541 2546 map = (struct map_lookup *)em->bdev;
2542 2547 for (i = 0; i < map->num_stripes; i++) {