summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2019-10-24 12:15:41 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-10-24 12:15:41 +0000
commit2c7ae59ede47792583b76141f6f73bcc6219bfbd (patch)
treedf0f28143642b2d0536d3070f9369cf4c8d6d9f2
parent376f04e0474e798787048d04c17c0f0ecf5e3c09 (diff)
parent391086908c8636f721e2cde87e92ce1ae8af899a (diff)
downloadcore-2c7ae59ede47792583b76141f6f73bcc6219bfbd.tar.gz
Merge "libsnapshot: MapCowImage returns the COW device path"
-rw-r--r--fs_mgr/libsnapshot/include/libsnapshot/snapshot.h4
-rw-r--r--fs_mgr/libsnapshot/snapshot.cpp14
-rw-r--r--fs_mgr/libsnapshot/snapshot_test.cpp7
3 files changed, 13 insertions, 12 deletions
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
index fcaa73ad7..120340c21 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
@@ -19,6 +19,7 @@
#include <chrono>
#include <map>
#include <memory>
+#include <optional>
#include <ostream>
#include <string>
#include <string_view>
@@ -298,7 +299,8 @@ class SnapshotManager final {
std::string* dev_path);
// Map a COW image that was previous created with CreateCowImage.
- bool MapCowImage(const std::string& name, const std::chrono::milliseconds& timeout_ms);
+ std::optional<std::string> MapCowImage(const std::string& name,
+ const std::chrono::milliseconds& timeout_ms);
// Remove the backing copy-on-write image and snapshot states for the named snapshot. The
// caller is responsible for ensuring that the snapshot is unmapped.
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 48a94e4f3..2c5eed11e 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -450,9 +450,9 @@ bool SnapshotManager::MapSnapshot(LockedFile* lock, const std::string& name,
return true;
}
-bool SnapshotManager::MapCowImage(const std::string& name,
- const std::chrono::milliseconds& timeout_ms) {
- if (!EnsureImageManager()) return false;
+std::optional<std::string> SnapshotManager::MapCowImage(
+ const std::string& name, const std::chrono::milliseconds& timeout_ms) {
+ if (!EnsureImageManager()) return std::nullopt;
auto cow_image_name = GetCowImageDeviceName(name);
bool ok;
@@ -468,10 +468,10 @@ bool SnapshotManager::MapCowImage(const std::string& name,
if (ok) {
LOG(INFO) << "Mapped " << cow_image_name << " to " << cow_dev;
- } else {
- LOG(ERROR) << "Could not map image device: " << cow_image_name;
+ return cow_dev;
}
- return ok;
+ LOG(ERROR) << "Could not map image device: " << cow_image_name;
+ return std::nullopt;
}
bool SnapshotManager::UnmapSnapshot(LockedFile* lock, const std::string& name) {
@@ -1443,7 +1443,7 @@ bool SnapshotManager::MapCowDevices(LockedFile* lock, const CreateLogicalPartiti
auto remaining_time = GetRemainingTime(params.timeout_ms, begin);
if (remaining_time.count() < 0) return false;
- if (!MapCowImage(partition_name, remaining_time)) {
+ if (!MapCowImage(partition_name, remaining_time).has_value()) {
LOG(ERROR) << "Could not map cow image for partition: " << partition_name;
return false;
}
diff --git a/fs_mgr/libsnapshot/snapshot_test.cpp b/fs_mgr/libsnapshot/snapshot_test.cpp
index a00829421..f6a47222a 100644
--- a/fs_mgr/libsnapshot/snapshot_test.cpp
+++ b/fs_mgr/libsnapshot/snapshot_test.cpp
@@ -254,12 +254,11 @@ class SnapshotTest : public ::testing::Test {
AssertionResult MapCowImage(const std::string& name,
const std::chrono::milliseconds& timeout_ms, std::string* path) {
- if (!sm->MapCowImage(name, timeout_ms)) {
+ auto cow_image_path = sm->MapCowImage(name, timeout_ms);
+ if (!cow_image_path.has_value()) {
return AssertionFailure() << "Cannot map cow image " << name;
}
- if (!dm_.GetDmDevicePathByName(name + "-cow-img"s, path)) {
- return AssertionFailure() << "No path for " << name << "-cow-img";
- }
+ *path = *cow_image_path;
return AssertionSuccess();
}