| 221 | } |
| 222 | |
| 223 | static int virt_machine_parse_config(VirtMachineParams *p, |
| 224 | char *config_file_str, int len) |
| 225 | { |
| 226 | int version, val; |
| 227 | const char *tag_name, *str; |
| 228 | char buf1[256]; |
| 229 | JSONValue cfg, obj, el; |
| 230 | |
| 231 | cfg = json_parse_value_len(config_file_str, len); |
| 232 | if (json_is_error(cfg)) { |
| 233 | vm_error("error: %s\n", json_get_error(cfg)); |
| 234 | json_free(cfg); |
| 235 | return -1; |
| 236 | } |
| 237 | |
| 238 | if (vm_get_int(cfg, "version", &version) < 0) |
| 239 | goto tag_fail; |
| 240 | if (version != VM_CONFIG_VERSION) { |
| 241 | if (version > VM_CONFIG_VERSION) { |
| 242 | vm_error("The emulator is too old to run this VM: please upgrade\n"); |
| 243 | return -1; |
| 244 | } else { |
| 245 | vm_error("The VM configuration file is too old for this emulator version: please upgrade the VM configuration file\n"); |
| 246 | return -1; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (vm_get_str(cfg, "machine", &str) < 0) |
| 251 | goto tag_fail; |
| 252 | p->machine_name = strdup(str); |
| 253 | p->vmc = virt_machine_find_class(p->machine_name); |
| 254 | if (!p->vmc) { |
| 255 | vm_error("Unknown machine name: %s\n", p->machine_name); |
| 256 | goto tag_fail; |
| 257 | } |
| 258 | p->vmc->virt_machine_set_defaults(p); |
| 259 | |
| 260 | tag_name = "memory_size"; |
| 261 | if (vm_get_int(cfg, tag_name, &val) < 0) |
| 262 | goto tag_fail; |
| 263 | p->ram_size = (uint64_t)val << 20; |
| 264 | |
| 265 | tag_name = "bios"; |
| 266 | if (vm_get_str_opt(cfg, tag_name, &str) < 0) |
| 267 | goto tag_fail; |
| 268 | if (str) { |
| 269 | p->files[VM_FILE_BIOS].filename = strdup(str); |
| 270 | } |
| 271 | |
| 272 | tag_name = "kernel"; |
| 273 | if (vm_get_str_opt(cfg, tag_name, &str) < 0) |
| 274 | goto tag_fail; |
| 275 | if (str) { |
| 276 | p->files[VM_FILE_KERNEL].filename = strdup(str); |
| 277 | } |
| 278 | |
| 279 | tag_name = "initrd"; |
| 280 | if (vm_get_str_opt(cfg, tag_name, &str) < 0) |
no test coverage detected