2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2011, Jack Lange <jacklange@cs.pitt.edu>
11 * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jacklange@cs.pitt.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #ifndef __VMM_CHKPT_STORES_H__
21 #define __VMM_CHKPT_STORES_H__
23 //#include <palacios/vmm_types.h>
26 * This is a place holder to ensure that the _v3_extensions section gets created by gcc
28 static struct {} null_store __attribute__((__used__)) \
29 __attribute__((unused, __section__ ("_v3_chkpt_stores"), \
30 aligned(sizeof(addr_t))));
33 #define register_chkpt_store(store) \
34 static struct chkpt_interface * _v3_store_##store \
35 __attribute__((used)) \
36 __attribute__((unused, __section__("_v3_chkpt_stores"), \
37 aligned(sizeof(addr_t)))) \
44 #include <palacios/vmm_util.h>
47 static void * debug_open_chkpt(char * url, chkpt_mode_t mode) {
50 V3_Print(VM_NONE, VCORE_NONE, "Cannot load from debug store\n");
54 V3_Print(VM_NONE, VCORE_NONE, "Opening Checkpoint: %s\n", url);
61 static int debug_close_chkpt(void * store_data) {
62 V3_Print(VM_NONE, VCORE_NONE, "Closing Checkpoint\n");
66 static void * debug_open_ctx(void * store_data,
68 V3_Print(VM_NONE, VCORE_NONE, "[%s]\n", name);
72 static int debug_close_ctx(void * store_data, void * ctx) {
73 V3_Print(VM_NONE, VCORE_NONE, "[CLOSE]\n");
77 static int debug_save(void * store_data, void * ctx,
78 char * tag, uint64_t len, void * buf) {
79 V3_Print(VM_NONE, VCORE_NONE, "%s:\n", tag);
85 v3_dump_mem(buf, len);
90 static int debug_load(void * store_data, void * ctx,
91 char * tag, uint64_t len, void * buf) {
92 V3_Print(VM_NONE, VCORE_NONE, "Loading not supported !!!\n");
97 static struct chkpt_interface debug_store = {
99 .open_chkpt = debug_open_chkpt,
100 .close_chkpt = debug_close_chkpt,
101 .open_ctx = debug_open_ctx,
102 .close_ctx = debug_close_ctx,
107 register_chkpt_store(debug_store);
111 #ifdef V3_CONFIG_KEYED_STREAMS
112 #include <interfaces/vmm_keyed_stream.h>
114 static void * keyed_stream_open_chkpt(char * url, chkpt_mode_t mode) {
116 return v3_keyed_stream_open(url, V3_KS_WR_ONLY_CREATE);
117 } else if (mode == LOAD) {
118 return v3_keyed_stream_open(url, V3_KS_RD_ONLY);
121 // Shouldn't get here
127 static int keyed_stream_close_chkpt(void * store_data) {
128 v3_keyed_stream_t stream = store_data;
130 v3_keyed_stream_close(stream);
135 static void * keyed_stream_open_ctx(void * store_data,
137 v3_keyed_stream_t stream = store_data;
139 return v3_keyed_stream_open_key(stream, name);
142 static int keyed_stream_close_ctx(void * store_data, void * ctx) {
143 v3_keyed_stream_t stream = store_data;
145 v3_keyed_stream_close_key(stream, ctx);
150 static int keyed_stream_save(void * store_data, void * ctx,
151 char * tag, uint64_t len, void * buf) {
152 if (v3_keyed_stream_write_key(store_data, ctx, tag, strlen(tag), buf, len) != len) {
159 static int keyed_stream_load(void * store_data, void * ctx,
160 char * tag, uint64_t len, void * buf) {
161 if (v3_keyed_stream_read_key(store_data, ctx, tag, strlen(tag), buf, len) != len) {
169 static struct chkpt_interface keyed_stream_store = {
170 .name = "KEYED_STREAM",
171 .open_chkpt = keyed_stream_open_chkpt,
172 .close_chkpt = keyed_stream_close_chkpt,
173 .open_ctx = keyed_stream_open_ctx,
174 .close_ctx = keyed_stream_close_ctx,
175 .save = keyed_stream_save,
176 .load = keyed_stream_load
179 register_chkpt_store(keyed_stream_store);
187 #ifdef V3_CONFIG_FILE
188 #include <interfaces/vmm_file.h>
198 static void * dir_open_chkpt(char * url, chkpt_mode_t mode) {
200 if (v3_mkdir(url, 0755, 1) != 0) {
210 static int dir_close_chkpt(void * store_data) {
214 static void * dir_open_ctx(void * store_data,
217 char * url = store_data;
218 struct file_ctx * ctx = NULL;
221 ctx = V3_Malloc(sizeof(struct file_ctx));
224 PrintError(VM_NONE, VCORE_NONE, "Cannot allocate\n");
228 memset(ctx, 0, sizeof(struct file_ctx));
230 ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5);
232 if (!ctx->filename) {
233 PrintError(VM_NONE, VCORE_NONE, "Cannot allocate\n");
239 memset(ctx->filename, 0, strlen(url) + strlen(name) + 5);
241 snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name);
244 ctx->file = v3_file_open(NULL, ctx->filename, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE | FILE_OPEN_MODE_CREATE);
249 static int dir_close_ctx(void * store_data, void * ctx) {
250 struct file_ctx * file_ctx = ctx;
252 v3_file_close(file_ctx->file);
254 V3_Free(file_ctx->filename);
260 static int dir_save(void * store_data, void * ctx,
261 char * tag, uint64_t len, void * buf) {
262 struct file_ctx * file_ctx = ctx;
265 ret = v3_file_write(file_ctx->file, buf, len, file_ctx->offset);
267 file_ctx->offset += ret;
272 static int dir_load(void * store_data, void * ctx,
273 char * tag, uint64_t len, void * buf) {
274 struct file_ctx * file_ctx = ctx;
277 ret = v3_file_read(file_ctx->file, buf, len, file_ctx->offset);
279 file_ctx->offset += ret;
285 static struct chkpt_interface dir_store = {
287 .open_chkpt = dir_open_chkpt,
288 .close_chkpt = dir_close_chkpt,
289 .open_ctx = dir_open_ctx,
290 .close_ctx = dir_close_ctx,
295 register_chkpt_store(dir_store);