summaryrefslogtreecommitdiff
path: root/btrfs-image.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fb.com>2015-02-06 14:40:45 -0500
committerJosef Bacik <jbacik@fb.com>2015-02-09 14:53:15 -0500
commitc7e3b63b7e231ed1d9a47ca735a7ead112b47078 (patch)
tree466ebb398d8679c843d97481610806501ffd8091 /btrfs-image.c
parent32bb725f667a5c26f208f0717cb91716523d88f9 (diff)
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 <jbacik@fb.com>
Diffstat (limited to 'btrfs-image.c')
-rw-r--r--btrfs-image.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/btrfs-image.c b/btrfs-image.c
index aaff26d3..ea855425 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) {