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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Patrick G. Bridges <bridges@cs.unm.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
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>
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
34 static char *option_storage;
35 static struct hashtable *option_table;
36 static char *truevalue = "true";
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));
42 static int option_eq_fn(addr_t key1, addr_t key2) {
43 char * name1 = (char *)key1;
44 char * name2 = (char *)key2;
46 return (strcmp(name1, name2) == 0);
49 // need to allocate these cleanly and separately so we can easily recover the
51 static int option_insert(char *key, char *val)
55 k = V3_Malloc(strlen(key)+1);
61 v = V3_Malloc(strlen(val)+1);
71 if (!v3_htable_insert(option_table, (addr_t)k, (addr_t)v)) {
81 void v3_parse_options(char *options)
83 char *currKey = NULL, *currVal = NULL;
88 option_table = v3_create_htable(0, option_hash_fn, option_eq_fn);
94 len = strlen(options);
95 option_storage = V3_Malloc(len + 1);
96 strcpy(option_storage, options);
100 /* Skip whitespace */
102 || (*c == '\t') || (*c == ',')) {
108 option_insert(currKey, currVal);
114 } else if (parseKey) {
123 } else /* !parseKey */ {
134 option_insert(currKey, currVal);
137 V3_Free(option_storage);
142 char *v3_lookup_option(char *key) {
143 return (char *)v3_htable_search(option_table, (addr_t)(key));
147 void v3_deinit_options()
149 v3_free_htable(option_table,1,1); // will free keys and values