aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c184
1 files changed, 91 insertions, 93 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1c8b0190d031..dbe1aabf96cd 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -48,7 +48,6 @@
48#include "ordered-data.h" 48#include "ordered-data.h"
49#include "xattr.h" 49#include "xattr.h"
50#include "tree-log.h" 50#include "tree-log.h"
51#include "ref-cache.h"
52#include "compression.h" 51#include "compression.h"
53#include "locking.h" 52#include "locking.h"
54 53
@@ -369,7 +368,7 @@ again:
369 * inode has not been flagged as nocompress. This flag can 368 * inode has not been flagged as nocompress. This flag can
370 * change at any time if we discover bad compression ratios. 369 * change at any time if we discover bad compression ratios.
371 */ 370 */
372 if (!btrfs_test_flag(inode, NOCOMPRESS) && 371 if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) &&
373 btrfs_test_opt(root, COMPRESS)) { 372 btrfs_test_opt(root, COMPRESS)) {
374 WARN_ON(pages); 373 WARN_ON(pages);
375 pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); 374 pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
@@ -470,7 +469,7 @@ again:
470 nr_pages_ret = 0; 469 nr_pages_ret = 0;
471 470
472 /* flag the file so we don't compress in the future */ 471 /* flag the file so we don't compress in the future */
473 btrfs_set_flag(inode, NOCOMPRESS); 472 BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
474 } 473 }
475 if (will_compress) { 474 if (will_compress) {
476 *num_added += 1; 475 *num_added += 1;
@@ -863,7 +862,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
863 async_cow->locked_page = locked_page; 862 async_cow->locked_page = locked_page;
864 async_cow->start = start; 863 async_cow->start = start;
865 864
866 if (btrfs_test_flag(inode, NOCOMPRESS)) 865 if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
867 cur_end = end; 866 cur_end = end;
868 else 867 else
869 cur_end = min(end, start + 512 * 1024 - 1); 868 cur_end = min(end, start + 512 * 1024 - 1);
@@ -944,6 +943,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
944 u64 cow_start; 943 u64 cow_start;
945 u64 cur_offset; 944 u64 cur_offset;
946 u64 extent_end; 945 u64 extent_end;
946 u64 extent_offset;
947 u64 disk_bytenr; 947 u64 disk_bytenr;
948 u64 num_bytes; 948 u64 num_bytes;
949 int extent_type; 949 int extent_type;
@@ -1005,6 +1005,7 @@ next_slot:
1005 if (extent_type == BTRFS_FILE_EXTENT_REG || 1005 if (extent_type == BTRFS_FILE_EXTENT_REG ||
1006 extent_type == BTRFS_FILE_EXTENT_PREALLOC) { 1006 extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
1007 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); 1007 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
1008 extent_offset = btrfs_file_extent_offset(leaf, fi);
1008 extent_end = found_key.offset + 1009 extent_end = found_key.offset +
1009 btrfs_file_extent_num_bytes(leaf, fi); 1010 btrfs_file_extent_num_bytes(leaf, fi);
1010 if (extent_end <= start) { 1011 if (extent_end <= start) {
@@ -1022,9 +1023,10 @@ next_slot:
1022 if (btrfs_extent_readonly(root, disk_bytenr)) 1023 if (btrfs_extent_readonly(root, disk_bytenr))
1023 goto out_check; 1024 goto out_check;
1024 if (btrfs_cross_ref_exist(trans, root, inode->i_ino, 1025 if (btrfs_cross_ref_exist(trans, root, inode->i_ino,
1025 disk_bytenr)) 1026 found_key.offset -
1027 extent_offset, disk_bytenr))
1026 goto out_check; 1028 goto out_check;
1027 disk_bytenr += btrfs_file_extent_offset(leaf, fi); 1029 disk_bytenr += extent_offset;
1028 disk_bytenr += cur_offset - found_key.offset; 1030 disk_bytenr += cur_offset - found_key.offset;
1029 num_bytes = min(end + 1, extent_end) - cur_offset; 1031 num_bytes = min(end + 1, extent_end) - cur_offset;
1030 /* 1032 /*
@@ -1131,10 +1133,10 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page,
1131 int ret; 1133 int ret;
1132 struct btrfs_root *root = BTRFS_I(inode)->root; 1134 struct btrfs_root *root = BTRFS_I(inode)->root;
1133 1135
1134 if (btrfs_test_flag(inode, NODATACOW)) 1136 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW)
1135 ret = run_delalloc_nocow(inode, locked_page, start, end, 1137 ret = run_delalloc_nocow(inode, locked_page, start, end,
1136 page_started, 1, nr_written); 1138 page_started, 1, nr_written);
1137 else if (btrfs_test_flag(inode, PREALLOC)) 1139 else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC)
1138 ret = run_delalloc_nocow(inode, locked_page, start, end, 1140 ret = run_delalloc_nocow(inode, locked_page, start, end,
1139 page_started, 0, nr_written); 1141 page_started, 0, nr_written);
1140 else if (!btrfs_test_opt(root, COMPRESS)) 1142 else if (!btrfs_test_opt(root, COMPRESS))
@@ -1288,7 +1290,7 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
1288 int ret = 0; 1290 int ret = 0;
1289 int skip_sum; 1291 int skip_sum;
1290 1292
1291 skip_sum = btrfs_test_flag(inode, NODATASUM); 1293 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM;
1292 1294
1293 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 1295 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0);
1294 BUG_ON(ret); 1296 BUG_ON(ret);
@@ -1489,9 +1491,9 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
1489 ins.objectid = disk_bytenr; 1491 ins.objectid = disk_bytenr;
1490 ins.offset = disk_num_bytes; 1492 ins.offset = disk_num_bytes;
1491 ins.type = BTRFS_EXTENT_ITEM_KEY; 1493 ins.type = BTRFS_EXTENT_ITEM_KEY;
1492 ret = btrfs_alloc_reserved_extent(trans, root, leaf->start, 1494 ret = btrfs_alloc_reserved_file_extent(trans, root,
1493 root->root_key.objectid, 1495 root->root_key.objectid,
1494 trans->transid, inode->i_ino, &ins); 1496 inode->i_ino, file_pos, &ins);
1495 BUG_ON(ret); 1497 BUG_ON(ret);
1496 btrfs_free_path(path); 1498 btrfs_free_path(path);
1497 1499
@@ -1788,7 +1790,8 @@ static int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end,
1788 ClearPageChecked(page); 1790 ClearPageChecked(page);
1789 goto good; 1791 goto good;
1790 } 1792 }
1791 if (btrfs_test_flag(inode, NODATASUM)) 1793
1794 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
1792 return 0; 1795 return 0;
1793 1796
1794 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID && 1797 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID &&
@@ -1956,23 +1959,13 @@ void btrfs_orphan_cleanup(struct btrfs_root *root)
1956 * crossing root thing. we store the inode number in the 1959 * crossing root thing. we store the inode number in the
1957 * offset of the orphan item. 1960 * offset of the orphan item.
1958 */ 1961 */
1959 inode = btrfs_iget_locked(root->fs_info->sb, 1962 found_key.objectid = found_key.offset;
1960 found_key.offset, root); 1963 found_key.type = BTRFS_INODE_ITEM_KEY;
1961 if (!inode) 1964 found_key.offset = 0;
1965 inode = btrfs_iget(root->fs_info->sb, &found_key, root);
1966 if (IS_ERR(inode))
1962 break; 1967 break;
1963 1968
1964 if (inode->i_state & I_NEW) {
1965 BTRFS_I(inode)->root = root;
1966
1967 /* have to set the location manually */
1968 BTRFS_I(inode)->location.objectid = inode->i_ino;
1969 BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
1970 BTRFS_I(inode)->location.offset = 0;
1971
1972 btrfs_read_locked_inode(inode);
1973 unlock_new_inode(inode);
1974 }
1975
1976 /* 1969 /*
1977 * add this inode to the orphan list so btrfs_orphan_del does 1970 * add this inode to the orphan list so btrfs_orphan_del does
1978 * the proper thing when we hit it 1971 * the proper thing when we hit it
@@ -2069,7 +2062,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
2069/* 2062/*
2070 * read an inode from the btree into the in-memory inode 2063 * read an inode from the btree into the in-memory inode
2071 */ 2064 */
2072void btrfs_read_locked_inode(struct inode *inode) 2065static void btrfs_read_locked_inode(struct inode *inode)
2073{ 2066{
2074 struct btrfs_path *path; 2067 struct btrfs_path *path;
2075 struct extent_buffer *leaf; 2068 struct extent_buffer *leaf;
@@ -2129,10 +2122,8 @@ void btrfs_read_locked_inode(struct inode *inode)
2129 * any xattrs or acls 2122 * any xattrs or acls
2130 */ 2123 */
2131 maybe_acls = acls_after_inode_item(leaf, path->slots[0], inode->i_ino); 2124 maybe_acls = acls_after_inode_item(leaf, path->slots[0], inode->i_ino);
2132 if (!maybe_acls) { 2125 if (!maybe_acls)
2133 BTRFS_I(inode)->i_acl = NULL; 2126 cache_no_acl(inode);
2134 BTRFS_I(inode)->i_default_acl = NULL;
2135 }
2136 2127
2137 BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0, 2128 BTRFS_I(inode)->block_group = btrfs_find_block_group(root, 0,
2138 alloc_group_block, 0); 2129 alloc_group_block, 0);
@@ -2164,6 +2155,8 @@ void btrfs_read_locked_inode(struct inode *inode)
2164 init_special_inode(inode, inode->i_mode, rdev); 2155 init_special_inode(inode, inode->i_mode, rdev);
2165 break; 2156 break;
2166 } 2157 }
2158
2159 btrfs_update_iflags(inode);
2167 return; 2160 return;
2168 2161
2169make_bad: 2162make_bad:
@@ -2327,7 +2320,6 @@ err:
2327 btrfs_update_inode(trans, root, dir); 2320 btrfs_update_inode(trans, root, dir);
2328 btrfs_drop_nlink(inode); 2321 btrfs_drop_nlink(inode);
2329 ret = btrfs_update_inode(trans, root, inode); 2322 ret = btrfs_update_inode(trans, root, inode);
2330 dir->i_sb->s_dirt = 1;
2331out: 2323out:
2332 return ret; 2324 return ret;
2333} 2325}
@@ -2599,9 +2591,8 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
2599 struct btrfs_file_extent_item *fi; 2591 struct btrfs_file_extent_item *fi;
2600 u64 extent_start = 0; 2592 u64 extent_start = 0;
2601 u64 extent_num_bytes = 0; 2593 u64 extent_num_bytes = 0;
2594 u64 extent_offset = 0;
2602 u64 item_end = 0; 2595 u64 item_end = 0;
2603 u64 root_gen = 0;
2604 u64 root_owner = 0;
2605 int found_extent; 2596 int found_extent;
2606 int del_item; 2597 int del_item;
2607 int pending_del_nr = 0; 2598 int pending_del_nr = 0;
@@ -2716,6 +2707,9 @@ search_again:
2716 extent_num_bytes = 2707 extent_num_bytes =
2717 btrfs_file_extent_disk_num_bytes(leaf, 2708 btrfs_file_extent_disk_num_bytes(leaf,
2718 fi); 2709 fi);
2710 extent_offset = found_key.offset -
2711 btrfs_file_extent_offset(leaf, fi);
2712
2719 /* FIXME blocksize != 4096 */ 2713 /* FIXME blocksize != 4096 */
2720 num_dec = btrfs_file_extent_num_bytes(leaf, fi); 2714 num_dec = btrfs_file_extent_num_bytes(leaf, fi);
2721 if (extent_start != 0) { 2715 if (extent_start != 0) {
@@ -2723,8 +2717,6 @@ search_again:
2723 if (root->ref_cows) 2717 if (root->ref_cows)
2724 inode_sub_bytes(inode, num_dec); 2718 inode_sub_bytes(inode, num_dec);
2725 } 2719 }
2726 root_gen = btrfs_header_generation(leaf);
2727 root_owner = btrfs_header_owner(leaf);
2728 } 2720 }
2729 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { 2721 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
2730 /* 2722 /*
@@ -2768,12 +2760,12 @@ delete:
2768 } else { 2760 } else {
2769 break; 2761 break;
2770 } 2762 }
2771 if (found_extent) { 2763 if (found_extent && root->ref_cows) {
2772 btrfs_set_path_blocking(path); 2764 btrfs_set_path_blocking(path);
2773 ret = btrfs_free_extent(trans, root, extent_start, 2765 ret = btrfs_free_extent(trans, root, extent_start,
2774 extent_num_bytes, 2766 extent_num_bytes, 0,
2775 leaf->start, root_owner, 2767 btrfs_header_owner(leaf),
2776 root_gen, inode->i_ino, 0); 2768 inode->i_ino, extent_offset);
2777 BUG_ON(ret); 2769 BUG_ON(ret);
2778 } 2770 }
2779next: 2771next:
@@ -2811,7 +2803,6 @@ error:
2811 pending_del_nr); 2803 pending_del_nr);
2812 } 2804 }
2813 btrfs_free_path(path); 2805 btrfs_free_path(path);
2814 inode->i_sb->s_dirt = 1;
2815 return ret; 2806 return ret;
2816} 2807}
2817 2808
@@ -3105,13 +3096,49 @@ static int fixup_tree_root_location(struct btrfs_root *root,
3105 return 0; 3096 return 0;
3106} 3097}
3107 3098
3099static void inode_tree_add(struct inode *inode)
3100{
3101 struct btrfs_root *root = BTRFS_I(inode)->root;
3102 struct btrfs_inode *entry;
3103 struct rb_node **p = &root->inode_tree.rb_node;
3104 struct rb_node *parent = NULL;
3105
3106 spin_lock(&root->inode_lock);
3107 while (*p) {
3108 parent = *p;
3109 entry = rb_entry(parent, struct btrfs_inode, rb_node);
3110
3111 if (inode->i_ino < entry->vfs_inode.i_ino)
3112 p = &(*p)->rb_left;
3113 else if (inode->i_ino > entry->vfs_inode.i_ino)
3114 p = &(*p)->rb_right;
3115 else {
3116 WARN_ON(!(entry->vfs_inode.i_state &
3117 (I_WILL_FREE | I_FREEING | I_CLEAR)));
3118 break;
3119 }
3120 }
3121 rb_link_node(&BTRFS_I(inode)->rb_node, parent, p);
3122 rb_insert_color(&BTRFS_I(inode)->rb_node, &root->inode_tree);
3123 spin_unlock(&root->inode_lock);
3124}
3125
3126static void inode_tree_del(struct inode *inode)
3127{
3128 struct btrfs_root *root = BTRFS_I(inode)->root;
3129
3130 if (!RB_EMPTY_NODE(&BTRFS_I(inode)->rb_node)) {
3131 spin_lock(&root->inode_lock);
3132 rb_erase(&BTRFS_I(inode)->rb_node, &root->inode_tree);
3133 spin_unlock(&root->inode_lock);
3134 RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node);
3135 }
3136}
3137
3108static noinline void init_btrfs_i(struct inode *inode) 3138static noinline void init_btrfs_i(struct inode *inode)
3109{ 3139{
3110 struct btrfs_inode *bi = BTRFS_I(inode); 3140 struct btrfs_inode *bi = BTRFS_I(inode);
3111 3141
3112 bi->i_acl = BTRFS_ACL_NOT_CACHED;
3113 bi->i_default_acl = BTRFS_ACL_NOT_CACHED;
3114
3115 bi->generation = 0; 3142 bi->generation = 0;
3116 bi->sequence = 0; 3143 bi->sequence = 0;
3117 bi->last_trans = 0; 3144 bi->last_trans = 0;
@@ -3130,6 +3157,7 @@ static noinline void init_btrfs_i(struct inode *inode)
3130 inode->i_mapping, GFP_NOFS); 3157 inode->i_mapping, GFP_NOFS);
3131 INIT_LIST_HEAD(&BTRFS_I(inode)->delalloc_inodes); 3158 INIT_LIST_HEAD(&BTRFS_I(inode)->delalloc_inodes);
3132 INIT_LIST_HEAD(&BTRFS_I(inode)->ordered_operations); 3159 INIT_LIST_HEAD(&BTRFS_I(inode)->ordered_operations);
3160 RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node);
3133 btrfs_ordered_inode_tree_init(&BTRFS_I(inode)->ordered_tree); 3161 btrfs_ordered_inode_tree_init(&BTRFS_I(inode)->ordered_tree);
3134 mutex_init(&BTRFS_I(inode)->extent_mutex); 3162 mutex_init(&BTRFS_I(inode)->extent_mutex);
3135 mutex_init(&BTRFS_I(inode)->log_mutex); 3163 mutex_init(&BTRFS_I(inode)->log_mutex);
@@ -3152,26 +3180,9 @@ static int btrfs_find_actor(struct inode *inode, void *opaque)
3152 args->root == BTRFS_I(inode)->root; 3180 args->root == BTRFS_I(inode)->root;
3153} 3181}
3154 3182
3155struct inode *btrfs_ilookup(struct super_block *s, u64 objectid, 3183static struct inode *btrfs_iget_locked(struct super_block *s,
3156 struct btrfs_root *root, int wait) 3184 u64 objectid,
3157{ 3185 struct btrfs_root *root)
3158 struct inode *inode;
3159 struct btrfs_iget_args args;
3160 args.ino = objectid;
3161 args.root = root;
3162
3163 if (wait) {
3164 inode = ilookup5(s, objectid, btrfs_find_actor,
3165 (void *)&args);
3166 } else {
3167 inode = ilookup5_nowait(s, objectid, btrfs_find_actor,
3168 (void *)&args);
3169 }
3170 return inode;
3171}
3172
3173struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
3174 struct btrfs_root *root)
3175{ 3186{
3176 struct inode *inode; 3187 struct inode *inode;
3177 struct btrfs_iget_args args; 3188 struct btrfs_iget_args args;
@@ -3188,24 +3199,21 @@ struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
3188 * Returns in *is_new if the inode was read from disk 3199 * Returns in *is_new if the inode was read from disk
3189 */ 3200 */
3190struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, 3201struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
3191 struct btrfs_root *root, int *is_new) 3202 struct btrfs_root *root)
3192{ 3203{
3193 struct inode *inode; 3204 struct inode *inode;
3194 3205
3195 inode = btrfs_iget_locked(s, location->objectid, root); 3206 inode = btrfs_iget_locked(s, location->objectid, root);
3196 if (!inode) 3207 if (!inode)
3197 return ERR_PTR(-EACCES); 3208 return ERR_PTR(-ENOMEM);
3198 3209
3199 if (inode->i_state & I_NEW) { 3210 if (inode->i_state & I_NEW) {
3200 BTRFS_I(inode)->root = root; 3211 BTRFS_I(inode)->root = root;
3201 memcpy(&BTRFS_I(inode)->location, location, sizeof(*location)); 3212 memcpy(&BTRFS_I(inode)->location, location, sizeof(*location));
3202 btrfs_read_locked_inode(inode); 3213 btrfs_read_locked_inode(inode);
3214
3215 inode_tree_add(inode);
3203 unlock_new_inode(inode); 3216 unlock_new_inode(inode);
3204 if (is_new)
3205 *is_new = 1;
3206 } else {
3207 if (is_new)
3208 *is_new = 0;
3209 } 3217 }
3210 3218
3211 return inode; 3219 return inode;
@@ -3218,7 +3226,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
3218 struct btrfs_root *root = bi->root; 3226 struct btrfs_root *root = bi->root;
3219 struct btrfs_root *sub_root = root; 3227 struct btrfs_root *sub_root = root;
3220 struct btrfs_key location; 3228 struct btrfs_key location;
3221 int ret, new; 3229 int ret;
3222 3230
3223 if (dentry->d_name.len > BTRFS_NAME_LEN) 3231 if (dentry->d_name.len > BTRFS_NAME_LEN)
3224 return ERR_PTR(-ENAMETOOLONG); 3232 return ERR_PTR(-ENAMETOOLONG);
@@ -3236,7 +3244,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
3236 return ERR_PTR(ret); 3244 return ERR_PTR(ret);
3237 if (ret > 0) 3245 if (ret > 0)
3238 return ERR_PTR(-ENOENT); 3246 return ERR_PTR(-ENOENT);
3239 inode = btrfs_iget(dir->i_sb, &location, sub_root, &new); 3247 inode = btrfs_iget(dir->i_sb, &location, sub_root);
3240 if (IS_ERR(inode)) 3248 if (IS_ERR(inode))
3241 return ERR_CAST(inode); 3249 return ERR_CAST(inode);
3242 } 3250 }
@@ -3574,9 +3582,9 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3574 btrfs_find_block_group(root, 0, alloc_hint, owner); 3582 btrfs_find_block_group(root, 0, alloc_hint, owner);
3575 if ((mode & S_IFREG)) { 3583 if ((mode & S_IFREG)) {
3576 if (btrfs_test_opt(root, NODATASUM)) 3584 if (btrfs_test_opt(root, NODATASUM))
3577 btrfs_set_flag(inode, NODATASUM); 3585 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
3578 if (btrfs_test_opt(root, NODATACOW)) 3586 if (btrfs_test_opt(root, NODATACOW))
3579 btrfs_set_flag(inode, NODATACOW); 3587 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
3580 } 3588 }
3581 3589
3582 key[0].objectid = objectid; 3590 key[0].objectid = objectid;
@@ -3630,7 +3638,10 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3630 location->offset = 0; 3638 location->offset = 0;
3631 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY); 3639 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
3632 3640
3641 btrfs_inherit_iflags(inode, dir);
3642
3633 insert_inode_hash(inode); 3643 insert_inode_hash(inode);
3644 inode_tree_add(inode);
3634 return inode; 3645 return inode;
3635fail: 3646fail:
3636 if (dir) 3647 if (dir)
@@ -3750,7 +3761,6 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
3750 init_special_inode(inode, inode->i_mode, rdev); 3761 init_special_inode(inode, inode->i_mode, rdev);
3751 btrfs_update_inode(trans, root, inode); 3762 btrfs_update_inode(trans, root, inode);
3752 } 3763 }
3753 dir->i_sb->s_dirt = 1;
3754 btrfs_update_inode_block_group(trans, inode); 3764 btrfs_update_inode_block_group(trans, inode);
3755 btrfs_update_inode_block_group(trans, dir); 3765 btrfs_update_inode_block_group(trans, dir);
3756out_unlock: 3766out_unlock:
@@ -3815,7 +3825,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
3815 inode->i_op = &btrfs_file_inode_operations; 3825 inode->i_op = &btrfs_file_inode_operations;
3816 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 3826 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
3817 } 3827 }
3818 dir->i_sb->s_dirt = 1;
3819 btrfs_update_inode_block_group(trans, inode); 3828 btrfs_update_inode_block_group(trans, inode);
3820 btrfs_update_inode_block_group(trans, dir); 3829 btrfs_update_inode_block_group(trans, dir);
3821out_unlock: 3830out_unlock:
@@ -3862,7 +3871,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
3862 if (err) 3871 if (err)
3863 drop_inode = 1; 3872 drop_inode = 1;
3864 3873
3865 dir->i_sb->s_dirt = 1;
3866 btrfs_update_inode_block_group(trans, dir); 3874 btrfs_update_inode_block_group(trans, dir);
3867 err = btrfs_update_inode(trans, root, inode); 3875 err = btrfs_update_inode(trans, root, inode);
3868 3876
@@ -3944,7 +3952,6 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
3944 3952
3945 d_instantiate(dentry, inode); 3953 d_instantiate(dentry, inode);
3946 drop_on_err = 0; 3954 drop_on_err = 0;
3947 dir->i_sb->s_dirt = 1;
3948 btrfs_update_inode_block_group(trans, inode); 3955 btrfs_update_inode_block_group(trans, inode);
3949 btrfs_update_inode_block_group(trans, dir); 3956 btrfs_update_inode_block_group(trans, dir);
3950 3957
@@ -4628,8 +4635,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
4628 ei->last_trans = 0; 4635 ei->last_trans = 0;
4629 ei->logged_trans = 0; 4636 ei->logged_trans = 0;
4630 btrfs_ordered_inode_tree_init(&ei->ordered_tree); 4637 btrfs_ordered_inode_tree_init(&ei->ordered_tree);
4631 ei->i_acl = BTRFS_ACL_NOT_CACHED;
4632 ei->i_default_acl = BTRFS_ACL_NOT_CACHED;
4633 INIT_LIST_HEAD(&ei->i_orphan); 4638 INIT_LIST_HEAD(&ei->i_orphan);
4634 INIT_LIST_HEAD(&ei->ordered_operations); 4639 INIT_LIST_HEAD(&ei->ordered_operations);
4635 return &ei->vfs_inode; 4640 return &ei->vfs_inode;
@@ -4643,13 +4648,6 @@ void btrfs_destroy_inode(struct inode *inode)
4643 WARN_ON(!list_empty(&inode->i_dentry)); 4648 WARN_ON(!list_empty(&inode->i_dentry));
4644 WARN_ON(inode->i_data.nrpages); 4649 WARN_ON(inode->i_data.nrpages);
4645 4650
4646 if (BTRFS_I(inode)->i_acl &&
4647 BTRFS_I(inode)->i_acl != BTRFS_ACL_NOT_CACHED)
4648 posix_acl_release(BTRFS_I(inode)->i_acl);
4649 if (BTRFS_I(inode)->i_default_acl &&
4650 BTRFS_I(inode)->i_default_acl != BTRFS_ACL_NOT_CACHED)
4651 posix_acl_release(BTRFS_I(inode)->i_default_acl);
4652
4653 /* 4651 /*
4654 * Make sure we're properly removed from the ordered operation 4652 * Make sure we're properly removed from the ordered operation
4655 * lists. 4653 * lists.
@@ -4683,6 +4681,7 @@ void btrfs_destroy_inode(struct inode *inode)
4683 btrfs_put_ordered_extent(ordered); 4681 btrfs_put_ordered_extent(ordered);
4684 } 4682 }
4685 } 4683 }
4684 inode_tree_del(inode);
4686 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); 4685 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0);
4687 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); 4686 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
4688} 4687}
@@ -4972,7 +4971,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
4972 inode->i_op = &btrfs_file_inode_operations; 4971 inode->i_op = &btrfs_file_inode_operations;
4973 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 4972 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
4974 } 4973 }
4975 dir->i_sb->s_dirt = 1;
4976 btrfs_update_inode_block_group(trans, inode); 4974 btrfs_update_inode_block_group(trans, inode);
4977 btrfs_update_inode_block_group(trans, dir); 4975 btrfs_update_inode_block_group(trans, dir);
4978 if (drop_inode) 4976 if (drop_inode)
@@ -5061,7 +5059,7 @@ static int prealloc_file_range(struct btrfs_trans_handle *trans,
5061out: 5059out:
5062 if (cur_offset > start) { 5060 if (cur_offset > start) {
5063 inode->i_ctime = CURRENT_TIME; 5061 inode->i_ctime = CURRENT_TIME;
5064 btrfs_set_flag(inode, PREALLOC); 5062 BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC;
5065 if (!(mode & FALLOC_FL_KEEP_SIZE) && 5063 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
5066 cur_offset > i_size_read(inode)) 5064 cur_offset > i_size_read(inode))
5067 btrfs_i_size_write(inode, cur_offset); 5065 btrfs_i_size_write(inode, cur_offset);
@@ -5182,7 +5180,7 @@ static int btrfs_set_page_dirty(struct page *page)
5182 5180
5183static int btrfs_permission(struct inode *inode, int mask) 5181static int btrfs_permission(struct inode *inode, int mask)
5184{ 5182{
5185 if (btrfs_test_flag(inode, READONLY) && (mask & MAY_WRITE)) 5183 if ((BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) && (mask & MAY_WRITE))
5186 return -EACCES; 5184 return -EACCES;
5187 return generic_permission(inode, mask, btrfs_check_acl); 5185 return generic_permission(inode, mask, btrfs_check_acl);
5188} 5186}