Skip to content

Commit edd1415

Browse files
committed
allow File::write_async() to be detached (fire and forget mode)
1 parent e669b22 commit edd1415

16 files changed

+213
-25
lines changed

include/fsmod/File.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ namespace simgrid::fsmod {
5454
s4u::IoPtr read_async(sg_size_t num_bytes);
5555
sg_size_t read(const std::string& num_bytes, bool simulate_it=true);
5656
sg_size_t read(sg_size_t num_bytes, bool simulate_it=true);
57-
s4u::IoPtr write_async(const std::string& num_bytes);
58-
s4u::IoPtr write_async(sg_size_t num_bytes);
57+
s4u::IoPtr write_async(const std::string& num_bytes, bool detached=false);
58+
s4u::IoPtr write_async(sg_size_t num_bytes, bool detached=false);
5959
sg_size_t write(const std::string& num_bytes, bool simulate_it=true);
6060
sg_size_t write(sg_size_t num_bytes, bool simulate_it=true);
6161

include/fsmod/JBODStorage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace simgrid::fsmod {
4848
protected:
4949
s4u::IoPtr read_async(sg_size_t size) override;
5050
void read(sg_size_t size) override;
51-
s4u::IoPtr write_async(sg_size_t size) override;
51+
s4u::IoPtr write_async(sg_size_t size, bool detached = false) override;
5252
void write(sg_size_t size) override;
5353

5454
void update_parity_disk_idx() { parity_disk_idx_ = (parity_disk_idx_- 1) % num_disks_; }

include/fsmod/OneDiskStorage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace simgrid::fsmod {
2222
protected:
2323
s4u::IoPtr read_async(sg_size_t size) override;
2424
void read(sg_size_t size) override;
25-
s4u::IoPtr write_async(sg_size_t size) override;
25+
s4u::IoPtr write_async(sg_size_t size, bool detached = false) override;
2626
void write(sg_size_t size) override;
2727
};
2828
} // namespace simgrid::fsmod

include/fsmod/OneRemoteDiskStorage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace simgrid::fsmod {
2222
protected:
2323
s4u::IoPtr read_async(sg_size_t size) override;
2424
void read(sg_size_t size) override;
25-
s4u::IoPtr write_async(sg_size_t size) override;
25+
s4u::IoPtr write_async(sg_size_t size, bool detached = false) override;
2626
void write(sg_size_t size) override;
2727
};
2828
} // namespace simgrid::fsmod

