Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volumeSource := req.VolumeContentSource
switch volumeSource.Type.(type) {
case *csi.VolumeContentSource_Snapshot:
if volumeSource.GetSnapshot() != nil && exVol.ParentSnapID != volumeSource.GetSnapshot().GetSnapshotId() {
if volumeSource.GetSnapshot() != nil && exVol.ParentSnapID != "" && exVol.ParentSnapID != volumeSource.GetSnapshot().GetSnapshotId() {
return nil, status.Error(codes.AlreadyExists, "existing volume source snapshot id not matching")
}
case *csi.VolumeContentSource_Volume:
Expand Down
12 changes: 10 additions & 2 deletions pkg/hostpath/hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,16 @@ func createHostpathVolume(volID, name string, cap int64, volAccessType accessTyp
executor := utilexec.New()
size := fmt.Sprintf("%dM", cap/mib)
// Create a block file.
out, err := executor.Command("fallocate", "-l", size, path).CombinedOutput()
_, err := os.Stat(path)
if err != nil {
return nil, fmt.Errorf("failed to create block device: %v, %v", err, string(out))
if os.IsNotExist(err) {
out, err := executor.Command("fallocate", "-l", size, path).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("failed to create block device: %v, %v", err, string(out))
}
} else {
return nil, fmt.Errorf("failed to stat block device: %v, %v", path, err)
}
}

// Associate block file with the loop device.
Expand Down Expand Up @@ -335,6 +342,7 @@ func loadFromSnapshot(size int64, snapshotId, destPath string, mode accessType)
default:
return status.Errorf(codes.InvalidArgument, "unknown accessType: %d", mode)
}

executor := utilexec.New()
out, err := executor.Command(cmd[0], cmd[1:]...).CombinedOutput()
if err != nil {
Expand Down