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 return v3_keyed_stream_write_key(store_data, ctx, buf, len);
158 static int keyed_stream_load(void * store_data, void * ctx,
159 char * tag, uint64_t len, void * buf) {
160 return v3_keyed_stream_read_key(store_data, ctx, buf, len);
164 static struct chkpt_interface keyed_stream_store = {
165 .name = "KEYED_STREAM",
166 .open_chkpt = keyed_stream_open_chkpt,
167 .close_chkpt = keyed_stream_close_chkpt,
168 .open_ctx = keyed_stream_open_ctx,
169 .close_ctx = keyed_stream_close_ctx,
170 .save = keyed_stream_save,
171 .load = keyed_stream_load
174 register_chkpt_store(keyed_stream_store);
182 #ifdef V3_CONFIG_FILE
183 #include <interfaces/vmm_file.h>
193 static void * dir_open_chkpt(char * url, chkpt_mode_t mode) {
195 if (v3_mkdir(url, 0755, 1) != 0) {
205 static int dir_close_chkpt(void * store_data) {
209 static void * dir_open_ctx(void * store_data,
213 char * url = store_data;
214 struct file_ctx * ctx = NULL;
217 ctx = V3_Malloc(sizeof(struct file_ctx));
218 memset(ctx, 0, sizeof(struct file_ctx));
220 ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5);
221 memset(ctx->filename, 0, strlen(url) + strlen(name) + 5);
223 snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name);
226 ctx->file = v3_file_open(NULL, ctx->filename, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE | FILE_OPEN_MODE_CREATE);
231 static int dir_close_ctx(void * store_data, void * ctx) {
232 struct file_ctx * file_ctx = ctx;
234 v3_file_close(file_ctx->file);
236 V3_Free(file_ctx->filename);
242 static int dir_save(void * store_data, void * ctx,
243 char * tag, uint64_t len, void * buf) {
244 struct file_ctx * file_ctx = ctx;
247 ret = v3_file_write(file_ctx->file, buf, len, file_ctx->offset);
249 file_ctx->offset += ret;
254 static int dir_load(void * store_data, void * ctx,
255 char * tag, uint64_t len, void * buf) {
256 struct file_ctx * file_ctx = ctx;
259 ret = v3_file_read(file_ctx->file, buf, len, file_ctx->offset);
261 file_ctx->offset += ret;
267 static struct chkpt_interface dir_store = {
269 .open_chkpt = dir_open_chkpt,
270 .close_chkpt = dir_close_chkpt,
271 .open_ctx = dir_open_ctx,
272 .close_ctx = dir_close_ctx,
277 register_chkpt_store(dir_store);