27 #include <linux/types.h>
28 #include <linux/slab.h>
168 .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk,
169 .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk,
170 .eo_update_clusters = ocfs2_dinode_update_clusters,
171 .eo_extent_map_insert = ocfs2_dinode_extent_map_insert,
172 .eo_extent_map_truncate = ocfs2_dinode_extent_map_truncate,
173 .eo_insert_check = ocfs2_dinode_insert_check,
174 .eo_sanity_check = ocfs2_dinode_sanity_check,
175 .eo_fill_root_el = ocfs2_dinode_fill_root_el,
232 "Device %s, asking for sparse allocation: inode %llu, "
233 "cpos %u, clusters %u\n",
286 le32_add_cpu(&vb->
vb_xv->xr_clusters, clusters);
290 .eo_set_last_eb_blk = ocfs2_xattr_value_set_last_eb_blk,
291 .eo_get_last_eb_blk = ocfs2_xattr_value_get_last_eb_blk,
292 .eo_update_clusters = ocfs2_xattr_value_update_clusters,
293 .eo_fill_root_el = ocfs2_xattr_value_fill_root_el,
303 static void ocfs2_xattr_tree_fill_max_leaf_clusters(
struct ocfs2_extent_tree *et)
336 .eo_set_last_eb_blk = ocfs2_xattr_tree_set_last_eb_blk,
337 .eo_get_last_eb_blk = ocfs2_xattr_tree_get_last_eb_blk,
338 .eo_update_clusters = ocfs2_xattr_tree_update_clusters,
339 .eo_fill_root_el = ocfs2_xattr_tree_fill_root_el,
340 .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters,
383 .eo_set_last_eb_blk = ocfs2_dx_root_set_last_eb_blk,
384 .eo_get_last_eb_blk = ocfs2_dx_root_get_last_eb_blk,
385 .eo_update_clusters = ocfs2_dx_root_update_clusters,
386 .eo_sanity_check = ocfs2_dx_root_sanity_check,
387 .eo_fill_root_el = ocfs2_dx_root_fill_root_el,
429 .eo_set_last_eb_blk = ocfs2_refcount_tree_set_last_eb_blk,
430 .eo_get_last_eb_blk = ocfs2_refcount_tree_get_last_eb_blk,
431 .eo_update_clusters = ocfs2_refcount_tree_update_clusters,
432 .eo_fill_root_el = ocfs2_refcount_tree_fill_root_el,
433 .eo_extent_contig = ocfs2_refcount_tree_extent_contig,
438 struct buffer_head *bh,
448 obj = (
void *)bh->b_data;
451 et->
et_ops->eo_fill_root_el(et);
452 if (!et->
et_ops->eo_fill_max_leaf_clusters)
455 et->
et_ops->eo_fill_max_leaf_clusters(et);
460 struct buffer_head *bh)
463 NULL, &ocfs2_dinode_et_ops);
468 struct buffer_head *bh)
471 NULL, &ocfs2_xattr_tree_et_ops);
479 &ocfs2_xattr_value_et_ops);
484 struct buffer_head *bh)
487 NULL, &ocfs2_dx_root_et_ops);
492 struct buffer_head *bh)
495 NULL, &ocfs2_refcount_tree_et_ops);
501 et->
et_ops->eo_set_last_eb_blk(et, new_last_eb_blk);
506 return et->
et_ops->eo_get_last_eb_blk(et);
512 et->
et_ops->eo_update_clusters(et, clusters);
518 if (et->
et_ops->eo_extent_map_insert)
519 et->
et_ops->eo_extent_map_insert(et, rec);
525 if (et->
et_ops->eo_extent_map_truncate)
526 et->
et_ops->eo_extent_map_truncate(et, clusters);
529 static inline int ocfs2_et_root_journal_access(handle_t *
handle,
542 if (et->
et_ops->eo_extent_contig)
543 return et->
et_ops->eo_extent_contig(et, rec, insert_rec);
545 return ocfs2_extent_rec_contig(
555 if (et->
et_ops->eo_insert_check)
556 ret = et->
et_ops->eo_insert_check(et, rec);
564 if (et->
et_ops->eo_sanity_check)
565 ret = et->
et_ops->eo_sanity_check(et);
571 static void ocfs2_adjust_rightmost_records(handle_t *handle,
639 get_bh(dest->
p_node[i].bh);
655 brelse(dest->
p_node[i].bh);
671 struct buffer_head *eb_bh)
687 static struct ocfs2_path *ocfs2_new_path(
struct buffer_head *root_bh,
695 path = kzalloc(
sizeof(*path),
GFP_NOFS);
778 u32 rec_end, rec_start, clusters;
784 clusters = ocfs2_rec_clusters(el, rec);
786 rec_end = rec_start + clusters;
788 if (v_cluster >= rec_start && v_cluster < rec_end) {
807 blk_end += ocfs2_clusters_to_blocks(sb,
810 return blkno == blk_end;
839 if (ocfs2_extents_adjacent(ext, insert_rec) &&
840 ocfs2_block_extent_contig(sb, ext, blkno))
844 if (ocfs2_extents_adjacent(insert_rec, ext) &&
845 ocfs2_block_extent_contig(sb, insert_rec, blkno))
883 static int ocfs2_validate_extent_block(
struct super_block *sb,
884 struct buffer_head *bh)
890 trace_ocfs2_validate_extent_block((
unsigned long long)bh->b_blocknr);
892 BUG_ON(!buffer_uptodate(bh));
901 mlog(
ML_ERROR,
"Checksum failed for extent block %llu\n",
902 (
unsigned long long)bh->b_blocknr);
912 "Extent block #%llu has bad signature %.*s",
913 (
unsigned long long)bh->b_blocknr, 7,
920 "Extent block #%llu has an invalid h_blkno "
922 (
unsigned long long)bh->b_blocknr,
929 "Extent block #%llu has an invalid "
930 "h_fs_generation of #%u",
931 (
unsigned long long)bh->b_blocknr,
940 struct buffer_head **bh)
943 struct buffer_head *
tmp = *bh;
945 rc = ocfs2_read_block(ci, eb_blkno, &tmp,
946 ocfs2_validate_extent_block);
965 struct buffer_head *eb_bh =
NULL;
969 last_eb_blk = ocfs2_et_get_last_eb_blk(et);
988 trace_ocfs2_num_free_extents(retval);
997 static int ocfs2_create_new_meta_bhs(handle_t *handle,
1001 struct buffer_head *bhs[])
1004 u16 suballoc_bit_start;
1006 u64 suballoc_loc, first_blkno;
1012 while (count < wanted) {
1017 &suballoc_bit_start,
1025 for(i = count; i < (num_got +
count); i++) {
1026 bhs[
i] = sb_getblk(osb->
sb, first_blkno);
1027 if (bhs[i] ==
NULL) {
1042 memset(bhs[i]->b_data, 0, osb->
sb->s_blocksize);
1055 suballoc_bit_start++;
1069 for(i = 0; i <
wanted; i++) {
1097 ocfs2_rec_clusters(el, &el->
l_recs[i]);
1104 static int ocfs2_adjust_rightmost_branch(handle_t *handle,
1139 ocfs2_adjust_rightmost_records(handle, et, path, rec);
1157 static int ocfs2_add_branch(handle_t *handle,
1159 struct buffer_head *eb_bh,
1160 struct buffer_head **last_eb_bh,
1164 u64 next_blkno, new_last_eb_blk;
1165 struct buffer_head *bh;
1166 struct buffer_head **new_eb_bhs =
NULL;
1170 u32 new_cpos, root_end;
1172 BUG_ON(!last_eb_bh || !*last_eb_bh);
1186 new_cpos = ocfs2_sum_rightmost_rec(&eb->
h_list);
1187 root_end = ocfs2_sum_rightmost_rec(et->
et_root_el);
1196 if (root_end > new_cpos) {
1197 trace_ocfs2_adjust_rightmost_branch(
1198 (
unsigned long long)
1200 root_end, new_cpos);
1202 status = ocfs2_adjust_rightmost_branch(handle, et);
1210 new_eb_bhs = kcalloc(new_blocks,
sizeof(
struct buffer_head *),
1218 status = ocfs2_create_new_meta_bhs(handle, et, new_blocks,
1219 meta_ac, new_eb_bhs);
1232 next_blkno = new_last_eb_blk = 0;
1233 for(i = 0; i < new_blocks; i++) {
1281 status = ocfs2_et_root_journal_access(handle, et,
1301 el->
l_recs[
i].e_int_clusters = 0;
1306 ocfs2_et_set_last_eb_blk(et, new_last_eb_blk);
1320 brelse(*last_eb_bh);
1321 get_bh(new_eb_bhs[0]);
1322 *last_eb_bh = new_eb_bhs[0];
1327 for (i = 0; i < new_blocks; i++)
1328 brelse(new_eb_bhs[i]);
1340 static int ocfs2_shift_tree_depth(handle_t *handle,
1343 struct buffer_head **ret_new_eb_bh)
1347 struct buffer_head *new_eb_bh =
NULL;
1352 status = ocfs2_create_new_meta_bhs(handle, et, 1, meta_ac,
1381 status = ocfs2_et_root_journal_access(handle, et,
1388 new_clusters = ocfs2_sum_rightmost_rec(eb_el);
1392 root_el->
l_recs[0].e_cpos = 0;
1406 *ret_new_eb_bh = new_eb_bh;
1433 struct buffer_head **target_bh)
1439 struct buffer_head *bh =
NULL;
1440 struct buffer_head *lowest_bh =
NULL;
1449 "Owner %llu has empty "
1450 "extent list (next_free_rec == 0)",
1459 "Owner %llu has extent "
1460 "list where extent # %d has no physical "
1493 *target_bh = lowest_bh;
1511 int *final_depth,
struct buffer_head **last_eb_bh,
1517 struct buffer_head *bh =
NULL;
1521 shift = ocfs2_find_branch_target(et, &bh);
1533 trace_ocfs2_grow_tree(
1534 (
unsigned long long)
1541 ret = ocfs2_shift_tree_depth(handle, et, meta_ac, &bh);
1566 ret = ocfs2_add_branch(handle, et, bh, last_eb_bh,
1575 *final_depth =
depth;
1591 BUG_ON(next_free >= count);
1601 int i, insert_index, next_free, has_empty,
num_bytes;
1606 has_empty = ocfs2_is_empty_extent(&el->
l_recs[0]);
1623 for(i = 0; i < (next_free - 1); i++)
1632 for(i = 0; i < next_free; i++) {
1640 trace_ocfs2_rotate_leaf(insert_cpos, insert_index,
1641 has_empty, next_free,
1644 BUG_ON(insert_index < 0);
1646 BUG_ON(insert_index > next_free);
1651 if (insert_index != next_free) {
1654 num_bytes = next_free - insert_index;
1657 &el->
l_recs[insert_index],
1673 el->
l_recs[insert_index] = *insert_rec;
1683 if (ocfs2_is_empty_extent(&el->
l_recs[0])) {
1709 if (ocfs2_is_empty_extent(&el->
l_recs[0]))
1713 "Asked to create an empty extent in a full list:\n"
1714 "count = %u, tree depth = %u",
1718 ocfs2_shift_records_right(el);
1755 "Owner %llu, left depth %u, right depth %u\n"
1756 "left leaf blk %llu, right leaf blk %llu\n",
1761 }
while (left->
p_node[i].bh->b_blocknr ==
1762 right->
p_node[i].bh->b_blocknr);
1782 struct buffer_head *bh =
NULL;
1791 "Owner %llu has empty extent list at "
1809 ocfs2_rec_clusters(el, rec);
1817 "Owner %llu has bad blkno in extent list "
1818 "at depth %u (index %d)\n",
1839 "Owner %llu has bad count in extent list "
1840 "at block %llu (next free=%u, count=%u)\n",
1842 (
unsigned long long)bh->b_blocknr,
1877 static void find_path_ins(
void *
data,
struct buffer_head *bh)
1882 ocfs2_path_insert_eb(fp->
path, fp->
index, bh);
1893 find_path_ins, &data);
1896 static void find_leaf_ins(
void *
data,
struct buffer_head *bh)
1900 struct buffer_head **ret = data;
1919 struct buffer_head **leaf_bh)
1922 struct buffer_head *bh =
NULL;
1924 ret = __ocfs2_find_path(ci, root_el, cpos, find_leaf_ins, &bh);
1949 static void ocfs2_adjust_adjacent_records(
struct ocfs2_extent_rec *left_rec,
1954 u32 left_clusters, right_end;
1964 if (!ocfs2_rec_clusters(right_child_el, &right_child_el->
l_recs[0])) {
1981 le32_add_cpu(&right_rec->
e_cpos, left_clusters);
2013 ocfs2_adjust_adjacent_records(&root_el->
l_recs[i], left_el,
2014 &root_el->
l_recs[i + 1], right_el);
2030 static void ocfs2_complete_edge_insert(handle_t *handle,
2038 struct buffer_head *root_bh = left_path->
p_node[subtree_index].bh;
2054 for(i = left_path->
p_tree_depth - 1; i > subtree_index; i--) {
2055 trace_ocfs2_complete_edge_insert(i);
2067 el = right_path->
p_node[
i].el;
2068 right_rec = &el->
l_recs[0];
2070 ocfs2_adjust_adjacent_records(left_rec, left_el, right_rec,
2080 left_el = left_path->
p_node[
i].el;
2081 right_el = right_path->
p_node[
i].el;
2089 el = left_path->
p_node[subtree_index].el;
2090 left_el = left_path->
p_node[subtree_index + 1].el;
2091 right_el = right_path->
p_node[subtree_index + 1].el;
2093 ocfs2_adjust_root_records(el, left_el, right_el,
2094 left_path->
p_node[subtree_index + 1].bh->b_blocknr);
2096 root_bh = left_path->
p_node[subtree_index].bh;
2101 static int ocfs2_rotate_subtree_right(handle_t *handle,
2108 struct buffer_head *right_leaf_bh;
2109 struct buffer_head *left_leaf_bh =
NULL;
2110 struct buffer_head *root_bh;
2119 "Inode %llu has non-full interior leaf node %llu"
2122 (
unsigned long long)left_leaf_bh->b_blocknr,
2131 if (ocfs2_is_empty_extent(&left_el->
l_recs[0]))
2134 root_bh = left_path->
p_node[subtree_index].bh;
2135 BUG_ON(root_bh != right_path->
p_node[subtree_index].bh);
2144 for(i = subtree_index + 1; i <
path_num_items(right_path); i++) {
2165 "because rightmost leaf block %llu is empty\n",
2167 (
unsigned long long)right_leaf_bh->b_blocknr);
2169 ocfs2_create_empty_extent(right_el);
2175 move_rec = left_el->
l_recs[
i];
2176 right_el->
l_recs[0] = move_rec;
2186 ocfs2_shift_records_right(left_el);
2192 ocfs2_complete_edge_insert(handle, left_path, right_path,
2248 *cpos = *cpos + ocfs2_rec_clusters(el,
2260 "Invalid extent tree at extent block %llu\n",
2261 (
unsigned long long)blkno);
2266 blkno = path->
p_node[
i].bh->b_blocknr;
2279 static int ocfs2_extend_rotate_transaction(handle_t *handle,
int subtree_depth,
2284 int credits = (path->
p_tree_depth - subtree_depth) * 2 + 1 + op_credits;
2286 if (handle->h_buffer_credits < credits)
2288 credits - handle->h_buffer_credits);
2303 static int ocfs2_rotate_requires_path_adjustment(
struct ocfs2_path *left_path,
2312 rec = &left_el->
l_recs[next_free - 1];
2329 if (ocfs2_is_empty_extent(rec)) {
2358 static int ocfs2_rotate_tree_right(handle_t *handle,
2365 int ret,
start, orig_credits = handle->h_buffer_credits;
2370 *ret_left_path =
NULL;
2385 trace_ocfs2_rotate_tree_right(
2415 while (cpos && insert_cpos <= cpos) {
2416 trace_ocfs2_rotate_tree_right(
2417 (
unsigned long long)
2429 "Owner %llu: error during insert of %u "
2430 "(left path cpos %u) results in two identical "
2431 "paths ending at %llu\n",
2434 (
unsigned long long)
2438 ocfs2_rotate_requires_path_adjustment(left_path,
2455 *ret_left_path = left_path;
2461 trace_ocfs2_rotate_subtree(start,
2462 (
unsigned long long)
2463 right_path->
p_node[start].bh->b_blocknr,
2466 ret = ocfs2_extend_rotate_transaction(handle, start,
2467 orig_credits, right_path);
2473 ret = ocfs2_rotate_subtree_right(handle, et, left_path,
2494 *ret_left_path = left_path;
2503 ocfs2_mv_path(right_path, left_path);
2519 static int ocfs2_update_edge_lengths(handle_t *handle,
2574 static void ocfs2_unlink_path(handle_t *handle,
2582 struct buffer_head *bh;
2595 "Inode %llu, attempted to remove extent block "
2596 "%llu with %u records\n",
2611 ret = ocfs2_cache_extent_block_free(dealloc, eb);
2619 static void ocfs2_unlink_subtree(handle_t *handle,
2627 struct buffer_head *root_bh = left_path->
p_node[subtree_index].bh;
2651 ocfs2_unlink_path(handle, et, dealloc, right_path,
2655 static int ocfs2_rotate_subtree_left(handle_t *handle,
2663 int ret,
i, del_right_subtree = 0, right_has_empty = 0;
2664 struct buffer_head *root_bh, *et_root_bh =
path_root_bh(right_path);
2672 root_bh = left_path->
p_node[subtree_index].bh;
2673 BUG_ON(root_bh != right_path->
p_node[subtree_index].bh);
2675 if (!ocfs2_is_empty_extent(&left_leaf_el->
l_recs[0]))
2679 if (ocfs2_is_empty_extent(&right_leaf_el->
l_recs[0])) {
2705 ocfs2_remove_empty_extent(right_leaf_el);
2707 right_has_empty = 1;
2716 ret = ocfs2_et_root_journal_access(handle, et,
2723 del_right_subtree = 1;
2730 BUG_ON(right_has_empty && !del_right_subtree);
2739 for(i = subtree_index + 1; i <
path_num_items(right_path); i++) {
2755 if (!right_has_empty) {
2762 ocfs2_rotate_leaf(left_leaf_el, &right_leaf_el->
l_recs[0]);
2773 ocfs2_remove_empty_extent(right_leaf_el);
2779 if (del_right_subtree) {
2780 ocfs2_unlink_subtree(handle, et, left_path, right_path,
2781 subtree_index, dealloc);
2782 ret = ocfs2_update_edge_lengths(handle, et, subtree_index,
2797 if (right_has_empty)
2798 ocfs2_remove_empty_extent(left_leaf_el);
2804 ocfs2_complete_edge_insert(handle, left_path, right_path,
2848 if (j == (next_free - 1)) {
2876 "Invalid extent tree at extent block %llu\n",
2877 (
unsigned long long)blkno);
2882 blkno = path->
p_node[
i].bh->b_blocknr;
2890 static int ocfs2_rotate_rightmost_leaf_left(handle_t *handle,
2898 if (!ocfs2_is_empty_extent(&el->
l_recs[0]))
2908 ocfs2_remove_empty_extent(el);
2915 static int __ocfs2_rotate_tree_left(handle_t *handle,
2922 int ret, subtree_root, deleted;
2930 *empty_extent_path =
NULL;
2945 ocfs2_cp_path(left_path, path);
2954 while (right_cpos) {
2964 trace_ocfs2_rotate_subtree(subtree_root,
2965 (
unsigned long long)
2966 right_path->
p_node[subtree_root].bh->b_blocknr,
2969 ret = ocfs2_extend_rotate_transaction(handle, subtree_root,
2970 orig_credits, left_path);
2987 ret = ocfs2_rotate_subtree_left(handle, et, left_path,
2988 right_path, subtree_root,
2997 *empty_extent_path = right_path;
3014 ocfs2_mv_path(left_path, right_path);
3031 static int ocfs2_remove_rightmost_path(handle_t *handle,
3036 int ret, subtree_index;
3043 ret = ocfs2_et_sanity_check(et);
3050 ret = ocfs2_extend_rotate_transaction(handle, 0,
3051 handle->h_buffer_credits,
3097 ocfs2_unlink_subtree(handle, et, left_path, path,
3098 subtree_index, dealloc);
3099 ret = ocfs2_update_edge_lengths(handle, et, subtree_index,
3116 ocfs2_unlink_path(handle, et, dealloc, path, 1);
3123 ocfs2_et_set_last_eb_blk(et, 0);
3149 static int ocfs2_rotate_tree_left(handle_t *handle,
3154 int ret, orig_credits = handle->h_buffer_credits;
3160 if (!ocfs2_is_empty_extent(&el->
l_recs[0]))
3164 rightmost_no_delete:
3169 ret = ocfs2_rotate_rightmost_leaf_left(handle, et, path);
3197 goto rightmost_no_delete;
3202 "Owner %llu has empty extent block at %llu",
3217 ret = ocfs2_remove_rightmost_path(handle, et, path,
3229 ret = __ocfs2_rotate_tree_left(handle, et, orig_credits, path,
3230 dealloc, &restart_path);
3231 if (ret && ret != -
EAGAIN) {
3237 tmp_path = restart_path;
3238 restart_path =
NULL;
3240 ret = __ocfs2_rotate_tree_left(handle, et, orig_credits,
3243 if (ret && ret != -
EAGAIN) {
3302 *ret_right_path =
NULL;
3311 left_path, &right_cpos);
3333 *ret_right_path = right_path;
3347 static int ocfs2_merge_rec_right(
struct ocfs2_path *left_path,
3353 int ret, next_free,
i;
3359 int subtree_index = 0;
3362 struct buffer_head *root_bh =
NULL;
3370 ret = ocfs2_get_right_path(et, left_path, &right_path);
3379 right_rec = &right_el->
l_recs[0];
3380 if (ocfs2_is_empty_extent(right_rec)) {
3382 right_rec = &right_el->
l_recs[1];
3392 ret = ocfs2_extend_rotate_transaction(handle, subtree_index,
3393 handle->h_buffer_credits,
3400 root_bh = left_path->
p_node[subtree_index].bh;
3401 BUG_ON(root_bh != right_path->
p_node[subtree_index].bh);
3410 for (i = subtree_index + 1;
3429 right_rec = &el->
l_recs[index + 1];
3441 le32_add_cpu(&right_rec->
e_cpos, -split_clusters);
3442 le64_add_cpu(&right_rec->
e_blkno,
3447 ocfs2_cleanup_merge(el, index);
3452 ocfs2_complete_edge_insert(handle, left_path, right_path,
3469 *ret_left_path =
NULL;
3475 right_path, &left_cpos);
3497 *ret_left_path = left_path;
3514 static int ocfs2_merge_rec_left(
struct ocfs2_path *right_path,
3521 int ret,
i, subtree_index = 0, has_empty_extent = 0;
3527 struct buffer_head *root_bh =
NULL;
3536 ret = ocfs2_get_left_path(et, right_path, &left_path);
3546 left_rec = &left_el->
l_recs[
3555 ret = ocfs2_extend_rotate_transaction(handle, subtree_index,
3556 handle->h_buffer_credits,
3563 root_bh = left_path->
p_node[subtree_index].bh;
3564 BUG_ON(root_bh != right_path->
p_node[subtree_index].bh);
3573 for (i = subtree_index + 1;
3590 left_rec = &el->
l_recs[index - 1];
3591 if (ocfs2_is_empty_extent(&el->
l_recs[0]))
3592 has_empty_extent = 1;
3602 if (has_empty_extent && index == 1) {
3606 *left_rec = *split_rec;
3608 has_empty_extent = 0;
3612 le32_add_cpu(&right_rec->
e_cpos, split_clusters);
3613 le64_add_cpu(&right_rec->
e_blkno,
3618 ocfs2_cleanup_merge(el, index);
3632 ret = ocfs2_remove_rightmost_path(handle, et,
3643 ocfs2_mv_path(right_path, left_path);
3646 ocfs2_complete_edge_insert(handle, left_path,
3647 right_path, subtree_index);
3655 static int ocfs2_try_to_merge_extent(handle_t *handle,
3677 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
3683 rec = &el->
l_recs[split_index];
3706 ret = ocfs2_merge_rec_right(path, handle, et, split_rec,
3719 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
3725 rec = &el->
l_recs[split_index];
3731 ret = ocfs2_merge_rec_left(path, handle, et, rec,
3732 dealloc, split_index);
3739 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
3756 ret = ocfs2_merge_rec_left(path, handle, et,
3764 ret = ocfs2_merge_rec_right(path, handle,
3778 ret = ocfs2_rotate_tree_left(handle, et, path,
3790 static void ocfs2_subtract_from_rec(
struct super_block *sb,
3797 len_blocks = ocfs2_clusters_to_blocks(sb,
3805 le32_add_cpu(&rec->
e_cpos,
3807 le64_add_cpu(&rec->
e_blkno, len_blocks);
3865 ocfs2_is_empty_extent(&el->
l_recs[0]))) {
3866 el->
l_recs[0] = *insert_rec;
3883 "owner %llu, depth %u, count %u, next free %u, "
3884 "rec.cpos %u, rec.clusters %u, "
3885 "insert.cpos %u, insert.clusters %u\n",
3911 ocfs2_rotate_leaf(el, insert_rec);
3914 static void ocfs2_adjust_rightmost_records(handle_t *handle,
3919 int ret,
i, next_free;
3920 struct buffer_head *bh;
3932 if (next_free == 0) {
3934 "Owner %llu has a bad extent list",
3940 rec = &el->
l_recs[next_free - 1];
3952 static int ocfs2_append_rec_to_path(handle_t *handle,
3962 *ret_left_path =
NULL;
3977 if (next_free == 0 ||
3978 (next_free == 1 && ocfs2_is_empty_extent(&el->
l_recs[0]))) {
3982 right_path, &left_cpos);
3988 trace_ocfs2_append_rec_to_path(
3989 (
unsigned long long)
4026 ocfs2_adjust_rightmost_records(handle, et, right_path, insert_rec);
4028 *ret_left_path = left_path;
4053 insert_el = right_el;
4056 if (index == 0 && left_path) {
4057 BUG_ON(ocfs2_is_empty_extent(&el->l_recs[0]));
4078 insert_el = left_el;
4087 tmprec = &right_el->l_recs[
index];
4088 ocfs2_rotate_leaf(left_el, tmprec);
4091 memset(tmprec, 0,
sizeof(*tmprec));
4104 insert_el = left_el;
4109 rec = &el->l_recs[
index];
4111 split, rec, split_rec);
4112 ocfs2_rotate_leaf(insert_el, split_rec);
4123 static int ocfs2_insert_path(handle_t *handle,
4130 int ret, subtree_index;
4131 struct buffer_head *leaf_bh =
path_leaf_bh(right_path);
4169 ocfs2_split_record(et, left_path, right_path,
4181 ocfs2_insert_at_leaf(et, insert_rec,
path_leaf_el(right_path),
4195 ocfs2_complete_edge_insert(handle, left_path, right_path,
4204 static int ocfs2_do_insert_extent(handle_t *handle,
4209 int ret, rotate = 0;
4217 ret = ocfs2_et_root_journal_access(handle, et,
4225 ocfs2_insert_at_leaf(et, insert_rec, el, type);
4226 goto out_update_clusters;
4267 ret = ocfs2_rotate_tree_right(handle, et, type->
ins_split,
4269 right_path, &left_path);
4279 ret = ocfs2_et_root_journal_access(handle, et,
4287 ret = ocfs2_append_rec_to_path(handle, et, insert_rec,
4288 right_path, &left_path);
4295 ret = ocfs2_insert_path(handle, et, left_path, right_path,
4302 out_update_clusters:
4304 ocfs2_et_update_clusters(et,
4324 u32 left_cpos, right_cpos;
4328 struct buffer_head *bh;
4333 rec = &el->
l_recs[index - 1];
4339 if (left_cpos != 0) {
4356 "Extent block #%llu has an "
4357 "invalid l_next_free_rec of "
4358 "%d. It should have "
4359 "matched the l_count of %d",
4376 if (index == 1 && ocfs2_is_empty_extent(rec)) {
4380 ret = ocfs2_et_extent_contig(et, rec, split_rec);
4386 rec = &el->
l_recs[index + 1];
4393 if (right_cpos == 0)
4405 rec = &new_el->
l_recs[0];
4406 if (ocfs2_is_empty_extent(rec)) {
4411 "Extent block #%llu has an "
4412 "invalid l_next_free_rec of %d",
4418 rec = &new_el->
l_recs[1];
4425 contig_type = ocfs2_et_extent_contig(et, rec, split_rec);
4453 contig_type = ocfs2_et_extent_contig(et, &el->
l_recs[i],
4501 goto set_tail_append;
4503 if (ocfs2_is_empty_extent(&el->
l_recs[0])) {
4506 goto set_tail_append;
4514 goto set_tail_append;
4536 struct buffer_head **last_eb_bh,
4545 struct buffer_head *bh =
NULL;
4560 ocfs2_et_get_last_eb_blk(et),
4582 ocfs2_figure_contig_type(et, insert, el, insert_rec);
4583 ocfs2_figure_appending_type(insert, el, insert_rec);
4616 ocfs2_figure_contig_type(et, insert, el, insert_rec);
4637 if (ocfs2_et_get_last_eb_blk(et) ==
4647 ocfs2_figure_appending_type(insert, el, insert_rec);
4675 struct buffer_head *last_eb_bh =
NULL;
4679 trace_ocfs2_insert_extent_start(
4681 cpos, new_clusters);
4683 memset(&rec, 0,
sizeof(rec));
4688 status = ocfs2_et_insert_check(et, &rec);
4694 status = ocfs2_figure_insert_type(et, &last_eb_bh, &rec,
4695 &free_records, &insert);
4706 status = ocfs2_grow_tree(handle, et,
4716 status = ocfs2_do_insert_extent(handle, et, &rec, &insert);
4720 ocfs2_et_extent_map_insert(et, &rec);
4737 u32 *logical_offset,
4738 u32 clusters_to_add,
4744 int status = 0,
err = 0;
4747 u32 bit_off, num_bits;
4753 BUG_ON(!clusters_to_add);
4759 if (free_extents < 0) {
4760 status = free_extents;
4770 if (!free_extents && !meta_ac) {
4775 }
else if ((!free_extents)
4776 && (ocfs2_alloc_context_bits_left(meta_ac)
4777 < ocfs2_extend_meta_needed(et->
et_root_el))) {
4785 clusters_to_add, &bit_off, &num_bits);
4792 BUG_ON(num_bits > clusters_to_add);
4795 status = ocfs2_et_root_journal_access(handle, et,
4802 block = ocfs2_clusters_to_blocks(osb->
sb, bit_off);
4803 trace_ocfs2_add_clusters_in_btree(
4807 num_bits, flags, meta_ac);
4815 clusters_to_add -= num_bits;
4816 *logical_offset += num_bits;
4818 if (clusters_to_add) {
4819 err = clusters_to_add;
4827 trace_ocfs2_add_clusters_in_btree_ret(status, reason,
err);
4831 static void ocfs2_make_right_split_rec(
struct super_block *sb,
4845 le64_add_cpu(&split_rec->
e_blkno,
4846 ocfs2_clusters_to_blocks(sb, cpos - rec_cpos));
4851 static int ocfs2_split_and_insert(handle_t *handle,
4854 struct buffer_head **last_eb_bh,
4860 unsigned int insert_range, rec_range, do_leftright = 0;
4881 rightmost_el = &eb->
h_list;
4886 ret = ocfs2_grow_tree(handle, et,
4887 &depth, last_eb_bh, meta_ac);
4906 }
else if (insert_range == rec_range) {
4916 &tmprec, insert_range, &rec);
4924 ret = ocfs2_do_insert_extent(handle, et, &split_rec, &insert);
4930 if (do_leftright == 1) {
4935 split_rec = *orig_split_rec;
4955 static int ocfs2_replace_extent_rec(handle_t *handle,
4971 el->
l_recs[split_index] = *split_rec;
5007 struct buffer_head *last_eb_bh =
NULL;
5020 ctxt.
c_contig_type = ocfs2_figure_merge_contig_type(et, path, el,
5033 ocfs2_et_get_last_eb_blk(et),
5041 rightmost_el = &eb->
h_list;
5059 ret = ocfs2_replace_extent_rec(handle, et, path, el,
5060 split_index, split_rec);
5062 ret = ocfs2_split_and_insert(handle, et, path,
5063 &last_eb_bh, split_index,
5064 split_rec, meta_ac);
5068 ret = ocfs2_try_to_merge_extent(handle, et, path,
5069 split_index, split_rec,
5097 int new_flags,
int clear_flags)
5101 u64 start_blkno = ocfs2_clusters_to_blocks(sb, phys);
5124 "Owner %llu has an extent at cpos %u which can no "
5125 "longer be found.\n",
5126 (
unsigned long long)
5134 if (new_flags && (rec->
e_flags & new_flags)) {
5135 mlog(
ML_ERROR,
"Owner %llu tried to set %d flags on an "
5136 "extent that already had them",
5142 if (clear_flags && !(rec->
e_flags & clear_flags)) {
5143 mlog(
ML_ERROR,
"Owner %llu tried to clear %d flags on an "
5144 "extent that didn't have them",
5156 split_rec.
e_flags |= new_flags;
5158 split_rec.
e_flags &= ~clear_flags;
5161 index, &split_rec, meta_ac,
5189 trace_ocfs2_mark_extent_written(
5190 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
5193 if (!ocfs2_writes_unwritten_extents(
OCFS2_SB(inode->
i_sb))) {
5195 "that are being written to, but the feature bit "
5196 "is not set in the super block.",
5197 (
unsigned long long)OCFS2_I(inode)->ip_blkno);
5206 ocfs2_et_extent_map_truncate(et, 0);
5209 len, phys, meta_ac, dealloc,
5220 int index,
u32 new_range,
5224 struct buffer_head *last_eb_bh =
NULL;
5235 rec = &el->l_recs[
index];
5237 &split_rec, new_range, rec);
5242 ocfs2_et_get_last_eb_blk(et),
5250 rightmost_el = &eb->
h_list;
5264 ret = ocfs2_grow_tree(handle, et, &depth, &last_eb_bh,
5278 ret = ocfs2_do_insert_extent(handle, et, &split_rec, &insert);
5294 u32 left_cpos, rec_range, trunc_range;
5295 int wants_rotate = 0, is_rightmost_tree_rec = 0;
5302 if (ocfs2_is_empty_extent(&el->
l_recs[0]) && index > 0) {
5303 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
5322 is_rightmost_tree_rec = 1;
5364 ret = ocfs2_extend_rotate_transaction(handle, 0,
5365 handle->h_buffer_credits,
5385 trunc_range = cpos + len;
5390 memset(rec, 0,
sizeof(*rec));
5391 ocfs2_cleanup_merge(el, index);
5395 if (is_rightmost_tree_rec && next_free > 1) {
5400 rec = &el->
l_recs[next_free - 1];
5401 ocfs2_adjust_rightmost_records(handle, et, path,
5406 le32_add_cpu(&rec->
e_cpos, len);
5407 le64_add_cpu(&rec->
e_blkno, ocfs2_clusters_to_blocks(sb, len));
5409 }
else if (rec_range == trunc_range) {
5412 if (is_rightmost_tree_rec)
5413 ocfs2_adjust_rightmost_records(handle, et, path, rec);
5416 mlog(
ML_ERROR,
"Owner %llu: Invalid record truncate: (%u, %u) "
5428 ocfs2_complete_edge_insert(handle, left_path, path,
5434 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
5452 u32 rec_range, trunc_range;
5461 ocfs2_et_extent_map_truncate(et, 0);
5480 "Owner %llu has an extent at cpos %u which can no "
5481 "longer be found.\n",
5506 trunc_range = cpos + len;
5510 trace_ocfs2_remove_extent(
5513 ocfs2_rec_clusters(el, rec));
5523 ret = ocfs2_split_tree(handle, et, path, index,
5524 trunc_range, meta_ac);
5546 "Owner %llu: split at cpos %u lost record.",
5559 ocfs2_rec_clusters(el, rec);
5560 if (rec_range != trunc_range) {
5562 "Owner %llu: error after split at cpos %u"
5563 "trunc len %u, existing record is (%u,%u)",
5566 ocfs2_rec_clusters(el, rec));
5593 static int ocfs2_reserve_blocks_for_rec_trunc(
struct inode *
inode,
5595 u32 extents_to_split,
5599 int ret = 0, num_free_extents;
5600 unsigned int max_recs_needed = 2 * extents_to_split;
5606 if (num_free_extents < 0) {
5607 ret = num_free_extents;
5612 if (!num_free_extents ||
5613 (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed))
5614 extra_blocks += ocfs2_extend_meta_needed(et->
et_root_el);
5642 int ret, credits = 0, extra_blocks = 0;
5643 u64 phys_blkno = ocfs2_clusters_to_blocks(inode->
i_sb, phys_cpos);
5651 BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
5673 ret = ocfs2_reserve_blocks_for_rec_trunc(inode, et, 1, &meta_ac,
5691 ocfs2_remove_extent_credits(osb->
sb) + credits);
5692 if (IS_ERR(handle)) {
5693 ret = PTR_ERR(handle);
5698 ret = ocfs2_et_root_journal_access(handle, et,
5705 dquot_free_space_nodirty(inode,
5706 ocfs2_clusters_to_bytes(inode->
i_sb, len));
5714 ocfs2_et_update_clusters(et, -len);
5719 if (flags & OCFS2_EXT_REFCOUNTED)
5721 ocfs2_blocks_to_clusters(osb->
sb,
5749 struct buffer_head *tl_bh = osb->
osb_tl_bh;
5757 "slot %d, invalid truncate log parameters: used = "
5764 unsigned int new_start)
5766 unsigned int tail_index;
5767 unsigned int current_tail;
5777 return current_tail == new_start;
5783 unsigned int num_clusters)
5786 unsigned int start_cluster, tl_count;
5788 struct buffer_head *tl_bh = osb->
osb_tl_bh;
5794 start_cluster = ocfs2_blocks_to_clusters(osb->
sb, start_blk);
5807 "Truncate record count on #%llu invalid "
5808 "wanted %u, actual %u\n",
5809 (
unsigned long long)OCFS2_I(tl_inode)->ip_blkno,
5810 ocfs2_truncate_recs_per_inode(osb->
sb),
5815 if (index >= tl_count) {
5828 trace_ocfs2_truncate_log_append(
5829 (
unsigned long long)OCFS2_I(tl_inode)->ip_blkno, index,
5830 start_cluster, num_clusters);
5831 if (ocfs2_truncate_log_can_coalesce(tl, start_cluster)) {
5839 trace_ocfs2_truncate_log_append(
5840 (
unsigned long long)OCFS2_I(tl_inode)->ip_blkno,
5856 static int ocfs2_replay_truncate_records(
struct ocfs2_super *osb,
5858 struct inode *data_alloc_inode,
5859 struct buffer_head *data_alloc_bh)
5863 unsigned int num_clusters;
5869 struct buffer_head *tl_bh = osb->
osb_tl_bh;
5899 start_blk = ocfs2_clusters_to_blocks(data_alloc_inode->
i_sb,
5906 trace_ocfs2_replay_truncate_records(
5907 (
unsigned long long)OCFS2_I(tl_inode)->ip_blkno,
5911 data_alloc_bh, start_blk,
5931 unsigned int num_to_flush;
5934 struct inode *data_alloc_inode =
NULL;
5935 struct buffer_head *tl_bh = osb->
osb_tl_bh;
5936 struct buffer_head *data_alloc_bh =
NULL;
5951 trace_ocfs2_flush_truncate_log(
5952 (
unsigned long long)OCFS2_I(tl_inode)->ip_blkno,
5954 if (!num_to_flush) {
5962 if (!data_alloc_inode) {
5977 if (IS_ERR(handle)) {
5978 status = PTR_ERR(handle);
5983 status = ocfs2_replay_truncate_records(osb, handle, data_alloc_inode,
5991 brelse(data_alloc_bh);
5996 iput(data_alloc_inode);
6028 #define OCFS2_TRUNCATE_LOG_FLUSH_INTERVAL (2 * HZ)
6043 static int ocfs2_get_truncate_log_info(
struct ocfs2_super *osb,
6045 struct inode **tl_inode,
6046 struct buffer_head **tl_bh)
6049 struct inode *inode =
NULL;
6050 struct buffer_head *bh =
NULL;
6057 mlog(
ML_ERROR,
"Could not get load truncate log inode!\n");
6083 struct inode *tl_inode =
NULL;
6084 struct buffer_head *tl_bh =
NULL;
6090 trace_ocfs2_begin_truncate_log_recovery(slot_num);
6092 status = ocfs2_get_truncate_log_info(osb, slot_num, &tl_inode, &tl_bh);
6118 memcpy(*tl_copy, tl_bh->b_data, tl_bh->b_size);
6137 if (status < 0 && (*tl_copy)) {
6151 unsigned int clusters, num_recs, start_cluster;
6158 mlog(
ML_ERROR,
"Asked to recover my own truncate log!\n");
6164 trace_ocfs2_complete_truncate_log_recovery(
6169 for(i = 0; i < num_recs; i++) {
6179 if (IS_ERR(handle)) {
6180 status = PTR_ERR(handle);
6187 start_blk = ocfs2_clusters_to_blocks(osb->
sb, start_cluster);
6190 start_blk, clusters);
6225 struct inode *tl_inode =
NULL;
6226 struct buffer_head *tl_bh =
NULL;
6228 status = ocfs2_get_truncate_log_info(osb,
6239 ocfs2_truncate_log_worker);
6284 static int ocfs2_free_cached_blocks(
struct ocfs2_super *osb,
6292 struct inode *
inode;
6293 struct buffer_head *di_bh =
NULL;
6312 if (IS_ERR(handle)) {
6313 ret = PTR_ERR(handle);
6322 bg_blkno = ocfs2_which_suballoc_group(head->
free_blk,
6324 trace_ocfs2_free_cached_blocks(
6366 u64 blkno,
unsigned int bit)
6371 item = kzalloc(
sizeof(*item),
GFP_NOFS);
6378 trace_ocfs2_cache_cluster_dealloc((
unsigned long long)blkno, bit);
6388 static int ocfs2_free_cached_clusters(
struct ocfs2_super *osb,
6408 if (IS_ERR(handle)) {
6409 ret = PTR_ERR(handle);
6455 ret2 = ocfs2_free_cached_blocks(osb,
6470 ret2 = ocfs2_free_cached_clusters(osb,
6484 ocfs2_find_per_slot_free_list(
int type,
6510 int type,
int slot,
u64 suballoc,
6511 u64 blkno,
unsigned int bit)
6517 fl = ocfs2_find_per_slot_free_list(type, slot, ctxt);
6524 item = kzalloc(
sizeof(*item),
GFP_NOFS);
6531 trace_ocfs2_cache_block_dealloc(type, slot,
6532 (
unsigned long long)suballoc,
6533 (
unsigned long long)blkno, bit);
6557 static int ocfs2_zero_func(handle_t *handle,
struct buffer_head *bh)
6559 set_buffer_uptodate(bh);
6565 unsigned int from,
unsigned int to,
6568 int ret, partial = 0;
6575 zero_user_segment(page, from, to);
6587 else if (ocfs2_should_order_data(inode)) {
6588 ret = ocfs2_jbd2_file_inode(handle, inode);
6594 SetPageUptodate(page);
6599 static void ocfs2_zero_cluster_pages(
struct inode *inode, loff_t start,
6601 int numpages,
u64 phys, handle_t *handle)
6614 for(i = 0; i < numpages; i++) {
6635 struct page **pages,
int *num)
6637 int numpages, ret = 0;
6639 unsigned long index;
6640 loff_t last_page_bytes;
6649 if (!pages[numpages]) {
6657 }
while (index < (last_page_bytes >> PAGE_CACHE_SHIFT));
6671 static int ocfs2_grab_eof_pages(
struct inode *inode, loff_t start, loff_t end,
6672 struct page **pages,
int *num)
6677 (end - 1) >>
OCFS2_SB(sb)->s_clustersize_bits);
6694 int ret = 0, numpages;
6695 struct page **pages =
NULL;
6704 if (!ocfs2_sparse_alloc(
OCFS2_SB(sb)))
6707 pages = kcalloc(ocfs2_pages_per_cluster(sb),
6709 if (pages ==
NULL) {
6715 if (range_start == range_end)
6720 &phys,
NULL, &ext_flags);
6733 ret = ocfs2_grab_eof_pages(inode, range_start, range_end, pages,
6740 ocfs2_zero_cluster_pages(inode, range_start, range_end, pages,
6741 numpages, phys, handle);
6760 static void ocfs2_zero_dinode_id2_with_xattr(
struct inode *inode,
6763 unsigned int blocksize = 1 << inode->
i_sb->s_blocksize_bits;
6778 ocfs2_zero_dinode_id2_with_xattr(inode, di);
6782 ocfs2_extent_recs_per_inode_with_xattr(inode->
i_sb, di));
6799 ocfs2_zero_dinode_id2_with_xattr(inode, di);
6802 ocfs2_max_inline_data_with_xattr(inode->
i_sb, di));
6806 struct buffer_head *di_bh)
6815 struct page **pages =
NULL;
6820 has_data = i_size_read(inode) ? 1 : 0;
6823 pages = kcalloc(ocfs2_pages_per_cluster(osb->
sb),
6825 if (pages ==
NULL) {
6839 ocfs2_inline_to_extents_credits(osb->
sb));
6840 if (IS_ERR(handle)) {
6841 ret = PTR_ERR(handle);
6855 unsigned int page_end;
6858 ret = dquot_alloc_space_nodirty(inode,
6859 ocfs2_clusters_to_bytes(osb->
sb, 1));
6864 data_ac->ac_resv = &OCFS2_I(inode)->ip_la_data_resv;
6877 block = phys = ocfs2_clusters_to_blocks(inode->
i_sb, bit_off);
6883 if (!ocfs2_sparse_alloc(osb) &&
6884 PAGE_CACHE_SIZE < osb->s_clustersize)
6887 ret = ocfs2_grab_eof_pages(inode, 0, end, pages, &num_pages);
6909 pages[i], i > 0, &phys);
6934 inode->
i_blocks = ocfs2_inode_sector_count(inode);
6938 if (ret < 0 && did_quota)
6939 dquot_free_space_nodirty(inode,
6940 ocfs2_clusters_to_bytes(osb->
sb, 1));
6964 struct inode *inode,
6965 struct buffer_head *di_bh)
6967 int status = 0,
i,
flags = 0;
6968 u32 new_highest_cpos,
range, trunc_cpos, trunc_len, phys_cpos, coff;
6980 ocfs2_init_dealloc_ctxt(&dealloc);
6982 new_highest_cpos = ocfs2_clusters_for_bytes(osb->
sb,
6983 i_size_read(inode));
6985 path = ocfs2_new_path(di_bh, &di->
id2.
i_list,
6999 if (OCFS2_I(inode)->ip_clusters == 0) {
7013 trace_ocfs2_commit_truncate(
7014 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
7016 OCFS2_I(inode)->ip_clusters,
7033 "Inode %llu has empty extent block at %llu\n",
7034 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
7045 if (i == 0 && ocfs2_is_empty_extent(rec)) {
7052 "extent record, depth %u\n", inode->
i_ino,
7065 trunc_len = ocfs2_rec_clusters(el, rec);
7067 }
else if (range > new_highest_cpos) {
7072 trunc_cpos = new_highest_cpos;
7073 trunc_len = range - new_highest_cpos;
7076 ocfs2_clusters_to_blocks(inode->
i_sb, coff);
7085 phys_cpos = ocfs2_blocks_to_clusters(inode->
i_sb, blkno);
7088 phys_cpos, trunc_len, flags, &dealloc,
7118 unsigned int start,
unsigned int end,
int trunc)
7121 unsigned int numbytes;
7127 if (end > i_size_read(inode))
7128 end = i_size_read(inode);
7134 !ocfs2_supports_inline_data(osb)) {
7136 "Inline data flags for inode %llu don't agree! "
7137 "Disk: 0x%x, Memory: 0x%x, Superblock: 0x%x\n",
7138 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
7140 OCFS2_I(inode)->ip_dyn_features,
7147 if (IS_ERR(handle)) {
7148 ret = PTR_ERR(handle);
7160 numbytes = end -
start;
7161 memset(idata->id_data + start, 0, numbytes);
7170 i_size_write(inode, start);
7174 inode->
i_blocks = ocfs2_inode_sector_count(inode);
7189 static int ocfs2_trim_extent(
struct super_block *sb,
7195 bcount = ocfs2_clusters_to_blocks(sb, count);
7197 ocfs2_clusters_to_blocks(sb, start);
7199 trace_ocfs2_trim_extent(sb, (
unsigned long long)discard, bcount);
7201 return sb_issue_discard(sb, discard, bcount,
GFP_NOFS, 0);
7204 static int ocfs2_trim_group(
struct super_block *sb,
7208 int ret = 0, count = 0,
next;
7215 start, max, minbits);
7217 while (start < max) {
7223 if ((
next - start) >= minbits) {
7224 ret = ocfs2_trim_extent(sb, gd,
7225 start,
next - start);
7234 if (fatal_signal_pending(
current)) {
7254 u32 first_bit, last_bit, minlen;
7255 struct buffer_head *main_bm_bh =
NULL;
7256 struct inode *main_bm_inode =
NULL;
7257 struct buffer_head *gd_bh =
NULL;
7277 if (!main_bm_inode) {
7300 trace_ocfs2_trim_fs(start, len, minlen);
7307 first_bit = start - ocfs2_blocks_to_clusters(sb, first_group);
7311 for (group = first_group; group <= last_group;) {
7315 last_bit = first_bit + len;
7326 cnt = ocfs2_trim_group(sb, gd, first_bit, last_bit, minlen);
7339 group = ocfs2_clusters_to_blocks(sb, osb->
bitmap_cpg);
7341 group += ocfs2_clusters_to_blocks(sb, osb->
bitmap_cpg);
7349 iput(main_bm_inode);