Skip to content

Commit ba35df6

Browse files
committed
Make thinpool.sh work with loopback devices
Since both Getting Started and Quickstart docs write about a loopback-based device mapper configuration, this script should support that as well. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent ce42c4e commit ba35df6

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

examples/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ integ-test:
4141
--volume $(CURDIR)/etc/containerd/firecracker-runtime.json:/etc/containerd/firecracker-runtime.json \
4242
--volume $(CURDIR)/logs:/var/log/firecracker-containerd-test \
4343
--volume $(CURDIR)/..:/src \
44+
--env FICD_DM_VOLUME_GROUP=$(FICD_DM_VOLUME_GROUP) \
4445
--env FICD_DM_POOL=$(TEST_POOL) \
4546
--env EXTRAGOARGS="${EXTRAGOARGS}" \
4647
--workdir="/src/examples" \
@@ -50,6 +51,7 @@ integ-test:
5051
TEST_GATEWAY?=172.16.0.1
5152
TEST_IP?=172.16.0.2
5253
TEST_SUBNET?=/24
54+
FICD_DM_VOLUME_GROUP?=
5355
TEST_POOL?=
5456
testtap:
5557
ip link add br0 type bridge

runtime/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ integ-test-%: logs
6262
--volume $(CURDIR)/..:/src \
6363
--volume $(GO_CACHE_VOLUME_NAME):/go \
6464
--env ENABLE_ISOLATED_TESTS=1 \
65+
--env FICD_DM_VOLUME_GROUP=$(FICD_DM_VOLUME_GROUP) \
6566
--env FICD_DM_POOL=$(FICD_DM_POOL) \
6667
--env GOPROXY=direct \
6768
--env GOSUMDB=off \
@@ -80,6 +81,7 @@ PERF_RUNTIME_SECONDS?=600
8081
PERF_VM_MEMSIZE_MB?=1024
8182
PERF_TARGET_BANDWIDTH?=1G
8283

84+
FICD_DM_VOLUME_GROUP?=
8385
FICD_DM_POOL?=
8486

8587
tc-redirect-tap-perf:
@@ -107,6 +109,7 @@ perf-test:
107109
--env PERF_RUNTIME_SECONDS=$(PERF_RUNTIME_SECONDS) \
108110
--env PERF_VM_MEMSIZE_MB=$(PERF_VM_MEMSIZE_MB) \
109111
--env PERF_TARGET_BANDWIDTH=$(PERF_TARGET_BANDWIDTH) \
112+
--env FICD_DM_VOLUME_GROUP=$(FICD_DM_VOLUME_GROUP) \
110113
--env FICD_DM_POOL=$(FICD_DM_POOL) \
111114
--env GOPROXY=direct \
112115
--env GOSUMDB=off \

tools/thinpool.sh

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/sh
1+
#! /bin/bash
22
#
33
# Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
#
@@ -13,9 +13,9 @@
1313
# express or implied. See the License for the specific language governing
1414
# permissions and limitations under the License.
1515

16-
set -eu
16+
FICD_DM_VOLUME_GROUP="$FICD_DM_VOLUME_GROUP"
1717

18-
VOLUME_GROUP='fcci-vg'
18+
set -eu
1919

2020
subcommand="$1"
2121
name="$2"
@@ -24,22 +24,51 @@ if [ -z "$name" ]; then
2424
exit 0
2525
fi
2626

27-
dm_device="/dev/mapper/$(echo ${VOLUME_GROUP} | sed -e s/-/--/g)-$name"
27+
if [[ -z "$FICD_DM_VOLUME_GROUP" ]]; then
28+
pool_create() {
29+
echo
30+
}
31+
32+
pool_remove() {
33+
echo
34+
}
35+
36+
pool_reset() {
37+
local dev_no=1
38+
while true; do
39+
sudo dmsetup message "$name" 0 "delete $dev_no" || break
40+
dev_no=$(($dev_no + 1))
41+
done
42+
}
43+
else
44+
dm_device="/dev/mapper/$(echo ${FICD_DM_VOLUME_GROUP} | sed -e s/-/--/g)-$name"
2845

29-
pool_create() {
30-
sudo lvcreate --type thin-pool \
31-
--poolmetadatasize 16GiB \
32-
--size 1G \
33-
-n "$name" "$VOLUME_GROUP"
34-
}
46+
pool_create() {
47+
echo sudo lvcreate --type thin-pool \
48+
--poolmetadatasize 16GiB \
49+
--size 1G \
50+
-n "$name" "$FICD_DM_VOLUME_GROUP"
51+
sudo lvcreate --type thin-pool \
52+
--poolmetadatasize 16GiB \
53+
--size 1G \
54+
-n "$name" "$FICD_DM_VOLUME_GROUP"
55+
}
3556

36-
pool_remove() {
37-
sudo dmsetup remove "${dm_device}-snap-"* || true
38-
sudo dmsetup remove \
57+
pool_remove() {
58+
sudo dmsetup remove "${dm_device}-snap-"* || true
59+
sudo dmsetup remove \
3960
"${dm_device}" \
4061
"${dm_device}_tdata" "${dm_device}_tmeta" || true
41-
sudo lvremove -f "$dm_device"
42-
}
62+
sudo lvremove -f "$dm_device"
63+
}
64+
65+
pool_reset() {
66+
if [ -e "${dm_device}" ]; then
67+
pool_remove
68+
fi
69+
pool_create
70+
}
71+
fi
4372

4473
case "$subcommand" in
4574
'create')
@@ -49,10 +78,7 @@ case "$subcommand" in
4978
pool_remove
5079
;;
5180
'reset')
52-
if [ -e "${dm_device}" ]; then
53-
pool_remove
54-
fi
55-
pool_create
81+
pool_reset
5682
;;
5783
*)
5884
echo "This script doesn't support $subcommand"

0 commit comments

Comments
 (0)