1 /* Copyright (c) 2008-2010, 2012-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/msg.h"
10 #define FILENAME1 "/sd1/doc/simgrid/examples/cxx/autoDestination/Main.cxx"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
14 static void display_storage_properties(msg_storage_t storage){
15 xbt_dict_cursor_t cursor = NULL;
17 xbt_dict_t props = MSG_storage_get_properties(storage);
18 if (xbt_dict_length(props) > 0){
19 XBT_INFO("\tProperties of mounted storage: %s", MSG_storage_get_name(storage));
20 xbt_dict_foreach(props, cursor, key, data)
21 XBT_INFO("\t\t'%s' -> '%s'", key, data);
23 XBT_INFO("\tNo property attached.");
27 static void display_storage_content(msg_storage_t storage){
28 XBT_INFO("Print the content of the storage element: %s",MSG_storage_get_name(storage));
29 xbt_dict_cursor_t cursor = NULL;
32 xbt_dict_t content = MSG_storage_get_content(storage);
34 xbt_dict_foreach(content, cursor, file, psize)
35 XBT_INFO("\t%s size: %llu bytes", file, *psize);
37 XBT_INFO("\tNo content.");
39 xbt_dict_free(&content);
42 static void dump_storage_by_name(char *name){
43 XBT_INFO("*** Dump a storage element ***");
44 msg_storage_t storage = MSG_storage_get_by_name(name);
47 display_storage_content(storage);
49 XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
52 static void storage_info(msg_host_t host)
54 const char* host_name = MSG_host_get_name(host);
55 XBT_INFO("*** Storage info on %s ***", host_name);
57 xbt_dict_cursor_t cursor = NULL;
60 msg_storage_t storage;
62 xbt_dict_t storage_list = MSG_host_get_mounted_storage_list(host);
64 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name){
65 XBT_INFO("\tStorage name: %s, mount name: %s", storage_name, mount_name);
66 storage = MSG_storage_get_by_name(storage_name);
68 sg_size_t free_size = MSG_storage_get_free_size(storage);
69 sg_size_t used_size = MSG_storage_get_used_size(storage);
71 XBT_INFO("\t\tFree size: %llu bytes", free_size);
72 XBT_INFO("\t\tUsed size: %llu bytes", used_size);
74 display_storage_properties(storage);
75 dump_storage_by_name(storage_name);
77 xbt_dict_free(&storage_list);
80 static int host(int argc, char *argv[])
83 sprintf(name,"%s%i", FILENAME1,MSG_process_self_PID());
84 msg_file_t file = MSG_file_open(name, NULL);
85 //MSG_file_read(file, MSG_file_get_size(file));
86 MSG_file_write(file, 500000);
88 XBT_INFO("Size of %s: %llu", MSG_file_get_name(file), MSG_file_get_size(file));
94 int main(int argc, char **argv)
96 MSG_init(&argc, argv);
97 MSG_create_environment(argv[1]);
99 MSG_function_register("host", host);
100 storage_info(MSG_host_by_name(xbt_strdup("host")));
101 for(int i = 0 ; i<10; i++){
102 MSG_process_create(xbt_strdup("host"), host, NULL, MSG_host_by_name(xbt_strdup("host")));
105 int res = MSG_main();
106 storage_info(MSG_host_by_name(xbt_strdup("host")));
107 XBT_INFO("Simulation time %g", MSG_get_clock());
109 return res != MSG_OK;