5 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
7 void storage_info(msg_host_t host);
8 void display_storage_properties(msg_storage_t storage);
9 int hsm_put(const char *remote_host, const char *src, const char *dest);
10 sg_size_t write_local_file(char *dest, sg_size_t file_size);
11 sg_size_t read_local_file(const char *src);
12 void display_storage_info(msg_host_t host);
13 void dump_storage_by_name(char *name);
14 void display_storage_content(msg_storage_t storage);
15 void get_set_storage_data(const char *storage_name);
16 int client(int argc, char *argv[]);
17 int server(int argc, char *argv[]);
19 void storage_info(msg_host_t host)
21 const char* host_name = MSG_host_get_name(host);
22 XBT_INFO("*** Storage info on %s ***:", host_name);
24 xbt_dict_cursor_t cursor = NULL;
27 msg_storage_t storage;
29 xbt_dict_t storage_list = MSG_host_get_storage_list(MSG_host_self());
31 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
33 XBT_INFO("Storage name: %s, mount name: %s", storage_name, mount_name);
35 sg_size_t free_size = MSG_storage_get_free_size(mount_name);
36 sg_size_t used_size = MSG_storage_get_used_size(mount_name);
38 XBT_INFO("Free size: %" PRIu64 " bytes", free_size);
39 XBT_INFO("Used size: %" PRIu64 " bytes", used_size);
41 storage = MSG_storage_get_by_name(storage_name);
42 display_storage_properties(storage);
44 xbt_dict_free(&storage_list);
47 void display_storage_properties(msg_storage_t storage){
48 xbt_dict_cursor_t cursor = NULL;
50 xbt_dict_t props = MSG_storage_get_properties(storage);
52 XBT_INFO("Properties of mounted storage: %s", MSG_storage_get_name(storage));
53 xbt_dict_foreach(props, cursor, key, data)
54 XBT_INFO("'%s' -> '%s'", key, data);
56 XBT_INFO("No property attached.");
60 // Read src file on local disk and send a put message to remote host (size of message = size of src file)
61 int hsm_put(const char *remote_host, const char *src, const char *dest){
63 // Read local src file, and return the size that was actually read
64 sg_size_t read_size = read_local_file(src);
67 XBT_INFO("%s sends %" PRIu64 " to %s",MSG_host_get_name(MSG_host_self()),read_size,remote_host);
68 msg_task_t to_execute = MSG_task_create((const char*)"hsm_put", 0, (double) read_size, (void*)dest);
69 MSG_task_send(to_execute, remote_host);
74 sg_size_t write_local_file(char *dest, sg_size_t file_size)
77 msg_file_t file = MSG_file_open("/sd1",dest, NULL);
78 write = MSG_file_write(file, file_size);
83 sg_size_t read_local_file(const char *src)
85 sg_size_t read, file_size;
86 msg_file_t file = MSG_file_open("/sd1",src, NULL);
87 file_size = MSG_file_get_size(file);
89 read = MSG_file_read(file, file_size);
90 XBT_INFO("%s has read %" PRIu64 " on %s",MSG_host_get_name(MSG_host_self()),read,src);
96 void display_storage_info(msg_host_t host)
98 const char* host_name = MSG_host_get_name(host);
99 XBT_INFO("*** Storage info of: %s ***", host_name);
101 xbt_dict_cursor_t cursor = NULL;
105 xbt_dict_t storage_list = MSG_host_get_storage_list(host);
107 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
109 dump_storage_by_name(storage_name);
111 xbt_dict_free(&storage_list);
114 void dump_storage_by_name(char *name){
115 XBT_INFO("*** Dump a storage element ***");
116 msg_storage_t storage = MSG_storage_get_by_name(name);
119 display_storage_content(storage);
122 XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
126 void display_storage_content(msg_storage_t storage){
127 XBT_INFO("Print the content of the storage element: %s",MSG_storage_get_name(storage));
128 xbt_dict_cursor_t cursor = NULL;
131 xbt_dict_t content = MSG_storage_get_content(storage);
133 xbt_dict_foreach(content, cursor, file, psize)
134 XBT_INFO("%s size: %" PRIu64 " bytes", file, *psize);
136 XBT_INFO("No content.");
138 xbt_dict_free(&content);
141 void get_set_storage_data(const char *storage_name){
142 XBT_INFO("*** GET/SET DATA for storage element: %s ***",storage_name);
143 msg_storage_t storage = MSG_storage_get_by_name(storage_name);
144 char *data = MSG_storage_get_data(storage);
145 XBT_INFO("Get data: '%s'", data);
147 MSG_storage_set_data(storage,strdup("Some data"));
148 data = MSG_storage_get_data(storage);
149 XBT_INFO("Set and get data: '%s'", data);
152 int client(int argc, char *argv[])
154 hsm_put("server","./doc/simgrid/examples/cxx/autoDestination/FinalizeTask.cxx","./scratch/toto.xml");
155 hsm_put("server","./doc/simgrid/examples/cxx/autoDestination/autoDestination_deployment.xml","./scratch/titi.cxx");
156 hsm_put("server","./doc/simgrid/examples/cxx/autoDestination/Slave.cxx","./scratch/tata.cxx");
158 msg_task_t finalize = MSG_task_create("finalize", 0, 0, NULL);
159 MSG_task_send(finalize, "server");
161 get_set_storage_data("cdisk");
162 display_storage_info(MSG_host_self());
167 int server(int argc, char *argv[])
169 msg_task_t to_execute = NULL;
170 _XBT_GNUC_UNUSED int res;
172 display_storage_info(MSG_host_self());
174 XBT_INFO("Server waiting for transfers");
176 res = MSG_task_receive(&(to_execute), MSG_host_get_name(MSG_host_self()));
177 xbt_assert(res == MSG_OK, "MSG_task_get failed");
179 const char *task_name;
180 task_name = MSG_task_get_name(to_execute);
182 if (!strcmp(task_name, "finalize")) { // Shutdown ...
183 MSG_task_destroy(to_execute);
186 else if(!strcmp(task_name,"hsm_put")){// Receive file to save
187 // Write file on local disk
188 char *dest = MSG_task_get_data(to_execute);
189 sg_size_t size_to_write = (sg_size_t)MSG_task_get_data_size(to_execute);
190 write_local_file(dest, size_to_write);
193 MSG_task_destroy(to_execute);
197 display_storage_info(MSG_host_self());
201 int main(int argc, char *argv[])
203 MSG_init(&argc, argv);
205 /* Check the arguments */
207 printf("Usage: %s platform_file deployment_file \n", argv[0]);
211 const char *platform_file = argv[1];
212 const char *deployment_file = argv[2];
214 MSG_create_environment(platform_file);
216 MSG_function_register("client", client);
217 MSG_function_register("server", server);
218 MSG_launch_application(deployment_file);
220 msg_error_t res = MSG_main();
221 XBT_INFO("Simulated time: %g", MSG_get_clock());