debuggers.hg

view tools/libxc/xc_linux_restore.c @ 2626:1e99cd1cb3a3

bitkeeper revision 1.1159.1.199 (415eb976aT_IbGUyZQZwMzprjVdnPA)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into freefall.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xeno.bk-nbsd
author cl349@freefall.cl.cam.ac.uk
date Sat Oct 02 14:21:42 2004 +0000 (2004-10-02)
parents 538350dcb66f 23bc5e8a9321
children 98bdf2c88015
line source
1 /******************************************************************************
2 * xc_linux_restore.c
3 *
4 * Restore the state of a Linux session.
5 *
6 * Copyright (c) 2003, K A Fraser.
7 */
9 #include "xc_private.h"
10 #include <asm-xen/suspend.h>
12 #define MAX_BATCH_SIZE 1024
14 #define DEBUG 0
16 #if DEBUG
17 #define DPRINTF(_f, _a...) printf ( _f , ## _a )
18 #else
19 #define DPRINTF(_f, _a...) ((void)0)
20 #endif
22 static int get_pfn_list(int xc_handle,
23 u32 domain_id,
24 unsigned long *pfn_buf,
25 unsigned long max_pfns)
26 {
27 dom0_op_t op;
28 int ret;
29 op.cmd = DOM0_GETMEMLIST;
30 op.u.getmemlist.domain = (domid_t)domain_id;
31 op.u.getmemlist.max_pfns = max_pfns;
32 op.u.getmemlist.buffer = pfn_buf;
34 if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
35 {
36 PERROR("Could not lock pfn list buffer");
37 return -1;
38 }
40 ret = do_dom0_op(xc_handle, &op);
42 (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long));
44 return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
45 }
47 /** Read the vmconfig string from the state input.
48 * It is stored as a 4-byte count 'n' followed by n bytes.
49 * The config data is stored in a new string in 'ioctxt->vmconfig',
50 * and is null-terminated. The count is stored in 'ioctxt->vmconfig_n'.
51 *
52 * @param ioctxt i/o context
53 * @return 0 on success, non-zero on error.
54 */
55 static int read_vmconfig(XcIOContext *ioctxt)
56 {
57 int err = -1;
59 if ( xcio_read(ioctxt, &ioctxt->vmconfig_n, sizeof(ioctxt->vmconfig_n)) )
60 goto exit;
62 ioctxt->vmconfig = malloc(ioctxt->vmconfig_n + 1);
63 if ( ioctxt->vmconfig == NULL )
64 goto exit;
66 if ( xcio_read(ioctxt, ioctxt->vmconfig, ioctxt->vmconfig_n) )
67 goto exit;
69 ioctxt->vmconfig[ioctxt->vmconfig_n] = '\0';
70 err = 0;
72 exit:
73 if ( err )
74 {
75 if ( ioctxt->vmconfig != NULL )
76 free(ioctxt->vmconfig);
77 ioctxt->vmconfig = NULL;
78 ioctxt->vmconfig_n = 0;
79 }
80 return err;
81 }
83 int xc_linux_restore(int xc_handle, XcIOContext *ioctxt)
84 {
85 dom0_op_t op;
86 int rc = 1, i, n, k;
87 unsigned long mfn, pfn, xpfn;
88 unsigned int prev_pc, this_pc;
89 u32 dom = 0;
90 int verify = 0;
92 /* Number of page frames in use by this Linux session. */
93 unsigned long nr_pfns;
95 /* The new domain's shared-info frame number. */
96 unsigned long shared_info_frame;
97 unsigned char shared_info[PAGE_SIZE]; /* saved contents from file */
99 /* A copy of the CPU context of the guest. */
100 full_execution_context_t ctxt;
102 /* First 16 bytes of the state file must contain 'LinuxGuestRecord'. */
103 char signature[16];
105 /* A copy of the domain's name. */
106 char name[MAX_DOMAIN_NAME];
108 /* A table containg the type of each PFN (/not/ MFN!). */
109 unsigned long *pfn_type = NULL;
111 /* A table of MFNs to map in the current region */
112 unsigned long *region_mfn = NULL;
114 /* A temporary mapping, and a copy, of one frame of guest memory. */
115 unsigned long *ppage = NULL;
117 /* A copy of the pfn-to-mfn table frame list. */
118 unsigned long pfn_to_mfn_frame_list[1024];
120 /* A table mapping each PFN to its new MFN. */
121 unsigned long *pfn_to_mfn_table = NULL;
123 /* used by mapper for updating the domain's copy of the table */
124 unsigned long *live_pfn_to_mfn_table = NULL;
126 /* A temporary mapping of the guest's suspend record. */
127 suspend_record_t *p_srec;
129 char *region_base;
131 mmu_t *mmu = NULL;
133 /* used by debug verify code */
134 unsigned long buf[PAGE_SIZE/sizeof(unsigned long)];
136 if ( mlock(&ctxt, sizeof(ctxt) ) )
137 {
138 /* needed for when we do the build dom0 op,
139 but might as well do early */
140 PERROR("Unable to mlock ctxt");
141 return 1;
142 }
144 /* Start reading the saved-domain record. */
145 if ( xcio_read(ioctxt, signature, 16) ||
146 (memcmp(signature, "LinuxGuestRecord", 16) != 0) )
147 {
148 xcio_error(ioctxt, "Unrecognised state format -- no signature found");
149 goto out;
150 }
152 if ( xcio_read(ioctxt, name, sizeof(name)) ||
153 xcio_read(ioctxt, &nr_pfns, sizeof(unsigned long)) ||
154 xcio_read(ioctxt, pfn_to_mfn_frame_list, PAGE_SIZE) )
155 {
156 xcio_error(ioctxt, "Error reading header");
157 goto out;
158 }
160 if ( read_vmconfig(ioctxt) )
161 {
162 xcio_error(ioctxt, "Error writing vmconfig");
163 goto out;
164 }
166 for ( i = 0; i < MAX_DOMAIN_NAME; i++ )
167 {
168 if ( name[i] == '\0' ) break;
169 if ( name[i] & 0x80 )
170 {
171 xcio_error(ioctxt, "Random characters in domain name");
172 goto out;
173 }
174 }
175 name[MAX_DOMAIN_NAME-1] = '\0';
177 if ( nr_pfns > 1024*1024 )
178 {
179 xcio_error(ioctxt, "Invalid state file -- pfn count out of range");
180 goto out;
181 }
183 /* We want zeroed memory so use calloc rather than malloc. */
184 pfn_to_mfn_table = calloc(1, 4 * nr_pfns);
185 pfn_type = calloc(1, 4 * nr_pfns);
186 region_mfn = calloc(1, 4 * MAX_BATCH_SIZE);
188 if ( (pfn_to_mfn_table == NULL) ||
189 (pfn_type == NULL) ||
190 (region_mfn == NULL) )
191 {
192 errno = ENOMEM;
193 goto out;
194 }
196 if ( mlock(region_mfn, 4 * MAX_BATCH_SIZE ) )
197 {
198 xcio_error(ioctxt, "Could not mlock region_mfn");
199 goto out;
200 }
202 #if 0
203 /* Set the domain's name to that from the restore file */
204 if ( xc_domain_setname( xc_handle, dom, name ) )
205 {
206 xcio_error(ioctxt, "Could not set domain name");
207 goto out;
208 }
210 /* Set the domain's initial memory allocation
211 to that from the restore file */
213 if ( xc_domain_setinitialmem(xc_handle, dom,
214 nr_pfns * (PAGE_SIZE / 1024)) )
215 {
216 xcio_error(ioctxt, "Could not set domain %d initial memory. pfns=%d, %dKB",
217 dom, nr_pfns,nr_pfns * (PAGE_SIZE / 1024));
218 goto out;
219 }
220 #endif
223 /* XXX create domain on CPU=-1 so that in future it auto load ballances by default */
224 if ( xc_domain_create( xc_handle, nr_pfns * (PAGE_SIZE / 1024),
225 "", -1, 1, &dom ) )
226 {
227 xcio_error(ioctxt, "Could not create domain. pfns=%d, %dKB",
228 nr_pfns,nr_pfns * (PAGE_SIZE / 1024));
229 goto out;
230 }
232 ioctxt->domain = dom;
233 printf("Created domain %ld\n",dom);
235 /* Get the domain's shared-info frame. */
236 op.cmd = DOM0_GETDOMAININFO;
237 op.u.getdomaininfo.domain = (domid_t)dom;
238 op.u.getdomaininfo.ctxt = NULL;
239 if ( do_dom0_op(xc_handle, &op) < 0 )
240 {
241 xcio_error(ioctxt, "Could not get information on new domain");
242 goto out;
243 }
244 shared_info_frame = op.u.getdomaininfo.shared_info_frame;
246 /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
247 if ( get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns )
248 {
249 xcio_error(ioctxt, "Did not read correct number of frame "
250 "numbers for new dom");
251 goto out;
252 }
254 if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL )
255 {
256 xcio_error(ioctxt, "Could not initialise for MMU updates");
257 goto out;
258 }
260 xcio_info(ioctxt, "Reloading memory pages: 0%%");
262 /*
263 * Now simply read each saved frame into its new machine frame.
264 * We uncanonicalise page tables as we go.
265 */
266 prev_pc = 0;
268 n = 0;
269 while ( 1 )
270 {
271 int j;
272 unsigned long region_pfn_type[MAX_BATCH_SIZE];
274 this_pc = (n * 100) / nr_pfns;
275 if ( (this_pc - prev_pc) >= 5 )
276 {
277 xcio_info(ioctxt, "\b\b\b\b%3d%%", this_pc);
278 prev_pc = this_pc;
279 }
281 if ( xcio_read(ioctxt, &j, sizeof(int)) )
282 {
283 xcio_error(ioctxt, "Error when reading from state file");
284 goto out;
285 }
287 DPRINTF("batch %d\n",j);
289 if ( j == -1 )
290 {
291 verify = 1;
292 printf("Entering page verify mode\n");
293 continue;
294 }
296 if ( j == 0 )
297 break; /* our work here is done */
299 if ( j > MAX_BATCH_SIZE )
300 {
301 xcio_error(ioctxt, "Max batch size exceeded. Giving up.");
302 goto out;
303 }
305 if ( xcio_read(ioctxt, region_pfn_type, j*sizeof(unsigned long)) ) {
306 xcio_error(ioctxt, "Error when reading from state file");
307 goto out;
308 }
310 for ( i = 0; i < j; i++ )
311 {
312 if ( (region_pfn_type[i] & LTAB_MASK) == XTAB)
313 {
314 region_mfn[i] = 0; /* we know map will fail, but don't care */
315 }
316 else
317 {
318 pfn = region_pfn_type[i] & ~LTAB_MASK;
319 region_mfn[i] = pfn_to_mfn_table[pfn];
320 }
321 }
323 if ( (region_base = xc_map_foreign_batch( xc_handle, dom,
324 PROT_WRITE,
325 region_mfn,
326 j )) == 0 )
327 {
328 xcio_error(ioctxt, "map batch failed");
329 goto out;
330 }
332 for ( i = 0; i < j; i++ )
333 {
334 unsigned long *ppage;
336 pfn = region_pfn_type[i] & ~LTAB_MASK;
338 if ( (region_pfn_type[i] & LTAB_MASK) == XTAB) continue;
340 if (pfn>nr_pfns)
341 {
342 xcio_error(ioctxt, "pfn out of range");
343 goto out;
344 }
346 region_pfn_type[i] &= LTAB_MASK;
348 pfn_type[pfn] = region_pfn_type[i];
350 mfn = pfn_to_mfn_table[pfn];
352 if ( verify )
353 ppage = (unsigned long*) buf; /* debug case */
354 else
355 ppage = (unsigned long*) (region_base + i*PAGE_SIZE);
357 if ( xcio_read(ioctxt, ppage, PAGE_SIZE) )
358 {
359 xcio_error(ioctxt, "Error when reading from state file");
360 goto out;
361 }
363 switch( region_pfn_type[i] & LTABTYPE_MASK )
364 {
365 case 0:
366 break;
368 case L1TAB:
369 {
370 for ( k = 0; k < 1024; k++ )
371 {
372 if ( ppage[k] & _PAGE_PRESENT )
373 {
374 xpfn = ppage[k] >> PAGE_SHIFT;
375 if ( xpfn >= nr_pfns )
376 {
377 xcio_error(ioctxt, "Frame number in type %lu page "
378 "table is out of range. i=%d k=%d "
379 "pfn=0x%lx nr_pfns=%lu",
380 region_pfn_type[i]>>28, i,
381 k, xpfn, nr_pfns);
382 goto out;
383 }
385 ppage[k] &= (PAGE_SIZE - 1) &
386 ~(_PAGE_GLOBAL | _PAGE_PAT);
387 ppage[k] |= pfn_to_mfn_table[xpfn] << PAGE_SHIFT;
388 }
389 }
390 }
391 break;
393 case L2TAB:
394 {
395 for ( k = 0;
396 k < (HYPERVISOR_VIRT_START>>L2_PAGETABLE_SHIFT);
397 k++ )
398 {
399 if ( ppage[k] & _PAGE_PRESENT )
400 {
401 xpfn = ppage[k] >> PAGE_SHIFT;
403 if ( xpfn >= nr_pfns )
404 {
405 xcio_error(ioctxt, "Frame number in type %lu page"
406 " table is out of range. i=%d k=%d "
407 "pfn=%lu nr_pfns=%lu",
408 region_pfn_type[i]>>28, i, k,
409 xpfn, nr_pfns);
410 goto out;
411 }
413 ppage[k] &= (PAGE_SIZE - 1) &
414 ~(_PAGE_GLOBAL | _PAGE_PSE);
415 ppage[k] |= pfn_to_mfn_table[xpfn] << PAGE_SHIFT;
416 }
417 }
418 }
419 break;
421 default:
422 xcio_error(ioctxt, "Bogus page type %lx page table is "
423 "out of range. i=%d nr_pfns=%lu",
424 region_pfn_type[i], i, nr_pfns);
425 goto out;
427 } /* end of page type switch statement */
429 if ( verify )
430 {
431 int res = memcmp(buf, (region_base + i*PAGE_SIZE), PAGE_SIZE );
432 if ( res )
433 {
434 int v;
435 printf("************** pfn=%lx type=%lx gotcs=%08lx "
436 "actualcs=%08lx\n", pfn, pfn_type[pfn],
437 csum_page(region_base + i*PAGE_SIZE),
438 csum_page(buf));
439 for ( v = 0; v < 4; v++ )
440 {
441 unsigned long *p = (unsigned long *)
442 (region_base + i*PAGE_SIZE);
443 if ( buf[v] != p[v] )
444 printf(" %d: %08lx %08lx\n",
445 v, buf[v], p[v] );
446 }
447 }
448 }
450 if ( add_mmu_update(xc_handle, mmu,
451 (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, pfn) )
452 {
453 printf("machpys mfn=%ld pfn=%ld\n",mfn,pfn);
454 goto out;
455 }
457 } /* end of 'batch' for loop */
459 munmap( region_base, j*PAGE_SIZE );
460 n+=j; /* crude stats */
461 }
463 DPRINTF("Received all pages\n");
465 /*
466 * Pin page tables. Do this after writing to them as otherwise Xen
467 * will barf when doing the type-checking.
468 */
469 for ( i = 0; i < nr_pfns; i++ )
470 {
471 if ( pfn_type[i] == (L1TAB|LPINTAB) )
472 {
473 if ( add_mmu_update(xc_handle, mmu,
474 (pfn_to_mfn_table[i]<<PAGE_SHIFT) |
475 MMU_EXTENDED_COMMAND,
476 MMUEXT_PIN_L1_TABLE) ) {
477 printf("ERR pin L1 pfn=%lx mfn=%lx\n",
478 (unsigned long)i, pfn_to_mfn_table[i]);
479 goto out;
480 }
481 }
482 }
484 /* must pin all L1's before L2's (need consistent va back ptr) */
485 for ( i = 0; i < nr_pfns; i++ )
486 {
487 if ( pfn_type[i] == (L2TAB|LPINTAB) )
488 {
489 if ( add_mmu_update(xc_handle, mmu,
490 (pfn_to_mfn_table[i]<<PAGE_SHIFT) |
491 MMU_EXTENDED_COMMAND,
492 MMUEXT_PIN_L2_TABLE) )
493 {
494 printf("ERR pin L2 pfn=%lx mfn=%lx\n",
495 (unsigned long)i, pfn_to_mfn_table[i]);
496 goto out;
497 }
498 }
499 }
501 if ( finish_mmu_updates(xc_handle, mmu) ) goto out;
503 xcio_info(ioctxt, "\b\b\b\b100%%\nMemory reloaded.\n");
505 /* Get the list of PFNs that are not in the psuedo-phys map */
506 {
507 unsigned int count, *pfntab;
508 int rc;
510 if ( xcio_read(ioctxt, &count, sizeof(count)) )
511 {
512 xcio_error(ioctxt, "Error when reading from state file");
513 goto out;
514 }
516 pfntab = malloc( sizeof(unsigned int) * count );
517 if ( pfntab == NULL )
518 {
519 xcio_error(ioctxt, "Out of memory");
520 goto out;
521 }
523 if ( xcio_read(ioctxt, pfntab, sizeof(unsigned int)*count) )
524 {
525 xcio_error(ioctxt, "Error when reading pfntab from state file");
526 goto out;
527 }
529 for ( i = 0; i < count; i++ )
530 {
531 unsigned long pfn = pfntab[i];
532 pfntab[i]=pfn_to_mfn_table[pfn];
533 pfn_to_mfn_table[pfn] = 0x80000001; // not in pmap
534 }
536 if ( count > 0 )
537 {
538 if ( (rc = do_dom_mem_op( xc_handle,
539 MEMOP_decrease_reservation,
540 pfntab, count, 0, dom )) <0 )
541 {
542 xcio_error(ioctxt, "Could not decrease reservation : %d",rc);
543 goto out;
544 }
545 else
546 {
547 printf("Decreased reservation by %d pages\n", count);
548 }
549 }
550 }
552 if ( xcio_read(ioctxt, &ctxt, sizeof(ctxt)) ||
553 xcio_read(ioctxt, shared_info, PAGE_SIZE) )
554 {
555 xcio_error(ioctxt, "Error when reading from state file");
556 goto out;
557 }
559 /* Uncanonicalise the suspend-record frame number and poke resume rec. */
560 pfn = ctxt.cpu_ctxt.esi;
561 if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) )
562 {
563 xcio_error(ioctxt, "Suspend record frame number is bad");
564 goto out;
565 }
566 ctxt.cpu_ctxt.esi = mfn = pfn_to_mfn_table[pfn];
567 p_srec = xc_map_foreign_range(
568 xc_handle, dom, PAGE_SIZE, PROT_WRITE, mfn);
569 p_srec->resume_info.nr_pages = nr_pfns;
570 p_srec->resume_info.shared_info = shared_info_frame << PAGE_SHIFT;
571 p_srec->resume_info.flags = 0;
572 munmap(p_srec, PAGE_SIZE);
574 /* Uncanonicalise each GDT frame number. */
575 if ( ctxt.gdt_ents > 8192 )
576 {
577 xcio_error(ioctxt, "GDT entry count out of range");
578 goto out;
579 }
581 for ( i = 0; i < ctxt.gdt_ents; i += 512 )
582 {
583 pfn = ctxt.gdt_frames[i];
584 if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) )
585 {
586 xcio_error(ioctxt, "GDT frame number is bad");
587 goto out;
588 }
589 ctxt.gdt_frames[i] = pfn_to_mfn_table[pfn];
590 }
592 /* Uncanonicalise the page table base pointer. */
593 pfn = ctxt.pt_base >> PAGE_SHIFT;
594 if ( (pfn >= nr_pfns) || ((pfn_type[pfn]&LTABTYPE_MASK) != L2TAB) )
595 {
596 printf("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx\n",
597 pfn, nr_pfns, pfn_type[pfn], (unsigned long)L2TAB);
598 xcio_error(ioctxt, "PT base is bad.");
599 goto out;
600 }
601 ctxt.pt_base = pfn_to_mfn_table[pfn] << PAGE_SHIFT;
603 /* clear any pending events and the selector */
604 memset(&(((shared_info_t *)shared_info)->evtchn_pending[0]),
605 0, sizeof (((shared_info_t *)shared_info)->evtchn_pending)+
606 sizeof(((shared_info_t *)shared_info)->evtchn_pending_sel));
608 /* Copy saved contents of shared-info page. No checking needed. */
609 ppage = xc_map_foreign_range(
610 xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
611 memcpy(ppage, shared_info, sizeof(shared_info_t));
612 munmap(ppage, PAGE_SIZE);
614 /* Uncanonicalise the pfn-to-mfn table frame-number list. */
615 for ( i = 0; i < (nr_pfns+1023)/1024; i++ )
616 {
617 unsigned long pfn, mfn;
619 pfn = pfn_to_mfn_frame_list[i];
620 if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) )
621 {
622 xcio_error(ioctxt, "PFN-to-MFN frame number is bad");
623 goto out;
624 }
625 mfn = pfn_to_mfn_table[pfn];
626 pfn_to_mfn_frame_list[i] = mfn;
627 }
629 if ( (live_pfn_to_mfn_table =
630 xc_map_foreign_batch(xc_handle, dom,
631 PROT_WRITE,
632 pfn_to_mfn_frame_list,
633 (nr_pfns+1023)/1024 )) == 0 )
634 {
635 xcio_error(ioctxt, "Couldn't map pfn_to_mfn table");
636 goto out;
637 }
639 memcpy(live_pfn_to_mfn_table, pfn_to_mfn_table,
640 nr_pfns*sizeof(unsigned long) );
642 munmap(live_pfn_to_mfn_table, ((nr_pfns+1023)/1024)*PAGE_SIZE);
644 /*
645 * Safety checking of saved context:
646 * 1. cpu_ctxt is fine, as Xen checks that on context switch.
647 * 2. fpu_ctxt is fine, as it can't hurt Xen.
648 * 3. trap_ctxt needs the code selectors checked.
649 * 4. fast_trap_idx is checked by Xen.
650 * 5. ldt base must be page-aligned, no more than 8192 ents, ...
651 * 6. gdt already done, and further checking is done by Xen.
652 * 7. check that guestos_ss is safe.
653 * 8. pt_base is already done.
654 * 9. debugregs are checked by Xen.
655 * 10. callback code selectors need checking.
656 */
657 for ( i = 0; i < 256; i++ )
658 {
659 ctxt.trap_ctxt[i].vector = i;
660 if ( (ctxt.trap_ctxt[i].cs & 3) == 0 )
661 ctxt.trap_ctxt[i].cs = FLAT_GUESTOS_CS;
662 }
663 if ( (ctxt.guestos_ss & 3) == 0 )
664 ctxt.guestos_ss = FLAT_GUESTOS_DS;
665 if ( (ctxt.event_callback_cs & 3) == 0 )
666 ctxt.event_callback_cs = FLAT_GUESTOS_CS;
667 if ( (ctxt.failsafe_callback_cs & 3) == 0 )
668 ctxt.failsafe_callback_cs = FLAT_GUESTOS_CS;
669 if ( ((ctxt.ldt_base & (PAGE_SIZE - 1)) != 0) ||
670 (ctxt.ldt_ents > 8192) ||
671 (ctxt.ldt_base > HYPERVISOR_VIRT_START) ||
672 ((ctxt.ldt_base + ctxt.ldt_ents*8) > HYPERVISOR_VIRT_START) )
673 {
674 xcio_error(ioctxt, "Bad LDT base or size");
675 goto out;
676 }
678 op.cmd = DOM0_BUILDDOMAIN;
679 op.u.builddomain.domain = (domid_t)dom;
680 op.u.builddomain.ctxt = &ctxt;
681 rc = do_dom0_op(xc_handle, &op);
683 /* don't start the domain as we have console etc to set up */
685 if ( rc == 0 )
686 {
687 /* Success: print the domain id. */
688 xcio_info(ioctxt, "DOM=%lu\n", dom);
689 return 0;
690 }
693 out:
694 if ( (rc != 0) && (dom != 0) )
695 xc_domain_destroy(xc_handle, dom);
696 if ( mmu != NULL )
697 free(mmu);
698 if ( pfn_to_mfn_table != NULL )
699 free(pfn_to_mfn_table);
700 if ( pfn_type != NULL )
701 free(pfn_type);
703 if ( rc == 0 )
704 ioctxt->domain = dom;
706 DPRINTF("Restore exit with rc=%d\n",rc);
707 return rc;
708 }