summaryrefslogtreecommitdiff
path: root/btrfs-convert.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-08-23 17:44:03 +0200
committerDavid Sterba <dsterba@suse.com>2016-08-24 14:37:36 +0200
commit1a7ee0c2969877ed5fc4cd93fe049b2aab3b636a (patch)
tree5799f0fd7cca5f02cca4a09ef2dd65749e407d83 /btrfs-convert.c
parent0e4cabc479455a2047ee8a76ca7e23b5be995013 (diff)
btrfs-progs: convert: move _expand_extent_cache
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-convert.c')
-rw-r--r--btrfs-convert.c102
1 files changed, 51 insertions, 51 deletions
diff --git a/btrfs-convert.c b/btrfs-convert.c
index 1c6d02c0..e80ea3b2 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.c
@@ -655,6 +655,57 @@ static int migrate_reserved_ranges(struct btrfs_trans_handle *trans,
}
/*
+ * Helper for expand and merge extent_cache for wipe_one_reserved_range() to
+ * handle wiping a range that exists in cache.
+ */
+static int _expand_extent_cache(struct cache_tree *tree,
+ struct cache_extent *entry,
+ u64 min_stripe_size, int backward)
+{
+ struct cache_extent *ce;
+ int diff;
+
+ if (entry->size >= min_stripe_size)
+ return 0;
+ diff = min_stripe_size - entry->size;
+
+ if (backward) {
+ ce = prev_cache_extent(entry);
+ if (!ce)
+ goto expand_back;
+ if (ce->start + ce->size >= entry->start - diff) {
+ /* Directly merge with previous extent */
+ ce->size = entry->start + entry->size - ce->start;
+ remove_cache_extent(tree, entry);
+ free(entry);
+ return 0;
+ }
+expand_back:
+ /* No overlap, normal extent */
+ if (entry->start < diff) {
+ error("cannot find space for data chunk layout");
+ return -ENOSPC;
+ }
+ entry->start -= diff;
+ entry->size += diff;
+ return 0;
+ }
+ ce = next_cache_extent(entry);
+ if (!ce)
+ goto expand_after;
+ if (entry->start + entry->size + diff >= ce->start) {
+ /* Directly merge with next extent */
+ entry->size = ce->start + ce->size - entry->start;
+ remove_cache_extent(tree, ce);
+ free(ce);
+ return 0;
+ }
+expand_after:
+ entry->size += diff;
+ return 0;
+}
+
+/*
* Open Ext2fs in readonly mode, read block allocation bitmap and
* inode bitmap into memory.
*/
@@ -1996,57 +2047,6 @@ static int convert_open_fs(const char *devname,
}
/*
- * Helper for expand and merge extent_cache for wipe_one_reserved_range() to
- * handle wiping a range that exists in cache.
- */
-static int _expand_extent_cache(struct cache_tree *tree,
- struct cache_extent *entry,
- u64 min_stripe_size, int backward)
-{
- struct cache_extent *ce;
- int diff;
-
- if (entry->size >= min_stripe_size)
- return 0;
- diff = min_stripe_size - entry->size;
-
- if (backward) {
- ce = prev_cache_extent(entry);
- if (!ce)
- goto expand_back;
- if (ce->start + ce->size >= entry->start - diff) {
- /* Directly merge with previous extent */
- ce->size = entry->start + entry->size - ce->start;
- remove_cache_extent(tree, entry);
- free(entry);
- return 0;
- }
-expand_back:
- /* No overlap, normal extent */
- if (entry->start < diff) {
- error("cannot find space for data chunk layout");
- return -ENOSPC;
- }
- entry->start -= diff;
- entry->size += diff;
- return 0;
- }
- ce = next_cache_extent(entry);
- if (!ce)
- goto expand_after;
- if (entry->start + entry->size + diff >= ce->start) {
- /* Directly merge with next extent */
- entry->size = ce->start + ce->size - entry->start;
- remove_cache_extent(tree, ce);
- free(ce);
- return 0;
- }
-expand_after:
- entry->size += diff;
- return 0;
-}
-
-/*
* Remove one reserve range from given cache tree
* if min_stripe_size is non-zero, it will ensure for split case,
* all its split cache extent is no smaller than @min_strip_size / 2.