Skip to content

Commit 59a11f8

Browse files
committed
remove block file when losetup fails at creation
This change logs the attach device failure while creating a block volume and tries to remove the associated block file which will not be reused.
1 parent 840f6ca commit 59a11f8

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)