@@ -143,6 +143,8 @@ type service struct {
143
143
driveMountStubs []MountableStubDrive
144
144
exitAfterAllTasksDeleted bool // exit the VM and shim when all tasks are deleted
145
145
146
+ blockDeviceTasks map [string ]struct {}
147
+
146
148
cleanupErr error
147
149
cleanupOnce sync.Once
148
150
@@ -216,9 +218,10 @@ func NewService(shimCtx context.Context, id string, remotePublisher shim.Publish
216
218
217
219
config : cfg ,
218
220
219
- vmReady : make (chan struct {}),
220
- jailer : newNoopJailer (shimCtx , logger , shimDir ),
221
- fifos : make (map [string ]map [string ]cio.Config ),
221
+ vmReady : make (chan struct {}),
222
+ jailer : newNoopJailer (shimCtx , logger , shimDir ),
223
+ blockDeviceTasks : make (map [string ]struct {}),
224
+ fifos : make (map [string ]map [string ]cio.Config ),
222
225
}
223
226
224
227
s .startEventForwarders (remotePublisher )
@@ -1188,6 +1191,7 @@ func (s *service) Create(requestCtx context.Context, request *taskAPI.CreateTask
1188
1191
logger .WithError (err ).Error ()
1189
1192
return nil , err
1190
1193
}
1194
+ s .blockDeviceTasks [request .ID ] = struct {}{}
1191
1195
}
1192
1196
1193
1197
ociConfigBytes , err := hostBundleDir .OCIConfig ().Bytes ()
@@ -1278,11 +1282,14 @@ func (s *service) Delete(requestCtx context.Context, req *taskAPI.DeleteRequest)
1278
1282
if req .ExecID != "" {
1279
1283
return resp , nil
1280
1284
}
1285
+
1281
1286
var result * multierror.Error
1282
- // Trying to release stub drive for further reuse
1283
- err = s .containerStubHandler .Release (requestCtx , req .ID , s .driveMountClient , s .machine )
1284
- if err != nil {
1285
- result = multierror .Append (result , errors .Wrapf (err , "failed to release stub drive for container: %s" , req .ID ))
1287
+
1288
+ if _ , contains := s .blockDeviceTasks [req .ID ]; contains {
1289
+ // Trying to release stub drive for further reuse
1290
+ if err := s .containerStubHandler .Release (requestCtx , req .ID , s .driveMountClient , s .machine ); err != nil {
1291
+ result = multierror .Append (errors .Wrapf (err , "failed to release stub drive for container: %s" , req .ID ))
1292
+ }
1286
1293
}
1287
1294
1288
1295
// Otherwise, delete the container
0 commit comments