From: Samuel Lepetit Date: Wed, 13 Jun 2012 16:07:40 +0000 (+0200) Subject: Debug the cloud API, it should work as expected now. X-Git-Tag: v3_8~630 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/535815db45bb2162b257e5c208ee7015dd2cc8f6 Debug the cloud API, it should work as expected now. --- diff --git a/examples/msg/cloud/masterslave_virtual_machines.c b/examples/msg/cloud/masterslave_virtual_machines.c index 0ed5b9069d..87d10504ba 100644 --- a/examples/msg/cloud/masterslave_virtual_machines.c +++ b/examples/msg/cloud/masterslave_virtual_machines.c @@ -98,7 +98,6 @@ int master(int argc, char *argv[]) { argv[2] = NULL; MSG_vm_bind(vm, MSG_process_create_with_arguments(slavename,slave_fun,NULL,slaves[i],2,argv)); } - work_batch(slaves_count*2); XBT_INFO("Migrate everyone to the second host."); for (i=0;idata && msg_global->process_data_cleanup) { - msg_global->process_data_cleanup(msg_proc->data); + msg_process_data_t process_data = (msg_process_data_t)msg_proc->data; + //free the process data + if (process_data) { + //Remove the process from its vm + if (process_data->current_vm) { + int pos = xbt_dynar_search(process_data->current_vm->processes,&smx_proc); + xbt_dynar_remove_at(process_data->current_vm->processes,pos, NULL); + } + //Free the data if a function was provided + if (process_data->data && msg_global->process_data_cleanup) { + msg_global->process_data_cleanup(process_data->data); + } + xbt_free(process_data); } - // free the MSG process + //free the MSG process xbt_free(msg_proc); } @@ -248,7 +258,10 @@ void* MSG_process_get_data(m_process_t process) /* get from SIMIX the MSG process data, and then the user data */ simdata_process_t simdata = simcall_process_get_data(process); - return simdata->data; + if (!simdata->data) { + return NULL; + } + return ((msg_process_data_t)simdata->data)->data; } /** \ingroup m_process_management @@ -262,8 +275,10 @@ MSG_error_t MSG_process_set_data(m_process_t process, void *data) xbt_assert(process != NULL, "Invalid parameter"); simdata_process_t simdata = simcall_process_get_data(process); - simdata->data = data; - + if (!simdata->data) { + simdata->data = xbt_new0(s_msg_process_data_t, 1); + } + ((msg_process_data_t)simdata->data)->data = data; return MSG_OK; } diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index b31536f187..fd951c21dd 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -65,7 +65,24 @@ int MSG_vm_is_running(msg_vm_t vm) { * @bug for now, if a binded process terminates, every VM functions will segfault. Baaaad. */ void MSG_vm_bind(msg_vm_t vm, m_process_t process) { - xbt_dynar_push_as(vm->processes,m_process_t,process); + simdata_process_t simdata = simcall_process_get_data(process); + if (!simdata->data) { + simdata->data = xbt_new0(s_msg_process_data_t,1); + } + //If if it is already in a vm, get it out of it + if ( ((msg_process_data_t)(simdata->data))->current_vm) { + msg_vm_t old_vm = ((msg_process_data_t)(simdata->data))->current_vm; + int pos = xbt_dynar_search(old_vm->processes,&process); + xbt_dynar_remove_at(old_vm->processes,pos, NULL); + //If it is on the wrong host, migrate it to the new host + if (vm->location != old_vm->location) { + MSG_process_migrate(process,vm->location); + } + } + + ((msg_process_data_t)(simdata->data))->current_vm = vm; + + xbt_dynar_push_as(vm->processes,m_process_t,process); } /** @brief Removes the given process from the given VM, and kill it * @ingroup msg_VMs @@ -107,7 +124,7 @@ void MSG_vm_suspend(msg_vm_t vm) { unsigned int cpt; m_process_t process; xbt_dynar_foreach(vm->processes,cpt,process) { - XBT_INFO("suspend process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process))); + XBT_DEBUG("suspend process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process))); MSG_process_suspend(process); } } @@ -123,7 +140,7 @@ void MSG_vm_resume(msg_vm_t vm) { unsigned int cpt; m_process_t process; xbt_dynar_foreach(vm->processes,cpt,process) { - XBT_INFO("resume process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process))); + XBT_DEBUG("resume process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process))); MSG_process_resume(process); } }