Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add vm_migration with no overhead
[simgrid.git] / src / surf / vm_workstation.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/ex.h"
8 #include "xbt/dict.h"
9 #include "portable.h"
10 #include "surf_private.h"
11 #include "surf/surf_resource.h"
12 #include "simgrid/sg_config.h"
13
14 typedef struct workstation_VM2013 {
15   s_surf_resource_t generic_resource;   /* Must remain first to add this to a trace */
16   surf_resource_t physical_workstation;  // Pointer to the host OS
17   e_msg_vm_state_t current_state;            // See include/msg/datatypes.h
18 } s_workstation_VM2013_t, *workstation_VM2013_t;
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
21                                 "Logging specific to the SURF VM workstation module");
22
23 surf_model_t surf_vm_workstation_model = NULL;
24
25 static void vm_ws_create(const char *name, void *ind_phys_workstation)
26 {
27   workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
28 // TODO Complete the surf vm workstation model
29   vm_ws->generic_resource.model = surf_vm_workstation_model;
30   vm_ws->generic_resource.name = xbt_strdup(name);
31  // ind means ''indirect'' that this is a reference on the whole dict_elm structure (i.e not on the surf_resource_private infos)
32   vm_ws->physical_workstation = surf_workstation_resource_priv(ind_phys_workstation);
33   vm_ws->current_state=msg_vm_state_created,
34   xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
35 }
36
37 /*
38  * Update the physical host of the given VM
39  */
40 static void vm_ws_migrate(void *ind_vm_workstation, void *ind_dest_phys_workstation)
41
42    /* ind_phys_workstation equals to smx_host_t */
43    workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_workstation);
44    xbt_assert(vm_ws);
45
46    /* do something */
47    
48    vm_ws->physical_workstation = surf_workstation_resource_priv(ind_dest_phys_workstation);
49 }
50
51 /*
52  * A physical host does not disapper in the current SimGrid code, but a VM may
53  * disapper during a simulation.
54  */
55 static void vm_ws_destroy(void *ind_vm_workstation)
56
57         /* ind_phys_workstation equals to smx_host_t */
58         workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_workstation);
59         xbt_assert(vm_ws);
60         xbt_assert(vm_ws->generic_resource.model == surf_vm_workstation_model);
61
62         const char *name = vm_ws->generic_resource.name;
63         /* this will call surf_resource_free() */
64         xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL);
65
66         xbt_free(vm_ws->generic_resource.name);
67         xbt_free(vm_ws);
68 }
69
70 static int vm_ws_get_state(void *ind_vm_ws){
71         return ((workstation_VM2013_t) surf_workstation_resource_priv(ind_vm_ws))->current_state;
72 }
73
74 static void vm_ws_set_state(void *ind_vm_ws, int state){
75          ((workstation_VM2013_t) surf_workstation_resource_priv(ind_vm_ws))->current_state=state;
76 }
77 static void surf_vm_workstation_model_init_internal(void)
78 {
79   surf_vm_workstation_model = surf_model_init();
80
81   surf_vm_workstation_model->name = "Virtual Workstation";
82
83   surf_vm_workstation_model->extension.vm_workstation.create = vm_ws_create;
84   surf_vm_workstation_model->extension.vm_workstation.set_state = vm_ws_set_state;
85   surf_vm_workstation_model->extension.vm_workstation.get_state = vm_ws_get_state;
86   surf_vm_workstation_model->extension.vm_workstation.migrate = vm_ws_migrate;
87   surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy;
88
89 }
90
91 void surf_vm_workstation_model_init()
92 {
93   surf_vm_workstation_model_init_internal();
94   xbt_dynar_push(model_list, &surf_vm_workstation_model);
95 }