diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/selftests/breakpoints/Makefile | 16 | ||||
-rw-r--r-- | tools/testing/selftests/lib.mk | 13 | ||||
-rw-r--r-- | tools/testing/selftests/zram/Makefile | 9 | ||||
-rw-r--r-- | tools/testing/selftests/zram/README | 40 | ||||
-rwxr-xr-x | tools/testing/selftests/zram/zram.sh | 35 | ||||
-rwxr-xr-x | tools/testing/selftests/zram/zram01.sh | 99 | ||||
-rwxr-xr-x | tools/testing/selftests/zram/zram02.sh | 54 | ||||
-rwxr-xr-x | tools/testing/selftests/zram/zram_lib.sh | 232 |
9 files changed, 481 insertions, 19 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index b8f12e0897e6..050151144596 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile | |||
@@ -23,6 +23,7 @@ TARGETS += user | |||
23 | TARGETS += jumplabel | 23 | TARGETS += jumplabel |
24 | TARGETS += vm | 24 | TARGETS += vm |
25 | TARGETS += x86 | 25 | TARGETS += x86 |
26 | TARGETS += zram | ||
26 | #Please keep the TARGETS list alphabetically sorted | 27 | #Please keep the TARGETS list alphabetically sorted |
27 | # Run "make quicktest=1 run_tests" or | 28 | # Run "make quicktest=1 run_tests" or |
28 | # "make quicktest=1 kselftest from top level Makefile | 29 | # "make quicktest=1 kselftest from top level Makefile |
@@ -72,7 +73,6 @@ ifdef INSTALL_PATH | |||
72 | @# Ask all targets to install their files | 73 | @# Ask all targets to install their files |
73 | mkdir -p $(INSTALL_PATH) | 74 | mkdir -p $(INSTALL_PATH) |
74 | for TARGET in $(TARGETS); do \ | 75 | for TARGET in $(TARGETS); do \ |
75 | mkdir -p $(INSTALL_PATH)/$$TARGET ; \ | ||
76 | make -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ | 76 | make -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ |
77 | done; | 77 | done; |
78 | 78 | ||
diff --git a/tools/testing/selftests/breakpoints/Makefile b/tools/testing/selftests/breakpoints/Makefile index 182235640209..d27108b4f208 100644 --- a/tools/testing/selftests/breakpoints/Makefile +++ b/tools/testing/selftests/breakpoints/Makefile | |||
@@ -1,22 +1,12 @@ | |||
1 | # Taken from perf makefile | 1 | # Taken from perf makefile |
2 | uname_M := $(shell uname -m 2>/dev/null || echo not) | 2 | uname_M := $(shell uname -m 2>/dev/null || echo not) |
3 | ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) | 3 | ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) |
4 | ifeq ($(ARCH),i386) | ||
5 | ARCH := x86 | ||
6 | endif | ||
7 | ifeq ($(ARCH),x86_64) | ||
8 | ARCH := x86 | ||
9 | endif | ||
10 | 4 | ||
11 | |||
12 | all: | ||
13 | ifeq ($(ARCH),x86) | 5 | ifeq ($(ARCH),x86) |
14 | gcc breakpoint_test.c -o breakpoint_test | 6 | TEST_PROGS := breakpoint_test |
15 | else | ||
16 | echo "Not an x86 target, can't build breakpoints selftests" | ||
17 | endif | 7 | endif |
18 | 8 | ||
19 | TEST_PROGS := breakpoint_test | 9 | all: |
20 | 10 | ||
21 | include ../lib.mk | 11 | include ../lib.mk |
22 | 12 | ||
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index ee412bab7ed4..97f1c6742066 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk | |||
@@ -12,11 +12,14 @@ run_tests: all | |||
12 | $(RUN_TESTS) | 12 | $(RUN_TESTS) |
13 | 13 | ||
14 | define INSTALL_RULE | 14 | define INSTALL_RULE |
15 | mkdir -p $(INSTALL_PATH) | 15 | @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ |
16 | @for TEST_DIR in $(TEST_DIRS); do\ | 16 | mkdir -p $(INSTALL_PATH); \ |
17 | cp -r $$TEST_DIR $(INSTALL_PATH); \ | 17 | for TEST_DIR in $(TEST_DIRS); do \ |
18 | done; | 18 | cp -r $$TEST_DIR $(INSTALL_PATH); \ |
19 | install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) | 19 | done; \ |
20 | echo "install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)"; \ | ||
21 | install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES); \ | ||
22 | fi | ||
20 | endef | 23 | endef |
21 | 24 | ||
22 | install: all | 25 | install: all |
diff --git a/tools/testing/selftests/zram/Makefile b/tools/testing/selftests/zram/Makefile new file mode 100644 index 000000000000..29d80346e3eb --- /dev/null +++ b/tools/testing/selftests/zram/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | all: | ||
2 | |||
3 | TEST_PROGS := zram.sh | ||
4 | TEST_FILES := zram01.sh zram02.sh zram_lib.sh | ||
5 | |||
6 | include ../lib.mk | ||
7 | |||
8 | clean: | ||
9 | $(RM) err.log | ||
diff --git a/tools/testing/selftests/zram/README b/tools/testing/selftests/zram/README new file mode 100644 index 000000000000..eb17917c8a3a --- /dev/null +++ b/tools/testing/selftests/zram/README | |||
@@ -0,0 +1,40 @@ | |||
1 | zram: Compressed RAM based block devices | ||
2 | ---------------------------------------- | ||
3 | * Introduction | ||
4 | |||
5 | The zram module creates RAM based block devices named /dev/zram<id> | ||
6 | (<id> = 0, 1, ...). Pages written to these disks are compressed and stored | ||
7 | in memory itself. These disks allow very fast I/O and compression provides | ||
8 | good amounts of memory savings. Some of the usecases include /tmp storage, | ||
9 | use as swap disks, various caches under /var and maybe many more :) | ||
10 | |||
11 | Statistics for individual zram devices are exported through sysfs nodes at | ||
12 | /sys/block/zram<id>/ | ||
13 | |||
14 | Kconfig required: | ||
15 | CONFIG_ZRAM=y | ||
16 | CONFIG_ZRAM_LZ4_COMPRESS=y | ||
17 | CONFIG_ZPOOL=y | ||
18 | CONFIG_ZSMALLOC=y | ||
19 | |||
20 | ZRAM Testcases | ||
21 | -------------- | ||
22 | zram_lib.sh: create library with initialization/cleanup functions | ||
23 | zram.sh: For sanity check of CONFIG_ZRAM and to run zram01 and zram02 | ||
24 | |||
25 | Two functional tests: zram01 and zram02: | ||
26 | zram01.sh: creates general purpose ram disks with ext4 filesystems | ||
27 | zram02.sh: creates block device for swap | ||
28 | |||
29 | Commands required for testing: | ||
30 | - bc | ||
31 | - dd | ||
32 | - free | ||
33 | - awk | ||
34 | - mkswap | ||
35 | - swapon | ||
36 | - swapoff | ||
37 | - mkfs/ mkfs.ext4 | ||
38 | |||
39 | For more information please refer: | ||
40 | kernel-source-tree/Documentation/blockdev/zram.txt | ||
diff --git a/tools/testing/selftests/zram/zram.sh b/tools/testing/selftests/zram/zram.sh new file mode 100755 index 000000000000..20de9a761269 --- /dev/null +++ b/tools/testing/selftests/zram/zram.sh | |||
@@ -0,0 +1,35 @@ | |||
1 | #!/bin/bash | ||
2 | TCID="zram.sh" | ||
3 | |||
4 | check_prereqs() | ||
5 | { | ||
6 | local msg="skip all tests:" | ||
7 | |||
8 | if [ $UID != 0 ]; then | ||
9 | echo $msg must be run as root >&2 | ||
10 | exit 0 | ||
11 | fi | ||
12 | } | ||
13 | |||
14 | run_zram () { | ||
15 | echo "--------------------" | ||
16 | echo "running zram tests" | ||
17 | echo "--------------------" | ||
18 | ./zram01.sh | ||
19 | echo "" | ||
20 | ./zram02.sh | ||
21 | } | ||
22 | |||
23 | check_prereqs | ||
24 | |||
25 | # check zram module exists | ||
26 | MODULE_PATH=/lib/modules/`uname -r`/kernel/drivers/block/zram/zram.ko | ||
27 | if [ -f $MODULE_PATH ]; then | ||
28 | run_zram | ||
29 | elif [ -b /dev/zram0 ]; then | ||
30 | run_zram | ||
31 | else | ||
32 | echo "$TCID : No zram.ko module or /dev/zram0 device file not found" | ||
33 | echo "$TCID : CONFIG_ZRAM is not set" | ||
34 | exit 1 | ||
35 | fi | ||
diff --git a/tools/testing/selftests/zram/zram01.sh b/tools/testing/selftests/zram/zram01.sh new file mode 100755 index 000000000000..b9566a6478a9 --- /dev/null +++ b/tools/testing/selftests/zram/zram01.sh | |||
@@ -0,0 +1,99 @@ | |||
1 | #!/bin/bash | ||
2 | # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. | ||
3 | # | ||
4 | # This program is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 2 of | ||
7 | # the License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it would be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # Test creates several zram devices with different filesystems on them. | ||
15 | # It fills each device with zeros and checks that compression works. | ||
16 | # | ||
17 | # Author: Alexey Kodanev <alexey.kodanev@oracle.com> | ||
18 | # Modified: Naresh Kamboju <naresh.kamboju@linaro.org> | ||
19 | |||
20 | TCID="zram01" | ||
21 | ERR_CODE=0 | ||
22 | |||
23 | . ./zram_lib.sh | ||
24 | |||
25 | # Test will create the following number of zram devices: | ||
26 | dev_num=1 | ||
27 | # This is a list of parameters for zram devices. | ||
28 | # Number of items must be equal to 'dev_num' parameter. | ||
29 | zram_max_streams="2" | ||
30 | |||
31 | # The zram sysfs node 'disksize' value can be either in bytes, | ||
32 | # or you can use mem suffixes. But in some old kernels, mem | ||
33 | # suffixes are not supported, for example, in RHEL6.6GA's kernel | ||
34 | # layer, it uses strict_strtoull() to parse disksize which does | ||
35 | # not support mem suffixes, in some newer kernels, they use | ||
36 | # memparse() which supports mem suffixes. So here we just use | ||
37 | # bytes to make sure everything works correctly. | ||
38 | zram_sizes="2097152" # 2MB | ||
39 | zram_mem_limits="2M" | ||
40 | zram_filesystems="ext4" | ||
41 | zram_algs="lzo" | ||
42 | |||
43 | zram_fill_fs() | ||
44 | { | ||
45 | local mem_free0=$(free -m | awk 'NR==2 {print $4}') | ||
46 | |||
47 | for i in $(seq 0 $(($dev_num - 1))); do | ||
48 | echo "fill zram$i..." | ||
49 | local b=0 | ||
50 | while [ true ]; do | ||
51 | dd conv=notrunc if=/dev/zero of=zram${i}/file \ | ||
52 | oflag=append count=1 bs=1024 status=none \ | ||
53 | > /dev/null 2>&1 || break | ||
54 | b=$(($b + 1)) | ||
55 | done | ||
56 | echo "zram$i can be filled with '$b' KB" | ||
57 | done | ||
58 | |||
59 | local mem_free1=$(free -m | awk 'NR==2 {print $4}') | ||
60 | local used_mem=$(($mem_free0 - $mem_free1)) | ||
61 | |||
62 | local total_size=0 | ||
63 | for sm in $zram_sizes; do | ||
64 | local s=$(echo $sm | sed 's/M//') | ||
65 | total_size=$(($total_size + $s)) | ||
66 | done | ||
67 | |||
68 | echo "zram used ${used_mem}M, zram disk sizes ${total_size}M" | ||
69 | |||
70 | local v=$((100 * $total_size / $used_mem)) | ||
71 | |||
72 | if [ "$v" -lt 100 ]; then | ||
73 | echo "FAIL compression ratio: 0.$v:1" | ||
74 | ERR_CODE=-1 | ||
75 | zram_cleanup | ||
76 | return | ||
77 | fi | ||
78 | |||
79 | echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK" | ||
80 | } | ||
81 | |||
82 | check_prereqs | ||
83 | zram_load | ||
84 | zram_max_streams | ||
85 | zram_compress_alg | ||
86 | zram_set_disksizes | ||
87 | zram_set_memlimit | ||
88 | zram_makefs | ||
89 | zram_mount | ||
90 | |||
91 | zram_fill_fs | ||
92 | zram_cleanup | ||
93 | zram_unload | ||
94 | |||
95 | if [ $ERR_CODE -ne 0 ]; then | ||
96 | echo "$TCID : [FAIL]" | ||
97 | else | ||
98 | echo "$TCID : [PASS]" | ||
99 | fi | ||
diff --git a/tools/testing/selftests/zram/zram02.sh b/tools/testing/selftests/zram/zram02.sh new file mode 100755 index 000000000000..74569b883737 --- /dev/null +++ b/tools/testing/selftests/zram/zram02.sh | |||
@@ -0,0 +1,54 @@ | |||
1 | #!/bin/bash | ||
2 | # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. | ||
3 | # | ||
4 | # This program is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 2 of | ||
7 | # the License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it would be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # Test checks that we can create swap zram device. | ||
15 | # | ||
16 | # Author: Alexey Kodanev <alexey.kodanev@oracle.com> | ||
17 | # Modified: Naresh Kamboju <naresh.kamboju@linaro.org> | ||
18 | |||
19 | TCID="zram02" | ||
20 | ERR_CODE=0 | ||
21 | |||
22 | . ./zram_lib.sh | ||
23 | |||
24 | # Test will create the following number of zram devices: | ||
25 | dev_num=1 | ||
26 | # This is a list of parameters for zram devices. | ||
27 | # Number of items must be equal to 'dev_num' parameter. | ||
28 | zram_max_streams="2" | ||
29 | |||
30 | # The zram sysfs node 'disksize' value can be either in bytes, | ||
31 | # or you can use mem suffixes. But in some old kernels, mem | ||
32 | # suffixes are not supported, for example, in RHEL6.6GA's kernel | ||
33 | # layer, it uses strict_strtoull() to parse disksize which does | ||
34 | # not support mem suffixes, in some newer kernels, they use | ||
35 | # memparse() which supports mem suffixes. So here we just use | ||
36 | # bytes to make sure everything works correctly. | ||
37 | zram_sizes="1048576" # 1M | ||
38 | zram_mem_limits="1M" | ||
39 | |||
40 | check_prereqs | ||
41 | zram_load | ||
42 | zram_max_streams | ||
43 | zram_set_disksizes | ||
44 | zram_set_memlimit | ||
45 | zram_makeswap | ||
46 | zram_swapoff | ||
47 | zram_cleanup | ||
48 | zram_unload | ||
49 | |||
50 | if [ $ERR_CODE -ne 0 ]; then | ||
51 | echo "$TCID : [FAIL]" | ||
52 | else | ||
53 | echo "$TCID : [PASS]" | ||
54 | fi | ||
diff --git a/tools/testing/selftests/zram/zram_lib.sh b/tools/testing/selftests/zram/zram_lib.sh new file mode 100755 index 000000000000..424e68ed1487 --- /dev/null +++ b/tools/testing/selftests/zram/zram_lib.sh | |||
@@ -0,0 +1,232 @@ | |||
1 | #!/bin/sh | ||
2 | # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. | ||
3 | # | ||
4 | # This program is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 2 of | ||
7 | # the License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it would be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # Author: Alexey Kodanev <alexey.kodanev@oracle.com> | ||
15 | # Modified: Naresh Kamboju <naresh.kamboju@linaro.org> | ||
16 | |||
17 | MODULE=0 | ||
18 | dev_makeswap=-1 | ||
19 | dev_mounted=-1 | ||
20 | |||
21 | trap INT | ||
22 | |||
23 | check_prereqs() | ||
24 | { | ||
25 | local msg="skip all tests:" | ||
26 | |||
27 | if [ $UID != 0 ]; then | ||
28 | echo $msg must be run as root >&2 | ||
29 | exit 0 | ||
30 | fi | ||
31 | } | ||
32 | |||
33 | zram_cleanup() | ||
34 | { | ||
35 | echo "zram cleanup" | ||
36 | local i= | ||
37 | for i in $(seq 0 $dev_makeswap); do | ||
38 | swapoff /dev/zram$i | ||
39 | done | ||
40 | |||
41 | for i in $(seq 0 $dev_mounted); do | ||
42 | umount /dev/zram$i | ||
43 | done | ||
44 | |||
45 | for i in $(seq 0 $(($dev_num - 1))); do | ||
46 | echo 1 > /sys/block/zram${i}/reset | ||
47 | rm -rf zram$i | ||
48 | done | ||
49 | |||
50 | } | ||
51 | |||
52 | zram_unload() | ||
53 | { | ||
54 | if [ $MODULE -ne 0 ] ; then | ||
55 | echo "zram rmmod zram" | ||
56 | rmmod zram > /dev/null 2>&1 | ||
57 | fi | ||
58 | } | ||
59 | |||
60 | zram_load() | ||
61 | { | ||
62 | # check zram module exists | ||
63 | MODULE_PATH=/lib/modules/`uname -r`/kernel/drivers/block/zram/zram.ko | ||
64 | if [ -f $MODULE_PATH ]; then | ||
65 | MODULE=1 | ||
66 | echo "create '$dev_num' zram device(s)" | ||
67 | modprobe zram num_devices=$dev_num | ||
68 | if [ $? -ne 0 ]; then | ||
69 | echo "failed to insert zram module" | ||
70 | exit 1 | ||
71 | fi | ||
72 | |||
73 | dev_num_created=$(ls /dev/zram* | wc -w) | ||
74 | |||
75 | if [ "$dev_num_created" -ne "$dev_num" ]; then | ||
76 | echo "unexpected num of devices: $dev_num_created" | ||
77 | ERR_CODE=-1 | ||
78 | else | ||
79 | echo "zram load module successful" | ||
80 | fi | ||
81 | elif [ -b /dev/zram0 ]; then | ||
82 | echo "/dev/zram0 device file found: OK" | ||
83 | else | ||
84 | echo "ERROR: No zram.ko module or no /dev/zram0 device found" | ||
85 | echo "$TCID : CONFIG_ZRAM is not set" | ||
86 | exit 1 | ||
87 | fi | ||
88 | } | ||
89 | |||
90 | zram_max_streams() | ||
91 | { | ||
92 | echo "set max_comp_streams to zram device(s)" | ||
93 | |||
94 | local i=0 | ||
95 | for max_s in $zram_max_streams; do | ||
96 | local sys_path="/sys/block/zram${i}/max_comp_streams" | ||
97 | echo $max_s > $sys_path || \ | ||
98 | echo "FAIL failed to set '$max_s' to $sys_path" | ||
99 | sleep 1 | ||
100 | local max_streams=$(cat $sys_path) | ||
101 | |||
102 | [ "$max_s" -ne "$max_streams" ] && \ | ||
103 | echo "FAIL can't set max_streams '$max_s', get $max_stream" | ||
104 | |||
105 | i=$(($i + 1)) | ||
106 | echo "$sys_path = '$max_streams' ($i/$dev_num)" | ||
107 | done | ||
108 | |||
109 | echo "zram max streams: OK" | ||
110 | } | ||
111 | |||
112 | zram_compress_alg() | ||
113 | { | ||
114 | echo "test that we can set compression algorithm" | ||
115 | |||
116 | local algs=$(cat /sys/block/zram0/comp_algorithm) | ||
117 | echo "supported algs: $algs" | ||
118 | local i=0 | ||
119 | for alg in $zram_algs; do | ||
120 | local sys_path="/sys/block/zram${i}/comp_algorithm" | ||
121 | echo "$alg" > $sys_path || \ | ||
122 | echo "FAIL can't set '$alg' to $sys_path" | ||
123 | i=$(($i + 1)) | ||
124 | echo "$sys_path = '$alg' ($i/$dev_num)" | ||
125 | done | ||
126 | |||
127 | echo "zram set compression algorithm: OK" | ||
128 | } | ||
129 | |||
130 | zram_set_disksizes() | ||
131 | { | ||
132 | echo "set disk size to zram device(s)" | ||
133 | local i=0 | ||
134 | for ds in $zram_sizes; do | ||
135 | local sys_path="/sys/block/zram${i}/disksize" | ||
136 | echo "$ds" > $sys_path || \ | ||
137 | echo "FAIL can't set '$ds' to $sys_path" | ||
138 | |||
139 | i=$(($i + 1)) | ||
140 | echo "$sys_path = '$ds' ($i/$dev_num)" | ||
141 | done | ||
142 | |||
143 | echo "zram set disksizes: OK" | ||
144 | } | ||
145 | |||
146 | zram_set_memlimit() | ||
147 | { | ||
148 | echo "set memory limit to zram device(s)" | ||
149 | |||
150 | local i=0 | ||
151 | for ds in $zram_mem_limits; do | ||
152 | local sys_path="/sys/block/zram${i}/mem_limit" | ||
153 | echo "$ds" > $sys_path || \ | ||
154 | echo "FAIL can't set '$ds' to $sys_path" | ||
155 | |||
156 | i=$(($i + 1)) | ||
157 | echo "$sys_path = '$ds' ($i/$dev_num)" | ||
158 | done | ||
159 | |||
160 | echo "zram set memory limit: OK" | ||
161 | } | ||
162 | |||
163 | zram_makeswap() | ||
164 | { | ||
165 | echo "make swap with zram device(s)" | ||
166 | local i=0 | ||
167 | for i in $(seq 0 $(($dev_num - 1))); do | ||
168 | mkswap /dev/zram$i > err.log 2>&1 | ||
169 | if [ $? -ne 0 ]; then | ||
170 | cat err.log | ||
171 | echo "FAIL mkswap /dev/zram$1 failed" | ||
172 | fi | ||
173 | |||
174 | swapon /dev/zram$i > err.log 2>&1 | ||
175 | if [ $? -ne 0 ]; then | ||
176 | cat err.log | ||
177 | echo "FAIL swapon /dev/zram$1 failed" | ||
178 | fi | ||
179 | |||
180 | echo "done with /dev/zram$i" | ||
181 | dev_makeswap=$i | ||
182 | done | ||
183 | |||
184 | echo "zram making zram mkswap and swapon: OK" | ||
185 | } | ||
186 | |||
187 | zram_swapoff() | ||
188 | { | ||
189 | local i= | ||
190 | for i in $(seq 0 $dev_makeswap); do | ||
191 | swapoff /dev/zram$i > err.log 2>&1 | ||
192 | if [ $? -ne 0 ]; then | ||
193 | cat err.log | ||
194 | echo "FAIL swapoff /dev/zram$i failed" | ||
195 | fi | ||
196 | done | ||
197 | dev_makeswap=-1 | ||
198 | |||
199 | echo "zram swapoff: OK" | ||
200 | } | ||
201 | |||
202 | zram_makefs() | ||
203 | { | ||
204 | local i=0 | ||
205 | for fs in $zram_filesystems; do | ||
206 | # if requested fs not supported default it to ext2 | ||
207 | which mkfs.$fs > /dev/null 2>&1 || fs=ext2 | ||
208 | |||
209 | echo "make $fs filesystem on /dev/zram$i" | ||
210 | mkfs.$fs /dev/zram$i > err.log 2>&1 | ||
211 | if [ $? -ne 0 ]; then | ||
212 | cat err.log | ||
213 | echo "FAIL failed to make $fs on /dev/zram$i" | ||
214 | fi | ||
215 | i=$(($i + 1)) | ||
216 | echo "zram mkfs.$fs: OK" | ||
217 | done | ||
218 | } | ||
219 | |||
220 | zram_mount() | ||
221 | { | ||
222 | local i=0 | ||
223 | for i in $(seq 0 $(($dev_num - 1))); do | ||
224 | echo "mount /dev/zram$i" | ||
225 | mkdir zram$i | ||
226 | mount /dev/zram$i zram$i > /dev/null || \ | ||
227 | echo "FAIL mount /dev/zram$i failed" | ||
228 | dev_mounted=$i | ||
229 | done | ||
230 | |||
231 | echo "zram mount of zram device(s): OK" | ||
232 | } | ||