diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-10-15 18:06:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-10-15 18:06:37 -0400 |
commit | dcbeb0bec5f2695c3ff53f174efb8e03c209f3f3 (patch) | |
tree | 30d223a3a3c7470c657284ef030657bd1753d4d3 /fs/btrfs | |
parent | 2b650df2cea96e487f2fd9ecaa68e533ea9b5ed7 (diff) | |
parent | 444528b3e614f7f2391488d9bca8e0b872db909b (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable:
Btrfs: always pin metadata in discard mode
Btrfs: enable discard support
Btrfs: add -o discard option
Btrfs: properly wait log writers during log sync
Btrfs: fix possible ENOSPC problems with truncate
Btrfs: fix btrfs acl #ifdef checks
Btrfs: streamline tree-log btree block writeout
Btrfs: avoid tree log commit when there are no changes
Btrfs: only write one super copy during fsync
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/acl.c | 6 | ||||
-rw-r--r-- | fs/btrfs/btrfs_inode.h | 6 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 4 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 2 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 17 | ||||
-rw-r--r-- | fs/btrfs/file.c | 41 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 33 | ||||
-rw-r--r-- | fs/btrfs/super.c | 9 | ||||
-rw-r--r-- | fs/btrfs/transaction.c | 45 | ||||
-rw-r--r-- | fs/btrfs/transaction.h | 5 | ||||
-rw-r--r-- | fs/btrfs/tree-log.c | 48 | ||||
-rw-r--r-- | fs/btrfs/tree-log.h | 3 | ||||
-rw-r--r-- | fs/btrfs/xattr.c | 2 |
13 files changed, 179 insertions, 42 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 69b355ae7f4..36160424427 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include "btrfs_inode.h" | 27 | #include "btrfs_inode.h" |
28 | #include "xattr.h" | 28 | #include "xattr.h" |
29 | 29 | ||
30 | #ifdef CONFIG_BTRFS_POSIX_ACL | 30 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
31 | 31 | ||
32 | static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | 32 | static struct posix_acl *btrfs_get_acl(struct inode *inode, int type) |
33 | { | 33 | { |
@@ -313,7 +313,7 @@ struct xattr_handler btrfs_xattr_acl_access_handler = { | |||
313 | .set = btrfs_xattr_acl_access_set, | 313 | .set = btrfs_xattr_acl_access_set, |
314 | }; | 314 | }; |
315 | 315 | ||
316 | #else /* CONFIG_BTRFS_POSIX_ACL */ | 316 | #else /* CONFIG_BTRFS_FS_POSIX_ACL */ |
317 | 317 | ||
318 | int btrfs_acl_chmod(struct inode *inode) | 318 | int btrfs_acl_chmod(struct inode *inode) |
319 | { | 319 | { |
@@ -325,4 +325,4 @@ int btrfs_init_acl(struct inode *inode, struct inode *dir) | |||
325 | return 0; | 325 | return 0; |
326 | } | 326 | } |
327 | 327 | ||
328 | #endif /* CONFIG_BTRFS_POSIX_ACL */ | 328 | #endif /* CONFIG_BTRFS_FS_POSIX_ACL */ |
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index c71abec0ab9..f6783a42f01 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -86,6 +86,12 @@ struct btrfs_inode { | |||
86 | * transid of the trans_handle that last modified this inode | 86 | * transid of the trans_handle that last modified this inode |
87 | */ | 87 | */ |
88 | u64 last_trans; | 88 | u64 last_trans; |
89 | |||
90 | /* | ||
91 | * log transid when this inode was last modified | ||
92 | */ | ||
93 | u64 last_sub_trans; | ||
94 | |||
89 | /* | 95 | /* |
90 | * transid that last logged this inode | 96 | * transid that last logged this inode |
91 | */ | 97 | */ |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 1bb897ecdee..444b3e9b92a 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -1009,6 +1009,7 @@ struct btrfs_root { | |||
1009 | atomic_t log_writers; | 1009 | atomic_t log_writers; |
1010 | atomic_t log_commit[2]; | 1010 | atomic_t log_commit[2]; |
1011 | unsigned long log_transid; | 1011 | unsigned long log_transid; |
1012 | unsigned long last_log_commit; | ||
1012 | unsigned long log_batch; | 1013 | unsigned long log_batch; |
1013 | pid_t log_start_pid; | 1014 | pid_t log_start_pid; |
1014 | bool log_multiple_pids; | 1015 | bool log_multiple_pids; |
@@ -1152,6 +1153,7 @@ struct btrfs_root { | |||
1152 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) | 1153 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) |
1153 | #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) | 1154 | #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) |
1154 | #define BTRFS_MOUNT_NOSSD (1 << 9) | 1155 | #define BTRFS_MOUNT_NOSSD (1 << 9) |
1156 | #define BTRFS_MOUNT_DISCARD (1 << 10) | ||
1155 | 1157 | ||
1156 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1158 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1157 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1159 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
@@ -2373,7 +2375,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options); | |||
2373 | int btrfs_sync_fs(struct super_block *sb, int wait); | 2375 | int btrfs_sync_fs(struct super_block *sb, int wait); |
2374 | 2376 | ||
2375 | /* acl.c */ | 2377 | /* acl.c */ |
2376 | #ifdef CONFIG_BTRFS_POSIX_ACL | 2378 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
2377 | int btrfs_check_acl(struct inode *inode, int mask); | 2379 | int btrfs_check_acl(struct inode *inode, int mask); |
2378 | #else | 2380 | #else |
2379 | #define btrfs_check_acl NULL | 2381 | #define btrfs_check_acl NULL |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 100551a66c4..02b6afbd745 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -917,6 +917,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
917 | atomic_set(&root->log_writers, 0); | 917 | atomic_set(&root->log_writers, 0); |
918 | root->log_batch = 0; | 918 | root->log_batch = 0; |
919 | root->log_transid = 0; | 919 | root->log_transid = 0; |
920 | root->last_log_commit = 0; | ||
920 | extent_io_tree_init(&root->dirty_log_pages, | 921 | extent_io_tree_init(&root->dirty_log_pages, |
921 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 922 | fs_info->btree_inode->i_mapping, GFP_NOFS); |
922 | 923 | ||
@@ -1087,6 +1088,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans, | |||
1087 | WARN_ON(root->log_root); | 1088 | WARN_ON(root->log_root); |
1088 | root->log_root = log_root; | 1089 | root->log_root = log_root; |
1089 | root->log_transid = 0; | 1090 | root->log_transid = 0; |
1091 | root->last_log_commit = 0; | ||
1090 | return 0; | 1092 | return 0; |
1091 | } | 1093 | } |
1092 | 1094 | ||
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d0c4d584efa..e238a0cdac6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -1568,23 +1568,23 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans, | |||
1568 | return ret; | 1568 | return ret; |
1569 | } | 1569 | } |
1570 | 1570 | ||
1571 | #ifdef BIO_RW_DISCARD | ||
1572 | static void btrfs_issue_discard(struct block_device *bdev, | 1571 | static void btrfs_issue_discard(struct block_device *bdev, |
1573 | u64 start, u64 len) | 1572 | u64 start, u64 len) |
1574 | { | 1573 | { |
1575 | blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, | 1574 | blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, |
1576 | DISCARD_FL_BARRIER); | 1575 | DISCARD_FL_BARRIER); |
1577 | } | 1576 | } |
1578 | #endif | ||
1579 | 1577 | ||
1580 | static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | 1578 | static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, |
1581 | u64 num_bytes) | 1579 | u64 num_bytes) |
1582 | { | 1580 | { |
1583 | #ifdef BIO_RW_DISCARD | ||
1584 | int ret; | 1581 | int ret; |
1585 | u64 map_length = num_bytes; | 1582 | u64 map_length = num_bytes; |
1586 | struct btrfs_multi_bio *multi = NULL; | 1583 | struct btrfs_multi_bio *multi = NULL; |
1587 | 1584 | ||
1585 | if (!btrfs_test_opt(root, DISCARD)) | ||
1586 | return 0; | ||
1587 | |||
1588 | /* Tell the block device(s) that the sectors can be discarded */ | 1588 | /* Tell the block device(s) that the sectors can be discarded */ |
1589 | ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, | 1589 | ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, |
1590 | bytenr, &map_length, &multi, 0); | 1590 | bytenr, &map_length, &multi, 0); |
@@ -1604,9 +1604,6 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | |||
1604 | } | 1604 | } |
1605 | 1605 | ||
1606 | return ret; | 1606 | return ret; |
1607 | #else | ||
1608 | return 0; | ||
1609 | #endif | ||
1610 | } | 1607 | } |
1611 | 1608 | ||
1612 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | 1609 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
@@ -3690,6 +3687,14 @@ static int pin_down_bytes(struct btrfs_trans_handle *trans, | |||
3690 | if (is_data) | 3687 | if (is_data) |
3691 | goto pinit; | 3688 | goto pinit; |
3692 | 3689 | ||
3690 | /* | ||
3691 | * discard is sloooow, and so triggering discards on | ||
3692 | * individual btree blocks isn't a good plan. Just | ||
3693 | * pin everything in discard mode. | ||
3694 | */ | ||
3695 | if (btrfs_test_opt(root, DISCARD)) | ||
3696 | goto pinit; | ||
3697 | |||
3693 | buf = btrfs_find_tree_block(root, bytenr, num_bytes); | 3698 | buf = btrfs_find_tree_block(root, bytenr, num_bytes); |
3694 | if (!buf) | 3699 | if (!buf) |
3695 | goto pinit; | 3700 | goto pinit; |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 2d623aa0625..06550affbd2 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1086,8 +1086,10 @@ out_nolock: | |||
1086 | btrfs_end_transaction(trans, root); | 1086 | btrfs_end_transaction(trans, root); |
1087 | else | 1087 | else |
1088 | btrfs_commit_transaction(trans, root); | 1088 | btrfs_commit_transaction(trans, root); |
1089 | } else { | 1089 | } else if (ret != BTRFS_NO_LOG_SYNC) { |
1090 | btrfs_commit_transaction(trans, root); | 1090 | btrfs_commit_transaction(trans, root); |
1091 | } else { | ||
1092 | btrfs_end_transaction(trans, root); | ||
1091 | } | 1093 | } |
1092 | } | 1094 | } |
1093 | if (file->f_flags & O_DIRECT) { | 1095 | if (file->f_flags & O_DIRECT) { |
@@ -1137,6 +1139,13 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1137 | int ret = 0; | 1139 | int ret = 0; |
1138 | struct btrfs_trans_handle *trans; | 1140 | struct btrfs_trans_handle *trans; |
1139 | 1141 | ||
1142 | |||
1143 | /* we wait first, since the writeback may change the inode */ | ||
1144 | root->log_batch++; | ||
1145 | /* the VFS called filemap_fdatawrite for us */ | ||
1146 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | ||
1147 | root->log_batch++; | ||
1148 | |||
1140 | /* | 1149 | /* |
1141 | * check the transaction that last modified this inode | 1150 | * check the transaction that last modified this inode |
1142 | * and see if its already been committed | 1151 | * and see if its already been committed |
@@ -1144,6 +1153,11 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1144 | if (!BTRFS_I(inode)->last_trans) | 1153 | if (!BTRFS_I(inode)->last_trans) |
1145 | goto out; | 1154 | goto out; |
1146 | 1155 | ||
1156 | /* | ||
1157 | * if the last transaction that changed this file was before | ||
1158 | * the current transaction, we can bail out now without any | ||
1159 | * syncing | ||
1160 | */ | ||
1147 | mutex_lock(&root->fs_info->trans_mutex); | 1161 | mutex_lock(&root->fs_info->trans_mutex); |
1148 | if (BTRFS_I(inode)->last_trans <= | 1162 | if (BTRFS_I(inode)->last_trans <= |
1149 | root->fs_info->last_trans_committed) { | 1163 | root->fs_info->last_trans_committed) { |
@@ -1153,13 +1167,6 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1153 | } | 1167 | } |
1154 | mutex_unlock(&root->fs_info->trans_mutex); | 1168 | mutex_unlock(&root->fs_info->trans_mutex); |
1155 | 1169 | ||
1156 | root->log_batch++; | ||
1157 | filemap_fdatawrite(inode->i_mapping); | ||
1158 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | ||
1159 | root->log_batch++; | ||
1160 | |||
1161 | if (datasync && !(inode->i_state & I_DIRTY_PAGES)) | ||
1162 | goto out; | ||
1163 | /* | 1170 | /* |
1164 | * ok we haven't committed the transaction yet, lets do a commit | 1171 | * ok we haven't committed the transaction yet, lets do a commit |
1165 | */ | 1172 | */ |
@@ -1188,14 +1195,18 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1188 | */ | 1195 | */ |
1189 | mutex_unlock(&dentry->d_inode->i_mutex); | 1196 | mutex_unlock(&dentry->d_inode->i_mutex); |
1190 | 1197 | ||
1191 | if (ret > 0) { | 1198 | if (ret != BTRFS_NO_LOG_SYNC) { |
1192 | ret = btrfs_commit_transaction(trans, root); | 1199 | if (ret > 0) { |
1193 | } else { | ||
1194 | ret = btrfs_sync_log(trans, root); | ||
1195 | if (ret == 0) | ||
1196 | ret = btrfs_end_transaction(trans, root); | ||
1197 | else | ||
1198 | ret = btrfs_commit_transaction(trans, root); | 1200 | ret = btrfs_commit_transaction(trans, root); |
1201 | } else { | ||
1202 | ret = btrfs_sync_log(trans, root); | ||
1203 | if (ret == 0) | ||
1204 | ret = btrfs_end_transaction(trans, root); | ||
1205 | else | ||
1206 | ret = btrfs_commit_transaction(trans, root); | ||
1207 | } | ||
1208 | } else { | ||
1209 | ret = btrfs_end_transaction(trans, root); | ||
1199 | } | 1210 | } |
1200 | mutex_lock(&dentry->d_inode->i_mutex); | 1211 | mutex_lock(&dentry->d_inode->i_mutex); |
1201 | out: | 1212 | out: |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9e138b793dc..dae12dc7e15 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -3032,12 +3032,22 @@ static int btrfs_truncate_page(struct address_space *mapping, loff_t from) | |||
3032 | 3032 | ||
3033 | if ((offset & (blocksize - 1)) == 0) | 3033 | if ((offset & (blocksize - 1)) == 0) |
3034 | goto out; | 3034 | goto out; |
3035 | ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE); | ||
3036 | if (ret) | ||
3037 | goto out; | ||
3038 | |||
3039 | ret = btrfs_reserve_metadata_for_delalloc(root, inode, 1); | ||
3040 | if (ret) | ||
3041 | goto out; | ||
3035 | 3042 | ||
3036 | ret = -ENOMEM; | 3043 | ret = -ENOMEM; |
3037 | again: | 3044 | again: |
3038 | page = grab_cache_page(mapping, index); | 3045 | page = grab_cache_page(mapping, index); |
3039 | if (!page) | 3046 | if (!page) { |
3047 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
3048 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
3040 | goto out; | 3049 | goto out; |
3050 | } | ||
3041 | 3051 | ||
3042 | page_start = page_offset(page); | 3052 | page_start = page_offset(page); |
3043 | page_end = page_start + PAGE_CACHE_SIZE - 1; | 3053 | page_end = page_start + PAGE_CACHE_SIZE - 1; |
@@ -3070,6 +3080,10 @@ again: | |||
3070 | goto again; | 3080 | goto again; |
3071 | } | 3081 | } |
3072 | 3082 | ||
3083 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, | ||
3084 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, | ||
3085 | GFP_NOFS); | ||
3086 | |||
3073 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); | 3087 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); |
3074 | if (ret) { | 3088 | if (ret) { |
3075 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3089 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); |
@@ -3088,6 +3102,9 @@ again: | |||
3088 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3102 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); |
3089 | 3103 | ||
3090 | out_unlock: | 3104 | out_unlock: |
3105 | if (ret) | ||
3106 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
3107 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
3091 | unlock_page(page); | 3108 | unlock_page(page); |
3092 | page_cache_release(page); | 3109 | page_cache_release(page); |
3093 | out: | 3110 | out: |
@@ -3111,7 +3128,9 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3111 | if (size <= hole_start) | 3128 | if (size <= hole_start) |
3112 | return 0; | 3129 | return 0; |
3113 | 3130 | ||
3114 | btrfs_truncate_page(inode->i_mapping, inode->i_size); | 3131 | err = btrfs_truncate_page(inode->i_mapping, inode->i_size); |
3132 | if (err) | ||
3133 | return err; | ||
3115 | 3134 | ||
3116 | while (1) { | 3135 | while (1) { |
3117 | struct btrfs_ordered_extent *ordered; | 3136 | struct btrfs_ordered_extent *ordered; |
@@ -3480,6 +3499,7 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3480 | bi->generation = 0; | 3499 | bi->generation = 0; |
3481 | bi->sequence = 0; | 3500 | bi->sequence = 0; |
3482 | bi->last_trans = 0; | 3501 | bi->last_trans = 0; |
3502 | bi->last_sub_trans = 0; | ||
3483 | bi->logged_trans = 0; | 3503 | bi->logged_trans = 0; |
3484 | bi->delalloc_bytes = 0; | 3504 | bi->delalloc_bytes = 0; |
3485 | bi->reserved_bytes = 0; | 3505 | bi->reserved_bytes = 0; |
@@ -4980,7 +5000,9 @@ again: | |||
4980 | set_page_dirty(page); | 5000 | set_page_dirty(page); |
4981 | SetPageUptodate(page); | 5001 | SetPageUptodate(page); |
4982 | 5002 | ||
4983 | BTRFS_I(inode)->last_trans = root->fs_info->generation + 1; | 5003 | BTRFS_I(inode)->last_trans = root->fs_info->generation; |
5004 | BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; | ||
5005 | |||
4984 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 5006 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); |
4985 | 5007 | ||
4986 | out_unlock: | 5008 | out_unlock: |
@@ -5005,7 +5027,9 @@ static void btrfs_truncate(struct inode *inode) | |||
5005 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | 5027 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) |
5006 | return; | 5028 | return; |
5007 | 5029 | ||
5008 | btrfs_truncate_page(inode->i_mapping, inode->i_size); | 5030 | ret = btrfs_truncate_page(inode->i_mapping, inode->i_size); |
5031 | if (ret) | ||
5032 | return; | ||
5009 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); | 5033 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); |
5010 | 5034 | ||
5011 | trans = btrfs_start_transaction(root, 1); | 5035 | trans = btrfs_start_transaction(root, 1); |
@@ -5100,6 +5124,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
5100 | if (!ei) | 5124 | if (!ei) |
5101 | return NULL; | 5125 | return NULL; |
5102 | ei->last_trans = 0; | 5126 | ei->last_trans = 0; |
5127 | ei->last_sub_trans = 0; | ||
5103 | ei->logged_trans = 0; | 5128 | ei->logged_trans = 0; |
5104 | ei->outstanding_extents = 0; | 5129 | ei->outstanding_extents = 0; |
5105 | ei->reserved_extents = 0; | 5130 | ei->reserved_extents = 0; |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 9de9b223641..752a5463bf5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -66,7 +66,8 @@ enum { | |||
66 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, | 66 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, |
67 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, | 67 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, |
68 | Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, | 68 | Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, |
69 | Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_err, | 69 | Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit, |
70 | Opt_discard, Opt_err, | ||
70 | }; | 71 | }; |
71 | 72 | ||
72 | static match_table_t tokens = { | 73 | static match_table_t tokens = { |
@@ -88,6 +89,7 @@ static match_table_t tokens = { | |||
88 | {Opt_notreelog, "notreelog"}, | 89 | {Opt_notreelog, "notreelog"}, |
89 | {Opt_flushoncommit, "flushoncommit"}, | 90 | {Opt_flushoncommit, "flushoncommit"}, |
90 | {Opt_ratio, "metadata_ratio=%d"}, | 91 | {Opt_ratio, "metadata_ratio=%d"}, |
92 | {Opt_discard, "discard"}, | ||
91 | {Opt_err, NULL}, | 93 | {Opt_err, NULL}, |
92 | }; | 94 | }; |
93 | 95 | ||
@@ -257,6 +259,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
257 | info->metadata_ratio); | 259 | info->metadata_ratio); |
258 | } | 260 | } |
259 | break; | 261 | break; |
262 | case Opt_discard: | ||
263 | btrfs_set_opt(info->mount_opt, DISCARD); | ||
264 | break; | ||
260 | default: | 265 | default: |
261 | break; | 266 | break; |
262 | } | 267 | } |
@@ -344,7 +349,7 @@ static int btrfs_fill_super(struct super_block *sb, | |||
344 | sb->s_export_op = &btrfs_export_ops; | 349 | sb->s_export_op = &btrfs_export_ops; |
345 | sb->s_xattr = btrfs_xattr_handlers; | 350 | sb->s_xattr = btrfs_xattr_handlers; |
346 | sb->s_time_gran = 1; | 351 | sb->s_time_gran = 1; |
347 | #ifdef CONFIG_BTRFS_POSIX_ACL | 352 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
348 | sb->s_flags |= MS_POSIXACL; | 353 | sb->s_flags |= MS_POSIXACL; |
349 | #endif | 354 | #endif |
350 | 355 | ||
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 0b8f36d4400..bca82a4ca8e 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -344,10 +344,10 @@ int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, | |||
344 | /* | 344 | /* |
345 | * when btree blocks are allocated, they have some corresponding bits set for | 345 | * when btree blocks are allocated, they have some corresponding bits set for |
346 | * them in one of two extent_io trees. This is used to make sure all of | 346 | * them in one of two extent_io trees. This is used to make sure all of |
347 | * those extents are on disk for transaction or log commit | 347 | * those extents are sent to disk but does not wait on them |
348 | */ | 348 | */ |
349 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | 349 | int btrfs_write_marked_extents(struct btrfs_root *root, |
350 | struct extent_io_tree *dirty_pages) | 350 | struct extent_io_tree *dirty_pages) |
351 | { | 351 | { |
352 | int ret; | 352 | int ret; |
353 | int err = 0; | 353 | int err = 0; |
@@ -394,6 +394,29 @@ int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | |||
394 | page_cache_release(page); | 394 | page_cache_release(page); |
395 | } | 395 | } |
396 | } | 396 | } |
397 | if (err) | ||
398 | werr = err; | ||
399 | return werr; | ||
400 | } | ||
401 | |||
402 | /* | ||
403 | * when btree blocks are allocated, they have some corresponding bits set for | ||
404 | * them in one of two extent_io trees. This is used to make sure all of | ||
405 | * those extents are on disk for transaction or log commit. We wait | ||
406 | * on all the pages and clear them from the dirty pages state tree | ||
407 | */ | ||
408 | int btrfs_wait_marked_extents(struct btrfs_root *root, | ||
409 | struct extent_io_tree *dirty_pages) | ||
410 | { | ||
411 | int ret; | ||
412 | int err = 0; | ||
413 | int werr = 0; | ||
414 | struct page *page; | ||
415 | struct inode *btree_inode = root->fs_info->btree_inode; | ||
416 | u64 start = 0; | ||
417 | u64 end; | ||
418 | unsigned long index; | ||
419 | |||
397 | while (1) { | 420 | while (1) { |
398 | ret = find_first_extent_bit(dirty_pages, 0, &start, &end, | 421 | ret = find_first_extent_bit(dirty_pages, 0, &start, &end, |
399 | EXTENT_DIRTY); | 422 | EXTENT_DIRTY); |
@@ -424,6 +447,22 @@ int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | |||
424 | return werr; | 447 | return werr; |
425 | } | 448 | } |
426 | 449 | ||
450 | /* | ||
451 | * when btree blocks are allocated, they have some corresponding bits set for | ||
452 | * them in one of two extent_io trees. This is used to make sure all of | ||
453 | * those extents are on disk for transaction or log commit | ||
454 | */ | ||
455 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | ||
456 | struct extent_io_tree *dirty_pages) | ||
457 | { | ||
458 | int ret; | ||
459 | int ret2; | ||
460 | |||
461 | ret = btrfs_write_marked_extents(root, dirty_pages); | ||
462 | ret2 = btrfs_wait_marked_extents(root, dirty_pages); | ||
463 | return ret || ret2; | ||
464 | } | ||
465 | |||
427 | int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, | 466 | int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, |
428 | struct btrfs_root *root) | 467 | struct btrfs_root *root) |
429 | { | 468 | { |
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 663c6740491..d4e3e7a6938 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -79,6 +79,7 @@ static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans, | |||
79 | struct inode *inode) | 79 | struct inode *inode) |
80 | { | 80 | { |
81 | BTRFS_I(inode)->last_trans = trans->transaction->transid; | 81 | BTRFS_I(inode)->last_trans = trans->transaction->transid; |
82 | BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; | ||
82 | } | 83 | } |
83 | 84 | ||
84 | int btrfs_end_transaction(struct btrfs_trans_handle *trans, | 85 | int btrfs_end_transaction(struct btrfs_trans_handle *trans, |
@@ -107,5 +108,9 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, | |||
107 | struct btrfs_root *root); | 108 | struct btrfs_root *root); |
108 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | 109 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, |
109 | struct extent_io_tree *dirty_pages); | 110 | struct extent_io_tree *dirty_pages); |
111 | int btrfs_write_marked_extents(struct btrfs_root *root, | ||
112 | struct extent_io_tree *dirty_pages); | ||
113 | int btrfs_wait_marked_extents(struct btrfs_root *root, | ||
114 | struct extent_io_tree *dirty_pages); | ||
110 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); | 115 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); |
111 | #endif | 116 | #endif |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 4edfdc2acc5..741666a7676 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -1980,6 +1980,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1980 | int ret; | 1980 | int ret; |
1981 | struct btrfs_root *log = root->log_root; | 1981 | struct btrfs_root *log = root->log_root; |
1982 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; | 1982 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; |
1983 | u64 log_transid = 0; | ||
1983 | 1984 | ||
1984 | mutex_lock(&root->log_mutex); | 1985 | mutex_lock(&root->log_mutex); |
1985 | index1 = root->log_transid % 2; | 1986 | index1 = root->log_transid % 2; |
@@ -1994,12 +1995,13 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1994 | if (atomic_read(&root->log_commit[(index1 + 1) % 2])) | 1995 | if (atomic_read(&root->log_commit[(index1 + 1) % 2])) |
1995 | wait_log_commit(trans, root, root->log_transid - 1); | 1996 | wait_log_commit(trans, root, root->log_transid - 1); |
1996 | 1997 | ||
1997 | while (root->log_multiple_pids) { | 1998 | while (1) { |
1998 | unsigned long batch = root->log_batch; | 1999 | unsigned long batch = root->log_batch; |
1999 | mutex_unlock(&root->log_mutex); | 2000 | if (root->log_multiple_pids) { |
2000 | schedule_timeout_uninterruptible(1); | 2001 | mutex_unlock(&root->log_mutex); |
2001 | mutex_lock(&root->log_mutex); | 2002 | schedule_timeout_uninterruptible(1); |
2002 | 2003 | mutex_lock(&root->log_mutex); | |
2004 | } | ||
2003 | wait_for_writer(trans, root); | 2005 | wait_for_writer(trans, root); |
2004 | if (batch == root->log_batch) | 2006 | if (batch == root->log_batch) |
2005 | break; | 2007 | break; |
@@ -2012,12 +2014,16 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2012 | goto out; | 2014 | goto out; |
2013 | } | 2015 | } |
2014 | 2016 | ||
2015 | ret = btrfs_write_and_wait_marked_extents(log, &log->dirty_log_pages); | 2017 | /* we start IO on all the marked extents here, but we don't actually |
2018 | * wait for them until later. | ||
2019 | */ | ||
2020 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages); | ||
2016 | BUG_ON(ret); | 2021 | BUG_ON(ret); |
2017 | 2022 | ||
2018 | btrfs_set_root_node(&log->root_item, log->node); | 2023 | btrfs_set_root_node(&log->root_item, log->node); |
2019 | 2024 | ||
2020 | root->log_batch = 0; | 2025 | root->log_batch = 0; |
2026 | log_transid = root->log_transid; | ||
2021 | root->log_transid++; | 2027 | root->log_transid++; |
2022 | log->log_transid = root->log_transid; | 2028 | log->log_transid = root->log_transid; |
2023 | root->log_start_pid = 0; | 2029 | root->log_start_pid = 0; |
@@ -2046,6 +2052,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2046 | 2052 | ||
2047 | index2 = log_root_tree->log_transid % 2; | 2053 | index2 = log_root_tree->log_transid % 2; |
2048 | if (atomic_read(&log_root_tree->log_commit[index2])) { | 2054 | if (atomic_read(&log_root_tree->log_commit[index2])) { |
2055 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2049 | wait_log_commit(trans, log_root_tree, | 2056 | wait_log_commit(trans, log_root_tree, |
2050 | log_root_tree->log_transid); | 2057 | log_root_tree->log_transid); |
2051 | mutex_unlock(&log_root_tree->log_mutex); | 2058 | mutex_unlock(&log_root_tree->log_mutex); |
@@ -2065,6 +2072,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2065 | * check the full commit flag again | 2072 | * check the full commit flag again |
2066 | */ | 2073 | */ |
2067 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { | 2074 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { |
2075 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2068 | mutex_unlock(&log_root_tree->log_mutex); | 2076 | mutex_unlock(&log_root_tree->log_mutex); |
2069 | ret = -EAGAIN; | 2077 | ret = -EAGAIN; |
2070 | goto out_wake_log_root; | 2078 | goto out_wake_log_root; |
@@ -2073,6 +2081,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2073 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, | 2081 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, |
2074 | &log_root_tree->dirty_log_pages); | 2082 | &log_root_tree->dirty_log_pages); |
2075 | BUG_ON(ret); | 2083 | BUG_ON(ret); |
2084 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2076 | 2085 | ||
2077 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, | 2086 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, |
2078 | log_root_tree->node->start); | 2087 | log_root_tree->node->start); |
@@ -2092,9 +2101,14 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2092 | * the running transaction open, so a full commit can't hop | 2101 | * the running transaction open, so a full commit can't hop |
2093 | * in and cause problems either. | 2102 | * in and cause problems either. |
2094 | */ | 2103 | */ |
2095 | write_ctree_super(trans, root->fs_info->tree_root, 2); | 2104 | write_ctree_super(trans, root->fs_info->tree_root, 1); |
2096 | ret = 0; | 2105 | ret = 0; |
2097 | 2106 | ||
2107 | mutex_lock(&root->log_mutex); | ||
2108 | if (root->last_log_commit < log_transid) | ||
2109 | root->last_log_commit = log_transid; | ||
2110 | mutex_unlock(&root->log_mutex); | ||
2111 | |||
2098 | out_wake_log_root: | 2112 | out_wake_log_root: |
2099 | atomic_set(&log_root_tree->log_commit[index2], 0); | 2113 | atomic_set(&log_root_tree->log_commit[index2], 0); |
2100 | smp_mb(); | 2114 | smp_mb(); |
@@ -2862,6 +2876,21 @@ out: | |||
2862 | return ret; | 2876 | return ret; |
2863 | } | 2877 | } |
2864 | 2878 | ||
2879 | static int inode_in_log(struct btrfs_trans_handle *trans, | ||
2880 | struct inode *inode) | ||
2881 | { | ||
2882 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
2883 | int ret = 0; | ||
2884 | |||
2885 | mutex_lock(&root->log_mutex); | ||
2886 | if (BTRFS_I(inode)->logged_trans == trans->transid && | ||
2887 | BTRFS_I(inode)->last_sub_trans <= root->last_log_commit) | ||
2888 | ret = 1; | ||
2889 | mutex_unlock(&root->log_mutex); | ||
2890 | return ret; | ||
2891 | } | ||
2892 | |||
2893 | |||
2865 | /* | 2894 | /* |
2866 | * helper function around btrfs_log_inode to make sure newly created | 2895 | * helper function around btrfs_log_inode to make sure newly created |
2867 | * parent directories also end up in the log. A minimal inode and backref | 2896 | * parent directories also end up in the log. A minimal inode and backref |
@@ -2901,6 +2930,11 @@ int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
2901 | if (ret) | 2930 | if (ret) |
2902 | goto end_no_trans; | 2931 | goto end_no_trans; |
2903 | 2932 | ||
2933 | if (inode_in_log(trans, inode)) { | ||
2934 | ret = BTRFS_NO_LOG_SYNC; | ||
2935 | goto end_no_trans; | ||
2936 | } | ||
2937 | |||
2904 | start_log_trans(trans, root); | 2938 | start_log_trans(trans, root); |
2905 | 2939 | ||
2906 | ret = btrfs_log_inode(trans, root, inode, inode_only); | 2940 | ret = btrfs_log_inode(trans, root, inode, inode_only); |
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index d09c7609e16..0776eacb508 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h | |||
@@ -19,6 +19,9 @@ | |||
19 | #ifndef __TREE_LOG_ | 19 | #ifndef __TREE_LOG_ |
20 | #define __TREE_LOG_ | 20 | #define __TREE_LOG_ |
21 | 21 | ||
22 | /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ | ||
23 | #define BTRFS_NO_LOG_SYNC 256 | ||
24 | |||
22 | int btrfs_sync_log(struct btrfs_trans_handle *trans, | 25 | int btrfs_sync_log(struct btrfs_trans_handle *trans, |
23 | struct btrfs_root *root); | 26 | struct btrfs_root *root); |
24 | int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); | 27 | int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); |
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index b0fc93f95fd..b6dd5967c48 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c | |||
@@ -260,7 +260,7 @@ err: | |||
260 | * attributes are handled directly. | 260 | * attributes are handled directly. |
261 | */ | 261 | */ |
262 | struct xattr_handler *btrfs_xattr_handlers[] = { | 262 | struct xattr_handler *btrfs_xattr_handlers[] = { |
263 | #ifdef CONFIG_BTRFS_POSIX_ACL | 263 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
264 | &btrfs_xattr_acl_access_handler, | 264 | &btrfs_xattr_acl_access_handler, |
265 | &btrfs_xattr_acl_default_handler, | 265 | &btrfs_xattr_acl_default_handler, |
266 | #endif | 266 | #endif |