Logo AND Algorithmique Numérique Distribuée

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