Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b4a3a54e61a35556ea93d9f2c4026a7211aebdae
[simgrid.git] / teshsuite / msg / storage / storage.c
1 #include "msg/msg.h"
2 #include "xbt/log.h"
3
4 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
5
6 void storage_info(msg_host_t host);
7 void display_storage_properties(msg_storage_t storage);
8 int client(int argc, char *argv[]);
9 int server(int argc, char *argv[]);
10
11
12 int client(int argc, char *argv[])
13 {
14   storage_info(MSG_host_self());
15   return 1;
16 }
17
18 int server(int argc, char *argv[])
19 {
20   //display_storage_info();
21   return 1;
22 }
23
24 void storage_info(msg_host_t host){
25
26   const char* host_name = MSG_host_get_name(host);
27   XBT_INFO("** Storage info on %s:", host_name);
28
29   xbt_dict_cursor_t cursor = NULL;
30   char* mount_name;
31   char* storage_name;
32   msg_storage_t storage;
33
34   xbt_dict_t storage_list = MSG_host_get_storage_list(MSG_host_self());
35
36   xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
37   {
38     XBT_INFO("\tStorage mount name: %s", mount_name);
39
40     sg_storage_size_t free_size = MSG_storage_get_free_size(mount_name);
41     sg_storage_size_t used_size = MSG_storage_get_used_size(mount_name);
42
43     XBT_INFO("\t\tFree size: %zu bytes", free_size);
44     XBT_INFO("\t\tUsed size: %zu bytes", used_size);
45
46     storage = MSG_storage_get_by_name(storage_name);
47     display_storage_properties(storage);
48   }
49 }
50
51 void display_storage_properties(msg_storage_t storage){
52   xbt_dict_cursor_t cursor = NULL;
53   char *key, *data;
54   xbt_dict_t props = MSG_storage_get_properties(storage);
55   if (props){
56     XBT_INFO("\tProperties of mounted storage: %s", MSG_storage_get_name(storage));
57     xbt_dict_foreach(props, cursor, key, data)
58           XBT_INFO("\t\t'%s' -> '%s'", key, data);
59   }else{
60         XBT_INFO("\t\tNo property attached.");
61   }
62 }
63
64 int main(int argc, char *argv[])
65 {
66   MSG_init(&argc, argv);
67
68   /* Check the arguments */
69   if (argc < 3) {
70     printf("Usage: %s platform_file deployment_file \n", argv[0]);
71     return -1;
72   }
73
74   const char *platform_file = argv[1];
75   const char *deployment_file = argv[2];
76
77   MSG_create_environment(platform_file);
78
79   MSG_function_register("client", client);
80   MSG_function_register("server", server);
81   MSG_launch_application(deployment_file);
82
83   msg_error_t res = MSG_main();
84
85   if (res == MSG_OK)
86     return 0;
87   else
88     return 1;
89 }