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.


Updated kernel module and user tools to reflect ioctl changes for host devices
[palacios.git] / linux_usr / v3_os_debug.c
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <string.h>
6 #include <sys/select.h>
7 #include <malloc.h>
8
9 #include "v3_user_host_dev.h"
10
11 void usage()
12 {
13     fprintf(stderr,"v3_user_host_dev_example /dev/v3-vm0 user:mydev busywait|select\n");
14 }
15
16
17 int do_work(struct palacios_host_dev_host_request_response *req, 
18             struct palacios_host_dev_host_request_response **resp)
19 {
20     uint64_t datasize;
21
22     switch (req->type) {
23     case PALACIOS_HOST_DEV_HOST_REQUEST_WRITE_IO: {
24       if (req->port==0xc0c0) {
25         uint64_t i;
26         uint64_t numchars;
27         numchars = req->data_len - sizeof(struct palacios_host_dev_host_request_response);
28         for (i=0;i<numchars;i++) { 
29           putchar(req->data[i]);
30         }
31         *resp = malloc(sizeof(struct palacios_host_dev_host_request_response));
32         **resp=*req;
33         (*resp)->len = (*resp)->data_len = sizeof(struct palacios_host_dev_host_request_response);
34         (*resp)->op_len = numchars;
35       } else {
36         printf("Huh?  Unknown port %d\n",req->port);
37       }
38     }
39       break;
40
41       default:
42         printf("Huh?  Unknown request %d\n", req->type);
43     }
44     
45     
46     return 0;
47 }
48
49 int main(int argc, char *argv[])
50 {
51     int devfd;
52     int mode=0;
53     char *vm, *url;
54
55     if (argc!=4) { 
56         usage();
57         exit(-1);
58     }
59     
60     vm=argv[1];
61     url=argv[2];
62     mode = argv[3][0]=='s';
63
64     fprintf(stderr,"Attempting to rendezvous with host device %s on vm %s\n", url, vm);
65     
66     if ((devfd = v3_user_host_dev_rendezvous(vm,url))<0) { 
67         perror("failed to rendezvous");
68         exit(-1);
69     }
70     
71     fprintf(stderr,"Rendezvous succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
72     
73     if (mode==0) { 
74         //busywait
75
76         struct palacios_host_dev_host_request_response *req;
77         struct palacios_host_dev_host_request_response *resp;
78         uint64_t datasize;
79
80         while (1) { 
81             while (!(v3_user_host_dev_have_request(devfd))) { 
82             }
83             v3_user_host_dev_pull_request(devfd, &req);
84
85             do_work(req, &resp);
86             
87             v3_user_host_dev_push_response(devfd, resp);
88
89             free(resp);
90             free(req);
91         }
92     } else {
93
94         struct palacios_host_dev_host_request_response *req;
95         struct palacios_host_dev_host_request_response *resp;
96         uint64_t datasize;
97         fd_set   readset;
98         int rc;
99
100         // select-based operation so that you can wait for multiple things
101         
102         while (1) { 
103             FD_ZERO(&readset);
104             FD_SET(devfd,&readset);
105
106             rc = select(devfd+1, &readset, 0, 0, 0);  // pick whatever you want to select on, just include devfd
107
108             if (rc>0) { 
109                 if (FD_ISSET(devfd,&readset)) { 
110                     // a request is read for us!
111                     v3_user_host_dev_pull_request(devfd, &req);
112
113                     do_work(req, &resp);
114                     
115                     v3_user_host_dev_push_response(devfd, resp);
116                     
117                     free(resp);
118                     free(req);
119                 }
120             }
121         }
122     }
123
124     v3_user_host_dev_depart(devfd);
125
126     return 0;
127                     
128 }