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("Cannot load from debug store\n");
54 V3_Print("Opening Checkpoint: %s\n", url);
61 static int debug_close_chkpt(void * store_data) {
62 V3_Print("Closing Checkpoint\n");
66 static void * debug_open_ctx(void * store_data,
69 V3_Print("[%s]\n", name);
73 static int debug_close_ctx(void * store_data, void * ctx) {
74 V3_Print("[CLOSE]\n");
78 static int debug_save(void * store_data, void * ctx,
79 char * tag, uint64_t len, void * buf) {
80 V3_Print("%s:\n", tag);
86 v3_dump_mem(buf, len);
91 static int debug_load(void * store_data, void * ctx,
92 char * tag, uint64_t len, void * buf) {
93 V3_Print("Loading not supported !!!\n");
98 static struct chkpt_interface debug_store = {
100 .open_chkpt = debug_open_chkpt,
101 .close_chkpt = debug_close_chkpt,
102 .open_ctx = debug_open_ctx,
103 .close_ctx = debug_close_ctx,
108 register_chkpt_store(debug_store);
113 #ifdef V3_CONFIG_KEYED_STREAMS
114 #include <interfaces/vmm_keyed_stream.h>
116 static void * keyed_stream_open_chkpt(char * url, chkpt_mode_t mode) {
118 return v3_keyed_stream_open(url, V3_KS_WR_ONLY_CREATE);
119 } else if (mode == LOAD) {
120 return v3_keyed_stream_open(url, V3_KS_RD_ONLY);
123 // Shouldn't get here
129 static int keyed_stream_close_chkpt(void * store_data) {
130 v3_keyed_stream_t stream = store_data;
132 v3_keyed_stream_close(stream);
137 static void * keyed_stream_open_ctx(void * store_data,
140 v3_keyed_stream_t stream = store_data;
142 return v3_keyed_stream_open_key(stream, name);
145 static int keyed_stream_close_ctx(void * store_data, void * ctx) {
146 v3_keyed_stream_t stream = store_data;
148 v3_keyed_stream_close_key(stream, ctx);
153 static int keyed_stream_save(void * store_data, void * ctx,
154 char * tag, uint64_t len, void * buf) {
155 if (v3_keyed_stream_write_key(store_data, ctx, buf, len) != len) {
162 static int keyed_stream_load(void * store_data, void * ctx,
163 char * tag, uint64_t len, void * buf) {
164 if (v3_keyed_stream_read_key(store_data, ctx, buf, len) != len) {
172 static struct chkpt_interface keyed_stream_store = {
173 .name = "KEYED_STREAM",
174 .open_chkpt = keyed_stream_open_chkpt,
175 .close_chkpt = keyed_stream_close_chkpt,
176 .open_ctx = keyed_stream_open_ctx,
177 .close_ctx = keyed_stream_close_ctx,
178 .save = keyed_stream_save,
179 .load = keyed_stream_load
182 register_chkpt_store(keyed_stream_store);
190 #ifdef V3_CONFIG_FILE
191 #include <interfaces/vmm_file.h>
201 static void * dir_open_chkpt(char * url, chkpt_mode_t mode) {
203 if (v3_mkdir(url, 0755, 1) != 0) {
213 static int dir_close_chkpt(void * store_data) {
217 static void * dir_open_ctx(void * store_data,
221 char * url = store_data;
222 struct file_ctx * ctx = NULL;
225 ctx = V3_Malloc(sizeof(struct file_ctx));
226 memset(ctx, 0, sizeof(struct file_ctx));
228 ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5);
229 memset(ctx->filename, 0, strlen(url) + strlen(name) + 5);
231 snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name);
234 ctx->file = v3_file_open(NULL, ctx->filename, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE | FILE_OPEN_MODE_CREATE);
239 static int dir_close_ctx(void * store_data, void * ctx) {
240 struct file_ctx * file_ctx = ctx;
242 v3_file_close(file_ctx->file);
244 V3_Free(file_ctx->filename);
250 static int dir_save(void * store_data, void * ctx,
251 char * tag, uint64_t len, void * buf) {
252 struct file_ctx * file_ctx = ctx;
255 ret = v3_file_write(file_ctx->file, buf, len, file_ctx->offset);
257 file_ctx->offset += ret;
262 static int dir_load(void * store_data, void * ctx,
263 char * tag, uint64_t len, void * buf) {
264 struct file_ctx * file_ctx = ctx;
267 ret = v3_file_read(file_ctx->file, buf, len, file_ctx->offset);
269 file_ctx->offset += ret;
275 static struct chkpt_interface dir_store = {
277 .open_chkpt = dir_open_chkpt,
278 .close_chkpt = dir_close_chkpt,
279 .open_ctx = dir_open_ctx,
280 .close_ctx = dir_close_ctx,
285 register_chkpt_store(dir_store);