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
57 libxl__srm_callout_enumcallbacks_restore(&shs->callbacks.restore.a); in libxl__xc_domain_restore()
68 shs->ao = ao; in libxl__xc_domain_restore()
69 shs->domid = domid; in libxl__xc_domain_restore()
70 shs->recv_callback = libxl__srm_callout_received_restore; in libxl__xc_domain_restore()
73 shs->completion_callback = libxl__colo_restore_teardown; in libxl__xc_domain_restore()
75 shs->completion_callback = libxl__xc_domain_restore_done; in libxl__xc_domain_restore()
76 shs->caller_state = dcs; in libxl__xc_domain_restore()
77 shs->need_results = 1; in libxl__xc_domain_restore()
79 run_helper(egc, shs, "--restore-domain", restore_fd, send_back_fd, 0, 0, in libxl__xc_domain_restore()
84 libxl__save_helper_state *shs) in libxl__xc_domain_save() argument
89 libxl__srm_callout_enumcallbacks_save(&shs->callbacks.save.a); in libxl__xc_domain_save()
96 shs->ao = ao; in libxl__xc_domain_save()
97 shs->domid = dss->domid; in libxl__xc_domain_save()
98 shs->recv_callback = libxl__srm_callout_received_save; in libxl__xc_domain_save()
99 shs->completion_callback = libxl__xc_domain_save_done; in libxl__xc_domain_save()
100 shs->caller_state = dss; in libxl__xc_domain_save()
101 shs->need_results = 0; in libxl__xc_domain_save()
103 run_helper(egc, shs, "--save-domain", dss->fd, dss->recv_fd, in libxl__xc_domain_save()
111 libxl__save_helper_state *shs, int return_value) in libxl__xc_domain_saverestore_async_callback_done() argument
113 shs->egc = egc; in libxl__xc_domain_saverestore_async_callback_done()
114 libxl__srm_callout_sendreply(return_value, shs); in libxl__xc_domain_saverestore_async_callback_done()
115 shs->egc = 0; in libxl__xc_domain_saverestore_async_callback_done()
118 void libxl__save_helper_init(libxl__save_helper_state *shs) in libxl__save_helper_init() argument
120 libxl__ao_abortable_init(&shs->abrt); in libxl__save_helper_init()
121 libxl__ev_fd_init(&shs->readable); in libxl__save_helper_init()
122 libxl__ev_child_init(&shs->child); in libxl__save_helper_init()
154 static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, in run_helper() argument
160 STATE_AO_GC(shs->ao); in run_helper()
169 const uint32_t domid = shs->domid; in run_helper()
171 shs->rc = 0; in run_helper()
172 shs->completed = 0; in run_helper()
173 shs->pipes[0] = shs->pipes[1] = 0; in run_helper()
174 libxl__save_helper_init(shs); in run_helper()
176 shs->abrt.ao = shs->ao; in run_helper()
177 shs->abrt.callback = helper_stop; in run_helper()
178 rc = libxl__ao_abortable_register(&shs->abrt); in run_helper()
181 shs->stdin_what = GCSPRINTF("domain %"PRIu32" save/restore helper" in run_helper()
183 shs->stdout_what = GCSPRINTF("domain %"PRIu32" save/restore helper" in run_helper()
208 shs->pipes[childfd] = libxl__carefd_record(CTX, fds[our_end]); in run_helper()
212 pid_t pid = libxl__ev_child_fork(gc, &shs->child, helper_exited); in run_helper()
238 rc = libxl__ev_fd_register(gc, &shs->readable, helper_stdout_readable, in run_helper()
239 libxl__carefd_fd(shs->pipes[1]), POLLIN|POLLPRI); in run_helper()
246 helper_failed(egc, shs, rc);; in run_helper()
249 static void helper_failed(libxl__egc *egc, libxl__save_helper_state *shs, in helper_failed() argument
252 STATE_AO_GC(shs->ao); in helper_failed()
254 if (!shs->rc) in helper_failed()
255 shs->rc = rc; in helper_failed()
257 libxl__ev_fd_deregister(gc, &shs->readable); in helper_failed()
259 if (!libxl__save_helper_inuse(shs)) { in helper_failed()
260 helper_done(egc, shs); in helper_failed()
264 libxl__kill(gc, shs->child.pid, SIGKILL, "save/restore helper"); in helper_failed()
269 libxl__save_helper_state *shs = CONTAINER_OF(abrt, *shs, abrt); in helper_stop() local
270 STATE_AO_GC(shs->ao); in helper_stop()
272 if (!libxl__save_helper_inuse(shs)) { in helper_stop()
273 helper_failed(egc, shs, rc); in helper_stop()
277 if (!shs->rc) in helper_stop()
278 shs->rc = rc; in helper_stop()
280 libxl__kill(gc, shs->child.pid, SIGTERM, "save/restore helper"); in helper_stop()
284 libxl__save_helper_state *shs) in libxl__save_helper_abort() argument
286 helper_stop(egc, &shs->abrt, ERROR_FAIL); in libxl__save_helper_abort()
292 libxl__save_helper_state *shs = CONTAINER_OF(ev, *shs, readable); in helper_stdout_readable() local
293 STATE_AO_GC(shs->ao); in helper_stdout_readable()
297 LOGD(ERROR, shs->domid, "%s signaled POLLERR|POLLPRI (%#x)", in helper_stdout_readable()
298 shs->stdout_what, revents); in helper_stdout_readable()
302 helper_failed(egc, shs, rc); in helper_stdout_readable()
308 shs->stdout_what, "ipc msg header"); in helper_stdout_readable()
313 shs->stdout_what, "ipc msg body"); in helper_stdout_readable()
316 shs->egc = egc; in helper_stdout_readable()
317 shs->recv_callback(msg, msglen, shs); in helper_stdout_readable()
318 shs->egc = 0; in helper_stdout_readable()
325 libxl__save_helper_state *shs = CONTAINER_OF(ch, *shs, child); in helper_exited() local
326 STATE_AO_GC(shs->ao); in helper_exited()
329 const uint32_t domid = shs->domid; in helper_exited()
336 if (!shs->rc) in helper_exited()
337 shs->rc = ERROR_FAIL; in helper_exited()
340 if (shs->need_results) { in helper_exited()
341 if (!shs->rc) { in helper_exited()
342 LOGD(ERROR,shs->domid,"%s exited without providing results",what); in helper_exited()
343 shs->rc = ERROR_FAIL; in helper_exited()
347 if (!shs->completed) { in helper_exited()
348 if (!shs->rc) { in helper_exited()
349 LOGD(ERROR,shs->domid,"%s exited without signaling completion",what); in helper_exited()
350 shs->rc = ERROR_FAIL; in helper_exited()
354 helper_done(egc, shs); in helper_exited()
358 static void helper_done(libxl__egc *egc, libxl__save_helper_state *shs) in helper_done() argument
360 STATE_AO_GC(shs->ao); in helper_done()
362 libxl__ao_abortable_deregister(&shs->abrt); in helper_done()
363 libxl__ev_fd_deregister(gc, &shs->readable); in helper_done()
364 libxl__carefd_close(shs->pipes[0]); shs->pipes[0] = 0; in helper_done()
365 libxl__carefd_close(shs->pipes[1]); shs->pipes[1] = 0; in helper_done()
366 assert(!libxl__save_helper_inuse(shs)); in helper_done()
368 shs->egc = egc; in helper_done()
369 shs->completion_callback(egc, shs->caller_state, in helper_done()
370 shs->rc, shs->retval, shs->errnoval); in helper_done()
371 shs->egc = 0; in helper_done()
379 libxl__save_helper_state *shs = user; in libxl__srm_callout_get_callbacks_save() local
380 return &shs->callbacks.save.a; in libxl__srm_callout_get_callbacks_save()
386 libxl__save_helper_state *shs = user; in libxl__srm_callout_get_callbacks_restore() local
387 return &shs->callbacks.restore.a; in libxl__srm_callout_get_callbacks_restore()
392 libxl__save_helper_state *shs = user; in libxl__srm_callout_sendreply() local
393 libxl__egc *egc = shs->egc; in libxl__srm_callout_sendreply()
394 STATE_AO_GC(shs->ao); in libxl__srm_callout_sendreply()
397 errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]), in libxl__srm_callout_sendreply()
398 &r, sizeof(r), shs->stdin_what, in libxl__srm_callout_sendreply()
401 helper_failed(egc, shs, ERROR_FAIL); in libxl__srm_callout_sendreply()
407 libxl__save_helper_state *shs = user; in libxl__srm_callout_callback_log() local
408 STATE_AO_GC(shs->ao); in libxl__srm_callout_callback_log()
416 libxl__save_helper_state *shs = user; in libxl__srm_callout_callback_progress() local
417 STATE_AO_GC(shs->ao); in libxl__srm_callout_callback_progress()
424 libxl__save_helper_state *shs = user; in libxl__srm_callout_callback_complete() local
425 STATE_AO_GC(shs->ao); in libxl__srm_callout_callback_complete()
427 shs->completed = 1; in libxl__srm_callout_callback_complete()
428 shs->retval = retval; in libxl__srm_callout_callback_complete()
429 shs->errnoval = errnoval; in libxl__srm_callout_callback_complete()
430 libxl__ev_fd_deregister(gc, &shs->readable); in libxl__srm_callout_callback_complete()