Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make progress towards a programmatic creation of disks
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Disk.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/Io.hpp"
10 #include "simgrid/simix.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12
13 namespace simgrid {
14
15 template class xbt::Extendable<s4u::Disk>;
16
17 namespace s4u {
18
19 xbt::signal<void(Disk&)> Disk::on_creation;
20 xbt::signal<void(Disk const&)> Disk::on_destruction;
21 xbt::signal<void(Disk const&)> Disk::on_state_change;
22
23 Disk* Disk::set_name(const std::string& name)
24 {
25   name_ = name;
26   return this;
27 }
28
29 Disk* Disk::set_read_bandwidth(double read_bw)
30 {
31   pimpl_->set_read_bandwidth(read_bw);
32   return this;
33 }
34
35 Disk* Disk::set_write_bandwidth(double write_bw)
36 {
37   pimpl_->set_write_bandwidth(write_bw);
38   return this;
39 }
40
41 double Disk::get_read_bandwidth() const
42 {
43   return this->pimpl_->get_read_bandwidth();
44 }
45
46 double Disk::get_write_bandwidth() const
47 {
48   return pimpl_->get_write_bandwidth();
49 }
50
51 Host* Disk::get_host() const
52 {
53   return pimpl_->get_host();
54 }
55
56 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
57 {
58   return pimpl_->get_properties();
59 }
60
61 const char* Disk::get_property(const std::string& key) const
62 {
63   return this->pimpl_->get_property(key);
64 }
65
66 void Disk::set_property(const std::string& key, const std::string& value)
67 {
68   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
69 }
70
71 IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
72 {
73   return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
74 }
75
76 IoPtr Disk::read_async(sg_size_t size)
77 {
78   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
79 }
80
81 sg_size_t Disk::read(sg_size_t size)
82 {
83   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
84 }
85
86 IoPtr Disk::write_async(sg_size_t size)
87 {
88   return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
89 }
90
91 sg_size_t Disk::write(sg_size_t size)
92 {
93   return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
94 }
95
96 } // namespace s4u
97 } // namespace simgrid
98
99 /* **************************** Public C interface *************************** */
100
101 const char* sg_disk_get_name(const_sg_disk_t disk)
102 {
103   return disk->get_cname();
104 }
105
106 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
107 {
108   return disk->get_host();
109 }
110
111 double sg_disk_read_bandwidth(const_sg_disk_t disk)
112 {
113   return disk->get_read_bandwidth();
114 }
115
116 double sg_disk_write_bandwidth(const_sg_disk_t disk)
117 {
118   return disk->get_write_bandwidth();
119 }
120
121 sg_size_t sg_disk_read(sg_disk_t disk, sg_size_t size)
122 {
123   return disk->read(size);
124 }
125 sg_size_t sg_disk_write(sg_disk_t disk, sg_size_t size)
126 {
127   return disk->write(size);
128 }
129
130 void* sg_disk_get_data(const_sg_disk_t disk)
131 {
132   return disk->get_data();
133 }
134
135 void sg_disk_set_data(sg_disk_t disk, void* data)
136 {
137   disk->set_data(data);
138 }