diff --git a/pkg/nas/nodeserver.go b/pkg/nas/nodeserver.go index 365e07c94..2623f1f7b 100644 --- a/pkg/nas/nodeserver.go +++ b/pkg/nas/nodeserver.go @@ -441,7 +441,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis } //mount nas client - if err := doMount(ns.mounter, opt, mountPath, req.VolumeId, podUID); err != nil { + if err := doMount(ns.mounter, opt, mountPath, req.VolumeId, podUID, ns.config.AgentMode); err != nil { return nil, status.Error(codes.Internal, err.Error()) } if opt.MountProtocol == "efc" { @@ -575,7 +575,7 @@ func (ns *nodeServer) mountLosetupPv(mountPoint string, opt *Options, volumeID s return fmt.Errorf("mountLosetupPv: create nfs mountPath error %s ", err.Error()) } //mount nas to use losetup dev - err := doMount(ns.mounter, opt, nfsPath, volumeID, podID) + err := doMount(ns.mounter, opt, nfsPath, volumeID, podID, ns.config.AgentMode) if err != nil { return fmt.Errorf("mountLosetupPv: mount losetup volume failed: %s", err.Error()) } diff --git a/pkg/nas/utils.go b/pkg/nas/utils.go index b0dd92d61..7970a1ceb 100644 --- a/pkg/nas/utils.go +++ b/pkg/nas/utils.go @@ -66,7 +66,7 @@ type RoleAuth struct { Code string } -func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, podUid string) error { +func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, podUid string, agentMode bool) error { var ( mountFstype string source string @@ -94,9 +94,7 @@ func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, p } mountFstype = "alinas" // err = mounter.Mount(source, mountPoint, "alinas", combinedOptions) - isPathNotFound = func(err error) bool { - return strings.Contains(err.Error(), "Failed to bind mount") - } + isPathNotFound = isEFCPathNotFoundError case NativeClient: switch opt.FSType { case "cpfs": @@ -115,17 +113,20 @@ func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, p // must enable tls when using accesspoint combinedOptions = addTLSMountOptions(combinedOptions) } + isPathNotFound = isNFSPathNotFoundError // Enable compatibility for BMCPFS VPC mount points using the NAS Driver, to support the same usage in ECI. if isCPFS(opt.FSType, opt.Server) && opt.MountProtocol == "efc" { mountFstype = "alinas" combinedOptions = append(combinedOptions, "efc,protocol=efc,net=tcp,fstype=cpfs") + if agentMode { + isPathNotFound = isEFCPathNotFoundError + } else { + klog.V(4).InfoS("CSI will only auto create directory under agent mode when using EFC mount protocol.") + } } if mountFstype == "" { mountFstype = opt.MountProtocol } - isPathNotFound = func(err error) bool { - return strings.Contains(err.Error(), "reason given by server: No such file or directory") || strings.Contains(err.Error(), "access denied by server while mounting") - } } err := mounter.Mount(source, targetPath, mountFstype, combinedOptions) if err == nil { @@ -166,6 +167,23 @@ func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, p return mounter.Mount(source, targetPath, mountFstype, combinedOptions) } +func isEFCPathNotFoundError(err error) bool { + return strings.Contains(err.Error(), "Failed to bind mount") +} + +func isNFSPathNotFoundError(err error) bool { + errors := []string{ + "reason given by server: No such file or directory", + "access denied by server while mounting", + } + for _, error := range errors { + if strings.Contains(err.Error(), error) { + return true + } + } + return false +} + // check system config, // if tcp_slot_table_entries not set to 128, just config. func checkSystemNasConfig() error {