int host(int argc, char *argv[])
{
- msg_file_t file;
+ msg_file_t file = NULL;
+ s_msg_stat_t stat;
+
char* mount = bprintf("C:");
size_t read,write;
if(!strcmp(MSG_process_get_name(MSG_process_self()),"0"))
read = MSG_file_read(mount,NULL,10000000,sizeof(char*),file); // Read for 10Mo
XBT_INFO("\tHaving read %Zu \ton %s",read,file->name);
-// res = MSG_file_stat(mount,0,NULL);
-// XBT_INFO("Host '%s' stat %d",MSG_host_get_name(MSG_host_self()), res);
+ MSG_file_stat(mount,file,&stat);
+ XBT_INFO("\tFile %s Size %d",file->name,(int)stat.size);
XBT_INFO("\tClose file '%s'",file->name);
MSG_file_close(mount,file);
#ifndef MSG_DATATYPE_H
#define MSG_DATATYPE_H
#include "xbt/misc.h"
+#include "xbt/file_stat.h"
#include "simgrid_config.h" // for HAVE_TRACING
SG_BEGIN_DECL()
} s_msg_file_t;
/** @brief File datatype
@ingroup m_datatypes_management_details */
+
typedef struct msg_file *msg_file_t;
+typedef s_file_stat_t s_msg_stat_t, *msg_stat_t;
+
/*************** Begin GPU ***************/
typedef struct simdata_gpu_task *simdata_gpu_task_t;
XBT_PUBLIC(size_t) MSG_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, msg_file_t stream);
XBT_PUBLIC(msg_file_t) MSG_file_open(const char* storage, const char* path, const char* mode);
XBT_PUBLIC(int) MSG_file_close(const char* storage, msg_file_t fp);
-XBT_PUBLIC(int) MSG_file_stat(const char* storage, int fd, void* buf);
+XBT_PUBLIC(int) MSG_file_stat(const char* storage, msg_file_t fd, s_msg_stat_t *buf);
/************************** Host handling ***********************************/
/********************************** File *************************************/
typedef struct s_smx_file *smx_file_t;
+typedef struct s_smx_stat *smx_stat_t;
/********************************** Action *************************************/
typedef struct s_smx_action *smx_action_t; /* FIXME: replace by specialized action handlers */
#include "xbt/misc.h"
#include "xbt/fifo.h"
#include "xbt/dict.h"
+#include "xbt/file_stat.h"
#include "xbt/function_types.h"
#include "simix/datatypes.h"
#include "simix/context.h"
XBT_PUBLIC(size_t) simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream);
XBT_PUBLIC(smx_file_t) simcall_file_open(const char* storage, const char* path, const char* mode);
XBT_PUBLIC(int) simcall_file_close(const char* storage, smx_file_t fp);
-XBT_PUBLIC(int) simcall_file_stat(const char* storage, int fd, void* buf);
+XBT_PUBLIC(int) simcall_file_stat(const char* storage, smx_file_t fd, s_file_stat_t *buf);
SG_END_DECL()
#endif /* _SIMIX_SIMIX_H */
--- /dev/null
+/*
+ * file_stat.h
+ *
+ * Created on: 3 avr. 2012
+ * Author: navarro
+ */
+
+#ifndef _FILE_STAT_H
+#define _FILE_STAT_H
+
+#include "xbt/sysdep.h"
+
+typedef struct file_stat {
+ char *user_rights;
+ char *user;
+ char *group;
+ char *date; /* FIXME: update to time_t or double */
+ char *time; /* FIXME: update to time_t or double */
+ size_t size;
+} s_file_stat_t, *file_stat_t;
+
+static XBT_INLINE void file_stat_copy(s_file_stat_t *src, s_file_stat_t *dst)
+{
+ dst->date = xbt_strdup(src->date);
+ dst->group = xbt_strdup(src->group);
+ dst->size = src->size;
+ dst->time = xbt_strdup(src->time);
+ dst->user = xbt_strdup(src->user);
+ dst->user_rights = xbt_strdup(src->user_rights);
+}
+
+#endif /* _FILE_STAT_H */
*/
typedef struct surf_action *surf_action_t;
typedef struct surf_file *surf_file_t;
+typedef struct surf_stat *surf_stat_t;
typedef struct lmm_element *lmm_element_t;
typedef struct lmm_variable *lmm_variable_t;
#include "xbt/dynar.h"
#include "xbt/dict.h"
#include "xbt/misc.h"
+#include "xbt/file_stat.h"
#include "portable.h"
#include "xbt/config.h"
#include "surf/datatypes.h"
char *category; /**< tracing category for categorized resource utilization monitoring */
#endif
surf_file_t file; /**< surf_file_t for storage model */
+ s_file_stat_t stat; /**< surf_file_t for storage model */
} s_surf_action_t;
typedef struct surf_action_lmm {
surf_action_t(*close) (void *storage, surf_file_t fp);
surf_action_t(*read) (void *storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream);
surf_action_t(*write) (void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream);
- surf_action_t(*stat) (void *storage, int fd, void* buf);
+ surf_action_t(*stat) (void *storage, surf_file_t stream);
void* (*create_resource) (const char* id, const char* model,const char* type_id);
} s_surf_model_extension_storage_t;
surf_action_t(*close) (void *workstation, const char* storage, surf_file_t fp);
surf_action_t(*read) (void *workstation, const char* storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream);
surf_action_t(*write) (void *workstation, const char* storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream);
- surf_action_t(*stat) (void *workstation, const char* storage, int fd, void* buf);
+ surf_action_t(*stat) (void *workstation, const char* storage, surf_file_t stream);
int (*link_shared) (const void *link);
xbt_dict_t(*get_properties) (const void *resource);
void* (*link_create_resource) (const char *name,
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "msg_private.h"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, simix,
+ "Logging specific to MSG (io)");
/** @addtogroup m_file_management
* \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="File" --> \endhtmlonly
* \brief Stats the file pointed by fd
*
* \param storage is the name where find the stream
- * \param fd is the file descriptor
+ * \param fd is the file descriptor (#msg_file_t)
* \param buf is the return structure with informations
* \return 0 on success or 1 on error
*/
-int MSG_file_stat(const char* storage, int fd, void* buf)
+int MSG_file_stat(const char* storage, msg_file_t fd, s_msg_stat_t *buf)
{
- return simcall_file_stat(storage, fd, buf);
+ int res;
+ res = simcall_file_stat(storage, fd->simdata->smx_file, buf);
+ return res;
}
simcall->issuer->waiting_action = action;
}
-smx_action_t SIMIX_file_stat(smx_process_t process ,const char* storage, int fd, void* buf)
+smx_action_t SIMIX_file_stat(smx_process_t process ,const char* storage, smx_file_t fd, s_file_stat_t buf)
{
smx_action_t action;
smx_host_t host = process->smx_host;
-
/* check if the host is active */
if (surf_workstation_model->extension.
workstation.get_state(host->host) != SURF_RESOURCE_ON) {
#endif
action->io.host = host;
- action->io.surf_io = surf_workstation_model->extension.workstation.stat(host->host, storage, fd, buf);
+ action->io.surf_io = surf_workstation_model->extension.workstation.stat(host->host, storage, fd->surf_file);
surf_workstation_model->action_data_set(action->io.surf_io, action);
XBT_DEBUG("Create io action %p", action);
simcall->file_read.result = (action->io.surf_io)->cost;
break;
case SIMCALL_FILE_STAT:
- simcall->file_read.result = 0;
+ simcall->file_stat.result = 0;
+ s_file_stat_t *dst = &(simcall->file_stat.buf);
+ s_file_stat_t *src = &((action->io.surf_io)->stat);
+ file_stat_copy(src,dst);
break;
default:
break;
smx_action_t SIMIX_file_write(smx_process_t process, const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream);
smx_action_t SIMIX_file_open(smx_process_t process, const char* storage, const char* path, const char* mode);
smx_action_t SIMIX_file_close(smx_process_t process, const char* storage, smx_file_t fp);
-smx_action_t SIMIX_file_stat(smx_process_t process, const char* storage, int fd, void* buf);
+smx_action_t SIMIX_file_stat(smx_process_t process, const char* storage, smx_file_t fd, s_file_stat_t buf);
void SIMIX_post_io(smx_action_t action);
void SIMIX_io_destroy(smx_action_t action);
surf_file_t surf_file;
} s_smx_file_t;
+typedef struct s_smx_stat {
+ s_file_stat_t surf_stat;
+} s_smx_stat_t, *smx_stat_t;
/*********************************** Time ************************************/
struct {
const char* storage;
- int fd;
- //Next should be struct stat* buf
- void* buf;
+ smx_file_t fd;
+ s_file_stat_t buf;
int result;
} file_stat;
return simcall->file_close.result;
}
-int simcall_file_stat(const char* storage, int fd, void* buf)
+int simcall_file_stat(const char* storage, smx_file_t fd, s_file_stat_t *buf)
{
smx_simcall_t simcall = SIMIX_simcall_mine();
-
simcall->call = SIMCALL_FILE_STAT;
simcall->file_stat.storage = storage;
simcall->file_stat.fd = fd;
- simcall->file_stat.buf = buf;
+
SIMIX_simcall_push(simcall->issuer);
+ *buf = simcall->file_stat.buf;
+
return simcall->file_stat.result;
}
#include "xbt/ex.h"
#include "xbt/dict.h"
+#include "xbt/file_stat.h"
#include "portable.h"
#include "surf_private.h"
#include "storage_private.h"
#define GENERIC_LMM_ACTION(action) action->generic_lmm_action
#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
-typedef enum {
- READ = 0,
- WRITE = 1,
- DEFAULT = 2
-} STORAGE_execute_type_t;
-
typedef struct surf_storage {
s_surf_resource_t generic_resource;
const char* type;
} s_surf_storage_t, *surf_storage_t;
static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state);
-static surf_action_t storage_action_sleep (void *storage, double duration);
-static surf_action_t storage_action_execute (void *storage, size_t size, STORAGE_execute_type_t type);
+static surf_action_t storage_action_execute (void *storage, size_t size, e_surf_action_storage_type_t type);
+
+static surf_action_t storage_action_stat(void *storage, surf_file_t stream)
+{
+ surf_action_t action = storage_action_execute(storage,0, STAT);
+ action->file = stream;
+ action->stat = stream->content->stat;
+ return action;
+}
static surf_action_t storage_action_open(void *storage, const char* path, const char* mode)
{
ROUTING_STORAGE_LEVEL);
storage_type_t storage_type = xbt_lib_get_or_null(storage_type_lib, storage_type_id,ROUTING_STORAGE_TYPE_LEVEL);
xbt_dict_t content_dict = storage_type->content;
- content_t content = xbt_dict_get(content_dict,path);
+ surf_stat_t content = xbt_dict_get(content_dict,path);
surf_file_t file = xbt_new0(s_surf_file_t,1);
file->name = xbt_strdup(path);
file->content = content;
- surf_action_t action = storage_action_execute(storage,0, DEFAULT);
+ surf_action_t action = storage_action_execute(storage,0, OPEN);
action->file = (void *)file;
return action;
}
free(fp->name);
fp->content = NULL;
xbt_free(fp);
- surf_action_t action = storage_action_execute(storage,0, DEFAULT);
+ surf_action_t action = storage_action_execute(storage,0, CLOSE);
XBT_DEBUG("\tClose file '%s'",filename);
return action;
}
static surf_action_t storage_action_read(void *storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream)
{
char *filename = stream->name;
- content_t content = stream->content;
- XBT_DEBUG("\tRead file '%s' size '%Zu/%Zu'",filename,size,content->size);
- if(size > content->size)
- size = content->size;
+ surf_stat_t content = stream->content;
+ XBT_DEBUG("\tRead file '%s' size '%Zu/%Zu'",filename,size,content->stat.size);
+ if(size > content->stat.size)
+ size = content->stat.size;
surf_action_t action = storage_action_execute(storage,size,READ);
return action;
}
static surf_action_t storage_action_write(void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream)
{
char *filename = stream->name;
- content_t content = stream->content;
- XBT_DEBUG("\tWrite file '%s' size '%Zu/%Zu'",filename,size,content->size);
+ surf_stat_t content = stream->content;
+ XBT_DEBUG("\tWrite file '%s' size '%Zu/%Zu'",filename,size,content->stat.size);
surf_action_t action = storage_action_execute(storage,size,WRITE);
- content->size += size;
+ content->stat.size += size;
return action;
}
-static surf_action_t storage_action_stat(void *storage, int fd, void* buf)
-{
- THROW_UNIMPLEMENTED;
- return NULL;
-}
-
-static surf_action_t storage_action_execute (void *storage, size_t size, STORAGE_execute_type_t type)
+static surf_action_t storage_action_execute (void *storage, size_t size, e_surf_action_storage_type_t type)
{
surf_action_storage_t action = NULL;
storage_t STORAGE = storage;
GENERIC_LMM_ACTION(action).variable =
lmm_variable_new(storage_maxmin_system, action, 1.0, -1.0 , 3);
- if(type == DEFAULT)
- lmm_expand(storage_maxmin_system, STORAGE->constraint,
- GENERIC_LMM_ACTION(action).variable, 1.0);
- else if(type == READ)
+ switch(type) {
+ case OPEN:
+ case CLOSE:
+ case STAT:
+ lmm_expand(storage_maxmin_system, STORAGE->constraint,
+ GENERIC_LMM_ACTION(action).variable, 1.0);
+ break;
+ case READ:
lmm_expand(storage_maxmin_system, STORAGE->constraint_read,
GENERIC_LMM_ACTION(action).variable, 1.0);
- else if(type == WRITE)
+ break;
+ case WRITE:
lmm_expand(storage_maxmin_system, STORAGE->constraint_write,
GENERIC_LMM_ACTION(action).variable, 1.0);
- else xbt_die("storage_action_execute with type '%d'",(int) type);
-
- XBT_OUT();
- return (surf_action_t) action;
-}
-
-static surf_action_t storage_action_sleep (void *storage, double duration)
-{
- surf_action_storage_t action = NULL;
-
- if (duration > 0)
- duration = MAX(duration, MAXMIN_PRECISION);
-
- XBT_IN("(%s,%g)", surf_resource_name(storage), duration);
- action = (surf_action_storage_t) storage_action_execute(storage, 1.0, DEFAULT);
- GENERIC_ACTION(action).max_duration = duration;
- GENERIC_LMM_ACTION(action).suspended = 2;
- if (duration == NO_MAX_DURATION) {
- /* Move to the *end* of the corresponding action set. This convention
- is used to speed up update_resource_state */
- xbt_swag_remove(action, ((surf_action_t) action)->state_set);
- ((surf_action_t) action)->state_set =
- storage_running_action_set_that_does_not_need_being_checked;
- xbt_swag_insert(action, ((surf_action_t) action)->state_set);
+ break;
}
- lmm_update_variable_weight(storage_maxmin_system,
- GENERIC_LMM_ACTION(action).variable, 0.0);
-
XBT_OUT();
return (surf_action_t) action;
}
surf_action_storage_t action = NULL;
surf_action_storage_t next_action = NULL;
xbt_swag_t running_actions = surf_storage_model->states.running_action_set;
- xbt_swag_foreach_safe(action, next_action, running_actions) {
+ xbt_swag_foreach_safe(action, next_action, running_actions) {
double_update(&(GENERIC_ACTION(action).remains),
lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
static void free_storage_content(void *p)
{
- content_t content = p;
- free(content->date);
- free(content->group);
- free(content->time);
- free(content->user);
- free(content->user_rights);
+ surf_stat_t content = p;
+ free(content->stat.date);
+ free(content->stat.group);
+ free(content->stat.time);
+ free(content->stat.user);
+ free(content->stat.user_rights);
free(content);
}
char path[1024];
int nb, size;
- content_t content;
+ surf_stat_t content;
while ((read = getline(&line, &len, file)) != -1) {
- content = xbt_new0(s_content_t,1);
+ content = xbt_new0(s_surf_stat_t,1);
if(sscanf(line,"%s %d %s %s %d %s %s %s",user_rights,&nb,user,group,&size,date,time,path)==8) {
- content->date = xbt_strdup(date);
- content->group = xbt_strdup(group);
- content->size = size;
- content->time = xbt_strdup(time);
- content->user = xbt_strdup(user);
- content->user_rights = xbt_strdup(user_rights);
+ content->stat.date = xbt_strdup(date);
+ content->stat.group = xbt_strdup(group);
+ content->stat.size = size;
+ content->stat.time = xbt_strdup(time);
+ content->stat.user = xbt_strdup(user);
+ content->stat.user_rights = xbt_strdup(user_rights);
xbt_dict_set(parse_content,path,content,NULL);
} else {
xbt_die("Be sure of passing a good format for content file.\n");
typedef struct s_storage_type {
char *model;
- xbt_dict_t content;
+ xbt_dict_t content; /* char * -> s_surf_stat_t */
char *type_id;
xbt_dict_t properties;
} s_storage_type_t, *storage_type_t;
char *name;
} s_mount_t, *mount_t;
-typedef struct s_content {
- char *user_rights;
- char *user;
- char *group;
- char *date;
- char *time;
- size_t size;
-} s_content_t, *content_t;
-
+typedef struct surf_stat { /* file status structure */
+ s_file_stat_t stat;
+ /* possible additionnal fields (e.g., popularity, last access time to know whether the file is in cache, ...) */
+} s_surf_stat_t, *surf_stat_t;
typedef struct surf_file {
char *name;
- content_t content;
+ surf_stat_t content;
} s_surf_file_t;
typedef struct storage {
lmm_constraint_t constraint_read; /* Constraint for maximum write bandwidth*/
} s_storage_t, *storage_t;
+typedef enum {
+ READ, WRITE, STAT, OPEN, CLOSE
+} e_surf_action_storage_type_t;
+
typedef struct surf_action_storage {
s_surf_action_lmm_t generic_lmm_action;
- int index_heap;
+ e_surf_action_storage_type_t type;
} s_surf_action_storage_t, *surf_action_storage_t;
#endif /* STORAGE_PRIVATE_H_ */
return model->extension.storage.write(st, ptr, size, nmemb, stream);
}
-static surf_action_t ws_action_stat(void *workstation, const char* storage, int fd, void* buf)
+static surf_action_t ws_action_stat(void *workstation, const char* storage, surf_file_t stream)
{
storage_t st = find_storage_on_mount_list(workstation, storage);
XBT_DEBUG("STAT on disk '%s'",st->generic_resource.name);
surf_model_t model = st->generic_resource.model;
- return model->extension.storage.stat(st, fd, buf);
+ return model->extension.storage.stat(st, stream);
}
static void surf_workstation_model_init_internal(void)