diff options
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/Makefile | 19 | ||||
-rw-r--r-- | fs/btrfs/acl.c | 18 | ||||
-rw-r--r-- | fs/btrfs/ctree.c | 39 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 6 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 95 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 102 | ||||
-rw-r--r-- | fs/btrfs/extent_io.c | 81 | ||||
-rw-r--r-- | fs/btrfs/extent_map.c | 17 | ||||
-rw-r--r-- | fs/btrfs/file.c | 89 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 15 | ||||
-rw-r--r-- | fs/btrfs/inode-map.c | 2 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 149 | ||||
-rw-r--r-- | fs/btrfs/ioctl.c | 13 | ||||
-rw-r--r-- | fs/btrfs/super.c | 43 | ||||
-rw-r--r-- | fs/btrfs/transaction.c | 6 | ||||
-rw-r--r-- | fs/btrfs/tree-log.c | 2 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 36 | ||||
-rw-r--r-- | fs/btrfs/volumes.h | 3 |
18 files changed, 374 insertions, 361 deletions
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 9adf5e4f7e96..94212844a9bc 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile | |||
@@ -1,25 +1,10 @@ | |||
1 | ifneq ($(KERNELRELEASE),) | ||
2 | # kbuild part of makefile | ||
3 | 1 | ||
4 | obj-$(CONFIG_BTRFS_FS) := btrfs.o | 2 | obj-$(CONFIG_BTRFS_FS) := btrfs.o |
5 | btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ | 3 | |
4 | btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ | ||
6 | file-item.o inode-item.o inode-map.o disk-io.o \ | 5 | file-item.o inode-item.o inode-map.o disk-io.o \ |
7 | transaction.o inode.o file.o tree-defrag.o \ | 6 | transaction.o inode.o file.o tree-defrag.o \ |
8 | extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ | 7 | extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ |
9 | extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ | 8 | extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ |
10 | ref-cache.o export.o tree-log.o acl.o free-space-cache.o zlib.o \ | 9 | ref-cache.o export.o tree-log.o acl.o free-space-cache.o zlib.o \ |
11 | compression.o delayed-ref.o | 10 | compression.o delayed-ref.o |
12 | else | ||
13 | |||
14 | # Normal Makefile | ||
15 | |||
16 | KERNELDIR := /lib/modules/`uname -r`/build | ||
17 | all: | ||
18 | $(MAKE) -C $(KERNELDIR) M=`pwd` CONFIG_BTRFS_FS=m modules | ||
19 | |||
20 | modules_install: | ||
21 | $(MAKE) -C $(KERNELDIR) M=`pwd` modules_install | ||
22 | clean: | ||
23 | $(MAKE) -C $(KERNELDIR) M=`pwd` clean | ||
24 | |||
25 | endif | ||
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 7fdd184a528d..cbba000dccbe 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -60,15 +60,20 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | |||
60 | return ERR_PTR(-EINVAL); | 60 | return ERR_PTR(-EINVAL); |
61 | } | 61 | } |
62 | 62 | ||
63 | /* Handle the cached NULL acl case without locking */ | ||
64 | acl = ACCESS_ONCE(*p_acl); | ||
65 | if (!acl) | ||
66 | return acl; | ||
67 | |||
63 | spin_lock(&inode->i_lock); | 68 | spin_lock(&inode->i_lock); |
64 | if (*p_acl != BTRFS_ACL_NOT_CACHED) | 69 | acl = *p_acl; |
65 | acl = posix_acl_dup(*p_acl); | 70 | if (acl != BTRFS_ACL_NOT_CACHED) |
71 | acl = posix_acl_dup(acl); | ||
66 | spin_unlock(&inode->i_lock); | 72 | spin_unlock(&inode->i_lock); |
67 | 73 | ||
68 | if (acl) | 74 | if (acl != BTRFS_ACL_NOT_CACHED) |
69 | return acl; | 75 | return acl; |
70 | 76 | ||
71 | |||
72 | size = __btrfs_getxattr(inode, name, "", 0); | 77 | size = __btrfs_getxattr(inode, name, "", 0); |
73 | if (size > 0) { | 78 | if (size > 0) { |
74 | value = kzalloc(size, GFP_NOFS); | 79 | value = kzalloc(size, GFP_NOFS); |
@@ -80,9 +85,12 @@ static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | |||
80 | btrfs_update_cached_acl(inode, p_acl, acl); | 85 | btrfs_update_cached_acl(inode, p_acl, acl); |
81 | } | 86 | } |
82 | kfree(value); | 87 | kfree(value); |
83 | } else if (size == -ENOENT) { | 88 | } else if (size == -ENOENT || size == -ENODATA || size == 0) { |
89 | /* FIXME, who returns -ENOENT? I think nobody */ | ||
84 | acl = NULL; | 90 | acl = NULL; |
85 | btrfs_update_cached_acl(inode, p_acl, acl); | 91 | btrfs_update_cached_acl(inode, p_acl, acl); |
92 | } else { | ||
93 | acl = ERR_PTR(-EIO); | ||
86 | } | 94 | } |
87 | 95 | ||
88 | return acl; | 96 | return acl; |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index a99f1c2a710d..fedf8b9f03a2 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1469,6 +1469,7 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
1469 | u32 blocksize; | 1469 | u32 blocksize; |
1470 | struct extent_buffer *b = *eb_ret; | 1470 | struct extent_buffer *b = *eb_ret; |
1471 | struct extent_buffer *tmp; | 1471 | struct extent_buffer *tmp; |
1472 | int ret; | ||
1472 | 1473 | ||
1473 | blocknr = btrfs_node_blockptr(b, slot); | 1474 | blocknr = btrfs_node_blockptr(b, slot); |
1474 | gen = btrfs_node_ptr_generation(b, slot); | 1475 | gen = btrfs_node_ptr_generation(b, slot); |
@@ -1476,6 +1477,10 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
1476 | 1477 | ||
1477 | tmp = btrfs_find_tree_block(root, blocknr, blocksize); | 1478 | tmp = btrfs_find_tree_block(root, blocknr, blocksize); |
1478 | if (tmp && btrfs_buffer_uptodate(tmp, gen)) { | 1479 | if (tmp && btrfs_buffer_uptodate(tmp, gen)) { |
1480 | /* | ||
1481 | * we found an up to date block without sleeping, return | ||
1482 | * right away | ||
1483 | */ | ||
1479 | *eb_ret = tmp; | 1484 | *eb_ret = tmp; |
1480 | return 0; | 1485 | return 0; |
1481 | } | 1486 | } |
@@ -1483,7 +1488,9 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
1483 | /* | 1488 | /* |
1484 | * reduce lock contention at high levels | 1489 | * reduce lock contention at high levels |
1485 | * of the btree by dropping locks before | 1490 | * of the btree by dropping locks before |
1486 | * we read. | 1491 | * we read. Don't release the lock on the current |
1492 | * level because we need to walk this node to figure | ||
1493 | * out which blocks to read. | ||
1487 | */ | 1494 | */ |
1488 | btrfs_unlock_up_safe(p, level + 1); | 1495 | btrfs_unlock_up_safe(p, level + 1); |
1489 | btrfs_set_path_blocking(p); | 1496 | btrfs_set_path_blocking(p); |
@@ -1494,10 +1501,21 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
1494 | reada_for_search(root, p, level, slot, key->objectid); | 1501 | reada_for_search(root, p, level, slot, key->objectid); |
1495 | 1502 | ||
1496 | btrfs_release_path(NULL, p); | 1503 | btrfs_release_path(NULL, p); |
1504 | |||
1505 | ret = -EAGAIN; | ||
1497 | tmp = read_tree_block(root, blocknr, blocksize, gen); | 1506 | tmp = read_tree_block(root, blocknr, blocksize, gen); |
1498 | if (tmp) | 1507 | if (tmp) { |
1508 | /* | ||
1509 | * If the read above didn't mark this buffer up to date, | ||
1510 | * it will never end up being up to date. Set ret to EIO now | ||
1511 | * and give up so that our caller doesn't loop forever | ||
1512 | * on our EAGAINs. | ||
1513 | */ | ||
1514 | if (!btrfs_buffer_uptodate(tmp, 0)) | ||
1515 | ret = -EIO; | ||
1499 | free_extent_buffer(tmp); | 1516 | free_extent_buffer(tmp); |
1500 | return -EAGAIN; | 1517 | } |
1518 | return ret; | ||
1501 | } | 1519 | } |
1502 | 1520 | ||
1503 | /* | 1521 | /* |
@@ -1696,6 +1714,9 @@ cow_done: | |||
1696 | if (ret == -EAGAIN) | 1714 | if (ret == -EAGAIN) |
1697 | goto again; | 1715 | goto again; |
1698 | 1716 | ||
1717 | if (ret == -EIO) | ||
1718 | goto done; | ||
1719 | |||
1699 | if (!p->skip_locking) { | 1720 | if (!p->skip_locking) { |
1700 | int lret; | 1721 | int lret; |
1701 | 1722 | ||
@@ -1738,6 +1759,8 @@ done: | |||
1738 | */ | 1759 | */ |
1739 | if (!p->leave_spinning) | 1760 | if (!p->leave_spinning) |
1740 | btrfs_set_path_blocking(p); | 1761 | btrfs_set_path_blocking(p); |
1762 | if (ret < 0) | ||
1763 | btrfs_release_path(root, p); | ||
1741 | return ret; | 1764 | return ret; |
1742 | } | 1765 | } |
1743 | 1766 | ||
@@ -4212,6 +4235,11 @@ again: | |||
4212 | if (ret == -EAGAIN) | 4235 | if (ret == -EAGAIN) |
4213 | goto again; | 4236 | goto again; |
4214 | 4237 | ||
4238 | if (ret < 0) { | ||
4239 | btrfs_release_path(root, path); | ||
4240 | goto done; | ||
4241 | } | ||
4242 | |||
4215 | if (!path->skip_locking) { | 4243 | if (!path->skip_locking) { |
4216 | ret = btrfs_try_spin_lock(next); | 4244 | ret = btrfs_try_spin_lock(next); |
4217 | if (!ret) { | 4245 | if (!ret) { |
@@ -4246,6 +4274,11 @@ again: | |||
4246 | if (ret == -EAGAIN) | 4274 | if (ret == -EAGAIN) |
4247 | goto again; | 4275 | goto again; |
4248 | 4276 | ||
4277 | if (ret < 0) { | ||
4278 | btrfs_release_path(root, path); | ||
4279 | goto done; | ||
4280 | } | ||
4281 | |||
4249 | if (!path->skip_locking) { | 4282 | if (!path->skip_locking) { |
4250 | btrfs_assert_tree_locked(path->nodes[level]); | 4283 | btrfs_assert_tree_locked(path->nodes[level]); |
4251 | ret = btrfs_try_spin_lock(next); | 4284 | ret = btrfs_try_spin_lock(next); |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index ad96495dedc5..4414a5d9983a 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -881,6 +881,9 @@ struct btrfs_fs_info { | |||
881 | u64 metadata_alloc_profile; | 881 | u64 metadata_alloc_profile; |
882 | u64 system_alloc_profile; | 882 | u64 system_alloc_profile; |
883 | 883 | ||
884 | unsigned data_chunk_allocations; | ||
885 | unsigned metadata_ratio; | ||
886 | |||
884 | void *bdev_holder; | 887 | void *bdev_holder; |
885 | }; | 888 | }; |
886 | 889 | ||
@@ -2174,7 +2177,8 @@ int btrfs_check_file(struct btrfs_root *root, struct inode *inode); | |||
2174 | extern struct file_operations btrfs_file_operations; | 2177 | extern struct file_operations btrfs_file_operations; |
2175 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, | 2178 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, |
2176 | struct btrfs_root *root, struct inode *inode, | 2179 | struct btrfs_root *root, struct inode *inode, |
2177 | u64 start, u64 end, u64 inline_limit, u64 *hint_block); | 2180 | u64 start, u64 end, u64 locked_end, |
2181 | u64 inline_limit, u64 *hint_block); | ||
2178 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | 2182 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, |
2179 | struct btrfs_root *root, | 2183 | struct btrfs_root *root, |
2180 | struct inode *inode, u64 start, u64 end); | 2184 | struct inode *inode, u64 start, u64 end); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index a6b83744b05d..4b0ea0b80c23 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -232,10 +232,14 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | |||
232 | memcpy(&found, result, csum_size); | 232 | memcpy(&found, result, csum_size); |
233 | 233 | ||
234 | read_extent_buffer(buf, &val, 0, csum_size); | 234 | read_extent_buffer(buf, &val, 0, csum_size); |
235 | printk(KERN_INFO "btrfs: %s checksum verify failed " | 235 | if (printk_ratelimit()) { |
236 | "on %llu wanted %X found %X level %d\n", | 236 | printk(KERN_INFO "btrfs: %s checksum verify " |
237 | root->fs_info->sb->s_id, | 237 | "failed on %llu wanted %X found %X " |
238 | buf->start, val, found, btrfs_header_level(buf)); | 238 | "level %d\n", |
239 | root->fs_info->sb->s_id, | ||
240 | (unsigned long long)buf->start, val, found, | ||
241 | btrfs_header_level(buf)); | ||
242 | } | ||
239 | if (result != (char *)&inline_result) | 243 | if (result != (char *)&inline_result) |
240 | kfree(result); | 244 | kfree(result); |
241 | return 1; | 245 | return 1; |
@@ -268,10 +272,13 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
268 | ret = 0; | 272 | ret = 0; |
269 | goto out; | 273 | goto out; |
270 | } | 274 | } |
271 | printk("parent transid verify failed on %llu wanted %llu found %llu\n", | 275 | if (printk_ratelimit()) { |
272 | (unsigned long long)eb->start, | 276 | printk("parent transid verify failed on %llu wanted %llu " |
273 | (unsigned long long)parent_transid, | 277 | "found %llu\n", |
274 | (unsigned long long)btrfs_header_generation(eb)); | 278 | (unsigned long long)eb->start, |
279 | (unsigned long long)parent_transid, | ||
280 | (unsigned long long)btrfs_header_generation(eb)); | ||
281 | } | ||
275 | ret = 1; | 282 | ret = 1; |
276 | clear_extent_buffer_uptodate(io_tree, eb); | 283 | clear_extent_buffer_uptodate(io_tree, eb); |
277 | out: | 284 | out: |
@@ -415,9 +422,12 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
415 | 422 | ||
416 | found_start = btrfs_header_bytenr(eb); | 423 | found_start = btrfs_header_bytenr(eb); |
417 | if (found_start != start) { | 424 | if (found_start != start) { |
418 | printk(KERN_INFO "btrfs bad tree block start %llu %llu\n", | 425 | if (printk_ratelimit()) { |
419 | (unsigned long long)found_start, | 426 | printk(KERN_INFO "btrfs bad tree block start " |
420 | (unsigned long long)eb->start); | 427 | "%llu %llu\n", |
428 | (unsigned long long)found_start, | ||
429 | (unsigned long long)eb->start); | ||
430 | } | ||
421 | ret = -EIO; | 431 | ret = -EIO; |
422 | goto err; | 432 | goto err; |
423 | } | 433 | } |
@@ -429,8 +439,10 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
429 | goto err; | 439 | goto err; |
430 | } | 440 | } |
431 | if (check_tree_block_fsid(root, eb)) { | 441 | if (check_tree_block_fsid(root, eb)) { |
432 | printk(KERN_INFO "btrfs bad fsid on block %llu\n", | 442 | if (printk_ratelimit()) { |
433 | (unsigned long long)eb->start); | 443 | printk(KERN_INFO "btrfs bad fsid on block %llu\n", |
444 | (unsigned long long)eb->start); | ||
445 | } | ||
434 | ret = -EIO; | 446 | ret = -EIO; |
435 | goto err; | 447 | goto err; |
436 | } | 448 | } |
@@ -584,18 +596,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | |||
584 | btrfs_set_work_high_prio(&async->work); | 596 | btrfs_set_work_high_prio(&async->work); |
585 | 597 | ||
586 | btrfs_queue_worker(&fs_info->workers, &async->work); | 598 | btrfs_queue_worker(&fs_info->workers, &async->work); |
587 | #if 0 | ||
588 | int limit = btrfs_async_submit_limit(fs_info); | ||
589 | if (atomic_read(&fs_info->nr_async_submits) > limit) { | ||
590 | wait_event_timeout(fs_info->async_submit_wait, | ||
591 | (atomic_read(&fs_info->nr_async_submits) < limit), | ||
592 | HZ/10); | ||
593 | 599 | ||
594 | wait_event_timeout(fs_info->async_submit_wait, | ||
595 | (atomic_read(&fs_info->nr_async_bios) < limit), | ||
596 | HZ/10); | ||
597 | } | ||
598 | #endif | ||
599 | while (atomic_read(&fs_info->async_submit_draining) && | 600 | while (atomic_read(&fs_info->async_submit_draining) && |
600 | atomic_read(&fs_info->nr_async_submits)) { | 601 | atomic_read(&fs_info->nr_async_submits)) { |
601 | wait_event(fs_info->async_submit_wait, | 602 | wait_event(fs_info->async_submit_wait, |
@@ -770,27 +771,6 @@ static void btree_invalidatepage(struct page *page, unsigned long offset) | |||
770 | } | 771 | } |
771 | } | 772 | } |
772 | 773 | ||
773 | #if 0 | ||
774 | static int btree_writepage(struct page *page, struct writeback_control *wbc) | ||
775 | { | ||
776 | struct buffer_head *bh; | ||
777 | struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; | ||
778 | struct buffer_head *head; | ||
779 | if (!page_has_buffers(page)) { | ||
780 | create_empty_buffers(page, root->fs_info->sb->s_blocksize, | ||
781 | (1 << BH_Dirty)|(1 << BH_Uptodate)); | ||
782 | } | ||
783 | head = page_buffers(page); | ||
784 | bh = head; | ||
785 | do { | ||
786 | if (buffer_dirty(bh)) | ||
787 | csum_tree_block(root, bh, 0); | ||
788 | bh = bh->b_this_page; | ||
789 | } while (bh != head); | ||
790 | return block_write_full_page(page, btree_get_block, wbc); | ||
791 | } | ||
792 | #endif | ||
793 | |||
794 | static struct address_space_operations btree_aops = { | 774 | static struct address_space_operations btree_aops = { |
795 | .readpage = btree_readpage, | 775 | .readpage = btree_readpage, |
796 | .writepage = btree_writepage, | 776 | .writepage = btree_writepage, |
@@ -868,8 +848,6 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, | |||
868 | 848 | ||
869 | if (ret == 0) | 849 | if (ret == 0) |
870 | set_bit(EXTENT_BUFFER_UPTODATE, &buf->bflags); | 850 | set_bit(EXTENT_BUFFER_UPTODATE, &buf->bflags); |
871 | else | ||
872 | WARN_ON(1); | ||
873 | return buf; | 851 | return buf; |
874 | 852 | ||
875 | } | 853 | } |
@@ -1278,11 +1256,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits) | |||
1278 | int ret = 0; | 1256 | int ret = 0; |
1279 | struct btrfs_device *device; | 1257 | struct btrfs_device *device; |
1280 | struct backing_dev_info *bdi; | 1258 | struct backing_dev_info *bdi; |
1281 | #if 0 | 1259 | |
1282 | if ((bdi_bits & (1 << BDI_write_congested)) && | ||
1283 | btrfs_congested_async(info, 0)) | ||
1284 | return 1; | ||
1285 | #endif | ||
1286 | list_for_each_entry(device, &info->fs_devices->devices, dev_list) { | 1260 | list_for_each_entry(device, &info->fs_devices->devices, dev_list) { |
1287 | if (!device->bdev) | 1261 | if (!device->bdev) |
1288 | continue; | 1262 | continue; |
@@ -1604,6 +1578,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1604 | fs_info->btree_inode = new_inode(sb); | 1578 | fs_info->btree_inode = new_inode(sb); |
1605 | fs_info->btree_inode->i_ino = 1; | 1579 | fs_info->btree_inode->i_ino = 1; |
1606 | fs_info->btree_inode->i_nlink = 1; | 1580 | fs_info->btree_inode->i_nlink = 1; |
1581 | fs_info->metadata_ratio = 8; | ||
1607 | 1582 | ||
1608 | fs_info->thread_pool_size = min_t(unsigned long, | 1583 | fs_info->thread_pool_size = min_t(unsigned long, |
1609 | num_online_cpus() + 2, 8); | 1584 | num_online_cpus() + 2, 8); |
@@ -1694,7 +1669,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1694 | if (features) { | 1669 | if (features) { |
1695 | printk(KERN_ERR "BTRFS: couldn't mount because of " | 1670 | printk(KERN_ERR "BTRFS: couldn't mount because of " |
1696 | "unsupported optional features (%Lx).\n", | 1671 | "unsupported optional features (%Lx).\n", |
1697 | features); | 1672 | (unsigned long long)features); |
1698 | err = -EINVAL; | 1673 | err = -EINVAL; |
1699 | goto fail_iput; | 1674 | goto fail_iput; |
1700 | } | 1675 | } |
@@ -1704,7 +1679,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1704 | if (!(sb->s_flags & MS_RDONLY) && features) { | 1679 | if (!(sb->s_flags & MS_RDONLY) && features) { |
1705 | printk(KERN_ERR "BTRFS: couldn't mount RDWR because of " | 1680 | printk(KERN_ERR "BTRFS: couldn't mount RDWR because of " |
1706 | "unsupported option features (%Lx).\n", | 1681 | "unsupported option features (%Lx).\n", |
1707 | features); | 1682 | (unsigned long long)features); |
1708 | err = -EINVAL; | 1683 | err = -EINVAL; |
1709 | goto fail_iput; | 1684 | goto fail_iput; |
1710 | } | 1685 | } |
@@ -2296,7 +2271,7 @@ int close_ctree(struct btrfs_root *root) | |||
2296 | 2271 | ||
2297 | if (fs_info->delalloc_bytes) { | 2272 | if (fs_info->delalloc_bytes) { |
2298 | printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n", | 2273 | printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n", |
2299 | fs_info->delalloc_bytes); | 2274 | (unsigned long long)fs_info->delalloc_bytes); |
2300 | } | 2275 | } |
2301 | if (fs_info->total_ref_cache_size) { | 2276 | if (fs_info->total_ref_cache_size) { |
2302 | printk(KERN_INFO "btrfs: at umount reference cache size %llu\n", | 2277 | printk(KERN_INFO "btrfs: at umount reference cache size %llu\n", |
@@ -2333,16 +2308,6 @@ int close_ctree(struct btrfs_root *root) | |||
2333 | btrfs_stop_workers(&fs_info->endio_write_workers); | 2308 | btrfs_stop_workers(&fs_info->endio_write_workers); |
2334 | btrfs_stop_workers(&fs_info->submit_workers); | 2309 | btrfs_stop_workers(&fs_info->submit_workers); |
2335 | 2310 | ||
2336 | #if 0 | ||
2337 | while (!list_empty(&fs_info->hashers)) { | ||
2338 | struct btrfs_hasher *hasher; | ||
2339 | hasher = list_entry(fs_info->hashers.next, struct btrfs_hasher, | ||
2340 | hashers); | ||
2341 | list_del(&hasher->hashers); | ||
2342 | crypto_free_hash(&fs_info->hash_tfm); | ||
2343 | kfree(hasher); | ||
2344 | } | ||
2345 | #endif | ||
2346 | btrfs_close_devices(fs_info->fs_devices); | 2311 | btrfs_close_devices(fs_info->fs_devices); |
2347 | btrfs_mapping_tree_free(&fs_info->mapping_tree); | 2312 | btrfs_mapping_tree_free(&fs_info->mapping_tree); |
2348 | 2313 | ||
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 178df4c67de4..35af93355063 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -312,7 +312,7 @@ btrfs_lookup_first_block_group(struct btrfs_fs_info *info, u64 bytenr) | |||
312 | } | 312 | } |
313 | 313 | ||
314 | /* | 314 | /* |
315 | * return the block group that contains teh given bytenr | 315 | * return the block group that contains the given bytenr |
316 | */ | 316 | */ |
317 | struct btrfs_block_group_cache *btrfs_lookup_block_group( | 317 | struct btrfs_block_group_cache *btrfs_lookup_block_group( |
318 | struct btrfs_fs_info *info, | 318 | struct btrfs_fs_info *info, |
@@ -1844,10 +1844,14 @@ again: | |||
1844 | printk(KERN_ERR "no space left, need %llu, %llu delalloc bytes" | 1844 | printk(KERN_ERR "no space left, need %llu, %llu delalloc bytes" |
1845 | ", %llu bytes_used, %llu bytes_reserved, " | 1845 | ", %llu bytes_used, %llu bytes_reserved, " |
1846 | "%llu bytes_pinned, %llu bytes_readonly, %llu may use" | 1846 | "%llu bytes_pinned, %llu bytes_readonly, %llu may use" |
1847 | "%llu total\n", bytes, data_sinfo->bytes_delalloc, | 1847 | "%llu total\n", (unsigned long long)bytes, |
1848 | data_sinfo->bytes_used, data_sinfo->bytes_reserved, | 1848 | (unsigned long long)data_sinfo->bytes_delalloc, |
1849 | data_sinfo->bytes_pinned, data_sinfo->bytes_readonly, | 1849 | (unsigned long long)data_sinfo->bytes_used, |
1850 | data_sinfo->bytes_may_use, data_sinfo->total_bytes); | 1850 | (unsigned long long)data_sinfo->bytes_reserved, |
1851 | (unsigned long long)data_sinfo->bytes_pinned, | ||
1852 | (unsigned long long)data_sinfo->bytes_readonly, | ||
1853 | (unsigned long long)data_sinfo->bytes_may_use, | ||
1854 | (unsigned long long)data_sinfo->total_bytes); | ||
1851 | return -ENOSPC; | 1855 | return -ENOSPC; |
1852 | } | 1856 | } |
1853 | data_sinfo->bytes_may_use += bytes; | 1857 | data_sinfo->bytes_may_use += bytes; |
@@ -1918,15 +1922,29 @@ void btrfs_delalloc_free_space(struct btrfs_root *root, struct inode *inode, | |||
1918 | spin_unlock(&info->lock); | 1922 | spin_unlock(&info->lock); |
1919 | } | 1923 | } |
1920 | 1924 | ||
1925 | static void force_metadata_allocation(struct btrfs_fs_info *info) | ||
1926 | { | ||
1927 | struct list_head *head = &info->space_info; | ||
1928 | struct btrfs_space_info *found; | ||
1929 | |||
1930 | rcu_read_lock(); | ||
1931 | list_for_each_entry_rcu(found, head, list) { | ||
1932 | if (found->flags & BTRFS_BLOCK_GROUP_METADATA) | ||
1933 | found->force_alloc = 1; | ||
1934 | } | ||
1935 | rcu_read_unlock(); | ||
1936 | } | ||
1937 | |||
1921 | static int do_chunk_alloc(struct btrfs_trans_handle *trans, | 1938 | static int do_chunk_alloc(struct btrfs_trans_handle *trans, |
1922 | struct btrfs_root *extent_root, u64 alloc_bytes, | 1939 | struct btrfs_root *extent_root, u64 alloc_bytes, |
1923 | u64 flags, int force) | 1940 | u64 flags, int force) |
1924 | { | 1941 | { |
1925 | struct btrfs_space_info *space_info; | 1942 | struct btrfs_space_info *space_info; |
1943 | struct btrfs_fs_info *fs_info = extent_root->fs_info; | ||
1926 | u64 thresh; | 1944 | u64 thresh; |
1927 | int ret = 0; | 1945 | int ret = 0; |
1928 | 1946 | ||
1929 | mutex_lock(&extent_root->fs_info->chunk_mutex); | 1947 | mutex_lock(&fs_info->chunk_mutex); |
1930 | 1948 | ||
1931 | flags = btrfs_reduce_alloc_profile(extent_root, flags); | 1949 | flags = btrfs_reduce_alloc_profile(extent_root, flags); |
1932 | 1950 | ||
@@ -1958,6 +1976,18 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, | |||
1958 | } | 1976 | } |
1959 | spin_unlock(&space_info->lock); | 1977 | spin_unlock(&space_info->lock); |
1960 | 1978 | ||
1979 | /* | ||
1980 | * if we're doing a data chunk, go ahead and make sure that | ||
1981 | * we keep a reasonable number of metadata chunks allocated in the | ||
1982 | * FS as well. | ||
1983 | */ | ||
1984 | if (flags & BTRFS_BLOCK_GROUP_DATA) { | ||
1985 | fs_info->data_chunk_allocations++; | ||
1986 | if (!(fs_info->data_chunk_allocations % | ||
1987 | fs_info->metadata_ratio)) | ||
1988 | force_metadata_allocation(fs_info); | ||
1989 | } | ||
1990 | |||
1961 | ret = btrfs_alloc_chunk(trans, extent_root, flags); | 1991 | ret = btrfs_alloc_chunk(trans, extent_root, flags); |
1962 | if (ret) | 1992 | if (ret) |
1963 | space_info->full = 1; | 1993 | space_info->full = 1; |
@@ -2592,7 +2622,18 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, | |||
2592 | search_start); | 2622 | search_start); |
2593 | if (block_group && block_group_bits(block_group, data)) { | 2623 | if (block_group && block_group_bits(block_group, data)) { |
2594 | down_read(&space_info->groups_sem); | 2624 | down_read(&space_info->groups_sem); |
2595 | goto have_block_group; | 2625 | if (list_empty(&block_group->list) || |
2626 | block_group->ro) { | ||
2627 | /* | ||
2628 | * someone is removing this block group, | ||
2629 | * we can't jump into the have_block_group | ||
2630 | * target because our list pointers are not | ||
2631 | * valid | ||
2632 | */ | ||
2633 | btrfs_put_block_group(block_group); | ||
2634 | up_read(&space_info->groups_sem); | ||
2635 | } else | ||
2636 | goto have_block_group; | ||
2596 | } else if (block_group) { | 2637 | } else if (block_group) { |
2597 | btrfs_put_block_group(block_group); | 2638 | btrfs_put_block_group(block_group); |
2598 | } | 2639 | } |
@@ -2626,6 +2667,13 @@ have_block_group: | |||
2626 | * people trying to start a new cluster | 2667 | * people trying to start a new cluster |
2627 | */ | 2668 | */ |
2628 | spin_lock(&last_ptr->refill_lock); | 2669 | spin_lock(&last_ptr->refill_lock); |
2670 | if (last_ptr->block_group && | ||
2671 | (last_ptr->block_group->ro || | ||
2672 | !block_group_bits(last_ptr->block_group, data))) { | ||
2673 | offset = 0; | ||
2674 | goto refill_cluster; | ||
2675 | } | ||
2676 | |||
2629 | offset = btrfs_alloc_from_cluster(block_group, last_ptr, | 2677 | offset = btrfs_alloc_from_cluster(block_group, last_ptr, |
2630 | num_bytes, search_start); | 2678 | num_bytes, search_start); |
2631 | if (offset) { | 2679 | if (offset) { |
@@ -2651,10 +2699,17 @@ have_block_group: | |||
2651 | 2699 | ||
2652 | last_ptr_loop = 1; | 2700 | last_ptr_loop = 1; |
2653 | search_start = block_group->key.objectid; | 2701 | search_start = block_group->key.objectid; |
2702 | /* | ||
2703 | * we know this block group is properly | ||
2704 | * in the list because | ||
2705 | * btrfs_remove_block_group, drops the | ||
2706 | * cluster before it removes the block | ||
2707 | * group from the list | ||
2708 | */ | ||
2654 | goto have_block_group; | 2709 | goto have_block_group; |
2655 | } | 2710 | } |
2656 | spin_unlock(&last_ptr->lock); | 2711 | spin_unlock(&last_ptr->lock); |
2657 | 2712 | refill_cluster: | |
2658 | /* | 2713 | /* |
2659 | * this cluster didn't work out, free it and | 2714 | * this cluster didn't work out, free it and |
2660 | * start over | 2715 | * start over |
@@ -2798,9 +2853,12 @@ static void dump_space_info(struct btrfs_space_info *info, u64 bytes) | |||
2798 | info->bytes_pinned - info->bytes_reserved), | 2853 | info->bytes_pinned - info->bytes_reserved), |
2799 | (info->full) ? "" : "not "); | 2854 | (info->full) ? "" : "not "); |
2800 | printk(KERN_INFO "space_info total=%llu, pinned=%llu, delalloc=%llu," | 2855 | printk(KERN_INFO "space_info total=%llu, pinned=%llu, delalloc=%llu," |
2801 | " may_use=%llu, used=%llu\n", info->total_bytes, | 2856 | " may_use=%llu, used=%llu\n", |
2802 | info->bytes_pinned, info->bytes_delalloc, info->bytes_may_use, | 2857 | (unsigned long long)info->total_bytes, |
2803 | info->bytes_used); | 2858 | (unsigned long long)info->bytes_pinned, |
2859 | (unsigned long long)info->bytes_delalloc, | ||
2860 | (unsigned long long)info->bytes_may_use, | ||
2861 | (unsigned long long)info->bytes_used); | ||
2804 | 2862 | ||
2805 | down_read(&info->groups_sem); | 2863 | down_read(&info->groups_sem); |
2806 | list_for_each_entry(cache, &info->block_groups, list) { | 2864 | list_for_each_entry(cache, &info->block_groups, list) { |
@@ -5935,6 +5993,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, | |||
5935 | { | 5993 | { |
5936 | struct btrfs_path *path; | 5994 | struct btrfs_path *path; |
5937 | struct btrfs_block_group_cache *block_group; | 5995 | struct btrfs_block_group_cache *block_group; |
5996 | struct btrfs_free_cluster *cluster; | ||
5938 | struct btrfs_key key; | 5997 | struct btrfs_key key; |
5939 | int ret; | 5998 | int ret; |
5940 | 5999 | ||
@@ -5946,6 +6005,21 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, | |||
5946 | 6005 | ||
5947 | memcpy(&key, &block_group->key, sizeof(key)); | 6006 | memcpy(&key, &block_group->key, sizeof(key)); |
5948 | 6007 | ||
6008 | /* make sure this block group isn't part of an allocation cluster */ | ||
6009 | cluster = &root->fs_info->data_alloc_cluster; | ||
6010 | spin_lock(&cluster->refill_lock); | ||
6011 | btrfs_return_cluster_to_free_space(block_group, cluster); | ||
6012 | spin_unlock(&cluster->refill_lock); | ||
6013 | |||
6014 | /* | ||
6015 | * make sure this block group isn't part of a metadata | ||
6016 | * allocation cluster | ||
6017 | */ | ||
6018 | cluster = &root->fs_info->meta_alloc_cluster; | ||
6019 | spin_lock(&cluster->refill_lock); | ||
6020 | btrfs_return_cluster_to_free_space(block_group, cluster); | ||
6021 | spin_unlock(&cluster->refill_lock); | ||
6022 | |||
5949 | path = btrfs_alloc_path(); | 6023 | path = btrfs_alloc_path(); |
5950 | BUG_ON(!path); | 6024 | BUG_ON(!path); |
5951 | 6025 | ||
@@ -5955,7 +6029,11 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, | |||
5955 | spin_unlock(&root->fs_info->block_group_cache_lock); | 6029 | spin_unlock(&root->fs_info->block_group_cache_lock); |
5956 | btrfs_remove_free_space_cache(block_group); | 6030 | btrfs_remove_free_space_cache(block_group); |
5957 | down_write(&block_group->space_info->groups_sem); | 6031 | down_write(&block_group->space_info->groups_sem); |
5958 | list_del(&block_group->list); | 6032 | /* |
6033 | * we must use list_del_init so people can check to see if they | ||
6034 | * are still on the list after taking the semaphore | ||
6035 | */ | ||
6036 | list_del_init(&block_group->list); | ||
5959 | up_write(&block_group->space_info->groups_sem); | 6037 | up_write(&block_group->space_info->groups_sem); |
5960 | 6038 | ||
5961 | spin_lock(&block_group->space_info->lock); | 6039 | spin_lock(&block_group->space_info->lock); |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 05a1c42e25bf..fe9eb990e443 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -17,12 +17,6 @@ | |||
17 | #include "ctree.h" | 17 | #include "ctree.h" |
18 | #include "btrfs_inode.h" | 18 | #include "btrfs_inode.h" |
19 | 19 | ||
20 | /* temporary define until extent_map moves out of btrfs */ | ||
21 | struct kmem_cache *btrfs_cache_create(const char *name, size_t size, | ||
22 | unsigned long extra_flags, | ||
23 | void (*ctor)(void *, struct kmem_cache *, | ||
24 | unsigned long)); | ||
25 | |||
26 | static struct kmem_cache *extent_state_cache; | 20 | static struct kmem_cache *extent_state_cache; |
27 | static struct kmem_cache *extent_buffer_cache; | 21 | static struct kmem_cache *extent_buffer_cache; |
28 | 22 | ||
@@ -58,15 +52,15 @@ struct extent_page_data { | |||
58 | 52 | ||
59 | int __init extent_io_init(void) | 53 | int __init extent_io_init(void) |
60 | { | 54 | { |
61 | extent_state_cache = btrfs_cache_create("extent_state", | 55 | extent_state_cache = kmem_cache_create("extent_state", |
62 | sizeof(struct extent_state), 0, | 56 | sizeof(struct extent_state), 0, |
63 | NULL); | 57 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); |
64 | if (!extent_state_cache) | 58 | if (!extent_state_cache) |
65 | return -ENOMEM; | 59 | return -ENOMEM; |
66 | 60 | ||
67 | extent_buffer_cache = btrfs_cache_create("extent_buffers", | 61 | extent_buffer_cache = kmem_cache_create("extent_buffers", |
68 | sizeof(struct extent_buffer), 0, | 62 | sizeof(struct extent_buffer), 0, |
69 | NULL); | 63 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); |
70 | if (!extent_buffer_cache) | 64 | if (!extent_buffer_cache) |
71 | goto free_state_cache; | 65 | goto free_state_cache; |
72 | return 0; | 66 | return 0; |
@@ -1407,69 +1401,6 @@ out: | |||
1407 | return total_bytes; | 1401 | return total_bytes; |
1408 | } | 1402 | } |
1409 | 1403 | ||
1410 | #if 0 | ||
1411 | /* | ||
1412 | * helper function to lock both pages and extents in the tree. | ||
1413 | * pages must be locked first. | ||
1414 | */ | ||
1415 | static int lock_range(struct extent_io_tree *tree, u64 start, u64 end) | ||
1416 | { | ||
1417 | unsigned long index = start >> PAGE_CACHE_SHIFT; | ||
1418 | unsigned long end_index = end >> PAGE_CACHE_SHIFT; | ||
1419 | struct page *page; | ||
1420 | int err; | ||
1421 | |||
1422 | while (index <= end_index) { | ||
1423 | page = grab_cache_page(tree->mapping, index); | ||
1424 | if (!page) { | ||
1425 | err = -ENOMEM; | ||
1426 | goto failed; | ||
1427 | } | ||
1428 | if (IS_ERR(page)) { | ||
1429 | err = PTR_ERR(page); | ||
1430 | goto failed; | ||
1431 | } | ||
1432 | index++; | ||
1433 | } | ||
1434 | lock_extent(tree, start, end, GFP_NOFS); | ||
1435 | return 0; | ||
1436 | |||
1437 | failed: | ||
1438 | /* | ||
1439 | * we failed above in getting the page at 'index', so we undo here | ||
1440 | * up to but not including the page at 'index' | ||
1441 | */ | ||
1442 | end_index = index; | ||
1443 | index = start >> PAGE_CACHE_SHIFT; | ||
1444 | while (index < end_index) { | ||
1445 | page = find_get_page(tree->mapping, index); | ||
1446 | unlock_page(page); | ||
1447 | page_cache_release(page); | ||
1448 | index++; | ||
1449 | } | ||
1450 | return err; | ||
1451 | } | ||
1452 | |||
1453 | /* | ||
1454 | * helper function to unlock both pages and extents in the tree. | ||
1455 | */ | ||
1456 | static int unlock_range(struct extent_io_tree *tree, u64 start, u64 end) | ||
1457 | { | ||
1458 | unsigned long index = start >> PAGE_CACHE_SHIFT; | ||
1459 | unsigned long end_index = end >> PAGE_CACHE_SHIFT; | ||
1460 | struct page *page; | ||
1461 | |||
1462 | while (index <= end_index) { | ||
1463 | page = find_get_page(tree->mapping, index); | ||
1464 | unlock_page(page); | ||
1465 | page_cache_release(page); | ||
1466 | index++; | ||
1467 | } | ||
1468 | unlock_extent(tree, start, end, GFP_NOFS); | ||
1469 | return 0; | ||
1470 | } | ||
1471 | #endif | ||
1472 | |||
1473 | /* | 1404 | /* |
1474 | * set the private field for a given byte offset in the tree. If there isn't | 1405 | * set the private field for a given byte offset in the tree. If there isn't |
1475 | * an extent_state there already, this does nothing. | 1406 | * an extent_state there already, this does nothing. |
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index b187917b36fa..30c9365861e6 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c | |||
@@ -6,19 +6,14 @@ | |||
6 | #include <linux/hardirq.h> | 6 | #include <linux/hardirq.h> |
7 | #include "extent_map.h" | 7 | #include "extent_map.h" |
8 | 8 | ||
9 | /* temporary define until extent_map moves out of btrfs */ | ||
10 | struct kmem_cache *btrfs_cache_create(const char *name, size_t size, | ||
11 | unsigned long extra_flags, | ||
12 | void (*ctor)(void *, struct kmem_cache *, | ||
13 | unsigned long)); | ||
14 | 9 | ||
15 | static struct kmem_cache *extent_map_cache; | 10 | static struct kmem_cache *extent_map_cache; |
16 | 11 | ||
17 | int __init extent_map_init(void) | 12 | int __init extent_map_init(void) |
18 | { | 13 | { |
19 | extent_map_cache = btrfs_cache_create("extent_map", | 14 | extent_map_cache = kmem_cache_create("extent_map", |
20 | sizeof(struct extent_map), 0, | 15 | sizeof(struct extent_map), 0, |
21 | NULL); | 16 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); |
22 | if (!extent_map_cache) | 17 | if (!extent_map_cache) |
23 | return -ENOMEM; | 18 | return -ENOMEM; |
24 | return 0; | 19 | return 0; |
@@ -43,7 +38,6 @@ void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask) | |||
43 | tree->map.rb_node = NULL; | 38 | tree->map.rb_node = NULL; |
44 | spin_lock_init(&tree->lock); | 39 | spin_lock_init(&tree->lock); |
45 | } | 40 | } |
46 | EXPORT_SYMBOL(extent_map_tree_init); | ||
47 | 41 | ||
48 | /** | 42 | /** |
49 | * alloc_extent_map - allocate new extent map structure | 43 | * alloc_extent_map - allocate new extent map structure |
@@ -64,7 +58,6 @@ struct extent_map *alloc_extent_map(gfp_t mask) | |||
64 | atomic_set(&em->refs, 1); | 58 | atomic_set(&em->refs, 1); |
65 | return em; | 59 | return em; |
66 | } | 60 | } |
67 | EXPORT_SYMBOL(alloc_extent_map); | ||
68 | 61 | ||
69 | /** | 62 | /** |
70 | * free_extent_map - drop reference count of an extent_map | 63 | * free_extent_map - drop reference count of an extent_map |
@@ -83,7 +76,6 @@ void free_extent_map(struct extent_map *em) | |||
83 | kmem_cache_free(extent_map_cache, em); | 76 | kmem_cache_free(extent_map_cache, em); |
84 | } | 77 | } |
85 | } | 78 | } |
86 | EXPORT_SYMBOL(free_extent_map); | ||
87 | 79 | ||
88 | static struct rb_node *tree_insert(struct rb_root *root, u64 offset, | 80 | static struct rb_node *tree_insert(struct rb_root *root, u64 offset, |
89 | struct rb_node *node) | 81 | struct rb_node *node) |
@@ -264,7 +256,6 @@ int add_extent_mapping(struct extent_map_tree *tree, | |||
264 | out: | 256 | out: |
265 | return ret; | 257 | return ret; |
266 | } | 258 | } |
267 | EXPORT_SYMBOL(add_extent_mapping); | ||
268 | 259 | ||
269 | /* simple helper to do math around the end of an extent, handling wrap */ | 260 | /* simple helper to do math around the end of an extent, handling wrap */ |
270 | static u64 range_end(u64 start, u64 len) | 261 | static u64 range_end(u64 start, u64 len) |
@@ -326,7 +317,6 @@ found: | |||
326 | out: | 317 | out: |
327 | return em; | 318 | return em; |
328 | } | 319 | } |
329 | EXPORT_SYMBOL(lookup_extent_mapping); | ||
330 | 320 | ||
331 | /** | 321 | /** |
332 | * remove_extent_mapping - removes an extent_map from the extent tree | 322 | * remove_extent_mapping - removes an extent_map from the extent tree |
@@ -346,4 +336,3 @@ int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em) | |||
346 | em->in_tree = 0; | 336 | em->in_tree = 0; |
347 | return ret; | 337 | return ret; |
348 | } | 338 | } |
349 | EXPORT_SYMBOL(remove_extent_mapping); | ||
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 482f8db2cfd0..1d51dc38bb49 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -272,83 +272,6 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | |||
272 | return 0; | 272 | return 0; |
273 | } | 273 | } |
274 | 274 | ||
275 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode) | ||
276 | { | ||
277 | return 0; | ||
278 | #if 0 | ||
279 | struct btrfs_path *path; | ||
280 | struct btrfs_key found_key; | ||
281 | struct extent_buffer *leaf; | ||
282 | struct btrfs_file_extent_item *extent; | ||
283 | u64 last_offset = 0; | ||
284 | int nritems; | ||
285 | int slot; | ||
286 | int found_type; | ||
287 | int ret; | ||
288 | int err = 0; | ||
289 | u64 extent_end = 0; | ||
290 | |||
291 | path = btrfs_alloc_path(); | ||
292 | ret = btrfs_lookup_file_extent(NULL, root, path, inode->i_ino, | ||
293 | last_offset, 0); | ||
294 | while (1) { | ||
295 | nritems = btrfs_header_nritems(path->nodes[0]); | ||
296 | if (path->slots[0] >= nritems) { | ||
297 | ret = btrfs_next_leaf(root, path); | ||
298 | if (ret) | ||
299 | goto out; | ||
300 | nritems = btrfs_header_nritems(path->nodes[0]); | ||
301 | } | ||
302 | slot = path->slots[0]; | ||
303 | leaf = path->nodes[0]; | ||
304 | btrfs_item_key_to_cpu(leaf, &found_key, slot); | ||
305 | if (found_key.objectid != inode->i_ino) | ||
306 | break; | ||
307 | if (found_key.type != BTRFS_EXTENT_DATA_KEY) | ||
308 | goto out; | ||
309 | |||
310 | if (found_key.offset < last_offset) { | ||
311 | WARN_ON(1); | ||
312 | btrfs_print_leaf(root, leaf); | ||
313 | printk(KERN_ERR "inode %lu found offset %llu " | ||
314 | "expected %llu\n", inode->i_ino, | ||
315 | (unsigned long long)found_key.offset, | ||
316 | (unsigned long long)last_offset); | ||
317 | err = 1; | ||
318 | goto out; | ||
319 | } | ||
320 | extent = btrfs_item_ptr(leaf, slot, | ||
321 | struct btrfs_file_extent_item); | ||
322 | found_type = btrfs_file_extent_type(leaf, extent); | ||
323 | if (found_type == BTRFS_FILE_EXTENT_REG) { | ||
324 | extent_end = found_key.offset + | ||
325 | btrfs_file_extent_num_bytes(leaf, extent); | ||
326 | } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { | ||
327 | struct btrfs_item *item; | ||
328 | item = btrfs_item_nr(leaf, slot); | ||
329 | extent_end = found_key.offset + | ||
330 | btrfs_file_extent_inline_len(leaf, extent); | ||
331 | extent_end = (extent_end + root->sectorsize - 1) & | ||
332 | ~((u64)root->sectorsize - 1); | ||
333 | } | ||
334 | last_offset = extent_end; | ||
335 | path->slots[0]++; | ||
336 | } | ||
337 | if (0 && last_offset < inode->i_size) { | ||
338 | WARN_ON(1); | ||
339 | btrfs_print_leaf(root, leaf); | ||
340 | printk(KERN_ERR "inode %lu found offset %llu size %llu\n", | ||
341 | inode->i_ino, (unsigned long long)last_offset, | ||
342 | (unsigned long long)inode->i_size); | ||
343 | err = 1; | ||
344 | |||
345 | } | ||
346 | out: | ||
347 | btrfs_free_path(path); | ||
348 | return err; | ||
349 | #endif | ||
350 | } | ||
351 | |||
352 | /* | 275 | /* |
353 | * this is very complex, but the basic idea is to drop all extents | 276 | * this is very complex, but the basic idea is to drop all extents |
354 | * in the range start - end. hint_block is filled in with a block number | 277 | * in the range start - end. hint_block is filled in with a block number |
@@ -363,15 +286,16 @@ out: | |||
363 | */ | 286 | */ |
364 | noinline int btrfs_drop_extents(struct btrfs_trans_handle *trans, | 287 | noinline int btrfs_drop_extents(struct btrfs_trans_handle *trans, |
365 | struct btrfs_root *root, struct inode *inode, | 288 | struct btrfs_root *root, struct inode *inode, |
366 | u64 start, u64 end, u64 inline_limit, u64 *hint_byte) | 289 | u64 start, u64 end, u64 locked_end, |
290 | u64 inline_limit, u64 *hint_byte) | ||
367 | { | 291 | { |
368 | u64 extent_end = 0; | 292 | u64 extent_end = 0; |
369 | u64 locked_end = end; | ||
370 | u64 search_start = start; | 293 | u64 search_start = start; |
371 | u64 leaf_start; | 294 | u64 leaf_start; |
372 | u64 ram_bytes = 0; | 295 | u64 ram_bytes = 0; |
373 | u64 orig_parent = 0; | 296 | u64 orig_parent = 0; |
374 | u64 disk_bytenr = 0; | 297 | u64 disk_bytenr = 0; |
298 | u64 orig_locked_end = locked_end; | ||
375 | u8 compression; | 299 | u8 compression; |
376 | u8 encryption; | 300 | u8 encryption; |
377 | u16 other_encoding = 0; | 301 | u16 other_encoding = 0; |
@@ -684,11 +608,10 @@ next_slot: | |||
684 | } | 608 | } |
685 | out: | 609 | out: |
686 | btrfs_free_path(path); | 610 | btrfs_free_path(path); |
687 | if (locked_end > end) { | 611 | if (locked_end > orig_locked_end) { |
688 | unlock_extent(&BTRFS_I(inode)->io_tree, end, locked_end - 1, | 612 | unlock_extent(&BTRFS_I(inode)->io_tree, orig_locked_end, |
689 | GFP_NOFS); | 613 | locked_end - 1, GFP_NOFS); |
690 | } | 614 | } |
691 | btrfs_check_file(root, inode); | ||
692 | return ret; | 615 | return ret; |
693 | } | 616 | } |
694 | 617 | ||
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 768b9523662d..0bc93657b460 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -332,13 +332,17 @@ int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group, | |||
332 | printk(KERN_ERR "couldn't find space %llu to free\n", | 332 | printk(KERN_ERR "couldn't find space %llu to free\n", |
333 | (unsigned long long)offset); | 333 | (unsigned long long)offset); |
334 | printk(KERN_ERR "cached is %d, offset %llu bytes %llu\n", | 334 | printk(KERN_ERR "cached is %d, offset %llu bytes %llu\n", |
335 | block_group->cached, block_group->key.objectid, | 335 | block_group->cached, |
336 | block_group->key.offset); | 336 | (unsigned long long)block_group->key.objectid, |
337 | (unsigned long long)block_group->key.offset); | ||
337 | btrfs_dump_free_space(block_group, bytes); | 338 | btrfs_dump_free_space(block_group, bytes); |
338 | } else if (info) { | 339 | } else if (info) { |
339 | printk(KERN_ERR "hmm, found offset=%llu bytes=%llu, " | 340 | printk(KERN_ERR "hmm, found offset=%llu bytes=%llu, " |
340 | "but wanted offset=%llu bytes=%llu\n", | 341 | "but wanted offset=%llu bytes=%llu\n", |
341 | info->offset, info->bytes, offset, bytes); | 342 | (unsigned long long)info->offset, |
343 | (unsigned long long)info->bytes, | ||
344 | (unsigned long long)offset, | ||
345 | (unsigned long long)bytes); | ||
342 | } | 346 | } |
343 | WARN_ON(1); | 347 | WARN_ON(1); |
344 | } | 348 | } |
@@ -357,8 +361,9 @@ void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, | |||
357 | info = rb_entry(n, struct btrfs_free_space, offset_index); | 361 | info = rb_entry(n, struct btrfs_free_space, offset_index); |
358 | if (info->bytes >= bytes) | 362 | if (info->bytes >= bytes) |
359 | count++; | 363 | count++; |
360 | printk(KERN_ERR "entry offset %llu, bytes %llu\n", info->offset, | 364 | printk(KERN_ERR "entry offset %llu, bytes %llu\n", |
361 | info->bytes); | 365 | (unsigned long long)info->offset, |
366 | (unsigned long long)info->bytes); | ||
362 | } | 367 | } |
363 | printk(KERN_INFO "%d blocks of free space at or bigger than bytes is" | 368 | printk(KERN_INFO "%d blocks of free space at or bigger than bytes is" |
364 | "\n", count); | 369 | "\n", count); |
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c index cc7334d833c9..9abbced1123d 100644 --- a/fs/btrfs/inode-map.c +++ b/fs/btrfs/inode-map.c | |||
@@ -79,7 +79,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, | |||
79 | } | 79 | } |
80 | path = btrfs_alloc_path(); | 80 | path = btrfs_alloc_path(); |
81 | BUG_ON(!path); | 81 | BUG_ON(!path); |
82 | search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); | 82 | search_start = max(search_start, (u64)BTRFS_FIRST_FREE_OBJECTID); |
83 | search_key.objectid = search_start; | 83 | search_key.objectid = search_start; |
84 | search_key.type = 0; | 84 | search_key.type = 0; |
85 | search_key.offset = 0; | 85 | search_key.offset = 0; |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 65219f6a16a1..1c8b0190d031 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -70,7 +70,6 @@ static struct extent_io_ops btrfs_extent_io_ops; | |||
70 | static struct kmem_cache *btrfs_inode_cachep; | 70 | static struct kmem_cache *btrfs_inode_cachep; |
71 | struct kmem_cache *btrfs_trans_handle_cachep; | 71 | struct kmem_cache *btrfs_trans_handle_cachep; |
72 | struct kmem_cache *btrfs_transaction_cachep; | 72 | struct kmem_cache *btrfs_transaction_cachep; |
73 | struct kmem_cache *btrfs_bit_radix_cachep; | ||
74 | struct kmem_cache *btrfs_path_cachep; | 73 | struct kmem_cache *btrfs_path_cachep; |
75 | 74 | ||
76 | #define S_SHIFT 12 | 75 | #define S_SHIFT 12 |
@@ -234,7 +233,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans, | |||
234 | } | 233 | } |
235 | 234 | ||
236 | ret = btrfs_drop_extents(trans, root, inode, start, | 235 | ret = btrfs_drop_extents(trans, root, inode, start, |
237 | aligned_end, start, &hint_byte); | 236 | aligned_end, aligned_end, start, &hint_byte); |
238 | BUG_ON(ret); | 237 | BUG_ON(ret); |
239 | 238 | ||
240 | if (isize > actual_end) | 239 | if (isize > actual_end) |
@@ -1439,6 +1438,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1439 | struct inode *inode, u64 file_pos, | 1438 | struct inode *inode, u64 file_pos, |
1440 | u64 disk_bytenr, u64 disk_num_bytes, | 1439 | u64 disk_bytenr, u64 disk_num_bytes, |
1441 | u64 num_bytes, u64 ram_bytes, | 1440 | u64 num_bytes, u64 ram_bytes, |
1441 | u64 locked_end, | ||
1442 | u8 compression, u8 encryption, | 1442 | u8 compression, u8 encryption, |
1443 | u16 other_encoding, int extent_type) | 1443 | u16 other_encoding, int extent_type) |
1444 | { | 1444 | { |
@@ -1455,7 +1455,8 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1455 | 1455 | ||
1456 | path->leave_spinning = 1; | 1456 | path->leave_spinning = 1; |
1457 | ret = btrfs_drop_extents(trans, root, inode, file_pos, | 1457 | ret = btrfs_drop_extents(trans, root, inode, file_pos, |
1458 | file_pos + num_bytes, file_pos, &hint); | 1458 | file_pos + num_bytes, locked_end, |
1459 | file_pos, &hint); | ||
1459 | BUG_ON(ret); | 1460 | BUG_ON(ret); |
1460 | 1461 | ||
1461 | ins.objectid = inode->i_ino; | 1462 | ins.objectid = inode->i_ino; |
@@ -1590,6 +1591,8 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1590 | ordered_extent->disk_len, | 1591 | ordered_extent->disk_len, |
1591 | ordered_extent->len, | 1592 | ordered_extent->len, |
1592 | ordered_extent->len, | 1593 | ordered_extent->len, |
1594 | ordered_extent->file_offset + | ||
1595 | ordered_extent->len, | ||
1593 | compressed, 0, 0, | 1596 | compressed, 0, 0, |
1594 | BTRFS_FILE_EXTENT_REG); | 1597 | BTRFS_FILE_EXTENT_REG); |
1595 | BUG_ON(ret); | 1598 | BUG_ON(ret); |
@@ -1819,10 +1822,12 @@ good: | |||
1819 | return 0; | 1822 | return 0; |
1820 | 1823 | ||
1821 | zeroit: | 1824 | zeroit: |
1822 | printk(KERN_INFO "btrfs csum failed ino %lu off %llu csum %u " | 1825 | if (printk_ratelimit()) { |
1823 | "private %llu\n", page->mapping->host->i_ino, | 1826 | printk(KERN_INFO "btrfs csum failed ino %lu off %llu csum %u " |
1824 | (unsigned long long)start, csum, | 1827 | "private %llu\n", page->mapping->host->i_ino, |
1825 | (unsigned long long)private); | 1828 | (unsigned long long)start, csum, |
1829 | (unsigned long long)private); | ||
1830 | } | ||
1826 | memset(kaddr + offset, 1, end - start + 1); | 1831 | memset(kaddr + offset, 1, end - start + 1); |
1827 | flush_dcache_page(page); | 1832 | flush_dcache_page(page); |
1828 | kunmap_atomic(kaddr, KM_USER0); | 1833 | kunmap_atomic(kaddr, KM_USER0); |
@@ -2011,6 +2016,57 @@ void btrfs_orphan_cleanup(struct btrfs_root *root) | |||
2011 | } | 2016 | } |
2012 | 2017 | ||
2013 | /* | 2018 | /* |
2019 | * very simple check to peek ahead in the leaf looking for xattrs. If we | ||
2020 | * don't find any xattrs, we know there can't be any acls. | ||
2021 | * | ||
2022 | * slot is the slot the inode is in, objectid is the objectid of the inode | ||
2023 | */ | ||
2024 | static noinline int acls_after_inode_item(struct extent_buffer *leaf, | ||
2025 | int slot, u64 objectid) | ||
2026 | { | ||
2027 | u32 nritems = btrfs_header_nritems(leaf); | ||
2028 | struct btrfs_key found_key; | ||
2029 | int scanned = 0; | ||
2030 | |||
2031 | slot++; | ||
2032 | while (slot < nritems) { | ||
2033 | btrfs_item_key_to_cpu(leaf, &found_key, slot); | ||
2034 | |||
2035 | /* we found a different objectid, there must not be acls */ | ||
2036 | if (found_key.objectid != objectid) | ||
2037 | return 0; | ||
2038 | |||
2039 | /* we found an xattr, assume we've got an acl */ | ||
2040 | if (found_key.type == BTRFS_XATTR_ITEM_KEY) | ||
2041 | return 1; | ||
2042 | |||
2043 | /* | ||
2044 | * we found a key greater than an xattr key, there can't | ||
2045 | * be any acls later on | ||
2046 | */ | ||
2047 | if (found_key.type > BTRFS_XATTR_ITEM_KEY) | ||
2048 | return 0; | ||
2049 | |||
2050 | slot++; | ||
2051 | scanned++; | ||
2052 | |||
2053 | /* | ||
2054 | * it goes inode, inode backrefs, xattrs, extents, | ||
2055 | * so if there are a ton of hard links to an inode there can | ||
2056 | * be a lot of backrefs. Don't waste time searching too hard, | ||
2057 | * this is just an optimization | ||
2058 | */ | ||
2059 | if (scanned >= 8) | ||
2060 | break; | ||
2061 | } | ||
2062 | /* we hit the end of the leaf before we found an xattr or | ||
2063 | * something larger than an xattr. We have to assume the inode | ||
2064 | * has acls | ||
2065 | */ | ||
2066 | return 1; | ||
2067 | } | ||
2068 | |||
2069 | /* | ||
2014 | * read an inode from the btree into the in-memory inode | 2070 | * read an inode from the btree into the in-memory inode |
2015 | */ | 2071 | */ |
2016 | void btrfs_read_locked_inode(struct inode *inode) | 2072 | void btrfs_read_locked_inode(struct inode *inode) |
@@ -2021,6 +2077,7 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
2021 | struct btrfs_timespec *tspec; | 2077 | struct btrfs_timespec *tspec; |
2022 | struct btrfs_root *root = BTRFS_I(inode)->root; | 2078 | struct btrfs_root *root = BTRFS_I(inode)->root; |
2023 | struct btrfs_key location; | 2079 | struct btrfs_key location; |
2080 | int maybe_acls; | ||
2024 | u64 alloc_group_block; | 2081 | u64 alloc_group_block; |
2025 | u32 rdev; | 2082 | u32 rdev; |
2026 | int ret; | 2083 | int ret; |
@@ -2067,6 +2124,16 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
2067 | 2124 | ||
2068 | alloc_group_block = btrfs_inode_block_group(leaf, inode_item); | 2125 | alloc_group_block = btrfs_inode_block_group(leaf, inode_item); |
2069 | 2126 | ||
2127 | /* | ||
2128 | * try to precache a NULL acl entry for files that don't have | ||
2129 | * any xattrs or acls | ||
2130 | */ | ||
2131 | maybe_acls = acls_after_inode_item(leaf, path->slots[0], inode->i_ino); | ||
2132 | if (!maybe_acls) { | ||
2133 | BTRFS_I(inode)->i_acl = NULL; | ||
2134 | BTRFS_I(inode)->i_default_acl = NULL; | ||
2135 | } | ||
2136 | |||
2070 | BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0, | 2137 | BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0, |
2071 | alloc_group_block, 0); | 2138 | alloc_group_block, 0); |
2072 | btrfs_free_path(path); | 2139 | btrfs_free_path(path); |
@@ -2877,6 +2944,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
2877 | err = btrfs_drop_extents(trans, root, inode, | 2944 | err = btrfs_drop_extents(trans, root, inode, |
2878 | cur_offset, | 2945 | cur_offset, |
2879 | cur_offset + hole_size, | 2946 | cur_offset + hole_size, |
2947 | block_end, | ||
2880 | cur_offset, &hint_byte); | 2948 | cur_offset, &hint_byte); |
2881 | if (err) | 2949 | if (err) |
2882 | break; | 2950 | break; |
@@ -3041,8 +3109,8 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3041 | { | 3109 | { |
3042 | struct btrfs_inode *bi = BTRFS_I(inode); | 3110 | struct btrfs_inode *bi = BTRFS_I(inode); |
3043 | 3111 | ||
3044 | bi->i_acl = NULL; | 3112 | bi->i_acl = BTRFS_ACL_NOT_CACHED; |
3045 | bi->i_default_acl = NULL; | 3113 | bi->i_default_acl = BTRFS_ACL_NOT_CACHED; |
3046 | 3114 | ||
3047 | bi->generation = 0; | 3115 | bi->generation = 0; |
3048 | bi->sequence = 0; | 3116 | bi->sequence = 0; |
@@ -3054,6 +3122,7 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3054 | bi->flags = 0; | 3122 | bi->flags = 0; |
3055 | bi->index_cnt = (u64)-1; | 3123 | bi->index_cnt = (u64)-1; |
3056 | bi->last_unlink_trans = 0; | 3124 | bi->last_unlink_trans = 0; |
3125 | bi->ordered_data_close = 0; | ||
3057 | extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); | 3126 | extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); |
3058 | extent_io_tree_init(&BTRFS_I(inode)->io_tree, | 3127 | extent_io_tree_init(&BTRFS_I(inode)->io_tree, |
3059 | inode->i_mapping, GFP_NOFS); | 3128 | inode->i_mapping, GFP_NOFS); |
@@ -4227,7 +4296,6 @@ out: | |||
4227 | } | 4296 | } |
4228 | if (err) { | 4297 | if (err) { |
4229 | free_extent_map(em); | 4298 | free_extent_map(em); |
4230 | WARN_ON(1); | ||
4231 | return ERR_PTR(err); | 4299 | return ERR_PTR(err); |
4232 | } | 4300 | } |
4233 | return em; | 4301 | return em; |
@@ -4634,47 +4702,36 @@ void btrfs_destroy_cachep(void) | |||
4634 | kmem_cache_destroy(btrfs_trans_handle_cachep); | 4702 | kmem_cache_destroy(btrfs_trans_handle_cachep); |
4635 | if (btrfs_transaction_cachep) | 4703 | if (btrfs_transaction_cachep) |
4636 | kmem_cache_destroy(btrfs_transaction_cachep); | 4704 | kmem_cache_destroy(btrfs_transaction_cachep); |
4637 | if (btrfs_bit_radix_cachep) | ||
4638 | kmem_cache_destroy(btrfs_bit_radix_cachep); | ||
4639 | if (btrfs_path_cachep) | 4705 | if (btrfs_path_cachep) |
4640 | kmem_cache_destroy(btrfs_path_cachep); | 4706 | kmem_cache_destroy(btrfs_path_cachep); |
4641 | } | 4707 | } |
4642 | 4708 | ||
4643 | struct kmem_cache *btrfs_cache_create(const char *name, size_t size, | ||
4644 | unsigned long extra_flags, | ||
4645 | void (*ctor)(void *)) | ||
4646 | { | ||
4647 | return kmem_cache_create(name, size, 0, (SLAB_RECLAIM_ACCOUNT | | ||
4648 | SLAB_MEM_SPREAD | extra_flags), ctor); | ||
4649 | } | ||
4650 | |||
4651 | int btrfs_init_cachep(void) | 4709 | int btrfs_init_cachep(void) |
4652 | { | 4710 | { |
4653 | btrfs_inode_cachep = btrfs_cache_create("btrfs_inode_cache", | 4711 | btrfs_inode_cachep = kmem_cache_create("btrfs_inode_cache", |
4654 | sizeof(struct btrfs_inode), | 4712 | sizeof(struct btrfs_inode), 0, |
4655 | 0, init_once); | 4713 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, init_once); |
4656 | if (!btrfs_inode_cachep) | 4714 | if (!btrfs_inode_cachep) |
4657 | goto fail; | 4715 | goto fail; |
4658 | btrfs_trans_handle_cachep = | 4716 | |
4659 | btrfs_cache_create("btrfs_trans_handle_cache", | 4717 | btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle_cache", |
4660 | sizeof(struct btrfs_trans_handle), | 4718 | sizeof(struct btrfs_trans_handle), 0, |
4661 | 0, NULL); | 4719 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); |
4662 | if (!btrfs_trans_handle_cachep) | 4720 | if (!btrfs_trans_handle_cachep) |
4663 | goto fail; | 4721 | goto fail; |
4664 | btrfs_transaction_cachep = btrfs_cache_create("btrfs_transaction_cache", | 4722 | |
4665 | sizeof(struct btrfs_transaction), | 4723 | btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction_cache", |
4666 | 0, NULL); | 4724 | sizeof(struct btrfs_transaction), 0, |
4725 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | ||
4667 | if (!btrfs_transaction_cachep) | 4726 | if (!btrfs_transaction_cachep) |
4668 | goto fail; | 4727 | goto fail; |
4669 | btrfs_path_cachep = btrfs_cache_create("btrfs_path_cache", | 4728 | |
4670 | sizeof(struct btrfs_path), | 4729 | btrfs_path_cachep = kmem_cache_create("btrfs_path_cache", |
4671 | 0, NULL); | 4730 | sizeof(struct btrfs_path), 0, |
4731 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); | ||
4672 | if (!btrfs_path_cachep) | 4732 | if (!btrfs_path_cachep) |
4673 | goto fail; | 4733 | goto fail; |
4674 | btrfs_bit_radix_cachep = btrfs_cache_create("btrfs_radix", 256, | 4734 | |
4675 | SLAB_DESTROY_BY_RCU, NULL); | ||
4676 | if (!btrfs_bit_radix_cachep) | ||
4677 | goto fail; | ||
4678 | return 0; | 4735 | return 0; |
4679 | fail: | 4736 | fail: |
4680 | btrfs_destroy_cachep(); | 4737 | btrfs_destroy_cachep(); |
@@ -4972,7 +5029,7 @@ out_fail: | |||
4972 | 5029 | ||
4973 | static int prealloc_file_range(struct btrfs_trans_handle *trans, | 5030 | static int prealloc_file_range(struct btrfs_trans_handle *trans, |
4974 | struct inode *inode, u64 start, u64 end, | 5031 | struct inode *inode, u64 start, u64 end, |
4975 | u64 alloc_hint, int mode) | 5032 | u64 locked_end, u64 alloc_hint, int mode) |
4976 | { | 5033 | { |
4977 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5034 | struct btrfs_root *root = BTRFS_I(inode)->root; |
4978 | struct btrfs_key ins; | 5035 | struct btrfs_key ins; |
@@ -4993,7 +5050,8 @@ static int prealloc_file_range(struct btrfs_trans_handle *trans, | |||
4993 | ret = insert_reserved_file_extent(trans, inode, | 5050 | ret = insert_reserved_file_extent(trans, inode, |
4994 | cur_offset, ins.objectid, | 5051 | cur_offset, ins.objectid, |
4995 | ins.offset, ins.offset, | 5052 | ins.offset, ins.offset, |
4996 | ins.offset, 0, 0, 0, | 5053 | ins.offset, locked_end, |
5054 | 0, 0, 0, | ||
4997 | BTRFS_FILE_EXTENT_PREALLOC); | 5055 | BTRFS_FILE_EXTENT_PREALLOC); |
4998 | BUG_ON(ret); | 5056 | BUG_ON(ret); |
4999 | num_bytes -= ins.offset; | 5057 | num_bytes -= ins.offset; |
@@ -5022,6 +5080,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5022 | u64 alloc_start; | 5080 | u64 alloc_start; |
5023 | u64 alloc_end; | 5081 | u64 alloc_end; |
5024 | u64 alloc_hint = 0; | 5082 | u64 alloc_hint = 0; |
5083 | u64 locked_end; | ||
5025 | u64 mask = BTRFS_I(inode)->root->sectorsize - 1; | 5084 | u64 mask = BTRFS_I(inode)->root->sectorsize - 1; |
5026 | struct extent_map *em; | 5085 | struct extent_map *em; |
5027 | struct btrfs_trans_handle *trans; | 5086 | struct btrfs_trans_handle *trans; |
@@ -5043,6 +5102,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5043 | goto out; | 5102 | goto out; |
5044 | } | 5103 | } |
5045 | 5104 | ||
5105 | locked_end = alloc_end - 1; | ||
5046 | while (1) { | 5106 | while (1) { |
5047 | struct btrfs_ordered_extent *ordered; | 5107 | struct btrfs_ordered_extent *ordered; |
5048 | 5108 | ||
@@ -5055,8 +5115,8 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5055 | /* the extent lock is ordered inside the running | 5115 | /* the extent lock is ordered inside the running |
5056 | * transaction | 5116 | * transaction |
5057 | */ | 5117 | */ |
5058 | lock_extent(&BTRFS_I(inode)->io_tree, alloc_start, | 5118 | lock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, |
5059 | alloc_end - 1, GFP_NOFS); | 5119 | GFP_NOFS); |
5060 | ordered = btrfs_lookup_first_ordered_extent(inode, | 5120 | ordered = btrfs_lookup_first_ordered_extent(inode, |
5061 | alloc_end - 1); | 5121 | alloc_end - 1); |
5062 | if (ordered && | 5122 | if (ordered && |
@@ -5064,7 +5124,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5064 | ordered->file_offset < alloc_end) { | 5124 | ordered->file_offset < alloc_end) { |
5065 | btrfs_put_ordered_extent(ordered); | 5125 | btrfs_put_ordered_extent(ordered); |
5066 | unlock_extent(&BTRFS_I(inode)->io_tree, | 5126 | unlock_extent(&BTRFS_I(inode)->io_tree, |
5067 | alloc_start, alloc_end - 1, GFP_NOFS); | 5127 | alloc_start, locked_end, GFP_NOFS); |
5068 | btrfs_end_transaction(trans, BTRFS_I(inode)->root); | 5128 | btrfs_end_transaction(trans, BTRFS_I(inode)->root); |
5069 | 5129 | ||
5070 | /* | 5130 | /* |
@@ -5089,7 +5149,8 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5089 | last_byte = (last_byte + mask) & ~mask; | 5149 | last_byte = (last_byte + mask) & ~mask; |
5090 | if (em->block_start == EXTENT_MAP_HOLE) { | 5150 | if (em->block_start == EXTENT_MAP_HOLE) { |
5091 | ret = prealloc_file_range(trans, inode, cur_offset, | 5151 | ret = prealloc_file_range(trans, inode, cur_offset, |
5092 | last_byte, alloc_hint, mode); | 5152 | last_byte, locked_end + 1, |
5153 | alloc_hint, mode); | ||
5093 | if (ret < 0) { | 5154 | if (ret < 0) { |
5094 | free_extent_map(em); | 5155 | free_extent_map(em); |
5095 | break; | 5156 | break; |
@@ -5105,7 +5166,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5105 | break; | 5166 | break; |
5106 | } | 5167 | } |
5107 | } | 5168 | } |
5108 | unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, alloc_end - 1, | 5169 | unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, |
5109 | GFP_NOFS); | 5170 | GFP_NOFS); |
5110 | 5171 | ||
5111 | btrfs_end_transaction(trans, BTRFS_I(inode)->root); | 5172 | btrfs_end_transaction(trans, BTRFS_I(inode)->root); |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9f135e878507..2624b53ea783 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -437,10 +437,6 @@ out_unlock: | |||
437 | return 0; | 437 | return 0; |
438 | } | 438 | } |
439 | 439 | ||
440 | /* | ||
441 | * Called inside transaction, so use GFP_NOFS | ||
442 | */ | ||
443 | |||
444 | static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg) | 440 | static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg) |
445 | { | 441 | { |
446 | u64 new_size; | 442 | u64 new_size; |
@@ -477,11 +473,13 @@ static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg) | |||
477 | *devstr = '\0'; | 473 | *devstr = '\0'; |
478 | devstr = vol_args->name; | 474 | devstr = vol_args->name; |
479 | devid = simple_strtoull(devstr, &end, 10); | 475 | devid = simple_strtoull(devstr, &end, 10); |
480 | printk(KERN_INFO "resizing devid %llu\n", devid); | 476 | printk(KERN_INFO "resizing devid %llu\n", |
477 | (unsigned long long)devid); | ||
481 | } | 478 | } |
482 | device = btrfs_find_device(root, devid, NULL, NULL); | 479 | device = btrfs_find_device(root, devid, NULL, NULL); |
483 | if (!device) { | 480 | if (!device) { |
484 | printk(KERN_INFO "resizer unable to find device %llu\n", devid); | 481 | printk(KERN_INFO "resizer unable to find device %llu\n", |
482 | (unsigned long long)devid); | ||
485 | ret = -EINVAL; | 483 | ret = -EINVAL; |
486 | goto out_unlock; | 484 | goto out_unlock; |
487 | } | 485 | } |
@@ -805,7 +803,8 @@ static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
805 | BUG_ON(!trans); | 803 | BUG_ON(!trans); |
806 | 804 | ||
807 | /* punch hole in destination first */ | 805 | /* punch hole in destination first */ |
808 | btrfs_drop_extents(trans, root, inode, off, off+len, 0, &hint_byte); | 806 | btrfs_drop_extents(trans, root, inode, off, off + len, |
807 | off + len, 0, &hint_byte); | ||
809 | 808 | ||
810 | /* clone data */ | 809 | /* clone data */ |
811 | key.objectid = src->i_ino; | 810 | key.objectid = src->i_ino; |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index a7acfe639a44..2ff7cd2db25f 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -68,7 +68,7 @@ enum { | |||
68 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, | 68 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, |
69 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, | 69 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, |
70 | Opt_ssd, Opt_thread_pool, Opt_noacl, Opt_compress, Opt_notreelog, | 70 | Opt_ssd, Opt_thread_pool, Opt_noacl, Opt_compress, Opt_notreelog, |
71 | Opt_flushoncommit, Opt_err, | 71 | Opt_ratio, Opt_flushoncommit, Opt_err, |
72 | }; | 72 | }; |
73 | 73 | ||
74 | static match_table_t tokens = { | 74 | static match_table_t tokens = { |
@@ -87,6 +87,7 @@ static match_table_t tokens = { | |||
87 | {Opt_noacl, "noacl"}, | 87 | {Opt_noacl, "noacl"}, |
88 | {Opt_notreelog, "notreelog"}, | 88 | {Opt_notreelog, "notreelog"}, |
89 | {Opt_flushoncommit, "flushoncommit"}, | 89 | {Opt_flushoncommit, "flushoncommit"}, |
90 | {Opt_ratio, "metadata_ratio=%d"}, | ||
90 | {Opt_err, NULL}, | 91 | {Opt_err, NULL}, |
91 | }; | 92 | }; |
92 | 93 | ||
@@ -195,7 +196,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
195 | info->max_extent = max_t(u64, | 196 | info->max_extent = max_t(u64, |
196 | info->max_extent, root->sectorsize); | 197 | info->max_extent, root->sectorsize); |
197 | printk(KERN_INFO "btrfs: max_extent at %llu\n", | 198 | printk(KERN_INFO "btrfs: max_extent at %llu\n", |
198 | info->max_extent); | 199 | (unsigned long long)info->max_extent); |
199 | } | 200 | } |
200 | break; | 201 | break; |
201 | case Opt_max_inline: | 202 | case Opt_max_inline: |
@@ -210,7 +211,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
210 | root->sectorsize); | 211 | root->sectorsize); |
211 | } | 212 | } |
212 | printk(KERN_INFO "btrfs: max_inline at %llu\n", | 213 | printk(KERN_INFO "btrfs: max_inline at %llu\n", |
213 | info->max_inline); | 214 | (unsigned long long)info->max_inline); |
214 | } | 215 | } |
215 | break; | 216 | break; |
216 | case Opt_alloc_start: | 217 | case Opt_alloc_start: |
@@ -220,7 +221,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
220 | kfree(num); | 221 | kfree(num); |
221 | printk(KERN_INFO | 222 | printk(KERN_INFO |
222 | "btrfs: allocations start at %llu\n", | 223 | "btrfs: allocations start at %llu\n", |
223 | info->alloc_start); | 224 | (unsigned long long)info->alloc_start); |
224 | } | 225 | } |
225 | break; | 226 | break; |
226 | case Opt_noacl: | 227 | case Opt_noacl: |
@@ -234,6 +235,15 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
234 | printk(KERN_INFO "btrfs: turning on flush-on-commit\n"); | 235 | printk(KERN_INFO "btrfs: turning on flush-on-commit\n"); |
235 | btrfs_set_opt(info->mount_opt, FLUSHONCOMMIT); | 236 | btrfs_set_opt(info->mount_opt, FLUSHONCOMMIT); |
236 | break; | 237 | break; |
238 | case Opt_ratio: | ||
239 | intarg = 0; | ||
240 | match_int(&args[0], &intarg); | ||
241 | if (intarg) { | ||
242 | info->metadata_ratio = intarg; | ||
243 | printk(KERN_INFO "btrfs: metadata ratio %d\n", | ||
244 | info->metadata_ratio); | ||
245 | } | ||
246 | break; | ||
237 | default: | 247 | default: |
238 | break; | 248 | break; |
239 | } | 249 | } |
@@ -410,11 +420,14 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
410 | if (btrfs_test_opt(root, NOBARRIER)) | 420 | if (btrfs_test_opt(root, NOBARRIER)) |
411 | seq_puts(seq, ",nobarrier"); | 421 | seq_puts(seq, ",nobarrier"); |
412 | if (info->max_extent != (u64)-1) | 422 | if (info->max_extent != (u64)-1) |
413 | seq_printf(seq, ",max_extent=%llu", info->max_extent); | 423 | seq_printf(seq, ",max_extent=%llu", |
424 | (unsigned long long)info->max_extent); | ||
414 | if (info->max_inline != 8192 * 1024) | 425 | if (info->max_inline != 8192 * 1024) |
415 | seq_printf(seq, ",max_inline=%llu", info->max_inline); | 426 | seq_printf(seq, ",max_inline=%llu", |
427 | (unsigned long long)info->max_inline); | ||
416 | if (info->alloc_start != 0) | 428 | if (info->alloc_start != 0) |
417 | seq_printf(seq, ",alloc_start=%llu", info->alloc_start); | 429 | seq_printf(seq, ",alloc_start=%llu", |
430 | (unsigned long long)info->alloc_start); | ||
418 | if (info->thread_pool_size != min_t(unsigned long, | 431 | if (info->thread_pool_size != min_t(unsigned long, |
419 | num_online_cpus() + 2, 8)) | 432 | num_online_cpus() + 2, 8)) |
420 | seq_printf(seq, ",thread_pool=%d", info->thread_pool_size); | 433 | seq_printf(seq, ",thread_pool=%d", info->thread_pool_size); |
@@ -423,9 +436,9 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
423 | if (btrfs_test_opt(root, SSD)) | 436 | if (btrfs_test_opt(root, SSD)) |
424 | seq_puts(seq, ",ssd"); | 437 | seq_puts(seq, ",ssd"); |
425 | if (btrfs_test_opt(root, NOTREELOG)) | 438 | if (btrfs_test_opt(root, NOTREELOG)) |
426 | seq_puts(seq, ",no-treelog"); | 439 | seq_puts(seq, ",notreelog"); |
427 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) | 440 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) |
428 | seq_puts(seq, ",flush-on-commit"); | 441 | seq_puts(seq, ",flushoncommit"); |
429 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) | 442 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) |
430 | seq_puts(seq, ",noacl"); | 443 | seq_puts(seq, ",noacl"); |
431 | return 0; | 444 | return 0; |
@@ -489,8 +502,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, | |||
489 | 502 | ||
490 | if (s->s_root) { | 503 | if (s->s_root) { |
491 | if ((flags ^ s->s_flags) & MS_RDONLY) { | 504 | if ((flags ^ s->s_flags) & MS_RDONLY) { |
492 | up_write(&s->s_umount); | 505 | deactivate_locked_super(s); |
493 | deactivate_super(s); | ||
494 | error = -EBUSY; | 506 | error = -EBUSY; |
495 | goto error_close_devices; | 507 | goto error_close_devices; |
496 | } | 508 | } |
@@ -504,8 +516,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, | |||
504 | error = btrfs_fill_super(s, fs_devices, data, | 516 | error = btrfs_fill_super(s, fs_devices, data, |
505 | flags & MS_SILENT ? 1 : 0); | 517 | flags & MS_SILENT ? 1 : 0); |
506 | if (error) { | 518 | if (error) { |
507 | up_write(&s->s_umount); | 519 | deactivate_locked_super(s); |
508 | deactivate_super(s); | ||
509 | goto error_free_subvol_name; | 520 | goto error_free_subvol_name; |
510 | } | 521 | } |
511 | 522 | ||
@@ -522,15 +533,13 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, | |||
522 | mutex_unlock(&s->s_root->d_inode->i_mutex); | 533 | mutex_unlock(&s->s_root->d_inode->i_mutex); |
523 | 534 | ||
524 | if (IS_ERR(root)) { | 535 | if (IS_ERR(root)) { |
525 | up_write(&s->s_umount); | 536 | deactivate_locked_super(s); |
526 | deactivate_super(s); | ||
527 | error = PTR_ERR(root); | 537 | error = PTR_ERR(root); |
528 | goto error_free_subvol_name; | 538 | goto error_free_subvol_name; |
529 | } | 539 | } |
530 | if (!root->d_inode) { | 540 | if (!root->d_inode) { |
531 | dput(root); | 541 | dput(root); |
532 | up_write(&s->s_umount); | 542 | deactivate_locked_super(s); |
533 | deactivate_super(s); | ||
534 | error = -ENXIO; | 543 | error = -ENXIO; |
535 | goto error_free_subvol_name; | 544 | goto error_free_subvol_name; |
536 | } | 545 | } |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 2869b3361eb6..01b143605ec1 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -687,7 +687,13 @@ static noinline int wait_transaction_pre_flush(struct btrfs_fs_info *info) | |||
687 | prepare_to_wait(&info->transaction_wait, &wait, | 687 | prepare_to_wait(&info->transaction_wait, &wait, |
688 | TASK_UNINTERRUPTIBLE); | 688 | TASK_UNINTERRUPTIBLE); |
689 | mutex_unlock(&info->trans_mutex); | 689 | mutex_unlock(&info->trans_mutex); |
690 | |||
691 | atomic_dec(&info->throttles); | ||
692 | wake_up(&info->transaction_throttle); | ||
693 | |||
690 | schedule(); | 694 | schedule(); |
695 | |||
696 | atomic_inc(&info->throttles); | ||
691 | mutex_lock(&info->trans_mutex); | 697 | mutex_lock(&info->trans_mutex); |
692 | finish_wait(&info->transaction_wait, &wait); | 698 | finish_wait(&info->transaction_wait, &wait); |
693 | } | 699 | } |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 25f20ea11f27..db5e212e8445 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -536,7 +536,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
536 | saved_nbytes = inode_get_bytes(inode); | 536 | saved_nbytes = inode_get_bytes(inode); |
537 | /* drop any overlapping extents */ | 537 | /* drop any overlapping extents */ |
538 | ret = btrfs_drop_extents(trans, root, inode, | 538 | ret = btrfs_drop_extents(trans, root, inode, |
539 | start, extent_end, start, &alloc_hint); | 539 | start, extent_end, extent_end, start, &alloc_hint); |
540 | BUG_ON(ret); | 540 | BUG_ON(ret); |
541 | 541 | ||
542 | if (found_type == BTRFS_FILE_EXTENT_REG || | 542 | if (found_type == BTRFS_FILE_EXTENT_REG || |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e53835b88594..a6d35b0054ca 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1440,6 +1440,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) | |||
1440 | device->io_align = root->sectorsize; | 1440 | device->io_align = root->sectorsize; |
1441 | device->sector_size = root->sectorsize; | 1441 | device->sector_size = root->sectorsize; |
1442 | device->total_bytes = i_size_read(bdev->bd_inode); | 1442 | device->total_bytes = i_size_read(bdev->bd_inode); |
1443 | device->disk_total_bytes = device->total_bytes; | ||
1443 | device->dev_root = root->fs_info->dev_root; | 1444 | device->dev_root = root->fs_info->dev_root; |
1444 | device->bdev = bdev; | 1445 | device->bdev = bdev; |
1445 | device->in_fs_metadata = 1; | 1446 | device->in_fs_metadata = 1; |
@@ -1543,7 +1544,7 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans, | |||
1543 | btrfs_set_device_io_align(leaf, dev_item, device->io_align); | 1544 | btrfs_set_device_io_align(leaf, dev_item, device->io_align); |
1544 | btrfs_set_device_io_width(leaf, dev_item, device->io_width); | 1545 | btrfs_set_device_io_width(leaf, dev_item, device->io_width); |
1545 | btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); | 1546 | btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); |
1546 | btrfs_set_device_total_bytes(leaf, dev_item, device->total_bytes); | 1547 | btrfs_set_device_total_bytes(leaf, dev_item, device->disk_total_bytes); |
1547 | btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used); | 1548 | btrfs_set_device_bytes_used(leaf, dev_item, device->bytes_used); |
1548 | btrfs_mark_buffer_dirty(leaf); | 1549 | btrfs_mark_buffer_dirty(leaf); |
1549 | 1550 | ||
@@ -1940,14 +1941,6 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) | |||
1940 | device->total_bytes = new_size; | 1941 | device->total_bytes = new_size; |
1941 | if (device->writeable) | 1942 | if (device->writeable) |
1942 | device->fs_devices->total_rw_bytes -= diff; | 1943 | device->fs_devices->total_rw_bytes -= diff; |
1943 | ret = btrfs_update_device(trans, device); | ||
1944 | if (ret) { | ||
1945 | unlock_chunks(root); | ||
1946 | btrfs_end_transaction(trans, root); | ||
1947 | goto done; | ||
1948 | } | ||
1949 | WARN_ON(diff > old_total); | ||
1950 | btrfs_set_super_total_bytes(super_copy, old_total - diff); | ||
1951 | unlock_chunks(root); | 1944 | unlock_chunks(root); |
1952 | btrfs_end_transaction(trans, root); | 1945 | btrfs_end_transaction(trans, root); |
1953 | 1946 | ||
@@ -1979,7 +1972,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) | |||
1979 | length = btrfs_dev_extent_length(l, dev_extent); | 1972 | length = btrfs_dev_extent_length(l, dev_extent); |
1980 | 1973 | ||
1981 | if (key.offset + length <= new_size) | 1974 | if (key.offset + length <= new_size) |
1982 | goto done; | 1975 | break; |
1983 | 1976 | ||
1984 | chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent); | 1977 | chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent); |
1985 | chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); | 1978 | chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); |
@@ -1992,6 +1985,26 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) | |||
1992 | goto done; | 1985 | goto done; |
1993 | } | 1986 | } |
1994 | 1987 | ||
1988 | /* Shrinking succeeded, else we would be at "done". */ | ||
1989 | trans = btrfs_start_transaction(root, 1); | ||
1990 | if (!trans) { | ||
1991 | ret = -ENOMEM; | ||
1992 | goto done; | ||
1993 | } | ||
1994 | lock_chunks(root); | ||
1995 | |||
1996 | device->disk_total_bytes = new_size; | ||
1997 | /* Now btrfs_update_device() will change the on-disk size. */ | ||
1998 | ret = btrfs_update_device(trans, device); | ||
1999 | if (ret) { | ||
2000 | unlock_chunks(root); | ||
2001 | btrfs_end_transaction(trans, root); | ||
2002 | goto done; | ||
2003 | } | ||
2004 | WARN_ON(diff > old_total); | ||
2005 | btrfs_set_super_total_bytes(super_copy, old_total - diff); | ||
2006 | unlock_chunks(root); | ||
2007 | btrfs_end_transaction(trans, root); | ||
1995 | done: | 2008 | done: |
1996 | btrfs_free_path(path); | 2009 | btrfs_free_path(path); |
1997 | return ret; | 2010 | return ret; |
@@ -3076,7 +3089,8 @@ static int fill_device_from_item(struct extent_buffer *leaf, | |||
3076 | unsigned long ptr; | 3089 | unsigned long ptr; |
3077 | 3090 | ||
3078 | device->devid = btrfs_device_id(leaf, dev_item); | 3091 | device->devid = btrfs_device_id(leaf, dev_item); |
3079 | device->total_bytes = btrfs_device_total_bytes(leaf, dev_item); | 3092 | device->disk_total_bytes = btrfs_device_total_bytes(leaf, dev_item); |
3093 | device->total_bytes = device->disk_total_bytes; | ||
3080 | device->bytes_used = btrfs_device_bytes_used(leaf, dev_item); | 3094 | device->bytes_used = btrfs_device_bytes_used(leaf, dev_item); |
3081 | device->type = btrfs_device_type(leaf, dev_item); | 3095 | device->type = btrfs_device_type(leaf, dev_item); |
3082 | device->io_align = btrfs_device_io_align(leaf, dev_item); | 3096 | device->io_align = btrfs_device_io_align(leaf, dev_item); |
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 5836327ba5dd..5c3ff6d02fd7 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h | |||
@@ -61,6 +61,9 @@ struct btrfs_device { | |||
61 | /* size of the device */ | 61 | /* size of the device */ |
62 | u64 total_bytes; | 62 | u64 total_bytes; |
63 | 63 | ||
64 | /* size of the disk */ | ||
65 | u64 disk_total_bytes; | ||
66 | |||
64 | /* bytes used */ | 67 | /* bytes used */ |
65 | u64 bytes_used; | 68 | u64 bytes_used; |
66 | 69 | ||