/* * Read and validate the Image and Domain headers. */ static int read_headers(struct xc_sr_context *ctx) { xc_interface *xch = ctx->xch; struct xc_sr_ihdr ihdr; struct xc_sr_dhdr dhdr; if ( read_exact(ctx->fd, &ihdr, sizeof(ihdr)) ) { PERROR("Failed to read Image Header from stream"); return -1; } ihdr.id = ntohl(ihdr.id); ihdr.version = ntohl(ihdr.version); ihdr.options = ntohs(ihdr.options); if ( ihdr.marker != IHDR_MARKER ) { ERROR("Invalid marker: Got 0x%016"PRIx64, ihdr.marker); return -1; } else if ( ihdr.id != IHDR_ID ) { ERROR("Invalid ID: Expected 0x%08x, Got 0x%08x", IHDR_ID, ihdr.id); return -1; } else if ( ihdr.version != IHDR_VERSION ) { ERROR("Invalid Version: Expected %d, Got %d", ihdr.version, IHDR_VERSION); return -1; } else if ( ihdr.options & IHDR_OPT_BIG_ENDIAN ) { ERROR("Unable to handle big endian streams"); return -1; } ctx->restore.format_version = ihdr.version; if ( read_exact(ctx->fd, &dhdr, sizeof(dhdr)) ) { PERROR("Failed to read Domain Header from stream"); return -1; } ctx->restore.guest_type = dhdr.type; ctx->restore.guest_page_size = (1U << dhdr.page_shift); if ( dhdr.xen_major == 0 ) { IPRINTF("Found %s domain, converted from legacy stream format", dhdr_type_to_str(dhdr.type)); DPRINTF(" Legacy conversion script version %u", dhdr.xen_minor); } else IPRINTF("Found %s domain from Xen %u.%u", dhdr_type_to_str(dhdr.type), dhdr.xen_major, dhdr.xen_minor); return 0; }
/* * restore_ops function. Confirms the stream matches the domain. */ static int x86_hvm_setup(struct xc_sr_context *ctx) { xc_interface *xch = ctx->xch; if ( ctx->restore.guest_type != DHDR_TYPE_X86_HVM ) { ERROR("Unable to restore %s domain into an x86_hvm domain", dhdr_type_to_str(ctx->restore.guest_type)); return -1; } else if ( ctx->restore.guest_page_size != PAGE_SIZE ) { ERROR("Invalid page size %u for x86_hvm domains", ctx->restore.guest_page_size); return -1; } return 0; }