_hidden void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,
int rc, int retval, int errnoval);
+_hidden void libxl__save_helper_init(libxl__save_helper_state *shs);
+_hidden void libxl__save_helper_abort(libxl__egc *egc,
+ libxl__save_helper_state *shs);
+
+static inline bool libxl__save_helper_inuse(const libxl__save_helper_state *shs)
+{
+ return libxl__ev_child_inuse(&shs->child);
+}
+
/* Each time the dm needs to be saved, we must call suspend and then save */
_hidden int libxl__domain_suspend_device_model(libxl__gc *gc,
libxl__domain_suspend_state *dss);
shs->egc = 0;
}
+void libxl__save_helper_init(libxl__save_helper_state *shs)
+{
+ libxl__ao_abortable_init(&shs->abrt);
+ libxl__ev_fd_init(&shs->readable);
+ libxl__ev_child_init(&shs->child);
+}
+
/*----- helper execution -----*/
static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs,
shs->rc = 0;
shs->completed = 0;
shs->pipes[0] = shs->pipes[1] = 0;
- libxl__ao_abortable_init(&shs->abrt);
- libxl__ev_fd_init(&shs->readable);
- libxl__ev_child_init(&shs->child);
+ libxl__save_helper_init(shs);
shs->abrt.ao = shs->ao;
shs->abrt.callback = helper_stop;
libxl__ev_fd_deregister(gc, &shs->readable);
- if (!libxl__ev_child_inuse(&shs->child)) {
+ if (!libxl__save_helper_inuse(shs)) {
helper_done(egc, shs);
return;
}
libxl__save_helper_state *shs = CONTAINER_OF(abrt, *shs, abrt);
STATE_AO_GC(shs->ao);
- if (!libxl__ev_child_inuse(&shs->child)) {
+ if (!libxl__save_helper_inuse(shs)) {
helper_failed(egc, shs, rc);
return;
}
libxl__kill(gc, shs->child.pid, SIGTERM, "save/restore helper");
}
+void libxl__save_helper_abort(libxl__egc *egc,
+ libxl__save_helper_state *shs)
+{
+ helper_stop(egc, &shs->abrt, ERROR_FAIL);
+}
+
static void helper_stdout_readable(libxl__egc *egc, libxl__ev_fd *ev,
int fd, short events, short revents)
{
libxl__ev_fd_deregister(gc, &shs->readable);
libxl__carefd_close(shs->pipes[0]); shs->pipes[0] = 0;
libxl__carefd_close(shs->pipes[1]); shs->pipes[1] = 0;
- assert(!libxl__ev_child_inuse(&shs->child));
+ assert(!libxl__save_helper_inuse(shs));
if (shs->toolstack_data_file) fclose(shs->toolstack_data_file);
shs->egc = egc;