void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_suspend_state *dss, unsigned long vm_generationid_addr) { STATE_AO_GC(dss->ao); int r, rc, toolstack_data_fd = -1; uint32_t toolstack_data_len = 0; /* Resources we need to free */ uint8_t *toolstack_data_buf = 0; unsigned cbflags = libxl__srm_callout_enumcallbacks_save (&dss->shs.callbacks.save.a); if (dss->shs.callbacks.save.toolstack_save) { r = dss->shs.callbacks.save.toolstack_save (dss->domid, &toolstack_data_buf, &toolstack_data_len, dss); if (r) { rc = ERROR_FAIL; goto out; } dss->shs.toolstack_data_file = tmpfile(); if (!dss->shs.toolstack_data_file) { LOGE(ERROR, "cannot create toolstack data tmpfile"); rc = ERROR_FAIL; goto out; } toolstack_data_fd = fileno(dss->shs.toolstack_data_file); r = libxl_write_exactly(CTX, toolstack_data_fd, toolstack_data_buf, toolstack_data_len, "toolstack data tmpfile", 0); if (r) { rc = ERROR_FAIL; goto out; } } const unsigned long argnums[] = { dss->domid, 0, 0, dss->xcflags, dss->hvm, vm_generationid_addr, toolstack_data_fd, toolstack_data_len, cbflags, }; dss->shs.ao = ao; dss->shs.domid = dss->domid; dss->shs.recv_callback = libxl__srm_callout_received_save; dss->shs.completion_callback = libxl__xc_domain_save_done; dss->shs.caller_state = dss; dss->shs.need_results = 0; free(toolstack_data_buf); run_helper(egc, &dss->shs, "--save-domain", dss->fd, &toolstack_data_fd, 1, argnums, ARRAY_SIZE(argnums)); return; out: free(toolstack_data_buf); if (dss->shs.toolstack_data_file) fclose(dss->shs.toolstack_data_file); libxl__xc_domain_save_done(egc, dss, rc, 0, 0); }
void log_callback( void *userdata, int loglevel, const char *file, int line, const char *func, char *s) { char str[1024]; snprintf(str, sizeof(str), "[%d] %s:%d:%s: %s\n", loglevel, file, line, func, s); libxl_write_exactly(NULL, logfile, str, strlen(str), NULL, NULL); }
void libxl__srm_callout_sendreply(int r, void *user) { libxl__save_helper_state *shs = user; libxl__egc *egc = shs->egc; STATE_AO_GC(shs->ao); int errnoval; errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]), &r, sizeof(r), shs->stdin_what, "callback return value"); if (errnoval) helper_failed(egc, shs, ERROR_FAIL); }