Logo AND Algorithmique Numérique Distribuée

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