Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0e8c60ab39d88bb05a5de9b93ce50ef0b88378b6
[simgrid.git] / teshsuite / msg / storage / concurrent_rw.c
1 /* Copyright (c) 2008-2010, 2012-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 "simgrid/msg.h"
8 #include "xbt/log.h"
9 #include <unistd.h>
10
11
12 #define FILENAME1 "/sd1/doc/simgrid/examples/cxx/autoDestination/Main.cxx"
13
14 int host(int argc, char *argv[]);
15 void storage_info(msg_host_t host);
16 void display_storage_properties(msg_storage_t storage);
17 void dump_storage_by_name(char *name);
18 void display_storage_content(msg_storage_t storage);
19
20 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
21
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_mounted_storage_list(host);
35
36   xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
37   {
38     XBT_INFO("\tStorage name: %s, mount name: %s", storage_name, mount_name);
39
40     storage = MSG_storage_get_by_name(storage_name);
41
42     sg_size_t free_size = MSG_storage_get_free_size(storage);
43     sg_size_t used_size = MSG_storage_get_used_size(storage);
44
45     XBT_INFO("\t\tFree size: %llu bytes", free_size);
46     XBT_INFO("\t\tUsed size: %llu bytes", used_size);
47
48     display_storage_properties(storage);
49     dump_storage_by_name(storage_name);
50   }
51   xbt_dict_free(&storage_list);
52 }
53
54 void display_storage_properties(msg_storage_t storage){
55   xbt_dict_cursor_t cursor = NULL;
56   char *key, *data;
57   xbt_dict_t props = MSG_storage_get_properties(storage);
58   if (xbt_dict_length(props) > 0){
59     XBT_INFO("\tProperties of mounted storage: %s", MSG_storage_get_name(storage));
60     xbt_dict_foreach(props, cursor, key, data)
61     XBT_INFO("\t\t'%s' -> '%s'", key, data);
62   }else{
63   XBT_INFO("\tNo property attached.");
64   }
65 }
66
67 void dump_storage_by_name(char *name){
68   XBT_INFO("*** Dump a storage element ***");
69   msg_storage_t storage = MSG_storage_get_by_name(name);
70
71   if(storage){
72     display_storage_content(storage);
73   }
74   else{
75     XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
76   }
77 }
78
79 void display_storage_content(msg_storage_t storage){
80   XBT_INFO("Print the content of the storage element: %s",MSG_storage_get_name(storage));
81   xbt_dict_cursor_t cursor = NULL;
82   char *file;
83   sg_size_t *psize;
84   xbt_dict_t content = MSG_storage_get_content(storage);
85   if (content){
86     xbt_dict_foreach(content, cursor, file, psize)
87     XBT_INFO("\t%s size: %llu bytes", file, *psize);
88   } else {
89     XBT_INFO("\tNo content.");
90   }
91   xbt_dict_free(&content);
92 }
93
94
95
96
97
98 int host(int argc, char *argv[])
99 {
100   char name[2048];
101   sprintf(name,"%s%i", FILENAME1,MSG_process_self_PID());
102   msg_file_t file = MSG_file_open(name, NULL);
103   //MSG_file_read(file, MSG_file_get_size(file));
104   MSG_file_write(file, 500000);
105
106   XBT_INFO("Size of %s: %llu", MSG_file_get_name(file), MSG_file_get_size(file));
107   MSG_file_close(file);
108
109   return 1;
110 }
111
112
113 int main(int argc, char **argv)
114 {
115
116   int res, i;
117   MSG_init(&argc, argv);
118   MSG_create_environment(argv[1]);
119
120   MSG_function_register("host", host);
121   storage_info(MSG_host_by_name(xbt_strdup("host")));
122   for(i = 0 ; i<10; i++){
123     MSG_process_create(xbt_strdup("host"), host, NULL, MSG_host_by_name(xbt_strdup("host")));
124   }
125
126
127
128
129   res = MSG_main();
130   storage_info(MSG_host_by_name(xbt_strdup("host")));
131   XBT_INFO("Simulation time %g", MSG_get_clock());
132
133   return res != MSG_OK;
134 }