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.


missed file commit
[palacios.git] / linux_module / palacios-stream.c
1
2 /* 
3  * VM specific Controls
4  * (c) Lei Xia, 2010
5  */
6 #include <linux/errno.h>
7 #include <linux/percpu.h>
8 #include <linux/sched.h>
9
10 #include <interfaces/vmm_stream.h>
11 #include "palacios-stream.h"
12
13 static struct list_head global_streams;
14
15 static int stream_enqueue(struct stream_buffer * stream, char * buf, int len) {
16     int bytes = 0;
17
18     bytes = ringbuf_write(stream->buf, buf, len);
19
20     return bytes;
21 }
22
23
24 int stream_dequeue(struct stream_buffer * stream, char * buf, int len) {
25     int bytes = 0;
26
27     bytes = ringbuf_read(stream->buf, buf, len);
28
29     return bytes;
30 }
31
32 int stream_datalen(struct stream_buffer * stream){
33     return ringbuf_data_len(stream->buf);
34 }
35
36
37 int open_stream(const char * name) {
38     return -1;
39 }
40
41
42
43 struct stream_buffer * find_stream_by_name(struct v3_guest * guest, const char * name) {
44     struct stream_buffer * stream = NULL;
45     struct list_head * stream_list = NULL;
46
47     if (guest == NULL) {
48         stream_list = &global_streams;
49     } else {
50         stream_list = &(guest->streams);
51     }
52
53     list_for_each_entry(stream,  stream_list, stream_node) {
54         if (strncmp(stream->name, name, STREAM_NAME_LEN) == 0) {
55             return stream;
56         }
57     }
58
59     return NULL;
60 }
61
62
63 static void * palacios_stream_open(const char * name, void * private_data) {
64     struct v3_guest * guest = (struct v3_guest *)private_data;
65     struct stream_buffer * stream = NULL;
66
67     if (find_stream_by_name(guest, name) != NULL) {
68         printk("Stream already exists\n");
69         return NULL;
70     }
71
72     stream = kmalloc(sizeof(struct stream_buffer), GFP_KERNEL);
73         
74     stream->buf = create_ringbuf(STREAM_BUF_SIZE);
75     stream->guest = guest;
76
77     strncpy(stream->name, name, STREAM_NAME_LEN - 1);
78
79     init_waitqueue_head(&(stream->intr_queue));
80     spin_lock_init(&(stream->lock));
81
82     if (guest == NULL) {
83         list_add(&(stream->stream_node), &(global_streams));
84     } else {
85         list_add(&(stream->stream_node), &(guest->streams));
86     } 
87
88     return stream;
89 }
90
91
92 static int palacios_stream_write(void * stream_ptr, char * buf, int len) {
93     struct stream_buffer * stream = (struct stream_buffer *)stream_ptr;
94     int ret = 0;
95
96     ret = stream_enqueue(stream, buf, len);
97
98     if (ret > 0) {
99         wake_up_interruptible(&(stream->intr_queue));
100     }
101
102     return ret;
103 }
104
105
106 static void palacios_stream_close(void * stream_ptr) {
107     struct stream_buffer * stream = (struct stream_buffer *)stream_ptr;
108
109     free_ringbuf(stream->buf);
110     list_del(&(stream->stream_node));
111     kfree(stream);
112
113 }
114
115 struct v3_stream_hooks palacios_stream_hooks = {
116     .open = palacios_stream_open,
117     .write = palacios_stream_write,
118     .close = palacios_stream_close,
119 };
120
121
122 void palacios_init_stream() {
123     INIT_LIST_HEAD(&(global_streams));
124     V3_Init_Stream(&palacios_stream_hooks);
125 }
126
127
128 void palacios_deinit_stream() {
129     if (!list_empty(&(global_streams))) {
130         printk("Error removing module with open streams\n");
131     }
132 }