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, Peter Dinda <pdinda@northwestern.edu>
11 * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Peter Dinda <pdinda@northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #ifndef __VMM_KEYED_STREAM_H__
22 #define __VMM_KEYED_STREAM_H__
24 #include <palacios/vmm.h>
28 A keyed stream essentially supports this:
30 URL => {collection of key->stream pairs}
32 If you open a key for reading, you get the read pointer set to its beginning.
33 You can then make repeated reads to advance the read pointer. You cannot seek.
35 Writing works similarly.
37 You cannot both read and write.
41 /* A keyed stream and its components are opaque to palacios */
42 typedef void * v3_keyed_stream_t;
43 typedef void * v3_keyed_stream_key_t;
45 typedef enum {V3_KS_RD_ONLY,V3_KS_WR_ONLY,V3_KS_WR_ONLY_CREATE} v3_keyed_stream_open_t;
50 v3_keyed_stream_t v3_keyed_stream_open(char *url, v3_keyed_stream_open_t open_type);
51 void v3_keyed_stream_close(v3_keyed_stream_t stream);
52 void v3_keyed_stream_preallocate_hint_key(v3_keyed_stream_t stream, char *key, uint64_t size);
53 v3_keyed_stream_key_t v3_keyed_stream_open_key(v3_keyed_stream_t stream, char *key);
54 void v3_keyed_stream_close_key(v3_keyed_stream_t stream, char *key);
55 sint64_t v3_keyed_stream_write_key(v3_keyed_stream_t stream,
56 v3_keyed_stream_key_t key,
59 sint64_t v3_keyed_stream_read_key(v3_keyed_stream_t stream,
60 v3_keyed_stream_key_t key,
64 #define STD_SAVE(stream,ks,x) \
66 if (sizeof((x)) != v3_keyed_stream_write_key((stream), (ks), &(x), sizeof((x)))) { \
67 v3_keyed_stream_close_key((stream),(ks)); \
72 #define STD_LOAD(stream,ks,x) \
74 if (sizeof((x)) != v3_keyed_stream_read_key((stream), (ks), &(x), sizeof((x)))) { \
75 v3_keyed_stream_close_key((stream),(ks)); \
82 struct v3_keyed_stream_hooks {
83 // url is meaningful only to the host implementation
84 v3_keyed_stream_t (*open)(char *url,
85 v3_keyed_stream_open_t open_type);
87 void (*close)(v3_keyed_stream_t stream);
89 void (*preallocate_hint_key)(v3_keyed_stream_t stream,
93 v3_keyed_stream_key_t (*open_key)(v3_keyed_stream_t stream,
96 void (*close_key)(v3_keyed_stream_t stream,
97 v3_keyed_stream_key_t key);
100 sint64_t (*write_key)(v3_keyed_stream_t stream,
101 v3_keyed_stream_key_t key,
105 sint64_t (*read_key)(v3_keyed_stream_t stream,
106 v3_keyed_stream_key_t key,
113 extern void V3_Init_Keyed_Streams(struct v3_keyed_stream_hooks *hooks);