@@ -22,6 +22,7 @@ import (
2222 "os"
2323 "sort"
2424 "strconv"
25+ "strings"
2526
2627 "github.com/golang/protobuf/ptypes"
2728
@@ -346,8 +347,16 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
346347 snapshotID := uuid .NewUUID ().String ()
347348 creationTime := ptypes .TimestampNow ()
348349 volPath := hostPathVolume .VolPath
349- file := snapshotRoot + snapshotID + ".tgz"
350- args := []string {"czf" , file , "-C" , volPath , "." }
350+ filePath := []string {snapshotRoot , "/" , snapshotID , ".tgz" }
351+ file := strings .Join (filePath , "" )
352+ args := []string {}
353+ if hostPathVolume .VolAccessType == blockAccess {
354+ glog .V (4 ).Infof ("Creating snapshot of Raw Block Mode Volume" )
355+ args = []string {"czf" , file , volPath }
356+ } else {
357+ glog .V (4 ).Infof ("Creating snapshot of Filsystem Mode Volume" )
358+ args = []string {"czf" , file , "-C" , volPath , "." }
359+ }
351360 executor := utilexec .New ()
352361 out , err := executor .Command ("tar" , args ... ).CombinedOutput ()
353362 if err != nil {
@@ -389,7 +398,8 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
389398 }
390399 snapshotID := req .GetSnapshotId ()
391400 glog .V (4 ).Infof ("deleting volume %s" , snapshotID )
392- path := snapshotRoot + snapshotID + ".tgz"
401+ pathSlice := []string {snapshotRoot , "/" , snapshotID , ".tgz" }
402+ path := strings .Join (pathSlice , "" )
393403 os .RemoveAll (path )
394404 delete (hostPathVolumeSnapshots , snapshotID )
395405 return & csi.DeleteSnapshotResponse {}, nil
0 commit comments