diff --git a/pkg/nas/controllerserver.go b/pkg/nas/controllerserver.go index 020c20ef0..6733b22d5 100644 --- a/pkg/nas/controllerserver.go +++ b/pkg/nas/controllerserver.go @@ -724,7 +724,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol if strings.Contains(nfsServer, ".nas.aliyuncs.com") && !strings.Contains(nfsServer, ".extreme.nas.aliyuncs.com") && !strings.Contains(nfsServer, ".cpfs.nas.aliyuncs.com") { - fileSystemID = GetFsIDByServer(nfsServer) + fileSystemID = GetFsIDByNasServer(nfsServer) if len(fileSystemID) != 0 { //1、Does describe dir quota exist? //2、If the dir quota exists, cancel the quota before deleting the subdirectory. diff --git a/pkg/nas/nodeserver.go b/pkg/nas/nodeserver.go index 22edc1998..e7877b0b3 100644 --- a/pkg/nas/nodeserver.go +++ b/pkg/nas/nodeserver.go @@ -87,6 +87,8 @@ const ( NasMntPoint = "/mnt/nasplugin.alibabacloud.com" // MountProtocolNFS common nfs protocol MountProtocolNFS = "nfs" + // MountProtocolCPFS common cpfs protocol + MountProtocolCPFSEAC = "cpfs-eac" // MountProtocolCPFSNFS cpfs-nfs protocol MountProtocolCPFSNFS = "cpfs-nfs" // MountProtocolAliNas alinas protocal @@ -163,6 +165,12 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis } opt.Server = cnfs.Status.FsAttributes.Server useEaClient = cnfs.Status.FsAttributes.UseElasticAccelerationClient + if cnfs.Status.FsAttributes.FilesystemType == "cpfs" { + opt.MountProtocol = MountProtocolCPFSNFS + if useEaClient == "true" { + opt.MountProtocol = MountProtocolCPFSEAC + } + } } if opt.LoopLock != "false" { @@ -230,7 +238,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis doNfsPortCheck = false } if (opt.MountProtocol == MountProtocolNFS || opt.MountProtocol == MountProtocolAliNas) && doNfsPortCheck { - conn, err := net.DialTimeout("tcp", opt.Server+":"+NasPortnum, time.Second*time.Duration(3)) + conn, err := net.DialTimeout("tcp", opt.Server+":"+NasPortnum, time.Second*time.Duration(30)) if err != nil { log.Errorf("NAS: Cannot connect to nas host: %s", opt.Server) return nil, errors.New("NAS: Cannot connect to nas host: " + opt.Server) @@ -241,7 +249,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis if opt.Path == "" { opt.Path = "/" } - // remove / if path end with /; + // if path end with /, remove /; if opt.Path != "/" && strings.HasSuffix(opt.Path, "/") { opt.Path = opt.Path[0 : len(opt.Path)-1] } @@ -279,7 +287,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis // Create Mount Path if err := utils.CreateDest(mountPath); err != nil { - return nil, errors.New("Nas, Mount error with create Path fail: " + mountPath) + return nil, errors.New("Create mount path is failed, mountPath: " + mountPath + ", err:" + err.Error()) } // if volume set mountType as skipmount; @@ -314,9 +322,9 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis checkSystemNasConfig() //cpfs-nfs check valid - if opt.MountProtocol == MountProtocolCPFSNFS { + if opt.MountProtocol == MountProtocolCPFSNFS || opt.MountProtocol == MountProtocolCPFSEAC { if !strings.HasPrefix(opt.Path, "/share") { - return nil, errors.New("The path to cpfs-nfs must start with /share.") + return nil, errors.New("The cpfs2.0 mount path must start with /share.") } } @@ -331,11 +339,19 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis log.Errorf("Nas, Mount Nfs error: %s", err.Error()) return nil, errors.New("Nas, Mount Nfs error:" + err.Error()) } - if strings.Contains(opt.Server, ".nas.aliyuncs.com") && useEaClient == "true" { - fsID := GetFsIDByServer(opt.Server) - if len(fsID) != 0 { - utils.WriteMetricsInfo(metricsPathPrefix, req, "10", "eac", "nas", fsID) + if useEaClient == "true" { + if strings.Contains(opt.Server, ".nas.aliyuncs.com") { + fsID := GetFsIDByNasServer(opt.Server) + if len(fsID) != 0 { + utils.WriteMetricsInfo(metricsPathPrefix, req, "10", "eac", "nas", fsID) + } + } else { + fsID := GetFsIDByCpfsServer(opt.Server) + if len(fsID) != 0 { + utils.WriteMetricsInfo(metricsPathPrefix, req, "10", "eac", "cpfs", fsID) + } } + } // change the mode if opt.Mode != "" && opt.Path != "/" { diff --git a/pkg/nas/utils.go b/pkg/nas/utils.go index 5a7f37f4e..e01c3361c 100644 --- a/pkg/nas/utils.go +++ b/pkg/nas/utils.go @@ -84,7 +84,7 @@ type RoleAuth struct { // DoMount execute the mount command for nas dir func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint, volumeID, podUID, useEaClient string) error { if !utils.IsFileExisting(mountPoint) { - CreateDest(mountPoint) + _ = CreateDest(mountPoint) } if CheckNfsPathMounted(mountPoint, nfsPath) { @@ -96,12 +96,13 @@ func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint, var err error //EAC Mount if len(useEaClient) != 0 && useEaClient == "true" { - mntCmd = fmt.Sprintf("systemd-run --scope -- mount -t alinas -o eac -o bindtag=%s -o client_owner=%s -o %s %s:%s %s", volumeID, podUID, mountOptions, nfsServer, nfsPath, mountPoint) - if err := utils.DoMountInHost(mntCmd); err != nil { - return err + if nfsProtocol == MountProtocolCPFSEAC { + mntCmd = fmt.Sprintf("systemd-run --scope -- mount -t alinas -o eac -o protocol=nfs3 -o bindtag=%s -o client_owner=%s -o %s %s:%s %s", volumeID, podUID, mountOptions, nfsServer, nfsPath, mountPoint) + } else { + mntCmd = fmt.Sprintf("systemd-run --scope -- mount -t alinas -o eac -o bindtag=%s -o client_owner=%s -o %s %s:%s %s", volumeID, podUID, mountOptions, nfsServer, nfsPath, mountPoint) } } else { - //NFS Mount(Capacity/Performance Extreme Nas、Cpfs2.0, AliNas) + //NFS Mount(Capacdity/Performance Extreme Nas、Cpfs2.0, AliNas) versStr := fmt.Sprintf("vers=%s", nfsVers) if mountOptions == "" { mountOptions = versStr @@ -114,11 +115,17 @@ func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint, } _, err = utils.Run(mntCmd) - //Mount rootpath is failed, return err + //try mount nfsPath is successfully. + if err == nil { + log.Infof("DoMount: Mount is successfully with command: %s", mntCmd) + return nil + } + + //mount root-path is failed, return error if err != nil && nfsPath == "/" { return err } - //Mount subpath is failed, if subpath is not exist or cpfs don't output subpath + //mount sub-path is failed, if subpath is not exist or cpfs don't output subpath if err != nil && nfsPath != "/" { //Other errors if !strings.Contains(err.Error(), "reason given by server: No such file or directory") && !strings.Contains(err.Error(), "access denied by server while mounting") { @@ -128,13 +135,19 @@ func DoMount(nfsProtocol, nfsServer, nfsPath, nfsVers, mountOptions, mountPoint, log.Errorf("DoMount: Create subpath is failed, err: %s", err.Error()) return err } - if _, err := utils.Run(mntCmd); err != nil { - log.Errorf("DoMount: Mount %s is failed, err: %s", mntCmd, err.Error()) - return err - } } } - log.Infof("DoMount: Mount nfs is successfully with command: %s", mntCmd) + //execute mount + if len(useEaClient) != 0 && useEaClient == "true" { + err = utils.DoMountInHost(mntCmd) + } else { + _, err = utils.Run(mntCmd) + } + if err != nil { + log.Errorf("DoMount: Mount %s is failed, err: %s", mntCmd, err.Error()) + return err + } + log.Infof("DoMount: Mount is successfully with command: %s", mntCmd) return nil } @@ -644,21 +657,21 @@ func getPvObj(volumeID string) (*v1.PersistentVolume, error) { func isValidCnfsParameter(server string, cnfsName string) error { if len(server) == 0 && len(cnfsName) == 0 { - msg := fmt.Sprintf("Server and ContainerNetworkFileSystem need to be configured at least one.") + msg := fmt.Sprintf("Server and Cnfs need to be configured at least one.") log.Errorf(msg) return errors.New(msg) } if len(server) != 0 && len(cnfsName) != 0 { - msg := fmt.Sprintf("Server and ContainerNetworkFileSystem can only be configured to use one.") + msg := fmt.Sprintf("Server and Cnfs can only be configured to use one.") log.Errorf(msg) return errors.New(msg) } return nil } -// GetFsIDByServer func is get fsID from serverName -func GetFsIDByServer(server string) string { +// GetFsIDByNasServer func is get fsID from serverName +func GetFsIDByNasServer(server string) string { if len(server) == 0 { return "" } @@ -666,6 +679,15 @@ func GetFsIDByServer(server string) string { return serverArray[0] } +// GetFsIDByCpfsServer func is get fsID from serverName +func GetFsIDByCpfsServer(server string) string { + if len(server) == 0 { + return "" + } + serverArray := strings.Split(server, "-") + return serverArray[0] + "-" + serverArray[1] +} + func saveVolumeData(opt *Options, mountPath string) { // save volume data to json file if utils.IsKataInstall() { diff --git a/pkg/utils/util.go b/pkg/utils/util.go index ae64fc035..b01e38a44 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -108,7 +108,7 @@ const ( fsckErrorsUncorrected = 4 // NsenterCmd is the nsenter command - NsenterCmd = "nsenter --mount=/proc/1/ns/mnt --ipc=/proc/1/ns/ipc --net=/proc/1/ns/net --uts=/proc/1/ns/uts " + NsenterCmd = "nsenter --mount=/proc/1/ns/mnt --ipc=/proc/1/ns/ipc --net=/proc/1/ns/net --uts=/proc/1/ns/uts" // socketPath is path of connector sock socketPath = "/host/etc/csi-tool/connector.sock"