From 2437803e5268005bba1bb6c6eeccbb1d21d41b3d Mon Sep 17 00:00:00 2001 From: Manuel Tellez Date: Wed, 21 Apr 2021 09:22:40 -0700 Subject: [PATCH] normalize windows path, change to GPT --- integrationtests/volume_test.go | 2 +- internal/os/disk/api.go | 2 +- internal/server/smb/server.go | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/integrationtests/volume_test.go b/integrationtests/volume_test.go index 7c80e2b8..e9a5d7a0 100644 --- a/integrationtests/volume_test.go +++ b/integrationtests/volume_test.go @@ -56,7 +56,7 @@ func diskInit(t *testing.T, vhdxPath, mountPath, testPluginPath string) string { var cmd, out string var err error const initialSize = 5 * 1024 * 1024 * 1024 - const partitionStyle = "MBR" + const partitionStyle = "GPT" cmd = fmt.Sprintf("mkdir %s", mountPath) if out, err = runPowershellCmd(cmd); err != nil { diff --git a/internal/os/disk/api.go b/internal/os/disk/api.go index bb3e0ce0..6abcde08 100644 --- a/internal/os/disk/api.go +++ b/internal/os/disk/api.go @@ -109,7 +109,7 @@ func (APIImplementor) IsDiskInitialized(diskID string) (bool, error) { } func (APIImplementor) InitializeDisk(diskID string) error { - cmd := fmt.Sprintf("Initialize-Disk -Number %s -PartitionStyle MBR", diskID) + cmd := fmt.Sprintf("Initialize-Disk -Number %s -PartitionStyle GPT", diskID) out, err := exec.Command("powershell", "/c", cmd).CombinedOutput() if err != nil { return fmt.Errorf("error initializing disk %s: %v, %v", diskID, out, err) diff --git a/internal/server/smb/server.go b/internal/server/smb/server.go index fc1cf0ea..380064bb 100644 --- a/internal/server/smb/server.go +++ b/internal/server/smb/server.go @@ -3,11 +3,11 @@ package smb import ( "context" "fmt" - "github.com/kubernetes-csi/csi-proxy/client/apiversion" fsserver "github.com/kubernetes-csi/csi-proxy/internal/server/filesystem" "github.com/kubernetes-csi/csi-proxy/internal/server/smb/internal" "k8s.io/klog/v2" + "strings" ) type Server struct { @@ -22,6 +22,11 @@ type API interface { RemoveSmbGlobalMapping(remotePath string) error } +func normalizeWindowsPath(path string) string { + normalizedPath := strings.Replace(path, "/", "\\", -1) + return normalizedPath +} + func NewServer(hostAPI API, fsServer *fsserver.Server) (*Server, error) { return &Server{ hostAPI: hostAPI, @@ -32,7 +37,7 @@ func NewServer(hostAPI API, fsServer *fsserver.Server) (*Server, error) { func (s *Server) NewSmbGlobalMapping(context context.Context, request *internal.NewSmbGlobalMappingRequest, version apiversion.Version) (*internal.NewSmbGlobalMappingResponse, error) { klog.V(4).Infof("calling NewSmbGlobalMapping with remote path %q", request.RemotePath) response := &internal.NewSmbGlobalMappingResponse{} - remotePath := request.RemotePath + remotePath := normalizeWindowsPath(request.RemotePath) localPath := request.LocalPath if remotePath == "" { @@ -90,7 +95,7 @@ func (s *Server) NewSmbGlobalMapping(context context.Context, request *internal. func (s *Server) RemoveSmbGlobalMapping(context context.Context, request *internal.RemoveSmbGlobalMappingRequest, version apiversion.Version) (*internal.RemoveSmbGlobalMappingResponse, error) { klog.V(4).Infof("calling RemoveSmbGlobalMapping with remote path %q", request.RemotePath) response := &internal.RemoveSmbGlobalMappingResponse{} - remotePath := request.RemotePath + remotePath := normalizeWindowsPath(request.RemotePath) if remotePath == "" { klog.Errorf("remote path is empty")