From: Josef Bacik Date: Fri, 6 Feb 2015 19:40:45 +0000 (-0500) Subject: Btrfs-progs: multi-thread btrfs-image restore X-Git-Tag: upstream/4.16.1~2372^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c7e3b63b7e231ed1d9a47ca735a7ead112b47078;p=platform%2Fupstream%2Fbtrfs-progs.git Btrfs-progs: multi-thread btrfs-image restore For some reason we only allow btrfs-image restore to have one thread, which is incredibly slow with large images. So allow us to do work with more than just one thread. This made my restore go from 16 minutes to 3 minutes. Thanks, Signed-off-by: Josef Bacik --- diff --git a/btrfs-image.c b/btrfs-image.c index aaff26d..ea85542 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -1922,7 +1922,6 @@ static int add_cluster(struct meta_cluster *cluster, u32 i, nritems; int ret; - BUG_ON(mdres->num_items); mdres->compress_method = header->compress; bytenr = le64_to_cpu(header->bytenr) + BLOCK_SIZE; @@ -2433,7 +2432,7 @@ static int __restore_metadump(const char *input, FILE *out, int old_restore, goto out; } - while (1) { + while (!mdrestore.error) { ret = fread(cluster, BLOCK_SIZE, 1, in); if (!ret) break; @@ -2450,14 +2449,8 @@ static int __restore_metadump(const char *input, FILE *out, int old_restore, fprintf(stderr, "Error adding cluster\n"); break; } - - ret = wait_for_worker(&mdrestore); - if (ret) { - fprintf(stderr, "One of the threads errored out %d\n", - ret); - break; - } } + ret = wait_for_worker(&mdrestore); out: mdrestore_destroy(&mdrestore, num_threads); failed_cluster: @@ -2598,7 +2591,7 @@ int main(int argc, char *argv[]) { char *source; char *target; - u64 num_threads = 0; + u64 num_threads = 1; u64 compress_level = 0; int create = 1; int old_restore = 0; @@ -2689,7 +2682,7 @@ int main(int argc, char *argv[]) } } - if (num_threads == 0 && compress_level > 0) { + if (num_threads == 1 && compress_level > 0) { num_threads = sysconf(_SC_NPROCESSORS_ONLN); if (num_threads <= 0) num_threads = 1; @@ -2708,7 +2701,7 @@ int main(int argc, char *argv[]) ret = create_metadump(source, out, num_threads, compress_level, sanitize, walk_trees); } else { - ret = restore_metadump(source, out, old_restore, 1, + ret = restore_metadump(source, out, old_restore, num_threads, multi_devices); } if (ret) {