mirror of
https://github.com/kdave/btrfs-progs
synced 2025-03-24 03:46:39 +00:00
btrfs-progs: image: reorder initialization in metadump_init
Put the allocations first, move pthread cond and mutex last so we don't have to do cleanup. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
575ca96425
commit
5b81b9366f
@ -733,38 +733,32 @@ static int metadump_init(struct metadump_struct *md, struct btrfs_root *root,
|
|||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
|
|
||||||
memset(md, 0, sizeof(*md));
|
memset(md, 0, sizeof(*md));
|
||||||
pthread_cond_init(&md->cond, NULL);
|
md->cluster = calloc(1, BLOCK_SIZE);
|
||||||
pthread_mutex_init(&md->mutex, NULL);
|
if (!md->cluster)
|
||||||
|
return -ENOMEM;
|
||||||
|
md->threads = calloc(num_threads, sizeof(pthread_t));
|
||||||
|
if (!md->threads) {
|
||||||
|
free(md->cluster);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
INIT_LIST_HEAD(&md->list);
|
INIT_LIST_HEAD(&md->list);
|
||||||
INIT_LIST_HEAD(&md->ordered);
|
INIT_LIST_HEAD(&md->ordered);
|
||||||
md->root = root;
|
md->root = root;
|
||||||
md->out = out;
|
md->out = out;
|
||||||
md->pending_start = (u64)-1;
|
md->pending_start = (u64)-1;
|
||||||
md->compress_level = compress_level;
|
md->compress_level = compress_level;
|
||||||
md->cluster = calloc(1, BLOCK_SIZE);
|
|
||||||
md->sanitize_names = sanitize_names;
|
md->sanitize_names = sanitize_names;
|
||||||
if (sanitize_names > 1)
|
if (sanitize_names > 1)
|
||||||
crc32c_optimization_init();
|
crc32c_optimization_init();
|
||||||
|
|
||||||
if (!md->cluster) {
|
|
||||||
pthread_cond_destroy(&md->cond);
|
|
||||||
pthread_mutex_destroy(&md->mutex);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
meta_cluster_init(md, 0);
|
|
||||||
if (!num_threads)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
md->name_tree.rb_node = NULL;
|
md->name_tree.rb_node = NULL;
|
||||||
md->num_threads = num_threads;
|
md->num_threads = num_threads;
|
||||||
md->threads = calloc(num_threads, sizeof(pthread_t));
|
pthread_cond_init(&md->cond, NULL);
|
||||||
if (!md->threads) {
|
pthread_mutex_init(&md->mutex, NULL);
|
||||||
free(md->cluster);
|
meta_cluster_init(md, 0);
|
||||||
pthread_cond_destroy(&md->cond);
|
|
||||||
pthread_mutex_destroy(&md->mutex);
|
if (!num_threads)
|
||||||
return -ENOMEM;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num_threads; i++) {
|
for (i = 0; i < num_threads; i++) {
|
||||||
ret = pthread_create(md->threads + i, NULL, dump_worker, md);
|
ret = pthread_create(md->threads + i, NULL, dump_worker, md);
|
||||||
|
Loading…
Reference in New Issue
Block a user