Skip to content

Commit 55ad3a4

Browse files
committed
fix(nas): sub directory not created when mounting cpfs with efc protocol
1 parent 46b9226 commit 55ad3a4

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

pkg/nas/nodeserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
441441
}
442442

443443
//mount nas client
444-
if err := doMount(ns.mounter, opt, mountPath, req.VolumeId, podUID); err != nil {
444+
if err := doMount(ns.mounter, opt, mountPath, req.VolumeId, podUID, ns.config.AgentMode); err != nil {
445445
return nil, status.Error(codes.Internal, err.Error())
446446
}
447447
if opt.MountProtocol == "efc" {
@@ -575,7 +575,7 @@ func (ns *nodeServer) mountLosetupPv(mountPoint string, opt *Options, volumeID s
575575
return fmt.Errorf("mountLosetupPv: create nfs mountPath error %s ", err.Error())
576576
}
577577
//mount nas to use losetup dev
578-
err := doMount(ns.mounter, opt, nfsPath, volumeID, podID)
578+
err := doMount(ns.mounter, opt, nfsPath, volumeID, podID, ns.config.AgentMode)
579579
if err != nil {
580580
return fmt.Errorf("mountLosetupPv: mount losetup volume failed: %s", err.Error())
581581
}

pkg/nas/utils.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type RoleAuth struct {
6666
Code string
6767
}
6868

69-
func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, podUid string) error {
69+
func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, podUid string, agentMode bool) error {
7070
var (
7171
mountFstype string
7272
source string
@@ -94,9 +94,7 @@ func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, p
9494
}
9595
mountFstype = "alinas"
9696
// err = mounter.Mount(source, mountPoint, "alinas", combinedOptions)
97-
isPathNotFound = func(err error) bool {
98-
return strings.Contains(err.Error(), "Failed to bind mount")
99-
}
97+
isPathNotFound = isEFCPathNotFoundError
10098
case NativeClient:
10199
switch opt.FSType {
102100
case "cpfs":
@@ -115,17 +113,20 @@ func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, p
115113
// must enable tls when using accesspoint
116114
combinedOptions = addTLSMountOptions(combinedOptions)
117115
}
116+
isPathNotFound = isNFSPathNotFoundError
118117
// Enable compatibility for BMCPFS VPC mount points using the NAS Driver, to support the same usage in ECI.
119118
if isCPFS(opt.FSType, opt.Server) && opt.MountProtocol == "efc" {
120119
mountFstype = "alinas"
121120
combinedOptions = append(combinedOptions, "efc,protocol=efc,net=tcp,fstype=cpfs")
121+
if agentMode {
122+
isPathNotFound = isEFCPathNotFoundError
123+
} else {
124+
klog.V(4).InfoS("CSI will only auto create directory under agent mode when using EFC mount protocol.")
125+
}
122126
}
123127
if mountFstype == "" {
124128
mountFstype = opt.MountProtocol
125129
}
126-
isPathNotFound = func(err error) bool {
127-
return strings.Contains(err.Error(), "reason given by server: No such file or directory") || strings.Contains(err.Error(), "access denied by server while mounting")
128-
}
129130
}
130131
err := mounter.Mount(source, targetPath, mountFstype, combinedOptions)
131132
if err == nil {
@@ -166,6 +167,23 @@ func doMount(mounter mountutils.Interface, opt *Options, targetPath, volumeId, p
166167
return mounter.Mount(source, targetPath, mountFstype, combinedOptions)
167168
}
168169

170+
func isEFCPathNotFoundError(err error) bool {
171+
return strings.Contains(err.Error(), "Failed to bind mount")
172+
}
173+
174+
func isNFSPathNotFoundError(err error) bool {
175+
errors := []string{
176+
"reason given by server: No such file or directory",
177+
"access denied by server while mounting",
178+
}
179+
for _, error := range errors {
180+
if strings.Contains(err.Error(), error) {
181+
return true
182+
}
183+
}
184+
return false
185+
}
186+
169187
// check system config,
170188
// if tcp_slot_table_entries not set to 128, just config.
171189
func checkSystemNasConfig() error {

0 commit comments

Comments
 (0)