4 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
6 void storage_info(msg_host_t host);
7 void display_storage_properties(msg_storage_t storage);
8 int hsm_put(const char *remote_host, const char *src, const char *dest);
9 sg_size_t write_local_file(char *dest, sg_size_t file_size);
10 sg_size_t read_local_file(const char *src);
11 void display_storage_info(msg_host_t host);
12 void dump_storage_by_name(char *name);
13 void display_storage_content(msg_storage_t storage);
14 void get_set_storage_data(const char *storage_name);
15 int client(int argc, char *argv[]);
16 int server(int argc, char *argv[]);
18 void storage_info(msg_host_t host)
20 const char* host_name = MSG_host_get_name(host);
21 XBT_INFO("*** Storage info on %s ***:", host_name);
23 xbt_dict_cursor_t cursor = NULL;
26 msg_storage_t storage;
28 xbt_dict_t storage_list = MSG_host_get_storage_list(MSG_host_self());
30 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
32 XBT_INFO("Storage name: %s, mount name: %s", storage_name, mount_name);
34 sg_size_t free_size = MSG_storage_get_free_size(mount_name);
35 sg_size_t used_size = MSG_storage_get_used_size(mount_name);
37 XBT_INFO("Free size: %llu bytes", free_size);
38 XBT_INFO("Used size: %llu bytes", used_size);
40 storage = MSG_storage_get_by_name(storage_name);
41 display_storage_properties(storage);
43 xbt_dict_free(&storage_list);
46 void display_storage_properties(msg_storage_t storage){
47 xbt_dict_cursor_t cursor = NULL;
49 xbt_dict_t props = MSG_storage_get_properties(storage);
51 XBT_INFO("Properties of mounted storage: %s", MSG_storage_get_name(storage));
52 xbt_dict_foreach(props, cursor, key, data)
53 XBT_INFO("'%s' -> '%s'", key, data);
55 XBT_INFO("No property attached.");
59 // Read src file on local disk and send a put message to remote host (size of message = size of src file)
60 int hsm_put(const char *remote_host, const char *src, const char *dest){
62 // Read local src file, and return the size that was actually read
63 sg_size_t read_size = read_local_file(src);
66 XBT_INFO("%s sends %llu to %s",MSG_host_get_name(MSG_host_self()),read_size,remote_host);
67 msg_task_t to_execute = MSG_task_create((const char*)"hsm_put", 0, (double) read_size, (void*)dest);
68 MSG_task_send(to_execute, remote_host);
73 sg_size_t write_local_file(char *dest, sg_size_t file_size)
76 msg_file_t file = MSG_file_open("/sd1",dest, NULL);
77 write = MSG_file_write(file, file_size);
82 sg_size_t read_local_file(const char *src)
84 sg_size_t read, file_size;
85 msg_file_t file = MSG_file_open("/sd1",src, NULL);
86 file_size = MSG_file_get_size(file);
88 read = MSG_file_read(file, file_size);
89 XBT_INFO("%s has read %llu on %s",MSG_host_get_name(MSG_host_self()),read,src);
95 void display_storage_info(msg_host_t host)
97 const char* host_name = MSG_host_get_name(host);
98 XBT_INFO("*** Storage info of: %s ***", host_name);
100 xbt_dict_cursor_t cursor = NULL;
104 xbt_dict_t storage_list = MSG_host_get_storage_list(host);
106 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
108 dump_storage_by_name(storage_name);
110 xbt_dict_free(&storage_list);
113 void dump_storage_by_name(char *name){
114 XBT_INFO("*** Dump a storage element ***");
115 msg_storage_t storage = MSG_storage_get_by_name(name);
118 display_storage_content(storage);
121 XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
125 void display_storage_content(msg_storage_t storage){
126 XBT_INFO("Print the content of the storage element: %s",MSG_storage_get_name(storage));
127 xbt_dict_cursor_t cursor = NULL;
130 xbt_dict_t content = MSG_storage_get_content(storage);
132 xbt_dict_foreach(content, cursor, file, psize)
133 XBT_INFO("%s size: %llu bytes", file, *psize);
135 XBT_INFO("No content.");
137 xbt_dict_free(&content);
140 void get_set_storage_data(const char *storage_name){
141 XBT_INFO("*** GET/SET DATA for storage element: %s ***",storage_name);
142 msg_storage_t storage = MSG_storage_get_by_name(storage_name);
143 char *data = MSG_storage_get_data(storage);
144 XBT_INFO("Get data: '%s'", data);
146 MSG_storage_set_data(storage,strdup("Some data"));
147 data = MSG_storage_get_data(storage);
148 XBT_INFO("Set and get data: '%s'", data);
151 int client(int argc, char *argv[])
153 hsm_put("server","./doc/simgrid/examples/cxx/autoDestination/FinalizeTask.cxx","./scratch/toto.xml");
154 hsm_put("server","./doc/simgrid/examples/cxx/autoDestination/autoDestination_deployment.xml","./scratch/titi.cxx");
155 hsm_put("server","./doc/simgrid/examples/cxx/autoDestination/Slave.cxx","./scratch/tata.cxx");
157 msg_task_t finalize = MSG_task_create("finalize", 0, 0, NULL);
158 MSG_task_send(finalize, "server");
160 get_set_storage_data("cdisk");
161 display_storage_info(MSG_host_self());
166 int server(int argc, char *argv[])
168 msg_task_t to_execute = NULL;
169 _XBT_GNUC_UNUSED int res;
171 display_storage_info(MSG_host_self());
173 XBT_INFO("Server waiting for transfers");
175 res = MSG_task_receive(&(to_execute), MSG_host_get_name(MSG_host_self()));
176 xbt_assert(res == MSG_OK, "MSG_task_get failed");
178 const char *task_name;
179 task_name = MSG_task_get_name(to_execute);
181 if (!strcmp(task_name, "finalize")) { // Shutdown ...
182 MSG_task_destroy(to_execute);
185 else if(!strcmp(task_name,"hsm_put")){// Receive file to save
186 // Write file on local disk
187 char *dest = MSG_task_get_data(to_execute);
188 sg_size_t size_to_write = (sg_size_t)MSG_task_get_data_size(to_execute);
189 write_local_file(dest, size_to_write);
192 MSG_task_destroy(to_execute);
196 display_storage_info(MSG_host_self());
200 int main(int argc, char *argv[])
202 MSG_init(&argc, argv);
204 /* Check the arguments */
206 printf("Usage: %s platform_file deployment_file \n", argv[0]);
210 const char *platform_file = argv[1];
211 const char *deployment_file = argv[2];
213 MSG_create_environment(platform_file);
215 MSG_function_register("client", client);
216 MSG_function_register("server", server);
217 MSG_launch_application(deployment_file);
219 msg_error_t res = MSG_main();
220 XBT_INFO("Simulated time: %g", MSG_get_clock());