Merge "libsnapshot: MapCowImage returns the COW device path"
This commit is contained in:
commit
2c7ae59ede
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue