X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lib%2Fext2fs%2Fblkmap64_rb.c;h=6fc245fda08eb5711aa3ae52e20aeda8a3ce5262;hb=055866d84dab5e4a0547f54d3bdc017ba4ba99b5;hp=a484751081d87678404dfc1b79f0904c64289db1;hpb=4d46e6c737947b336fd412f43c060955b07bd319;p=tools%2Fe2fsprogs.git diff --git a/lib/ext2fs/blkmap64_rb.c b/lib/ext2fs/blkmap64_rb.c index a484751..6fc245f 100644 --- a/lib/ext2fs/blkmap64_rb.c +++ b/lib/ext2fs/blkmap64_rb.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -41,7 +42,7 @@ struct ext2fs_rb_private { struct bmap_rb_extent *wcursor; struct bmap_rb_extent *rcursor; struct bmap_rb_extent *rcursor_next; -#ifdef BMAP_STATS_OPS +#ifdef ENABLE_BMAP_STATS_OPS __u64 mark_hit; __u64 test_hit; #endif @@ -83,7 +84,7 @@ static void print_tree(struct rb_root *root) static void check_tree(struct rb_root *root, const char *msg) { - struct rb_node *new_node, *node, *next; + struct rb_node *node; struct bmap_rb_extent *ext, *old = NULL; for (node = ext2fs_rb_first(root); node; @@ -146,10 +147,8 @@ static void rb_get_new_extent(struct bmap_rb_extent **ext, __u64 start, retval = ext2fs_get_mem(sizeof (struct bmap_rb_extent), &new_ext); - if (retval) { - perror("ext2fs_get_mem"); - exit(1); - } + if (retval) + abort(); new_ext->start = start; new_ext->count = count; @@ -183,7 +182,7 @@ static errcode_t rb_alloc_private_data (ext2fs_generic_bitmap bitmap) bp->rcursor_next = NULL; bp->wcursor = NULL; -#ifdef BMAP_STATS_OPS +#ifdef ENABLE_BMAP_STATS_OPS bp->test_hit = 0; bp->mark_hit = 0; #endif @@ -299,21 +298,19 @@ static errcode_t rb_resize_bmap(ext2fs_generic_bitmap bmap, { struct ext2fs_rb_private *bp; - if (new_real_end >= bmap->real_end) { - bmap->end = new_end; - bmap->real_end = new_real_end; - return 0; - } - bp = (struct ext2fs_rb_private *) bmap->private; bp->rcursor = NULL; bp->wcursor = NULL; - /* truncate tree to new_real_end size */ - rb_truncate(new_real_end, &bp->root); + rb_truncate(((new_end < bmap->end) ? new_end : bmap->end) - bmap->start, + &bp->root); bmap->end = new_end; bmap->real_end = new_real_end; + + if (bmap->end < bmap->real_end) + rb_insert_extent(bmap->end + 1 - bmap->start, + bmap->real_end - bmap->end, bp); return 0; } @@ -331,7 +328,7 @@ rb_test_bit(struct ext2fs_rb_private *bp, __u64 bit) goto search_tree; if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) { -#ifdef BMAP_STATS_OPS +#ifdef ENABLE_BMAP_STATS_OPS bp->test_hit++; #endif return 1; @@ -396,7 +393,7 @@ static int rb_insert_extent(__u64 start, __u64 count, if (ext) { if (start >= ext->start && start <= (ext->start + ext->count)) { -#ifdef BMAP_STATS_OPS +#ifdef ENABLE_BMAP_STATS_OPS bp->mark_hit++; #endif goto got_extent; @@ -492,7 +489,7 @@ static int rb_remove_extent(__u64 start, __u64 count, __u64 new_start, new_count; int retval = 0; - if (EXT2FS_RB_EMPTY_ROOT(root)) + if (ext2fs_rb_empty_root(root)) return 0; while (*n) { @@ -555,7 +552,7 @@ static int rb_remove_extent(__u64 start, __u64 count, retval = 1; continue; } else { - /* modify the last extent in reigon to be removed */ + /* modify the last extent in region to be removed */ ext->count -= ((start + count) - ext->start); ext->start = start + count; retval = 1; @@ -641,7 +638,7 @@ static int rb_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap, n = &bp->root.rb_node; start -= bitmap->start; - if ((len == 0) || EXT2FS_RB_EMPTY_ROOT(&bp->root)) + if (len == 0 || ext2fs_rb_empty_root(&bp->root)) return 1; /* @@ -737,14 +734,13 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, struct rb_node *parent = NULL, *next, **n; struct ext2fs_rb_private *bp; struct bmap_rb_extent *ext; - int count; - __u64 pos; + __u64 count, pos; bp = (struct ext2fs_rb_private *) bitmap->private; n = &bp->root.rb_node; start -= bitmap->start; - if (EXT2FS_RB_EMPTY_ROOT(&bp->root)) + if (ext2fs_rb_empty_root(&bp->root)) return 0; while (*n) { @@ -769,9 +765,9 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, if (pos >= start + num) break; if (pos < start) { - count -= start - pos; - if (count < 0) + if (pos + count < start) continue; + count -= start - pos; pos = start; } if (pos + count > start + num) @@ -813,10 +809,8 @@ static errcode_t rb_find_first_zero(ext2fs_generic_bitmap bitmap, __u64 start, __u64 end, __u64 *out) { struct rb_node *parent = NULL, **n; - struct rb_node *node, *next; struct ext2fs_rb_private *bp; struct bmap_rb_extent *ext; - int retval = 1; bp = (struct ext2fs_rb_private *) bitmap->private; n = &bp->root.rb_node; @@ -826,7 +820,7 @@ static errcode_t rb_find_first_zero(ext2fs_generic_bitmap bitmap, if (start > end) return EINVAL; - if (EXT2FS_RB_EMPTY_ROOT(&bp->root)) + if (ext2fs_rb_empty_root(&bp->root)) return ENOENT; while (*n) { @@ -851,10 +845,9 @@ static errcode_t rb_find_first_set(ext2fs_generic_bitmap bitmap, __u64 start, __u64 end, __u64 *out) { struct rb_node *parent = NULL, **n; - struct rb_node *node, *next; + struct rb_node *node; struct ext2fs_rb_private *bp; struct bmap_rb_extent *ext; - int retval = 1; bp = (struct ext2fs_rb_private *) bitmap->private; n = &bp->root.rb_node; @@ -864,7 +857,7 @@ static errcode_t rb_find_first_set(ext2fs_generic_bitmap bitmap, if (start > end) return EINVAL; - if (EXT2FS_RB_EMPTY_ROOT(&bp->root)) + if (ext2fs_rb_empty_root(&bp->root)) return ENOENT; while (*n) { @@ -896,7 +889,7 @@ static errcode_t rb_find_first_set(ext2fs_generic_bitmap bitmap, return ENOENT; } -#ifdef BMAP_STATS +#ifdef ENABLE_BMAP_STATS static void rb_print_stats(ext2fs_generic_bitmap bitmap) { struct ext2fs_rb_private *bp; @@ -907,7 +900,7 @@ static void rb_print_stats(ext2fs_generic_bitmap bitmap) __u64 min_size = ULONG_MAX; __u64 size = 0, avg_size = 0; double eff; -#ifdef BMAP_STATS_OPS +#ifdef ENABLE_BMAP_STATS_OPS __u64 mark_all, test_all; double m_hit = 0.0, t_hit = 0.0; #endif @@ -931,7 +924,7 @@ static void rb_print_stats(ext2fs_generic_bitmap bitmap) min_size = 0; eff = (double)((count * sizeof(struct bmap_rb_extent)) << 3) / (bitmap->real_end - bitmap->start); -#ifdef BMAP_STATS_OPS +#ifdef ENABLE_BMAP_STATS_OPS mark_all = bitmap->stats.mark_count + bitmap->stats.mark_ext_count; test_all = bitmap->stats.test_count + bitmap->stats.test_ext_count; if (mark_all) @@ -958,7 +951,9 @@ static void rb_print_stats(ext2fs_generic_bitmap bitmap) eff); } #else -static void rb_print_stats(ext2fs_generic_bitmap bitmap){} +static void rb_print_stats(ext2fs_generic_bitmap bitmap EXT2FS_ATTR((unused))) +{ +} #endif struct ext2_bitmap_ops ext2fs_blkmap64_rbtree = {