Logo AND Algorithmique Numérique Distribuée

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