Skip to content

Commit a392897

Browse files
authored
Merge pull request kubernetes#79784 from cwdsuzhou/July/RemoveDeviceVolumeDir
Bugfix: remove PV dir when umount raw block device
2 parents 2b4dc31 + f30a549 commit a392897

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/volume/csi/csi_block.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"os"
24+
"path"
2425
"path/filepath"
2526

2627
"k8s.io/klog"
@@ -361,5 +362,25 @@ func (m *csiBlockMapper) TearDownDevice(globalMapPath, devicePath string) error
361362
}
362363
}
363364

365+
dataDir := getVolumeDeviceDataDir(m.specName, m.plugin.host)
366+
367+
// remove ~/${pv}/data/vol_data.json first, then remove the other dir.
368+
volDataFile := path.Join(dataDir, volDataFileName)
369+
err = os.Remove(volDataFile)
370+
if err != nil && !os.IsNotExist(err) {
371+
return err
372+
}
373+
// remove ~/${pv}/data
374+
err = os.Remove(dataDir)
375+
if err != nil && !os.IsNotExist(err) {
376+
return err
377+
}
378+
379+
// remove ~/${pv}
380+
pvPath := filepath.Dir(dataDir)
381+
err = os.Remove(pvPath)
382+
if err != nil && !os.IsNotExist(err) {
383+
return err
384+
}
364385
return nil
365386
}

0 commit comments

Comments
 (0)