Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement file open read and stat in simix.
authornavarro <navarro@caraja.(none)>
Tue, 31 Jan 2012 14:01:40 +0000 (15:01 +0100)
committernavarro <navarro@caraja.(none)>
Tue, 31 Jan 2012 14:01:40 +0000 (15:01 +0100)
include/simix/simix.h
src/simix/smx_io.c
src/simix/smx_io_private.h
src/simix/smx_smurf.c
src/simix/smx_smurf_private.h
src/simix/smx_user.c

index beab8b6..6022a19 100644 (file)
@@ -246,6 +246,10 @@ XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem);
 
 XBT_PUBLIC(size_t) simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 XBT_PUBLIC(size_t) simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 
 XBT_PUBLIC(size_t) simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 XBT_PUBLIC(size_t) simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
+XBT_PUBLIC(smx_file_t*) simcall_file_open(const char* path, const char* mode);
+XBT_PUBLIC(size_t) simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
+XBT_PUBLIC(int) simcall_file_close(smx_file_t* fp);
+XBT_PUBLIC(int) simcall_file_stat(int fd, void* buf);
 
 SG_END_DECL()
 #endif                          /* _SIMIX_SIMIX_H */
 
 SG_END_DECL()
 #endif                          /* _SIMIX_SIMIX_H */
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)) {
index cca116a..c2ffde4 100644 (file)
@@ -21,8 +21,15 @@ typedef struct s_smx_file *smx_file_t;
 
 void SIMIX_pre_file_read(smx_simcall_t simcall);
 void SIMIX_pre_file_write(smx_simcall_t simcall);
 
 void SIMIX_pre_file_read(smx_simcall_t simcall);
 void SIMIX_pre_file_write(smx_simcall_t simcall);
+void SIMIX_pre_file_open(smx_simcall_t simcall);
+void SIMIX_pre_file_close(smx_simcall_t simcall);
+void SIMIX_pre_file_stat(smx_simcall_t simcall);
+
 smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 smx_action_t SIMIX_file_write(smx_process_t process, 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* path, const char* mode);
+smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t* fp);
+smx_action_t SIMIX_file_stat(smx_process_t process, int fd, void* buf);
 
 void SIMIX_post_io(smx_action_t action);
 void SIMIX_io_destroy(smx_action_t action);
 
 void SIMIX_post_io(smx_action_t action);
 void SIMIX_io_destroy(smx_action_t action);
index 06a084e..56863f8 100644 (file)
@@ -490,12 +490,15 @@ void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
       break;
 
     case SIMCALL_FILE_OPEN:
       break;
 
     case SIMCALL_FILE_OPEN:
+      SIMIX_pre_file_open(simcall);
       break;
 
     case SIMCALL_FILE_CLOSE:
       break;
 
     case SIMCALL_FILE_CLOSE:
+      SIMIX_pre_file_close(simcall);
       break;
 
     case SIMCALL_FILE_STAT:
       break;
 
     case SIMCALL_FILE_STAT:
+      SIMIX_pre_file_stat(simcall);
       break;
 
     case SIMCALL_NONE:
       break;
 
     case SIMCALL_NONE:
index 4135e30..026252c 100644 (file)
@@ -534,6 +534,13 @@ typedef struct s_smx_simcall {
       int result;
     } file_close;
 
       int result;
     } file_close;
 
+    struct {
+      int fd;
+      //Next should be struct stat* buf
+      void* buf;
+      int result;
+    } file_stat;
+
   };
 } s_smx_simcall_t, *smx_simcall_t;
 
   };
 } s_smx_simcall_t, *smx_simcall_t;
 
index 255907e..e26d97f 100644 (file)
@@ -1205,6 +1205,41 @@ size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t
   return simcall->file_write.result;
 }
 
   return simcall->file_write.result;
 }
 
+smx_file_t* simcall_file_open(const char* path, const char* mode)
+{
+  smx_simcall_t simcall = SIMIX_simcall_mine();
+
+  simcall->call = SIMCALL_FILE_OPEN;
+  simcall->file_open.path = path;
+  simcall->file_open.mode = mode;
+  SIMIX_simcall_push(simcall->issuer);
+
+  return simcall->file_open.result;
+}
+
+int simcall_file_close(smx_file_t* fp)
+{
+  smx_simcall_t simcall = SIMIX_simcall_mine();
+
+  simcall->call = SIMCALL_FILE_CLOSE;
+  simcall->file_close.fp = fp;
+  SIMIX_simcall_push(simcall->issuer);
+
+  return simcall->file_close.result;
+}
+
+int simcall_file_stat(int fd, void* buf)
+{
+  smx_simcall_t simcall = SIMIX_simcall_mine();
+
+  simcall->call = SIMCALL_FILE_STAT;
+  simcall->file_stat.fd = fd;
+  simcall->file_stat.buf = buf;
+  SIMIX_simcall_push(simcall->issuer);
+
+  return simcall->file_stat.result;
+}
+
 /* ************************************************************************** */
 
 /** @brief returns a printable string representing a simcall */
 /* ************************************************************************** */
 
 /** @brief returns a printable string representing a simcall */