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.


0b9829f42c550995089e74b218d801fe7b8a2f9e
[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                              char * name) {
68     V3_Print("[%s]\n", name);
69     return (void *)1;
70 }
71
72 static int debug_close_ctx(void * store_data, void * ctx) {
73     V3_Print("[CLOSE]\n"); 
74     return 0;
75 }
76
77 static int debug_save(void * store_data, void * ctx, 
78                       char * tag, uint64_t len, void * buf) {
79     V3_Print("%s:\n", tag);
80
81     if (len > 100) {
82         len = 100;
83     }
84
85     v3_dump_mem(buf, len);
86     
87     return 0;
88 }
89
90 static int debug_load(void * store_data, void * ctx, 
91                                   char * tag, uint64_t len, void * buf) {
92     V3_Print("Loading not supported !!!\n");
93     return 0;
94 }
95
96
97 static struct chkpt_interface debug_store = {
98     .name = "DEBUG",
99     .open_chkpt = debug_open_chkpt,
100     .close_chkpt = debug_close_chkpt,
101     .open_ctx = debug_open_ctx, 
102     .close_ctx = debug_close_ctx,
103     .save = debug_save,
104     .load = debug_load
105 };
106
107 register_chkpt_store(debug_store);
108
109
110
111 #ifdef V3_CONFIG_KEYED_STREAMS
112 #include <interfaces/vmm_keyed_stream.h>
113
114 static void * keyed_stream_open_chkpt(char * url, chkpt_mode_t mode) {
115     if (mode == SAVE) {
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);
119     }
120
121     // Shouldn't get here
122     return NULL;
123 }
124
125
126
127 static int keyed_stream_close_chkpt(void * store_data) {
128     v3_keyed_stream_t stream = store_data;
129
130     v3_keyed_stream_close(stream);
131
132     return 0;
133 }
134
135 static void * keyed_stream_open_ctx(void * store_data, 
136                                     char * name) {
137     v3_keyed_stream_t stream = store_data;
138
139     return v3_keyed_stream_open_key(stream, name);
140 }
141
142 static int keyed_stream_close_ctx(void * store_data, void * ctx) {
143     v3_keyed_stream_t stream = store_data;
144
145     v3_keyed_stream_close_key(stream, ctx);
146
147     return 0;
148 }
149
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) { 
153     return -1;
154   } else {
155     return 0;
156   }
157 }
158
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) { 
162     return -1;
163   } else {
164     return 0;
165   }
166 }
167
168
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
177 };
178
179 register_chkpt_store(keyed_stream_store);
180
181
182
183 #endif
184
185
186
187 #ifdef V3_CONFIG_FILE
188 #include <interfaces/vmm_file.h>
189
190
191 struct file_ctx {
192     v3_file_t file;
193     uint64_t offset;
194     char * filename;
195 };
196     
197
198 static void * dir_open_chkpt(char * url, chkpt_mode_t mode) {
199     if (mode == SAVE) {
200         if (v3_mkdir(url, 0755, 1) != 0) {
201             return NULL;
202         }
203     }
204
205     return url;
206 }
207
208
209
210 static int dir_close_chkpt(void * store_data) {
211     return 0;
212 }
213
214 static void * dir_open_ctx(void * store_data, 
215                            char * name) {
216
217     char * url = store_data;
218     struct file_ctx * ctx = NULL;
219
220
221     ctx = V3_Malloc(sizeof(struct file_ctx));
222
223     if (!ctx) {
224         PrintError("Cannot allocate\n");
225         return NULL;
226     }
227
228     memset(ctx, 0, sizeof(struct file_ctx));
229
230     ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5);
231
232     if (!ctx->filename) {
233         PrintError("Cannot allocate\n");
234         V3_Free(ctx);
235         return NULL;
236     }
237
238
239     memset(ctx->filename, 0, strlen(url) + strlen(name) + 5);
240
241     snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name);
242
243
244     ctx->file = v3_file_open(NULL, ctx->filename, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE | FILE_OPEN_MODE_CREATE);
245    
246     return ctx;
247 }
248
249 static int dir_close_ctx(void * store_data, void * ctx) {
250     struct file_ctx * file_ctx = ctx;
251
252     v3_file_close(file_ctx->file);
253
254     V3_Free(file_ctx->filename);
255     V3_Free(file_ctx);
256
257     return 0;
258 }
259
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;
263     uint64_t ret = 0;
264    
265     ret = v3_file_write(file_ctx->file, buf, len, file_ctx->offset);
266
267     file_ctx->offset += ret;
268     
269     return 0;
270 }
271
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;
275     uint64_t ret = 0;
276     
277     ret = v3_file_read(file_ctx->file, buf, len, file_ctx->offset);
278
279     file_ctx->offset += ret;
280
281     return 0;
282 }
283
284
285 static struct chkpt_interface dir_store = {
286     .name = "DIR",
287     .open_chkpt = dir_open_chkpt,
288     .close_chkpt = dir_close_chkpt,
289     .open_ctx = dir_open_ctx, 
290     .close_ctx = dir_close_ctx,
291     .save = dir_save,
292     .load = dir_load
293 };
294
295 register_chkpt_store(dir_store);
296
297
298
299 #endif
300
301
302
303
304
305
306
307 #endif