Skip to content

Commit

Permalink
Ensure HyperV 9p mounts work when a dir doesn't exist
Browse files Browse the repository at this point in the history
Before, we required that the mount target exist and be a
directory for the 9p mount to successfully complete, which is not
how things are supposed to work - the user should be able to
mount anywhere. This should just be a simple mkdir, but with FCOS
the root directory is immutable so we need to undo that before we
can mkdir, and unfortunately we don't have a library that can do
chattr (and I didn't want to drag in a new dependency just for
that), so let's be gross and add it to the SSH command. I
aggressively dislike this but it does work.

[NO NEW TESTS NEEDED] Can worry about getting a more generic
mount test together for Machine later.

Signed-off-by: Matt Heon <mheon@redhat.com>
  • Loading branch information
mheon committed Feb 9, 2024
1 parent b7d15a2 commit de61dc1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/machine/hyperv/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package hyperv
import (
"errors"
"fmt"
"path"

"github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/hyperv/vsock"
Expand Down Expand Up @@ -40,7 +41,19 @@ func removeShares(mc *vmconfigs.MachineConfig) error {

func startShares(mc *vmconfigs.MachineConfig) error {
for _, mount := range mc.Mounts {
args := []string{"-q", "--", "sudo", "podman"}
args := []string{"-q", "--"}

cleanTarget := path.Clean(mount.Target)
requiresChattr := !strings.HasPrefix(cleanTarget, "/home") && !strings.HasPrefix(cleanTarget, "/mnt")
if requiresChattr {
args = append(args, "sudo", "chattr", "-i", "/", "; ")
}
args = append(args, "sudo", "mkdir", "-p", cleanTarget, "; ")
if requiresChattr {
args = append(args, "sudo", "chattr", "+i", "/", "; ")
}

args = append(args, "sudo", "podman"}
if logrus.IsLevelEnabled(logrus.DebugLevel) {
args = append(args, "--log-level=debug")
}
Expand Down

0 comments on commit de61dc1

Please sign in to comment.