From 59e0919bc71433450c82d4686ff51341d713722e Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Fri, 29 Sep 2023 10:14:49 -0500 Subject: [PATCH] update vfkit vendored code upstream reversed width and height and now we get an unusable gui [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude --- go.mod | 2 +- go.sum | 4 +- pkg/machine/applehv/vfkit.go | 4 +- .../crc-org/vfkit/pkg/config/json.go | 16 +++++ .../crc-org/vfkit/pkg/config/virtio.go | 72 ++++++++++++++++--- vendor/modules.txt | 2 +- 6 files changed, 86 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index b6181bba27..00d9f0c730 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/containers/storage v1.50.2 github.com/coreos/go-systemd/v22 v22.5.0 github.com/coreos/stream-metadata-go v0.4.3 - github.com/crc-org/vfkit v0.1.1 + github.com/crc-org/vfkit v0.1.2-0.20230829083117-09e62065eb6e github.com/cyphar/filepath-securejoin v0.2.4 github.com/digitalocean/go-qemu v0.0.0-20230711162256-2e3d0186973e github.com/docker/distribution v2.8.2+incompatible diff --git a/go.sum b/go.sum index 64945706e6..7fb0e215c1 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/coreos/stream-metadata-go v0.4.3/go.mod h1:fMObQqQm8Ku91G04btKzEH3Asd github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/crc-org/vfkit v0.1.1 h1:F0QXj9ik1mhVq2R8FmWFhQH8SuFGYP5Xu2KF7cTvALs= -github.com/crc-org/vfkit v0.1.1/go.mod h1:vjZiHDacUi0iLosvwyLvqJvJXQhByzlLQbMkdIfCQWk= +github.com/crc-org/vfkit v0.1.2-0.20230829083117-09e62065eb6e h1:UlIzed038y+BSh8GTg3yuL1i8309mrs3Gth9s26AdT8= +github.com/crc-org/vfkit v0.1.2-0.20230829083117-09e62065eb6e/go.mod h1:RJbirUrdvb3qyOxjySBeOfuc9wgbJrZxJP2eNcxDWGs= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= diff --git a/pkg/machine/applehv/vfkit.go b/pkg/machine/applehv/vfkit.go index 8c59b54249..ff8c2874c1 100644 --- a/pkg/machine/applehv/vfkit.go +++ b/pkg/machine/applehv/vfkit.go @@ -56,7 +56,9 @@ func getIgnitionVsockDevice(path string) (vfConfig.VirtioDevice, error) { func VirtIOFsToVFKitVirtIODevice(fs machine.VirtIoFs) vfConfig.VirtioFs { return vfConfig.VirtioFs{ + DirectorySharingConfig: vfConfig.DirectorySharingConfig{ + MountTag: fs.Tag, + }, SharedDir: fs.Source, - MountTag: fs.Tag, } } diff --git a/vendor/github.com/crc-org/vfkit/pkg/config/json.go b/vendor/github.com/crc-org/vfkit/pkg/config/json.go index 15ba5bc566..8d7be70672 100644 --- a/vendor/github.com/crc-org/vfkit/pkg/config/json.go +++ b/vendor/github.com/crc-org/vfkit/pkg/config/json.go @@ -25,6 +25,7 @@ const ( vfGpu vmComponentKind = "virtiogpu" vfInput vmComponentKind = "virtioinput" usbMassStorage vmComponentKind = "usbmassstorage" + rosetta vmComponentKind = "rosetta" ) type jsonKind struct { @@ -112,6 +113,10 @@ func unmarshalDevice(rawMsg json.RawMessage) (VirtioDevice, error) { var newDevice VirtioFs err = json.Unmarshal(rawMsg, &newDevice) dev = &newDevice + case rosetta: + var newDevice RosettaShare + err = json.Unmarshal(rawMsg, &newDevice) + dev = &newDevice case vfRng: var newDevice VirtioRng err = json.Unmarshal(rawMsg, &newDevice) @@ -253,6 +258,17 @@ func (dev *VirtioFs) MarshalJSON() ([]byte, error) { }) } +func (dev *RosettaShare) MarshalJSON() ([]byte, error) { + type devWithKind struct { + jsonKind + RosettaShare + } + return json.Marshal(devWithKind{ + jsonKind: kind(rosetta), + RosettaShare: *dev, + }) +} + func (dev *VirtioRng) MarshalJSON() ([]byte, error) { type devWithKind struct { jsonKind diff --git a/vendor/github.com/crc-org/vfkit/pkg/config/virtio.go b/vendor/github.com/crc-org/vfkit/pkg/config/virtio.go index d145fde60b..318e08d75b 100644 --- a/vendor/github.com/crc-org/vfkit/pkg/config/virtio.go +++ b/vendor/github.com/crc-org/vfkit/pkg/config/virtio.go @@ -17,12 +17,12 @@ const ( VirtioInputKeyboardDevice = "keyboard" // Options for VirtioGPUResolution - VirtioGPUResolutionHeight = "height" VirtioGPUResolutionWidth = "width" + VirtioGPUResolutionHeight = "height" // Default VirtioGPU Resolution - defaultVirtioGPUResolutionHeight = 800 - defaultVirtioGPUResolutionWidth = 600 + defaultVirtioGPUResolutionWidth = 800 + defaultVirtioGPUResolutionHeight = 600 ) // VirtioInput configures an input device, such as a keyboard or pointing device @@ -32,8 +32,8 @@ type VirtioInput struct { } type VirtioGPUResolution struct { - Height int `json:"height"` Width int `json:"width"` + Height int `json:"height"` } // VirtioGPU configures a GPU device, such as the host computer's display @@ -61,10 +61,20 @@ type VirtioBlk struct { DeviceIdentifier string } +type DirectorySharingConfig struct { + MountTag string +} + // VirtioFs configures directory sharing between the guest and the host. type VirtioFs struct { + DirectorySharingConfig SharedDir string - MountTag string +} + +// RosettaShare configures rosetta support in the guest to run Intel binaries on Apple CPUs +type RosettaShare struct { + DirectorySharingConfig + InstallRosetta bool } // virtioRng configures a random number generator (RNG) device. @@ -131,6 +141,8 @@ func deviceFromCmdLine(deviceOpts string) (VirtioDevice, error) { } var dev VirtioDevice switch opts[0] { + case "rosetta": + dev = &RosettaShare{} case "virtio-blk": dev = virtioBlkNewEmpty() case "virtio-fs": @@ -268,15 +280,15 @@ func VirtioGPUNew() (VirtioDevice, error) { return &VirtioGPU{ UsesGUI: false, VirtioGPUResolution: VirtioGPUResolution{ - Height: defaultVirtioGPUResolutionHeight, Width: defaultVirtioGPUResolutionWidth, + Height: defaultVirtioGPUResolutionHeight, }, }, nil } func (dev *VirtioGPU) validate() error { if dev.Height < 1 || dev.Width < 1 { - return fmt.Errorf("Invalid dimensions for virtio-gpu device resolution: %dx%d", dev.Height, dev.Width) + return fmt.Errorf("Invalid dimensions for virtio-gpu device resolution: %dx%d", dev.Width, dev.Height) } return nil @@ -287,7 +299,7 @@ func (dev *VirtioGPU) ToCmdLine() ([]string, error) { return nil, err } - return []string{"--device", fmt.Sprintf("virtio-gpu,height=%d,width=%d", dev.Height, dev.Width)}, nil + return []string{"--device", fmt.Sprintf("virtio-gpu,width=%d,height=%d", dev.Width, dev.Height)}, nil } func (dev *VirtioGPU) FromOptions(options []option) error { @@ -545,8 +557,10 @@ func (dev *VirtioVsock) FromOptions(options []option) error { // mounted in the VM using `mount -t virtiofs mountTag /some/dir` func VirtioFsNew(sharedDir string, mountTag string) (VirtioDevice, error) { return &VirtioFs{ + DirectorySharingConfig: DirectorySharingConfig{ + MountTag: mountTag, + }, SharedDir: sharedDir, - MountTag: mountTag, }, nil } @@ -575,6 +589,46 @@ func (dev *VirtioFs) FromOptions(options []option) error { return nil } +// RosettaShare creates a new rosetta share for running x86_64 binaries on M1 machines. +// It will share a directory containing the linux rosetta binaries with the +// virtual machine. This directory can be mounted in the VM using `mount -t +// virtiofs mountTag /some/dir` +func RosettaShareNew(mountTag string) (VirtioDevice, error) { + return &RosettaShare{ + DirectorySharingConfig: DirectorySharingConfig{ + MountTag: mountTag, + }, + }, nil +} + +func (dev *RosettaShare) ToCmdLine() ([]string, error) { + if dev.MountTag == "" { + return nil, fmt.Errorf("rosetta shares require a mount tag to be specified") + } + builder := strings.Builder{} + builder.WriteString("rosetta") + fmt.Fprintf(&builder, ",mountTag=%s", dev.MountTag) + if dev.InstallRosetta { + builder.WriteString(",install") + } + + return []string{"--device", builder.String()}, nil +} + +func (dev *RosettaShare) FromOptions(options []option) error { + for _, option := range options { + switch option.key { + case "mountTag": + dev.MountTag = option.value + case "install": + dev.InstallRosetta = true + default: + return fmt.Errorf("Unknown option for rosetta share: %s", option.key) + } + } + return nil +} + type USBMassStorage struct { StorageConfig } diff --git a/vendor/modules.txt b/vendor/modules.txt index 442c61fbea..ffef349b11 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -409,7 +409,7 @@ github.com/coreos/stream-metadata-go/release github.com/coreos/stream-metadata-go/release/rhcos github.com/coreos/stream-metadata-go/stream github.com/coreos/stream-metadata-go/stream/rhcos -# github.com/crc-org/vfkit v0.1.1 +# github.com/crc-org/vfkit v0.1.2-0.20230829083117-09e62065eb6e ## explicit; go 1.18 github.com/crc-org/vfkit/pkg/cmdline github.com/crc-org/vfkit/pkg/config