Skip to content

Commit

Permalink
vfkit: Don't try to use virtiofs it's unsupported
Browse files Browse the repository at this point in the history
virtiofs file sharing is only available in macOS 12 and newer. This
commit makes use of sw_vers to return a proper error when running on too
old macOS versions.
This also skips vfkit shared directory configuration so that we can
start the VM anyway.
For all of this to work, vfkit has to be built on a macOS 11 builder,
the file sharing APIs will still be available when this binary is run on
macOS 12.
Building vfkit on macOS 12 and trying to run the resulting binary on
macOS 11 will badly fail though:

```
DEBU Running '/Users/teuf/.crc/bin/vfkit -v'
DEBU Command failed: signal: abort trap
DEBU stdout:
DEBU stderr: dyld: Symbol not found:
_OBJC_CLASS_$_VZMultipleDirectoryShare
  Referenced from: /Users/teuf/.crc/bin/vfkit (which was built for Mac OS X 12.0)
  Expected in:
/System/Library/Frameworks/Virtualization.framework/Versions/A/Virtualization
 in /Users/teuf/.crc/bin/vfkit
DEBU failed to run executable /Users/teuf/.crc/bin/vfkit: signal: abort trap
```
  • Loading branch information
cfergeau authored and anjannath committed Aug 4, 2022
1 parent 50faa96 commit 038c43b
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions pkg/drivers/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,18 @@ func (d *Driver) Start() error {
}

// shared directories
for _, sharedDir := range d.SharedDirs {
// TODO: add support for 'mount.ReadOnly'
// TODO: check format
dev, err := client.VirtioFsNew(sharedDir.Source, sharedDir.Tag)
if err != nil {
return err
}
err = vm.AddDevice(dev)
if err != nil {
return err
if d.supportsVirtiofs() {
for _, sharedDir := range d.SharedDirs {
// TODO: add support for 'mount.ReadOnly'
// TODO: check format
dev, err := client.VirtioFsNew(sharedDir.Source, sharedDir.Tag)
if err != nil {
return err
}
err = vm.AddDevice(dev)
if err != nil {
return err
}
}
}

Expand Down Expand Up @@ -279,6 +281,9 @@ func (d *Driver) Start() error {
}

func (d *Driver) GetSharedDirs() ([]drivers.SharedDir, error) {
if !d.supportsVirtiofs() {
return nil, drivers.ErrNotSupported
}
// check if host supports file sharing, return drivers.ErrNotSupported if not
return d.SharedDirs, nil
}
Expand Down Expand Up @@ -461,3 +466,11 @@ func (d *Driver) sendSignal(s syscall.Signal) error {

return proc.SendSignal(s)
}

func (d *Driver) supportsVirtiofs() bool {
macosVersion, _, err := crcos.RunWithDefaultLocale("sw_vers", "-productVersion")
if err != nil {
return false
}
return strings.HasPrefix(macosVersion, "12.")
}

0 comments on commit 038c43b

Please sign in to comment.