Skip to content

Commit 51278a4

Browse files
authored
Merge pull request kubernetes-csi#25 from darkowlzz/hostpath-23
remove block file when losetup fails at volume creation
2 parents 840f6ca + 59a11f8 commit 51278a4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/hostpath/controllerserver.go

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
153153
volPathHandler := volumepathhandler.VolumePathHandler{}
154154
_, err = volPathHandler.AttachFileDevice(path)
155155
if err != nil {
156+
glog.Errorf("failed to attach device: %v", err)
157+
// Remove the block file because it'll no longer be used again.
158+
if err2 := os.Remove(path); err != nil {
159+
glog.Errorf("failed to cleanup block file %s: %v", path, err2)
160+
}
156161
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to attach device: %v", err))
157162
}
158163
case mountAccess:

0 commit comments

Comments
 (0)