Lines Matching refs:ctx
10 static int read_headers(struct xc_sr_context *ctx) in read_headers() argument
12 xc_interface *xch = ctx->xch; in read_headers()
16 if ( read_exact(ctx->fd, &ihdr, sizeof(ihdr)) ) in read_headers()
51 ctx->restore.format_version = ihdr.version; in read_headers()
53 if ( read_exact(ctx->fd, &dhdr, sizeof(dhdr)) ) in read_headers()
59 ctx->restore.guest_type = dhdr.type; in read_headers()
60 ctx->restore.guest_page_size = (1U << dhdr.page_shift); in read_headers()
77 static bool pfn_is_populated(const struct xc_sr_context *ctx, xen_pfn_t pfn) in pfn_is_populated() argument
79 if ( pfn > ctx->restore.max_populated_pfn ) in pfn_is_populated()
81 return test_bit(pfn, ctx->restore.populated_pfns); in pfn_is_populated()
89 static int pfn_set_populated(struct xc_sr_context *ctx, xen_pfn_t pfn) in pfn_set_populated() argument
91 xc_interface *xch = ctx->xch; in pfn_set_populated()
93 if ( pfn > ctx->restore.max_populated_pfn ) in pfn_set_populated()
110 old_sz = bitmap_size(ctx->restore.max_populated_pfn + 1); in pfn_set_populated()
112 p = realloc(ctx->restore.populated_pfns, new_sz); in pfn_set_populated()
122 ctx->restore.populated_pfns = p; in pfn_set_populated()
123 ctx->restore.max_populated_pfn = new_max; in pfn_set_populated()
126 assert(!test_bit(pfn, ctx->restore.populated_pfns)); in pfn_set_populated()
127 set_bit(pfn, ctx->restore.populated_pfns); in pfn_set_populated()
137 int populate_pfns(struct xc_sr_context *ctx, unsigned int count, in populate_pfns() argument
140 xc_interface *xch = ctx->xch; in populate_pfns()
158 !pfn_is_populated(ctx, original_pfns[i]) ) in populate_pfns()
160 rc = pfn_set_populated(ctx, original_pfns[i]); in populate_pfns()
171 xch, ctx->domid, nr_pfns, 0, 0, mfns); in populate_pfns()
187 ctx->restore.ops.set_gfn(ctx, pfns[i], mfns[i]); in populate_pfns()
205 static int process_page_data(struct xc_sr_context *ctx, unsigned int count, in process_page_data() argument
208 xc_interface *xch = ctx->xch; in process_page_data()
225 rc = populate_pfns(ctx, count, pfns, types); in process_page_data()
234 ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); in process_page_data()
252 mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); in process_page_data()
262 xch->fmem, ctx->domid, PROT_READ | PROT_WRITE, in process_page_data()
292 rc = ctx->restore.ops.localise_page(ctx, types[i], page_data); in process_page_data()
300 if ( ctx->restore.verify ) in process_page_data()
335 static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) in handle_page_data() argument
337 xc_interface *xch = ctx->xch; in handle_page_data()
352 if ( ctx->restore.format_version < 3 && !ctx->restore.seen_static_data_end ) in handle_page_data()
354 rc = handle_static_data_end(ctx); in handle_page_data()
363 if ( !ctx->restore.seen_static_data_end ) in handle_page_data()
402 if ( !ctx->restore.ops.pfn_is_valid(ctx, pfn) ) in handle_page_data()
436 rc = process_page_data(ctx, pages->count, pfns, types, in handle_page_data()
448 static int send_checkpoint_dirty_pfn_list(struct xc_sr_context *ctx) in send_checkpoint_dirty_pfn_list() argument
450 xc_interface *xch = ctx->xch; in send_checkpoint_dirty_pfn_list()
455 xc_shadow_op_stats_t stats = { 0, ctx->restore.p2m_size }; in send_checkpoint_dirty_pfn_list()
460 &ctx->restore.dirty_bitmap_hbuf); in send_checkpoint_dirty_pfn_list()
463 xch, ctx->domid, XEN_DOMCTL_SHADOW_OP_CLEAN, in send_checkpoint_dirty_pfn_list()
464 HYPERCALL_BUFFER(dirty_bitmap), ctx->restore.p2m_size, in send_checkpoint_dirty_pfn_list()
465 NULL, 0, &stats) != ctx->restore.p2m_size ) in send_checkpoint_dirty_pfn_list()
471 for ( i = 0, count = 0; i < ctx->restore.p2m_size; i++ ) in send_checkpoint_dirty_pfn_list()
486 for ( i = 0, written = 0; i < ctx->restore.p2m_size; ++i ) in send_checkpoint_dirty_pfn_list()
519 if ( writev_exact(ctx->restore.send_back_fd, iov, 3) ) in send_checkpoint_dirty_pfn_list()
532 static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);
533 static int handle_checkpoint(struct xc_sr_context *ctx) in handle_checkpoint() argument
535 xc_interface *xch = ctx->xch; in handle_checkpoint()
539 if ( ctx->stream_type == XC_STREAM_PLAIN ) in handle_checkpoint()
546 ret = ctx->restore.callbacks->checkpoint(ctx->restore.callbacks->data); in handle_checkpoint()
553 if ( ctx->restore.buffer_all_records ) in handle_checkpoint()
565 if ( ctx->restore.buffer_all_records ) in handle_checkpoint()
569 for ( i = 0; i < ctx->restore.buffered_rec_num; i++ ) in handle_checkpoint()
571 rc = process_record(ctx, &ctx->restore.buffered_records[i]); in handle_checkpoint()
575 ctx->restore.buffered_rec_num = 0; in handle_checkpoint()
579 ctx->restore.buffer_all_records = true; in handle_checkpoint()
581 if ( ctx->stream_type == XC_STREAM_COLO ) in handle_checkpoint()
600 rc = ctx->restore.ops.stream_complete(ctx); in handle_checkpoint()
604 ctx->restore.callbacks->restore_results(ctx->restore.xenstore_gfn, in handle_checkpoint()
605 ctx->restore.console_gfn, in handle_checkpoint()
606 ctx->restore.callbacks->data); in handle_checkpoint()
609 ret = ctx->restore.callbacks->postcopy(ctx->restore.callbacks->data); in handle_checkpoint()
613 ret = ctx->restore.callbacks->wait_checkpoint( in handle_checkpoint()
614 ctx->restore.callbacks->data); in handle_checkpoint()
618 ret = ctx->restore.callbacks->suspend(ctx->restore.callbacks->data); in handle_checkpoint()
623 rc = send_checkpoint_dirty_pfn_list(ctx); in handle_checkpoint()
632 static int buffer_record(struct xc_sr_context *ctx, struct xc_sr_record *rec) in buffer_record() argument
634 xc_interface *xch = ctx->xch; in buffer_record()
638 if ( ctx->restore.buffered_rec_num >= ctx->restore.allocated_rec_num ) in buffer_record()
640 new_alloc_num = ctx->restore.allocated_rec_num + DEFAULT_BUF_RECORDS; in buffer_record()
641 p = realloc(ctx->restore.buffered_records, in buffer_record()
649 ctx->restore.buffered_records = p; in buffer_record()
650 ctx->restore.allocated_rec_num = new_alloc_num; in buffer_record()
653 memcpy(&ctx->restore.buffered_records[ctx->restore.buffered_rec_num++], in buffer_record()
659 int handle_static_data_end(struct xc_sr_context *ctx) in handle_static_data_end() argument
661 xc_interface *xch = ctx->xch; in handle_static_data_end()
665 if ( ctx->restore.seen_static_data_end ) in handle_static_data_end()
671 ctx->restore.seen_static_data_end = true; in handle_static_data_end()
673 rc = ctx->restore.ops.static_data_complete(ctx, &missing); in handle_static_data_end()
677 if ( ctx->restore.callbacks->static_data_done && in handle_static_data_end()
678 (rc = ctx->restore.callbacks->static_data_done( in handle_static_data_end()
679 missing, ctx->restore.callbacks->data) != 0) ) in handle_static_data_end()
685 static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec) in process_record() argument
687 xc_interface *xch = ctx->xch; in process_record()
696 rc = handle_page_data(ctx, rec); in process_record()
701 ctx->restore.verify = true; in process_record()
705 rc = handle_checkpoint(ctx); in process_record()
709 rc = handle_static_data_end(ctx); in process_record()
713 rc = ctx->restore.ops.process_record(ctx, rec); in process_record()
723 static int setup(struct xc_sr_context *ctx) in setup() argument
725 xc_interface *xch = ctx->xch; in setup()
728 &ctx->restore.dirty_bitmap_hbuf); in setup()
730 if ( ctx->stream_type == XC_STREAM_COLO ) in setup()
733 xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size))); in setup()
743 rc = ctx->restore.ops.setup(ctx); in setup()
747 ctx->restore.max_populated_pfn = (32 * 1024 / 4) - 1; in setup()
748 ctx->restore.populated_pfns = bitmap_alloc( in setup()
749 ctx->restore.max_populated_pfn + 1); in setup()
750 if ( !ctx->restore.populated_pfns ) in setup()
757 ctx->restore.buffered_records = malloc( in setup()
759 if ( !ctx->restore.buffered_records ) in setup()
765 ctx->restore.allocated_rec_num = DEFAULT_BUF_RECORDS; in setup()
771 static void cleanup(struct xc_sr_context *ctx) in cleanup() argument
773 xc_interface *xch = ctx->xch; in cleanup()
776 &ctx->restore.dirty_bitmap_hbuf); in cleanup()
778 for ( i = 0; i < ctx->restore.buffered_rec_num; i++ ) in cleanup()
779 free(ctx->restore.buffered_records[i].data); in cleanup()
781 if ( ctx->stream_type == XC_STREAM_COLO ) in cleanup()
783 xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size))); in cleanup()
785 free(ctx->restore.buffered_records); in cleanup()
786 free(ctx->restore.populated_pfns); in cleanup()
788 if ( ctx->restore.ops.cleanup(ctx) ) in cleanup()
795 static int restore(struct xc_sr_context *ctx) in restore() argument
797 xc_interface *xch = ctx->xch; in restore()
803 rc = setup(ctx); in restore()
809 rc = read_record(ctx, ctx->fd, &rec); in restore()
812 if ( ctx->restore.buffer_all_records ) in restore()
818 if ( ctx->restore.buffer_all_records && in restore()
822 rc = buffer_record(ctx, &rec); in restore()
828 rc = process_record(ctx, &rec); in restore()
851 if ( ctx->stream_type == XC_STREAM_COLO ) in restore()
863 rc = ctx->restore.ops.stream_complete(ctx); in restore()
876 cleanup(ctx); in restore()
895 struct xc_sr_context ctx = { in xc_domain_restore() local
902 ctx.restore.console_evtchn = console_evtchn; in xc_domain_restore()
903 ctx.restore.console_domid = console_domid; in xc_domain_restore()
904 ctx.restore.xenstore_evtchn = store_evtchn; in xc_domain_restore()
905 ctx.restore.xenstore_domid = store_domid; in xc_domain_restore()
906 ctx.restore.callbacks = callbacks; in xc_domain_restore()
907 ctx.restore.send_back_fd = send_back_fd; in xc_domain_restore()
929 if ( xc_domain_getinfo(xch, dom, 1, &ctx.dominfo) != 1 ) in xc_domain_restore()
935 if ( ctx.dominfo.domid != dom ) in xc_domain_restore()
942 io_fd, dom, ctx.dominfo.hvm, stream_type); in xc_domain_restore()
944 ctx.domid = dom; in xc_domain_restore()
946 if ( read_headers(&ctx) ) in xc_domain_restore()
955 ctx.restore.p2m_size = nr_pfns; in xc_domain_restore()
956 ctx.restore.ops = ctx.dominfo.hvm in xc_domain_restore()
959 if ( restore(&ctx) ) in xc_domain_restore()
963 ctx.restore.xenstore_gfn, in xc_domain_restore()
964 ctx.restore.xenstore_domid, in xc_domain_restore()
965 ctx.restore.xenstore_evtchn); in xc_domain_restore()
968 ctx.restore.console_gfn, in xc_domain_restore()
969 ctx.restore.console_domid, in xc_domain_restore()
970 ctx.restore.console_evtchn); in xc_domain_restore()
972 *console_gfn = ctx.restore.console_gfn; in xc_domain_restore()
973 *store_mfn = ctx.restore.xenstore_gfn; in xc_domain_restore()