Skip to content

Commit

Permalink
allow to find FileSystems by giving a specific NetZone
Browse files Browse the repository at this point in the history
  • Loading branch information
frs69wq committed Jun 10, 2024
1 parent 5c050dc commit 97a5ccb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
5 changes: 4 additions & 1 deletion include/fsmod/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ namespace simgrid::fsmod {


static std::shared_ptr<FileSystem> create(const std::string &name, int max_num_open_files = 1024);
static const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>>& get_file_systems_by_actor(s4u::ActorPtr actor);
static const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>>&
get_file_systems_by_actor(s4u::ActorPtr actor);
static const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>>&
get_file_systems_by_netzone(s4u::NetZone* netzone);
static void register_file_system(s4u::NetZone* netzone, std::shared_ptr<FileSystem> fs);

/**
Expand Down
11 changes: 11 additions & 0 deletions src/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ namespace simgrid::fsmod {
}
}

const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>>&
FileSystem::get_file_systems_by_netzone(s4u::NetZone* netzone) {
auto* extension = netzone->get_impl()->extension<FileSystemNetZoneImplExtension>();
if (extension) {
return extension->get_all_file_systems();
} else {
static const std::map<std::string, std::shared_ptr<FileSystem>, std::less<>>& empty = {};
return empty;
}
}

/**
* @brief Retrieve a partition by name (i.e., mount point), and throw an exception if no such partition exists
* @param name: A name (i.e., mount point)
Expand Down
30 changes: 29 additions & 1 deletion test/register_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RegisterTest : public ::testing::Test {
}
};

TEST_F(RegisterTest, Retrieve) {
TEST_F(RegisterTest, RetrieveByActor) {
DO_TEST_WITH_FORK([this]() {
this->setup_platform();
auto hosts = sg4::Engine::get_instance()->get_all_hosts();
Expand Down Expand Up @@ -91,6 +91,34 @@ TEST_F(RegisterTest, Retrieve) {
});
}

TEST_F(RegisterTest, RetrieveByZone) {
DO_TEST_WITH_FORK([this]() {
xbt_log_control_set("root.thresh:info");
this->setup_platform();
auto netzones = sg4::Engine::get_instance()->get_all_netzones();
int index = -1;
for (const auto& nz : netzones) {
XBT_INFO("Looking for file systems in NetZone '%s'", nz->get_cname());
std::map<std::string, std::shared_ptr<sgfs::FileSystem>, std::less<>> accessible_file_systems;
ASSERT_NO_THROW(accessible_file_systems = sgfs::FileSystem::get_file_systems_by_netzone(nz));
if (nz->get_name() == "root_zone") {
ASSERT_EQ(accessible_file_systems.size(), 0);
} else if (index == 0) {
ASSERT_EQ(accessible_file_systems.size(), 2);
} else {
ASSERT_EQ(accessible_file_systems.size(), 1);
auto [name, fs] = *accessible_file_systems.begin();
ASSERT_EQ(name, "my_fs_" + std::to_string(index));
ASSERT_EQ(fs->get_name(), "my_fs_" + std::to_string(index));
}
index++;
}

// Run the simulation
ASSERT_NO_THROW(sg4::Engine::get_instance()->run());
});
}

TEST_F(RegisterTest, NoActor) {
DO_TEST_WITH_FORK([this]() {
XBT_INFO("Creating a very small platform");
Expand Down

0 comments on commit 97a5ccb

Please sign in to comment.