/* Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package smb import ( "fmt" "github.com/container-storage-interface/spec/lib/go/csi" "k8s.io/klog/v2" "k8s.io/utils/mount" csicommon "github.com/kubernetes-csi/csi-driver-smb/pkg/csi-common" "github.com/kubernetes-csi/csi-driver-smb/pkg/mounter" ) const ( DriverName = "smb.csi.k8s.io" createSubDirField = "createsubdir" ) // Driver implements all interfaces of CSI drivers type Driver struct { csicommon.CSIDriver mounter *mount.SafeFormatAndMount } // NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version & // does not support optional driver plugin info manifest field. Refer to CSI spec for more details. func NewDriver(nodeID string) *Driver { driver := Driver{} driver.Name = DriverName driver.Version = driverVersion driver.NodeID = nodeID return &driver } // Run driver initialization func (d *Driver) Run(endpoint, kubeconfig string, testMode bool) { versionMeta, err := GetVersionYAML() if err != nil { klog.Fatalf("%v", err) } klog.Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta) d.mounter, err = mounter.NewSafeMounter() if err != nil { klog.Fatalf("Failed to get safe mounter. Error: %v", err) } // Initialize default library driver d.AddControllerServiceCapabilities( []csi.ControllerServiceCapability_RPC_Type{ csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME, }) d.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{ csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY, csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY, csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER, csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, }) d.AddNodeServiceCapabilities([]csi.NodeServiceCapability_RPC_Type{ csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME, }) s := csicommon.NewNonBlockingGRPCServer() // Driver d act as IdentityServer, ControllerServer and NodeServer s.Start(endpoint, d, d, d, testMode) s.Wait() } func IsCorruptedDir(dir string) bool { _, pathErr := mount.PathExists(dir) fmt.Printf("IsCorruptedDir(%s) returned with error: %v", dir, pathErr) return pathErr != nil && mount.IsCorruptedMnt(pathErr) }