Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
df57ce86ec241bb4c90e6a49f4725bfeba3cc9c8
[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 <unistd.h>
9
10 #define FILENAME1 "/sd1/doc/simgrid/examples/cxx/autoDestination/Main.cxx"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
13
14 static void display_storage_properties(msg_storage_t storage){
15   xbt_dict_cursor_t cursor = NULL;
16   char *key, *data;
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);
22   } else {
23   XBT_INFO("\tNo property attached.");
24   }
25 }
26
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;
30   char *file;
31   sg_size_t *psize;
32   xbt_dict_t content = MSG_storage_get_content(storage);
33   if (content){
34     xbt_dict_foreach(content, cursor, file, psize)
35     XBT_INFO("\t%s size: %llu bytes", file, *psize);
36   } else {
37     XBT_INFO("\tNo content.");
38   }
39   xbt_dict_free(&content);
40 }
41
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);
45
46   if(storage){
47     display_storage_content(storage);
48   } else{
49     XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
50   }
51 }
52 static void storage_info(msg_host_t host)
53 {
54   const char* host_name = MSG_host_get_name(host);
55   XBT_INFO("*** Storage info on %s ***", host_name);
56
57   xbt_dict_cursor_t cursor = NULL;
58   char* mount_name;
59   char* storage_name;
60   msg_storage_t storage;
61
62   xbt_dict_t storage_list = MSG_host_get_mounted_storage_list(host);
63
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);
67
68     sg_size_t free_size = MSG_storage_get_free_size(storage);
69     sg_size_t used_size = MSG_storage_get_used_size(storage);
70
71     XBT_INFO("\t\tFree size: %llu bytes", free_size);
72     XBT_INFO("\t\tUsed size: %llu bytes", used_size);
73
74     display_storage_properties(storage);
75     dump_storage_by_name(storage_name);
76   }
77   xbt_dict_free(&storage_list);
78 }
79
80 static int host(int argc, char *argv[])
81 {
82   char name[2048];
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);
87
88   XBT_INFO("Size of %s: %llu", MSG_file_get_name(file), MSG_file_get_size(file));
89   MSG_file_close(file);
90
91   return 1;
92 }
93
94 int main(int argc, char **argv)
95 {
96   MSG_init(&argc, argv);
97   MSG_create_environment(argv[1]);
98
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")));
103   }
104
105   int res = MSG_main();
106   storage_info(MSG_host_by_name(xbt_strdup("host")));
107   XBT_INFO("Simulation time %g", MSG_get_clock());
108
109   return res != MSG_OK;
110 }