From 251eb9b4b8dc52ca55f3903b64f4f7027343fd5b Mon Sep 17 00:00:00 2001 From: Viktor Kuzmin Date: Sun, 6 Aug 2023 23:23:54 +0300 Subject: Graceful stop with mounts cleanup --- pkg/driver/volume.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'pkg/driver/volume.go') diff --git a/pkg/driver/volume.go b/pkg/driver/volume.go index 5358700..e4e2cf3 100644 --- a/pkg/driver/volume.go +++ b/pkg/driver/volume.go @@ -13,7 +13,8 @@ import ( ) type Volume struct { - VolumeId string + VolumeId string + StagedPath string mounter Mounter unmounter Unmounter @@ -40,7 +41,17 @@ func (vol *Volume) Stage(stagingTargetPath string) error { } if u, err := vol.mounter.Mount(stagingTargetPath); err == nil { + if vol.StagedPath != "" { + if vol.StagedPath == stagingTargetPath { + glog.Warningf("staged path is already set to %s for volume %s", vol.StagedPath, vol.VolumeId) + } else { + glog.Warningf("staged path is already set to %s and differs from %s for volume %s", vol.StagedPath, stagingTargetPath, vol.VolumeId) + } + } + + vol.StagedPath = stagingTargetPath vol.unmounter = u + return nil } else { return err @@ -99,15 +110,21 @@ func (vol *Volume) Unstage(stagingTargetPath string) error { glog.V(0).Infof("unmounting volume %s from %s", vol.VolumeId, stagingTargetPath) if vol.unmounter == nil { - glog.Errorf("volume is not mounted: %s, path", vol.VolumeId, stagingTargetPath) + glog.Errorf("volume is not mounted: %s, path: %s", vol.VolumeId, stagingTargetPath) return nil } + if stagingTargetPath != vol.StagedPath { + glog.Warningf("staging path %s differs for volume %s at %s", stagingTargetPath, vol.VolumeId, vol.StagedPath) + } + if err := vol.unmounter.Unmount(); err != nil { + glog.Errorf("error unmounting volume during unstage: %s, err: %v", err) return err } if err := os.Remove(stagingTargetPath); err != nil && !os.IsNotExist(err) { + glog.Errorf("error removing staging path for volume %s at %s, err: %v", vol.VolumeId, stagingTargetPath, err) return err } -- cgit v1.2.3