Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: bring back sshfs, workaround virtiofs #545

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
vm: bring back sshfs, workaround virtiofs
  • Loading branch information
abiosoft committed Dec 27, 2022
commit 4e8507f0ad1eb66e8f356d8771958a0129204a6d
62 changes: 41 additions & 21 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ const (
defaultMemory = 2
defaultDisk = 60
defaultKubernetesVersion = kubernetes.DefaultVersion
defaultNetworkDriver = "gvproxy"

defaultNetworkDriver = "gvproxy"

defaultVMType = "qemu"
defaultMountTypeQEMU = "sshfs"
defaultMountTypeVZ = "virtiofs"
)

var defaultKubernetesDisable = []string{"traefik"}
Expand All @@ -115,13 +120,10 @@ var startCmdArgs struct {

func init() {
runtimes := strings.Join(environment.ContainerRuntimes(), ", ")
networkDrivers := strings.Join([]string{"slirp", gvproxy.Name}, ", ")
networkDrivers := strings.Join([]string{gvproxy.Name, "slirp"}, ", ")
defaultArch := string(environment.HostArch())

defaultMountType := "9p"
defaultVMType := "qemu"

mounts := strings.Join([]string{defaultMountType, "sshfs", "virtiofs"}, ", ")
mounts := strings.Join([]string{defaultMountTypeQEMU, "9p", "virtiofs"}, ", ")
types := strings.Join([]string{defaultVMType, "vz"}, ", ")

root.Cmd().AddCommand(startCmd)
Expand All @@ -148,7 +150,7 @@ func init() {

// mounts
startCmd.Flags().StringSliceVarP(&startCmdArgs.Flags.Mounts, "mount", "V", nil, "directories to mount, suffix ':w' for writable")
startCmd.Flags().StringVar(&startCmdArgs.MountType, "mount-type", defaultMountType, "volume driver for the mount ("+mounts+")")
startCmd.Flags().StringVar(&startCmdArgs.MountType, "mount-type", defaultMountTypeQEMU, "volume driver for the mount ("+mounts+")")

// ssh agent
startCmd.Flags().BoolVarP(&startCmdArgs.ForwardAgent, "ssh-agent", "s", false, "forward SSH agent to the VM")
Expand Down Expand Up @@ -214,6 +216,35 @@ func mountsFromFlag(mounts []string) []config.Mount {
return mnts
}

func setDefaults(cmd *cobra.Command) {
if util.MacOS13OrNewer() {
// changing to vz implies changing mount type to virtiofs
if cmd.Flag("vm-type").Changed && startCmdArgs.VMType == "vz" && !cmd.Flag("mount-type").Changed {
startCmdArgs.MountType = "virtiofs"
cmd.Flag("mount-type").Changed = true
}
}

// mount type
{
// convert mount type for qemu
if startCmdArgs.VMType != "vz" && startCmdArgs.MountType == defaultMountTypeVZ {
startCmdArgs.MountType = defaultMountTypeQEMU
if cmd.Flag("mount-type").Changed {
log.Warnf("%s is only available for 'vz' vmType, using %s", defaultMountTypeVZ, defaultMountTypeQEMU)
}
}
// convert mount type for vz
if startCmdArgs.VMType == "vz" && startCmdArgs.MountType == "9p" {
startCmdArgs.MountType = "virtiofs"
if cmd.Flag("mount-type").Changed {
log.Warnf("9p is only available for 'qemu' vmType, using %s", defaultMountTypeVZ)
}
}
}

}

func prepareConfig(cmd *cobra.Command) {
current, err := configmanager.Load()
if err != nil {
Expand All @@ -233,25 +264,14 @@ func prepareConfig(cmd *cobra.Command) {
startCmdArgs.Network.DNSHosts = dnsHostsFromFlag(startCmdArgs.Flags.DNSHosts)
startCmdArgs.ActivateRuntime = &startCmdArgs.Flags.ActivateRuntime

// set relevant missing default values
setDefaults(cmd)

// handle macOS virtualization.framework transition
{
if current.VMType == "" {
current.VMType = "qemu"
}
// convert mount type for qemu
if startCmdArgs.VMType != "vz" && startCmdArgs.MountType == "virtiofs" {
startCmdArgs.MountType = "9p"
if cmd.Flag("mount-type").Changed {
log.Warnln("virtiofs is only available for 'vz' vmType, using 9p")
}
}
// convert mount type for vz
if startCmdArgs.VMType == "vz" && startCmdArgs.MountType == "9p" {
startCmdArgs.MountType = "virtiofs"
if cmd.Flag("mount-type").Changed {
log.Warnln("9p is only available for 'qemu' vmType, using virtiofs")
}
}
}
// if there is no existing settings
if current.Empty() {
Expand Down
4 changes: 2 additions & 2 deletions embedded/defaults/colima.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ vmType: qemu
# sshfs is faster than 9p but the least reliable of the options (when there are lots
# of concurrent reads or writes).
#
# Default: virtiofs (for vz), 9p (for qemu)
mountType: 9p
# Default: virtiofs (for vz), sshfs (for qemu)
mountType: sshfs

# The CPU type for the virtual machine (requires vmType `qemu`).
# Options available for host emulation can be checked with: `qemu-system-$(arch) -cpu help`.
Expand Down
9 changes: 9 additions & 0 deletions environment/vm/lima/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) {
Script: `readlink /sbin/fstrim || fstrim -a`,
})

// workaround for slow virtiofs https://github.com/drud/ddev/issues/4466#issuecomment-1361261185
// TODO: remove when fixed upstream
if l.MountType == VIRTIOFS {
l.Provision = append(l.Provision, Provision{
Mode: ProvisionModeSystem,
Script: `stat /sys/class/block/vda/queue/write_cache && echo 'write through' > /sys/class/block/vda/queue/write_cache`,
})
}

if len(conf.Mounts) == 0 {
l.Mounts = append(l.Mounts,
Mount{Location: "~", Writable: true},
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ require (
github.com/google/btree v1.0.1 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/insomniacslk/dhcp v0.0.0-20220504074936-1ca156eafb9f // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2 // indirect
github.com/mdlayher/socket v0.2.0 // indirect
github.com/mdlayher/vsock v1.1.1 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/u-root/uio v0.0.0-20210528114334-82958018845c // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -333,12 +334,14 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7 h1:lez6TS6aAau+8wXUP3G9I3TGlmPFEq2CTxBaRqY6AGE=
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7/go.mod h1:U6ZQobyTjI/tJyq2HG+i/dfSoFUt8/aZCM+GKtmFk/Y=
github.com/mdlayher/netlink v0.0.0-20190409211403-11939a169225/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
github.com/mdlayher/netlink v1.0.0/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M=
github.com/mdlayher/netlink v1.1.0/go.mod h1:H4WCitaheIsdF9yOYu8CFmCgQthAPIWZmcKp9uZHgmY=
github.com/mdlayher/netlink v1.1.1/go.mod h1:WTYpFb/WTvlRJAyKhZL5/uy69TDDpHHu2VZmb2XgV7o=
github.com/mdlayher/raw v0.0.0-20190606142536-fef19f00fc18/go.mod h1:7EpbotpCmVZcu+KCX4g9WaRNuu11uyhiW7+Le1dKawg=
github.com/mdlayher/raw v0.0.0-20191009151244-50f2db8cc065 h1:aFkJ6lx4FPip+S+Uw4aTegFMct9shDvP+79PsSxpm3w=
github.com/mdlayher/raw v0.0.0-20191009151244-50f2db8cc065/go.mod h1:7EpbotpCmVZcu+KCX4g9WaRNuu11uyhiW7+Le1dKawg=
github.com/mdlayher/socket v0.2.0 h1:EY4YQd6hTAg2tcXF84p5DTHazShE50u5HeBzBaNgjkA=
github.com/mdlayher/socket v0.2.0/go.mod h1:QLlNPkFR88mRUNQIzRBMfXxwKal8H7u1h3bL1CV+f0E=
Expand Down