diff options
Diffstat (limited to 'fs/ocfs2/refcounttree.c')
| -rw-r--r-- | fs/ocfs2/refcounttree.c | 150 |
1 files changed, 117 insertions, 33 deletions
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 30967e3f5e43..74db2be75dd6 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c | |||
| @@ -276,7 +276,7 @@ static void ocfs2_erase_refcount_tree_from_list(struct ocfs2_super *osb, | |||
| 276 | spin_unlock(&osb->osb_lock); | 276 | spin_unlock(&osb->osb_lock); |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | void ocfs2_kref_remove_refcount_tree(struct kref *kref) | 279 | static void ocfs2_kref_remove_refcount_tree(struct kref *kref) |
| 280 | { | 280 | { |
| 281 | struct ocfs2_refcount_tree *tree = | 281 | struct ocfs2_refcount_tree *tree = |
| 282 | container_of(kref, struct ocfs2_refcount_tree, rf_getcnt); | 282 | container_of(kref, struct ocfs2_refcount_tree, rf_getcnt); |
| @@ -524,23 +524,6 @@ out: | |||
| 524 | return ret; | 524 | return ret; |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | int ocfs2_lock_refcount_tree_by_inode(struct inode *inode, int rw, | ||
| 528 | struct ocfs2_refcount_tree **ret_tree, | ||
| 529 | struct buffer_head **ref_bh) | ||
| 530 | { | ||
| 531 | int ret; | ||
| 532 | u64 ref_blkno; | ||
| 533 | |||
| 534 | ret = ocfs2_get_refcount_block(inode, &ref_blkno); | ||
| 535 | if (ret) { | ||
| 536 | mlog_errno(ret); | ||
| 537 | return ret; | ||
| 538 | } | ||
| 539 | |||
| 540 | return ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb), ref_blkno, | ||
| 541 | rw, ret_tree, ref_bh); | ||
| 542 | } | ||
| 543 | |||
| 544 | void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb, | 527 | void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb, |
| 545 | struct ocfs2_refcount_tree *tree, int rw) | 528 | struct ocfs2_refcount_tree *tree, int rw) |
| 546 | { | 529 | { |
| @@ -969,6 +952,103 @@ out: | |||
| 969 | } | 952 | } |
| 970 | 953 | ||
| 971 | /* | 954 | /* |
| 955 | * Find the end range for a leaf refcount block indicated by | ||
| 956 | * el->l_recs[index].e_blkno. | ||
| 957 | */ | ||
| 958 | static int ocfs2_get_refcount_cpos_end(struct ocfs2_caching_info *ci, | ||
| 959 | struct buffer_head *ref_root_bh, | ||
| 960 | struct ocfs2_extent_block *eb, | ||
| 961 | struct ocfs2_extent_list *el, | ||
| 962 | int index, u32 *cpos_end) | ||
| 963 | { | ||
| 964 | int ret, i, subtree_root; | ||
| 965 | u32 cpos; | ||
| 966 | u64 blkno; | ||
| 967 | struct super_block *sb = ocfs2_metadata_cache_get_super(ci); | ||
| 968 | struct ocfs2_path *left_path = NULL, *right_path = NULL; | ||
| 969 | struct ocfs2_extent_tree et; | ||
| 970 | struct ocfs2_extent_list *tmp_el; | ||
| 971 | |||
| 972 | if (index < le16_to_cpu(el->l_next_free_rec) - 1) { | ||
| 973 | /* | ||
| 974 | * We have a extent rec after index, so just use the e_cpos | ||
| 975 | * of the next extent rec. | ||
| 976 | */ | ||
| 977 | *cpos_end = le32_to_cpu(el->l_recs[index+1].e_cpos); | ||
| 978 | return 0; | ||
| 979 | } | ||
| 980 | |||
| 981 | if (!eb || (eb && !eb->h_next_leaf_blk)) { | ||
| 982 | /* | ||
| 983 | * We are the last extent rec, so any high cpos should | ||
| 984 | * be stored in this leaf refcount block. | ||
| 985 | */ | ||
| 986 | *cpos_end = UINT_MAX; | ||
| 987 | return 0; | ||
| 988 | } | ||
| 989 | |||
| 990 | /* | ||
| 991 | * If the extent block isn't the last one, we have to find | ||
| 992 | * the subtree root between this extent block and the next | ||
| 993 | * leaf extent block and get the corresponding e_cpos from | ||
| 994 | * the subroot. Otherwise we may corrupt the b-tree. | ||
| 995 | */ | ||
| 996 | ocfs2_init_refcount_extent_tree(&et, ci, ref_root_bh); | ||
| 997 | |||
| 998 | left_path = ocfs2_new_path_from_et(&et); | ||
| 999 | if (!left_path) { | ||
| 1000 | ret = -ENOMEM; | ||
| 1001 | mlog_errno(ret); | ||
| 1002 | goto out; | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | cpos = le32_to_cpu(eb->h_list.l_recs[index].e_cpos); | ||
| 1006 | ret = ocfs2_find_path(ci, left_path, cpos); | ||
| 1007 | if (ret) { | ||
| 1008 | mlog_errno(ret); | ||
| 1009 | goto out; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | right_path = ocfs2_new_path_from_path(left_path); | ||
| 1013 | if (!right_path) { | ||
| 1014 | ret = -ENOMEM; | ||
| 1015 | mlog_errno(ret); | ||
| 1016 | goto out; | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | ret = ocfs2_find_cpos_for_right_leaf(sb, left_path, &cpos); | ||
| 1020 | if (ret) { | ||
| 1021 | mlog_errno(ret); | ||
| 1022 | goto out; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | ret = ocfs2_find_path(ci, right_path, cpos); | ||
| 1026 | if (ret) { | ||
| 1027 | mlog_errno(ret); | ||
| 1028 | goto out; | ||
| 1029 | } | ||
| 1030 | |||
| 1031 | subtree_root = ocfs2_find_subtree_root(&et, left_path, | ||
| 1032 | right_path); | ||
| 1033 | |||
| 1034 | tmp_el = left_path->p_node[subtree_root].el; | ||
| 1035 | blkno = left_path->p_node[subtree_root+1].bh->b_blocknr; | ||
| 1036 | for (i = 0; i < le32_to_cpu(tmp_el->l_next_free_rec); i++) { | ||
| 1037 | if (le64_to_cpu(tmp_el->l_recs[i].e_blkno) == blkno) { | ||
| 1038 | *cpos_end = le32_to_cpu(tmp_el->l_recs[i+1].e_cpos); | ||
| 1039 | break; | ||
| 1040 | } | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | BUG_ON(i == le32_to_cpu(tmp_el->l_next_free_rec)); | ||
| 1044 | |||
| 1045 | out: | ||
| 1046 | ocfs2_free_path(left_path); | ||
| 1047 | ocfs2_free_path(right_path); | ||
| 1048 | return ret; | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | /* | ||
| 972 | * Given a cpos and len, try to find the refcount record which contains cpos. | 1052 | * Given a cpos and len, try to find the refcount record which contains cpos. |
| 973 | * 1. If cpos can be found in one refcount record, return the record. | 1053 | * 1. If cpos can be found in one refcount record, return the record. |
| 974 | * 2. If cpos can't be found, return a fake record which start from cpos | 1054 | * 2. If cpos can't be found, return a fake record which start from cpos |
| @@ -983,10 +1063,10 @@ static int ocfs2_get_refcount_rec(struct ocfs2_caching_info *ci, | |||
| 983 | struct buffer_head **ret_bh) | 1063 | struct buffer_head **ret_bh) |
| 984 | { | 1064 | { |
| 985 | int ret = 0, i, found; | 1065 | int ret = 0, i, found; |
| 986 | u32 low_cpos; | 1066 | u32 low_cpos, uninitialized_var(cpos_end); |
| 987 | struct ocfs2_extent_list *el; | 1067 | struct ocfs2_extent_list *el; |
| 988 | struct ocfs2_extent_rec *tmp, *rec = NULL; | 1068 | struct ocfs2_extent_rec *rec = NULL; |
| 989 | struct ocfs2_extent_block *eb; | 1069 | struct ocfs2_extent_block *eb = NULL; |
| 990 | struct buffer_head *eb_bh = NULL, *ref_leaf_bh = NULL; | 1070 | struct buffer_head *eb_bh = NULL, *ref_leaf_bh = NULL; |
| 991 | struct super_block *sb = ocfs2_metadata_cache_get_super(ci); | 1071 | struct super_block *sb = ocfs2_metadata_cache_get_super(ci); |
| 992 | struct ocfs2_refcount_block *rb = | 1072 | struct ocfs2_refcount_block *rb = |
| @@ -1034,12 +1114,16 @@ static int ocfs2_get_refcount_rec(struct ocfs2_caching_info *ci, | |||
| 1034 | } | 1114 | } |
| 1035 | } | 1115 | } |
| 1036 | 1116 | ||
| 1037 | /* adjust len when we have ocfs2_extent_rec after it. */ | 1117 | if (found) { |
| 1038 | if (found && i < le16_to_cpu(el->l_next_free_rec) - 1) { | 1118 | ret = ocfs2_get_refcount_cpos_end(ci, ref_root_bh, |
| 1039 | tmp = &el->l_recs[i+1]; | 1119 | eb, el, i, &cpos_end); |
| 1120 | if (ret) { | ||
| 1121 | mlog_errno(ret); | ||
| 1122 | goto out; | ||
| 1123 | } | ||
| 1040 | 1124 | ||
| 1041 | if (le32_to_cpu(tmp->e_cpos) < cpos + len) | 1125 | if (cpos_end < low_cpos + len) |
| 1042 | len = le32_to_cpu(tmp->e_cpos) - cpos; | 1126 | len = cpos_end - low_cpos; |
| 1043 | } | 1127 | } |
| 1044 | 1128 | ||
| 1045 | ret = ocfs2_read_refcount_block(ci, le64_to_cpu(rec->e_blkno), | 1129 | ret = ocfs2_read_refcount_block(ci, le64_to_cpu(rec->e_blkno), |
| @@ -1418,7 +1502,7 @@ static int ocfs2_divide_leaf_refcount_block(struct buffer_head *ref_leaf_bh, | |||
| 1418 | 1502 | ||
| 1419 | /* change old and new rl_used accordingly. */ | 1503 | /* change old and new rl_used accordingly. */ |
| 1420 | le16_add_cpu(&rl->rl_used, -num_moved); | 1504 | le16_add_cpu(&rl->rl_used, -num_moved); |
| 1421 | new_rl->rl_used = cpu_to_le32(num_moved); | 1505 | new_rl->rl_used = cpu_to_le16(num_moved); |
| 1422 | 1506 | ||
| 1423 | sort(&rl->rl_recs, le16_to_cpu(rl->rl_used), | 1507 | sort(&rl->rl_recs, le16_to_cpu(rl->rl_used), |
| 1424 | sizeof(struct ocfs2_refcount_rec), | 1508 | sizeof(struct ocfs2_refcount_rec), |
| @@ -1797,7 +1881,8 @@ static int ocfs2_split_refcount_rec(handle_t *handle, | |||
| 1797 | recs_need++; | 1881 | recs_need++; |
| 1798 | 1882 | ||
| 1799 | /* If the leaf block don't have enough record, expand it. */ | 1883 | /* If the leaf block don't have enough record, expand it. */ |
| 1800 | if (le16_to_cpu(rf_list->rl_used) + recs_need > rf_list->rl_count) { | 1884 | if (le16_to_cpu(rf_list->rl_used) + recs_need > |
| 1885 | le16_to_cpu(rf_list->rl_count)) { | ||
| 1801 | struct ocfs2_refcount_rec tmp_rec; | 1886 | struct ocfs2_refcount_rec tmp_rec; |
| 1802 | u64 cpos = le64_to_cpu(orig_rec->r_cpos); | 1887 | u64 cpos = le64_to_cpu(orig_rec->r_cpos); |
| 1803 | len = le32_to_cpu(orig_rec->r_clusters); | 1888 | len = le32_to_cpu(orig_rec->r_clusters); |
| @@ -1859,7 +1944,7 @@ static int ocfs2_split_refcount_rec(handle_t *handle, | |||
| 1859 | memcpy(tail_rec, orig_rec, sizeof(struct ocfs2_refcount_rec)); | 1944 | memcpy(tail_rec, orig_rec, sizeof(struct ocfs2_refcount_rec)); |
| 1860 | le64_add_cpu(&tail_rec->r_cpos, | 1945 | le64_add_cpu(&tail_rec->r_cpos, |
| 1861 | le32_to_cpu(tail_rec->r_clusters) - len); | 1946 | le32_to_cpu(tail_rec->r_clusters) - len); |
| 1862 | tail_rec->r_clusters = le32_to_cpu(len); | 1947 | tail_rec->r_clusters = cpu_to_le32(len); |
| 1863 | } | 1948 | } |
| 1864 | 1949 | ||
| 1865 | /* | 1950 | /* |
| @@ -3840,8 +3925,7 @@ static int ocfs2_add_refcounted_extent(struct inode *inode, | |||
| 3840 | } | 3925 | } |
| 3841 | 3926 | ||
| 3842 | ret = ocfs2_insert_extent(handle, et, cpos, | 3927 | ret = ocfs2_insert_extent(handle, et, cpos, |
| 3843 | cpu_to_le64(ocfs2_clusters_to_blocks(inode->i_sb, | 3928 | ocfs2_clusters_to_blocks(inode->i_sb, p_cluster), |
| 3844 | p_cluster)), | ||
| 3845 | num_clusters, ext_flags, meta_ac); | 3929 | num_clusters, ext_flags, meta_ac); |
| 3846 | if (ret) { | 3930 | if (ret) { |
| 3847 | mlog_errno(ret); | 3931 | mlog_errno(ret); |
| @@ -4253,8 +4337,8 @@ static int ocfs2_user_path_parent(const char __user *path, | |||
| 4253 | * @new_dentry: target dentry | 4337 | * @new_dentry: target dentry |
| 4254 | * @preserve: if true, preserve all file attributes | 4338 | * @preserve: if true, preserve all file attributes |
| 4255 | */ | 4339 | */ |
| 4256 | int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir, | 4340 | static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir, |
| 4257 | struct dentry *new_dentry, bool preserve) | 4341 | struct dentry *new_dentry, bool preserve) |
| 4258 | { | 4342 | { |
| 4259 | struct inode *inode = old_dentry->d_inode; | 4343 | struct inode *inode = old_dentry->d_inode; |
| 4260 | int error; | 4344 | int error; |
