Logo AND Algorithmique Numérique Distribuée

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