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.


Merge branch 'devel' of newskysaw.cs.northwestern.edu:/home/palacios/palacios into...
[palacios.git] / linux_usr / v3_user_keyed_stream.c
1 #include <unistd.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <malloc.h>
5 #include <string.h>
6 #include <stdio.h>
7
8 #include "v3_user_keyed_stream.h"
9
10
11 int v3_user_keyed_stream_attach(char *vmdev, char *url)
12 {
13     int vmfd;
14     int devfd;
15
16     struct palacios_user_keyed_stream_url *u;
17
18     u=malloc(sizeof(struct palacios_user_keyed_stream_url)+strlen(url)+1);
19
20     if (!u) { 
21         return -1;
22     }
23
24     strcpy(u->url,url);
25     u->len = strlen(url)+1;
26
27
28     if ((vmfd=open(vmdev,O_RDWR))<0) { 
29         free(u);
30         return -1;
31     }
32
33     devfd = ioctl(vmfd,V3_VM_KSTREAM_USER_CONNECT,u);
34     
35     close(vmfd);
36
37     free(u);
38
39     return devfd;
40
41 }
42 int v3_user_keyed_stream_detach(int devfd)
43 {
44     return close(devfd);
45 }
46
47
48 int v3_user_keyed_stream_have_request(int devfd)
49 {
50     uint64_t len;
51
52     int rc=ioctl(devfd,V3_KSTREAM_REQUEST_SIZE_IOCTL,&len);
53
54     return rc==1;
55 }
56
57 int v3_user_keyed_stream_pull_request(int devfd, struct palacios_user_keyed_stream_op **req)
58 {
59     uint64_t len;
60     int rc;
61
62     rc=ioctl(devfd,V3_KSTREAM_REQUEST_SIZE_IOCTL,&len);
63
64     if (rc<=0) { 
65         return -1;
66     } else {
67         struct palacios_user_keyed_stream_op *r = malloc(len);
68
69         if (!r) { 
70             fprintf(stderr,"malloc failed\n");
71             return -1;
72         }
73
74         rc=ioctl(devfd, V3_KSTREAM_REQUEST_PULL_IOCTL,r);
75
76         
77         if (rc<=0) { 
78             free(r);
79             return -1;
80         } else {
81             *req=r;
82             return 0;
83         }
84     }
85 }
86                 
87
88 int v3_user_keyed_stream_push_response(int devfd, struct palacios_user_keyed_stream_op *resp)
89 {
90     int rc;
91
92     rc=ioctl(devfd,V3_KSTREAM_RESPONSE_PUSH_IOCTL,resp);
93
94     if (rc<=0) { 
95         return -1;
96     } else {
97         return 0;
98     }
99 }
100                 
101
102
103
104