Skip to content

Commit

Permalink
remove block file when losetup fails at creation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darkowlzz committed Mar 6, 2019
1 parent 840f6ca commit 59a11f8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volPathHandler := volumepathhandler.VolumePathHandler{}
_, err = volPathHandler.AttachFileDevice(path)
if err != nil {
glog.Errorf("failed to attach device: %v", err)
// Remove the block file because it'll no longer be used again.
if err2 := os.Remove(path); err != nil {
glog.Errorf("failed to cleanup block file %s: %v", path, err2)
}
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to attach device: %v", err))
}
case mountAccess:
Expand Down

0 comments on commit 59a11f8

Please sign in to comment.