Skip to content

Commit be8a3ec

Browse files
Brian Woodssstabellini
Brian Woods
authored andcommitted
Add support for filesystem binds
Since enabling every filesystem operation would be extensive, just enable filesystem binds for now. The default is RW and bind, but it use mount -o option. Signed-off-by: Brian Woods <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Signed-off-by: Stefano Stabellini <[email protected]>
1 parent db062ad commit be8a3ec

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,35 @@ An example cni file is:
114114
}
115115
}
116116
```
117+
118+
119+
120+
Container Filesystem Binds
121+
--------------------------
122+
123+
Currently runX only supports filesystem binds. The defaults are bind and RW.
124+
You can also pass any -o arguement mount uses. Now you use them in containerd
125+
like:
126+
127+
```
128+
ctr ... --mount type=bind,src=/tmp,dst=/host,options=bind:rw ...
129+
```
130+
131+
which is the same as:
132+
133+
```
134+
ctr ... --mount type=bind,src=/tmp,dst=/host ...
135+
```
136+
137+
Or to have it RO and disable execution:
138+
139+
```
140+
ctr ... --mount type=bind,src=/tmp,dst=/host,options=ro:noexec ...
141+
```
142+
143+
Likewise to just use rbind rather than bind:
144+
145+
146+
```
147+
ctr ... --mount type=bind,src=/tmp,dst=/host,options=rbind ...
148+
```

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o pipefail
1818
# Path to statically built busybox binary i.e.
1919
# busybox=/usr/bin/busybox-static-aarch64
2020

21-
execs="start delete state serial_start create pause"
21+
execs="start delete state serial_start create pause mount"
2222

2323
# Clean the repo, but save the vendor area
2424
if [ "x${1:-}" != "x" ] && [ "clean" == "$1" ]; then

files/mount

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
workpath=/usr/share/runX
4+
MNT_MAX_IT=30
5+
OPT_MAX_IT=15
6+
UMNT_MAX_IT=5
7+
8+
containerid="$1"
9+
crundir="$2"
10+
op="$3"
11+
bundle=$( cat "$crundir"/bundle )
12+
configfile="$bundle"/config.json
13+
mountpoint=$( cat "$crundir"/rootfs )
14+
15+
for (( i=0 ; i < MNT_MAX_IT ; i++ ))
16+
do
17+
jq_type=$( jq -r .[\"mounts\"][$i][\"type\"] "$configfile" )
18+
19+
if test "$jq_type" = "null"
20+
then
21+
break
22+
fi
23+
24+
if test "$jq_type" = "bind"
25+
then
26+
jq_des=$( jq -r .[\"mounts\"][$i][\"destination\"] "$configfile" )
27+
jq_src=$( jq -r .[\"mounts\"][$i][\"source\"] "$configfile" )
28+
29+
if test "$op" = "mount"
30+
then
31+
jq_rw="rw"
32+
jq_bind="bind"
33+
jq_cmd=""
34+
for (( j=0 ; j < OPT_MAX_IT ; j++ ))
35+
do
36+
jq_opt=$( jq -r .[\"mounts\"][$i][\"options\"][$j] "$configfile" )
37+
38+
case "$jq_opt" in
39+
"null")
40+
break
41+
;;
42+
"bind")
43+
;&
44+
"rbind")
45+
jq_bind="$jq_opt"
46+
;;
47+
"rw")
48+
;&
49+
"ro")
50+
jq_rw="$jq_opt"
51+
;;
52+
*)
53+
jq_cmd+="$jq_opt,"
54+
;;
55+
esac
56+
done
57+
58+
mkdir -p "$mountpoint$jq_des"
59+
mount -o "$jq_cmd$jq_bind" "$jq_src" "$mountpoint$jq_des"
60+
if test "$jq_rw" = "ro"
61+
then
62+
mount -o "$jq_cmd$jq_bind,remount,ro" "$mountpoint$jq_des"
63+
fi
64+
else
65+
for (( j=0 ; j < UMNT_MAX_IT ; j++ ))
66+
do
67+
umount "$mountpoint$jq_des"
68+
if test "$?" = "0"
69+
then
70+
break
71+
else
72+
sleep 1
73+
fi
74+
done
75+
fi
76+
fi
77+
done

runX

+2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ then
116116
elif test $cmd = "kill"
117117
then
118118
$workpath/delete $containerid
119+
$workpath/mount $containerid "$crundir" unmount
119120
elif test $cmd = "create"
120121
then
122+
$workpath/mount $containerid "$crundir" mount
121123
$workpath/create $containerid "$crundir"
122124

123125
if test "$guestconsole"

0 commit comments

Comments
 (0)