This is an automated email from the ASF dual-hosted git repository. qianzhang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push: new 014431e Updated volume manager to support user specified target path root. 014431e is described below commit 014431e3c1b98e514e327318b52e5c54cc6174df Author: Qian Zhang <zhq527...@gmail.com> AuthorDate: Mon Aug 17 19:22:48 2020 +0800 Updated volume manager to support user specified target path root. Review: https://reviews.apache.org/r/72781 --- src/csi/v0_volume_manager.cpp | 29 +++++++++++------------------ src/csi/v0_volume_manager_process.hpp | 1 + src/csi/v1_volume_manager.cpp | 31 ++++++++++++------------------- src/csi/v1_volume_manager_process.hpp | 1 + src/slave/csi_server.cpp | 14 ++++++-------- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/csi/v0_volume_manager.cpp b/src/csi/v0_volume_manager.cpp index 9e840a7..42a23ba 100644 --- a/src/csi/v0_volume_manager.cpp +++ b/src/csi/v0_volume_manager.cpp @@ -92,7 +92,10 @@ VolumeManagerProcess::VolumeManagerProcess( runtime(_runtime), serviceManager(_serviceManager), metrics(_metrics), - secretResolver(_secretResolver) + secretResolver(_secretResolver), + mountRootDir(info.has_target_path_root() + ? info.target_path_root() + : paths::getMountRootDir(rootDir, info.type(), info.name())) { // This should have been validated in `VolumeManager::create`. CHECK(!services.empty()) @@ -210,9 +213,6 @@ Future<Nothing> VolumeManagerProcess::recover() } // Garbage collect leftover mount paths that were failed to remove before. - const string mountRootDir = - paths::getMountRootDir(rootDir, info.type(), info.name()); - Try<list<string>> mountPaths = paths::getMountPaths(mountRootDir); if (mountPaths.isError()) { // TODO(chhsiao): This could indicate that something is seriously wrong. @@ -723,8 +723,7 @@ Future<bool> VolumeManagerProcess::_deleteVolume(const std::string& volumeId) if (volumeState.node_publish_required()) { CHECK_EQ(VolumeState::PUBLISHED, volumeState.state()); - const string targetPath = paths::getMountTargetPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string targetPath = paths::getMountTargetPath(mountRootDir, volumeId); // NOTE: Normally the volume should have been cleaned up. However this may // not be true for preprovisioned volumes (e.g., leftover from a previous @@ -929,8 +928,7 @@ Future<Nothing> VolumeManagerProcess::_publishVolume(const string& volumeId) .then(process::defer(self(), &Self::_publishVolume, volumeId)); } - const string targetPath = paths::getMountTargetPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string targetPath = paths::getMountTargetPath(mountRootDir, volumeId); // NOTE: The target path will be cleaned up during volume removal. Try<Nothing> mkdir = os::mkdir(targetPath); @@ -959,7 +957,7 @@ Future<Nothing> VolumeManagerProcess::_publishVolume(const string& volumeId) if (nodeCapabilities->stageUnstageVolume) { const string stagingPath = paths::getMountStagingPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + mountRootDir, volumeId); CHECK(os::exists(stagingPath)); request.set_staging_target_path(stagingPath); @@ -1044,8 +1042,7 @@ Future<Nothing> VolumeManagerProcess::__publishVolume(const string& volumeId) .then(process::defer(self(), &Self::__publishVolume, volumeId)); } - const string stagingPath = paths::getMountStagingPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string stagingPath = paths::getMountStagingPath(mountRootDir, volumeId); // NOTE: The staging path will be cleaned up in during volume removal. Try<Nothing> mkdir = os::mkdir(stagingPath); @@ -1151,8 +1148,7 @@ Future<Nothing> VolumeManagerProcess::_unpublishVolume(const string& volumeId) checkpointVolumeState(volumeId); } - const string stagingPath = paths::getMountStagingPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string stagingPath = paths::getMountStagingPath(mountRootDir, volumeId); CHECK(os::exists(stagingPath)); @@ -1210,8 +1206,7 @@ Future<Nothing> VolumeManagerProcess::__unpublishVolume(const string& volumeId) checkpointVolumeState(volumeId); } - const string targetPath = paths::getMountTargetPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string targetPath = paths::getMountTargetPath(mountRootDir, volumeId); CHECK(os::exists(targetPath)); @@ -1255,9 +1250,7 @@ void VolumeManagerProcess::garbageCollectMountPath(const string& volumeId) { CHECK(!volumes.contains(volumeId)); - const string path = paths::getMountPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); - + const string path = paths::getMountPath(mountRootDir, volumeId); if (os::exists(path)) { Try<Nothing> rmdir = os::rmdir(path); if (rmdir.isError()) { diff --git a/src/csi/v0_volume_manager_process.hpp b/src/csi/v0_volume_manager_process.hpp index 1162955..e392c57 100644 --- a/src/csi/v0_volume_manager_process.hpp +++ b/src/csi/v0_volume_manager_process.hpp @@ -191,6 +191,7 @@ private: ServiceManager* serviceManager; Metrics* metrics; SecretResolver* secretResolver; + const std::string mountRootDir; Option<std::string> bootId; Option<PluginCapabilities> pluginCapabilities; diff --git a/src/csi/v1_volume_manager.cpp b/src/csi/v1_volume_manager.cpp index 7230676..c05265c 100644 --- a/src/csi/v1_volume_manager.cpp +++ b/src/csi/v1_volume_manager.cpp @@ -93,7 +93,10 @@ VolumeManagerProcess::VolumeManagerProcess( runtime(_runtime), serviceManager(_serviceManager), metrics(_metrics), - secretResolver(_secretResolver) + secretResolver(_secretResolver), + mountRootDir(info.has_target_path_root() + ? info.target_path_root() + : paths::getMountRootDir(rootDir, info.type(), info.name())) { // This should have been validated in `VolumeManager::create`. CHECK(!services.empty()) @@ -211,9 +214,6 @@ Future<Nothing> VolumeManagerProcess::recover() } // Garbage collect leftover mount paths that were failed to remove before. - const string mountRootDir = - paths::getMountRootDir(rootDir, info.type(), info.name()); - Try<list<string>> mountPaths = paths::getMountPaths(mountRootDir); if (mountPaths.isError()) { // TODO(chhsiao): This could indicate that something is seriously wrong. @@ -745,8 +745,7 @@ Future<bool> VolumeManagerProcess::_deleteVolume(const std::string& volumeId) if (volumeState.node_publish_required()) { CHECK_EQ(VolumeState::PUBLISHED, volumeState.state()); - const string targetPath = paths::getMountTargetPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string targetPath = paths::getMountTargetPath(mountRootDir, volumeId); // NOTE: Normally the volume should have been cleaned up. However this may // not be true for preprovisioned volumes (e.g., leftover from a previous @@ -951,8 +950,7 @@ Future<Nothing> VolumeManagerProcess::_publishVolume(const string& volumeId) .then(process::defer(self(), &Self::_publishVolume, volumeId)); } - const string targetPath = paths::getMountTargetPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string targetPath = paths::getMountTargetPath(mountRootDir, volumeId); // Ensure the parent directory of the target path exists. The target path // itself will be created by the plugin. @@ -984,8 +982,8 @@ Future<Nothing> VolumeManagerProcess::_publishVolume(const string& volumeId) *request.mutable_volume_context() = volumeState.volume_context(); if (nodeCapabilities->stageUnstageVolume) { - const string stagingPath = paths::getMountStagingPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string stagingPath = + paths::getMountStagingPath(mountRootDir, volumeId); CHECK(os::exists(stagingPath)); request.set_staging_target_path(stagingPath); @@ -1070,8 +1068,7 @@ Future<Nothing> VolumeManagerProcess::__publishVolume(const string& volumeId) .then(process::defer(self(), &Self::__publishVolume, volumeId)); } - const string stagingPath = paths::getMountStagingPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string stagingPath = paths::getMountStagingPath(mountRootDir, volumeId); // NOTE: The staging path will be cleaned up in during volume removal. Try<Nothing> mkdir = os::mkdir(stagingPath); @@ -1177,8 +1174,7 @@ Future<Nothing> VolumeManagerProcess::_unpublishVolume(const string& volumeId) checkpointVolumeState(volumeId); } - const string stagingPath = paths::getMountStagingPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string stagingPath = paths::getMountStagingPath(mountRootDir, volumeId); CHECK(os::exists(stagingPath)); @@ -1236,8 +1232,7 @@ Future<Nothing> VolumeManagerProcess::__unpublishVolume(const string& volumeId) checkpointVolumeState(volumeId); } - const string targetPath = paths::getMountTargetPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); + const string targetPath = paths::getMountTargetPath(mountRootDir, volumeId); LOG(INFO) << "Calling '/csi.v1.Node/NodeUnpublishVolume' for volume '" << volumeId << "'"; @@ -1284,9 +1279,7 @@ void VolumeManagerProcess::garbageCollectMountPath(const string& volumeId) { CHECK(!volumes.contains(volumeId)); - const string path = paths::getMountPath( - paths::getMountRootDir(rootDir, info.type(), info.name()), volumeId); - + const string path = paths::getMountPath(mountRootDir, volumeId); if (os::exists(path)) { Try<Nothing> rmdir = os::rmdir(path); if (rmdir.isError()) { diff --git a/src/csi/v1_volume_manager_process.hpp b/src/csi/v1_volume_manager_process.hpp index 63dc03e..9f2c1f5 100644 --- a/src/csi/v1_volume_manager_process.hpp +++ b/src/csi/v1_volume_manager_process.hpp @@ -191,6 +191,7 @@ private: ServiceManager* serviceManager; Metrics* metrics; SecretResolver* secretResolver; + const std::string mountRootDir; Option<std::string> bootId; Option<PluginCapabilities> pluginCapabilities; diff --git a/src/slave/csi_server.cpp b/src/slave/csi_server.cpp index a9a3995..b435d5d 100644 --- a/src/slave/csi_server.cpp +++ b/src/slave/csi_server.cpp @@ -246,16 +246,14 @@ Future<string> CSIServerProcess::publishVolume( .then([=]() { CHECK(plugins.contains(volume.plugin_name())); - const string targetRootDir = - plugins.at(volume.plugin_name()).info.has_target_path_root() - ? plugins.at(volume.plugin_name()).info.target_path_root() - : rootDir; + const CSIPluginInfo& info = plugins.at(volume.plugin_name()).info; + + const string mountRootDir = info.has_target_path_root() + ? info.target_path_root() + : csi::paths::getMountRootDir(rootDir, info.type(), info.name()); return csi::paths::getMountTargetPath( - csi::paths::getMountRootDir( - targetRootDir, - plugins.at(volume.plugin_name()).info.type(), - plugins.at(volume.plugin_name()).info.name()), + mountRootDir, volume.static_provisioning().volume_id()); }); }