Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8848f3ab0e2b8e247dd39e0199ef7202c00453df
[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   void apply_event(tmgr_trace_iterator_t event, double value) override;
144
145   void turnOn() override;
146   void turnOff() override;
147
148   xbt_dict_t p_content;
149   char* p_contentType;
150   sg_size_t m_size;
151   sg_size_t m_usedSize;
152   char * p_typeId;
153   char* p_attach; //FIXME: this is the name of the host. Use the host directly
154
155   /**
156    * @brief Open a file
157    *
158    * @param mount The mount point
159    * @param path The path to the file
160    *
161    * @return The StorageAction corresponding to the opening
162    */
163   virtual StorageAction *open(const char* mount, const char* path)=0;
164
165   /**
166    * @brief Close a file
167    *
168    * @param fd The file descriptor to close
169    * @return The StorageAction corresponding to the closing
170    */
171   virtual StorageAction *close(surf_file_t fd)=0;
172
173   /**
174    * @brief Read a file
175    *
176    * @param fd The file descriptor to read
177    * @param size The size in bytes to read
178    * @return The StorageAction corresponding to the reading
179    */
180   virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
181
182   /**
183    * @brief Write a file
184    *
185    * @param fd The file descriptor to write
186    * @param size The size in bytes to write
187    * @return The StorageAction corresponding to the writing
188    */
189   virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
190
191   /**
192    * @brief Get the content of the current Storage
193    *
194    * @return A xbt_dict_t with path as keys and size in bytes as values
195    */
196   virtual xbt_dict_t getContent();
197
198   /**
199    * @brief Get the size in bytes of the current Storage
200    *
201    * @return The size in bytes of the current Storage
202    */
203   virtual sg_size_t getSize();
204
205   /**
206    * @brief Get the available size in bytes of the current Storage
207    *
208    * @return The available size in bytes of the current Storage
209    */
210   virtual sg_size_t getFreeSize();
211
212   /**
213    * @brief Get the used size in bytes of the current Storage
214    *
215    * @return The used size in bytes of the current Storage
216    */
217   virtual sg_size_t getUsedSize();
218
219
220   xbt_dict_t parseContent(const char *filename);
221
222   xbt_dynar_t p_writeActions;
223
224   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
225   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
226 };
227
228 /**********
229  * Action *
230  **********/
231
232 /** @ingroup SURF_storage_interface
233  * @brief The possible type of action for the storage component
234  */
235 typedef enum {
236   READ=0, /**< Read a file */
237   WRITE,  /**< Write in a file */
238   STAT,   /**< Stat a file */
239   OPEN,   /**< Open a file */
240   CLOSE  /**< Close a file */
241 } e_surf_action_storage_type_t;
242
243 /** @ingroup SURF_storage_interface
244  * @brief SURF storage action interface class
245  */
246 class StorageAction : public Action {
247 public:
248   /**
249    * @brief StorageAction constructor
250    *
251    * @param model The StorageModel associated to this StorageAction
252    * @param cost The cost of this  NetworkAction in [TODO]
253    * @param failed [description]
254    * @param storage The Storage associated to this StorageAction
255    * @param type [description]
256    */
257   StorageAction(Model *model, double cost, bool failed, Storage *storage,
258       e_surf_action_storage_type_t type);
259
260     /**
261    * @brief StorageAction constructor
262    *
263    * @param model The StorageModel associated to this StorageAction
264    * @param cost The cost of this  StorageAction in [TODO]
265    * @param failed [description]
266    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
267    * @param storage The Storage associated to this StorageAction
268    * @param type [description]
269    */
270   StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
271       Storage *storage, e_surf_action_storage_type_t type);
272
273   void setState(e_surf_action_state_t state);
274
275   e_surf_action_storage_type_t m_type;
276   Storage *p_storage;
277   surf_file_t p_file;
278   double progress;
279 };
280
281 }
282 }
283
284 typedef struct s_storage_type {
285   char *model;
286   char *content;
287   char *content_type;
288   char *type_id;
289   xbt_dict_t properties;
290   xbt_dict_t model_properties;
291   sg_size_t size;
292 } s_storage_type_t, *storage_type_t;
293
294 typedef struct s_mount {
295   void *storage;
296   char *name;
297 } s_mount_t, *mount_t;
298
299 typedef struct surf_file {
300   char *name;
301   char *mount;
302   sg_size_t size;
303   sg_size_t current_position;
304 } s_surf_file_t;
305
306
307 #endif /* STORAGE_INTERFACE_HPP_ */