Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into disk
[simgrid.git] / src / kernel / activity / IoImpl.cpp
index b7c10da2c80df7d87ce037b8bdff27bb45b466d6..63f5381293a8dd049c0fb8216b8931abf67b6e2a 100644 (file)
@@ -7,6 +7,7 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/kernel/resource/Action.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "src/kernel/resource/DiskImpl.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
 #include "src/surf/StorageImpl.hpp"
@@ -44,6 +45,12 @@ IoImpl& IoImpl::set_size(sg_size_t size)
   return *this;
 }
 
+IoImpl& IoImpl::set_disk(resource::DiskImpl* disk)
+{
+  disk_ = disk;
+  return *this;
+}
+
 IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
 {
   storage_ = storage;
@@ -53,7 +60,10 @@ IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
 IoImpl* IoImpl::start()
 {
   state_       = SIMIX_RUNNING;
-  surf_action_ = storage_->io_start(size_, type_);
+  if (storage_)
+    surf_action_ = storage_->io_start(size_, type_);
+  else
+    surf_action_ = disk_->io_start(size_, type_);
   surf_action_->set_activity(this);
 
   XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
@@ -66,7 +76,7 @@ void IoImpl::post()
 {
   performed_ioops_ = surf_action_->get_cost();
   if (surf_action_->get_state() == resource::Action::State::FAILED) {
-    if (storage_ && not storage_->is_on())
+    if ((storage_ && not storage_->is_on()) || (disk_ && not disk_->is_on()))
       state_ = SIMIX_FAILED;
     else
       state_ = SIMIX_CANCELED;
@@ -75,6 +85,7 @@ void IoImpl::post()
   }
   on_completion(*this);
 
+  /* Answer all simcalls associated with the synchro */
   finish();
 }
 
@@ -88,19 +99,19 @@ void IoImpl::finish()
         /* do nothing, synchro done */
         break;
       case SIMIX_FAILED:
-        simcall->issuer->context_->iwannadie = true;
-        simcall->issuer->exception_ =
+        simcall->issuer_->context_->iwannadie = true;
+        simcall->issuer_->exception_ =
             std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
         break;
       case SIMIX_CANCELED:
-        simcall->issuer->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
+        simcall->issuer_->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
         break;
       default:
         xbt_die("Internal error in IoImpl::finish(): unexpected synchro state %d", static_cast<int>(state_));
     }
 
-    simcall->issuer->waiting_synchro = nullptr;
-    SIMIX_simcall_answer(simcall);
+    simcall->issuer_->waiting_synchro = nullptr;
+    simcall->issuer_->simcall_answer();
   }
 }