@@ -20,9 +20,9 @@ import (
2020 "fmt"
2121 "math"
2222 "os"
23+ "path/filepath"
2324 "sort"
2425 "strconv"
25- "strings"
2626
2727 "github.com/golang/protobuf/ptypes"
2828
@@ -38,8 +38,6 @@ import (
3838
3939const (
4040 deviceID = "deviceID"
41- provisionRoot = "/csi-data-dir"
42- snapshotRoot = "/csi-data-dir"
4341 maxStorageCapacity = tib
4442)
4543
@@ -251,6 +249,11 @@ func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
251249 return nil , status .Error (codes .Unimplemented , "" )
252250}
253251
252+ // getSnapshotPath returns the full path to where the snapshot is stored
253+ func getSnapshotPath (snapshotId string ) string {
254+ return filepath .Join (dataRoot , fmt .Sprintf ("%s.tgz" , snapshotId ))
255+ }
256+
254257// CreateSnapshot uses tar command to create snapshot for hostpath volume. The tar command can quickly create
255258// archives of entire directories. The host image must have "tar" binaries in /bin, /usr/sbin, or /usr/bin.
256259func (cs * controllerServer ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
@@ -296,8 +299,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
296299 snapshotID := uuid .NewUUID ().String ()
297300 creationTime := ptypes .TimestampNow ()
298301 volPath := hostPathVolume .VolPath
299- filePath := []string {snapshotRoot , "/" , snapshotID , ".tgz" }
300- file := strings .Join (filePath , "" )
302+ file := getSnapshotPath (snapshotID )
301303 args := []string {}
302304 if hostPathVolume .VolAccessType == blockAccess {
303305 glog .V (4 ).Infof ("Creating snapshot of Raw Block Mode Volume" )
@@ -346,9 +348,8 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
346348 return nil , err
347349 }
348350 snapshotID := req .GetSnapshotId ()
349- glog .V (4 ).Infof ("deleting volume %s" , snapshotID )
350- pathSlice := []string {snapshotRoot , "/" , snapshotID , ".tgz" }
351- path := strings .Join (pathSlice , "" )
351+ glog .V (4 ).Infof ("deleting snapshot %s" , snapshotID )
352+ path := getSnapshotPath (snapshotID )
352353 os .RemoveAll (path )
353354 delete (hostPathVolumeSnapshots , snapshotID )
354355 return & csi.DeleteSnapshotResponse {}, nil
0 commit comments