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
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/types.h>
40 #include <sys/systm.h>
42 #include <machine/vmm_snapshot.h>
45 vm_snapshot_buf_err(const char *bufname, const enum vm_snapshot_op op)
49 if (op == VM_SNAPSHOT_SAVE)
51 else if (op == VM_SNAPSHOT_RESTORE)
56 printf("%s: snapshot-%s failed for %s\r\n", __func__, opstr, bufname);
60 vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta)
62 struct vm_snapshot_buffer *buffer;
65 buffer = &meta->buffer;
68 if (buffer->buf_rem < data_size) {
69 printf("%s: buffer too small\r\n", __func__);
73 if (op == VM_SNAPSHOT_SAVE)
74 copyout(data, buffer->buf, data_size);
75 else if (op == VM_SNAPSHOT_RESTORE)
76 copyin(buffer->buf, data, data_size);
80 buffer->buf += data_size;
81 buffer->buf_rem -= data_size;
87 vm_get_snapshot_size(struct vm_snapshot_meta *meta)
90 struct vm_snapshot_buffer *buffer;
92 buffer = &meta->buffer;
94 if (buffer->buf_size < buffer->buf_rem) {
95 printf("%s: Invalid buffer: size = %zu, rem = %zu\r\n",
96 __func__, buffer->buf_size, buffer->buf_rem);
99 length = buffer->buf_size - buffer->buf_rem;
106 vm_snapshot_buf_cmp(void *data, size_t data_size, struct vm_snapshot_meta *meta)
108 struct vm_snapshot_buffer *buffer;
112 buffer = &meta->buffer;
115 if (buffer->buf_rem < data_size) {
116 printf("%s: buffer too small\r\n", __func__);
121 if (op == VM_SNAPSHOT_SAVE) {
123 copyout(data, buffer->buf, data_size);
124 } else if (op == VM_SNAPSHOT_RESTORE) {
125 ret = memcmp(data, buffer->buf, data_size);
131 buffer->buf += data_size;
132 buffer->buf_rem -= data_size;