/* Create an instance of the specified type */ vm_instance_t *vm_create_instance(char *name,int instance_id,char *type) { vm_platform_t *platform; vm_instance_t *vm = NULL; if (!(platform = vm_platform_find(type))) { fprintf(stderr,"VM %s: unknown platform '%s'\n",name,type); goto error; } /* Create a generic VM instance */ if (!(vm = vm_create(name,instance_id,platform))) goto error; /* Initialize specific parts */ if (vm->platform->create_instance(vm) == -1) goto error; return vm; error: fprintf(stderr,"VM %s: unable to create instance!\n",name); vm_free(vm); return NULL; }
/* Register a platform */ int vm_platform_register(vm_platform_t *platform) { struct vm_platform_list *p; if (vm_platform_find(platform->name) != NULL) { fprintf(stderr,"vm_platform_register: platform '%s' already exists.\n", platform->name); return(-1); } if (!(p = malloc(sizeof(*p)))) { fprintf(stderr,"vm_platform_register: unable to record platform.\n"); return(-1); } p->platform = platform; p->next = vm_platforms; vm_platforms = p; return(0); }