diff --git a/cmd/start.go b/cmd/start.go index 40204e82f..763d99f47 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -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"} @@ -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) @@ -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") @@ -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 { @@ -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() { diff --git a/embedded/defaults/colima.yaml b/embedded/defaults/colima.yaml index b26948e27..1f0c3a3cb 100644 --- a/embedded/defaults/colima.yaml +++ b/embedded/defaults/colima.yaml @@ -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`. diff --git a/environment/vm/lima/yaml.go b/environment/vm/lima/yaml.go index 6f9ee11a7..7feb22570 100644 --- a/environment/vm/lima/yaml.go +++ b/environment/vm/lima/yaml.go @@ -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}, diff --git a/go.mod b/go.mod index c565e4c0a..ff1b3a219 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a198628e8..6ff70a57b 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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=