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.


Basic HRT startup for HVM, plus assorted cleanup
[palacios.git] / palacios / src / palacios / vmm_options.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2013, Patrick G. Bridges <bridges@cs.unm.edu> 
11  * Copyright (c) 2013, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Patrick G. Bridges <bridges@cs.unm.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #include <palacios/vmm.h>
22 #include <palacios/vmm_config.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_sprintf.h>
25 #include <palacios/vmm_options.h>
26
27 /* Options are space-separated values of the form "X=Y", for example
28  * scheduler=EDF CPUs=1,2,3,4
29  * THe following code pushes them into a hashtable for each of access
30  * by other code. Storage is allocated for keys and values as part
31  * of this process. XXX Need a way to deallocate this storage if the 
32  * module is removed XXX
33  */
34 static char *option_storage;
35 static struct hashtable *option_table;
36 static char *truevalue = "true";
37
38 static uint_t option_hash_fn(addr_t key) {
39     char * name = (char *)key;
40     return v3_hash_buffer((uint8_t *)name, strlen(name));
41 }
42 static int option_eq_fn(addr_t key1, addr_t key2) {
43     char * name1 = (char *)key1;
44     char * name2 = (char *)key2;
45
46     return (strcmp(name1, name2) == 0);
47 }
48
49 // need to allocate these cleanly and separately so we can easily recover the
50 // storage
51 static int option_insert(char *key, char *val)
52 {
53     char *k, *v;
54
55     k = V3_Malloc(strlen(key)+1);
56
57     if (!k) { 
58         return -1;
59     }
60     
61     v = V3_Malloc(strlen(val)+1);
62
63     if (!v) { 
64         V3_Free(k);
65         return -1;
66     }
67
68     strcpy(k,key);
69     strcpy(v,val);
70
71     if (!v3_htable_insert(option_table, (addr_t)k, (addr_t)v)) {
72         V3_Free(v);
73         V3_Free(k);
74         return -1;
75     }
76
77     return 0;
78 }
79
80
81 void v3_parse_options(char *options)
82 {
83     char *currKey = NULL, *currVal = NULL;
84     int parseKey = 1;
85     int len;
86     char *c;
87
88     option_table = v3_create_htable(0, option_hash_fn, option_eq_fn);
89
90     if (!options) {
91         return; 
92     }
93
94     len = strlen(options);
95     option_storage = V3_Malloc(len + 1);
96     strcpy(option_storage, options);
97     c = option_storage;
98
99     while (c && *c) {
100         /* Skip whitespace */
101         if ((*c == ' ')
102             || (*c == '\t') || (*c == ',')) {
103             *c = 0;
104             if (currKey) {
105                 if (!currVal) {
106                     currVal = truevalue;
107                 }
108                 option_insert(currKey, currVal);
109                 parseKey = 1;
110                 currKey = NULL;
111                 currVal = NULL;
112             } 
113             c++;
114         } else if (parseKey) {
115             if (!currKey) {
116                 currKey = c;
117             } 
118             if (*c == '=') {
119                 parseKey = 0;
120                 *c = 0;
121             }
122             c++;
123         } else /* !parseKey */ {
124             if (!currVal) {
125                 currVal = c;
126             }
127             c++;
128         }
129     }
130     if (currKey) {
131         if (!currVal) {
132             currVal = truevalue;
133         } 
134         option_insert(currKey, currVal);
135     }
136     
137     V3_Free(option_storage);
138
139     return;
140 }
141
142 char *v3_lookup_option(char *key) {
143     return (char *)v3_htable_search(option_table, (addr_t)(key));
144 }
145
146
147 void v3_deinit_options()
148 {
149     v3_free_htable(option_table,1,1); // will free keys and values
150 }