Skip to content

Commit 89ec95b

Browse files
committed
vde: allow vde URL with "vde://" prefix
It is called "URL" so we should support at least "vde://" prefix Signed-off-by: Akihiro Suda <[email protected]>
1 parent 662bc86 commit 89ec95b

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

docs/network.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ network:
3434
# daemons must be running before the instance is started. The interface type
3535
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
3636
vde:
37-
# url points to the vde_switch socket directory
38-
- url: "/var/run/vde.ctl"
37+
# url points to the vde_switch socket directory, optionally with vde:// prefix
38+
- url: "vde:///var/run/vde.ctl"
3939
# MAC address of the instance; lima will pick one based on the instance name,
4040
# so DHCP assigned ip addresses should remain constant over instance restarts.
4141
macAddress: ""

examples/vmnet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ network:
2020
# daemons must be running before the instance is started. The interface type
2121
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
2222
vde:
23-
- url: "/var/run/vde.ctl"
23+
- url: "vde:///var/run/vde.ctl"

pkg/limayaml/default.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ network:
125125
# daemons must be running before the instance is started. The interface type
126126
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
127127
vde:
128-
# url points to the vde_switch socket directory
129-
# - url: "/var/run/vde.ctl"
128+
# url points to the vde_switch socket directory, optionally with vde:// prefix
129+
# - url: "vde:///var/run/vde.ctl"
130130
# # MAC address of the instance; lima will pick one based on the instance name,
131131
# # so DHCP assigned ip addresses should remain constant over instance restarts.
132132
# macAddress: ""

pkg/limayaml/validate.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66
"os"
77
"os/user"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011

1112
"github.com/AkihiroSuda/lima/pkg/localpathutil"
1213
"github.com/AkihiroSuda/lima/pkg/qemu/qemuconst"
1314
"github.com/docker/go-units"
1415
"github.com/pkg/errors"
16+
"github.com/sirupsen/logrus"
1517
)
1618

1719
func Validate(y LimaYAML) error {
@@ -176,21 +178,28 @@ func validateNetwork(yNetwork Network) error {
176178
return errors.Errorf("field `%s.url` must not be empty", field)
177179
}
178180
// The field is called VDE.URL in anticipation of QEMU upgrading VDE2 to VDEplug4,
179-
// but right now the only valid value is a path to the vde_switch socket directory.
180-
fi, err := os.Stat(vde.URL)
181-
if err != nil {
182-
return errors.Wrapf(err, "field `%s.url` %q failed stat", field, vde.URL)
183-
}
184-
if !fi.IsDir() {
185-
return errors.Wrapf(err, "field `%s.url` %q is not a directory", field, vde.URL)
186-
}
187-
ctlSocket := filepath.Join(vde.URL, "ctl")
188-
fi, err = os.Stat(ctlSocket)
189-
if err != nil {
190-
return errors.Wrapf(err, "field `%s.url` control socket %q failed stat", field, ctlSocket)
191-
}
192-
if fi.Mode()&os.ModeSocket == 0 {
193-
return errors.Errorf("field `%s.url` file %q is not a UNIX socket", field, ctlSocket)
181+
// but right now the only valid value on macOS is a path to the vde_switch socket directory,
182+
// optionally with vde:// prefix.
183+
if !strings.Contains(vde.URL, "://") || strings.HasPrefix(vde.URL, "vde://") {
184+
vdeSwitch := strings.TrimPrefix(vde.URL, "vde://")
185+
fi, err := os.Stat(vdeSwitch)
186+
if err != nil {
187+
return errors.Wrapf(err, "field `%s.url` %q failed stat", field, vdeSwitch)
188+
}
189+
if !fi.IsDir() {
190+
return errors.Wrapf(err, "field `%s.url` %q is not a directory", field, vdeSwitch)
191+
}
192+
ctlSocket := filepath.Join(vdeSwitch, "ctl")
193+
fi, err = os.Stat(ctlSocket)
194+
if err != nil {
195+
return errors.Wrapf(err, "field `%s.url` control socket %q failed stat", field, ctlSocket)
196+
}
197+
if fi.Mode()&os.ModeSocket == 0 {
198+
return errors.Errorf("field `%s.url` file %q is not a UNIX socket", field, ctlSocket)
199+
}
200+
} else if runtime.GOOS != "linux" {
201+
logrus.Warnf("field `%s.url` is unlikely to work for %s (unless libvdeplug4 has been ported to %s and is installed)",
202+
field, runtime.GOOS, runtime.GOOS)
194203
}
195204
if vde.MACAddress != "" {
196205
hw, err := net.ParseMAC(vde.MACAddress)

pkg/qemu/qemu.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ func Cmdline(cfg Config) (string, []string, error) {
197197
args = append(args, "-netdev", fmt.Sprintf("user,id=net0,net=192.168.5.0/24,hostfwd=tcp:127.0.0.1:%d-:22", y.SSH.LocalPort))
198198
args = append(args, "-device", "virtio-net-pci,netdev=net0,mac="+limayaml.MACAddress(cfg.InstanceDir))
199199
for i, vde := range y.Network.VDE {
200-
args = append(args, "-netdev", fmt.Sprintf("vde,id=net%d,sock=%s", i+1, vde.URL))
200+
// VDE4 accepts URL such as vde:///var/run/vde.ctl as well as file path such as /var/run/vde.ctl .
201+
// VDE2 only accepts the latter form.
202+
// VDE2 supports macOS but VDE4 does not yet, so we trim vde:// prefix here for VDE2 compatibility.
203+
vdeSock := strings.TrimPrefix(vde.URL, "vde://")
204+
args = append(args, "-netdev", fmt.Sprintf("vde,id=net%d,sock=%s", i+1, vdeSock))
201205
args = append(args, "-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s", i+1, vde.MACAddress))
202206
}
203207

0 commit comments

Comments
 (0)