Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
HOSTIMPL IS NO LONGER A RESOURCE! At least! \o/
[simgrid.git] / src / surf / HostImpl.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 "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
12
13 #include <xbt/base.h>
14
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
17
18 /***********
19  * Classes *
20  ***********/
21
22 namespace simgrid {
23 namespace surf {
24
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE HostImpl;
27 class XBT_PRIVATE HostAction;
28
29
30 }
31 }
32
33 /*********
34  * Tools *
35  *********/
36
37 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
38
39 /*********
40  * Model *
41  *********/
42
43 namespace simgrid {
44 namespace surf {
45
46 /** @ingroup SURF_host_interface
47  * @brief SURF Host model interface class
48  * @details A model is an object which handle the interactions between its Resources and its Actions
49  */
50 class HostModel : public Model {
51 public:
52   HostModel() : Model() {}
53
54   virtual void adjustWeightOfDummyCpuActions();
55   virtual Action *executeParallelTask(int host_nb, sg_host_t *host_list,
56       double *flops_amount, double *bytes_amount, double rate);
57 };
58
59 /************
60  * Resource *
61  ************/
62 /** @ingroup SURF_host_interface
63  * @brief SURF Host interface class
64  * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
65  */
66 class HostImpl : public simgrid::surf::PropertyHolder {
67
68 public:
69   /**
70    * @brief Host constructor
71    *
72    * @param model HostModel associated to this Host
73    * @param name The name of the Host
74    * @param storage The Storage associated to this Host
75    */
76   HostImpl(HostModel* model, const char* name, xbt_dynar_t storage);
77
78   /**
79    * @brief Host constructor
80    *
81    * @param model HostModel associated to this Host
82    * @param name The name of the Host
83    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
84    * @param storage The Storage associated to this Host
85    */
86   HostImpl(HostModel* model, const char* name, lmm_constraint_t constraint, xbt_dynar_t storage);
87
88   /* Host destruction logic */
89   /**************************/
90   virtual ~HostImpl();
91
92 public:
93   void attach(simgrid::s4u::Host* host);
94
95   /** @brief Return the storage of corresponding mount point */
96   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
97
98   /** @brief Get the xbt_dict_t of mount_point: Storage */
99   virtual xbt_dict_t getMountedStorageList();
100
101   /** @brief Get the xbt_dynar_t of storages attached to the Host */
102   virtual xbt_dynar_t getAttachedStorageList();
103
104   /**
105    * @brief Open a file
106    *
107    * @param fullpath The full path to the file
108    * @return The StorageAction corresponding to the opening
109    */
110   virtual Action *open(const char* fullpath);
111
112   /**
113    * @brief Close a file
114    *
115    * @param fd The file descriptor to close
116    * @return The StorageAction corresponding to the closing
117    */
118   virtual Action *close(surf_file_t fd);
119
120   /**
121    * @brief Unlink a file
122    * @details [long description]
123    *
124    * @param fd [description]
125    * @return [description]
126    */
127   virtual int unlink(surf_file_t fd);
128
129   /**
130    * @brief Get the size in bytes of the file
131    *
132    * @param fd The file descriptor to read
133    * @return The size in bytes of the file
134    */
135   virtual sg_size_t getSize(surf_file_t fd);
136
137   /**
138    * @brief Read a file
139    *
140    * @param fd The file descriptor to read
141    * @param size The size in bytes to read
142    * @return The StorageAction corresponding to the reading
143    */
144   virtual Action *read(surf_file_t fd, sg_size_t size);
145
146   /**
147    * @brief Write a file
148    *
149    * @param fd The file descriptor to write
150    * @param size The size in bytes to write
151    * @return The StorageAction corresponding to the writing
152    */
153   virtual Action *write(surf_file_t fd, sg_size_t size);
154
155   /**
156    * @brief Get the information of a file descriptor
157    * @details The returned xbt_dynar_t contains:
158    *  - the size of the file,
159    *  - the mount point,
160    *  - the storage name,
161    *  - the storage typeId,
162    *  - the storage content type
163    *
164    * @param fd The file descriptor
165    * @return An xbt_dynar_t with the file information
166    */
167   virtual xbt_dynar_t getInfo(surf_file_t fd);
168
169   /**
170    * @brief Get the current position of the file descriptor
171    *
172    * @param fd The file descriptor
173    * @return The current position of the file descriptor
174    */
175   virtual sg_size_t fileTell(surf_file_t fd);
176
177   /**
178    * @brief Set the position indicator associated with the file descriptor to a new position
179    * @details [long description]
180    *
181    * @param fd The file descriptor
182    * @param offset The offset from the origin
183    * @param origin Position used as a reference for the offset
184    *  - SEEK_SET: beginning of the file
185    *  - SEEK_CUR: current position indicator
186    *  - SEEK_END: end of the file
187    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
188    */
189   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
190
191   /**
192    * @brief Move a file to another location on the *same mount point*.
193    * @details [long description]
194    *
195    * @param fd The file descriptor
196    * @param fullpath The new full path
197    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
198    * full path is not on the same mount point
199    */
200   virtual int fileMove(surf_file_t fd, const char* fullpath);
201
202 public:
203   xbt_dynar_t storage_        = nullptr;
204   simgrid::s4u::Host* piface_ = nullptr;
205
206   /** @brief Get the list of virtual machines on the current Host */
207   xbt_dynar_t getVms();
208
209   /* common with vm */
210   /** @brief Retrieve a copy of the parameters of that VM/PM
211    *  @details The ramsize and overcommit fields are used on the PM too */
212   void getParams(vm_params_t params);
213   /** @brief Sets the params of that VM/PM */
214   void setParams(vm_params_t params);
215   simgrid::s4u::Host* getHost() { return piface_; }
216 private:
217   s_vm_params_t params_;
218 };
219
220 }
221 }
222
223 #endif /* SURF_Host_INTERFACE_HPP_ */