1
+ /*
2
+ Copyright © 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+ Unless required by applicable law or agreed to in writing, software
9
+ distributed under the License is distributed on an "AS IS" BASIS,
10
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ See the License for the specific language governing permissions and
12
+ limitations under the License.
13
+ */
14
+
1
15
package file
2
16
3
17
import (
@@ -295,13 +309,13 @@ func StageFileSystem(ctx context.Context, reqID, symID, fsID string, privTgt str
295
309
// staging already done
296
310
return & csi.NodeStageVolumeResponse {}, nil
297
311
}
298
- if err := os . MkdirAll (privTgt , 0o750 ); err != nil {
312
+ if err := MkdirAll (privTgt , 0o750 ); err != nil {
299
313
return nil , status .Errorf (codes .Internal ,
300
314
"can't create target folder %s: %s" , privTgt , err .Error ())
301
315
}
302
316
log .Info ("stage path successfully created" )
303
317
304
- if err := gofsutil . Mount (ctx , nfsExportPath , privTgt , "nfs" ); err != nil {
318
+ if err := Mount (ctx , nfsExportPath , privTgt , "nfs" ); err != nil {
305
319
return nil , status .Errorf (codes .Internal ,
306
320
"error mount nfs share %s to target path: %s" , nfsExportPath , err .Error ())
307
321
}
@@ -344,7 +358,7 @@ func PublishFileSystem(ctx context.Context, req *csi.NodePublishVolumeRequest, r
344
358
return & csi.NodePublishVolumeResponse {}, nil
345
359
}
346
360
347
- if err := os . MkdirAll (targetPath , 0o750 ); err != nil {
361
+ if err := MkdirAll (targetPath , 0o750 ); err != nil {
348
362
return nil , status .Errorf (codes .Internal ,
349
363
"can't create target folder %s: %s" , targetPath , err .Error ())
350
364
}
@@ -357,7 +371,7 @@ func PublishFileSystem(ctx context.Context, req *csi.NodePublishVolumeRequest, r
357
371
mntFlags = append (mntFlags , "ro" )
358
372
}
359
373
stagingPath := req .GetStagingTargetPath ()
360
- if err := gofsutil . BindMount (ctx , stagingPath , targetPath , mntFlags ... ); err != nil {
374
+ if err := BindMount (ctx , stagingPath , targetPath , mntFlags ... ); err != nil {
361
375
return nil , status .Errorf (codes .Internal ,
362
376
"error bind disk %s to target path %s: err %s" , stagingPath , targetPath , err .Error ())
363
377
}
@@ -438,7 +452,7 @@ func isAlreadyPublished(targetPath string) (bool, error) {
438
452
439
453
func getTargetMount (target string ) (gofsutil.Info , bool , error ) {
440
454
var targetMount gofsutil.Info
441
- mounts , err := gofsutil . GetMounts (context .Background ())
455
+ mounts , err := GetMounts (context .Background ())
442
456
if err != nil {
443
457
log .Error ("could not reliably determine existing mount status" )
444
458
return targetMount , false , status .Error (codes .Internal , "could not reliably determine existing mount status" )
@@ -453,3 +467,19 @@ func getTargetMount(target string) (gofsutil.Info, bool, error) {
453
467
}
454
468
return targetMount , found , nil
455
469
}
470
+
471
+ var GetMounts = func (ctx context.Context ) ([]gofsutil.Info , error ) {
472
+ return gofsutil .GetMounts (ctx )
473
+ }
474
+
475
+ var Mount = func (ctx context.Context , source string , target string , fstype string , options ... string ) error {
476
+ return gofsutil .Mount (ctx , source , target , fstype , options ... )
477
+ }
478
+
479
+ var BindMount = func (ctx context.Context , source string , target string , options ... string ) error {
480
+ return gofsutil .BindMount (ctx , source , target , options ... )
481
+ }
482
+
483
+ var MkdirAll = func (path string , perm os.FileMode ) error {
484
+ return os .MkdirAll (path , perm )
485
+ }
0 commit comments