Lines Matching refs:shs
28 static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs,
34 static void helper_failed(libxl__egc*, libxl__save_helper_state *shs, int rc);
40 static void helper_done(libxl__egc *egc, libxl__save_helper_state *shs);
45 libxl__save_helper_state *shs) in libxl__xc_domain_restore() argument
56 libxl__srm_callout_enumcallbacks_restore(&shs->callbacks.restore.a); in libxl__xc_domain_restore()
66 shs->ao = ao; in libxl__xc_domain_restore()
67 shs->domid = domid; in libxl__xc_domain_restore()
68 shs->recv_callback = libxl__srm_callout_received_restore; in libxl__xc_domain_restore()
71 shs->completion_callback = libxl__colo_restore_teardown; in libxl__xc_domain_restore()
73 shs->completion_callback = libxl__xc_domain_restore_done; in libxl__xc_domain_restore()
74 shs->caller_state = dcs; in libxl__xc_domain_restore()
75 shs->need_results = 1; in libxl__xc_domain_restore()
77 run_helper(egc, shs, "--restore-domain", restore_fd, send_back_fd, 0, 0, in libxl__xc_domain_restore()
82 libxl__save_helper_state *shs) in libxl__xc_domain_save() argument
87 libxl__srm_callout_enumcallbacks_save(&shs->callbacks.save.a); in libxl__xc_domain_save()
94 shs->ao = ao; in libxl__xc_domain_save()
95 shs->domid = dss->domid; in libxl__xc_domain_save()
96 shs->recv_callback = libxl__srm_callout_received_save; in libxl__xc_domain_save()
97 shs->completion_callback = libxl__xc_domain_save_done; in libxl__xc_domain_save()
98 shs->caller_state = dss; in libxl__xc_domain_save()
99 shs->need_results = 0; in libxl__xc_domain_save()
101 run_helper(egc, shs, "--save-domain", dss->fd, dss->recv_fd, in libxl__xc_domain_save()
109 libxl__save_helper_state *shs, int return_value) in libxl__xc_domain_saverestore_async_callback_done() argument
111 shs->egc = egc; in libxl__xc_domain_saverestore_async_callback_done()
112 libxl__srm_callout_sendreply(return_value, shs); in libxl__xc_domain_saverestore_async_callback_done()
113 shs->egc = 0; in libxl__xc_domain_saverestore_async_callback_done()
116 void libxl__save_helper_init(libxl__save_helper_state *shs) in libxl__save_helper_init() argument
118 libxl__ao_abortable_init(&shs->abrt); in libxl__save_helper_init()
119 libxl__ev_fd_init(&shs->readable); in libxl__save_helper_init()
120 libxl__ev_child_init(&shs->child); in libxl__save_helper_init()
152 static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, in run_helper() argument
158 STATE_AO_GC(shs->ao); in run_helper()
167 const uint32_t domid = shs->domid; in run_helper()
169 shs->rc = 0; in run_helper()
170 shs->completed = 0; in run_helper()
171 shs->pipes[0] = shs->pipes[1] = 0; in run_helper()
172 libxl__save_helper_init(shs); in run_helper()
174 shs->abrt.ao = shs->ao; in run_helper()
175 shs->abrt.callback = helper_stop; in run_helper()
176 rc = libxl__ao_abortable_register(&shs->abrt); in run_helper()
179 shs->stdin_what = GCSPRINTF("domain %"PRIu32" save/restore helper" in run_helper()
181 shs->stdout_what = GCSPRINTF("domain %"PRIu32" save/restore helper" in run_helper()
206 shs->pipes[childfd] = libxl__carefd_record(CTX, fds[our_end]); in run_helper()
210 pid_t pid = libxl__ev_child_fork(gc, &shs->child, helper_exited); in run_helper()
236 rc = libxl__ev_fd_register(gc, &shs->readable, helper_stdout_readable, in run_helper()
237 libxl__carefd_fd(shs->pipes[1]), POLLIN|POLLPRI); in run_helper()
244 helper_failed(egc, shs, rc);; in run_helper()
247 static void helper_failed(libxl__egc *egc, libxl__save_helper_state *shs, in helper_failed() argument
250 STATE_AO_GC(shs->ao); in helper_failed()
252 if (!shs->rc) in helper_failed()
253 shs->rc = rc; in helper_failed()
255 libxl__ev_fd_deregister(gc, &shs->readable); in helper_failed()
257 if (!libxl__save_helper_inuse(shs)) { in helper_failed()
258 helper_done(egc, shs); in helper_failed()
262 libxl__kill(gc, shs->child.pid, SIGKILL, "save/restore helper"); in helper_failed()
267 libxl__save_helper_state *shs = CONTAINER_OF(abrt, *shs, abrt); in helper_stop() local
268 STATE_AO_GC(shs->ao); in helper_stop()
270 if (!libxl__save_helper_inuse(shs)) { in helper_stop()
271 helper_failed(egc, shs, rc); in helper_stop()
275 if (!shs->rc) in helper_stop()
276 shs->rc = rc; in helper_stop()
278 libxl__kill(gc, shs->child.pid, SIGTERM, "save/restore helper"); in helper_stop()
282 libxl__save_helper_state *shs) in libxl__save_helper_abort() argument
284 helper_stop(egc, &shs->abrt, ERROR_FAIL); in libxl__save_helper_abort()
290 libxl__save_helper_state *shs = CONTAINER_OF(ev, *shs, readable); in helper_stdout_readable() local
291 STATE_AO_GC(shs->ao); in helper_stdout_readable()
295 LOGD(ERROR, shs->domid, "%s signaled POLLERR|POLLPRI (%#x)", in helper_stdout_readable()
296 shs->stdout_what, revents); in helper_stdout_readable()
300 helper_failed(egc, shs, rc); in helper_stdout_readable()
306 shs->stdout_what, "ipc msg header"); in helper_stdout_readable()
311 shs->stdout_what, "ipc msg body"); in helper_stdout_readable()
314 shs->egc = egc; in helper_stdout_readable()
315 shs->recv_callback(msg, msglen, shs); in helper_stdout_readable()
316 shs->egc = 0; in helper_stdout_readable()
323 libxl__save_helper_state *shs = CONTAINER_OF(ch, *shs, child); in helper_exited() local
324 STATE_AO_GC(shs->ao); in helper_exited()
327 const uint32_t domid = shs->domid; in helper_exited()
334 if (!shs->rc) in helper_exited()
335 shs->rc = ERROR_FAIL; in helper_exited()
338 if (shs->need_results) { in helper_exited()
339 if (!shs->rc) { in helper_exited()
340 LOGD(ERROR,shs->domid,"%s exited without providing results",what); in helper_exited()
341 shs->rc = ERROR_FAIL; in helper_exited()
345 if (!shs->completed) { in helper_exited()
346 if (!shs->rc) { in helper_exited()
347 LOGD(ERROR,shs->domid,"%s exited without signaling completion",what); in helper_exited()
348 shs->rc = ERROR_FAIL; in helper_exited()
352 helper_done(egc, shs); in helper_exited()
356 static void helper_done(libxl__egc *egc, libxl__save_helper_state *shs) in helper_done() argument
358 STATE_AO_GC(shs->ao); in helper_done()
360 libxl__ao_abortable_deregister(&shs->abrt); in helper_done()
361 libxl__ev_fd_deregister(gc, &shs->readable); in helper_done()
362 libxl__carefd_close(shs->pipes[0]); shs->pipes[0] = 0; in helper_done()
363 libxl__carefd_close(shs->pipes[1]); shs->pipes[1] = 0; in helper_done()
364 assert(!libxl__save_helper_inuse(shs)); in helper_done()
366 shs->egc = egc; in helper_done()
367 shs->completion_callback(egc, shs->caller_state, in helper_done()
368 shs->rc, shs->retval, shs->errnoval); in helper_done()
369 shs->egc = 0; in helper_done()
377 libxl__save_helper_state *shs = user; in libxl__srm_callout_get_callbacks_save() local
378 return &shs->callbacks.save.a; in libxl__srm_callout_get_callbacks_save()
384 libxl__save_helper_state *shs = user; in libxl__srm_callout_get_callbacks_restore() local
385 return &shs->callbacks.restore.a; in libxl__srm_callout_get_callbacks_restore()
390 libxl__save_helper_state *shs = user; in libxl__srm_callout_sendreply() local
391 libxl__egc *egc = shs->egc; in libxl__srm_callout_sendreply()
392 STATE_AO_GC(shs->ao); in libxl__srm_callout_sendreply()
395 errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]), in libxl__srm_callout_sendreply()
396 &r, sizeof(r), shs->stdin_what, in libxl__srm_callout_sendreply()
399 helper_failed(egc, shs, ERROR_FAIL); in libxl__srm_callout_sendreply()
405 libxl__save_helper_state *shs = user; in libxl__srm_callout_callback_log() local
406 STATE_AO_GC(shs->ao); in libxl__srm_callout_callback_log()
414 libxl__save_helper_state *shs = user; in libxl__srm_callout_callback_progress() local
415 STATE_AO_GC(shs->ao); in libxl__srm_callout_callback_progress()
422 libxl__save_helper_state *shs = user; in libxl__srm_callout_callback_complete() local
423 STATE_AO_GC(shs->ao); in libxl__srm_callout_callback_complete()
425 shs->completed = 1; in libxl__srm_callout_callback_complete()
426 shs->retval = retval; in libxl__srm_callout_callback_complete()
427 shs->errnoval = errnoval; in libxl__srm_callout_callback_complete()
428 libxl__ev_fd_deregister(gc, &shs->readable); in libxl__srm_callout_callback_complete()