6 #include <sys/select.h>
9 #include "v3_user_host_dev.h"
13 fprintf(stderr,"v3_user_host_dev_example /dev/v3-vm0 user:mydev busywait|select\n");
17 int do_work(struct palacios_host_dev_host_request_response *req,
18 struct palacios_host_dev_host_request_response **resp)
23 case PALACIOS_HOST_DEV_HOST_REQUEST_WRITE_IO: {
24 if (req->port==0xc0c0) {
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]);
31 *resp = malloc(sizeof(struct palacios_host_dev_host_request_response));
33 printf("Cannot allocate response\n");
37 (*resp)->len = (*resp)->data_len = sizeof(struct palacios_host_dev_host_request_response);
38 (*resp)->op_len = numchars;
40 printf("Huh? Unknown port %d\n",req->port);
46 printf("Huh? Unknown request %d\n", req->type);
53 int main(int argc, char *argv[])
66 mode = argv[3][0]=='s';
68 fprintf(stderr,"Attempting to rendezvous with host device %s on vm %s\n", url, vm);
70 if ((devfd = v3_user_host_dev_rendezvous(vm,url))<0) {
71 perror("failed to rendezvous");
75 fprintf(stderr,"Rendezvous succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
80 struct palacios_host_dev_host_request_response *req;
81 struct palacios_host_dev_host_request_response *resp;
85 while (!(v3_user_host_dev_have_request(devfd))) {
87 v3_user_host_dev_pull_request(devfd, &req);
91 v3_user_host_dev_push_response(devfd, resp);
98 struct palacios_host_dev_host_request_response *req;
99 struct palacios_host_dev_host_request_response *resp;
104 // select-based operation so that you can wait for multiple things
108 FD_SET(devfd,&readset);
110 rc = select(devfd+1, &readset, 0, 0, 0); // pick whatever you want to select on, just include devfd
113 if (FD_ISSET(devfd,&readset)) {
114 // a request is read for us!
115 v3_user_host_dev_pull_request(devfd, &req);
119 v3_user_host_dev_push_response(devfd, resp);
128 v3_user_host_dev_depart(devfd);