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.


userspace changes to break apart VM lifecycle management
[palacios.git] / linux_usr / v3_create.c
1 /* 
2  * V3 Control utility
3  * (c) Jack lange, 2010
4  */
5
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h> 
10 #include <sys/ioctl.h> 
11 #include <sys/stat.h> 
12 #include <sys/types.h> 
13 #include <unistd.h> 
14 #include <string.h>
15  
16 #include "v3_ctrl.h"
17
18 int read_file(int fd, int size, unsigned char * buf);
19
20 int main(int argc, char* argv[]) {
21     char * filename = argv[1];
22     char * name = argv[2];
23     int guest_fd = 0;
24     int v3_fd = 0;
25     struct v3_guest_img guest_img;
26     struct stat guest_stats;
27     int dev_idx = 0;
28
29     memset(&guest_img, 0, sizeof(struct v3_guest_img));
30
31     if (argc <= 2) {
32         printf("Usage: ./v3_ctrl <guest_img> <vm name>\n");
33         return -1;
34     }
35
36     printf("Launching guest: %s\n", filename);
37
38     guest_fd = open(filename, O_RDONLY); 
39
40     if (guest_fd == -1) {
41         printf("Error Opening guest image: %s\n", filename);
42         return -1;
43     }
44
45     if (fstat(guest_fd, &guest_stats) == -1) {
46         printf("ERROR: Could not stat guest image file -- %s\n", filename);
47         return -1;
48     }
49
50     
51     guest_img.size = guest_stats.st_size;
52     
53     // load guest image into user memory
54     guest_img.guest_data = malloc(guest_img.size);
55
56     read_file(guest_fd, guest_img.size, guest_img.guest_data);
57     
58     close(guest_fd);
59
60     printf("Loaded guest image. Launching to V3Vee\n");
61     
62     strncpy(guest_img.name, name, 127);
63
64
65     v3_fd = open(v3_dev, O_RDONLY);
66
67     if (v3_fd == -1) {
68         printf("Error opening V3Vee control device\n");
69         return -1;
70     }
71
72     dev_idx = ioctl(v3_fd, V3_CREATE_GUEST, &guest_img); 
73
74
75     if (dev_idx < 0) {
76         printf("Error (%d) creating VM\n", dev_idx);
77         return -1;
78     }
79
80     printf("VM (%s) created at /dev/v3-vm%d\n", name, dev_idx);
81
82     /* Close the file descriptor.  */ 
83     close(v3_fd); 
84  
85
86
87     return 0; 
88
89
90
91
92 int read_file(int fd, int size, unsigned char * buf) {
93     int left_to_read = size;
94     int have_read = 0;
95
96     while (left_to_read != 0) {
97         int bytes_read = read(fd, buf + have_read, left_to_read);
98
99         if (bytes_read <= 0) {
100             break;
101         }
102
103         have_read += bytes_read;
104         left_to_read -= bytes_read;
105     }
106
107     if (left_to_read != 0) {
108         printf("Error could not finish reading file\n");
109         return -1;
110     }
111     
112     return 0;
113 }