Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement file open read and stat in simix.
[simgrid.git] / src / simix / smx_io.c
index e4072e6..5720658 100644 (file)
@@ -47,7 +47,7 @@ smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size
 
   action->io.host = host;
   //  TODO in surf model disk???
 
   action->io.host = host;
   //  TODO in surf model disk???
-  //  action->io.surf_io = surf_workstation_model->extension.disk.read(host->host, name),
+  //  action->io.surf_io = surf_workstation_model->extension.storage.read(host->host, name),
   action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 1.0);
 
   surf_workstation_model->action_data_set(action->io.surf_io, action);
   action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 1.0);
 
   surf_workstation_model->action_data_set(action->io.surf_io, action);
@@ -89,7 +89,7 @@ smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t siz
 
   action->io.host = host;
   //  TODO in surf model disk???
 
   action->io.host = host;
   //  TODO in surf model disk???
-  //  action->io.surf_io = surf_workstation_model->extension.disk.write(host->host, name),
+  //  action->io.surf_io = surf_workstation_model->extension.storage.write(host->host, name),
   action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 2.0);
 
   surf_workstation_model->action_data_set(action->io.surf_io, action);
   action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 2.0);
 
   surf_workstation_model->action_data_set(action->io.surf_io, action);
@@ -98,6 +98,125 @@ smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t siz
   return action;
 }
 
   return action;
 }
 
+//SIMIX FILE OPEN
+void SIMIX_pre_file_open(smx_simcall_t simcall)
+{
+  smx_action_t action = SIMIX_file_open(simcall->issuer,
+      simcall->file_open.path,
+      simcall->file_open.mode);
+  xbt_fifo_push(action->simcalls, simcall);
+  simcall->issuer->waiting_action = action;
+}
+
+smx_action_t SIMIX_file_open(smx_process_t process, const char* path, const char* mode)
+{
+  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) {
+    THROWF(host_error, 0, "Host %s failed, you cannot call this function",
+           host->name);
+  }
+
+  action = xbt_mallocator_get(simix_global->action_mallocator);
+  action->type = SIMIX_ACTION_IO;
+  action->name = NULL;
+#ifdef HAVE_TRACING
+  action->category = NULL;
+#endif
+
+  action->io.host = host;
+  //  TODO in surf model disk???
+  //  action->io.surf_io = surf_workstation_model->extension.storage.open(host->host, name),
+  action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 3.0);
+
+  surf_workstation_model->action_data_set(action->io.surf_io, action);
+  XBT_DEBUG("Create io action %p", action);
+
+  return action;
+}
+
+//SIMIX FILE CLOSE
+void SIMIX_pre_file_close(smx_simcall_t simcall)
+{
+  smx_action_t action = SIMIX_file_close(simcall->issuer,
+      simcall->file_close.fp);
+  xbt_fifo_push(action->simcalls, simcall);
+  simcall->issuer->waiting_action = action;
+}
+
+smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t* fp)
+{
+  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) {
+    THROWF(host_error, 0, "Host %s failed, you cannot call this function",
+           host->name);
+  }
+
+  action = xbt_mallocator_get(simix_global->action_mallocator);
+  action->type = SIMIX_ACTION_IO;
+  action->name = NULL;
+#ifdef HAVE_TRACING
+  action->category = NULL;
+#endif
+
+  action->io.host = host;
+  //  TODO in surf model disk???
+  //  action->io.surf_io = surf_workstation_model->extension.storage.close(host->host, name),
+  action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 4.0);
+
+  surf_workstation_model->action_data_set(action->io.surf_io, action);
+  XBT_DEBUG("Create io action %p", action);
+
+  return action;
+}
+
+//SIMIX FILE STAT
+void SIMIX_pre_file_stat(smx_simcall_t simcall)
+{
+  smx_action_t action = SIMIX_file_stat(simcall->issuer,
+      simcall->file_stat.fd,
+      simcall->file_stat.buf);
+  xbt_fifo_push(action->simcalls, simcall);
+  simcall->issuer->waiting_action = action;
+}
+
+smx_action_t SIMIX_file_stat(smx_process_t process, int fd, void* 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) {
+    THROWF(host_error, 0, "Host %s failed, you cannot call this function",
+           host->name);
+  }
+
+  action = xbt_mallocator_get(simix_global->action_mallocator);
+  action->type = SIMIX_ACTION_IO;
+  action->name = NULL;
+#ifdef HAVE_TRACING
+  action->category = NULL;
+#endif
+
+  action->io.host = host;
+  //  TODO in surf model disk???
+  //  action->io.surf_io = surf_workstation_model->extension.storage.stat(host->host, name),
+  action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 5.0);
+
+  surf_workstation_model->action_data_set(action->io.surf_io, action);
+  XBT_DEBUG("Create io action %p", action);
+
+  return action;
+}
+
 void SIMIX_post_io(smx_action_t action)
 {
   switch (surf_workstation_model->action_state_get(action->io.surf_io)) {
 void SIMIX_post_io(smx_action_t action)
 {
   switch (surf_workstation_model->action_state_get(action->io.surf_io)) {