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.


Cleanup based on cppcheck pass (Linux module and user)
[palacios.git] / linux_usr / v3_reset.c
1 /* 
2  * V3 VM reset
3  * (c) Peter Dinda 2015
4  */
5
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/ioctl.h> 
10 #include <errno.h>
11 #include <assert.h>
12 #include <string.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15
16 #include "v3_ctrl.h"
17
18 void usage()
19 {
20     printf("usage: v3_reset <vm_device> all|hrt|ros|range [first_core num_cores]\n\n");
21     printf("Resets the VM or a part of it.\n");
22     printf("  all   : full reset of entire VM\n");
23     printf("  hrt   : reset of all HRT cores for an HVM VM\n");
24     printf("  ros   : reset of ROS cores for an HVM VM\n");
25     printf("  range : reset of cores first_core to first_core+num_cores-1\n\n");
26 }
27
28 int main(int argc, char* argv[]) {
29     int vm_fd;
30     char * vm_dev = NULL;
31     struct v3_reset_cmd cmd; 
32
33     if (argc < 3) {
34         usage();
35         return -1;
36     }
37
38     vm_dev = argv[1];
39
40     if (!strcasecmp(argv[2],"all")) { 
41         cmd.type=V3_RESET_VM_ALL;
42     } else if (!strcasecmp(argv[2],"hrt")) { 
43         cmd.type=V3_RESET_VM_HRT;
44     } else if (!strcasecmp(argv[2],"ros")) { 
45         cmd.type=V3_RESET_VM_ROS;
46     } else if (!strcasecmp(argv[2],"range")) { 
47         cmd.type=V3_RESET_VM_CORE_RANGE;
48         if (argc!=5) { 
49             usage();
50             return -1;
51         } else {
52             cmd.first_core = atoi(argv[3]);
53             cmd.num_cores = atoi(argv[4]);
54         }
55     } else {
56         usage();
57         return -1;
58     }
59
60     printf("Doing VM reset:  %s ",
61            cmd.type==V3_RESET_VM_ALL ? "ALL" :
62            cmd.type==V3_RESET_VM_HRT ? "HRT" :
63            cmd.type==V3_RESET_VM_ROS ? "ROS" :
64            cmd.type==V3_RESET_VM_CORE_RANGE ? "RANGE" : "UNKNOWN");
65     if (cmd.type==V3_RESET_VM_CORE_RANGE) { 
66         printf("cores %u to %u\n", cmd.first_core, cmd.first_core+cmd.num_cores-1);
67     } else {
68         printf("\n");
69     }
70
71     vm_fd = open(vm_dev, O_RDONLY);
72
73     if (vm_fd == -1) {
74         printf("Error opening VM device: %s\n", vm_dev);
75         return -1;
76     }
77
78     int err = ioctl(vm_fd, V3_VM_RESET, &cmd); 
79
80     if (err < 0) {
81         printf("Error sending reset commad to vm\n");
82         return -1;
83     }
84
85     close(vm_fd); 
86
87     return 0; 
88 }
89
90