@@ -178,6 +178,18 @@ func (qc *QemuContext) Shutdown(ctx *hypervisor.VmContext) {
178
178
qmpQemuQuit (ctx , qc )
179
179
}
180
180
181
+ func (qc * QemuContext ) qmpSend (ctx * hypervisor.VmContext , s QmpInteraction ) {
182
+ ctx .Rlock ()
183
+ defer ctx .RUnlock ()
184
+ if ctx .IsClosedLocked () {
185
+ glog .Errorf ("Cannot send message to closed sandbox %s %+v" , ctx .Id , s )
186
+ } else {
187
+ glog .V (3 ).Infof ("Send message to sandbox %s start" , ctx .Id )
188
+ qc .qmp <- s
189
+ glog .V (3 ).Infof ("Send message to sandbox %s done" , ctx .Id )
190
+ }
191
+ }
192
+
181
193
func (qc * QemuContext ) Kill (ctx * hypervisor.VmContext ) {
182
194
defer func () {
183
195
err := recover ()
@@ -215,12 +227,12 @@ func (qc *QemuContext) Pause(ctx *hypervisor.VmContext, pause bool) error {
215
227
}
216
228
217
229
result := make (chan error , 1 )
218
- qc .qmp <- & QmpSession {
230
+ qc .qmpSend ( ctx , & QmpSession {
219
231
commands : commands ,
220
232
respond : func (err error ) {
221
233
result <- err
222
234
},
223
- }
235
+ })
224
236
return <- result
225
237
}
226
238
@@ -321,15 +333,15 @@ func (qc *QemuContext) SetCpus(ctx *hypervisor.VmContext, cpus int) error {
321
333
}
322
334
323
335
result := make (chan error , 1 )
324
- qc .qmp <- & QmpSession {
336
+ qc .qmpSend ( ctx , & QmpSession {
325
337
commands : commands ,
326
338
respond : func (err error ) {
327
339
if err == nil {
328
340
qc .cpus = cpus
329
341
}
330
342
result <- err
331
343
},
332
- }
344
+ })
333
345
return <- result
334
346
}
335
347
@@ -352,10 +364,10 @@ func (qc *QemuContext) AddMem(ctx *hypervisor.VmContext, slot, size int) error {
352
364
},
353
365
}
354
366
result := make (chan error , 1 )
355
- qc .qmp <- & QmpSession {
367
+ qc .qmpSend ( ctx , & QmpSession {
356
368
commands : commands ,
357
369
respond : func (err error ) { result <- err },
358
- }
370
+ })
359
371
return <- result
360
372
}
361
373
@@ -385,10 +397,10 @@ func (qc *QemuContext) Save(ctx *hypervisor.VmContext, path string) error {
385
397
386
398
result := make (chan error , 1 )
387
399
// TODO: use query-migrate to query until completed
388
- qc .qmp <- & QmpSession {
400
+ qc .qmpSend ( ctx , & QmpSession {
389
401
commands : commands ,
390
402
respond : func (err error ) { result <- err },
391
- }
403
+ })
392
404
393
405
return <- result
394
406
}
0 commit comments