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

[WIP] Volume mount paths compatibility on darwin #13453

Closed
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
18 changes: 6 additions & 12 deletions pkg/machine/qemu/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func GetQemuProvider() machine.Provider {
return qemuProvider
}

func getCoreOSTargetMountPath(targetMountPath string) string {
return "/mnt" + targetMountPath
}

const (
VolumeTypeVirtfs = "virtfs"
MountType9p = "9p"
Expand Down Expand Up @@ -246,7 +250,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
virtfsOptions += ",readonly"
}
v.CmdLine = append(v.CmdLine, []string{"-virtfs", virtfsOptions}...)
mounts = append(mounts, Mount{Type: MountType9p, Tag: tag, Source: source, Target: target, ReadOnly: readonly})
mounts = append(mounts, Mount{Type: MountType9p, Tag: tag, Source: source, Target: getCoreOSTargetMountPath(target), ReadOnly: readonly})
}
}
v.Mounts = mounts
Expand Down Expand Up @@ -479,17 +483,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
for _, mount := range v.Mounts {
fmt.Printf("Mounting volume... %s:%s\n", mount.Source, mount.Target)
// create mountpoint directory if it doesn't exist
// because / is immutable, we have to monkey around with permissions
// if we dont mount in /home or /mnt
args := []string{"-q", "--"}
if !strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt") {
args = append(args, "sudo", "chattr", "-i", "/", ";")
}
args = append(args, "sudo", "mkdir", "-p", mount.Target)
if !strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt") {
args = append(args, ";", "sudo", "chattr", "+i", "/", ";")
}
err = v.SSH(name, machine.SSHOptions{Args: args})
err = v.SSH(name, machine.SSHOptions{Args: []string{"-q", "--", "sudo", "mkdir", "-p", mount.Target}})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/specgenutil/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func parseVolumes(volumeFlag, mountFlag, tmpfsFlag []string, addReadOnlyTmpfs bo
if err != nil {
return nil, nil, nil, nil, errors.Wrapf(err, "error getting absolute path of %s", mount.Source)
}
mount.Source = absSrc
mount.Source = util.GetSrcMountPath(absSrc)
}
finalMounts = append(finalMounts, mount)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/utils_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ import (
func GetContainerPidInformationDescriptors() ([]string, error) {
return []string{}, errors.New("this function is not supported on darwin")
}

func GetSrcMountPath(absolutePath string) string {
return "/mnt" + absolutePath
}
4 changes: 4 additions & 0 deletions pkg/util/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func GetContainerPidInformationDescriptors() ([]string, error) {
return psgo.ListDescriptors(), nil
}

func GetSrcMountPath(absolutePath string) string {
return absolutePath
}

// FindDeviceNodes parses /dev/ into a set of major:minor -> path, where
// [major:minor] is the device's major and minor numbers formatted as, for
// example, 2:0 and path is the path to the device node.
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ func GetRuntimeDir() (string, error) {
func GetRootlessConfigHomeDir() (string, error) {
return "", errors.New("this function is not implemented for windows")
}

func GetSrcMountPath(absolutePath string) string {
return "/mnt" + absolutePath
}