diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 166 |
1 files changed, 89 insertions, 77 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1c8b0190d031..8612b3a09811 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 | */ |
2072 | void btrfs_read_locked_inode(struct inode *inode) | 2065 | static 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; |
@@ -2164,6 +2157,8 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
2164 | init_special_inode(inode, inode->i_mode, rdev); | 2157 | init_special_inode(inode, inode->i_mode, rdev); |
2165 | break; | 2158 | break; |
2166 | } | 2159 | } |
2160 | |||
2161 | btrfs_update_iflags(inode); | ||
2167 | return; | 2162 | return; |
2168 | 2163 | ||
2169 | make_bad: | 2164 | make_bad: |
@@ -2327,7 +2322,6 @@ err: | |||
2327 | btrfs_update_inode(trans, root, dir); | 2322 | btrfs_update_inode(trans, root, dir); |
2328 | btrfs_drop_nlink(inode); | 2323 | btrfs_drop_nlink(inode); |
2329 | ret = btrfs_update_inode(trans, root, inode); | 2324 | ret = btrfs_update_inode(trans, root, inode); |
2330 | dir->i_sb->s_dirt = 1; | ||
2331 | out: | 2325 | out: |
2332 | return ret; | 2326 | return ret; |
2333 | } | 2327 | } |
@@ -2599,9 +2593,8 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2599 | struct btrfs_file_extent_item *fi; | 2593 | struct btrfs_file_extent_item *fi; |
2600 | u64 extent_start = 0; | 2594 | u64 extent_start = 0; |
2601 | u64 extent_num_bytes = 0; | 2595 | u64 extent_num_bytes = 0; |
2596 | u64 extent_offset = 0; | ||
2602 | u64 item_end = 0; | 2597 | u64 item_end = 0; |
2603 | u64 root_gen = 0; | ||
2604 | u64 root_owner = 0; | ||
2605 | int found_extent; | 2598 | int found_extent; |
2606 | int del_item; | 2599 | int del_item; |
2607 | int pending_del_nr = 0; | 2600 | int pending_del_nr = 0; |
@@ -2716,6 +2709,9 @@ search_again: | |||
2716 | extent_num_bytes = | 2709 | extent_num_bytes = |
2717 | btrfs_file_extent_disk_num_bytes(leaf, | 2710 | btrfs_file_extent_disk_num_bytes(leaf, |
2718 | fi); | 2711 | fi); |
2712 | extent_offset = found_key.offset - | ||
2713 | btrfs_file_extent_offset(leaf, fi); | ||
2714 | |||
2719 | /* FIXME blocksize != 4096 */ | 2715 | /* FIXME blocksize != 4096 */ |
2720 | num_dec = btrfs_file_extent_num_bytes(leaf, fi); | 2716 | num_dec = btrfs_file_extent_num_bytes(leaf, fi); |
2721 | if (extent_start != 0) { | 2717 | if (extent_start != 0) { |
@@ -2723,8 +2719,6 @@ search_again: | |||
2723 | if (root->ref_cows) | 2719 | if (root->ref_cows) |
2724 | inode_sub_bytes(inode, num_dec); | 2720 | inode_sub_bytes(inode, num_dec); |
2725 | } | 2721 | } |
2726 | root_gen = btrfs_header_generation(leaf); | ||
2727 | root_owner = btrfs_header_owner(leaf); | ||
2728 | } | 2722 | } |
2729 | } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { | 2723 | } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { |
2730 | /* | 2724 | /* |
@@ -2768,12 +2762,12 @@ delete: | |||
2768 | } else { | 2762 | } else { |
2769 | break; | 2763 | break; |
2770 | } | 2764 | } |
2771 | if (found_extent) { | 2765 | if (found_extent && root->ref_cows) { |
2772 | btrfs_set_path_blocking(path); | 2766 | btrfs_set_path_blocking(path); |
2773 | ret = btrfs_free_extent(trans, root, extent_start, | 2767 | ret = btrfs_free_extent(trans, root, extent_start, |
2774 | extent_num_bytes, | 2768 | extent_num_bytes, 0, |
2775 | leaf->start, root_owner, | 2769 | btrfs_header_owner(leaf), |
2776 | root_gen, inode->i_ino, 0); | 2770 | inode->i_ino, extent_offset); |
2777 | BUG_ON(ret); | 2771 | BUG_ON(ret); |
2778 | } | 2772 | } |
2779 | next: | 2773 | next: |
@@ -2811,7 +2805,6 @@ error: | |||
2811 | pending_del_nr); | 2805 | pending_del_nr); |
2812 | } | 2806 | } |
2813 | btrfs_free_path(path); | 2807 | btrfs_free_path(path); |
2814 | inode->i_sb->s_dirt = 1; | ||
2815 | return ret; | 2808 | return ret; |
2816 | } | 2809 | } |
2817 | 2810 | ||
@@ -3105,6 +3098,45 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
3105 | return 0; | 3098 | return 0; |
3106 | } | 3099 | } |
3107 | 3100 | ||
3101 | static void inode_tree_add(struct inode *inode) | ||
3102 | { | ||
3103 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
3104 | struct btrfs_inode *entry; | ||
3105 | struct rb_node **p = &root->inode_tree.rb_node; | ||
3106 | struct rb_node *parent = NULL; | ||
3107 | |||
3108 | spin_lock(&root->inode_lock); | ||
3109 | while (*p) { | ||
3110 | parent = *p; | ||
3111 | entry = rb_entry(parent, struct btrfs_inode, rb_node); | ||
3112 | |||
3113 | if (inode->i_ino < entry->vfs_inode.i_ino) | ||
3114 | p = &(*p)->rb_left; | ||
3115 | else if (inode->i_ino > entry->vfs_inode.i_ino) | ||
3116 | p = &(*p)->rb_right; | ||
3117 | else { | ||
3118 | WARN_ON(!(entry->vfs_inode.i_state & | ||
3119 | (I_WILL_FREE | I_FREEING | I_CLEAR))); | ||
3120 | break; | ||
3121 | } | ||
3122 | } | ||
3123 | rb_link_node(&BTRFS_I(inode)->rb_node, parent, p); | ||
3124 | rb_insert_color(&BTRFS_I(inode)->rb_node, &root->inode_tree); | ||
3125 | spin_unlock(&root->inode_lock); | ||
3126 | } | ||
3127 | |||
3128 | static void inode_tree_del(struct inode *inode) | ||
3129 | { | ||
3130 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
3131 | |||
3132 | if (!RB_EMPTY_NODE(&BTRFS_I(inode)->rb_node)) { | ||
3133 | spin_lock(&root->inode_lock); | ||
3134 | rb_erase(&BTRFS_I(inode)->rb_node, &root->inode_tree); | ||
3135 | spin_unlock(&root->inode_lock); | ||
3136 | RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); | ||
3137 | } | ||
3138 | } | ||
3139 | |||
3108 | static noinline void init_btrfs_i(struct inode *inode) | 3140 | static noinline void init_btrfs_i(struct inode *inode) |
3109 | { | 3141 | { |
3110 | struct btrfs_inode *bi = BTRFS_I(inode); | 3142 | struct btrfs_inode *bi = BTRFS_I(inode); |
@@ -3130,6 +3162,7 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3130 | inode->i_mapping, GFP_NOFS); | 3162 | inode->i_mapping, GFP_NOFS); |
3131 | INIT_LIST_HEAD(&BTRFS_I(inode)->delalloc_inodes); | 3163 | INIT_LIST_HEAD(&BTRFS_I(inode)->delalloc_inodes); |
3132 | INIT_LIST_HEAD(&BTRFS_I(inode)->ordered_operations); | 3164 | INIT_LIST_HEAD(&BTRFS_I(inode)->ordered_operations); |
3165 | RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); | ||
3133 | btrfs_ordered_inode_tree_init(&BTRFS_I(inode)->ordered_tree); | 3166 | btrfs_ordered_inode_tree_init(&BTRFS_I(inode)->ordered_tree); |
3134 | mutex_init(&BTRFS_I(inode)->extent_mutex); | 3167 | mutex_init(&BTRFS_I(inode)->extent_mutex); |
3135 | mutex_init(&BTRFS_I(inode)->log_mutex); | 3168 | mutex_init(&BTRFS_I(inode)->log_mutex); |
@@ -3152,26 +3185,9 @@ static int btrfs_find_actor(struct inode *inode, void *opaque) | |||
3152 | args->root == BTRFS_I(inode)->root; | 3185 | args->root == BTRFS_I(inode)->root; |
3153 | } | 3186 | } |
3154 | 3187 | ||
3155 | struct inode *btrfs_ilookup(struct super_block *s, u64 objectid, | 3188 | static struct inode *btrfs_iget_locked(struct super_block *s, |
3156 | struct btrfs_root *root, int wait) | 3189 | u64 objectid, |
3157 | { | 3190 | 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 | |||
3173 | struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid, | ||
3174 | struct btrfs_root *root) | ||
3175 | { | 3191 | { |
3176 | struct inode *inode; | 3192 | struct inode *inode; |
3177 | struct btrfs_iget_args args; | 3193 | struct btrfs_iget_args args; |
@@ -3188,24 +3204,21 @@ struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid, | |||
3188 | * Returns in *is_new if the inode was read from disk | 3204 | * Returns in *is_new if the inode was read from disk |
3189 | */ | 3205 | */ |
3190 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, | 3206 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, |
3191 | struct btrfs_root *root, int *is_new) | 3207 | struct btrfs_root *root) |
3192 | { | 3208 | { |
3193 | struct inode *inode; | 3209 | struct inode *inode; |
3194 | 3210 | ||
3195 | inode = btrfs_iget_locked(s, location->objectid, root); | 3211 | inode = btrfs_iget_locked(s, location->objectid, root); |
3196 | if (!inode) | 3212 | if (!inode) |
3197 | return ERR_PTR(-EACCES); | 3213 | return ERR_PTR(-ENOMEM); |
3198 | 3214 | ||
3199 | if (inode->i_state & I_NEW) { | 3215 | if (inode->i_state & I_NEW) { |
3200 | BTRFS_I(inode)->root = root; | 3216 | BTRFS_I(inode)->root = root; |
3201 | memcpy(&BTRFS_I(inode)->location, location, sizeof(*location)); | 3217 | memcpy(&BTRFS_I(inode)->location, location, sizeof(*location)); |
3202 | btrfs_read_locked_inode(inode); | 3218 | btrfs_read_locked_inode(inode); |
3219 | |||
3220 | inode_tree_add(inode); | ||
3203 | unlock_new_inode(inode); | 3221 | unlock_new_inode(inode); |
3204 | if (is_new) | ||
3205 | *is_new = 1; | ||
3206 | } else { | ||
3207 | if (is_new) | ||
3208 | *is_new = 0; | ||
3209 | } | 3222 | } |
3210 | 3223 | ||
3211 | return inode; | 3224 | return inode; |
@@ -3218,7 +3231,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3218 | struct btrfs_root *root = bi->root; | 3231 | struct btrfs_root *root = bi->root; |
3219 | struct btrfs_root *sub_root = root; | 3232 | struct btrfs_root *sub_root = root; |
3220 | struct btrfs_key location; | 3233 | struct btrfs_key location; |
3221 | int ret, new; | 3234 | int ret; |
3222 | 3235 | ||
3223 | if (dentry->d_name.len > BTRFS_NAME_LEN) | 3236 | if (dentry->d_name.len > BTRFS_NAME_LEN) |
3224 | return ERR_PTR(-ENAMETOOLONG); | 3237 | return ERR_PTR(-ENAMETOOLONG); |
@@ -3236,7 +3249,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3236 | return ERR_PTR(ret); | 3249 | return ERR_PTR(ret); |
3237 | if (ret > 0) | 3250 | if (ret > 0) |
3238 | return ERR_PTR(-ENOENT); | 3251 | return ERR_PTR(-ENOENT); |
3239 | inode = btrfs_iget(dir->i_sb, &location, sub_root, &new); | 3252 | inode = btrfs_iget(dir->i_sb, &location, sub_root); |
3240 | if (IS_ERR(inode)) | 3253 | if (IS_ERR(inode)) |
3241 | return ERR_CAST(inode); | 3254 | return ERR_CAST(inode); |
3242 | } | 3255 | } |
@@ -3574,9 +3587,9 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
3574 | btrfs_find_block_group(root, 0, alloc_hint, owner); | 3587 | btrfs_find_block_group(root, 0, alloc_hint, owner); |
3575 | if ((mode & S_IFREG)) { | 3588 | if ((mode & S_IFREG)) { |
3576 | if (btrfs_test_opt(root, NODATASUM)) | 3589 | if (btrfs_test_opt(root, NODATASUM)) |
3577 | btrfs_set_flag(inode, NODATASUM); | 3590 | BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM; |
3578 | if (btrfs_test_opt(root, NODATACOW)) | 3591 | if (btrfs_test_opt(root, NODATACOW)) |
3579 | btrfs_set_flag(inode, NODATACOW); | 3592 | BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW; |
3580 | } | 3593 | } |
3581 | 3594 | ||
3582 | key[0].objectid = objectid; | 3595 | key[0].objectid = objectid; |
@@ -3630,7 +3643,10 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
3630 | location->offset = 0; | 3643 | location->offset = 0; |
3631 | btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY); | 3644 | btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY); |
3632 | 3645 | ||
3646 | btrfs_inherit_iflags(inode, dir); | ||
3647 | |||
3633 | insert_inode_hash(inode); | 3648 | insert_inode_hash(inode); |
3649 | inode_tree_add(inode); | ||
3634 | return inode; | 3650 | return inode; |
3635 | fail: | 3651 | fail: |
3636 | if (dir) | 3652 | if (dir) |
@@ -3750,7 +3766,6 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, | |||
3750 | init_special_inode(inode, inode->i_mode, rdev); | 3766 | init_special_inode(inode, inode->i_mode, rdev); |
3751 | btrfs_update_inode(trans, root, inode); | 3767 | btrfs_update_inode(trans, root, inode); |
3752 | } | 3768 | } |
3753 | dir->i_sb->s_dirt = 1; | ||
3754 | btrfs_update_inode_block_group(trans, inode); | 3769 | btrfs_update_inode_block_group(trans, inode); |
3755 | btrfs_update_inode_block_group(trans, dir); | 3770 | btrfs_update_inode_block_group(trans, dir); |
3756 | out_unlock: | 3771 | out_unlock: |
@@ -3815,7 +3830,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
3815 | inode->i_op = &btrfs_file_inode_operations; | 3830 | inode->i_op = &btrfs_file_inode_operations; |
3816 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; | 3831 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; |
3817 | } | 3832 | } |
3818 | dir->i_sb->s_dirt = 1; | ||
3819 | btrfs_update_inode_block_group(trans, inode); | 3833 | btrfs_update_inode_block_group(trans, inode); |
3820 | btrfs_update_inode_block_group(trans, dir); | 3834 | btrfs_update_inode_block_group(trans, dir); |
3821 | out_unlock: | 3835 | out_unlock: |
@@ -3862,7 +3876,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | |||
3862 | if (err) | 3876 | if (err) |
3863 | drop_inode = 1; | 3877 | drop_inode = 1; |
3864 | 3878 | ||
3865 | dir->i_sb->s_dirt = 1; | ||
3866 | btrfs_update_inode_block_group(trans, dir); | 3879 | btrfs_update_inode_block_group(trans, dir); |
3867 | err = btrfs_update_inode(trans, root, inode); | 3880 | err = btrfs_update_inode(trans, root, inode); |
3868 | 3881 | ||
@@ -3944,7 +3957,6 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
3944 | 3957 | ||
3945 | d_instantiate(dentry, inode); | 3958 | d_instantiate(dentry, inode); |
3946 | drop_on_err = 0; | 3959 | drop_on_err = 0; |
3947 | dir->i_sb->s_dirt = 1; | ||
3948 | btrfs_update_inode_block_group(trans, inode); | 3960 | btrfs_update_inode_block_group(trans, inode); |
3949 | btrfs_update_inode_block_group(trans, dir); | 3961 | btrfs_update_inode_block_group(trans, dir); |
3950 | 3962 | ||
@@ -4683,6 +4695,7 @@ void btrfs_destroy_inode(struct inode *inode) | |||
4683 | btrfs_put_ordered_extent(ordered); | 4695 | btrfs_put_ordered_extent(ordered); |
4684 | } | 4696 | } |
4685 | } | 4697 | } |
4698 | inode_tree_del(inode); | ||
4686 | btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); | 4699 | btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); |
4687 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); | 4700 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); |
4688 | } | 4701 | } |
@@ -4972,7 +4985,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
4972 | inode->i_op = &btrfs_file_inode_operations; | 4985 | inode->i_op = &btrfs_file_inode_operations; |
4973 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; | 4986 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; |
4974 | } | 4987 | } |
4975 | dir->i_sb->s_dirt = 1; | ||
4976 | btrfs_update_inode_block_group(trans, inode); | 4988 | btrfs_update_inode_block_group(trans, inode); |
4977 | btrfs_update_inode_block_group(trans, dir); | 4989 | btrfs_update_inode_block_group(trans, dir); |
4978 | if (drop_inode) | 4990 | if (drop_inode) |
@@ -5061,7 +5073,7 @@ static int prealloc_file_range(struct btrfs_trans_handle *trans, | |||
5061 | out: | 5073 | out: |
5062 | if (cur_offset > start) { | 5074 | if (cur_offset > start) { |
5063 | inode->i_ctime = CURRENT_TIME; | 5075 | inode->i_ctime = CURRENT_TIME; |
5064 | btrfs_set_flag(inode, PREALLOC); | 5076 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; |
5065 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | 5077 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
5066 | cur_offset > i_size_read(inode)) | 5078 | cur_offset > i_size_read(inode)) |
5067 | btrfs_i_size_write(inode, cur_offset); | 5079 | btrfs_i_size_write(inode, cur_offset); |
@@ -5182,7 +5194,7 @@ static int btrfs_set_page_dirty(struct page *page) | |||
5182 | 5194 | ||
5183 | static int btrfs_permission(struct inode *inode, int mask) | 5195 | static int btrfs_permission(struct inode *inode, int mask) |
5184 | { | 5196 | { |
5185 | if (btrfs_test_flag(inode, READONLY) && (mask & MAY_WRITE)) | 5197 | if ((BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) && (mask & MAY_WRITE)) |
5186 | return -EACCES; | 5198 | return -EACCES; |
5187 | return generic_permission(inode, mask, btrfs_check_acl); | 5199 | return generic_permission(inode, mask, btrfs_check_acl); |
5188 | } | 5200 | } |