From 280afb44a51d970f116dbe52ccf16989136e21da Mon Sep 17 00:00:00 2001 From: Takahiro Hirofuchi Date: Thu, 31 Jan 2013 17:03:31 +0100 Subject: [PATCH] working on vm destroy stuff --- src/include/surf/surf.h | 1 + src/simix/smx_vm.c | 8 +++++++- src/surf/vm_workstation.c | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 36c30c836f..d84f0618a2 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -279,6 +279,7 @@ typedef struct surf_workstation_model_extension_public { typedef struct surf_vm_workstation_model_extension_public { s_surf_model_extension_workstation_t basic; void* (*create) (const char *name, void *workstation); // First operation of the VM model + void (*destroy) (const char *name); // destory the vm-specific data } s_surf_model_extension_vm_workstation_t; /** \ingroup SURF_models diff --git a/src/simix/smx_vm.c b/src/simix/smx_vm.c index bb3805f772..36b7c2e035 100644 --- a/src/simix/smx_vm.c +++ b/src/simix/smx_vm.c @@ -46,10 +46,16 @@ smx_host_t SIMIX_vm_create(const char *name, smx_host_t phys_host) * * \param h the host to destroy (a smx_host_t) */ -void SIMIX_host_destroy(void *h) +void SIMIX_vm_host_destroy(void *h) { smx_host_priv_t host = (smx_host_priv_t) h; + smx_host_t + xbt_lib_(host_lib,name,SIMIX_HOST_LEVEL,smx_host); + + /* jump to vm_ws_destroy() */ + surf_vm_workstation_model->extension.vm_workstation.destroy(name); + xbt_assert((host != NULL), "Invalid parameters"); /* Clean Simulator data */ diff --git a/src/surf/vm_workstation.c b/src/surf/vm_workstation.c index cb76055ee7..f174e5136d 100644 --- a/src/surf/vm_workstation.c +++ b/src/surf/vm_workstation.c @@ -30,6 +30,25 @@ static void *vm_ws_create (const char *name, void *phys_workstation) workstation->physical_workstation = phys_workstation; xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, workstation); + +} + +/* + * A physical host does not disapper in the current SimGrid code, but a VM may + * disapper during a simulation. + */ +static void vm_ws_destroy(const char *name) +{ + workstation_VM2013_t workstation = xbt_lib_get_or_null(host_lib, name, SURF_WKS_LEVEL); + xbt_assert(workstation); + xbt_assert(workstation->generic_resource.model == surf_vm_workstation_model); + + xbt_free(workstation->generic_resource.name); + + /* not defined yet, but we should have */ + // xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL); + + xbt_free(workstation); } static int ws_resource_used(void *resource_id) @@ -436,6 +455,7 @@ static void surf_vm_workstation_model_init_internal(void) surf_vm_workstation_model->extension.workstation.unlink = ws_action_unlink; surf_vm_workstation_model->extension.workstation.ls = ws_action_ls; surf_vm_workstation_model->extension.vm_workstation.create = vm_ws_create; + surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy; } -- 2.20.1