diff --git a/pkg/hostpath/controllerserver.go b/pkg/hostpath/controllerserver.go index acc121cfb..6f962fdc9 100644 --- a/pkg/hostpath/controllerserver.go +++ b/pkg/hostpath/controllerserver.go @@ -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: diff --git a/pkg/hostpath/hostpath.go b/pkg/hostpath/hostpath.go index f7db55e73..d01e88516 100644 --- a/pkg/hostpath/hostpath.go +++ b/pkg/hostpath/hostpath.go @@ -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. @@ -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 {