Skip to content

Commit 939f79b

Browse files
authored
Merge pull request #726 from afbjorklund/virtfs
Add virtfs/9p mounts, instead of sshocker/sshfs
2 parents 7c8e81c + 9d1d21b commit 939f79b

File tree

20 files changed

+302
-43
lines changed

20 files changed

+302
-43
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ jobs:
115115
retry_on: error
116116
max_attempts: 3
117117
command: ./hack/test-example.sh examples/alpine.yaml
118+
- name: "Test experimental-9p.yaml"
119+
uses: nick-invision/retry@v2
120+
with:
121+
timeout_minutes: 30
122+
retry_on: error
123+
max_attempts: 3
124+
command: ./hack/test-example.sh examples/experimental-9p.yaml
118125
- name: "Test vmnet.yaml"
119126
uses: nick-invision/retry@v2
120127
with:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ The current default spec:
266266
- Performance optimization
267267
- More guest distros
268268
- Windows hosts
269-
- [VirtFS to replace the current reverse sshfs (work has to be done on QEMU repo)](https://github.com/NixOS/nixpkgs/pull/122420)
270269
- [vsock](https://github.com/apple/darwin-xnu/blob/xnu-7195.81.3/bsd/man/man4/vsock.4) to replace SSH (work has to be done on QEMU repo)
271270

272271
## FAQs & Troubleshooting

docs/internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://cloudin
115115
- `LIMA_CIDATA_UID`: the numeric UID
116116
- `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts
117117
- `LIMA_CIDATA_MOUNTS_%d_MOUNTPOINT`: the N-th mount point of Lima mounts (N=0, 1, ...)
118+
- `LIMA_CIDATA_MOUNTTYPE`: the type of the Lima mounts ("reverse-sshfs", "9p", ...)
118119
- `LIMA_CIDATA_CONTAINERD_USER`: set to "1" if rootless containerd to be set up
119120
- `LIMA_CIDATA_CONTAINERD_SYSTEM`: set to "1" if system-wide containerd to be set up
120121
- `LIMA_CIDATA_SLIRP_GATEWAY`: set to the IP address of the host on the SLIRP network. `192.168.5.2`.

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Container orchestration:
3434
Others:
3535
- [`vmnet.yaml`](./vmnet.yaml): ⭐enable [`vmnet.framework`](../docs/network.md)
3636
- [`deprecated/centos-7.yaml`](./deprecated/centos-7.yaml): [deprecated] CentOS 7
37+
- [`experimental-9p.yaml`](experimental-9p.yaml): use 9p mount type
3738

3839
## Tier 1
3940

examples/default.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,28 @@ mounts:
6161
# system will look and feel like regular files directories in the Guest OS.
6262
# 🟢 Builtin default: false
6363
followSymlinks: null
64+
9p:
65+
# Supported security models are "passthrough", "mapped-xattr", "mapped-file" and "none".
66+
# 🟢 Builtin default: "mapped-xattr"
67+
securityModel: null
68+
# Select 9P protocol version. Valid options are: "9p2000" (legacy), "9p2000.u", "9p2000.L".
69+
# 🟢 Builtin default: "9p2000.L"
70+
protocolVersion: null
71+
# The number of bytes to use for 9p packet payload, where 4KiB is the absolute minimum.
72+
# 🟢 Builtin default: "128KiB"
73+
msize: null
74+
# Specifies a caching policy. Valid options are: "none", "loose", "fscache" and "mmap".
75+
# 🟢 Builtin default: "mmap"
76+
cache: null
6477
- location: "/tmp/lima"
6578
# 🟢 Builtin default: false
6679
# 🔵 This file: true (only for "/tmp/lima")
6780
writable: true
6881

82+
# Mount type for above mounts, such as "reverse-sshfs" (from sshocker) or "9p" (EXPERIMENTAL, from QEMU’s virtio-9p-pci, aka virtfs)
83+
# 🟢 Builtin default: "reverse-sshfs"
84+
mountType: null
85+
6986
ssh:
7087
# A localhost port of the host. Forwarded to port 22 of the guest.
7188
# 🟢 Builtin default: 0 (automatically assigned to a free port)

examples/experimental-9p.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This example requires Lima v0.10.0 or later.
2+
# On macOS hosts, QEMU needs to be v7.0.0 or later. Homebrew's QEMU v6.2.0_1 can be used too.
3+
# This example is planned to be merged to default.yaml in Lima v1.0 (ETA: 2022 Q2).
4+
images:
5+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
6+
- location: "https://cloud-images.ubuntu.com/releases/21.10/release-20220201/ubuntu-21.10-server-cloudimg-amd64.img"
7+
arch: "x86_64"
8+
digest: "sha256:73fe1785c60edeb506f191affff0440abcc2de02420bb70865d51d0ff9b28223"
9+
- location: "https://cloud-images.ubuntu.com/releases/21.10/release-20220201/ubuntu-21.10-server-cloudimg-arm64.img"
10+
arch: "aarch64"
11+
digest: "sha256:1b5b3fe616e1eea4176049d434a360344a7d471f799e151190f21b0a27f0b424"
12+
# Fallback to the latest release image.
13+
# Hint: run `limactl prune` to invalidate the cache
14+
- location: "https://cloud-images.ubuntu.com/releases/21.10/release/ubuntu-21.10-server-cloudimg-amd64.img"
15+
arch: "x86_64"
16+
- location: "https://cloud-images.ubuntu.com/releases/21.10/release/ubuntu-21.10-server-cloudimg-arm64.img"
17+
arch: "aarch64"
18+
19+
mounts:
20+
- location: "~"
21+
- location: "/tmp/lima"
22+
writable: true
23+
mountType: "9p"

pkg/cidata/cidata.TEMPLATE.d/boot/25-guestagent-base.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
set -eux
44

5-
# Create mount points
6-
# NOTE: Busybox sh does not support `for ((i=0;i<$N;i++))` form
7-
for f in $(seq 0 $((LIMA_CIDATA_MOUNTS - 1))); do
8-
mountpointvar="LIMA_CIDATA_MOUNTS_${f}_MOUNTPOINT"
9-
mountpoint="$(eval echo \$"$mountpointvar")"
10-
mkdir -p "${mountpoint}"
11-
gid=$(id -g "${LIMA_CIDATA_USER}")
12-
chown "${LIMA_CIDATA_UID}:${gid}" "${mountpoint}"
13-
done
5+
if [ "${LIMA_CIDATA_MOUNTTYPE}" != "9p" ]; then
6+
# Create mount points
7+
# NOTE: Busybox sh does not support `for ((i=0;i<$N;i++))` form
8+
for f in $(seq 0 $((LIMA_CIDATA_MOUNTS - 1))); do
9+
mountpointvar="LIMA_CIDATA_MOUNTS_${f}_MOUNTPOINT"
10+
mountpoint="$(eval echo \$"$mountpointvar")"
11+
mkdir -p "${mountpoint}"
12+
gid=$(id -g "${LIMA_CIDATA_USER}")
13+
chown "${LIMA_CIDATA_UID}:${gid}" "${mountpoint}"
14+
done
15+
fi
1416

1517
# Install or update the guestagent binary
1618
install -m 755 "${LIMA_CIDATA_MNT}"/lima-guestagent /usr/local/bin/lima-guestagent

pkg/cidata/cidata.TEMPLATE.d/boot/30-install-packages.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ fi
2121
# Install minimum dependencies
2222
if command -v apt-get >/dev/null 2>&1; then
2323
pkgs=""
24-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
25-
pkgs="${pkgs} sshfs"
24+
if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
25+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
26+
pkgs="${pkgs} sshfs"
27+
fi
2628
fi
2729
if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then
2830
pkgs="${pkgs} iptables"
@@ -42,8 +44,10 @@ elif command -v dnf >/dev/null 2>&1; then
4244
if ! command -v tar >/dev/null 2>&1; then
4345
pkgs="${pkgs} tar"
4446
fi
45-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
46-
pkgs="${pkgs} fuse-sshfs"
47+
if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
48+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
49+
pkgs="${pkgs} fuse-sshfs"
50+
fi
4751
fi
4852
if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then
4953
pkgs="${pkgs} iptables"
@@ -102,8 +106,10 @@ elif command -v yum >/dev/null 2>&1; then
102106
fi
103107
elif command -v pacman >/dev/null 2>&1; then
104108
pkgs=""
105-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
106-
pkgs="${pkgs} sshfs"
109+
if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
110+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
111+
pkgs="${pkgs} sshfs"
112+
fi
107113
fi
108114
# other dependencies are preinstalled on Arch Linux
109115
if [ -n "${pkgs}" ]; then
@@ -112,8 +118,10 @@ elif command -v pacman >/dev/null 2>&1; then
112118
fi
113119
elif command -v zypper >/dev/null 2>&1; then
114120
pkgs=""
115-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
116-
pkgs="${pkgs} sshfs"
121+
if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
122+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
123+
pkgs="${pkgs} sshfs"
124+
fi
117125
fi
118126
if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then
119127
pkgs="${pkgs} iptables"
@@ -127,8 +135,10 @@ elif command -v zypper >/dev/null 2>&1; then
127135
fi
128136
elif command -v apk >/dev/null 2>&1; then
129137
pkgs=""
130-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
131-
pkgs="${pkgs} sshfs"
138+
if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
139+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then
140+
pkgs="${pkgs} sshfs"
141+
fi
132142
fi
133143
if [ "${INSTALL_IPTABLES}" = 1 ] && ! command -v iptables >/dev/null 2>&1; then
134144
pkgs="${pkgs} iptables"
@@ -154,4 +164,6 @@ fi
154164

155165
# update_fuse_conf has to be called after installing all the packages,
156166
# otherwise apt-get fails with conflict
157-
update_fuse_conf
167+
if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
168+
update_fuse_conf
169+
fi

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ LIMA_CIDATA_USER={{ .User }}
33
LIMA_CIDATA_UID={{ .UID }}
44
LIMA_CIDATA_MOUNTS={{ len .Mounts }}
55
{{- range $i, $val := .Mounts}}
6-
LIMA_CIDATA_MOUNTS_{{$i}}_MOUNTPOINT={{$val}}
6+
LIMA_CIDATA_MOUNTS_{{$i}}_MOUNTPOINT={{$val.Target}}
77
{{- end}}
8+
LIMA_CIDATA_MOUNTTYPE={{ .MountType }}
89
{{- if .Containerd.User}}
910
LIMA_CIDATA_CONTAINERD_USER=1
1011
{{- else}}

pkg/cidata/cidata.TEMPLATE.d/user-data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ growpart:
55
mode: auto
66
devices: ['/']
77

8+
{{- if eq .MountType "9p" }}
9+
{{- if .Mounts }}
10+
mounts:
11+
{{- range $m := $.Mounts}}
12+
- [{{$m.Tag}}, {{$m.Target}}, {{$m.Type}}, "{{$m.Options}}", "0", "0"]
13+
{{- end }}
14+
{{- end }}
15+
{{- end }}
16+
817
users:
918
- name: "{{.User}}"
1019
uid: "{{.UID}}"

0 commit comments

Comments
 (0)