mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-28 09:02:19 +00:00
btrfs-progs: convert: move make_convert_data_block_groups
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
65eca20739
commit
c4c17f4c52
100
btrfs-convert.c
100
btrfs-convert.c
@ -1187,6 +1187,56 @@ static int create_subvol(struct btrfs_trans_handle *trans,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* New make_btrfs() has handle system and meta chunks quite well.
|
||||
* So only need to add remaining data chunks.
|
||||
*/
|
||||
static int make_convert_data_block_groups(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_mkfs_config *cfg,
|
||||
struct btrfs_convert_context *cctx)
|
||||
{
|
||||
struct btrfs_root *extent_root = fs_info->extent_root;
|
||||
struct cache_tree *data_chunks = &cctx->data_chunks;
|
||||
struct cache_extent *cache;
|
||||
u64 max_chunk_size;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* Don't create data chunk over 10% of the convert device
|
||||
* And for single chunk, don't create chunk larger than 1G.
|
||||
*/
|
||||
max_chunk_size = cfg->num_bytes / 10;
|
||||
max_chunk_size = min((u64)(1024 * 1024 * 1024), max_chunk_size);
|
||||
max_chunk_size = round_down(max_chunk_size, extent_root->sectorsize);
|
||||
|
||||
for (cache = first_cache_extent(data_chunks); cache;
|
||||
cache = next_cache_extent(cache)) {
|
||||
u64 cur = cache->start;
|
||||
|
||||
while (cur < cache->start + cache->size) {
|
||||
u64 len;
|
||||
u64 cur_backup = cur;
|
||||
|
||||
len = min(max_chunk_size,
|
||||
cache->start + cache->size - cur);
|
||||
ret = btrfs_alloc_data_chunk(trans, extent_root,
|
||||
&cur_backup, len,
|
||||
BTRFS_BLOCK_GROUP_DATA, 1);
|
||||
if (ret < 0)
|
||||
break;
|
||||
ret = btrfs_make_block_group(trans, extent_root, 0,
|
||||
BTRFS_BLOCK_GROUP_DATA,
|
||||
BTRFS_FIRST_CHUNK_TREE_OBJECTID,
|
||||
cur, len);
|
||||
if (ret < 0)
|
||||
break;
|
||||
cur += len;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open Ext2fs in readonly mode, read block allocation bitmap and
|
||||
* inode bitmap into memory.
|
||||
@ -2036,56 +2086,6 @@ static int ext2_copy_inodes(struct btrfs_convert_context *cctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* New make_btrfs() has handle system and meta chunks quite well.
|
||||
* So only need to add remaining data chunks.
|
||||
*/
|
||||
static int make_convert_data_block_groups(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_mkfs_config *cfg,
|
||||
struct btrfs_convert_context *cctx)
|
||||
{
|
||||
struct btrfs_root *extent_root = fs_info->extent_root;
|
||||
struct cache_tree *data_chunks = &cctx->data_chunks;
|
||||
struct cache_extent *cache;
|
||||
u64 max_chunk_size;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* Don't create data chunk over 10% of the convert device
|
||||
* And for single chunk, don't create chunk larger than 1G.
|
||||
*/
|
||||
max_chunk_size = cfg->num_bytes / 10;
|
||||
max_chunk_size = min((u64)(1024 * 1024 * 1024), max_chunk_size);
|
||||
max_chunk_size = round_down(max_chunk_size, extent_root->sectorsize);
|
||||
|
||||
for (cache = first_cache_extent(data_chunks); cache;
|
||||
cache = next_cache_extent(cache)) {
|
||||
u64 cur = cache->start;
|
||||
|
||||
while (cur < cache->start + cache->size) {
|
||||
u64 len;
|
||||
u64 cur_backup = cur;
|
||||
|
||||
len = min(max_chunk_size,
|
||||
cache->start + cache->size - cur);
|
||||
ret = btrfs_alloc_data_chunk(trans, extent_root,
|
||||
&cur_backup, len,
|
||||
BTRFS_BLOCK_GROUP_DATA, 1);
|
||||
if (ret < 0)
|
||||
break;
|
||||
ret = btrfs_make_block_group(trans, extent_root, 0,
|
||||
BTRFS_BLOCK_GROUP_DATA,
|
||||
BTRFS_FIRST_CHUNK_TREE_OBJECTID,
|
||||
cur, len);
|
||||
if (ret < 0)
|
||||
break;
|
||||
cur += len;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Init the temp btrfs to a operational status.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user