1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. 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. */
10 #include "surf_private.h"
11 #include "surf/surf_resource.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
14 "Logging specific to the SURF storage module");
16 surf_model_t surf_storage_model = NULL;
18 typedef struct surf_storage {
19 s_surf_resource_t generic_resource;
21 const char* content; /*should be a dict */
22 } s_surf_storage_t, *surf_storage_t;
24 static surf_action_t storage_action_open(void *storage, const char* path, const char* mode)
29 static surf_action_t storage_action_close(void *storage, surf_file_t fp)
34 static surf_action_t storage_action_read(void *storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream)
39 static surf_action_t storage_action_write(void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream)
44 static surf_action_t storage_action_stat(void *storage, int fd, void* buf)
49 static void* storage_create_resource(const char* id, const char* type,
50 const char* content, xbt_dict_t storage_properties)
52 xbt_assert(!surf_storage_resource_by_name(id),
53 "Storage '%s' declared several times in the platform file",
55 XBT_DEBUG("Storage_create_resource '%s' at level SURF_STORAGE_LEVEL",id);
56 surf_storage_t storage = NULL;
57 storage = (surf_storage_t) surf_resource_new(sizeof(s_surf_storage_t),
58 surf_storage_model, id, storage_properties);
60 storage->content = content;
61 xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
66 static void storage_finalize(void)
68 surf_model_exit(surf_storage_model);
69 surf_storage_model = NULL;
72 static void storage_update_actions_state(double now, double delta)
77 static double storage_share_resources(double NOW)
79 double min_action_duration = -1;
80 return min_action_duration;
83 static int storage_resource_used(void *resource_id)
89 static void storage_resources_state(void *id, tmgr_trace_event_t event_type,
90 double value, double time)
95 static int storage_action_unref(surf_action_t action)
101 static void storage_action_cancel(surf_action_t action)
106 static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state)
111 static void storage_action_suspend(surf_action_t action)
116 static void storage_action_resume(surf_action_t action)
121 static int storage_action_is_suspended(surf_action_t action)
127 static void storage_action_set_max_duration(surf_action_t action, double duration)
132 static void storage_action_set_priority(surf_action_t action, double priority)
137 static void parse_storage_init(sg_platf_storage_cbarg_t storage)
139 XBT_INFO("parse_storage_init");
142 static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage)
144 XBT_INFO("parse_mstorage_init");
147 static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_)
149 XBT_INFO("parse_storage_type_init");
152 static void parse_mount_init(sg_platf_mount_cbarg_t mount)
154 XBT_INFO("parse_mount_init");
157 static void storage_define_callbacks()
159 sg_platf_storage_add_cb(parse_storage_init);
160 sg_platf_mstorage_add_cb(parse_mstorage_init);
161 sg_platf_storage_type_add_cb(parse_storage_type_init);
162 sg_platf_mount_add_cb(parse_mount_init);
165 static void surf_storage_model_init_internal(void)
167 XBT_DEBUG("surf_storage_model_init_internal");
168 surf_storage_model = surf_model_init();
170 surf_storage_model->name = "Storage";
171 surf_storage_model->action_unref = storage_action_unref;
172 surf_storage_model->action_cancel = storage_action_cancel;
173 surf_storage_model->action_state_set = storage_action_state_set;
175 surf_storage_model->model_private->finalize = storage_finalize;
176 surf_storage_model->model_private->update_actions_state = storage_update_actions_state;
177 surf_storage_model->model_private->share_resources = storage_share_resources;
178 surf_storage_model->model_private->resource_used = storage_resource_used;
179 surf_storage_model->model_private->update_resource_state = storage_resources_state;
181 surf_storage_model->suspend = storage_action_suspend;
182 surf_storage_model->resume = storage_action_resume;
183 surf_storage_model->is_suspended = storage_action_is_suspended;
184 surf_storage_model->set_max_duration = storage_action_set_max_duration;
185 surf_storage_model->set_priority = storage_action_set_priority;
187 surf_storage_model->extension.storage.open = storage_action_open;
188 surf_storage_model->extension.storage.close = storage_action_close;
189 surf_storage_model->extension.storage.read = storage_action_read;
190 surf_storage_model->extension.storage.write = storage_action_write;
191 surf_storage_model->extension.storage.stat = storage_action_stat;
192 surf_storage_model->extension.storage.create_resource = storage_create_resource;
195 void surf_storage_model_init_default(void)
197 surf_storage_model_init_internal();
198 storage_define_callbacks();
200 xbt_dynar_push(model_list, &surf_storage_model);