This is an automated email from the ASF dual-hosted git repository. chhsiao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 13f4c5c4e3584cb891cda48002291f1b7fdf3234 Author: Chun-Hung Hsiao <[email protected]> AuthorDate: Mon Apr 1 23:23:58 2019 -0700 Implemented the remaining methods of v0 `VolumeManager`. This patch completes the v0 `VolumeManager` by properly implemented the `attachVolume`, `detachVolume` and `unpublishVolume` functions that are not used by SLRP. Review: https://reviews.apache.org/r/70285/ --- src/csi/v0_volume_manager.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/csi/v0_volume_manager.cpp b/src/csi/v0_volume_manager.cpp index c6112be..3a5aee7 100644 --- a/src/csi/v0_volume_manager.cpp +++ b/src/csi/v0_volume_manager.cpp @@ -424,13 +424,37 @@ Future<bool> VolumeManagerProcess::deleteVolume(const string& volumeId) Future<Nothing> VolumeManagerProcess::attachVolume(const string& volumeId) { - return Failure("Unimplemented"); + if (!volumes.contains(volumeId)) { + return Failure("Cannot attach unknown volume '" + volumeId + "'"); + } + + VolumeData& volume = volumes.at(volumeId); + + LOG(INFO) << "Attaching volume '" << volumeId << "' in " + << volume.state.state() << " state"; + + // Volume attaching is serialized with other operations on the same volume to + // avoid races. + return volume.sequence->add(std::function<Future<Nothing>()>( + process::defer(self(), &Self::_attachVolume, volumeId))); } Future<Nothing> VolumeManagerProcess::detachVolume(const string& volumeId) { - return Failure("Unimplemented"); + if (!volumes.contains(volumeId)) { + return Failure("Cannot detach unknown volume '" + volumeId + "'"); + } + + VolumeData& volume = volumes.at(volumeId); + + LOG(INFO) << "Detaching volume '" << volumeId << "' in " + << volume.state.state() << " state"; + + // Volume detaching is serialized with other operations on the same volume to + // avoid races. + return volume.sequence->add(std::function<Future<Nothing>()>( + process::defer(self(), &Self::_detachVolume, volumeId))); } @@ -454,7 +478,19 @@ Future<Nothing> VolumeManagerProcess::publishVolume(const string& volumeId) Future<Nothing> VolumeManagerProcess::unpublishVolume(const string& volumeId) { - return Failure("Unimplemented"); + if (!volumes.contains(volumeId)) { + return Failure("Cannot unpublish unknown volume '" + volumeId + "'"); + } + + VolumeData& volume = volumes.at(volumeId); + + LOG(INFO) << "Unpublishing volume '" << volumeId << "' in " + << volume.state.state() << " state"; + + // Volume unpublishing is serialized with other operations on the same volume + // to avoid races. + return volume.sequence->add(std::function<Future<Nothing>()>( + process::defer(self(), &Self::_unpublishVolume, volumeId))); }
