Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


3c2572b8a695255af6beb11959429b52ec6ca161
[palacios.git] / palacios / src / palacios / vmm_chkpt_stores.h
1 /*
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
13  *
14  * Author: Jack Lange <jacklange@cs.pitt.edu> 
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __VMM_CHKPT_STORES_H__
21 #define __VMM_CHKPT_STORES_H__
22
23 //#include <palacios/vmm_types.h>
24
25 /*
26  * This is a place holder to ensure that the _v3_extensions section gets created by gcc
27  */
28 static struct {} null_store __attribute__((__used__))                   \
29     __attribute__((unused, __section__ ("_v3_chkpt_stores"),            \
30                    aligned(sizeof(addr_t))));
31
32
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))))                        \
38         = &store;
39
40
41
42
43
44 #include <palacios/vmm_util.h>
45
46
47 static void * debug_open_chkpt(char * url, chkpt_mode_t mode) {
48    
49     if (mode == LOAD) {
50         V3_Print("Cannot load from debug store\n");
51         return NULL;
52     }
53
54     V3_Print("Opening Checkpoint: %s\n", url);
55
56     return (void *)1;
57 }
58
59
60
61 static int debug_close_chkpt(void * store_data) {
62     V3_Print("Closing Checkpoint\n");
63     return 0;
64 }
65
66 static void * debug_open_ctx(void * store_data, 
67                              void * parent_ctx, 
68                              char * name) {
69     V3_Print("[%s]\n", name);
70     return (void *)1;
71 }
72
73 static int debug_close_ctx(void * store_data, void * ctx) {
74     V3_Print("[CLOSE]\n"); 
75     return 0;
76 }
77
78 static int debug_save(void * store_data, void * ctx, 
79                       char * tag, uint64_t len, void * buf) {
80     V3_Print("%s:\n", tag);
81
82     if (len > 100) {
83         len = 100;
84     }
85
86     v3_dump_mem(buf, len);
87     
88     return 0;
89 }
90
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");
94     return 0;
95 }
96
97
98 static struct chkpt_interface debug_store = {
99     .name = "DEBUG",
100     .open_chkpt = debug_open_chkpt,
101     .close_chkpt = debug_close_chkpt,
102     .open_ctx = debug_open_ctx, 
103     .close_ctx = debug_close_ctx,
104     .save = debug_save,
105     .load = debug_load
106 };
107
108 register_chkpt_store(debug_store);
109
110
111
112
113 #ifdef V3_CONFIG_KEYED_STREAMS
114 #include <interfaces/vmm_keyed_stream.h>
115
116 static void * keyed_stream_open_chkpt(char * url, chkpt_mode_t mode) {
117     if (mode == SAVE) {
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);
121     }
122
123     // Shouldn't get here
124     return NULL;
125 }
126
127
128
129 static int keyed_stream_close_chkpt(void * store_data) {
130     v3_keyed_stream_t stream = store_data;
131
132     v3_keyed_stream_close(stream);
133
134     return 0;
135 }
136
137 static void * keyed_stream_open_ctx(void * store_data, 
138                                     void * parent_ctx, 
139                                     char * name) {
140     v3_keyed_stream_t stream = store_data;
141
142     return v3_keyed_stream_open_key(stream, name);
143 }
144
145 static int keyed_stream_close_ctx(void * store_data, void * ctx) {
146     v3_keyed_stream_t stream = store_data;
147
148     v3_keyed_stream_close_key(stream, ctx);
149
150     return 0;
151 }
152
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) { 
156         return -1;
157     } else {
158         return 0;
159     }
160 }
161
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) { 
165         return -1;
166     } else {
167         return 0;
168     }
169 }
170
171
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
180 };
181
182 register_chkpt_store(keyed_stream_store);
183
184
185
186 #endif
187
188
189
190 #ifdef V3_CONFIG_FILE
191 #include <interfaces/vmm_file.h>
192
193
194 struct file_ctx {
195     v3_file_t file;
196     uint64_t offset;
197     char * filename;
198 };
199     
200
201 static void * dir_open_chkpt(char * url, chkpt_mode_t mode) {
202     if (mode == SAVE) {
203         if (v3_mkdir(url, 0755, 1) != 0) {
204             return NULL;
205         }
206     }
207
208     return url;
209 }
210
211
212
213 static int dir_close_chkpt(void * store_data) {
214     return 0;
215 }
216
217 static void * dir_open_ctx(void * store_data, 
218                            void * parent_ctx, 
219                            char * name) {
220
221     char * url = store_data;
222     struct file_ctx * ctx = NULL;
223
224
225     ctx = V3_Malloc(sizeof(struct file_ctx));
226     memset(ctx, 0, sizeof(struct file_ctx));
227
228     ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5);
229     memset(ctx->filename, 0, strlen(url) + strlen(name) + 5);
230
231     snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name);
232
233
234     ctx->file = v3_file_open(NULL, ctx->filename, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE | FILE_OPEN_MODE_CREATE);
235    
236     return ctx;
237 }
238
239 static int dir_close_ctx(void * store_data, void * ctx) {
240     struct file_ctx * file_ctx = ctx;
241
242     v3_file_close(file_ctx->file);
243
244     V3_Free(file_ctx->filename);
245     V3_Free(file_ctx);
246
247     return 0;
248 }
249
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;
253     uint64_t ret = 0;
254    
255     ret = v3_file_write(file_ctx->file, buf, len, file_ctx->offset);
256
257     file_ctx->offset += ret;
258     
259     return 0;
260 }
261
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;
265     uint64_t ret = 0;
266     
267     ret = v3_file_read(file_ctx->file, buf, len, file_ctx->offset);
268
269     file_ctx->offset += ret;
270
271     return 0;
272 }
273
274
275 static struct chkpt_interface dir_store = {
276     .name = "DIR",
277     .open_chkpt = dir_open_chkpt,
278     .close_chkpt = dir_close_chkpt,
279     .open_ctx = dir_open_ctx, 
280     .close_ctx = dir_close_ctx,
281     .save = dir_save,
282     .load = dir_load
283 };
284
285 register_chkpt_store(dir_store);
286
287
288
289 #endif
290
291
292
293
294
295
296
297 #endif