Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Comment unused parameters.
[simgrid.git] / src / surf / storage.cpp
1 #include "storage.hpp"
2 #include "surf_private.h"
3
4 #define __STDC_FORMAT_MACROS
5
6 extern "C" {
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
8                                 "Logging specific to the SURF storage module");
9 }
10
11 xbt_lib_t storage_lib;
12 int ROUTING_STORAGE_LEVEL;      //Routing for storagelevel
13 int ROUTING_STORAGE_HOST_LEVEL;
14 int SURF_STORAGE_LEVEL;
15 xbt_lib_t storage_type_lib;
16 int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level
17
18 static xbt_dynar_t storage_list;
19
20 xbt_dynar_t mount_list = NULL;  /* temporary store of current mount storage */
21 StorageModelPtr surf_storage_model = NULL;
22
23 static int storage_selective_update = 0;
24 static xbt_swag_t storage_running_action_set_that_does_not_need_being_checked = NULL;
25
26 /*************
27  * CallBacks *
28  *************/
29
30 static XBT_INLINE void routing_storage_type_free(void *r)
31 {
32   storage_type_t stype = (storage_type_t) r;
33   free(stype->model);
34   free(stype->type_id);
35   free(stype->content);
36   xbt_dict_free(&(stype->properties));
37   xbt_dict_free(&(stype->properties));
38   free(stype);
39 }
40
41 static XBT_INLINE void surf_storage_resource_free(void *r)
42 {
43   // specific to storage
44   StoragePtr storage = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(r));
45   xbt_dict_free(&storage->p_content);
46   xbt_dynar_free(&storage->p_writeActions);
47   free(storage->p_typeId);
48   free(storage->p_contentType);
49   // generic resource
50   delete storage;
51 }
52
53 static XBT_INLINE void routing_storage_host_free(void *r)
54 {
55   xbt_dynar_t dyn = (xbt_dynar_t) r;
56   xbt_dynar_free(&dyn);
57 }
58
59 static void parse_storage_init(sg_platf_storage_cbarg_t storage)
60 {
61   void* stype = xbt_lib_get_or_null(storage_type_lib,
62                                     storage->type_id,
63                                     ROUTING_STORAGE_TYPE_LEVEL);
64   if(!stype) xbt_die("No storage type '%s'",storage->type_id);
65
66   // if storage content is not specified use the content of storage_type if exist
67   if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
68     storage->content = ((storage_type_t) stype)->content;
69     storage->content_type = ((storage_type_t) stype)->content_type;
70     XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
71         storage->id,((storage_type_t) stype)->content_type,
72         ((storage_type_t) stype)->type_id);
73   }
74
75   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
76       "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
77       "\n\t\tproperties '%p'\n",
78       storage->id,
79       ((storage_type_t) stype)->model,
80       ((storage_type_t) stype)->type_id,
81       storage->content,
82       storage->content_type,
83       ((storage_type_t) stype)->properties);
84
85   surf_storage_model->createResource(storage->id, ((storage_type_t) stype)->model,
86                                      ((storage_type_t) stype)->type_id,
87                                      storage->content,
88                                      storage->content_type,
89                                      storage->properties);
90 }
91
92 static void parse_mstorage_init(sg_platf_mstorage_cbarg_t /*mstorage*/)
93 {
94   XBT_DEBUG("parse_mstorage_init");
95 }
96
97 static void parse_storage_type_init(sg_platf_storage_type_cbarg_t /*storagetype_*/)
98 {
99   XBT_DEBUG("parse_storage_type_init");
100 }
101
102 static void parse_mount_init(sg_platf_mount_cbarg_t /*mount*/)
103 {
104   XBT_DEBUG("parse_mount_init");
105 }
106
107 static void storage_parse_storage(sg_platf_storage_cbarg_t storage)
108 {
109   xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
110                "Reading a storage, processing unit \"%s\" already exists", storage->id);
111
112   // Verification of an existing type_id
113 #ifndef NDEBUG
114   void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
115 #endif
116   xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
117
118   XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
119       storage->id,
120       storage->type_id,
121       storage->content);
122
123   xbt_lib_set(storage_lib,
124       storage->id,
125       ROUTING_STORAGE_LEVEL,
126       (void *) xbt_strdup(storage->type_id));
127 }
128
129 static xbt_dict_t parse_storage_content(char *filename, sg_size_t *used_size)
130 {
131   *used_size = 0;
132   if ((!filename) || (strcmp(filename, "") == 0))
133     return NULL;
134
135   xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
136   FILE *file = NULL;
137
138   file = surf_fopen(filename, "r");
139   xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
140               xbt_str_join(surf_path, ":"));
141
142   char *line = NULL;
143   size_t len = 0;
144   ssize_t read;
145   char path[1024];
146   sg_size_t size;
147
148
149   while ((read = xbt_getline(&line, &len, file)) != -1) {
150     if (read){
151     if(sscanf(line,"%s %llu", path, &size) == 2) {
152         *used_size += size;
153         sg_size_t *psize = xbt_new(sg_size_t, 1);
154         *psize = size;
155         xbt_dict_set(parse_content,path,psize,NULL);
156       } else {
157         xbt_die("Be sure of passing a good format for content file.\n");
158       }
159     }
160   }
161   free(line);
162   fclose(file);
163   return parse_content;
164 }
165
166 static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type)
167 {
168   xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
169                "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
170
171   storage_type_t stype = xbt_new0(s_storage_type_t, 1);
172   stype->model = xbt_strdup(storage_type->model);
173   stype->properties = storage_type->properties;
174   stype->content = xbt_strdup(storage_type->content);
175   stype->content_type = xbt_strdup(storage_type->content_type);
176   stype->type_id = xbt_strdup(storage_type->id);
177   stype->size = storage_type->size;
178
179   XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
180       "content '%s', and content_type '%s'",
181       stype->type_id,
182       stype->model,
183       storage_type->content,
184       storage_type->content_type);
185
186   xbt_lib_set(storage_type_lib,
187       stype->type_id,
188       ROUTING_STORAGE_TYPE_LEVEL,
189       (void *) stype);
190 }
191 static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t /*mstorage*/)
192 {
193   THROW_UNIMPLEMENTED;
194 //  mount_t mnt = xbt_new0(s_mount_t, 1);
195 //  mnt->id = xbt_strdup(mstorage->type_id);
196 //  mnt->name = xbt_strdup(mstorage->name);
197 //
198 //  if(!mount_list){
199 //    XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
200 //    mount_list = xbt_dynar_new(sizeof(char *), NULL);
201 //  }
202 //  xbt_dynar_push(mount_list,(void *) mnt);
203 //  free(mnt->id);
204 //  free(mnt->name);
205 //  xbt_free(mnt);
206 //  XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
207 }
208
209 static void mount_free(void *p)
210 {
211   mount_t mnt = (mount_t) p;
212   xbt_free(mnt->name);
213 }
214
215 static void storage_parse_mount(sg_platf_mount_cbarg_t mount)
216 {
217   // Verification of an existing storage
218 #ifndef NDEBUG
219   void* storage = xbt_lib_get_or_null(storage_lib, mount->storageId, ROUTING_STORAGE_LEVEL);
220 #endif
221   xbt_assert(storage,"Disk id \"%s\" does not exists", mount->storageId);
222
223   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
224
225   s_mount_t mnt;
226   mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
227   mnt.name = xbt_strdup(mount->name);
228
229   if(!mount_list){
230     //FIXME:XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
231     mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
232   }
233   xbt_dynar_push(mount_list,&mnt);
234 }
235
236 static void storage_define_callbacks()
237 {
238   sg_platf_storage_add_cb(parse_storage_init);
239   sg_platf_storage_type_add_cb(parse_storage_type_init);
240   sg_platf_mstorage_add_cb(parse_mstorage_init);
241   sg_platf_mount_add_cb(parse_mount_init);
242 }
243
244 void storage_register_callbacks() {
245
246   ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,xbt_free);
247   ROUTING_STORAGE_HOST_LEVEL = xbt_lib_add_level(storage_lib, routing_storage_host_free);
248   ROUTING_STORAGE_TYPE_LEVEL = xbt_lib_add_level(storage_type_lib, routing_storage_type_free);
249   SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, surf_storage_resource_free);
250
251   sg_platf_storage_add_cb(storage_parse_storage);
252   sg_platf_mstorage_add_cb(storage_parse_mstorage);
253   sg_platf_storage_type_add_cb(storage_parse_storage_type);
254   sg_platf_mount_add_cb(storage_parse_mount);
255 }
256
257 /*********
258  * Model *
259  *********/
260
261 void surf_storage_model_init_default(void)
262 {
263   surf_storage_model = new StorageModel();
264   storage_define_callbacks();
265   xbt_dynar_push(model_list, &surf_storage_model);
266 }
267
268 StorageModel::StorageModel() : Model("Storage") {
269   StorageActionLmm action;
270
271   XBT_DEBUG("surf_storage_model_init_internal");
272
273   storage_running_action_set_that_does_not_need_being_checked =
274       xbt_swag_new(xbt_swag_offset(action, p_stateHookup));
275
276   if (!p_maxminSystem) {
277     p_maxminSystem = lmm_system_new(storage_selective_update);
278   }
279 }
280
281
282 StorageModel::~StorageModel(){
283   lmm_system_free(p_maxminSystem);
284
285   surf_storage_model = NULL;
286
287   xbt_dynar_free(&storage_list);
288
289   xbt_swag_free(storage_running_action_set_that_does_not_need_being_checked);
290   storage_running_action_set_that_does_not_need_being_checked = NULL;
291 }
292
293 StoragePtr StorageModel::createResource(const char* id, const char* model, const char* type_id,
294                 const char* content_name, const char* content_type, xbt_dict_t properties)
295 {
296
297   xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)),
298               "Storage '%s' declared several times in the platform file",
299               id);
300
301   storage_type_t storage_type = (storage_type_t) xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL);
302
303   double Bread  = surf_parse_get_bandwidth((char*)xbt_dict_get(storage_type->properties, "Bread"));
304   double Bwrite = surf_parse_get_bandwidth((char*)xbt_dict_get(storage_type->properties, "Bwrite"));
305   double Bconnection   = surf_parse_get_bandwidth((char*)xbt_dict_get(storage_type->properties, "Bconnection"));
306
307   StoragePtr storage = new StorageLmm(this, id, properties, p_maxminSystem,
308                   Bread, Bwrite, Bconnection,
309                   type_id, (char *)content_name, xbt_strdup(content_type), storage_type->size);
310
311   xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, static_cast<ResourcePtr>(storage));
312
313   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tproperties '%p'\n\t\tBread '%f'\n",
314       id,
315       model,
316       type_id,
317       storage_type->properties,
318       Bread);
319
320   if(!storage_list)
321         storage_list = xbt_dynar_new(sizeof(char *),NULL);
322   xbt_dynar_push(storage_list, &storage);
323
324   return storage;
325 }
326
327 double StorageModel::shareResources(double now)
328 {
329   XBT_DEBUG("storage_share_resources %f", now);
330   unsigned int i, j;
331   StoragePtr storage;
332   StorageActionLmmPtr write_action;
333
334   double min_completion = shareResourcesMaxMin(p_runningActionSet,
335       p_maxminSystem, lmm_solve);
336
337   double rate;
338   // Foreach disk
339   xbt_dynar_foreach(storage_list,i,storage)
340   {
341     rate = 0;
342     // Foreach write action on disk
343     xbt_dynar_foreach(storage->p_writeActions, j, write_action)
344     {
345       rate += lmm_variable_getvalue(write_action->p_variable);
346     }
347     if(rate > 0)
348       min_completion = MIN(min_completion, (storage->m_size-storage->m_usedSize)/rate);
349   }
350
351   return min_completion;
352 }
353
354 void StorageModel::updateActionsState(double /*now*/, double delta)
355 {
356   void *_action, *_next_action;
357   StorageActionLmmPtr action = NULL;
358
359   xbt_swag_foreach_safe(_action, _next_action, p_runningActionSet) {
360         action = dynamic_cast<StorageActionLmmPtr>(static_cast<ActionPtr>(_action));
361     if(action->m_type == WRITE)
362     {
363       // Update the disk usage
364      // Update the file size
365      // For each action of type write
366       double rate = lmm_variable_getvalue(action->p_variable);
367       /* Hack to avoid rounding differences between x86 and x86_64
368        * (note that the next sizes are of type sg_size_t). */
369       long incr = delta * rate + MAXMIN_PRECISION;
370       action->p_storage->m_usedSize += incr; // disk usage
371       action->p_file->size += incr; // file size
372
373       sg_size_t *psize = xbt_new(sg_size_t,1);
374       *psize = action->p_file->size;
375
376       xbt_dict_t content_dict = action->p_storage->p_content;
377       xbt_dict_set(content_dict, action->p_file->name, psize, NULL);
378     }
379
380     double_update(&action->m_remains,
381                   lmm_variable_getvalue(action->p_variable) * delta);
382
383     if (action->m_maxDuration != NO_MAX_DURATION)
384       double_update(&action->m_maxDuration, delta);
385
386     if(action->m_remains > 0 &&
387         lmm_get_variable_weight(action->p_variable) > 0 &&
388         action->p_storage->m_usedSize == action->p_storage->m_size)
389     {
390       action->m_finish = surf_get_clock();
391       action->setState(SURF_ACTION_FAILED);
392     } else if ((action->m_remains <= 0) &&
393         (lmm_get_variable_weight(action->p_variable) > 0))
394     {
395       action->m_finish = surf_get_clock();
396       action->setState(SURF_ACTION_DONE);
397     } else if ((action->m_maxDuration != NO_MAX_DURATION) &&
398                (action->m_maxDuration <= 0))
399     {
400       action->m_finish = surf_get_clock();
401       action->setState(SURF_ACTION_DONE);
402     }
403   }
404
405   return;
406 }
407
408 xbt_dict_t Storage::parseContent(char *filename)
409 {
410   m_usedSize = 0;
411   if ((!filename) || (strcmp(filename, "") == 0))
412     return NULL;
413
414   xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
415   FILE *file = NULL;
416
417   file = surf_fopen(filename, "r");
418   xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
419               xbt_str_join(surf_path, ":"));
420
421   char *line = NULL;
422   size_t len = 0;
423   ssize_t read;
424   char path[1024];
425   sg_size_t size;
426
427
428   while ((read = xbt_getline(&line, &len, file)) != -1) {
429     if (read){
430     if(sscanf(line,"%s %llu", path, &size) == 2) {
431         m_usedSize += size;
432         sg_size_t *psize = xbt_new(sg_size_t, 1);
433         *psize = size;
434         xbt_dict_set(parse_content,path,psize,NULL);
435       } else {
436         xbt_die("Be sure of passing a good format for content file.\n");
437       }
438     }
439   }
440   free(line);
441   fclose(file);
442   return parse_content;
443 }
444
445 /************
446  * Resource *
447  ************/
448
449 Storage::Storage(StorageModelPtr model, const char* name, xbt_dict_t properties)
450 :  Resource(model, name, properties)
451 {
452   p_writeActions = xbt_dynar_new(sizeof(char *),NULL);
453 }
454
455 StorageLmm::StorageLmm(StorageModelPtr model, const char* name, xbt_dict_t properties,
456              lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
457              const char* type_id, char *content_name, char *content_type, size_t size)
458  :  Resource(model, name, properties), ResourceLmm(), Storage(model, name, properties) {
459   XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'", bconnection, bread, bwrite, ((unsigned long)size));
460
461   p_stateCurrent = SURF_RESOURCE_ON;
462   m_usedSize = 0;
463   m_size = 0;
464
465   p_content = parseContent(content_name);
466   p_contentType = content_type;
467   p_constraint = lmm_constraint_new(maxminSystem, this, bconnection);
468   p_constraintRead  = lmm_constraint_new(maxminSystem, this, bread);
469   p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
470   m_size = size;
471   p_typeId = xbt_strdup(type_id);
472 }
473
474 bool Storage::isUsed()
475 {
476   THROW_UNIMPLEMENTED;
477   return false;
478 }
479
480 void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/)
481 {
482   THROW_UNIMPLEMENTED;
483 }
484
485 StorageActionPtr StorageLmm::ls(const char* path)
486 {
487   StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, LS);
488
489   action->p_lsDict = NULL;
490   xbt_dict_t ls_dict = xbt_dict_new_homogeneous(xbt_free);
491
492   char* key;
493   sg_size_t size = 0;
494   xbt_dict_cursor_t cursor = NULL;
495
496   xbt_dynar_t dyn = NULL;
497   char* file = NULL;
498
499   // for each file in the storage content
500   xbt_dict_foreach(p_content,cursor,key,size){
501     // Search if file start with the prefix 'path'
502     if(xbt_str_start_with(key,path)){
503       file = &key[strlen(path)];
504
505       // Split file with '/'
506       dyn = xbt_str_split(file,"/");
507       file = xbt_dynar_get_as(dyn,0,char*);
508
509       // file
510       if(xbt_dynar_length(dyn) == 1){
511         sg_size_t *psize = xbt_new(sg_size_t, 1);
512         *psize=size;
513         xbt_dict_set(ls_dict, file, psize, NULL);
514       }
515       // Directory
516       else
517       {
518         // if directory does not exist yet in the dictionary
519         if(!xbt_dict_get_or_null(ls_dict,file))
520           xbt_dict_set(ls_dict,file,NULL,NULL);
521       }
522       xbt_dynar_free(&dyn);
523     }
524   }
525
526   action->p_lsDict = ls_dict;
527   return action;
528 }
529
530 StorageActionPtr StorageLmm::open(const char* mount, const char* path)
531 {
532   XBT_DEBUG("\tOpen file '%s'",path);
533   sg_size_t size, *psize;
534   psize = (sg_size_t*) xbt_dict_get_or_null(p_content, path);
535   // if file does not exist create an empty file
536   if(psize)
537     size = *psize;
538   else {
539         psize = xbt_new(sg_size_t,1);
540     size = 0;
541     *psize = size;
542     xbt_dict_set(p_content, path, psize, NULL);
543     XBT_DEBUG("File '%s' was not found, file created.",path);
544   }
545   surf_file_t file = xbt_new0(s_surf_file_t,1);
546   file->name = xbt_strdup(path);
547   file->size = size;
548   file->mount = xbt_strdup(mount);
549
550   StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, OPEN);
551   action->p_file = file;
552   return action;
553 }
554
555 StorageActionPtr StorageLmm::close(surf_file_t fd)
556 {
557   char *filename = fd->name;
558   XBT_DEBUG("\tClose file '%s' size '%llu'", filename, fd->size);
559   // unref write actions from storage
560   StorageActionLmmPtr write_action;
561   unsigned int i;
562   xbt_dynar_foreach(p_writeActions, i, write_action) {
563     if ((write_action->p_file) == fd) {
564       xbt_dynar_cursor_rm(p_writeActions, &i);
565       write_action->unref();
566     }
567   }
568   free(fd->name);
569   free(fd->mount);
570   xbt_free(fd);
571   StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, CLOSE);
572   return action;
573 }
574
575 StorageActionPtr StorageLmm::read(surf_file_t fd, sg_size_t size)
576 {
577   if(size > fd->size)
578     size = fd->size;
579   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, READ);
580   return action;
581 }
582
583 StorageActionPtr StorageLmm::write(surf_file_t fd, sg_size_t size)
584 {
585   char *filename = fd->name;
586   XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size);
587
588   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
589   action->p_file = fd;
590
591   // If the storage is full
592   if(m_usedSize==m_size) {
593     action->setState(SURF_ACTION_FAILED);
594   }
595   return action;
596 }
597
598 void StorageLmm::rename(const char *src, const char *dest)
599 {
600   sg_size_t *psize, *new_psize;
601   psize = (sg_size_t*) xbt_dict_get_or_null(p_content,src);
602   new_psize = xbt_new(sg_size_t, 1);
603   *new_psize = *psize;
604   if (psize){// src file exists
605     xbt_dict_remove(p_content, src);
606     xbt_dict_set(p_content, dest, new_psize,NULL);
607     XBT_DEBUG("Change file name from %s to %s, size '%llu'",src, dest, *psize);
608   }
609   else
610     XBT_DEBUG("File %s doesn't exist",src);
611 }
612
613 xbt_dict_t StorageLmm::getContent()
614 {
615   /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
616   /*surf_action_t action = storage_action_execute(storage,0, LS);*/
617
618   xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
619   xbt_dict_cursor_t cursor = NULL;
620   char *file;
621   sg_size_t *psize;
622
623   xbt_dict_foreach(p_content, cursor, file, psize){
624     xbt_dict_set(content_dict,file,psize,NULL);
625   }
626   return content_dict;
627 }
628
629 sg_size_t StorageLmm::getSize(){
630   return m_size;
631 }
632
633 /**********
634  * Action *
635  **********/
636
637 StorageActionLmm::StorageActionLmm(ModelPtr model, double cost, bool failed, StorageLmmPtr storage, e_surf_action_storage_type_t type)
638   : Action(model, cost, failed), ActionLmm(model, cost, failed), StorageAction(model, cost, failed, storage, type) {
639   XBT_IN("(%s,%g", storage->m_name, cost);
640   p_variable = lmm_variable_new(p_model->p_maxminSystem, this, 1.0, -1.0 , 3);
641
642   // Must be less than the max bandwidth for all actions
643   lmm_expand(p_model->p_maxminSystem, storage->p_constraint, p_variable, 1.0);
644   switch(type) {
645   case OPEN:
646   case CLOSE:
647   case STAT:
648   case LS:
649     break;
650   case READ:
651     lmm_expand(p_model->p_maxminSystem, storage->p_constraintRead,
652                p_variable, 1.0);
653     break;
654   case WRITE:
655     lmm_expand(p_model->p_maxminSystem, storage->p_constraintWrite,
656                p_variable, 1.0);
657     xbt_dynar_push(storage->p_writeActions, static_cast<ActionPtr>(this));
658     break;
659   }
660   XBT_OUT();
661 }
662
663 int StorageActionLmm::unref()
664 {
665   m_refcount--;
666   if (!m_refcount) {
667     xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
668     if (p_variable)
669       lmm_variable_free(p_model->p_maxminSystem, p_variable);
670 #ifdef HAVE_TRACING
671     xbt_free(p_category);
672 #endif
673     delete this;
674     return 1;
675   }
676   return 0;
677 }
678
679 void StorageActionLmm::cancel()
680 {
681   setState(SURF_ACTION_FAILED);
682   return;
683 }
684
685 void StorageActionLmm::suspend()
686 {
687   XBT_IN("(%p)", this);
688   if (m_suspended != 2) {
689     lmm_update_variable_weight(p_model->p_maxminSystem,
690                                p_variable,
691                                0.0);
692     m_suspended = 1;
693   }
694   XBT_OUT();
695 }
696
697 void StorageActionLmm::resume()
698 {
699   THROW_UNIMPLEMENTED;
700 }
701
702 bool StorageActionLmm::isSuspended()
703 {
704   return m_suspended == 1;
705 }
706
707 void StorageActionLmm::setMaxDuration(double /*duration*/)
708 {
709   THROW_UNIMPLEMENTED;
710 }
711
712 void StorageActionLmm::setPriority(double /*priority*/)
713 {
714   THROW_UNIMPLEMENTED;
715 }
716