Skip to content

Commit fdaf92f

Browse files
committed
Use storage system volume ID for unmounting ephemeral volumes.
1 parent c4a6819 commit fdaf92f

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

service/mount.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,12 @@ func mkdir(path string) (bool, error) {
599599
// It determines this by checking to see if the volume is mounted anywhere else
600600
// other than the private mount.
601601
func unpublishVolume(
602-
req *csi.NodeUnpublishVolumeRequest,
602+
volumeID, targetPath string,
603603
privDir, device string, reqID string,
604604
) error {
605605
ctx := context.Background()
606-
id := req.GetVolumeId()
607606

608-
target := req.GetTargetPath()
609-
if target == "" {
607+
if targetPath == "" {
610608
return status.Error(codes.InvalidArgument,
611609
"target path required")
612610
}
@@ -616,17 +614,17 @@ func unpublishVolume(
616614
if err != nil {
617615
return status.Errorf(codes.Internal,
618616
"error getting block device for volume: %s, err: %s",
619-
id, err.Error())
617+
volumeID, err.Error())
620618
}
621619

622620
// Path to mount device to
623-
privTgt := getPrivateMountPoint(privDir, id)
621+
privTgt := getPrivateMountPoint(privDir, volumeID)
624622

625623
f := logrus.Fields{
626624
"device": sysDevice.RealDev,
627625
"privTgt": privTgt,
628626
"CSIRequestID": reqID,
629-
"target": target,
627+
"target": targetPath,
630628
}
631629

632630
mnts, err := gofsutil.GetMounts(ctx)
@@ -644,10 +642,10 @@ func unpublishVolume(
644642
if m.Path == privTgt {
645643
privMntExist = true
646644
Log.Printf("Found private mount for device %#v, private mount path: %s .", sysDevice, privTgt)
647-
} else if m.Path == target {
645+
} else if m.Path == targetPath {
648646
tgtMntExist = true
649647
deviceMount = m
650-
Log.Printf("Found target mount for device %#v, target mount path: %s .", sysDevice, target)
648+
Log.Printf("Found target mount for device %#v, target mount path: %s .", sysDevice, targetPath)
651649
}
652650
}
653651
}
@@ -656,12 +654,12 @@ func unpublishVolume(
656654
}
657655

658656
if tgtMntExist {
659-
Log.WithFields(f).Debug(fmt.Sprintf("Unmounting %s", target))
660-
if err := gofsutil.Unmount(ctx, target); err != nil {
657+
Log.WithFields(f).Debug(fmt.Sprintf("Unmounting %s", targetPath))
658+
if err := gofsutil.Unmount(ctx, targetPath); err != nil {
661659
return status.Errorf(codes.Internal,
662660
"Error unmounting target: %s", err.Error())
663661
}
664-
if err := removeWithRetry(target); err != nil {
662+
if err := removeWithRetry(targetPath); err != nil {
665663
return status.Errorf(codes.Internal,
666664
"Error remove target folder: %s", err.Error())
667665
}

service/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func (s *service) NodeUnpublishVolume(
371371
return &csi.NodeUnpublishVolumeResponse{}, nil
372372
}
373373

374-
if err := unpublishVolume(req, s.privDir, sdcMappedVol.SdcDevice, reqID); err != nil {
374+
if err := unpublishVolume(csiVolID, req.GetTargetPath(), s.privDir, sdcMappedVol.SdcDevice, reqID); err != nil {
375375
return nil, err
376376
}
377377

service/step_defs_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,15 +2854,12 @@ func (f *feature) iCallMountPublishVolume() error {
28542854
}
28552855

28562856
func (f *feature) iCallMountUnpublishVolume() error {
2857-
req := new(csi.NodeUnpublishVolumeRequest)
2858-
req.TargetPath = ""
2859-
err := unpublishVolume(req, "", "/bad/device", "1")
2857+
err := unpublishVolume("", "", "", "/bad/device", "1")
28602858
if err != nil {
28612859
fmt.Printf("NodeUnpublishVolume bad targetPath: %s\n", err.Error())
28622860
f.err = errors.New("error in unpublishVolume")
28632861
}
2864-
req.TargetPath = "/badpath"
2865-
err = unpublishVolume(req, "", "/bad/device", "1")
2862+
err = unpublishVolume("", "/badpath", "", "/bad/device", "1")
28662863
if err != nil {
28672864
fmt.Printf("NodeUnpublishVolume bad device : %s\n", err.Error())
28682865
f.err = errors.New("error in unpublishVolume")

0 commit comments

Comments
 (0)