/*==================== Domain suspend (save) ====================*/
+static void stream_done(libxl__egc *egc,
+ libxl__stream_write_state *sws, int rc);
static void domain_suspend_done(libxl__egc *egc,
libxl__domain_suspend_state *dss, int rc);
static void domain_suspend_callback_common_done(libxl__egc *egc,
} else {
broke = 0;
}
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, broke);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, broke);
}
/*----- callbacks, called by xc_domain_save -----*/
libxl__domain_suspend_state *dss, int rc)
{
dss->rc = rc;
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, !rc);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, !rc);
}
/*----- remus callbacks -----*/
out:
dss->rc = rc;
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, !rc);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, !rc);
}
static void remus_devices_postsuspend_cb(libxl__egc *egc,
out:
if (rc)
dss->rc = rc;
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, !rc);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, !rc);
}
static void libxl__remus_domain_resume_callback(void *data)
out:
if (rc)
dss->rc = rc;
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, !rc);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, !rc);
}
/*----- remus asynchronous checkpoint callback -----*/
return;
out:
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, 0);
}
static void remus_devices_commit_cb(libxl__egc *egc,
return;
out:
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, 0);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, 0);
}
static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev,
if (rc)
dss->rc = rc;
- libxl__xc_domain_saverestore_async_callback_done(egc, &dss->shs, !rc);
+ libxl__xc_domain_saverestore_async_callback_done(egc, &dss->sws.shs, !rc);
}
/*----- main code for suspending, in order of execution -----*/
const int debug = dss->debug;
const libxl_domain_remus_info *const r_info = dss->remus;
libxl__srm_save_autogen_callbacks *const callbacks =
- &dss->shs.callbacks.save.a;
+ &dss->sws.shs.callbacks.save.a;
dss->rc = 0;
logdirty_init(&dss->logdirty);
callbacks->suspend = libxl__domain_suspend_callback;
callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty;
- dss->shs.callbacks.save.toolstack_save = libxl__toolstack_save;
+ dss->sws.shs.callbacks.save.toolstack_save = libxl__toolstack_save;
- libxl__xc_domain_save(egc, dss, &dss->shs);
+ dss->sws.ao = dss->ao;
+ dss->sws.dss = dss;
+ dss->sws.fd = dss->fd;
+ dss->sws.completion_callback = stream_done;
+
+ libxl__stream_write_start(egc, &dss->sws);
return;
out:
domain_suspend_done(egc, dss, rc);
}
-void libxl__xc_domain_save_done(libxl__egc *egc, void *dss_void,
- int rc, int retval, int errnoval)
+static void stream_done(libxl__egc *egc,
+ libxl__stream_write_state *sws, int rc)
{
- libxl__domain_suspend_state *dss = dss_void;
- STATE_AO_GC(dss->ao);
-
- /* Convenience aliases */
- const libxl_domain_type type = dss->type;
-
- if (rc)
- goto out;
-
- if (retval) {
- LOGEV(ERROR, errnoval, "saving domain: %s",
- dss->guest_responded ?
- "domain responded to suspend request" :
- "domain did not respond to suspend request");
- if ( !dss->guest_responded )
- rc = ERROR_GUEST_TIMEDOUT;
- else if (dss->rc)
- rc = dss->rc;
- else
- rc = ERROR_FAIL;
- goto out;
- }
-
- if (type == LIBXL_DOMAIN_TYPE_HVM) {
- rc = libxl__domain_suspend_device_model(gc, dss);
- if (rc) goto out;
-
- libxl__domain_save_device_model(egc, dss, domain_suspend_done);
- return;
- }
-
- rc = 0;
-
-out:
- domain_suspend_done(egc, dss, rc);
+ domain_suspend_done(egc, sws->dss, rc);
}
static void save_device_model_datacopier_done(libxl__egc *egc,
static void libxc_header_done(libxl__egc *egc,
libxl__stream_write_state *stream)
{
- libxl__xc_domain_save(egc, stream->dss, &stream->dss->shs);
+ libxl__xc_domain_save(egc, stream->dss, &stream->shs);
}
-static void __attribute__((unused))
-write_toolstack_record(libxl__egc *egc,
+void libxl__xc_domain_save_done(libxl__egc *egc, void *dss_void,
+ int rc, int retval, int errnoval)
+{
+ libxl__domain_suspend_state *dss = dss_void;
+ libxl__stream_write_state *stream = &dss->sws;
+ STATE_AO_GC(dss->ao);
+
+ if (rc)
+ goto err;
+
+ if (retval) {
+ LOGEV(ERROR, errnoval, "saving domain: %s",
+ dss->guest_responded ?
+ "domain responded to suspend request" :
+ "domain did not respond to suspend request");
+ if (!dss->guest_responded)
+ rc = ERROR_GUEST_TIMEDOUT;
+ else if (dss->rc)
+ rc = dss->rc;
+ else
+ rc = ERROR_FAIL;
+ goto err;
+ }
+
+ write_toolstack_record(egc, stream);
+
+ err:
+ check_all_finished(egc, stream, rc);
+}
+
+static void write_toolstack_record(libxl__egc *egc,
libxl__stream_write_state *stream)
{
libxl__domain_suspend_state *dss = stream->dss;
libxl__stream_write_state *stream,
int rc)
{
- libxl__domain_suspend_state *dss = stream->dss;
STATE_AO_GC(stream->ao);
if (!stream->rc && rc) {
stream->rc = rc;
libxl__stream_write_abort(egc, stream, rc);
- libxl__save_helper_abort(egc, &dss->shs);
+ libxl__save_helper_abort(egc, &stream->shs);
}
/* Don't fire the callback until all our parallel tasks have stopped. */
if (libxl__stream_write_inuse(stream) ||
- libxl__save_helper_inuse(&dss->shs))
+ libxl__save_helper_inuse(&stream->shs))
return;
stream->completion_callback(egc, stream, stream->rc);