Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merging changes done by Steven, Samuel and Luka, regarding simulation of StarPU-MPI
[simgrid.git] / src / surf / storage_interface.hpp
1 /* Copyright (c) 2004-2015. 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/base.h>
8
9 #include "surf_interface.hpp"
10
11 #ifndef STORAGE_INTERFACE_HPP_
12 #define STORAGE_INTERFACE_HPP_
13
14 extern xbt_dynar_t mount_list;
15
16 namespace simgrid {
17 namespace surf {
18
19 /***********
20  * Classes *
21  ***********/
22
23 class StorageModel;
24 class Storage;
25 class StorageAction;
26
27 /*************
28  * Callbacks *
29  *************/
30
31 /** @ingroup SURF_callbacks
32  * @brief Callbacks handler which emit the callbacks after Storage creation *
33  * @details Callback functions have the following signature: `void(Storage*)`
34  */
35 XBT_PUBLIC_DATA(surf_callback(void, simgrid::surf::Storage*)) storageCreatedCallbacks;
36
37 /** @ingroup SURF_callbacks
38  * @brief Callbacks handler which emit the callbacks after Storage destruction *
39  * @details Callback functions have the following signature: `void(StoragePtr)`
40  */
41 XBT_PUBLIC_DATA(surf_callback(void, simgrid::surf::Storage*)) storageDestructedCallbacks;
42
43 /** @ingroup SURF_callbacks
44  * @brief Callbacks handler which emit the callbacks after Storage State changed *
45  * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
46  */
47 XBT_PUBLIC_DATA(surf_callback(void, simgrid::surf::Storage*, e_surf_resource_state_t, e_surf_resource_state_t)) storageStateChangedCallbacks;
48
49 /** @ingroup SURF_callbacks
50  * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
51  * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
52  */
53 XBT_PUBLIC_DATA(surf_callback(void, simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)) storageActionStateChangedCallbacks;
54
55 /*********
56  * Model *
57  *********/
58 /** @ingroup SURF_storage_interface
59  * @brief SURF storage model interface class
60  * @details A model is an object which handle the interactions between its Resources and its Actions
61  */
62 class StorageModel : public Model {
63 public:
64   /**
65    * @brief The storage model constructor
66    */
67   StorageModel();
68
69   /**
70    * @brief The Storange model destructor
71    */
72   ~StorageModel();
73
74   /**
75    * @brief Create a Storage
76    *
77    * @param id [description]
78    * @param type_id [description]
79    * @param content_name [description]
80    * @param content_type [description]
81    * @param properties [description]
82    * @param attach [description]
83    * @return The created Storage
84    */
85   virtual Storage *createStorage(const char* id,
86                                     const char* type_id,
87                                     const char* content_name,
88                                     const char* content_type,
89                                     xbt_dict_t properties,
90                                     const char *attach) = 0;
91
92   bool shareResourcesIsIdempotent() {return true;}
93
94   xbt_dynar_t p_storageList;
95 };
96
97 /************
98  * Resource *
99  ************/
100 /** @ingroup SURF_storage_interface
101  * @brief SURF storage interface class
102  * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
103  */
104 class Storage : public simgrid::surf::Resource {
105 public:
106   /**
107    * @brief Storage constructor
108    *
109    * @param model StorageModel associated to this Storage
110    * @param name The name of the Storage
111    * @param props Dictionary of properties associated to this Storage
112    * @param type_id [description]
113    * @param content_name [description]
114    * @param content_type [description]
115    * @param size [description]
116    */
117   Storage(Model *model, const char *name, xbt_dict_t props,
118           const char* type_id, char *content_name, char *content_type,
119           sg_size_t size);
120
121   /**
122    * @brief Storage constructor
123    *
124    * @param model StorageModel associated to this Storage
125    * @param name The name of the Storage
126    * @param props Dictionary of properties associated to this Storage
127    * @param maxminSystem [description]
128    * @param bread [description]
129    * @param bwrite [description]
130    * @param bconnection [description]
131    * @param type_id [description]
132    * @param content_name [description]
133    * @param content_type [description]
134    * @param size [description]
135    * @param attach [description]
136    */
137   Storage(Model *model, const char *name, xbt_dict_t props,
138           lmm_system_t maxminSystem, double bread, double bwrite,
139           double bconnection,
140           const char* type_id, char *content_name, char *content_type,
141           sg_size_t size, char *attach);
142
143   /**
144    * @brief Storage destructor
145    */
146   ~Storage();
147
148   /**
149    * @brief Check if the Storage is used
150    *
151    * @return true if the current Storage is used, false otherwise
152    */
153   bool isUsed();
154
155   /**
156    * @brief Update the state of the current Storage
157    *
158    * @param event_type [description]
159    * @param value [description]
160    * @param date [description]
161    */
162   void updateState(tmgr_trace_event_t event_type, double value, double date);
163
164   void setState(e_surf_resource_state_t state);
165
166   xbt_dict_t p_content;
167   char* p_contentType;
168   sg_size_t m_size;
169   sg_size_t m_usedSize;
170   char * p_typeId;
171   char* p_attach;
172
173   /**
174    * @brief Open a file
175    *
176    * @param mount The mount point
177    * @param path The path to the file
178    *
179    * @return The StorageAction corresponding to the opening
180    */
181   virtual StorageAction *open(const char* mount, const char* path)=0;
182
183   /**
184    * @brief Close a file
185    *
186    * @param fd The file descriptor to close
187    * @return The StorageAction corresponding to the closing
188    */
189   virtual StorageAction *close(surf_file_t fd)=0;
190
191   /**
192    * @brief Read a file
193    *
194    * @param fd The file descriptor to read
195    * @param size The size in bytes to read
196    * @return The StorageAction corresponding to the reading
197    */
198   virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
199
200   /**
201    * @brief Write a file
202    *
203    * @param fd The file descriptor to write
204    * @param size The size in bytes to write
205    * @return The StorageAction corresponding to the writing
206    */
207   virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
208
209   /**
210    * @brief Get the content of the current Storage
211    *
212    * @return A xbt_dict_t with path as keys and size in bytes as values
213    */
214   virtual xbt_dict_t getContent();
215
216   /**
217    * @brief Get the size in bytes of the current Storage
218    *
219    * @return The size in bytes of the current Storage
220    */
221   virtual sg_size_t getSize();
222
223   /**
224    * @brief Get the available size in bytes of the current Storage
225    *
226    * @return The available size in bytes of the current Storage
227    */
228   virtual sg_size_t getFreeSize();
229
230   /**
231    * @brief Get the used size in bytes of the current Storage
232    *
233    * @return The used size in bytes of the current Storage
234    */
235   virtual sg_size_t getUsedSize();
236
237
238   xbt_dict_t parseContent(char *filename);
239
240   xbt_dynar_t p_writeActions;
241
242   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
243   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
244 };
245
246 /**********
247  * Action *
248  **********/
249
250 /** @ingroup SURF_storage_interface
251  * @brief The possible type of action for the storage component
252  */
253 typedef enum {
254   READ=0, /**< Read a file */
255   WRITE,  /**< Write in a file */
256   STAT,   /**< Stat a file */
257   OPEN,   /**< Open a file */
258   CLOSE  /**< Close a file */
259 } e_surf_action_storage_type_t;
260
261 /** @ingroup SURF_storage_interface
262  * @brief SURF storage action interface class
263  */
264 class StorageAction : public Action {
265 public:
266   /**
267    * @brief StorageAction constructor
268    *
269    * @param model The StorageModel associated to this StorageAction
270    * @param cost The cost of this  NetworkAction in [TODO]
271    * @param failed [description]
272    * @param storage The Storage associated to this StorageAction
273    * @param type [description]
274    */
275   StorageAction(Model *model, double cost, bool failed, Storage *storage,
276       e_surf_action_storage_type_t type);
277
278     /**
279    * @brief StorageAction constructor
280    *
281    * @param model The StorageModel associated to this StorageAction
282    * @param cost The cost of this  StorageAction in [TODO]
283    * @param failed [description]
284    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
285    * @param storage The Storage associated to this StorageAction
286    * @param type [description]
287    */
288   StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
289       Storage *storage, e_surf_action_storage_type_t type);
290
291   void setState(e_surf_action_state_t state);
292
293   e_surf_action_storage_type_t m_type;
294   Storage *p_storage;
295   surf_file_t p_file;
296   double progress;
297 };
298
299 }
300 }
301
302 typedef struct s_storage_type {
303   char *model;
304   char *content;
305   char *content_type;
306   char *type_id;
307   xbt_dict_t properties;
308   xbt_dict_t model_properties;
309   sg_size_t size;
310 } s_storage_type_t, *storage_type_t;
311
312 typedef struct s_mount {
313   void *storage;
314   char *name;
315 } s_mount_t, *mount_t;
316
317 typedef struct surf_file {
318   char *name;
319   char *mount;
320   sg_size_t size;
321   sg_size_t current_position;
322 } s_surf_file_t;
323
324
325 #endif /* STORAGE_INTERFACE_HPP_ */