2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2016 Flavius Anton
5 * Copyright (c) 2016 Mihai Tiganus
6 * Copyright (c) 2016-2019 Mihai Carabas
7 * Copyright (c) 2017-2019 Darius Mihai
8 * Copyright (c) 2017-2019 Elena Mihailescu
9 * Copyright (c) 2018-2019 Sergiu Weisz
10 * All rights reserved.
11 * The bhyve-snapshot feature was developed under sponsorships
12 * from Matthew Grooms.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #ifndef _BHYVE_SNAPSHOT_
39 #define _BHYVE_SNAPSHOT_
41 #include <machine/vmm_snapshot.h>
45 #define BHYVE_RUN_DIR "/var/run/bhyve/"
46 #define MAX_SNAPSHOT_FILENAME PATH_MAX
50 struct restore_state {
59 struct ucl_parser *meta_parser;
60 ucl_object_t *meta_root_obj;
63 /* Filename that will be used for save/restore */
64 struct checkpoint_op {
65 char snapshot_filename[MAX_SNAPSHOT_FILENAME];
68 /* Messages that a bhyve process understands. */
75 * The type of message and associated data to
76 * send to a bhyve process.
82 * message specific structures
84 struct checkpoint_op op;
88 struct checkpoint_thread_info {
93 typedef int (*vm_snapshot_dev_cb)(struct vm_snapshot_meta *);
94 typedef int (*vm_pause_dev_cb) (struct vmctx *, const char *);
95 typedef int (*vm_resume_dev_cb) (struct vmctx *, const char *);
97 struct vm_snapshot_dev_info {
98 const char *dev_name; /* device name */
99 vm_snapshot_dev_cb snapshot_cb; /* callback for device snapshot */
100 vm_pause_dev_cb pause_cb; /* callback for device pause */
101 vm_resume_dev_cb resume_cb; /* callback for device resume */
104 struct vm_snapshot_kern_info {
105 const char *struct_name; /* kernel structure name*/
106 enum snapshot_req req; /* request type */
109 void destroy_restore_state(struct restore_state *rstate);
111 const char *lookup_vmname(struct restore_state *rstate);
112 int lookup_memflags(struct restore_state *rstate);
113 size_t lookup_memsize(struct restore_state *rstate);
114 int lookup_guest_ncpus(struct restore_state *rstate);
116 void checkpoint_cpu_add(int vcpu);
117 void checkpoint_cpu_resume(int vcpu);
118 void checkpoint_cpu_suspend(int vcpu);
120 int restore_vm_mem(struct vmctx *ctx, struct restore_state *rstate);
121 int vm_restore_kern_structs(struct vmctx *ctx, struct restore_state *rstate);
123 int vm_restore_user_devs(struct vmctx *ctx, struct restore_state *rstate);
124 int vm_pause_user_devs(struct vmctx *ctx);
125 int vm_resume_user_devs(struct vmctx *ctx);
127 int get_checkpoint_msg(int conn_fd, struct vmctx *ctx);
128 void *checkpoint_thread(void *param);
129 int init_checkpoint_thread(struct vmctx *ctx);
130 void init_snapshot(void);
132 int load_restore_file(const char *filename, struct restore_state *rstate);