From de61dc1526555b1950da9f0008c4dfa46ac55501 Mon Sep 17 00:00:00 2001 From: Matt Heon Date: Thu, 8 Feb 2024 14:37:14 -0500 Subject: [PATCH] Ensure HyperV 9p mounts work when a dir doesn't exist 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 --- pkg/machine/hyperv/volumes.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/machine/hyperv/volumes.go b/pkg/machine/hyperv/volumes.go index 8a802a35b8a9..89d2d9932f3f 100644 --- a/pkg/machine/hyperv/volumes.go +++ b/pkg/machine/hyperv/volumes.go @@ -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" @@ -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") }