aboutsummaryrefslogtreecommitdiffstats
path: root/btrfs-image.c
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-09-09 21:32:21 +0800
committerDavid Sterba <dsterba@suse.com>2015-09-11 17:00:10 +0200
commit50ef0322b4aecf8c5ea8031aa4f022619d255f10 (patch)
treedc0f23dff3e3929235d2a6a0c13192edc90509ff /btrfs-image.c
parent73a894e51e5bcea9fddc4f3ded37d0ad81456e92 (diff)
downloadbtrfs-progs-50ef0322b4aecf8c5ea8031aa4f022619d255f10.tar.gz
btrfs-progs-50ef0322b4aecf8c5ea8031aa4f022619d255f10.tar.xz
btrfs-progs-50ef0322b4aecf8c5ea8031aa4f022619d255f10.zip
btrfs-progs: image: fix infinite looping with -t 0
Bug: # btrfs-image -t0 -c9 /dev/sda6 /tmp/btrfs_image.img (hang) # btrfs-image -r -t0 /tmp/btrfs_image.img /dev/sda6 (hang) Reason: The program need to create at least 1 thread for compression/decompression. If the user specifies -t0, it overwrites the default value of 1, then the program really creates 0 thread, and ends up looping Fix: We can add a check, to make the program not to allow -t0 argument, but there is another problem: For example, on a node with 4 cpus: btrfs-image -c9 -t1: 4 threads (1 means use NR_CPUS) -c9 -t2: 2 threads -c9 -t3: 3 threads ... (-t1 has more threads than -t2 and -t3) So we change to use value of 0 as "use NR_CPUS threads", then: btrfs-image [no -t arg]: use NR_CPUS threads -t0: use NR_CPUS threads -t val: use val threads. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-image.c')
-rw-r--r--btrfs-image.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/btrfs-image.c b/btrfs-image.c
index 630fdf8..6eddbd5 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2690,7 +2690,7 @@ int main(int argc, char *argv[])
{
char *source;
char *target;
- u64 num_threads = 1;
+ u64 num_threads = 0;
u64 compress_level = 0;
int create = 1;
int old_restore = 0;
@@ -2786,7 +2786,8 @@ int main(int argc, char *argv[])
}
}
- if (num_threads == 1 && compress_level > 0) {
+ if ((compress_level > 0 || create == 0) &&
+ num_threads == 0) {
num_threads = sysconf(_SC_NPROCESSORS_ONLN);
if (num_threads <= 0)
num_threads = 1;