include/fsmod/Storage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace simgrid::fsmod {
4646
virtual s4u::IoPtr read_async(sg_size_t size) = 0;
4747
virtual void read(sg_size_t size) = 0;
4848

49-
virtual s4u::IoPtr write_async(sg_size_t size) = 0;
49+
virtual s4u::IoPtr write_async(sg_size_t size, bool detached = false) = 0;
5050
virtual void write(sg_size_t size) = 0;
5151

5252
private:

src/File.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ namespace simgrid::fsmod {
120120
* @param num_bytes: the number of bytes to read as a string with units
121121
* @return An I/O activity
122122
*/
123-
s4u::IoPtr File::write_async(const std::string& num_bytes) {
124-
return write_async(static_cast<sg_size_t>(xbt_parse_get_size("", 0, num_bytes, "")));
123+
s4u::IoPtr File::write_async(const std::string& num_bytes, bool detached) {
124+
return write_async(static_cast<sg_size_t>(xbt_parse_get_size("", 0, num_bytes, "")), detached);
125125
}
126126

127127
/**
128128
* @brief Asynchronously write data from the file
129129
* @param num_bytes: the number of bytes to read
130130
* @return An I/O activity
131131
*/
132-
s4u::IoPtr File::write_async(sg_size_t num_bytes) {
132+
s4u::IoPtr File::write_async(sg_size_t num_bytes, bool detached) {
133133
int my_sequence_number = write_init_checks(num_bytes);
134-
s4u::IoPtr io = boost::dynamic_pointer_cast<s4u::Io>(partition_->get_storage()->write_async(num_bytes));
134+
s4u::IoPtr io = boost::dynamic_pointer_cast<s4u::Io>(partition_->get_storage()->write_async(num_bytes, detached));
135135
io->on_this_completion_cb([this, my_sequence_number](s4u::Io const&) {
136136
// Update
137137
metadata_->set_access_date(s4u::Engine::get_clock());

src/JBODStorage.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ namespace simgrid::fsmod {
142142
read_async(size)->wait();
143143
}
144144

145-
s4u::IoPtr JBODStorage::write_async(sg_size_t size) {
145+
s4u::IoPtr JBODStorage::write_async(sg_size_t size, bool detached) {
146146
// Transfer data from the host that requested a write to the controller host of the JBOD
147147
auto comm = s4u::Comm::sendto_init()->set_payload_size(size)->set_source(s4u::Host::current());
148148
comm->set_name("Transfer to JBod");
@@ -219,6 +219,9 @@ namespace simgrid::fsmod {
219219
// Completion activity is now blocked by I/Os, start it by assigning it to the controller host first disk
220220
completion_activity->set_disk(get_first_disk());
221221

222+
if (detached)
223+
completion_activity->detach();
224+
222225
return completion_activity;
223226
}
224227

src/OneDiskStorage.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ namespace simgrid::fsmod {
3030
get_first_disk()->read(size);
3131
}
3232

33-
s4u::IoPtr OneDiskStorage::write_async(sg_size_t size) {
34-
return get_first_disk()->write_async(size);
33+
s4u::IoPtr OneDiskStorage::write_async(sg_size_t size, bool detached) {
34+
auto io = s4u::IoPtr(get_first_disk()->io_init(size, s4u::Io::OpType::WRITE));
35+
if (detached)
36+
io->detach();
37+
else
38+
io->start();
39+
40+
return io;
3541
}
3642

3743
void OneDiskStorage::write(sg_size_t size) {

src/OneRemoteDiskStorage.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ namespace simgrid::fsmod {
3333
this->read_async(size)->wait();
3434
}
3535

36-
s4u::IoPtr OneRemoteDiskStorage::write_async(sg_size_t size) {
36+
s4u::IoPtr OneRemoteDiskStorage::write_async(sg_size_t size, bool detached) {
3737
auto destination_host = get_controller_host();
3838
if (destination_host == nullptr)
3939
destination_host= this->get_first_disk()->get_host();
40-
return s4u::Io::streamto_async(s4u::Host::current(), nullptr, destination_host, get_first_disk(), size);
40+
auto io = s4u::Io::streamto_init(s4u::Host::current(), nullptr, destination_host, get_first_disk())->set_size(size);
41+
if (detached)
42+
io->detach();
43+
else
44+
io->start();
45+
46+
return io;
4147
}
4248

4349
void OneRemoteDiskStorage::write(sg_size_t size) {

src/bindings/python/fsmod_python.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ PYBIND11_MODULE(fsmod, m)
9191
py::arg("simulate_it") = true, "Read data from the File")
9292
.def("read", py::overload_cast<sg_size_t, bool>(&File::read), py::arg("num_bytes"), py::arg("simulate_it") = true,
9393
"Read data from the File")
94-
.def("write_async", py::overload_cast<const std::string&>(&File::write_async), py::arg("num_bytes"),
95-
"Asynchronously write data to the File")
96-
.def("write_async", py::overload_cast<sg_size_t>(&File::write_async), py::arg("num_bytes"),
97-
"Asynchronously write data to the File")
94+
.def("write_async", py::overload_cast<const std::string&, bool>(&File::write_async), py::arg("num_bytes"),
95+
py::arg("detached") = false, "Asynchronously write data to the File")
96+
.def("write_async", py::overload_cast<sg_size_t, bool>(&File::write_async), py::arg("num_bytes"),
97+
py::arg("detached") = false, "Asynchronously write data to the File")
9898
.def("write", py::overload_cast<const std::string&, bool>(&File::write), py::arg("num_bytes"),
9999
py::arg("simulate_it") = true, "Write data to the File")
100100
.def("write", py::overload_cast<sg_size_t, bool>(&File::write), py::arg("num_bytes"),

0 commit comments

Comments
 (0)