@@ -178,6 +178,18 @@ func (qc *QemuContext) Shutdown(ctx *hypervisor.VmContext) {
178178 qmpQemuQuit (ctx , qc )
179179}
180180
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+
181193func (qc * QemuContext ) Kill (ctx * hypervisor.VmContext ) {
182194 defer func () {
183195 err := recover ()
@@ -215,12 +227,12 @@ func (qc *QemuContext) Pause(ctx *hypervisor.VmContext, pause bool) error {
215227 }
216228
217229 result := make (chan error , 1 )
218- qc .qmp <- & QmpSession {
230+ qc .qmpSend ( ctx , & QmpSession {
219231 commands : commands ,
220232 respond : func (err error ) {
221233 result <- err
222234 },
223- }
235+ })
224236 return <- result
225237}
226238
@@ -321,15 +333,15 @@ func (qc *QemuContext) SetCpus(ctx *hypervisor.VmContext, cpus int) error {
321333 }
322334
323335 result := make (chan error , 1 )
324- qc .qmp <- & QmpSession {
336+ qc .qmpSend ( ctx , & QmpSession {
325337 commands : commands ,
326338 respond : func (err error ) {
327339 if err == nil {
328340 qc .cpus = cpus
329341 }
330342 result <- err
331343 },
332- }
344+ })
333345 return <- result
334346}
335347
@@ -352,10 +364,10 @@ func (qc *QemuContext) AddMem(ctx *hypervisor.VmContext, slot, size int) error {
352364 },
353365 }
354366 result := make (chan error , 1 )
355- qc .qmp <- & QmpSession {
367+ qc .qmpSend ( ctx , & QmpSession {
356368 commands : commands ,
357369 respond : func (err error ) { result <- err },
358- }
370+ })
359371 return <- result
360372}
361373
@@ -385,10 +397,10 @@ func (qc *QemuContext) Save(ctx *hypervisor.VmContext, path string) error {
385397
386398 result := make (chan error , 1 )
387399 // TODO: use query-migrate to query until completed
388- qc .qmp <- & QmpSession {
400+ qc .qmpSend ( ctx , & QmpSession {
389401 commands : commands ,
390402 respond : func (err error ) { result <- err },
391- }
403+ })
392404
393405 return <- result
394406}
0 commit comments