s_surf_model_extension_workstation_t basic;
void* (*create) (const char *name, void *workstation); // First operation of the VM model
// start does not appear here as it corresponds to turn the state from created to running (see smx_vm.c)
- int (*get_state) (void *workstation);
+ int (*get_state) (void *workstation);
void (*set_state) (void *workstation, int state);
- void (*destroy) (const char *name); // destory the vm-specific data
+ void (*destroy) (const char *name); // destory the vm-specific data
} s_surf_model_extension_vm_workstation_t;
/** \ingroup SURF_models
#endif
}
+
/** @brief Immediately resumes the execution of all processes within the given VM.
* @ingroup msg_VMs
*
#endif
}
-/** @brief Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
- * @ingroup msg_VMs
- *
- * No extra delay occurs. If you want to simulate this too, you want to
- * use a #MSG_process_sleep() or something. I'm not quite sure.
- */
+
void MSG_vm_shutdown(msg_vm_t vm)
{
- msg_process_t process;
- XBT_DEBUG("%lu processes in the VM", xbt_dynar_length(vm->processes));
- while (xbt_dynar_length(vm->processes) > 0) {
- process = xbt_dynar_get_as(vm->processes,0,msg_process_t);
- MSG_process_kill(process);
+ /* msg_vm_t equals to msg_host_t */
+ char *name = simcall_host_get_name(vm);
+ smx_host_t smx_host = xbt_lib_get_or_null(host_lib, name, SIMIX_HOST_LEVEL);
+ smx_process_t smx_process, smx_process_next;
+
+ XBT_DEBUG("%lu processes in the VM", xbt_swag_size(SIMIX_host_priv(smx_host)->process_list));
+
+ xbt_swag_foreach_safe(smx_process, SIMIX_host_priv(smx_host)->process_list) {
+ XBT_DEBUG("kill %s", SIMIX_host_get_name(smx_host));
+ simcall_process_kill(smx_process);
}
+ /* taka: not yet confirmed */
#ifdef HAVE_TRACING
TRACE_msg_vm_kill(vm);
#endif
+
+ /* TODO: update the state of vm */
+
+#if 0
+ while (xbt_dynar_length(vm->processes) > 0) {
+ process = xbt_dynar_get_as(vm->processes,0,msg_process_t);
+ }
+#endif
}
+
+
/**
* \ingroup msg_VMs
* \brief Reboot the VM, restarting all the processes in it.
xbt_dynar_free(&new_processes);
}
+
/** @brief Destroy a msg_vm_t.
* @ingroup msg_VMs
*/
*
* \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 */
static void vm_ws_create (const char *name, void *phys_workstation)
{
workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
-// TODO Implement the surf vm workstation model
+// TODO Complete the surf vm workstation model
vm_ws->generic_resource.model = surf_vm_workstation_model;
vm_ws->generic_resource.name = xbt_strdup(name);
vm_ws->physical_workstation = phys_workstation;
vm_ws->current_state=msg_vm_state_created,
xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
}
+/*
+ * 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 vm_ws_get_state(void *vm_ws){
return ((workstation_VM2013_t)vm_ws)->current_state;
surf_vm_workstation_model->extension.vm_workstation.create = vm_ws_create;
surf_vm_workstation_model->extension.vm_workstation.set_state = vm_ws_set_state;
surf_vm_workstation_model->extension.vm_workstation.get_state = vm_ws_get_state;
+ surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy;
}